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