From a108298bb9529dd1ad4b195849f3c1e12daa82bf Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 1 Nov 2015 19:18:31 +0100 Subject: Add AbstractButton::autoExclusive This feature is adopted from QtWidgets' QAbstractButton. It's no longer necessary to create an ExclusiveGroup to manage a simple list of radio buttons: Column { RadioButton { text: "Option 1" } RadioButton { text: "Option 2" } } Change-Id: Ib4cb718c3b3034c9c956b2f23db4b06b00547b8e Reviewed-by: Mitch Curtis --- tests/auto/controls/data/tst_radiobutton.qml | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_radiobutton.qml b/tests/auto/controls/data/tst_radiobutton.qml index d76a8c38..2df3542d 100644 --- a/tests/auto/controls/data/tst_radiobutton.qml +++ b/tests/auto/controls/data/tst_radiobutton.qml @@ -225,4 +225,72 @@ TestCase { container.destroy() } + + Component { + id: radioButtonGroup + Column { + // auto-exclusive buttons behave as if they were in their own exclusive group + RadioButton { } + RadioButton { } + + // explicitly grouped buttons are only exclusive with each other, not with + // auto-exclusive buttons, and the autoExclusive property is ignored + ExclusiveGroup { id: eg } + RadioButton { ExclusiveGroup.group: eg } + RadioButton { ExclusiveGroup.group: eg; autoExclusive: false } + + // non-exclusive buttons don't affect the others + RadioButton { autoExclusive: false } + RadioButton { autoExclusive: false } + } + } + + function test_autoExclusive() { + var container = radioButtonGroup.createObject(testCase) + compare(container.children.length, 6) + + var checkStates = [false, false, false, false, false, false] + for (var i = 0; i < 6; ++i) + compare(container.children[i].checked, checkStates[i]) + + container.children[0].checked = true + checkStates[0] = true + for (i = 0; i < 6; ++i) + compare(container.children[i].checked, checkStates[i]) + + container.children[1].checked = true + checkStates[0] = false + checkStates[1] = true + for (i = 0; i < 6; ++i) + compare(container.children[i].checked, checkStates[i]) + + container.children[2].checked = true + checkStates[2] = true + for (i = 0; i < 6; ++i) + compare(container.children[i].checked, checkStates[i]) + + container.children[3].checked = true + checkStates[2] = false + checkStates[3] = true + for (i = 0; i < 6; ++i) + compare(container.children[i].checked, checkStates[i]) + + container.children[4].checked = true + checkStates[4] = true + for (i = 0; i < 6; ++i) + compare(container.children[i].checked, checkStates[i]) + + container.children[5].checked = true + checkStates[5] = true + for (i = 0; i < 6; ++i) + compare(container.children[i].checked, checkStates[i]) + + container.children[0].checked = true + checkStates[0] = true + checkStates[1] = false + for (i = 0; i < 6; ++i) + compare(container.children[i].checked, checkStates[i]) + + container.destroy() + } } -- cgit v1.2.3