From 3688d440ab22c5887dd5f5e85de561f5571ea6ba Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Tue, 12 Dec 2017 14:25:48 +0200 Subject: Fix double toggling through Action with checked AbstractButton Action caused checked state of the button to be reset back to its original value if checked status had been change through click or key press. To avoid this, separate private function has been added to that does not change the status. Task-number: QTBUG-65108 Change-Id: I8a5aaa9aab739db3ba10d0202f5fb718cc7195bd Reviewed-by: J-P Nurmi --- tests/auto/controls/data/tst_abstractbutton.qml | 63 +++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/controls/data/tst_abstractbutton.qml b/tests/auto/controls/data/tst_abstractbutton.qml index 90c6567f..ea381a32 100644 --- a/tests/auto/controls/data/tst_abstractbutton.qml +++ b/tests/auto/controls/data/tst_abstractbutton.qml @@ -262,6 +262,69 @@ TestCase { compare(control.action.enabled, true) // does NOT propagate } + Component { + id: checkableButton + AbstractButton { + checkable: true + action: Action {} + } + } + + function test_checkable_button() { + var control = createTemporaryObject(checkableButton, testCase) + verify(control) + control.checked = false + control.forceActiveFocus() + verify(control.activeFocus) + verify(!control.checked) + verify(!control.action.checked) + + keyPress(Qt.Key_Space) + keyRelease(Qt.Key_Space) + + compare(control.action.checked, true) + compare(control.checked, true) + + keyPress(Qt.Key_Space) + + compare(control.action.checked, true) + compare(control.checked, true) + + keyRelease(Qt.Key_Space) + + compare(control.action.checked, false) + compare(control.checked, false) + + var checkedSpy = signalSpy.createObject(control, {target: control.action, signalName: "checkedChanged"}) + var toggledSpy = signalSpy.createObject(control, {target: control, signalName: "toggled"}) + var actionToggledSpy = signalSpy.createObject(control, {target: control.action, signalName: "toggled"}) + + verify(checkedSpy.valid) + verify(toggledSpy.valid) + verify(actionToggledSpy.valid) + + mousePress(control) + + compare(control.action.checked, false) + compare(control.checked, false) + + mouseRelease(control) + + checkedSpy.wait() + compare(checkedSpy.count, 1) + compare(actionToggledSpy.count, 1) + compare(toggledSpy.count, 1) + + compare(control.action.checked, true) + compare(control.checked, true) + + mousePress(control) + mouseRelease(control) + + compare(control.checked, false) + compare(control.action.checked, false) + } + function test_trigger_data() { return [ {tag: "click", click: true, button: true, action: true, clicked: true, triggered: true}, -- cgit v1.2.3