Also update InterfacesModel

pull/531/head
Michael Zanetti 2021-02-13 00:48:21 +01:00
parent 748793b376
commit 6dad1dfb5f
4 changed files with 25 additions and 24 deletions

View File

@ -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<DeviceClass*> 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++) {

View File

@ -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;
};

View File

@ -60,7 +60,7 @@ Page {
model: InterfacesSortModel {
interfacesModel: InterfacesModel {
engine: _engine
devices: devicesInGroup
things: devicesInGroup
shownInterfaces: app.supportedInterfaces
showUncategorized: true
}

View File

@ -43,7 +43,7 @@ MainViewBase {
id: mainModel
interfacesModel: InterfacesModel {
engine: _engine
devices: DevicesProxy {
things: DevicesProxy {
engine: _engine
}
shownInterfaces: app.supportedInterfaces