diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2021-12-15 14:55:48 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2022-01-03 13:51:49 +0100 |
commit | 778e08a4061a87b5b2d6c4cee082ded74e1bcc64 (patch) | |
tree | 72f0913a5b939364a93f4d45dbe8574d5c8f8173 /tests | |
parent | 203ec601e59db72638642e56c692bd96356ccf1a (diff) |
AbstractButton: fix fast clicks being treated as double clicks
Only emit the doubleClicked signal if it's connected to something.
While we're at it, optimize isPressAndHoldConnected() by making
locals static.
Fixes: QTBUG-96888
Change-Id: I7b737d5ab75240bd06cc7f9daad7d848b8278d49
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 220a547aa440019ebcb1dd411ed95ecbf197e0f1)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quickcontrols2/controls/data/tst_abstractbutton.qml | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/quickcontrols2/controls/data/tst_abstractbutton.qml b/tests/auto/quickcontrols2/controls/data/tst_abstractbutton.qml index 00f8affdd2..2c9ce4d9ed 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_abstractbutton.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_abstractbutton.qml @@ -918,6 +918,55 @@ TestCase { compare(doubleClickedSpy.count, 1) } + // It should be possible to quickly click a button whose doubleClicked signal + // is not connected to anything. + function test_fastClick() { + let control = createTemporaryObject(button, testCase, { text: "Hello" }) + verify(control) + + let pressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) + verify(pressedSpy.valid) + + let releasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) + verify(releasedSpy.valid) + + let clickedSpy = signalSpy.createObject(control, { target: control, signalName: "clicked" }) + verify(clickedSpy.valid) + + // Can't listen to doubleClicked because it would cause it to be emitted. + // We instead just check that clicked is emitted twice. + + mouseDoubleClickSequence(control) + compare(pressedSpy.count, 2) + compare(releasedSpy.count, 2) + compare(clickedSpy.count, 2) + + let touch = touchEvent(control) + touch.press(0, control) + touch.commit() + compare(pressedSpy.count, 3) + compare(releasedSpy.count, 2) + compare(clickedSpy.count, 2) + + touch.release(0, control) + touch.commit() + compare(pressedSpy.count, 3) + compare(releasedSpy.count, 3) + compare(clickedSpy.count, 3) + + touch.press(0, control) + touch.commit() + compare(pressedSpy.count, 4) + compare(releasedSpy.count, 3) + compare(clickedSpy.count, 3) + + touch.release(0, control) + touch.commit() + compare(pressedSpy.count, 4) + compare(releasedSpy.count, 4) + compare(clickedSpy.count, 4) + } + function test_checkedShouldNotSetCheckable() { let control = createTemporaryObject(button, testCase, { checked: true }) verify(control) |