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>

+ Inheritance diagram for camitk::SyntaxHighlighter:
+ Collaboration diagram for camitk::SyntaxHighlighter:

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);
...
}
Base class for syntax highlighting.
Definition SyntaxHighlighter.h:62

You can now highlight any text edit:

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

Constructor & Destructor Documentation

◆ SyntaxHighlighter()

SyntaxHighlighter::SyntaxHighlighter ( QTextDocument *  parent = nullptr)

constructor

Parameters
parent(optional) if not given during instantiation, use setDocument(..) afterward

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(), ExtensionBuilderLogSyntaxHighlighter::ExtensionBuilderLogSyntaxHighlighter(), JsonSyntaxHighlighter::JsonSyntaxHighlighter(), and camitk::LogSyntaxHighlighter::LogSyntaxHighlighter().

+ Here is the caller graph for this function:

◆ 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

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