From b09240ede1ebba005fe7c8ec3c940f7dc420ea7b Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 10 Dec 2019 23:20:10 +0100 Subject: [PATCH] Fix new thing page after uuid changes --- libnymea-common/types/vendor.cpp | 6 +++--- libnymea-common/types/vendor.h | 10 +++++----- libnymea-common/types/vendors.cpp | 20 +++++++++---------- libnymea-common/types/vendors.h | 2 +- .../ui/thingconfiguration/NewThingPage.qml | 8 +++++--- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/libnymea-common/types/vendor.cpp b/libnymea-common/types/vendor.cpp index 714c153b..d3b16256 100644 --- a/libnymea-common/types/vendor.cpp +++ b/libnymea-common/types/vendor.cpp @@ -22,19 +22,19 @@ #include "vendor.h" -Vendor::Vendor(const QString &id, const QString &name, QObject *parent) : +Vendor::Vendor(const QUuid &id, const QString &name, QObject *parent) : QObject(parent), m_id(id), m_name(name) { } -QString Vendor::id() const +QUuid Vendor::id() const { return m_id; } -void Vendor::setId(const QString &id) +void Vendor::setId(const QUuid &id) { m_id = id; } diff --git a/libnymea-common/types/vendor.h b/libnymea-common/types/vendor.h index 72b7c4c5..ef2ec948 100644 --- a/libnymea-common/types/vendor.h +++ b/libnymea-common/types/vendor.h @@ -32,13 +32,13 @@ class Vendor : public QObject Q_OBJECT Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString displayName READ displayName CONSTANT) - Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QUuid id READ id CONSTANT) public: - Vendor(const QString &id = QString(), const QString &name = QString(), QObject *parent = nullptr); + Vendor(const QUuid &id = QUuid(), const QString &name = QString(), QObject *parent = nullptr); - QString id() const; - void setId(const QString &id); + QUuid id() const; + void setId(const QUuid &id); QString name() const; void setName(const QString &name); @@ -47,7 +47,7 @@ public: void setDisplayName(const QString &displayName); private: - QString m_id; + QUuid m_id; QString m_name; QString m_displayName; }; diff --git a/libnymea-common/types/vendors.cpp b/libnymea-common/types/vendors.cpp index a1abd887..41bcb4dd 100644 --- a/libnymea-common/types/vendors.cpp +++ b/libnymea-common/types/vendors.cpp @@ -29,16 +29,6 @@ Vendors::Vendors(QObject *parent) : { } -Vendor *Vendors::getVendor(const QString &vendorId) const -{ - foreach (Vendor *vendor, m_vendors) { - if (vendor->id() == vendorId) { - return vendor; - } - } - return nullptr; -} - int Vendors::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) @@ -89,6 +79,16 @@ Vendor *Vendors::get(int index) const return m_vendors.at(index); } +Vendor *Vendors::getVendor(const QUuid &vendorId) const +{ + foreach (Vendor *vendor, m_vendors) { + if (vendor->id() == vendorId) { + return vendor; + } + } + return nullptr; +} + QHash Vendors::roleNames() const { QHash roles; diff --git a/libnymea-common/types/vendors.h b/libnymea-common/types/vendors.h index 35b56707..5924b064 100644 --- a/libnymea-common/types/vendors.h +++ b/libnymea-common/types/vendors.h @@ -48,7 +48,7 @@ public: void clearModel(); Q_INVOKABLE Vendor* get(int index) const; - Q_INVOKABLE Vendor *getVendor(const QString &vendorId) const; + Q_INVOKABLE Vendor *getVendor(const QUuid &vendorId) const; signals: void countChanged(); diff --git a/nymea-app/ui/thingconfiguration/NewThingPage.qml b/nymea-app/ui/thingconfiguration/NewThingPage.qml index 465f889e..9f8c8145 100644 --- a/nymea-app/ui/thingconfiguration/NewThingPage.qml +++ b/nymea-app/ui/thingconfiguration/NewThingPage.qml @@ -42,20 +42,22 @@ Page { id: vendorFilterComboBox Layout.fillWidth: true textRole: "displayName" + currentIndex: -1 VendorsProxy { id: vendorsProxy vendors: engine.deviceManager.vendors } model: ListModel { id: vendorsFilterModel - ListElement { displayName: qsTr("All"); vendorId: "" } - + dynamicRoles: true Component.onCompleted: { + append({displayName: qsTr("All"), vendorId: ""}) for (var i = 0; i < vendorsProxy.count; i++) { var vendor = vendorsProxy.get(i); append({displayName: vendor.displayName, vendorId: vendor.id}) } + vendorFilterComboBox.currentIndex = 0 } } } @@ -117,7 +119,7 @@ Page { model: DeviceClassesProxy { id: deviceClassesProxy - vendorId: vendorsFilterModel.get(vendorFilterComboBox.currentIndex).vendorId + vendorId: vendorFilterComboBox.currentIndex >= 0 ? vendorsFilterModel.get(vendorFilterComboBox.currentIndex).vendorId : "" deviceClasses: engine.deviceManager.deviceClasses filterInterface: typeFilterModel.get(typeFilterComboBox.currentIndex).interfaceName filterDisplayName: displayNameFilterField.displayText