aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2017-11-01 13:03:22 +0100
committerJędrzej Nowacki <jedrzej.nowacki@qt.io>2017-11-03 08:27:29 +0000
commita7880a0c92323ccb2f297a39a993a87e20d65e9c (patch)
tree64002c86e06fd5a1c8fc8a5532c3d2f26eb32346
parenteb2265d4c89b64c571f276e628b751abac29f895 (diff)
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 <jpnurmi@qt.io>
-rw-r--r--src/quick/items/qquickitemview.cpp1
-rw-r--r--tests/auto/quick/qquicklistview/data/appendDuringScrollDown.qml28
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp32
3 files changed, 60 insertions, 1 deletions
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp
index 9038f7cde4..8f3fe9f0f2 100644
--- a/src/quick/items/qquickitemview.cpp
+++ b/src/quick/items/qquickitemview.cpp
@@ -1979,7 +1979,6 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
}
updateUnrequestedIndexes();
- moveReason = QQuickItemViewPrivate::Other;
FxViewItem *prevVisibleItemsFirst = visibleItems.count() ? *visibleItems.constBegin() : 0;
int prevItemCount = itemCount;
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<QQuickView> window(createView());
+ window->setSource(testFileUrl("appendDuringScrollDown.qml"));
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
+
+ QQuickListView *listView = qobject_cast<QQuickListView *>(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;