aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-05-15 13:48:36 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-05-16 06:41:44 +0000
commitf61a49efa2172dda996f33a7420b81fe33ad1692 (patch)
treeacec68962bf623d25e3ac24fec68319bea396db2 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
parentf1049d45bf85c09bff7deceda5ba8655792260ef (diff)
TableView: ensure we don't update viewport rect while loading edges
Flickable will change the viewport recursively while we're loading/unloading rows/columns. This will confuse TableView and might cause it to freeze. The correct time to update the internal viewport rect is from inside updatePolish(), where we have better control over the current state. Change-Id: I94f964b8b0f6920ffe31cedd7a461f3853998be3 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.cpp144
1 files changed, 144 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 0063d15434..16a13707d2 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -95,6 +95,8 @@ private slots:
void fillTableViewButNothingMore();
void flick_data();
void flick();
+ void flickOvershoot_data();
+ void flickOvershoot();
};
tst_QQuickTableView::tst_QQuickTableView()
@@ -473,6 +475,148 @@ void tst_QQuickTableView::flick()
}
}
+void tst_QQuickTableView::flickOvershoot_data()
+{
+ QTest::addColumn<QSizeF>("spacing");
+ QTest::addColumn<QMarginsF>("margins");
+
+ QTest::newRow("s:0 m:0") << QSizeF(0, 0) << QMarginsF(0, 0, 0, 0);
+ QTest::newRow("s:5 m:0") << QSizeF(5, 5) << QMarginsF(0, 0, 0, 0);
+ QTest::newRow("s:0 m:20") << QSizeF(0, 0) << QMarginsF(20, 20, 20, 20);
+ QTest::newRow("s:5 m:20") << QSizeF(5, 5) << QMarginsF(20, 20, 20, 20);
+}
+
+void tst_QQuickTableView::flickOvershoot()
+{
+ // Flick the table completely out and then in again, and see
+ // that we still contains the expected rows/columns
+ // Note that TableView always keeps top-left item loaded, even
+ // when everything is flicked out of view.
+ QFETCH(QSizeF, spacing);
+ QFETCH(QMarginsF, margins);
+ LOAD_TABLEVIEW("plaintableview.qml");
+
+ const int rowCount = 5;
+ const int columnCount = 5;
+ const qreal delegateWidth = 100;
+ const qreal delegateHeight = 50;
+ const qreal cellWidth = delegateWidth + spacing.width();
+ const qreal cellHeight = delegateHeight + spacing.height();
+ const qreal tableWidth = margins.left() + margins.right() + (cellWidth * columnCount) - spacing.width();
+ const qreal tableHeight = margins.top() + margins.bottom() + (cellHeight * rowCount) - spacing.height();
+ const int outsideMargin = 10;
+ auto model = TestModelAsVariant(rowCount, columnCount);
+
+ tableView->setModel(model);
+ tableView->setRowSpacing(spacing.height());
+ tableView->setColumnSpacing(spacing.width());
+ tableView->setLeftMargin(margins.left());
+ tableView->setTopMargin(margins.top());
+ tableView->setRightMargin(margins.right());
+ tableView->setBottomMargin(margins.bottom());
+ tableView->setCacheBuffer(0);
+ tableView->setWidth(tableWidth - margins.right() - cellWidth / 2);
+ tableView->setHeight(tableHeight - margins.bottom() - cellHeight / 2);
+
+ WAIT_UNTIL_POLISHED;
+
+ // Flick table out of view left
+ tableView->setContentX(-tableView->width() - outsideMargin);
+ tableView->setContentY(0);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableViewPrivate->loadedTable.left(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.right(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.top(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1);
+
+ // Flick table out of view right
+ tableView->setContentX(tableWidth + outsideMargin);
+ tableView->setContentY(0);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableViewPrivate->loadedTable.left(), columnCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.top(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1);
+
+ // Flick table out of view on top
+ tableView->setContentX(0);
+ tableView->setContentY(-tableView->height() - outsideMargin);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableViewPrivate->loadedTable.left(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.top(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.bottom(), 0);
+
+ // Flick table out of view at the bottom
+ tableView->setContentX(0);
+ tableView->setContentY(tableHeight + outsideMargin);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableViewPrivate->loadedTable.left(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.top(), rowCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1);
+
+ // Flick table out of view left and top at the same time
+ tableView->setContentX(-tableView->width() - outsideMargin);
+ tableView->setContentY(-tableView->height() - outsideMargin);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableViewPrivate->loadedTable.left(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.right(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.top(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.bottom(), 0);
+
+ // Flick table back to origo
+ tableView->setContentX(0);
+ tableView->setContentY(0);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableViewPrivate->loadedTable.left(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.top(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1);
+
+ // Flick table out of view right and bottom at the same time
+ tableView->setContentX(tableWidth + outsideMargin);
+ tableView->setContentY(tableHeight + outsideMargin);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableViewPrivate->loadedTable.left(), columnCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.top(), rowCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1);
+
+ // Flick table back to origo
+ tableView->setContentX(0);
+ tableView->setContentY(0);
+ tableView->polish();
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableViewPrivate->loadedTable.left(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1);
+ QCOMPARE(tableViewPrivate->loadedTable.top(), 0);
+ QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1);
+}
+
QTEST_MAIN(tst_QQuickTableView)
#include "tst_qquicktableview.moc"