61 #define PMDEBUG if(0) qDebug |
61 #define PMDEBUG if(0) qDebug |
62 |
62 |
63 // The VxWorks DIAB compiler crashes when initializing the anonymouse union with { a7 } |
63 // The VxWorks DIAB compiler crashes when initializing the anonymouse union with { a7 } |
64 #if !defined(Q_CC_DIAB) |
64 #if !defined(Q_CC_DIAB) |
65 # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ |
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 #else |
67 #else |
68 # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ |
68 # define QT_INIT_TEXTUNDOCOMMAND(c, a1, a2, a3, a4, a5, a6, a7, a8) \ |
69 QTextUndoCommand c = { a1, a2, 0, 0, a3, a4, a5, a6 }; c.blockFormat = a7; c.revision = a8 |
69 QTextUndoCommand c = { a1, a2, 0, 0, a3, a4, a5, a6 }; c.blockFormat = a7; c.revision = a8 |
70 #endif |
70 #endif |
71 |
71 |
881 case QTextUndoCommand::Inserted: |
881 case QTextUndoCommand::Inserted: |
882 remove(c.pos, c.length, (QTextUndoCommand::Operation)c.operation); |
882 remove(c.pos, c.length, (QTextUndoCommand::Operation)c.operation); |
883 PMDEBUG(" erase: from %d, length %d", c.pos, c.length); |
883 PMDEBUG(" erase: from %d, length %d", c.pos, c.length); |
884 c.command = QTextUndoCommand::Removed; |
884 c.command = QTextUndoCommand::Removed; |
885 editPos = c.pos; |
885 editPos = c.pos; |
|
886 editLength = 0; |
886 break; |
887 break; |
887 case QTextUndoCommand::Removed: |
888 case QTextUndoCommand::Removed: |
888 PMDEBUG(" insert: format %d (from %d, length %d, strpos=%d)", c.format, c.pos, c.length, c.strPos); |
889 PMDEBUG(" insert: format %d (from %d, length %d, strpos=%d)", c.format, c.pos, c.length, c.strPos); |
889 insert_string(c.pos, c.strPos, c.length, c.format, (QTextUndoCommand::Operation)c.operation); |
890 insert_string(c.pos, c.strPos, c.length, c.format, (QTextUndoCommand::Operation)c.operation); |
890 c.command = QTextUndoCommand::Inserted; |
891 c.command = QTextUndoCommand::Inserted; |
891 editPos = c.pos + c.length; |
892 if (editPos != (int)c.pos) |
|
893 editLength = 0; |
|
894 editPos = c.pos; |
|
895 editLength += c.length; |
892 break; |
896 break; |
893 case QTextUndoCommand::BlockInserted: |
897 case QTextUndoCommand::BlockInserted: |
894 case QTextUndoCommand::BlockAdded: |
898 case QTextUndoCommand::BlockAdded: |
895 remove_block(c.pos, &c.blockFormat, c.command, (QTextUndoCommand::Operation)c.operation); |
899 remove_block(c.pos, &c.blockFormat, c.command, (QTextUndoCommand::Operation)c.operation); |
896 PMDEBUG(" blockremove: from %d", c.pos); |
900 PMDEBUG(" blockremove: from %d", c.pos); |
897 if (c.command == QTextUndoCommand::BlockInserted) |
901 if (c.command == QTextUndoCommand::BlockInserted) |
898 c.command = QTextUndoCommand::BlockRemoved; |
902 c.command = QTextUndoCommand::BlockRemoved; |
899 else |
903 else |
900 c.command = QTextUndoCommand::BlockDeleted; |
904 c.command = QTextUndoCommand::BlockDeleted; |
901 editPos = c.pos; |
905 editPos = c.pos; |
|
906 editLength = 0; |
902 break; |
907 break; |
903 case QTextUndoCommand::BlockRemoved: |
908 case QTextUndoCommand::BlockRemoved: |
904 case QTextUndoCommand::BlockDeleted: |
909 case QTextUndoCommand::BlockDeleted: |
905 PMDEBUG(" blockinsert: charformat %d blockformat %d (pos %d, strpos=%d)", c.format, c.blockFormat, c.pos, c.strPos); |
910 PMDEBUG(" blockinsert: charformat %d blockformat %d (pos %d, strpos=%d)", c.format, c.blockFormat, c.pos, c.strPos); |
906 insert_block(c.pos, c.strPos, c.format, c.blockFormat, (QTextUndoCommand::Operation)c.operation, c.command); |
911 insert_block(c.pos, c.strPos, c.format, c.blockFormat, (QTextUndoCommand::Operation)c.operation, c.command); |
907 resetBlockRevision += 1; |
912 resetBlockRevision += 1; |
908 if (c.command == QTextUndoCommand::BlockRemoved) |
913 if (c.command == QTextUndoCommand::BlockRemoved) |
909 c.command = QTextUndoCommand::BlockInserted; |
914 c.command = QTextUndoCommand::BlockInserted; |
910 else |
915 else |
911 c.command = QTextUndoCommand::BlockAdded; |
916 c.command = QTextUndoCommand::BlockAdded; |
912 editPos = c.pos + 1; |
917 if (editPos != (int)c.pos) |
|
918 editLength = 0; |
|
919 editPos = c.pos; |
|
920 editLength += 1; |
913 break; |
921 break; |
914 case QTextUndoCommand::CharFormatChanged: { |
922 case QTextUndoCommand::CharFormatChanged: { |
915 resetBlockRevision = -1; // ## TODO |
923 resetBlockRevision = -1; // ## TODO |
916 PMDEBUG(" charFormat: format %d (from %d, length %d)", c.format, c.pos, c.length); |
924 PMDEBUG(" charFormat: format %d (from %d, length %d)", c.format, c.pos, c.length); |
917 FragmentIterator it = find(c.pos); |
925 FragmentIterator it = find(c.pos); |
918 Q_ASSERT(!it.atEnd()); |
926 Q_ASSERT(!it.atEnd()); |
919 |
927 |
920 int oldFormat = it.value()->format; |
928 int oldFormat = it.value()->format; |
921 setCharFormat(c.pos, c.length, formats.charFormat(c.format)); |
929 setCharFormat(c.pos, c.length, formats.charFormat(c.format)); |
922 c.format = oldFormat; |
930 c.format = oldFormat; |
923 editPos = c.pos + c.length; |
931 if (editPos != (int)c.pos) |
|
932 editLength = 0; |
|
933 editPos = c.pos; |
|
934 editLength += c.length; |
924 break; |
935 break; |
925 } |
936 } |
926 case QTextUndoCommand::BlockFormatChanged: { |
937 case QTextUndoCommand::BlockFormatChanged: { |
927 resetBlockRevision = -1; // ## TODO |
938 resetBlockRevision = -1; // ## TODO |
928 PMDEBUG(" blockformat: format %d pos %d", c.format, c.pos); |
939 PMDEBUG(" blockformat: format %d pos %d", c.format, c.pos); |
1048 |
1065 |
1049 if (!c.block_part) |
1066 if (!c.block_part) |
1050 emit document()->undoCommandAdded(); |
1067 emit document()->undoCommandAdded(); |
1051 } |
1068 } |
1052 |
1069 |
1053 void QTextDocumentPrivate::truncateUndoStack() |
1070 void QTextDocumentPrivate::clearUndoRedoStacks(QTextDocument::Stacks stacksToClear, |
1054 { |
1071 bool emitSignals) |
1055 if (undoState == undoStack.size()) |
1072 { |
1056 return; |
1073 bool undoCommandsAvailable = undoState != 0; |
1057 |
1074 bool redoCommandsAvailable = undoState != undoStack.size(); |
1058 for (int i = undoState; i < undoStack.size(); ++i) { |
1075 if (stacksToClear == QTextDocument::UndoStack && undoCommandsAvailable) { |
1059 QTextUndoCommand c = undoStack[i]; |
1076 for (int i = 0; i < undoState; ++i) { |
1060 if (c.command & QTextUndoCommand::Removed) { |
1077 QTextUndoCommand c = undoStack[undoState]; |
1061 // ######## |
1078 if (c.command & QTextUndoCommand::Custom) |
1062 // QTextFragment *f = c.fragment_list; |
1079 delete c.custom; |
1063 // while (f) { |
1080 } |
1064 // QTextFragment *n = f->right; |
1081 undoStack.remove(0, undoState); |
1065 // delete f; |
1082 undoStack.resize(undoStack.size() - undoState); |
1066 // f = n; |
1083 undoState = 0; |
1067 // } |
1084 if (emitSignals) |
1068 } else if (c.command & QTextUndoCommand::Custom) { |
1085 emitUndoAvailable(false); |
1069 delete c.custom; |
1086 } else if (stacksToClear == QTextDocument::RedoStack |
1070 } |
1087 && redoCommandsAvailable) { |
1071 } |
1088 for (int i = undoState; i < undoStack.size(); ++i) { |
1072 undoStack.resize(undoState); |
1089 QTextUndoCommand c = undoStack[i]; |
|
1090 if (c.command & QTextUndoCommand::Custom) |
|
1091 delete c.custom; |
|
1092 } |
|
1093 undoStack.resize(undoState); |
|
1094 if (emitSignals) |
|
1095 emitRedoAvailable(false); |
|
1096 } else if (stacksToClear == QTextDocument::UndoAndRedoStacks |
|
1097 && !undoStack.isEmpty()) { |
|
1098 for (int i = 0; i < undoStack.size(); ++i) { |
|
1099 QTextUndoCommand c = undoStack[i]; |
|
1100 if (c.command & QTextUndoCommand::Custom) |
|
1101 delete c.custom; |
|
1102 } |
|
1103 undoState = 0; |
|
1104 undoStack.resize(0); |
|
1105 if (emitSignals && undoCommandsAvailable) |
|
1106 emitUndoAvailable(false); |
|
1107 if (emitSignals && redoCommandsAvailable) |
|
1108 emitRedoAvailable(false); |
|
1109 } |
1073 } |
1110 } |
1074 |
1111 |
1075 void QTextDocumentPrivate::emitUndoAvailable(bool available) |
1112 void QTextDocumentPrivate::emitUndoAvailable(bool available) |
1076 { |
1113 { |
1077 if (available != wasUndoAvailable) { |
1114 if (available != wasUndoAvailable) { |