From 1bdb56ff9571dfbf4b7bd52b9d8a45ca00f4ecac Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 7 Aug 2020 13:50:06 +0200 Subject: SwipeDelegate: don't allow calling close() when pressed This conflicts with the behavior of SwipeDelegate. The released() or clicked() signals should be used instead. Fixes: QTBUG-85804 Change-Id: I06111b63941f54c06f0e1b828d17264f37d765d5 Reviewed-by: Andy Shaw (cherry picked from commit 6f41c69c9bc5a0ce59444e40d3a55018f7994743) Reviewed-by: Qt Cherry-pick Bot --- src/quicktemplates2/qquickswipedelegate.cpp | 5 +++ tests/auto/controls/data/tst_swipedelegate.qml | 46 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp index ad3865ff..c6214243 100644 --- a/src/quicktemplates2/qquickswipedelegate.cpp +++ b/src/quicktemplates2/qquickswipedelegate.cpp @@ -697,6 +697,11 @@ void QQuickSwipe::close() if (qFuzzyIsNull(d->position)) return; + if (d->control->isPressed()) { + // We don't support closing when we're pressed; release() or clicked() should be used instead. + return; + } + d->beginTransition(0.0); d->wasComplete = false; d->positionBeforePress = 0.0; diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index e5221b54..d37ea42b 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -1129,6 +1129,52 @@ TestCase { compare(closedSpy.count, 0) } + // Can't just connect to pressed in QML, because there is a pressed property + // that conflicts with the signal. + Component { + id: swipeDelegateCloseOnPressedComponent + + SwipeDelegate { + text: "SwipeDelegate" + width: 150 + swipe.right: Rectangle { + objectName: "rightItem" + width: parent.width / 2 + height: parent.height + color: "tomato" + } + + onPressed: swipe.close() + } + } + + /* + We don't want to support closing on pressed(); released() or clicked() + should be used instead. However, calling swipe.close() in response to + a press should still not cause closed() to be emitted. + */ + function test_closeOnPressed() { + let control = createTemporaryObject(swipeDelegateCloseOnPressedComponent, testCase) + verify(control) + + swipe(control, 0.0, -1.0) + + let closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }) + verify(closedSpy) + verify(closedSpy.valid) + + mousePress(control, control.width * 0.1) + compare(closedSpy.count, 0) + compare(control.swipe.position, -1.0) + + // Simulate a somewhat realistic delay between press and release + // to ensure that the bug is triggered. + wait(100) + mouseRelease(control, control.width * 0.1) + compare(closedSpy.count, 0) + compare(control.swipe.position, -1.0) + } + Component { id: multiActionSwipeDelegateComponent -- cgit v1.2.3