diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-09-10 15:35:09 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-09-11 12:37:29 +0000 |
commit | 5b95cc34c15a021b0be37080b29f423144b5e64c (patch) | |
tree | 80748cfdff3a0e089cf884b9cea554edd25398c8 /tests | |
parent | f3daa8bb97bbfc7a309c2bf59de1e41d279e05d1 (diff) |
QQuickTableView: don't rebuild table upon querying content size
Overriding contentWidth/Height was done to be able to force build the
table early if the app needed to know the size of the table already at
Component.onCompleted (to e.g center the viewport on the center of
the table). But now that we have a forceLayout() function, it's better
to require that that function should be called before querying
contentWidth/Height at this stage.
By not building the table on the fly, we allow the application to
bind expressions directly to contentWidth/Height, without being concerned
about potential binding loops that can occur as a result of us
rebuilding the whole table behind his back. The benefit of this overshadows
the need to call forceLayout() explicit for some corner cases.
Note that we still redefine the contentWidth/Height properties in TableView
so that we can catch if the application sets an explicit contentWidth/Height
(which is tested by checkExplicitContentWidthAndHeight()).
Change-Id: Ic4499b3939af1cb3a543e4c006023d0d6f12fd3b
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index c7fd51f72c..dfcce6afdb 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -538,13 +538,14 @@ void tst_QQuickTableView::checkContentWidthAndHeight() tableView->setContentY(flickTo); const int largeSizeCellCountInView = qCeil(tableView->width() / cellSizeLarge); - const int bottomRow = smallCellCount + largeSizeCellCountInView - 1; - QCOMPARE(tableViewPrivate->loadedTable.right(), bottomRow); + const int columnCount = smallCellCount + largeSizeCellCountInView; + QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1); const qreal firstHalfLength = smallCellCount * cellSizeSmall; const qreal secondHalfOneScreenLength = largeSizeCellCountInView * cellSizeLarge; const qreal lengthAfterFlick = firstHalfLength + secondHalfOneScreenLength; - const qreal averageCellSize = lengthAfterFlick / (smallCellCount + largeSizeCellCountInView); + + const qreal averageCellSize = lengthAfterFlick / columnCount; const qreal expectedSizeHalf = (tableSize * averageCellSize) + accumulatedSpacing; QCOMPARE(tableView->contentWidth(), expectedSizeHalf); @@ -580,6 +581,10 @@ void tst_QQuickTableView::checkExplicitContentWidthAndHeight() QCOMPARE(tableView->contentWidth(), 1000); QCOMPARE(tableView->contentHeight(), 1000); + auto model = TestModelAsVariant(100, 100); + tableView->setModel(model); + WAIT_UNTIL_POLISHED; + // Flick somewhere. It should not affect the contentWidth/Height tableView->setContentX(500); tableView->setContentY(500); |