diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2014-07-21 14:55:30 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@digia.com> | 2014-07-24 10:17:13 +0200 |
commit | 1416e6bd3ec4aaefe33bb64c9ad64d251f7f2885 (patch) | |
tree | 9c3ad42a4d18e543473ce57e925fe4b7f985c5ad /tests | |
parent | bca2eb550de0148dc53aeb1f9e7a036a692fd01d (diff) |
Schedule layout changes to avoid refill() recursion.
Otherwise we add duplicate item delegates.
Task-number: QTBUG-40298
Change-Id: I8a2221d72f458c892720a71d87513808a5d725a6
Reviewed-by: Martin Jones <martin.jones@jollamobile.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickpathview/data/changePathDuringRefill.qml | 45 | ||||
-rw-r--r-- | tests/auto/quick/qquickpathview/tst_qquickpathview.cpp | 40 |
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickpathview/data/changePathDuringRefill.qml b/tests/auto/quick/qquickpathview/data/changePathDuringRefill.qml new file mode 100644 index 0000000000..f02ab35faf --- /dev/null +++ b/tests/auto/quick/qquickpathview/data/changePathDuringRefill.qml @@ -0,0 +1,45 @@ +import QtQuick 2.3 + +PathView { + id: view + objectName: "pathView" + width: 100 + height: delegateHeight * pathItemCount + model: ["A", "B", "C"] + pathItemCount: 3 + anchors.centerIn: parent + + property int delegateHeight: 0 + + activeFocusOnTab: true + Keys.onDownPressed: view.incrementCurrentIndex() + Keys.onUpPressed: view.decrementCurrentIndex() + preferredHighlightBegin: 0.5 + preferredHighlightEnd: 0.5 + + delegate: Rectangle { + objectName: "delegate" + modelData + width: view.width + height: textItem.height + border.color: "red" + + onHeightChanged: { + if (index == 0) + view.delegateHeight = textItem.height + } + + Text { + id: textItem + text: modelData + } + } + + path: Path { + startX: view.width / 2 + startY: 0 + PathLine { + x: view.width / 2 + y: view.pathItemCount * view.delegateHeight + } + } +} diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 405e0267ff..1960775ad3 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -144,6 +144,7 @@ private slots: void indexAt_itemAt_data(); void cacheItemCount(); void incorrectSteal(); + void changePathDuringRefill(); }; class TestObject : public QObject @@ -2122,7 +2123,46 @@ void tst_QQuickPathView::cacheItemCount() bool b = true; controller.incubateWhile(&b); } +} + +static void testCurrentIndexChange(QQuickPathView *pathView, const QStringList &objectNamesInOrder) +{ + for (int visualIndex = 0; visualIndex < objectNamesInOrder.size() - 1; ++visualIndex) { + QQuickRectangle *delegate = findItem<QQuickRectangle>(pathView, objectNamesInOrder.at(visualIndex)); + QVERIFY(delegate); + + QQuickRectangle *nextDelegate = findItem<QQuickRectangle>(pathView, objectNamesInOrder.at(visualIndex + 1)); + QVERIFY(nextDelegate); + + QVERIFY(delegate->y() < nextDelegate->y()); + } +} + +void tst_QQuickPathView::changePathDuringRefill() +{ + QScopedPointer<QQuickView> window(createView()); + + window->setSource(testFileUrl("changePathDuringRefill.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QCOMPARE(window.data(), qGuiApp->focusWindow()); + + QQuickPathView *pathView = qobject_cast<QQuickPathView*>(window->rootObject()); + QVERIFY(pathView != 0); + + testCurrentIndexChange(pathView, QStringList() << "delegateC" << "delegateA" << "delegateB"); + + pathView->incrementCurrentIndex(); + /* + Decrementing moves delegateA down, resulting in an offset of 1, + so incrementing will move it up, resulting in an offset of 2: + delegateC delegateA + delegateA => delegateB + delegateB delegateC + */ + QTRY_COMPARE(pathView->offset(), 2.0); + testCurrentIndexChange(pathView, QStringList() << "delegateA" << "delegateB" << "delegateC"); } void tst_QQuickPathView::incorrectSteal() |