Changing PathView offset doesn't set currentIndex appropriately
authorMartin Jones <martin.jones@nokia.com>
Wed, 27 Jun 2012 04:05:38 +0000 (14:05 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 27 Jun 2012 06:49:46 +0000 (08:49 +0200)
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 <andrew.den-exter@nokia.com>
src/quick/items/qquickpathview.cpp
tests/auto/quick/qquickpathview/tst_qquickpathview.cpp

index 1c3b9aa..e96e988 100644 (file)
@@ -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;
index 5c0df16..d164563 100644 (file)
@@ -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();