From 42720cb625433cfe33cd6a84829360c34966c32e Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 14 May 2018 10:26:48 +0200 Subject: TableView: remove using a floatingPointMargin The floatingPointMargin was added at an early stage to avoid that we ended up in a locked situation where we loaded and unloaded the same edge continuously without being able to exit the loading loop. This was done wrongly because we didn't take spacing into account in QQuickTableViewPrivate::canLoadTableEdge (spacing was usually one pixel, coincidentally the same as the floatingPointMargin). This has now been fixed in a previous patch, so we can remove the faulty floatingPointMargin as well. Change-Id: I3caa7808298a1954a3c02f609bad98c3c2c2426a Reviewed-by: Mitch Curtis --- .../quick/qquicktableview/tst_qquicktableview.cpp | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp') diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index e18ed88348..0063d15434 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -93,6 +93,8 @@ private slots: void checkTableMargins(); void fillTableViewButNothingMore_data(); void fillTableViewButNothingMore(); + void flick_data(); + void flick(); }; tst_QQuickTableView::tst_QQuickTableView() @@ -407,6 +409,70 @@ void tst_QQuickTableView::fillTableViewButNothingMore() QCOMPARE(actualRows, expectedRows); } +void tst_QQuickTableView::flick_data() +{ + QTest::addColumn("spacing"); + QTest::addColumn("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::flick() +{ + // Check that if we end up with the correct start and end column/row as we flick around + // with different table configurations. + QFETCH(QSizeF, spacing); + QFETCH(QMarginsF, margins); + LOAD_TABLEVIEW("plaintableview.qml"); + + const qreal delegateWidth = 100; + const qreal delegateHeight = 50; + const int visualColumnCount = 4; + const int visualRowCount = 4; + const qreal cellWidth = delegateWidth + spacing.width(); + const qreal cellHeight = delegateHeight + spacing.height(); + auto model = TestModelAsVariant(100, 100); + + 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(margins.left() + (visualColumnCount * cellWidth) - spacing.width()); + tableView->setHeight(margins.top() + (visualRowCount * cellHeight) - spacing.height()); + + WAIT_UNTIL_POLISHED; + + // Check the "simple" case if the cells never lands egde-to-edge with the viewport. For + // that case we only accept that visible row/columns are loaded. + qreal flickValues[] = {0.5, 1.5, 4.5, 20.5, 10.5, 3.5, 1.5, 0.5}; + + for (qreal cellsToFlick : flickValues) { + // Flick to the beginning of the cell + tableView->setContentX(cellsToFlick * cellWidth); + tableView->setContentY(cellsToFlick * cellHeight); + tableView->polish(); + + WAIT_UNTIL_POLISHED; + + const QRect loadedTable = tableViewPrivate->loadedTable; + + const int expectedTableLeft = cellsToFlick - int((margins.left() + spacing.width()) / cellWidth); + const int expectedTableTop = cellsToFlick - int((margins.top() + spacing.height()) / cellHeight); + + QCOMPARE(loadedTable.left(), expectedTableLeft); + QCOMPARE(loadedTable.right(), expectedTableLeft + visualColumnCount); + QCOMPARE(loadedTable.top(), expectedTableTop); + QCOMPARE(loadedTable.bottom(), expectedTableTop + visualRowCount); + } +} + QTEST_MAIN(tst_QQuickTableView) #include "tst_qquicktableview.moc" -- cgit v1.2.3