Resizing items out of the list viewport should not change the viewport
authorAlbert Astals Cid <albert.astals@canonical.com>
Tue, 28 May 2013 08:28:56 +0000 (10:28 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 24 Jul 2013 09:30:40 +0000 (11:30 +0200)
Consider the old geometry, not the new one to check if an item
was outside the viewport or not

Change-Id: I108412d560faf86130044f3d091254c07af0c004
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
src/quick/items/qquicklistview.cpp
tests/auto/quick/qquicklistview/data/outsideViewportChangeNotAffectingView.qml [new file with mode: 0644]
tests/auto/quick/qquicklistview/tst_qquicklistview.cpp

index f0e39c5..afbbca2 100644 (file)
@@ -1360,16 +1360,18 @@ void QQuickListViewPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &
             if (visibleItems.count() && item == visibleItems.first()->item) {
                 FxListItemSG *listItem = static_cast<FxListItemSG*>(visibleItems.first());
                 if (orient == QQuickListView::Vertical) {
+                    const qreal oldItemEndPosition = verticalLayoutDirection == QQuickItemView::BottomToTop ? -oldGeometry.y() : oldGeometry.y() + oldGeometry.height();
                     qreal diff = newGeometry.height() - oldGeometry.height();
-                    if (verticalLayoutDirection == QQuickListView::TopToBottom && listItem->endPosition() < q->contentY())
+                    if (verticalLayoutDirection == QQuickListView::TopToBottom && oldItemEndPosition < q->contentY())
                         listItem->setPosition(listItem->position() - diff, true);
-                    else if (verticalLayoutDirection == QQuickListView::BottomToTop && listItem->endPosition() > q->contentY())
+                    else if (verticalLayoutDirection == QQuickListView::BottomToTop && oldItemEndPosition > q->contentY())
                         listItem->setPosition(listItem->position() + diff, true);
                 } else {
+                    const qreal oldItemEndPosition = q->effectiveLayoutDirection() == Qt::RightToLeft ? -oldGeometry.x() : oldGeometry.x() + oldGeometry.width();
                     qreal diff = newGeometry.width() - oldGeometry.width();
-                    if (q->effectiveLayoutDirection() == Qt::LeftToRight && listItem->endPosition() < q->contentX())
+                    if (q->effectiveLayoutDirection() == Qt::LeftToRight && oldItemEndPosition < q->contentX())
                         listItem->setPosition(listItem->position() - diff, true);
-                    else if (q->effectiveLayoutDirection() == Qt::RightToLeft && listItem->endPosition() > q->contentX())
+                    else if (q->effectiveLayoutDirection() == Qt::RightToLeft && oldItemEndPosition > q->contentX())
                         listItem->setPosition(listItem->position() + diff, true);
                 }
             }
diff --git a/tests/auto/quick/qquicklistview/data/outsideViewportChangeNotAffectingView.qml b/tests/auto/quick/qquicklistview/data/outsideViewportChangeNotAffectingView.qml
new file mode 100644 (file)
index 0000000..7903c39
--- /dev/null
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**   * Redistributions of source code must retain the above copyright
+**     notice, this list of conditions and the following disclaimer.
+**   * Redistributions in binary form must reproduce the above copyright
+**     notice, this list of conditions and the following disclaimer in
+**     the documentation and/or other materials provided with the
+**     distribution.
+**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+**     of its contributors may be used to endorse or promote products derived
+**     from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.1
+import QtTest 1.0
+
+Item {
+    function resizeThirdItem(size) {
+        resizingListModel.setProperty(3, "size", size)
+    }
+
+    ListView {
+        width: 300
+        height: 542
+        model: ListModel {
+            id: resizingListModel
+            ListElement { size: 300; }
+            ListElement { size: 300; }
+            ListElement { size: 300; }
+            ListElement { size: 300; }
+            ListElement { size: 300; }
+            ListElement { size: 300; }
+        }
+        delegate: Rectangle {
+            width: parent.width
+            color: index % 2 == 0 ? "red" : "blue"
+            height: size
+        }
+    }
+}
index bec61ea..2268f07 100644 (file)
@@ -209,6 +209,7 @@ private slots:
     void defaultHighlightMoveDuration();
     void accessEmptyCurrentItem_QTBUG_30227();
     void delayedChanges_QTBUG_30555();
+    void outsideViewportChangeNotAffectingView();
 
 private:
     template <class T> void items(const QUrl &source);
@@ -6880,6 +6881,43 @@ void tst_QQuickListView::delayedChanges_QTBUG_30555()
     delete window;
 }
 
+void tst_QQuickListView::outsideViewportChangeNotAffectingView()
+{
+    QQuickView *window = createView();
+    window->setSource(testFileUrl("outsideViewportChangeNotAffectingView.qml"));
+
+    QQuickListView *listview = window->rootObject()->findChild<QQuickListView*>();
+    QTRY_VERIFY(listview != 0);
+
+    window->show();
+    QVERIFY(QTest::qWaitForWindowExposed(window));
+
+    flick(window, QPoint(20, 200), QPoint(20, 20), 10);
+
+    QTRY_COMPARE(listview->isFlicking(), false);
+
+    QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4);
+    QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.);
+
+    QMetaObject::invokeMethod(window->rootObject(), "resizeThirdItem", Q_ARG(QVariant, 290));
+    QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4);
+    QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.);
+
+    QMetaObject::invokeMethod(window->rootObject(), "resizeThirdItem", Q_ARG(QVariant, 300));
+    QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4);
+    QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.);
+
+    QMetaObject::invokeMethod(window->rootObject(), "resizeThirdItem", Q_ARG(QVariant, 310));
+    QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4);
+    QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.);
+
+    QMetaObject::invokeMethod(window->rootObject(), "resizeThirdItem", Q_ARG(QVariant, 400));
+    QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4);
+    QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.);
+
+    delete window;
+}
+
 QTEST_MAIN(tst_QQuickListView)
 
 #include "tst_qquicklistview.moc"