aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-08-06 11:22:57 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-08-07 21:17:17 +0000
commit13ea1d89f2bc35b878dde10a89dc186d8d0cd8e7 (patch)
tree43fdaeadb043001f23d890341a90e2f7b4432f68 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
parent1b493d992c1876f280e2cade5ea4a92bd4acbf38 (diff)
QQuickTableView: improve draining of reuse pool
It turns out that using a maxTime of 2 when draining the pool was a bit naive. If e.g the width of the table is greater than the height, it starts releasing pooled items to quickly. So change the logic to be more dynamic, and to calculate what the maxTime should be based on the geometry of the table. Change-Id: Ifeed62789575f98cff063f550f45eb54ef312fdb Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index b4c672e5e2..7418189ee1 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -117,6 +117,7 @@ private slots:
void dataChangedSignal();
void checkIfDelegatesAreReused_data();
void checkIfDelegatesAreReused();
+ void checkIfDelegatesAreReusedAsymmetricTableSize();
void checkContextProperties_data();
void checkContextProperties();
void checkContextPropertiesQQmlListProperyModel_data();
@@ -1226,6 +1227,96 @@ void tst_QQuickTableView::checkIfDelegatesAreReused()
}
}
+void tst_QQuickTableView::checkIfDelegatesAreReusedAsymmetricTableSize()
+{
+ // Check that we end up reusing all delegate items while flicking, also if the table contain
+ // more columns than rows. In that case, if we flick out a whole row, we'll move a lot of
+ // items into the pool. And if we then start flicking in columns, we'll only reuse a few of
+ // them for each column. Still, we don't want the pool to release the superfluous items after
+ // each load, since they are still in circulation and will be needed once we flick in a new
+ // row at the end of the test.
+ LOAD_TABLEVIEW("countingtableview.qml");
+
+ const int pageFlickCount = 3;
+ const int columnCount = 20;
+ const int rowCount = 2;
+ const qreal delegateWidth = tableView->width() / columnCount;
+ const qreal delegateHeight = (tableView->height() / rowCount) + 10;
+
+ auto model = TestModelAsVariant(100, 100);
+ tableView->setModel(model);
+
+ // Let the height of each row be much bigger than the width of each column.
+ view->rootObject()->setProperty("delegateWidth", delegateWidth);
+ view->rootObject()->setProperty("delegateHeight", delegateHeight);
+
+ WAIT_UNTIL_POLISHED;
+
+ auto initialTopLeftItem = tableViewPrivate->loadedTableItem(QPoint(0, 0))->item;
+ QVERIFY(initialTopLeftItem);
+ int pooledCount = initialTopLeftItem->property("pooledCount").toInt();
+ int reusedCount = initialTopLeftItem->property("reusedCount").toInt();
+ QCOMPARE(pooledCount, 0);
+ QCOMPARE(reusedCount, 0);
+
+ // Flick half an item left+down, to force one extra row and column to load. By doing
+ // so, we force the maximum number of rows and columns to show before we start the test.
+ // This will make things less complicated below, when checking how many
+ // times the items have been reused (all items will then report the same number).
+ tableView->setContentX(delegateWidth * 0.5);
+ tableView->setContentY(delegateHeight * 0.5);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ pooledCount = initialTopLeftItem->property("pooledCount").toInt();
+ reusedCount = initialTopLeftItem->property("reusedCount").toInt();
+ QCOMPARE(pooledCount, 0);
+ QCOMPARE(reusedCount, 0);
+ QCOMPARE(tableViewPrivate->tableModel->poolSize(), 0);
+
+ // Flick one row out of view. This will move one whole row of items into the
+ // pool without reusing them, since no new row is exposed at the bottom.
+ tableView->setContentY(delegateHeight + 1);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ pooledCount = initialTopLeftItem->property("pooledCount").toInt();
+ reusedCount = initialTopLeftItem->property("reusedCount").toInt();
+ QCOMPARE(pooledCount, 1);
+ QCOMPARE(reusedCount, 0);
+ QCOMPARE(tableViewPrivate->tableModel->poolSize(), columnCount + 1);
+
+ const int visibleColumnCount = tableViewPrivate->loadedTable.width();
+ const int delegateCountAfterInit = view->rootObject()->property(kDelegatesCreatedCountProp).toInt();
+
+ // Start flicking in a lot of columns, and check that the created count stays the same
+ for (int column = 1; column <= (visibleColumnCount * pageFlickCount); ++column) {
+ tableView->setContentX((delegateWidth * column) + 1);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ const int delegatesCreatedCount = view->rootObject()->property(kDelegatesCreatedCountProp).toInt();
+ QCOMPARE(delegatesCreatedCount, delegateCountAfterInit);
+ }
+
+ // Finally, flick one row back into view. The pool should still contain
+ // enough items so that we don't have to create any new ones.
+ tableView->setContentY(delegateHeight * 2);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ const int delegatesCreatedCount = view->rootObject()->property(kDelegatesCreatedCountProp).toInt();
+ QCOMPARE(delegatesCreatedCount, delegateCountAfterInit);
+
+ // After we flicked in a new row, we now expect all items
+ // to be visible in the view, effectively making the pool empty.
+ QCOMPARE(tableViewPrivate->tableModel->poolSize(), 0);
+}
+
void tst_QQuickTableView::checkContextProperties_data()
{
QTest::addColumn<QVariant>("model");