Fix new thing page after uuid changes

This commit is contained in:
Michael Zanetti 2019-12-10 23:20:10 +01:00
parent b5c5e8b5f4
commit b09240ede1
5 changed files with 24 additions and 22 deletions

View File

@ -22,19 +22,19 @@
#include "vendor.h" #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), QObject(parent),
m_id(id), m_id(id),
m_name(name) m_name(name)
{ {
} }
QString Vendor::id() const QUuid Vendor::id() const
{ {
return m_id; return m_id;
} }
void Vendor::setId(const QString &id) void Vendor::setId(const QUuid &id)
{ {
m_id = id; m_id = id;
} }

View File

@ -32,13 +32,13 @@ class Vendor : public QObject
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString displayName READ displayName CONSTANT) Q_PROPERTY(QString displayName READ displayName CONSTANT)
Q_PROPERTY(QString id READ id CONSTANT) Q_PROPERTY(QUuid id READ id CONSTANT)
public: 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; QUuid id() const;
void setId(const QString &id); void setId(const QUuid &id);
QString name() const; QString name() const;
void setName(const QString &name); void setName(const QString &name);
@ -47,7 +47,7 @@ public:
void setDisplayName(const QString &displayName); void setDisplayName(const QString &displayName);
private: private:
QString m_id; QUuid m_id;
QString m_name; QString m_name;
QString m_displayName; QString m_displayName;
}; };

View File

@ -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 int Vendors::rowCount(const QModelIndex &parent) const
{ {
Q_UNUSED(parent) Q_UNUSED(parent)
@ -89,6 +79,16 @@ Vendor *Vendors::get(int index) const
return m_vendors.at(index); 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<int, QByteArray> Vendors::roleNames() const QHash<int, QByteArray> Vendors::roleNames() const
{ {
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;

View File

@ -48,7 +48,7 @@ public:
void clearModel(); void clearModel();
Q_INVOKABLE Vendor* get(int index) const; Q_INVOKABLE Vendor* get(int index) const;
Q_INVOKABLE Vendor *getVendor(const QString &vendorId) const; Q_INVOKABLE Vendor *getVendor(const QUuid &vendorId) const;
signals: signals:
void countChanged(); void countChanged();

View File

@ -42,20 +42,22 @@ Page {
id: vendorFilterComboBox id: vendorFilterComboBox
Layout.fillWidth: true Layout.fillWidth: true
textRole: "displayName" textRole: "displayName"
currentIndex: -1
VendorsProxy { VendorsProxy {
id: vendorsProxy id: vendorsProxy
vendors: engine.deviceManager.vendors vendors: engine.deviceManager.vendors
} }
model: ListModel { model: ListModel {
id: vendorsFilterModel id: vendorsFilterModel
ListElement { displayName: qsTr("All"); vendorId: "" } dynamicRoles: true
Component.onCompleted: { Component.onCompleted: {
append({displayName: qsTr("All"), vendorId: ""})
for (var i = 0; i < vendorsProxy.count; i++) { for (var i = 0; i < vendorsProxy.count; i++) {
var vendor = vendorsProxy.get(i); var vendor = vendorsProxy.get(i);
append({displayName: vendor.displayName, vendorId: vendor.id}) append({displayName: vendor.displayName, vendorId: vendor.id})
} }
vendorFilterComboBox.currentIndex = 0
} }
} }
} }
@ -117,7 +119,7 @@ Page {
model: DeviceClassesProxy { model: DeviceClassesProxy {
id: deviceClassesProxy id: deviceClassesProxy
vendorId: vendorsFilterModel.get(vendorFilterComboBox.currentIndex).vendorId vendorId: vendorFilterComboBox.currentIndex >= 0 ? vendorsFilterModel.get(vendorFilterComboBox.currentIndex).vendorId : ""
deviceClasses: engine.deviceManager.deviceClasses deviceClasses: engine.deviceManager.deviceClasses
filterInterface: typeFilterModel.get(typeFilterComboBox.currentIndex).interfaceName filterInterface: typeFilterModel.get(typeFilterComboBox.currentIndex).interfaceName
filterDisplayName: displayNameFilterField.displayText filterDisplayName: displayNameFilterField.displayText