Move path with highlightMoveDuration: 0
authorMartin Jones <martin.jones@nokia.com>
Mon, 21 Nov 2011 23:28:40 +0000 (09:28 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 22 Nov 2011 02:32:42 +0000 (03:32 +0100)
Task-number: QTBUG-22786

Change-Id: I10043bfa5d8c622fc4e7a25bcb1f96ef43d23890
Reviewed-by: Bea Lam <bea.lam@nokia.com>
src/declarative/items/qquickpathview.cpp
tests/auto/declarative/qquickpathview/tst_qquickpathview.cpp

index c7eee84..f7e58ea 100644 (file)
@@ -1720,7 +1720,9 @@ void QQuickPathViewPrivate::snapToCurrent()
 
     const int duration = highlightMoveDuration;
 
-    if (moveDirection == Positive || (moveDirection == Shortest && targetOffset - offset > modelCount/2)) {
+    if (!duration) {
+        tl.set(moveOffset, targetOffset);
+    } else if (moveDirection == Positive || (moveDirection == Shortest && targetOffset - offset > modelCount/2)) {
         qreal distance = modelCount - targetOffset + offset;
         if (targetOffset > moveOffset) {
             tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance));
index 5e434b0..8b0ecc2 100644 (file)
@@ -621,6 +621,19 @@ void tst_QQuickPathView::setCurrentIndex()
     QCOMPARE(pathview->currentItem(), firstItem);
     QCOMPARE(firstItem->property("onPath"), QVariant(true));
 
+    // move an item, set move duration to 0, and change currentIndex to moved item. QTBUG-22786
+    model.moveItem(0, 3);
+    pathview->setHighlightMoveDuration(0);
+    pathview->setCurrentIndex(3);
+    QCOMPARE(pathview->currentIndex(), 3);
+    firstItem = findItem<QQuickRectangle>(pathview, "wrapper", 3);
+    QVERIFY(firstItem);
+    QCOMPARE(pathview->currentItem(), firstItem);
+    QTRY_COMPARE(firstItem->pos() + offset, start);
+    model.moveItem(3, 0);
+    pathview->setCurrentIndex(0);
+    pathview->setHighlightMoveDuration(300);
+
     // Check the current item is still created when outside the bounds of pathItemCount.
     pathview->setPathItemCount(2);
     pathview->setHighlightRangeMode(QQuickPathView::NoHighlightRange);