aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/controls
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-09-08 10:13:34 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-09-10 15:25:25 +0000
commit34dcf20a0536ec7df4f847b16f03e6f66f308025 (patch)
tree4787089abdfaea7599180c4d7ef68e746d047c98 /tests/auto/controls
parent8a0135b82e9b354fe5304144a12c850c248f2a79 (diff)
Add ExclusiveGroup::checkables
Exclusive checkables typically share the same parent item. For example, a row or column positioner or layout. This change makes it convenient to handle such cases so that one can add the whole list of children to an exclusive group, without the need of creating any attached objects. Column { id: column ExclusiveGroup { id: eg checkables: column.children } Switch { id: s1; text: qsTr("First") } Switch { id: s2; text: qsTr("Second") } Switch { id: s3; text: qsTr("Third") } } Last but not least, this allows breaking the C++ dependency between QQuickTabBar and QQuickExclusiveGroup. Change-Id: Ic75065b87ef8fa532f77118d740f04484994bbf0 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Diffstat (limited to 'tests/auto/controls')
-rw-r--r--tests/auto/controls/data/tst_exclusivegroup.qml93
1 files changed, 89 insertions, 4 deletions
diff --git a/tests/auto/controls/data/tst_exclusivegroup.qml b/tests/auto/controls/data/tst_exclusivegroup.qml
index 537121d0..41794ab2 100644
--- a/tests/auto/controls/data/tst_exclusivegroup.qml
+++ b/tests/auto/controls/data/tst_exclusivegroup.qml
@@ -50,24 +50,45 @@ TestCase {
when: windowShown
name: "ExclusiveGroup"
+ Component {
+ id: exclusiveGroup
+ ExclusiveGroup { }
+ }
+
+ Component {
+ id: checkableGroup
+ ExclusiveGroup {
+ QtObject { objectName: "non-checkable" }
+ QtObject { objectName: "checkable1"; property bool checked: false }
+ QtObject { objectName: "checkable2"; property bool checked: true }
+ QtObject { objectName: "checkable3"; property bool checked: false }
+ }
+ }
+
SignalSpy {
id: currentSpy
signalName: "currentChanged"
}
- Component {
- id: exclusiveGroup
- ExclusiveGroup { }
+ SignalSpy {
+ id: checkablesSpy
+ signalName: "checkablesChanged"
}
function init() {
verify(!currentSpy.target)
compare(currentSpy.count, 0)
+
+ verify(!checkablesSpy.target)
+ compare(checkablesSpy.count, 0)
}
function cleanup() {
currentSpy.target = null
currentSpy.clear()
+
+ checkablesSpy.target = null
+ checkablesSpy.clear()
}
function test_null() {
@@ -156,6 +177,55 @@ TestCase {
group.destroy()
}
+ function test_checkables() {
+ ignoreWarning(Qt.resolvedUrl("tst_exclusivegroup.qml") + ":60:9: QML ExclusiveGroup: The object has no checkedChanged() or toggled() signal.")
+ var group = checkableGroup.createObject(testCase)
+ verify(group)
+
+ checkablesSpy.target = group
+ verify(checkablesSpy.valid)
+
+ compare(group.checkables.length, 3)
+ compare(group.checkables[0].objectName, "checkable1")
+ compare(group.checkables[1].objectName, "checkable2")
+ compare(group.checkables[2].objectName, "checkable3")
+ compare(group.current, group.checkables[1])
+
+ var checkable4 = checkable.createObject(testCase, {checked: true})
+ var checkable5 = checkable.createObject(testCase, {checked: false})
+
+ group.checkables = [checkable4, checkable5]
+ compare(group.checkables.length, 2)
+ compare(group.checkables[0], checkable4)
+ compare(group.checkables[1], checkable5)
+ compare(group.current, checkable4)
+ compare(checkablesSpy.count, 3) // clear + 2 * append :/
+
+ var checkable6 = checkable.createObject(testCase, {checked: true})
+
+ group.addCheckable(checkable6)
+ compare(group.checkables.length, 3)
+ compare(group.checkables[0], checkable4)
+ compare(group.checkables[1], checkable5)
+ compare(group.checkables[2], checkable6)
+ compare(group.current, checkable6)
+ compare(checkablesSpy.count, 4)
+
+ group.removeCheckable(checkable4)
+ compare(group.checkables.length, 2)
+ compare(group.checkables[0], checkable5)
+ compare(group.checkables[1], checkable6)
+ compare(group.current, checkable6)
+ compare(checkablesSpy.count, 5)
+
+ group.checkables = []
+ compare(group.checkables.length, 0)
+ compare(group.current, null)
+ compare(checkablesSpy.count, 6)
+
+ group.destroy()
+ }
+
Component {
id: checkBoxes
Item {
@@ -196,12 +266,27 @@ TestCase {
}
}
+ Component {
+ id: childControls
+ Item {
+ id: container
+ property ExclusiveGroup group: ExclusiveGroup { id: group; checkables: container.children }
+ property alias control1: control1
+ property alias control2: control2
+ property alias control3: control3
+ CheckBox { id: control1 }
+ RadioButton { id: control2 }
+ Switch { id: control3 }
+ }
+ }
+
function test_controls_data() {
return [
{ tag: "CheckBox", component: checkBoxes },
{ tag: "RadioButton", component: radioButtons },
{ tag: "Switch", component: switches },
- { tag: "ToggleButton", component: toggleButtons }
+ { tag: "ToggleButton", component: toggleButtons },
+ { tag: "Children", component: childControls }
]
}