From 6eb08e7dda16c6dc8b7bdeed612e56ecc6b6e510 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 13 Jul 2018 23:57:52 +0200 Subject: [PATCH] fix allowedValues for statetypes --- libnymea-app-core/devicemanager.cpp | 1 + libnymea-app-core/jsonrpc/jsontypes.cpp | 2 ++ libnymea-app-core/rulemanager.cpp | 2 +- libnymea-common/types/paramtype.cpp | 2 +- libnymea-common/types/paramtype.h | 2 +- libnymea-common/types/statetype.cpp | 10 ++++++++++ libnymea-common/types/statetype.h | 5 +++++ nymea-app/ui/delegates/ParamDescriptorDelegate.qml | 2 +- nymea-app/ui/devicelistpages/GenericDeviceListPage.qml | 2 +- nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml | 1 + 10 files changed, 24 insertions(+), 5 deletions(-) diff --git a/libnymea-app-core/devicemanager.cpp b/libnymea-app-core/devicemanager.cpp index 8e035da2..62efb381 100644 --- a/libnymea-app-core/devicemanager.cpp +++ b/libnymea-app-core/devicemanager.cpp @@ -150,6 +150,7 @@ void DeviceManager::getVendorsResponse(const QVariantMap ¶ms) void DeviceManager::getSupportedDevicesResponse(const QVariantMap ¶ms) { + qDebug() << "DeviceClass received:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented)); if (params.value("params").toMap().keys().contains("deviceClasses")) { QVariantList deviceClassList = params.value("params").toMap().value("deviceClasses").toList(); foreach (QVariant deviceClassVariant, deviceClassList) { diff --git a/libnymea-app-core/jsonrpc/jsontypes.cpp b/libnymea-app-core/jsonrpc/jsontypes.cpp index bb620de4..c99d82d3 100644 --- a/libnymea-app-core/jsonrpc/jsontypes.cpp +++ b/libnymea-app-core/jsonrpc/jsontypes.cpp @@ -157,7 +157,9 @@ StateType *JsonTypes::unpackStateType(const QVariantMap &stateTypeMap, QObject * stateType->setDisplayName(stateTypeMap.value("displayName").toString()); stateType->setIndex(stateTypeMap.value("index").toInt()); stateType->setDefaultValue(stateTypeMap.value("defaultValue")); + stateType->setAllowedValues(stateTypeMap.value("possibleValues").toList()); stateType->setType(stateTypeMap.value("type").toString()); + QPair unit = stringToUnit(stateTypeMap.value("unit").toString()); stateType->setUnit(unit.first); stateType->setUnitString(unit.second); diff --git a/libnymea-app-core/rulemanager.cpp b/libnymea-app-core/rulemanager.cpp index 3f22ac99..14970864 100644 --- a/libnymea-app-core/rulemanager.cpp +++ b/libnymea-app-core/rulemanager.cpp @@ -154,7 +154,7 @@ void RuleManager::getRuleDetailsReply(const QVariantMap ¶ms) qDebug() << "Got rule details for a rule we don't know"; return; } - qDebug() << "got rule details for rule" << qUtf8Printable(QJsonDocument::fromVariant(ruleMap).toJson()); +// qDebug() << "got rule details for rule" << qUtf8Printable(QJsonDocument::fromVariant(ruleMap).toJson()); parseEventDescriptors(ruleMap.value("eventDescriptors").toList(), rule); parseRuleActions(ruleMap.value("actions").toList(), rule); parseRuleExitActions(ruleMap.value("exitActions").toList(), rule); diff --git a/libnymea-common/types/paramtype.cpp b/libnymea-common/types/paramtype.cpp index ea7c7e84..b2fcc5aa 100644 --- a/libnymea-common/types/paramtype.cpp +++ b/libnymea-common/types/paramtype.cpp @@ -147,7 +147,7 @@ void ParamType::setUnit(const Types::Unit &unit) m_unit = unit; } -QList ParamType::allowedValues() const +QVariantList ParamType::allowedValues() const { return m_allowedValues; } diff --git a/libnymea-common/types/paramtype.h b/libnymea-common/types/paramtype.h index 7ecf1f6a..c7007c4e 100644 --- a/libnymea-common/types/paramtype.h +++ b/libnymea-common/types/paramtype.h @@ -83,7 +83,7 @@ public: QString unitString() const; void setUnitString(const QString &unitString); - QList allowedValues() const; + QVariantList allowedValues() const; void setAllowedValues(const QList allowedValues); bool readOnly() const; diff --git a/libnymea-common/types/statetype.cpp b/libnymea-common/types/statetype.cpp index c4a546bd..99888e2e 100644 --- a/libnymea-common/types/statetype.cpp +++ b/libnymea-common/types/statetype.cpp @@ -92,6 +92,16 @@ void StateType::setDefaultValue(const QVariant &defaultValue) m_defaultValue = defaultValue; } +QVariantList StateType::allowedValues() const +{ + return m_allowedValues; +} + +void StateType::setAllowedValues(const QVariantList &allowedValues) +{ + m_allowedValues = allowedValues; +} + Types::Unit StateType::unit() const { return m_unit; diff --git a/libnymea-common/types/statetype.h b/libnymea-common/types/statetype.h index 8ab87380..85bdea34 100644 --- a/libnymea-common/types/statetype.h +++ b/libnymea-common/types/statetype.h @@ -38,6 +38,7 @@ class StateType : public QObject Q_PROPERTY(QString type READ type CONSTANT) Q_PROPERTY(int index READ index CONSTANT) Q_PROPERTY(QVariant defaultValue READ defaultValue CONSTANT) + Q_PROPERTY(QVariantList allowedValues READ allowedValues WRITE setAllowedValues CONSTANT) Q_PROPERTY(Types::Unit unit READ unit CONSTANT) Q_PROPERTY(QString unitString READ unitString CONSTANT) @@ -63,6 +64,9 @@ public: QVariant defaultValue() const; void setDefaultValue(const QVariant &defaultValue); + QVariantList allowedValues() const; + void setAllowedValues(const QVariantList &allowedValues); + Types::Unit unit() const; void setUnit(const Types::Unit &unit); @@ -76,6 +80,7 @@ private: QString m_type; int m_index; QVariant m_defaultValue; + QVariantList m_allowedValues; Types::Unit m_unit; QString m_unitString; diff --git a/nymea-app/ui/delegates/ParamDescriptorDelegate.qml b/nymea-app/ui/delegates/ParamDescriptorDelegate.qml index 481b0307..ab02b16e 100644 --- a/nymea-app/ui/delegates/ParamDescriptorDelegate.qml +++ b/nymea-app/ui/delegates/ParamDescriptorDelegate.qml @@ -62,7 +62,7 @@ ItemDelegate { Layout.fillWidth: true sourceComponent: { - print("Datatye is:", paramType.type, paramType.minValue, paramType.maxValue, paramType.allowedValues) + print("Datatye is:", paramType.name, paramType.type, paramType.minValue, paramType.maxValue, paramType.allowedValues) switch (paramType.type.toLowerCase()) { case "bool": return boolComponent; diff --git a/nymea-app/ui/devicelistpages/GenericDeviceListPage.qml b/nymea-app/ui/devicelistpages/GenericDeviceListPage.qml index a792d936..bef784c5 100644 --- a/nymea-app/ui/devicelistpages/GenericDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/GenericDeviceListPage.qml @@ -19,7 +19,7 @@ Page { header: GuhHeader { text: { if (subPage.shownInterfaces.length === 1) { - return qsTr("My %1 things").arg(interfaceToString(subPage.filterInterface)) + return qsTr("My %1").arg(interfaceToString(subPage.shownInterfaces[0])) } else if (subPage.shownInterfaces.length > 1 || subPage.hiddenInterfaces.length > 0) { return qsTr("My things") } diff --git a/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml b/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml index d06d6c55..a277ef23 100644 --- a/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml +++ b/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml @@ -40,6 +40,7 @@ SwipeDelegate { Label { Layout.fillWidth: true font.pixelSize: childEvaluatorsRepeater.count > 0 ? app.smallFont : app.mediumFont + wrapMode: Text.WordWrap property string operatorString: { if (!root.stateEvaluator) { return "";