From 748793b376942729b483e91127abc5d05b194a85 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 13 Feb 2021 00:39:56 +0100 Subject: [PATCH 1/2] Update devices to things in interfacesproxy --- libnymea-app/models/interfacesproxy.cpp | 12 +++++------ libnymea-app/models/interfacesproxy.h | 20 +++++++++---------- .../ui/customviews/ThermostatController.qml | 2 +- nymea-app/ui/grouping/GroupThingsPage.qml | 2 +- nymea-app/ui/magic/SelectThingPage.qml | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libnymea-app/models/interfacesproxy.cpp b/libnymea-app/models/interfacesproxy.cpp index b16eea8c..059e92d6 100644 --- a/libnymea-app/models/interfacesproxy.cpp +++ b/libnymea-app/models/interfacesproxy.cpp @@ -98,11 +98,11 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source } } - if (m_devicesFilter != nullptr) { + if (m_thingsFilter != nullptr) { // TODO: This could be improved *a lot* by caching interfaces in the devices model... bool found = false; - for (int i = 0; i < m_devicesFilter->rowCount(); i++) { - Device *d = m_devicesFilter->get(i); + for (int i = 0; i < m_thingsFilter->rowCount(); i++) { + Device *d = m_thingsFilter->get(i); if (!d->thingClass()) { qWarning() << "Cannot find DeviceClass for device:" << d->id() << d->name(); return false; @@ -116,11 +116,11 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source return false; } } - if (m_devicesProxyFilter != nullptr) { + if (m_thingsProxyFilter != nullptr) { // TODO: This could be improved *a lot* by caching interfaces in the devices model... bool found = false; - for (int i = 0; i < m_devicesProxyFilter->rowCount(); i++) { - Device *d = m_devicesProxyFilter->get(i); + for (int i = 0; i < m_thingsProxyFilter->rowCount(); i++) { + Device *d = m_thingsProxyFilter->get(i); if (!d->thingClass()) { qWarning() << "Cannot find ThingClass for thing:" << d->id() << d->name(); return false; diff --git a/libnymea-app/models/interfacesproxy.h b/libnymea-app/models/interfacesproxy.h index 30f0049b..271c681c 100644 --- a/libnymea-app/models/interfacesproxy.h +++ b/libnymea-app/models/interfacesproxy.h @@ -44,8 +44,8 @@ class InterfacesProxy: public QSortFilterProxyModel Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged) - Q_PROPERTY(Devices* devicesFilter READ devicesFilter WRITE setDevicesFilter NOTIFY devicesFilterChanged) - Q_PROPERTY(DevicesProxy* devicesProxyFilter READ devicesProxyFilter WRITE setDevicesProxyFilter NOTIFY devicesProxyFilterChanged) + Q_PROPERTY(Devices* thingsFilter READ thingsFilter WRITE setThingsFilter NOTIFY thingsFilterChanged) + Q_PROPERTY(DevicesProxy* thingsProxyFilter READ thingsProxyFilter WRITE setThingsProxyFilter NOTIFY thingsProxyFilterChanged) Q_PROPERTY(bool showEvents READ showEvents WRITE setShowEvents NOTIFY showEventsChanged) Q_PROPERTY(bool showActions READ showActions WRITE setShowActions NOTIFY showActionsChanged) Q_PROPERTY(bool showStates READ showStates WRITE setShowStates NOTIFY showStatesChanged) @@ -56,11 +56,11 @@ public: QStringList shownInterfaces() const { return m_shownInterfaces; } void setShownInterfaces(const QStringList &shownInterfaces) { m_shownInterfaces = shownInterfaces; emit shownInterfacesChanged(); invalidateFilter(); } - Devices* devicesFilter() const { return m_devicesFilter; } - void setDevicesFilter(Devices *devices) { m_devicesFilter = devices; emit devicesFilterChanged(); invalidateFilter(); } + Devices* thingsFilter() const { return m_thingsFilter; } + void setThingsFilter(Devices *things) { m_thingsFilter = things; emit thingsFilterChanged(); invalidateFilter(); } - DevicesProxy* devicesProxyFilter() const { return m_devicesProxyFilter; } - void setDevicesProxyFilter(DevicesProxy *devicesProxy) { m_devicesProxyFilter = devicesProxy; emit devicesProxyFilterChanged(); invalidateFilter(); } + DevicesProxy* thingsProxyFilter() const { return m_thingsProxyFilter; } + void setThingsProxyFilter(DevicesProxy *thingsProxy) { m_thingsProxyFilter = thingsProxy; emit thingsProxyFilterChanged(); invalidateFilter(); } bool showEvents() const; void setShowEvents(bool showEvents); @@ -78,8 +78,8 @@ public: signals: void shownInterfacesChanged(); - void devicesFilterChanged(); - void devicesProxyFilterChanged(); + void thingsFilterChanged(); + void thingsProxyFilterChanged(); void showEventsChanged(); void showActionsChanged(); void showStatesChanged(); @@ -89,8 +89,8 @@ signals: private: Interfaces *m_interfaces = nullptr; QStringList m_shownInterfaces; - Devices* m_devicesFilter = nullptr; - DevicesProxy* m_devicesProxyFilter = nullptr; + Devices* m_thingsFilter = nullptr; + DevicesProxy* m_thingsProxyFilter = nullptr; bool m_showEvents = false; bool m_showActions = false; bool m_showStates = false; diff --git a/nymea-app/ui/customviews/ThermostatController.qml b/nymea-app/ui/customviews/ThermostatController.qml index 73a990ae..19a0beb8 100644 --- a/nymea-app/ui/customviews/ThermostatController.qml +++ b/nymea-app/ui/customviews/ThermostatController.qml @@ -136,7 +136,7 @@ Item { ctx.beginPath(); ctx.font = "" + app.hugeFont + "px " + Style.fontFamily; ctx.fillStyle = Style.foregroundColor; - var roundedTargetTemp = Types.toUiValue(root.targetTemperatureState.value, root.targetTemperatureStateType.unit) + var roundedTargetTemp = Types.toUiValue(currentValue, root.targetTemperatureStateType.unit) roundedTargetTemp = roundToPrecision(roundedTargetTemp).toFixed(1) + "°" var size = ctx.measureText(roundedTargetTemp) ctx.text(roundedTargetTemp, center.x - size.width / 2, center.y + app.hugeFont / 2); diff --git a/nymea-app/ui/grouping/GroupThingsPage.qml b/nymea-app/ui/grouping/GroupThingsPage.qml index 6966be01..f800bc16 100644 --- a/nymea-app/ui/grouping/GroupThingsPage.qml +++ b/nymea-app/ui/grouping/GroupThingsPage.qml @@ -54,7 +54,7 @@ Page { InterfacesProxy { id: interfacesInGroup - devicesProxyFilter: devicesInGroup + thingsProxyFilter: devicesInGroup showStates: true } diff --git a/nymea-app/ui/magic/SelectThingPage.qml b/nymea-app/ui/magic/SelectThingPage.qml index 512a14dd..6e5d0f2c 100644 --- a/nymea-app/ui/magic/SelectThingPage.qml +++ b/nymea-app/ui/magic/SelectThingPage.qml @@ -70,7 +70,7 @@ Page { InterfacesProxy { id: interfacesProxy - devicesFilter: engine.deviceManager.devices + thingsFilter: engine.thingManager.things } DevicesProxy { From 6dad1dfb5f63f20d3566f66a1562a90bb9264b78 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 13 Feb 2021 00:48:21 +0100 Subject: [PATCH 2/2] Also update InterfacesModel --- libnymea-app/interfacesmodel.cpp | 31 +++++++++---------- libnymea-app/interfacesmodel.h | 14 ++++++--- nymea-app/ui/grouping/GroupInterfacesPage.qml | 2 +- nymea-app/ui/mainviews/ThingsView.qml | 2 +- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/libnymea-app/interfacesmodel.cpp b/libnymea-app/interfacesmodel.cpp index 5aac5972..f73faa13 100644 --- a/libnymea-app/interfacesmodel.cpp +++ b/libnymea-app/interfacesmodel.cpp @@ -69,16 +69,15 @@ Engine *InterfacesModel::engine() const void InterfacesModel::setEngine(Engine *engine) { if (m_engine != engine) { - static QMetaObject::Connection countChangedConnection; if (m_engine) { - disconnect(countChangedConnection); + disconnect(m_thingClassesCountChangedConnection); } m_engine = engine; emit engineChanged(); - countChangedConnection = connect(engine->deviceManager()->deviceClasses(), &DeviceClasses::countChanged, this, [this]() { + m_thingClassesCountChangedConnection = connect(engine->deviceManager()->deviceClasses(), &DeviceClasses::countChanged, this, [this]() { syncInterfaces(); }); @@ -86,24 +85,22 @@ void InterfacesModel::setEngine(Engine *engine) } } -DevicesProxy *InterfacesModel::devices() const +DevicesProxy *InterfacesModel::things() const { - return m_devicesProxy; + return m_thingsProxy; } -void InterfacesModel::setDevices(DevicesProxy *devices) +void InterfacesModel::setThings(DevicesProxy *things) { - if (m_devicesProxy != devices) { - static QMetaObject::Connection countChangedConnection; - - if (m_devicesProxy) { - disconnect(countChangedConnection); + if (m_thingsProxy != things) { + if (m_thingsProxy) { + disconnect(m_thingsCountChangedConnection); } - m_devicesProxy = devices; - emit devicesChanged(); + m_thingsProxy = things; + emit thingsChanged(); - countChangedConnection = connect(devices, &DevicesProxy::countChanged, this, [this]() { + m_thingsCountChangedConnection = connect(things, &DevicesProxy::countChanged, this, [this]() { syncInterfaces(); }); syncInterfaces(); @@ -153,9 +150,9 @@ void InterfacesModel::syncInterfaces() return; } QList deviceClasses; - if (m_devicesProxy) { - for (int i = 0; i < m_devicesProxy->rowCount(); i++) { - deviceClasses << m_engine->deviceManager()->deviceClasses()->getDeviceClass(m_devicesProxy->get(i)->deviceClassId()); + if (m_thingsProxy) { + for (int i = 0; i < m_thingsProxy->rowCount(); i++) { + deviceClasses << m_engine->deviceManager()->deviceClasses()->getDeviceClass(m_thingsProxy->get(i)->deviceClassId()); } } else { for (int i = 0; i < m_engine->deviceManager()->deviceClasses()->rowCount(); i++) { diff --git a/libnymea-app/interfacesmodel.h b/libnymea-app/interfacesmodel.h index 28714c00..e6fca2e9 100644 --- a/libnymea-app/interfacesmodel.h +++ b/libnymea-app/interfacesmodel.h @@ -48,7 +48,7 @@ class InterfacesModel : public QAbstractListModel Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged) // Optional filters - Q_PROPERTY(DevicesProxy* devices READ devices WRITE setDevices NOTIFY devicesChanged) + Q_PROPERTY(DevicesProxy* things READ things WRITE setThings NOTIFY thingsChanged) Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged) Q_PROPERTY(bool showUncategorized READ showUncategorized WRITE setShowUncategorized NOTIFY showUncategorizedChanged) @@ -67,8 +67,8 @@ public: Engine* engine() const; void setEngine(Engine *engine); - DevicesProxy* devices() const; - void setDevices(DevicesProxy *devices); + DevicesProxy* things() const; + void setThings(DevicesProxy *things); QStringList shownInterfaces() const; void setShownInterfaces(const QStringList &shownInterfaces); @@ -84,7 +84,7 @@ public: signals: void countChanged(); void engineChanged(); - void devicesChanged(); + void thingsChanged(); void shownInterfacesChanged(); bool onlyConfiguredDevicesChanged(); void showUncategorizedChanged(); @@ -95,9 +95,13 @@ private slots: private: Engine *m_engine = nullptr; + QMetaObject::Connection m_thingClassesCountChangedConnection; + QStringList m_interfaces; - DevicesProxy *m_devicesProxy = nullptr; + DevicesProxy *m_thingsProxy = nullptr; + QMetaObject::Connection m_thingsCountChangedConnection; + QStringList m_shownInterfaces; bool m_showUncategorized = false; }; diff --git a/nymea-app/ui/grouping/GroupInterfacesPage.qml b/nymea-app/ui/grouping/GroupInterfacesPage.qml index d89f419b..435c6ef2 100644 --- a/nymea-app/ui/grouping/GroupInterfacesPage.qml +++ b/nymea-app/ui/grouping/GroupInterfacesPage.qml @@ -60,7 +60,7 @@ Page { model: InterfacesSortModel { interfacesModel: InterfacesModel { engine: _engine - devices: devicesInGroup + things: devicesInGroup shownInterfaces: app.supportedInterfaces showUncategorized: true } diff --git a/nymea-app/ui/mainviews/ThingsView.qml b/nymea-app/ui/mainviews/ThingsView.qml index 12b92e39..55aca788 100644 --- a/nymea-app/ui/mainviews/ThingsView.qml +++ b/nymea-app/ui/mainviews/ThingsView.qml @@ -43,7 +43,7 @@ MainViewBase { id: mainModel interfacesModel: InterfacesModel { engine: _engine - devices: DevicesProxy { + things: DevicesProxy { engine: _engine } shownInterfaces: app.supportedInterfaces