DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
src
qtutils
highlighter.cpp
Go to the documentation of this file.
1
#include "
dbe/highlighter.hpp
"
2
#include <QMutexLocker>
3
#include <QtGui>
4
5
// using namespace daq::QTUtils;
10
Highlighter::Highlighter
(QTextDocument* parent)
11
: QSyntaxHighlighter(parent)
12
{
13
mutex
=
new
QMutex();
14
}
15
21
void
22
Highlighter::highlightBlock
(
const
QString& text)
23
{
24
QMutexLocker locker(
mutex
);
25
26
/*
27
* check if we have formatted this text before
28
* If so there is no need to run regexp again and we can simply reapply the cached formatting.
29
* Remember to clear the cache if new rules are added after it has been filled (not likely)
30
*/
31
uint hash = qHash(text);
32
if
(
cache
.contains(hash)) {
36
FormatCache
form;
37
foreach
(form,
cache
.value(hash)) {
38
for
(
int
i = 0; i < form.
indexes
.size(); i++) {
39
setFormat(form.
indexes
.at(i), form.
lengths
.at(i), form.
rule
.
format
);
40
}
41
}
42
}
else
{
46
QList<FormatCache> forms;
// list of all formatting being done
47
foreach
(
HighlightingRule
rule,
highlightingRules
) {
48
FormatCache
form;
49
form.
rule
= rule;
// store the rule
50
QRegExp expression(rule.
pattern
);
51
int
index = text.indexOf(expression);
52
int
length;
53
while
(index >= 0) {
54
55
length = expression.matchedLength();
56
form.
indexes
.append(index);
// store index
57
form.
lengths
.append(length);
// store length
58
setFormat(index, length, rule.
format
);
59
index = text.indexOf(expression, index + length);
60
}
61
forms.append(form);
// append this formatting (rule, indexes and lengths) to the list
62
}
63
cache
.insert(hash, forms);
// store list in cache
64
}
68
if
(!
highlightAllReg
.isEmpty()) {
69
int
index = text.indexOf(
highlightAllReg
);
70
while
(index >= 0) {
71
int
length =
highlightAllReg
.matchedLength();
72
QTextCharFormat format;
73
format.setBackground(Qt::yellow);
74
setFormat(index, length, format);
75
index = text.indexOf(
highlightAllReg
, index + length);
76
}
77
}
78
}
daq::QTUtils::Highlighter::highlightAllReg
QRegExp highlightAllReg
regexp containing text to highlight
Definition
highlighter.hpp:87
daq::QTUtils::Highlighter::highlightingRules
QVector< HighlightingRule > highlightingRules
highlighting rules
Definition
highlighter.hpp:86
daq::QTUtils::Highlighter::mutex
QMutex * mutex
mutex to protect highlightBlock method
Definition
highlighter.hpp:88
daq::QTUtils::Highlighter::cache
QHash< uint, QList< FormatCache > > cache
stores result of formatting for a given QString text (using uint qHash(QString) method)
Definition
highlighter.hpp:90
daq::QTUtils::Highlighter::highlightBlock
void highlightBlock(const QString &text)
Definition
highlighter.cpp:22
daq::QTUtils::Highlighter::Highlighter
Highlighter(QTextDocument *parent=0)
ctor
Definition
highlighter.cpp:10
highlighter.hpp
daq::QTUtils::Highlighter::FormatCache
Definition
highlighter.hpp:81
daq::QTUtils::Highlighter::FormatCache::lengths
QVector< int > lengths
Definition
highlighter.hpp:84
daq::QTUtils::Highlighter::FormatCache::indexes
QVector< int > indexes
Definition
highlighter.hpp:83
daq::QTUtils::Highlighter::FormatCache::rule
HighlightingRule rule
Definition
highlighter.hpp:82
daq::QTUtils::Highlighter::HighlightingRule
Definition
highlighter.hpp:72
daq::QTUtils::Highlighter::HighlightingRule::pattern
QRegExp pattern
Definition
highlighter.hpp:73
daq::QTUtils::Highlighter::HighlightingRule::format
QTextCharFormat format
Definition
highlighter.hpp:74
Generated on
for DUNE-DAQ by
1.18.0