text/qabstracttextdocumentlayout.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 <qabstracttextdocumentlayout.h> -
43#include <qtextformat.h> -
44#include "qtextdocument_p.h" -
45#include "qtextengine_p.h" -
46 -
47#include "qabstracttextdocumentlayout_p.h" -
48 -
49QT_BEGIN_NAMESPACE -
50 -
51/*! -
52 \class QAbstractTextDocumentLayout -
53 \reentrant -
54 -
55 \brief The QAbstractTextDocumentLayout class is an abstract base -
56 class used to implement custom layouts for QTextDocuments. -
57 \inmodule QtGui -
58 -
59 \ingroup richtext-processing -
60 -
61 The standard layout provided by Qt can handle simple word processing -
62 including inline images, lists and tables. -
63 -
64 Some applications, e.g., a word processor or a DTP application might need -
65 more features than the ones provided by Qt's layout engine, in which case -
66 you can subclass QAbstractTextDocumentLayout to provide custom layout -
67 behavior for your text documents. -
68 -
69 An instance of the QAbstractTextDocumentLayout subclass can be installed -
70 on a QTextDocument object with the -
71 \l{QTextDocument::}{setDocumentLayout()} function. -
72 -
73 You can insert custom objects into a QTextDocument; see the -
74 QTextObjectInterface class description for details. -
75 -
76 \sa QTextObjectInterface -
77*/ -
78 -
79/*! -
80 \class QTextObjectInterface -
81 \brief The QTextObjectInterface class allows drawing of -
82 custom text objects in \l{QTextDocument}s. -
83 \since 4.5 -
84 \inmodule QtGui -
85 -
86 A text object describes the structure of one or more elements in a -
87 text document; for instance, images imported from HTML are -
88 implemented using text objects. A text object knows how to lay out -
89 and draw its elements when a document is being rendered. -
90 -
91 Qt allows custom text objects to be inserted into a document by -
92 registering a custom \l{QTextCharFormat::objectType()}{object -
93 type} with QTextCharFormat. A QTextObjectInterface must also be -
94 implemented for this type and be -
95 \l{QAbstractTextDocumentLayout::registerHandler()}{registered} -
96 with the QAbstractTextDocumentLayout of the document. When the -
97 object type is encountered while rendering a QTextDocument, the -
98 intrinsicSize() and drawObject() functions of the interface are -
99 called. -
100 -
101 The following list explains the required steps of inserting a -
102 custom text object into a document: -
103 -
104 \list -
105 \li Choose an \a objectType. The \a objectType is an integer with a -
106 value greater or equal to QTextFormat::UserObject. -
107 \li Create a QTextCharFormat object and set the object type to the -
108 chosen type using the setObjectType() function. -
109 \li Implement the QTextObjectInterface class. -
110 \li Call QAbstractTextDocumentLayout::registerHandler() with an instance of your -
111 QTextObjectInterface subclass to register your object type. -
112 \li Insert QChar::ObjectReplacementCharacter with the aforementioned -
113 QTextCharFormat of the chosen object type into the document. -
114 As mentioned, the functions of QTextObjectInterface -
115 \l{QTextObjectInterface::}{intrinsicSize()} and -
116 \l{QTextObjectInterface::}{drawObject()} will then be called with the -
117 QTextFormat as parameter whenever the replacement character is -
118 encountered. -
119 \endlist -
120 -
121 A class implementing a text object needs to inherit both QObject -
122 and QTextObjectInterface. QObject must be the first class -
123 inherited. For instance: -
124 -
125 \snippet qtextobject/textobjectinterface.h 0 -
126 -
127 The data of a text object is usually stored in the QTextCharFormat -
128 using QTextCharFormat::setProperty(), and then retrieved with -
129 QTextCharFormat::property(). -
130 -
131 \warning Copy and Paste operations ignore custom text objects. -
132 -
133 \sa {Text Object Example}, QTextCharFormat, QTextLayout -
134*/ -
135 -
136/*! -
137 \fn QTextObjectInterface::~QTextObjectInterface() -
138 -
139 Destroys this QTextObjectInterface. -
140*/ -
141 -
142/*! -
143 \fn virtual QSizeF QTextObjectInterface::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0 -
144 -
145 The intrinsicSize() function returns the size of the text object -
146 represented by \a format in the given document (\a doc) at the -
147 given position (\a posInDocument). -
148 -
149 The size calculated will be used for subsequent calls to -
150 drawObject() for this \a format. -
151 -
152 \sa drawObject() -
153*/ -
154 -
155/*! -
156 \fn virtual void QTextObjectInterface::drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0 -
157 -
158 Draws this text object using the specified \a painter. -
159 -
160 The size of the rectangle, \a rect, to draw in is the size -
161 previously calculated by intrinsicSize(). The rectangles position -
162 is relative to the \a painter. -
163 -
164 You also get the document (\a doc) and the position (\a -
165 posInDocument) of the \a format in that document. -
166 -
167 \sa intrinsicSize() -
168*/ -
169 -
170/*! -
171 \fn void QAbstractTextDocumentLayout::update(const QRectF &rect) -
172 -
173 This signal is emitted when the rectangle \a rect has been updated. -
174 -
175 Subclasses of QAbstractTextDocumentLayout should emit this signal when -
176 the layout of the contents change in order to repaint. -
177*/ -
178 -
179/*! -
180 \fn void QAbstractTextDocumentLayout::updateBlock(const QTextBlock &block) -
181 \since 4.4 -
182 -
183 This signal is emitted when the specified \a block has been updated. -
184 -
185 Subclasses of QAbstractTextDocumentLayout should emit this signal when -
186 the layout of \a block has changed in order to repaint. -
187*/ -
188 -
189/*! -
190 \fn void QAbstractTextDocumentLayout::documentSizeChanged(const QSizeF &newSize) -
191 -
192 This signal is emitted when the size of the document layout changes to -
193 \a newSize. -
194 -
195 Subclasses of QAbstractTextDocumentLayout should emit this signal when the -
196 document's entire layout size changes. This signal is useful for widgets -
197 that display text documents since it enables them to update their scroll -
198 bars correctly. -
199 -
200 \sa documentSize() -
201*/ -
202 -
203/*! -
204 \fn void QAbstractTextDocumentLayout::pageCountChanged(int newPages) -
205 -
206 This signal is emitted when the number of pages in the layout changes; -
207 \a newPages is the updated page count. -
208 -
209 Subclasses of QAbstractTextDocumentLayout should emit this signal when -
210 the number of pages in the layout has changed. Changes to the page count -
211 are caused by changes to the layout or the document content itself. -
212 -
213 \sa pageCount() -
214*/ -
215 -
216/*! -
217 \fn int QAbstractTextDocumentLayout::pageCount() const -
218 -
219 Returns the number of pages contained in the layout. -
220 -
221 \sa pageCountChanged() -
222*/ -
223 -
224/*! -
225 \fn QSizeF QAbstractTextDocumentLayout::documentSize() const -
226 -
227 Returns the total size of the document's layout. -
228 -
229 This information can be used by display widgets to update their scroll bars -
230 correctly. -
231 -
232 \sa documentSizeChanged(), QTextDocument::pageSize -
233*/ -
234 -
235/*! -
236 \fn void QAbstractTextDocumentLayout::draw(QPainter *painter, const PaintContext &context) -
237 -
238 Draws the layout with the given \a painter using the given \a context. -
239*/ -
240 -
241/*! -
242 \fn int QAbstractTextDocumentLayout::hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const -
243 -
244 Returns the cursor position for the given \a point with the specified -
245 \a accuracy. Returns -1 if no valid cursor position was found. -
246*/ -
247 -
248/*! -
249 \fn void QAbstractTextDocumentLayout::documentChanged(int position, int charsRemoved, int charsAdded) -
250 -
251 This function is called whenever the contents of the document change. A -
252 change occurs when text is inserted, removed, or a combination of these -
253 two. The change is specified by \a position, \a charsRemoved, and -
254 \a charsAdded corresponding to the starting character position of the -
255 change, the number of characters removed from the document, and the -
256 number of characters added. -
257 -
258 For example, when inserting the text "Hello" into an empty document, -
259 \a charsRemoved would be 0 and \a charsAdded would be 5 (the length of -
260 the string). -
261 -
262 Replacing text is a combination of removing and inserting. For example, if -
263 the text "Hello" gets replaced by "Hi", \a charsRemoved would be 5 and -
264 \a charsAdded would be 2. -
265 -
266 For subclasses of QAbstractTextDocumentLayout, this is the central function -
267 where a large portion of the work to lay out and position document contents -
268 is done. -
269 -
270 For example, in a subclass that only arranges blocks of text, an -
271 implementation of this function would have to do the following: -
272 -
273 \list -
274 \li Determine the list of changed \l{QTextBlock}(s) using the parameters -
275 provided. -
276 \li Each QTextBlock object's corresponding QTextLayout object needs to -
277 be processed. You can access the \l{QTextBlock}'s layout using the -
278 QTextBlock::layout() function. This processing should take the -
279 document's page size into consideration. -
280 \li If the total number of pages changed, the pageCountChanged() signal -
281 should be emitted. -
282 \li If the total size changed, the documentSizeChanged() signal should -
283 be emitted. -
284 \li The update() signal should be emitted to schedule a repaint of areas -
285 in the layout that require repainting. -
286 \endlist -
287 -
288 \sa QTextLayout -
289*/ -
290 -
291/*! -
292 \class QAbstractTextDocumentLayout::PaintContext -
293 \reentrant -
294 \inmodule QtGui -
295 -
296 \brief The QAbstractTextDocumentLayout::PaintContext class is a convenience -
297 class defining the parameters used when painting a document's layout. -
298 -
299 A paint context is used when rendering custom layouts for QTextDocuments -
300 with the QAbstractTextDocumentLayout::draw() function. It is specified by -
301 a \l {cursorPosition}{cursor position}, \l {palette}{default text color}, -
302 \l clip rectangle and a collection of \l selections. -
303 -
304 \sa QAbstractTextDocumentLayout -
305*/ -
306 -
307/*! -
308 \fn QAbstractTextDocumentLayout::PaintContext::PaintContext() -
309 \internal -
310*/ -
311 -
312/*! -
313 \variable QAbstractTextDocumentLayout::PaintContext::cursorPosition -
314 -
315 \brief the position within the document, where the cursor line should be -
316 drawn. -
317 -
318 The default value is -1. -
319*/ -
320 -
321/*! -
322 \variable QAbstractTextDocumentLayout::PaintContext::palette -
323 -
324 \brief the default color that is used for the text, when no color is -
325 specified. -
326 -
327 The default value is the application's default palette. -
328*/ -
329 -
330/*! -
331 \variable QAbstractTextDocumentLayout::PaintContext::clip -
332 -
333 \brief a hint to the layout specifying the area around paragraphs, frames -
334 or text require painting. -
335 -
336 Everything outside of this rectangle does not need to be painted. -
337 -
338 Specifying a clip rectangle can speed up drawing of large documents -
339 significantly. Note that the clip rectangle is in document coordinates (not -
340 in viewport coordinates). It is not a substitute for a clip region set on -
341 the painter but merely a hint. -
342 -
343 The default value is a null rectangle indicating everything needs to be -
344 painted. -
345*/ -
346 -
347/*! -
348 \variable QAbstractTextDocumentLayout::PaintContext::selections -
349 -
350 \brief the collection of selections that will be rendered when passing this -
351 paint context to QAbstractTextDocumentLayout's draw() function. -
352 -
353 The default value is an empty vector indicating no selection. -
354*/ -
355 -
356/*! -
357 \class QAbstractTextDocumentLayout::Selection -
358 \reentrant -
359 \inmodule QtGui -
360 -
361 \brief The QAbstractTextDocumentLayout::Selection class is a convenience -
362 class defining the parameters of a selection. -
363 -
364 A selection can be used to specify a part of a document that should be -
365 highlighted when drawing custom layouts for QTextDocuments with the -
366 QAbstractTextDocumentLayout::draw() function. It is specified using -
367 \l cursor and a \l format. -
368 -
369 \sa QAbstractTextDocumentLayout, PaintContext -
370*/ -
371 -
372/*! -
373 \variable QAbstractTextDocumentLayout::Selection::format -
374 -
375 \brief the format of the selection -
376 -
377 The default value is QTextFormat::InvalidFormat. -
378*/ -
379 -
380/*! -
381 \variable QAbstractTextDocumentLayout::Selection::cursor -
382 \brief the selection's cursor -
383 -
384 The default value is a null cursor. -
385*/ -
386 -
387/*! -
388 Creates a new text document layout for the given \a document. -
389*/ -
390QAbstractTextDocumentLayout::QAbstractTextDocumentLayout(QTextDocument *document) -
391 : QObject(*new QAbstractTextDocumentLayoutPrivate, document) -
392{ -
393 Q_D(QAbstractTextDocumentLayout);
executed (the execution status of this line is deduced): QAbstractTextDocumentLayoutPrivate * const d = d_func();
-
394 d->setDocument(document);
executed (the execution status of this line is deduced): d->setDocument(document);
-
395}
executed: }
Execution Count:47
47
396 -
397/*! -
398 \internal -
399*/ -
400QAbstractTextDocumentLayout::QAbstractTextDocumentLayout(QAbstractTextDocumentLayoutPrivate &p, QTextDocument *document) -
401 :QObject(p, document) -
402{ -
403 Q_D(QAbstractTextDocumentLayout);
executed (the execution status of this line is deduced): QAbstractTextDocumentLayoutPrivate * const d = d_func();
-
404 d->setDocument(document);
executed (the execution status of this line is deduced): d->setDocument(document);
-
405}
executed: }
Execution Count:406
406
406 -
407/*! -
408 \internal -
409*/ -
410QAbstractTextDocumentLayout::~QAbstractTextDocumentLayout() -
411{ -
412} -
413 -
414/*! -
415 \fn void QAbstractTextDocumentLayout::registerHandler(int objectType, QObject *component) -
416 -
417 Registers the given \a component as a handler for items of the given \a objectType. -
418 -
419 \note registerHandler() has to be called once for each object type. This -
420 means that there is only one handler for multiple replacement characters -
421 of the same object type. -
422 -
423 The text document layout does not take ownership of \c component. -
424*/ -
425void QAbstractTextDocumentLayout::registerHandler(int formatType, QObject *component) -
426{ -
427 Q_D(QAbstractTextDocumentLayout);
executed (the execution status of this line is deduced): QAbstractTextDocumentLayoutPrivate * const d = d_func();
-
428 -
429 QTextObjectInterface *iface = qobject_cast<QTextObjectInterface *>(component);
executed (the execution status of this line is deduced): QTextObjectInterface *iface = qobject_cast<QTextObjectInterface *>(component);
-
430 if (!iface)
partially evaluated: !iface
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:314
0-314
431 return; // ### print error message on terminal?
never executed: return;
0
432 -
433 connect(component, SIGNAL(destroyed(QObject*)), this, SLOT(_q_handlerDestroyed(QObject*)));
executed (the execution status of this line is deduced): connect(component, "2""destroyed(QObject*)", this, "1""_q_handlerDestroyed(QObject*)");
-
434 -
435 QTextObjectHandler h;
executed (the execution status of this line is deduced): QTextObjectHandler h;
-
436 h.iface = iface;
executed (the execution status of this line is deduced): h.iface = iface;
-
437 h.component = component;
executed (the execution status of this line is deduced): h.component = component;
-
438 d->handlers.insert(formatType, h);
executed (the execution status of this line is deduced): d->handlers.insert(formatType, h);
-
439}
executed: }
Execution Count:314
314
440 -
441/*! -
442 Returns a handler for objects of the given \a objectType. -
443*/ -
444QTextObjectInterface *QAbstractTextDocumentLayout::handlerForObject(int objectType) const -
445{ -
446 Q_D(const QAbstractTextDocumentLayout);
executed (the execution status of this line is deduced): const QAbstractTextDocumentLayoutPrivate * const d = d_func();
-
447 -
448 QTextObjectHandler handler = d->handlers.value(objectType);
executed (the execution status of this line is deduced): QTextObjectHandler handler = d->handlers.value(objectType);
-
449 if (!handler.component)
partially evaluated: !handler.component
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
450 return 0;
never executed: return 0;
0
451 -
452 return handler.iface;
executed: return handler.iface;
Execution Count:1
1
453} -
454 -
455/*! -
456 Sets the size of the inline object \a item corresponding to the text -
457 \a format. -
458 -
459 \a posInDocument specifies the position of the object within the document. -
460 -
461 The default implementation resizes the \a item to the size returned by -
462 the object handler's intrinsicSize() function. This function is called only -
463 within Qt. Subclasses can reimplement this function to customize the -
464 resizing of inline objects. -
465*/ -
466void QAbstractTextDocumentLayout::resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format) -
467{ -
468 Q_D(QAbstractTextDocumentLayout);
never executed (the execution status of this line is deduced): QAbstractTextDocumentLayoutPrivate * const d = d_func();
-
469 -
470 QTextCharFormat f = format.toCharFormat();
never executed (the execution status of this line is deduced): QTextCharFormat f = format.toCharFormat();
-
471 Q_ASSERT(f.isValid());
never executed (the execution status of this line is deduced): qt_noop();
-
472 QTextObjectHandler handler = d->handlers.value(f.objectType());
never executed (the execution status of this line is deduced): QTextObjectHandler handler = d->handlers.value(f.objectType());
-
473 if (!handler.component)
never evaluated: !handler.component
0
474 return;
never executed: return;
0
475 -
476 QSizeF s = handler.iface->intrinsicSize(document(), posInDocument, format);
never executed (the execution status of this line is deduced): QSizeF s = handler.iface->intrinsicSize(document(), posInDocument, format);
-
477 item.setWidth(s.width());
never executed (the execution status of this line is deduced): item.setWidth(s.width());
-
478 item.setAscent(s.height());
never executed (the execution status of this line is deduced): item.setAscent(s.height());
-
479 item.setDescent(0);
never executed (the execution status of this line is deduced): item.setDescent(0);
-
480}
never executed: }
0
481 -
482/*! -
483 Lays out the inline object \a item using the given text \a format. -
484 -
485 \a posInDocument specifies the position of the object within the document. -
486 -
487 The default implementation does nothing. This function is called only -
488 within Qt. Subclasses can reimplement this function to customize the -
489 position of inline objects. -
490 -
491 \sa drawInlineObject() -
492*/ -
493void QAbstractTextDocumentLayout::positionInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format) -
494{ -
495 Q_UNUSED(item);
never executed (the execution status of this line is deduced): (void)item;;
-
496 Q_UNUSED(posInDocument);
never executed (the execution status of this line is deduced): (void)posInDocument;;
-
497 Q_UNUSED(format);
never executed (the execution status of this line is deduced): (void)format;;
-
498}
never executed: }
0
499 -
500/*! -
501 \fn void QAbstractTextDocumentLayout::drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format) -
502 -
503 This function is called to draw the inline object, \a object, with the -
504 given \a painter within the rectangle specified by \a rect using the -
505 specified text \a format. -
506 -
507 \a posInDocument specifies the position of the object within the document. -
508 -
509 The default implementation calls drawObject() on the object handlers. This -
510 function is called only within Qt. Subclasses can reimplement this function -
511 to customize the drawing of inline objects. -
512 -
513 \sa draw() -
514*/ -
515void QAbstractTextDocumentLayout::drawInlineObject(QPainter *p, const QRectF &rect, QTextInlineObject item, -
516 int posInDocument, const QTextFormat &format) -
517{ -
518 Q_UNUSED(item);
executed (the execution status of this line is deduced): (void)item;;
-
519 Q_D(QAbstractTextDocumentLayout);
executed (the execution status of this line is deduced): QAbstractTextDocumentLayoutPrivate * const d = d_func();
-
520 -
521 QTextCharFormat f = format.toCharFormat();
executed (the execution status of this line is deduced): QTextCharFormat f = format.toCharFormat();
-
522 Q_ASSERT(f.isValid());
executed (the execution status of this line is deduced): qt_noop();
-
523 QTextObjectHandler handler = d->handlers.value(f.objectType());
executed (the execution status of this line is deduced): QTextObjectHandler handler = d->handlers.value(f.objectType());
-
524 if (!handler.component)
partially evaluated: !handler.component
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
525 return;
never executed: return;
0
526 -
527 handler.iface->drawObject(p, rect, document(), posInDocument, format);
executed (the execution status of this line is deduced): handler.iface->drawObject(p, rect, document(), posInDocument, format);
-
528}
executed: }
Execution Count:1
1
529 -
530void QAbstractTextDocumentLayoutPrivate::_q_handlerDestroyed(QObject *obj) -
531{ -
532 HandlerHash::Iterator it = handlers.begin();
never executed (the execution status of this line is deduced): HandlerHash::Iterator it = handlers.begin();
-
533 while (it != handlers.end())
never evaluated: it != handlers.end()
0
534 if ((*it).component == obj)
never evaluated: (*it).component == obj
0
535 it = handlers.erase(it);
never executed: it = handlers.erase(it);
0
536 else -
537 ++it;
never executed: ++it;
0
538}
never executed: }
0
539 -
540/*! -
541 \internal -
542 -
543 Returns the index of the format at position \a pos. -
544*/ -
545int QAbstractTextDocumentLayout::formatIndex(int pos) -
546{ -
547 QTextDocumentPrivate *pieceTable = qobject_cast<QTextDocument *>(parent())->docHandle();
never executed (the execution status of this line is deduced): QTextDocumentPrivate *pieceTable = qobject_cast<QTextDocument *>(parent())->docHandle();
-
548 return pieceTable->find(pos).value()->format;
never executed: return pieceTable->find(pos).value()->format;
0
549} -
550 -
551/*! -
552 \fn QTextCharFormat QAbstractTextDocumentLayout::format(int position) -
553 -
554 Returns the character format that is applicable at the given \a position. -
555*/ -
556QTextCharFormat QAbstractTextDocumentLayout::format(int pos) -
557{ -
558 QTextDocumentPrivate *pieceTable = qobject_cast<QTextDocument *>(parent())->docHandle();
executed (the execution status of this line is deduced): QTextDocumentPrivate *pieceTable = qobject_cast<QTextDocument *>(parent())->docHandle();
-
559 int idx = pieceTable->find(pos).value()->format;
executed (the execution status of this line is deduced): int idx = pieceTable->find(pos).value()->format;
-
560 return pieceTable->formatCollection()->charFormat(idx);
executed: return pieceTable->formatCollection()->charFormat(idx);
Execution Count:1
1
561} -
562 -
563 -
564 -
565/*! -
566 Returns the text document that this layout is operating on. -
567*/ -
568QTextDocument *QAbstractTextDocumentLayout::document() const -
569{ -
570 Q_D(const QAbstractTextDocumentLayout);
executed (the execution status of this line is deduced): const QAbstractTextDocumentLayoutPrivate * const d = d_func();
-
571 return d->document;
executed: return d->document;
Execution Count:20089
20089
572} -
573 -
574/*! -
575 \fn QString QAbstractTextDocumentLayout::anchorAt(const QPointF &position) const -
576 -
577 Returns the reference of the anchor the given \a position, or an empty -
578 string if no anchor exists at that point. -
579*/ -
580QString QAbstractTextDocumentLayout::anchorAt(const QPointF& pos) const -
581{ -
582 int cursorPos = hitTest(pos, Qt::ExactHit);
executed (the execution status of this line is deduced): int cursorPos = hitTest(pos, Qt::ExactHit);
-
583 if (cursorPos == -1)
evaluated: cursorPos == -1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:6
1-6
584 return QString();
executed: return QString();
Execution Count:1
1
585 -
586 // compensate for preedit in the hit text block -
587 QTextBlock block = document()->firstBlock();
executed (the execution status of this line is deduced): QTextBlock block = document()->firstBlock();
-
588 while (block.isValid()) {
partially evaluated: block.isValid()
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
589 QRectF blockBr = blockBoundingRect(block);
executed (the execution status of this line is deduced): QRectF blockBr = blockBoundingRect(block);
-
590 if (blockBr.contains(pos)) {
evaluated: blockBr.contains(pos)
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:4
4-6
591 QTextLayout *layout = block.layout();
executed (the execution status of this line is deduced): QTextLayout *layout = block.layout();
-
592 int relativeCursorPos = cursorPos - block.position();
executed (the execution status of this line is deduced): int relativeCursorPos = cursorPos - block.position();
-
593 const int preeditLength = layout ? layout->preeditAreaText().length() : 0;
partially evaluated: layout
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
594 if (preeditLength > 0 && relativeCursorPos > layout->preeditAreaPosition())
evaluated: preeditLength > 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:4
evaluated: relativeCursorPos > layout->preeditAreaPosition()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1-4
595 cursorPos -= qMin(cursorPos - layout->preeditAreaPosition(), preeditLength);
executed: cursorPos -= qMin(cursorPos - layout->preeditAreaPosition(), preeditLength);
Execution Count:1
1
596 break;
executed: break;
Execution Count:6
6
597 } -
598 block = block.next();
executed (the execution status of this line is deduced): block = block.next();
-
599 }
executed: }
Execution Count:4
4
600 -
601 QTextDocumentPrivate *pieceTable = qobject_cast<const QTextDocument *>(parent())->docHandle();
executed (the execution status of this line is deduced): QTextDocumentPrivate *pieceTable = qobject_cast<const QTextDocument *>(parent())->docHandle();
-
602 QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);
executed (the execution status of this line is deduced): QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos);
-
603 QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);
executed (the execution status of this line is deduced): QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format);
-
604 return fmt.anchorHref();
executed: return fmt.anchorHref();
Execution Count:6
6
605} -
606 -
607/*! -
608 \fn QRectF QAbstractTextDocumentLayout::frameBoundingRect(QTextFrame *frame) const -
609 -
610 Returns the bounding rectangle of \a frame. -
611*/ -
612 -
613/*! -
614 \fn QRectF QAbstractTextDocumentLayout::blockBoundingRect(const QTextBlock &block) const -
615 -
616 Returns the bounding rectangle of \a block. -
617*/ -
618 -
619/*! -
620 Sets the paint device used for rendering the document's layout to the given -
621 \a device. -
622 -
623 \sa paintDevice() -
624*/ -
625void QAbstractTextDocumentLayout::setPaintDevice(QPaintDevice *device) -
626{ -
627 Q_D(QAbstractTextDocumentLayout);
executed (the execution status of this line is deduced): QAbstractTextDocumentLayoutPrivate * const d = d_func();
-
628 d->paintDevice = device;
executed (the execution status of this line is deduced): d->paintDevice = device;
-
629}
executed: }
Execution Count:262
262
630 -
631/*! -
632 Returns the paint device used to render the document's layout. -
633 -
634 \sa setPaintDevice() -
635*/ -
636QPaintDevice *QAbstractTextDocumentLayout::paintDevice() const -
637{ -
638 Q_D(const QAbstractTextDocumentLayout);
executed (the execution status of this line is deduced): const QAbstractTextDocumentLayoutPrivate * const d = d_func();
-
639 return d->paintDevice;
executed: return d->paintDevice;
Execution Count:94779
94779
640} -
641 -
642QT_END_NAMESPACE -
643 -
644#include "moc_qabstracttextdocumentlayout.cpp" -
645 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial