summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtableview
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-09-25 19:59:12 +0200
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2009-10-06 14:03:18 +0200
commit0d51611fa524091ddca3c6c11edb0eae8ffe3b02 (patch)
tree12d7a29651988a017758609208f9ad79cc8cf83d /tests/auto/qtableview
parent6c14af1cdb02d1d6957ad23ec435e2b95dda5b4a (diff)
Span update after row and column insertion and removal in QTableView.
The feature had not been implemented yet. Auto-test and benchmark included. As a bonus, single cell spans are no longer added to the span collection. Reviewed-by: Thierry Task-number: 245327 Task-number: QTBUG-3610
Diffstat (limited to 'tests/auto/qtableview')
-rw-r--r--tests/auto/qtableview/tst_qtableview.cpp193
1 files changed, 192 insertions, 1 deletions
diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp
index deb0b71050..4bf7c2e2cb 100644
--- a/tests/auto/qtableview/tst_qtableview.cpp
+++ b/tests/auto/qtableview/tst_qtableview.cpp
@@ -164,6 +164,10 @@ private slots:
void span();
void spans();
void spans_data();
+ void spansAfterRowInsertion();
+ void spansAfterColumnInsertion();
+ void spansAfterRowRemoval();
+ void spansAfterColumnRemoval();
void checkHeaderReset();
void checkHeaderMinSize();
@@ -268,6 +272,28 @@ public:
return QVariant();
}
+ bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex())
+ {
+ if (start < 0 || start > row_count)
+ return false;
+
+ beginInsertRows(parent, start, start + count - 1);
+ row_count += count;
+ endInsertRows();
+ return true;
+ }
+
+ bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex())
+ {
+ if (start < 0 || start >= row_count || row_count < count)
+ return false;
+
+ beginRemoveRows(parent, start, start + count - 1);
+ row_count -= count;
+ endRemoveRows();
+ return true;
+ }
+
void removeLastRow()
{
beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1);
@@ -282,6 +308,28 @@ public:
endRemoveRows();
}
+ bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex())
+ {
+ if (start < 0 || start > column_count)
+ return false;
+
+ beginInsertColumns(parent, start, start + count - 1);
+ column_count += count;
+ endInsertColumns();
+ return true;
+ }
+
+ bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex())
+ {
+ if (start < 0 || start >= column_count || column_count < count)
+ return false;
+
+ beginRemoveColumns(parent, start, start + count - 1);
+ column_count -= count;
+ endRemoveColumns();
+ return true;
+ }
+
void removeLastColumn()
{
beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1);
@@ -2608,7 +2656,7 @@ void tst_QTableView::span_data()
<< -1 << -1
<< 6 << 6
<< 3 << 3
- << 3 << 3
+ << 2 << 3
<< true;
}
@@ -2797,6 +2845,149 @@ void tst_QTableView::spans()
QCOMPARE(view.rowSpan(pos.x(), pos.y()), expectedRowSpan);
}
+void tst_QTableView::spansAfterRowInsertion()
+{
+ QtTestTableModel model(10, 10);
+ QtTestTableView view;
+ view.setModel(&model);
+ view.setSpan(3, 3, 3, 3);
+ view.show();
+ QTest::qWait(50);
+
+ // Insertion before the span only shifts the span.
+ view.model()->insertRows(0, 2);
+ QCOMPARE(view.rowSpan(3, 3), 1);
+ QCOMPARE(view.columnSpan(3, 3), 1);
+ QCOMPARE(view.rowSpan(5, 3), 3);
+ QCOMPARE(view.columnSpan(5, 3), 3);
+
+ // Insertion happens before the given row, so it only shifts the span also.
+ view.model()->insertRows(5, 2);
+ QCOMPARE(view.rowSpan(5, 3), 1);
+ QCOMPARE(view.columnSpan(5, 3), 1);
+ QCOMPARE(view.rowSpan(7, 3), 3);
+ QCOMPARE(view.columnSpan(7, 3), 3);
+
+ // Insertion inside the span expands it.
+ view.model()->insertRows(8, 2);
+ QCOMPARE(view.rowSpan(7, 3), 5);
+ QCOMPARE(view.columnSpan(7, 3), 3);
+
+ // Insertion after the span does nothing to it.
+ view.model()->insertRows(12, 2);
+ QCOMPARE(view.rowSpan(7, 3), 5);
+ QCOMPARE(view.columnSpan(7, 3), 3);
+}
+
+void tst_QTableView::spansAfterColumnInsertion()
+{
+ QtTestTableModel model(10, 10);
+ QtTestTableView view;
+ view.setModel(&model);
+ view.setSpan(3, 3, 3, 3);
+ view.show();
+ QTest::qWait(50);
+
+ // Insertion before the span only shifts the span.
+ view.model()->insertColumns(0, 2);
+ QCOMPARE(view.rowSpan(3, 3), 1);
+ QCOMPARE(view.columnSpan(3, 3), 1);
+ QCOMPARE(view.rowSpan(3, 5), 3);
+ QCOMPARE(view.columnSpan(3, 5), 3);
+
+ // Insertion happens before the given column, so it only shifts the span also.
+ view.model()->insertColumns(5, 2);
+ QCOMPARE(view.rowSpan(3, 5), 1);
+ QCOMPARE(view.columnSpan(3, 5), 1);
+ QCOMPARE(view.rowSpan(3, 7), 3);
+ QCOMPARE(view.columnSpan(3, 7), 3);
+
+ // Insertion inside the span expands it.
+ view.model()->insertColumns(8, 2);
+ QCOMPARE(view.rowSpan(3, 7), 3);
+ QCOMPARE(view.columnSpan(3, 7), 5);
+
+ // Insertion after the span does nothing to it.
+ view.model()->insertColumns(12, 2);
+ QCOMPARE(view.rowSpan(3, 7), 3);
+ QCOMPARE(view.columnSpan(3, 7), 5);
+}
+
+void tst_QTableView::spansAfterRowRemoval()
+{
+ QtTestTableModel model(10, 10);
+ QtTestTableView view;
+ view.setModel(&model);
+
+ QList<QRect> spans;
+ spans << QRect(0, 1, 1, 2)
+ << QRect(1, 2, 1, 2)
+ << QRect(2, 2, 1, 5)
+ << QRect(2, 8, 1, 2)
+ << QRect(3, 4, 1, 2)
+ << QRect(4, 4, 1, 4)
+ << QRect(5, 6, 1, 3)
+ << QRect(6, 7, 1, 3);
+ foreach (QRect span, spans)
+ view.setSpan(span.top(), span.left(), span.height(), span.width());
+
+ view.show();
+ QTest::qWait(100);
+ view.model()->removeRows(3, 3);
+
+ QList<QRect> expectedSpans;
+ expectedSpans << QRect(0, 1, 1, 2)
+ << QRect(1, 2, 1, 1)
+ << QRect(2, 2, 1, 2)
+ << QRect(2, 5, 1, 2)
+ << QRect(3, 4, 1, 1)
+ << QRect(4, 3, 1, 2)
+ << QRect(5, 3, 1, 3)
+ << QRect(6, 4, 1, 3);
+ foreach (QRect span, expectedSpans) {
+ QCOMPARE(view.columnSpan(span.top(), span.left()), span.width());
+ QCOMPARE(view.rowSpan(span.top(), span.left()), span.height());
+ }
+}
+
+void tst_QTableView::spansAfterColumnRemoval()
+{
+ QtTestTableModel model(10, 10);
+ QtTestTableView view;
+ view.setModel(&model);
+
+ // Same set as above just swapping columns and rows.
+ QList<QRect> spans;
+ spans << QRect(0, 1, 1, 2)
+ << QRect(1, 2, 1, 2)
+ << QRect(2, 2, 1, 5)
+ << QRect(2, 8, 1, 2)
+ << QRect(3, 4, 1, 2)
+ << QRect(4, 4, 1, 4)
+ << QRect(5, 6, 1, 3)
+ << QRect(6, 7, 1, 3);
+ foreach (QRect span, spans)
+ view.setSpan(span.left(), span.top(), span.width(), span.height());
+
+ view.show();
+ QTest::qWait(100);
+ view.model()->removeColumns(3, 3);
+
+ QList<QRect> expectedSpans;
+ expectedSpans << QRect(0, 1, 1, 2)
+ << QRect(1, 2, 1, 1)
+ << QRect(2, 2, 1, 2)
+ << QRect(2, 5, 1, 2)
+ << QRect(3, 4, 1, 1)
+ << QRect(4, 3, 1, 2)
+ << QRect(5, 3, 1, 3)
+ << QRect(6, 4, 1, 3);
+ foreach (QRect span, expectedSpans) {
+ QCOMPARE(view.columnSpan(span.left(), span.top()), span.height());
+ QCOMPARE(view.rowSpan(span.left(), span.top()), span.width());
+ }
+}
+
class Model : public QAbstractTableModel {
Q_OBJECT