Skip to content

Commit

Permalink
[QgsQuick] Handling missing config values for CheckBox widget
Browse files Browse the repository at this point in the history
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 4824afa
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/quickgui/plugin/editor/qgsquickcheckbox.qml
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.