diff options
3 files changed, 111 insertions, 4 deletions
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index f0e39c5e5a..afbbca201e 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -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 index 0000000000..7903c392d1 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/outsideViewportChangeNotAffectingView.qml @@ -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 + } + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index bec61eaccb..2268f0754c 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -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" |