aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2018-08-22 13:21:14 -0500
committerMichael Brasser <michael.brasser@live.com>2018-08-23 17:14:33 +0000
commit6e2fc84646987135c96755fbe1c2af20fc722e3d (patch)
treecd7af170589621180b0cbb59e345a4a68b8ed871
parentee0713e3988b0acf3a1ec6cad1c7722dbec76ea7 (diff)
Prevent ListView from jumping horizontally with flick(0,<number>)
The internal flick functions were not written to handle empty flicks in invalid directions. Guard our calls accordingly. Change-Id: I34801a7e548160ce4895dd8a2f6c0b17172cd02e Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quick/items/qquickflickable.cpp4
-rw-r--r--tests/auto/quick/qquicklistview/data/snapOneItemWrongDirection.qml18
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp19
3 files changed, 39 insertions, 2 deletions
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp
index 8ae5ea64a7..85045be411 100644
--- a/src/quick/items/qquickflickable.cpp
+++ b/src/quick/items/qquickflickable.cpp
@@ -1847,8 +1847,8 @@ void QQuickFlickable::flick(qreal xVelocity, qreal yVelocity)
d->vData.velocity = yVelocity;
d->hData.vTime = d->vData.vTime = d->timeline.time();
- bool flickedX = d->flickX(xVelocity);
- bool flickedY = d->flickY(yVelocity);
+ const bool flickedX = xflick() && !qFuzzyIsNull(xVelocity) && d->flickX(xVelocity);
+ const bool flickedY = yflick() && !qFuzzyIsNull(yVelocity) && d->flickY(yVelocity);
if (flickedX)
d->hMoved = true;
diff --git a/tests/auto/quick/qquicklistview/data/snapOneItemWrongDirection.qml b/tests/auto/quick/qquicklistview/data/snapOneItemWrongDirection.qml
new file mode 100644
index 0000000000..f5b7b35d0c
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/data/snapOneItemWrongDirection.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+
+ListView {
+ width: 400
+ height: 400
+ focus: true
+
+ model: 10
+ delegate: Rectangle {
+ width: parent.width
+ height: 50
+ color: index % 2 ? "blue" : "green"
+ }
+
+ snapMode: ListView.SnapOneItem
+ Keys.onUpPressed: flick(0,500)
+ Keys.onDownPressed: flick(0,-500)
+}
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index 64a186eade..9c11957894 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -182,6 +182,7 @@ private slots:
void snapOneItem_data();
void snapOneItem();
void snapOneItemCurrentIndexRemoveAnimation();
+ void snapOneItemWrongDirection();
void QTBUG_9791();
void QTBUG_33568();
@@ -5672,6 +5673,24 @@ void tst_QQuickListView::snapOneItemCurrentIndexRemoveAnimation()
QCOMPARE(currentIndexSpy.count(), 0);
}
+void tst_QQuickListView::snapOneItemWrongDirection()
+{
+ QScopedPointer<QQuickView> window(createView());
+ window->setSource(testFileUrl("snapOneItemWrongDirection.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject());
+ QTRY_VERIFY(listview != nullptr);
+
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+ QTRY_COMPARE(listview->currentIndex(), 0);
+
+ listview->flick(0,500);
+ QTRY_VERIFY(!listview->isMovingHorizontally());
+ QCOMPARE(listview->contentX(), qreal(0));
+}
+
void tst_QQuickListView::attachedProperties_QTBUG_32836()
{
QScopedPointer<QQuickView> window(createView());