Merge PR #376: Small improvements in the edit rules page

This commit is contained in:
Jenkins nymea 2020-05-07 17:51:03 +02:00
commit d4eff3baa2
5 changed files with 35 additions and 14 deletions

View File

@ -66,7 +66,8 @@ ItemDelegate {
id: loader
Layout.fillWidth: true// sourceComponent === textFieldComponent || sourceComponent === stringComponent
sourceComponent: {
print("loading paramdelegate:", root.writable, root.paramType.type)
print("Loading ParamDelegate");
print("Writable:", root.writable, "type:", root.paramType.type, "min:", root.paramType.minValue, "max:", root.paramType.maxValue)
if (!root.writable) {
return stringComponent;
}
@ -79,7 +80,8 @@ ItemDelegate {
case "double":
if (root.paramType.allowedValues.length > 0) {
return comboBoxComponent;
} else if (root.paramType.minValue !== undefined && root.paramType.maxValue !== undefined) {
} else if (root.paramType.minValue !== undefined && root.paramType.maxValue !== undefined
&& (root.paramType.maxValue - root.paramType.minValue <= 100)) {
return sliderComponent;
} else {
return spinnerComponent;
@ -149,6 +151,7 @@ ItemDelegate {
id: sliderComponent
RowLayout {
spacing: app.margins
Slider {
id: slider
Layout.fillWidth: true
@ -162,7 +165,7 @@ ItemDelegate {
}
return ret;
}
property int decimals: root.paramType.type.toLocaleLowerCase() === "int" ? 0 : 1
property int decimals: root.paramType.type.toLocaleLowerCase() === "double" ? 1 : 0
onMoved: {
var newValue
@ -190,12 +193,12 @@ ItemDelegate {
SpinBox {
value: root.param.value ? root.param.value : 0
from: root.paramType.minValue
from: root.paramType.minValue !== undefined
? root.paramType.minValue
: root.paramType.type.toLowerCase() === "uint"
? 0
: -2000000000
to: root.paramType.maxValue
to: root.paramType.maxValue !== undefined
? root.paramType.maxValue
: 2000000000
editable: true
@ -205,6 +208,7 @@ ItemDelegate {
return Types.toUiValue(value, root.paramType.unit)
}
Component.onCompleted: {
print("from:", from, "min", root.paramType.minValue)
if (root.value === undefined) {
root.value = value
}

View File

@ -137,6 +137,7 @@ ItemDelegate {
Label {
text: Types.toUiUnit(paramType.unit)
visible: paramType.unit !== Types.UnitNone
}
}

View File

@ -499,7 +499,7 @@ Page {
Button {
Layout.fillWidth: true
Layout.margins: app.margins
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins; Layout.bottomMargin: app.margins
text: eventsRepeater.count == 0 && timeEventRepeater.count === 0 ? qsTr("Configure...") : qsTr("Add another...")
visible: !root.isStateBased
onClicked: {
@ -592,8 +592,8 @@ Page {
Button {
Layout.fillWidth: true
Layout.margins: app.margins
text: root.rule.stateEvaluator === null && root.rule.timeDescriptor.calendarItems.count === 0 ?
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins; Layout.bottomMargin: app.margins
text: root.rule.stateEvaluator === null || root.rule.timeDescriptor.calendarItems.count === 0 ?
qsTr("Configure...") :
qsTr("Add another...")
visible: root.rule.timeDescriptor.timeEventItems.count === 0 || root.rule.stateEvaluator === null
@ -661,7 +661,7 @@ Page {
Button {
Layout.fillWidth: true
Layout.margins: app.margins
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins; Layout.bottomMargin: app.margins
text: root.isEmpty ? qsTr("Configure...") :
actionsRepeater.count == 0 ? qsTr("Add an action...") : qsTr("Add another action...")
onClicked: {
@ -697,7 +697,7 @@ Page {
Button {
Layout.fillWidth: true
Layout.margins: app.margins
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins; Layout.bottomMargin: app.margins
text: actionsRepeater.count == 0 ? qsTr("Add an action...") : qsTr("Add another action...")
onClicked: {
var page = pageStack.push(ruleActionQuestionPageComponent, {exitAction: true});

View File

@ -64,9 +64,18 @@ NymeaListItemDelegate {
var ruleActionParam = root.ruleAction.ruleActionParams.get(i)
print("populating subtext:", ruleActionParam.eventTypeId, ruleActionParam.eventParamTypeId, ruleActionParam.stateDeviceId, ruleActionParam.stateTypeId, ruleActionParam.isValueBased, ruleActionParam.isEventParamBased, ruleActionParam.isStateValueBased)
var paramString = qsTr("%1: %2").arg(root.actionType.paramTypes.getParamType(ruleActionParam.paramTypeId).displayName)
var paramType = root.actionType.paramTypes.getParamType(ruleActionParam.paramTypeId);
var paramString = qsTr("%1: %2").arg(paramType.displayName)
if (ruleActionParam.isValueBased) {
paramString = paramString.arg(ruleActionParam.value)
var text = ""
switch (paramType.type.toLowerCase()) {
case "bool":
text = ruleActionParam.value === true ? qsTr("True") : qsTr("False")
break;
default:
text = ruleActionParam.value
}
paramString = paramString.arg(text)
} else if (ruleActionParam.isEventParamBased) {
paramString = paramString.arg(qsTr("value from event"))
} else if (ruleActionParam.isStateValueBased) {

View File

@ -97,10 +97,17 @@ SwipeDelegate {
if (!root.stateType) {
return qsTr("Press to edit condition")
}
var valueText = root.stateEvaluator.stateDescriptor.value;
switch (root.stateType.type.toLowerCase()) {
case "bool":
valueText = root.stateEvaluator.stateDescriptor.value === true ? qsTr("True") : qsTr("False")
break;
}
if (root.device) {
return qsTr("%1: %2 %3 %4").arg(root.device.name).arg(root.stateType.displayName).arg(operatorString).arg(root.stateEvaluator.stateDescriptor.value)
return qsTr("%1: %2 %3 %4").arg(root.device.name).arg(root.stateType.displayName).arg(operatorString).arg(valueText)
} else if (root.iface) {
return qsTr("%1: %2 %3 %4").arg(root.iface.displayName).arg(root.stateType.displayName).arg(operatorString).arg(root.stateEvaluator.stateDescriptor.value)
return qsTr("%1: %2 %3 %4").arg(root.iface.displayName).arg(root.stateType.displayName).arg(operatorString).arg(valueText)
}
return "--";
}