qsyntaxhighlighter.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qsyntaxhighlighter.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6class QSyntaxHighlighterPrivate : public QObjectPrivate-
7{-
8 inline QSyntaxHighlighter* q_func() { return static_cast<QSyntaxHighlighter *>(q_ptr); } inline const QSyntaxHighlighter* q_func() const { return static_cast<const QSyntaxHighlighter *>(q_ptr); } friend class QSyntaxHighlighter;-
9public:-
10 inline QSyntaxHighlighterPrivate()-
11 : rehighlightPending(false), inReformatBlocks(false)-
12 {}
never executed: end of block
0
13-
14 QPointer<QTextDocument> doc;-
15-
16 void _q_reformatBlocks(int from, int charsRemoved, int charsAdded);-
17 void reformatBlocks(int from, int charsRemoved, int charsAdded);-
18 void reformatBlock(const QTextBlock &block);-
19-
20 inline void rehighlight(QTextCursor &cursor, QTextCursor::MoveOperation operation) {-
21 inReformatBlocks = true;-
22 cursor.beginEditBlock();-
23 int from = cursor.position();-
24 cursor.movePosition(operation);-
25 reformatBlocks(from, 0, cursor.position() - from);-
26 cursor.endEditBlock();-
27 inReformatBlocks = false;-
28 }
never executed: end of block
0
29-
30 inline void _q_delayedRehighlight() {-
31 if (!rehighlightPending
!rehighlightPendingDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
32 return;
never executed: return;
0
33 rehighlightPending = false;-
34 q_func()->rehighlight();-
35 }
never executed: end of block
0
36-
37 void applyFormatChanges();-
38 QVector<QTextCharFormat> formatChanges;-
39 QTextBlock currentBlock;-
40 bool rehighlightPending;-
41 bool inReformatBlocks;-
42};-
43-
44void QSyntaxHighlighterPrivate::applyFormatChanges()-
45{-
46 bool formatsChanged = false;-
47-
48 QTextLayout *layout = currentBlock.layout();-
49-
50 QVector<QTextLayout::FormatRange> ranges = layout->formats();-
51-
52 const int preeditAreaStart = layout->preeditAreaPosition();-
53 const int preeditAreaLength = layout->preeditAreaText().length();-
54-
55 if (preeditAreaLength != 0
preeditAreaLength != 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
56 QVector<QTextLayout::FormatRange>::Iterator it = ranges.begin();-
57 while (it != ranges.end()
it != ranges.end()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
58 if (it->start >= preeditAreaStart
it->start >= preeditAreaStartDescription
TRUEnever evaluated
FALSEnever evaluated
0
59 && it->start + it->length <= preeditAreaStart + preeditAreaLength
it->start + it...editAreaLengthDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
60 ++it;-
61 }
never executed: end of block
else {
0
62 it = ranges.erase(it);-
63 formatsChanged = true;-
64 }
never executed: end of block
0
65 }-
66 }
never executed: end of block
else if (!ranges.isEmpty()
!ranges.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
67 ranges.clear();-
68 formatsChanged = true;-
69 }
never executed: end of block
0
70-
71 int i = 0;-
72 while (i < formatChanges.count()
i < formatChanges.count()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
73 QTextLayout::FormatRange r;-
74-
75 while (i < formatChanges.count()
i < formatChanges.count()Description
TRUEnever evaluated
FALSEnever evaluated
&& formatChanges.at(i) == r.format
formatChanges....i) == r.formatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
76 ++
never executed: ++i;
i;
never executed: ++i;
0
77-
78 if (i == formatChanges.count()
i == formatChanges.count()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
79 break;
never executed: break;
0
80-
81 r.start = i;-
82 r.format = formatChanges.at(i);-
83-
84 while (i < formatChanges.count()
i < formatChanges.count()Description
TRUEnever evaluated
FALSEnever evaluated
&& formatChanges.at(i) == r.format
formatChanges....i) == r.formatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
85 ++
never executed: ++i;
i;
never executed: ++i;
0
86-
87 ((!(i <= formatChanges.count())) ? qt_assert("i <= formatChanges.count()",__FILE__,130) : qt_noop());-
88 r.length = i - r.start;-
89-
90 if (preeditAreaLength != 0
preeditAreaLength != 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
91 if (r.start >= preeditAreaStart
r.start >= preeditAreaStartDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
92 r.start += preeditAreaLength;
never executed: r.start += preeditAreaLength;
0
93 else if (r.start + r.length >= preeditAreaStart
r.start + r.le...eeditAreaStartDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
94 r.length += preeditAreaLength;
never executed: r.length += preeditAreaLength;
0
95 }
never executed: end of block
0
96-
97 ranges << r;-
98 formatsChanged = true;-
99 }
never executed: end of block
0
100-
101 if (formatsChanged
formatsChangedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
102 layout->setFormats(ranges);-
103 doc->markContentsDirty(currentBlock.position(), currentBlock.length());-
104 }
never executed: end of block
0
105}
never executed: end of block
0
106-
107void QSyntaxHighlighterPrivate::_q_reformatBlocks(int from, int charsRemoved, int charsAdded)-
108{-
109 if (!inReformatBlocks
!inReformatBlocksDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
110 reformatBlocks(from, charsRemoved, charsAdded);
never executed: reformatBlocks(from, charsRemoved, charsAdded);
0
111}
never executed: end of block
0
112-
113void QSyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int charsAdded)-
114{-
115 rehighlightPending = false;-
116-
117 QTextBlock block = doc->findBlock(from);-
118 if (!block.isValid()
!block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
119 return;
never executed: return;
0
120-
121 int endPosition;-
122 QTextBlock lastBlock = doc->findBlock(from + charsAdded + (charsRemoved > 0 ? 1 : 0));-
123 if (lastBlock.isValid()
lastBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
124 endPosition = lastBlock.position() + lastBlock.length();
never executed: endPosition = lastBlock.position() + lastBlock.length();
0
125 else-
126 endPosition = doc->docHandle()->length();
never executed: endPosition = doc->docHandle()->length();
0
127-
128 bool forceHighlightOfNextBlock = false;-
129-
130 while (block.isValid()
block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
&& (block.position() < endPosition
block.position() < endPositionDescription
TRUEnever evaluated
FALSEnever evaluated
|| forceHighlightOfNextBlock
forceHighlightOfNextBlockDescription
TRUEnever evaluated
FALSEnever evaluated
)) {
0
131 const int stateBeforeHighlight = block.userState();-
132-
133 reformatBlock(block);-
134-
135 forceHighlightOfNextBlock = (block.userState() != stateBeforeHighlight);-
136-
137 block = block.next();-
138 }
never executed: end of block
0
139-
140 formatChanges.clear();-
141}
never executed: end of block
0
142-
143void QSyntaxHighlighterPrivate::reformatBlock(const QTextBlock &block)-
144{-
145 QSyntaxHighlighter * const q = q_func();-
146-
147 ((!(!currentBlock.isValid())) ? qt_assert_x("QSyntaxHighlighter::reformatBlock()", "reFormatBlock() called recursively",__FILE__,190) : qt_noop());-
148-
149 currentBlock = block;-
150-
151 formatChanges.fill(QTextCharFormat(), block.length() - 1);-
152 q->highlightBlock(block.text());-
153 applyFormatChanges();-
154-
155 currentBlock = QTextBlock();-
156}
never executed: end of block
0
157QSyntaxHighlighter::QSyntaxHighlighter(QObject *parent)-
158 : QObject(*new QSyntaxHighlighterPrivate, parent)-
159{-
160 if (parent->inherits("QTextEdit")
parent->inherits("QTextEdit")Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
161 QTextDocument *doc = parent->property("document").value<QTextDocument *>();-
162 if (doc
docDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
163 setDocument(doc);
never executed: setDocument(doc);
0
164 }
never executed: end of block
0
165}
never executed: end of block
0
166-
167-
168-
169-
170-
171-
172QSyntaxHighlighter::QSyntaxHighlighter(QTextDocument *parent)-
173 : QObject(*new QSyntaxHighlighterPrivate, parent)-
174{-
175 setDocument(parent);-
176}
never executed: end of block
0
177-
178-
179-
180-
181QSyntaxHighlighter::~QSyntaxHighlighter()-
182{-
183 setDocument(0);-
184}
never executed: end of block
0
185-
186-
187-
188-
189-
190void QSyntaxHighlighter::setDocument(QTextDocument *doc)-
191{-
192 QSyntaxHighlighterPrivate * const d = d_func();-
193 if (d->doc
d->docDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
194 disconnect(d->doc, qFlagLocation("2""contentsChange(int,int,int)" "\0" __FILE__ ":" "326"),-
195 this, qFlagLocation("1""_q_reformatBlocks(int,int,int)" "\0" __FILE__ ":" "327"));-
196-
197 QTextCursor cursor(d->doc);-
198 cursor.beginEditBlock();-
199 for (QTextBlock blk = d->doc->begin(); blk.isValid()
blk.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
; blk = blk.next())
0
200 blk.layout()->clearFormats();
never executed: blk.layout()->clearFormats();
0
201 cursor.endEditBlock();-
202 }
never executed: end of block
0
203 d->doc = doc;-
204 if (d->doc
d->docDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
205 connect(d->doc, qFlagLocation("2""contentsChange(int,int,int)" "\0" __FILE__ ":" "337"),-
206 this, qFlagLocation("1""_q_reformatBlocks(int,int,int)" "\0" __FILE__ ":" "338"));-
207 d->rehighlightPending = true;-
208 QTimer::singleShot(0, this, qFlagLocation("1""_q_delayedRehighlight()" "\0" __FILE__ ":" "340"));-
209 }
never executed: end of block
0
210}
never executed: end of block
0
211-
212-
213-
214-
215-
216QTextDocument *QSyntaxHighlighter::document() const-
217{-
218 const QSyntaxHighlighterPrivate * const d = d_func();-
219 return
never executed: return d->doc;
d->doc;
never executed: return d->doc;
0
220}-
221void QSyntaxHighlighter::rehighlight()-
222{-
223 QSyntaxHighlighterPrivate * const d = d_func();-
224 if (!d->doc
!d->docDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
225 return;
never executed: return;
0
226-
227 QTextCursor cursor(d->doc);-
228 d->rehighlight(cursor, QTextCursor::End);-
229}
never executed: end of block
0
230void QSyntaxHighlighter::rehighlightBlock(const QTextBlock &block)-
231{-
232 QSyntaxHighlighterPrivate * const d = d_func();-
233 if (!d->doc
!d->docDescription
TRUEnever evaluated
FALSEnever evaluated
|| !block.isValid()
!block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
|| block.document() != d->doc
block.document() != d->docDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
234 return;
never executed: return;
0
235-
236 const bool rehighlightPending = d->rehighlightPending;-
237-
238 QTextCursor cursor(block);-
239 d->rehighlight(cursor, QTextCursor::EndOfBlock);-
240-
241 if (rehighlightPending
rehighlightPendingDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
242 d->rehighlightPending = rehighlightPending;
never executed: d->rehighlightPending = rehighlightPending;
0
243}
never executed: end of block
0
244void QSyntaxHighlighter::setFormat(int start, int count, const QTextCharFormat &format)-
245{-
246 QSyntaxHighlighterPrivate * const d = d_func();-
247 if (start < 0
start < 0Description
TRUEnever evaluated
FALSEnever evaluated
|| start >= d->formatChanges.count()
start >= d->fo...hanges.count()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
248 return;
never executed: return;
0
249-
250 const int end = qMin(start + count, d->formatChanges.count());-
251 for (int i = start; i < end
i < endDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
252 d->formatChanges[i] = format;
never executed: d->formatChanges[i] = format;
0
253}
never executed: end of block
0
254void QSyntaxHighlighter::setFormat(int start, int count, const QColor &color)-
255{-
256 QTextCharFormat format;-
257 format.setForeground(color);-
258 setFormat(start, count, format);-
259}
never executed: end of block
0
260void QSyntaxHighlighter::setFormat(int start, int count, const QFont &font)-
261{-
262 QTextCharFormat format;-
263 format.setFont(font);-
264 setFormat(start, count, format);-
265}
never executed: end of block
0
266-
267-
268-
269-
270-
271-
272-
273QTextCharFormat QSyntaxHighlighter::format(int pos) const-
274{-
275 const QSyntaxHighlighterPrivate * const d = d_func();-
276 if (pos < 0
pos < 0Description
TRUEnever evaluated
FALSEnever evaluated
|| pos >= d->formatChanges.count()
pos >= d->form...hanges.count()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
277 return
never executed: return QTextCharFormat();
QTextCharFormat();
never executed: return QTextCharFormat();
0
278 return
never executed: return d->formatChanges.at(pos);
d->formatChanges.at(pos);
never executed: return d->formatChanges.at(pos);
0
279}-
280int QSyntaxHighlighter::previousBlockState() const-
281{-
282 const QSyntaxHighlighterPrivate * const d = d_func();-
283 if (!d->currentBlock.isValid()
!d->currentBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
284 return
never executed: return -1;
-1;
never executed: return -1;
0
285-
286 const QTextBlock previous = d->currentBlock.previous();-
287 if (!previous.isValid()
!previous.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
288 return
never executed: return -1;
-1;
never executed: return -1;
0
289-
290 return
never executed: return previous.userState();
previous.userState();
never executed: return previous.userState();
0
291}-
292-
293-
294-
295-
296-
297int QSyntaxHighlighter::currentBlockState() const-
298{-
299 const QSyntaxHighlighterPrivate * const d = d_func();-
300 if (!d->currentBlock.isValid()
!d->currentBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
301 return
never executed: return -1;
-1;
never executed: return -1;
0
302-
303 return
never executed: return d->currentBlock.userState();
d->currentBlock.userState();
never executed: return d->currentBlock.userState();
0
304}-
305-
306-
307-
308-
309-
310-
311void QSyntaxHighlighter::setCurrentBlockState(int newState)-
312{-
313 QSyntaxHighlighterPrivate * const d = d_func();-
314 if (!d->currentBlock.isValid()
!d->currentBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
315 return;
never executed: return;
0
316-
317 d->currentBlock.setUserState(newState);-
318}
never executed: end of block
0
319void QSyntaxHighlighter::setCurrentBlockUserData(QTextBlockUserData *data)-
320{-
321 QSyntaxHighlighterPrivate * const d = d_func();-
322 if (!d->currentBlock.isValid()
!d->currentBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
323 return;
never executed: return;
0
324-
325 d->currentBlock.setUserData(data);-
326}
never executed: end of block
0
327-
328-
329-
330-
331-
332-
333-
334QTextBlockUserData *QSyntaxHighlighter::currentBlockUserData() const-
335{-
336 const QSyntaxHighlighterPrivate * const d = d_func();-
337 if (!d->currentBlock.isValid()
!d->currentBlock.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
338 return
never executed: return 0;
0;
never executed: return 0;
0
339-
340 return
never executed: return d->currentBlock.userData();
d->currentBlock.userData();
never executed: return d->currentBlock.userData();
0
341}-
342-
343-
344-
345-
346-
347-
348QTextBlock QSyntaxHighlighter::currentBlock() const-
349{-
350 const QSyntaxHighlighterPrivate * const d = d_func();-
351 return
never executed: return d->currentBlock;
d->currentBlock;
never executed: return d->currentBlock;
0
352}-
353-
354-
355-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9