summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtextdocument/tst_qtextdocument.cpp
diff options
context:
space:
mode:
authormae <qt-info@nokia.com>2009-09-24 10:31:51 (GMT)
committermae <qt-info@nokia.com>2009-09-24 10:33:20 (GMT)
commit06aa9b6704637864130e318e8700f1b0b4f8a5e3 (patch)
treef2140e2d31b62570bcd278a088670bbc9cf87234 /tests/auto/qtextdocument/tst_qtextdocument.cpp
parent135e02d11becc8ee434524756d85221244c185ee (diff)
downloadQt-06aa9b6704637864130e318e8700f1b0b4f8a5e3.zip
Qt-06aa9b6704637864130e318e8700f1b0b4f8a5e3.tar.gz
Qt-06aa9b6704637864130e318e8700f1b0b4f8a5e3.tar.bz2
Fix QTextDocument::revision()
The revision was bound to the current depth of the undo stack. This had the negative side effect, that equal revisions could point to different documents, and sometimes changes would not even increase the revision (in the case of undo command merging). Reviewed-by: Roberto Raggi
Diffstat (limited to 'tests/auto/qtextdocument/tst_qtextdocument.cpp')
-rw-r--r--tests/auto/qtextdocument/tst_qtextdocument.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp
index 323df58..c0d7ed3 100644
--- a/tests/auto/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp
@@ -168,6 +168,7 @@ private slots:
void characterAt();
void revisions();
+ void revisionWithUndoCompressionAndUndo();
void testUndoCommandAdded();
@@ -2499,6 +2500,44 @@ void tst_QTextDocument::revisions()
QCOMPARE(cursor.block().revision(), 5);
}
+void tst_QTextDocument::revisionWithUndoCompressionAndUndo()
+{
+ QTextDocument doc;
+ QTextCursor cursor(&doc);
+ cursor.insertText("This is the beginning of it all.");
+ QCOMPARE(doc.firstBlock().revision(), 1);
+ QCOMPARE(doc.revision(), 1);
+ cursor.insertBlock();
+ QCOMPARE(doc.revision(), 2);
+ cursor.insertText("this");
+ QCOMPARE(doc.revision(), 3);
+ cursor.insertText("is");
+ QCOMPARE(doc.revision(), 4);
+ cursor.insertText("compressed");
+ QCOMPARE(doc.revision(), 5);
+ doc.undo();
+ QCOMPARE(doc.revision(), 6);
+ QCOMPARE(doc.toPlainText(), QString("This is the beginning of it all.\n")) ;
+ cursor.setPosition(0);
+ QCOMPARE(doc.firstBlock().revision(), 1);
+ cursor.insertText("Very beginnig");
+ QCOMPARE(doc.firstBlock().revision(), 7);
+ doc.undo();
+ QCOMPARE(doc.revision(), 8);
+ QCOMPARE(doc.firstBlock().revision(), 1);
+
+ cursor.beginEditBlock();
+ cursor.insertText("Hello");
+ cursor.insertBlock();
+ cursor.insertText("world");
+ cursor.endEditBlock();
+ QCOMPARE(doc.revision(), 9);
+ doc.undo();
+ QCOMPARE(doc.revision(), 10);
+
+
+}
+
void tst_QTextDocument::testUndoCommandAdded()
{
QVERIFY(doc);