From c30edaafdc4c2aec20ac0e2218d2e987af894e5d Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 7 May 2020 15:24:41 +0200 Subject: [PATCH 1/2] Small improvments in the edit rules page --- nymea-app/ui/magic/EditRulePage.qml | 10 +++++----- nymea-app/ui/magic/RuleActionDelegate.qml | 13 +++++++++++-- nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml | 11 +++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/nymea-app/ui/magic/EditRulePage.qml b/nymea-app/ui/magic/EditRulePage.qml index 1c4f9ce7..60e9099c 100644 --- a/nymea-app/ui/magic/EditRulePage.qml +++ b/nymea-app/ui/magic/EditRulePage.qml @@ -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}); diff --git a/nymea-app/ui/magic/RuleActionDelegate.qml b/nymea-app/ui/magic/RuleActionDelegate.qml index e8557b72..1bf93385 100644 --- a/nymea-app/ui/magic/RuleActionDelegate.qml +++ b/nymea-app/ui/magic/RuleActionDelegate.qml @@ -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) { diff --git a/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml b/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml index fe84366c..fd23ed6a 100644 --- a/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml +++ b/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml @@ -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 "--"; } From d69c466c22bd5ab47b85655a7c133ae18b53beb2 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 7 May 2020 17:37:40 +0200 Subject: [PATCH 2/2] Also tune some param delegates a bit --- nymea-app/ui/delegates/ParamDelegate.qml | 14 +++++++++----- nymea-app/ui/delegates/ParamDescriptorDelegate.qml | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/nymea-app/ui/delegates/ParamDelegate.qml b/nymea-app/ui/delegates/ParamDelegate.qml index 41421a29..4dc710c5 100644 --- a/nymea-app/ui/delegates/ParamDelegate.qml +++ b/nymea-app/ui/delegates/ParamDelegate.qml @@ -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 } diff --git a/nymea-app/ui/delegates/ParamDescriptorDelegate.qml b/nymea-app/ui/delegates/ParamDescriptorDelegate.qml index 6c4de5ae..0dcf6cee 100644 --- a/nymea-app/ui/delegates/ParamDescriptorDelegate.qml +++ b/nymea-app/ui/delegates/ParamDescriptorDelegate.qml @@ -137,6 +137,7 @@ ItemDelegate { Label { text: Types.toUiUnit(paramType.unit) + visible: paramType.unit !== Types.UnitNone } }