From 7722786a1305d9fdd4e0e8856322352c806de25c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 27 Jun 2012 14:05:38 +1000 Subject: Changing PathView offset doesn't set currentIndex appropriately If the highlightRangeMode is StrictlyEnforceRange then the currentIndex should always be updated when the path offset changes. Task-number: QTBUG-19835 Change-Id: I2371e5abd430e770bbb8f9f9d5f4e1d17e0d8ff5 Reviewed-by: Andrew den Exter --- .../quick/qquickpathview/tst_qquickpathview.cpp | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 5c0df1612f..d164563b93 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -108,6 +108,8 @@ private slots: void consecutiveModelChanges(); void path(); void pathMoved(); + void offset_data(); + void offset(); void setCurrentIndex(); void resetModel(); void propertyChanges(); @@ -267,7 +269,7 @@ void tst_QQuickPathView::pathview3() QVERIFY(obj->path() != 0); QVERIFY(obj->delegate() != 0); QVERIFY(obj->model() != QVariant()); - QCOMPARE(obj->currentIndex(), 0); + QCOMPARE(obj->currentIndex(), 7); QCOMPARE(obj->offset(), 1.0); QCOMPARE(obj->preferredHighlightBegin(), 0.5); QCOMPARE(obj->dragMargin(), 24.); @@ -801,7 +803,7 @@ void tst_QQuickPathView::dataModel() QVERIFY(testItem == 0); pathview->setCurrentIndex(1); - QCOMPARE(pathview->currentItem(), findItem(pathview, "wrapper", 1)); + QTRY_COMPARE(pathview->currentItem(), findItem(pathview, "wrapper", 1)); QTest::qWait(100); model.insertItem(2, "pink", "2"); @@ -836,6 +838,7 @@ void tst_QQuickPathView::dataModel() QCOMPARE(findItems(pathview, "wrapper").count(), 5); pathview->setCurrentIndex(model.count()-1); + QTRY_COMPARE(pathview->offset(), 1.0); model.removeItem(model.count()-1); QCOMPARE(pathview->currentIndex(), model.count()-1); @@ -880,8 +883,11 @@ void tst_QQuickPathView::pathMoved() QCOMPARE(curItem->pos() + offset, QPointF(itemPos.x(), itemPos.y())); } + QCOMPARE(pathview->currentIndex(), 3); + pathview->setOffset(0.0); QCOMPARE(firstItem->pos() + offset, start); + QCOMPARE(pathview->currentIndex(), 0); // Change delegate size pathview->setOffset(0.1); @@ -900,6 +906,35 @@ void tst_QQuickPathView::pathMoved() delete canvas; } +void tst_QQuickPathView::offset_data() +{ + QTest::addColumn("offset"); + QTest::addColumn("currentIndex"); + + QTest::newRow("0.0") << 0.0 << 0; + QTest::newRow("1.0") << 7.0 << 1; + QTest::newRow("5.0") << 5.0 << 3; + QTest::newRow("4.6") << 4.6 << 3; + QTest::newRow("4.4") << 4.4 << 4; + QTest::newRow("5.4") << 5.4 << 3; + QTest::newRow("5.6") << 5.6 << 2; +} + +void tst_QQuickPathView::offset() +{ + QFETCH(qreal, offset); + QFETCH(int, currentIndex); + + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("pathview3.qml")); + QQuickPathView *view = qobject_cast(c.create()); + + view->setOffset(offset); + QCOMPARE(view->currentIndex(), currentIndex); + + delete view; +} + void tst_QQuickPathView::setCurrentIndex() { QQuickView *canvas = createView(); -- cgit v1.2.3