diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2020-08-06 11:12:35 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-08-19 14:01:24 +0000 |
commit | 2ee9e0c2d8cb8dc066f15ef488630d455947fd6a (patch) | |
tree | 3e06535de641e7bcf32328e2f261d68d49bbe5a5 | |
parent | ef7290de7be9d36fc590956a32444bb8b1db384c (diff) |
SwipeDelegate: don't emit closed() when already closed
If the mouse is released while our position is 0, it means we were
clicked, and we don't need to begin any transitions to close.
Fixes: QTBUG-85806
Change-Id: Ic521f48e2977c1a99dbecaa585792a7798b9d749
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
(cherry picked from commit f3a64b13725081eb94b05dbeb5f68a2298c9163e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quicktemplates2/qquickswipedelegate.cpp | 6 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_swipedelegate.qml | 21 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp index 30616f7a..ad3865ff 100644 --- a/src/quicktemplates2/qquickswipedelegate.cpp +++ b/src/quicktemplates2/qquickswipedelegate.cpp @@ -889,7 +889,11 @@ bool QQuickSwipeDelegatePrivate::handleMouseReleaseEvent(QQuickItem *item, QMous swipePrivate->beginTransition(-1.0); swipePrivate->wasComplete = true; } else if (!swipePrivate->isTransitioning()) { - swipePrivate->beginTransition(0.0); + // The position is either <= 0.5 or >= -0.5, so the position should go to 0. + // However, if the position was already 0 or close to it, we were just clicked, + // and we don't need to start a transition. + if (!qFuzzyIsNull(swipePrivate->position)) + swipePrivate->beginTransition(0.0); swipePrivate->wasComplete = false; } diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index 71eb0b99..e5221b54 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -196,7 +196,8 @@ TestCase { mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton); mouseMove(control, control.width / 2 + distance, control.height / 2); mouseRelease(control, control.width / 2 + distance, control.height / 2, Qt.LeftButton); - compare(control.swipe.position, to); + compare(control.swipe.position, to, "Expected swipe.position to be " + to + + " after swiping from " + from + ", but it's " + control.swipe.position); if (control.swipe.position === -1.0) { if (control.swipe.right) @@ -1110,6 +1111,24 @@ TestCase { swipe(control, 0.0, -1.0); } + function test_callCloseWhenAlreadyClosed() { + let control = createTemporaryObject(swipeDelegateComponent, testCase) + verify(control) + + let closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }) + verify(closedSpy) + verify(closedSpy.valid) + + // Calling close() when it's already closed should have no effect. + control.swipe.close() + compare(closedSpy.count, 0) + + // The game goes for calling close() in response to a click. + control.clicked.connect(function() { control.swipe.close() }) + mouseClick(control) + compare(closedSpy.count, 0) + } + Component { id: multiActionSwipeDelegateComponent |