diff options
author | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2009-09-25 19:59:12 +0200 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2009-10-06 14:03:18 +0200 |
commit | 0d51611fa524091ddca3c6c11edb0eae8ffe3b02 (patch) | |
tree | 12d7a29651988a017758609208f9ad79cc8cf83d /tests/benchmarks/qtableview | |
parent | 6c14af1cdb02d1d6957ad23ec435e2b95dda5b4a (diff) | |
download | qt4-tools-0d51611fa524091ddca3c6c11edb0eae8ffe3b02.tar.gz |
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/benchmarks/qtableview')
-rw-r--r-- | tests/benchmarks/qtableview/tst_qtableview.cpp | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/tests/benchmarks/qtableview/tst_qtableview.cpp b/tests/benchmarks/qtableview/tst_qtableview.cpp index deeba3fa5b..7247a23b52 100644 --- a/tests/benchmarks/qtableview/tst_qtableview.cpp +++ b/tests/benchmarks/qtableview/tst_qtableview.cpp @@ -75,6 +75,50 @@ 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; + } + + 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; + } + int row_count; int column_count; }; @@ -99,6 +143,14 @@ private slots: void spanDraw(); void spanSelectColumn(); void spanSelectAll(); + void rowInsertion_data(); + void rowInsertion(); + void rowRemoval_data(); + void rowRemoval(); + void columnInsertion_data(); + void columnInsertion(); + void columnRemoval_data(); + void columnRemoval(); private: static inline void spanInit_helper(QTableView *); }; @@ -189,5 +241,127 @@ void tst_QTableView::spanSelectColumn() } } +typedef QVector<QRect> SpanList; +Q_DECLARE_METATYPE(SpanList) + +void spansData() +{ + QTest::addColumn<SpanList>("spans"); + + QTest::newRow("Without spans") + << SpanList(); + + QTest::newRow("With spans") + << (SpanList() + << 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)); +} + +void tst_QTableView::rowInsertion_data() +{ + spansData(); +} + +void tst_QTableView::rowInsertion() +{ + QFETCH(SpanList, spans); + + QtTestTableModel model(10, 10); + QTableView view; + view.setModel(&model); + + foreach (QRect span, spans) + view.setSpan(span.top(), span.left(), span.height(), span.width()); + view.show(); + QTest::qWait(50); + + QBENCHMARK_ONCE { + view.model()->insertRows(0, 2); + view.model()->insertRows(5, 2); + view.model()->insertRows(8, 2); + view.model()->insertRows(12, 2); + } +} + +void tst_QTableView::rowRemoval_data() +{ + spansData(); +} + +void tst_QTableView::rowRemoval() +{ + QFETCH(SpanList, spans); + + QtTestTableModel model(10, 10); + QTableView view; + view.setModel(&model); + + foreach (QRect span, spans) + view.setSpan(span.top(), span.left(), span.height(), span.width()); + view.show(); + QTest::qWait(50); + + QBENCHMARK_ONCE { + view.model()->removeRows(3, 3); + } +} + +void tst_QTableView::columnInsertion_data() +{ + spansData(); +} + +void tst_QTableView::columnInsertion() +{ + QFETCH(SpanList, spans); + + QtTestTableModel model(10, 10); + QTableView view; + view.setModel(&model); + + // Same set as for rowInsertion, just swapping columns and rows. + foreach (QRect span, spans) + view.setSpan(span.left(), span.top(), span.width(), span.height()); + view.show(); + QTest::qWait(50); + + QBENCHMARK_ONCE { + view.model()->insertColumns(0, 2); + view.model()->insertColumns(5, 2); + view.model()->insertColumns(8, 2); + view.model()->insertColumns(12, 2); + } +} + +void tst_QTableView::columnRemoval_data() +{ + spansData(); +} + +void tst_QTableView::columnRemoval() +{ + QFETCH(SpanList, spans); + + QtTestTableModel model(10, 10); + QTableView view; + view.setModel(&model); + + // Same set as for rowRemoval, just swapping columns and rows. + foreach (QRect span, spans) + view.setSpan(span.left(), span.top(), span.width(), span.height()); + view.show(); + QTest::qWait(50); + + QBENCHMARK_ONCE { + view.model()->removeColumns(3, 3); + } +} + QTEST_MAIN(tst_QTableView) #include "tst_qtableview.moc" |