text/qtextobject.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qtextobject.h" -
43#include "qtextobject_p.h" -
44#include "qtextdocument.h" -
45#include "qtextformat_p.h" -
46#include "qtextdocument_p.h" -
47#include "qtextcursor.h" -
48#include "qtextlist.h" -
49#include "qabstracttextdocumentlayout.h" -
50#include "qtextengine_p.h" -
51#include "qdebug.h" -
52 -
53#include <algorithm> -
54 -
55QT_BEGIN_NAMESPACE -
56 -
57// ### DOC: We ought to explain the CONCEPT of objectIndexes if -
58// relevant to the public API -
59/*! -
60 \class QTextObject -
61 \reentrant -
62 -
63 \brief The QTextObject class is a base class for different kinds -
64 of objects that can group parts of a QTextDocument together. -
65 \inmodule QtGui -
66 -
67 \ingroup richtext-processing -
68 -
69 The common grouping text objects are lists (QTextList), frames -
70 (QTextFrame), and tables (QTextTable). A text object has an -
71 associated format() and document(). -
72 -
73 There are essentially two kinds of text objects: those that are used -
74 with blocks (block formats), and those that are used with characters -
75 (character formats). The first kind are derived from QTextBlockGroup, -
76 and the second kind from QTextFrame. -
77 -
78 You rarely need to use this class directly. When creating custom text -
79 objects, you will also need to reimplement QTextDocument::createObject() -
80 which acts as a factory method for creating text objects. -
81 -
82 \sa QTextDocument, {Text Object Example} -
83*/ -
84 -
85/*! -
86 \fn QTextObject::QTextObject(QTextDocument *document) -
87 -
88 Creates a new QTextObject for the given \a document. -
89 -
90 \warning This function should never be called directly, but only -
91 from QTextDocument::createObject(). -
92*/ -
93QTextObject::QTextObject(QTextDocument *doc) -
94 : QObject(*new QTextObjectPrivate(doc), doc) -
95{ -
96}
executed: }
Execution Count:1
1
97 -
98/*! -
99 \fn QTextObject::QTextObject(QTextObjectPrivate &p, QTextDocument *document) -
100 -
101 \internal -
102*/ -
103QTextObject::QTextObject(QTextObjectPrivate &p, QTextDocument *doc) -
104 : QObject(p, doc) -
105{ -
106}
executed: }
Execution Count:2217
2217
107 -
108/*! -
109 Destroys the text object. -
110 -
111 \warning Text objects are owned by the document, so you should -
112 never destroy them yourself. -
113*/ -
114QTextObject::~QTextObject() -
115{ -
116} -
117 -
118/*! -
119 Returns the text object's format. -
120 -
121 \sa setFormat(), document() -
122*/ -
123QTextFormat QTextObject::format() const -
124{ -
125 Q_D(const QTextObject);
executed (the execution status of this line is deduced): const QTextObjectPrivate * const d = d_func();
-
126 return d->pieceTable->formatCollection()->objectFormat(d->objectIndex);
executed: return d->pieceTable->formatCollection()->objectFormat(d->objectIndex);
Execution Count:5302
5302
127} -
128 -
129/*! -
130 Returns the index of the object's format in the document's internal -
131 list of formats. -
132 -
133 \sa QTextDocument::allFormats() -
134*/ -
135int QTextObject::formatIndex() const -
136{ -
137 Q_D(const QTextObject);
executed (the execution status of this line is deduced): const QTextObjectPrivate * const d = d_func();
-
138 return d->pieceTable->formatCollection()->objectFormatIndex(d->objectIndex);
executed: return d->pieceTable->formatCollection()->objectFormatIndex(d->objectIndex);
Execution Count:1
1
139} -
140 -
141 -
142/*! -
143 Sets the text object's \a format. -
144 -
145 \sa format() -
146*/ -
147void QTextObject::setFormat(const QTextFormat &format) -
148{ -
149 Q_D(QTextObject);
executed (the execution status of this line is deduced): QTextObjectPrivate * const d = d_func();
-
150 int idx = d->pieceTable->formatCollection()->indexForFormat(format);
executed (the execution status of this line is deduced): int idx = d->pieceTable->formatCollection()->indexForFormat(format);
-
151 d->pieceTable->changeObjectFormat(this, idx);
executed (the execution status of this line is deduced): d->pieceTable->changeObjectFormat(this, idx);
-
152}
executed: }
Execution Count:104
104
153 -
154/*! -
155 Returns the object index of this object. This can be used together with -
156 QTextFormat::setObjectIndex(). -
157*/ -
158int QTextObject::objectIndex() const -
159{ -
160 Q_D(const QTextObject);
executed (the execution status of this line is deduced): const QTextObjectPrivate * const d = d_func();
-
161 return d->objectIndex;
executed: return d->objectIndex;
Execution Count:392
392
162} -
163 -
164/*! -
165 Returns the document this object belongs to. -
166 -
167 \sa format() -
168*/ -
169QTextDocument *QTextObject::document() const -
170{ -
171 return static_cast<QTextDocument *>(parent());
executed: return static_cast<QTextDocument *>(parent());
Execution Count:25
25
172} -
173 -
174/*! -
175 \internal -
176*/ -
177QTextDocumentPrivate *QTextObject::docHandle() const -
178{ -
179 return static_cast<const QTextDocument *>(parent())->docHandle();
executed: return static_cast<const QTextDocument *>(parent())->docHandle();
Execution Count:35199
35199
180} -
181 -
182/*! -
183 \class QTextBlockGroup -
184 \reentrant -
185 -
186 \brief The QTextBlockGroup class provides a container for text blocks within -
187 a QTextDocument. -
188 \inmodule QtGui -
189 -
190 \ingroup richtext-processing -
191 -
192 Block groups can be used to organize blocks of text within a document. -
193 They maintain an up-to-date list of the text blocks that belong to -
194 them, even when text blocks are being edited. -
195 -
196 Each group has a parent document which is specified when the group is -
197 constructed. -
198 -
199 Text blocks can be inserted into a group with blockInserted(), and removed -
200 with blockRemoved(). If a block's format is changed, blockFormatChanged() -
201 is called. -
202 -
203 The list of blocks in the group is returned by blockList(). Note that the -
204 blocks in the list are not necessarily adjacent elements in the document; -
205 for example, the top-level items in a multi-level list will be separated -
206 by the items in lower levels of the list. -
207 -
208 \sa QTextBlock, QTextDocument -
209*/ -
210 -
211void QTextBlockGroupPrivate::markBlocksDirty() -
212{ -
213 for (int i = 0; i < blocks.count(); ++i) {
evaluated: i < blocks.count()
TRUEFALSE
yes
Evaluation Count:25270651
yes
Evaluation Count:11079
11079-25270651
214 const QTextBlock &block = blocks.at(i);
executed (the execution status of this line is deduced): const QTextBlock &block = blocks.at(i);
-
215 pieceTable->documentChange(block.position(), block.length());
executed (the execution status of this line is deduced): pieceTable->documentChange(block.position(), block.length());
-
216 }
executed: }
Execution Count:25270651
25270651
217}
executed: }
Execution Count:11079
11079
218 -
219/*! -
220 \fn QTextBlockGroup::QTextBlockGroup(QTextDocument *document) -
221 -
222 Creates a new new block group for the given \a document. -
223 -
224 \warning This function should only be called from -
225 QTextDocument::createObject(). -
226*/ -
227QTextBlockGroup::QTextBlockGroup(QTextDocument *doc) -
228 : QTextObject(*new QTextBlockGroupPrivate(doc), doc) -
229{ -
230}
never executed: }
0
231 -
232/*! -
233 \internal -
234*/ -
235QTextBlockGroup::QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc) -
236 : QTextObject(p, doc) -
237{ -
238}
executed: }
Execution Count:105
105
239 -
240/*! -
241 Destroys this block group; the blocks are not deleted, they simply -
242 don't belong to this block anymore. -
243*/ -
244QTextBlockGroup::~QTextBlockGroup() -
245{ -
246} -
247 -
248// ### DOC: Shouldn't this be insertBlock()? -
249/*! -
250 Appends the given \a block to the end of the group. -
251 -
252 \warning If you reimplement this function you must call the base -
253 class implementation. -
254*/ -
255void QTextBlockGroup::blockInserted(const QTextBlock &block) -
256{ -
257 Q_D(QTextBlockGroup);
executed (the execution status of this line is deduced): QTextBlockGroupPrivate * const d = d_func();
-
258 QTextBlockGroupPrivate::BlockList::Iterator it = std::lower_bound(d->blocks.begin(), d->blocks.end(), block);
executed (the execution status of this line is deduced): QTextBlockGroupPrivate::BlockList::Iterator it = std::lower_bound(d->blocks.begin(), d->blocks.end(), block);
-
259 d->blocks.insert(it, block);
executed (the execution status of this line is deduced): d->blocks.insert(it, block);
-
260 d->markBlocksDirty();
executed (the execution status of this line is deduced): d->markBlocksDirty();
-
261}
executed: }
Execution Count:11068
11068
262 -
263// ### DOC: Shouldn't this be removeBlock()? -
264/*! -
265 Removes the given \a block from the group; the block itself is not -
266 deleted, it simply isn't a member of this group anymore. -
267*/ -
268void QTextBlockGroup::blockRemoved(const QTextBlock &block) -
269{ -
270 Q_D(QTextBlockGroup);
executed (the execution status of this line is deduced): QTextBlockGroupPrivate * const d = d_func();
-
271 d->blocks.removeAll(block);
executed (the execution status of this line is deduced): d->blocks.removeAll(block);
-
272 d->markBlocksDirty();
executed (the execution status of this line is deduced): d->markBlocksDirty();
-
273 if (d->blocks.isEmpty()) {
evaluated: d->blocks.isEmpty()
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:5
5
274 document()->docHandle()->deleteObject(this);
executed (the execution status of this line is deduced): document()->docHandle()->deleteObject(this);
-
275 return;
executed: return;
Execution Count:5
5
276 } -
277}
executed: }
Execution Count:5
5
278 -
279/*! -
280 This function is called whenever the specified \a block of text is changed. -
281 The text block is a member of this group. -
282 -
283 The base class implementation does nothing. -
284*/ -
285void QTextBlockGroup::blockFormatChanged(const QTextBlock &) -
286{ -
287} -
288 -
289/*! -
290 Returns a (possibly empty) list of all the blocks that are part of -
291 the block group. -
292*/ -
293QList<QTextBlock> QTextBlockGroup::blockList() const -
294{ -
295 Q_D(const QTextBlockGroup);
never executed (the execution status of this line is deduced): const QTextBlockGroupPrivate * const d = d_func();
-
296 return d->blocks;
never executed: return d->blocks;
0
297} -
298 -
299 -
300 -
301QTextFrameLayoutData::~QTextFrameLayoutData() -
302{ -
303} -
304 -
305 -
306/*! -
307 \class QTextFrame -
308 \reentrant -
309 -
310 \brief The QTextFrame class represents a frame in a QTextDocument. -
311 \inmodule QtGui -
312 -
313 \ingroup richtext-processing -
314 -
315 Text frames provide structure for the text in a document. They are used -
316 as generic containers for other document elements. -
317 Frames are usually created by using QTextCursor::insertFrame(). -
318 -
319 \omit -
320 Each frame in a document consists of a frame start character, -
321 QChar(0xFDD0), followed by the frame's contents, followed by a -
322 frame end character, QChar(0xFDD1). The character formats of the -
323 start and end character contain a reference to the frame object's -
324 objectIndex. -
325 \endomit -
326 -
327 Frames can be used to create hierarchical structures in rich text documents. -
328 Each document has a root frame (QTextDocument::rootFrame()), and each frame -
329 beneath the root frame has a parent frame and a (possibly empty) list of -
330 child frames. The parent frame can be found with parentFrame(), and the -
331 childFrames() function provides a list of child frames. -
332 -
333 Each frame contains at least one text block to enable text cursors to -
334 insert new document elements within. As a result, the QTextFrame::iterator -
335 class is used to traverse both the blocks and child frames within a given -
336 frame. The first and last child elements in the frame can be found with -
337 begin() and end(). -
338 -
339 A frame also has a format (specified using QTextFrameFormat) which can be set -
340 with setFormat() and read with format(). -
341 -
342 Text cursors can be obtained that point to the first and last valid cursor -
343 positions within a frame; use the firstCursorPosition() and -
344 lastCursorPosition() functions for this. The frame's extent in the -
345 document can be found with firstPosition() and lastPosition(). -
346 -
347 You can iterate over a frame's contents using the -
348 QTextFrame::iterator class: this provides read-only access to its -
349 internal list of text blocks and child frames. -
350 -
351 \sa QTextCursor, QTextDocument -
352*/ -
353 -
354/*! -
355 \typedef QTextFrame::Iterator -
356 -
357 Qt-style synonym for QTextFrame::iterator. -
358*/ -
359 -
360/*! -
361 \fn QTextFrame *QTextFrame::iterator::parentFrame() const -
362 -
363 Returns the parent frame of the current frame. -
364 -
365 \sa currentFrame(), QTextFrame::parentFrame() -
366*/ -
367 -
368/*! -
369 \fn bool QTextFrame::iterator::operator==(const iterator &other) const -
370 -
371 Retuns true if the iterator is the same as the \a other iterator; -
372 otherwise returns false. -
373*/ -
374 -
375/*! -
376 \fn bool QTextFrame::iterator::operator!=(const iterator &other) const -
377 -
378 Retuns true if the iterator is different from the \a other iterator; -
379 otherwise returns false. -
380*/ -
381 -
382/*! -
383 \fn QTextFrame::iterator QTextFrame::iterator::operator++(int) -
384 -
385 The postfix ++ operator (\c{i++}) advances the iterator to the -
386 next item in the text frame, and returns an iterator to the old item. -
387*/ -
388 -
389/*! -
390 \fn QTextFrame::iterator QTextFrame::iterator::operator--(int) -
391 -
392 The postfix -- operator (\c{i--}) makes the preceding item in the -
393 current frame, and returns an iterator to the old item. -
394*/ -
395 -
396/*! -
397 \fn void QTextFrame::setFrameFormat(const QTextFrameFormat &format) -
398 -
399 Sets the frame's \a format. -
400 -
401 \sa frameFormat() -
402*/ -
403 -
404/*! -
405 \fn QTextFrameFormat QTextFrame::frameFormat() const -
406 -
407 Returns the frame's format. -
408 -
409 \sa setFrameFormat() -
410*/ -
411 -
412/*! -
413 \fn QTextFrame::QTextFrame(QTextDocument *document) -
414 -
415 Creates a new empty frame for the text \a document. -
416*/ -
417QTextFrame::QTextFrame(QTextDocument *doc) -
418 : QTextObject(*new QTextFramePrivate(doc), doc) -
419{ -
420}
executed: }
Execution Count:1872
1872
421 -
422// ### DOC: What does this do to child frames? -
423/*! -
424 Destroys the frame, and removes it from the document's layout. -
425*/ -
426QTextFrame::~QTextFrame() -
427{ -
428 Q_D(QTextFrame);
executed (the execution status of this line is deduced): QTextFramePrivate * const d = d_func();
-
429 delete d->layoutData;
executed (the execution status of this line is deduced): delete d->layoutData;
-
430}
executed: }
Execution Count:2108
2108
431 -
432/*! -
433 \internal -
434*/ -
435QTextFrame::QTextFrame(QTextFramePrivate &p, QTextDocument *doc) -
436 : QTextObject(p, doc) -
437{ -
438}
executed: }
Execution Count:240
240
439 -
440/*! -
441 Returns a (possibly empty) list of the frame's child frames. -
442 -
443 \sa parentFrame() -
444*/ -
445QList<QTextFrame *> QTextFrame::childFrames() const -
446{ -
447 Q_D(const QTextFrame);
executed (the execution status of this line is deduced): const QTextFramePrivate * const d = d_func();
-
448 return d->childFrames;
executed: return d->childFrames;
Execution Count:17627
17627
449} -
450 -
451/*! -
452 Returns the frame's parent frame. If the frame is the root frame of a -
453 document, this will return 0. -
454 -
455 \sa childFrames(), QTextDocument::rootFrame() -
456*/ -
457QTextFrame *QTextFrame::parentFrame() const -
458{ -
459 Q_D(const QTextFrame);
executed (the execution status of this line is deduced): const QTextFramePrivate * const d = d_func();
-
460 return d->parentFrame;
executed: return d->parentFrame;
Execution Count:9476
9476
461} -
462 -
463 -
464/*! -
465 Returns the first cursor position inside the frame. -
466 -
467 \sa lastCursorPosition(), firstPosition(), lastPosition() -
468*/ -
469QTextCursor QTextFrame::firstCursorPosition() const -
470{ -
471 Q_D(const QTextFrame);
executed (the execution status of this line is deduced): const QTextFramePrivate * const d = d_func();
-
472 return QTextCursor(d->pieceTable, firstPosition());
executed: return QTextCursor(d->pieceTable, firstPosition());
Execution Count:1
1
473} -
474 -
475/*! -
476 Returns the last cursor position inside the frame. -
477 -
478 \sa firstCursorPosition(), firstPosition(), lastPosition() -
479*/ -
480QTextCursor QTextFrame::lastCursorPosition() const -
481{ -
482 Q_D(const QTextFrame);
executed (the execution status of this line is deduced): const QTextFramePrivate * const d = d_func();
-
483 return QTextCursor(d->pieceTable, lastPosition());
executed: return QTextCursor(d->pieceTable, lastPosition());
Execution Count:66
66
484} -
485 -
486/*! -
487 Returns the first document position inside the frame. -
488 -
489 \sa lastPosition(), firstCursorPosition(), lastCursorPosition() -
490*/ -
491int QTextFrame::firstPosition() const -
492{ -
493 Q_D(const QTextFrame);
executed (the execution status of this line is deduced): const QTextFramePrivate * const d = d_func();
-
494 if (!d->fragment_start)
evaluated: !d->fragment_start
TRUEFALSE
yes
Evaluation Count:7364
yes
Evaluation Count:1200
1200-7364
495 return 0;
executed: return 0;
Execution Count:7364
7364
496 return d->pieceTable->fragmentMap().position(d->fragment_start) + 1;
executed: return d->pieceTable->fragmentMap().position(d->fragment_start) + 1;
Execution Count:1200
1200
497} -
498 -
499/*! -
500 Returns the last document position inside the frame. -
501 -
502 \sa firstPosition(), firstCursorPosition(), lastCursorPosition() -
503*/ -
504int QTextFrame::lastPosition() const -
505{ -
506 Q_D(const QTextFrame);
executed (the execution status of this line is deduced): const QTextFramePrivate * const d = d_func();
-
507 if (!d->fragment_end)
evaluated: !d->fragment_end
TRUEFALSE
yes
Evaluation Count:7054
yes
Evaluation Count:1385
1385-7054
508 return d->pieceTable->length() - 1;
executed: return d->pieceTable->length() - 1;
Execution Count:7054
7054
509 return d->pieceTable->fragmentMap().position(d->fragment_end);
executed: return d->pieceTable->fragmentMap().position(d->fragment_end);
Execution Count:1385
1385
510} -
511 -
512/*! -
513 \internal -
514*/ -
515QTextFrameLayoutData *QTextFrame::layoutData() const -
516{ -
517 Q_D(const QTextFrame);
executed (the execution status of this line is deduced): const QTextFramePrivate * const d = d_func();
-
518 return d->layoutData;
executed: return d->layoutData;
Execution Count:77273
77273
519} -
520 -
521/*! -
522 \internal -
523*/ -
524void QTextFrame::setLayoutData(QTextFrameLayoutData *data) -
525{ -
526 Q_D(QTextFrame);
executed (the execution status of this line is deduced): QTextFramePrivate * const d = d_func();
-
527 delete d->layoutData;
executed (the execution status of this line is deduced): delete d->layoutData;
-
528 d->layoutData = data;
executed (the execution status of this line is deduced): d->layoutData = data;
-
529}
executed: }
Execution Count:830
830
530 -
531 -
532 -
533void QTextFramePrivate::fragmentAdded(QChar type, uint fragment) -
534{ -
535 if (type == QTextBeginningOfFrame) {
evaluated: type == QChar(0xfdd0)
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:140
17-140
536 Q_ASSERT(!fragment_start);
executed (the execution status of this line is deduced): qt_noop();
-
537 fragment_start = fragment;
executed (the execution status of this line is deduced): fragment_start = fragment;
-
538 } else if (type == QTextEndOfFrame) {
executed: }
Execution Count:17
evaluated: type == QChar(0xfdd1)
TRUEFALSE
yes
Evaluation Count:107
yes
Evaluation Count:33
17-107
539 Q_ASSERT(!fragment_end);
executed (the execution status of this line is deduced): qt_noop();
-
540 fragment_end = fragment;
executed (the execution status of this line is deduced): fragment_end = fragment;
-
541 } else if (type == QChar::ObjectReplacementCharacter) {
executed: }
Execution Count:107
partially evaluated: type == QChar::ObjectReplacementCharacter
TRUEFALSE
yes
Evaluation Count:33
no
Evaluation Count:0
0-107
542 Q_ASSERT(!fragment_start);
executed (the execution status of this line is deduced): qt_noop();
-
543 Q_ASSERT(!fragment_end);
executed (the execution status of this line is deduced): qt_noop();
-
544 fragment_start = fragment;
executed (the execution status of this line is deduced): fragment_start = fragment;
-
545 fragment_end = fragment;
executed (the execution status of this line is deduced): fragment_end = fragment;
-
546 } else {
executed: }
Execution Count:33
33
547 Q_ASSERT(false);
never executed (the execution status of this line is deduced): qt_noop();
-
548 }
never executed: }
0
549} -
550 -
551void QTextFramePrivate::fragmentRemoved(QChar type, uint fragment) -
552{ -
553 Q_UNUSED(fragment); // --release warning
executed (the execution status of this line is deduced): (void)fragment;;
-
554 if (type == QTextBeginningOfFrame) {
evaluated: type == QChar(0xfdd0)
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:7
6-7
555 Q_ASSERT(fragment_start == fragment);
executed (the execution status of this line is deduced): qt_noop();
-
556 fragment_start = 0;
executed (the execution status of this line is deduced): fragment_start = 0;
-
557 } else if (type == QTextEndOfFrame) {
executed: }
Execution Count:6
partially evaluated: type == QChar(0xfdd1)
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
558 Q_ASSERT(fragment_end == fragment);
executed (the execution status of this line is deduced): qt_noop();
-
559 fragment_end = 0;
executed (the execution status of this line is deduced): fragment_end = 0;
-
560 } else if (type == QChar::ObjectReplacementCharacter) {
executed: }
Execution Count:7
never evaluated: type == QChar::ObjectReplacementCharacter
0-7
561 Q_ASSERT(fragment_start == fragment);
never executed (the execution status of this line is deduced): qt_noop();
-
562 Q_ASSERT(fragment_end == fragment);
never executed (the execution status of this line is deduced): qt_noop();
-
563 fragment_start = 0;
never executed (the execution status of this line is deduced): fragment_start = 0;
-
564 fragment_end = 0;
never executed (the execution status of this line is deduced): fragment_end = 0;
-
565 } else {
never executed: }
0
566 Q_ASSERT(false);
never executed (the execution status of this line is deduced): qt_noop();
-
567 }
never executed: }
0
568 remove_me();
executed (the execution status of this line is deduced): remove_me();
-
569}
executed: }
Execution Count:13
13
570 -
571 -
572void QTextFramePrivate::remove_me() -
573{ -
574 Q_Q(QTextFrame);
executed (the execution status of this line is deduced): QTextFrame * const q = q_func();
-
575 if (fragment_start == 0 && fragment_end == 0
evaluated: fragment_start == 0
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:4
evaluated: fragment_end == 0
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:3
3-9
576 && !parentFrame) {
partially evaluated: !parentFrame
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
577 q->document()->docHandle()->deleteObject(q);
executed (the execution status of this line is deduced): q->document()->docHandle()->deleteObject(q);
-
578 return;
executed: return;
Execution Count:6
6
579 } -
580 -
581 if (!parentFrame)
partially evaluated: !parentFrame
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
582 return;
never executed: return;
0
583 -
584 int index = parentFrame->d_func()->childFrames.indexOf(q);
executed (the execution status of this line is deduced): int index = parentFrame->d_func()->childFrames.indexOf(q);
-
585 -
586 // iterator over all children and move them to the parent -
587 for (int i = 0; i < childFrames.size(); ++i) {
partially evaluated: i < childFrames.size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
588 QTextFrame *c = childFrames.at(i);
never executed (the execution status of this line is deduced): QTextFrame *c = childFrames.at(i);
-
589 parentFrame->d_func()->childFrames.insert(index, c);
never executed (the execution status of this line is deduced): parentFrame->d_func()->childFrames.insert(index, c);
-
590 c->d_func()->parentFrame = parentFrame;
never executed (the execution status of this line is deduced): c->d_func()->parentFrame = parentFrame;
-
591 ++index;
never executed (the execution status of this line is deduced): ++index;
-
592 }
never executed: }
0
593 Q_ASSERT(parentFrame->d_func()->childFrames.at(index) == q);
executed (the execution status of this line is deduced): qt_noop();
-
594 parentFrame->d_func()->childFrames.removeAt(index);
executed (the execution status of this line is deduced): parentFrame->d_func()->childFrames.removeAt(index);
-
595 -
596 childFrames.clear();
executed (the execution status of this line is deduced): childFrames.clear();
-
597 parentFrame = 0;
executed (the execution status of this line is deduced): parentFrame = 0;
-
598}
executed: }
Execution Count:7
7
599 -
600/*! -
601 \class QTextFrame::iterator -
602 \reentrant -
603 -
604 \brief The iterator class provides an iterator for reading -
605 the contents of a QTextFrame. -
606 -
607 \inmodule QtGui -
608 \ingroup richtext-processing -
609 -
610 A frame consists of an arbitrary sequence of \l{QTextBlock}s and -
611 child \l{QTextFrame}s. This class provides a way to iterate over the -
612 child objects of a frame, and read their contents. It does not provide -
613 a way to modify the contents of the frame. -
614 -
615*/ -
616 -
617/*! -
618 \fn bool QTextFrame::iterator::atEnd() const -
619 -
620 Returns true if the current item is the last item in the text frame. -
621*/ -
622 -
623/*! -
624 Returns an iterator pointing to the first document element inside the frame. -
625 Please see the document \l{STL-style-Iterators} for more information. -
626 -
627 \sa end() -
628*/ -
629QTextFrame::iterator QTextFrame::begin() const -
630{ -
631 const QTextDocumentPrivate *priv = docHandle();
executed (the execution status of this line is deduced): const QTextDocumentPrivate *priv = docHandle();
-
632 int b = priv->blockMap().findNode(firstPosition());
executed (the execution status of this line is deduced): int b = priv->blockMap().findNode(firstPosition());
-
633 int e = priv->blockMap().findNode(lastPosition()+1);
executed (the execution status of this line is deduced): int e = priv->blockMap().findNode(lastPosition()+1);
-
634 return iterator(const_cast<QTextFrame *>(this), b, b, e);
executed: return iterator(const_cast<QTextFrame *>(this), b, b, e);
Execution Count:2353
2353
635} -
636 -
637/*! -
638 Returns an iterator pointing to the position past the last document element inside the frame. -
639 Please see the document \l{STL-Style Iterators} for more information. -
640 \sa begin() -
641*/ -
642QTextFrame::iterator QTextFrame::end() const -
643{ -
644 const QTextDocumentPrivate *priv = docHandle();
executed (the execution status of this line is deduced): const QTextDocumentPrivate *priv = docHandle();
-
645 int b = priv->blockMap().findNode(firstPosition());
executed (the execution status of this line is deduced): int b = priv->blockMap().findNode(firstPosition());
-
646 int e = priv->blockMap().findNode(lastPosition()+1);
executed (the execution status of this line is deduced): int e = priv->blockMap().findNode(lastPosition()+1);
-
647 return iterator(const_cast<QTextFrame *>(this), e, b, e);
executed: return iterator(const_cast<QTextFrame *>(this), e, b, e);
Execution Count:13
13
648} -
649 -
650/*! -
651 Constructs an invalid iterator. -
652*/ -
653QTextFrame::iterator::iterator() -
654{ -
655 f = 0;
executed (the execution status of this line is deduced): f = 0;
-
656 b = 0;
executed (the execution status of this line is deduced): b = 0;
-
657 e = 0;
executed (the execution status of this line is deduced): e = 0;
-
658 cf = 0;
executed (the execution status of this line is deduced): cf = 0;
-
659 cb = 0;
executed (the execution status of this line is deduced): cb = 0;
-
660}
executed: }
Execution Count:6412
6412
661 -
662/*! -
663 \internal -
664*/ -
665QTextFrame::iterator::iterator(QTextFrame *frame, int block, int begin, int end) -
666{ -
667 f = frame;
executed (the execution status of this line is deduced): f = frame;
-
668 b = begin;
executed (the execution status of this line is deduced): b = begin;
-
669 e = end;
executed (the execution status of this line is deduced): e = end;
-
670 cf = 0;
executed (the execution status of this line is deduced): cf = 0;
-
671 cb = block;
executed (the execution status of this line is deduced): cb = block;
-
672}
executed: }
Execution Count:4330
4330
673 -
674/*! -
675 Copy constructor. Constructs a copy of the \a other iterator. -
676*/ -
677QTextFrame::iterator::iterator(const iterator &other) -
678{ -
679 f = other.f;
executed (the execution status of this line is deduced): f = other.f;
-
680 b = other.b;
executed (the execution status of this line is deduced): b = other.b;
-
681 e = other.e;
executed (the execution status of this line is deduced): e = other.e;
-
682 cf = other.cf;
executed (the execution status of this line is deduced): cf = other.cf;
-
683 cb = other.cb;
executed (the execution status of this line is deduced): cb = other.cb;
-
684}
executed: }
Execution Count:2524
2524
685 -
686/*! -
687 Assigns \a other to this iterator and returns a reference to -
688 this iterator. -
689*/ -
690QTextFrame::iterator &QTextFrame::iterator::operator=(const iterator &other) -
691{ -
692 f = other.f;
executed (the execution status of this line is deduced): f = other.f;
-
693 b = other.b;
executed (the execution status of this line is deduced): b = other.b;
-
694 e = other.e;
executed (the execution status of this line is deduced): e = other.e;
-
695 cf = other.cf;
executed (the execution status of this line is deduced): cf = other.cf;
-
696 cb = other.cb;
executed (the execution status of this line is deduced): cb = other.cb;
-
697 return *this;
executed: return *this;
Execution Count:5217
5217
698} -
699 -
700/*! -
701 Returns the current frame pointed to by the iterator, or 0 if the -
702 iterator currently points to a block. -
703 -
704 \sa currentBlock() -
705*/ -
706QTextFrame *QTextFrame::iterator::currentFrame() const -
707{ -
708 return cf;
executed: return cf;
Execution Count:17138
17138
709} -
710 -
711/*! -
712 Returns the current block the iterator points to. If the iterator -
713 points to a child frame, the returned block is invalid. -
714 -
715 \sa currentFrame() -
716*/ -
717QTextBlock QTextFrame::iterator::currentBlock() const -
718{ -
719 if (!f)
evaluated: !f
TRUEFALSE
yes
Evaluation Count:5563
yes
Evaluation Count:10549
5563-10549
720 return QTextBlock();
executed: return QTextBlock();
Execution Count:5563
5563
721 return QTextBlock(f->docHandle(), cb);
executed: return QTextBlock(f->docHandle(), cb);
Execution Count:10549
10549
722} -
723 -
724/*! -
725 Moves the iterator to the next frame or block. -
726 -
727 \sa currentBlock(), currentFrame() -
728*/ -
729QTextFrame::iterator &QTextFrame::iterator::operator++() -
730{ -
731 const QTextDocumentPrivate *priv = f->docHandle();
executed (the execution status of this line is deduced): const QTextDocumentPrivate *priv = f->docHandle();
-
732 const QTextDocumentPrivate::BlockMap &map = priv->blockMap();
executed (the execution status of this line is deduced): const QTextDocumentPrivate::BlockMap &map = priv->blockMap();
-
733 if (cf) {
evaluated: cf
TRUEFALSE
yes
Evaluation Count:60
yes
Evaluation Count:4411
60-4411
734 int end = cf->lastPosition() + 1;
executed (the execution status of this line is deduced): int end = cf->lastPosition() + 1;
-
735 cb = map.findNode(end);
executed (the execution status of this line is deduced): cb = map.findNode(end);
-
736 cf = 0;
executed (the execution status of this line is deduced): cf = 0;
-
737 } else if (cb) {
executed: }
Execution Count:60
partially evaluated: cb
TRUEFALSE
yes
Evaluation Count:4411
no
Evaluation Count:0
0-4411
738 cb = map.next(cb);
executed (the execution status of this line is deduced): cb = map.next(cb);
-
739 if (cb == e)
evaluated: cb == e
TRUEFALSE
yes
Evaluation Count:3329
yes
Evaluation Count:1082
1082-3329
740 return *this;
executed: return *this;
Execution Count:3329
3329
741 -
742 if (!f->d_func()->childFrames.isEmpty()) {
evaluated: !f->d_func()->childFrames.isEmpty()
TRUEFALSE
yes
Evaluation Count:95
yes
Evaluation Count:987
95-987
743 int pos = map.position(cb);
executed (the execution status of this line is deduced): int pos = map.position(cb);
-
744 // check if we entered a frame -
745 QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);
executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);
-
746 if (priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator) {
evaluated: priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator
TRUEFALSE
yes
Evaluation Count:91
yes
Evaluation Count:4
4-91
747 QTextFrame *nf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));
executed (the execution status of this line is deduced): QTextFrame *nf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));
-
748 if (nf) {
partially evaluated: nf
TRUEFALSE
yes
Evaluation Count:91
no
Evaluation Count:0
0-91
749 if (priv->buffer().at(frag->stringPosition) == QTextBeginningOfFrame && nf != f) {
partially evaluated: priv->buffer().at(frag->stringPosition) == QChar(0xfdd0)
TRUEFALSE
yes
Evaluation Count:91
no
Evaluation Count:0
evaluated: nf != f
TRUEFALSE
yes
Evaluation Count:81
yes
Evaluation Count:10
0-91
750 cf = nf;
executed (the execution status of this line is deduced): cf = nf;
-
751 cb = 0;
executed (the execution status of this line is deduced): cb = 0;
-
752 } else {
executed: }
Execution Count:81
81
753 Q_ASSERT(priv->buffer().at(frag->stringPosition) != QTextEndOfFrame);
executed (the execution status of this line is deduced): qt_noop();
-
754 }
executed: }
Execution Count:10
10
755 } -
756 }
executed: }
Execution Count:91
91
757 }
executed: }
Execution Count:95
95
758 }
executed: }
Execution Count:1082
1082
759 return *this;
executed: return *this;
Execution Count:1142
1142
760} -
761 -
762/*! -
763 Moves the iterator to the previous frame or block. -
764 -
765 \sa currentBlock(), currentFrame() -
766*/ -
767QTextFrame::iterator &QTextFrame::iterator::operator--() -
768{ -
769 const QTextDocumentPrivate *priv = f->docHandle();
executed (the execution status of this line is deduced): const QTextDocumentPrivate *priv = f->docHandle();
-
770 const QTextDocumentPrivate::BlockMap &map = priv->blockMap();
executed (the execution status of this line is deduced): const QTextDocumentPrivate::BlockMap &map = priv->blockMap();
-
771 if (cf) {
partially evaluated: cf
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
772 int start = cf->firstPosition() - 1;
never executed (the execution status of this line is deduced): int start = cf->firstPosition() - 1;
-
773 cb = map.findNode(start);
never executed (the execution status of this line is deduced): cb = map.findNode(start);
-
774 cf = 0;
never executed (the execution status of this line is deduced): cf = 0;
-
775 } else {
never executed: }
0
776 if (cb == b)
partially evaluated: cb == b
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
777 goto end;
executed: goto end;
Execution Count:2
2
778 if (cb != e) {
never evaluated: cb != e
0
779 int pos = map.position(cb);
never executed (the execution status of this line is deduced): int pos = map.position(cb);
-
780 // check if we have to enter a frame -
781 QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);
never executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);
-
782 if (priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator) {
never evaluated: priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator
0
783 QTextFrame *pf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));
never executed (the execution status of this line is deduced): QTextFrame *pf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));
-
784 if (pf) {
never evaluated: pf
0
785 if (priv->buffer().at(frag->stringPosition) == QTextBeginningOfFrame) {
never evaluated: priv->buffer().at(frag->stringPosition) == QChar(0xfdd0)
0
786 Q_ASSERT(pf == f);
never executed (the execution status of this line is deduced): qt_noop();
-
787 } else if (priv->buffer().at(frag->stringPosition) == QTextEndOfFrame) {
never executed: }
never evaluated: priv->buffer().at(frag->stringPosition) == QChar(0xfdd1)
0
788 Q_ASSERT(pf != f);
never executed (the execution status of this line is deduced): qt_noop();
-
789 cf = pf;
never executed (the execution status of this line is deduced): cf = pf;
-
790 cb = 0;
never executed (the execution status of this line is deduced): cb = 0;
-
791 goto end;
never executed: goto end;
0
792 } -
793 } -
794 }
never executed: }
0
795 }
never executed: }
0
796 cb = map.previous(cb);
never executed (the execution status of this line is deduced): cb = map.previous(cb);
-
797 }
never executed: }
0
798 end: -
799 return *this;
executed: return *this;
Execution Count:2
2
800} -
801 -
802/*! -
803 \class QTextBlockUserData -
804 \reentrant -
805 -
806 \brief The QTextBlockUserData class is used to associate custom data with blocks of text. -
807 \inmodule QtGui -
808 \since 4.1 -
809 -
810 \ingroup richtext-processing -
811 -
812 QTextBlockUserData provides an abstract interface for container classes that are used -
813 to associate application-specific user data with text blocks in a QTextDocument. -
814 -
815 Generally, subclasses of this class provide functions to allow data to be stored -
816 and retrieved, and instances are attached to blocks of text using -
817 QTextBlock::setUserData(). This makes it possible to store additional data per text -
818 block in a way that can be retrieved safely by the application. -
819 -
820 Each subclass should provide a reimplementation of the destructor to ensure that any -
821 private data is automatically cleaned up when user data objects are deleted. -
822 -
823 \sa QTextBlock -
824*/ -
825 -
826/*! -
827 Destroys the user data. -
828*/ -
829QTextBlockUserData::~QTextBlockUserData() -
830{ -
831} -
832 -
833/*! -
834 \class QTextBlock -
835 \reentrant -
836 -
837 \brief The QTextBlock class provides a container for text fragments in a -
838 QTextDocument. -
839 \inmodule QtGui -
840 -
841 \ingroup richtext-processing -
842 -
843 A text block encapsulates a block or paragraph of text in a QTextDocument. -
844 QTextBlock provides read-only access to the block/paragraph structure of -
845 QTextDocuments. It is mainly of use if you want to implement your own -
846 layouts for the visual representation of a QTextDocument, or if you want to -
847 iterate over a document and write out the contents in your own custom -
848 format. -
849 -
850 Text blocks are created by their parent documents. If you need to create -
851 a new text block, or modify the contents of a document while examining its -
852 contents, use the cursor-based interface provided by QTextCursor instead. -
853 -
854 Each text block is located at a specific position() in a document(). -
855 The contents of the block can be obtained by using the text() function. -
856 The length() function determines the block's size within the document -
857 (including formatting characters). -
858 The visual properties of the block are determined by its text layout(), -
859 its charFormat(), and its blockFormat(). -
860 -
861 The next() and previous() functions enable iteration over consecutive -
862 valid blocks in a document under the condition that the document is not -
863 modified by other means during the iteration process. Note that, although -
864 blocks are returned in sequence, adjacent blocks may come from different -
865 places in the document structure. The validity of a block can be determined -
866 by calling isValid(). -
867 -
868 QTextBlock provides comparison operators to make it easier to work with -
869 blocks: \l operator==() compares two block for equality, \l operator!=() -
870 compares two blocks for inequality, and \l operator<() determines whether -
871 a block precedes another in the same document. -
872 -
873 \image qtextblock-sequence.png -
874 -
875 \sa QTextBlockFormat, QTextCharFormat, QTextFragment -
876 */ -
877 -
878/*! -
879 \fn QTextBlock::QTextBlock(QTextDocumentPrivate *priv, int b) -
880 -
881 \internal -
882*/ -
883 -
884/*! -
885 \fn QTextBlock::QTextBlock() -
886 -
887 \internal -
888*/ -
889 -
890/*! -
891 \fn QTextBlock::QTextBlock(const QTextBlock &other) -
892 -
893 Copies the \a other text block's attributes to this text block. -
894*/ -
895 -
896/*! -
897 \fn bool QTextBlock::isValid() const -
898 -
899 Returns true if this text block is valid; otherwise returns false. -
900*/ -
901 -
902bool QTextBlock::isValid() const -
903{ -
904 return p != 0 && p->blockMap().isValid(n);
executed: return p != 0 && p->blockMap().isValid(n);
Execution Count:73059
73059
905} -
906 -
907/*! -
908 \fn QTextBlock &QTextBlock::operator=(const QTextBlock &other) -
909 -
910 Assigns the \a other text block to this text block. -
911*/ -
912 -
913/*! -
914 \fn bool QTextBlock::operator==(const QTextBlock &other) const -
915 -
916 Returns true if this text block is the same as the \a other text -
917 block. -
918*/ -
919 -
920/*! -
921 \fn bool QTextBlock::operator!=(const QTextBlock &other) const -
922 -
923 Returns true if this text block is different from the \a other -
924 text block. -
925*/ -
926 -
927/*! -
928 \fn bool QTextBlock::operator<(const QTextBlock &other) const -
929 -
930 Returns true if this text block occurs before the \a other text -
931 block in the document. -
932*/ -
933 -
934/*! -
935 \class QTextBlock::iterator -
936 \reentrant -
937 -
938 \brief The QTextBlock::iterator class provides an iterator for reading -
939 the contents of a QTextBlock. -
940 \inmodule QtGui -
941 -
942 \ingroup richtext-processing -
943 -
944 A block consists of a sequence of text fragments. This class provides -
945 a way to iterate over these, and read their contents. It does not provide -
946 a way to modify the internal structure or contents of the block. -
947 -
948 An iterator can be constructed and used to access the fragments within -
949 a text block in the following way: -
950 -
951 \snippet textblock-fragments/xmlwriter.cpp 4 -
952 \snippet textblock-fragments/xmlwriter.cpp 7 -
953 -
954 \sa QTextFragment -
955*/ -
956 -
957/*! -
958 \typedef QTextBlock::Iterator -
959 -
960 Qt-style synonym for QTextBlock::iterator. -
961*/ -
962 -
963/*! -
964 \fn QTextBlock::iterator::iterator() -
965 -
966 Constructs an iterator for this text block. -
967*/ -
968 -
969/*! -
970 \fn QTextBlock::iterator::iterator(const iterator &other) -
971 -
972 Copy constructor. Constructs a copy of the \a other iterator. -
973*/ -
974 -
975/*! -
976 \fn bool QTextBlock::iterator::atEnd() const -
977 -
978 Returns true if the current item is the last item in the text block. -
979*/ -
980 -
981/*! -
982 \fn bool QTextBlock::iterator::operator==(const iterator &other) const -
983 -
984 Retuns true if this iterator is the same as the \a other iterator; -
985 otherwise returns false. -
986*/ -
987 -
988/*! -
989 \fn bool QTextBlock::iterator::operator!=(const iterator &other) const -
990 -
991 Retuns true if this iterator is different from the \a other iterator; -
992 otherwise returns false. -
993*/ -
994 -
995/*! -
996 \fn QTextBlock::iterator QTextBlock::iterator::operator++(int) -
997 -
998 The postfix ++ operator (\c{i++}) advances the iterator to the -
999 next item in the text block and returns an iterator to the old current -
1000 item. -
1001*/ -
1002 -
1003/*! -
1004 \fn QTextBlock::iterator QTextBlock::iterator::operator--(int) -
1005 -
1006 The postfix -- operator (\c{i--}) makes the preceding item current and -
1007 returns an iterator to the old current item. -
1008*/ -
1009 -
1010/*! -
1011 \fn QTextDocumentPrivate *QTextBlock::docHandle() const -
1012 -
1013 \internal -
1014*/ -
1015 -
1016/*! -
1017 \fn int QTextBlock::fragmentIndex() const -
1018 -
1019 \internal -
1020*/ -
1021 -
1022/*! -
1023 Returns the index of the block's first character within the document. -
1024 */ -
1025int QTextBlock::position() const -
1026{ -
1027 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25594783
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25594783
0-25594783
1028 return 0;
never executed: return 0;
0
1029 -
1030 return p->blockMap().position(n);
executed: return p->blockMap().position(n);
Execution Count:25594783
25594783
1031} -
1032 -
1033/*! -
1034 Returns the length of the block in characters. -
1035 -
1036 \note The length returned includes all formatting characters, -
1037 for example, newline. -
1038 -
1039 \sa text(), charFormat(), blockFormat() -
1040 */ -
1041int QTextBlock::length() const -
1042{ -
1043 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25345962
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25345962
0-25345962
1044 return 0;
never executed: return 0;
0
1045 -
1046 return p->blockMap().size(n);
executed: return p->blockMap().size(n);
Execution Count:25345962
25345962
1047} -
1048 -
1049/*! -
1050 Returns true if the given \a position is located within the text -
1051 block; otherwise returns false. -
1052 */ -
1053bool QTextBlock::contains(int position) const -
1054{ -
1055 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
1056 return false;
never executed: return false;
0
1057 -
1058 int pos = p->blockMap().position(n);
executed (the execution status of this line is deduced): int pos = p->blockMap().position(n);
-
1059 int len = p->blockMap().size(n);
executed (the execution status of this line is deduced): int len = p->blockMap().size(n);
-
1060 return position >= pos && position < pos + len;
executed: return position >= pos && position < pos + len;
Execution Count:9
9
1061} -
1062 -
1063/*! -
1064 Returns the QTextLayout that is used to lay out and display the -
1065 block's contents. -
1066 -
1067 Note that the returned QTextLayout object can only be modified from the -
1068 documentChanged implementation of a QAbstractTextDocumentLayout subclass. -
1069 Any changes applied from the outside cause undefined behavior. -
1070 -
1071 \sa clearLayout() -
1072 */ -
1073QTextLayout *QTextBlock::layout() const -
1074{ -
1075 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36033
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36033
0-36033
1076 return 0;
never executed: return 0;
0
1077 -
1078 const QTextBlockData *b = p->blockMap().fragment(n);
executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1079 if (!b->layout)
evaluated: !b->layout
TRUEFALSE
yes
Evaluation Count:15452
yes
Evaluation Count:20581
15452-20581
1080 b->layout = new QTextLayout(*this);
executed: b->layout = new QTextLayout(*this);
Execution Count:15452
15452
1081 return b->layout;
executed: return b->layout;
Execution Count:36033
36033
1082} -
1083 -
1084/*! -
1085 \since 4.4 -
1086 Clears the QTextLayout that is used to lay out and display the -
1087 block's contents. -
1088 -
1089 \sa layout() -
1090 */ -
1091void QTextBlock::clearLayout() -
1092{ -
1093 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6174
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6174
0-6174
1094 return;
never executed: return;
0
1095 -
1096 const QTextBlockData *b = p->blockMap().fragment(n);
executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1097 if (b->layout)
evaluated: b->layout
TRUEFALSE
yes
Evaluation Count:2338
yes
Evaluation Count:3836
2338-3836
1098 b->layout->clearLayout();
executed: b->layout->clearLayout();
Execution Count:2338
2338
1099}
executed: }
Execution Count:6174
6174
1100 -
1101/*! -
1102 Returns the QTextBlockFormat that describes block-specific properties. -
1103 -
1104 \sa charFormat() -
1105 */ -
1106QTextBlockFormat QTextBlock::blockFormat() const -
1107{ -
1108 if (!p || !n)
evaluated: !p
TRUEFALSE
yes
Evaluation Count:3117
yes
Evaluation Count:29734
evaluated: !n
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:29725
9-29734
1109 return QTextFormat().toBlockFormat();
executed: return QTextFormat().toBlockFormat();
Execution Count:3126
3126
1110 -
1111 return p->formatCollection()->blockFormat(p->blockMap().fragment(n)->format);
executed: return p->formatCollection()->blockFormat(p->blockMap().fragment(n)->format);
Execution Count:29725
29725
1112} -
1113 -
1114/*! -
1115 Returns an index into the document's internal list of block formats -
1116 for the text block's format. -
1117 -
1118 \sa QTextDocument::allFormats() -
1119*/ -
1120int QTextBlock::blockFormatIndex() const -
1121{ -
1122 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1123 return -1;
never executed: return -1;
0
1124 -
1125 return p->blockMap().fragment(n)->format;
executed: return p->blockMap().fragment(n)->format;
Execution Count:3
3
1126} -
1127 -
1128/*! -
1129 Returns the QTextCharFormat that describes the block's character -
1130 format. The block's character format is used when inserting text into -
1131 an empty block. -
1132 -
1133 \sa blockFormat() -
1134 */ -
1135QTextCharFormat QTextBlock::charFormat() const -
1136{ -
1137 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6929
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6929
0-6929
1138 return QTextFormat().toCharFormat();
never executed: return QTextFormat().toCharFormat();
0
1139 -
1140 return p->formatCollection()->charFormat(charFormatIndex());
executed: return p->formatCollection()->charFormat(charFormatIndex());
Execution Count:6929
6929
1141} -
1142 -
1143/*! -
1144 Returns an index into the document's internal list of character formats -
1145 for the text block's character format. -
1146 -
1147 \sa QTextDocument::allFormats() -
1148*/ -
1149int QTextBlock::charFormatIndex() const -
1150{ -
1151 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6929
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6929
0-6929
1152 return -1;
never executed: return -1;
0
1153 -
1154 return p->blockCharFormatIndex(n);
executed: return p->blockCharFormatIndex(n);
Execution Count:6929
6929
1155} -
1156 -
1157/*! -
1158 \since 4.7 -
1159 -
1160 Returns the resolved text direction. -
1161 -
1162 If the block has no explicit direction set, it will resolve the -
1163 direction from the blocks content. Returns either Qt::LeftToRight -
1164 or Qt::RightToLeft. -
1165 -
1166 \sa QTextFormat::layoutDirection(), QString::isRightToLeft(), Qt::LayoutDirection -
1167*/ -
1168Qt::LayoutDirection QTextBlock::textDirection() const -
1169{ -
1170 Qt::LayoutDirection dir = blockFormat().layoutDirection();
executed (the execution status of this line is deduced): Qt::LayoutDirection dir = blockFormat().layoutDirection();
-
1171 if (dir != Qt::LayoutDirectionAuto)
evaluated: dir != Qt::LayoutDirectionAuto
TRUEFALSE
yes
Evaluation Count:147
yes
Evaluation Count:6552
147-6552
1172 return dir;
executed: return dir;
Execution Count:147
147
1173 -
1174 dir = p->defaultTextOption.textDirection();
executed (the execution status of this line is deduced): dir = p->defaultTextOption.textDirection();
-
1175 if (dir != Qt::LayoutDirectionAuto)
partially evaluated: dir != Qt::LayoutDirectionAuto
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6552
0-6552
1176 return dir;
never executed: return dir;
0
1177 -
1178 const QString buffer = p->buffer();
executed (the execution status of this line is deduced): const QString buffer = p->buffer();
-
1179 -
1180 const int pos = position();
executed (the execution status of this line is deduced): const int pos = position();
-
1181 QTextDocumentPrivate::FragmentIterator it = p->find(pos);
executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it = p->find(pos);
-
1182 QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1); // -1 to omit the block separator char
executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1);
-
1183 for (; it != end; ++it) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:4010
yes
Evaluation Count:3161
3161-4010
1184 const QTextFragmentData * const frag = it.value();
executed (the execution status of this line is deduced): const QTextFragmentData * const frag = it.value();
-
1185 const QChar *p = buffer.constData() + frag->stringPosition;
executed (the execution status of this line is deduced): const QChar *p = buffer.constData() + frag->stringPosition;
-
1186 const QChar * const end = p + frag->size_array[0];
executed (the execution status of this line is deduced): const QChar * const end = p + frag->size_array[0];
-
1187 while (p < end) {
evaluated: p < end
TRUEFALSE
yes
Evaluation Count:7115
yes
Evaluation Count:619
619-7115
1188 uint ucs4 = p->unicode();
executed (the execution status of this line is deduced): uint ucs4 = p->unicode();
-
1189 if (QChar::isHighSurrogate(ucs4) && p + 1 < end) {
partially evaluated: QChar::isHighSurrogate(ucs4)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7115
never evaluated: p + 1 < end
0-7115
1190 ushort low = p[1].unicode();
never executed (the execution status of this line is deduced): ushort low = p[1].unicode();
-
1191 if (QChar::isLowSurrogate(low)) {
never evaluated: QChar::isLowSurrogate(low)
0
1192 ucs4 = QChar::surrogateToUcs4(ucs4, low);
never executed (the execution status of this line is deduced): ucs4 = QChar::surrogateToUcs4(ucs4, low);
-
1193 ++p;
never executed (the execution status of this line is deduced): ++p;
-
1194 }
never executed: }
0
1195 }
never executed: }
0
1196 switch (QChar::direction(ucs4)) { -
1197 case QChar::DirL: -
1198 return Qt::LeftToRight;
executed: return Qt::LeftToRight;
Execution Count:3390
3390
1199 case QChar::DirR: -
1200 case QChar::DirAL: -
1201 return Qt::RightToLeft;
executed: return Qt::RightToLeft;
Execution Count:1
1
1202 default: -
1203 break;
executed: break;
Execution Count:3724
3724
1204 } -
1205 ++p;
executed (the execution status of this line is deduced): ++p;
-
1206 }
executed: }
Execution Count:3724
3724
1207 }
executed: }
Execution Count:619
619
1208 return Qt::LeftToRight;
executed: return Qt::LeftToRight;
Execution Count:3161
3161
1209} -
1210 -
1211/*! -
1212 Returns the block's contents as plain text. -
1213 -
1214 \sa length(), charFormat(), blockFormat() -
1215 */ -
1216QString QTextBlock::text() const -
1217{ -
1218 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21074
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21074
0-21074
1219 return QString();
never executed: return QString();
0
1220 -
1221 const QString buffer = p->buffer();
executed (the execution status of this line is deduced): const QString buffer = p->buffer();
-
1222 QString text;
executed (the execution status of this line is deduced): QString text;
-
1223 text.reserve(length());
executed (the execution status of this line is deduced): text.reserve(length());
-
1224 -
1225 const int pos = position();
executed (the execution status of this line is deduced): const int pos = position();
-
1226 QTextDocumentPrivate::FragmentIterator it = p->find(pos);
executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it = p->find(pos);
-
1227 QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1); // -1 to omit the block separator char
executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1);
-
1228 for (; it != end; ++it) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:6170
yes
Evaluation Count:21074
6170-21074
1229 const QTextFragmentData * const frag = it.value();
executed (the execution status of this line is deduced): const QTextFragmentData * const frag = it.value();
-
1230 text += QString::fromRawData(buffer.constData() + frag->stringPosition, frag->size_array[0]);
executed (the execution status of this line is deduced): text += QString::fromRawData(buffer.constData() + frag->stringPosition, frag->size_array[0]);
-
1231 }
executed: }
Execution Count:6170
6170
1232 -
1233 return text;
executed: return text;
Execution Count:21074
21074
1234} -
1235 -
1236 -
1237/*! -
1238 Returns the text document this text block belongs to, or 0 if the -
1239 text block does not belong to any document. -
1240*/ -
1241const QTextDocument *QTextBlock::document() const -
1242{ -
1243 return p ? p->document() : 0;
executed: return p ? p->document() : 0;
Execution Count:3
3
1244} -
1245 -
1246/*! -
1247 If the block represents a list item, returns the list that the item belongs -
1248 to; otherwise returns 0. -
1249*/ -
1250QTextList *QTextBlock::textList() const -
1251{ -
1252 if (!isValid())
partially evaluated: !isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:996
0-996
1253 return 0;
never executed: return 0;
0
1254 -
1255 const QTextBlockFormat fmt = blockFormat();
executed (the execution status of this line is deduced): const QTextBlockFormat fmt = blockFormat();
-
1256 QTextObject *obj = p->document()->objectForFormat(fmt);
executed (the execution status of this line is deduced): QTextObject *obj = p->document()->objectForFormat(fmt);
-
1257 return qobject_cast<QTextList *>(obj);
executed: return qobject_cast<QTextList *>(obj);
Execution Count:996
996
1258} -
1259 -
1260/*! -
1261 \since 4.1 -
1262 -
1263 Returns a pointer to a QTextBlockUserData object if previously set with -
1264 setUserData() or a null pointer. -
1265*/ -
1266QTextBlockUserData *QTextBlock::userData() const -
1267{ -
1268 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
1269 return 0;
never executed: return 0;
0
1270 -
1271 const QTextBlockData *b = p->blockMap().fragment(n);
executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1272 return b->userData;
executed: return b->userData;
Execution Count:5
5
1273} -
1274 -
1275/*! -
1276 \since 4.1 -
1277 -
1278 Attaches the given \a data object to the text block. -
1279 -
1280 QTextBlockUserData can be used to store custom settings. The -
1281 ownership is passed to the underlying text document, i.e. the -
1282 provided QTextBlockUserData object will be deleted if the -
1283 corresponding text block gets deleted. The user data object is -
1284 not stored in the undo history, so it will not be available after -
1285 undoing the deletion of a text block. -
1286 -
1287 For example, if you write a programming editor in an IDE, you may -
1288 want to let your user set breakpoints visually in your code for an -
1289 integrated debugger. In a programming editor a line of text -
1290 usually corresponds to one QTextBlock. The QTextBlockUserData -
1291 interface allows the developer to store data for each QTextBlock, -
1292 like for example in which lines of the source code the user has a -
1293 breakpoint set. Of course this could also be stored externally, -
1294 but by storing it inside the QTextDocument, it will for example be -
1295 automatically deleted when the user deletes the associated -
1296 line. It's really just a way to store custom information in the -
1297 QTextDocument without using custom properties in QTextFormat which -
1298 would affect the undo/redo stack. -
1299*/ -
1300void QTextBlock::setUserData(QTextBlockUserData *data) -
1301{ -
1302 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1303 return;
never executed: return;
0
1304 -
1305 const QTextBlockData *b = p->blockMap().fragment(n);
executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1306 if (data != b->userData)
partially evaluated: data != b->userData
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
1307 delete b->userData;
executed: delete b->userData;
Execution Count:3
3
1308 b->userData = data;
executed (the execution status of this line is deduced): b->userData = data;
-
1309}
executed: }
Execution Count:3
3
1310 -
1311/*! -
1312 \since 4.1 -
1313 -
1314 Returns the integer value previously set with setUserState() or -1. -
1315*/ -
1316int QTextBlock::userState() const -
1317{ -
1318 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1070
evaluated: !n
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1068
0-1070
1319 return -1;
executed: return -1;
Execution Count:2
2
1320 -
1321 const QTextBlockData *b = p->blockMap().fragment(n);
executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1322 return b->userState;
executed: return b->userState;
Execution Count:1068
1068
1323} -
1324 -
1325/*! -
1326 \since 4.1 -
1327 -
1328 Stores the specified \a state integer value in the text block. This may be -
1329 useful for example in a syntax highlighter to store a text parsing state. -
1330*/ -
1331void QTextBlock::setUserState(int state) -
1332{ -
1333 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22
0-22
1334 return;
never executed: return;
0
1335 -
1336 const QTextBlockData *b = p->blockMap().fragment(n);
executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1337 b->userState = state;
executed (the execution status of this line is deduced): b->userState = state;
-
1338}
executed: }
Execution Count:22
22
1339 -
1340/*! -
1341 \since 4.4 -
1342 -
1343 Returns the blocks revision. -
1344 -
1345 \sa setRevision(), QTextDocument::revision() -
1346*/ -
1347int QTextBlock::revision() const -
1348{ -
1349 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:14
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:14
0-14
1350 return -1;
never executed: return -1;
0
1351 -
1352 const QTextBlockData *b = p->blockMap().fragment(n);
executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1353 return b->revision;
executed: return b->revision;
Execution Count:14
14
1354} -
1355 -
1356/*! -
1357 \since 4.4 -
1358 -
1359 Sets a blocks revision to \a rev. -
1360 -
1361 \sa revision(), QTextDocument::revision() -
1362*/ -
1363void QTextBlock::setRevision(int rev) -
1364{ -
1365 if (!p || !n)
never evaluated: !p
never evaluated: !n
0
1366 return;
never executed: return;
0
1367 -
1368 const QTextBlockData *b = p->blockMap().fragment(n);
never executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1369 b->revision = rev;
never executed (the execution status of this line is deduced): b->revision = rev;
-
1370}
never executed: }
0
1371 -
1372/*! -
1373 \since 4.4 -
1374 -
1375 Returns true if the block is visible; otherwise returns false. -
1376 -
1377 \sa setVisible() -
1378*/ -
1379bool QTextBlock::isVisible() const -
1380{ -
1381 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5405
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5405
0-5405
1382 return true;
never executed: return true;
0
1383 -
1384 const QTextBlockData *b = p->blockMap().fragment(n);
executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1385 return !b->hidden;
executed: return !b->hidden;
Execution Count:5405
5405
1386} -
1387 -
1388/*! -
1389 \since 4.4 -
1390 -
1391 Sets the block's visibility to \a visible. -
1392 -
1393 \sa isVisible() -
1394*/ -
1395void QTextBlock::setVisible(bool visible) -
1396{ -
1397 if (!p || !n)
never evaluated: !p
never evaluated: !n
0
1398 return;
never executed: return;
0
1399 -
1400 const QTextBlockData *b = p->blockMap().fragment(n);
never executed (the execution status of this line is deduced): const QTextBlockData *b = p->blockMap().fragment(n);
-
1401 b->hidden = !visible;
never executed (the execution status of this line is deduced): b->hidden = !visible;
-
1402}
never executed: }
0
1403 -
1404 -
1405/*! -
1406\since 4.4 -
1407 -
1408 Returns the number of this block, or -1 if the block is invalid. -
1409 -
1410 \sa QTextCursor::blockNumber() -
1411 -
1412*/ -
1413int QTextBlock::blockNumber() const -
1414{ -
1415 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2397
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2397
0-2397
1416 return -1;
never executed: return -1;
0
1417 return p->blockMap().position(n, 1);
executed: return p->blockMap().position(n, 1);
Execution Count:2397
2397
1418} -
1419 -
1420/*! -
1421\since 4.5 -
1422 -
1423 Returns the first line number of this block, or -1 if the block is invalid. -
1424 Unless the layout supports it, the line number is identical to the block number. -
1425 -
1426 \sa QTextBlock::blockNumber() -
1427 -
1428*/ -
1429int QTextBlock::firstLineNumber() const -
1430{ -
1431 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:733
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:733
0-733
1432 return -1;
never executed: return -1;
0
1433 return p->blockMap().position(n, 2);
executed: return p->blockMap().position(n, 2);
Execution Count:733
733
1434} -
1435 -
1436 -
1437/*! -
1438\since 4.5 -
1439 -
1440Sets the line count to \a count. -
1441 -
1442\sa lineCount() -
1443*/ -
1444void QTextBlock::setLineCount(int count) -
1445{ -
1446 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1621
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1621
0-1621
1447 return;
never executed: return;
0
1448 p->blockMap().setSize(n, count, 2);
executed (the execution status of this line is deduced): p->blockMap().setSize(n, count, 2);
-
1449}
executed: }
Execution Count:1621
1621
1450/*! -
1451\since 4.5 -
1452 -
1453Returns the line count. Not all document layouts support this feature. -
1454 -
1455\sa setLineCount() -
1456 */ -
1457int QTextBlock::lineCount() const -
1458{ -
1459 if (!p || !n)
never evaluated: !p
never evaluated: !n
0
1460 return -1;
never executed: return -1;
0
1461 return p->blockMap().size(n, 2);
never executed: return p->blockMap().size(n, 2);
0
1462} -
1463 -
1464 -
1465/*! -
1466 Returns a text block iterator pointing to the beginning of the -
1467 text block. -
1468 -
1469 \sa end() -
1470*/ -
1471QTextBlock::iterator QTextBlock::begin() const -
1472{ -
1473 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:748
evaluated: !n
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:747
0-748
1474 return iterator();
executed: return iterator();
Execution Count:1
1
1475 -
1476 int pos = position();
executed (the execution status of this line is deduced): int pos = position();
-
1477 int len = length() - 1; // exclude the fragment that holds the paragraph separator
executed (the execution status of this line is deduced): int len = length() - 1;
-
1478 int b = p->fragmentMap().findNode(pos);
executed (the execution status of this line is deduced): int b = p->fragmentMap().findNode(pos);
-
1479 int e = p->fragmentMap().findNode(pos+len);
executed (the execution status of this line is deduced): int e = p->fragmentMap().findNode(pos+len);
-
1480 return iterator(p, b, e, b);
executed: return iterator(p, b, e, b);
Execution Count:747
747
1481} -
1482 -
1483/*! -
1484 Returns a text block iterator pointing to the end of the text -
1485 block. -
1486 -
1487 \sa begin(), next(), previous() -
1488*/ -
1489QTextBlock::iterator QTextBlock::end() const -
1490{ -
1491 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1492 return iterator();
never executed: return iterator();
0
1493 -
1494 int pos = position();
executed (the execution status of this line is deduced): int pos = position();
-
1495 int len = length() - 1; // exclude the fragment that holds the paragraph separator
executed (the execution status of this line is deduced): int len = length() - 1;
-
1496 int b = p->fragmentMap().findNode(pos);
executed (the execution status of this line is deduced): int b = p->fragmentMap().findNode(pos);
-
1497 int e = p->fragmentMap().findNode(pos+len);
executed (the execution status of this line is deduced): int e = p->fragmentMap().findNode(pos+len);
-
1498 return iterator(p, b, e, e);
executed: return iterator(p, b, e, e);
Execution Count:3
3
1499} -
1500 -
1501 -
1502/*! -
1503 Returns the text block in the document after this block, or an empty -
1504 text block if this is the last one. -
1505 -
1506 Note that the next block may be in a different frame or table to this block. -
1507 -
1508 \sa previous(), begin(), end() -
1509*/ -
1510QTextBlock QTextBlock::next() const -
1511{ -
1512 if (!isValid())
evaluated: !isValid()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:26075
4-26075
1513 return QTextBlock();
executed: return QTextBlock();
Execution Count:4
4
1514 -
1515 return QTextBlock(p, p->blockMap().next(n));
executed: return QTextBlock(p, p->blockMap().next(n));
Execution Count:26075
26075
1516} -
1517 -
1518/*! -
1519 Returns the text block in the document before this block, or an empty text -
1520 block if this is the first one. -
1521 -
1522 Note that the next block may be in a different frame or table to this block. -
1523 -
1524 \sa next(), begin(), end() -
1525*/ -
1526QTextBlock QTextBlock::previous() const -
1527{ -
1528 if (!p)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:277
0-277
1529 return QTextBlock();
never executed: return QTextBlock();
0
1530 -
1531 return QTextBlock(p, p->blockMap().previous(n));
executed: return QTextBlock(p, p->blockMap().previous(n));
Execution Count:277
277
1532} -
1533 -
1534 -
1535/*! -
1536 Returns the text fragment the iterator currently points to. -
1537*/ -
1538QTextFragment QTextBlock::iterator::fragment() const -
1539{ -
1540 int ne = n;
executed (the execution status of this line is deduced): int ne = n;
-
1541 int formatIndex = p->fragmentMap().fragment(n)->format;
executed (the execution status of this line is deduced): int formatIndex = p->fragmentMap().fragment(n)->format;
-
1542 do { -
1543 ne = p->fragmentMap().next(ne);
executed (the execution status of this line is deduced): ne = p->fragmentMap().next(ne);
-
1544 } while (ne != e && p->fragmentMap().fragment(ne)->format == formatIndex);
executed: }
Execution Count:242
evaluated: ne != e
TRUEFALSE
yes
Evaluation Count:65
yes
Evaluation Count:177
partially evaluated: p->fragmentMap().fragment(ne)->format == formatIndex
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:65
0-242
1545 return QTextFragment(p, n, ne);
executed: return QTextFragment(p, n, ne);
Execution Count:242
242
1546} -
1547 -
1548/*! -
1549 The prefix ++ operator (\c{++i}) advances the iterator to the -
1550 next item in the hash and returns an iterator to the new current -
1551 item. -
1552*/ -
1553 -
1554QTextBlock::iterator &QTextBlock::iterator::operator++() -
1555{ -
1556 int ne = n;
executed (the execution status of this line is deduced): int ne = n;
-
1557 int formatIndex = p->fragmentMap().fragment(n)->format;
executed (the execution status of this line is deduced): int formatIndex = p->fragmentMap().fragment(n)->format;
-
1558 do { -
1559 ne = p->fragmentMap().next(ne);
executed (the execution status of this line is deduced): ne = p->fragmentMap().next(ne);
-
1560 } while (ne != e && p->fragmentMap().fragment(ne)->format == formatIndex);
executed: }
Execution Count:141
evaluated: ne != e
TRUEFALSE
yes
Evaluation Count:35
yes
Evaluation Count:106
partially evaluated: p->fragmentMap().fragment(ne)->format == formatIndex
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:35
0-141
1561 n = ne;
executed (the execution status of this line is deduced): n = ne;
-
1562 return *this;
executed: return *this;
Execution Count:141
141
1563} -
1564 -
1565/*! -
1566 The prefix -- operator (\c{--i}) makes the preceding item -
1567 current and returns an iterator pointing to the new current item. -
1568*/ -
1569 -
1570QTextBlock::iterator &QTextBlock::iterator::operator--() -
1571{ -
1572 n = p->fragmentMap().previous(n);
executed (the execution status of this line is deduced): n = p->fragmentMap().previous(n);
-
1573 -
1574 if (n == b)
evaluated: n == b
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:3
3
1575 return *this;
executed: return *this;
Execution Count:3
3
1576 -
1577 int formatIndex = p->fragmentMap().fragment(n)->format;
executed (the execution status of this line is deduced): int formatIndex = p->fragmentMap().fragment(n)->format;
-
1578 int last = n;
executed (the execution status of this line is deduced): int last = n;
-
1579 -
1580 while (n != b && p->fragmentMap().fragment(n)->format != formatIndex) {
partially evaluated: n != b
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
partially evaluated: p->fragmentMap().fragment(n)->format != formatIndex
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1581 last = n;
never executed (the execution status of this line is deduced): last = n;
-
1582 n = p->fragmentMap().previous(n);
never executed (the execution status of this line is deduced): n = p->fragmentMap().previous(n);
-
1583 }
never executed: }
0
1584 -
1585 n = last;
executed (the execution status of this line is deduced): n = last;
-
1586 return *this;
executed: return *this;
Execution Count:3
3
1587} -
1588 -
1589 -
1590/*! -
1591 \class QTextFragment -
1592 \reentrant -
1593 -
1594 \brief The QTextFragment class holds a piece of text in a -
1595 QTextDocument with a single QTextCharFormat. -
1596 \inmodule QtGui -
1597 -
1598 \ingroup richtext-processing -
1599 -
1600 A text fragment describes a piece of text that is stored with a single -
1601 character format. Text in which the character format changes can be -
1602 represented by sequences of text fragments with different formats. -
1603 -
1604 If the user edits the text in a fragment and introduces a different -
1605 character format, the fragment's text will be split at each point where -
1606 the format changes, and new fragments will be created. -
1607 For example, changing the style of some text in the middle of a -
1608 sentence will cause the fragment to be broken into three separate fragments: -
1609 the first and third with the same format as before, and the second with -
1610 the new style. The first fragment will contain the text from the beginning -
1611 of the sentence, the second will contain the text from the middle, and the -
1612 third takes the text from the end of the sentence. -
1613 -
1614 \image qtextfragment-split.png -
1615 -
1616 A fragment's text and character format can be obtained with the text() -
1617 and charFormat() functions. The length() function gives the length of -
1618 the text in the fragment. position() gives the position in the document -
1619 of the start of the fragment. To determine whether the fragment contains -
1620 a particular position within the document, use the contains() function. -
1621 -
1622 \sa QTextDocument, {Rich Text Document Structure} -
1623*/ -
1624 -
1625/*! -
1626 \fn QTextFragment::QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) -
1627 \internal -
1628*/ -
1629 -
1630/*! -
1631 \fn QTextFragment::QTextFragment() -
1632 -
1633 Creates a new empty text fragment. -
1634*/ -
1635 -
1636/*! -
1637 \fn QTextFragment::QTextFragment(const QTextFragment &other) -
1638 -
1639 Copies the content (text and format) of the \a other text fragment -
1640 to this text fragment. -
1641*/ -
1642 -
1643/*! -
1644 \fn QTextFragment &QTextFragment::operator=(const QTextFragment -
1645 &other) -
1646 -
1647 Assigns the content (text and format) of the \a other text fragment -
1648 to this text fragment. -
1649*/ -
1650 -
1651/*! -
1652 \fn bool QTextFragment::isValid() const -
1653 -
1654 Returns true if this is a valid text fragment (i.e. has a valid -
1655 position in a document); otherwise returns false. -
1656*/ -
1657 -
1658/*! -
1659 \fn bool QTextFragment::operator==(const QTextFragment &other) const -
1660 -
1661 Returns true if this text fragment is the same (at the same -
1662 position) as the \a other text fragment; otherwise returns false. -
1663*/ -
1664 -
1665/*! -
1666 \fn bool QTextFragment::operator!=(const QTextFragment &other) const -
1667 -
1668 Returns true if this text fragment is different (at a different -
1669 position) from the \a other text fragment; otherwise returns -
1670 false. -
1671*/ -
1672 -
1673/*! -
1674 \fn bool QTextFragment::operator<(const QTextFragment &other) const -
1675 -
1676 Returns true if this text fragment appears earlier in the document -
1677 than the \a other text fragment; otherwise returns false. -
1678*/ -
1679 -
1680/*! -
1681 Returns the glyphs corresponding to \a len characters of this text fragment starting at -
1682 position \a pos. The positions of the glyphs are relative to the position of the QTextBlock's -
1683 layout. -
1684 -
1685 If \a pos is less than zero, it will default to the start of the QTextFragment. If \a len -
1686 is less than zero, it will default to the length of the fragment. -
1687 -
1688 \sa QGlyphRun, QTextBlock::layout(), QTextLayout::position(), QPainter::drawGlyphRun() -
1689*/ -
1690#if !defined(QT_NO_RAWFONT) -
1691QList<QGlyphRun> QTextFragment::glyphRuns(int pos, int len) const -
1692{ -
1693 if (!p || !n)
never evaluated: !p
never evaluated: !n
0
1694 return QList<QGlyphRun>();
never executed: return QList<QGlyphRun>();
0
1695 -
1696 int blockNode = p->blockMap().findNode(position());
never executed (the execution status of this line is deduced): int blockNode = p->blockMap().findNode(position());
-
1697 -
1698 const QTextBlockData *blockData = p->blockMap().fragment(blockNode);
never executed (the execution status of this line is deduced): const QTextBlockData *blockData = p->blockMap().fragment(blockNode);
-
1699 QTextLayout *layout = blockData->layout;
never executed (the execution status of this line is deduced): QTextLayout *layout = blockData->layout;
-
1700 -
1701 int blockPosition = p->blockMap().position(blockNode);
never executed (the execution status of this line is deduced): int blockPosition = p->blockMap().position(blockNode);
-
1702 if (pos < 0)
never evaluated: pos < 0
0
1703 pos = position() - blockPosition;
never executed: pos = position() - blockPosition;
0
1704 if (len < 0)
never evaluated: len < 0
0
1705 len = length();
never executed: len = length();
0
1706 if (len == 0)
never evaluated: len == 0
0
1707 return QList<QGlyphRun>();
never executed: return QList<QGlyphRun>();
0
1708 -
1709 QList<QGlyphRun> ret;
never executed (the execution status of this line is deduced): QList<QGlyphRun> ret;
-
1710 for (int i=0; i<layout->lineCount(); ++i) {
never evaluated: i<layout->lineCount()
0
1711 QTextLine textLine = layout->lineAt(i);
never executed (the execution status of this line is deduced): QTextLine textLine = layout->lineAt(i);
-
1712 ret += textLine.glyphRuns(pos, len);
never executed (the execution status of this line is deduced): ret += textLine.glyphRuns(pos, len);
-
1713 }
never executed: }
0
1714 -
1715 return ret;
never executed: return ret;
0
1716} -
1717#endif // QT_NO_RAWFONT -
1718 -
1719/*! -
1720 Returns the position of this text fragment in the document. -
1721*/ -
1722int QTextFragment::position() const -
1723{ -
1724 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
0-46
1725 return 0; // ### -1 instead?
never executed: return 0;
0
1726 -
1727 return p->fragmentMap().position(n);
executed: return p->fragmentMap().position(n);
Execution Count:46
46
1728} -
1729 -
1730/*! -
1731 Returns the number of characters in the text fragment. -
1732 -
1733 \sa text() -
1734*/ -
1735int QTextFragment::length() const -
1736{ -
1737 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
1738 return 0;
never executed: return 0;
0
1739 -
1740 int len = 0;
executed (the execution status of this line is deduced): int len = 0;
-
1741 int f = n;
executed (the execution status of this line is deduced): int f = n;
-
1742 while (f != ne) {
evaluated: f != ne
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:10
10
1743 len += p->fragmentMap().size(f);
executed (the execution status of this line is deduced): len += p->fragmentMap().size(f);
-
1744 f = p->fragmentMap().next(f);
executed (the execution status of this line is deduced): f = p->fragmentMap().next(f);
-
1745 }
executed: }
Execution Count:10
10
1746 return len;
executed: return len;
Execution Count:10
10
1747} -
1748 -
1749/*! -
1750 Returns true if the text fragment contains the text at the given -
1751 \a position in the document; otherwise returns false. -
1752*/ -
1753bool QTextFragment::contains(int position) const -
1754{ -
1755 if (!p || !n)
never evaluated: !p
never evaluated: !n
0
1756 return false;
never executed: return false;
0
1757 int pos = this->position();
never executed (the execution status of this line is deduced): int pos = this->position();
-
1758 return position >= pos && position < pos + length();
never executed: return position >= pos && position < pos + length();
0
1759} -
1760 -
1761/*! -
1762 Returns the text fragment's character format. -
1763 -
1764 \sa text() -
1765*/ -
1766QTextCharFormat QTextFragment::charFormat() const -
1767{ -
1768 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:193
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:193
0-193
1769 return QTextCharFormat();
never executed: return QTextCharFormat();
0
1770 const QTextFragmentData *data = p->fragmentMap().fragment(n);
executed (the execution status of this line is deduced): const QTextFragmentData *data = p->fragmentMap().fragment(n);
-
1771 return p->formatCollection()->charFormat(data->format);
executed: return p->formatCollection()->charFormat(data->format);
Execution Count:193
193
1772} -
1773 -
1774/*! -
1775 Returns an index into the document's internal list of character formats -
1776 for the text fragment's character format. -
1777 -
1778 \sa QTextDocument::allFormats() -
1779*/ -
1780int QTextFragment::charFormatIndex() const -
1781{ -
1782 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1783 return -1;
never executed: return -1;
0
1784 const QTextFragmentData *data = p->fragmentMap().fragment(n);
executed (the execution status of this line is deduced): const QTextFragmentData *data = p->fragmentMap().fragment(n);
-
1785 return data->format;
executed: return data->format;
Execution Count:3
3
1786} -
1787 -
1788/*! -
1789 Returns the text fragment's as plain text. -
1790 -
1791 \sa length(), charFormat() -
1792*/ -
1793QString QTextFragment::text() const -
1794{ -
1795 if (!p || !n)
partially evaluated: !p
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:119
partially evaluated: !n
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:119
0-119
1796 return QString();
never executed: return QString();
0
1797 -
1798 QString result;
executed (the execution status of this line is deduced): QString result;
-
1799 QString buffer = p->buffer();
executed (the execution status of this line is deduced): QString buffer = p->buffer();
-
1800 int f = n;
executed (the execution status of this line is deduced): int f = n;
-
1801 while (f != ne) {
evaluated: f != ne
TRUEFALSE
yes
Evaluation Count:119
yes
Evaluation Count:119
119
1802 const QTextFragmentData * const frag = p->fragmentMap().fragment(f);
executed (the execution status of this line is deduced): const QTextFragmentData * const frag = p->fragmentMap().fragment(f);
-
1803 result += QString(buffer.constData() + frag->stringPosition, frag->size_array[0]);
executed (the execution status of this line is deduced): result += QString(buffer.constData() + frag->stringPosition, frag->size_array[0]);
-
1804 f = p->fragmentMap().next(f);
executed (the execution status of this line is deduced): f = p->fragmentMap().next(f);
-
1805 }
executed: }
Execution Count:119
119
1806 return result;
executed: return result;
Execution Count:119
119
1807} -
1808 -
1809QT_END_NAMESPACE -
1810 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial