diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2017-12-13 16:16:44 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-01-10 18:41:07 +0000 |
commit | ddf495fb81ea89173af3310f50314b177bc866d2 (patch) | |
tree | 2a4ef827c02960c5b54c398769059798f94869fa /tests/auto/quick/qquickgridview/tst_qquickgridview.cpp | |
parent | cee8c21efada48c6f1ce9e0359170edbf334cec3 (diff) |
GridView: Fix an off-by-one offset of positioning of items
The block for finding the position for the item *before* needs to be
applied for the case where visibleItems is empty too, so we separate it
out.
Change-Id: I60a7e3a44d01a0087970e37bf4e73b94da5ebd48
Task-number: QTBUG-49218
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickgridview/tst_qquickgridview.cpp')
-rw-r--r-- | tests/auto/quick/qquickgridview/tst_qquickgridview.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 388ecc2ab8..e271cc1d7b 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -210,6 +210,7 @@ private slots: void contentHeightWithDelayRemove(); void QTBUG_45640(); + void QTBUG_49218(); void QTBUG_48870_fastModelUpdates(); void keyNavigationEnabled(); @@ -6629,6 +6630,36 @@ void tst_QQuickGridView::QTBUG_45640() delete window; } +void tst_QQuickGridView::QTBUG_49218() +{ + QQuickView *window = createView(); + window->setSource(testFileUrl("qtbug49218.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickItem *rootItem = qobject_cast<QQuickItem*>(window->rootObject()); + QQuickGridView *gridview = qobject_cast<QQuickGridView *>(rootItem->childItems().first()); + QVERIFY(gridview != 0); + + auto processEventsAndForceLayout = [&gridview] () { + for (int pass = 0; pass < 2; ++pass) { + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); + gridview->forceLayout(); + } + }; + QMetaObject::invokeMethod(rootItem, "scrollToTop"); + processEventsAndForceLayout(); + QMetaObject::invokeMethod(rootItem, "changeModel"); + processEventsAndForceLayout(); + QMetaObject::invokeMethod(rootItem, "changeModel"); + processEventsAndForceLayout(); + QMetaObject::invokeMethod(rootItem, "scrollToTop"); + processEventsAndForceLayout(); + + QCOMPARE(gridview->indexAt(gridview->cellWidth() - 10, gridview->cellHeight() - 10), 0); + delete window; +} + void tst_QQuickGridView::keyNavigationEnabled() { QScopedPointer<QQuickView> window(createView()); |