summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorC. Boemann <cbo@boemann.dk>2011-12-10 05:15:38 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-09 23:09:40 +0100
commit1222da803ad5d9393956f7fa0e6716bd54da5f36 (patch)
tree785f6f9e957af3ee6924c846aa050cd0f0f06d1d /tests/auto
parent1ee9c0925b5aa99113fff9b9483868290cf921ae (diff)
Make sure cursor navigation in qtexttable works like user expects
Before the selection of cells NW of anchor showed some defects where cells would not be selected as the user expects Change-Id: Ia2b63f11b8d534e918ffb97b76339d60f1ca0389 Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp134
1 files changed, 127 insertions, 7 deletions
diff --git a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp
index ca0feec2bf..09b9a06a1d 100644
--- a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp
+++ b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp
@@ -872,27 +872,147 @@ void tst_QTextCursor::tableMovement()
void tst_QTextCursor::selectionsInTable()
{
- QTextTable *table = cursor.insertTable(2, 2);
- table->cellAt(0, 0).firstCursorPosition().insertText("First");
- table->cellAt(0, 1).firstCursorPosition().insertText("Second");
- table->cellAt(1, 0).firstCursorPosition().insertText("Third");
- table->cellAt(1, 1).firstCursorPosition().insertText("Fourth");
+ QTextTable *table = cursor.insertTable(3, 3);
+ table->cellAt(0, 0).firstCursorPosition().insertText("A a"); // first = 1
+ table->cellAt(0, 1).firstCursorPosition().insertText("B b"); // first = 5
+ table->cellAt(0, 2).firstCursorPosition().insertText("C c"); // first = 9
+ table->cellAt(1, 0).firstCursorPosition().insertText("D d"); // first = 13
+ table->cellAt(1, 1).firstCursorPosition().insertText("E e"); // first = 17
+ table->cellAt(1, 2).firstCursorPosition().insertText("F f"); // first = 21
+ table->cellAt(2, 0).firstCursorPosition().insertText("G g"); // first = 25
+ table->cellAt(2, 1).firstCursorPosition().insertText("H h"); // first = 29
+ table->cellAt(2, 2).firstCursorPosition().insertText("I i"); // first = 33
cursor = table->cellAt(0, 0).lastCursorPosition();
+ QCOMPARE(cursor.position(), 4);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor));
QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor));
QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor) == false);
+ QCOMPARE(cursor.position(), 1);
cursor = table->cellAt(1, 0).lastCursorPosition();
+ QCOMPARE(cursor.position(), 16);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor));
QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor));
QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor) == false);
+ QCOMPARE(cursor.position(), 13);
- cursor = table->cellAt(0, 1).firstCursorPosition();
+ cursor = table->cellAt(0, 2).firstCursorPosition();
+ QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor));
QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor));
QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor) == false);
- cursor = table->cellAt(1, 1).firstCursorPosition();
+ cursor = table->cellAt(1, 2).firstCursorPosition();
+ QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor));
QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor));
QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor) == false);
+
+ // Next let's test selecting entire cells one at a time
+ cursor = table->cellAt(0, 0).firstCursorPosition();
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 5);
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 9);
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 13);
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 17);
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 21);
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 25);
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 29);
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 33);
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor) == false);
+
+ // And now lets walk all the way back
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 29);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 25);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 21);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 17);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 13);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 9);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 5);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 1);
+ QVERIFY(cursor.movePosition(QTextCursor::PreviousCell, QTextCursor::KeepAnchor) == false);
+
+ QTextCursor::MoveOperation leftMovements[5] = {
+ QTextCursor::PreviousBlock
+ , QTextCursor::PreviousCharacter
+ , QTextCursor::PreviousWord
+ , QTextCursor::Left
+ , QTextCursor::WordLeft
+ };
+
+ QTextCursor::MoveOperation rightMovements[5] = {
+ QTextCursor::NextBlock
+ , QTextCursor::NextCharacter
+ , QTextCursor::NextWord
+ , QTextCursor::Right
+ , QTextCursor::WordRight
+ };
+
+ for (int i = 0; i < 5; ++i) {
+ QTextCursor::MoveOperation left = leftMovements[i];
+ QTextCursor::MoveOperation right = rightMovements[i];
+
+ // Lets walk circle around anchor placed at 1,1 using up, down, left and right
+ cursor = table->cellAt(1, 1).firstCursorPosition();
+ QCOMPARE(cursor.position(), 17);
+ QVERIFY(cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 18); // First right should not jump more than one char
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 21); // Lets jump to the next cell
+ QVERIFY(cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 33);
+ QVERIFY(cursor.movePosition(left, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 29);
+ QVERIFY(cursor.movePosition(left, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 25);
+ QVERIFY(cursor.movePosition(QTextCursor::Up, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 13);
+ QVERIFY(cursor.movePosition(QTextCursor::Up, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 1);
+ QVERIFY(cursor.movePosition(right, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 5);
+ QVERIFY(cursor.movePosition(right, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 9);
+ QVERIFY(cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 21);
+
+ // Lets walk to the side 2 cells and back, first right
+ cursor = table->cellAt(0, 0).firstCursorPosition();
+ QVERIFY(cursor.movePosition(QTextCursor::NextCell, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 5); // Lets jump to the next cell
+ QVERIFY(cursor.movePosition(right, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 9);
+ QVERIFY(cursor.movePosition(left, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 5);
+ QVERIFY(cursor.movePosition(left, QTextCursor::KeepAnchor));
+ QVERIFY(cursor.position() < 5);
+
+ // Then left
+ cursor = table->cellAt(0, 2).firstCursorPosition();
+ QCOMPARE(cursor.position(), 9);
+ QVERIFY(cursor.movePosition(left, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 5); // A single left should do
+ QVERIFY(cursor.movePosition(left, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 1);
+ QVERIFY(cursor.movePosition(right, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 5);
+ QVERIFY(cursor.movePosition(right, QTextCursor::KeepAnchor));
+ QCOMPARE(cursor.position(), 9);
+ }
}
void tst_QTextCursor::selectedText()