qtextdocument_p.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextdocument_p.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6void QTextBlockData::invalidate() const-
7{-
8 if (layout)-
9 layout->engine()->invalidate();-
10}-
11-
12static bool isValidBlockSeparator(QChar ch)-
13{-
14 return ch == QChar::ParagraphSeparator-
15 || ch == QChar(0xfdd0)-
16 || ch == QChar(0xfdd1);-
17}-
18-
19static bool noBlockInString(const QString &str)-
20{-
21 return !str.contains(QChar::ParagraphSeparator)-
22 && !str.contains(QChar(0xfdd0))-
23 && !str.contains(QChar(0xfdd1));-
24}-
25-
26bool QTextUndoCommand::tryMerge(const QTextUndoCommand &other)-
27{-
28 if (command != other.command)-
29 return false;-
30-
31 if (command == Inserted-
32 && (pos + length == other.pos)-
33 && (strPos + length == other.strPos)-
34 && format == other.format) {-
35-
36 length += other.length;-
37 return true;-
38 }-
39-
40-
41 if (command == Removed-
42 && pos == other.pos-
43 && (strPos + length == other.strPos)-
44 && format == other.format) {-
45-
46 length += other.length;-
47 return true;-
48 }-
49-
50-
51 if (command == Removed-
52 && (other.pos + other.length == pos)-
53 && (other.strPos + other.length == strPos)-
54 && (format == other.format)) {-
55-
56 int l = length;-
57 (*this) = other;-
58-
59 length += l;-
60 return true;-
61 }-
62-
63 return false;-
64}-
65-
66QTextDocumentPrivate::QTextDocumentPrivate()-
67 : wasUndoAvailable(false),-
68 wasRedoAvailable(false),-
69 docChangeOldLength(0),-
70 docChangeLength(0),-
71 framesDirty(true),-
72 rtFrame(0),-
73 initialBlockCharFormatIndex(-1)-
74{-
75 editBlock = 0;-
76 editBlockCursorPosition = -1;-
77 docChangeFrom = -1;-
78-
79 undoState = 0;-
80 revision = -1;-
81-
82 lout = 0;-
83-
84 modified = false;-
85 modifiedState = 0;-
86-
87 undoEnabled = true;-
88 inContentsChange = false;-
89 blockCursorAdjustment = false;-
90-
91 defaultTextOption.setTabStop(80);-
92 defaultTextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);-
93 defaultCursorMoveStyle = Qt::LogicalMoveStyle;-
94-
95 indentWidth = 40;-
96 documentMargin = 4;-
97-
98 maximumBlockCount = 0;-
99 needsEnsureMaximumBlockCount = false;-
100 unreachableCharacterCount = 0;-
101 lastBlockCount = 0;-
102}-
103-
104void QTextDocumentPrivate::init()-
105{-
106 framesDirty = false;-
107-
108 bool undoState = undoEnabled;-
109 undoEnabled = false;-
110 initialBlockCharFormatIndex = formats.indexForFormat(QTextCharFormat());-
111 insertBlock(0, formats.indexForFormat(QTextBlockFormat()), formats.indexForFormat(QTextCharFormat()));-
112 undoEnabled = undoState;-
113 modified = false;-
114 modifiedState = 0;-
115-
116 qRegisterMetaType<QTextDocument *>();-
117}-
118-
119void QTextDocumentPrivate::clear()-
120{-
121 QTextDocument * const q = q_func();-
122-
123 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(cursors)>::type> _container_((cursors)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QTextCursorPrivate *curs = *_container_.i; _container_.control; _container_.control = 0): qAsConst(cursors)) {-
124 curs->setPosition(0);-
125 curs->currentCharFormat = -1;-
126 curs->anchor = 0;-
127 curs->adjusted_anchor = 0;-
128 }
never executed: end of block
0
129-
130 QList<QTextCursorPrivate *>oldCursors = cursors;-
131 if (true){-
132 cursors.clear();-
133-
134 QMap<int, QTextObject *>::Iterator objectIt = objects.begin();-
135 while (objectIt != objects.end()
objectIt != objects.end()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
136 if (*
*objectIt != rtFrameDescription
TRUEnever evaluated
FALSEnever evaluated
objectIt != rtFrame
*objectIt != rtFrameDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
137 delete *objectIt;-
138 objectIt = objects.erase(objectIt);-
139 }
never executed: end of block
else {
0
140 ++objectIt;-
141 }
never executed: end of block
0
142 }-
143-
144-
145 objects.clear();-
146-
147 title.clear();-
148 clearUndoRedoStacks(QTextDocument::UndoAndRedoStacks);-
149 text = QString();-
150 unreachableCharacterCount = 0;-
151 modifiedState = 0;-
152 modified = false;-
153 formats = QTextFormatCollection();-
154 int len = fragments.length();-
155 fragments.clear();-
156 blocks.clear();-
157 cachedResources.clear();-
158 delete rtFrame;-
159 rtFrame = 0;-
160 init();-
161 cursors = oldCursors;-
162 inContentsChange = true;-
163 q->contentsChange(0, len, 0);-
164 inContentsChange = false;-
165 if (lout
loutDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
166 lout->documentChanged(0, len, 0);
never executed: lout->documentChanged(0, len, 0);
0
167 }
never executed: end of block
else {
dead code: { cursors = oldCursors; qt_noop(); }
-
168 cursors = oldCursors;
dead code: { cursors = oldCursors; qt_noop(); }
-
169 qt_noop();
dead code: { cursors = oldCursors; qt_noop(); }
-
170 }
dead code: { cursors = oldCursors; qt_noop(); }
-
171}-
172-
173QTextDocumentPrivate::~QTextDocumentPrivate()-
174{-
175 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(cursors)>::type> _container_((cursors)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (QTextCursorPrivate *curs = *_container_.i; _container_.control; _container_.control = 0): qAsConst(cursors))-
176 curs->priv = 0;
never executed: curs->priv = 0;
0
177 cursors.clear();-
178 undoState = 0;-
179 undoEnabled = true;-
180 clearUndoRedoStacks(QTextDocument::RedoStack);-
181}
never executed: end of block
0
182-
183void QTextDocumentPrivate::setLayout(QAbstractTextDocumentLayout *layout)-
184{-
185 QTextDocument * const q = q_func();-
186 if (lout == layout)-
187 return;-
188 const bool firstLayout = !lout;-
189 delete lout;-
190 lout = layout;-
191-
192 if (!firstLayout)-
193 for (BlockMap::Iterator it = blocks.begin(); !it.atEnd(); ++it)-
194 it->free();-
195-
196 q->documentLayoutChanged();-
197 inContentsChange = true;-
198 q->contentsChange(0, 0, length());-
199 inContentsChange = false;-
200 if (lout)-
201 lout->documentChanged(0, 0, length());-
202}-
203-
204-
205void QTextDocumentPrivate::insert_string(int pos, uint strPos, uint length, int format, QTextUndoCommand::Operation op)-
206{-
207-
208 ((!(noBlockInString(text.mid(strPos, length)))) ? qt_assert("noBlockInString(text.mid(strPos, length))",__FILE__,317323) : qt_noop());-
209-
210 split(pos);-
211 uint x = fragments.insert_single(pos, length);-
212 QTextFragmentData *X = fragments.fragment(x);-
213 X->format = format;-
214 X->stringPosition = strPos;-
215 uint w = fragments.previous(x);-
216 if (w)-
217 unite(w);-
218-
219 int b = blocks.findNode(pos);-
220 blocks.setSize(b, blocks.size(b)+length);-
221-
222 ((!(blocks.length() == fragments.length())) ? qt_assert("blocks.length() == fragments.length()",__FILE__,331337) : qt_noop());-
223-
224 QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(format));-
225 if (frame) {-
226 frame->d_func()->fragmentAdded(text.at(strPos), x);-
227 framesDirty = true;-
228 }-
229-
230 adjustDocumentChangesAndCursors(pos, length, op);-
231}-
232-
233int QTextDocumentPrivate::insert_block(int pos, uint strPos, int format, int blockFormat, QTextUndoCommand::Operation op, int command)-
234{-
235 split(pos);-
236 uint x = fragments.insert_single(pos, 1);-
237 QTextFragmentData *X = fragments.fragment(x);-
238 X->format = format;-
239 X->stringPosition = strPos;-
240-
241-
242 ((!(isValidBlockSeparator(text.at(strPos)))) ? qt_assert("isValidBlockSeparator(text.at(strPos))",__FILE__,351357) : qt_noop());-
243 ((!(blocks.length()+1 == fragments.length())) ? qt_assert("blocks.length()+1 == fragments.length()",__FILE__,352358) : qt_noop());-
244-
245 int block_pos = pos;-
246 if (blocks.length() && command == QTextUndoCommand::BlockRemoved)-
247 ++block_pos;-
248 int size = 1;-
249 int n = blocks.findNode(block_pos);-
250 int key = n ? blocks.position(n) : blocks.length();-
251-
252 ((!(n || (!n && block_pos == blocks.length()))) ? qt_assert("n || (!n && block_pos == blocks.length())",__FILE__,361367) : qt_noop());-
253 if (key != block_pos) {-
254 ((!(key < block_pos)) ? qt_assert("key < block_pos",__FILE__,363369) : qt_noop());-
255 int oldSize = blocks.size(n);-
256 blocks.setSize(n, block_pos-key);-
257 size += oldSize - (block_pos-key);-
258 }-
259 int b = blocks.insert_single(block_pos, size);-
260 QTextBlockData *B = blocks.fragment(b);-
261 B->format = blockFormat;-
262-
263 ((!(blocks.length() == fragments.length())) ? qt_assert("blocks.length() == fragments.length()",__FILE__,372378) : qt_noop());-
264-
265 QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(blockFormat));-
266 if (group)-
267 group->blockInserted(QTextBlock(this, b));-
268-
269 QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(formats.format(format)));-
270 if (frame) {-
271 frame->d_func()->fragmentAdded(text.at(strPos), x);-
272 framesDirty = true;-
273 }-
274-
275 adjustDocumentChangesAndCursors(pos, 1, op);-
276 return x;-
277}-
278-
279int QTextDocumentPrivate::insertBlock(QChar blockSeparator,-
280 int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation op)-
281{-
282 ((!(formats.format(blockFormat).isBlockFormat())) ? qt_assert("formats.format(blockFormat).isBlockFormat()",__FILE__,391397) : qt_noop());-
283 ((!(formats.format(charFormat).isCharFormat())) ? qt_assert("formats.format(charFormat).isCharFormat()",__FILE__,392398) : qt_noop());-
284 ((!(pos >= 0 && (pos < fragments.length() || (pos == 0 && fragments.length() == 0)))) ? qt_assert("pos >= 0 && (pos < fragments.length() || (pos == 0 && fragments.length() == 0))",__FILE__,393399) : qt_noop());-
285 ((!(isValidBlockSeparator(blockSeparator))) ? qt_assert("isValidBlockSeparator(blockSeparator)",__FILE__,394400) : qt_noop());-
286-
287 beginEditBlock();-
288-
289 int strPos = text.length();-
290 text.append(blockSeparator);-
291-
292 int ob = blocks.findNode(pos);-
293 bool atBlockEnd = true;-
294 bool atBlockStart = true;-
295 int oldRevision = 0;-
296 if (ob) {-
297 atBlockEnd = (pos - blocks.position(ob) == blocks.size(ob)-1);-
298 atBlockStart = ((int)blocks.position(ob) == pos);-
299 oldRevision = blocks.fragment(ob)->revision;-
300 }-
301-
302 const int fragment = insert_block(pos, strPos, charFormat, blockFormat, op, QTextUndoCommand::BlockRemoved);-
303-
304 ((!(blocks.length() == fragments.length())) ? qt_assert("blocks.length() == fragments.length()",__FILE__,413419) : qt_noop());-
305-
306 int b = blocks.findNode(pos);-
307 QTextBlockData *B = blocks.fragment(b);-
308-
309 QTextUndoCommand c = { QTextUndoCommand::BlockInserted, (editBlock != 0), 0, 0, quint8(op), charFormat, quint32(strPos), quint32(pos), { int(blockFormat) }, quint32(B->revision) }-
310-
311 ;-
312-
313 appendUndoItem(c);-
314 ((!(undoState == undoStack.size())) ? qt_assert("undoState == undoStack.size()",__FILE__,423429) : qt_noop());-
315-
316-
317 B->revision = (atBlockEnd && !atBlockStart)? oldRevision : revision;-
318 b = blocks.next(b);-
319 if (b) {-
320 B = blocks.fragment(b);-
321 B->revision = atBlockStart ? oldRevision : revision;-
322 }-
323-
324 if (formats.charFormat(charFormat).objectIndex() == -1)-
325 needsEnsureMaximumBlockCount = true;-
326-
327 endEditBlock();-
328 return fragment;-
329}-
330-
331int QTextDocumentPrivate::insertBlock(int pos, int blockFormat, int charFormat, QTextUndoCommand::Operation op)-
332{-
333 return insertBlock(QChar::ParagraphSeparator, pos, blockFormat, charFormat, op);-
334}-
335-
336void QTextDocumentPrivate::insert(int pos, int strPos, int strLength, int format)-
337{-
338 if (strLength <= 0)-
339 return;-
340-
341 ((!(pos >= 0 && pos < fragments.length())) ? qt_assert("pos >= 0 && pos < fragments.length()",__FILE__,450456) : qt_noop());-
342 ((!(formats.format(format).isCharFormat())) ? qt_assert("formats.format(format).isCharFormat()",__FILE__,451457) : qt_noop());-
343-
344 insert_string(pos, strPos, strLength, format, QTextUndoCommand::MoveCursor);-
345 if (undoEnabled) {-
346 int b = blocks.findNode(pos);-
347 QTextBlockData *B = blocks.fragment(b);-
348-
349 QTextUndoCommand c = { QTextUndoCommand::Inserted, (editBlock != 0), 0, 0, quint8(QTextUndoCommand::MoveCursor), format, quint32(strPos), quint32(pos), { int(strLength) }, quint32(B->revision) }-
350-
351 ;-
352 appendUndoItem(c);-
353 B->revision = revision;-
354 ((!(undoState == undoStack.size())) ? qt_assert("undoState == undoStack.size()",__FILE__,463469) : qt_noop());-
355 }-
356 finishEdit();-
357}-
358-
359void QTextDocumentPrivate::insert(int pos, const QString &str, int format)-
360{-
361 if (str.size() == 0)-
362 return;-
363-
364 ((!(noBlockInString(str))) ? qt_assert("noBlockInString(str)",__FILE__,473479) : qt_noop());-
365-
366 int strPos = text.length();-
367 text.append(str);-
368 insert(pos, strPos, str.length(), format);-
369}-
370-
371int QTextDocumentPrivate::remove_string(int pos, uint length, QTextUndoCommand::Operation op)-
372{-
373 ((!(pos >= 0)) ? qt_assert("pos >= 0",__FILE__,482488) : qt_noop());-
374 ((!(blocks.length() == fragments.length())) ? qt_assert("blocks.length() == fragments.length()",__FILE__,483489) : qt_noop());-
375 ((!(blocks.length() >= pos+(int)length)) ? qt_assert("blocks.length() >= pos+(int)length",__FILE__,484490) : qt_noop());-
376-
377 int b = blocks.findNode(pos);-
378 uint x = fragments.findNode(pos);-
379-
380 ((!(blocks.size(b) > length)) ? qt_assert("blocks.size(b) > length",__FILE__,489495) : qt_noop());-
381 ((!(x && fragments.position(x) == (uint)pos && fragments.size(x) == length)) ? qt_assert("x && fragments.position(x) == (uint)pos && fragments.size(x) == length",__FILE__,490496) : qt_noop());-
382 ((!(noBlockInString(text.mid(fragments.fragment(x)->stringPosition, length)))) ? qt_assert("noBlockInString(text.mid(fragments.fragment(x)->stringPosition, length))",__FILE__,491497) : qt_noop());-
383-
384 blocks.setSize(b, blocks.size(b)-length);-
385-
386 QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(fragments.fragment(x)->format));-
387 if (frame) {-
388 frame->d_func()->fragmentRemoved(text.at(fragments.fragment(x)->stringPosition), x);-
389 framesDirty = true;-
390 }-
391-
392 const int w = fragments.erase_single(x);-
393-
394 if (!undoEnabled)-
395 unreachableCharacterCount += length;-
396-
397 adjustDocumentChangesAndCursors(pos, -int(length), op);-
398-
399 return w;-
400}-
401-
402int QTextDocumentPrivate::remove_block(int pos, int *blockFormat, int command, QTextUndoCommand::Operation op)-
403{-
404 ((!(pos >= 0)) ? qt_assert("pos >= 0",__FILE__,513519) : qt_noop());-
405 ((!(blocks.length() == fragments.length())) ? qt_assert("blocks.length() == fragments.length()",__FILE__,514520) : qt_noop());-
406 ((!(blocks.length() > pos)) ? qt_assert("blocks.length() > pos",__FILE__,515521) : qt_noop());-
407-
408 int b = blocks.findNode(pos);-
409 uint x = fragments.findNode(pos);-
410-
411 ((!(x && (int)fragments.position(x) == pos)) ? qt_assert("x && (int)fragments.position(x) == pos",__FILE__,520526) : qt_noop());-
412 ((!(fragments.size(x) == 1)) ? qt_assert("fragments.size(x) == 1",__FILE__,521527) : qt_noop());-
413 ((!(isValidBlockSeparator(text.at(fragments.fragment(x)->stringPosition)))) ? qt_assert("isValidBlockSeparator(text.at(fragments.fragment(x)->stringPosition))",__FILE__,522528) : qt_noop());-
414 ((!(b)) ? qt_assert("b",__FILE__,523529) : qt_noop());-
415-
416 if (blocks.size(b) == 1 && command == QTextUndoCommand::BlockAdded) {-
417 ((!((int)blocks.position(b) == pos)) ? qt_assert("(int)blocks.position(b) == pos",__FILE__,526532) : qt_noop());-
418-
419-
420 } else {-
421-
422-
423 int n = blocks.next(b);-
424 ((!((int)blocks.position(n) == pos + 1)) ? qt_assert("(int)blocks.position(n) == pos + 1",__FILE__,533539) : qt_noop());-
425 blocks.setSize(b, blocks.size(b) + blocks.size(n) - 1);-
426 blocks.fragment(b)->userState = blocks.fragment(n)->userState;-
427 b = n;-
428 }-
429 *blockFormat = blocks.fragment(b)->format;-
430-
431 QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(blocks.fragment(b)->format));-
432 if (group)-
433 group->blockRemoved(QTextBlock(this, b));-
434-
435 QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(fragments.fragment(x)->format));-
436 if (frame) {-
437 frame->d_func()->fragmentRemoved(text.at(fragments.fragment(x)->stringPosition), x);-
438 framesDirty = true;-
439 }-
440-
441 blocks.erase_single(b);-
442 const int w = fragments.erase_single(x);-
443-
444 adjustDocumentChangesAndCursors(pos, -1, op);-
445-
446 return w;-
447}-
448-
449-
450static bool isAncestorFrame(QTextFrame *possibleAncestor, QTextFrame *child)-
451{-
452 while (child) {-
453 if (child == possibleAncestor)-
454 return true;-
455 child = child->parentFrame();-
456 }-
457 return false;-
458}-
459-
460-
461void QTextDocumentPrivate::move(int pos, int to, int length, QTextUndoCommand::Operation op)-
462{-
463 ((!(to <= fragments.length() && to <= pos)) ? qt_assert("to <= fragments.length() && to <= pos",__FILE__,572578) : qt_noop());-
464 ((!(pos >= 0 && pos+length <= fragments.length())) ? qt_assert("pos >= 0 && pos+length <= fragments.length()",__FILE__,573579) : qt_noop());-
465 ((!(blocks.length() == fragments.length())) ? qt_assert("blocks.length() == fragments.length()",__FILE__,574580) : qt_noop());-
466-
467 if (pos == to)-
468 return;-
469-
470 const bool needsInsert = to != -1;-
471-
472-
473 const bool startAndEndInSameFrame = (frameAt(pos) == frameAt(pos + length - 1));-
474-
475 const bool endIsEndOfChildFrame = (isAncestorFrame(frameAt(pos), frameAt(pos + length - 1))-
476 && text.at(find(pos + length - 1)->stringPosition) == QChar(0xfdd1));-
477-
478 const bool startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent-
479 = (text.at(find(pos)->stringPosition) == QChar(0xfdd0)-
480 && text.at(find(pos + length - 1)->stringPosition) == QChar(0xfdd1)-
481 && frameAt(pos)->parentFrame() == frameAt(pos + length - 1)->parentFrame());-
482-
483 const bool isFirstTableCell = (qobject_cast<QTextTable *>(frameAt(pos + length - 1))-
484 && frameAt(pos + length - 1)->parentFrame() == frameAt(pos));-
485-
486 ((!(startAndEndInSameFrame || endIsEndOfChildFrame || startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent || isFirstTableCell)) ? qt_assert("startAndEndInSameFrame || endIsEndOfChildFrame || startIsStartOfFrameAndEndIsEndOfFrameWithCommonParent || isFirstTableCell",__FILE__,595601) : qt_noop());-
487-
488-
489 split(pos);-
490 split(pos+length);-
491-
492 uint dst = needsInsert ? fragments.findNode(to) : 0;-
493 uint dstKey = needsInsert ? fragments.position(dst) : 0;-
494-
495 uint x = fragments.findNode(pos);-
496 uint end = fragments.findNode(pos+length);-
497-
498 uint w = 0;-
499 while (x != end) {-
500 uint n = fragments.next(x);-
501-
502 uint key = fragments.position(x);-
503 uint b = blocks.findNode(key+1);-
504 QTextBlockData *B = blocks.fragment(b);-
505 int blockRevision = B->revision;-
506-
507 QTextFragmentData *X = fragments.fragment(x);-
508 QTextUndoCommand c = { QTextUndoCommand::Removed, (editBlock != 0), 0, 0, quint8(op), X->format, quint32(X->stringPosition), quint32(key), { int(X->size_array[0]) }, quint32(blockRevision) }-
509-
510 ;-
511 QTextUndoCommand cInsert = { QTextUndoCommand::Inserted, (editBlock != 0), 0, 0, quint8(op), X->format, quint32(X->stringPosition), quint32(dstKey), { int(X->size_array[0]) }, quint32(blockRevision) }-
512-
513 ;-
514-
515 if (key+1 != blocks.position(b)) {-
516-
517 ((!(noBlockInString(text.mid(X->stringPosition, X->size_array[0])))) ? qt_assert("noBlockInString(text.mid(X->stringPosition, X->size_array[0]))",__FILE__,626632) : qt_noop());-
518 w = remove_string(key, X->size_array[0], op);-
519-
520 if (needsInsert) {-
521 insert_string(dstKey, X->stringPosition, X->size_array[0], X->format, op);-
522 dstKey += X->size_array[0];-
523 }-
524 } else {-
525-
526 ((!(X->size_array[0] == 1 && isValidBlockSeparator(text.at(X->stringPosition)))) ? qt_assert("X->size_array[0] == 1 && isValidBlockSeparator(text.at(X->stringPosition))",__FILE__,635641) : qt_noop());-
527 b = blocks.previous(b);-
528 B = 0;-
529 c.command = blocks.size(b) == 1 ? QTextUndoCommand::BlockDeleted : QTextUndoCommand::BlockRemoved;-
530 w = remove_block(key, &c.blockFormat, QTextUndoCommand::BlockAdded, op);-
531-
532 if (needsInsert) {-
533 insert_block(dstKey++, X->stringPosition, X->format, c.blockFormat, op, QTextUndoCommand::BlockRemoved);-
534 cInsert.command = blocks.size(b) == 1 ? QTextUndoCommand::BlockAdded : QTextUndoCommand::BlockInserted;-
535 cInsert.blockFormat = c.blockFormat;-
536 }-
537 }-
538 appendUndoItem(c);-
539 if (B)-
540 B->revision = revision;-
541 x = n;-
542-
543 if (needsInsert)-
544 appendUndoItem(cInsert);-
545 }-
546 if (w)-
547 unite(w);-
548-
549 ((!(blocks.length() == fragments.length())) ? qt_assert("blocks.length() == fragments.length()",__FILE__,658664) : qt_noop());-
550-
551 if (!blockCursorAdjustment)-
552 finishEdit();-
553}-
554-
555void QTextDocumentPrivate::remove(int pos, int length, QTextUndoCommand::Operation op)-
556{-
557 if (length == 0
length == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
558 return;
never executed: return;
0
559 blockCursorAdjustment = true;-
560 move(pos, -1, length, op);-
561 blockCursorAdjustment = false;-
for (QForeachContainer<typename QtPrivate::remove_reference<decltype(cursors)>::type> _container_((cursors)); _container_.control && _container_.i != _container_.e;
562 ++_container_.i, _container_.control ^= 1)for (QTextCursorPrivate *curs = *_container_.i; _container_.control; _container_.control = 0): qAsConst(cursors)) {-
563 if (curs->adjustPosition(pos, -length, op) == QTextCursorPrivate::CursorMoved
curs->adjustPo...e::CursorMovedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
564 curs->changed = true;-
565 }
never executed: end of block
0
566 }
never executed: end of block
0
567 finishEdit();-
568}
never executed: end of block
0
569-
570void QTextDocumentPrivate::setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode)-
571{-
572 beginEditBlock();-
573-
574 ((!(newFormat.isValid())) ? qt_assert("newFormat.isValid()",__FILE__,683689) : qt_noop());-
575-
576 int newFormatIdx = -1;-
577 if (mode == SetFormatAndPreserveObjectIndices) {-
578 QTextCharFormat cleanFormat = newFormat;-
579 cleanFormat.clearProperty(QTextFormat::ObjectIndex);-
580 newFormatIdx = formats.indexForFormat(cleanFormat);-
581 } else if (mode == SetFormat) {-
582 newFormatIdx = formats.indexForFormat(newFormat);-
583 }-
584-
585 if (pos == -1) {-
586 if (mode == MergeFormat) {-
587 QTextFormat format = formats.format(initialBlockCharFormatIndex);-
588 format.merge(newFormat);-
589 initialBlockCharFormatIndex = formats.indexForFormat(format);-
590 } else if (mode == SetFormatAndPreserveObjectIndices-
591 && formats.format(initialBlockCharFormatIndex).objectIndex() != -1) {-
592 QTextCharFormat f = newFormat;-
593 f.setObjectIndex(formats.format(initialBlockCharFormatIndex).objectIndex());-
594 initialBlockCharFormatIndex = formats.indexForFormat(f);-
595 } else {-
596 initialBlockCharFormatIndex = newFormatIdx;-
597 }-
598-
599 ++pos;-
600 --length;-
601 }-
602-
603 const int startPos = pos;-
604 const int endPos = pos + length;-
605-
606 split(startPos);-
607 split(endPos);-
608-
609 while (pos < endPos) {-
610 FragmentMap::Iterator it = fragments.find(pos);-
611 ((!(!it.atEnd())) ? qt_assert("!it.atEnd()",__FILE__,720726) : qt_noop());-
612-
613 QTextFragmentData *fragment = it.value();-
614-
615 ((!(formats.format(fragment->format).type() == QTextFormat::CharFormat)) ? qt_assert("formats.format(fragment->format).type() == QTextFormat::CharFormat",__FILE__,724730) : qt_noop());-
616-
617 int offset = pos - it.position();-
618 int length = qMin(endPos - pos, int(fragment->size_array[0] - offset));-
619 int oldFormat = fragment->format;-
620-
621 if (mode == MergeFormat) {-
622 QTextFormat format = formats.format(fragment->format);-
623 format.merge(newFormat);-
624 fragment->format = formats.indexForFormat(format);-
625 } else if (mode == SetFormatAndPreserveObjectIndices-
626 && formats.format(oldFormat).objectIndex() != -1) {-
627 QTextCharFormat f = newFormat;-
628 f.setObjectIndex(formats.format(oldFormat).objectIndex());-
629 fragment->format = formats.indexForFormat(f);-
630 } else {-
631 fragment->format = newFormatIdx;-
632 }-
633-
634 QTextUndoCommand c = { QTextUndoCommand::CharFormatChanged, true, 0, 0, quint8(QTextUndoCommand::MoveCursor), oldFormat, quint32(0), quint32(pos), { int(length) }, quint32(0) }-
635 ;-
636 appendUndoItem(c);-
637-
638 pos += length;-
639 ((!(pos == (int)(it.position() + fragment->size_array[0]) || pos >= endPos)) ? qt_assert("pos == (int)(it.position() + fragment->size_array[0]) || pos >= endPos",__FILE__,748754) : qt_noop());-
640 }-
641-
642 int n = fragments.findNode(startPos - 1);-
643 if (n)-
644 unite(n);-
645-
646 n = fragments.findNode(endPos);-
647 if (n)-
648 unite(n);-
649-
650 QTextBlock blockIt = blocksFind(startPos);-
651 QTextBlock endIt = blocksFind(endPos);-
652 if (endIt.isValid())-
653 endIt = endIt.next();-
654 for (; blockIt.isValid() && blockIt != endIt; blockIt = blockIt.next())-
655 QTextDocumentPrivate::block(blockIt)->invalidate();-
656-
657 documentChange(startPos, length);-
658-
659 endEditBlock();-
660}-
661-
662void QTextDocumentPrivate::setBlockFormat(const QTextBlock &from, const QTextBlock &to,-
663 const QTextBlockFormat &newFormat, FormatChangeMode mode)-
664{-
665 beginEditBlock();-
666-
667 ((!(mode != SetFormatAndPreserveObjectIndices)) ? qt_assert("mode != SetFormatAndPreserveObjectIndices",__FILE__,776782) : qt_noop());-
668-
669 ((!(newFormat.isValid())) ? qt_assert("newFormat.isValid()",__FILE__,778784) : qt_noop());-
670-
671 int newFormatIdx = -1;-
672 if (mode == SetFormat)-
673 newFormatIdx = formats.indexForFormat(newFormat);-
674 QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(newFormat));-
675-
676 QTextBlock it = from;-
677 QTextBlock end = to;-
678 if (end.isValid())-
679 end = end.next();-
680-
681 for (; it != end; it = it.next()) {-
682 int oldFormat = block(it)->format;-
683 QTextBlockFormat format = formats.blockFormat(oldFormat);-
684 QTextBlockGroup *oldGroup = qobject_cast<QTextBlockGroup *>(objectForFormat(format));-
685 if (mode == MergeFormat) {-
686 format.merge(newFormat);-
687 newFormatIdx = formats.indexForFormat(format);-
688 group = qobject_cast<QTextBlockGroup *>(objectForFormat(format));-
689 }-
690 block(it)->format = newFormatIdx;-
691-
692 block(it)->invalidate();-
693-
694 QTextUndoCommand c = { QTextUndoCommand::BlockFormatChanged, true, 0, 0, quint8(QTextUndoCommand::MoveCursor), oldFormat, quint32(0), quint32(it.position()), { int(1) }, quint32(0) }-
695 ;-
696 appendUndoItem(c);-
697-
698 if (group != oldGroup) {-
699 if (oldGroup)-
700 oldGroup->blockRemoved(it);-
701 if (group)-
702 group->blockInserted(it);-
703 } else if (group) {-
704 group->blockFormatChanged(it);-
705 }-
706 }-
707-
708 documentChange(from.position(), to.position() + to.length() - from.position());-
709-
710 endEditBlock();-
711}-
712-
713-
714bool QTextDocumentPrivate::split(int pos)-
715{-
716 uint x = fragments.findNode(pos);-
717 if (x) {-
718 int k = fragments.position(x);-
719-
720-
721 if (k != pos) {-
722 ((!(k <= pos)) ? qt_assert("k <= pos",__FILE__,831837) : qt_noop());-
723-
724 QTextFragmentData *X = fragments.fragment(x);-
725 int oldsize = X->size_array[0];-
726 fragments.setSize(x, pos-k);-
727 uint n = fragments.insert_single(pos, oldsize-(pos-k));-
728 X = fragments.fragment(x);-
729 QTextFragmentData *N = fragments.fragment(n);-
730 N->stringPosition = X->stringPosition + pos-k;-
731 N->format = X->format;-
732 return true;-
733 }-
734 }-
735 return false;-
736}-
737-
738bool QTextDocumentPrivate::unite(uint f)-
739{-
740 uint n = fragments.next(f);-
741 if (!n)-
742 return false;-
743-
744 QTextFragmentData *ff = fragments.fragment(f);-
745 QTextFragmentData *nf = fragments.fragment(n);-
746-
747 if (nf->format == ff->format && (ff->stringPosition + (int)ff->size_array[0] == nf->stringPosition)) {-
748 if (isValidBlockSeparator(text.at(ff->stringPosition))-
749 || isValidBlockSeparator(text.at(nf->stringPosition)))-
750 return false;-
751-
752 fragments.setSize(f, ff->size_array[0] + nf->size_array[0]);-
753 fragments.erase_single(n);-
754 return true;-
755 }-
756 return false;-
757}-
758-
759-
760int QTextDocumentPrivate::undoRedo(bool undo)-
761{-
762 if(0) QMessageLogger(__FILE__, 871877, __PRETTY_FUNCTION__).debug("%s, undoState=%d, undoStack size=%d", undo ? "undo:" : "redo:", undoState, undoStack.size());
dead code: QMessageLogger(__FILE__, 877, __PRETTY_FUNCTION__).debug("%s, undoState=%d, undoStack size=%d", undo ? "undo:" : "redo:", undoState, undoStack.size());
-
763 if (!undoEnabled
!undoEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
|| (undo
undoDescription
TRUEnever evaluated
FALSEnever evaluated
&& undoState == 0
undoState == 0Description
TRUEnever evaluated
FALSEnever evaluated
) || (!undo
!undoDescription
TRUEnever evaluated
FALSEnever evaluated
&& undoState == undoStack.size()
undoState == undoStack.size()Description
TRUEnever evaluated
FALSEnever evaluated
))
0
764 return
never executed: return -1;
-1;
never executed: return -1;
0
765-
766 undoEnabled = false;-
767 beginEditBlock();-
768 int editPos = -1;-
769 int editLength = -1;-
770 while (1) {-
771 if (undo
undoDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
772 --
never executed: --undoState;
undoState;
never executed: --undoState;
0
773 QTextUndoCommand &c = undoStack[undoState];-
774 int resetBlockRevision = c.pos;-
775-
776 switch (c.command) {-
777 case
never executed: case QTextUndoCommand::Inserted:
QTextUndoCommand::Inserted:
never executed: case QTextUndoCommand::Inserted:
0
778 remove(c.pos, c.length, (QTextUndoCommand::Operation)c.operation);-
779 if(0) QMessageLogger(__FILE__, 888894, __PRETTY_FUNCTION__).debug(" erase: from %d, length %d", c.pos, c.length);
dead code: QMessageLogger(__FILE__, 894, __PRETTY_FUNCTION__).debug(" erase: from %d, length %d", c.pos, c.length);
-
780 c.command = QTextUndoCommand::Removed;-
781 editPos = c.pos;-
782 editLength = 0;-
783 break;
never executed: break;
0
784 case
never executed: case QTextUndoCommand::Removed:
QTextUndoCommand::Removed:
never executed: case QTextUndoCommand::Removed:
0
785 if(0) QMessageLogger(__FILE__, 894900, __PRETTY_FUNCTION__).debug(" insert: format %d (from %d, length %d, strpos=%d)", c.format, c.pos, c.length, c.strPos);
dead code: QMessageLogger(__FILE__, 900, __PRETTY_FUNCTION__).debug(" insert: format %d (from %d, length %d, strpos=%d)", c.format, c.pos, c.length, c.strPos);
-
786 insert_string(c.pos, c.strPos, c.length, c.format, (QTextUndoCommand::Operation)c.operation);-
787 c.command = QTextUndoCommand::Inserted;-
788 if (editPos != (int)c.pos
editPos != (int)c.posDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
789 editLength = 0;
never executed: editLength = 0;
0
790 editPos = c.pos;-
791 editLength += c.length;-
792 break;
never executed: break;
0
793 case
never executed: case QTextUndoCommand::BlockInserted:
QTextUndoCommand::BlockInserted:
never executed: case QTextUndoCommand::BlockInserted:
0
794 case
never executed: case QTextUndoCommand::BlockAdded:
QTextUndoCommand::BlockAdded:
never executed: case QTextUndoCommand::BlockAdded:
0
795 remove_block(c.pos, &c.blockFormat, c.command, (QTextUndoCommand::Operation)c.operation);-
796 if(0) QMessageLogger(__FILE__, 905911, __PRETTY_FUNCTION__).debug(" blockremove: from %d", c.pos);
dead code: QMessageLogger(__FILE__, 911, __PRETTY_FUNCTION__).debug(" blockremove: from %d", c.pos);
-
797 if (c.command == QTextUndoCommand::BlockInserted
c.command == Q...:BlockInsertedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
798 c.command = QTextUndoCommand::BlockRemoved;
never executed: c.command = QTextUndoCommand::BlockRemoved;
0
799 else-
800 c.command = QTextUndoCommand::BlockDeleted;
never executed: c.command = QTextUndoCommand::BlockDeleted;
0
801 editPos = c.pos;-
802 editLength = 0;-
803 break;
never executed: break;
0
804 case
never executed: case QTextUndoCommand::BlockRemoved:
QTextUndoCommand::BlockRemoved:
never executed: case QTextUndoCommand::BlockRemoved:
0
805 case
never executed: case QTextUndoCommand::BlockDeleted:
QTextUndoCommand::BlockDeleted:
never executed: case QTextUndoCommand::BlockDeleted:
0
806 if(0) QMessageLogger(__FILE__, 915921, __PRETTY_FUNCTION__).debug(" blockinsert: charformat %d blockformat %d (pos %d, strpos=%d)", c.format, c.blockFormat, c.pos, c.strPos);
dead code: QMessageLogger(__FILE__, 921, __PRETTY_FUNCTION__).debug(" blockinsert: charformat %d blockformat %d (pos %d, strpos=%d)", c.format, c.blockFormat, c.pos, c.strPos);
-
807 insert_block(c.pos, c.strPos, c.format, c.blockFormat, (QTextUndoCommand::Operation)c.operation, c.command);-
808 resetBlockRevision += 1;-
809 if (c.command == QTextUndoCommand::BlockRemoved
c.command == Q...::BlockRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
810 c.command = QTextUndoCommand::BlockInserted;
never executed: c.command = QTextUndoCommand::BlockInserted;
0
811 else-
812 c.command = QTextUndoCommand::BlockAdded;
never executed: c.command = QTextUndoCommand::BlockAdded;
0
813 if (editPos != (int)c.pos
editPos != (int)c.posDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
814 editLength = 0;
never executed: editLength = 0;
0
815 editPos = c.pos;-
816 editLength += 1;-
817 break;
never executed: break;
0
818 case
never executed: case QTextUndoCommand::CharFormatChanged:
QTextUndoCommand::CharFormatChanged:
never executed: case QTextUndoCommand::CharFormatChanged:
{
0
819 resetBlockRevision = -1;-
820 if(0) QMessageLogger(__FILE__, 929935, __PRETTY_FUNCTION__).debug(" charFormat: format %d (from %d, length %d)", c.format, c.pos, c.length);
dead code: QMessageLogger(__FILE__, 935, __PRETTY_FUNCTION__).debug(" charFormat: format %d (from %d, length %d)", c.format, c.pos, c.length);
-
821 FragmentIterator it = find(c.pos);-
822 ((!(!it.atEnd())) ? qt_assert("!it.atEnd()",__FILE__,931937) : qt_noop());-
823-
824 int oldFormat = it.value()->format;-
825 setCharFormat(c.pos, c.length, formats.charFormat(c.format));-
826 c.format = oldFormat;-
827 if (editPos != (int)c.pos
editPos != (int)c.posDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
828 editLength = 0;
never executed: editLength = 0;
0
829 editPos = c.pos;-
830 editLength += c.length;-
831 break;
never executed: break;
0
832 }-
833 case
never executed: case QTextUndoCommand::BlockFormatChanged:
QTextUndoCommand::BlockFormatChanged:
never executed: case QTextUndoCommand::BlockFormatChanged:
{
0
834 resetBlockRevision = -1;-
835 if(0) QMessageLogger(__FILE__, 944950, __PRETTY_FUNCTION__).debug(" blockformat: format %d pos %d", c.format, c.pos);
dead code: QMessageLogger(__FILE__, 950, __PRETTY_FUNCTION__).debug(" blockformat: format %d pos %d", c.format, c.pos);
-
836 QTextBlock it = blocksFind(c.pos);-
837 ((!(it.isValid())) ? qt_assert("it.isValid()",__FILE__,946952) : qt_noop());-
838-
839 int oldFormat = block(it)->format;-
840 block(it)->format = c.format;-
841 QTextBlockGroup *oldGroup = qobject_cast<QTextBlockGroup *>(objectForFormat(formats.blockFormat(oldFormat)));-
842 QTextBlockGroup *group = qobject_cast<QTextBlockGroup *>(objectForFormat(formats.blockFormat(c.format)));-
843 c.format = oldFormat;-
844 if (group != oldGroup
group != oldGroupDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
845 if (oldGroup
oldGroupDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
846 oldGroup->blockRemoved(it);
never executed: oldGroup->blockRemoved(it);
0
847 if (group
groupDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
848 group->blockInserted(it);
never executed: group->blockInserted(it);
0
849 }
never executed: end of block
else if (group
groupDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
850 group->blockFormatChanged(it);-
851 }
never executed: end of block
0
852 documentChange(it.position(), it.length());-
853 editPos = -1;-
854 break;
never executed: break;
0
855 }-
856 case
never executed: case QTextUndoCommand::GroupFormatChange:
QTextUndoCommand::GroupFormatChange:
never executed: case QTextUndoCommand::GroupFormatChange:
{
0
857 resetBlockRevision = -1;-
858 if(0) QMessageLogger(__FILE__, 967973, __PRETTY_FUNCTION__).debug(" group format change");
dead code: QMessageLogger(__FILE__, 973, __PRETTY_FUNCTION__).debug(" group format change");
-
859 QTextObject *object = objectForIndex(c.objectIndex);-
860 int oldFormat = formats.objectFormatIndex(c.objectIndex);-
861 changeObjectFormat(object, c.format);-
862 c.format = oldFormat;-
863 editPos = -1;-
864 break;
never executed: break;
0
865 }-
866 case
never executed: case QTextUndoCommand::CursorMoved:
QTextUndoCommand::CursorMoved:
never executed: case QTextUndoCommand::CursorMoved:
0
867 editPos = c.pos;-
868 editLength = 0;-
869 break;
never executed: break;
0
870 case
never executed: case QTextUndoCommand::Custom:
QTextUndoCommand::Custom:
never executed: case QTextUndoCommand::Custom:
0
871 resetBlockRevision = -1;-
872 if (undo
undoDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
873 c.custom->undo();
never executed: c.custom->undo();
0
874 else-
875 c.custom->redo();
never executed: c.custom->redo();
0
876 editPos = -1;-
877 break;
never executed: break;
0
878 default
never executed: default:
:
never executed: default:
0
879 ((!(false)) ? qt_assert("false",__FILE__,988994) : qt_noop());-
880 }
never executed: end of block
0
881-
882 if (resetBlockRevision >= 0
resetBlockRevision >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
883 int b = blocks.findNode(resetBlockRevision);-
884 QTextBlockData *B = blocks.fragment(b);-
885 B->revision = c.revision;-
886 }
never executed: end of block
0
887-
888 if (!undo
!undoDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
889 ++
never executed: ++undoState;
undoState;
never executed: ++undoState;
0
890-
891 bool inBlock = (-
892 undoState > 0
undoState > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
893 && undoState < undoStack.size()
undoState < undoStack.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
894 && undoStack[.at(undoState].).block_part
undoStack.at(u...te).block_partDescription
TRUEnever evaluated
FALSEnever evaluated
0
895 && undoStack[.at(undoState - 1].).block_part
undoStack.at(u... 1).block_partDescription
TRUEnever evaluated
FALSEnever evaluated
0
896 && !undoStack[.at(undoState - 1].).block_end
!undoStack.at(...- 1).block_endDescription
TRUEnever evaluated
FALSEnever evaluated
0
897 );-
898 if (!inBlock
!inBlockDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
899 break;
never executed: break;
0
900 }
never executed: end of block
0
901 undoEnabled = true;-
902-
903 int newCursorPos = -1;-
904-
905 if (editPos >=0
editPos >=0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
906 newCursorPos = editPos + editLength;
never executed: newCursorPos = editPos + editLength;
0
907 else if (docChangeFrom >= 0
docChangeFrom >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
908 newCursorPos= qMin(docChangeFrom + docChangeLength, length() - 1);
never executed: newCursorPos= qMin(docChangeFrom + docChangeLength, length() - 1);
0
909-
910 endEditBlock();-
911 emitUndoAvailable(isUndoAvailable());-
912 emitRedoAvailable(isRedoAvailable());-
913-
914 return
never executed: return newCursorPos;
newCursorPos;
never executed: return newCursorPos;
0
915}-
916-
917-
918-
919-
920void QTextDocumentPrivate::appendUndoItem(QAbstractUndoItem *item)-
921{-
922 if (!undoEnabled) {-
923 delete item;-
924 return;-
925 }-
926-
927 QTextUndoCommand c;-
928 c.command = QTextUndoCommand::Custom;-
929 c.block_part = editBlock != 0;-
930 c.block_end = 0;-
931 c.operation = QTextUndoCommand::MoveCursor;-
932 c.format = 0;-
933 c.strPos = 0;-
934 c.pos = 0;-
935 c.blockFormat = 0;-
936-
937 c.custom = item;-
938 appendUndoItem(c);-
939}-
940-
941void QTextDocumentPrivate::appendUndoItem(const QTextUndoCommand &c)-
942{-
943 if(0) QMessageLogger(__FILE__, 10521058, __PRETTY_FUNCTION__).debug("appendUndoItem, command=%d enabled=%d", c.command, undoEnabled);
dead code: QMessageLogger(__FILE__, 1058, __PRETTY_FUNCTION__).debug("appendUndoItem, command=%d enabled=%d", c.command, undoEnabled);
-
944 if (!undoEnabled
!undoEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
945 return;
never executed: return;
0
946 if (undoState < undoStack.size()
undoState < undoStack.size()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
947 clearUndoRedoStacks(QTextDocument::RedoStack);
never executed: clearUndoRedoStacks(QTextDocument::RedoStack);
0
948-
949 if (editBlock != 0
editBlock != 0Description
TRUEnever evaluated
FALSEnever evaluated
&& editBlockCursorPosition >= 0
editBlockCursorPosition >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
950 if (c.pos != (quint32) editBlockCursorPosition
c.pos != (quin...CursorPositionDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
951-
952 QTextUndoCommand cc = { QTextUndoCommand::CursorMoved, true, 0, 0, quint8(QTextUndoCommand::MoveCursor), 0, quint32(0), quint32(editBlockCursorPosition), { int(0) }, quint32(0) }-
953 ;-
954 undoStack.append(cc);-
955 undoState++;-
956 editBlockCursorPosition = -1;-
957 }
never executed: end of block
0
958 }
never executed: end of block
0
959-
960-
961 if (!undoStack.isEmpty()
!undoStack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
&& modified
modifiedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
962 QTextUndoCommand &lastconst int lastIdx = undoStack[undoState - 1];;-
963 const QTextUndoCommand &last = undoStack.at(lastIdx);-
964-
965 if ( (last.block_part
last.block_partDescription
TRUEnever evaluated
FALSEnever evaluated
&& c.block_part
c.block_partDescription
TRUEnever evaluated
FALSEnever evaluated
&& !last.block_end
!last.block_endDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
966 || (!c.block_part
!c.block_partDescription
TRUEnever evaluated
FALSEnever evaluated
&& !last.block_part
!last.block_partDescription
TRUEnever evaluated
FALSEnever evaluated
)) {
0
967-
968 if (last.undoStack[lastIdx].
undoStack[lastIdx].tryMerge(c)Description
TRUEnever evaluated
FALSEnever evaluated
tryMerge(c)
undoStack[lastIdx].tryMerge(c)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
969 return;
never executed: return;
0
970 }
never executed: end of block
0
971 }
never executed: end of block
0
972 if (modifiedState > undoState
modifiedState > undoStateDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
973 modifiedState = -1;
never executed: modifiedState = -1;
0
974 undoStack.append(c);-
975 undoState++;-
976 emitUndoAvailable(true);-
977 emitRedoAvailable(false);-
978-
979 if (!c.block_part
!c.block_partDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
980 document()->undoCommandAdded();
never executed: document()->undoCommandAdded();
0
981}
never executed: end of block
0
982-
983void QTextDocumentPrivate::clearUndoRedoStacks(QTextDocument::Stacks stacksToClear,-
984 bool emitSignals)-
985{-
986 bool undoCommandsAvailable = undoState != 0;-
987 bool redoCommandsAvailable = undoState != undoStack.size();-
988 if (stacksToClear == QTextDocument::UndoStack
stacksToClear ...ent::UndoStackDescription
TRUEnever evaluated
FALSEnever evaluated
&& undoCommandsAvailable
undoCommandsAvailableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
989 for (int i = 0; i < undoState
i < undoStateDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
990 QTextUndoCommand c = undoStack[.at(undoState];);-
991 if (c.command & QTextUndoCommand::Custom
c.command & QT...ommand::CustomDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
992 delete c.custom;
never executed: delete c.custom;
0
993 }
never executed: end of block
0
994 undoStack.remove(0, undoState);-
995 undoStack.resize(undoStack.size() - undoState);-
996 undoState = 0;-
997 if (emitSignals
emitSignalsDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
998 emitUndoAvailable(false);
never executed: emitUndoAvailable(false);
0
999 }
never executed: end of block
else if (stacksToClear == QTextDocument::RedoStack
stacksToClear ...ent::RedoStackDescription
TRUEnever evaluated
FALSEnever evaluated
0
1000 && redoCommandsAvailable
redoCommandsAvailableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1001 for (int i = undoState; i < undoStack.size()
i < undoStack.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1002 QTextUndoCommand c = undoStack[.at(i];);-
1003 if (c.command & QTextUndoCommand::Custom
c.command & QT...ommand::CustomDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1004 delete c.custom;
never executed: delete c.custom;
0
1005 }
never executed: end of block
0
1006 undoStack.resize(undoState);-
1007 if (emitSignals
emitSignalsDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1008 emitRedoAvailable(false);
never executed: emitRedoAvailable(false);
0
1009 }
never executed: end of block
else if (stacksToClear == QTextDocument::UndoAndRedoStacks
stacksToClear ...oAndRedoStacksDescription
TRUEnever evaluated
FALSEnever evaluated
0
1010 && !undoStack.isEmpty()
!undoStack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1011 for (int i = 0; i < undoStack.size()
i < undoStack.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1012 QTextUndoCommand c = undoStack[.at(i];);-
1013 if (c.command & QTextUndoCommand::Custom
c.command & QT...ommand::CustomDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1014 delete c.custom;
never executed: delete c.custom;
0
1015 }
never executed: end of block
0
1016 undoState = 0;-
1017 undoStack.resize(0);clear();-
1018 if (emitSignals
emitSignalsDescription
TRUEnever evaluated
FALSEnever evaluated
&& undoCommandsAvailable
undoCommandsAvailableDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1019 emitUndoAvailable(false);
never executed: emitUndoAvailable(false);
0
1020 if (emitSignals
emitSignalsDescription
TRUEnever evaluated
FALSEnever evaluated
&& redoCommandsAvailable
redoCommandsAvailableDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1021 emitRedoAvailable(false);
never executed: emitRedoAvailable(false);
0
1022 }
never executed: end of block
0
1023}
never executed: end of block
0
1024-
1025void QTextDocumentPrivate::emitUndoAvailable(bool available)-
1026{-
1027 if (available != wasUndoAvailable) {-
1028 QTextDocument * const q = q_func();-
1029 q->undoAvailable(available);-
1030 wasUndoAvailable = available;-
1031 }-
1032}-
1033-
1034void QTextDocumentPrivate::emitRedoAvailable(bool available)-
1035{-
1036 if (available != wasRedoAvailable) {-
1037 QTextDocument * const q = q_func();-
1038 q->redoAvailable(available);-
1039 wasRedoAvailable = available;-
1040 }-
1041}-
1042-
1043void QTextDocumentPrivate::enableUndoRedo(bool enable)-
1044{-
1045 if (enable && maximumBlockCount > 0)-
1046 return;-
1047-
1048 if (!enable) {-
1049 undoState = 0;-
1050 clearUndoRedoStacks(QTextDocument::RedoStack);-
1051 emitUndoAvailable(false);-
1052 emitRedoAvailable(false);-
1053 }-
1054 modifiedState = modified ? -1 : undoState;-
1055 undoEnabled = enable;-
1056 if (!undoEnabled)-
1057 compressPieceTable();-
1058}-
1059-
1060void QTextDocumentPrivate::joinPreviousEditBlock()-
1061{-
1062 beginEditBlock();-
1063-
1064 if (undoEnabled && undoState)-
1065 undoStack[undoState - 1].block_end = false;-
1066}-
1067-
1068void QTextDocumentPrivate::endEditBlock()-
1069{-
1070 ((!(editBlock > 0)) ? qt_assert("editBlock > 0",__FILE__,11781185) : qt_noop());-
1071 if (--
--editBlockDescription
TRUEnever evaluated
FALSEnever evaluated
editBlock
--editBlockDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1072 return;
never executed: return;
0
1073-
1074 if (undoEnabled
undoEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
&& undoState > 0
undoState > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1075 const bool wasBlocking = !undoStack[.at(undoState - 1].).block_end;-
1076 if (undoStack[.at(undoState - 1].).block_part
undoStack.at(u... 1).block_partDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1077 undoStack[undoState - 1].block_end = true;-
1078 if (wasBlocking
wasBlockingDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1079 document()->undoCommandAdded();
never executed: document()->undoCommandAdded();
0
1080 }
never executed: end of block
0
1081 }
never executed: end of block
0
1082-
1083 editBlockCursorPosition = -1;-
1084-
1085 finishEdit();-
1086}
never executed: end of block
0
1087-
1088void QTextDocumentPrivate::finishEdit()-
1089{-
1090 QTextDocument * const q = q_func();-
1091-
1092 if (editBlock
editBlockDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1093 return;
never executed: return;
0
1094-
1095 if (framesDirty
framesDirtyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1096 scan_frames(docChangeFrom, docChangeOldLength, docChangeLength);
never executed: scan_frames(docChangeFrom, docChangeOldLength, docChangeLength);
0
1097-
1098 if (lout
loutDescription
TRUEnever evaluated
FALSEnever evaluated
&& docChangeFrom >= 0
docChangeFrom >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1099 if (!inContentsChange
!inContentsChangeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1100 inContentsChange = true;-
1101 q->contentsChange(docChangeFrom, docChangeOldLength, docChangeLength);-
1102 inContentsChange = false;-
1103 }
never executed: end of block
0
1104 lout->documentChanged(docChangeFrom, docChangeOldLength, docChangeLength);-
1105 }
never executed: end of block
0
1106-
1107 docChangeFrom = -1;-
1108-
1109 if (needsEnsureMaximumBlockCount
needsEnsureMaximumBlockCountDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1110 needsEnsureMaximumBlockCount = false;-
1111 if (ensureMaximumBlockCount()
ensureMaximumBlockCount()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1112-
1113-
1114-
1115-
1116 return;
never executed: return;
0
1117 }-
1118 }
never executed: end of block
0
1119-
1120 QList<QTextCursor> changedCursors;-
for (QForeachContainer<typename QtPrivate::remove_reference<decltype(cursors)>::type> _container_((cursors)); _container_.control && _container_.i != _container_.e;
1121 ++_container_.i, _container_.control ^= 1)for (QTextCursorPrivate *curs = *_container_.i; _container_.control; _container_.control = 0): qAsConst(cursors)) {-
1122 if (curs->changed
curs->changedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1123 curs->changed = false;-
1124 changedCursors.append(QTextCursor(curs));-
1125 }
never executed: end of block
0
1126 }
never executed: end of block
0
1127 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(changedCursors)>::type> _container_((changedCursors)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QTextCursor &cursor = *_container_.i; _container_.control; _container_.control = 0): qAsConst(changedCursors))-
1128 q->cursorPositionChanged(cursor);
never executed: q->cursorPositionChanged(cursor);
0
1129-
1130 contentsChanged();-
1131-
1132 if (blocks.numNodes() != lastBlockCount
blocks.numNode...lastBlockCountDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1133 lastBlockCount = blocks.numNodes();-
1134 q->blockCountChanged(lastBlockCount);-
1135 }
never executed: end of block
0
1136-
1137 if (!undoEnabled
!undoEnabledDescription
TRUEnever evaluated
FALSEnever evaluated
&& unreachableCharacterCount
unreachableCharacterCountDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1138 compressPieceTable();
never executed: compressPieceTable();
0
1139}
never executed: end of block
0
1140-
1141void QTextDocumentPrivate::documentChange(int from, int length)-
1142{-
1143-
1144 if (docChangeFrom < 0) {-
1145 docChangeFrom = from;-
1146 docChangeOldLength = length;-
1147 docChangeLength = length;-
1148 return;-
1149 }-
1150 int start = qMin(from, docChangeFrom);-
1151 int end = qMax(from + length, docChangeFrom + docChangeLength);-
1152 int diff = qMax(0, end - start - docChangeLength);-
1153 docChangeFrom = start;-
1154 docChangeOldLength += diff;-
1155 docChangeLength += diff;-
1156}-
1157void QTextDocumentPrivate::adjustDocumentChangesAndCursors(int from, int addedOrRemoved, QTextUndoCommand::Operation op)-
1158{-
1159 if (!editBlock
!editBlockDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1160 ++
never executed: ++revision;
revision;
never executed: ++revision;
0
1161-
1162 if (blockCursorAdjustment
blockCursorAdjustmentDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1163 ;-
1164 }
never executed: end of block
else {
0
1165 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(cursors)>::type> _container_((cursors)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (QTextCursorPrivate *curs = *_container_.i; _container_.control; _container_.control = 0): qAsConst(cursors)) {-
1166 if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved
curs->adjustPo...e::CursorMovedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1167 curs->changed = true;-
1168 }
never executed: end of block
0
1169 }
never executed: end of block
0
1170 }
never executed: end of block
0
1171-
1172-
1173 if (docChangeFrom < 0
docChangeFrom < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1174 docChangeFrom = from;-
1175 if (addedOrRemoved > 0
addedOrRemoved > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1176 docChangeOldLength = 0;-
1177 docChangeLength = addedOrRemoved;-
1178 }
never executed: end of block
else {
0
1179 docChangeOldLength = -addedOrRemoved;-
1180 docChangeLength = 0;-
1181 }
never executed: end of block
0
1182-
1183-
1184 return;
never executed: return;
0
1185 }-
1186-
1187-
1188 int added = qMax(0, addedOrRemoved);-
1189 int removed = qMax(0, -addedOrRemoved);-
1190-
1191 int diff = 0;-
1192 if (from + removed < docChangeFrom
from + removed < docChangeFromDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1193 diff = docChangeFrom - from - removed;
never executed: diff = docChangeFrom - from - removed;
0
1194 else if (from > docChangeFrom + docChangeLength
from > docChan...ocChangeLengthDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1195 diff = from - (docChangeFrom + docChangeLength);
never executed: diff = from - (docChangeFrom + docChangeLength);
0
1196-
1197 int overlap_start = qMax(from, docChangeFrom);-
1198 int overlap_end = qMin(from + removed, docChangeFrom + docChangeLength);-
1199 int removedInside = qMax(0, overlap_end - overlap_start);-
1200 removed -= removedInside;-
1201-
1202-
1203 docChangeFrom = qMin(docChangeFrom, from);-
1204 docChangeOldLength += removed + diff;-
1205 docChangeLength += added - removedInside + diff;-
1206-
1207-
1208}
never executed: end of block
0
1209-
1210-
1211QString QTextDocumentPrivate::plainText() const-
1212{-
1213 QString result;-
1214 result.resize(length());-
1215 const QChar *text_unicode = text.unicode();-
1216 QChar *data = result.data();-
1217 for (QTextDocumentPrivate::FragmentIterator it = begin(); it != end(); ++it) {-
1218 const QTextFragmentData *f = *it;-
1219 ::memcpy(data, text_unicode + f->stringPosition, f->size_array[0] * sizeof(QChar));-
1220 data += f->size_array[0];-
1221 }-
1222-
1223 result.chop(1);-
1224 return result;-
1225}-
1226-
1227int QTextDocumentPrivate::blockCharFormatIndex(int node) const-
1228{-
1229 int pos = blocks.position(node);-
1230 if (pos == 0)-
1231 return initialBlockCharFormatIndex;-
1232-
1233 return fragments.find(pos - 1)->format;-
1234}-
1235-
1236int QTextDocumentPrivate::nextCursorPosition(int position, QTextLayout::CursorMode mode) const-
1237{-
1238 if (position == length()-1)-
1239 return position;-
1240-
1241 QTextBlock it = blocksFind(position);-
1242 int start = it.position();-
1243 int end = start + it.length() - 1;-
1244 if (position == end)-
1245 return end + 1;-
1246-
1247 return it.layout()->nextCursorPosition(position-start, mode) + start;-
1248}-
1249-
1250int QTextDocumentPrivate::previousCursorPosition(int position, QTextLayout::CursorMode mode) const-
1251{-
1252 if (position == 0)-
1253 return position;-
1254-
1255 QTextBlock it = blocksFind(position);-
1256 int start = it.position();-
1257 if (position == start)-
1258 return start - 1;-
1259-
1260 return it.layout()->previousCursorPosition(position-start, mode) + start;-
1261}-
1262-
1263int QTextDocumentPrivate::leftCursorPosition(int position) const-
1264{-
1265 QTextBlock it = blocksFind(position);-
1266 int start = it.position();-
1267 return it.layout()->leftCursorPosition(position-start) + start;-
1268}-
1269-
1270int QTextDocumentPrivate::rightCursorPosition(int position) const-
1271{-
1272 QTextBlock it = blocksFind(position);-
1273 int start = it.position();-
1274 return it.layout()->rightCursorPosition(position-start) + start;-
1275}-
1276-
1277void QTextDocumentPrivate::changeObjectFormat(QTextObject *obj, int format)-
1278{-
1279 beginEditBlock();-
1280 int objectIndex = obj->objectIndex();-
1281 int oldFormatIndex = formats.objectFormatIndex(objectIndex);-
1282 formats.setObjectFormatIndex(objectIndex, format);-
1283-
1284 QTextBlockGroup *b = qobject_cast<QTextBlockGroup *>(obj);-
1285 if (b) {-
1286 b->d_func()->markBlocksDirty();-
1287 }-
1288 QTextFrame *f = qobject_cast<QTextFrame *>(obj);-
1289 if (f)-
1290 documentChange(f->firstPosition(), f->lastPosition() - f->firstPosition());-
1291-
1292 QTextUndoCommand c = { QTextUndoCommand::GroupFormatChange, (editBlock != 0), 0, 0, quint8(QTextUndoCommand::MoveCursor), oldFormatIndex, quint32(0), quint32(0), { int(obj->d_func()->objectIndex) }, quint32(0) }-
1293 ;-
1294 appendUndoItem(c);-
1295-
1296 endEditBlock();-
1297}-
1298-
1299static QTextFrame *findChildFrame(QTextFrame *f, int pos)-
1300{-
1301-
1302 const QList<QTextFrame *> children = f->childFrames();-
1303 int first = 0;-
1304 int last = children.size() - 1;-
1305 while (first <= last) {-
1306 int mid = (first + last) / 2;-
1307 QTextFrame *c = children.at(mid);-
1308 if (pos > c->lastPosition())-
1309 first = mid + 1;-
1310 else if (pos < c->firstPosition())-
1311 last = mid - 1;-
1312 else-
1313 return c;-
1314 }-
1315 return 0;-
1316}-
1317-
1318QTextFrame *QTextDocumentPrivate::rootFrame() const-
1319{-
1320 if (!rtFrame) {-
1321 QTextFrameFormat defaultRootFrameFormat;-
1322 defaultRootFrameFormat.setMargin(documentMargin);-
1323 rtFrame = qobject_cast<QTextFrame *>(const_cast<QTextDocumentPrivate *>(this)->createObject(defaultRootFrameFormat));-
1324 }-
1325 return rtFrame;-
1326}-
1327-
1328QTextFrame *QTextDocumentPrivate::frameAt(int pos) const-
1329{-
1330 QTextFrame *f = rootFrame();-
1331-
1332 while (1) {-
1333 QTextFrame *c = findChildFrame(f, pos);-
1334 if (!c)-
1335 return f;-
1336 f = c;-
1337 }-
1338}-
1339-
1340void QTextDocumentPrivate::clearFrame(QTextFrame *f)-
1341{-
1342 for (int i = 0; i < f->d_func()->childFrames.count(); ++i)-
1343 clearFrame(f->d_func()->childFrames.at(i));-
1344 f->d_func()->childFrames.clear();-
1345 f->d_func()->parentFrame = 0;-
1346}-
1347-
1348void QTextDocumentPrivate::scan_frames(int pos, int charsRemoved, int charsAdded)-
1349{-
1350-
1351 (void)pos;;-
1352 (void)charsRemoved;;-
1353 (void)charsAdded;;-
1354-
1355 QTextFrame *f = rootFrame();-
1356 clearFrame(f);-
1357-
1358 for (FragmentIterator it = begin(); it != end(); ++it) {-
1359-
1360 QTextFrame *frame = qobject_cast<QTextFrame *>(objectForFormat(it->format));-
1361 if (!frame)-
1362 continue;-
1363-
1364 ((!(it.size() == 1)) ? qt_assert("it.size() == 1",__FILE__,14801487) : qt_noop());-
1365 QChar ch = text.at(it->stringPosition);-
1366-
1367 if (ch == QChar(0xfdd0)) {-
1368 if (f != frame) {-
1369-
1370 ((!(frame->d_func()->fragment_start == it.n || frame->d_func()->fragment_start == 0)) ? qt_assert("frame->d_func()->fragment_start == it.n || frame->d_func()->fragment_start == 0",__FILE__,14861493) : qt_noop());-
1371 frame->d_func()->parentFrame = f;-
1372 f->d_func()->childFrames.append(frame);-
1373 f = frame;-
1374 }-
1375 } else if (ch == QChar(0xfdd1)) {-
1376 ((!(f == frame)) ? qt_assert("f == frame",__FILE__,14921499) : qt_noop());-
1377 ((!(frame->d_func()->fragment_end == it.n || frame->d_func()->fragment_end == 0)) ? qt_assert("frame->d_func()->fragment_end == it.n || frame->d_func()->fragment_end == 0",__FILE__,14931500) : qt_noop());-
1378 f = frame->d_func()->parentFrame;-
1379 } else if (ch == QChar::ObjectReplacementCharacter) {-
1380 ((!(f != frame)) ? qt_assert("f != frame",__FILE__,14961503) : qt_noop());-
1381 ((!(frame->d_func()->fragment_start == it.n || frame->d_func()->fragment_start == 0)) ? qt_assert("frame->d_func()->fragment_start == it.n || frame->d_func()->fragment_start == 0",__FILE__,14971504) : qt_noop());-
1382 ((!(frame->d_func()->fragment_end == it.n || frame->d_func()->fragment_end == 0)) ? qt_assert("frame->d_func()->fragment_end == it.n || frame->d_func()->fragment_end == 0",__FILE__,14981505) : qt_noop());-
1383 frame->d_func()->parentFrame = f;-
1384 f->d_func()->childFrames.append(frame);-
1385 } else {-
1386 ((!(false)) ? qt_assert("false",__FILE__,15021509) : qt_noop());-
1387 }-
1388 }-
1389 ((!(f == rtFrame)) ? qt_assert("f == rtFrame",__FILE__,15051512) : qt_noop());-
1390 framesDirty = false;-
1391}-
1392-
1393void QTextDocumentPrivate::insert_frame(QTextFrame *f)-
1394{-
1395 int start = f->firstPosition();-
1396 int end = f->lastPosition();-
1397 QTextFrame *parent = frameAt(start-1);-
1398 ((!(parent == frameAt(end+1))) ? qt_assert("parent == frameAt(end+1)",__FILE__,15141521) : qt_noop());-
1399-
1400 if (start != end) {-
1401-
1402 for (int i = 0; i < parent->d_func()->childFrames.size(); ++i) {-
1403 QTextFrame *c = parent->d_func()->childFrames.at(i);-
1404 if (start < c->firstPosition() && end > c->lastPosition()) {-
1405 parent->d_func()->childFrames.removeAt(i);-
1406 f->d_func()->childFrames.append(c);-
1407 c->d_func()->parentFrame = f;-
1408 }-
1409 }-
1410 }-
1411-
1412 int i = 0;-
1413 for (; i < parent->d_func()->childFrames.size(); ++i) {-
1414 QTextFrame *c = parent->d_func()->childFrames.at(i);-
1415 if (c->firstPosition() > end)-
1416 break;-
1417 }-
1418 parent->d_func()->childFrames.insert(i, f);-
1419 f->d_func()->parentFrame = parent;-
1420}-
1421-
1422QTextFrame *QTextDocumentPrivate::insertFrame(int start, int end, const QTextFrameFormat &format)-
1423{-
1424 ((!(start >= 0 && start < length())) ? qt_assert("start >= 0 && start < length()",__FILE__,15401547) : qt_noop());-
1425 ((!(end >= 0 && end < length())) ? qt_assert("end >= 0 && end < length()",__FILE__,15411548) : qt_noop());-
1426 ((!(start <= end || end == -1)) ? qt_assert("start <= end || end == -1",__FILE__,15421549) : qt_noop());-
1427-
1428 if (start != end && frameAt(start) != frameAt(end))-
1429 return 0;-
1430-
1431 beginEditBlock();-
1432-
1433 QTextFrame *frame = qobject_cast<QTextFrame *>(createObject(format));-
1434 ((!(frame)) ? qt_assert("frame",__FILE__,15501557) : qt_noop());-
1435-
1436-
1437 int idx = formats.indexForFormat(QTextBlockFormat());-
1438 QTextCharFormat cfmt;-
1439 cfmt.setObjectIndex(frame->objectIndex());-
1440 int charIdx = formats.indexForFormat(cfmt);-
1441-
1442 insertBlock(QChar(0xfdd0), start, idx, charIdx, QTextUndoCommand::MoveCursor);-
1443 insertBlock(QChar(0xfdd1), ++end, idx, charIdx, QTextUndoCommand::KeepCursor);-
1444-
1445 frame->d_func()->fragment_start = find(start).n;-
1446 frame->d_func()->fragment_end = find(end).n;-
1447-
1448 insert_frame(frame);-
1449-
1450 endEditBlock();-
1451-
1452 return frame;-
1453}-
1454-
1455void QTextDocumentPrivate::removeFrame(QTextFrame *frame)-
1456{-
1457 QTextFrame *parent = frame->d_func()->parentFrame;-
1458 if (!parent)-
1459 return;-
1460-
1461 int start = frame->firstPosition();-
1462 int end = frame->lastPosition();-
1463 ((!(end >= start)) ? qt_assert("end >= start",__FILE__,15791586) : qt_noop());-
1464-
1465 beginEditBlock();-
1466-
1467-
1468 remove(end, 1);-
1469 remove(start-1, 1);-
1470-
1471 endEditBlock();-
1472}-
1473-
1474QTextObject *QTextDocumentPrivate::objectForIndex(int objectIndex) const-
1475{-
1476 if (objectIndex < 0)-
1477 return 0;-
1478-
1479 QTextObject *object = objects.value(objectIndex, 0);-
1480 if (!object) {-
1481 QTextDocumentPrivate *that = const_cast<QTextDocumentPrivate *>(this);-
1482 QTextFormat fmt = formats.objectFormat(objectIndex);-
1483 object = that->createObject(fmt, objectIndex);-
1484 }-
1485 return object;-
1486}-
1487-
1488QTextObject *QTextDocumentPrivate::objectForFormat(int formatIndex) const-
1489{-
1490 int objectIndex = formats.format(formatIndex).objectIndex();-
1491 return objectForIndex(objectIndex);-
1492}-
1493-
1494QTextObject *QTextDocumentPrivate::objectForFormat(const QTextFormat &f) const-
1495{-
1496 return objectForIndex(f.objectIndex());-
1497}-
1498-
1499QTextObject *QTextDocumentPrivate::createObject(const QTextFormat &f, int objectIndex)-
1500{-
1501 QTextObject *obj = document()->createObject(f);-
1502-
1503 if (obj) {-
1504 obj->d_func()->objectIndex = objectIndex == -1 ? formats.createObjectIndex(f) : objectIndex;-
1505 objects[obj->d_func()->objectIndex] = obj;-
1506 }-
1507-
1508 return obj;-
1509}-
1510-
1511void QTextDocumentPrivate::deleteObject(QTextObject *object)-
1512{-
1513 const int objIdx = object->d_func()->objectIndex;-
1514 objects.remove(objIdx);-
1515 delete object;-
1516}-
1517-
1518void QTextDocumentPrivate::contentsChanged()-
1519{-
1520 QTextDocument * const q = q_func();-
1521 if (editBlock)-
1522 return;-
1523-
1524 bool m = undoEnabled ? (modifiedState != undoState) : true;-
1525 if (modified != m) {-
1526 modified = m;-
1527 q->modificationChanged(modified);-
1528 }-
1529-
1530 q->contentsChanged();-
1531}-
1532-
1533void QTextDocumentPrivate::compressPieceTable()-
1534{-
1535 if (undoEnabled)-
1536 return;-
1537-
1538 const uint garbageCollectionThreshold = 96 * 1024;-
1539-
1540-
1541-
1542 bool compressTable = unreachableCharacterCount * sizeof(QChar) > garbageCollectionThreshold-
1543 && text.size() >= text.capacity() * 0.9;-
1544 if (!compressTable)-
1545 return;-
1546-
1547 QString newText;-
1548 newText.resize(text.size());-
1549 QChar *newTextPtr = newText.data();-
1550 int newLen = 0;-
1551-
1552 for (FragmentMap::Iterator it = fragments.begin(); !it.atEnd(); ++it) {-
1553 memcpy(newTextPtr, text.constData() + it->stringPosition, it->size_array[0] * sizeof(QChar));-
1554 it->stringPosition = newLen;-
1555 newTextPtr += it->size_array[0];-
1556 newLen += it->size_array[0];-
1557 }-
1558-
1559 newText.resize(newLen);-
1560 newText.squeeze();-
1561-
1562 text = newText;-
1563 unreachableCharacterCount = 0;-
1564}-
1565-
1566void QTextDocumentPrivate::setModified(bool m)-
1567{-
1568 QTextDocument * const q = q_func();-
1569 if (m == modified)-
1570 return;-
1571-
1572 modified = m;-
1573 if (!modified)-
1574 modifiedState = undoState;-
1575 else-
1576 modifiedState = -1;-
1577-
1578 q->modificationChanged(modified);-
1579}-
1580-
1581bool QTextDocumentPrivate::ensureMaximumBlockCount()-
1582{-
1583 if (maximumBlockCount <= 0)-
1584 return false;-
1585 if (blocks.numNodes() <= maximumBlockCount)-
1586 return false;-
1587-
1588 beginEditBlock();-
1589-
1590 const int blocksToRemove = blocks.numNodes() - maximumBlockCount;-
1591 QTextCursor cursor(this, 0);-
1592 cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor, blocksToRemove);-
1593-
1594 unreachableCharacterCount += cursor.selectionEnd() - cursor.selectionStart();-
1595-
1596-
1597 QTextCharFormat charFmt = cursor.blockCharFormat();-
1598 cursor.removeSelectedText();-
1599 cursor.setBlockCharFormat(charFmt);-
1600-
1601 endEditBlock();-
1602-
1603 compressPieceTable();-
1604-
1605 return true;-
1606}-
1607-
1608-
1609void QTextDocumentPrivate::aboutToRemoveCell(int from, int to)-
1610{-
1611 ((!(from <= to)) ? qt_assert("from <= to",__FILE__,17271734) : qt_noop());-
1612 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(cursors)>::type> _container_((cursors)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (QTextCursorPrivate *curs = *_container_.i; _container_.control; _container_.control = 0): qAsConst(cursors))-
1613 curs->aboutToRemoveCell(from, to);
never executed: curs->aboutToRemoveCell(from, to);
0
1614}
never executed: end of block
0
1615-
1616-
Switch to Source codePreprocessed file

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