diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-08-21 13:08:59 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-08-27 11:48:29 +0000 |
commit | 267eb009ee77dd52a3764a87594f4a7385f26b4f (patch) | |
tree | 2263e893ef60331e4afc026f02f246b3fe497383 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | |
parent | 4dc3582a1ee332bf8b577bb974f29e7692df85e9 (diff) |
QQuickTableView: handle RebuildOption::ViewportOnly
When rebuildOptions have ViewportOnly set, we now let the top-left
item be the same as before (and at the same position as before), and
start rebuilding from there. This will greatly increase performance
if e.g the table has been flicked far down to row 1000 when the
rebuild needs to happen (e.g because the model got a new row).
Change-Id: I30beb34a7beccedff8dc406f9a524119a2893eb3
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
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" |