diff options
author | Matt Vogt <matthew.vogt@jollamobile.com> | 2015-06-22 17:40:02 +1000 |
---|---|---|
committer | Matthew Vogt <matthew.vogt@qinetic.com.au> | 2015-06-23 05:27:02 +0000 |
commit | 2869aa5bc5f05db83f0627de6dfe61b9df0a4d9e (patch) | |
tree | 71ac0adbd82d787829a941a18b2ea355847aa5dd /tests/auto/quick/qquickgridview | |
parent | 93c1b8cc6bb7feb922a1cd5d038db6b488745eaa (diff) |
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 <martin.jones@qinetic.com.au>
Diffstat (limited to 'tests/auto/quick/qquickgridview')
-rw-r--r-- | tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml | 47 | ||||
-rw-r--r-- | tests/auto/quick/qquickgridview/tst_qquickgridview.cpp | 71 |
2 files changed, 118 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml b/tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml new file mode 100644 index 0000000000..3f8246bafc --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/contentHeightWithDelayRemove.qml @@ -0,0 +1,47 @@ +import QtQuick 2.1 + +Item { + width: 400 + height: 600 + function takeOne() + { + gridView.model.remove(2) + } + function takeThree() + { + gridView.model.remove(4) + gridView.model.remove(2) + gridView.model.remove(0) + } + function takeAll() + { + gridView.model.clear() + } + + GridView { + id: gridView + + property bool useDelayRemove + + height: parent.height + width: 400 + cellWidth: width/2 + model: ListModel { + ListElement { name: "A" } + ListElement { name: "B" } + ListElement { name: "C" } + ListElement { name: "D" } + ListElement { name: "E" } + } + delegate: Text { + id: wrapper + height: 100 + text: index + gridView.count + GridView.delayRemove: gridView.useDelayRemove + GridView.onRemove: SequentialAnimation { + PauseAnimation { duration: wrapper.GridView.delayRemove ? 100 : 0 } + PropertyAction { target: wrapper; property: "GridView.delayRemove"; value: false } + } + } + } +} diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index f9262fb074..d53ee00b45 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -206,6 +206,9 @@ private slots: void jsArrayChange(); + void contentHeightWithDelayRemove_data(); + void contentHeightWithDelayRemove(); + private: QList<int> toIntList(const QVariantList &list); void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes); @@ -6471,6 +6474,74 @@ void tst_QQuickGridView::jsArrayChange() QCOMPARE(spy.count(), 1); } +void tst_QQuickGridView::contentHeightWithDelayRemove_data() +{ + QTest::addColumn<bool>("useDelayRemove"); + QTest::addColumn<QByteArray>("removeFunc"); + QTest::addColumn<int>("countDelta"); + QTest::addColumn<qreal>("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(-2 * 100.0); + + QTest::newRow("clear with delayRemove") + << true + << QByteArray("takeAll") + << -5 + << qreal(-3 * 100.0); +} + +void tst_QQuickGridView::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)); + + QQuickGridView *gridview = window->rootObject()->findChild<QQuickGridView*>(); + QTRY_VERIFY(gridview != 0); + + const int initialCount(gridview->count()); + const int eventualCount(initialCount + countDelta); + + const qreal initialContentHeight(gridview->contentHeight()); + const int eventualContentHeight(qRound(initialContentHeight + contentHeightDelta)); + + gridview->setProperty("useDelayRemove", useDelayRemove); + QMetaObject::invokeMethod(window->rootObject(), removeFunc.constData()); + QTest::qWait(50); + QCOMPARE(gridview->count(), eventualCount); + + if (useDelayRemove) { + QCOMPARE(qRound(gridview->contentHeight()), qRound(initialContentHeight)); + QTRY_COMPARE(qRound(gridview->contentHeight()), eventualContentHeight); + } else { + QCOMPARE(qRound(gridview->contentHeight()), eventualContentHeight); + } + + delete window; +} + QTEST_MAIN(tst_QQuickGridView) #include "tst_qquickgridview.moc" |