Changeset 846 for trunk/src/gui/text/qtextdocument_p.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/text/qtextdocument_p.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 64 64 #if !defined(Q_CC_DIAB) 65 65 # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ 66 QTextUndoCommand c = { a1, a2, 0, 0, a3, a4, a5, a6, { a7 }, a8 }66 QTextUndoCommand c = { a1, a2, 0, 0, quint8(a3), a4, a5, a6, { a7 }, a8 } 67 67 #else 68 68 # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ … … 92 92 93 93 Lists are not in here, as they are treated specially. A list is just 94 a collection of (not nec cessarily connected) blocks, that share the94 a collection of (not necessarily connected) blocks, that share the 95 95 same objectIndex() in the format that refers to the list format and 96 96 object. … … 193 193 { 194 194 editBlock = 0; 195 editBlockCursorPosition = -1; 195 196 docChangeFrom = -1; 196 197 … … 205 206 undoEnabled = true; 206 207 inContentsChange = false; 208 blockCursorAdjustment = false; 207 209 208 210 defaultTextOption.setTabStop(80); // same as in qtextengine.cpp … … 234 236 { 235 237 Q_Q(QTextDocument); 236 for (int i = 0; i < cursors.count(); ++i) { 237 cursors.at(i)->setPosition(0); 238 cursors.at(i)->currentCharFormat = -1; 239 cursors.at(i)->anchor = 0; 240 cursors.at(i)->adjusted_anchor = 0; 238 239 foreach (QTextCursorPrivate *curs, cursors) { 240 curs->setPosition(0); 241 curs->currentCharFormat = -1; 242 curs->anchor = 0; 243 curs->adjusted_anchor = 0; 241 244 } 242 245 … … 244 247 QT_TRY{ 245 248 cursors.clear(); 246 changedCursors.clear();247 249 248 250 QMap<int, QTextObject *>::Iterator objectIt = objects.begin(); … … 260 262 261 263 title.clear(); 262 undoState = 0; 263 truncateUndoStack(); 264 clearUndoRedoStacks(QTextDocument::UndoAndRedoStacks); 264 265 text = QString(); 265 266 unreachableCharacterCount = 0; … … 288 289 QTextDocumentPrivate::~QTextDocumentPrivate() 289 290 { 290 for (int i = 0; i < cursors.count(); ++i)291 curs ors.at(i)->priv = 0;291 foreach (QTextCursorPrivate *curs, cursors) 292 curs->priv = 0; 292 293 cursors.clear(); 293 294 undoState = 0; 294 295 undoEnabled = true; 295 truncateUndoStack();296 clearUndoRedoStacks(QTextDocument::RedoStack); 296 297 } 297 298 … … 320 321 void QTextDocumentPrivate::insert_string(int pos, uint strPos, uint length, int format, QTextUndoCommand::Operation op) 321 322 { 322 // ##### optimi se when only appending to the fragment!323 // ##### optimize when only appending to the fragment! 323 324 Q_ASSERT(noBlockInString(text.mid(strPos, length))); 324 325 … … 663 664 Q_ASSERT(blocks.length() == fragments.length()); 664 665 665 finishEdit(); 666 if (!blockCursorAdjustment) 667 finishEdit(); 666 668 } 667 669 … … 670 672 if (length == 0) 671 673 return; 674 blockCursorAdjustment = true; 672 675 move(pos, -1, length, op); 676 blockCursorAdjustment = false; 677 foreach (QTextCursorPrivate *curs, cursors) { 678 if (curs->adjustPosition(pos, -length, op) == QTextCursorPrivate::CursorMoved) { 679 curs->changed = true; 680 } 681 } 682 finishEdit(); 673 683 } 674 684 … … 872 882 beginEditBlock(); 873 883 int editPos = -1; 884 int editLength = -1; 874 885 while (1) { 875 886 if (undo) … … 884 895 c.command = QTextUndoCommand::Removed; 885 896 editPos = c.pos; 897 editLength = 0; 886 898 break; 887 899 case QTextUndoCommand::Removed: … … 889 901 insert_string(c.pos, c.strPos, c.length, c.format, (QTextUndoCommand::Operation)c.operation); 890 902 c.command = QTextUndoCommand::Inserted; 891 editPos = c.pos + c.length; 903 if (editPos != (int)c.pos) 904 editLength = 0; 905 editPos = c.pos; 906 editLength += c.length; 892 907 break; 893 908 case QTextUndoCommand::BlockInserted: … … 900 915 c.command = QTextUndoCommand::BlockDeleted; 901 916 editPos = c.pos; 917 editLength = 0; 902 918 break; 903 919 case QTextUndoCommand::BlockRemoved: … … 910 926 else 911 927 c.command = QTextUndoCommand::BlockAdded; 912 editPos = c.pos + 1; 928 if (editPos != (int)c.pos) 929 editLength = 0; 930 editPos = c.pos; 931 editLength += 1; 913 932 break; 914 933 case QTextUndoCommand::CharFormatChanged: { … … 921 940 setCharFormat(c.pos, c.length, formats.charFormat(c.format)); 922 941 c.format = oldFormat; 923 editPos = c.pos + c.length; 942 if (editPos != (int)c.pos) 943 editLength = 0; 944 editPos = c.pos; 945 editLength += c.length; 924 946 break; 925 947 } … … 957 979 break; 958 980 } 981 case QTextUndoCommand::CursorMoved: 982 editPos = c.pos; 983 editLength = 0; 984 break; 959 985 case QTextUndoCommand::Custom: 960 986 resetBlockRevision = -1; // ## TODO … … 989 1015 } 990 1016 undoEnabled = true; 991 if (editPos < 0 && docChangeFrom >= 0) { 992 editPos = qMin(docChangeFrom + docChangeLength, length() - 1); 993 } 1017 1018 int newCursorPos = -1; 1019 1020 if (editPos >=0) 1021 newCursorPos = editPos + editLength; 1022 else if (docChangeFrom >= 0) 1023 newCursorPos= qMin(docChangeFrom + docChangeLength, length() - 1); 1024 994 1025 endEditBlock(); 995 1026 emitUndoAvailable(isUndoAvailable()); 996 1027 emitRedoAvailable(isRedoAvailable()); 997 return editPos; 1028 1029 return newCursorPos; 998 1030 } 999 1031 … … 1028 1060 return; 1029 1061 if (undoState < undoStack.size()) 1030 truncateUndoStack(); 1062 clearUndoRedoStacks(QTextDocument::RedoStack); 1063 1064 if (editBlock != 0 && editBlockCursorPosition >= 0) { // we had a beginEditBlock() with a cursor position 1065 if (c.pos != (quint32) editBlockCursorPosition) { // and that cursor position is different from the command 1066 // generate a CursorMoved undo item 1067 QT_INIT_TEXTUNDOCOMMAND(cc, QTextUndoCommand::CursorMoved, true, QTextUndoCommand::MoveCursor, 1068 0, 0, editBlockCursorPosition, 0, 0); 1069 undoStack.append(cc); 1070 undoState++; 1071 editBlockCursorPosition = -1; 1072 } 1073 } 1074 1031 1075 1032 1076 if (!undoStack.isEmpty() && modified) { … … 1051 1095 } 1052 1096 1053 void QTextDocumentPrivate::truncateUndoStack() 1054 { 1055 if (undoState == undoStack.size()) 1056 return; 1057 1058 for (int i = undoState; i < undoStack.size(); ++i) { 1059 QTextUndoCommand c = undoStack[i]; 1060 if (c.command & QTextUndoCommand::Removed) { 1061 // ######## 1062 // QTextFragment *f = c.fragment_list; 1063 // while (f) { 1064 // QTextFragment *n = f->right; 1065 // delete f; 1066 // f = n; 1067 // } 1068 } else if (c.command & QTextUndoCommand::Custom) { 1069 delete c.custom; 1070 } 1071 } 1072 undoStack.resize(undoState); 1097 void QTextDocumentPrivate::clearUndoRedoStacks(QTextDocument::Stacks stacksToClear, 1098 bool emitSignals) 1099 { 1100 bool undoCommandsAvailable = undoState != 0; 1101 bool redoCommandsAvailable = undoState != undoStack.size(); 1102 if (stacksToClear == QTextDocument::UndoStack && undoCommandsAvailable) { 1103 for (int i = 0; i < undoState; ++i) { 1104 QTextUndoCommand c = undoStack[undoState]; 1105 if (c.command & QTextUndoCommand::Custom) 1106 delete c.custom; 1107 } 1108 undoStack.remove(0, undoState); 1109 undoStack.resize(undoStack.size() - undoState); 1110 undoState = 0; 1111 if (emitSignals) 1112 emitUndoAvailable(false); 1113 } else if (stacksToClear == QTextDocument::RedoStack 1114 && redoCommandsAvailable) { 1115 for (int i = undoState; i < undoStack.size(); ++i) { 1116 QTextUndoCommand c = undoStack[i]; 1117 if (c.command & QTextUndoCommand::Custom) 1118 delete c.custom; 1119 } 1120 undoStack.resize(undoState); 1121 if (emitSignals) 1122 emitRedoAvailable(false); 1123 } else if (stacksToClear == QTextDocument::UndoAndRedoStacks 1124 && !undoStack.isEmpty()) { 1125 for (int i = 0; i < undoStack.size(); ++i) { 1126 QTextUndoCommand c = undoStack[i]; 1127 if (c.command & QTextUndoCommand::Custom) 1128 delete c.custom; 1129 } 1130 undoState = 0; 1131 undoStack.resize(0); 1132 if (emitSignals && undoCommandsAvailable) 1133 emitUndoAvailable(false); 1134 if (emitSignals && redoCommandsAvailable) 1135 emitRedoAvailable(false); 1136 } 1073 1137 } 1074 1138 … … 1098 1162 if (!enable) { 1099 1163 undoState = 0; 1100 truncateUndoStack();1164 clearUndoRedoStacks(QTextDocument::RedoStack); 1101 1165 emitUndoAvailable(false); 1102 1166 emitRedoAvailable(false); … … 1130 1194 } 1131 1195 } 1196 1197 editBlockCursorPosition = -1; 1132 1198 1133 1199 finishEdit(); … … 1166 1232 } 1167 1233 1168 while (!changedCursors.isEmpty()) { 1169 QTextCursorPrivate *curs = changedCursors.takeFirst(); 1170 emit q->cursorPositionChanged(QTextCursor(curs)); 1171 } 1234 QList<QTextCursor> changedCursors; 1235 foreach (QTextCursorPrivate *curs, cursors) { 1236 if (curs->changed) { 1237 curs->changed = false; 1238 changedCursors.append(QTextCursor(curs)); 1239 } 1240 } 1241 foreach (const QTextCursor &cursor, changedCursors) 1242 emit q->cursorPositionChanged(cursor); 1172 1243 1173 1244 contentsChanged(); … … 1211 1282 ++revision; 1212 1283 1213 for (int i = 0; i < cursors.size(); ++i) { 1214 QTextCursorPrivate *curs = cursors.at(i); 1215 if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) { 1216 if (!changedCursors.contains(curs)) 1217 changedCursors.append(curs); 1284 if (blockCursorAdjustment) { 1285 ; // postpone, will be called again from QTextDocumentPrivate::remove() 1286 } else { 1287 foreach (QTextCursorPrivate *curs, cursors) { 1288 if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) { 1289 curs->changed = true; 1290 } 1218 1291 } 1219 1292 } … … 1376 1449 void QTextDocumentPrivate::scan_frames(int pos, int charsRemoved, int charsAdded) 1377 1450 { 1378 // ###### optimi se1451 // ###### optimize 1379 1452 Q_UNUSED(pos); 1380 1453 Q_UNUSED(charsRemoved); … … 1579 1652 1580 1653 for (FragmentMap::Iterator it = fragments.begin(); !it.atEnd(); ++it) { 1581 qMemCopy(newTextPtr, text.constData() + it->stringPosition, it->size_array[0] * sizeof(QChar));1654 memcpy(newTextPtr, text.constData() + it->stringPosition, it->size_array[0] * sizeof(QChar)); 1582 1655 it->stringPosition = newLen; 1583 1656 newTextPtr += it->size_array[0]; … … 1638 1711 { 1639 1712 Q_ASSERT(from <= to); 1640 for (int i = 0; i < cursors.size(); ++i)1641 curs ors.at(i)->aboutToRemoveCell(from, to);1713 foreach (QTextCursorPrivate *curs, cursors) 1714 curs->aboutToRemoveCell(from, to); 1642 1715 } 1643 1716
Note:
See TracChangeset
for help on using the changeset viewer.