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 <QtGui>
3
#include <QMutexLocker>
4
5
//using namespace daq::QTUtils;
10
Highlighter::Highlighter
(QTextDocument *parent)
11
: QSyntaxHighlighter(parent)
12
{
13
mutex
=
new
QMutex();
14
}
15
21
void
Highlighter::highlightBlock
(
const
QString &text)
22
{
23
QMutexLocker locker(
mutex
);
24
25
/*
26
* check if we have formatted this text before
27
* If so there is no need to run regexp again and we can simply reapply the cached formatting.
28
* Remember to clear the cache if new rules are added after it has been filled (not likely)
29
*/
30
uint hash = qHash(text);
31
if
(
cache
.contains(hash))
32
{
36
FormatCache
form;
37
foreach
(form,
cache
.value(hash)){
38
for
(
int
i =0; i < form.
indexes
.size();i++)
39
{
40
setFormat(form.
indexes
.at(i), form.
lengths
.at(i), form.
rule
.
format
);
41
}
42
}
43
}
44
else
45
{
49
QList<FormatCache> forms;
//list of all formatting being done
50
foreach
(
HighlightingRule
rule,
highlightingRules
)
51
{
52
FormatCache
form;
53
form.
rule
= rule;
//store the rule
54
QRegExp expression(rule.
pattern
);
55
int
index = text.indexOf(expression);
56
int
length;
57
while
(index >= 0)
58
{
59
60
length = expression.matchedLength();
61
form.
indexes
.append(index);
//store index
62
form.
lengths
.append(length);
//store length
63
setFormat(index, length, rule.
format
);
64
index = text.indexOf(expression, index + length);
65
}
66
forms.append(form);
//append this formatting (rule, indexes and lengths) to the list
67
}
68
cache
.insert(hash,forms);
//store list in cache
69
70
}
74
if
(!
highlightAllReg
.isEmpty())
75
{
76
int
index = text.indexOf(
highlightAllReg
);
77
while
(index >= 0)
78
{
79
int
length =
highlightAllReg
.matchedLength();
80
QTextCharFormat format;
81
format.setBackground(Qt::yellow);
82
setFormat(index, length, format);
83
index = text.indexOf(
highlightAllReg
, index + length);
84
}
85
}
86
87
}
daq::QTUtils::Highlighter::highlightAllReg
QRegExp highlightAllReg
regexp containing text to highlight
Definition
highlighter.hpp:86
daq::QTUtils::Highlighter::highlightingRules
QVector< HighlightingRule > highlightingRules
highlighting rules
Definition
highlighter.hpp:85
daq::QTUtils::Highlighter::mutex
QMutex * mutex
mutex to protect highlightBlock method
Definition
highlighter.hpp:87
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:88
daq::QTUtils::Highlighter::highlightBlock
void highlightBlock(const QString &text)
Definition
highlighter.cpp:21
daq::QTUtils::Highlighter::Highlighter
Highlighter(QTextDocument *parent=0)
ctor
Definition
highlighter.cpp:10
highlighter.hpp
daq::QTUtils::Highlighter::FormatCache
Definition
highlighter.hpp:80
daq::QTUtils::Highlighter::FormatCache::lengths
QVector< int > lengths
Definition
highlighter.hpp:83
daq::QTUtils::Highlighter::FormatCache::indexes
QVector< int > indexes
Definition
highlighter.hpp:82
daq::QTUtils::Highlighter::FormatCache::rule
HighlightingRule rule
Definition
highlighter.hpp:81
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.17.0