summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2016-09-08 17:14:33 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2016-09-29 13:08:59 +0000
commit7b84962c47c9618af49526e3a2ef8c1c969d5aaa (patch)
tree3bbb101cf8ac91a1d322b9f53a8a0fbd6cfef739
parent3a45458b96bdcbccc189aabf668e998ea03be46f (diff)
Flickable: do not emit movementEnded until it really does
This was occurring when using a physical mouse wheel: movementEnded was emitted, then contentYChanged would still be emitted a few more times. Task-number: QTBUG-55886 Change-Id: Ib5e833d5d84633bb07b8c240ea3ccc9977e443f8 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/quick/items/qquickflickable.cpp2
-rw-r--r--tests/auto/quick/qquickflickable/data/wheel.qml5
-rw-r--r--tests/auto/quick/qquickflickable/tst_qquickflickable.cpp20
3 files changed, 25 insertions, 2 deletions
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp
index 7c45d1c5ad..a5b4bb0309 100644
--- a/src/quick/items/qquickflickable.cpp
+++ b/src/quick/items/qquickflickable.cpp
@@ -1563,7 +1563,7 @@ void QQuickFlickable::timerEvent(QTimerEvent *event)
d->movementEndingTimer.stop();
d->pressed = false;
d->stealMouse = false;
- if (!d->velocityTimeline.isActive())
+ if (!d->velocityTimeline.isActive() && !d->timeline.isActive())
movementEnding(true, true);
}
}
diff --git a/tests/auto/quick/qquickflickable/data/wheel.qml b/tests/auto/quick/qquickflickable/data/wheel.qml
index 2928bbcd72..2be543cdde 100644
--- a/tests/auto/quick/qquickflickable/data/wheel.qml
+++ b/tests/auto/quick/qquickflickable/data/wheel.qml
@@ -8,9 +8,14 @@ Rectangle {
Flickable {
id: flick
objectName: "flick"
+ property bool ended: false
+ property int movementsAfterEnd: 0
anchors.fill: parent
contentWidth: 800
contentHeight: 800
+ onContentXChanged: if (ended) ++movementsAfterEnd
+ onContentYChanged: if (ended) ++movementsAfterEnd
+ onMovementEnded: ended = true
Rectangle {
width: flick.contentWidth
diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
index 294f7069c0..7de0a0fa0e 100644
--- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
+++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
@@ -724,7 +724,10 @@ void tst_qquickflickable::wheel()
QQuickFlickable *flick = window->rootObject()->findChild<QQuickFlickable*>("flick");
QVERIFY(flick != 0);
+ QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flick);
+ QSignalSpy moveEndSpy(flick, SIGNAL(movementEnded()));
+ // test a vertical flick
{
QPoint pos(200, 200);
QWheelEvent event(pos, window->mapToGlobal(pos), QPoint(), QPoint(0,-120), -120, Qt::Vertical, Qt::NoButton, Qt::NoModifier);
@@ -735,9 +738,19 @@ void tst_qquickflickable::wheel()
QTRY_VERIFY(flick->contentY() > 0);
QCOMPARE(flick->contentX(), qreal(0));
- flick->setContentY(0);
+ QTRY_COMPARE(moveEndSpy.count(), 1);
+ QCOMPARE(fp->velocityTimeline.isActive(), false);
+ QCOMPARE(fp->timeline.isActive(), false);
+ QTest::qWait(50); // make sure that onContentYChanged won't sneak in again
+ QCOMPARE(flick->property("movementsAfterEnd").value<int>(), 0); // QTBUG-55886
+
+ // get ready to test horizontal flick
+ flick->setContentY(0); // which triggers movementEnded again
+ flick->setProperty("movementsAfterEnd", 0);
+ flick->setProperty("ended", false);
QCOMPARE(flick->contentY(), qreal(0));
+ // test a horizontal flick
{
QPoint pos(200, 200);
QWheelEvent event(pos, window->mapToGlobal(pos), QPoint(), QPoint(-120,0), -120, Qt::Horizontal, Qt::NoButton, Qt::NoModifier);
@@ -748,6 +761,11 @@ void tst_qquickflickable::wheel()
QTRY_VERIFY(flick->contentX() > 0);
QCOMPARE(flick->contentY(), qreal(0));
+ QTRY_COMPARE(moveEndSpy.count(), 2);
+ QCOMPARE(fp->velocityTimeline.isActive(), false);
+ QCOMPARE(fp->timeline.isActive(), false);
+ QTest::qWait(50); // make sure that onContentXChanged won't sneak in again
+ QCOMPARE(flick->property("movementsAfterEnd").value<int>(), 0); // QTBUG-55886
}
void tst_qquickflickable::movingAndFlicking_data()