Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextdocument_p.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 <private/qtools_p.h> | - | ||||||||||||||||||||||||||||||
35 | #include <qdebug.h> | - | ||||||||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||||||||
37 | #include "qtextdocument_p.h" | - | ||||||||||||||||||||||||||||||
38 | #include "qtextdocument.h" | - | ||||||||||||||||||||||||||||||
39 | #include <qtextformat.h> | - | ||||||||||||||||||||||||||||||
40 | #include "qtextformat_p.h" | - | ||||||||||||||||||||||||||||||
41 | #include "qtextobject_p.h" | - | ||||||||||||||||||||||||||||||
42 | #include "qtextcursor.h" | - | ||||||||||||||||||||||||||||||
43 | #include "qtextimagehandler_p.h" | - | ||||||||||||||||||||||||||||||
44 | #include "qtextcursor_p.h" | - | ||||||||||||||||||||||||||||||
45 | #include "qtextdocumentlayout_p.h" | - | ||||||||||||||||||||||||||||||
46 | #include "qtexttable.h" | - | ||||||||||||||||||||||||||||||
47 | #include "qtextengine_p.h" | - | ||||||||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||||||||
49 | #include <stdlib.h> | - | ||||||||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||||||||
51 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||||||||
53 | #define PMDEBUG if(0) qDebug | - | ||||||||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||||||||
55 | // The VxWorks DIAB compiler crashes when initializing the anonymouse union with { a7 } | - | ||||||||||||||||||||||||||||||
56 | #if !defined(Q_CC_DIAB) | - | ||||||||||||||||||||||||||||||
57 | # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ | - | ||||||||||||||||||||||||||||||
58 | QTextUndoCommand c = { a1, a2, 0, 0, quint8(a3), a4, quint32(a5), quint32(a6), { int(a7) }, quint32(a8) } | - | ||||||||||||||||||||||||||||||
59 | #else | - | ||||||||||||||||||||||||||||||
60 | # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ | - | ||||||||||||||||||||||||||||||
61 | QTextUndoCommand c = { a1, a2, 0, 0, a3, a4, a5, a6 }; c.blockFormat = a7; c.revision = a8 | - | ||||||||||||||||||||||||||||||
62 | #endif | - | ||||||||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||||||||
64 | /* | - | ||||||||||||||||||||||||||||||
65 | Structure of a document: | - | ||||||||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||||||||
67 | DOCUMENT :== FRAME_CONTENTS | - | ||||||||||||||||||||||||||||||
68 | FRAME :== START_OF_FRAME FRAME_CONTENTS END_OF_FRAME | - | ||||||||||||||||||||||||||||||
69 | FRAME_CONTENTS = LIST_OF_BLOCKS ((FRAME | TABLE) LIST_OF_BLOCKS)* | - | ||||||||||||||||||||||||||||||
70 | TABLE :== (START_OF_FRAME TABLE_CELL)+ END_OF_FRAME | - | ||||||||||||||||||||||||||||||
71 | TABLE_CELL = FRAME_CONTENTS | - | ||||||||||||||||||||||||||||||
72 | LIST_OF_BLOCKS :== (BLOCK END_OF_PARA)* BLOCK | - | ||||||||||||||||||||||||||||||
73 | BLOCK :== (FRAGMENT)* | - | ||||||||||||||||||||||||||||||
74 | FRAGMENT :== String of characters | - | ||||||||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||||||||
76 | END_OF_PARA :== 0x2029 # Paragraph separator in Unicode | - | ||||||||||||||||||||||||||||||
77 | START_OF_FRAME :== 0xfdd0 | - | ||||||||||||||||||||||||||||||
78 | END_OF_FRAME := 0xfdd1 | - | ||||||||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||||||||
80 | Note also that LIST_OF_BLOCKS can be empty. Nevertheless, there is | - | ||||||||||||||||||||||||||||||
81 | at least one valid cursor position there where you could start | - | ||||||||||||||||||||||||||||||
82 | typing. The block format is in this case determined by the last | - | ||||||||||||||||||||||||||||||
83 | END_OF_PARA/START_OF_FRAME/END_OF_FRAME (see below). | - | ||||||||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||||||||
85 | Lists are not in here, as they are treated specially. A list is just | - | ||||||||||||||||||||||||||||||
86 | a collection of (not necessarily connected) blocks, that share the | - | ||||||||||||||||||||||||||||||
87 | same objectIndex() in the format that refers to the list format and | - | ||||||||||||||||||||||||||||||
88 | object. | - | ||||||||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||||||||
90 | The above does not clearly note where formats are. Here's | - | ||||||||||||||||||||||||||||||
91 | how it looks currently: | - | ||||||||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||||||||
93 | FRAGMENT: one charFormat associated | - | ||||||||||||||||||||||||||||||
94 | - | |||||||||||||||||||||||||||||||
95 | END_OF_PARA: one charFormat, and a blockFormat for the _next_ block. | - | ||||||||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||||||||
97 | START_OF_FRAME: one char format, and a blockFormat (for the next | - | ||||||||||||||||||||||||||||||
98 | block). The format associated with the objectIndex() of the | - | ||||||||||||||||||||||||||||||
99 | charFormat decides whether this is a frame or table and its | - | ||||||||||||||||||||||||||||||
100 | properties | - | ||||||||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||||||||
102 | END_OF_FRAME: one charFormat and a blockFormat (for the next | - | ||||||||||||||||||||||||||||||
103 | block). The object() of the charFormat is the same as for the | - | ||||||||||||||||||||||||||||||
104 | corresponding START_OF_BLOCK. | - | ||||||||||||||||||||||||||||||
105 | - | |||||||||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||||||||
107 | The document is independent of the layout with certain restrictions: | - | ||||||||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||||||||
109 | * Cursor movement (esp. up and down) depend on the layout. | - | ||||||||||||||||||||||||||||||
110 | * You cannot have more than one layout, as the layout data of QTextObjects | - | ||||||||||||||||||||||||||||||
111 | is stored in the text object itself. | - | ||||||||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||||||||
113 | */ | - | ||||||||||||||||||||||||||||||
114 | - | |||||||||||||||||||||||||||||||
115 | void QTextBlockData::invalidate() const | - | ||||||||||||||||||||||||||||||
116 | { | - | ||||||||||||||||||||||||||||||
117 | if (layout)
| 0 | ||||||||||||||||||||||||||||||
118 | layout->engine()->invalidate(); never executed: layout->engine()->invalidate(); | 0 | ||||||||||||||||||||||||||||||
119 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
120 | - | |||||||||||||||||||||||||||||||
121 | static bool isValidBlockSeparator(QChar ch) | - | ||||||||||||||||||||||||||||||
122 | { | - | ||||||||||||||||||||||||||||||
123 | return ch == QChar::ParagraphSeparator never executed: return ch == QChar::ParagraphSeparator || ch == QChar(0xfdd0) || ch == QChar(0xfdd1);
| 0 | ||||||||||||||||||||||||||||||
124 | || ch == QTextBeginningOfFrame never executed: return ch == QChar::ParagraphSeparator || ch == QChar(0xfdd0) || ch == QChar(0xfdd1);
| 0 | ||||||||||||||||||||||||||||||
125 | || ch == QTextEndOfFrame; never executed: return ch == QChar::ParagraphSeparator || ch == QChar(0xfdd0) || ch == QChar(0xfdd1);
| 0 | ||||||||||||||||||||||||||||||
126 | } | - | ||||||||||||||||||||||||||||||
127 | - | |||||||||||||||||||||||||||||||
128 | static bool noBlockInString(const QString &str) | - | ||||||||||||||||||||||||||||||
129 | { | - | ||||||||||||||||||||||||||||||
130 | return !str.contains(QChar::ParagraphSeparator) never executed: return !str.contains(QChar::ParagraphSeparator) && !str.contains(QChar(0xfdd0)) && !str.contains(QChar(0xfdd1));
| 0 | ||||||||||||||||||||||||||||||
131 | && !str.contains(QTextBeginningOfFrame) never executed: return !str.contains(QChar::ParagraphSeparator) && !str.contains(QChar(0xfdd0)) && !str.contains(QChar(0xfdd1));
| 0 | ||||||||||||||||||||||||||||||
132 | && !str.contains(QTextEndOfFrame); never executed: return !str.contains(QChar::ParagraphSeparator) && !str.contains(QChar(0xfdd0)) && !str.contains(QChar(0xfdd1));
| 0 | ||||||||||||||||||||||||||||||
133 | } | - | ||||||||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||||||||
135 | bool QTextUndoCommand::tryMerge(const QTextUndoCommand &other) | - | ||||||||||||||||||||||||||||||
136 | { | - | ||||||||||||||||||||||||||||||
137 | if (command != other.command)
| 0 | ||||||||||||||||||||||||||||||
138 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||||||||
140 | if (command == Inserted
| 0 | ||||||||||||||||||||||||||||||
141 | && (pos + length == other.pos)
| 0 | ||||||||||||||||||||||||||||||
142 | && (strPos + length == other.strPos)
| 0 | ||||||||||||||||||||||||||||||
143 | && format == other.format) {
| 0 | ||||||||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||||||||
145 | length += other.length; | - | ||||||||||||||||||||||||||||||
146 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
147 | } | - | ||||||||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||||||||
149 | // removal to the 'right' using 'Delete' key | - | ||||||||||||||||||||||||||||||
150 | if (command == Removed
| 0 | ||||||||||||||||||||||||||||||
151 | && pos == other.pos
| 0 | ||||||||||||||||||||||||||||||
152 | && (strPos + length == other.strPos)
| 0 | ||||||||||||||||||||||||||||||
153 | && format == other.format) {
| 0 | ||||||||||||||||||||||||||||||
154 | - | |||||||||||||||||||||||||||||||
155 | length += other.length; | - | ||||||||||||||||||||||||||||||
156 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
157 | } | - | ||||||||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||||||||
159 | // removal to the 'left' using 'Backspace' | - | ||||||||||||||||||||||||||||||
160 | if (command == Removed
| 0 | ||||||||||||||||||||||||||||||
161 | && (other.pos + other.length == pos)
| 0 | ||||||||||||||||||||||||||||||
162 | && (other.strPos + other.length == strPos)
| 0 | ||||||||||||||||||||||||||||||
163 | && (format == other.format)) {
| 0 | ||||||||||||||||||||||||||||||
164 | - | |||||||||||||||||||||||||||||||
165 | int l = length; | - | ||||||||||||||||||||||||||||||
166 | (*this) = other; | - | ||||||||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||||||||
168 | length += l; | - | ||||||||||||||||||||||||||||||
169 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
170 | } | - | ||||||||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||||||||
172 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
173 | } | - | ||||||||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||||||||
175 | QTextDocumentPrivate::QTextDocumentPrivate() | - | ||||||||||||||||||||||||||||||
176 | : wasUndoAvailable(false), | - | ||||||||||||||||||||||||||||||
177 | wasRedoAvailable(false), | - | ||||||||||||||||||||||||||||||
178 | docChangeOldLength(0), | - | ||||||||||||||||||||||||||||||
179 | docChangeLength(0), | - | ||||||||||||||||||||||||||||||
180 | framesDirty(true), | - | ||||||||||||||||||||||||||||||
181 | rtFrame(0), | - | ||||||||||||||||||||||||||||||
182 | initialBlockCharFormatIndex(-1) // set correctly later in init() | - | ||||||||||||||||||||||||||||||
183 | { | - | ||||||||||||||||||||||||||||||
184 | editBlock = 0; | - | ||||||||||||||||||||||||||||||
185 | editBlockCursorPosition = -1; | - | ||||||||||||||||||||||||||||||
186 | docChangeFrom = -1; | - | ||||||||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||||||||
188 | undoState = 0; | - | ||||||||||||||||||||||||||||||
189 | revision = -1; // init() inserts a block, bringing it to 0 | - | ||||||||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||||||||
191 | lout = 0; | - | ||||||||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||||||||
193 | modified = false; | - | ||||||||||||||||||||||||||||||
194 | modifiedState = 0; | - | ||||||||||||||||||||||||||||||
195 | - | |||||||||||||||||||||||||||||||
196 | undoEnabled = true; | - | ||||||||||||||||||||||||||||||
197 | inContentsChange = false; | - | ||||||||||||||||||||||||||||||
198 | blockCursorAdjustment = false; | - | ||||||||||||||||||||||||||||||
199 | - | |||||||||||||||||||||||||||||||
200 | defaultTextOption.setTabStop(80); // same as in qtextengine.cpp | - | ||||||||||||||||||||||||||||||
201 | defaultTextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); | - | ||||||||||||||||||||||||||||||
202 | defaultCursorMoveStyle = Qt::LogicalMoveStyle; | - | ||||||||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||||||||
204 | indentWidth = 40; | - | ||||||||||||||||||||||||||||||
205 | documentMargin = 4; | - | ||||||||||||||||||||||||||||||
206 | - | |||||||||||||||||||||||||||||||
207 | maximumBlockCount = 0; | - | ||||||||||||||||||||||||||||||
208 | needsEnsureMaximumBlockCount = false; | - | ||||||||||||||||||||||||||||||
209 | unreachableCharacterCount = 0; | - | ||||||||||||||||||||||||||||||
210 | lastBlockCount = 0; | - | ||||||||||||||||||||||||||||||
211 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
212 | - | |||||||||||||||||||||||||||||||
213 | void QTextDocumentPrivate::init() | - | ||||||||||||||||||||||||||||||
214 | { | - | ||||||||||||||||||||||||||||||
215 | framesDirty = false; | - | ||||||||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||||||||
217 | bool undoState = undoEnabled; | - | ||||||||||||||||||||||||||||||
218 | undoEnabled = false; | - | ||||||||||||||||||||||||||||||
219 | initialBlockCharFormatIndex = formats.indexForFormat(QTextCharFormat()); | - | ||||||||||||||||||||||||||||||
220 | insertBlock(0, formats.indexForFormat(QTextBlockFormat()), formats.indexForFormat(QTextCharFormat())); | - | ||||||||||||||||||||||||||||||
221 | undoEnabled = undoState; | - | ||||||||||||||||||||||||||||||
222 | modified = false; | - | ||||||||||||||||||||||||||||||
223 | modifiedState = 0; | - | ||||||||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||||||||
225 | qRegisterMetaType<QTextDocument *>(); | - | ||||||||||||||||||||||||||||||
226 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
227 | - | |||||||||||||||||||||||||||||||
228 | void QTextDocumentPrivate::clear() | - | ||||||||||||||||||||||||||||||
229 | { | - | ||||||||||||||||||||||||||||||
230 | Q_Q(QTextDocument); | - | ||||||||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||||||||
232 | foreach (QTextCursorPrivate *curs, cursors) { | - | ||||||||||||||||||||||||||||||
233 | curs->setPosition(0); | - | ||||||||||||||||||||||||||||||
234 | curs->currentCharFormat = -1; | - | ||||||||||||||||||||||||||||||
235 | curs->anchor = 0; | - | ||||||||||||||||||||||||||||||
236 | curs->adjusted_anchor = 0; | - | ||||||||||||||||||||||||||||||
237 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||||||||
239 | QList<QTextCursorPrivate *>oldCursors = cursors; | - | ||||||||||||||||||||||||||||||
240 | QT_TRY{ | - | ||||||||||||||||||||||||||||||
241 | cursors.clear(); | - | ||||||||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||||||||
243 | QMap<int, QTextObject *>::Iterator objectIt = objects.begin(); | - | ||||||||||||||||||||||||||||||
244 | while (objectIt != objects.end()) {
| 0 | ||||||||||||||||||||||||||||||
245 | if (*objectIt != rtFrame) {
| 0 | ||||||||||||||||||||||||||||||
246 | delete *objectIt; | - | ||||||||||||||||||||||||||||||
247 | objectIt = objects.erase(objectIt); | - | ||||||||||||||||||||||||||||||
248 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
249 | ++objectIt; | - | ||||||||||||||||||||||||||||||
250 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||||||||
252 | // also clear out the remaining root frame pointer | - | ||||||||||||||||||||||||||||||
253 | // (we're going to delete the object further down) | - | ||||||||||||||||||||||||||||||
254 | objects.clear(); | - | ||||||||||||||||||||||||||||||
255 | - | |||||||||||||||||||||||||||||||
256 | title.clear(); | - | ||||||||||||||||||||||||||||||
257 | clearUndoRedoStacks(QTextDocument::UndoAndRedoStacks); | - | ||||||||||||||||||||||||||||||
258 | text = QString(); | - | ||||||||||||||||||||||||||||||
259 | unreachableCharacterCount = 0; | - | ||||||||||||||||||||||||||||||
260 | modifiedState = 0; | - | ||||||||||||||||||||||||||||||
261 | modified = false; | - | ||||||||||||||||||||||||||||||
262 | formats = QTextFormatCollection(); | - | ||||||||||||||||||||||||||||||
263 | int len = fragments.length(); | - | ||||||||||||||||||||||||||||||
264 | fragments.clear(); | - | ||||||||||||||||||||||||||||||
265 | blocks.clear(); | - | ||||||||||||||||||||||||||||||
266 | cachedResources.clear(); | - | ||||||||||||||||||||||||||||||
267 | delete rtFrame; | - | ||||||||||||||||||||||||||||||
268 | rtFrame = 0; | - | ||||||||||||||||||||||||||||||
269 | init(); | - | ||||||||||||||||||||||||||||||
270 | cursors = oldCursors; | - | ||||||||||||||||||||||||||||||
271 | inContentsChange = true; | - | ||||||||||||||||||||||||||||||
272 | q->contentsChange(0, len, 0); | - | ||||||||||||||||||||||||||||||
273 | inContentsChange = false; | - | ||||||||||||||||||||||||||||||
274 | if (lout)
| 0 | ||||||||||||||||||||||||||||||
275 | lout->documentChanged(0, len, 0); never executed: lout->documentChanged(0, len, 0); | 0 | ||||||||||||||||||||||||||||||
276 | } QT_CATCH(...) { never executed: end of block dead code: { cursors = oldCursors; qt_noop(); } | - | ||||||||||||||||||||||||||||||
277 | cursors = oldCursors; // at least recover the cursors dead code: { cursors = oldCursors; qt_noop(); } | - | ||||||||||||||||||||||||||||||
278 | QT_RETHROW; dead code: { cursors = oldCursors; qt_noop(); } | - | ||||||||||||||||||||||||||||||
279 | } dead code: { cursors = oldCursors; qt_noop(); } | - | ||||||||||||||||||||||||||||||
280 | } | - | ||||||||||||||||||||||||||||||
281 | - | |||||||||||||||||||||||||||||||
282 | QTextDocumentPrivate::~QTextDocumentPrivate() | - | ||||||||||||||||||||||||||||||
283 | { | - | ||||||||||||||||||||||||||||||
284 | foreach (QTextCursorPrivate *curs, cursors) | - | ||||||||||||||||||||||||||||||
285 | curs->priv = 0; never executed: curs->priv = 0; | 0 | ||||||||||||||||||||||||||||||
286 | cursors.clear(); | - | ||||||||||||||||||||||||||||||
287 | undoState = 0; | - | ||||||||||||||||||||||||||||||
288 | undoEnabled = true; | - | ||||||||||||||||||||||||||||||
289 | clearUndoRedoStacks(QTextDocument::RedoStack); | - | ||||||||||||||||||||||||||||||
290 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
291 | - | |||||||||||||||||||||||||||||||
292 | void QTextDocumentPrivate::setLayout(QAbstractTextDocumentLayout *layout) | - | ||||||||||||||||||||||||||||||
293 | { | - | ||||||||||||||||||||||||||||||
294 | Q_Q(QTextDocument); | - | ||||||||||||||||||||||||||||||
295 | if (lout == layout)
| 0 | ||||||||||||||||||||||||||||||
296 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
297 | const bool firstLayout = !lout; | - | ||||||||||||||||||||||||||||||
298 | delete lout; | - | ||||||||||||||||||||||||||||||
299 | lout = layout; | - | ||||||||||||||||||||||||||||||
300 | - | |||||||||||||||||||||||||||||||
301 | if (!firstLayout)
| 0 | ||||||||||||||||||||||||||||||
302 | for (BlockMap::Iterator it = blocks.begin(); !it.atEnd(); ++it)
| 0 | ||||||||||||||||||||||||||||||
303 | it->free(); never executed: it->free(); | 0 | ||||||||||||||||||||||||||||||
304 | - | |||||||||||||||||||||||||||||||
305 | emit q->documentLayoutChanged(); | - | ||||||||||||||||||||||||||||||
306 | inContentsChange = true; | - | ||||||||||||||||||||||||||||||
307 | emit q->contentsChange(0, 0, length()); | - | ||||||||||||||||||||||||||||||
308 | inContentsChange = false; | - | ||||||||||||||||||||||||||||||
309 | if (lout)
| 0 | ||||||||||||||||||||||||||||||
310 | lout->documentChanged(0, 0, length()); never executed: lout->documentChanged(0, 0, length()); | 0 | ||||||||||||||||||||||||||||||
311 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||||||||
314 | void QTextDocumentPrivate::insert_string(int pos, uint strPos, uint length, int format, QTextUndoCommand::Operation op) | - | ||||||||||||||||||||||||||||||
315 | { | - | ||||||||||||||||||||||||||||||
316 | // ##### optimize when only appending to the fragment! | - | ||||||||||||||||||||||||||||||
317 | Q_ASSERT(noBlockInString(text.mid(strPos, length))); | - | ||||||||||||||||||||||||||||||
318 | - | |||||||||||||||||||||||||||||||
319 | split(pos); | - | ||||||||||||||||||||||||||||||
320 | uint x = fragments.insert_single(pos, length); | - | ||||||||||||||||||||||||||||||
321 | QTextFragmentData *X = fragments.fragment(x); | - | ||||||||||||||||||||||||||||||
322 | X->format = format; | - | ||||||||||||||||||||||||||||||
323 | X->stringPosition = strPos; | - | ||||||||||||||||||||||||||||||
324 | uint w = fragments.previous(x); | - | ||||||||||||||||||||||||||||||
325 | if (w)
| 0 | ||||||||||||||||||||||||||||||
326 | unite(w); never executed: unite(w); | 0 | ||||||||||||||||||||||||||||||
327 | - | |||||||||||||||||||||||||||||||
328 | int b = blocks.findNode(pos); | - | ||||||||||||||||||||||||||||||
329 | blocks.setSize(b, blocks.size(b)+length); | - | ||||||||||||||||||||||||||||||
330 | - | |||||||||||||||||||||||||||||||
331 | Q_ASSERT(blocks.length() == fragments.length()); | - | ||||||||||||||||||||||||||||||
332 | - | |||||||||||||||||||||||||||||||
333 | QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(format)); | - | ||||||||||||||||||||||||||||||
334 | if (frame) {
| 0 | ||||||||||||||||||||||||||||||
335 | frame->d_func()->fragmentAdded(text.at(strPos), x); | - | ||||||||||||||||||||||||||||||
336 | framesDirty = true; | - | ||||||||||||||||||||||||||||||
337 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
338 | - | |||||||||||||||||||||||||||||||
339 | adjustDocumentChangesAndCursors(pos, length, op); | - | ||||||||||||||||||||||||||||||
340 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
341 | - | |||||||||||||||||||||||||||||||
342 | int QTextDocumentPrivate::insert_block(int pos, uint strPos, int format, int blockFormat, QTextUndoCommand::Operation op, int command) | - | ||||||||||||||||||||||||||||||
343 | { | - | ||||||||||||||||||||||||||||||
344 | split(pos); | - | ||||||||||||||||||||||||||||||
345 | uint x = fragments.insert_single(pos, 1); | - | ||||||||||||||||||||||||||||||
346 | QTextFragmentData *X = fragments.fragment(x); | - | ||||||||||||||||||||||||||||||
347 | X->format = format; | - | ||||||||||||||||||||||||||||||
348 | X->stringPosition = strPos; | - | ||||||||||||||||||||||||||||||
349 | // no need trying to unite, since paragraph separators are always in a fragment of their own | - | ||||||||||||||||||||||||||||||
350 | - | |||||||||||||||||||||||||||||||
351 | Q_ASSERT(isValidBlockSeparator(text.at(strPos))); | - | ||||||||||||||||||||||||||||||
352 | Q_ASSERT(blocks.length()+1 == fragments.length()); | - | ||||||||||||||||||||||||||||||
353 | - | |||||||||||||||||||||||||||||||
354 | int block_pos = pos; | - | ||||||||||||||||||||||||||||||
355 | if (blocks.length() && command == QTextUndoCommand::BlockRemoved)
| 0 | ||||||||||||||||||||||||||||||
356 | ++block_pos; never executed: ++block_pos; | 0 | ||||||||||||||||||||||||||||||
357 | int size = 1; | - | ||||||||||||||||||||||||||||||
358 | int n = blocks.findNode(block_pos); | - | ||||||||||||||||||||||||||||||
359 | int key = n ? blocks.position(n) : blocks.length();
| 0 | ||||||||||||||||||||||||||||||
360 | - | |||||||||||||||||||||||||||||||
361 | Q_ASSERT(n || (!n && block_pos == blocks.length())); | - | ||||||||||||||||||||||||||||||
362 | if (key != block_pos) {
| 0 | ||||||||||||||||||||||||||||||
363 | Q_ASSERT(key < block_pos); | - | ||||||||||||||||||||||||||||||
364 | int oldSize = blocks.size(n); | - | ||||||||||||||||||||||||||||||
365 | blocks.setSize(n, block_pos-key); | - | ||||||||||||||||||||||||||||||
366 | size += oldSize - (block_pos-key); | - | ||||||||||||||||||||||||||||||
367 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
368 | int b = blocks.insert_single(block_pos, size); | - | ||||||||||||||||||||||||||||||
369 | QTextBlockData *B = blocks.fragment(b); | - | ||||||||||||||||||||||||||||||
370 | B->format = blockFormat; | - | ||||||||||||||||||||||||||||||
371 | - | |||||||||||||||||||||||||||||||
372 | Q_ASSERT(blocks.length() == fragments.length()); | - | ||||||||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||||||||
374 | QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(blockFormat)); | - | ||||||||||||||||||||||||||||||
375 | if (group)
| 0 | ||||||||||||||||||||||||||||||
376 | group->blockInserted(QTextBlock(this, b)); never executed: group->blockInserted(QTextBlock(this, b)); | 0 | ||||||||||||||||||||||||||||||
377 | - | |||||||||||||||||||||||||||||||
378 | QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(formats.format(format))); | - | ||||||||||||||||||||||||||||||
379 | if (frame) {
| 0 | ||||||||||||||||||||||||||||||
380 | frame->d_func()->fragmentAdded(text.at(strPos), x); | - | ||||||||||||||||||||||||||||||
381 | framesDirty = true; | - | ||||||||||||||||||||||||||||||
382 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
383 | - | |||||||||||||||||||||||||||||||
384 | adjustDocumentChangesAndCursors(pos, 1, op); | - | ||||||||||||||||||||||||||||||
385 | return x; never executed: return x; | 0 | ||||||||||||||||||||||||||||||
386 | } | - | ||||||||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||||||||
388 | int QTextDocumentPrivate::insertBlock(QChar blockSeparator, | - | ||||||||||||||||||||||||||||||
389 | int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation op) | - | ||||||||||||||||||||||||||||||
390 | { | - | ||||||||||||||||||||||||||||||
391 | Q_ASSERT(formats.format(blockFormat).isBlockFormat()); | - | ||||||||||||||||||||||||||||||
392 | Q_ASSERT(formats.format(charFormat).isCharFormat()); | - | ||||||||||||||||||||||||||||||
393 | Q_ASSERT(pos >= 0 && (pos < fragments.length() || (pos == 0 && fragments.length() == 0))); | - | ||||||||||||||||||||||||||||||
394 | Q_ASSERT(isValidBlockSeparator(blockSeparator)); | - | ||||||||||||||||||||||||||||||
395 | - | |||||||||||||||||||||||||||||||
396 | beginEditBlock(); | - | ||||||||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||||||||
398 | int strPos = text.length(); | - | ||||||||||||||||||||||||||||||
399 | text.append(blockSeparator); | - | ||||||||||||||||||||||||||||||
400 | - | |||||||||||||||||||||||||||||||
401 | int ob = blocks.findNode(pos); | - | ||||||||||||||||||||||||||||||
402 | bool atBlockEnd = true; | - | ||||||||||||||||||||||||||||||
403 | bool atBlockStart = true; | - | ||||||||||||||||||||||||||||||
404 | int oldRevision = 0; | - | ||||||||||||||||||||||||||||||
405 | if (ob) {
| 0 | ||||||||||||||||||||||||||||||
406 | atBlockEnd = (pos - blocks.position(ob) == blocks.size(ob)-1); | - | ||||||||||||||||||||||||||||||
407 | atBlockStart = ((int)blocks.position(ob) == pos); | - | ||||||||||||||||||||||||||||||
408 | oldRevision = blocks.fragment(ob)->revision; | - | ||||||||||||||||||||||||||||||
409 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
410 | - | |||||||||||||||||||||||||||||||
411 | const int fragment = insert_block(pos, strPos, charFormat, blockFormat, op, QTextUndoCommand::BlockRemoved); | - | ||||||||||||||||||||||||||||||
412 | - | |||||||||||||||||||||||||||||||
413 | Q_ASSERT(blocks.length() == fragments.length()); | - | ||||||||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||||||||
415 | int b = blocks.findNode(pos); | - | ||||||||||||||||||||||||||||||
416 | QTextBlockData *B = blocks.fragment(b); | - | ||||||||||||||||||||||||||||||
417 | - | |||||||||||||||||||||||||||||||
418 | QT_INIT_TEXTUNDOCOMMAND(c, QTextUndoCommand::BlockInserted, (editBlock != 0), | - | ||||||||||||||||||||||||||||||
419 | op, charFormat, strPos, pos, blockFormat, | - | ||||||||||||||||||||||||||||||
420 | B->revision); | - | ||||||||||||||||||||||||||||||
421 | - | |||||||||||||||||||||||||||||||
422 | appendUndoItem(c); | - | ||||||||||||||||||||||||||||||
423 | Q_ASSERT(undoState == undoStack.size()); | - | ||||||||||||||||||||||||||||||
424 | - | |||||||||||||||||||||||||||||||
425 | // update revision numbers of the modified blocks. | - | ||||||||||||||||||||||||||||||
426 | B->revision = (atBlockEnd && !atBlockStart)? oldRevision : revision;
| 0 | ||||||||||||||||||||||||||||||
427 | b = blocks.next(b); | - | ||||||||||||||||||||||||||||||
428 | if (b) {
| 0 | ||||||||||||||||||||||||||||||
429 | B = blocks.fragment(b); | - | ||||||||||||||||||||||||||||||
430 | B->revision = atBlockStart ? oldRevision : revision;
| 0 | ||||||||||||||||||||||||||||||
431 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
432 | - | |||||||||||||||||||||||||||||||
433 | if (formats.charFormat(charFormat).objectIndex() == -1)
| 0 | ||||||||||||||||||||||||||||||
434 | needsEnsureMaximumBlockCount = true; never executed: needsEnsureMaximumBlockCount = true; | 0 | ||||||||||||||||||||||||||||||
435 | - | |||||||||||||||||||||||||||||||
436 | endEditBlock(); | - | ||||||||||||||||||||||||||||||
437 | return fragment; never executed: return fragment; | 0 | ||||||||||||||||||||||||||||||
438 | } | - | ||||||||||||||||||||||||||||||
439 | - | |||||||||||||||||||||||||||||||
440 | int QTextDocumentPrivate::insertBlock(int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation op) | - | ||||||||||||||||||||||||||||||
441 | { | - | ||||||||||||||||||||||||||||||
442 | return insertBlock(QChar::ParagraphSeparator, pos, blockFormat, charFormat, op); never executed: return insertBlock(QChar::ParagraphSeparator, pos, blockFormat, charFormat, op); | 0 | ||||||||||||||||||||||||||||||
443 | } | - | ||||||||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||||||||
445 | void QTextDocumentPrivate::insert(int pos, int strPos, int strLength, int format) | - | ||||||||||||||||||||||||||||||
446 | { | - | ||||||||||||||||||||||||||||||
447 | if (strLength <= 0)
| 0 | ||||||||||||||||||||||||||||||
448 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
449 | - | |||||||||||||||||||||||||||||||
450 | Q_ASSERT(pos >= 0 && pos < fragments.length()); | - | ||||||||||||||||||||||||||||||
451 | Q_ASSERT(formats.format(format).isCharFormat()); | - | ||||||||||||||||||||||||||||||
452 | - | |||||||||||||||||||||||||||||||
453 | insert_string(pos, strPos, strLength, format, QTextUndoCommand::MoveCursor); | - | ||||||||||||||||||||||||||||||
454 | if (undoEnabled) {
| 0 | ||||||||||||||||||||||||||||||
455 | int b = blocks.findNode(pos); | - | ||||||||||||||||||||||||||||||
456 | QTextBlockData *B = blocks.fragment(b); | - | ||||||||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||||||||
458 | QT_INIT_TEXTUNDOCOMMAND(c, QTextUndoCommand::Inserted, (editBlock != 0), | - | ||||||||||||||||||||||||||||||
459 | QTextUndoCommand::MoveCursor, format, strPos, pos, strLength, | - | ||||||||||||||||||||||||||||||
460 | B->revision); | - | ||||||||||||||||||||||||||||||
461 | appendUndoItem(c); | - | ||||||||||||||||||||||||||||||
462 | B->revision = revision; | - | ||||||||||||||||||||||||||||||
463 | Q_ASSERT(undoState == undoStack.size()); | - | ||||||||||||||||||||||||||||||
464 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
465 | finishEdit(); | - | ||||||||||||||||||||||||||||||
466 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||||||||
468 | void QTextDocumentPrivate::insert(int pos, const QString &str, int format) | - | ||||||||||||||||||||||||||||||
469 | { | - | ||||||||||||||||||||||||||||||
470 | if (str.size() == 0)
| 0 | ||||||||||||||||||||||||||||||
471 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
472 | - | |||||||||||||||||||||||||||||||
473 | Q_ASSERT(noBlockInString(str)); | - | ||||||||||||||||||||||||||||||
474 | - | |||||||||||||||||||||||||||||||
475 | int strPos = text.length(); | - | ||||||||||||||||||||||||||||||
476 | text.append(str); | - | ||||||||||||||||||||||||||||||
477 | insert(pos, strPos, str.length(), format); | - | ||||||||||||||||||||||||||||||
478 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
479 | - | |||||||||||||||||||||||||||||||
480 | int QTextDocumentPrivate::remove_string(int pos, uint length, QTextUndoCommand::Operation op) | - | ||||||||||||||||||||||||||||||
481 | { | - | ||||||||||||||||||||||||||||||
482 | Q_ASSERT(pos >= 0); | - | ||||||||||||||||||||||||||||||
483 | Q_ASSERT(blocks.length() == fragments.length()); | - | ||||||||||||||||||||||||||||||
484 | Q_ASSERT(blocks.length() >= pos+(int)length); | - | ||||||||||||||||||||||||||||||
485 | - | |||||||||||||||||||||||||||||||
486 | int b = blocks.findNode(pos); | - | ||||||||||||||||||||||||||||||
487 | uint x = fragments.findNode(pos); | - | ||||||||||||||||||||||||||||||
488 | - | |||||||||||||||||||||||||||||||
489 | Q_ASSERT(blocks.size(b) > length); | - | ||||||||||||||||||||||||||||||
490 | Q_ASSERT(x && fragments.position(x) == (uint)pos && fragments.size(x) == length); | - | ||||||||||||||||||||||||||||||
491 | Q_ASSERT(noBlockInString(text.mid(fragments.fragment(x)->stringPosition, length))); | - | ||||||||||||||||||||||||||||||
492 | - | |||||||||||||||||||||||||||||||
493 | blocks.setSize(b, blocks.size(b)-length); | - | ||||||||||||||||||||||||||||||
494 | - | |||||||||||||||||||||||||||||||
495 | QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(fragments.fragment(x)->format)); | - | ||||||||||||||||||||||||||||||
496 | if (frame) {
| 0 | ||||||||||||||||||||||||||||||
497 | frame->d_func()->fragmentRemoved(text.at(fragments.fragment(x)->stringPosition), x); | - | ||||||||||||||||||||||||||||||
498 | framesDirty = true; | - | ||||||||||||||||||||||||||||||
499 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
500 | - | |||||||||||||||||||||||||||||||
501 | const int w = fragments.erase_single(x); | - | ||||||||||||||||||||||||||||||
502 | - | |||||||||||||||||||||||||||||||
503 | if (!undoEnabled)
| 0 | ||||||||||||||||||||||||||||||
504 | unreachableCharacterCount += length; never executed: unreachableCharacterCount += length; | 0 | ||||||||||||||||||||||||||||||
505 | - | |||||||||||||||||||||||||||||||
506 | adjustDocumentChangesAndCursors(pos, -int(length), op); | - | ||||||||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||||||||
508 | return w; never executed: return w; | 0 | ||||||||||||||||||||||||||||||
509 | } | - | ||||||||||||||||||||||||||||||
510 | - | |||||||||||||||||||||||||||||||
511 | int QTextDocumentPrivate::remove_block(int pos, int *blockFormat, int command, QTextUndoCommand::Operation op) | - | ||||||||||||||||||||||||||||||
512 | { | - | ||||||||||||||||||||||||||||||
513 | Q_ASSERT(pos >= 0); | - | ||||||||||||||||||||||||||||||
514 | Q_ASSERT(blocks.length() == fragments.length()); | - | ||||||||||||||||||||||||||||||
515 | Q_ASSERT(blocks.length() > pos); | - | ||||||||||||||||||||||||||||||
516 | - | |||||||||||||||||||||||||||||||
517 | int b = blocks.findNode(pos); | - | ||||||||||||||||||||||||||||||
518 | uint x = fragments.findNode(pos); | - | ||||||||||||||||||||||||||||||
519 | - | |||||||||||||||||||||||||||||||
520 | Q_ASSERT(x && (int)fragments.position(x) == pos); | - | ||||||||||||||||||||||||||||||
521 | Q_ASSERT(fragments.size(x) == 1); | - | ||||||||||||||||||||||||||||||
522 | Q_ASSERT(isValidBlockSeparator(text.at(fragments.fragment(x)->stringPosition))); | - | ||||||||||||||||||||||||||||||
523 | Q_ASSERT(b); | - | ||||||||||||||||||||||||||||||
524 | - | |||||||||||||||||||||||||||||||
525 | if (blocks.size(b) == 1 && command == QTextUndoCommand::BlockAdded) {
| 0 | ||||||||||||||||||||||||||||||
526 | Q_ASSERT((int)blocks.position(b) == pos); | - | ||||||||||||||||||||||||||||||
527 | // qDebug("removing empty block"); | - | ||||||||||||||||||||||||||||||
528 | // empty block remove the block itself | - | ||||||||||||||||||||||||||||||
529 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
530 | // non empty block, merge with next one into this block | - | ||||||||||||||||||||||||||||||
531 | // qDebug("merging block with next"); | - | ||||||||||||||||||||||||||||||
532 | int n = blocks.next(b); | - | ||||||||||||||||||||||||||||||
533 | Q_ASSERT((int)blocks.position(n) == pos + 1); | - | ||||||||||||||||||||||||||||||
534 | blocks.setSize(b, blocks.size(b) + blocks.size(n) - 1); | - | ||||||||||||||||||||||||||||||
535 | blocks.fragment(b)->userState = blocks.fragment(n)->userState; | - | ||||||||||||||||||||||||||||||
536 | b = n; | - | ||||||||||||||||||||||||||||||
537 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
538 | *blockFormat = blocks.fragment(b)->format; | - | ||||||||||||||||||||||||||||||
539 | - | |||||||||||||||||||||||||||||||
540 | QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(blocks.fragment(b)->format)); | - | ||||||||||||||||||||||||||||||
541 | if (group)
| 0 | ||||||||||||||||||||||||||||||
542 | group->blockRemoved(QTextBlock(this, b)); never executed: group->blockRemoved(QTextBlock(this, b)); | 0 | ||||||||||||||||||||||||||||||
543 | - | |||||||||||||||||||||||||||||||
544 | QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(fragments.fragment(x)->format)); | - | ||||||||||||||||||||||||||||||
545 | if (frame) {
| 0 | ||||||||||||||||||||||||||||||
546 | frame->d_func()->fragmentRemoved(text.at(fragments.fragment(x)->stringPosition), x); | - | ||||||||||||||||||||||||||||||
547 | framesDirty = true; | - | ||||||||||||||||||||||||||||||
548 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
549 | - | |||||||||||||||||||||||||||||||
550 | blocks.erase_single(b); | - | ||||||||||||||||||||||||||||||
551 | const int w = fragments.erase_single(x); | - | ||||||||||||||||||||||||||||||
552 | - | |||||||||||||||||||||||||||||||
553 | adjustDocumentChangesAndCursors(pos, -1, op); | - | ||||||||||||||||||||||||||||||
554 | - | |||||||||||||||||||||||||||||||
555 | return w; never executed: return w; | 0 | ||||||||||||||||||||||||||||||
556 | } | - | ||||||||||||||||||||||||||||||
557 | - | |||||||||||||||||||||||||||||||
558 | #if !defined(QT_NO_DEBUG) | - | ||||||||||||||||||||||||||||||
559 | static bool isAncestorFrame(QTextFrame *possibleAncestor, QTextFrame *child) | - | ||||||||||||||||||||||||||||||
560 | { | - | ||||||||||||||||||||||||||||||
561 | while (child) {
| 0 | ||||||||||||||||||||||||||||||
562 | if (child == possibleAncestor)
| 0 | ||||||||||||||||||||||||||||||
563 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
564 | child = child->parentFrame(); | - | ||||||||||||||||||||||||||||||
565 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
566 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
567 | } | - | ||||||||||||||||||||||||||||||
568 | #endif | - | ||||||||||||||||||||||||||||||
569 | - | |||||||||||||||||||||||||||||||
570 | void QTextDocumentPrivate::move(int pos, int to, int length, QTextUndoCommand::Operation op) | - | ||||||||||||||||||||||||||||||
571 | { | - | ||||||||||||||||||||||||||||||
572 | Q_ASSERT(to <= fragments.length() && to <= pos); | - | ||||||||||||||||||||||||||||||
573 | Q_ASSERT(pos >= 0 && pos+length <= fragments.length()); | - | ||||||||||||||||||||||||||||||
574 | Q_ASSERT(blocks.length() == fragments.length()); | - | ||||||||||||||||||||||||||||||
575 | - | |||||||||||||||||||||||||||||||
576 | if (pos == to)
| 0 | ||||||||||||||||||||||||||||||
577 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
578 | - | |||||||||||||||||||||||||||||||
579 | const bool needsInsert = to != -1; | - | ||||||||||||||||||||||||||||||
580 | - | |||||||||||||||||||||||||||||||
581 | #if !defined(QT_NO_DEBUG) | - | ||||||||||||||||||||||||||||||
582 | const bool startAndEndInSameFrame = (frameAt(pos) == frameAt(pos + length - 1)); | - | ||||||||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||||||||
584 | const bool endIsEndOfChildFrame = (isAncestorFrame(frameAt(pos), frameAt(pos + length - 1))
| 0 | ||||||||||||||||||||||||||||||
585 | && text.at(find(pos + length - 1)->stringPosition) == QTextEndOfFrame);
| 0 | ||||||||||||||||||||||||||||||
586 | - | |||||||||||||||||||||||||||||||
587 | const bool startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent | - | ||||||||||||||||||||||||||||||
588 | = (text.at(find(pos)->stringPosition) == QTextBeginningOfFrame
| 0 | ||||||||||||||||||||||||||||||
589 | && text.at(find(pos + length - 1)->stringPosition) == QTextEndOfFrame
| 0 | ||||||||||||||||||||||||||||||
590 | && frameAt(pos)->parentFrame() == frameAt(pos + length - 1)->parentFrame());
| 0 | ||||||||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||||||||
592 | const bool isFirstTableCell = (qobject_cast<QTextTable *>(frameAt(pos + length - 1))
| 0 | ||||||||||||||||||||||||||||||
593 | && frameAt(pos + length - 1)->parentFrame() == frameAt(pos));
| 0 | ||||||||||||||||||||||||||||||
594 | - | |||||||||||||||||||||||||||||||
595 | Q_ASSERT(startAndEndInSameFrame || endIsEndOfChildFrame || startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent || isFirstTableCell); | - | ||||||||||||||||||||||||||||||
596 | #endif | - | ||||||||||||||||||||||||||||||
597 | - | |||||||||||||||||||||||||||||||
598 | split(pos); | - | ||||||||||||||||||||||||||||||
599 | split(pos+length); | - | ||||||||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||||||||
601 | uint dst = needsInsert ? fragments.findNode(to) : 0;
| 0 | ||||||||||||||||||||||||||||||
602 | uint dstKey = needsInsert ? fragments.position(dst) : 0;
| 0 | ||||||||||||||||||||||||||||||
603 | - | |||||||||||||||||||||||||||||||
604 | uint x = fragments.findNode(pos); | - | ||||||||||||||||||||||||||||||
605 | uint end = fragments.findNode(pos+length); | - | ||||||||||||||||||||||||||||||
606 | - | |||||||||||||||||||||||||||||||
607 | uint w = 0; | - | ||||||||||||||||||||||||||||||
608 | while (x != end) {
| 0 | ||||||||||||||||||||||||||||||
609 | uint n = fragments.next(x); | - | ||||||||||||||||||||||||||||||
610 | - | |||||||||||||||||||||||||||||||
611 | uint key = fragments.position(x); | - | ||||||||||||||||||||||||||||||
612 | uint b = blocks.findNode(key+1); | - | ||||||||||||||||||||||||||||||
613 | QTextBlockData *B = blocks.fragment(b); | - | ||||||||||||||||||||||||||||||
614 | int blockRevision = B->revision; | - | ||||||||||||||||||||||||||||||
615 | - | |||||||||||||||||||||||||||||||
616 | QTextFragmentData *X = fragments.fragment(x); | - | ||||||||||||||||||||||||||||||
617 | QT_INIT_TEXTUNDOCOMMAND(c, QTextUndoCommand::Removed, (editBlock != 0), | - | ||||||||||||||||||||||||||||||
618 | op, X->format, X->stringPosition, key, X->size_array[0], | - | ||||||||||||||||||||||||||||||
619 | blockRevision); | - | ||||||||||||||||||||||||||||||
620 | QT_INIT_TEXTUNDOCOMMAND(cInsert, QTextUndoCommand::Inserted, (editBlock != 0), | - | ||||||||||||||||||||||||||||||
621 | op, X->format, X->stringPosition, dstKey, X->size_array[0], | - | ||||||||||||||||||||||||||||||
622 | blockRevision); | - | ||||||||||||||||||||||||||||||
623 | - | |||||||||||||||||||||||||||||||
624 | if (key+1 != blocks.position(b)) {
| 0 | ||||||||||||||||||||||||||||||
625 | // qDebug("remove_string from %d length %d", key, X->size_array[0]); | - | ||||||||||||||||||||||||||||||
626 | Q_ASSERT(noBlockInString(text.mid(X->stringPosition, X->size_array[0]))); | - | ||||||||||||||||||||||||||||||
627 | w = remove_string(key, X->size_array[0], op); | - | ||||||||||||||||||||||||||||||
628 | - | |||||||||||||||||||||||||||||||
629 | if (needsInsert) {
| 0 | ||||||||||||||||||||||||||||||
630 | insert_string(dstKey, X->stringPosition, X->size_array[0], X->format, op); | - | ||||||||||||||||||||||||||||||
631 | dstKey += X->size_array[0]; | - | ||||||||||||||||||||||||||||||
632 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
633 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
634 | // qDebug("remove_block at %d", key); | - | ||||||||||||||||||||||||||||||
635 | Q_ASSERT(X->size_array[0] == 1 && isValidBlockSeparator(text.at(X->stringPosition))); | - | ||||||||||||||||||||||||||||||
636 | b = blocks.previous(b); | - | ||||||||||||||||||||||||||||||
637 | B = 0; | - | ||||||||||||||||||||||||||||||
638 | c.command = blocks.size(b) == 1 ? QTextUndoCommand::BlockDeleted : QTextUndoCommand::BlockRemoved;
| 0 | ||||||||||||||||||||||||||||||
639 | w = remove_block(key, &c.blockFormat, QTextUndoCommand::BlockAdded, op); | - | ||||||||||||||||||||||||||||||
640 | - | |||||||||||||||||||||||||||||||
641 | if (needsInsert) {
| 0 | ||||||||||||||||||||||||||||||
642 | insert_block(dstKey++, X->stringPosition, X->format, c.blockFormat, op, QTextUndoCommand::BlockRemoved); | - | ||||||||||||||||||||||||||||||
643 | cInsert.command = blocks.size(b) == 1 ? QTextUndoCommand::BlockAdded : QTextUndoCommand::BlockInserted;
| 0 | ||||||||||||||||||||||||||||||
644 | cInsert.blockFormat = c.blockFormat; | - | ||||||||||||||||||||||||||||||
645 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
646 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
647 | appendUndoItem(c); | - | ||||||||||||||||||||||||||||||
648 | if (B)
| 0 | ||||||||||||||||||||||||||||||
649 | B->revision = revision; never executed: B->revision = revision; | 0 | ||||||||||||||||||||||||||||||
650 | x = n; | - | ||||||||||||||||||||||||||||||
651 | - | |||||||||||||||||||||||||||||||
652 | if (needsInsert)
| 0 | ||||||||||||||||||||||||||||||
653 | appendUndoItem(cInsert); never executed: appendUndoItem(cInsert); | 0 | ||||||||||||||||||||||||||||||
654 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
655 | if (w)
| 0 | ||||||||||||||||||||||||||||||
656 | unite(w); never executed: unite(w); | 0 | ||||||||||||||||||||||||||||||
657 | - | |||||||||||||||||||||||||||||||
658 | Q_ASSERT(blocks.length() == fragments.length()); | - | ||||||||||||||||||||||||||||||
659 | - | |||||||||||||||||||||||||||||||
660 | if (!blockCursorAdjustment)
| 0 | ||||||||||||||||||||||||||||||
661 | finishEdit(); never executed: finishEdit(); | 0 | ||||||||||||||||||||||||||||||
662 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
663 | - | |||||||||||||||||||||||||||||||
664 | void QTextDocumentPrivate::remove(int pos, int length, QTextUndoCommand::Operation op) | - | ||||||||||||||||||||||||||||||
665 | { | - | ||||||||||||||||||||||||||||||
666 | if (length == 0)
| 0 | ||||||||||||||||||||||||||||||
667 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
668 | blockCursorAdjustment = true; | - | ||||||||||||||||||||||||||||||
669 | move(pos, -1, length, op); | - | ||||||||||||||||||||||||||||||
670 | blockCursorAdjustment = false; | - | ||||||||||||||||||||||||||||||
671 | foreach (QTextCursorPrivate *curs, cursors) { | - | ||||||||||||||||||||||||||||||
672 | if (curs->adjustPosition(pos, -length, op) == QTextCursorPrivate::CursorMoved) {
| 0 | ||||||||||||||||||||||||||||||
673 | curs->changed = true; | - | ||||||||||||||||||||||||||||||
674 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
675 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
676 | finishEdit(); | - | ||||||||||||||||||||||||||||||
677 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
678 | - | |||||||||||||||||||||||||||||||
679 | void QTextDocumentPrivate::setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode) | - | ||||||||||||||||||||||||||||||
680 | { | - | ||||||||||||||||||||||||||||||
681 | beginEditBlock(); | - | ||||||||||||||||||||||||||||||
682 | - | |||||||||||||||||||||||||||||||
683 | Q_ASSERT(newFormat.isValid()); | - | ||||||||||||||||||||||||||||||
684 | - | |||||||||||||||||||||||||||||||
685 | int newFormatIdx = -1; | - | ||||||||||||||||||||||||||||||
686 | if (mode == SetFormatAndPreserveObjectIndices) {
| 0 | ||||||||||||||||||||||||||||||
687 | QTextCharFormat cleanFormat = newFormat; | - | ||||||||||||||||||||||||||||||
688 | cleanFormat.clearProperty(QTextFormat::ObjectIndex); | - | ||||||||||||||||||||||||||||||
689 | newFormatIdx = formats.indexForFormat(cleanFormat); | - | ||||||||||||||||||||||||||||||
690 | } else if (mode == SetFormat) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
691 | newFormatIdx = formats.indexForFormat(newFormat); | - | ||||||||||||||||||||||||||||||
692 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
693 | - | |||||||||||||||||||||||||||||||
694 | if (pos == -1) {
| 0 | ||||||||||||||||||||||||||||||
695 | if (mode == MergeFormat) {
| 0 | ||||||||||||||||||||||||||||||
696 | QTextFormat format = formats.format(initialBlockCharFormatIndex); | - | ||||||||||||||||||||||||||||||
697 | format.merge(newFormat); | - | ||||||||||||||||||||||||||||||
698 | initialBlockCharFormatIndex = formats.indexForFormat(format); | - | ||||||||||||||||||||||||||||||
699 | } else if (mode == SetFormatAndPreserveObjectIndices never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
700 | && formats.format(initialBlockCharFormatIndex).objectIndex() != -1) {
| 0 | ||||||||||||||||||||||||||||||
701 | QTextCharFormat f = newFormat; | - | ||||||||||||||||||||||||||||||
702 | f.setObjectIndex(formats.format(initialBlockCharFormatIndex).objectIndex()); | - | ||||||||||||||||||||||||||||||
703 | initialBlockCharFormatIndex = formats.indexForFormat(f); | - | ||||||||||||||||||||||||||||||
704 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
705 | initialBlockCharFormatIndex = newFormatIdx; | - | ||||||||||||||||||||||||||||||
706 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
707 | - | |||||||||||||||||||||||||||||||
708 | ++pos; | - | ||||||||||||||||||||||||||||||
709 | --length; | - | ||||||||||||||||||||||||||||||
710 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
711 | - | |||||||||||||||||||||||||||||||
712 | const int startPos = pos; | - | ||||||||||||||||||||||||||||||
713 | const int endPos = pos + length; | - | ||||||||||||||||||||||||||||||
714 | - | |||||||||||||||||||||||||||||||
715 | split(startPos); | - | ||||||||||||||||||||||||||||||
716 | split(endPos); | - | ||||||||||||||||||||||||||||||
717 | - | |||||||||||||||||||||||||||||||
718 | while (pos < endPos) {
| 0 | ||||||||||||||||||||||||||||||
719 | FragmentMap::Iterator it = fragments.find(pos); | - | ||||||||||||||||||||||||||||||
720 | Q_ASSERT(!it.atEnd()); | - | ||||||||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||||||||
722 | QTextFragmentData *fragment = it.value(); | - | ||||||||||||||||||||||||||||||
723 | - | |||||||||||||||||||||||||||||||
724 | Q_ASSERT(formats.format(fragment->format).type() == QTextFormat::CharFormat); | - | ||||||||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||||||||
726 | int offset = pos - it.position(); | - | ||||||||||||||||||||||||||||||
727 | int length = qMin(endPos - pos, int(fragment->size_array[0] - offset)); | - | ||||||||||||||||||||||||||||||
728 | int oldFormat = fragment->format; | - | ||||||||||||||||||||||||||||||
729 | - | |||||||||||||||||||||||||||||||
730 | if (mode == MergeFormat) {
| 0 | ||||||||||||||||||||||||||||||
731 | QTextFormat format = formats.format(fragment->format); | - | ||||||||||||||||||||||||||||||
732 | format.merge(newFormat); | - | ||||||||||||||||||||||||||||||
733 | fragment->format = formats.indexForFormat(format); | - | ||||||||||||||||||||||||||||||
734 | } else if (mode == SetFormatAndPreserveObjectIndices never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
735 | && formats.format(oldFormat).objectIndex() != -1) {
| 0 | ||||||||||||||||||||||||||||||
736 | QTextCharFormat f = newFormat; | - | ||||||||||||||||||||||||||||||
737 | f.setObjectIndex(formats.format(oldFormat).objectIndex()); | - | ||||||||||||||||||||||||||||||
738 | fragment->format = formats.indexForFormat(f); | - | ||||||||||||||||||||||||||||||
739 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
740 | fragment->format = newFormatIdx; | - | ||||||||||||||||||||||||||||||
741 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
742 | - | |||||||||||||||||||||||||||||||
743 | QT_INIT_TEXTUNDOCOMMAND(c, QTextUndoCommand::CharFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat, | - | ||||||||||||||||||||||||||||||
744 | 0, pos, length, 0); | - | ||||||||||||||||||||||||||||||
745 | appendUndoItem(c); | - | ||||||||||||||||||||||||||||||
746 | - | |||||||||||||||||||||||||||||||
747 | pos += length; | - | ||||||||||||||||||||||||||||||
748 | Q_ASSERT(pos == (int)(it.position() + fragment->size_array[0]) || pos >= endPos); | - | ||||||||||||||||||||||||||||||
749 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
750 | - | |||||||||||||||||||||||||||||||
751 | int n = fragments.findNode(startPos - 1); | - | ||||||||||||||||||||||||||||||
752 | if (n)
| 0 | ||||||||||||||||||||||||||||||
753 | unite(n); never executed: unite(n); | 0 | ||||||||||||||||||||||||||||||
754 | - | |||||||||||||||||||||||||||||||
755 | n = fragments.findNode(endPos); | - | ||||||||||||||||||||||||||||||
756 | if (n)
| 0 | ||||||||||||||||||||||||||||||
757 | unite(n); never executed: unite(n); | 0 | ||||||||||||||||||||||||||||||
758 | - | |||||||||||||||||||||||||||||||
759 | QTextBlock blockIt = blocksFind(startPos); | - | ||||||||||||||||||||||||||||||
760 | QTextBlock endIt = blocksFind(endPos); | - | ||||||||||||||||||||||||||||||
761 | if (endIt.isValid())
| 0 | ||||||||||||||||||||||||||||||
762 | endIt = endIt.next(); never executed: endIt = endIt.next(); | 0 | ||||||||||||||||||||||||||||||
763 | for (; blockIt.isValid() && blockIt != endIt; blockIt = blockIt.next())
| 0 | ||||||||||||||||||||||||||||||
764 | QTextDocumentPrivate::block(blockIt)->invalidate(); never executed: QTextDocumentPrivate::block(blockIt)->invalidate(); | 0 | ||||||||||||||||||||||||||||||
765 | - | |||||||||||||||||||||||||||||||
766 | documentChange(startPos, length); | - | ||||||||||||||||||||||||||||||
767 | - | |||||||||||||||||||||||||||||||
768 | endEditBlock(); | - | ||||||||||||||||||||||||||||||
769 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
770 | - | |||||||||||||||||||||||||||||||
771 | void QTextDocumentPrivate::setBlockFormat(const QTextBlock &from, const QTextBlock &to, | - | ||||||||||||||||||||||||||||||
772 | const QTextBlockFormat &newFormat, FormatChangeMode mode) | - | ||||||||||||||||||||||||||||||
773 | { | - | ||||||||||||||||||||||||||||||
774 | beginEditBlock(); | - | ||||||||||||||||||||||||||||||
775 | - | |||||||||||||||||||||||||||||||
776 | Q_ASSERT(mode != SetFormatAndPreserveObjectIndices); // only implemented for setCharFormat | - | ||||||||||||||||||||||||||||||
777 | - | |||||||||||||||||||||||||||||||
778 | Q_ASSERT(newFormat.isValid()); | - | ||||||||||||||||||||||||||||||
779 | - | |||||||||||||||||||||||||||||||
780 | int newFormatIdx = -1; | - | ||||||||||||||||||||||||||||||
781 | if (mode == SetFormat)
| 0 | ||||||||||||||||||||||||||||||
782 | newFormatIdx = formats.indexForFormat(newFormat); never executed: newFormatIdx = formats.indexForFormat(newFormat); | 0 | ||||||||||||||||||||||||||||||
783 | QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(newFormat)); | - | ||||||||||||||||||||||||||||||
784 | - | |||||||||||||||||||||||||||||||
785 | QTextBlock it = from; | - | ||||||||||||||||||||||||||||||
786 | QTextBlock end = to; | - | ||||||||||||||||||||||||||||||
787 | if (end.isValid())
| 0 | ||||||||||||||||||||||||||||||
788 | end = end.next(); never executed: end = end.next(); | 0 | ||||||||||||||||||||||||||||||
789 | - | |||||||||||||||||||||||||||||||
790 | for (; it != end; it = it.next()) {
| 0 | ||||||||||||||||||||||||||||||
791 | int oldFormat = block(it)->format; | - | ||||||||||||||||||||||||||||||
792 | QTextBlockFormat format = formats.blockFormat(oldFormat); | - | ||||||||||||||||||||||||||||||
793 | QTextBlockGroup *oldGroup = qobject_cast<QTextBlockGroup *>(objectForFormat(format)); | - | ||||||||||||||||||||||||||||||
794 | if (mode == MergeFormat) {
| 0 | ||||||||||||||||||||||||||||||
795 | format.merge(newFormat); | - | ||||||||||||||||||||||||||||||
796 | newFormatIdx = formats.indexForFormat(format); | - | ||||||||||||||||||||||||||||||
797 | group = qobject_cast<QTextBlockGroup *>(objectForFormat(format)); | - | ||||||||||||||||||||||||||||||
798 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
799 | block(it)->format = newFormatIdx; | - | ||||||||||||||||||||||||||||||
800 | - | |||||||||||||||||||||||||||||||
801 | block(it)->invalidate(); | - | ||||||||||||||||||||||||||||||
802 | - | |||||||||||||||||||||||||||||||
803 | QT_INIT_TEXTUNDOCOMMAND(c, QTextUndoCommand::BlockFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat, | - | ||||||||||||||||||||||||||||||
804 | 0, it.position(), 1, 0); | - | ||||||||||||||||||||||||||||||
805 | appendUndoItem(c); | - | ||||||||||||||||||||||||||||||
806 | - | |||||||||||||||||||||||||||||||
807 | if (group != oldGroup) {
| 0 | ||||||||||||||||||||||||||||||
808 | if (oldGroup)
| 0 | ||||||||||||||||||||||||||||||
809 | oldGroup->blockRemoved(it); never executed: oldGroup->blockRemoved(it); | 0 | ||||||||||||||||||||||||||||||
810 | if (group)
| 0 | ||||||||||||||||||||||||||||||
811 | group->blockInserted(it); never executed: group->blockInserted(it); | 0 | ||||||||||||||||||||||||||||||
812 | } else if (group) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
813 | group->blockFormatChanged(it); | - | ||||||||||||||||||||||||||||||
814 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
815 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
816 | - | |||||||||||||||||||||||||||||||
817 | documentChange(from.position(), to.position() + to.length() - from.position()); | - | ||||||||||||||||||||||||||||||
818 | - | |||||||||||||||||||||||||||||||
819 | endEditBlock(); | - | ||||||||||||||||||||||||||||||
820 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
821 | - | |||||||||||||||||||||||||||||||
822 | - | |||||||||||||||||||||||||||||||
823 | bool QTextDocumentPrivate::split(int pos) | - | ||||||||||||||||||||||||||||||
824 | { | - | ||||||||||||||||||||||||||||||
825 | uint x = fragments.findNode(pos); | - | ||||||||||||||||||||||||||||||
826 | if (x) {
| 0 | ||||||||||||||||||||||||||||||
827 | int k = fragments.position(x); | - | ||||||||||||||||||||||||||||||
828 | // qDebug("found fragment with key %d, size_left=%d, size=%d to split at %d", | - | ||||||||||||||||||||||||||||||
829 | // k, (*it)->size_left[0], (*it)->size_array[0], pos); | - | ||||||||||||||||||||||||||||||
830 | if (k != pos) {
| 0 | ||||||||||||||||||||||||||||||
831 | Q_ASSERT(k <= pos); | - | ||||||||||||||||||||||||||||||
832 | // need to resize the first fragment and add a new one | - | ||||||||||||||||||||||||||||||
833 | QTextFragmentData *X = fragments.fragment(x); | - | ||||||||||||||||||||||||||||||
834 | int oldsize = X->size_array[0]; | - | ||||||||||||||||||||||||||||||
835 | fragments.setSize(x, pos-k); | - | ||||||||||||||||||||||||||||||
836 | uint n = fragments.insert_single(pos, oldsize-(pos-k)); | - | ||||||||||||||||||||||||||||||
837 | X = fragments.fragment(x); | - | ||||||||||||||||||||||||||||||
838 | QTextFragmentData *N = fragments.fragment(n); | - | ||||||||||||||||||||||||||||||
839 | N->stringPosition = X->stringPosition + pos-k; | - | ||||||||||||||||||||||||||||||
840 | N->format = X->format; | - | ||||||||||||||||||||||||||||||
841 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
842 | } | - | ||||||||||||||||||||||||||||||
843 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
844 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
845 | } | - | ||||||||||||||||||||||||||||||
846 | - | |||||||||||||||||||||||||||||||
847 | bool QTextDocumentPrivate::unite(uint f) | - | ||||||||||||||||||||||||||||||
848 | { | - | ||||||||||||||||||||||||||||||
849 | uint n = fragments.next(f); | - | ||||||||||||||||||||||||||||||
850 | if (!n)
| 0 | ||||||||||||||||||||||||||||||
851 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
852 | - | |||||||||||||||||||||||||||||||
853 | QTextFragmentData *ff = fragments.fragment(f); | - | ||||||||||||||||||||||||||||||
854 | QTextFragmentData *nf = fragments.fragment(n); | - | ||||||||||||||||||||||||||||||
855 | - | |||||||||||||||||||||||||||||||
856 | if (nf->format == ff->format && (ff->stringPosition + (int)ff->size_array[0] == nf->stringPosition)) {
| 0 | ||||||||||||||||||||||||||||||
857 | if (isValidBlockSeparator(text.at(ff->stringPosition))
| 0 | ||||||||||||||||||||||||||||||
858 | || isValidBlockSeparator(text.at(nf->stringPosition)))
| 0 | ||||||||||||||||||||||||||||||
859 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
860 | - | |||||||||||||||||||||||||||||||
861 | fragments.setSize(f, ff->size_array[0] + nf->size_array[0]); | - | ||||||||||||||||||||||||||||||
862 | fragments.erase_single(n); | - | ||||||||||||||||||||||||||||||
863 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
864 | } | - | ||||||||||||||||||||||||||||||
865 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
866 | } | - | ||||||||||||||||||||||||||||||
867 | - | |||||||||||||||||||||||||||||||
868 | - | |||||||||||||||||||||||||||||||
869 | int QTextDocumentPrivate::undoRedo(bool undo) | - | ||||||||||||||||||||||||||||||
870 | { | - | ||||||||||||||||||||||||||||||
871 | PMDEBUG("%s, undoState=%d, undoStack size=%d", undo ? "undo:" : "redo:", undoState, undoStack.size()); dead code: QMessageLogger(__FILE__, 871, __PRETTY_FUNCTION__).debug("%s, undoState=%d, undoStack size=%d", undo ? "undo:" : "redo:", undoState, undoStack.size()); | - | ||||||||||||||||||||||||||||||
872 | if (!undoEnabled || (undo && undoState == 0) || (!undo && undoState == undoStack.size()))
| 0 | ||||||||||||||||||||||||||||||
873 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||
874 | - | |||||||||||||||||||||||||||||||
875 | undoEnabled = false; | - | ||||||||||||||||||||||||||||||
876 | beginEditBlock(); | - | ||||||||||||||||||||||||||||||
877 | int editPos = -1; | - | ||||||||||||||||||||||||||||||
878 | int editLength = -1; | - | ||||||||||||||||||||||||||||||
879 | while (1) { | - | ||||||||||||||||||||||||||||||
880 | if (undo)
| 0 | ||||||||||||||||||||||||||||||
881 | --undoState; never executed: --undoState; | 0 | ||||||||||||||||||||||||||||||
882 | QTextUndoCommand &c = undoStack[undoState]; | - | ||||||||||||||||||||||||||||||
883 | int resetBlockRevision = c.pos; | - | ||||||||||||||||||||||||||||||
884 | - | |||||||||||||||||||||||||||||||
885 | switch (c.command) { | - | ||||||||||||||||||||||||||||||
886 | case QTextUndoCommand::Inserted: never executed: case QTextUndoCommand::Inserted: | 0 | ||||||||||||||||||||||||||||||
887 | remove(c.pos, c.length, (QTextUndoCommand::Operation)c.operation); | - | ||||||||||||||||||||||||||||||
888 | PMDEBUG(" erase: from %d, length %d", c.pos, c.length); dead code: QMessageLogger(__FILE__, 888, __PRETTY_FUNCTION__).debug(" erase: from %d, length %d", c.pos, c.length); | - | ||||||||||||||||||||||||||||||
889 | c.command = QTextUndoCommand::Removed; | - | ||||||||||||||||||||||||||||||
890 | editPos = c.pos; | - | ||||||||||||||||||||||||||||||
891 | editLength = 0; | - | ||||||||||||||||||||||||||||||
892 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
893 | case QTextUndoCommand::Removed: never executed: case QTextUndoCommand::Removed: | 0 | ||||||||||||||||||||||||||||||
894 | PMDEBUG(" insert: format %d (from %d, length %d, strpos=%d)", c.format, c.pos, c.length, c.strPos); dead code: QMessageLogger(__FILE__, 894, __PRETTY_FUNCTION__).debug(" insert: format %d (from %d, length %d, strpos=%d)", c.format, c.pos, c.length, c.strPos); | - | ||||||||||||||||||||||||||||||
895 | insert_string(c.pos, c.strPos, c.length, c.format, (QTextUndoCommand::Operation)c.operation); | - | ||||||||||||||||||||||||||||||
896 | c.command = QTextUndoCommand::Inserted; | - | ||||||||||||||||||||||||||||||
897 | if (editPos != (int)c.pos)
| 0 | ||||||||||||||||||||||||||||||
898 | editLength = 0; never executed: editLength = 0; | 0 | ||||||||||||||||||||||||||||||
899 | editPos = c.pos; | - | ||||||||||||||||||||||||||||||
900 | editLength += c.length; | - | ||||||||||||||||||||||||||||||
901 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
902 | case QTextUndoCommand::BlockInserted: never executed: case QTextUndoCommand::BlockInserted: | 0 | ||||||||||||||||||||||||||||||
903 | case QTextUndoCommand::BlockAdded: never executed: case QTextUndoCommand::BlockAdded: | 0 | ||||||||||||||||||||||||||||||
904 | remove_block(c.pos, &c.blockFormat, c.command, (QTextUndoCommand::Operation)c.operation); | - | ||||||||||||||||||||||||||||||
905 | PMDEBUG(" blockremove: from %d", c.pos); dead code: QMessageLogger(__FILE__, 905, __PRETTY_FUNCTION__).debug(" blockremove: from %d", c.pos); | - | ||||||||||||||||||||||||||||||
906 | if (c.command == QTextUndoCommand::BlockInserted)
| 0 | ||||||||||||||||||||||||||||||
907 | c.command = QTextUndoCommand::BlockRemoved; never executed: c.command = QTextUndoCommand::BlockRemoved; | 0 | ||||||||||||||||||||||||||||||
908 | else | - | ||||||||||||||||||||||||||||||
909 | c.command = QTextUndoCommand::BlockDeleted; never executed: c.command = QTextUndoCommand::BlockDeleted; | 0 | ||||||||||||||||||||||||||||||
910 | editPos = c.pos; | - | ||||||||||||||||||||||||||||||
911 | editLength = 0; | - | ||||||||||||||||||||||||||||||
912 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
913 | case QTextUndoCommand::BlockRemoved: never executed: case QTextUndoCommand::BlockRemoved: | 0 | ||||||||||||||||||||||||||||||
914 | case QTextUndoCommand::BlockDeleted: never executed: case QTextUndoCommand::BlockDeleted: | 0 | ||||||||||||||||||||||||||||||
915 | PMDEBUG(" blockinsert: charformat %d blockformat %d (pos %d, strpos=%d)", c.format, c.blockFormat, c.pos, c.strPos); dead code: QMessageLogger(__FILE__, 915, __PRETTY_FUNCTION__).debug(" blockinsert: charformat %d blockformat %d (pos %d, strpos=%d)", c.format, c.blockFormat, c.pos, c.strPos); | - | ||||||||||||||||||||||||||||||
916 | insert_block(c.pos, c.strPos, c.format, c.blockFormat, (QTextUndoCommand::Operation)c.operation, c.command); | - | ||||||||||||||||||||||||||||||
917 | resetBlockRevision += 1; | - | ||||||||||||||||||||||||||||||
918 | if (c.command == QTextUndoCommand::BlockRemoved)
| 0 | ||||||||||||||||||||||||||||||
919 | c.command = QTextUndoCommand::BlockInserted; never executed: c.command = QTextUndoCommand::BlockInserted; | 0 | ||||||||||||||||||||||||||||||
920 | else | - | ||||||||||||||||||||||||||||||
921 | c.command = QTextUndoCommand::BlockAdded; never executed: c.command = QTextUndoCommand::BlockAdded; | 0 | ||||||||||||||||||||||||||||||
922 | if (editPos != (int)c.pos)
| 0 | ||||||||||||||||||||||||||||||
923 | editLength = 0; never executed: editLength = 0; | 0 | ||||||||||||||||||||||||||||||
924 | editPos = c.pos; | - | ||||||||||||||||||||||||||||||
925 | editLength += 1; | - | ||||||||||||||||||||||||||||||
926 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
927 | case QTextUndoCommand::CharFormatChanged: { never executed: case QTextUndoCommand::CharFormatChanged: | 0 | ||||||||||||||||||||||||||||||
928 | resetBlockRevision = -1; // ## TODO | - | ||||||||||||||||||||||||||||||
929 | PMDEBUG(" charFormat: format %d (from %d, length %d)", c.format, c.pos, c.length); dead code: QMessageLogger(__FILE__, 929, __PRETTY_FUNCTION__).debug(" charFormat: format %d (from %d, length %d)", c.format, c.pos, c.length); | - | ||||||||||||||||||||||||||||||
930 | FragmentIterator it = find(c.pos); | - | ||||||||||||||||||||||||||||||
931 | Q_ASSERT(!it.atEnd()); | - | ||||||||||||||||||||||||||||||
932 | - | |||||||||||||||||||||||||||||||
933 | int oldFormat = it.value()->format; | - | ||||||||||||||||||||||||||||||
934 | setCharFormat(c.pos, c.length, formats.charFormat(c.format)); | - | ||||||||||||||||||||||||||||||
935 | c.format = oldFormat; | - | ||||||||||||||||||||||||||||||
936 | if (editPos != (int)c.pos)
| 0 | ||||||||||||||||||||||||||||||
937 | editLength = 0; never executed: editLength = 0; | 0 | ||||||||||||||||||||||||||||||
938 | editPos = c.pos; | - | ||||||||||||||||||||||||||||||
939 | editLength += c.length; | - | ||||||||||||||||||||||||||||||
940 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
941 | } | - | ||||||||||||||||||||||||||||||
942 | case QTextUndoCommand::BlockFormatChanged: { never executed: case QTextUndoCommand::BlockFormatChanged: | 0 | ||||||||||||||||||||||||||||||
943 | resetBlockRevision = -1; // ## TODO | - | ||||||||||||||||||||||||||||||
944 | PMDEBUG(" blockformat: format %d pos %d", c.format, c.pos); dead code: QMessageLogger(__FILE__, 944, __PRETTY_FUNCTION__).debug(" blockformat: format %d pos %d", c.format, c.pos); | - | ||||||||||||||||||||||||||||||
945 | QTextBlock it = blocksFind(c.pos); | - | ||||||||||||||||||||||||||||||
946 | Q_ASSERT(it.isValid()); | - | ||||||||||||||||||||||||||||||
947 | - | |||||||||||||||||||||||||||||||
948 | int oldFormat = block(it)->format; | - | ||||||||||||||||||||||||||||||
949 | block(it)->format = c.format; | - | ||||||||||||||||||||||||||||||
950 | QTextBlockGroup *oldGroup = qobject_cast<QTextBlockGroup *>(objectForFormat(formats.blockFormat(oldFormat))); | - | ||||||||||||||||||||||||||||||
951 | QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(formats.blockFormat(c.format))); | - | ||||||||||||||||||||||||||||||
952 | c.format = oldFormat; | - | ||||||||||||||||||||||||||||||
953 | if (group != oldGroup) {
| 0 | ||||||||||||||||||||||||||||||
954 | if (oldGroup)
| 0 | ||||||||||||||||||||||||||||||
955 | oldGroup->blockRemoved(it); never executed: oldGroup->blockRemoved(it); | 0 | ||||||||||||||||||||||||||||||
956 | if (group)
| 0 | ||||||||||||||||||||||||||||||
957 | group->blockInserted(it); never executed: group->blockInserted(it); | 0 | ||||||||||||||||||||||||||||||
958 | } else if (group) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
959 | group->blockFormatChanged(it); | - | ||||||||||||||||||||||||||||||
960 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
961 | documentChange(it.position(), it.length()); | - | ||||||||||||||||||||||||||||||
962 | editPos = -1; | - | ||||||||||||||||||||||||||||||
963 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
964 | } | - | ||||||||||||||||||||||||||||||
965 | case QTextUndoCommand::GroupFormatChange: { never executed: case QTextUndoCommand::GroupFormatChange: | 0 | ||||||||||||||||||||||||||||||
966 | resetBlockRevision = -1; // ## TODO | - | ||||||||||||||||||||||||||||||
967 | PMDEBUG(" group format change"); dead code: QMessageLogger(__FILE__, 967, __PRETTY_FUNCTION__).debug(" group format change"); | - | ||||||||||||||||||||||||||||||
968 | QTextObject *object = objectForIndex(c.objectIndex); | - | ||||||||||||||||||||||||||||||
969 | int oldFormat = formats.objectFormatIndex(c.objectIndex); | - | ||||||||||||||||||||||||||||||
970 | changeObjectFormat(object, c.format); | - | ||||||||||||||||||||||||||||||
971 | c.format = oldFormat; | - | ||||||||||||||||||||||||||||||
972 | editPos = -1; | - | ||||||||||||||||||||||||||||||
973 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
974 | } | - | ||||||||||||||||||||||||||||||
975 | case QTextUndoCommand::CursorMoved: never executed: case QTextUndoCommand::CursorMoved: | 0 | ||||||||||||||||||||||||||||||
976 | editPos = c.pos; | - | ||||||||||||||||||||||||||||||
977 | editLength = 0; | - | ||||||||||||||||||||||||||||||
978 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
979 | case QTextUndoCommand::Custom: never executed: case QTextUndoCommand::Custom: | 0 | ||||||||||||||||||||||||||||||
980 | resetBlockRevision = -1; // ## TODO | - | ||||||||||||||||||||||||||||||
981 | if (undo)
| 0 | ||||||||||||||||||||||||||||||
982 | c.custom->undo(); never executed: c.custom->undo(); | 0 | ||||||||||||||||||||||||||||||
983 | else | - | ||||||||||||||||||||||||||||||
984 | c.custom->redo(); never executed: c.custom->redo(); | 0 | ||||||||||||||||||||||||||||||
985 | editPos = -1; | - | ||||||||||||||||||||||||||||||
986 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
987 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
988 | Q_ASSERT(false); | - | ||||||||||||||||||||||||||||||
989 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
990 | - | |||||||||||||||||||||||||||||||
991 | if (resetBlockRevision >= 0) {
| 0 | ||||||||||||||||||||||||||||||
992 | int b = blocks.findNode(resetBlockRevision); | - | ||||||||||||||||||||||||||||||
993 | QTextBlockData *B = blocks.fragment(b); | - | ||||||||||||||||||||||||||||||
994 | B->revision = c.revision; | - | ||||||||||||||||||||||||||||||
995 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
996 | - | |||||||||||||||||||||||||||||||
997 | if (!undo)
| 0 | ||||||||||||||||||||||||||||||
998 | ++undoState; never executed: ++undoState; | 0 | ||||||||||||||||||||||||||||||
999 | - | |||||||||||||||||||||||||||||||
1000 | bool inBlock = ( | - | ||||||||||||||||||||||||||||||
1001 | undoState > 0
| 0 | ||||||||||||||||||||||||||||||
1002 | && undoState < undoStack.size()
| 0 | ||||||||||||||||||||||||||||||
1003 | && undoStack[undoState].block_part
| 0 | ||||||||||||||||||||||||||||||
1004 | && undoStack[undoState-1].block_part
| 0 | ||||||||||||||||||||||||||||||
1005 | && !undoStack[undoState-1].block_end
| 0 | ||||||||||||||||||||||||||||||
1006 | ); | - | ||||||||||||||||||||||||||||||
1007 | if (!inBlock)
| 0 | ||||||||||||||||||||||||||||||
1008 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1009 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1010 | undoEnabled = true; | - | ||||||||||||||||||||||||||||||
1011 | - | |||||||||||||||||||||||||||||||
1012 | int newCursorPos = -1; | - | ||||||||||||||||||||||||||||||
1013 | - | |||||||||||||||||||||||||||||||
1014 | if (editPos >=0)
| 0 | ||||||||||||||||||||||||||||||
1015 | newCursorPos = editPos + editLength; never executed: newCursorPos = editPos + editLength; | 0 | ||||||||||||||||||||||||||||||
1016 | else if (docChangeFrom >= 0)
| 0 | ||||||||||||||||||||||||||||||
1017 | newCursorPos= qMin(docChangeFrom + docChangeLength, length() - 1); never executed: newCursorPos= qMin(docChangeFrom + docChangeLength, length() - 1); | 0 | ||||||||||||||||||||||||||||||
1018 | - | |||||||||||||||||||||||||||||||
1019 | endEditBlock(); | - | ||||||||||||||||||||||||||||||
1020 | emitUndoAvailable(isUndoAvailable()); | - | ||||||||||||||||||||||||||||||
1021 | emitRedoAvailable(isRedoAvailable()); | - | ||||||||||||||||||||||||||||||
1022 | - | |||||||||||||||||||||||||||||||
1023 | return newCursorPos; never executed: return newCursorPos; | 0 | ||||||||||||||||||||||||||||||
1024 | } | - | ||||||||||||||||||||||||||||||
1025 | - | |||||||||||||||||||||||||||||||
1026 | /*! | - | ||||||||||||||||||||||||||||||
1027 | Appends a custom undo \a item to the undo stack. | - | ||||||||||||||||||||||||||||||
1028 | */ | - | ||||||||||||||||||||||||||||||
1029 | void QTextDocumentPrivate::appendUndoItem(QAbstractUndoItem *item) | - | ||||||||||||||||||||||||||||||
1030 | { | - | ||||||||||||||||||||||||||||||
1031 | if (!undoEnabled) {
| 0 | ||||||||||||||||||||||||||||||
1032 | delete item; | - | ||||||||||||||||||||||||||||||
1033 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1034 | } | - | ||||||||||||||||||||||||||||||
1035 | - | |||||||||||||||||||||||||||||||
1036 | QTextUndoCommand c; | - | ||||||||||||||||||||||||||||||
1037 | c.command = QTextUndoCommand::Custom; | - | ||||||||||||||||||||||||||||||
1038 | c.block_part = editBlock != 0; | - | ||||||||||||||||||||||||||||||
1039 | c.block_end = 0; | - | ||||||||||||||||||||||||||||||
1040 | c.operation = QTextUndoCommand::MoveCursor; | - | ||||||||||||||||||||||||||||||
1041 | c.format = 0; | - | ||||||||||||||||||||||||||||||
1042 | c.strPos = 0; | - | ||||||||||||||||||||||||||||||
1043 | c.pos = 0; | - | ||||||||||||||||||||||||||||||
1044 | c.blockFormat = 0; | - | ||||||||||||||||||||||||||||||
1045 | - | |||||||||||||||||||||||||||||||
1046 | c.custom = item; | - | ||||||||||||||||||||||||||||||
1047 | appendUndoItem(c); | - | ||||||||||||||||||||||||||||||
1048 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1049 | - | |||||||||||||||||||||||||||||||
1050 | void QTextDocumentPrivate::appendUndoItem(const QTextUndoCommand &c) | - | ||||||||||||||||||||||||||||||
1051 | { | - | ||||||||||||||||||||||||||||||
1052 | PMDEBUG("appendUndoItem, command=%d enabled=%d", c.command, undoEnabled); dead code: QMessageLogger(__FILE__, 1052, __PRETTY_FUNCTION__).debug("appendUndoItem, command=%d enabled=%d", c.command, undoEnabled); | - | ||||||||||||||||||||||||||||||
1053 | if (!undoEnabled)
| 0 | ||||||||||||||||||||||||||||||
1054 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1055 | if (undoState < undoStack.size())
| 0 | ||||||||||||||||||||||||||||||
1056 | clearUndoRedoStacks(QTextDocument::RedoStack); never executed: clearUndoRedoStacks(QTextDocument::RedoStack); | 0 | ||||||||||||||||||||||||||||||
1057 | - | |||||||||||||||||||||||||||||||
1058 | if (editBlock != 0 && editBlockCursorPosition >= 0) { // we had a beginEditBlock() with a cursor position
| 0 | ||||||||||||||||||||||||||||||
1059 | if (c.pos != (quint32) editBlockCursorPosition) { // and that cursor position is different from the command
| 0 | ||||||||||||||||||||||||||||||
1060 | // generate a CursorMoved undo item | - | ||||||||||||||||||||||||||||||
1061 | QT_INIT_TEXTUNDOCOMMAND(cc, QTextUndoCommand::CursorMoved, true, QTextUndoCommand::MoveCursor, | - | ||||||||||||||||||||||||||||||
1062 | 0, 0, editBlockCursorPosition, 0, 0); | - | ||||||||||||||||||||||||||||||
1063 | undoStack.append(cc); | - | ||||||||||||||||||||||||||||||
1064 | undoState++; | - | ||||||||||||||||||||||||||||||
1065 | editBlockCursorPosition = -1; | - | ||||||||||||||||||||||||||||||
1066 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1067 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1068 | - | |||||||||||||||||||||||||||||||
1069 | - | |||||||||||||||||||||||||||||||
1070 | if (!undoStack.isEmpty() && modified) {
| 0 | ||||||||||||||||||||||||||||||
1071 | QTextUndoCommand &last = undoStack[undoState - 1]; | - | ||||||||||||||||||||||||||||||
1072 | - | |||||||||||||||||||||||||||||||
1073 | if ( (last.block_part && c.block_part && !last.block_end) // part of the same block => can merge
| 0 | ||||||||||||||||||||||||||||||
1074 | || (!c.block_part && !last.block_part)) { // two single undo items => can merge
| 0 | ||||||||||||||||||||||||||||||
1075 | - | |||||||||||||||||||||||||||||||
1076 | if (last.tryMerge(c))
| 0 | ||||||||||||||||||||||||||||||
1077 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1078 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1079 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1080 | if (modifiedState > undoState)
| 0 | ||||||||||||||||||||||||||||||
1081 | modifiedState = -1; never executed: modifiedState = -1; | 0 | ||||||||||||||||||||||||||||||
1082 | undoStack.append(c); | - | ||||||||||||||||||||||||||||||
1083 | undoState++; | - | ||||||||||||||||||||||||||||||
1084 | emitUndoAvailable(true); | - | ||||||||||||||||||||||||||||||
1085 | emitRedoAvailable(false); | - | ||||||||||||||||||||||||||||||
1086 | - | |||||||||||||||||||||||||||||||
1087 | if (!c.block_part)
| 0 | ||||||||||||||||||||||||||||||
1088 | emit document()->undoCommandAdded(); never executed: document()->undoCommandAdded(); | 0 | ||||||||||||||||||||||||||||||
1089 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1090 | - | |||||||||||||||||||||||||||||||
1091 | void QTextDocumentPrivate::clearUndoRedoStacks(QTextDocument::Stacks stacksToClear, | - | ||||||||||||||||||||||||||||||
1092 | bool emitSignals) | - | ||||||||||||||||||||||||||||||
1093 | { | - | ||||||||||||||||||||||||||||||
1094 | bool undoCommandsAvailable = undoState != 0; | - | ||||||||||||||||||||||||||||||
1095 | bool redoCommandsAvailable = undoState != undoStack.size(); | - | ||||||||||||||||||||||||||||||
1096 | if (stacksToClear == QTextDocument::UndoStack && undoCommandsAvailable) {
| 0 | ||||||||||||||||||||||||||||||
1097 | for (int i = 0; i < undoState; ++i) {
| 0 | ||||||||||||||||||||||||||||||
1098 | QTextUndoCommand c = undoStack[undoState]; | - | ||||||||||||||||||||||||||||||
1099 | if (c.command & QTextUndoCommand::Custom)
| 0 | ||||||||||||||||||||||||||||||
1100 | delete c.custom; never executed: delete c.custom; | 0 | ||||||||||||||||||||||||||||||
1101 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1102 | undoStack.remove(0, undoState); | - | ||||||||||||||||||||||||||||||
1103 | undoStack.resize(undoStack.size() - undoState); | - | ||||||||||||||||||||||||||||||
1104 | undoState = 0; | - | ||||||||||||||||||||||||||||||
1105 | if (emitSignals)
| 0 | ||||||||||||||||||||||||||||||
1106 | emitUndoAvailable(false); never executed: emitUndoAvailable(false); | 0 | ||||||||||||||||||||||||||||||
1107 | } else if (stacksToClear == QTextDocument::RedoStack never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
1108 | && redoCommandsAvailable) {
| 0 | ||||||||||||||||||||||||||||||
1109 | for (int i = undoState; i < undoStack.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
1110 | QTextUndoCommand c = undoStack[i]; | - | ||||||||||||||||||||||||||||||
1111 | if (c.command & QTextUndoCommand::Custom)
| 0 | ||||||||||||||||||||||||||||||
1112 | delete c.custom; never executed: delete c.custom; | 0 | ||||||||||||||||||||||||||||||
1113 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1114 | undoStack.resize(undoState); | - | ||||||||||||||||||||||||||||||
1115 | if (emitSignals)
| 0 | ||||||||||||||||||||||||||||||
1116 | emitRedoAvailable(false); never executed: emitRedoAvailable(false); | 0 | ||||||||||||||||||||||||||||||
1117 | } else if (stacksToClear == QTextDocument::UndoAndRedoStacks never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
1118 | && !undoStack.isEmpty()) {
| 0 | ||||||||||||||||||||||||||||||
1119 | for (int i = 0; i < undoStack.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
1120 | QTextUndoCommand c = undoStack[i]; | - | ||||||||||||||||||||||||||||||
1121 | if (c.command & QTextUndoCommand::Custom)
| 0 | ||||||||||||||||||||||||||||||
1122 | delete c.custom; never executed: delete c.custom; | 0 | ||||||||||||||||||||||||||||||
1123 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1124 | undoState = 0; | - | ||||||||||||||||||||||||||||||
1125 | undoStack.resize(0); | - | ||||||||||||||||||||||||||||||
1126 | if (emitSignals && undoCommandsAvailable)
| 0 | ||||||||||||||||||||||||||||||
1127 | emitUndoAvailable(false); never executed: emitUndoAvailable(false); | 0 | ||||||||||||||||||||||||||||||
1128 | if (emitSignals && redoCommandsAvailable)
| 0 | ||||||||||||||||||||||||||||||
1129 | emitRedoAvailable(false); never executed: emitRedoAvailable(false); | 0 | ||||||||||||||||||||||||||||||
1130 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1131 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1132 | - | |||||||||||||||||||||||||||||||
1133 | void QTextDocumentPrivate::emitUndoAvailable(bool available) | - | ||||||||||||||||||||||||||||||
1134 | { | - | ||||||||||||||||||||||||||||||
1135 | if (available != wasUndoAvailable) {
| 0 | ||||||||||||||||||||||||||||||
1136 | Q_Q(QTextDocument); | - | ||||||||||||||||||||||||||||||
1137 | emit q->undoAvailable(available); | - | ||||||||||||||||||||||||||||||
1138 | wasUndoAvailable = available; | - | ||||||||||||||||||||||||||||||
1139 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1140 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1141 | - | |||||||||||||||||||||||||||||||
1142 | void QTextDocumentPrivate::emitRedoAvailable(bool available) | - | ||||||||||||||||||||||||||||||
1143 | { | - | ||||||||||||||||||||||||||||||
1144 | if (available != wasRedoAvailable) {
| 0 | ||||||||||||||||||||||||||||||
1145 | Q_Q(QTextDocument); | - | ||||||||||||||||||||||||||||||
1146 | emit q->redoAvailable(available); | - | ||||||||||||||||||||||||||||||
1147 | wasRedoAvailable = available; | - | ||||||||||||||||||||||||||||||
1148 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1149 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1150 | - | |||||||||||||||||||||||||||||||
1151 | void QTextDocumentPrivate::enableUndoRedo(bool enable) | - | ||||||||||||||||||||||||||||||
1152 | { | - | ||||||||||||||||||||||||||||||
1153 | if (enable && maximumBlockCount > 0)
| 0 | ||||||||||||||||||||||||||||||
1154 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1155 | - | |||||||||||||||||||||||||||||||
1156 | if (!enable) {
| 0 | ||||||||||||||||||||||||||||||
1157 | undoState = 0; | - | ||||||||||||||||||||||||||||||
1158 | clearUndoRedoStacks(QTextDocument::RedoStack); | - | ||||||||||||||||||||||||||||||
1159 | emitUndoAvailable(false); | - | ||||||||||||||||||||||||||||||
1160 | emitRedoAvailable(false); | - | ||||||||||||||||||||||||||||||
1161 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1162 | modifiedState = modified ? -1 : undoState;
| 0 | ||||||||||||||||||||||||||||||
1163 | undoEnabled = enable; | - | ||||||||||||||||||||||||||||||
1164 | if (!undoEnabled)
| 0 | ||||||||||||||||||||||||||||||
1165 | compressPieceTable(); never executed: compressPieceTable(); | 0 | ||||||||||||||||||||||||||||||
1166 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1167 | - | |||||||||||||||||||||||||||||||
1168 | void QTextDocumentPrivate::joinPreviousEditBlock() | - | ||||||||||||||||||||||||||||||
1169 | { | - | ||||||||||||||||||||||||||||||
1170 | beginEditBlock(); | - | ||||||||||||||||||||||||||||||
1171 | - | |||||||||||||||||||||||||||||||
1172 | if (undoEnabled && undoState)
| 0 | ||||||||||||||||||||||||||||||
1173 | undoStack[undoState - 1].block_end = false; never executed: undoStack[undoState - 1].block_end = false; | 0 | ||||||||||||||||||||||||||||||
1174 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1175 | - | |||||||||||||||||||||||||||||||
1176 | void QTextDocumentPrivate::endEditBlock() | - | ||||||||||||||||||||||||||||||
1177 | { | - | ||||||||||||||||||||||||||||||
1178 | Q_ASSERT(editBlock > 0); | - | ||||||||||||||||||||||||||||||
1179 | if (--editBlock)
| 0 | ||||||||||||||||||||||||||||||
1180 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1181 | - | |||||||||||||||||||||||||||||||
1182 | if (undoEnabled && undoState > 0) {
| 0 | ||||||||||||||||||||||||||||||
1183 | const bool wasBlocking = !undoStack[undoState - 1].block_end; | - | ||||||||||||||||||||||||||||||
1184 | if (undoStack[undoState - 1].block_part) {
| 0 | ||||||||||||||||||||||||||||||
1185 | undoStack[undoState - 1].block_end = true; | - | ||||||||||||||||||||||||||||||
1186 | if (wasBlocking)
| 0 | ||||||||||||||||||||||||||||||
1187 | emit document()->undoCommandAdded(); never executed: document()->undoCommandAdded(); | 0 | ||||||||||||||||||||||||||||||
1188 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1189 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1190 | - | |||||||||||||||||||||||||||||||
1191 | editBlockCursorPosition = -1; | - | ||||||||||||||||||||||||||||||
1192 | - | |||||||||||||||||||||||||||||||
1193 | finishEdit(); | - | ||||||||||||||||||||||||||||||
1194 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1195 | - | |||||||||||||||||||||||||||||||
1196 | void QTextDocumentPrivate::finishEdit() | - | ||||||||||||||||||||||||||||||
1197 | { | - | ||||||||||||||||||||||||||||||
1198 | Q_Q(QTextDocument); | - | ||||||||||||||||||||||||||||||
1199 | - | |||||||||||||||||||||||||||||||
1200 | if (editBlock)
| 0 | ||||||||||||||||||||||||||||||
1201 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1202 | - | |||||||||||||||||||||||||||||||
1203 | if (framesDirty)
| 0 | ||||||||||||||||||||||||||||||
1204 | scan_frames(docChangeFrom, docChangeOldLength, docChangeLength); never executed: scan_frames(docChangeFrom, docChangeOldLength, docChangeLength); | 0 | ||||||||||||||||||||||||||||||
1205 | - | |||||||||||||||||||||||||||||||
1206 | if (lout && docChangeFrom >= 0) {
| 0 | ||||||||||||||||||||||||||||||
1207 | if (!inContentsChange) {
| 0 | ||||||||||||||||||||||||||||||
1208 | inContentsChange = true; | - | ||||||||||||||||||||||||||||||
1209 | emit q->contentsChange(docChangeFrom, docChangeOldLength, docChangeLength); | - | ||||||||||||||||||||||||||||||
1210 | inContentsChange = false; | - | ||||||||||||||||||||||||||||||
1211 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1212 | lout->documentChanged(docChangeFrom, docChangeOldLength, docChangeLength); | - | ||||||||||||||||||||||||||||||
1213 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1214 | - | |||||||||||||||||||||||||||||||
1215 | docChangeFrom = -1; | - | ||||||||||||||||||||||||||||||
1216 | - | |||||||||||||||||||||||||||||||
1217 | if (needsEnsureMaximumBlockCount) {
| 0 | ||||||||||||||||||||||||||||||
1218 | needsEnsureMaximumBlockCount = false; | - | ||||||||||||||||||||||||||||||
1219 | if (ensureMaximumBlockCount()) {
| 0 | ||||||||||||||||||||||||||||||
1220 | // if ensureMaximumBlockCount() returns true | - | ||||||||||||||||||||||||||||||
1221 | // it will have called endEditBlock() and | - | ||||||||||||||||||||||||||||||
1222 | // compressPieceTable() itself, so we return here | - | ||||||||||||||||||||||||||||||
1223 | // to prevent getting two contentsChanged emits | - | ||||||||||||||||||||||||||||||
1224 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1225 | } | - | ||||||||||||||||||||||||||||||
1226 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1227 | - | |||||||||||||||||||||||||||||||
1228 | QList<QTextCursor> changedCursors; | - | ||||||||||||||||||||||||||||||
1229 | foreach (QTextCursorPrivate *curs, cursors) { | - | ||||||||||||||||||||||||||||||
1230 | if (curs->changed) {
| 0 | ||||||||||||||||||||||||||||||
1231 | curs->changed = false; | - | ||||||||||||||||||||||||||||||
1232 | changedCursors.append(QTextCursor(curs)); | - | ||||||||||||||||||||||||||||||
1233 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1234 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1235 | foreach (const QTextCursor &cursor, changedCursors) | - | ||||||||||||||||||||||||||||||
1236 | emit q->cursorPositionChanged(cursor); never executed: q->cursorPositionChanged(cursor); | 0 | ||||||||||||||||||||||||||||||
1237 | - | |||||||||||||||||||||||||||||||
1238 | contentsChanged(); | - | ||||||||||||||||||||||||||||||
1239 | - | |||||||||||||||||||||||||||||||
1240 | if (blocks.numNodes() != lastBlockCount) {
| 0 | ||||||||||||||||||||||||||||||
1241 | lastBlockCount = blocks.numNodes(); | - | ||||||||||||||||||||||||||||||
1242 | emit q->blockCountChanged(lastBlockCount); | - | ||||||||||||||||||||||||||||||
1243 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1244 | - | |||||||||||||||||||||||||||||||
1245 | if (!undoEnabled && unreachableCharacterCount)
| 0 | ||||||||||||||||||||||||||||||
1246 | compressPieceTable(); never executed: compressPieceTable(); | 0 | ||||||||||||||||||||||||||||||
1247 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1248 | - | |||||||||||||||||||||||||||||||
1249 | void QTextDocumentPrivate::documentChange(int from, int length) | - | ||||||||||||||||||||||||||||||
1250 | { | - | ||||||||||||||||||||||||||||||
1251 | // qDebug("QTextDocumentPrivate::documentChange: from=%d,length=%d", from, length); | - | ||||||||||||||||||||||||||||||
1252 | if (docChangeFrom < 0) {
| 0 | ||||||||||||||||||||||||||||||
1253 | docChangeFrom = from; | - | ||||||||||||||||||||||||||||||
1254 | docChangeOldLength = length; | - | ||||||||||||||||||||||||||||||
1255 | docChangeLength = length; | - | ||||||||||||||||||||||||||||||
1256 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1257 | } | - | ||||||||||||||||||||||||||||||
1258 | int start = qMin(from, docChangeFrom); | - | ||||||||||||||||||||||||||||||
1259 | int end = qMax(from + length, docChangeFrom + docChangeLength); | - | ||||||||||||||||||||||||||||||
1260 | int diff = qMax(0, end - start - docChangeLength); | - | ||||||||||||||||||||||||||||||
1261 | docChangeFrom = start; | - | ||||||||||||||||||||||||||||||
1262 | docChangeOldLength += diff; | - | ||||||||||||||||||||||||||||||
1263 | docChangeLength += diff; | - | ||||||||||||||||||||||||||||||
1264 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1265 | - | |||||||||||||||||||||||||||||||
1266 | /* | - | ||||||||||||||||||||||||||||||
1267 | adjustDocumentChangesAndCursors is called whenever there is an insert or remove of characters. | - | ||||||||||||||||||||||||||||||
1268 | param from is the cursor position in the document | - | ||||||||||||||||||||||||||||||
1269 | param addedOrRemoved is the amount of characters added or removed. A negative number means characters are removed. | - | ||||||||||||||||||||||||||||||
1270 | - | |||||||||||||||||||||||||||||||
1271 | The function stores information to be emitted when finishEdit() is called. | - | ||||||||||||||||||||||||||||||
1272 | */ | - | ||||||||||||||||||||||||||||||
1273 | void QTextDocumentPrivate::adjustDocumentChangesAndCursors(int from, int addedOrRemoved, QTextUndoCommand::Operation op) | - | ||||||||||||||||||||||||||||||
1274 | { | - | ||||||||||||||||||||||||||||||
1275 | if (!editBlock)
| 0 | ||||||||||||||||||||||||||||||
1276 | ++revision; never executed: ++revision; | 0 | ||||||||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||||||||
1278 | if (blockCursorAdjustment) {
| 0 | ||||||||||||||||||||||||||||||
1279 | ; // postpone, will be called again from QTextDocumentPrivate::remove() | - | ||||||||||||||||||||||||||||||
1280 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1281 | foreach (QTextCursorPrivate *curs, cursors) { | - | ||||||||||||||||||||||||||||||
1282 | if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) {
| 0 | ||||||||||||||||||||||||||||||
1283 | curs->changed = true; | - | ||||||||||||||||||||||||||||||
1284 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1285 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1286 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1287 | - | |||||||||||||||||||||||||||||||
1288 | // qDebug("QTextDocumentPrivate::adjustDocumentChanges: from=%d,addedOrRemoved=%d", from, addedOrRemoved); | - | ||||||||||||||||||||||||||||||
1289 | if (docChangeFrom < 0) {
| 0 | ||||||||||||||||||||||||||||||
1290 | docChangeFrom = from; | - | ||||||||||||||||||||||||||||||
1291 | if (addedOrRemoved > 0) {
| 0 | ||||||||||||||||||||||||||||||
1292 | docChangeOldLength = 0; | - | ||||||||||||||||||||||||||||||
1293 | docChangeLength = addedOrRemoved; | - | ||||||||||||||||||||||||||||||
1294 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1295 | docChangeOldLength = -addedOrRemoved; | - | ||||||||||||||||||||||||||||||
1296 | docChangeLength = 0; | - | ||||||||||||||||||||||||||||||
1297 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1298 | // qDebug("adjustDocumentChanges:"); | - | ||||||||||||||||||||||||||||||
1299 | // qDebug(" -> %d %d %d", docChangeFrom, docChangeOldLength, docChangeLength); | - | ||||||||||||||||||||||||||||||
1300 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1301 | } | - | ||||||||||||||||||||||||||||||
1302 | - | |||||||||||||||||||||||||||||||
1303 | // have to merge the new change with the already existing one. | - | ||||||||||||||||||||||||||||||
1304 | int added = qMax(0, addedOrRemoved); | - | ||||||||||||||||||||||||||||||
1305 | int removed = qMax(0, -addedOrRemoved); | - | ||||||||||||||||||||||||||||||
1306 | - | |||||||||||||||||||||||||||||||
1307 | int diff = 0; | - | ||||||||||||||||||||||||||||||
1308 | if (from + removed < docChangeFrom)
| 0 | ||||||||||||||||||||||||||||||
1309 | diff = docChangeFrom - from - removed; never executed: diff = docChangeFrom - from - removed; | 0 | ||||||||||||||||||||||||||||||
1310 | else if (from > docChangeFrom + docChangeLength)
| 0 | ||||||||||||||||||||||||||||||
1311 | diff = from - (docChangeFrom + docChangeLength); never executed: diff = from - (docChangeFrom + docChangeLength); | 0 | ||||||||||||||||||||||||||||||
1312 | - | |||||||||||||||||||||||||||||||
1313 | int overlap_start = qMax(from, docChangeFrom); | - | ||||||||||||||||||||||||||||||
1314 | int overlap_end = qMin(from + removed, docChangeFrom + docChangeLength); | - | ||||||||||||||||||||||||||||||
1315 | int removedInside = qMax(0, overlap_end - overlap_start); | - | ||||||||||||||||||||||||||||||
1316 | removed -= removedInside; | - | ||||||||||||||||||||||||||||||
1317 | - | |||||||||||||||||||||||||||||||
1318 | // qDebug("adjustDocumentChanges: from=%d, addedOrRemoved=%d, diff=%d, removedInside=%d", from, addedOrRemoved, diff, removedInside); | - | ||||||||||||||||||||||||||||||
1319 | docChangeFrom = qMin(docChangeFrom, from); | - | ||||||||||||||||||||||||||||||
1320 | docChangeOldLength += removed + diff; | - | ||||||||||||||||||||||||||||||
1321 | docChangeLength += added - removedInside + diff; | - | ||||||||||||||||||||||||||||||
1322 | // qDebug(" -> %d %d %d", docChangeFrom, docChangeOldLength, docChangeLength); | - | ||||||||||||||||||||||||||||||
1323 | - | |||||||||||||||||||||||||||||||
1324 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1325 | - | |||||||||||||||||||||||||||||||
1326 | - | |||||||||||||||||||||||||||||||
1327 | QString QTextDocumentPrivate::plainText() const | - | ||||||||||||||||||||||||||||||
1328 | { | - | ||||||||||||||||||||||||||||||
1329 | QString result; | - | ||||||||||||||||||||||||||||||
1330 | result.resize(length()); | - | ||||||||||||||||||||||||||||||
1331 | const QChar *text_unicode = text.unicode(); | - | ||||||||||||||||||||||||||||||
1332 | QChar *data = result.data(); | - | ||||||||||||||||||||||||||||||
1333 | for (QTextDocumentPrivate::FragmentIterator it = begin(); it != end(); ++it) {
| 0 | ||||||||||||||||||||||||||||||
1334 | const QTextFragmentData *f = *it; | - | ||||||||||||||||||||||||||||||
1335 | ::memcpy(data, text_unicode + f->stringPosition, f->size_array[0] * sizeof(QChar)); | - | ||||||||||||||||||||||||||||||
1336 | data += f->size_array[0]; | - | ||||||||||||||||||||||||||||||
1337 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1338 | // remove trailing block separator | - | ||||||||||||||||||||||||||||||
1339 | result.chop(1); | - | ||||||||||||||||||||||||||||||
1340 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||||||||
1341 | } | - | ||||||||||||||||||||||||||||||
1342 | - | |||||||||||||||||||||||||||||||
1343 | int QTextDocumentPrivate::blockCharFormatIndex(int node) const | - | ||||||||||||||||||||||||||||||
1344 | { | - | ||||||||||||||||||||||||||||||
1345 | int pos = blocks.position(node); | - | ||||||||||||||||||||||||||||||
1346 | if (pos == 0)
| 0 | ||||||||||||||||||||||||||||||
1347 | return initialBlockCharFormatIndex; never executed: return initialBlockCharFormatIndex; | 0 | ||||||||||||||||||||||||||||||
1348 | - | |||||||||||||||||||||||||||||||
1349 | return fragments.find(pos - 1)->format; never executed: return fragments.find(pos - 1)->format; | 0 | ||||||||||||||||||||||||||||||
1350 | } | - | ||||||||||||||||||||||||||||||
1351 | - | |||||||||||||||||||||||||||||||
1352 | int QTextDocumentPrivate::nextCursorPosition(int position, QTextLayout::CursorMode mode) const | - | ||||||||||||||||||||||||||||||
1353 | { | - | ||||||||||||||||||||||||||||||
1354 | if (position == length()-1)
| 0 | ||||||||||||||||||||||||||||||
1355 | return position; never executed: return position; | 0 | ||||||||||||||||||||||||||||||
1356 | - | |||||||||||||||||||||||||||||||
1357 | QTextBlock it = blocksFind(position); | - | ||||||||||||||||||||||||||||||
1358 | int start = it.position(); | - | ||||||||||||||||||||||||||||||
1359 | int end = start + it.length() - 1; | - | ||||||||||||||||||||||||||||||
1360 | if (position == end)
| 0 | ||||||||||||||||||||||||||||||
1361 | return end + 1; never executed: return end + 1; | 0 | ||||||||||||||||||||||||||||||
1362 | - | |||||||||||||||||||||||||||||||
1363 | return it.layout()->nextCursorPosition(position-start, mode) + start; never executed: return it.layout()->nextCursorPosition(position-start, mode) + start; | 0 | ||||||||||||||||||||||||||||||
1364 | } | - | ||||||||||||||||||||||||||||||
1365 | - | |||||||||||||||||||||||||||||||
1366 | int QTextDocumentPrivate::previousCursorPosition(int position, QTextLayout::CursorMode mode) const | - | ||||||||||||||||||||||||||||||
1367 | { | - | ||||||||||||||||||||||||||||||
1368 | if (position == 0)
| 0 | ||||||||||||||||||||||||||||||
1369 | return position; never executed: return position; | 0 | ||||||||||||||||||||||||||||||
1370 | - | |||||||||||||||||||||||||||||||
1371 | QTextBlock it = blocksFind(position); | - | ||||||||||||||||||||||||||||||
1372 | int start = it.position(); | - | ||||||||||||||||||||||||||||||
1373 | if (position == start)
| 0 | ||||||||||||||||||||||||||||||
1374 | return start - 1; never executed: return start - 1; | 0 | ||||||||||||||||||||||||||||||
1375 | - | |||||||||||||||||||||||||||||||
1376 | return it.layout()->previousCursorPosition(position-start, mode) + start; never executed: return it.layout()->previousCursorPosition(position-start, mode) + start; | 0 | ||||||||||||||||||||||||||||||
1377 | } | - | ||||||||||||||||||||||||||||||
1378 | - | |||||||||||||||||||||||||||||||
1379 | int QTextDocumentPrivate::leftCursorPosition(int position) const | - | ||||||||||||||||||||||||||||||
1380 | { | - | ||||||||||||||||||||||||||||||
1381 | QTextBlock it = blocksFind(position); | - | ||||||||||||||||||||||||||||||
1382 | int start = it.position(); | - | ||||||||||||||||||||||||||||||
1383 | return it.layout()->leftCursorPosition(position-start) + start; never executed: return it.layout()->leftCursorPosition(position-start) + start; | 0 | ||||||||||||||||||||||||||||||
1384 | } | - | ||||||||||||||||||||||||||||||
1385 | - | |||||||||||||||||||||||||||||||
1386 | int QTextDocumentPrivate::rightCursorPosition(int position) const | - | ||||||||||||||||||||||||||||||
1387 | { | - | ||||||||||||||||||||||||||||||
1388 | QTextBlock it = blocksFind(position); | - | ||||||||||||||||||||||||||||||
1389 | int start = it.position(); | - | ||||||||||||||||||||||||||||||
1390 | return it.layout()->rightCursorPosition(position-start) + start; never executed: return it.layout()->rightCursorPosition(position-start) + start; | 0 | ||||||||||||||||||||||||||||||
1391 | } | - | ||||||||||||||||||||||||||||||
1392 | - | |||||||||||||||||||||||||||||||
1393 | void QTextDocumentPrivate::changeObjectFormat(QTextObject *obj, int format) | - | ||||||||||||||||||||||||||||||
1394 | { | - | ||||||||||||||||||||||||||||||
1395 | beginEditBlock(); | - | ||||||||||||||||||||||||||||||
1396 | int objectIndex = obj->objectIndex(); | - | ||||||||||||||||||||||||||||||
1397 | int oldFormatIndex = formats.objectFormatIndex(objectIndex); | - | ||||||||||||||||||||||||||||||
1398 | formats.setObjectFormatIndex(objectIndex, format); | - | ||||||||||||||||||||||||||||||
1399 | - | |||||||||||||||||||||||||||||||
1400 | QTextBlockGroup *b = qobject_cast<QTextBlockGroup *>(obj); | - | ||||||||||||||||||||||||||||||
1401 | if (b) {
| 0 | ||||||||||||||||||||||||||||||
1402 | b->d_func()->markBlocksDirty(); | - | ||||||||||||||||||||||||||||||
1403 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1404 | QTextFrame *f = qobject_cast<QTextFrame *>(obj); | - | ||||||||||||||||||||||||||||||
1405 | if (f)
| 0 | ||||||||||||||||||||||||||||||
1406 | documentChange(f->firstPosition(), f->lastPosition() - f->firstPosition()); never executed: documentChange(f->firstPosition(), f->lastPosition() - f->firstPosition()); | 0 | ||||||||||||||||||||||||||||||
1407 | - | |||||||||||||||||||||||||||||||
1408 | QT_INIT_TEXTUNDOCOMMAND(c, QTextUndoCommand::GroupFormatChange, (editBlock != 0), QTextUndoCommand::MoveCursor, oldFormatIndex, | - | ||||||||||||||||||||||||||||||
1409 | 0, 0, obj->d_func()->objectIndex, 0); | - | ||||||||||||||||||||||||||||||
1410 | appendUndoItem(c); | - | ||||||||||||||||||||||||||||||
1411 | - | |||||||||||||||||||||||||||||||
1412 | endEditBlock(); | - | ||||||||||||||||||||||||||||||
1413 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1414 | - | |||||||||||||||||||||||||||||||
1415 | static QTextFrame *findChildFrame(QTextFrame *f, int pos) | - | ||||||||||||||||||||||||||||||
1416 | { | - | ||||||||||||||||||||||||||||||
1417 | /* Binary search for frame at pos */ | - | ||||||||||||||||||||||||||||||
1418 | const QList<QTextFrame *> children = f->childFrames(); | - | ||||||||||||||||||||||||||||||
1419 | int first = 0; | - | ||||||||||||||||||||||||||||||
1420 | int last = children.size() - 1; | - | ||||||||||||||||||||||||||||||
1421 | while (first <= last) {
| 0 | ||||||||||||||||||||||||||||||
1422 | int mid = (first + last) / 2; | - | ||||||||||||||||||||||||||||||
1423 | QTextFrame *c = children.at(mid); | - | ||||||||||||||||||||||||||||||
1424 | if (pos > c->lastPosition())
| 0 | ||||||||||||||||||||||||||||||
1425 | first = mid + 1; never executed: first = mid + 1; | 0 | ||||||||||||||||||||||||||||||
1426 | else if (pos < c->firstPosition())
| 0 | ||||||||||||||||||||||||||||||
1427 | last = mid - 1; never executed: last = mid - 1; | 0 | ||||||||||||||||||||||||||||||
1428 | else | - | ||||||||||||||||||||||||||||||
1429 | return c; never executed: return c; | 0 | ||||||||||||||||||||||||||||||
1430 | } | - | ||||||||||||||||||||||||||||||
1431 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
1432 | } | - | ||||||||||||||||||||||||||||||
1433 | - | |||||||||||||||||||||||||||||||
1434 | QTextFrame *QTextDocumentPrivate::rootFrame() const | - | ||||||||||||||||||||||||||||||
1435 | { | - | ||||||||||||||||||||||||||||||
1436 | if (!rtFrame) {
| 0 | ||||||||||||||||||||||||||||||
1437 | QTextFrameFormat defaultRootFrameFormat; | - | ||||||||||||||||||||||||||||||
1438 | defaultRootFrameFormat.setMargin(documentMargin); | - | ||||||||||||||||||||||||||||||
1439 | rtFrame = qobject_cast<QTextFrame *>(const_cast<QTextDocumentPrivate *>(this)->createObject(defaultRootFrameFormat)); | - | ||||||||||||||||||||||||||||||
1440 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1441 | return rtFrame; never executed: return rtFrame; | 0 | ||||||||||||||||||||||||||||||
1442 | } | - | ||||||||||||||||||||||||||||||
1443 | - | |||||||||||||||||||||||||||||||
1444 | QTextFrame *QTextDocumentPrivate::frameAt(int pos) const | - | ||||||||||||||||||||||||||||||
1445 | { | - | ||||||||||||||||||||||||||||||
1446 | QTextFrame *f = rootFrame(); | - | ||||||||||||||||||||||||||||||
1447 | - | |||||||||||||||||||||||||||||||
1448 | while (1) { | - | ||||||||||||||||||||||||||||||
1449 | QTextFrame *c = findChildFrame(f, pos); | - | ||||||||||||||||||||||||||||||
1450 | if (!c)
| 0 | ||||||||||||||||||||||||||||||
1451 | return f; never executed: return f; | 0 | ||||||||||||||||||||||||||||||
1452 | f = c; | - | ||||||||||||||||||||||||||||||
1453 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1454 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1455 | - | |||||||||||||||||||||||||||||||
1456 | void QTextDocumentPrivate::clearFrame(QTextFrame *f) | - | ||||||||||||||||||||||||||||||
1457 | { | - | ||||||||||||||||||||||||||||||
1458 | for (int i = 0; i < f->d_func()->childFrames.count(); ++i)
| 0 | ||||||||||||||||||||||||||||||
1459 | clearFrame(f->d_func()->childFrames.at(i)); never executed: clearFrame(f->d_func()->childFrames.at(i)); | 0 | ||||||||||||||||||||||||||||||
1460 | f->d_func()->childFrames.clear(); | - | ||||||||||||||||||||||||||||||
1461 | f->d_func()->parentFrame = 0; | - | ||||||||||||||||||||||||||||||
1462 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1463 | - | |||||||||||||||||||||||||||||||
1464 | void QTextDocumentPrivate::scan_frames(int pos, int charsRemoved, int charsAdded) | - | ||||||||||||||||||||||||||||||
1465 | { | - | ||||||||||||||||||||||||||||||
1466 | // ###### optimize | - | ||||||||||||||||||||||||||||||
1467 | Q_UNUSED(pos); | - | ||||||||||||||||||||||||||||||
1468 | Q_UNUSED(charsRemoved); | - | ||||||||||||||||||||||||||||||
1469 | Q_UNUSED(charsAdded); | - | ||||||||||||||||||||||||||||||
1470 | - | |||||||||||||||||||||||||||||||
1471 | QTextFrame *f = rootFrame(); | - | ||||||||||||||||||||||||||||||
1472 | clearFrame(f); | - | ||||||||||||||||||||||||||||||
1473 | - | |||||||||||||||||||||||||||||||
1474 | for (FragmentIterator it = begin(); it != end(); ++it) {
| 0 | ||||||||||||||||||||||||||||||
1475 | // QTextFormat fmt = formats.format(it->format); | - | ||||||||||||||||||||||||||||||
1476 | QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(it->format)); | - | ||||||||||||||||||||||||||||||
1477 | if (!frame)
| 0 | ||||||||||||||||||||||||||||||
1478 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
1479 | - | |||||||||||||||||||||||||||||||
1480 | Q_ASSERT(it.size() == 1); | - | ||||||||||||||||||||||||||||||
1481 | QChar ch = text.at(it->stringPosition); | - | ||||||||||||||||||||||||||||||
1482 | - | |||||||||||||||||||||||||||||||
1483 | if (ch == QTextBeginningOfFrame) {
| 0 | ||||||||||||||||||||||||||||||
1484 | if (f != frame) {
| 0 | ||||||||||||||||||||||||||||||
1485 | // f == frame happens for tables | - | ||||||||||||||||||||||||||||||
1486 | Q_ASSERT(frame->d_func()->fragment_start == it.n || frame->d_func()->fragment_start == 0); | - | ||||||||||||||||||||||||||||||
1487 | frame->d_func()->parentFrame = f; | - | ||||||||||||||||||||||||||||||
1488 | f->d_func()->childFrames.append(frame); | - | ||||||||||||||||||||||||||||||
1489 | f = frame; | - | ||||||||||||||||||||||||||||||
1490 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1491 | } else if (ch == QTextEndOfFrame) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
1492 | Q_ASSERT(f == frame); | - | ||||||||||||||||||||||||||||||
1493 | Q_ASSERT(frame->d_func()->fragment_end == it.n || frame->d_func()->fragment_end == 0); | - | ||||||||||||||||||||||||||||||
1494 | f = frame->d_func()->parentFrame; | - | ||||||||||||||||||||||||||||||
1495 | } else if (ch == QChar::ObjectReplacementCharacter) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
1496 | Q_ASSERT(f != frame); | - | ||||||||||||||||||||||||||||||
1497 | Q_ASSERT(frame->d_func()->fragment_start == it.n || frame->d_func()->fragment_start == 0); | - | ||||||||||||||||||||||||||||||
1498 | Q_ASSERT(frame->d_func()->fragment_end == it.n || frame->d_func()->fragment_end == 0); | - | ||||||||||||||||||||||||||||||
1499 | frame->d_func()->parentFrame = f; | - | ||||||||||||||||||||||||||||||
1500 | f->d_func()->childFrames.append(frame); | - | ||||||||||||||||||||||||||||||
1501 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1502 | Q_ASSERT(false); | - | ||||||||||||||||||||||||||||||
1503 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1504 | } | - | ||||||||||||||||||||||||||||||
1505 | Q_ASSERT(f == rtFrame); | - | ||||||||||||||||||||||||||||||
1506 | framesDirty = false; | - | ||||||||||||||||||||||||||||||
1507 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1508 | - | |||||||||||||||||||||||||||||||
1509 | void QTextDocumentPrivate::insert_frame(QTextFrame *f) | - | ||||||||||||||||||||||||||||||
1510 | { | - | ||||||||||||||||||||||||||||||
1511 | int start = f->firstPosition(); | - | ||||||||||||||||||||||||||||||
1512 | int end = f->lastPosition(); | - | ||||||||||||||||||||||||||||||
1513 | QTextFrame *parent = frameAt(start-1); | - | ||||||||||||||||||||||||||||||
1514 | Q_ASSERT(parent == frameAt(end+1)); | - | ||||||||||||||||||||||||||||||
1515 | - | |||||||||||||||||||||||||||||||
1516 | if (start != end) {
| 0 | ||||||||||||||||||||||||||||||
1517 | // iterator over the parent and move all children contained in my frame to myself | - | ||||||||||||||||||||||||||||||
1518 | for (int i = 0; i < parent->d_func()->childFrames.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
1519 | QTextFrame *c = parent->d_func()->childFrames.at(i); | - | ||||||||||||||||||||||||||||||
1520 | if (start < c->firstPosition() && end > c->lastPosition()) {
| 0 | ||||||||||||||||||||||||||||||
1521 | parent->d_func()->childFrames.removeAt(i); | - | ||||||||||||||||||||||||||||||
1522 | f->d_func()->childFrames.append(c); | - | ||||||||||||||||||||||||||||||
1523 | c->d_func()->parentFrame = f; | - | ||||||||||||||||||||||||||||||
1524 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1525 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1526 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1527 | // insert at the correct position | - | ||||||||||||||||||||||||||||||
1528 | int i = 0; | - | ||||||||||||||||||||||||||||||
1529 | for (; i < parent->d_func()->childFrames.size(); ++i) {
| 0 | ||||||||||||||||||||||||||||||
1530 | QTextFrame *c = parent->d_func()->childFrames.at(i); | - | ||||||||||||||||||||||||||||||
1531 | if (c->firstPosition() > end)
| 0 | ||||||||||||||||||||||||||||||
1532 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
1533 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1534 | parent->d_func()->childFrames.insert(i, f); | - | ||||||||||||||||||||||||||||||
1535 | f->d_func()->parentFrame = parent; | - | ||||||||||||||||||||||||||||||
1536 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1537 | - | |||||||||||||||||||||||||||||||
1538 | QTextFrame *QTextDocumentPrivate::insertFrame(int start, int end, const QTextFrameFormat &format) | - | ||||||||||||||||||||||||||||||
1539 | { | - | ||||||||||||||||||||||||||||||
1540 | Q_ASSERT(start >= 0 && start < length()); | - | ||||||||||||||||||||||||||||||
1541 | Q_ASSERT(end >= 0 && end < length()); | - | ||||||||||||||||||||||||||||||
1542 | Q_ASSERT(start <= end || end == -1); | - | ||||||||||||||||||||||||||||||
1543 | - | |||||||||||||||||||||||||||||||
1544 | if (start != end && frameAt(start) != frameAt(end))
| 0 | ||||||||||||||||||||||||||||||
1545 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
1546 | - | |||||||||||||||||||||||||||||||
1547 | beginEditBlock(); | - | ||||||||||||||||||||||||||||||
1548 | - | |||||||||||||||||||||||||||||||
1549 | QTextFrame *frame = qobject_cast<QTextFrame *>(createObject(format)); | - | ||||||||||||||||||||||||||||||
1550 | Q_ASSERT(frame); | - | ||||||||||||||||||||||||||||||
1551 | - | |||||||||||||||||||||||||||||||
1552 | // #### using the default block and char format below might be wrong | - | ||||||||||||||||||||||||||||||
1553 | int idx = formats.indexForFormat(QTextBlockFormat()); | - | ||||||||||||||||||||||||||||||
1554 | QTextCharFormat cfmt; | - | ||||||||||||||||||||||||||||||
1555 | cfmt.setObjectIndex(frame->objectIndex()); | - | ||||||||||||||||||||||||||||||
1556 | int charIdx = formats.indexForFormat(cfmt); | - | ||||||||||||||||||||||||||||||
1557 | - | |||||||||||||||||||||||||||||||
1558 | insertBlock(QTextBeginningOfFrame, start, idx, charIdx, QTextUndoCommand::MoveCursor); | - | ||||||||||||||||||||||||||||||
1559 | insertBlock(QTextEndOfFrame, ++end, idx, charIdx, QTextUndoCommand::KeepCursor); | - | ||||||||||||||||||||||||||||||
1560 | - | |||||||||||||||||||||||||||||||
1561 | frame->d_func()->fragment_start = find(start).n; | - | ||||||||||||||||||||||||||||||
1562 | frame->d_func()->fragment_end = find(end).n; | - | ||||||||||||||||||||||||||||||
1563 | - | |||||||||||||||||||||||||||||||
1564 | insert_frame(frame); | - | ||||||||||||||||||||||||||||||
1565 | - | |||||||||||||||||||||||||||||||
1566 | endEditBlock(); | - | ||||||||||||||||||||||||||||||
1567 | - | |||||||||||||||||||||||||||||||
1568 | return frame; never executed: return frame; | 0 | ||||||||||||||||||||||||||||||
1569 | } | - | ||||||||||||||||||||||||||||||
1570 | - | |||||||||||||||||||||||||||||||
1571 | void QTextDocumentPrivate::removeFrame(QTextFrame *frame) | - | ||||||||||||||||||||||||||||||
1572 | { | - | ||||||||||||||||||||||||||||||
1573 | QTextFrame *parent = frame->d_func()->parentFrame; | - | ||||||||||||||||||||||||||||||
1574 | if (!parent)
| 0 | ||||||||||||||||||||||||||||||
1575 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1576 | - | |||||||||||||||||||||||||||||||
1577 | int start = frame->firstPosition(); | - | ||||||||||||||||||||||||||||||
1578 | int end = frame->lastPosition(); | - | ||||||||||||||||||||||||||||||
1579 | Q_ASSERT(end >= start); | - | ||||||||||||||||||||||||||||||
1580 | - | |||||||||||||||||||||||||||||||
1581 | beginEditBlock(); | - | ||||||||||||||||||||||||||||||
1582 | - | |||||||||||||||||||||||||||||||
1583 | // remove already removes the frames from the tree | - | ||||||||||||||||||||||||||||||
1584 | remove(end, 1); | - | ||||||||||||||||||||||||||||||
1585 | remove(start-1, 1); | - | ||||||||||||||||||||||||||||||
1586 | - | |||||||||||||||||||||||||||||||
1587 | endEditBlock(); | - | ||||||||||||||||||||||||||||||
1588 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1589 | - | |||||||||||||||||||||||||||||||
1590 | QTextObject *QTextDocumentPrivate::objectForIndex(int objectIndex) const | - | ||||||||||||||||||||||||||||||
1591 | { | - | ||||||||||||||||||||||||||||||
1592 | if (objectIndex < 0)
| 0 | ||||||||||||||||||||||||||||||
1593 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
1594 | - | |||||||||||||||||||||||||||||||
1595 | QTextObject *object = objects.value(objectIndex, 0); | - | ||||||||||||||||||||||||||||||
1596 | if (!object) {
| 0 | ||||||||||||||||||||||||||||||
1597 | QTextDocumentPrivate *that = const_cast<QTextDocumentPrivate *>(this); | - | ||||||||||||||||||||||||||||||
1598 | QTextFormat fmt = formats.objectFormat(objectIndex); | - | ||||||||||||||||||||||||||||||
1599 | object = that->createObject(fmt, objectIndex); | - | ||||||||||||||||||||||||||||||
1600 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1601 | return object; never executed: return object; | 0 | ||||||||||||||||||||||||||||||
1602 | } | - | ||||||||||||||||||||||||||||||
1603 | - | |||||||||||||||||||||||||||||||
1604 | QTextObject *QTextDocumentPrivate::objectForFormat(int formatIndex) const | - | ||||||||||||||||||||||||||||||
1605 | { | - | ||||||||||||||||||||||||||||||
1606 | int objectIndex = formats.format(formatIndex).objectIndex(); | - | ||||||||||||||||||||||||||||||
1607 | return objectForIndex(objectIndex); never executed: return objectForIndex(objectIndex); | 0 | ||||||||||||||||||||||||||||||
1608 | } | - | ||||||||||||||||||||||||||||||
1609 | - | |||||||||||||||||||||||||||||||
1610 | QTextObject *QTextDocumentPrivate::objectForFormat(const QTextFormat &f) const | - | ||||||||||||||||||||||||||||||
1611 | { | - | ||||||||||||||||||||||||||||||
1612 | return objectForIndex(f.objectIndex()); never executed: return objectForIndex(f.objectIndex()); | 0 | ||||||||||||||||||||||||||||||
1613 | } | - | ||||||||||||||||||||||||||||||
1614 | - | |||||||||||||||||||||||||||||||
1615 | QTextObject *QTextDocumentPrivate::createObject(const QTextFormat &f, int objectIndex) | - | ||||||||||||||||||||||||||||||
1616 | { | - | ||||||||||||||||||||||||||||||
1617 | QTextObject *obj = document()->createObject(f); | - | ||||||||||||||||||||||||||||||
1618 | - | |||||||||||||||||||||||||||||||
1619 | if (obj) {
| 0 | ||||||||||||||||||||||||||||||
1620 | obj->d_func()->objectIndex = objectIndex == -1 ? formats.createObjectIndex(f) : objectIndex;
| 0 | ||||||||||||||||||||||||||||||
1621 | objects[obj->d_func()->objectIndex] = obj; | - | ||||||||||||||||||||||||||||||
1622 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1623 | - | |||||||||||||||||||||||||||||||
1624 | return obj; never executed: return obj; | 0 | ||||||||||||||||||||||||||||||
1625 | } | - | ||||||||||||||||||||||||||||||
1626 | - | |||||||||||||||||||||||||||||||
1627 | void QTextDocumentPrivate::deleteObject(QTextObject *object) | - | ||||||||||||||||||||||||||||||
1628 | { | - | ||||||||||||||||||||||||||||||
1629 | const int objIdx = object->d_func()->objectIndex; | - | ||||||||||||||||||||||||||||||
1630 | objects.remove(objIdx); | - | ||||||||||||||||||||||||||||||
1631 | delete object; | - | ||||||||||||||||||||||||||||||
1632 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1633 | - | |||||||||||||||||||||||||||||||
1634 | void QTextDocumentPrivate::contentsChanged() | - | ||||||||||||||||||||||||||||||
1635 | { | - | ||||||||||||||||||||||||||||||
1636 | Q_Q(QTextDocument); | - | ||||||||||||||||||||||||||||||
1637 | if (editBlock)
| 0 | ||||||||||||||||||||||||||||||
1638 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1639 | - | |||||||||||||||||||||||||||||||
1640 | bool m = undoEnabled ? (modifiedState != undoState) : true;
| 0 | ||||||||||||||||||||||||||||||
1641 | if (modified != m) {
| 0 | ||||||||||||||||||||||||||||||
1642 | modified = m; | - | ||||||||||||||||||||||||||||||
1643 | emit q->modificationChanged(modified); | - | ||||||||||||||||||||||||||||||
1644 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1645 | - | |||||||||||||||||||||||||||||||
1646 | emit q->contentsChanged(); | - | ||||||||||||||||||||||||||||||
1647 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1648 | - | |||||||||||||||||||||||||||||||
1649 | void QTextDocumentPrivate::compressPieceTable() | - | ||||||||||||||||||||||||||||||
1650 | { | - | ||||||||||||||||||||||||||||||
1651 | if (undoEnabled)
| 0 | ||||||||||||||||||||||||||||||
1652 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1653 | - | |||||||||||||||||||||||||||||||
1654 | const uint garbageCollectionThreshold = 96 * 1024; // bytes | - | ||||||||||||||||||||||||||||||
1655 | - | |||||||||||||||||||||||||||||||
1656 | //qDebug() << "unreachable bytes:" << unreachableCharacterCount * sizeof(QChar) << " -- limit" << garbageCollectionThreshold << "text size =" << text.size() << "capacity:" << text.capacity(); | - | ||||||||||||||||||||||||||||||
1657 | - | |||||||||||||||||||||||||||||||
1658 | bool compressTable = unreachableCharacterCount * sizeof(QChar) > garbageCollectionThreshold
| 0 | ||||||||||||||||||||||||||||||
1659 | && text.size() >= text.capacity() * 0.9;
| 0 | ||||||||||||||||||||||||||||||
1660 | if (!compressTable)
| 0 | ||||||||||||||||||||||||||||||
1661 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1662 | - | |||||||||||||||||||||||||||||||
1663 | QString newText; | - | ||||||||||||||||||||||||||||||
1664 | newText.resize(text.size()); | - | ||||||||||||||||||||||||||||||
1665 | QChar *newTextPtr = newText.data(); | - | ||||||||||||||||||||||||||||||
1666 | int newLen = 0; | - | ||||||||||||||||||||||||||||||
1667 | - | |||||||||||||||||||||||||||||||
1668 | for (FragmentMap::Iterator it = fragments.begin(); !it.atEnd(); ++it) {
| 0 | ||||||||||||||||||||||||||||||
1669 | memcpy(newTextPtr, text.constData() + it->stringPosition, it->size_array[0] * sizeof(QChar)); | - | ||||||||||||||||||||||||||||||
1670 | it->stringPosition = newLen; | - | ||||||||||||||||||||||||||||||
1671 | newTextPtr += it->size_array[0]; | - | ||||||||||||||||||||||||||||||
1672 | newLen += it->size_array[0]; | - | ||||||||||||||||||||||||||||||
1673 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1674 | - | |||||||||||||||||||||||||||||||
1675 | newText.resize(newLen); | - | ||||||||||||||||||||||||||||||
1676 | newText.squeeze(); | - | ||||||||||||||||||||||||||||||
1677 | //qDebug() << "removed" << text.size() - newText.size() << "characters"; | - | ||||||||||||||||||||||||||||||
1678 | text = newText; | - | ||||||||||||||||||||||||||||||
1679 | unreachableCharacterCount = 0; | - | ||||||||||||||||||||||||||||||
1680 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1681 | - | |||||||||||||||||||||||||||||||
1682 | void QTextDocumentPrivate::setModified(bool m) | - | ||||||||||||||||||||||||||||||
1683 | { | - | ||||||||||||||||||||||||||||||
1684 | Q_Q(QTextDocument); | - | ||||||||||||||||||||||||||||||
1685 | if (m == modified)
| 0 | ||||||||||||||||||||||||||||||
1686 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
1687 | - | |||||||||||||||||||||||||||||||
1688 | modified = m; | - | ||||||||||||||||||||||||||||||
1689 | if (!modified)
| 0 | ||||||||||||||||||||||||||||||
1690 | modifiedState = undoState; never executed: modifiedState = undoState; | 0 | ||||||||||||||||||||||||||||||
1691 | else | - | ||||||||||||||||||||||||||||||
1692 | modifiedState = -1; never executed: modifiedState = -1; | 0 | ||||||||||||||||||||||||||||||
1693 | - | |||||||||||||||||||||||||||||||
1694 | emit q->modificationChanged(modified); | - | ||||||||||||||||||||||||||||||
1695 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1696 | - | |||||||||||||||||||||||||||||||
1697 | bool QTextDocumentPrivate::ensureMaximumBlockCount() | - | ||||||||||||||||||||||||||||||
1698 | { | - | ||||||||||||||||||||||||||||||
1699 | if (maximumBlockCount <= 0)
| 0 | ||||||||||||||||||||||||||||||
1700 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
1701 | if (blocks.numNodes() <= maximumBlockCount)
| 0 | ||||||||||||||||||||||||||||||
1702 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
1703 | - | |||||||||||||||||||||||||||||||
1704 | beginEditBlock(); | - | ||||||||||||||||||||||||||||||
1705 | - | |||||||||||||||||||||||||||||||
1706 | const int blocksToRemove = blocks.numNodes() - maximumBlockCount; | - | ||||||||||||||||||||||||||||||
1707 | QTextCursor cursor(this, 0); | - | ||||||||||||||||||||||||||||||
1708 | cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor, blocksToRemove); | - | ||||||||||||||||||||||||||||||
1709 | - | |||||||||||||||||||||||||||||||
1710 | unreachableCharacterCount += cursor.selectionEnd() - cursor.selectionStart(); | - | ||||||||||||||||||||||||||||||
1711 | - | |||||||||||||||||||||||||||||||
1712 | // preserve the char format of the paragraph that is to become the new first one | - | ||||||||||||||||||||||||||||||
1713 | QTextCharFormat charFmt = cursor.blockCharFormat(); | - | ||||||||||||||||||||||||||||||
1714 | cursor.removeSelectedText(); | - | ||||||||||||||||||||||||||||||
1715 | cursor.setBlockCharFormat(charFmt); | - | ||||||||||||||||||||||||||||||
1716 | - | |||||||||||||||||||||||||||||||
1717 | endEditBlock(); | - | ||||||||||||||||||||||||||||||
1718 | - | |||||||||||||||||||||||||||||||
1719 | compressPieceTable(); | - | ||||||||||||||||||||||||||||||
1720 | - | |||||||||||||||||||||||||||||||
1721 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||||||||
1722 | } | - | ||||||||||||||||||||||||||||||
1723 | - | |||||||||||||||||||||||||||||||
1724 | /// This method is called from QTextTable when it is about to remove a table-cell to allow cursors to update their selection. | - | ||||||||||||||||||||||||||||||
1725 | void QTextDocumentPrivate::aboutToRemoveCell(int from, int to) | - | ||||||||||||||||||||||||||||||
1726 | { | - | ||||||||||||||||||||||||||||||
1727 | Q_ASSERT(from <= to); | - | ||||||||||||||||||||||||||||||
1728 | foreach (QTextCursorPrivate *curs, cursors) | - | ||||||||||||||||||||||||||||||
1729 | curs->aboutToRemoveCell(from, to); never executed: curs->aboutToRemoveCell(from, to); | 0 | ||||||||||||||||||||||||||||||
1730 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
1731 | - | |||||||||||||||||||||||||||||||
1732 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |