diff options
-rw-r--r-- | src/quick/items/qquickpathview.cpp | 4 | ||||
-rw-r--r-- | tests/auto/quick/qquickpathview/tst_qquickpathview.cpp | 39 |
2 files changed, 40 insertions, 3 deletions
diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp index 1c3b9aaf46..e96e98856a 100644 --- a/src/quick/items/qquickpathview.cpp +++ b/src/quick/items/qquickpathview.cpp @@ -767,6 +767,7 @@ qreal QQuickPathView::offset() const void QQuickPathView::setOffset(qreal offset) { Q_D(QQuickPathView); + d->moveReason = QQuickPathViewPrivate::Other; d->setOffset(offset); d->updateCurrent(); } @@ -1562,6 +1563,7 @@ void QQuickPathView::componentComplete() d->regenerate(); } d->updateHighlight(); + d->updateCurrent(); if (d->modelCount) emit countChanged(); @@ -1866,7 +1868,7 @@ void QQuickPathViewPrivate::createCurrentItem() void QQuickPathViewPrivate::updateCurrent() { Q_Q(QQuickPathView); - if (moveReason != Mouse) + if (moveReason == SetIndex) return; if (!modelCount || !haveHighlightRange || highlightRangeMode != QQuickPathView::StrictlyEnforceRange) return; 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<QQuickItem>(pathview, "wrapper", 1)); + QTRY_COMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 1)); QTest::qWait(100); model.insertItem(2, "pink", "2"); @@ -836,6 +838,7 @@ void tst_QQuickPathView::dataModel() QCOMPARE(findItems<QQuickItem>(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<qreal>("offset"); + QTest::addColumn<int>("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<QQuickPathView*>(c.create()); + + view->setOffset(offset); + QCOMPARE(view->currentIndex(), currentIndex); + + delete view; +} + void tst_QQuickPathView::setCurrentIndex() { QQuickView *canvas = createView(); |