Changeset 561 for trunk/src/gui/text/qtextdocument_p.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/text/qtextdocument_p.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 61 61 #define PMDEBUG if(0) qDebug 62 62 63 64 65 66 67 68 69 70 71 63 72 /* 64 73 Structure of a document: … … 180 189 docChangeLength(0), 181 190 framesDirty(true), 191 182 192 initialBlockCharFormatIndex(-1) // set correctly later in init() 183 193 { … … 186 196 187 197 undoState = 0; 198 188 199 189 200 lout = 0; … … 194 205 undoEnabled = true; 195 206 inContentsChange = false; 207 196 208 defaultTextOption.setTabStop(80); // same as in qtextengine.cpp 197 209 defaultTextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); … … 208 220 void QTextDocumentPrivate::init() 209 221 { 210 rtFrame = 0;211 222 framesDirty = false; 212 223 … … 231 242 232 243 QList<QTextCursorPrivate *>oldCursors = cursors; 233 cursors.clear(); 234 changedCursors.clear(); 235 236 QMap<int, QTextObject *>::Iterator objectIt = objects.begin(); 237 while (objectIt != objects.end()) { 238 if (*objectIt != rtFrame) { 239 delete *objectIt; 240 objectIt = objects.erase(objectIt); 241 } else { 242 ++objectIt; 244 QT_TRY{ 245 cursors.clear(); 246 changedCursors.clear(); 247 248 QMap<int, QTextObject *>::Iterator objectIt = objects.begin(); 249 while (objectIt != objects.end()) { 250 if (*objectIt != rtFrame) { 251 delete *objectIt; 252 objectIt = objects.erase(objectIt); 253 } else { 254 ++objectIt; 255 } 243 256 } 244 } 245 // also clear out the remaining root frame pointer 246 // (we're going to delete the object further down) 247 objects.clear(); 248 249 title.clear(); 250 undoState = 0; 251 truncateUndoStack(); 252 text = QString(); 253 unreachableCharacterCount = 0; 254 modifiedState = 0; 255 modified = false; 256 formats = QTextFormatCollection(); 257 int len = fragments.length(); 258 fragments.clear(); 259 blocks.clear(); 260 cachedResources.clear(); 261 delete rtFrame; 262 init(); 263 cursors = oldCursors; 264 inContentsChange = true; 265 q->contentsChange(0, len, 0); 266 inContentsChange = false; 267 if (lout) 268 lout->documentChanged(0, len, 0); 257 // also clear out the remaining root frame pointer 258 // (we're going to delete the object further down) 259 objects.clear(); 260 261 title.clear(); 262 undoState = 0; 263 truncateUndoStack(); 264 text = QString(); 265 unreachableCharacterCount = 0; 266 modifiedState = 0; 267 modified = false; 268 formats = QTextFormatCollection(); 269 int len = fragments.length(); 270 fragments.clear(); 271 blocks.clear(); 272 cachedResources.clear(); 273 delete rtFrame; 274 rtFrame = 0; 275 init(); 276 cursors = oldCursors; 277 inContentsChange = true; 278 q->contentsChange(0, len, 0); 279 inContentsChange = false; 280 if (lout) 281 lout->documentChanged(0, len, 0); 282 } QT_CATCH(...) { 283 cursors = oldCursors; // at least recover the cursors 284 QT_RETHROW; 285 } 269 286 } 270 287 … … 405 422 QTextBlockData *B = blocks.fragment(b); 406 423 407 QT extUndoCommand c = { QTextUndoCommand::BlockInserted, true,408 op, charFormat, strPos, pos, { blockFormat },409 B->revision };424 QT, 425 , 426 ; 410 427 411 428 appendUndoItem(c); … … 413 430 414 431 // update revision numbers of the modified blocks. 415 B->revision = (atBlockEnd && !atBlockStart)? oldRevision : undoState;432 B->revision = (atBlockEnd && !atBlockStart)? oldRevision : ; 416 433 b = blocks.next(b); 417 434 if (b) { 418 435 B = blocks.fragment(b); 419 B->revision = atBlockStart ? oldRevision : undoState;436 B->revision = atBlockStart ? oldRevision : ; 420 437 } 421 438 … … 440 457 Q_ASSERT(formats.format(format).isCharFormat()); 441 458 442 beginEditBlock();443 459 insert_string(pos, strPos, strLength, format, QTextUndoCommand::MoveCursor); 444 460 if (undoEnabled) { … … 446 462 QTextBlockData *B = blocks.fragment(b); 447 463 448 QT extUndoCommand c = { QTextUndoCommand::Inserted, true,449 QTextUndoCommand::MoveCursor, format, strPos, pos, { strLength },450 B->revision };464 QT, 465 , 466 ; 451 467 appendUndoItem(c); 452 B->revision = undoState;468 B->revision = ; 453 469 Q_ASSERT(undoState == undoStack.size()); 454 470 } 455 endEditBlock();471 (); 456 472 } 457 473 … … 585 601 #endif 586 602 587 beginEditBlock();588 589 603 split(pos); 590 604 split(pos+length); … … 606 620 607 621 QTextFragmentData *X = fragments.fragment(x); 608 QT extUndoCommand c = { QTextUndoCommand::Removed, true,609 op, X->format, X->stringPosition, key, { X->size_array[0] },610 blockRevision };611 QT extUndoCommand cInsert = { QTextUndoCommand::Inserted, true,612 op, X->format, X->stringPosition, dstKey, { X->size_array[0] },613 blockRevision };622 QT, 623 , 624 ; 625 QT, 626 , 627 ; 614 628 615 629 if (key+1 != blocks.position(b)) { … … 638 652 appendUndoItem(c); 639 653 if (B) 640 B->revision = undoState;654 B->revision = ; 641 655 x = n; 642 656 … … 649 663 Q_ASSERT(blocks.length() == fragments.length()); 650 664 651 endEditBlock();665 (); 652 666 } 653 667 … … 723 737 } 724 738 725 QT extUndoCommand c = {QTextUndoCommand::CharFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat,726 0, pos, { length }, 0 };739 QT QTextUndoCommand::CharFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat, 740 ; 727 741 appendUndoItem(c); 728 742 … … 783 797 block(it)->invalidate(); 784 798 785 QT extUndoCommand c = {QTextUndoCommand::BlockFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat,786 0, it.position(), { 1 }, 0 };799 QT QTextUndoCommand::BlockFormatChanged, true, QTextUndoCommand::MoveCursor, oldFormat, 800 ; 787 801 appendUndoItem(c); 788 802 … … 857 871 undoEnabled = false; 858 872 beginEditBlock(); 873 859 874 while (1) { 860 875 if (undo) … … 868 883 PMDEBUG(" erase: from %d, length %d", c.pos, c.length); 869 884 c.command = QTextUndoCommand::Removed; 885 870 886 break; 871 887 case QTextUndoCommand::Removed: … … 873 889 insert_string(c.pos, c.strPos, c.length, c.format, (QTextUndoCommand::Operation)c.operation); 874 890 c.command = QTextUndoCommand::Inserted; 891 875 892 break; 876 893 case QTextUndoCommand::BlockInserted: … … 882 899 else 883 900 c.command = QTextUndoCommand::BlockDeleted; 901 884 902 break; 885 903 case QTextUndoCommand::BlockRemoved: … … 892 910 else 893 911 c.command = QTextUndoCommand::BlockAdded; 912 894 913 break; 895 914 case QTextUndoCommand::CharFormatChanged: { … … 902 921 setCharFormat(c.pos, c.length, formats.charFormat(c.format)); 903 922 c.format = oldFormat; 923 904 924 break; 905 925 } … … 924 944 } 925 945 documentChange(it.position(), it.length()); 946 926 947 break; 927 948 } … … 933 954 changeObjectFormat(object, c.format); 934 955 c.format = oldFormat; 956 935 957 break; 936 958 } … … 941 963 else 942 964 c.custom->redo(); 965 943 966 break; 944 967 default: … … 952 975 } 953 976 954 if (undo) { 955 if (undoState == 0 || !undoStack[undoState-1].block) 956 break; 957 } else { 977 if (!undo) 958 978 ++undoState; 959 if (undoState == undoStack.size() || !undoStack[undoState-1].block) 960 break; 961 } 979 980 bool inBlock = ( 981 undoState > 0 982 && undoState < undoStack.size() 983 && undoStack[undoState].block_part 984 && undoStack[undoState-1].block_part 985 && !undoStack[undoState-1].block_end 986 ); 987 if (!inBlock) 988 break; 962 989 } 963 990 undoEnabled = true; 964 int editPos = -1; 965 if (docChangeFrom >= 0) { 991 if (editPos < 0 && docChangeFrom >= 0) { 966 992 editPos = qMin(docChangeFrom + docChangeLength, length() - 1); 967 993 } … … 984 1010 QTextUndoCommand c; 985 1011 c.command = QTextUndoCommand::Custom; 986 c.block = editBlock != 0; 1012 c.block_part = editBlock != 0; 1013 c.block_end = 0; 987 1014 c.operation = QTextUndoCommand::MoveCursor; 988 1015 c.format = 0; … … 1005 1032 if (!undoStack.isEmpty() && modified) { 1006 1033 QTextUndoCommand &last = undoStack[undoState - 1]; 1007 if (last.tryMerge(c)) 1008 return; 1034 1035 if ( (last.block_part && c.block_part && !last.block_end) // part of the same block => can merge 1036 || (!c.block_part && !last.block_part)) { // two single undo items => can merge 1037 1038 if (last.tryMerge(c)) 1039 return; 1040 } 1009 1041 } 1010 1042 if (modifiedState > undoState) … … 1014 1046 emitUndoAvailable(true); 1015 1047 emitRedoAvailable(false); 1048 1049 1050 1016 1051 } 1017 1052 … … 1078 1113 1079 1114 if (undoEnabled && undoState) 1080 undoStack[undoState - 1].block = true;1115 undoStack[undoState - 1].blocke; 1081 1116 } 1082 1117 1083 1118 void QTextDocumentPrivate::endEditBlock() 1084 1119 { 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1085 1138 Q_Q(QTextDocument); 1086 if (--editBlock) 1087 return; 1088 1089 if (undoEnabled && undoState > 0) { 1090 const bool wasBlocking = undoStack[undoState - 1].block; 1091 undoStack[undoState - 1].block = false; 1092 if (wasBlocking) 1093 emit document()->undoCommandAdded(); 1094 } 1139 1140 if (editBlock) 1141 return; 1095 1142 1096 1143 if (framesDirty) … … 1156 1203 param from is the cursor position in the document 1157 1204 param addedOrRemoved is the amount of characters added or removed. A negative number means characters are removed. 1205 1206 1158 1207 */ 1159 1208 void QTextDocumentPrivate::adjustDocumentChangesAndCursors(int from, int addedOrRemoved, QTextUndoCommand::Operation op) 1160 1209 { 1161 Q_Q(QTextDocument); 1210 if (!editBlock) 1211 ++revision; 1212 1162 1213 for (int i = 0; i < cursors.size(); ++i) { 1163 1214 QTextCursorPrivate *curs = cursors.at(i); 1164 1215 if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) { 1165 if (editBlock) { 1166 if (!changedCursors.contains(curs)) 1167 changedCursors.append(curs); 1168 } else { 1169 emit q->cursorPositionChanged(QTextCursor(curs)); 1170 } 1216 if (!changedCursors.contains(curs)) 1217 changedCursors.append(curs); 1171 1218 } 1172 1219 } … … 1184 1231 // qDebug("adjustDocumentChanges:"); 1185 1232 // qDebug(" -> %d %d %d", docChangeFrom, docChangeOldLength, docChangeLength); 1186 contentsChanged();1187 1233 return; 1188 1234 } … … 1209 1255 // qDebug(" -> %d %d %d", docChangeFrom, docChangeOldLength, docChangeLength); 1210 1256 1211 contentsChanged();1212 1257 } 1213 1258 … … 1280 1325 documentChange(f->firstPosition(), f->lastPosition() - f->firstPosition()); 1281 1326 1282 QT extUndoCommand c = { QTextUndoCommand::GroupFormatChange, true, QTextUndoCommand::MoveCursor, oldFormatIndex,1283 0, 0, { obj->d_func()->objectIndex }, 0 };1327 QT, QTextUndoCommand::MoveCursor, oldFormatIndex, 1328 ; 1284 1329 appendUndoItem(c); 1285 1330
Note:
See TracChangeset
for help on using the changeset viewer.