aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2020-08-07 13:50:06 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-08-19 14:01:30 +0000
commit1bdb56ff9571dfbf4b7bd52b9d8a45ca00f4ecac (patch)
treeb8c9ebd1a1e4a6a5b4216662ef136005933b901e
parent2ee9e0c2d8cb8dc066f15ef488630d455947fd6a (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 Change-Id: I06111b63941f54c06f0e1b828d17264f37d765d5 Reviewed-by: Andy Shaw <andy.shaw@qt.io> (cherry picked from commit 6f41c69c9bc5a0ce59444e40d3a55018f7994743) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp5
-rw-r--r--tests/auto/controls/data/tst_swipedelegate.qml46
2 files changed, 51 insertions, 0 deletions
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