Skip to content

Commit 4824afa

Browse files
vsklencarwonder-sk
vsklencar
authored andcommitted
[QgsQuick] Handling missing config values for CheckBox widget
Added widget's properties for un/checked value - if a config is missing for boolean field, default value is set and work with. If those values are not set for a different type of a field, its considered as not valid setup and will not be working.
1 parent 80a40dd commit 4824afa

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/quickgui/plugin/editor/qgsquickcheckbox.qml

+15-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import QgsQuick 0.1 as QgsQuick
2525
Item {
2626
signal valueChanged( var value, bool isNull )
2727

28+
/**
29+
* Handling missing config value for un/checked state for boolean field
30+
*/
31+
property var checkedState: getConfigValue(config['CheckedState'], true)
32+
property var uncheckedState: getConfigValue(config['UncheckedState'], false)
33+
2834
id: fieldItem
2935
enabled: !readOnly
3036
height: childrenRect.height
@@ -33,12 +39,18 @@ Item {
3339
left: parent.left
3440
}
3541

42+
function getConfigValue(configValue, defaultValue) {
43+
if (typeof value === "boolean" && !configValue) {
44+
return defaultValue
45+
} else return configValue
46+
}
47+
3648
CheckBox {
3749
property var currentValue: value
3850
height: customStyle.fields.height
3951
id: checkBox
4052
leftPadding: 0
41-
checked: config['CheckedState'] ? value == config['CheckedState'] : value
53+
checked: value === fieldItem.checkedState
4254

4355
indicator: Rectangle {
4456
implicitWidth: customStyle.fields.height
@@ -60,14 +72,13 @@ Item {
6072
}
6173
}
6274
onCheckedChanged: {
63-
valueChanged( checked ? (config['CheckedState'] ? config['CheckedState'] : true) :
64-
(config['UncheckedState'] ? config['UncheckedState'] : false), false )
75+
valueChanged( checked ? fieldItem.checkedState : fieldItem.uncheckedState, false )
6576
forceActiveFocus()
6677
}
6778

6879
// Workaround to get a signal when the value has changed
6980
onCurrentValueChanged: {
70-
checked = config['CheckedState'] ? currentValue == config['CheckedState'] : currentValue
81+
checked = currentValue === fieldItem.checkedState
7182
}
7283
}
7384
}

0 commit comments

Comments
 (0)