46 #include <qtextdocument.h> |
46 #include <qtextdocument.h> |
47 #include <qtextdocumentfragment.h> |
47 #include <qtextdocumentfragment.h> |
48 #include <qtexttable.h> |
48 #include <qtexttable.h> |
49 #include <qdebug.h> |
49 #include <qdebug.h> |
50 #include <qtextcursor.h> |
50 #include <qtextcursor.h> |
|
51 #include <qtextdocument.h> |
|
52 #include <qtextedit.h> |
51 |
53 |
52 //TESTED_FILES= |
54 //TESTED_FILES= |
|
55 |
|
56 typedef QList<int> IntList; |
|
57 Q_DECLARE_METATYPE(IntList) |
53 |
58 |
54 QT_FORWARD_DECLARE_CLASS(QTextDocument) |
59 QT_FORWARD_DECLARE_CLASS(QTextDocument) |
55 |
60 |
56 class tst_QTextTable : public QObject |
61 class tst_QTextTable : public QObject |
57 { |
62 { |
91 void removeColumns1(); |
97 void removeColumns1(); |
92 void removeColumns2(); |
98 void removeColumns2(); |
93 void removeColumns3(); |
99 void removeColumns3(); |
94 void removeColumns4(); |
100 void removeColumns4(); |
95 void removeColumns5(); |
101 void removeColumns5(); |
|
102 void removeColumnsInTableWithMergedRows(); |
|
103 void QTBUG11282_insertBeforeMergedEnding_data(); |
|
104 void QTBUG11282_insertBeforeMergedEnding(); |
96 |
105 |
97 private: |
106 private: |
98 QTextTable *create2x2Table(); |
107 QTextTable *create2x2Table(); |
99 QTextTable *create4x4Table(); |
108 QTextTable *create4x4Table(); |
100 |
109 |
582 // should do nothing |
591 // should do nothing |
583 table->mergeCells(0, 0, 1, 2); |
592 table->mergeCells(0, 0, 1, 2); |
584 |
593 |
585 QVERIFY(table->cellAt(0, 0) != table->cellAt(0, 1)); |
594 QVERIFY(table->cellAt(0, 0) != table->cellAt(0, 1)); |
586 QVERIFY(table->cellAt(0, 1) == table->cellAt(1, 1)); |
595 QVERIFY(table->cellAt(0, 1) == table->cellAt(1, 1)); |
|
596 } |
|
597 |
|
598 void tst_QTextTable::mergeAndInsert() |
|
599 { |
|
600 QTextTable *table = cursor.insertTable(4,3); |
|
601 table->mergeCells(0,1,3,2); |
|
602 table->mergeCells(3,0,1,3); |
|
603 //Don't crash ! |
|
604 table->insertColumns(1,2); |
|
605 QCOMPARE(table->columns(), 5); |
587 } |
606 } |
588 |
607 |
589 void tst_QTextTable::splitCells() |
608 void tst_QTextTable::splitCells() |
590 { |
609 { |
591 QTextTable *table = create4x4Table(); |
610 QTextTable *table = create4x4Table(); |
929 QCOMPARE(table->cellAt(3, 0).firstPosition(), 7); |
948 QCOMPARE(table->cellAt(3, 0).firstPosition(), 7); |
930 QCOMPARE(table->cellAt(3, 1).firstPosition(), 10); |
949 QCOMPARE(table->cellAt(3, 1).firstPosition(), 10); |
931 QCOMPARE(table->cellAt(3, 2).firstPosition(), 11); |
950 QCOMPARE(table->cellAt(3, 2).firstPosition(), 11); |
932 } |
951 } |
933 |
952 |
|
953 void tst_QTextTable::removeColumnsInTableWithMergedRows() |
|
954 { |
|
955 QTextTable *table = cursor.insertTable(3, 4); |
|
956 table->mergeCells(0, 0, 1, 4); |
|
957 QCOMPARE(table->rows(), 3); |
|
958 QCOMPARE(table->columns(), 4); |
|
959 |
|
960 table->removeColumns(0, table->columns() - 1); |
|
961 |
|
962 QCOMPARE(table->rows(), 3); |
|
963 QCOMPARE(table->columns(), 1); |
|
964 } |
|
965 |
|
966 void tst_QTextTable::QTBUG11282_insertBeforeMergedEnding_data() |
|
967 { |
|
968 QTest::addColumn<int>("rows"); |
|
969 QTest::addColumn<int>("columns"); |
|
970 QTest::addColumn<QList<int> >("merge"); |
|
971 QTest::addColumn<QList<int> >("insert"); |
|
972 |
|
973 QTest::newRow("2x3, merge two, insert one") << 2 << 3 << (QList<int>() << 1 << 2 << 2) |
|
974 << (QList<int>() << 1 << 1) ; |
|
975 QTest::newRow("3x4, merge three, insert one") << 3 << 4 << (QList<int>() << 1 << 3 << 3) |
|
976 << (QList<int>() << 1 << 1) ; |
|
977 QTest::newRow("4x3, merge two, insert two") << 4 << 3 << (QList<int>() << 1 << 4 << 2) |
|
978 << (QList<int>() << 1 << 2) ; |
|
979 QTest::newRow("4x4, merge middle two, insert one") << 4 << 4 << (QList<int>() << 1 << 4 << 2) |
|
980 << (QList<int>() << 1 << 1) ; |
|
981 } |
|
982 |
|
983 void tst_QTextTable::QTBUG11282_insertBeforeMergedEnding() |
|
984 { |
|
985 QFETCH(int, rows); |
|
986 QFETCH(int, columns); |
|
987 QFETCH(QList<int>, merge); |
|
988 QFETCH(QList<int>, insert); |
|
989 QTextTable *table = cursor.insertTable(rows, columns); |
|
990 QTextEdit *textEdit = new QTextEdit; |
|
991 textEdit->setDocument(doc); |
|
992 textEdit->show(); |
|
993 QTest::qWaitForWindowShown(textEdit); |
|
994 table->mergeCells(0,merge.at(0), merge.at(1), merge.at(2)); |
|
995 //Don't crash ! |
|
996 table->insertColumns(insert.at(0), insert.at(1)); |
|
997 //Check that the final size is what we expected |
|
998 QCOMPARE(table->rows(), rows); |
|
999 QCOMPARE(table->columns(), columns + insert.at(1)); |
|
1000 delete textEdit; |
|
1001 } |
|
1002 |
934 QTEST_MAIN(tst_QTextTable) |
1003 QTEST_MAIN(tst_QTextTable) |
935 #include "tst_qtexttable.moc" |
1004 #include "tst_qtexttable.moc" |