From 7b84962c47c9618af49526e3a2ef8c1c969d5aaa Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 8 Sep 2016 17:14:33 +0200 Subject: 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 --- tests/auto/quick/qquickflickable/data/wheel.qml | 5 +++++ .../quick/qquickflickable/tst_qquickflickable.cpp | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'tests/auto/quick/qquickflickable') 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("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(), 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(), 0); // QTBUG-55886 } void tst_qquickflickable::movingAndFlicking_data() -- cgit v1.2.3