Skip to content
Permalink
Browse files

[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.
  • Loading branch information
vsklencar authored and wonder-sk committed Apr 25, 2019
1 parent 80a40dd commit 4824afabc46eabc9a8e43611c276ff229fc1870d
Showing with 15 additions and 4 deletions.
  1. +15 −4 src/quickgui/plugin/editor/qgsquickcheckbox.qml
@@ -25,6 +25,12 @@ import QgsQuick 0.1 as QgsQuick
Item {
signal valueChanged( var value, bool isNull )

/**
* Handling missing config value for un/checked state for boolean field
*/
property var checkedState: getConfigValue(config['CheckedState'], true)
property var uncheckedState: getConfigValue(config['UncheckedState'], false)

id: fieldItem
enabled: !readOnly
height: childrenRect.height
@@ -33,12 +39,18 @@ Item {
left: parent.left
}

function getConfigValue(configValue, defaultValue) {
if (typeof value === "boolean" && !configValue) {
return defaultValue
} else return configValue
}

CheckBox {
property var currentValue: value
height: customStyle.fields.height
id: checkBox
leftPadding: 0
checked: config['CheckedState'] ? value == config['CheckedState'] : value
checked: value === fieldItem.checkedState

indicator: Rectangle {
implicitWidth: customStyle.fields.height
@@ -60,14 +72,13 @@ Item {
}
}
onCheckedChanged: {
valueChanged( checked ? (config['CheckedState'] ? config['CheckedState'] : true) :
(config['UncheckedState'] ? config['UncheckedState'] : false), false )
valueChanged( checked ? fieldItem.checkedState : fieldItem.uncheckedState, false )
forceActiveFocus()
}

// Workaround to get a signal when the value has changed
onCurrentValueChanged: {
checked = config['CheckedState'] ? currentValue == config['CheckedState'] : currentValue
checked = currentValue === fieldItem.checkedState
}
}
}

0 comments on commit 4824afa

Please sign in to comment.
You can’t perform that action at this time.