From 26e99aeacdb2527e6b439d8244a774cd719d732a Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 5 Sep 2019 13:57:19 +0200 Subject: PathView: grab mouse on press if already moving A side effect of 8fd398c9d2f5f54e446e0b402bc63a2edb50da6f is that it became possible for the highlight to stop between items, rather than snapping to a specific item, if the user taps, clicks or drags an additional time while the movement is ongoing. That was because it didn't get a mouse grab, so it missed the release event. QQuickPathViewPrivate::handleMouseReleaseEvent() needs to take care of the snapping behavior after the user stops dragging. This only affects behavior in the case that the PathView is already moving and the mouse is pressed again: we assume the user wants to alter the PathView's velocity, not interact with any delegate inside or with any parent item. Task-number: QTBUG-77173 Task-number: QTBUG-59620 Change-Id: I7b2f69a6ef8d8022d7c917a5bf9e8fb40c8848db Reviewed-by: Mitch Curtis (cherry picked from commit e2df4233a77ce8a37d2c8ef26b7b42fc0d33a24b) --- .../quick/qquickpathview/tst_qquickpathview.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/auto/quick/qquickpathview/tst_qquickpathview.cpp') diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index e3dc0434b1..ed02a4ef48 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -120,6 +120,7 @@ private slots: void undefinedPath(); void mouseDrag(); void nestedMouseAreaDrag(); + void flickNClick(); void treeModel(); void changePreferredHighlight(); void missingPercent(); @@ -1601,6 +1602,32 @@ void tst_QQuickPathView::nestedMouseAreaDrag() QVERIFY(pathview->isMoving()); } +void tst_QQuickPathView::flickNClick() // QTBUG-77173 +{ + QScopedPointer window(createView()); + QQuickViewTestUtil::moveMouseAway(window.data()); + window->setSource(testFileUrl("nestedmousearea2.qml")); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QCOMPARE(window.data(), qGuiApp->focusWindow()); + + QQuickPathView *pathview = qobject_cast(window->rootObject()); + QVERIFY(pathview != nullptr); + + for (int duration = 100; duration > 0; duration -= 20) { + // Dragging the child mouse area should animate the PathView (MA has no drag target) + flick(window.data(), QPoint(200,200), QPoint(400,200), duration); + QVERIFY(pathview->isMoving()); + + // Now while it's still moving, click it. + // The PathView should stop at a position such that offset is a whole number. + QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); + QTRY_VERIFY(!pathview->isMoving()); + QVERIFY(qFuzzyIsNull(pathview->offset() - int(pathview->offset()))); + } +} + void tst_QQuickPathView::treeModel() { QScopedPointer window(createView()); -- cgit v1.2.3 From 44c51303b6968a4c8c5cf80fa92618852d017fd0 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 9 Oct 2019 08:25:17 +0200 Subject: Add signal spies to tst_QQuickPathView::flickNClick test QTBUG-78926 is about failing to emit the movingChanged signal. The test verifies that e2df4233a77ce8a37d2c8ef26b7b42fc0d33a24b fixed it. While we're at it, might as well verify a few more signals in this test scenario where we flick the PathView at various speeds and then stop the flick by clicking. Fixes: QTBUG-78926 Change-Id: I1253dfcd88a63abdbdd280dd9097b484a93cc491 Reviewed-by: Mitch Curtis --- .../quick/qquickpathview/tst_qquickpathview.cpp | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/auto/quick/qquickpathview/tst_qquickpathview.cpp') diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index ed02a4ef48..e2d3253e44 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -1614,16 +1614,55 @@ void tst_QQuickPathView::flickNClick() // QTBUG-77173 QQuickPathView *pathview = qobject_cast(window->rootObject()); QVERIFY(pathview != nullptr); + QSignalSpy movingChangedSpy(pathview, SIGNAL(movingChanged())); + QSignalSpy draggingSpy(pathview, SIGNAL(draggingChanged())); + QSignalSpy dragStartedSpy(pathview, SIGNAL(dragStarted())); + QSignalSpy dragEndedSpy(pathview, SIGNAL(dragEnded())); + QSignalSpy currentIndexSpy(pathview, SIGNAL(currentIndexChanged())); + QSignalSpy moveStartedSpy(pathview, SIGNAL(movementStarted())); + QSignalSpy moveEndedSpy(pathview, SIGNAL(movementEnded())); + QSignalSpy flickingSpy(pathview, SIGNAL(flickingChanged())); + QSignalSpy flickStartedSpy(pathview, SIGNAL(flickStarted())); + QSignalSpy flickEndedSpy(pathview, SIGNAL(flickEnded())); for (int duration = 100; duration > 0; duration -= 20) { + movingChangedSpy.clear(); + draggingSpy.clear(); + dragStartedSpy.clear(); + dragEndedSpy.clear(); + currentIndexSpy.clear(); + moveStartedSpy.clear(); + moveEndedSpy.clear(); + flickingSpy.clear(); + flickStartedSpy.clear(); + flickEndedSpy.clear(); // Dragging the child mouse area should animate the PathView (MA has no drag target) flick(window.data(), QPoint(200,200), QPoint(400,200), duration); QVERIFY(pathview->isMoving()); + QCOMPARE(movingChangedSpy.count(), 1); + QCOMPARE(draggingSpy.count(), 2); + QCOMPARE(dragStartedSpy.count(), 1); + QCOMPARE(dragEndedSpy.count(), 1); + QVERIFY(currentIndexSpy.count() > 0); + QCOMPARE(moveStartedSpy.count(), 1); + QCOMPARE(moveEndedSpy.count(), 0); + QCOMPARE(flickingSpy.count(), 1); + QCOMPARE(flickStartedSpy.count(), 1); + QCOMPARE(flickEndedSpy.count(), 0); // Now while it's still moving, click it. // The PathView should stop at a position such that offset is a whole number. QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); QTRY_VERIFY(!pathview->isMoving()); + QCOMPARE(movingChangedSpy.count(), 2); // QTBUG-78926 + QCOMPARE(draggingSpy.count(), 2); + QCOMPARE(dragStartedSpy.count(), 1); + QCOMPARE(dragEndedSpy.count(), 1); + QCOMPARE(moveStartedSpy.count(), 1); + QCOMPARE(moveEndedSpy.count(), 1); + QCOMPARE(flickingSpy.count(), 2); + QCOMPARE(flickStartedSpy.count(), 1); + QCOMPARE(flickEndedSpy.count(), 1); QVERIFY(qFuzzyIsNull(pathview->offset() - int(pathview->offset()))); } } -- cgit v1.2.3