DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
#include <highlighter.hpp>
Classes | |
struct | FormatCache |
struct | HighlightingRule |
Public Member Functions | |
Highlighter (QTextDocument *parent=0) | |
ctor | |
void | setRule (QRegExp r, QTextCharFormat f) |
void | highlightAll (const QString &txt, bool caseSensitivity) |
Protected Member Functions | |
void | highlightBlock (const QString &text) |
Private Attributes | |
QVector< HighlightingRule > | highlightingRules |
highlighting rules | |
QRegExp | highlightAllReg |
regexp containing text to highlight | |
QMutex * | mutex |
mutex to protect highlightBlock method | |
QHash< uint, QList< FormatCache > > | cache |
stores result of formatting for a given QString text (using uint qHash(QString) method) | |
This class provides custom highlighting of textedits. It is possible to define any number of patterns (using regular expressions) and a format to be applied to the given pattern. It also provides functionality to highlight all occocurences of a given text using the
method. For example in dvs_gui it is used to highlight the log outputs. Usage:
Definition at line 29 of file highlighter.hpp.
Highlighter::Highlighter | ( | QTextDocument * | parent = 0 | ) |
ctor
Creates highlighter. Initializes the mutex.
Definition at line 10 of file highlighter.cpp.
|
inline |
Updates the text to highlight and rechecks the entire text
txt | The text to highlight |
caseSensitivity | whether the highlighting is case sensitive or not |
Definition at line 55 of file highlighter.hpp.
|
protected |
Highlights a block of text according to the given rules (regexp + QTextCharFormat) Uses a cache for performance reasons. This way we do not have to run regexps every time.
text | text to highlight. Used to calculate the hash and hence cache value |
Reapply the stored formattings
Apply formatting using regexp and store it in cache for later use
Note. we should not cache highlighting as it changes all the time
Definition at line 21 of file highlighter.cpp.
|
inline |
Adds a highlighting rule to the list. We need to clear the cache in this case (though normally rules are added very rarely)
r | Regular expression to identify the text to highlight |
f | format to apply to the text |
Definition at line 41 of file highlighter.hpp.
|
private |
stores result of formatting for a given QString text (using uint qHash(QString) method)
Definition at line 88 of file highlighter.hpp.
|
private |
regexp containing text to highlight
Definition at line 86 of file highlighter.hpp.
|
private |
highlighting rules
Definition at line 85 of file highlighter.hpp.
|
private |
mutex to protect highlightBlock method
Definition at line 87 of file highlighter.hpp.