diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-05-14 10:26:48 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-05-15 07:45:31 +0000 |
commit | 42720cb625433cfe33cd6a84829360c34966c32e (patch) | |
tree | bafd89c7e69f3bf1c64e24d49a3a364bb827eac7 /tests/auto/quick | |
parent | 9f20a3155c9c3378d0cd4a712808c94d02d4561c (diff) |
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 <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r-- | tests/auto/quick/qquicktableview/data/plaintableview.qml | 6 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 66 |
2 files changed, 70 insertions, 2 deletions
diff --git a/tests/auto/quick/qquicktableview/data/plaintableview.qml b/tests/auto/quick/qquicktableview/data/plaintableview.qml index ced07451b0..905c1e528e 100644 --- a/tests/auto/quick/qquicktableview/data/plaintableview.qml +++ b/tests/auto/quick/qquicktableview/data/plaintableview.qml @@ -43,13 +43,14 @@ import Qt.labs.tableview 1.0 Item { width: 640 - height: 480 + height: 450 property alias tableView: tableView TableView { id: tableView - anchors.fill: parent + width: 600 + height: 400 anchors.margins: 1 clip: true delegate: tableViewDelegate @@ -65,6 +66,7 @@ Item { implicitWidth: 100 implicitHeight: 50 color: "lightgray" + border.width: 1 Text { anchors.centerIn: parent text: modelData 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<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::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" |