diff --git a/libnymea-app/rulemanager.cpp b/libnymea-app/rulemanager.cpp index e344fb93..5747faf2 100644 --- a/libnymea-app/rulemanager.cpp +++ b/libnymea-app/rulemanager.cpp @@ -427,7 +427,7 @@ QVariantList RuleManager::packEventDescriptors(EventDescriptors *eventDescriptor QVariantList paramDescriptors; for (int j = 0; j < eventDescriptor->paramDescriptors()->rowCount(); j++) { QVariantMap paramDescriptor; - if (!eventDescriptor->paramDescriptors()->get(j)->paramTypeId().isEmpty()) { + if (!eventDescriptor->paramDescriptors()->get(j)->paramTypeId().isNull()) { paramDescriptor.insert("paramTypeId", eventDescriptor->paramDescriptors()->get(j)->paramTypeId()); } else { paramDescriptor.insert("paramName", eventDescriptor->paramDescriptors()->get(j)->paramName()); diff --git a/libnymea-app/types/actiontypes.cpp b/libnymea-app/types/actiontypes.cpp index 14972811..0ae3c23e 100644 --- a/libnymea-app/types/actiontypes.cpp +++ b/libnymea-app/types/actiontypes.cpp @@ -49,7 +49,6 @@ ActionType *ActionTypes::get(int index) const ActionType *ActionTypes::getActionType(const QUuid &actionTypeId) const { foreach (ActionType *actionType, m_actionTypes) { - qDebug() << "checking:" << actionType->id(); if (actionType->id() == actionTypeId) { return actionType; } diff --git a/libnymea-app/types/param.cpp b/libnymea-app/types/param.cpp index 7ca55ad5..6c57ce92 100644 --- a/libnymea-app/types/param.cpp +++ b/libnymea-app/types/param.cpp @@ -30,7 +30,7 @@ #include "param.h" -Param::Param(const QString ¶mTypeId, const QVariant &value, QObject *parent) : +Param::Param(const QUuid ¶mTypeId, const QVariant &value, QObject *parent) : QObject(parent), m_paramTypeId(paramTypeId), m_value(value) @@ -43,12 +43,12 @@ Param::Param(QObject *parent): } -QString Param::paramTypeId() const +QUuid Param::paramTypeId() const { return m_paramTypeId; } -void Param::setParamTypeId(const QString ¶mTypeId) +void Param::setParamTypeId(const QUuid ¶mTypeId) { if (m_paramTypeId != paramTypeId) { m_paramTypeId = paramTypeId; diff --git a/libnymea-app/types/param.h b/libnymea-app/types/param.h index 9f0971a5..5a421b2d 100644 --- a/libnymea-app/types/param.h +++ b/libnymea-app/types/param.h @@ -32,21 +32,21 @@ #define PARAM_H #include -#include +#include #include class Param : public QObject { Q_OBJECT - Q_PROPERTY(QString paramTypeId READ paramTypeId WRITE setParamTypeId NOTIFY paramTypeIdChanged) + Q_PROPERTY(QUuid paramTypeId READ paramTypeId WRITE setParamTypeId NOTIFY paramTypeIdChanged) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) public: - Param(const QString ¶mTypeId = QString(), const QVariant &value = QVariant(), QObject *parent = nullptr); + Param(const QUuid ¶mTypeId = QString(), const QVariant &value = QVariant(), QObject *parent = nullptr); Param(QObject *parent); - QString paramTypeId() const; - void setParamTypeId(const QString ¶mTypeId); + QUuid paramTypeId() const; + void setParamTypeId(const QUuid ¶mTypeId); QVariant value() const; void setValue(const QVariant &value); @@ -56,7 +56,7 @@ signals: void valueChanged(); protected: - QString m_paramTypeId; + QUuid m_paramTypeId; QVariant m_value; }; diff --git a/libnymea-app/types/paramtypes.cpp b/libnymea-app/types/paramtypes.cpp index b2c05fec..9192b2ad 100644 --- a/libnymea-app/types/paramtypes.cpp +++ b/libnymea-app/types/paramtypes.cpp @@ -48,10 +48,10 @@ ParamType *ParamTypes::get(int index) const return nullptr; } -ParamType *ParamTypes::getParamType(const QString &id) const +ParamType *ParamTypes::getParamType(const QUuid &id) const { foreach (ParamType *paramType, m_paramTypes) { - if (paramType->id() == QUuid(id)) { + if (paramType->id() == id) { return paramType; } } diff --git a/libnymea-app/types/paramtypes.h b/libnymea-app/types/paramtypes.h index 1e5f6efe..2337b278 100644 --- a/libnymea-app/types/paramtypes.h +++ b/libnymea-app/types/paramtypes.h @@ -59,7 +59,7 @@ public: QList paramTypes(); Q_INVOKABLE ParamType *get(int index) const; - Q_INVOKABLE ParamType *getParamType(const QString &id) const; + Q_INVOKABLE ParamType *getParamType(const QUuid &id) const; Q_INVOKABLE ParamType *findByName(const QString &name) const; int rowCount(const QModelIndex & parent = QModelIndex()) const; diff --git a/libnymea-app/types/ruleactionparams.cpp b/libnymea-app/types/ruleactionparams.cpp index 7dd13bfa..e75aae2a 100644 --- a/libnymea-app/types/ruleactionparams.cpp +++ b/libnymea-app/types/ruleactionparams.cpp @@ -74,9 +74,10 @@ void RuleActionParams::addRuleActionParam(RuleActionParam *ruleActionParam) beginInsertRows(QModelIndex(), m_list.count(), m_list.count()); m_list.append(ruleActionParam); endInsertRows(); + emit countChanged(); } -void RuleActionParams::setRuleActionParam(const QString ¶mTypeId, const QVariant &value) +void RuleActionParams::setRuleActionParam(const QUuid ¶mTypeId, const QVariant &value) { foreach (RuleActionParam *rap, m_list) { if (rap->paramTypeId() == paramTypeId) { @@ -174,6 +175,9 @@ void RuleActionParams::setRuleActionParamStateByName(const QString ¶mName, c RuleActionParam *RuleActionParams::get(int index) const { + if (index < 0 || index >= m_list.count()) { + return nullptr; + } return m_list.at(index); } @@ -187,6 +191,15 @@ bool RuleActionParams::hasRuleActionParam(const QString ¶mTypeId) const return false; } +void RuleActionParams::clear() +{ + beginResetModel(); + qDeleteAll(m_list); + m_list.clear(); + endResetModel(); + emit countChanged(); +} + bool RuleActionParams::operator==(RuleActionParams *other) const { if (rowCount() != other->rowCount()) { diff --git a/libnymea-app/types/ruleactionparams.h b/libnymea-app/types/ruleactionparams.h index 013b10cb..2e6fcd07 100644 --- a/libnymea-app/types/ruleactionparams.h +++ b/libnymea-app/types/ruleactionparams.h @@ -56,7 +56,7 @@ public: void addRuleActionParam(RuleActionParam* ruleActionParam); - Q_INVOKABLE void setRuleActionParam(const QString ¶mTypeId, const QVariant &value); + Q_INVOKABLE void setRuleActionParam(const QUuid ¶mTypeId, const QVariant &value); Q_INVOKABLE void setRuleActionParamByName(const QString ¶mName, const QVariant &value); Q_INVOKABLE void setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId); Q_INVOKABLE void setRuleActionParamEventByName(const QString ¶mName, const QString &eventTypeId, const QString &eventParamTypeId); @@ -67,6 +67,8 @@ public: Q_INVOKABLE bool hasRuleActionParam(const QString ¶mTypeId) const; + Q_INVOKABLE void clear(); + bool operator==(RuleActionParams *other) const; signals: diff --git a/nymea-app/ui/delegates/ParamDelegate.qml b/nymea-app/ui/delegates/ParamDelegate.qml index 41eeda1f..bf205c0a 100644 --- a/nymea-app/ui/delegates/ParamDelegate.qml +++ b/nymea-app/ui/delegates/ParamDelegate.qml @@ -67,7 +67,7 @@ ItemDelegate { Layout.fillWidth: true// sourceComponent === textFieldComponent || sourceComponent === stringComponent sourceComponent: { print("Loading ParamDelegate"); - print("Writable:", root.writable, "type:", root.paramType.type, "min:", root.paramType.minValue, "max:", root.paramType.maxValue) + print("Writable:", root.writable, "type:", root.paramType.type, "min:", root.paramType.minValue, "max:", root.paramType.maxValue, "value:", root.param.value) if (!root.writable) { return stringComponent; } @@ -77,6 +77,9 @@ ItemDelegate { return boolComponent; case "uint": case "int": + if (root.paramType.name == "colorTemperature") { + return null; + } case "double": if (root.paramType.allowedValues.length > 0) { return comboBoxComponent; @@ -103,13 +106,11 @@ ItemDelegate { Loader { Layout.fillWidth: true sourceComponent: { + if (root.paramType.name == "colorTemperature") { + return colorTemperaturePickerComponent; + } + switch (root.paramType.type.toLowerCase()) { -// case "int": -// case "double": -// if (root.paramType.minValue !== undefined && root.paramType.maxValue !== undefined) { -// return sliderComponent -// } -// break; case "color": return colorPickerComponent } @@ -312,6 +313,32 @@ ItemDelegate { } } + Component { + id: colorTemperaturePickerComponent + ColorPickerCt { + id: colorPickerCt + implicitHeight: 50 + minCt: root.paramType.minValue + maxCt: root.paramType.maxValue + ct: root.param.value !== undefined + ? root.param.value + : root.paramType.defaultValue + ? root.paramType.defaultValue + : root.paramType.minValue + + onCtChanged: { + root.param.value = ct + } + + + touchDelegate: Rectangle { + height: colorPickerCt.height + width: 5 + color: app.accentColor + } + } + } + Component { id: colorPreviewComponent Rectangle { diff --git a/nymea-app/ui/devicepages/LightDevicePage.qml b/nymea-app/ui/devicepages/LightDevicePage.qml index de8dae6a..5cea7c52 100644 --- a/nymea-app/ui/devicepages/LightDevicePage.qml +++ b/nymea-app/ui/devicepages/LightDevicePage.qml @@ -220,7 +220,7 @@ DevicePageBase { touchDelegate: Rectangle { height: pickerCt.height width: 5 - color: app.foregroundColor + color: app.accentColor } property var lastSentTime: new Date() diff --git a/nymea-app/ui/magic/RuleActionDelegate.qml b/nymea-app/ui/magic/RuleActionDelegate.qml index 1bf93385..9e2e43aa 100644 --- a/nymea-app/ui/magic/RuleActionDelegate.qml +++ b/nymea-app/ui/magic/RuleActionDelegate.qml @@ -72,6 +72,9 @@ NymeaListItemDelegate { case "bool": text = ruleActionParam.value === true ? qsTr("True") : qsTr("False") break; + case "color": + text = "" + break; default: text = ruleActionParam.value } diff --git a/nymea-app/ui/magic/SelectRuleActionPage.qml b/nymea-app/ui/magic/SelectRuleActionPage.qml index 301ba81b..eb92a319 100644 --- a/nymea-app/ui/magic/SelectRuleActionPage.qml +++ b/nymea-app/ui/magic/SelectRuleActionPage.qml @@ -175,7 +175,10 @@ Page { } else { var actionType = root.deviceClass.actionTypes.getActionType(model.actionTypeId); console.log("ActionType", actionType.id, "selected. Has", actionType.paramTypes.count, "params"); - root.ruleAction.actionTypeId = actionType.id; + if (root.ruleAction.actionTypeId !== actionType.id) { + root.ruleAction.actionTypeId = actionType.id; + root.ruleAction.ruleActionParams.clear(); + } root.ruleAction.browserItemId = ""; root.ruleAction.interfaceAction = ""; if (actionType.paramTypes.count > 0) { diff --git a/nymea-app/ui/magic/SelectRuleActionParamsPage.qml b/nymea-app/ui/magic/SelectRuleActionParamsPage.qml index e37e79b6..4cd0d767 100644 --- a/nymea-app/ui/magic/SelectRuleActionParamsPage.qml +++ b/nymea-app/ui/magic/SelectRuleActionParamsPage.qml @@ -38,14 +38,14 @@ import Nymea 1.0 Page { id: root // Needs to be set and have rule.ruleActions filled in with deviceId and actionTypeId or interfaceName and interfaceAction - property var ruleAction: null + property RuleAction ruleAction: null // optionally a rule which will be used to propose events params as param values property var rule: null - readonly property var device: ruleAction && ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null + readonly property Device device: ruleAction && ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null readonly property var iface: ruleAction && ruleAction.interfaceName ? Interfaces.findByName(ruleAction.interfaceName) : null - readonly property var actionType: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId).actionTypes.getActionType(ruleAction.actionTypeId) + readonly property var actionType: device ? device.deviceClass.actionTypes.getActionType(ruleAction.actionTypeId) : iface ? iface.actionTypes.findByName(ruleAction.interfaceAction) : null signal backPressed(); @@ -125,6 +125,7 @@ Page { paramType: root.actionType.paramTypes.get(index) enabled: staticParamRadioButton.checked nameVisible: false + value: root.ruleAction.ruleActionParams.get(index).value visible: staticParamRadioButton.checked placeholderText: qsTr("Insert value here") } diff --git a/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml b/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml index fd23ed6a..1e07e7b8 100644 --- a/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml +++ b/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml @@ -63,7 +63,7 @@ SwipeDelegate { ColorIcon { Layout.preferredHeight: childEvaluatorsRepeater.count > 0 ? app.iconSize * .6 : app.iconSize Layout.preferredWidth: height - name: root.stateEvaluator.stateDescriptor.interfaceName.length === 0 ? "../images/state.svg" : "../images/state-interface.svg" + name: root.stateEvaluator && root.stateEvaluator.stateDescriptor.interfaceName.length === 0 ? "../images/state.svg" : "../images/state-interface.svg" color: app.accentColor }