Merge PR #141: Fixes in some generic state delegates

This commit is contained in:
Jenkins 2019-02-05 23:11:54 +01:00
commit 0396098390
4 changed files with 30 additions and 6 deletions

View File

@ -9,6 +9,7 @@ Item {
id: colorComponentItem id: colorComponentItem
implicitWidth: app.iconSize * 2 implicitWidth: app.iconSize * 2
implicitHeight: app.iconSize implicitHeight: app.iconSize
property bool writable: false
property var value property var value
signal changed(var value) signal changed(var value)
@ -25,6 +26,10 @@ Item {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
if (!colorComponentItem.writable) {
return;
}
var pos = colorComponentItem.mapToItem(root, 0, colorComponentItem.height) var pos = colorComponentItem.mapToItem(root, 0, colorComponentItem.height)
print("opening", colorComponentItem.value) print("opening", colorComponentItem.value)
var colorPicker = colorPickerComponent.createObject(root, {preferredY: pos.y, colorValue: colorComponentItem.value }) var colorPicker = colorPickerComponent.createObject(root, {preferredY: pos.y, colorValue: colorComponentItem.value })

View File

@ -8,7 +8,7 @@ import "../../components"
SpinBox { SpinBox {
width: 150 width: 150
signal changed(var value) signal changed(var value)
stepSize: (to - from) / 10 stepSize: Math.min(10, (to - from) / 10)
editable: true editable: true
onValueModified: { onValueModified: {
changed(value) changed(value)

View File

@ -8,4 +8,9 @@ import "../../components"
TextField { TextField {
property var value property var value
text: value text: value
signal changed(string value)
onEditingFinished: {
changed(text)
}
} }

View File

@ -12,6 +12,7 @@ DevicePageBase {
showDetailsButton: false showDetailsButton: false
function executeAction(actionTypeId, params) { function executeAction(actionTypeId, params) {
print("executing", actionTypeId)
return engine.deviceManager.executeAction(root.device.id, actionTypeId, params) return engine.deviceManager.executeAction(root.device.id, actionTypeId, params)
} }
@ -140,7 +141,7 @@ DevicePageBase {
switch (stateDelegate.stateType.type.toLowerCase()) { switch (stateDelegate.stateType.type.toLowerCase()) {
case "string": case "string":
if (isWritable) { if (isWritable) {
if (stateDelegate.stateType.allowedValues !== undefined) { if (stateDelegate.stateType.allowedValues.length > 0) {
sourceComp = "ComboBoxDelegate.qml" sourceComp = "ComboBoxDelegate.qml"
} else { } else {
sourceComp = "TextFieldDelegate.qml"; sourceComp = "TextFieldDelegate.qml";
@ -160,12 +161,16 @@ DevicePageBase {
} }
break; break;
case "int": case "int":
case "uint":
case "double": case "double":
if (stateDelegate.stateType.unit === Types.UnitUnixTime) { if (stateDelegate.stateType.unit === Types.UnitUnixTime) {
sourceComp = "DateTimeDelegate.qml"; sourceComp = "DateTimeDelegate.qml";
} else if (isWritable) { } else if (isWritable) {
sourceComp = "SliderDelegate.qml"; if (stateDelegate.stateType.minValue !== undefined && stateDelegate.stateType.maxValue !== undefined) {
// sourceComp = "SpinBoxDelegate.qml"; sourceComp = "SliderDelegate.qml";
} else {
sourceComp = "SpinBoxDelegate.qml";
}
} else { } else {
sourceComp = "NumberLabelDelegate.qml"; sourceComp = "NumberLabelDelegate.qml";
} }
@ -179,12 +184,21 @@ DevicePageBase {
print("GenericDevicePage: unhandled entry", stateDelegate.stateType.displayName) print("GenericDevicePage: unhandled entry", stateDelegate.stateType.displayName)
} }
var minValue = stateDelegate.stateType.minValue
? stateDelegate.stateType.minValue
: stateDelegate.stateType.type.toLowerCase() === "uint"
? 0
: -2000000000; // As per QML spec
var maxValue = stateDelegate.stateType.maxValue
? stateDelegate.stateType.maxValue
: 2000000000;
stateDelegateLoader.setSource("../delegates/statedelegates/" + sourceComp, stateDelegateLoader.setSource("../delegates/statedelegates/" + sourceComp,
{ {
// value: root.device.states.getState(stateType.id).value, // value: root.device.states.getState(stateType.id).value,
possibleValues: stateDelegate.stateType.allowedValues, possibleValues: stateDelegate.stateType.allowedValues,
from: stateDelegate.stateType.minValue, from: minValue,
to: stateDelegate.stateType.maxValue, to: maxValue,
writable: isWritable,
stateType: stateDelegate.stateType stateType: stateDelegate.stateType
}) })
} }