diff options
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index 99534ddb50..e5b06051a5 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -130,6 +130,7 @@ private slots: void checkContextPropertiesQQmlListProperyModel(); void checkRowAndColumnChangedButNotIndex(); void checkChangingModelFromDelegate(); + void checkRebuildViewportOnly(); }; tst_QQuickTableView::tst_QQuickTableView() @@ -1666,6 +1667,59 @@ void tst_QQuickTableView::checkChangingModelFromDelegate() QCOMPARE(tableViewPrivate->loadedTable.height(), 3); } +void tst_QQuickTableView::checkRebuildViewportOnly() +{ + // Check that we only rebuild from the current top-left cell + // when you add or remove rows and columns. There should be + // no need to do a rebuild from scratch in such cases. + LOAD_TABLEVIEW("countingtableview.qml"); + + const char *propName = "delegatesCreatedCount"; + const qreal delegateWidth = 100; + const qreal delegateHeight = 50; + + TestModel model(100, 100); + tableView->setModel(QVariant::fromValue(&model)); + + WAIT_UNTIL_POLISHED; + + // Flick to row/column 50, 50 + tableView->setContentX(delegateWidth * 50); + tableView->setContentY(delegateHeight * 50); + + // Set reuse items to false, just to make it easier to + // check the number of items created during a rebuild. + tableView->setReuseItems(false); + const int itemCountBeforeRebuild = tableViewPrivate->loadedItems.count(); + + // Since all cells have the same size, we expect that we end up creating + // the same amount of items that were already showing before, even after + // adding or removing rows and columns. + view->rootObject()->setProperty(propName, 0); + model.insertRow(51); + WAIT_UNTIL_POLISHED; + int countAfterRebuild = view->rootObject()->property(propName).toInt(); + QCOMPARE(countAfterRebuild, itemCountBeforeRebuild); + + view->rootObject()->setProperty(propName, 0); + model.removeRow(51); + WAIT_UNTIL_POLISHED; + countAfterRebuild = view->rootObject()->property(propName).toInt(); + QCOMPARE(countAfterRebuild, itemCountBeforeRebuild); + + view->rootObject()->setProperty(propName, 0); + model.insertColumn(51); + WAIT_UNTIL_POLISHED; + countAfterRebuild = view->rootObject()->property(propName).toInt(); + QCOMPARE(countAfterRebuild, itemCountBeforeRebuild); + + view->rootObject()->setProperty(propName, 0); + model.removeColumn(51); + WAIT_UNTIL_POLISHED; + countAfterRebuild = view->rootObject()->property(propName).toInt(); + QCOMPARE(countAfterRebuild, itemCountBeforeRebuild); +} + QTEST_MAIN(tst_QQuickTableView) #include "tst_qquicktableview.moc" |