From 2869aa5bc5f05db83f0627de6dfe61b9df0a4d9e Mon Sep 17 00:00:00 2001 From: Matt Vogt Date: Mon, 22 Jun 2015 17:40:02 +1000 Subject: ListView/GridView contentHeight should include delayRemove-d items When one or more items are in delayRemove state, the ListView's contentHeight property should include their height. This previously failed if the delayRemove items were at the end of the visibleItems list. Also applies to GridView. Change-Id: Id839e850367a3503123e8ac81dac6ebdccef1a1f Reviewed-by: Martin Jones --- .../quick/qquicklistview/tst_qquicklistview.cpp | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'tests/auto/quick/qquicklistview/tst_qquicklistview.cpp') diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 28025c3090..b25fc5402b 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -242,6 +242,9 @@ private slots: void jsArrayChange(); void objectModel(); + void contentHeightWithDelayRemove(); + void contentHeightWithDelayRemove_data(); + private: template void items(const QUrl &source); template void changed(const QUrl &source); @@ -8063,6 +8066,74 @@ void tst_QQuickListView::objectModel() delete listview; } +void tst_QQuickListView::contentHeightWithDelayRemove_data() +{ + QTest::addColumn("useDelayRemove"); + QTest::addColumn("removeFunc"); + QTest::addColumn("countDelta"); + QTest::addColumn("contentHeightDelta"); + + QTest::newRow("remove without delayRemove") + << false + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with delayRemove") + << true + << QByteArray("takeOne") + << -1 + << qreal(-1 * 100.0); + + QTest::newRow("remove with multiple delayRemove") + << true + << QByteArray("takeThree") + << -3 + << qreal(-3 * 100.0); + + QTest::newRow("clear with delayRemove") + << true + << QByteArray("takeAll") + << -5 + << qreal(-5 * 100.0); +} + +void tst_QQuickListView::contentHeightWithDelayRemove() +{ + QFETCH(bool, useDelayRemove); + QFETCH(QByteArray, removeFunc); + QFETCH(int, countDelta); + QFETCH(qreal, contentHeightDelta); + + QQuickView *window = createView(); + window->setSource(testFileUrl("contentHeightWithDelayRemove.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickListView *listview = window->rootObject()->findChild(); + QTRY_VERIFY(listview != 0); + + const int initialCount(listview->count()); + const int eventualCount(initialCount + countDelta); + + const qreal initialContentHeight(listview->contentHeight()); + const int eventualContentHeight(qRound(initialContentHeight + contentHeightDelta)); + + listview->setProperty("useDelayRemove", useDelayRemove); + QMetaObject::invokeMethod(window->rootObject(), removeFunc.constData()); + QTest::qWait(50); + QCOMPARE(listview->count(), eventualCount); + + if (useDelayRemove) { + QCOMPARE(qRound(listview->contentHeight()), qRound(initialContentHeight)); + QTRY_COMPARE(qRound(listview->contentHeight()), eventualContentHeight); + } else { + QCOMPARE(qRound(listview->contentHeight()), eventualContentHeight); + } + + delete window; +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" -- cgit v1.2.3