diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2020-08-07 13:50:06 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2020-08-19 15:16:49 +0200 |
commit | 6f41c69c9bc5a0ce59444e40d3a55018f7994743 (patch) | |
tree | 14a30f03160064058fad9913f3b17367193c2062 | |
parent | f3a64b13725081eb94b05dbeb5f68a2298c9163e (diff) |
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
Pick-to: 5.15
Change-Id: I06111b63941f54c06f0e1b828d17264f37d765d5
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickswipedelegate.cpp | 5 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_swipedelegate.qml | 46 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp index 3669ce05..4b16609d 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 |