From a7880a0c92323ccb2f297a39a993a87e20d65e9c Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 1 Nov 2017 13:03:22 +0100 Subject: ListView: don't stop moving the highlight because of model updates In QQuickItemViewPrivate::applyModelChanges(), if moveReason = QQuickItemViewPrivate::Other, then QQuickItemView::trackedPositionChanged() will fail to call d->setPosition(pos), which is normally what keeps the Flickable moving for a while. Leave the reason as-is (it will be SetIndex in this case), so as not to forget that we were actually trying to move down. Updating the model was just a side-effect of that: either because some QML code was trying to append to the model or because fetchMore() was called. Task-number: QTBUG-61269 Task-number: QTBUG-62864 Change-Id: I3fd402469950d6c12e6a8d6e42be83ea4f54776a Reviewed-by: J-P Nurmi --- .../qquicklistview/data/appendDuringScrollDown.qml | 28 +++++++++++++++++++ .../quick/qquicklistview/tst_qquicklistview.cpp | 32 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/auto/quick/qquicklistview/data/appendDuringScrollDown.qml (limited to 'tests/auto/quick/qquicklistview') diff --git a/tests/auto/quick/qquicklistview/data/appendDuringScrollDown.qml b/tests/auto/quick/qquicklistview/data/appendDuringScrollDown.qml new file mode 100644 index 0000000000..af35c29143 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/appendDuringScrollDown.qml @@ -0,0 +1,28 @@ +import QtQuick 2.6 + +ListView { + width: 320; height: 240 + focus: true + delegate: Text { + height: 40; width: parent.width + text: model.text + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + } + highlight: Rectangle { color: "red" } + model: ListModel { + ListElement { text: "0" } + ListElement { text: "1" } + ListElement { text: "2" } + ListElement { text: "3" } + ListElement { text: "4" } + ListElement { text: "5" } + ListElement { text: "6" } + ListElement { text: "7" } + ListElement { text: "8" } + ListElement { text: "9" } + } + + readonly property Item topItem: itemAt(0, contentY) + onTopItemChanged: model.append({ "text": "new" }) +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 0d0f234d33..2e9c54c5a3 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -254,6 +254,7 @@ private slots: void QTBUG_50105(); void keyNavigationEnabled(); + void QTBUG_61269_appendDuringScrollDown(); void QTBUG_50097_stickyHeader_positionViewAtIndex(); void itemFiltered(); void releaseItems(); @@ -8468,6 +8469,37 @@ void tst_QQuickListView::keyNavigationEnabled() QCOMPARE(listView->currentIndex(), 1); } +void tst_QQuickListView::QTBUG_61269_appendDuringScrollDown() +{ + QScopedPointer window(createView()); + window->setSource(testFileUrl("appendDuringScrollDown.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + + QQuickListView *listView = qobject_cast(window->rootObject()); + QQuickItem *highlightItem = listView->highlightItem(); + QVERIFY(listView); + QCOMPARE(listView->isKeyNavigationEnabled(), true); + listView->setHighlightMoveVelocity(400); + listView->setHighlightMoveDuration(-1); // let it animate + listView->setFocus(true); + QVERIFY(listView->hasActiveFocus()); + qreal highlightYLimit = listView->height() - highlightItem->height(); // should be 200 + + for (int i = 1; i < 15; ++i) { + QTest::keyClick(window.data(), Qt::Key_Down); + + // Wait for the highlight movement animation to finish. + QTRY_COMPARE(highlightItem->y(), 40.0 * i); + + // As we scroll down, the QML will append rows to its own model. + // Make sure the highlighted row and highlight item stay within the view. + // In QTBUG-62864 and QTBUG-61269, it would go off the bottom. + QVERIFY(highlightItem->y() - listView->contentY() <= highlightYLimit); + } +} + void tst_QQuickListView::QTBUG_48870_fastModelUpdates() { StressTestModel model; -- cgit v1.2.3 From 0f043c594b559f2f936333c8cf9779283a480c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pasi=20Pet=C3=A4j=C3=A4j=C3=A4rvi?= Date: Fri, 20 Oct 2017 11:09:22 +0300 Subject: Fix providing correct velocity when using index based scrolling Index based scrolling does not enable moving and flicking properties. Task-number: QTBUG-34576 Change-Id: Ief06d37115ca389027670c97ce6c0457a74d4872 Reviewed-by: Qt CI Bot Reviewed-by: Shawn Rutledge --- .../auto/quick/qquicklistview/data/qtbug34576.qml | 102 +++++++++++++++++++++ .../quick/qquicklistview/tst_qquicklistview.cpp | 50 ++++++++++ 2 files changed, 152 insertions(+) create mode 100644 tests/auto/quick/qquicklistview/data/qtbug34576.qml (limited to 'tests/auto/quick/qquicklistview') diff --git a/tests/auto/quick/qquicklistview/data/qtbug34576.qml b/tests/auto/quick/qquicklistview/data/qtbug34576.qml new file mode 100644 index 0000000000..f407d8ebe3 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/qtbug34576.qml @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +import QtQuick 2.7 + +Rectangle { + id: root + width: 320 + height: 240 + color: "black" + + property int current: list.currentIndex + property int horizontalVelocityZeroCount: 0 + + ListView { + id: list + objectName: "list" + anchors.fill: parent + + focus: true + + orientation: ListView.Horizontal + + snapMode: ListView.SnapToItem + flickableDirection: Flickable.HorizontalFlick + + model: 10 + delegate: Item { + width: root.width / 3 + height: root.height + Rectangle { + anchors.centerIn: parent + width: 50 + height: 50 + color: list.currentIndex === index ? "red" : "white" + } + } + + onHorizontalVelocityChanged: { + if (list.horizontalVelocity === 0.0) + root.horizontalVelocityZeroCount++ + } + + } + + Rectangle { + color: "red" + width: 50 + height: 50 + anchors.left: parent.left + anchors.bottom: parent.bottom + + MouseArea { + anchors.fill: parent + onClicked: { + list.currentIndex--; + } + } + } + + Rectangle { + color: "red" + width: 50 + height: 50 + anchors.right: parent.right + anchors.bottom: parent.bottom + + MouseArea { + anchors.fill: parent + onClicked: { + list.currentIndex++; + } + } + } +} + diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 2e9c54c5a3..42049fa9ca 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -259,6 +259,8 @@ private slots: void itemFiltered(); void releaseItems(); + void QTBUG_34576_velocityZero(); + private: template void items(const QUrl &source); template void changed(const QUrl &source); @@ -8607,6 +8609,54 @@ void tst_QQuickListView::releaseItems() listview->setModel(123); } +void tst_QQuickListView::QTBUG_34576_velocityZero() +{ + QQuickView *window = new QQuickView(0); + window->setGeometry(0,0,240,320); + + QQmlContext *ctxt = window->rootContext(); + + QString filename(testFile("qtbug34576.qml")); + window->setSource(QUrl::fromLocalFile(filename)); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickListView *listview = findItem(window->rootObject(), "list"); + QTRY_VERIFY(listview != 0); + QQuickItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); + QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + + QSignalSpy horizontalVelocitySpy(listview, SIGNAL(horizontalVelocityChanged())); + + // currentIndex is initialized to 0 + QCOMPARE(listview->currentIndex(), 0); + + // set currentIndex to last item currently visible item + window->rootObject()->setProperty("horizontalVelocityZeroCount", QVariant(0)); + listview->setCurrentIndex(2); + QTRY_COMPARE(window->rootObject()->property("current").toInt(), 2); + QTRY_COMPARE(horizontalVelocitySpy.count(), 0); + QTRY_COMPARE(window->rootObject()->property("horizontalVelocityZeroCount").toInt(), 0); + + // click button which increases currentIndex + QTest::mousePress(window, Qt::LeftButton, 0, QPoint(295,215)); + QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(295,215)); + + // verify that currentIndexChanged is triggered + QVERIFY(horizontalVelocitySpy.wait()); + + // set currentIndex to item out of view to cause listview scroll + QTRY_COMPARE(window->rootObject()->property("current").toInt(), 3); + QTRY_COMPARE(horizontalVelocitySpy.count() > 0, true); + QVERIFY(horizontalVelocitySpy.wait(1000)); + + // velocity should be always > 0.0 + QTRY_COMPARE(window->rootObject()->property("horizontalVelocityZeroCount").toInt(), 0); + + delete window; +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" -- cgit v1.2.3 From e7b73cc5e2cd1564d7f2ee9de1340b0913b4ecdf Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 1 Nov 2017 22:09:23 +0100 Subject: stabilize tst_QQuickListView::incrementalModel Task-number: QTBUG-30716 Change-Id: I0c6829ae496850d6a2cdcc349c496dfbf4e8adbb Reviewed-by: J-P Nurmi --- tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'tests/auto/quick/qquicklistview') diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 42049fa9ca..a31cb37c16 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -4684,29 +4684,24 @@ void tst_QQuickListView::indexAt_itemAt() void tst_QQuickListView::incrementalModel() { QScopedPointer window(createView()); - QSKIP("QTBUG-30716"); IncrementalModel model; QQmlContext *ctxt = window->rootContext(); ctxt->setContextProperty("testModel", &model); window->setSource(testFileUrl("displaylist.qml")); - qApp->processEvents(); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); QQuickListView *listview = findItem(window->rootObject(), "list"); QTRY_VERIFY(listview != 0); - listview->forceLayout(); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != 0); - - listview->forceLayout(); - QTRY_COMPARE(listview->count(), 20); + QTRY_COMPARE(listview->count(), 35); listview->positionViewAtIndex(10, QQuickListView::Beginning); - - listview->forceLayout(); - QTRY_COMPARE(listview->count(), 25); + QTRY_COMPARE(listview->count(), 45); } void tst_QQuickListView::onAdd() -- cgit v1.2.3