qtextcursor.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextcursor.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qtextcursor.h"-
41#include "qtextcursor_p.h"-
42#include "qglobal.h"-
43#include "qtextdocumentfragment.h"-
44#include "qtextdocumentfragment_p.h"-
45#include "qtextlist.h"-
46#include "qtexttable.h"-
47#include "qtexttable_p.h"-
48#include "qtextengine_p.h"-
49#include "qabstracttextdocumentlayout.h"-
50-
51#include <qtextlayout.h>-
52#include <qdebug.h>-
53-
54QT_BEGIN_NAMESPACE-
55-
56enum {-
57 AdjustPrev = 0x1,-
58 AdjustUp = 0x3,-
59 AdjustNext = 0x4,-
60 AdjustDown = 0x12-
61};-
62-
63QTextCursorPrivate::QTextCursorPrivate(QTextDocumentPrivate *p)-
64 : priv(p), x(0), position(0), anchor(0), adjusted_anchor(0),-
65 currentCharFormat(-1), visualNavigation(false), keepPositionOnInsert(false),-
66 changed(false)-
67{-
68 priv->addCursor(this);-
69}
never executed: end of block
0
70-
71QTextCursorPrivate::QTextCursorPrivate(const QTextCursorPrivate &rhs)-
72 : QSharedData(rhs)-
73{-
74 position = rhs.position;-
75 anchor = rhs.anchor;-
76 adjusted_anchor = rhs.adjusted_anchor;-
77 priv = rhs.priv;-
78 x = rhs.x;-
79 currentCharFormat = rhs.currentCharFormat;-
80 visualNavigation = rhs.visualNavigation;-
81 keepPositionOnInsert = rhs.keepPositionOnInsert;-
82 changed = rhs.changed;-
83 priv->addCursor(this);-
84}
never executed: end of block
0
85-
86QTextCursorPrivate::~QTextCursorPrivate()-
87{-
88 if (priv)
privDescription
TRUEnever evaluated
FALSEnever evaluated
0
89 priv->removeCursor(this);
never executed: priv->removeCursor(this);
0
90}
never executed: end of block
0
91-
92QTextCursorPrivate::AdjustResult QTextCursorPrivate::adjustPosition(int positionOfChange, int charsAddedOrRemoved, QTextUndoCommand::Operation op)-
93{-
94 QTextCursorPrivate::AdjustResult result = QTextCursorPrivate::CursorMoved;-
95 // not(!) <= , so that inserting text adjusts the cursor correctly-
96 if (position < positionOfChange
position < positionOfChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
97 || (position == positionOfChange
position == positionOfChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
98 && (op == QTextUndoCommand::KeepCursor
op == QTextUnd...nd::KeepCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
99 || keepPositionOnInsert)
keepPositionOnInsertDescription
TRUEnever evaluated
FALSEnever evaluated
0
100 )-
101 ) {-
102 result = CursorUnchanged;-
103 } else {
never executed: end of block
0
104 if (charsAddedOrRemoved < 0 && position < positionOfChange - charsAddedOrRemoved)
charsAddedOrRemoved < 0Description
TRUEnever evaluated
FALSEnever evaluated
position < pos...AddedOrRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
0
105 position = positionOfChange;
never executed: position = positionOfChange;
0
106 else-
107 position += charsAddedOrRemoved;
never executed: position += charsAddedOrRemoved;
0
108-
109 currentCharFormat = -1;-
110 }
never executed: end of block
0
111-
112 if (anchor >= positionOfChange
anchor >= positionOfChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
113 && (anchor != positionOfChange || op != QTextUndoCommand::KeepCursor)) {
anchor != positionOfChangeDescription
TRUEnever evaluated
FALSEnever evaluated
op != QTextUnd...nd::KeepCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
114 if (charsAddedOrRemoved < 0 && anchor < positionOfChange - charsAddedOrRemoved)
charsAddedOrRemoved < 0Description
TRUEnever evaluated
FALSEnever evaluated
anchor < posit...AddedOrRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
0
115 anchor = positionOfChange;
never executed: anchor = positionOfChange;
0
116 else-
117 anchor += charsAddedOrRemoved;
never executed: anchor += charsAddedOrRemoved;
0
118 }-
119-
120 if (adjusted_anchor >= positionOfChange
adjusted_ancho...sitionOfChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
121 && (adjusted_anchor != positionOfChange || op != QTextUndoCommand::KeepCursor)) {
adjusted_ancho...sitionOfChangeDescription
TRUEnever evaluated
FALSEnever evaluated
op != QTextUnd...nd::KeepCursorDescription
TRUEnever evaluated
FALSEnever evaluated
0
122 if (charsAddedOrRemoved < 0 && adjusted_anchor < positionOfChange - charsAddedOrRemoved)
charsAddedOrRemoved < 0Description
TRUEnever evaluated
FALSEnever evaluated
adjusted_ancho...AddedOrRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
0
123 adjusted_anchor = positionOfChange;
never executed: adjusted_anchor = positionOfChange;
0
124 else-
125 adjusted_anchor += charsAddedOrRemoved;
never executed: adjusted_anchor += charsAddedOrRemoved;
0
126 }-
127-
128 return result;
never executed: return result;
0
129}-
130-
131void QTextCursorPrivate::setX()-
132{-
133 if (priv->isInEditBlock() || priv->inContentsChange) {
priv->isInEditBlock()Description
TRUEnever evaluated
FALSEnever evaluated
priv->inContentsChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
134 x = -1; // mark dirty-
135 return;
never executed: return;
0
136 }-
137-
138 QTextBlock block = this->block();-
139 const QTextLayout *layout = blockLayout(block);-
140 int pos = position - block.position();-
141-
142 QTextLine line = layout->lineForTextPosition(pos);-
143 if (line.isValid())
line.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
144 x = line.cursorToX(pos);
never executed: x = line.cursorToX(pos);
0
145 else-
146 x = -1; // delayed init. Makes movePosition() call setX later on again.
never executed: x = -1;
0
147}-
148-
149void QTextCursorPrivate::remove()-
150{-
151 if (anchor == position)
anchor == positionDescription
TRUEnever evaluated
FALSEnever evaluated
0
152 return;
never executed: return;
0
153 currentCharFormat = -1;-
154 int pos1 = position;-
155 int pos2 = adjusted_anchor;-
156 QTextUndoCommand::Operation op = QTextUndoCommand::KeepCursor;-
157 if (pos1 > pos2) {
pos1 > pos2Description
TRUEnever evaluated
FALSEnever evaluated
0
158 pos1 = adjusted_anchor;-
159 pos2 = position;-
160 op = QTextUndoCommand::MoveCursor;-
161 }
never executed: end of block
0
162-
163 // deleting inside table? -> delete only content-
164 QTextTable *table = complexSelectionTable();-
165 if (table) {
tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
166 priv->beginEditBlock();-
167 int startRow, startCol, numRows, numCols;-
168 selectedTableCells(&startRow, &numRows, &startCol, &numCols);-
169 clearCells(table, startRow, startCol, numRows, numCols, op);-
170 adjusted_anchor = anchor = position;-
171 priv->endEditBlock();-
172 } else {
never executed: end of block
0
173 priv->remove(pos1, pos2-pos1, op);-
174 adjusted_anchor = anchor = position;-
175 }
never executed: end of block
0
176-
177}-
178-
179void QTextCursorPrivate::clearCells(QTextTable *table, int startRow, int startCol, int numRows, int numCols, QTextUndoCommand::Operation op)-
180{-
181 priv->beginEditBlock();-
182-
183 for (int row = startRow; row < startRow + numRows; ++row)
row < startRow + numRowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
184 for (int col = startCol; col < startCol + numCols; ++col) {
col < startCol + numColsDescription
TRUEnever evaluated
FALSEnever evaluated
0
185 QTextTableCell cell = table->cellAt(row, col);-
186 const int startPos = cell.firstPosition();-
187 const int endPos = cell.lastPosition();-
188 Q_ASSERT(startPos <= endPos);-
189 priv->remove(startPos, endPos - startPos, op);-
190 }
never executed: end of block
0
191-
192 priv->endEditBlock();-
193}
never executed: end of block
0
194-
195bool QTextCursorPrivate::canDelete(int pos) const-
196{-
197 QTextDocumentPrivate::FragmentIterator fit = priv->find(pos);-
198 QTextCharFormat fmt = priv->formatCollection()->charFormat((*fit)->format);-
199 return (fmt.objectIndex() == -1 || fmt.objectType() == QTextFormat::ImageObject);
never executed: return (fmt.objectIndex() == -1 || fmt.objectType() == QTextFormat::ImageObject);
0
200}-
201-
202void QTextCursorPrivate::insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat)-
203{-
204 QTextFormatCollection *formats = priv->formatCollection();-
205 int idx = formats->indexForFormat(format);-
206 Q_ASSERT(formats->format(idx).isBlockFormat());-
207-
208 priv->insertBlock(position, idx, formats->indexForFormat(charFormat));-
209 currentCharFormat = -1;-
210}
never executed: end of block
0
211-
212void QTextCursorPrivate::adjustCursor(QTextCursor::MoveOperation m)-
213{-
214 adjusted_anchor = anchor;-
215 if (position == anchor)
position == anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
216 return;
never executed: return;
0
217-
218 QTextFrame *f_position = priv->frameAt(position);-
219 QTextFrame *f_anchor = priv->frameAt(adjusted_anchor);-
220-
221 if (f_position != f_anchor) {
f_position != f_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
222 // find common parent frame-
223 QList<QTextFrame *> positionChain;-
224 QList<QTextFrame *> anchorChain;-
225 QTextFrame *f = f_position;-
226 while (f) {
fDescription
TRUEnever evaluated
FALSEnever evaluated
0
227 positionChain.prepend(f);-
228 f = f->parentFrame();-
229 }
never executed: end of block
0
230 f = f_anchor;-
231 while (f) {
fDescription
TRUEnever evaluated
FALSEnever evaluated
0
232 anchorChain.prepend(f);-
233 f = f->parentFrame();-
234 }
never executed: end of block
0
235 Q_ASSERT(positionChain.at(0) == anchorChain.at(0));-
236 int i = 1;-
237 int l = qMin(positionChain.size(), anchorChain.size());-
238 for (; i < l; ++i) {
i < lDescription
TRUEnever evaluated
FALSEnever evaluated
0
239 if (positionChain.at(i) != anchorChain.at(i))
positionChain....horChain.at(i)Description
TRUEnever evaluated
FALSEnever evaluated
0
240 break;
never executed: break;
0
241 }
never executed: end of block
0
242-
243 if (m <= QTextCursor::WordLeft) {
m <= QTextCursor::WordLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
244 if (i < positionChain.size())
i < positionChain.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
245 position = positionChain.at(i)->firstPosition() - 1;
never executed: position = positionChain.at(i)->firstPosition() - 1;
0
246 } else {
never executed: end of block
0
247 if (i < positionChain.size())
i < positionChain.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
248 position = positionChain.at(i)->lastPosition() + 1;
never executed: position = positionChain.at(i)->lastPosition() + 1;
0
249 }
never executed: end of block
0
250 if (position < adjusted_anchor) {
position < adjusted_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
251 if (i < anchorChain.size())
i < anchorChain.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
252 adjusted_anchor = anchorChain.at(i)->lastPosition() + 1;
never executed: adjusted_anchor = anchorChain.at(i)->lastPosition() + 1;
0
253 } else {
never executed: end of block
0
254 if (i < anchorChain.size())
i < anchorChain.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
255 adjusted_anchor = anchorChain.at(i)->firstPosition() - 1;
never executed: adjusted_anchor = anchorChain.at(i)->firstPosition() - 1;
0
256 }
never executed: end of block
0
257-
258 f_position = positionChain.at(i-1);-
259 }
never executed: end of block
0
260-
261 // same frame, either need to adjust to cell boundaries or return-
262 QTextTable *table = qobject_cast<QTextTable *>(f_position);-
263 if (!table)
!tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
264 return;
never executed: return;
0
265-
266 QTextTableCell c_position = table->cellAt(position);-
267 QTextTableCell c_anchor = table->cellAt(adjusted_anchor);-
268 if (c_position != c_anchor) {
c_position != c_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
269 position = c_position.firstPosition();-
270 if (position < adjusted_anchor)
position < adjusted_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
271 adjusted_anchor = c_anchor.lastPosition();
never executed: adjusted_anchor = c_anchor.lastPosition();
0
272 else-
273 adjusted_anchor = c_anchor.firstPosition();
never executed: adjusted_anchor = c_anchor.firstPosition();
0
274 }-
275 currentCharFormat = -1;-
276}
never executed: end of block
0
277-
278void QTextCursorPrivate::aboutToRemoveCell(int from, int to)-
279{-
280 Q_ASSERT(from <= to);-
281 if (position == anchor)
position == anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
282 return;
never executed: return;
0
283-
284 QTextTable *t = qobject_cast<QTextTable *>(priv->frameAt(position));-
285 if (!t)
!tDescription
TRUEnever evaluated
FALSEnever evaluated
0
286 return;
never executed: return;
0
287 QTextTableCell removedCellFrom = t->cellAt(from);-
288 QTextTableCell removedCellEnd = t->cellAt(to);-
289 if (! removedCellFrom.isValid() || !removedCellEnd.isValid())
! removedCellFrom.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
!removedCellEnd.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
290 return;
never executed: return;
0
291-
292 int curFrom = position;-
293 int curTo = adjusted_anchor;-
294 if (curTo < curFrom)
curTo < curFromDescription
TRUEnever evaluated
FALSEnever evaluated
0
295 qSwap(curFrom, curTo);
never executed: qSwap(curFrom, curTo);
0
296-
297 QTextTableCell cellStart = t->cellAt(curFrom);-
298 QTextTableCell cellEnd = t->cellAt(curTo);-
299-
300 if (cellStart.row() >= removedCellFrom.row() && cellEnd.row() <= removedCellEnd.row()
cellStart.row(...CellFrom.row()Description
TRUEnever evaluated
FALSEnever evaluated
cellEnd.row() ...dCellEnd.row()Description
TRUEnever evaluated
FALSEnever evaluated
0
301 && cellStart.column() >= removedCellFrom.column()
cellStart.colu...lFrom.column()Description
TRUEnever evaluated
FALSEnever evaluated
0
302 && cellEnd.column() <= removedCellEnd.column()) { // selection is completely removed
cellEnd.column...llEnd.column()Description
TRUEnever evaluated
FALSEnever evaluated
0
303 // find a new position, as close as possible to where we were.-
304 QTextTableCell cell;-
305 if (removedCellFrom.row() == 0 && removedCellEnd.row() == t->rows()-1) // removed n columns
removedCellFrom.row() == 0Description
TRUEnever evaluated
FALSEnever evaluated
removedCellEnd...== t->rows()-1Description
TRUEnever evaluated
FALSEnever evaluated
0
306 cell = t->cellAt(cellStart.row(), removedCellEnd.column()+1);
never executed: cell = t->cellAt(cellStart.row(), removedCellEnd.column()+1);
0
307 else if (removedCellFrom.column() == 0 && removedCellEnd.column() == t->columns()-1) // removed n rows
removedCellFrom.column() == 0Description
TRUEnever evaluated
FALSEnever evaluated
removedCellEnd...t->columns()-1Description
TRUEnever evaluated
FALSEnever evaluated
0
308 cell = t->cellAt(removedCellEnd.row() + 1, cellStart.column());
never executed: cell = t->cellAt(removedCellEnd.row() + 1, cellStart.column());
0
309-
310 int newPosition;-
311 if (cell.isValid())
cell.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
312 newPosition = cell.firstPosition();
never executed: newPosition = cell.firstPosition();
0
313 else-
314 newPosition = t->lastPosition()+1;
never executed: newPosition = t->lastPosition()+1;
0
315-
316 setPosition(newPosition);-
317 anchor = newPosition;-
318 adjusted_anchor = newPosition;-
319 x = 0;-
320 }
never executed: end of block
0
321 else if (cellStart.row() >= removedCellFrom.row() && cellStart.row() <= removedCellEnd.row()
cellStart.row(...CellFrom.row()Description
TRUEnever evaluated
FALSEnever evaluated
cellStart.row(...dCellEnd.row()Description
TRUEnever evaluated
FALSEnever evaluated
0
322 && cellEnd.row() > removedCellEnd.row()) {
cellEnd.row() ...dCellEnd.row()Description
TRUEnever evaluated
FALSEnever evaluated
0
323 int newPosition = t->cellAt(removedCellEnd.row() + 1, cellStart.column()).firstPosition();-
324 if (position < anchor)
position < anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
325 position = newPosition;
never executed: position = newPosition;
0
326 else-
327 anchor = adjusted_anchor = newPosition;
never executed: anchor = adjusted_anchor = newPosition;
0
328 }-
329 else if (cellStart.column() >= removedCellFrom.column() && cellStart.column() <= removedCellEnd.column()
cellStart.colu...lFrom.column()Description
TRUEnever evaluated
FALSEnever evaluated
cellStart.colu...llEnd.column()Description
TRUEnever evaluated
FALSEnever evaluated
0
330 && cellEnd.column() > removedCellEnd.column()) {
cellEnd.column...llEnd.column()Description
TRUEnever evaluated
FALSEnever evaluated
0
331 int newPosition = t->cellAt(cellStart.row(), removedCellEnd.column()+1).firstPosition();-
332 if (position < anchor)
position < anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
333 position = newPosition;
never executed: position = newPosition;
0
334 else-
335 anchor = adjusted_anchor = newPosition;
never executed: anchor = adjusted_anchor = newPosition;
0
336 }-
337}
never executed: end of block
0
338-
339bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode)-
340{-
341 currentCharFormat = -1;-
342 bool adjustX = true;-
343 QTextBlock blockIt = block();-
344 bool visualMovement = priv->defaultCursorMoveStyle == Qt::VisualMoveStyle;-
345-
346 if (!blockIt.isValid())
!blockIt.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
347 return false;
never executed: return false;
0
348-
349 if (blockIt.textDirection() == Qt::RightToLeft) {
blockIt.textDi...t::RightToLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
350 if (op == QTextCursor::WordLeft)
op == QTextCursor::WordLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
351 op = QTextCursor::NextWord;
never executed: op = QTextCursor::NextWord;
0
352 else if (op == QTextCursor::WordRight)
op == QTextCursor::WordRightDescription
TRUEnever evaluated
FALSEnever evaluated
0
353 op = QTextCursor::PreviousWord;
never executed: op = QTextCursor::PreviousWord;
0
354-
355 if (!visualMovement) {
!visualMovementDescription
TRUEnever evaluated
FALSEnever evaluated
0
356 if (op == QTextCursor::Left)
op == QTextCursor::LeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
357 op = QTextCursor::NextCharacter;
never executed: op = QTextCursor::NextCharacter;
0
358 else if (op == QTextCursor::Right)
op == QTextCursor::RightDescription
TRUEnever evaluated
FALSEnever evaluated
0
359 op = QTextCursor::PreviousCharacter;
never executed: op = QTextCursor::PreviousCharacter;
0
360 }
never executed: end of block
0
361 }
never executed: end of block
0
362-
363 const QTextLayout *layout = blockLayout(blockIt);-
364 int relativePos = position - blockIt.position();-
365 QTextLine line;-
366 if (!priv->isInEditBlock())
!priv->isInEditBlock()Description
TRUEnever evaluated
FALSEnever evaluated
0
367 line = layout->lineForTextPosition(relativePos);
never executed: line = layout->lineForTextPosition(relativePos);
0
368-
369 Q_ASSERT(priv->frameAt(position) == priv->frameAt(adjusted_anchor));-
370-
371 int newPosition = position;-
372-
373 if (mode == QTextCursor::KeepAnchor && complexSelectionTable() != 0) {
mode == QTextC...or::KeepAnchorDescription
TRUEnever evaluated
FALSEnever evaluated
complexSelectionTable() != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
374 if ((op >= QTextCursor::EndOfLine && op <= QTextCursor::NextWord)
op >= QTextCursor::EndOfLineDescription
TRUEnever evaluated
FALSEnever evaluated
op <= QTextCursor::NextWordDescription
TRUEnever evaluated
FALSEnever evaluated
0
375 || (op >= QTextCursor::Right && op <= QTextCursor::WordRight)) {
op >= QTextCursor::RightDescription
TRUEnever evaluated
FALSEnever evaluated
op <= QTextCursor::WordRightDescription
TRUEnever evaluated
FALSEnever evaluated
0
376 QTextTable *t = qobject_cast<QTextTable *>(priv->frameAt(position));-
377 Q_ASSERT(t); // as we have already made sure we have a complex selection-
378 QTextTableCell cell_pos = t->cellAt(position);-
379 if (cell_pos.column() + cell_pos.columnSpan() != t->columns())
cell_pos.colum...= t->columns()Description
TRUEnever evaluated
FALSEnever evaluated
0
380 op = QTextCursor::NextCell;
never executed: op = QTextCursor::NextCell;
0
381 }
never executed: end of block
0
382 }
never executed: end of block
0
383-
384 if (x == -1 && !priv->isInEditBlock() && (op == QTextCursor::Up || op == QTextCursor::Down))
x == -1Description
TRUEnever evaluated
FALSEnever evaluated
!priv->isInEditBlock()Description
TRUEnever evaluated
FALSEnever evaluated
op == QTextCursor::UpDescription
TRUEnever evaluated
FALSEnever evaluated
op == QTextCursor::DownDescription
TRUEnever evaluated
FALSEnever evaluated
0
385 setX();
never executed: setX();
0
386-
387 switch(op) {-
388 case QTextCursor::NoMove:
never executed: case QTextCursor::NoMove:
0
389 return true;
never executed: return true;
0
390-
391 case QTextCursor::Start:
never executed: case QTextCursor::Start:
0
392 newPosition = 0;-
393 break;
never executed: break;
0
394 case QTextCursor::StartOfLine: {
never executed: case QTextCursor::StartOfLine:
0
395 newPosition = blockIt.position();-
396 if (line.isValid())
line.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
397 newPosition += line.textStart();
never executed: newPosition += line.textStart();
0
398-
399 break;
never executed: break;
0
400 }-
401 case QTextCursor::StartOfBlock: {
never executed: case QTextCursor::StartOfBlock:
0
402 newPosition = blockIt.position();-
403 break;
never executed: break;
0
404 }-
405 case QTextCursor::PreviousBlock: {
never executed: case QTextCursor::PreviousBlock:
0
406 if (blockIt == priv->blocksBegin())
blockIt == priv->blocksBegin()Description
TRUEnever evaluated
FALSEnever evaluated
0
407 return false;
never executed: return false;
0
408 blockIt = blockIt.previous();-
409-
410 newPosition = blockIt.position();-
411 break;
never executed: break;
0
412 }-
413 case QTextCursor::PreviousCharacter:
never executed: case QTextCursor::PreviousCharacter:
0
414 if (mode == QTextCursor::MoveAnchor && position != adjusted_anchor)
mode == QTextC...or::MoveAnchorDescription
TRUEnever evaluated
FALSEnever evaluated
position != adjusted_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
415 newPosition = qMin(position, adjusted_anchor);
never executed: newPosition = qMin(position, adjusted_anchor);
0
416 else-
417 newPosition = priv->previousCursorPosition(position, QTextLayout::SkipCharacters);
never executed: newPosition = priv->previousCursorPosition(position, QTextLayout::SkipCharacters);
0
418 break;
never executed: break;
0
419 case QTextCursor::Left:
never executed: case QTextCursor::Left:
0
420 if (mode == QTextCursor::MoveAnchor && position != adjusted_anchor)
mode == QTextC...or::MoveAnchorDescription
TRUEnever evaluated
FALSEnever evaluated
position != adjusted_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
421 newPosition = visualMovement ? qMax(position, adjusted_anchor)
never executed: newPosition = visualMovement ? qMax(position, adjusted_anchor) : qMin(position, adjusted_anchor);
visualMovementDescription
TRUEnever evaluated
FALSEnever evaluated
0
422 : qMin(position, adjusted_anchor);
never executed: newPosition = visualMovement ? qMax(position, adjusted_anchor) : qMin(position, adjusted_anchor);
0
423 else-
424 newPosition = visualMovement ? priv->leftCursorPosition(position)
never executed: newPosition = visualMovement ? priv->leftCursorPosition(position) : priv->previousCursorPosition(position, QTextLayout::SkipCharacters);
visualMovementDescription
TRUEnever evaluated
FALSEnever evaluated
0
425 : priv->previousCursorPosition(position, QTextLayout::SkipCharacters);
never executed: newPosition = visualMovement ? priv->leftCursorPosition(position) : priv->previousCursorPosition(position, QTextLayout::SkipCharacters);
0
426 break;
never executed: break;
0
427 case QTextCursor::StartOfWord: {
never executed: case QTextCursor::StartOfWord:
0
428 if (relativePos == 0)
relativePos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
429 break;
never executed: break;
0
430-
431 // skip if already at word start-
432 QTextEngine *engine = layout->engine();-
433 const QCharAttributes *attributes = engine->attributes();-
434 if ((relativePos == blockIt.length() - 1)
(relativePos =....length() - 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
435 && (attributes[relativePos - 1].whiteSpace || engine->atWordSeparator(relativePos - 1)))
attributes[rel... 1].whiteSpaceDescription
TRUEnever evaluated
FALSEnever evaluated
engine->atWord...lativePos - 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
436 return false;
never executed: return false;
0
437-
438 if (relativePos < blockIt.length()-1)
relativePos < ...kIt.length()-1Description
TRUEnever evaluated
FALSEnever evaluated
0
439 ++position;
never executed: ++position;
0
440-
441 // FALL THROUGH!-
442 }-
443 case QTextCursor::PreviousWord:
code before this statement never executed: case QTextCursor::PreviousWord:
never executed: case QTextCursor::PreviousWord:
0
444 case QTextCursor::WordLeft:
never executed: case QTextCursor::WordLeft:
0
445 newPosition = priv->previousCursorPosition(position, QTextLayout::SkipWords);-
446 break;
never executed: break;
0
447 case QTextCursor::Up: {
never executed: case QTextCursor::Up:
0
448 int i = line.lineNumber() - 1;-
449 if (i == -1) {
i == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
450 if (blockIt == priv->blocksBegin())
blockIt == priv->blocksBegin()Description
TRUEnever evaluated
FALSEnever evaluated
0
451 return false;
never executed: return false;
0
452 int blockPosition = blockIt.position();-
453 QTextTable *table = qobject_cast<QTextTable *>(priv->frameAt(blockPosition));-
454 if (table) {
tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
455 QTextTableCell cell = table->cellAt(blockPosition);-
456 if (cell.firstPosition() == blockPosition) {
cell.firstPosi... blockPositionDescription
TRUEnever evaluated
FALSEnever evaluated
0
457 int row = cell.row() - 1;-
458 if (row >= 0) {
row >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
459 blockPosition = table->cellAt(row, cell.column()).lastPosition();-
460 } else {
never executed: end of block
0
461 // move to line above the table-
462 blockPosition = table->firstPosition() - 1;-
463 }
never executed: end of block
0
464 blockIt = priv->blocksFind(blockPosition);-
465 } else {
never executed: end of block
0
466 blockIt = blockIt.previous();-
467 }
never executed: end of block
0
468 } else {-
469 blockIt = blockIt.previous();-
470 }
never executed: end of block
0
471 layout = blockLayout(blockIt);-
472 i = layout->lineCount()-1;-
473 }
never executed: end of block
0
474 if (layout->lineCount()) {
layout->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
475 QTextLine line = layout->lineAt(i);-
476 newPosition = line.xToCursor(x) + blockIt.position();-
477 } else {
never executed: end of block
0
478 newPosition = blockIt.position();-
479 }
never executed: end of block
0
480 adjustX = false;-
481 break;
never executed: break;
0
482 }-
483-
484 case QTextCursor::End:
never executed: case QTextCursor::End:
0
485 newPosition = priv->length() - 1;-
486 break;
never executed: break;
0
487 case QTextCursor::EndOfLine: {
never executed: case QTextCursor::EndOfLine:
0
488 if (!line.isValid() || line.textLength() == 0) {
!line.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
line.textLength() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
489 if (blockIt.length() >= 1)
blockIt.length() >= 1Description
TRUEnever evaluated
FALSEnever evaluated
0
490 // position right before the block separator-
491 newPosition = blockIt.position() + blockIt.length() - 1;
never executed: newPosition = blockIt.position() + blockIt.length() - 1;
0
492 break;
never executed: break;
0
493 }-
494 newPosition = blockIt.position() + line.textStart() + line.textLength();-
495 if (newPosition >= priv->length())
newPosition >= priv->length()Description
TRUEnever evaluated
FALSEnever evaluated
0
496 newPosition = priv->length() - 1;
never executed: newPosition = priv->length() - 1;
0
497 if (line.lineNumber() < layout->lineCount() - 1) {
line.lineNumbe...ineCount() - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
498 const QString text = blockIt.text();-
499 // ###### this relies on spaces being the cause for linebreaks.-
500 // this doesn't work with japanese-
501 if (text.at(line.textStart() + line.textLength() - 1).isSpace())
text.at(line.t...- 1).isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
0
502 --newPosition;
never executed: --newPosition;
0
503 }
never executed: end of block
0
504 break;
never executed: break;
0
505 }-
506 case QTextCursor::EndOfWord: {
never executed: case QTextCursor::EndOfWord:
0
507 QTextEngine *engine = layout->engine();-
508 const QCharAttributes *attributes = engine->attributes();-
509 const int len = blockIt.length() - 1;-
510 if (relativePos >= len)
relativePos >= lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
511 return false;
never executed: return false;
0
512 if (engine->atWordSeparator(relativePos)) {
engine->atWord...r(relativePos)Description
TRUEnever evaluated
FALSEnever evaluated
0
513 ++relativePos;-
514 while (relativePos < len && engine->atWordSeparator(relativePos))
relativePos < lenDescription
TRUEnever evaluated
FALSEnever evaluated
engine->atWord...r(relativePos)Description
TRUEnever evaluated
FALSEnever evaluated
0
515 ++relativePos;
never executed: ++relativePos;
0
516 } else {
never executed: end of block
0
517 while (relativePos < len && !attributes[relativePos].whiteSpace && !engine->atWordSeparator(relativePos))
relativePos < lenDescription
TRUEnever evaluated
FALSEnever evaluated
!attributes[re...os].whiteSpaceDescription
TRUEnever evaluated
FALSEnever evaluated
!engine->atWor...r(relativePos)Description
TRUEnever evaluated
FALSEnever evaluated
0
518 ++relativePos;
never executed: ++relativePos;
0
519 }
never executed: end of block
0
520 newPosition = blockIt.position() + relativePos;-
521 break;
never executed: break;
0
522 }-
523 case QTextCursor::EndOfBlock:
never executed: case QTextCursor::EndOfBlock:
0
524 if (blockIt.length() >= 1)
blockIt.length() >= 1Description
TRUEnever evaluated
FALSEnever evaluated
0
525 // position right before the block separator-
526 newPosition = blockIt.position() + blockIt.length() - 1;
never executed: newPosition = blockIt.position() + blockIt.length() - 1;
0
527 break;
never executed: break;
0
528 case QTextCursor::NextBlock: {
never executed: case QTextCursor::NextBlock:
0
529 blockIt = blockIt.next();-
530 if (!blockIt.isValid())
!blockIt.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
531 return false;
never executed: return false;
0
532-
533 newPosition = blockIt.position();-
534 break;
never executed: break;
0
535 }-
536 case QTextCursor::NextCharacter:
never executed: case QTextCursor::NextCharacter:
0
537 if (mode == QTextCursor::MoveAnchor && position != adjusted_anchor)
mode == QTextC...or::MoveAnchorDescription
TRUEnever evaluated
FALSEnever evaluated
position != adjusted_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
538 newPosition = qMax(position, adjusted_anchor);
never executed: newPosition = qMax(position, adjusted_anchor);
0
539 else-
540 newPosition = priv->nextCursorPosition(position, QTextLayout::SkipCharacters);
never executed: newPosition = priv->nextCursorPosition(position, QTextLayout::SkipCharacters);
0
541 break;
never executed: break;
0
542 case QTextCursor::Right:
never executed: case QTextCursor::Right:
0
543 if (mode == QTextCursor::MoveAnchor && position != adjusted_anchor)
mode == QTextC...or::MoveAnchorDescription
TRUEnever evaluated
FALSEnever evaluated
position != adjusted_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
544 newPosition = visualMovement ? qMin(position, adjusted_anchor)
never executed: newPosition = visualMovement ? qMin(position, adjusted_anchor) : qMax(position, adjusted_anchor);
visualMovementDescription
TRUEnever evaluated
FALSEnever evaluated
0
545 : qMax(position, adjusted_anchor);
never executed: newPosition = visualMovement ? qMin(position, adjusted_anchor) : qMax(position, adjusted_anchor);
0
546 else-
547 newPosition = visualMovement ? priv->rightCursorPosition(position)
never executed: newPosition = visualMovement ? priv->rightCursorPosition(position) : priv->nextCursorPosition(position, QTextLayout::SkipCharacters);
visualMovementDescription
TRUEnever evaluated
FALSEnever evaluated
0
548 : priv->nextCursorPosition(position, QTextLayout::SkipCharacters);
never executed: newPosition = visualMovement ? priv->rightCursorPosition(position) : priv->nextCursorPosition(position, QTextLayout::SkipCharacters);
0
549 break;
never executed: break;
0
550 case QTextCursor::NextWord:
never executed: case QTextCursor::NextWord:
0
551 case QTextCursor::WordRight:
never executed: case QTextCursor::WordRight:
0
552 newPosition = priv->nextCursorPosition(position, QTextLayout::SkipWords);-
553 break;
never executed: break;
0
554-
555 case QTextCursor::Down: {
never executed: case QTextCursor::Down:
0
556 int i = line.lineNumber() + 1;-
557-
558 if (i >= layout->lineCount()) {
i >= layout->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
559 int blockPosition = blockIt.position() + blockIt.length() - 1;-
560 QTextTable *table = qobject_cast<QTextTable *>(priv->frameAt(blockPosition));-
561 if (table) {
tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
562 QTextTableCell cell = table->cellAt(blockPosition);-
563 if (cell.lastPosition() == blockPosition) {
cell.lastPosit... blockPositionDescription
TRUEnever evaluated
FALSEnever evaluated
0
564 int row = cell.row() + cell.rowSpan();-
565 if (row < table->rows()) {
row < table->rows()Description
TRUEnever evaluated
FALSEnever evaluated
0
566 blockPosition = table->cellAt(row, cell.column()).firstPosition();-
567 } else {
never executed: end of block
0
568 // move to line below the table-
569 blockPosition = table->lastPosition() + 1;-
570 }
never executed: end of block
0
571 blockIt = priv->blocksFind(blockPosition);-
572 } else {
never executed: end of block
0
573 blockIt = blockIt.next();-
574 }
never executed: end of block
0
575 } else {-
576 blockIt = blockIt.next();-
577 }
never executed: end of block
0
578-
579 if (blockIt == priv->blocksEnd())
blockIt == priv->blocksEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
580 return false;
never executed: return false;
0
581 layout = blockLayout(blockIt);-
582 i = 0;-
583 }
never executed: end of block
0
584 if (layout->lineCount()) {
layout->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
585 QTextLine line = layout->lineAt(i);-
586 newPosition = line.xToCursor(x) + blockIt.position();-
587 } else {
never executed: end of block
0
588 newPosition = blockIt.position();-
589 }
never executed: end of block
0
590 adjustX = false;-
591 break;
never executed: break;
0
592 }-
593 case QTextCursor::NextCell: // fall through
never executed: case QTextCursor::NextCell:
0
594 case QTextCursor::PreviousCell: // fall through
never executed: case QTextCursor::PreviousCell:
0
595 case QTextCursor::NextRow: // fall through
never executed: case QTextCursor::NextRow:
0
596 case QTextCursor::PreviousRow: {
never executed: case QTextCursor::PreviousRow:
0
597 QTextTable *table = qobject_cast<QTextTable *>(priv->frameAt(position));-
598 if (!table)
!tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
599 return false;
never executed: return false;
0
600-
601 QTextTableCell cell = table->cellAt(position);-
602 Q_ASSERT(cell.isValid());-
603 int column = cell.column();-
604 int row = cell.row();-
605 const int currentRow = row;-
606 if (op == QTextCursor::NextCell || op == QTextCursor::NextRow) {
op == QTextCursor::NextCellDescription
TRUEnever evaluated
FALSEnever evaluated
op == QTextCursor::NextRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
607 do {-
608 column += cell.columnSpan();-
609 if (column >= table->columns()) {
column >= table->columns()Description
TRUEnever evaluated
FALSEnever evaluated
0
610 column = 0;-
611 ++row;-
612 }
never executed: end of block
0
613 cell = table->cellAt(row, column);-
614 // note we also continue while we have not reached a cell thats not merged with one above us-
615 } while (cell.isValid()
never executed: end of block
cell.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
616 && ((op == QTextCursor::NextRow && currentRow == cell.row())
op == QTextCursor::NextRowDescription
TRUEnever evaluated
FALSEnever evaluated
currentRow == cell.row()Description
TRUEnever evaluated
FALSEnever evaluated
0
617 || cell.row() < row));
cell.row() < rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
618 }
never executed: end of block
0
619 else if (op == QTextCursor::PreviousCell || op == QTextCursor::PreviousRow) {
op == QTextCur...::PreviousCellDescription
TRUEnever evaluated
FALSEnever evaluated
op == QTextCursor::PreviousRowDescription
TRUEnever evaluated
FALSEnever evaluated
0
620 do {-
621 --column;-
622 if (column < 0) {
column < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
623 column = table->columns()-1;-
624 --row;-
625 }
never executed: end of block
0
626 cell = table->cellAt(row, column);-
627 // note we also continue while we have not reached a cell thats not merged with one above us-
628 } while (cell.isValid()
never executed: end of block
cell.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
629 && ((op == QTextCursor::PreviousRow && currentRow == cell.row())
op == QTextCursor::PreviousRowDescription
TRUEnever evaluated
FALSEnever evaluated
currentRow == cell.row()Description
TRUEnever evaluated
FALSEnever evaluated
0
630 || cell.row() < row));
cell.row() < rowDescription
TRUEnever evaluated
FALSEnever evaluated
0
631 }
never executed: end of block
0
632 if (cell.isValid())
cell.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
633 newPosition = cell.firstPosition();
never executed: newPosition = cell.firstPosition();
0
634 break;
never executed: break;
0
635 }-
636 }-
637-
638 if (mode == QTextCursor::KeepAnchor) {
mode == QTextC...or::KeepAnchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
639 QTextTable *table = qobject_cast<QTextTable *>(priv->frameAt(position));-
640 if (table && ((op >= QTextCursor::PreviousBlock && op <= QTextCursor::WordLeft)
tableDescription
TRUEnever evaluated
FALSEnever evaluated
op >= QTextCur...:PreviousBlockDescription
TRUEnever evaluated
FALSEnever evaluated
op <= QTextCursor::WordLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
641 || (op >= QTextCursor::NextBlock && op <= QTextCursor::WordRight))) {
op >= QTextCursor::NextBlockDescription
TRUEnever evaluated
FALSEnever evaluated
op <= QTextCursor::WordRightDescription
TRUEnever evaluated
FALSEnever evaluated
0
642 int oldColumn = table->cellAt(position).column();-
643-
644 const QTextTableCell otherCell = table->cellAt(newPosition);-
645 if (!otherCell.isValid())
!otherCell.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
646 return false;
never executed: return false;
0
647-
648 int newColumn = otherCell.column();-
649 if ((oldColumn > newColumn && op >= QTextCursor::End)
oldColumn > newColumnDescription
TRUEnever evaluated
FALSEnever evaluated
op >= QTextCursor::EndDescription
TRUEnever evaluated
FALSEnever evaluated
0
650 || (oldColumn < newColumn && op <= QTextCursor::WordLeft))
oldColumn < newColumnDescription
TRUEnever evaluated
FALSEnever evaluated
op <= QTextCursor::WordLeftDescription
TRUEnever evaluated
FALSEnever evaluated
0
651 return false;
never executed: return false;
0
652 }
never executed: end of block
0
653 }
never executed: end of block
0
654-
655 const bool moved = setPosition(newPosition);-
656-
657 if (mode == QTextCursor::MoveAnchor) {
mode == QTextC...or::MoveAnchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
658 anchor = position;-
659 adjusted_anchor = position;-
660 } else {
never executed: end of block
0
661 adjustCursor(op);-
662 }
never executed: end of block
0
663-
664 if (adjustX)
adjustXDescription
TRUEnever evaluated
FALSEnever evaluated
0
665 setX();
never executed: setX();
0
666-
667 return moved;
never executed: return moved;
0
668}-
669-
670QTextTable *QTextCursorPrivate::complexSelectionTable() const-
671{-
672 if (position == anchor)
position == anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
673 return 0;
never executed: return 0;
0
674-
675 QTextTable *t = qobject_cast<QTextTable *>(priv->frameAt(position));-
676 if (t) {
tDescription
TRUEnever evaluated
FALSEnever evaluated
0
677 QTextTableCell cell_pos = t->cellAt(position);-
678 QTextTableCell cell_anchor = t->cellAt(adjusted_anchor);-
679-
680 Q_ASSERT(cell_anchor.isValid());-
681-
682 if (cell_pos == cell_anchor)
cell_pos == cell_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
683 t = 0;
never executed: t = 0;
0
684 }
never executed: end of block
0
685 return t;
never executed: return t;
0
686}-
687-
688void QTextCursorPrivate::selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const-
689{-
690 *firstRow = -1;-
691 *firstColumn = -1;-
692 *numRows = -1;-
693 *numColumns = -1;-
694-
695 if (position == anchor)
position == anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
696 return;
never executed: return;
0
697-
698 QTextTable *t = qobject_cast<QTextTable *>(priv->frameAt(position));-
699 if (!t)
!tDescription
TRUEnever evaluated
FALSEnever evaluated
0
700 return;
never executed: return;
0
701-
702 QTextTableCell cell_pos = t->cellAt(position);-
703 QTextTableCell cell_anchor = t->cellAt(adjusted_anchor);-
704-
705 Q_ASSERT(cell_anchor.isValid());-
706-
707 if (cell_pos == cell_anchor)
cell_pos == cell_anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
708 return;
never executed: return;
0
709-
710 *firstRow = qMin(cell_pos.row(), cell_anchor.row());-
711 *firstColumn = qMin(cell_pos.column(), cell_anchor.column());-
712 *numRows = qMax(cell_pos.row() + cell_pos.rowSpan(), cell_anchor.row() + cell_anchor.rowSpan()) - *firstRow;-
713 *numColumns = qMax(cell_pos.column() + cell_pos.columnSpan(), cell_anchor.column() + cell_anchor.columnSpan()) - *firstColumn;-
714}
never executed: end of block
0
715-
716static void setBlockCharFormatHelper(QTextDocumentPrivate *priv, int pos1, int pos2,-
717 const QTextCharFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)-
718{-
719 QTextBlock it = priv->blocksFind(pos1);-
720 QTextBlock end = priv->blocksFind(pos2);-
721 if (end.isValid())
end.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
722 end = end.next();
never executed: end = end.next();
0
723-
724 for (; it != end; it = it.next()) {
it != endDescription
TRUEnever evaluated
FALSEnever evaluated
0
725 priv->setCharFormat(it.position() - 1, 1, format, changeMode);-
726 }
never executed: end of block
0
727}
never executed: end of block
0
728-
729void QTextCursorPrivate::setBlockCharFormat(const QTextCharFormat &_format,-
730 QTextDocumentPrivate::FormatChangeMode changeMode)-
731{-
732 priv->beginEditBlock();-
733-
734 QTextCharFormat format = _format;-
735 format.clearProperty(QTextFormat::ObjectIndex);-
736-
737 QTextTable *table = complexSelectionTable();-
738 if (table) {
tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
739 int row_start, col_start, num_rows, num_cols;-
740 selectedTableCells(&row_start, &num_rows, &col_start, &num_cols);-
741-
742 Q_ASSERT(row_start != -1);-
743 for (int r = row_start; r < row_start + num_rows; ++r) {
r < row_start + num_rowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
744 for (int c = col_start; c < col_start + num_cols; ++c) {
c < col_start + num_colsDescription
TRUEnever evaluated
FALSEnever evaluated
0
745 QTextTableCell cell = table->cellAt(r, c);-
746 int rspan = cell.rowSpan();-
747 int cspan = cell.columnSpan();-
748 if (rspan != 1) {
rspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
749 int cr = cell.row();-
750 if (cr != r)
cr != rDescription
TRUEnever evaluated
FALSEnever evaluated
0
751 continue;
never executed: continue;
0
752 }
never executed: end of block
0
753 if (cspan != 1) {
cspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
754 int cc = cell.column();-
755 if (cc != c)
cc != cDescription
TRUEnever evaluated
FALSEnever evaluated
0
756 continue;
never executed: continue;
0
757 }
never executed: end of block
0
758-
759 int pos1 = cell.firstPosition();-
760 int pos2 = cell.lastPosition();-
761 setBlockCharFormatHelper(priv, pos1, pos2, format, changeMode);-
762 }
never executed: end of block
0
763 }
never executed: end of block
0
764 } else {
never executed: end of block
0
765 int pos1 = position;-
766 int pos2 = adjusted_anchor;-
767 if (pos1 > pos2) {
pos1 > pos2Description
TRUEnever evaluated
FALSEnever evaluated
0
768 pos1 = adjusted_anchor;-
769 pos2 = position;-
770 }
never executed: end of block
0
771-
772 setBlockCharFormatHelper(priv, pos1, pos2, format, changeMode);-
773 }
never executed: end of block
0
774 priv->endEditBlock();-
775}
never executed: end of block
0
776-
777-
778void QTextCursorPrivate::setBlockFormat(const QTextBlockFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode)-
779{-
780 QTextTable *table = complexSelectionTable();-
781 if (table) {
tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
782 priv->beginEditBlock();-
783 int row_start, col_start, num_rows, num_cols;-
784 selectedTableCells(&row_start, &num_rows, &col_start, &num_cols);-
785-
786 Q_ASSERT(row_start != -1);-
787 for (int r = row_start; r < row_start + num_rows; ++r) {
r < row_start + num_rowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
788 for (int c = col_start; c < col_start + num_cols; ++c) {
c < col_start + num_colsDescription
TRUEnever evaluated
FALSEnever evaluated
0
789 QTextTableCell cell = table->cellAt(r, c);-
790 int rspan = cell.rowSpan();-
791 int cspan = cell.columnSpan();-
792 if (rspan != 1) {
rspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
793 int cr = cell.row();-
794 if (cr != r)
cr != rDescription
TRUEnever evaluated
FALSEnever evaluated
0
795 continue;
never executed: continue;
0
796 }
never executed: end of block
0
797 if (cspan != 1) {
cspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
798 int cc = cell.column();-
799 if (cc != c)
cc != cDescription
TRUEnever evaluated
FALSEnever evaluated
0
800 continue;
never executed: continue;
0
801 }
never executed: end of block
0
802-
803 int pos1 = cell.firstPosition();-
804 int pos2 = cell.lastPosition();-
805 priv->setBlockFormat(priv->blocksFind(pos1), priv->blocksFind(pos2), format, changeMode);-
806 }
never executed: end of block
0
807 }
never executed: end of block
0
808 priv->endEditBlock();-
809 } else {
never executed: end of block
0
810 int pos1 = position;-
811 int pos2 = adjusted_anchor;-
812 if (pos1 > pos2) {
pos1 > pos2Description
TRUEnever evaluated
FALSEnever evaluated
0
813 pos1 = adjusted_anchor;-
814 pos2 = position;-
815 }
never executed: end of block
0
816-
817 priv->setBlockFormat(priv->blocksFind(pos1), priv->blocksFind(pos2), format, changeMode);-
818 }
never executed: end of block
0
819}-
820-
821void QTextCursorPrivate::setCharFormat(const QTextCharFormat &_format, QTextDocumentPrivate::FormatChangeMode changeMode)-
822{-
823 Q_ASSERT(position != anchor);-
824-
825 QTextCharFormat format = _format;-
826 format.clearProperty(QTextFormat::ObjectIndex);-
827-
828 QTextTable *table = complexSelectionTable();-
829 if (table) {
tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
830 priv->beginEditBlock();-
831 int row_start, col_start, num_rows, num_cols;-
832 selectedTableCells(&row_start, &num_rows, &col_start, &num_cols);-
833-
834 Q_ASSERT(row_start != -1);-
835 for (int r = row_start; r < row_start + num_rows; ++r) {
r < row_start + num_rowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
836 for (int c = col_start; c < col_start + num_cols; ++c) {
c < col_start + num_colsDescription
TRUEnever evaluated
FALSEnever evaluated
0
837 QTextTableCell cell = table->cellAt(r, c);-
838 int rspan = cell.rowSpan();-
839 int cspan = cell.columnSpan();-
840 if (rspan != 1) {
rspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
841 int cr = cell.row();-
842 if (cr != r)
cr != rDescription
TRUEnever evaluated
FALSEnever evaluated
0
843 continue;
never executed: continue;
0
844 }
never executed: end of block
0
845 if (cspan != 1) {
cspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
846 int cc = cell.column();-
847 if (cc != c)
cc != cDescription
TRUEnever evaluated
FALSEnever evaluated
0
848 continue;
never executed: continue;
0
849 }
never executed: end of block
0
850-
851 int pos1 = cell.firstPosition();-
852 int pos2 = cell.lastPosition();-
853 priv->setCharFormat(pos1, pos2-pos1, format, changeMode);-
854 }
never executed: end of block
0
855 }
never executed: end of block
0
856 priv->endEditBlock();-
857 } else {
never executed: end of block
0
858 int pos1 = position;-
859 int pos2 = adjusted_anchor;-
860 if (pos1 > pos2) {
pos1 > pos2Description
TRUEnever evaluated
FALSEnever evaluated
0
861 pos1 = adjusted_anchor;-
862 pos2 = position;-
863 }
never executed: end of block
0
864-
865 priv->setCharFormat(pos1, pos2-pos1, format, changeMode);-
866 }
never executed: end of block
0
867}-
868-
869-
870QTextLayout *QTextCursorPrivate::blockLayout(QTextBlock &block) const{-
871 QTextLayout *tl = block.layout();-
872 if (!tl->lineCount() && priv->layout())
!tl->lineCount()Description
TRUEnever evaluated
FALSEnever evaluated
priv->layout()Description
TRUEnever evaluated
FALSEnever evaluated
0
873 priv->layout()->blockBoundingRect(block);
never executed: priv->layout()->blockBoundingRect(block);
0
874 return tl;
never executed: return tl;
0
875}-
876-
877/*!-
878 \class QTextCursor-
879 \reentrant-
880 \inmodule QtGui-
881-
882 \brief The QTextCursor class offers an API to access and modify QTextDocuments.-
883-
884 \ingroup richtext-processing-
885 \ingroup shared-
886-
887 Text cursors are objects that are used to access and modify the-
888 contents and underlying structure of text documents via a-
889 programming interface that mimics the behavior of a cursor in a-
890 text editor. QTextCursor contains information about both the-
891 cursor's position within a QTextDocument and any selection that it-
892 has made.-
893-
894 QTextCursor is modeled on the way a text cursor behaves in a text-
895 editor, providing a programmatic means of performing standard-
896 actions through the user interface. A document can be thought of-
897 as a single string of characters. The cursor's current position()-
898 then is always either \e between two consecutive characters in the-
899 string, or else \e before the very first character or \e after the-
900 very last character in the string. Documents can also contain-
901 tables, lists, images, and other objects in addition to text but,-
902 from the developer's point of view, the document can be treated as-
903 one long string. Some portions of that string can be considered-
904 to lie within particular blocks (e.g. paragraphs), or within a-
905 table's cell, or a list's item, or other structural elements. When-
906 we refer to "current character" we mean the character immediately-
907 \e before the cursor position() in the document. Similarly, the-
908 "current block" is the block that contains the cursor position().-
909-
910 A QTextCursor also has an anchor() position. The text that is-
911 between the anchor() and the position() is the selection. If-
912 anchor() == position() there is no selection.-
913-
914 The cursor position can be changed programmatically using-
915 setPosition() and movePosition(); the latter can also be used to-
916 select text. For selections see selectionStart(), selectionEnd(),-
917 hasSelection(), clearSelection(), and removeSelectedText().-
918-
919 If the position() is at the start of a block, atBlockStart()-
920 returns \c true; and if it is at the end of a block, atBlockEnd() returns-
921 true. The format of the current character is returned by-
922 charFormat(), and the format of the current block is returned by-
923 blockFormat().-
924-
925 Formatting can be applied to the current text document using the-
926 setCharFormat(), mergeCharFormat(), setBlockFormat() and-
927 mergeBlockFormat() functions. The 'set' functions will replace the-
928 cursor's current character or block format, while the 'merge'-
929 functions add the given format properties to the cursor's current-
930 format. If the cursor has a selection, the given format is applied-
931 to the current selection. Note that when only a part of a block is-
932 selected, the block format is applied to the entire block. The text-
933 at the current character position can be turned into a list using-
934 createList().-
935-
936 Deletions can be achieved using deleteChar(),-
937 deletePreviousChar(), and removeSelectedText().-
938-
939 Text strings can be inserted into the document with the insertText()-
940 function, blocks (representing new paragraphs) can be inserted with-
941 insertBlock().-
942-
943 Existing fragments of text can be inserted with insertFragment() but,-
944 if you want to insert pieces of text in various formats, it is usually-
945 still easier to use insertText() and supply a character format.-
946-
947 Various types of higher-level structure can also be inserted into the-
948 document with the cursor:-
949-
950 \list-
951 \li Lists are ordered sequences of block elements that are decorated with-
952 bullet points or symbols. These are inserted in a specified format-
953 with insertList().-
954 \li Tables are inserted with the insertTable() function, and can be-
955 given an optional format. These contain an array of cells that can-
956 be traversed using the cursor.-
957 \li Inline images are inserted with insertImage(). The image to be-
958 used can be specified in an image format, or by name.-
959 \li Frames are inserted by calling insertFrame() with a specified format.-
960 \endlist-
961-
962 Actions can be grouped (i.e. treated as a single action for-
963 undo/redo) using beginEditBlock() and endEditBlock().-
964-
965 Cursor movements are limited to valid cursor positions. In Latin-
966 writing this is between any two consecutive characters in the-
967 text, before the first character, or after the last character. In-
968 some other writing systems cursor movements are limited to-
969 "clusters" (e.g. a syllable in Devanagari, or a base letter plus-
970 diacritics). Functions such as movePosition() and deleteChar()-
971 limit cursor movement to these valid positions.-
972-
973 \sa {Rich Text Processing}-
974-
975*/-
976-
977/*!-
978 \enum QTextCursor::MoveOperation-
979-
980 \value NoMove Keep the cursor where it is-
981-
982 \value Start Move to the start of the document.-
983 \value StartOfLine Move to the start of the current line.-
984 \value StartOfBlock Move to the start of the current block.-
985 \value StartOfWord Move to the start of the current word.-
986 \value PreviousBlock Move to the start of the previous block.-
987 \value PreviousCharacter Move to the previous character.-
988 \value PreviousWord Move to the beginning of the previous word.-
989 \value Up Move up one line.-
990 \value Left Move left one character.-
991 \value WordLeft Move left one word.-
992-
993 \value End Move to the end of the document.-
994 \value EndOfLine Move to the end of the current line.-
995 \value EndOfWord Move to the end of the current word.-
996 \value EndOfBlock Move to the end of the current block.-
997 \value NextBlock Move to the beginning of the next block.-
998 \value NextCharacter Move to the next character.-
999 \value NextWord Move to the next word.-
1000 \value Down Move down one line.-
1001 \value Right Move right one character.-
1002 \value WordRight Move right one word.-
1003-
1004 \value NextCell Move to the beginning of the next table cell inside the-
1005 current table. If the current cell is the last cell in the row, the-
1006 cursor will move to the first cell in the next row.-
1007 \value PreviousCell Move to the beginning of the previous table cell-
1008 inside the current table. If the current cell is the first cell in-
1009 the row, the cursor will move to the last cell in the previous row.-
1010 \value NextRow Move to the first new cell of the next row in the current-
1011 table.-
1012 \value PreviousRow Move to the last cell of the previous row in the-
1013 current table.-
1014-
1015 \sa movePosition()-
1016*/-
1017-
1018/*!-
1019 \enum QTextCursor::MoveMode-
1020-
1021 \value MoveAnchor Moves the anchor to the same position as the cursor itself.-
1022 \value KeepAnchor Keeps the anchor where it is.-
1023-
1024 If the anchor() is kept where it is and the position() is moved,-
1025 the text in between will be selected.-
1026*/-
1027-
1028/*!-
1029 \enum QTextCursor::SelectionType-
1030-
1031 This enum describes the types of selection that can be applied with the-
1032 select() function.-
1033-
1034 \value Document Selects the entire document.-
1035 \value BlockUnderCursor Selects the block of text under the cursor.-
1036 \value LineUnderCursor Selects the line of text under the cursor.-
1037 \value WordUnderCursor Selects the word under the cursor. If the cursor-
1038 is not positioned within a string of selectable characters, no-
1039 text is selected.-
1040*/-
1041-
1042/*!-
1043 Constructs a null cursor.-
1044 */-
1045QTextCursor::QTextCursor()-
1046 : d(0)-
1047{-
1048}
never executed: end of block
0
1049-
1050/*!-
1051 Constructs a cursor pointing to the beginning of the \a document.-
1052 */-
1053QTextCursor::QTextCursor(QTextDocument *document)-
1054 : d(new QTextCursorPrivate(document->docHandle()))-
1055{-
1056}
never executed: end of block
0
1057-
1058/*!-
1059 Constructs a cursor pointing to the beginning of the \a frame.-
1060*/-
1061QTextCursor::QTextCursor(QTextFrame *frame)-
1062 : d(new QTextCursorPrivate(frame->document()->docHandle()))-
1063{-
1064 d->adjusted_anchor = d->anchor = d->position = frame->firstPosition();-
1065}
never executed: end of block
0
1066-
1067-
1068/*!-
1069 Constructs a cursor pointing to the beginning of the \a block.-
1070*/-
1071QTextCursor::QTextCursor(const QTextBlock &block)-
1072 : d(new QTextCursorPrivate(block.docHandle()))-
1073{-
1074 d->adjusted_anchor = d->anchor = d->position = block.position();-
1075}
never executed: end of block
0
1076-
1077-
1078/*!-
1079 \internal-
1080 */-
1081QTextCursor::QTextCursor(QTextDocumentPrivate *p, int pos)-
1082 : d(new QTextCursorPrivate(p))-
1083{-
1084 d->adjusted_anchor = d->anchor = d->position = pos;-
1085-
1086 d->setX();-
1087}
never executed: end of block
0
1088-
1089/*!-
1090 \internal-
1091*/-
1092QTextCursor::QTextCursor(QTextCursorPrivate *d)-
1093{-
1094 Q_ASSERT(d);-
1095 this->d = d;-
1096}
never executed: end of block
0
1097-
1098/*!-
1099 Constructs a new cursor that is a copy of \a cursor.-
1100 */-
1101QTextCursor::QTextCursor(const QTextCursor &cursor)-
1102{-
1103 d = cursor.d;-
1104}
never executed: end of block
0
1105-
1106/*!-
1107 Makes a copy of \a cursor and assigns it to this QTextCursor. Note-
1108 that QTextCursor is an \l{Implicitly Shared Classes}{implicitly-
1109 shared} class.-
1110-
1111 */-
1112QTextCursor &QTextCursor::operator=(const QTextCursor &cursor)-
1113{-
1114 d = cursor.d;-
1115 return *this;
never executed: return *this;
0
1116}-
1117-
1118/*!-
1119 \fn void QTextCursor::swap(QTextCursor &other)-
1120 \since 5.0-
1121-
1122 Swaps this text cursor instance with \a other. This function is-
1123 very fast and never fails.-
1124*/-
1125-
1126/*!-
1127 Destroys the QTextCursor.-
1128 */-
1129QTextCursor::~QTextCursor()-
1130{-
1131}-
1132-
1133/*!-
1134 Returns \c true if the cursor is null; otherwise returns \c false. A null-
1135 cursor is created by the default constructor.-
1136 */-
1137bool QTextCursor::isNull() const-
1138{-
1139 return !d || !d->priv;
never executed: return !d || !d->priv;
0
1140}-
1141-
1142/*!-
1143 Moves the cursor to the absolute position in the document specified by-
1144 \a pos using a \c MoveMode specified by \a m. The cursor is positioned-
1145 between characters.-
1146-
1147 \sa position(), movePosition(), anchor()-
1148*/-
1149void QTextCursor::setPosition(int pos, MoveMode m)-
1150{-
1151 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1152 return;
never executed: return;
0
1153-
1154 if (pos < 0 || pos >= d->priv->length()) {
pos < 0Description
TRUEnever evaluated
FALSEnever evaluated
pos >= d->priv->length()Description
TRUEnever evaluated
FALSEnever evaluated
0
1155 qWarning("QTextCursor::setPosition: Position '%d' out of range", pos);-
1156 return;
never executed: return;
0
1157 }-
1158-
1159 d->setPosition(pos);-
1160 if (m == MoveAnchor) {
m == MoveAnchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1161 d->anchor = pos;-
1162 d->adjusted_anchor = pos;-
1163 } else { // keep anchor
never executed: end of block
0
1164 QTextCursor::MoveOperation op;-
1165 if (pos < d->anchor)
pos < d->anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1166 op = QTextCursor::Left;
never executed: op = QTextCursor::Left;
0
1167 else-
1168 op = QTextCursor::Right;
never executed: op = QTextCursor::Right;
0
1169 d->adjustCursor(op);-
1170 }
never executed: end of block
0
1171 d->setX();-
1172}
never executed: end of block
0
1173-
1174/*!-
1175 Returns the absolute position of the cursor within the document.-
1176 The cursor is positioned between characters.-
1177-
1178 \sa setPosition(), movePosition(), anchor(), positionInBlock()-
1179*/-
1180int QTextCursor::position() const-
1181{-
1182 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1183 return -1;
never executed: return -1;
0
1184 return d->position;
never executed: return d->position;
0
1185}-
1186-
1187/*!-
1188 \since 4.7-
1189 Returns the relative position of the cursor within the block.-
1190 The cursor is positioned between characters.-
1191-
1192 This is equivalent to \c{ position() - block().position()}.-
1193-
1194 \sa position()-
1195*/-
1196int QTextCursor::positionInBlock() const-
1197{-
1198 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1199 return 0;
never executed: return 0;
0
1200 return d->position - d->block().position();
never executed: return d->position - d->block().position();
0
1201}-
1202-
1203/*!-
1204 Returns the anchor position; this is the same as position() unless-
1205 there is a selection in which case position() marks one end of the-
1206 selection and anchor() marks the other end. Just like the cursor-
1207 position, the anchor position is between characters.-
1208-
1209 \sa position(), setPosition(), movePosition(), selectionStart(), selectionEnd()-
1210*/-
1211int QTextCursor::anchor() const-
1212{-
1213 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1214 return -1;
never executed: return -1;
0
1215 return d->anchor;
never executed: return d->anchor;
0
1216}-
1217-
1218/*!-
1219 \fn bool QTextCursor::movePosition(MoveOperation operation, MoveMode mode, int n)-
1220-
1221 Moves the cursor by performing the given \a operation \a n times, using the specified-
1222 \a mode, and returns \c true if all operations were completed successfully; otherwise-
1223 returns \c false.-
1224-
1225 For example, if this function is repeatedly used to seek to the end of the next-
1226 word, it will eventually fail when the end of the document is reached.-
1227-
1228 By default, the move operation is performed once (\a n = 1).-
1229-
1230 If \a mode is \c KeepAnchor, the cursor selects the text it moves-
1231 over. This is the same effect that the user achieves when they-
1232 hold down the Shift key and move the cursor with the cursor keys.-
1233-
1234 \sa setVisualNavigation()-
1235*/-
1236bool QTextCursor::movePosition(MoveOperation op, MoveMode mode, int n)-
1237{-
1238 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1239 return false;
never executed: return false;
0
1240 switch (op) {-
1241 case Start:
never executed: case Start:
0
1242 case StartOfLine:
never executed: case StartOfLine:
0
1243 case End:
never executed: case End:
0
1244 case EndOfLine:
never executed: case EndOfLine:
0
1245 n = 1;-
1246 break;
never executed: break;
0
1247 default: break;
never executed: break;
never executed: default:
0
1248 }-
1249-
1250 int previousPosition = d->position;-
1251 for (; n > 0; --n) {
n > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1252 if (!d->movePosition(op, mode))
!d->movePosition(op, mode)Description
TRUEnever evaluated
FALSEnever evaluated
0
1253 return false;
never executed: return false;
0
1254 }
never executed: end of block
0
1255-
1256 if (d->visualNavigation && !d->block().isVisible()) {
d->visualNavigationDescription
TRUEnever evaluated
FALSEnever evaluated
!d->block().isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1257 QTextBlock b = d->block();-
1258 if (previousPosition < d->position) {
previousPosition < d->positionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1259 while (!b.next().isVisible())
!b.next().isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1260 b = b.next();
never executed: b = b.next();
0
1261 d->setPosition(b.position() + b.length() - 1);-
1262 } else {
never executed: end of block
0
1263 while (!b.previous().isVisible())
!b.previous().isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1264 b = b.previous();
never executed: b = b.previous();
0
1265 d->setPosition(b.position());-
1266 }
never executed: end of block
0
1267 if (mode == QTextCursor::MoveAnchor)
mode == QTextC...or::MoveAnchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1268 d->anchor = d->position;
never executed: d->anchor = d->position;
0
1269 while (d->movePosition(op, mode)
d->movePosition(op, mode)Description
TRUEnever evaluated
FALSEnever evaluated
0
1270 && !d->block().isVisible())
!d->block().isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1271 ;
never executed: ;
0
1272-
1273 }
never executed: end of block
0
1274 return true;
never executed: return true;
0
1275}-
1276-
1277/*!-
1278 \since 4.4-
1279-
1280 Returns \c true if the cursor does visual navigation; otherwise-
1281 returns \c false.-
1282-
1283 Visual navigation means skipping over hidden text paragraphs. The-
1284 default is false.-
1285-
1286 \sa setVisualNavigation(), movePosition()-
1287 */-
1288bool QTextCursor::visualNavigation() const-
1289{-
1290 return d ? d->visualNavigation : false;
never executed: return d ? d->visualNavigation : false;
0
1291}-
1292-
1293/*!-
1294 \since 4.4-
1295-
1296 Sets visual navigation to \a b.-
1297-
1298 Visual navigation means skipping over hidden text paragraphs. The-
1299 default is false.-
1300-
1301 \sa visualNavigation(), movePosition()-
1302 */-
1303void QTextCursor::setVisualNavigation(bool b)-
1304{-
1305 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1306 d->visualNavigation = b;
never executed: d->visualNavigation = b;
0
1307}
never executed: end of block
0
1308-
1309-
1310/*!-
1311 \since 4.7-
1312-
1313 Sets the visual x position for vertical cursor movements to \a x.-
1314-
1315 The vertical movement x position is cleared automatically when the cursor moves horizontally, and kept-
1316 unchanged when the cursor moves vertically. The mechanism allows the cursor to move up and down on a-
1317 visually straight line with proportional fonts, and to gently "jump" over short lines.-
1318-
1319 A value of -1 indicates no predefined x position. It will then be set automatically the next time the-
1320 cursor moves up or down.-
1321-
1322 \sa verticalMovementX()-
1323 */-
1324void QTextCursor::setVerticalMovementX(int x)-
1325{-
1326 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1327 d->x = x;
never executed: d->x = x;
0
1328}
never executed: end of block
0
1329-
1330/*! \since 4.7-
1331-
1332 Returns the visual x position for vertical cursor movements.-
1333-
1334 A value of -1 indicates no predefined x position. It will then be set automatically the next time the-
1335 cursor moves up or down.-
1336-
1337 \sa setVerticalMovementX()-
1338 */-
1339int QTextCursor::verticalMovementX() const-
1340{-
1341 return d ? d->x : -1;
never executed: return d ? d->x : -1;
0
1342}-
1343-
1344/*!-
1345 \since 4.7-
1346-
1347 Returns whether the cursor should keep its current position when text gets inserted at the position of the-
1348 cursor.-
1349-
1350 The default is false;-
1351-
1352 \sa setKeepPositionOnInsert()-
1353 */-
1354bool QTextCursor::keepPositionOnInsert() const-
1355{-
1356 return d ? d->keepPositionOnInsert : false;
never executed: return d ? d->keepPositionOnInsert : false;
0
1357}-
1358-
1359/*!-
1360 \since 4.7-
1361-
1362 Defines whether the cursor should keep its current position when text gets inserted at the current position of the-
1363 cursor.-
1364-
1365 If \a b is true, the cursor keeps its current position when text gets inserted at the positing of the cursor.-
1366 If \a b is false, the cursor moves along with the inserted text.-
1367-
1368 The default is false.-
1369-
1370 Note that a cursor always moves when text is inserted before the current position of the cursor, and it-
1371 always keeps its position when text is inserted after the current position of the cursor.-
1372-
1373 \sa keepPositionOnInsert()-
1374 */-
1375void QTextCursor::setKeepPositionOnInsert(bool b)-
1376{-
1377 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1378 d->keepPositionOnInsert = b;
never executed: d->keepPositionOnInsert = b;
0
1379}
never executed: end of block
0
1380-
1381-
1382-
1383/*!-
1384 Inserts \a text at the current position, using the current-
1385 character format.-
1386-
1387 If there is a selection, the selection is deleted and replaced by-
1388 \a text, for example:-
1389 \snippet code/src_gui_text_qtextcursor.cpp 0-
1390 This clears any existing selection, selects the word at the cursor-
1391 (i.e. from position() forward), and replaces the selection with-
1392 the phrase "Hello World".-
1393-
1394 Any ASCII linefeed characters (\\n) in the inserted text are transformed-
1395 into unicode block separators, corresponding to insertBlock() calls.-
1396-
1397 \sa charFormat(), hasSelection()-
1398*/-
1399void QTextCursor::insertText(const QString &text)-
1400{-
1401 QTextCharFormat fmt = charFormat();-
1402 fmt.clearProperty(QTextFormat::ObjectType);-
1403 insertText(text, fmt);-
1404}
never executed: end of block
0
1405-
1406/*!-
1407 \fn void QTextCursor::insertText(const QString &text, const QTextCharFormat &format)-
1408 \overload-
1409-
1410 Inserts \a text at the current position with the given \a format.-
1411*/-
1412void QTextCursor::insertText(const QString &text, const QTextCharFormat &_format)-
1413{-
1414 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1415 return;
never executed: return;
0
1416-
1417 Q_ASSERT(_format.isValid());-
1418-
1419 QTextCharFormat format = _format;-
1420 format.clearProperty(QTextFormat::ObjectIndex);-
1421-
1422 bool hasEditBlock = false;-
1423-
1424 if (d->anchor != d->position) {
d->anchor != d->positionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1425 hasEditBlock = true;-
1426 d->priv->beginEditBlock();-
1427 d->remove();-
1428 }
never executed: end of block
0
1429-
1430 if (!text.isEmpty()) {
!text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1431 QTextFormatCollection *formats = d->priv->formatCollection();-
1432 int formatIdx = formats->indexForFormat(format);-
1433 Q_ASSERT(formats->format(formatIdx).isCharFormat());-
1434-
1435 QTextBlockFormat blockFmt = blockFormat();-
1436-
1437-
1438 int textStart = d->priv->text.length();-
1439 int blockStart = 0;-
1440 d->priv->text += text;-
1441 int textEnd = d->priv->text.length();-
1442-
1443 for (int i = 0; i < text.length(); ++i) {
i < text.length()Description
TRUEnever evaluated
FALSEnever evaluated
0
1444 QChar ch = text.at(i);-
1445-
1446 const int blockEnd = i;-
1447-
1448 if (ch == QLatin1Char('\r')
ch == QLatin1Char('\r')Description
TRUEnever evaluated
FALSEnever evaluated
0
1449 && (i + 1) < text.length()
(i + 1) < text.length()Description
TRUEnever evaluated
FALSEnever evaluated
0
1450 && text.at(i + 1) == QLatin1Char('\n')) {
text.at(i + 1)...tin1Char('\n')Description
TRUEnever evaluated
FALSEnever evaluated
0
1451 ++i;-
1452 ch = text.at(i);-
1453 }
never executed: end of block
0
1454-
1455 if (ch == QLatin1Char('\n')
ch == QLatin1Char('\n')Description
TRUEnever evaluated
FALSEnever evaluated
0
1456 || ch == QChar::ParagraphSeparator
ch == QChar::P...graphSeparatorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1457 || ch == QTextBeginningOfFrame
ch == QChar(0xfdd0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1458 || ch == QTextEndOfFrame
ch == QChar(0xfdd1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1459 || ch == QLatin1Char('\r')) {
ch == QLatin1Char('\r')Description
TRUEnever evaluated
FALSEnever evaluated
0
1460-
1461 if (!hasEditBlock) {
!hasEditBlockDescription
TRUEnever evaluated
FALSEnever evaluated
0
1462 hasEditBlock = true;-
1463 d->priv->beginEditBlock();-
1464 }
never executed: end of block
0
1465-
1466 if (blockEnd > blockStart)
blockEnd > blockStartDescription
TRUEnever evaluated
FALSEnever evaluated
0
1467 d->priv->insert(d->position, textStart + blockStart, blockEnd - blockStart, formatIdx);
never executed: d->priv->insert(d->position, textStart + blockStart, blockEnd - blockStart, formatIdx);
0
1468-
1469 d->insertBlock(blockFmt, format);-
1470 blockStart = i + 1;-
1471 }
never executed: end of block
0
1472 }
never executed: end of block
0
1473 if (textStart + blockStart < textEnd)
textStart + bl...tart < textEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
1474 d->priv->insert(d->position, textStart + blockStart, textEnd - textStart - blockStart, formatIdx);
never executed: d->priv->insert(d->position, textStart + blockStart, textEnd - textStart - blockStart, formatIdx);
0
1475 }
never executed: end of block
0
1476 if (hasEditBlock)
hasEditBlockDescription
TRUEnever evaluated
FALSEnever evaluated
0
1477 d->priv->endEditBlock();
never executed: d->priv->endEditBlock();
0
1478 d->setX();-
1479}
never executed: end of block
0
1480-
1481/*!-
1482 If there is no selected text, deletes the character \e at the-
1483 current cursor position; otherwise deletes the selected text.-
1484-
1485 \sa deletePreviousChar(), hasSelection(), clearSelection()-
1486*/-
1487void QTextCursor::deleteChar()-
1488{-
1489 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1490 return;
never executed: return;
0
1491-
1492 if (d->position != d->anchor) {
d->position != d->anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1493 removeSelectedText();-
1494 return;
never executed: return;
0
1495 }-
1496-
1497 if (!d->canDelete(d->position))
!d->canDelete(d->position)Description
TRUEnever evaluated
FALSEnever evaluated
0
1498 return;
never executed: return;
0
1499 d->adjusted_anchor = d->anchor =-
1500 d->priv->nextCursorPosition(d->anchor, QTextLayout::SkipCharacters);-
1501 d->remove();-
1502 d->setX();-
1503}
never executed: end of block
0
1504-
1505/*!-
1506 If there is no selected text, deletes the character \e before the-
1507 current cursor position; otherwise deletes the selected text.-
1508-
1509 \sa deleteChar(), hasSelection(), clearSelection()-
1510*/-
1511void QTextCursor::deletePreviousChar()-
1512{-
1513 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1514 return;
never executed: return;
0
1515-
1516 if (d->position != d->anchor) {
d->position != d->anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1517 removeSelectedText();-
1518 return;
never executed: return;
0
1519 }-
1520-
1521 if (d->anchor < 1 || !d->canDelete(d->anchor-1))
d->anchor < 1Description
TRUEnever evaluated
FALSEnever evaluated
!d->canDelete(d->anchor-1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1522 return;
never executed: return;
0
1523 d->anchor--;-
1524-
1525 QTextDocumentPrivate::FragmentIterator fragIt = d->priv->find(d->anchor);-
1526 const QTextFragmentData * const frag = fragIt.value();-
1527 int fpos = fragIt.position();-
1528 QChar uc = d->priv->buffer().at(d->anchor - fpos + frag->stringPosition);-
1529 if (d->anchor > fpos && uc.isLowSurrogate()) {
d->anchor > fposDescription
TRUEnever evaluated
FALSEnever evaluated
uc.isLowSurrogate()Description
TRUEnever evaluated
FALSEnever evaluated
0
1530 // second half of a surrogate, check if we have the first half as well,-
1531 // if yes delete both at once-
1532 uc = d->priv->buffer().at(d->anchor - 1 - fpos + frag->stringPosition);-
1533 if (uc.isHighSurrogate())
uc.isHighSurrogate()Description
TRUEnever evaluated
FALSEnever evaluated
0
1534 --d->anchor;
never executed: --d->anchor;
0
1535 }
never executed: end of block
0
1536-
1537 d->adjusted_anchor = d->anchor;-
1538 d->remove();-
1539 d->setX();-
1540}
never executed: end of block
0
1541-
1542/*!-
1543 Selects text in the document according to the given \a selection.-
1544*/-
1545void QTextCursor::select(SelectionType selection)-
1546{-
1547 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1548 return;
never executed: return;
0
1549-
1550 clearSelection();-
1551-
1552 const QTextBlock block = d->block();-
1553-
1554 switch (selection) {-
1555 case LineUnderCursor:
never executed: case LineUnderCursor:
0
1556 movePosition(StartOfLine);-
1557 movePosition(EndOfLine, KeepAnchor);-
1558 break;
never executed: break;
0
1559 case WordUnderCursor:
never executed: case WordUnderCursor:
0
1560 movePosition(StartOfWord);-
1561 movePosition(EndOfWord, KeepAnchor);-
1562 break;
never executed: break;
0
1563 case BlockUnderCursor:
never executed: case BlockUnderCursor:
0
1564 if (block.length() == 1) // no content
block.length() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1565 break;
never executed: break;
0
1566 movePosition(StartOfBlock);-
1567 // also select the paragraph separator-
1568 if (movePosition(PreviousBlock)) {
movePosition(PreviousBlock)Description
TRUEnever evaluated
FALSEnever evaluated
0
1569 movePosition(EndOfBlock);-
1570 movePosition(NextBlock, KeepAnchor);-
1571 }
never executed: end of block
0
1572 movePosition(EndOfBlock, KeepAnchor);-
1573 break;
never executed: break;
0
1574 case Document:
never executed: case Document:
0
1575 movePosition(Start);-
1576 movePosition(End, KeepAnchor);-
1577 break;
never executed: break;
0
1578 }-
1579}
never executed: end of block
0
1580-
1581/*!-
1582 Returns \c true if the cursor contains a selection; otherwise returns \c false.-
1583*/-
1584bool QTextCursor::hasSelection() const-
1585{-
1586 return !!d && d->position != d->anchor;
never executed: return !!d && d->position != d->anchor;
0
1587}-
1588-
1589-
1590/*!-
1591 Returns \c true if the cursor contains a selection that is not simply a-
1592 range from selectionStart() to selectionEnd(); otherwise returns \c false.-
1593-
1594 Complex selections are ones that span at least two cells in a table;-
1595 their extent is specified by selectedTableCells().-
1596*/-
1597bool QTextCursor::hasComplexSelection() const-
1598{-
1599 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1600 return false;
never executed: return false;
0
1601-
1602 return d->complexSelectionTable() != 0;
never executed: return d->complexSelectionTable() != 0;
0
1603}-
1604-
1605/*!-
1606 If the selection spans over table cells, \a firstRow is populated-
1607 with the number of the first row in the selection, \a firstColumn-
1608 with the number of the first column in the selection, and \a-
1609 numRows and \a numColumns with the number of rows and columns in-
1610 the selection. If the selection does not span any table cells the-
1611 results are harmless but undefined.-
1612*/-
1613void QTextCursor::selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const-
1614{-
1615 *firstRow = -1;-
1616 *firstColumn = -1;-
1617 *numRows = -1;-
1618 *numColumns = -1;-
1619-
1620 if (!d || d->position == d->anchor)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
d->position == d->anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1621 return;
never executed: return;
0
1622-
1623 d->selectedTableCells(firstRow, numRows, firstColumn, numColumns);-
1624}
never executed: end of block
0
1625-
1626-
1627/*!-
1628 Clears the current selection by setting the anchor to the cursor position.-
1629-
1630 Note that it does \b{not} delete the text of the selection.-
1631-
1632 \sa removeSelectedText(), hasSelection()-
1633*/-
1634void QTextCursor::clearSelection()-
1635{-
1636 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1637 return;
never executed: return;
0
1638 d->adjusted_anchor = d->anchor = d->position;-
1639 d->currentCharFormat = -1;-
1640}
never executed: end of block
0
1641-
1642/*!-
1643 If there is a selection, its content is deleted; otherwise does-
1644 nothing.-
1645-
1646 \sa hasSelection()-
1647*/-
1648void QTextCursor::removeSelectedText()-
1649{-
1650 if (!d || !d->priv || d->position == d->anchor)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
d->position == d->anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1651 return;
never executed: return;
0
1652-
1653 d->priv->beginEditBlock();-
1654 d->remove();-
1655 d->priv->endEditBlock();-
1656 d->setX();-
1657}
never executed: end of block
0
1658-
1659/*!-
1660 Returns the start of the selection or position() if the-
1661 cursor doesn't have a selection.-
1662-
1663 \sa selectionEnd(), position(), anchor()-
1664*/-
1665int QTextCursor::selectionStart() const-
1666{-
1667 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1668 return -1;
never executed: return -1;
0
1669 return qMin(d->position, d->adjusted_anchor);
never executed: return qMin(d->position, d->adjusted_anchor);
0
1670}-
1671-
1672/*!-
1673 Returns the end of the selection or position() if the cursor-
1674 doesn't have a selection.-
1675-
1676 \sa selectionStart(), position(), anchor()-
1677*/-
1678int QTextCursor::selectionEnd() const-
1679{-
1680 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1681 return -1;
never executed: return -1;
0
1682 return qMax(d->position, d->adjusted_anchor);
never executed: return qMax(d->position, d->adjusted_anchor);
0
1683}-
1684-
1685static void getText(QString &text, QTextDocumentPrivate *priv, const QString &docText, int pos, int end)-
1686{-
1687 while (pos < end) {
pos < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
1688 QTextDocumentPrivate::FragmentIterator fragIt = priv->find(pos);-
1689 const QTextFragmentData * const frag = fragIt.value();-
1690-
1691 const int offsetInFragment = qMax(0, pos - fragIt.position());-
1692 const int len = qMin(int(frag->size_array[0] - offsetInFragment), end - pos);-
1693-
1694 text += QString(docText.constData() + frag->stringPosition + offsetInFragment, len);-
1695 pos += len;-
1696 }
never executed: end of block
0
1697}
never executed: end of block
0
1698-
1699/*!-
1700 Returns the current selection's text (which may be empty). This-
1701 only returns the text, with no rich text formatting information.-
1702 If you want a document fragment (i.e. formatted rich text) use-
1703 selection() instead.-
1704-
1705 \note If the selection obtained from an editor spans a line break,-
1706 the text will contain a Unicode U+2029 paragraph separator character-
1707 instead of a newline \c{\n} character. Use QString::replace() to-
1708 replace these characters with newlines.-
1709*/-
1710QString QTextCursor::selectedText() const-
1711{-
1712 if (!d || !d->priv || d->position == d->anchor)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
d->position == d->anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1713 return QString();
never executed: return QString();
0
1714-
1715 const QString docText = d->priv->buffer();-
1716 QString text;-
1717-
1718 QTextTable *table = d->complexSelectionTable();-
1719 if (table) {
tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1720 int row_start, col_start, num_rows, num_cols;-
1721 selectedTableCells(&row_start, &num_rows, &col_start, &num_cols);-
1722-
1723 Q_ASSERT(row_start != -1);-
1724 for (int r = row_start; r < row_start + num_rows; ++r) {
r < row_start + num_rowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1725 for (int c = col_start; c < col_start + num_cols; ++c) {
c < col_start + num_colsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1726 QTextTableCell cell = table->cellAt(r, c);-
1727 int rspan = cell.rowSpan();-
1728 int cspan = cell.columnSpan();-
1729 if (rspan != 1) {
rspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1730 int cr = cell.row();-
1731 if (cr != r)
cr != rDescription
TRUEnever evaluated
FALSEnever evaluated
0
1732 continue;
never executed: continue;
0
1733 }
never executed: end of block
0
1734 if (cspan != 1) {
cspan != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1735 int cc = cell.column();-
1736 if (cc != c)
cc != cDescription
TRUEnever evaluated
FALSEnever evaluated
0
1737 continue;
never executed: continue;
0
1738 }
never executed: end of block
0
1739-
1740 getText(text, d->priv, docText, cell.firstPosition(), cell.lastPosition());-
1741 }
never executed: end of block
0
1742 }
never executed: end of block
0
1743 } else {
never executed: end of block
0
1744 getText(text, d->priv, docText, selectionStart(), selectionEnd());-
1745 }
never executed: end of block
0
1746-
1747 return text;
never executed: return text;
0
1748}-
1749-
1750/*!-
1751 Returns the current selection (which may be empty) with all its-
1752 formatting information. If you just want the selected text (i.e.-
1753 plain text) use selectedText() instead.-
1754-
1755 \note Unlike QTextDocumentFragment::toPlainText(),-
1756 selectedText() may include special unicode characters such as-
1757 QChar::ParagraphSeparator.-
1758-
1759 \sa QTextDocumentFragment::toPlainText()-
1760*/-
1761QTextDocumentFragment QTextCursor::selection() const-
1762{-
1763 return QTextDocumentFragment(*this);
never executed: return QTextDocumentFragment(*this);
0
1764}-
1765-
1766/*!-
1767 Returns the block that contains the cursor.-
1768*/-
1769QTextBlock QTextCursor::block() const-
1770{-
1771 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1772 return QTextBlock();
never executed: return QTextBlock();
0
1773 return d->block();
never executed: return d->block();
0
1774}-
1775-
1776/*!-
1777 Returns the block format of the block the cursor is in.-
1778-
1779 \sa setBlockFormat(), charFormat()-
1780 */-
1781QTextBlockFormat QTextCursor::blockFormat() const-
1782{-
1783 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1784 return QTextBlockFormat();
never executed: return QTextBlockFormat();
0
1785-
1786 return d->block().blockFormat();
never executed: return d->block().blockFormat();
0
1787}-
1788-
1789/*!-
1790 Sets the block format of the current block (or all blocks that-
1791 are contained in the selection) to \a format.-
1792-
1793 \sa blockFormat(), mergeBlockFormat()-
1794*/-
1795void QTextCursor::setBlockFormat(const QTextBlockFormat &format)-
1796{-
1797 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1798 return;
never executed: return;
0
1799-
1800 d->setBlockFormat(format, QTextDocumentPrivate::SetFormat);-
1801}
never executed: end of block
0
1802-
1803/*!-
1804 Modifies the block format of the current block (or all blocks that-
1805 are contained in the selection) with the block format specified by-
1806 \a modifier.-
1807-
1808 \sa setBlockFormat(), blockFormat()-
1809*/-
1810void QTextCursor::mergeBlockFormat(const QTextBlockFormat &modifier)-
1811{-
1812 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1813 return;
never executed: return;
0
1814-
1815 d->setBlockFormat(modifier, QTextDocumentPrivate::MergeFormat);-
1816}
never executed: end of block
0
1817-
1818/*!-
1819 Returns the block character format of the block the cursor is in.-
1820-
1821 The block char format is the format used when inserting text at the-
1822 beginning of an empty block.-
1823-
1824 \sa setBlockCharFormat()-
1825 */-
1826QTextCharFormat QTextCursor::blockCharFormat() const-
1827{-
1828 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1829 return QTextCharFormat();
never executed: return QTextCharFormat();
0
1830-
1831 return d->block().charFormat();
never executed: return d->block().charFormat();
0
1832}-
1833-
1834/*!-
1835 Sets the block char format of the current block (or all blocks that-
1836 are contained in the selection) to \a format.-
1837-
1838 \sa blockCharFormat()-
1839*/-
1840void QTextCursor::setBlockCharFormat(const QTextCharFormat &format)-
1841{-
1842 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1843 return;
never executed: return;
0
1844-
1845 d->setBlockCharFormat(format, QTextDocumentPrivate::SetFormatAndPreserveObjectIndices);-
1846}
never executed: end of block
0
1847-
1848/*!-
1849 Modifies the block char format of the current block (or all blocks that-
1850 are contained in the selection) with the block format specified by-
1851 \a modifier.-
1852-
1853 \sa setBlockCharFormat()-
1854*/-
1855void QTextCursor::mergeBlockCharFormat(const QTextCharFormat &modifier)-
1856{-
1857 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1858 return;
never executed: return;
0
1859-
1860 d->setBlockCharFormat(modifier, QTextDocumentPrivate::MergeFormat);-
1861}
never executed: end of block
0
1862-
1863/*!-
1864 Returns the format of the character immediately before the cursor-
1865 position(). If the cursor is positioned at the beginning of a text-
1866 block that is not empty then the format of the character-
1867 immediately after the cursor is returned.-
1868-
1869 \sa insertText(), blockFormat()-
1870 */-
1871QTextCharFormat QTextCursor::charFormat() const-
1872{-
1873 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1874 return QTextCharFormat();
never executed: return QTextCharFormat();
0
1875-
1876 int idx = d->currentCharFormat;-
1877 if (idx == -1) {
idx == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1878 QTextBlock block = d->block();-
1879-
1880 int pos;-
1881 if (d->position == block.position()
d->position ==...ock.position()Description
TRUEnever evaluated
FALSEnever evaluated
0
1882 && block.length() > 1)
block.length() > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1883 pos = d->position;
never executed: pos = d->position;
0
1884 else-
1885 pos = d->position - 1;
never executed: pos = d->position - 1;
0
1886-
1887 if (pos == -1) {
pos == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1888 idx = d->priv->blockCharFormatIndex(d->priv->blockMap().firstNode());-
1889 } else {
never executed: end of block
0
1890 Q_ASSERT(pos >= 0 && pos < d->priv->length());-
1891-
1892 QTextDocumentPrivate::FragmentIterator it = d->priv->find(pos);-
1893 Q_ASSERT(!it.atEnd());-
1894 idx = it.value()->format;-
1895 }
never executed: end of block
0
1896 }-
1897-
1898 QTextCharFormat cfmt = d->priv->formatCollection()->charFormat(idx);-
1899 cfmt.clearProperty(QTextFormat::ObjectIndex);-
1900-
1901 Q_ASSERT(cfmt.isValid());-
1902 return cfmt;
never executed: return cfmt;
0
1903}-
1904-
1905/*!-
1906 Sets the cursor's current character format to the given \a-
1907 format. If the cursor has a selection, the given \a format is-
1908 applied to the current selection.-
1909-
1910 \sa hasSelection(), mergeCharFormat()-
1911*/-
1912void QTextCursor::setCharFormat(const QTextCharFormat &format)-
1913{-
1914 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1915 return;
never executed: return;
0
1916 if (d->position == d->anchor) {
d->position == d->anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1917 d->currentCharFormat = d->priv->formatCollection()->indexForFormat(format);-
1918 return;
never executed: return;
0
1919 }-
1920 d->setCharFormat(format, QTextDocumentPrivate::SetFormatAndPreserveObjectIndices);-
1921}
never executed: end of block
0
1922-
1923/*!-
1924 Merges the cursor's current character format with the properties-
1925 described by format \a modifier. If the cursor has a selection,-
1926 this function applies all the properties set in \a modifier to all-
1927 the character formats that are part of the selection.-
1928-
1929 \sa hasSelection(), setCharFormat()-
1930*/-
1931void QTextCursor::mergeCharFormat(const QTextCharFormat &modifier)-
1932{-
1933 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1934 return;
never executed: return;
0
1935 if (d->position == d->anchor) {
d->position == d->anchorDescription
TRUEnever evaluated
FALSEnever evaluated
0
1936 QTextCharFormat format = charFormat();-
1937 format.merge(modifier);-
1938 d->currentCharFormat = d->priv->formatCollection()->indexForFormat(format);-
1939 return;
never executed: return;
0
1940 }-
1941-
1942 d->setCharFormat(modifier, QTextDocumentPrivate::MergeFormat);-
1943}
never executed: end of block
0
1944-
1945/*!-
1946 Returns \c true if the cursor is at the start of a block; otherwise-
1947 returns \c false.-
1948-
1949 \sa atBlockEnd(), atStart()-
1950*/-
1951bool QTextCursor::atBlockStart() const-
1952{-
1953 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1954 return false;
never executed: return false;
0
1955-
1956 return d->position == d->block().position();
never executed: return d->position == d->block().position();
0
1957}-
1958-
1959/*!-
1960 Returns \c true if the cursor is at the end of a block; otherwise-
1961 returns \c false.-
1962-
1963 \sa atBlockStart(), atEnd()-
1964*/-
1965bool QTextCursor::atBlockEnd() const-
1966{-
1967 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1968 return false;
never executed: return false;
0
1969-
1970 return d->position == d->block().position() + d->block().length() - 1;
never executed: return d->position == d->block().position() + d->block().length() - 1;
0
1971}-
1972-
1973/*!-
1974 Returns \c true if the cursor is at the start of the document;-
1975 otherwise returns \c false.-
1976-
1977 \sa atBlockStart(), atEnd()-
1978*/-
1979bool QTextCursor::atStart() const-
1980{-
1981 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1982 return false;
never executed: return false;
0
1983-
1984 return d->position == 0;
never executed: return d->position == 0;
0
1985}-
1986-
1987/*!-
1988 \since 4.6-
1989-
1990 Returns \c true if the cursor is at the end of the document;-
1991 otherwise returns \c false.-
1992-
1993 \sa atStart(), atBlockEnd()-
1994*/-
1995bool QTextCursor::atEnd() const-
1996{-
1997 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
1998 return false;
never executed: return false;
0
1999-
2000 return d->position == d->priv->length() - 1;
never executed: return d->position == d->priv->length() - 1;
0
2001}-
2002-
2003/*!-
2004 Inserts a new empty block at the cursor position() with the-
2005 current blockFormat() and charFormat().-
2006-
2007 \sa setBlockFormat()-
2008*/-
2009void QTextCursor::insertBlock()-
2010{-
2011 insertBlock(blockFormat());-
2012}
never executed: end of block
0
2013-
2014/*!-
2015 \overload-
2016-
2017 Inserts a new empty block at the cursor position() with block-
2018 format \a format and the current charFormat() as block char format.-
2019-
2020 \sa setBlockFormat()-
2021*/-
2022void QTextCursor::insertBlock(const QTextBlockFormat &format)-
2023{-
2024 QTextCharFormat charFmt = charFormat();-
2025 charFmt.clearProperty(QTextFormat::ObjectType);-
2026 insertBlock(format, charFmt);-
2027}
never executed: end of block
0
2028-
2029/*!-
2030 \fn void QTextCursor::insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat)-
2031 \overload-
2032-
2033 Inserts a new empty block at the cursor position() with block-
2034 format \a format and \a charFormat as block char format.-
2035-
2036 \sa setBlockFormat()-
2037*/-
2038void QTextCursor::insertBlock(const QTextBlockFormat &format, const QTextCharFormat &_charFormat)-
2039{-
2040 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2041 return;
never executed: return;
0
2042-
2043 QTextCharFormat charFormat = _charFormat;-
2044 charFormat.clearProperty(QTextFormat::ObjectIndex);-
2045-
2046 d->priv->beginEditBlock();-
2047 d->remove();-
2048 d->insertBlock(format, charFormat);-
2049 d->priv->endEditBlock();-
2050 d->setX();-
2051}
never executed: end of block
0
2052-
2053/*!-
2054 Inserts a new block at the current position and makes it the first-
2055 list item of a newly created list with the given \a format. Returns-
2056 the created list.-
2057-
2058 \sa currentList(), createList(), insertBlock()-
2059 */-
2060QTextList *QTextCursor::insertList(const QTextListFormat &format)-
2061{-
2062 insertBlock();-
2063 return createList(format);
never executed: return createList(format);
0
2064}-
2065-
2066/*!-
2067 \overload-
2068-
2069 Inserts a new block at the current position and makes it the first-
2070 list item of a newly created list with the given \a style. Returns-
2071 the created list.-
2072-
2073 \sa currentList(), createList(), insertBlock()-
2074 */-
2075QTextList *QTextCursor::insertList(QTextListFormat::Style style)-
2076{-
2077 insertBlock();-
2078 return createList(style);
never executed: return createList(style);
0
2079}-
2080-
2081/*!-
2082 Creates and returns a new list with the given \a format, and makes the-
2083 current paragraph the cursor is in the first list item.-
2084-
2085 \sa insertList(), currentList()-
2086 */-
2087QTextList *QTextCursor::createList(const QTextListFormat &format)-
2088{-
2089 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2090 return 0;
never executed: return 0;
0
2091-
2092 QTextList *list = static_cast<QTextList *>(d->priv->createObject(format));-
2093 QTextBlockFormat modifier;-
2094 modifier.setObjectIndex(list->objectIndex());-
2095 mergeBlockFormat(modifier);-
2096 return list;
never executed: return list;
0
2097}-
2098-
2099/*!-
2100 \overload-
2101-
2102 Creates and returns a new list with the given \a style, making the-
2103 cursor's current paragraph the first list item.-
2104-
2105 The style to be used is defined by the QTextListFormat::Style enum.-
2106-
2107 \sa insertList(), currentList()-
2108 */-
2109QTextList *QTextCursor::createList(QTextListFormat::Style style)-
2110{-
2111 QTextListFormat fmt;-
2112 fmt.setStyle(style);-
2113 return createList(fmt);
never executed: return createList(fmt);
0
2114}-
2115-
2116/*!-
2117 Returns the current list if the cursor position() is inside a-
2118 block that is part of a list; otherwise returns 0.-
2119-
2120 \sa insertList(), createList()-
2121 */-
2122QTextList *QTextCursor::currentList() const-
2123{-
2124 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2125 return 0;
never executed: return 0;
0
2126-
2127 QTextBlockFormat b = blockFormat();-
2128 QTextObject *o = d->priv->objectForFormat(b);-
2129 return qobject_cast<QTextList *>(o);
never executed: return qobject_cast<QTextList *>(o);
0
2130}-
2131-
2132/*!-
2133 \fn QTextTable *QTextCursor::insertTable(int rows, int columns)-
2134-
2135 \overload-
2136-
2137 Creates a new table with the given number of \a rows and \a columns,-
2138 inserts it at the current cursor position() in the document, and returns-
2139 the table object. The cursor is moved to the beginning of the first cell.-
2140-
2141 There must be at least one row and one column in the table.-
2142-
2143 \sa currentTable()-
2144 */-
2145QTextTable *QTextCursor::insertTable(int rows, int cols)-
2146{-
2147 return insertTable(rows, cols, QTextTableFormat());
never executed: return insertTable(rows, cols, QTextTableFormat());
0
2148}-
2149-
2150/*!-
2151 \fn QTextTable *QTextCursor::insertTable(int rows, int columns, const QTextTableFormat &format)-
2152-
2153 Creates a new table with the given number of \a rows and \a columns-
2154 in the specified \a format, inserts it at the current cursor position()-
2155 in the document, and returns the table object. The cursor is moved to-
2156 the beginning of the first cell.-
2157-
2158 There must be at least one row and one column in the table.-
2159-
2160 \sa currentTable()-
2161*/-
2162QTextTable *QTextCursor::insertTable(int rows, int cols, const QTextTableFormat &format)-
2163{-
2164 if(!d || !d->priv || rows == 0 || cols == 0)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
rows == 0Description
TRUEnever evaluated
FALSEnever evaluated
cols == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2165 return 0;
never executed: return 0;
0
2166-
2167 int pos = d->position;-
2168 QTextTable *t = QTextTablePrivate::createTable(d->priv, d->position, rows, cols, format);-
2169 d->setPosition(pos+1);-
2170 // ##### what should we do if we have a selection?-
2171 d->anchor = d->position;-
2172 d->adjusted_anchor = d->anchor;-
2173 return t;
never executed: return t;
0
2174}-
2175-
2176/*!-
2177 Returns a pointer to the current table if the cursor position()-
2178 is inside a block that is part of a table; otherwise returns 0.-
2179-
2180 \sa insertTable()-
2181*/-
2182QTextTable *QTextCursor::currentTable() const-
2183{-
2184 if(!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2185 return 0;
never executed: return 0;
0
2186-
2187 QTextFrame *frame = d->priv->frameAt(d->position);-
2188 while (frame) {
frameDescription
TRUEnever evaluated
FALSEnever evaluated
0
2189 QTextTable *table = qobject_cast<QTextTable *>(frame);-
2190 if (table)
tableDescription
TRUEnever evaluated
FALSEnever evaluated
0
2191 return table;
never executed: return table;
0
2192 frame = frame->parentFrame();-
2193 }
never executed: end of block
0
2194 return 0;
never executed: return 0;
0
2195}-
2196-
2197/*!-
2198 Inserts a frame with the given \a format at the current cursor position(),-
2199 moves the cursor position() inside the frame, and returns the frame.-
2200-
2201 If the cursor holds a selection, the whole selection is moved inside the-
2202 frame.-
2203-
2204 \sa hasSelection()-
2205*/-
2206QTextFrame *QTextCursor::insertFrame(const QTextFrameFormat &format)-
2207{-
2208 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2209 return 0;
never executed: return 0;
0
2210-
2211 return d->priv->insertFrame(selectionStart(), selectionEnd(), format);
never executed: return d->priv->insertFrame(selectionStart(), selectionEnd(), format);
0
2212}-
2213-
2214/*!-
2215 Returns a pointer to the current frame. Returns 0 if the cursor is invalid.-
2216-
2217 \sa insertFrame()-
2218*/-
2219QTextFrame *QTextCursor::currentFrame() const-
2220{-
2221 if(!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2222 return 0;
never executed: return 0;
0
2223-
2224 return d->priv->frameAt(d->position);
never executed: return d->priv->frameAt(d->position);
0
2225}-
2226-
2227-
2228/*!-
2229 Inserts the text \a fragment at the current position().-
2230*/-
2231void QTextCursor::insertFragment(const QTextDocumentFragment &fragment)-
2232{-
2233 if (!d || !d->priv || fragment.isEmpty())
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
fragment.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2234 return;
never executed: return;
0
2235-
2236 d->priv->beginEditBlock();-
2237 d->remove();-
2238 fragment.d->insert(*this);-
2239 d->priv->endEditBlock();-
2240-
2241 if (fragment.d && fragment.d->doc)
fragment.dDescription
TRUEnever evaluated
FALSEnever evaluated
fragment.d->docDescription
TRUEnever evaluated
FALSEnever evaluated
0
2242 d->priv->mergeCachedResources(fragment.d->doc->docHandle());
never executed: d->priv->mergeCachedResources(fragment.d->doc->docHandle());
0
2243}
never executed: end of block
0
2244-
2245/*!-
2246 \since 4.2-
2247 Inserts the text \a html at the current position(). The text is interpreted as-
2248 HTML.-
2249-
2250 \note When using this function with a style sheet, the style sheet will-
2251 only apply to the current block in the document. In order to apply a style-
2252 sheet throughout a document, use QTextDocument::setDefaultStyleSheet()-
2253 instead.-
2254*/-
2255-
2256#ifndef QT_NO_TEXTHTMLPARSER-
2257-
2258void QTextCursor::insertHtml(const QString &html)-
2259{-
2260 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2261 return;
never executed: return;
0
2262 QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(html, d->priv->document());-
2263 insertFragment(fragment);-
2264}
never executed: end of block
0
2265-
2266#endif // QT_NO_TEXTHTMLPARSER-
2267-
2268/*!-
2269 \overload-
2270 \since 4.2-
2271-
2272 Inserts the image defined by the given \a format at the cursor's current position-
2273 with the specified \a alignment.-
2274-
2275 \sa position()-
2276*/-
2277void QTextCursor::insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment)-
2278{-
2279 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2280 return;
never executed: return;
0
2281-
2282 QTextFrameFormat ffmt;-
2283 ffmt.setPosition(alignment);-
2284 QTextObject *obj = d->priv->createObject(ffmt);-
2285-
2286 QTextImageFormat fmt = format;-
2287 fmt.setObjectIndex(obj->objectIndex());-
2288-
2289 d->priv->beginEditBlock();-
2290 d->remove();-
2291 const int idx = d->priv->formatCollection()->indexForFormat(fmt);-
2292 d->priv->insert(d->position, QString(QChar(QChar::ObjectReplacementCharacter)), idx);-
2293 d->priv->endEditBlock();-
2294}
never executed: end of block
0
2295-
2296/*!-
2297 Inserts the image defined by \a format at the current position().-
2298*/-
2299void QTextCursor::insertImage(const QTextImageFormat &format)-
2300{-
2301 insertText(QString(QChar::ObjectReplacementCharacter), format);-
2302}
never executed: end of block
0
2303-
2304/*!-
2305 \overload-
2306-
2307 Convenience method for inserting the image with the given \a name at the-
2308 current position().-
2309-
2310 \snippet code/src_gui_text_qtextcursor.cpp 1-
2311*/-
2312void QTextCursor::insertImage(const QString &name)-
2313{-
2314 QTextImageFormat format;-
2315 format.setName(name);-
2316 insertImage(format);-
2317}
never executed: end of block
0
2318-
2319/*!-
2320 \since 4.5-
2321 \overload-
2322-
2323 Convenience function for inserting the given \a image with an optional-
2324 \a name at the current position().-
2325*/-
2326void QTextCursor::insertImage(const QImage &image, const QString &name)-
2327{-
2328 if (image.isNull()) {
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2329 qWarning("QTextCursor::insertImage: attempt to add an invalid image");-
2330 return;
never executed: return;
0
2331 }-
2332 QString imageName = name;-
2333 if (name.isEmpty())
name.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2334 imageName = QString::number(image.cacheKey());
never executed: imageName = QString::number(image.cacheKey());
0
2335 d->priv->document()->addResource(QTextDocument::ImageResource, QUrl(imageName), image);-
2336 QTextImageFormat format;-
2337 format.setName(imageName);-
2338 insertImage(format);-
2339}
never executed: end of block
0
2340-
2341/*!-
2342 \fn bool QTextCursor::operator!=(const QTextCursor &other) const-
2343-
2344 Returns \c true if the \a other cursor is at a different position in-
2345 the document as this cursor; otherwise returns \c false.-
2346*/-
2347bool QTextCursor::operator!=(const QTextCursor &rhs) const-
2348{-
2349 return !operator==(rhs);
never executed: return !operator==(rhs);
0
2350}-
2351-
2352/*!-
2353 \fn bool QTextCursor::operator<(const QTextCursor &other) const-
2354-
2355 Returns \c true if the \a other cursor is positioned later in the-
2356 document than this cursor; otherwise returns \c false.-
2357*/-
2358bool QTextCursor::operator<(const QTextCursor &rhs) const-
2359{-
2360 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2361 return !!rhs.d;
never executed: return !!rhs.d;
0
2362-
2363 if (!rhs.d)
!rhs.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2364 return false;
never executed: return false;
0
2365-
2366 Q_ASSERT_X(d->priv == rhs.d->priv, "QTextCursor::operator<", "cannot compare cursors attached to different documents");-
2367-
2368 return d->position < rhs.d->position;
never executed: return d->position < rhs.d->position;
0
2369}-
2370-
2371/*!-
2372 \fn bool QTextCursor::operator<=(const QTextCursor &other) const-
2373-
2374 Returns \c true if the \a other cursor is positioned later or at the-
2375 same position in the document as this cursor; otherwise returns-
2376 false.-
2377*/-
2378bool QTextCursor::operator<=(const QTextCursor &rhs) const-
2379{-
2380 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2381 return true;
never executed: return true;
0
2382-
2383 if (!rhs.d)
!rhs.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2384 return false;
never executed: return false;
0
2385-
2386 Q_ASSERT_X(d->priv == rhs.d->priv, "QTextCursor::operator<=", "cannot compare cursors attached to different documents");-
2387-
2388 return d->position <= rhs.d->position;
never executed: return d->position <= rhs.d->position;
0
2389}-
2390-
2391/*!-
2392 \fn bool QTextCursor::operator==(const QTextCursor &other) const-
2393-
2394 Returns \c true if the \a other cursor is at the same position in the-
2395 document as this cursor; otherwise returns \c false.-
2396*/-
2397bool QTextCursor::operator==(const QTextCursor &rhs) const-
2398{-
2399 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2400 return !rhs.d;
never executed: return !rhs.d;
0
2401-
2402 if (!rhs.d)
!rhs.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2403 return false;
never executed: return false;
0
2404-
2405 return d->position == rhs.d->position && d->priv == rhs.d->priv;
never executed: return d->position == rhs.d->position && d->priv == rhs.d->priv;
0
2406}-
2407-
2408/*!-
2409 \fn bool QTextCursor::operator>=(const QTextCursor &other) const-
2410-
2411 Returns \c true if the \a other cursor is positioned earlier or at the-
2412 same position in the document as this cursor; otherwise returns-
2413 false.-
2414*/-
2415bool QTextCursor::operator>=(const QTextCursor &rhs) const-
2416{-
2417 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2418 return false;
never executed: return false;
0
2419-
2420 if (!rhs.d)
!rhs.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2421 return true;
never executed: return true;
0
2422-
2423 Q_ASSERT_X(d->priv == rhs.d->priv, "QTextCursor::operator>=", "cannot compare cursors attached to different documents");-
2424-
2425 return d->position >= rhs.d->position;
never executed: return d->position >= rhs.d->position;
0
2426}-
2427-
2428/*!-
2429 \fn bool QTextCursor::operator>(const QTextCursor &other) const-
2430-
2431 Returns \c true if the \a other cursor is positioned earlier in the-
2432 document than this cursor; otherwise returns \c false.-
2433*/-
2434bool QTextCursor::operator>(const QTextCursor &rhs) const-
2435{-
2436 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2437 return false;
never executed: return false;
0
2438-
2439 if (!rhs.d)
!rhs.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2440 return true;
never executed: return true;
0
2441-
2442 Q_ASSERT_X(d->priv == rhs.d->priv, "QTextCursor::operator>", "cannot compare cursors attached to different documents");-
2443-
2444 return d->position > rhs.d->position;
never executed: return d->position > rhs.d->position;
0
2445}-
2446-
2447/*!-
2448 Indicates the start of a block of editing operations on the-
2449 document that should appear as a single operation from an-
2450 undo/redo point of view.-
2451-
2452 For example:-
2453-
2454 \snippet code/src_gui_text_qtextcursor.cpp 2-
2455-
2456 The call to undo() will cause both insertions to be undone,-
2457 causing both "World" and "Hello" to be removed.-
2458-
2459 It is possible to nest calls to beginEditBlock and endEditBlock. The-
2460 top-most pair will determine the scope of the undo/redo operation.-
2461-
2462 \sa endEditBlock()-
2463 */-
2464void QTextCursor::beginEditBlock()-
2465{-
2466 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2467 return;
never executed: return;
0
2468-
2469 if (d->priv->editBlock == 0) // we are the initial edit block, store current cursor position for undo
d->priv->editBlock == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2470 d->priv->editBlockCursorPosition = d->position;
never executed: d->priv->editBlockCursorPosition = d->position;
0
2471-
2472 d->priv->beginEditBlock();-
2473}
never executed: end of block
0
2474-
2475/*!-
2476 Like beginEditBlock() indicates the start of a block of editing operations-
2477 that should appear as a single operation for undo/redo. However unlike-
2478 beginEditBlock() it does not start a new block but reverses the previous call to-
2479 endEditBlock() and therefore makes following operations part of the previous edit block created.-
2480-
2481 For example:-
2482-
2483 \snippet code/src_gui_text_qtextcursor.cpp 3-
2484-
2485 The call to undo() will cause all three insertions to be undone.-
2486-
2487 \sa beginEditBlock(), endEditBlock()-
2488 */-
2489void QTextCursor::joinPreviousEditBlock()-
2490{-
2491 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2492 return;
never executed: return;
0
2493-
2494 d->priv->joinPreviousEditBlock();-
2495}
never executed: end of block
0
2496-
2497/*!-
2498 Indicates the end of a block of editing operations on the document-
2499 that should appear as a single operation from an undo/redo point-
2500 of view.-
2501-
2502 \sa beginEditBlock()-
2503 */-
2504-
2505void QTextCursor::endEditBlock()-
2506{-
2507 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2508 return;
never executed: return;
0
2509-
2510 d->priv->endEditBlock();-
2511}
never executed: end of block
0
2512-
2513/*!-
2514 Returns \c true if this cursor and \a other are copies of each other, i.e.-
2515 one of them was created as a copy of the other and neither has moved since.-
2516 This is much stricter than equality.-
2517-
2518 \sa operator=(), operator==()-
2519*/-
2520bool QTextCursor::isCopyOf(const QTextCursor &other) const-
2521{-
2522 return d == other.d;
never executed: return d == other.d;
0
2523}-
2524-
2525/*!-
2526 \since 4.2-
2527 Returns the number of the block the cursor is in, or 0 if the cursor is invalid.-
2528-
2529 Note that this function only makes sense in documents without complex objects such-
2530 as tables or frames.-
2531*/-
2532int QTextCursor::blockNumber() const-
2533{-
2534 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2535 return 0;
never executed: return 0;
0
2536-
2537 return d->block().blockNumber();
never executed: return d->block().blockNumber();
0
2538}-
2539-
2540-
2541/*!-
2542 \since 4.2-
2543 Returns the position of the cursor within its containing line.-
2544-
2545 Note that this is the column number relative to a wrapped line,-
2546 not relative to the block (i.e. the paragraph).-
2547-
2548 You probably want to call positionInBlock() instead.-
2549-
2550 \sa positionInBlock()-
2551*/-
2552int QTextCursor::columnNumber() const-
2553{-
2554 if (!d || !d->priv)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2555 return 0;
never executed: return 0;
0
2556-
2557 QTextBlock block = d->block();-
2558 if (!block.isValid())
!block.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2559 return 0;
never executed: return 0;
0
2560-
2561 const QTextLayout *layout = d->blockLayout(block);-
2562-
2563 const int relativePos = d->position - block.position();-
2564-
2565 if (layout->lineCount() == 0)
layout->lineCount() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2566 return relativePos;
never executed: return relativePos;
0
2567-
2568 QTextLine line = layout->lineForTextPosition(relativePos);-
2569 if (!line.isValid())
!line.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2570 return 0;
never executed: return 0;
0
2571 return relativePos - line.textStart();
never executed: return relativePos - line.textStart();
0
2572}-
2573-
2574/*!-
2575 \since 4.5-
2576 Returns the document this cursor is associated with.-
2577*/-
2578QTextDocument *QTextCursor::document() const-
2579{-
2580 if (d->priv)
d->privDescription
TRUEnever evaluated
FALSEnever evaluated
0
2581 return d->priv->document();
never executed: return d->priv->document();
0
2582 return 0; // document went away
never executed: return 0;
0
2583}-
2584-
2585QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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