Computer Assisted Medical Intervention Tool Kit  version 6.0
Loading...
Searching...
No Matches
camitk::SyntaxHighlighter Class Reference

Base class for syntax highlighting. More...

#include <SyntaxHighlighter.h>

Public Member Functions

void addRule (QString regexp, QColor color, int weight=QFont::Normal, bool italic=false, QColor backgroundColor=Qt::transparent)
 add a new rule (can be done on the fly)
bool removeRule (QString regexp)
 remove an existing rule (can be done on the fly)
 SyntaxHighlighter (QTextDocument *parent=nullptr)
 constructor

Detailed Description

Base class for syntax highlighting.

Defines rules for transformation to facilitate new language highlighting.

In the inherited class' constructor, just add rules, and that's it!

MyLanguageHighlighter::MyLanguageHighlighter(QTextDocument* parent) : SyntaxHighlighter(parent) {
// display goto keywords in bold red
addRule(QRegularExpression("\\bgoto\\b"), QColor("#ff0000"), QFont::Bold);
...
}
void addRule(QString regexp, QColor color, int weight=QFont::Normal, bool italic=false, QColor backgroundColor=Qt::transparent)
add a new rule (can be done on the fly)
Definition SyntaxHighlighter.cpp:38
SyntaxHighlighter(QTextDocument *parent=nullptr)
constructor
Definition SyntaxHighlighter.cpp:31

You can now highlight any text edit:

QTextEdit* textEdit = new QTextEdit();
...
new MyLanguageHighlighter(textEdit->document());

Constructor & Destructor Documentation

◆ SyntaxHighlighter()

SyntaxHighlighter::SyntaxHighlighter ( QTextDocument * parent = nullptr)

Member Function Documentation

◆ addRule()

void SyntaxHighlighter::addRule ( QString regexp,
QColor color,
int weight = QFont::Normal,
bool italic = false,
QColor backgroundColor = Qt::transparent )

add a new rule (can be done on the fly)

Parameters
regexpto match
colortext color
weightQFont::Normal for normal (default) or QFont::Bold for bold
italicfalse by default
backgroundColortransparent by default

Referenced by CMakeSyntaxHighlighter::CMakeSyntaxHighlighter(), CppSyntaxHighlighter::CppSyntaxHighlighter(), ExtensionGeneratorLogSyntaxHighlighter::ExtensionGeneratorLogSyntaxHighlighter(), JsonSyntaxHighlighter::JsonSyntaxHighlighter(), camitk::LogSyntaxHighlighter::LogSyntaxHighlighter(), and camitk::LogSyntaxHighlighter::setHighlight().

◆ removeRule()

bool SyntaxHighlighter::removeRule ( QString regexp)

remove an existing rule (can be done on the fly)

Returns
true if the rule was found and removed

Referenced by camitk::LogSyntaxHighlighter::unsetHighlight().


The documentation for this class was generated from the following files: