aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-09-10 14:22:46 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-09-11 12:37:36 +0000
commit8e5578d3fcb86efad6bcde31a194ebd5009b1d70 (patch)
treea149bc9049b9e6eb9a2efe4263e5bf7781a56de1 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
parent47039ed7fb69b541afd4e81cffe89c8640c5f831 (diff)
QQuickTableView: override fixup() to preserve contentX/Y at start-up
Flickable::fixup() will be called from Flickable::componentComplete(). fixup() is a virtual function that subclasses can override to e.g ensure that cells snap to grid etc (which is not yet supported by TableView). The default implementation will check if the assigned contentX/Y is within the current content item size, and adjust it back to 0,0 if not. The problem is that during componentComplete(), the table has not yet been built. And we don't want Flickable to reset any assignments to contentX/Y until that has happened. So override the function and block it from doing any adjustments before the table has been built. Change-Id: Id6c5a3b5f053f71bf1854573cd5b9dc3ecc9f246 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.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index dfcce6afdb..9eb942fc93 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -594,21 +594,31 @@ void tst_QQuickTableView::checkExplicitContentWidthAndHeight()
void tst_QQuickTableView::checkContentXY()
{
- // Check that you can set contentX and contentY on
- // startup, and that this is respected by TableView
+ // Check that you can bind contentX and contentY to
+ // e.g show the center of the table at start-up
LOAD_TABLEVIEW("setcontentpos.qml");
auto model = TestModelAsVariant(10, 10);
tableView->setModel(model);
WAIT_UNTIL_POLISHED;
- QCOMPARE(tableView->contentX(), 250);
- QCOMPARE(tableView->contentY(), 250);
+ QCOMPARE(tableView->width(), 400);
+ QCOMPARE(tableView->height(), 400);
+ QCOMPARE(tableView->contentWidth(), 1000);
+ QCOMPARE(tableView->contentHeight(), 1000);
- // Since we flick the content item, we expect the
- // loaded table to end up at row/column 2,2
- QCOMPARE(tableViewPrivate->loadedTable.left(), 2);
- QCOMPARE(tableViewPrivate->loadedTable.top(), 2);
+ // Check that the content item is positioned according
+ // to the binding in the QML file (which will set the
+ // viewport to be at the center of the table).
+ const qreal expectedXY = (tableView->contentWidth() - tableView->width()) / 2;
+ QCOMPARE(tableView->contentX(), expectedXY);
+ QCOMPARE(tableView->contentY(), expectedXY);
+
+ // Check that we end up at the correct top-left cell:
+ const qreal delegateWidth = tableViewPrivate->loadedItems.values().first()->item->width();
+ const int expectedCellXY = qCeil(expectedXY / delegateWidth);
+ QCOMPARE(tableViewPrivate->loadedTable.left(), expectedCellXY);
+ QCOMPARE(tableViewPrivate->loadedTable.top(), expectedCellXY);
}
void tst_QQuickTableView::noDelegate()