diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-05-03 16:54:16 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-05-04 09:04:11 +0000 |
commit | ff9d924d98aac8248ce99aef992920aeb99fda7e (patch) | |
tree | 111f0559bac140df5f245172a38d13921577705e | |
parent | d3371de42f5262a2f0794a2d5e972ed50001028e (diff) |
QQuickSwitch: fix the order of checkedChanged() vs. clicked()
And emit clicked() also when the switch was dragged to make it possible
to use clicked() reliably to detect user interaction.
Change-Id: Iefbd95b90ed40f04d84e03e247a8ac12c7f0e9ca
Task-number: QTBUG-52558
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickswitch.cpp | 5 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_switch.qml | 6 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickswitch.cpp b/src/quicktemplates2/qquickswitch.cpp index e6f8cce0..380c37ec 100644 --- a/src/quicktemplates2/qquickswitch.cpp +++ b/src/quicktemplates2/qquickswitch.cpp @@ -142,14 +142,17 @@ bool QQuickSwitchPrivate::handleMouseReleaseEvent(QQuickItem *child, QMouseEvent pressPoint = QPoint(); q->setPressed(false); if (child->keepMouseGrab()) { + bool wasChecked = checked; q->setChecked(position > 0.5); q->setPosition(checked ? 1.0 : 0.0); child->setKeepMouseGrab(false); + if (wasChecked != checked) + emit q->clicked(); event->accept(); } else { + q->toggle(); emit q->clicked(); event->accept(); - q->toggle(); } return true; } diff --git a/tests/auto/controls/data/tst_switch.qml b/tests/auto/controls/data/tst_switch.qml index e8e34df5..f12e7612 100644 --- a/tests/auto/controls/data/tst_switch.qml +++ b/tests/auto/controls/data/tst_switch.qml @@ -162,7 +162,7 @@ TestCase { mouseMove(control, control.width * 2, control.height / 2, 0, Qt.LeftButton) compare(control.pressed, true) mouseRelease(control, control.width * 2, control.height / 2, Qt.LeftButton) - compare(clickedSpy.count, 2) + compare(clickedSpy.count, 3) compare(checkedSpy.count, 3) compare(pressedSpy.count, 6) compare(control.checked, true) @@ -175,7 +175,7 @@ TestCase { mouseMove(control, -control.width, control.height / 2, 0, Qt.LeftButton) compare(control.pressed, true) mouseRelease(control, -control.width, control.height / 2, Qt.LeftButton) - compare(clickedSpy.count, 2) + compare(clickedSpy.count, 4) compare(checkedSpy.count, 4) compare(pressedSpy.count, 8) compare(control.checked, false) @@ -186,7 +186,7 @@ TestCase { compare(pressedSpy.count, 8) compare(control.pressed, false) mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) - compare(clickedSpy.count, 2) + compare(clickedSpy.count, 4) compare(checkedSpy.count, 4) compare(pressedSpy.count, 8) compare(control.checked, false) |