widgets/qplaintextedit.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9static inline bool shouldEnableInputMethod(QPlainTextEdit *plaintextedit) -
10{ -
11 return !plaintextedit->isReadOnly();
executed: return !plaintextedit->isReadOnly();
Execution Count:2
2
12} -
13 -
14class QPlainTextDocumentLayoutPrivate : public QAbstractTextDocumentLayoutPrivate -
15{ -
16 inline QPlainTextDocumentLayout* q_func() { return static_cast<QPlainTextDocumentLayout *>(q_ptr); } inline const QPlainTextDocumentLayout* q_func() const { return static_cast<const QPlainTextDocumentLayout *>(q_ptr); } friend class QPlainTextDocumentLayout; -
17public: -
18 QPlainTextDocumentLayoutPrivate() { -
19 mainViewPrivate = 0; -
20 width = 0; -
21 maximumWidth = 0; -
22 maximumWidthBlockNumber = 0; -
23 blockCount = 1; -
24 blockUpdate = blockDocumentSizeChanged = false; -
25 cursorWidth = 1; -
26 textLayoutFlags = 0; -
27 }
executed: }
Execution Count:92
92
28 -
29 qreal width; -
30 qreal maximumWidth; -
31 int maximumWidthBlockNumber; -
32 int blockCount; -
33 QPlainTextEditPrivate *mainViewPrivate; -
34 bool blockUpdate; -
35 bool blockDocumentSizeChanged; -
36 int cursorWidth; -
37 int textLayoutFlags; -
38 -
39 void layoutBlock(const QTextBlock &block); -
40 qreal blockWidth(const QTextBlock &block); -
41 -
42 void relayout(); -
43}; -
44QPlainTextDocumentLayout::QPlainTextDocumentLayout(QTextDocument *document) -
45 :QAbstractTextDocumentLayout(* new QPlainTextDocumentLayoutPrivate, document) { -
46}
executed: }
Execution Count:92
92
47 -
48 -
49 -
50QPlainTextDocumentLayout::~QPlainTextDocumentLayout() {} -
51 -
52 -
53 -
54 -
55 -
56void QPlainTextDocumentLayout::draw(QPainter *, const PaintContext &) -
57{ -
58} -
59 -
60 -
61 -
62 -
63int QPlainTextDocumentLayout::hitTest(const QPointF &, Qt::HitTestAccuracy ) const -
64{ -
65 -
66 -
67 -
68 -
69 -
70 return -1;
never executed: return -1;
0
71} -
72 -
73 -
74 -
75 -
76int QPlainTextDocumentLayout::pageCount() const -
77{ return 1; }
never executed: return 1;
0
78 -
79 -
80 -
81 -
82QSizeF QPlainTextDocumentLayout::documentSize() const -
83{ -
84 const QPlainTextDocumentLayoutPrivate * const d = d_func(); -
85 return QSizeF(d->maximumWidth, document()->lineCount());
executed: return QSizeF(d->maximumWidth, document()->lineCount());
Execution Count:516
516
86} -
87 -
88 -
89 -
90 -
91QRectF QPlainTextDocumentLayout::frameBoundingRect(QTextFrame *) const -
92{ -
93 const QPlainTextDocumentLayoutPrivate * const d = d_func(); -
94 return QRectF(0, 0, qMax(d->width, d->maximumWidth), qreal(2147483647));
executed: return QRectF(0, 0, qMax(d->width, d->maximumWidth), qreal(2147483647));
Execution Count:7
7
95} -
96 -
97 -
98 -
99 -
100QRectF QPlainTextDocumentLayout::blockBoundingRect(const QTextBlock &block) const -
101{ -
102 if (!block.isValid()) { return QRectF(); }
partially evaluated: !block.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2896
never executed: return QRectF();
0-2896
103 QTextLayout *tl = block.layout(); -
104 if (!tl->lineCount())
evaluated: !tl->lineCount()
TRUEFALSE
yes
Evaluation Count:453
yes
Evaluation Count:2443
453-2443
105 const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
executed: const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
Execution Count:453
453
106 QRectF br; -
107 if (block.isVisible()) {
partially evaluated: block.isVisible()
TRUEFALSE
yes
Evaluation Count:2896
no
Evaluation Count:0
0-2896
108 br = QRectF(QPointF(0, 0), tl->boundingRect().bottomRight()); -
109 if (tl->lineCount() == 1)
evaluated: tl->lineCount() == 1
TRUEFALSE
yes
Evaluation Count:2758
yes
Evaluation Count:138
138-2758
110 br.setWidth(qMax(br.width(), tl->lineAt(0).naturalTextWidth()));
executed: br.setWidth(qMax(br.width(), tl->lineAt(0).naturalTextWidth()));
Execution Count:2758
2758
111 qreal margin = document()->documentMargin(); -
112 br.adjust(0, 0, margin, 0); -
113 if (!block.next().isValid())
evaluated: !block.next().isValid()
TRUEFALSE
yes
Evaluation Count:1939
yes
Evaluation Count:957
957-1939
114 br.adjust(0, 0, 0, margin);
executed: br.adjust(0, 0, 0, margin);
Execution Count:1939
1939
115 }
executed: }
Execution Count:2896
2896
116 return br;
executed: return br;
Execution Count:2896
2896
117 -
118} -
119 -
120 -
121 -
122 -
123void QPlainTextDocumentLayout::ensureBlockLayout(const QTextBlock &block) const -
124{ -
125 if (!block.isValid())
never evaluated: !block.isValid()
0
126 return;
never executed: return;
0
127 QTextLayout *tl = block.layout(); -
128 if (!tl->lineCount())
never evaluated: !tl->lineCount()
0
129 const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
never executed: const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block);
0
130}
never executed: }
0
131 -
132 -
133 -
134 -
135 -
136 -
137void QPlainTextDocumentLayout::setCursorWidth(int width) -
138{ -
139 QPlainTextDocumentLayoutPrivate * const d = d_func(); -
140 d->cursorWidth = width; -
141}
never executed: }
0
142 -
143int QPlainTextDocumentLayout::cursorWidth() const -
144{ -
145 const QPlainTextDocumentLayoutPrivate * const d = d_func(); -
146 return d->cursorWidth;
executed: return d->cursorWidth;
Execution Count:850
850
147} -
148 -
149QPlainTextDocumentLayoutPrivate *QPlainTextDocumentLayout::priv() const -
150{ -
151 const QPlainTextDocumentLayoutPrivate * const d = d_func(); -
152 return const_cast<QPlainTextDocumentLayoutPrivate*>(d);
executed: return const_cast<QPlainTextDocumentLayoutPrivate*>(d);
Execution Count:861
861
153} -
154 -
155 -
156 -
157 -
158 -
159 -
160void QPlainTextDocumentLayout::requestUpdate() -
161{ -
162 update(QRectF(0., -document()->documentMargin(), 1000000000., 1000000000.)); -
163}
never executed: }
0
164 -
165 -
166void QPlainTextDocumentLayout::setTextWidth(qreal newWidth) -
167{ -
168 QPlainTextDocumentLayoutPrivate * const d = d_func(); -
169 d->width = d->maximumWidth = newWidth; -
170 d->relayout(); -
171}
executed: }
Execution Count:31
31
172 -
173qreal QPlainTextDocumentLayout::textWidth() const -
174{ -
175 const QPlainTextDocumentLayoutPrivate * const d = d_func(); -
176 return d->width;
never executed: return d->width;
0
177} -
178 -
179void QPlainTextDocumentLayoutPrivate::relayout() -
180{ -
181 QPlainTextDocumentLayout * const q = q_func(); -
182 QTextBlock block = q->document()->firstBlock(); -
183 while (block.isValid()) {
evaluated: block.isValid()
TRUEFALSE
yes
Evaluation Count:833
yes
Evaluation Count:31
31-833
184 block.layout()->clearLayout(); -
185 block.setLineCount(block.isVisible() ? 1 : 0); -
186 block = block.next(); -
187 }
executed: }
Execution Count:833
833
188 q->update(); -
189}
executed: }
Execution Count:31
31
190 -
191 -
192 -
193 -
194void QPlainTextDocumentLayout::documentChanged(int from, int , int charsAdded) -
195{ -
196 QPlainTextDocumentLayoutPrivate * const d = d_func(); -
197 QTextDocument *doc = document(); -
198 int newBlockCount = doc->blockCount(); -
199 -
200 QTextBlock changeStartBlock = doc->findBlock(from); -
201 QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsAdded - 1)); -
202 -
203 if (changeStartBlock == changeEndBlock && newBlockCount == d->blockCount) {
evaluated: changeStartBlock == changeEndBlock
TRUEFALSE
yes
Evaluation Count:530
yes
Evaluation Count:23
evaluated: newBlockCount == d->blockCount
TRUEFALSE
yes
Evaluation Count:515
yes
Evaluation Count:15
15-530
204 QTextBlock block = changeStartBlock; -
205 int blockLineCount = block.layout()->lineCount(); -
206 if (block.isValid() && blockLineCount) {
partially evaluated: block.isValid()
TRUEFALSE
yes
Evaluation Count:515
no
Evaluation Count:0
evaluated: blockLineCount
TRUEFALSE
yes
Evaluation Count:335
yes
Evaluation Count:180
0-515
207 QRectF oldBr = blockBoundingRect(block); -
208 layoutBlock(block); -
209 QRectF newBr = blockBoundingRect(block); -
210 if (newBr.height() == oldBr.height()) {
evaluated: newBr.height() == oldBr.height()
TRUEFALSE
yes
Evaluation Count:331
yes
Evaluation Count:4
4-331
211 if (!d->blockUpdate)
partially evaluated: !d->blockUpdate
TRUEFALSE
yes
Evaluation Count:331
no
Evaluation Count:0
0-331
212 updateBlock(block);
executed: updateBlock(block);
Execution Count:331
331
213 return;
executed: return;
Execution Count:331
331
214 } -
215 }
executed: }
Execution Count:4
4
216 } else {
executed: }
Execution Count:184
184
217 QTextBlock block = changeStartBlock; -
218 do { -
219 block.clearLayout(); -
220 if (block == changeEndBlock)
evaluated: block == changeEndBlock
TRUEFALSE
yes
Evaluation Count:34
yes
Evaluation Count:2839
34-2839
221 break;
executed: break;
Execution Count:34
34
222 block = block.next(); -
223 } while(block.isValid());
executed: }
Execution Count:2839
evaluated: block.isValid()
TRUEFALSE
yes
Evaluation Count:2835
yes
Evaluation Count:4
4-2839
224 }
executed: }
Execution Count:38
38
225 -
226 if (newBlockCount != d->blockCount) {
evaluated: newBlockCount != d->blockCount
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:186
36-186
227 -
228 int changeEnd = changeEndBlock.blockNumber(); -
229 int blockDiff = newBlockCount - d->blockCount; -
230 int oldChangeEnd = changeEnd - blockDiff; -
231 -
232 if (d->maximumWidthBlockNumber > oldChangeEnd)
evaluated: d->maximumWidthBlockNumber > oldChangeEnd
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:20
16-20
233 d->maximumWidthBlockNumber += blockDiff;
executed: d->maximumWidthBlockNumber += blockDiff;
Execution Count:16
16
234 -
235 d->blockCount = newBlockCount; -
236 if (d->blockCount == 1)
evaluated: d->blockCount == 1
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:33
3-33
237 d->maximumWidth = blockWidth(doc->firstBlock());
executed: d->maximumWidth = blockWidth(doc->firstBlock());
Execution Count:3
3
238 -
239 if (!d->blockDocumentSizeChanged)
evaluated: !d->blockDocumentSizeChanged
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:9
9-27
240 documentSizeChanged(documentSize());
executed: documentSizeChanged(documentSize());
Execution Count:27
27
241 -
242 if (blockDiff == 1 && changeEnd == newBlockCount -1 ) {
evaluated: blockDiff == 1
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:13
evaluated: changeEnd == newBlockCount -1
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:11
11-23
243 if (!d->blockUpdate) {
partially evaluated: !d->blockUpdate
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
0-12
244 QTextBlock b = changeStartBlock; -
245 for(;;) { -
246 updateBlock(b); -
247 if (b == changeEndBlock)
evaluated: b == changeEndBlock
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:12
12
248 break;
executed: break;
Execution Count:12
12
249 b = b.next(); -
250 }
executed: }
Execution Count:12
12
251 }
executed: }
Execution Count:12
12
252 return;
executed: return;
Execution Count:12
12
253 } -
254 }
executed: }
Execution Count:24
24
255 -
256 if (!d->blockUpdate)
partially evaluated: !d->blockUpdate
TRUEFALSE
yes
Evaluation Count:210
no
Evaluation Count:0
0-210
257 update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.));
executed: update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.));
Execution Count:210
210
258}
executed: }
Execution Count:210
210
259 -
260 -
261void QPlainTextDocumentLayout::layoutBlock(const QTextBlock &block) -
262{ -
263 QPlainTextDocumentLayoutPrivate * const d = d_func(); -
264 QTextDocument *doc = document(); -
265 qreal margin = doc->documentMargin(); -
266 qreal blockMaximumWidth = 0; -
267 -
268 qreal height = 0; -
269 QTextLayout *tl = block.layout(); -
270 QTextOption option = doc->defaultTextOption(); -
271 tl->setTextOption(option); -
272 -
273 int extraMargin = 0; -
274 if (option.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) {
partially evaluated: option.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:788
0-788
275 QFontMetrics fm(block.charFormat().font()); -
276 extraMargin += fm.width(QChar(0x21B5)); -
277 }
never executed: }
0
278 tl->beginLayout(); -
279 qreal availableWidth = d->width; -
280 if (availableWidth <= 0) {
evaluated: availableWidth <= 0
TRUEFALSE
yes
Evaluation Count:668
yes
Evaluation Count:120
120-668
281 availableWidth = qreal(2147483647); -
282 }
executed: }
Execution Count:668
668
283 availableWidth -= 2*margin + extraMargin; -
284 while (1) {
partially evaluated: 1
TRUEFALSE
yes
Evaluation Count:1675
no
Evaluation Count:0
0-1675
285 QTextLine line = tl->createLine(); -
286 if (!line.isValid())
evaluated: !line.isValid()
TRUEFALSE
yes
Evaluation Count:788
yes
Evaluation Count:887
788-887
287 break;
executed: break;
Execution Count:788
788
288 line.setLeadingIncluded(true); -
289 line.setLineWidth(availableWidth); -
290 line.setPosition(QPointF(margin, height)); -
291 height += line.height(); -
292 blockMaximumWidth = qMax(blockMaximumWidth, line.naturalTextWidth() + 2*margin); -
293 }
executed: }
Execution Count:887
887
294 tl->endLayout(); -
295 -
296 int previousLineCount = doc->lineCount(); -
297 const_cast<QTextBlock&>(block).setLineCount(block.isVisible() ? tl->lineCount() : 0); -
298 int lineCount = doc->lineCount(); -
299 -
300 bool emitDocumentSizeChanged = previousLineCount != lineCount; -
301 if (blockMaximumWidth > d->maximumWidth) {
evaluated: blockMaximumWidth > d->maximumWidth
TRUEFALSE
yes
Evaluation Count:231
yes
Evaluation Count:557
231-557
302 -
303 d->maximumWidth = blockMaximumWidth; -
304 d->maximumWidthBlockNumber = block.blockNumber(); -
305 emitDocumentSizeChanged = true; -
306 } else if (block.blockNumber() == d->maximumWidthBlockNumber && blockMaximumWidth < d->maximumWidth) {
executed: }
Execution Count:231
evaluated: block.blockNumber() == d->maximumWidthBlockNumber
TRUEFALSE
yes
Evaluation Count:307
yes
Evaluation Count:250
evaluated: blockMaximumWidth < d->maximumWidth
TRUEFALSE
yes
Evaluation Count:40
yes
Evaluation Count:267
40-307
307 -
308 QTextBlock b = doc->firstBlock(); -
309 d->maximumWidth = 0; -
310 QTextBlock maximumBlock; -
311 while (b.isValid()) {
evaluated: b.isValid()
TRUEFALSE
yes
Evaluation Count:854
yes
Evaluation Count:40
40-854
312 qreal blockMaximumWidth = blockWidth(b); -
313 if (blockMaximumWidth > d->maximumWidth) {
evaluated: blockMaximumWidth > d->maximumWidth
TRUEFALSE
yes
Evaluation Count:40
yes
Evaluation Count:814
40-814
314 d->maximumWidth = blockMaximumWidth; -
315 maximumBlock = b; -
316 }
executed: }
Execution Count:40
40
317 b = b.next(); -
318 }
executed: }
Execution Count:854
854
319 if (maximumBlock.isValid()) {
partially evaluated: maximumBlock.isValid()
TRUEFALSE
yes
Evaluation Count:40
no
Evaluation Count:0
0-40
320 d->maximumWidthBlockNumber = maximumBlock.blockNumber(); -
321 emitDocumentSizeChanged = true; -
322 }
executed: }
Execution Count:40
40
323 }
executed: }
Execution Count:40
40
324 if (emitDocumentSizeChanged && !d->blockDocumentSizeChanged)
evaluated: emitDocumentSizeChanged
TRUEFALSE
yes
Evaluation Count:285
yes
Evaluation Count:503
evaluated: !d->blockDocumentSizeChanged
TRUEFALSE
yes
Evaluation Count:249
yes
Evaluation Count:36
36-503
325 documentSizeChanged(documentSize());
executed: documentSizeChanged(documentSize());
Execution Count:249
249
326}
executed: }
Execution Count:788
788
327 -
328qreal QPlainTextDocumentLayout::blockWidth(const QTextBlock &block) -
329{ -
330 QTextLayout *layout = block.layout(); -
331 if (!layout->lineCount())
evaluated: !layout->lineCount()
TRUEFALSE
yes
Evaluation Count:784
yes
Evaluation Count:73
73-784
332 return 0;
executed: return 0;
Execution Count:784
784
333 qreal blockWidth = 0; -
334 for (int i = 0; i < layout->lineCount(); ++i) {
evaluated: i < layout->lineCount()
TRUEFALSE
yes
Evaluation Count:75
yes
Evaluation Count:73
73-75
335 QTextLine line = layout->lineAt(i); -
336 blockWidth = qMax(line.naturalTextWidth() + 8, blockWidth); -
337 }
executed: }
Execution Count:75
75
338 return blockWidth;
executed: return blockWidth;
Execution Count:73
73
339} -
340 -
341 -
342QPlainTextEditControl::QPlainTextEditControl(QPlainTextEdit *parent) -
343 : QWidgetTextControl(parent), textEdit(parent), -
344 topBlock(0) -
345{ -
346 setAcceptRichText(false); -
347}
executed: }
Execution Count:87
87
348 -
349void QPlainTextEditPrivate::_q_cursorPositionChanged() -
350{ -
351 pageUpDownLastCursorYIsValid = false; -
352 QPlainTextEdit * const q = q_func(); -
353 -
354 QAccessibleTextCursorEvent ev(q, q->textCursor().position()); -
355 QAccessible::updateAccessibility(&ev); -
356 -
357 q->cursorPositionChanged(); -
358}
executed: }
Execution Count:250
250
359 -
360void QPlainTextEditPrivate::_q_verticalScrollbarActionTriggered(int action) { -
361 if (action == QAbstractSlider::SliderPageStepAdd) {
never evaluated: action == QAbstractSlider::SliderPageStepAdd
0
362 pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor, false); -
363 } else if (action == QAbstractSlider::SliderPageStepSub) {
never evaluated: action == QAbstractSlider::SliderPageStepSub
never executed: }
0
364 pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor, false); -
365 }
never executed: }
0
366} -
367 -
368QMimeData *QPlainTextEditControl::createMimeDataFromSelection() const { -
369 QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(parent()); -
370 if (!ed)
partially evaluated: !ed
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
371 return QWidgetTextControl::createMimeDataFromSelection();
never executed: return QWidgetTextControl::createMimeDataFromSelection();
0
372 return ed->createMimeDataFromSelection();
executed: return ed->createMimeDataFromSelection();
Execution Count:7
7
373 } -
374bool QPlainTextEditControl::canInsertFromMimeData(const QMimeData *source) const { -
375 QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(parent()); -
376 if (!ed)
partially evaluated: !ed
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
377 return QWidgetTextControl::canInsertFromMimeData(source);
never executed: return QWidgetTextControl::canInsertFromMimeData(source);
0
378 return ed->canInsertFromMimeData(source);
executed: return ed->canInsertFromMimeData(source);
Execution Count:9
9
379} -
380void QPlainTextEditControl::insertFromMimeData(const QMimeData *source) { -
381 QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(parent()); -
382 if (!ed)
partially evaluated: !ed
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
383 QWidgetTextControl::insertFromMimeData(source);
never executed: QWidgetTextControl::insertFromMimeData(source);
0
384 else -
385 ed->insertFromMimeData(source);
executed: ed->insertFromMimeData(source);
Execution Count:3
3
386} -
387 -
388qreal QPlainTextEditPrivate::verticalOffset(int topBlock, int topLine) const -
389{ -
390 qreal offset = 0; -
391 QTextDocument *doc = control->document(); -
392 -
393 if (topLine) {
evaluated: topLine
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:1476
7-1476
394 QTextBlock currentBlock = doc->findBlockByNumber(topBlock); -
395 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); -
396 qt_noop(); -
397 QRectF r = documentLayout->blockBoundingRect(currentBlock); -
398 (void)r;; -
399 QTextLayout *layout = currentBlock.layout(); -
400 if (layout && topLine <= layout->lineCount()) {
partially evaluated: layout
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
partially evaluated: topLine <= layout->lineCount()
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
401 QTextLine line = layout->lineAt(topLine - 1); -
402 const QRectF lr = line.naturalTextRect(); -
403 offset = lr.bottom(); -
404 }
executed: }
Execution Count:7
7
405 }
executed: }
Execution Count:7
7
406 if (topBlock == 0 && topLine == 0)
evaluated: topBlock == 0
TRUEFALSE
yes
Evaluation Count:1452
yes
Evaluation Count:31
evaluated: topLine == 0
TRUEFALSE
yes
Evaluation Count:1451
yes
Evaluation Count:1
1-1452
407 offset -= doc->documentMargin();
executed: offset -= doc->documentMargin();
Execution Count:1451
1451
408 return offset;
executed: return offset;
Execution Count:1483
1483
409} -
410 -
411 -
412qreal QPlainTextEditPrivate::verticalOffset() const { -
413 return verticalOffset(control->topBlock, topLine) + topLineFracture;
executed: return verticalOffset(control->topBlock, topLine) + topLineFracture;
Execution Count:1461
1461
414} -
415 -
416 -
417QTextBlock QPlainTextEditControl::firstVisibleBlock() const -
418{ -
419 return document()->findBlockByNumber(topBlock);
executed: return document()->findBlockByNumber(topBlock);
Execution Count:239
239
420} -
421 -
422 -
423 -
424int QPlainTextEditControl::hitTest(const QPointF &point, Qt::HitTestAccuracy ) const { -
425 int currentBlockNumber = topBlock; -
426 QTextBlock currentBlock = document()->findBlockByNumber(currentBlockNumber); -
427 if (!currentBlock.isValid())
never evaluated: !currentBlock.isValid()
0
428 return -1;
never executed: return -1;
0
429 -
430 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()); -
431 qt_noop(); -
432 -
433 QPointF offset; -
434 QRectF r = documentLayout->blockBoundingRect(currentBlock); -
435 while (currentBlock.next().isValid() && r.bottom() + offset.y() <= point.y()) {
never evaluated: currentBlock.next().isValid()
never evaluated: r.bottom() + offset.y() <= point.y()
0
436 offset.ry() += r.height(); -
437 currentBlock = currentBlock.next(); -
438 ++currentBlockNumber; -
439 r = documentLayout->blockBoundingRect(currentBlock); -
440 }
never executed: }
0
441 while (currentBlock.previous().isValid() && r.top() + offset.y() > point.y()) {
never evaluated: currentBlock.previous().isValid()
never evaluated: r.top() + offset.y() > point.y()
0
442 offset.ry() -= r.height(); -
443 currentBlock = currentBlock.previous(); -
444 --currentBlockNumber; -
445 r = documentLayout->blockBoundingRect(currentBlock); -
446 }
never executed: }
0
447 -
448 -
449 if (!currentBlock.isValid())
never evaluated: !currentBlock.isValid()
0
450 return -1;
never executed: return -1;
0
451 QTextLayout *layout = currentBlock.layout(); -
452 int off = 0; -
453 QPointF pos = point - offset; -
454 for (int i = 0; i < layout->lineCount(); ++i) {
never evaluated: i < layout->lineCount()
0
455 QTextLine line = layout->lineAt(i); -
456 const QRectF lr = line.naturalTextRect(); -
457 if (lr.top() > pos.y()) {
never evaluated: lr.top() > pos.y()
0
458 off = qMin(off, line.textStart()); -
459 } else if (lr.bottom() <= pos.y()) {
never evaluated: lr.bottom() <= pos.y()
never executed: }
0
460 off = qMax(off, line.textStart() + line.textLength()); -
461 } else {
never executed: }
0
462 off = line.xToCursor(pos.x(), overwriteMode() ? -
463 QTextLine::CursorOnCharacter : QTextLine::CursorBetweenCharacters); -
464 break;
never executed: break;
0
465 } -
466 } -
467 -
468 return currentBlock.position() + off;
never executed: return currentBlock.position() + off;
0
469} -
470 -
471QRectF QPlainTextEditControl::blockBoundingRect(const QTextBlock &block) const { -
472 int currentBlockNumber = topBlock; -
473 int blockNumber = block.blockNumber(); -
474 QTextBlock currentBlock = document()->findBlockByNumber(currentBlockNumber); -
475 if (!currentBlock.isValid())
partially evaluated: !currentBlock.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1262
0-1262
476 return QRectF();
never executed: return QRectF();
0
477 qt_noop(); -
478 QTextDocument *doc = document(); -
479 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); -
480 qt_noop(); -
481 -
482 QPointF offset; -
483 if (!block.isValid())
partially evaluated: !block.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1262
0-1262
484 return QRectF();
never executed: return QRectF();
0
485 QRectF r = documentLayout->blockBoundingRect(currentBlock); -
486 int maxVerticalOffset = r.height(); -
487 while (currentBlockNumber < blockNumber && offset.y() - maxVerticalOffset <= 2* textEdit->viewport()->height()) {
evaluated: currentBlockNumber < blockNumber
TRUEFALSE
yes
Evaluation Count:626
yes
Evaluation Count:1255
evaluated: offset.y() - maxVerticalOffset <= 2* textEdit->viewport()->height()
TRUEFALSE
yes
Evaluation Count:619
yes
Evaluation Count:7
7-1255
488 offset.ry() += r.height(); -
489 currentBlock = currentBlock.next(); -
490 ++currentBlockNumber; -
491 if (!currentBlock.isVisible()) {
partially evaluated: !currentBlock.isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:619
0-619
492 currentBlock = doc->findBlockByLineNumber(currentBlock.firstLineNumber()); -
493 currentBlockNumber = currentBlock.blockNumber(); -
494 }
never executed: }
0
495 r = documentLayout->blockBoundingRect(currentBlock); -
496 }
executed: }
Execution Count:619
619
497 while (currentBlockNumber > blockNumber && offset.y() + maxVerticalOffset >= -textEdit->viewport()->height()) {
evaluated: currentBlockNumber > blockNumber
TRUEFALSE
yes
Evaluation Count:108
yes
Evaluation Count:1257
evaluated: offset.y() + maxVerticalOffset >= -textEdit->viewport()->height()
TRUEFALSE
yes
Evaluation Count:103
yes
Evaluation Count:5
5-1257
498 currentBlock = currentBlock.previous(); -
499 --currentBlockNumber; -
500 while (!currentBlock.isVisible()) {
partially evaluated: !currentBlock.isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:103
0-103
501 currentBlock = currentBlock.previous(); -
502 --currentBlockNumber; -
503 }
never executed: }
0
504 if (!currentBlock.isValid())
partially evaluated: !currentBlock.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:103
0-103
505 break;
never executed: break;
0
506 -
507 r = documentLayout->blockBoundingRect(currentBlock); -
508 offset.ry() -= r.height(); -
509 }
executed: }
Execution Count:103
103
510 -
511 if (currentBlockNumber != blockNumber) {
evaluated: currentBlockNumber != blockNumber
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:1250
12-1250
512 -
513 -
514 r = documentLayout->blockBoundingRect(block); -
515 if (currentBlockNumber > blockNumber)
evaluated: currentBlockNumber > blockNumber
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:7
5-7
516 offset.ry() -= r.height();
executed: offset.ry() -= r.height();
Execution Count:5
5
517 }
executed: }
Execution Count:12
12
518 r.translate(offset); -
519 return r;
executed: return r;
Execution Count:1262
1262
520} -
521 -
522 -
523void QPlainTextEditPrivate::setTopLine(int visualTopLine, int dx) -
524{ -
525 QTextDocument *doc = control->document(); -
526 QTextBlock block = doc->findBlockByLineNumber(visualTopLine); -
527 int blockNumber = block.blockNumber(); -
528 int lineNumber = visualTopLine - block.firstLineNumber(); -
529 setTopBlock(blockNumber, lineNumber, dx); -
530}
executed: }
Execution Count:239
239
531 -
532void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx) -
533{ -
534 QPlainTextEdit * const q = q_func(); -
535 blockNumber = qMax(0, blockNumber); -
536 lineNumber = qMax(0, lineNumber); -
537 QTextDocument *doc = control->document(); -
538 QTextBlock block = doc->findBlockByNumber(blockNumber); -
539 -
540 int newTopLine = block.firstLineNumber() + lineNumber; -
541 int maxTopLine = vbar->maximum(); -
542 -
543 if (newTopLine > maxTopLine) {
partially evaluated: newTopLine > maxTopLine
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:251
0-251
544 block = doc->findBlockByLineNumber(maxTopLine); -
545 blockNumber = block.blockNumber(); -
546 lineNumber = maxTopLine - block.firstLineNumber(); -
547 }
never executed: }
0
548 -
549 bool vbarSignalsBlocked = vbar->blockSignals(true); -
550 vbar->setValue(newTopLine); -
551 vbar->blockSignals(vbarSignalsBlocked); -
552 -
553 if (!dx && blockNumber == control->topBlock && lineNumber == topLine)
evaluated: !dx
TRUEFALSE
yes
Evaluation Count:246
yes
Evaluation Count:5
evaluated: blockNumber == control->topBlock
TRUEFALSE
yes
Evaluation Count:238
yes
Evaluation Count:8
evaluated: lineNumber == topLine
TRUEFALSE
yes
Evaluation Count:237
yes
Evaluation Count:1
1-246
554 return;
executed: return;
Execution Count:237
237
555 -
556 if (viewport->updatesEnabled() && viewport->isVisible()) {
partially evaluated: viewport->updatesEnabled()
TRUEFALSE
yes
Evaluation Count:14
no
Evaluation Count:0
evaluated: viewport->isVisible()
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:3
0-14
557 int dy = 0; -
558 if (doc->findBlockByNumber(control->topBlock).isValid()) {
partially evaluated: doc->findBlockByNumber(control->topBlock).isValid()
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-11
559 qreal realdy = -q->blockBoundingGeometry(block).y() -
560 + verticalOffset() - verticalOffset(blockNumber, lineNumber); -
561 dy = (int)realdy; -
562 topLineFracture = realdy - dy; -
563 }
executed: }
Execution Count:11
11
564 control->topBlock = blockNumber; -
565 topLine = lineNumber; -
566 -
567 bool vbarSignalsBlocked = vbar->blockSignals(true); -
568 vbar->setValue(block.firstLineNumber() + lineNumber); -
569 vbar->blockSignals(vbarSignalsBlocked); -
570 -
571 if (dx || dy) {
evaluated: dx
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:7
partially evaluated: dy
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
572 viewport->scroll(q->isRightToLeft() ? -dx : dx, dy); -
573 } else {
executed: }
Execution Count:11
11
574 viewport->update(); -
575 topLineFracture = 0; -
576 }
never executed: }
0
577 q->updateRequest(viewport->rect(), dy); -
578 } else {
executed: }
Execution Count:11
11
579 control->topBlock = blockNumber; -
580 topLine = lineNumber; -
581 topLineFracture = 0; -
582 }
executed: }
Execution Count:3
3
583 -
584} -
585 -
586 -
587 -
588void QPlainTextEditPrivate::ensureVisible(int position, bool center, bool forceCenter) { -
589 QPlainTextEdit * const q = q_func(); -
590 QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset()); -
591 QTextBlock block = control->document()->findBlock(position); -
592 if (!block.isValid())
partially evaluated: !block.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
593 return;
never executed: return;
0
594 QRectF br = control->blockBoundingRect(block); -
595 if (!br.isValid())
partially evaluated: !br.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
596 return;
never executed: return;
0
597 QRectF lr = br; -
598 QTextLine line = block.layout()->lineForTextPosition(position - block.position()); -
599 qt_noop(); -
600 lr = line.naturalTextRect().translated(br.topLeft()); -
601 -
602 if (lr.bottom() >= visible.bottom() || (center && lr.top() < visible.top()) || forceCenter){
evaluated: lr.bottom() >= visible.bottom()
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:1
partially evaluated: center
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
never evaluated: lr.top() < visible.top()
partially evaluated: forceCenter
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-11
603 -
604 qreal height = visible.height(); -
605 if (center)
partially evaluated: center
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:11
0-11
606 height /= 2;
never executed: height /= 2;
0
607 -
608 qreal h = center ? line.naturalTextRect().center().y() : line.naturalTextRect().bottom();
partially evaluated: center
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:11
0-11
609 -
610 QTextBlock previousVisibleBlock = block; -
611 while (h < height && block.previous().isValid()) {
evaluated: h < height
TRUEFALSE
yes
Evaluation Count:40
yes
Evaluation Count:11
partially evaluated: block.previous().isValid()
TRUEFALSE
yes
Evaluation Count:40
no
Evaluation Count:0
0-40
612 previousVisibleBlock = block; -
613 do { -
614 block = block.previous(); -
615 } while (!block.isVisible() && block.previous().isValid());
executed: }
Execution Count:40
partially evaluated: !block.isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:40
never evaluated: block.previous().isValid()
0-40
616 h += q->blockBoundingRect(block).height(); -
617 }
executed: }
Execution Count:40
40
618 -
619 int l = 0; -
620 int lineCount = block.layout()->lineCount(); -
621 qreal voffset = verticalOffset(block.blockNumber(), 0); -
622 while (l < lineCount) {
evaluated: l < lineCount
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:8
8-21
623 QRectF lineRect = block.layout()->lineAt(l).naturalTextRect(); -
624 if (h - voffset - lineRect.top() <= height)
evaluated: h - voffset - lineRect.top() <= height
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:18
3-18
625 break;
executed: break;
Execution Count:3
3
626 ++l; -
627 }
executed: }
Execution Count:18
18
628 -
629 if (l >= lineCount) {
evaluated: l >= lineCount
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:3
3-8
630 block = previousVisibleBlock; -
631 l = 0; -
632 }
executed: }
Execution Count:8
8
633 setTopBlock(block.blockNumber(), l); -
634 } else if (lr.top() < visible.top()) {
executed: }
Execution Count:11
partially evaluated: lr.top() < visible.top()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-11
635 setTopBlock(block.blockNumber(), line.lineNumber()); -
636 }
executed: }
Execution Count:1
1
637 -
638} -
639 -
640 -
641void QPlainTextEditPrivate::updateViewport() -
642{ -
643 QPlainTextEdit * const q = q_func(); -
644 viewport->update(); -
645 q->updateRequest(viewport->rect(), 0); -
646}
executed: }
Execution Count:3
3
647 -
648QPlainTextEditPrivate::QPlainTextEditPrivate() -
649 : control(0), -
650 tabChangesFocus(false), -
651 lineWrap(QPlainTextEdit::WidgetWidth), -
652 wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), -
653 clickCausedFocus(0),topLine(0),topLineFracture(0), -
654 pageUpDownLastCursorYIsValid(false) -
655{ -
656 showCursorOnInitialShow = true; -
657 backgroundVisible = false; -
658 centerOnScroll = false; -
659 inDrag = false; -
660}
executed: }
Execution Count:87
87
661 -
662 -
663void QPlainTextEditPrivate::init(const QString &txt) -
664{ -
665 QPlainTextEdit * const q = q_func(); -
666 control = new QPlainTextEditControl(q); -
667 -
668 QTextDocument *doc = new QTextDocument(control); -
669 QAbstractTextDocumentLayout *layout = new QPlainTextDocumentLayout(doc); -
670 doc->setDocumentLayout(layout); -
671 control->setDocument(doc); -
672 -
673 control->setPalette(q->palette()); -
674 -
675 QObject::connect(vbar, "2""actionTriggered(int)", q, "1""_q_verticalScrollbarActionTriggered(int)"); -
676 -
677 QObject::connect(control, "2""microFocusChanged()", q, "1""updateMicroFocus()"); -
678 QObject::connect(control, "2""documentSizeChanged(QSizeF)", q, "1""_q_adjustScrollbars()"); -
679 QObject::connect(control, "2""blockCountChanged(int)", q, "2""blockCountChanged(int)"); -
680 QObject::connect(control, "2""updateRequest(QRectF)", q, "1""_q_repaintContents(QRectF)"); -
681 QObject::connect(control, "2""modificationChanged(bool)", q, "2""modificationChanged(bool)"); -
682 -
683 QObject::connect(control, "2""textChanged()", q, "2""textChanged()"); -
684 QObject::connect(control, "2""undoAvailable(bool)", q, "2""undoAvailable(bool)"); -
685 QObject::connect(control, "2""redoAvailable(bool)", q, "2""redoAvailable(bool)"); -
686 QObject::connect(control, "2""copyAvailable(bool)", q, "2""copyAvailable(bool)"); -
687 QObject::connect(control, "2""selectionChanged()", q, "2""selectionChanged()"); -
688 QObject::connect(control, "2""cursorPositionChanged()", q, "1""_q_cursorPositionChanged()"); -
689 -
690 QObject::connect(control, "2""textChanged()", q, "1""updateMicroFocus()"); -
691 -
692 -
693 -
694 -
695 doc->setTextWidth(-1); -
696 doc->documentLayout()->setPaintDevice(viewport); -
697 doc->setDefaultFont(q->font()); -
698 -
699 -
700 if (!txt.isEmpty())
partially evaluated: !txt.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:87
0-87
701 control->setPlainText(txt);
never executed: control->setPlainText(txt);
0
702 -
703 hbar->setSingleStep(20); -
704 vbar->setSingleStep(1); -
705 -
706 viewport->setBackgroundRole(QPalette::Base); -
707 q->setAcceptDrops(true); -
708 q->setFocusPolicy(Qt::WheelFocus); -
709 q->setAttribute(Qt::WA_KeyCompression); -
710 q->setAttribute(Qt::WA_InputMethodEnabled); -
711 -
712 -
713 viewport->setCursor(Qt::IBeamCursor); -
714 -
715 originalOffsetY = 0; -
716 -
717 -
718 -
719}
executed: }
Execution Count:87
87
720 -
721void QPlainTextEditPrivate::_q_repaintContents(const QRectF &contentsRect) -
722{ -
723 QPlainTextEdit * const q = q_func(); -
724 if (!contentsRect.isValid()) {
evaluated: !contentsRect.isValid()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:753
3-753
725 updateViewport(); -
726 return;
executed: return;
Execution Count:3
3
727 } -
728 const int xOffset = horizontalOffset(); -
729 const int yOffset = (int)verticalOffset(); -
730 const QRect visibleRect(xOffset, yOffset, viewport->width(), viewport->height()); -
731 -
732 QRect r = contentsRect.adjusted(-1, -1, 1, 1).intersected(visibleRect).toAlignedRect(); -
733 if (r.isEmpty())
evaluated: r.isEmpty()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:747
6-747
734 return;
executed: return;
Execution Count:6
6
735 -
736 r.translate(-xOffset, -yOffset); -
737 viewport->update(r); -
738 q->updateRequest(r, 0); -
739}
executed: }
Execution Count:747
747
740 -
741void QPlainTextEditPrivate::pageUpDown(QTextCursor::MoveOperation op, QTextCursor::MoveMode moveMode, bool moveCursor) -
742{ -
743 -
744 QPlainTextEdit * const q = q_func(); -
745 -
746 QTextCursor cursor = control->textCursor(); -
747 if (moveCursor) {
never evaluated: moveCursor
0
748 ensureCursorVisible(); -
749 if (!pageUpDownLastCursorYIsValid)
never evaluated: !pageUpDownLastCursorYIsValid
0
750 pageUpDownLastCursorY = control->cursorRect(cursor).top() - verticalOffset();
never executed: pageUpDownLastCursorY = control->cursorRect(cursor).top() - verticalOffset();
0
751 }
never executed: }
0
752 -
753 qreal lastY = pageUpDownLastCursorY; -
754 -
755 -
756 if (op == QTextCursor::Down) {
never evaluated: op == QTextCursor::Down
0
757 QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset()); -
758 QTextBlock firstVisibleBlock = q->firstVisibleBlock(); -
759 QTextBlock block = firstVisibleBlock; -
760 QRectF br = q->blockBoundingRect(block); -
761 qreal h = 0; -
762 int atEnd = false; -
763 while (h + br.height() <= visible.bottom()) {
never evaluated: h + br.height() <= visible.bottom()
0
764 if (!block.next().isValid()) {
never evaluated: !block.next().isValid()
0
765 atEnd = true; -
766 lastY = visible.bottom(); -
767 break;
never executed: break;
0
768 } -
769 h += br.height(); -
770 block = block.next(); -
771 br = q->blockBoundingRect(block); -
772 }
never executed: }
0
773 -
774 if (!atEnd) {
never evaluated: !atEnd
0
775 int line = 0; -
776 qreal diff = visible.bottom() - h; -
777 int lineCount = block.layout()->lineCount(); -
778 while (line < lineCount - 1) {
never evaluated: line < lineCount - 1
0
779 if (block.layout()->lineAt(line).naturalTextRect().bottom() > diff) {
never evaluated: block.layout()->lineAt(line).naturalTextRect().bottom() > diff
0
780 -
781 break;
never executed: break;
0
782 } -
783 ++line; -
784 }
never executed: }
0
785 setTopBlock(block.blockNumber(), line); -
786 }
never executed: }
0
787 -
788 if (moveCursor) {
never evaluated: moveCursor
0
789 -
790 lastY += verticalOffset(); -
791 bool moved = false; -
792 do { -
793 moved = cursor.movePosition(op, moveMode); -
794 } while (moved && control->cursorRect(cursor).top() < lastY);
never executed: }
never evaluated: moved
never evaluated: control->cursorRect(cursor).top() < lastY
0
795 }
never executed: }
0
796 -
797 } else if (op == QTextCursor::Up) {
never executed: }
never evaluated: op == QTextCursor::Up
0
798 -
799 QRectF visible = QRectF(viewport->rect()).translated(-q->contentOffset()); -
800 visible.translate(0, -visible.height()); -
801 QTextBlock block = q->firstVisibleBlock(); -
802 qreal h = 0; -
803 while (h >= visible.top()) {
never evaluated: h >= visible.top()
0
804 if (!block.previous().isValid()) {
never evaluated: !block.previous().isValid()
0
805 if (control->topBlock == 0 && topLine == 0) {
never evaluated: control->topBlock == 0
never evaluated: topLine == 0
0
806 lastY = 0; -
807 }
never executed: }
0
808 break;
never executed: break;
0
809 } -
810 block = block.previous(); -
811 QRectF br = q->blockBoundingRect(block); -
812 h -= br.height(); -
813 }
never executed: }
0
814 -
815 int line = 0; -
816 if (block.isValid()) {
never evaluated: block.isValid()
0
817 qreal diff = visible.top() - h; -
818 int lineCount = block.layout()->lineCount(); -
819 while (line < lineCount) {
never evaluated: line < lineCount
0
820 if (block.layout()->lineAt(line).naturalTextRect().top() >= diff)
never evaluated: block.layout()->lineAt(line).naturalTextRect().top() >= diff
0
821 break;
never executed: break;
0
822 ++line; -
823 }
never executed: }
0
824 if (line == lineCount) {
never evaluated: line == lineCount
0
825 if (block.next().isValid() && block.next() != q->firstVisibleBlock()) {
never evaluated: block.next().isValid()
never evaluated: block.next() != q->firstVisibleBlock()
0
826 block = block.next(); -
827 line = 0; -
828 } else {
never executed: }
0
829 --line; -
830 }
never executed: }
0
831 } -
832 }
never executed: }
0
833 setTopBlock(block.blockNumber(), line); -
834 -
835 if (moveCursor) {
never evaluated: moveCursor
0
836 cursor.setVisualNavigation(true); -
837 -
838 lastY += verticalOffset(); -
839 bool moved = false; -
840 do { -
841 moved = cursor.movePosition(op, moveMode); -
842 } while (moved && control->cursorRect(cursor).top() > lastY);
never executed: }
never evaluated: moved
never evaluated: control->cursorRect(cursor).top() > lastY
0
843 }
never executed: }
0
844 }
never executed: }
0
845 -
846 if (moveCursor) {
never evaluated: moveCursor
0
847 control->setTextCursor(cursor); -
848 pageUpDownLastCursorYIsValid = true; -
849 }
never executed: }
0
850}
never executed: }
0
851 -
852 -
853 -
854void QPlainTextEditPrivate::_q_adjustScrollbars() -
855{ -
856 QPlainTextEdit * const q = q_func(); -
857 QTextDocument *doc = control->document(); -
858 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); -
859 qt_noop(); -
860 bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged; -
861 documentLayout->priv()->blockDocumentSizeChanged = true; -
862 qreal margin = doc->documentMargin(); -
863 -
864 int vmax = 0; -
865 -
866 int vSliderLength = 0; -
867 if (!centerOnScroll && q->isVisible()) {
partially evaluated: !centerOnScroll
TRUEFALSE
yes
Evaluation Count:232
no
Evaluation Count:0
evaluated: q->isVisible()
TRUEFALSE
yes
Evaluation Count:42
yes
Evaluation Count:190
0-232
868 QTextBlock block = doc->lastBlock(); -
869 const qreal visible = viewport->rect().height() - margin - 1; -
870 qreal y = 0; -
871 int visibleFromBottom = 0; -
872 -
873 while (block.isValid()) {
evaluated: block.isValid()
TRUEFALSE
yes
Evaluation Count:90
yes
Evaluation Count:16
16-90
874 if (!block.isVisible()) {
partially evaluated: !block.isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:90
0-90
875 block = block.previous(); -
876 continue;
never executed: continue;
0
877 } -
878 y += documentLayout->blockBoundingRect(block).height(); -
879 -
880 QTextLayout *layout = block.layout(); -
881 int layoutLineCount = layout->lineCount(); -
882 if (y > visible) {
evaluated: y > visible
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:64
26-64
883 int lineNumber = 0; -
884 while (lineNumber < layoutLineCount) {
evaluated: lineNumber < layoutLineCount
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:16
16-48
885 QTextLine line = layout->lineAt(lineNumber); -
886 const QRectF lr = line.naturalTextRect(); -
887 if (lr.top() >= y - visible)
evaluated: lr.top() >= y - visible
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:38
10-38
888 break;
executed: break;
Execution Count:10
10
889 ++lineNumber; -
890 }
executed: }
Execution Count:38
38
891 if (lineNumber < layoutLineCount)
evaluated: lineNumber < layoutLineCount
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:16
10-16
892 visibleFromBottom += (layoutLineCount - lineNumber);
executed: visibleFromBottom += (layoutLineCount - lineNumber);
Execution Count:10
10
893 break;
executed: break;
Execution Count:26
26
894 -
895 } -
896 visibleFromBottom += layoutLineCount; -
897 block = block.previous(); -
898 }
executed: }
Execution Count:64
64
899 vmax = qMax(0, doc->lineCount() - visibleFromBottom); -
900 vSliderLength = visibleFromBottom; -
901 -
902 } else {
executed: }
Execution Count:42
42
903 vmax = qMax(0, doc->lineCount() - 1); -
904 vSliderLength = viewport->height() / q->fontMetrics().lineSpacing(); -
905 }
executed: }
Execution Count:190
190
906 -
907 -
908 -
909 QSizeF documentSize = documentLayout->documentSize(); -
910 vbar->setRange(0, qMax(0, vmax)); -
911 vbar->setPageStep(vSliderLength); -
912 int visualTopLine = vmax; -
913 QTextBlock firstVisibleBlock = q->firstVisibleBlock(); -
914 if (firstVisibleBlock.isValid())
partially evaluated: firstVisibleBlock.isValid()
TRUEFALSE
yes
Evaluation Count:232
no
Evaluation Count:0
0-232
915 visualTopLine = firstVisibleBlock.firstLineNumber() + topLine;
executed: visualTopLine = firstVisibleBlock.firstLineNumber() + topLine;
Execution Count:232
232
916 bool vbarSignalsBlocked = vbar->blockSignals(true); -
917 vbar->setValue(visualTopLine); -
918 vbar->blockSignals(vbarSignalsBlocked); -
919 -
920 hbar->setRange(0, (int)documentSize.width() - viewport->width()); -
921 hbar->setPageStep(viewport->width()); -
922 documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked; -
923 setTopLine(vbar->value()); -
924}
executed: }
Execution Count:232
232
925 -
926 -
927 -
928 -
929void QPlainTextEditPrivate::ensureViewportLayouted() -
930{ -
931} -
932QPlainTextEdit::QPlainTextEdit(QWidget *parent) -
933 : QAbstractScrollArea(*new QPlainTextEditPrivate, parent) -
934{ -
935 QPlainTextEditPrivate * const d = d_func(); -
936 d->init(); -
937}
executed: }
Execution Count:87
87
938 -
939 -
940 -
941 -
942QPlainTextEdit::QPlainTextEdit(QPlainTextEditPrivate &dd, QWidget *parent) -
943 : QAbstractScrollArea(dd, parent) -
944{ -
945 QPlainTextEditPrivate * const d = d_func(); -
946 d->init(); -
947}
never executed: }
0
948 -
949 -
950 -
951 -
952 -
953QPlainTextEdit::QPlainTextEdit(const QString &text, QWidget *parent) -
954 : QAbstractScrollArea(*new QPlainTextEditPrivate, parent) -
955{ -
956 QPlainTextEditPrivate * const d = d_func(); -
957 d->init(text); -
958}
never executed: }
0
959 -
960 -
961 -
962 -
963 -
964QPlainTextEdit::~QPlainTextEdit() -
965{ -
966 QPlainTextEditPrivate * const d = d_func(); -
967 if (d->documentLayoutPtr) {
evaluated: d->documentLayoutPtr
TRUEFALSE
yes
Evaluation Count:19
yes
Evaluation Count:68
19-68
968 if (d->documentLayoutPtr->priv()->mainViewPrivate == d)
partially evaluated: d->documentLayoutPtr->priv()->mainViewPrivate == d
TRUEFALSE
yes
Evaluation Count:19
no
Evaluation Count:0
0-19
969 d->documentLayoutPtr->priv()->mainViewPrivate = 0;
executed: d->documentLayoutPtr->priv()->mainViewPrivate = 0;
Execution Count:19
19
970 }
executed: }
Execution Count:19
19
971}
executed: }
Execution Count:87
87
972void QPlainTextEdit::setDocument(QTextDocument *document) -
973{ -
974 QPlainTextEditPrivate * const d = d_func(); -
975 QPlainTextDocumentLayout *documentLayout = 0; -
976 -
977 if (!document) {
evaluated: !document
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
978 document = new QTextDocument(d->control); -
979 documentLayout = new QPlainTextDocumentLayout(document); -
980 document->setDocumentLayout(documentLayout); -
981 } else {
executed: }
Execution Count:1
1
982 documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document->documentLayout()); -
983 if (!documentLayout) {
partially evaluated: !documentLayout
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
984 QMessageLogger("widgets/qplaintextedit.cpp", 1294, __PRETTY_FUNCTION__).warning("QPlainTextEdit::setDocument: Document set does not support QPlainTextDocumentLayout"); -
985 return;
never executed: return;
0
986 } -
987 }
executed: }
Execution Count:4
4
988 d->control->setDocument(document); -
989 if (!documentLayout->priv()->mainViewPrivate)
partially evaluated: !documentLayout->priv()->mainViewPrivate
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-5
990 documentLayout->priv()->mainViewPrivate = d;
executed: documentLayout->priv()->mainViewPrivate = d;
Execution Count:5
5
991 d->documentLayoutPtr = documentLayout; -
992 d->updateDefaultTextOption(); -
993 d->relayoutDocument(); -
994 d->_q_adjustScrollbars(); -
995}
executed: }
Execution Count:5
5
996 -
997 -
998 -
999 -
1000 -
1001 -
1002QTextDocument *QPlainTextEdit::document() const -
1003{ -
1004 const QPlainTextEditPrivate * const d = d_func(); -
1005 return d->control->document();
executed: return d->control->document();
Execution Count:218
218
1006} -
1007 -
1008 -
1009 -
1010 -
1011void QPlainTextEdit::setTextCursor(const QTextCursor &cursor) -
1012{ -
1013 doSetTextCursor(cursor); -
1014}
executed: }
Execution Count:16
16
1015 -
1016 -
1017 -
1018 -
1019 -
1020 -
1021 -
1022void QPlainTextEdit::doSetTextCursor(const QTextCursor &cursor) -
1023{ -
1024 QPlainTextEditPrivate * const d = d_func(); -
1025 d->control->setTextCursor(cursor); -
1026}
executed: }
Execution Count:16
16
1027 -
1028 -
1029 -
1030 -
1031 -
1032 -
1033QTextCursor QPlainTextEdit::textCursor() const -
1034{ -
1035 const QPlainTextEditPrivate * const d = d_func(); -
1036 return d->control->textCursor();
executed: return d->control->textCursor();
Execution Count:323
323
1037} -
1038 -
1039 -
1040 -
1041 -
1042 -
1043 -
1044 -
1045QString QPlainTextEdit::anchorAt(const QPoint &pos) const -
1046{ -
1047 const QPlainTextEditPrivate * const d = d_func(); -
1048 int cursorPos = d->control->hitTest(pos + QPointF(d->horizontalOffset(), -
1049 d->verticalOffset()), -
1050 Qt::ExactHit); -
1051 if (cursorPos < 0)
never evaluated: cursorPos < 0
0
1052 return QString();
never executed: return QString();
0
1053 -
1054 QTextDocumentPrivate *pieceTable = document()->docHandle(); -
1055 QTextDocumentPrivate::FragmentIterator it = pieceTable->find(cursorPos); -
1056 QTextCharFormat fmt = pieceTable->formatCollection()->charFormat(it->format); -
1057 return fmt.anchorHref();
never executed: return fmt.anchorHref();
0
1058} -
1059void QPlainTextEdit::undo() -
1060{ -
1061 QPlainTextEditPrivate * const d = d_func(); -
1062 d->control->undo(); -
1063}
executed: }
Execution Count:5
5
1064 -
1065void QPlainTextEdit::redo() -
1066{ -
1067 QPlainTextEditPrivate * const d = d_func(); -
1068 d->control->redo(); -
1069}
executed: }
Execution Count:5
5
1070void QPlainTextEdit::cut() -
1071{ -
1072 QPlainTextEditPrivate * const d = d_func(); -
1073 d->control->cut(); -
1074}
executed: }
Execution Count:2
2
1075 -
1076 -
1077 -
1078 -
1079 -
1080 -
1081 -
1082void QPlainTextEdit::copy() -
1083{ -
1084 QPlainTextEditPrivate * const d = d_func(); -
1085 d->control->copy(); -
1086}
executed: }
Execution Count:2
2
1087void QPlainTextEdit::paste() -
1088{ -
1089 QPlainTextEditPrivate * const d = d_func(); -
1090 d->control->paste(); -
1091}
executed: }
Execution Count:3
3
1092void QPlainTextEdit::clear() -
1093{ -
1094 QPlainTextEditPrivate * const d = d_func(); -
1095 -
1096 d->control->topBlock = d->topLine = d->topLineFracture = 0; -
1097 d->control->clear(); -
1098}
executed: }
Execution Count:11
11
1099 -
1100 -
1101 -
1102 -
1103 -
1104 -
1105 -
1106void QPlainTextEdit::selectAll() -
1107{ -
1108 QPlainTextEditPrivate * const d = d_func(); -
1109 d->control->selectAll(); -
1110}
executed: }
Execution Count:2
2
1111 -
1112 -
1113 -
1114bool QPlainTextEdit::event(QEvent *e) -
1115{ -
1116 QPlainTextEditPrivate * const d = d_func(); -
1117 -
1118 -
1119 if (e->type() == QEvent::ContextMenu
partially evaluated: e->type() == QEvent::ContextMenu
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:847
0-847
1120 && static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard) {
never evaluated: static_cast<QContextMenuEvent *>(e)->reason() == QContextMenuEvent::Keyboard
0
1121 ensureCursorVisible(); -
1122 const QPoint cursorPos = cursorRect().center(); -
1123 QContextMenuEvent ce(QContextMenuEvent::Keyboard, cursorPos, d->viewport->mapToGlobal(cursorPos)); -
1124 ce.setAccepted(e->isAccepted()); -
1125 const bool result = QAbstractScrollArea::event(&ce); -
1126 e->setAccepted(ce.isAccepted()); -
1127 return result;
never executed: return result;
0
1128 } -
1129 -
1130 if (e->type() == QEvent::ShortcutOverride
evaluated: e->type() == QEvent::ShortcutOverride
TRUEFALSE
yes
Evaluation Count:150
yes
Evaluation Count:697
150-697
1131 || e->type() == QEvent::ToolTip) {
partially evaluated: e->type() == QEvent::ToolTip
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:697
0-697
1132 d->sendControlEvent(e); -
1133 }
executed: }
Execution Count:150
150
1134 -
1135 -
1136 -
1137 -
1138 -
1139 -
1140 -
1141 else if (e->type() == QEvent::Gesture) {
partially evaluated: e->type() == QEvent::Gesture
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:697
0-697
1142 QGestureEvent *ge = static_cast<QGestureEvent *>(e); -
1143 QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture)); -
1144 if (g) {
never evaluated: g
0
1145 QScrollBar *hBar = horizontalScrollBar(); -
1146 QScrollBar *vBar = verticalScrollBar(); -
1147 if (g->state() == Qt::GestureStarted)
never evaluated: g->state() == Qt::GestureStarted
0
1148 d->originalOffsetY = vBar->value();
never executed: d->originalOffsetY = vBar->value();
0
1149 QPointF offset = g->offset(); -
1150 if (!offset.isNull()) {
never evaluated: !offset.isNull()
0
1151 if (QApplication::isRightToLeft())
never evaluated: QApplication::isRightToLeft()
0
1152 offset.rx() *= -1;
never executed: offset.rx() *= -1;
0
1153 -
1154 QFontMetrics fm(document()->defaultFont()); -
1155 int lineHeight = fm.height(); -
1156 int newX = hBar->value() - g->delta().x(); -
1157 int newY = d->originalOffsetY - offset.y()/lineHeight; -
1158 hBar->setValue(newX); -
1159 vBar->setValue(newY); -
1160 }
never executed: }
0
1161 }
never executed: }
0
1162 return true;
never executed: return true;
0
1163 } -
1164 -
1165 return QAbstractScrollArea::event(e);
executed: return QAbstractScrollArea::event(e);
Execution Count:847
847
1166} -
1167 -
1168 -
1169 -
1170 -
1171void QPlainTextEdit::timerEvent(QTimerEvent *e) -
1172{ -
1173 QPlainTextEditPrivate * const d = d_func(); -
1174 if (e->timerId() == d->autoScrollTimer.timerId()) {
never evaluated: e->timerId() == d->autoScrollTimer.timerId()
0
1175 QRect visible = d->viewport->rect(); -
1176 QPoint pos; -
1177 if (d->inDrag) {
never evaluated: d->inDrag
0
1178 pos = d->autoScrollDragPos; -
1179 visible.adjust(qMin(visible.width()/3,20), qMin(visible.height()/3,20), -
1180 -qMin(visible.width()/3,20), -qMin(visible.height()/3,20)); -
1181 } else {
never executed: }
0
1182 const QPoint globalPos = QCursor::pos(); -
1183 pos = d->viewport->mapFromGlobal(globalPos); -
1184 QMouseEvent ev(QEvent::MouseMove, pos, d->viewport->mapTo(d->viewport->topLevelWidget(), pos), globalPos, -
1185 Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); -
1186 mouseMoveEvent(&ev); -
1187 }
never executed: }
0
1188 int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height(); -
1189 int deltaX = qMax(pos.x() - visible.left(), visible.right() - pos.x()) - visible.width(); -
1190 int delta = qMax(deltaX, deltaY); -
1191 if (delta >= 0) {
never evaluated: delta >= 0
0
1192 if (delta < 7)
never evaluated: delta < 7
0
1193 delta = 7;
never executed: delta = 7;
0
1194 int timeout = 4900 / (delta * delta); -
1195 d->autoScrollTimer.start(timeout, this); -
1196 -
1197 if (deltaY > 0)
never evaluated: deltaY > 0
0
1198 d->vbar->triggerAction(pos.y() < visible.center().y() ? 0
1199 QAbstractSlider::SliderSingleStepSub 0
1200 : QAbstractSlider::SliderSingleStepAdd);
never executed: d->vbar->triggerAction(pos.y() < visible.center().y() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1201 if (deltaX > 0)
never evaluated: deltaX > 0
0
1202 d->hbar->triggerAction(pos.x() < visible.center().x() ? 0
1203 QAbstractSlider::SliderSingleStepSub 0
1204 : QAbstractSlider::SliderSingleStepAdd);
never executed: d->hbar->triggerAction(pos.x() < visible.center().x() ? QAbstractSlider::SliderSingleStepSub : QAbstractSlider::SliderSingleStepAdd);
0
1205 }
never executed: }
0
1206 }
never executed: }
0
1207 -
1208 -
1209 -
1210 -
1211 -
1212 -
1213}
never executed: }
0
1214void QPlainTextEdit::setPlainText(const QString &text) -
1215{ -
1216 QPlainTextEditPrivate * const d = d_func(); -
1217 d->control->setPlainText(text); -
1218}
executed: }
Execution Count:59
59
1219void QPlainTextEdit::keyPressEvent(QKeyEvent *e) -
1220{ -
1221 QPlainTextEditPrivate * const d = d_func(); -
1222 Qt::TextInteractionFlags tif = d->control->textInteractionFlags(); -
1223 -
1224 if (tif & Qt::TextSelectableByKeyboard){
evaluated: tif & Qt::TextSelectableByKeyboard
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:5
5-144
1225 if (e == QKeySequence::SelectPreviousPage) {
partially evaluated: e == QKeySequence::SelectPreviousPage
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:144
0-144
1226 e->accept(); -
1227 d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor); -
1228 return;
never executed: return;
0
1229 } else if (e ==QKeySequence::SelectNextPage) {
partially evaluated: e ==QKeySequence::SelectNextPage
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:144
0-144
1230 e->accept(); -
1231 d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor); -
1232 return;
never executed: return;
0
1233 } -
1234 } -
1235 if (tif & (Qt::TextSelectableByKeyboard | Qt::TextEditable)) {
evaluated: tif & (Qt::TextSelectableByKeyboard | Qt::TextEditable)
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:5
5-144
1236 if (e == QKeySequence::MoveToPreviousPage) {
partially evaluated: e == QKeySequence::MoveToPreviousPage
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:144
0-144
1237 e->accept(); -
1238 d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor); -
1239 return;
never executed: return;
0
1240 } else if (e == QKeySequence::MoveToNextPage) {
partially evaluated: e == QKeySequence::MoveToNextPage
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:144
0-144
1241 e->accept(); -
1242 d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor); -
1243 return;
never executed: return;
0
1244 } -
1245 } -
1246 -
1247 if (!(tif & Qt::TextEditable)) {
evaluated: !(tif & Qt::TextEditable)
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:144
5-144
1248 switch (e->key()) { -
1249 case Qt::Key_Space: -
1250 e->accept(); -
1251 if (e->modifiers() & Qt::ShiftModifier)
never evaluated: e->modifiers() & Qt::ShiftModifier
0
1252 d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
never executed: d->vbar->triggerAction(QAbstractSlider::SliderPageStepSub);
0
1253 else -
1254 d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
never executed: d->vbar->triggerAction(QAbstractSlider::SliderPageStepAdd);
0
1255 break;
never executed: break;
0
1256 default: -
1257 d->sendControlEvent(e); -
1258 if (!e->isAccepted() && e->modifiers() == Qt::NoModifier) {
evaluated: !e->isAccepted()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
evaluated: e->modifiers() == Qt::NoModifier
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-3
1259 if (e->key() == Qt::Key_Home) {
partially evaluated: e->key() == Qt::Key_Home
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1260 d->vbar->triggerAction(QAbstractSlider::SliderToMinimum); -
1261 e->accept(); -
1262 } else if (e->key() == Qt::Key_End) {
never executed: }
partially evaluated: e->key() == Qt::Key_End
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1263 d->vbar->triggerAction(QAbstractSlider::SliderToMaximum); -
1264 e->accept(); -
1265 }
never executed: }
0
1266 } -
1267 if (!e->isAccepted()) {
evaluated: !e->isAccepted()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
1268 QAbstractScrollArea::keyPressEvent(e); -
1269 }
executed: }
Execution Count:3
3
1270 }
executed: }
Execution Count:5
5
1271 return;
executed: return;
Execution Count:5
5
1272 } -
1273 -
1274 -
1275 d->sendControlEvent(e); -
1276}
executed: }
Execution Count:144
144
1277 -
1278 -
1279 -
1280void QPlainTextEdit::keyReleaseEvent(QKeyEvent *e) -
1281{ -
1282 (void)e;; -
1283 -
1284}
executed: }
Execution Count:150
150
1285QVariant QPlainTextEdit::loadResource(int type, const QUrl &name) -
1286{ -
1287 (void)type;; -
1288 (void)name;; -
1289 return QVariant();
executed: return QVariant();
Execution Count:1
1
1290} -
1291 -
1292 -
1293 -
1294void QPlainTextEdit::resizeEvent(QResizeEvent *e) -
1295{ -
1296 QPlainTextEditPrivate * const d = d_func(); -
1297 if (e->oldSize().width() != e->size().width())
partially evaluated: e->oldSize().width() != e->size().width()
TRUEFALSE
yes
Evaluation Count:20
no
Evaluation Count:0
0-20
1298 d->relayoutDocument();
executed: d->relayoutDocument();
Execution Count:20
20
1299 d->_q_adjustScrollbars(); -
1300}
executed: }
Execution Count:20
20
1301 -
1302void QPlainTextEditPrivate::relayoutDocument() -
1303{ -
1304 QTextDocument *doc = control->document(); -
1305 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); -
1306 qt_noop(); -
1307 documentLayoutPtr = documentLayout; -
1308 -
1309 int width = viewport->width(); -
1310 -
1311 if (documentLayout->priv()->mainViewPrivate == 0
evaluated: documentLayout->priv()->mainViewPrivate == 0
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:16
15-16
1312 || documentLayout->priv()->mainViewPrivate == this
partially evaluated: documentLayout->priv()->mainViewPrivate == this
TRUEFALSE
yes
Evaluation Count:16
no
Evaluation Count:0
0-16
1313 || width > documentLayout->textWidth()) {
never evaluated: width > documentLayout->textWidth()
0
1314 documentLayout->priv()->mainViewPrivate = this; -
1315 documentLayout->setTextWidth(width); -
1316 }
executed: }
Execution Count:31
31
1317}
executed: }
Execution Count:31
31
1318 -
1319static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, QRectF gradientRect = QRectF()) -
1320{ -
1321 p->save(); -
1322 if (brush.style() >= Qt::LinearGradientPattern && brush.style() <= Qt::ConicalGradientPattern) {
never evaluated: brush.style() >= Qt::LinearGradientPattern
never evaluated: brush.style() <= Qt::ConicalGradientPattern
0
1323 if (!gradientRect.isNull()) {
never evaluated: !gradientRect.isNull()
0
1324 QTransform m = QTransform::fromTranslate(gradientRect.left(), gradientRect.top()); -
1325 m.scale(gradientRect.width(), gradientRect.height()); -
1326 brush.setTransform(m); -
1327 const_cast<QGradient *>(brush.gradient())->setCoordinateMode(QGradient::LogicalMode); -
1328 }
never executed: }
0
1329 } else {
never executed: }
0
1330 p->setBrushOrigin(rect.topLeft()); -
1331 }
never executed: }
0
1332 p->fillRect(rect, brush); -
1333 p->restore(); -
1334}
never executed: }
0
1335 -
1336 -
1337 -
1338 -
1339 -
1340void QPlainTextEdit::paintEvent(QPaintEvent *e) -
1341{ -
1342 QPainter painter(viewport()); -
1343 qt_noop(); -
1344 -
1345 QPointF offset(contentOffset()); -
1346 -
1347 QRect er = e->rect(); -
1348 QRect viewportRect = viewport()->rect(); -
1349 -
1350 bool editable = !isReadOnly(); -
1351 -
1352 QTextBlock block = firstVisibleBlock(); -
1353 qreal maximumWidth = document()->documentLayout()->documentSize().width(); -
1354 -
1355 -
1356 painter.setBrushOrigin(offset); -
1357 -
1358 -
1359 int maxX = offset.x() + qMax((qreal)viewportRect.width(), maximumWidth) -
1360 - document()->documentMargin(); -
1361 er.setRight(qMin(er.right(), maxX)); -
1362 painter.setClipRect(er); -
1363 -
1364 -
1365 QAbstractTextDocumentLayout::PaintContext context = getPaintContext(); -
1366 -
1367 while (block.isValid()) {
evaluated: block.isValid()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:1
1-7
1368 -
1369 QRectF r = blockBoundingRect(block).translated(offset); -
1370 QTextLayout *layout = block.layout(); -
1371 -
1372 if (!block.isVisible()) {
partially evaluated: !block.isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
1373 offset.ry() += r.height(); -
1374 block = block.next(); -
1375 continue;
never executed: continue;
0
1376 } -
1377 -
1378 if (r.bottom() >= er.top() && r.top() <= er.bottom()) {
partially evaluated: r.bottom() >= er.top()
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
partially evaluated: r.top() <= er.bottom()
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
1379 -
1380 QTextBlockFormat blockFormat = block.blockFormat(); -
1381 -
1382 QBrush bg = blockFormat.background(); -
1383 if (bg != Qt::NoBrush) {
partially evaluated: bg != Qt::NoBrush
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
1384 QRectF contentsRect = r; -
1385 contentsRect.setWidth(qMax(r.width(), maximumWidth)); -
1386 fillBackground(&painter, contentsRect, bg); -
1387 }
never executed: }
0
1388 -
1389 -
1390 QVector<QTextLayout::FormatRange> selections; -
1391 int blpos = block.position(); -
1392 int bllen = block.length(); -
1393 for (int i = 0; i < context.selections.size(); ++i) {
partially evaluated: i < context.selections.size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
1394 const QAbstractTextDocumentLayout::Selection &range = context.selections.at(i); -
1395 const int selStart = range.cursor.selectionStart() - blpos; -
1396 const int selEnd = range.cursor.selectionEnd() - blpos; -
1397 if (selStart < bllen && selEnd > 0
never evaluated: selStart < bllen
never evaluated: selEnd > 0
0
1398 && selEnd > selStart) {
never evaluated: selEnd > selStart
0
1399 QTextLayout::FormatRange o; -
1400 o.start = selStart; -
1401 o.length = selEnd - selStart; -
1402 o.format = range.format; -
1403 selections.append(o); -
1404 } else if (!range.cursor.hasSelection() && range.format.hasProperty(QTextFormat::FullWidthSelection)
never executed: }
never evaluated: !range.cursor.hasSelection()
never evaluated: range.format.hasProperty(QTextFormat::FullWidthSelection)
0
1405 && block.contains(range.cursor.position())) {
never evaluated: block.contains(range.cursor.position())
0
1406 -
1407 -
1408 QTextLayout::FormatRange o; -
1409 QTextLine l = layout->lineForTextPosition(range.cursor.position() - blpos); -
1410 o.start = l.textStart(); -
1411 o.length = l.textLength(); -
1412 if (o.start + o.length == bllen - 1)
never evaluated: o.start + o.length == bllen - 1
0
1413 ++o.length;
never executed: ++o.length;
0
1414 o.format = range.format; -
1415 selections.append(o); -
1416 }
never executed: }
0
1417 } -
1418 -
1419 bool drawCursor = ((editable || (textInteractionFlags() & Qt::TextSelectableByKeyboard))
partially evaluated: editable
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
never evaluated: (textInteractionFlags() & Qt::TextSelectableByKeyboard)
0-7
1420 && context.cursorPosition >= blpos
evaluated: context.cursorPosition >= blpos
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1
1-6
1421 && context.cursorPosition < blpos + bllen);
partially evaluated: context.cursorPosition < blpos + bllen
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
1422 -
1423 bool drawCursorAsBlock = drawCursor && overwriteMode() ;
evaluated: drawCursor
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1
partially evaluated: overwriteMode()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
1424 -
1425 if (drawCursorAsBlock) {
partially evaluated: drawCursorAsBlock
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
1426 if (context.cursorPosition == blpos + bllen - 1) {
never evaluated: context.cursorPosition == blpos + bllen - 1
0
1427 drawCursorAsBlock = false; -
1428 } else {
never executed: }
0
1429 QTextLayout::FormatRange o; -
1430 o.start = context.cursorPosition - blpos; -
1431 o.length = 1; -
1432 o.format.setForeground(palette().base()); -
1433 o.format.setBackground(palette().text()); -
1434 selections.append(o); -
1435 }
never executed: }
0
1436 } -
1437 -
1438 -
1439 layout->draw(&painter, offset, selections, er); -
1440 if ((drawCursor && !drawCursorAsBlock)
evaluated: drawCursor
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1
partially evaluated: !drawCursorAsBlock
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
1441 || (editable && context.cursorPosition < -1
partially evaluated: editable
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
partially evaluated: context.cursorPosition < -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1442 && !layout->preeditAreaText().isEmpty())) {
never evaluated: !layout->preeditAreaText().isEmpty()
0
1443 int cpos = context.cursorPosition; -
1444 if (cpos < -1)
partially evaluated: cpos < -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
1445 cpos = layout->preeditAreaPosition() - (cpos + 2);
never executed: cpos = layout->preeditAreaPosition() - (cpos + 2);
0
1446 else -
1447 cpos -= blpos;
executed: cpos -= blpos;
Execution Count:6
6
1448 layout->drawCursor(&painter, offset, cpos, cursorWidth()); -
1449 }
executed: }
Execution Count:6
6
1450 }
executed: }
Execution Count:7
7
1451 -
1452 offset.ry() += r.height(); -
1453 if (offset.y() > viewportRect.height())
evaluated: offset.y() > viewportRect.height()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1
1-6
1454 break;
executed: break;
Execution Count:6
6
1455 block = block.next(); -
1456 }
executed: }
Execution Count:1
1
1457 -
1458 if (backgroundVisible() && !block.isValid() && offset.y() <= er.bottom()
partially evaluated: backgroundVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
never evaluated: !block.isValid()
never evaluated: offset.y() <= er.bottom()
0-7
1459 && (centerOnScroll() || verticalScrollBar()->maximum() == verticalScrollBar()->minimum())) {
never evaluated: centerOnScroll()
never evaluated: verticalScrollBar()->maximum() == verticalScrollBar()->minimum()
0
1460 painter.fillRect(QRect(QPoint((int)er.left(), (int)offset.y()), er.bottomRight()), palette().background()); -
1461 }
never executed: }
0
1462}
executed: }
Execution Count:7
7
1463 -
1464 -
1465void QPlainTextEditPrivate::updateDefaultTextOption() -
1466{ -
1467 QTextDocument *doc = control->document(); -
1468 -
1469 QTextOption opt = doc->defaultTextOption(); -
1470 QTextOption::WrapMode oldWrapMode = opt.wrapMode(); -
1471 -
1472 if (lineWrap == QPlainTextEdit::NoWrap)
evaluated: lineWrap == QPlainTextEdit::NoWrap
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:9
4-9
1473 opt.setWrapMode(QTextOption::NoWrap);
executed: opt.setWrapMode(QTextOption::NoWrap);
Execution Count:4
4
1474 else -
1475 opt.setWrapMode(wordWrap);
executed: opt.setWrapMode(wordWrap);
Execution Count:9
9
1476 -
1477 if (opt.wrapMode() != oldWrapMode)
evaluated: opt.wrapMode() != oldWrapMode
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:4
4-9
1478 doc->setDefaultTextOption(opt);
executed: doc->setDefaultTextOption(opt);
Execution Count:9
9
1479}
executed: }
Execution Count:13
13
1480 -
1481 -
1482 -
1483 -
1484void QPlainTextEdit::mousePressEvent(QMouseEvent *e) -
1485{ -
1486 QPlainTextEditPrivate * const d = d_func(); -
1487 -
1488 -
1489 -
1490 -
1491 d->sendControlEvent(e); -
1492}
never executed: }
0
1493 -
1494 -
1495 -
1496void QPlainTextEdit::mouseMoveEvent(QMouseEvent *e) -
1497{ -
1498 QPlainTextEditPrivate * const d = d_func(); -
1499 d->inDrag = false; -
1500 const QPoint pos = e->pos(); -
1501 d->sendControlEvent(e); -
1502 if (!(e->buttons() & Qt::LeftButton))
never evaluated: !(e->buttons() & Qt::LeftButton)
0
1503 return;
never executed: return;
0
1504 QRect visible = d->viewport->rect(); -
1505 if (visible.contains(pos))
never evaluated: visible.contains(pos)
0
1506 d->autoScrollTimer.stop();
never executed: d->autoScrollTimer.stop();
0
1507 else if (!d->autoScrollTimer.isActive())
never evaluated: !d->autoScrollTimer.isActive()
0
1508 d->autoScrollTimer.start(100, this);
never executed: d->autoScrollTimer.start(100, this);
0
1509} -
1510 -
1511 -
1512 -
1513void QPlainTextEdit::mouseReleaseEvent(QMouseEvent *e) -
1514{ -
1515 QPlainTextEditPrivate * const d = d_func(); -
1516 d->sendControlEvent(e); -
1517 if (d->autoScrollTimer.isActive()) {
never evaluated: d->autoScrollTimer.isActive()
0
1518 d->autoScrollTimer.stop(); -
1519 d->ensureCursorVisible(); -
1520 }
never executed: }
0
1521 -
1522 if (!isReadOnly() && rect().contains(e->pos()))
never evaluated: !isReadOnly()
never evaluated: rect().contains(e->pos())
0
1523 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
never executed: d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
0
1524 d->clickCausedFocus = 0; -
1525}
never executed: }
0
1526 -
1527 -
1528 -
1529void QPlainTextEdit::mouseDoubleClickEvent(QMouseEvent *e) -
1530{ -
1531 QPlainTextEditPrivate * const d = d_func(); -
1532 d->sendControlEvent(e); -
1533}
never executed: }
0
1534 -
1535 -
1536 -
1537bool QPlainTextEdit::focusNextPrevChild(bool next) -
1538{ -
1539 const QPlainTextEditPrivate * const d = d_func(); -
1540 if (!d->tabChangesFocus && d->control->textInteractionFlags() & Qt::TextEditable)
never evaluated: !d->tabChangesFocus
never evaluated: d->control->textInteractionFlags() & Qt::TextEditable
0
1541 return false;
never executed: return false;
0
1542 return QAbstractScrollArea::focusNextPrevChild(next);
never executed: return QAbstractScrollArea::focusNextPrevChild(next);
0
1543} -
1544void QPlainTextEdit::contextMenuEvent(QContextMenuEvent *e) -
1545{ -
1546 QPlainTextEditPrivate * const d = d_func(); -
1547 d->sendControlEvent(e); -
1548}
never executed: }
0
1549 -
1550 -
1551 -
1552 -
1553 -
1554void QPlainTextEdit::dragEnterEvent(QDragEnterEvent *e) -
1555{ -
1556 QPlainTextEditPrivate * const d = d_func(); -
1557 d->inDrag = true; -
1558 d->sendControlEvent(e); -
1559}
never executed: }
0
1560 -
1561 -
1562 -
1563void QPlainTextEdit::dragLeaveEvent(QDragLeaveEvent *e) -
1564{ -
1565 QPlainTextEditPrivate * const d = d_func(); -
1566 d->inDrag = false; -
1567 d->autoScrollTimer.stop(); -
1568 d->sendControlEvent(e); -
1569}
never executed: }
0
1570 -
1571 -
1572 -
1573void QPlainTextEdit::dragMoveEvent(QDragMoveEvent *e) -
1574{ -
1575 QPlainTextEditPrivate * const d = d_func(); -
1576 d->autoScrollDragPos = e->pos(); -
1577 if (!d->autoScrollTimer.isActive())
never evaluated: !d->autoScrollTimer.isActive()
0
1578 d->autoScrollTimer.start(100, this);
never executed: d->autoScrollTimer.start(100, this);
0
1579 d->sendControlEvent(e); -
1580}
never executed: }
0
1581 -
1582 -
1583 -
1584void QPlainTextEdit::dropEvent(QDropEvent *e) -
1585{ -
1586 QPlainTextEditPrivate * const d = d_func(); -
1587 d->inDrag = false; -
1588 d->autoScrollTimer.stop(); -
1589 d->sendControlEvent(e); -
1590}
never executed: }
0
1591 -
1592 -
1593 -
1594 -
1595 -
1596void QPlainTextEdit::inputMethodEvent(QInputMethodEvent *e) -
1597{ -
1598 QPlainTextEditPrivate * const d = d_func(); -
1599 d->sendControlEvent(e); -
1600 ensureCursorVisible(); -
1601}
never executed: }
0
1602 -
1603 -
1604 -
1605void QPlainTextEdit::scrollContentsBy(int dx, int ) -
1606{ -
1607 QPlainTextEditPrivate * const d = d_func(); -
1608 d->setTopLine(d->vbar->value(), dx); -
1609}
executed: }
Execution Count:7
7
1610 -
1611 -
1612 -
1613QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const -
1614{ -
1615 const QPlainTextEditPrivate * const d = d_func(); -
1616 QVariant v; -
1617 switch (property) { -
1618 case Qt::ImHints: -
1619 v = QWidget::inputMethodQuery(property); -
1620 break;
executed: break;
Execution Count:3
3
1621 default: -
1622 v = d->control->inputMethodQuery(property); -
1623 const QPoint offset(-d->horizontalOffset(), -0); -
1624 if (v.type() == QVariant::RectF)
partially evaluated: v.type() == QVariant::RectF
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
0-15
1625 v = v.toRectF().toRect().translated(offset);
never executed: v = v.toRectF().toRect().translated(offset);
0
1626 else if (v.type() == QVariant::PointF)
partially evaluated: v.type() == QVariant::PointF
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
0-15
1627 v = v.toPointF().toPoint() + offset;
never executed: v = v.toPointF().toPoint() + offset;
0
1628 else if (v.type() == QVariant::Rect)
partially evaluated: v.type() == QVariant::Rect
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
0-15
1629 v = v.toRect().translated(offset);
never executed: v = v.toRect().translated(offset);
0
1630 else if (v.type() == QVariant::Point)
partially evaluated: v.type() == QVariant::Point
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
0-15
1631 v = v.toPoint() + offset;
never executed: v = v.toPoint() + offset;
0
1632 } -
1633 -
1634 return v;
executed: return v;
Execution Count:18
18
1635} -
1636 -
1637 -
1638 -
1639void QPlainTextEdit::focusInEvent(QFocusEvent *e) -
1640{ -
1641 QPlainTextEditPrivate * const d = d_func(); -
1642 if (e->reason() == Qt::MouseFocusReason) {
partially evaluated: e->reason() == Qt::MouseFocusReason
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
1643 d->clickCausedFocus = 1; -
1644 }
never executed: }
0
1645 QAbstractScrollArea::focusInEvent(e); -
1646 d->sendControlEvent(e); -
1647}
executed: }
Execution Count:5
5
1648 -
1649 -
1650 -
1651void QPlainTextEdit::focusOutEvent(QFocusEvent *e) -
1652{ -
1653 QPlainTextEditPrivate * const d = d_func(); -
1654 QAbstractScrollArea::focusOutEvent(e); -
1655 d->sendControlEvent(e); -
1656}
executed: }
Execution Count:4
4
1657 -
1658 -
1659 -
1660void QPlainTextEdit::showEvent(QShowEvent *) -
1661{ -
1662 QPlainTextEditPrivate * const d = d_func(); -
1663 if (d->showCursorOnInitialShow) {
evaluated: d->showCursorOnInitialShow
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:1
1-14
1664 d->showCursorOnInitialShow = false; -
1665 ensureCursorVisible(); -
1666 }
executed: }
Execution Count:14
14
1667}
executed: }
Execution Count:15
15
1668 -
1669 -
1670 -
1671void QPlainTextEdit::changeEvent(QEvent *e) -
1672{ -
1673 QPlainTextEditPrivate * const d = d_func(); -
1674 QAbstractScrollArea::changeEvent(e); -
1675 if (e->type() == QEvent::ApplicationFontChange
partially evaluated: e->type() == QEvent::ApplicationFontChange
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
1676 || e->type() == QEvent::FontChange) {
evaluated: e->type() == QEvent::FontChange
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
1677 d->control->document()->setDefaultFont(font()); -
1678 } else if(e->type() == QEvent::ActivationChange) {
executed: }
Execution Count:1
evaluated: e->type() == QEvent::ActivationChange
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
1679 if (!isActiveWindow())
partially evaluated: !isActiveWindow()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1680 d->autoScrollTimer.stop();
never executed: d->autoScrollTimer.stop();
0
1681 } else if (e->type() == QEvent::EnabledChange) {
executed: }
Execution Count:1
partially evaluated: e->type() == QEvent::EnabledChange
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1682 e->setAccepted(isEnabled()); -
1683 d->sendControlEvent(e); -
1684 } else if (e->type() == QEvent::PaletteChange) {
never executed: }
partially evaluated: e->type() == QEvent::PaletteChange
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1685 d->control->setPalette(palette()); -
1686 } else if (e->type() == QEvent::LayoutDirectionChange) {
never executed: }
evaluated: e->type() == QEvent::LayoutDirectionChange
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
0-2
1687 d->sendControlEvent(e); -
1688 }
executed: }
Execution Count:1
1
1689} -
1690 -
1691 -
1692 -
1693 -
1694void QPlainTextEdit::wheelEvent(QWheelEvent *e) -
1695{ -
1696 QAbstractScrollArea::wheelEvent(e); -
1697 updateMicroFocus(); -
1698}
never executed: }
0
1699QMenu *QPlainTextEdit::createStandardContextMenu() -
1700{ -
1701 QPlainTextEditPrivate * const d = d_func(); -
1702 return d->control->createStandardContextMenu(QPointF(), this);
never executed: return d->control->createStandardContextMenu(QPointF(), this);
0
1703} -
1704 -
1705 -
1706 -
1707 -
1708 -
1709QTextCursor QPlainTextEdit::cursorForPosition(const QPoint &pos) const -
1710{ -
1711 const QPlainTextEditPrivate * const d = d_func(); -
1712 return d->control->cursorForPosition(d->mapToContents(pos));
never executed: return d->control->cursorForPosition(d->mapToContents(pos));
0
1713} -
1714 -
1715 -
1716 -
1717 -
1718 -
1719QRect QPlainTextEdit::cursorRect(const QTextCursor &cursor) const -
1720{ -
1721 const QPlainTextEditPrivate * const d = d_func(); -
1722 if (cursor.isNull())
never evaluated: cursor.isNull()
0
1723 return QRect();
never executed: return QRect();
0
1724 -
1725 QRect r = d->control->cursorRect(cursor).toRect(); -
1726 r.translate(-d->horizontalOffset(),-(int)d->verticalOffset()); -
1727 return r;
never executed: return r;
0
1728} -
1729 -
1730 -
1731 -
1732 -
1733 -
1734QRect QPlainTextEdit::cursorRect() const -
1735{ -
1736 const QPlainTextEditPrivate * const d = d_func(); -
1737 QRect r = d->control->cursorRect().toRect(); -
1738 r.translate(-d->horizontalOffset(),-(int)d->verticalOffset()); -
1739 return r;
executed: return r;
Execution Count:369
369
1740} -
1741bool QPlainTextEdit::overwriteMode() const -
1742{ -
1743 const QPlainTextEditPrivate * const d = d_func(); -
1744 return d->control->overwriteMode();
executed: return d->control->overwriteMode();
Execution Count:9
9
1745} -
1746 -
1747void QPlainTextEdit::setOverwriteMode(bool overwrite) -
1748{ -
1749 QPlainTextEditPrivate * const d = d_func(); -
1750 d->control->setOverwriteMode(overwrite); -
1751}
executed: }
Execution Count:5
5
1752int QPlainTextEdit::tabStopWidth() const -
1753{ -
1754 const QPlainTextEditPrivate * const d = d_func(); -
1755 return qRound(d->control->document()->defaultTextOption().tabStop());
executed: return qRound(d->control->document()->defaultTextOption().tabStop());
Execution Count:3
3
1756} -
1757 -
1758void QPlainTextEdit::setTabStopWidth(int width) -
1759{ -
1760 QPlainTextEditPrivate * const d = d_func(); -
1761 QTextOption opt = d->control->document()->defaultTextOption(); -
1762 if (opt.tabStop() == width || width < 0)
partially evaluated: opt.tabStop() == width
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
evaluated: width < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
0-3
1763 return;
executed: return;
Execution Count:1
1
1764 opt.setTabStop(width); -
1765 d->control->document()->setDefaultTextOption(opt); -
1766}
executed: }
Execution Count:2
2
1767 -
1768 -
1769 -
1770 -
1771 -
1772 -
1773int QPlainTextEdit::cursorWidth() const -
1774{ -
1775 const QPlainTextEditPrivate * const d = d_func(); -
1776 return d->control->cursorWidth();
executed: return d->control->cursorWidth();
Execution Count:6
6
1777} -
1778 -
1779void QPlainTextEdit::setCursorWidth(int width) -
1780{ -
1781 QPlainTextEditPrivate * const d = d_func(); -
1782 d->control->setCursorWidth(width); -
1783}
never executed: }
0
1784void QPlainTextEdit::setExtraSelections(const QList<QTextEdit::ExtraSelection> &selections) -
1785{ -
1786 QPlainTextEditPrivate * const d = d_func(); -
1787 d->control->setExtraSelections(selections); -
1788}
executed: }
Execution Count:2
2
1789 -
1790 -
1791 -
1792 -
1793 -
1794 -
1795QList<QTextEdit::ExtraSelection> QPlainTextEdit::extraSelections() const -
1796{ -
1797 const QPlainTextEditPrivate * const d = d_func(); -
1798 return d->control->extraSelections();
executed: return d->control->extraSelections();
Execution Count:1
1
1799} -
1800QMimeData *QPlainTextEdit::createMimeDataFromSelection() const -
1801{ -
1802 const QPlainTextEditPrivate * const d = d_func(); -
1803 return d->control->QWidgetTextControl::createMimeDataFromSelection();
executed: return d->control->QWidgetTextControl::createMimeDataFromSelection();
Execution Count:7
7
1804} -
1805 -
1806 -
1807 -
1808 -
1809 -
1810 -
1811 -
1812bool QPlainTextEdit::canInsertFromMimeData(const QMimeData *source) const -
1813{ -
1814 const QPlainTextEditPrivate * const d = d_func(); -
1815 return d->control->QWidgetTextControl::canInsertFromMimeData(source);
executed: return d->control->QWidgetTextControl::canInsertFromMimeData(source);
Execution Count:9
9
1816} -
1817void QPlainTextEdit::insertFromMimeData(const QMimeData *source) -
1818{ -
1819 QPlainTextEditPrivate * const d = d_func(); -
1820 d->control->QWidgetTextControl::insertFromMimeData(source); -
1821}
executed: }
Execution Count:3
3
1822bool QPlainTextEdit::isReadOnly() const -
1823{ -
1824 const QPlainTextEditPrivate * const d = d_func(); -
1825 return !(d->control->textInteractionFlags() & Qt::TextEditable);
executed: return !(d->control->textInteractionFlags() & Qt::TextEditable);
Execution Count:10
10
1826} -
1827 -
1828void QPlainTextEdit::setReadOnly(bool ro) -
1829{ -
1830 QPlainTextEditPrivate * const d = d_func(); -
1831 Qt::TextInteractionFlags flags = Qt::NoTextInteraction; -
1832 if (ro) {
partially evaluated: ro
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
1833 flags = Qt::TextSelectableByMouse; -
1834 } else {
executed: }
Execution Count:2
2
1835 flags = Qt::TextEditorInteraction; -
1836 }
never executed: }
0
1837 setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this)); -
1838 d->control->setTextInteractionFlags(flags); -
1839}
executed: }
Execution Count:2
2
1840void QPlainTextEdit::setTextInteractionFlags(Qt::TextInteractionFlags flags) -
1841{ -
1842 QPlainTextEditPrivate * const d = d_func(); -
1843 d->control->setTextInteractionFlags(flags); -
1844}
executed: }
Execution Count:1
1
1845 -
1846Qt::TextInteractionFlags QPlainTextEdit::textInteractionFlags() const -
1847{ -
1848 const QPlainTextEditPrivate * const d = d_func(); -
1849 return d->control->textInteractionFlags();
never executed: return d->control->textInteractionFlags();
0
1850} -
1851void QPlainTextEdit::mergeCurrentCharFormat(const QTextCharFormat &modifier) -
1852{ -
1853 QPlainTextEditPrivate * const d = d_func(); -
1854 d->control->mergeCurrentCharFormat(modifier); -
1855}
executed: }
Execution Count:4
4
1856 -
1857 -
1858 -
1859 -
1860 -
1861 -
1862 -
1863void QPlainTextEdit::setCurrentCharFormat(const QTextCharFormat &format) -
1864{ -
1865 QPlainTextEditPrivate * const d = d_func(); -
1866 d->control->setCurrentCharFormat(format); -
1867}
never executed: }
0
1868 -
1869 -
1870 -
1871 -
1872QTextCharFormat QPlainTextEdit::currentCharFormat() const -
1873{ -
1874 const QPlainTextEditPrivate * const d = d_func(); -
1875 return d->control->currentCharFormat();
never executed: return d->control->currentCharFormat();
0
1876} -
1877void QPlainTextEdit::insertPlainText(const QString &text) -
1878{ -
1879 QPlainTextEditPrivate * const d = d_func(); -
1880 d->control->insertPlainText(text); -
1881}
executed: }
Execution Count:1
1
1882void QPlainTextEdit::moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode) -
1883{ -
1884 QPlainTextEditPrivate * const d = d_func(); -
1885 d->control->moveCursor(operation, mode); -
1886}
executed: }
Execution Count:10
10
1887 -
1888 -
1889 -
1890 -
1891bool QPlainTextEdit::canPaste() const -
1892{ -
1893 const QPlainTextEditPrivate * const d = d_func(); -
1894 return d->control->canPaste();
executed: return d->control->canPaste();
Execution Count:10
10
1895} -
1896void QPlainTextEdit::print(QPagedPaintDevice *printer) const -
1897{ -
1898 const QPlainTextEditPrivate * const d = d_func(); -
1899 d->control->print(printer); -
1900}
never executed: }
0
1901bool QPlainTextEdit::tabChangesFocus() const -
1902{ -
1903 const QPlainTextEditPrivate * const d = d_func(); -
1904 return d->tabChangesFocus;
executed: return d->tabChangesFocus;
Execution Count:2
2
1905} -
1906 -
1907void QPlainTextEdit::setTabChangesFocus(bool b) -
1908{ -
1909 QPlainTextEditPrivate * const d = d_func(); -
1910 d->tabChangesFocus = b; -
1911}
executed: }
Execution Count:2
2
1912QPlainTextEdit::LineWrapMode QPlainTextEdit::lineWrapMode() const -
1913{ -
1914 const QPlainTextEditPrivate * const d = d_func(); -
1915 return d->lineWrap;
executed: return d->lineWrap;
Execution Count:4
4
1916} -
1917 -
1918void QPlainTextEdit::setLineWrapMode(LineWrapMode wrap) -
1919{ -
1920 QPlainTextEditPrivate * const d = d_func(); -
1921 if (d->lineWrap == wrap)
partially evaluated: d->lineWrap == wrap
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
1922 return;
never executed: return;
0
1923 d->lineWrap = wrap; -
1924 d->updateDefaultTextOption(); -
1925 d->relayoutDocument(); -
1926 d->_q_adjustScrollbars(); -
1927 ensureCursorVisible(); -
1928}
executed: }
Execution Count:6
6
1929QTextOption::WrapMode QPlainTextEdit::wordWrapMode() const -
1930{ -
1931 const QPlainTextEditPrivate * const d = d_func(); -
1932 return d->wordWrap;
executed: return d->wordWrap;
Execution Count:2
2
1933} -
1934 -
1935void QPlainTextEdit::setWordWrapMode(QTextOption::WrapMode mode) -
1936{ -
1937 QPlainTextEditPrivate * const d = d_func(); -
1938 if (mode == d->wordWrap)
partially evaluated: mode == d->wordWrap
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
1939 return;
never executed: return;
0
1940 d->wordWrap = mode; -
1941 d->updateDefaultTextOption(); -
1942}
executed: }
Execution Count:2
2
1943bool QPlainTextEdit::backgroundVisible() const -
1944{ -
1945 const QPlainTextEditPrivate * const d = d_func(); -
1946 return d->backgroundVisible;
executed: return d->backgroundVisible;
Execution Count:7
7
1947} -
1948 -
1949void QPlainTextEdit::setBackgroundVisible(bool visible) -
1950{ -
1951 QPlainTextEditPrivate * const d = d_func(); -
1952 if (visible == d->backgroundVisible)
never evaluated: visible == d->backgroundVisible
0
1953 return;
never executed: return;
0
1954 d->backgroundVisible = visible; -
1955 d->updateViewport(); -
1956}
never executed: }
0
1957bool QPlainTextEdit::centerOnScroll() const -
1958{ -
1959 const QPlainTextEditPrivate * const d = d_func(); -
1960 return d->centerOnScroll;
never executed: return d->centerOnScroll;
0
1961} -
1962 -
1963void QPlainTextEdit::setCenterOnScroll(bool enabled) -
1964{ -
1965 QPlainTextEditPrivate * const d = d_func(); -
1966 if (enabled == d->centerOnScroll)
never evaluated: enabled == d->centerOnScroll
0
1967 return;
never executed: return;
0
1968 d->centerOnScroll = enabled; -
1969}
never executed: }
0
1970bool QPlainTextEdit::find(const QString &exp, QTextDocument::FindFlags options) -
1971{ -
1972 QPlainTextEditPrivate * const d = d_func(); -
1973 return d->control->find(exp, options);
never executed: return d->control->find(exp, options);
0
1974} -
1975void QPlainTextEditPrivate::append(const QString &text, Qt::TextFormat format) -
1976{ -
1977 QPlainTextEdit * const q = q_func(); -
1978 -
1979 QTextDocument *document = control->document(); -
1980 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document->documentLayout()); -
1981 qt_noop(); -
1982 -
1983 int maximumBlockCount = document->maximumBlockCount(); -
1984 if (maximumBlockCount)
partially evaluated: maximumBlockCount
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
1985 document->setMaximumBlockCount(0);
never executed: document->setMaximumBlockCount(0);
0
1986 -
1987 const bool atBottom = q->isVisible()
partially evaluated: q->isVisible()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
1988 && (control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset() 0
1989 <= viewport->rect().bottom());
never evaluated: (control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset() <= viewport->rect().bottom())
0
1990 -
1991 if (!q->isVisible())
partially evaluated: !q->isVisible()
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
1992 showCursorOnInitialShow = true;
executed: showCursorOnInitialShow = true;
Execution Count:13
13
1993 -
1994 bool documentSizeChangedBlocked = documentLayout->priv()->blockDocumentSizeChanged; -
1995 documentLayout->priv()->blockDocumentSizeChanged = true; -
1996 -
1997 if (format == Qt::RichText)
evaluated: format == Qt::RichText
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:9
4-9
1998 control->appendHtml(text);
executed: control->appendHtml(text);
Execution Count:4
4
1999 else if (format == Qt::PlainText)
partially evaluated: format == Qt::PlainText
TRUEFALSE
yes
Evaluation Count:9
no
Evaluation Count:0
0-9
2000 control->appendPlainText(text);
executed: control->appendPlainText(text);
Execution Count:9
9
2001 else -
2002 control->append(text);
never executed: control->append(text);
0
2003 -
2004 if (maximumBlockCount > 0) {
partially evaluated: maximumBlockCount > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
2005 if (document->blockCount() > maximumBlockCount) {
never evaluated: document->blockCount() > maximumBlockCount
0
2006 bool blockUpdate = false; -
2007 if (control->topBlock) {
never evaluated: control->topBlock
0
2008 control->topBlock--; -
2009 blockUpdate = true; -
2010 q->updateRequest(viewport->rect(), 0); -
2011 }
never executed: }
0
2012 -
2013 bool updatesBlocked = documentLayout->priv()->blockUpdate; -
2014 documentLayout->priv()->blockUpdate = blockUpdate; -
2015 QTextCursor cursor(document); -
2016 cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor); -
2017 cursor.removeSelectedText(); -
2018 documentLayout->priv()->blockUpdate = updatesBlocked; -
2019 }
never executed: }
0
2020 document->setMaximumBlockCount(maximumBlockCount); -
2021 }
never executed: }
0
2022 -
2023 documentLayout->priv()->blockDocumentSizeChanged = documentSizeChangedBlocked; -
2024 _q_adjustScrollbars(); -
2025 -
2026 -
2027 if (atBottom) {
partially evaluated: atBottom
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
2028 const bool needScroll = !centerOnScroll
never evaluated: !centerOnScroll
0
2029 || control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset() 0
2030 > viewport->rect().bottom();
never evaluated: control->blockBoundingRect(document->lastBlock()).bottom() - verticalOffset() > viewport->rect().bottom()
0
2031 if (needScroll)
never evaluated: needScroll
0
2032 vbar->setValue(vbar->maximum());
never executed: vbar->setValue(vbar->maximum());
0
2033 }
never executed: }
0
2034}
executed: }
Execution Count:13
13
2035void QPlainTextEdit::appendPlainText(const QString &text) -
2036{ -
2037 QPlainTextEditPrivate * const d = d_func(); -
2038 d->append(text, Qt::PlainText); -
2039}
executed: }
Execution Count:9
9
2040 -
2041 -
2042 -
2043 -
2044 -
2045 -
2046 -
2047void QPlainTextEdit::appendHtml(const QString &html) -
2048{ -
2049 QPlainTextEditPrivate * const d = d_func(); -
2050 d->append(html, Qt::RichText); -
2051}
executed: }
Execution Count:4
4
2052 -
2053void QPlainTextEditPrivate::ensureCursorVisible(bool center) -
2054{ -
2055 QPlainTextEdit * const q = q_func(); -
2056 QRect visible = viewport->rect(); -
2057 QRect cr = q->cursorRect(); -
2058 if (cr.top() < visible.top() || cr.bottom() > visible.bottom()) {
evaluated: cr.top() < visible.top()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:368
evaluated: cr.bottom() > visible.bottom()
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:357
1-368
2059 ensureVisible(control->textCursor().position(), center); -
2060 }
executed: }
Execution Count:12
12
2061 -
2062 const bool rtl = q->isRightToLeft(); -
2063 if (cr.left() < visible.left() || cr.right() > visible.right()) {
evaluated: cr.left() < visible.left()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:366
evaluated: cr.right() > visible.right()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:364
2-366
2064 int x = cr.center().x() + horizontalOffset() - visible.width()/2; -
2065 hbar->setValue(rtl ? hbar->maximum() - x : x); -
2066 }
executed: }
Execution Count:5
5
2067}
executed: }
Execution Count:369
369
2068 -
2069 -
2070 -
2071 -
2072 -
2073 -
2074 -
2075void QPlainTextEdit::ensureCursorVisible() -
2076{ -
2077 QPlainTextEditPrivate * const d = d_func(); -
2078 d->ensureCursorVisible(d->centerOnScroll); -
2079}
executed: }
Execution Count:369
369
2080 -
2081 -
2082 -
2083 -
2084 -
2085 -
2086void QPlainTextEdit::centerCursor() -
2087{ -
2088 QPlainTextEditPrivate * const d = d_func(); -
2089 d->ensureVisible(textCursor().position(), true, true); -
2090}
never executed: }
0
2091 -
2092 -
2093 -
2094 -
2095 -
2096 -
2097QTextBlock QPlainTextEdit::firstVisibleBlock() const -
2098{ -
2099 const QPlainTextEditPrivate * const d = d_func(); -
2100 return d->control->firstVisibleBlock();
executed: return d->control->firstVisibleBlock();
Execution Count:239
239
2101} -
2102QPointF QPlainTextEdit::contentOffset() const -
2103{ -
2104 const QPlainTextEditPrivate * const d = d_func(); -
2105 return QPointF(-d->horizontalOffset(), -d->verticalOffset());
executed: return QPointF(-d->horizontalOffset(), -d->verticalOffset());
Execution Count:19
19
2106} -
2107QRectF QPlainTextEdit::blockBoundingGeometry(const QTextBlock &block) const -
2108{ -
2109 const QPlainTextEditPrivate * const d = d_func(); -
2110 return d->control->blockBoundingRect(block);
executed: return d->control->blockBoundingRect(block);
Execution Count:11
11
2111} -
2112 -
2113 -
2114 -
2115 -
2116 -
2117 -
2118QRectF QPlainTextEdit::blockBoundingRect(const QTextBlock &block) const -
2119{ -
2120 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()); -
2121 qt_noop(); -
2122 return documentLayout->blockBoundingRect(block);
executed: return documentLayout->blockBoundingRect(block);
Execution Count:47
47
2123} -
2124 -
2125 -
2126 -
2127 -
2128 -
2129 -
2130 -
2131int QPlainTextEdit::blockCount() const -
2132{ -
2133 return document()->blockCount();
never executed: return document()->blockCount();
0
2134} -
2135 -
2136 -
2137 -
2138 -
2139QAbstractTextDocumentLayout::PaintContext QPlainTextEdit::getPaintContext() const -
2140{ -
2141 const QPlainTextEditPrivate * const d = d_func(); -
2142 return d->control->getPaintContext(d->viewport);
executed: return d->control->getPaintContext(d->viewport);
Execution Count:7
7
2143} -
2144 -
2145 -
2146 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial