From 18f573fce2bc3445defbe5f290c60b382f8476cf Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 31 Aug 2018 21:00:36 +0200 Subject: [PATCH] interfaces- and tagsproxymodel are not accessing the engine any more --- libnymea-app-core/models/interfacesproxy.cpp | 6 ++-- libnymea-app-core/models/tagsproxymodel.cpp | 31 ++++++++++++++------ libnymea-app-core/models/tagsproxymodel.h | 7 +++++ nymea-app/ui/devicepages/DevicePageBase.qml | 1 + nymea-app/ui/mainviews/FavoritesView.qml | 1 + 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/libnymea-app-core/models/interfacesproxy.cpp b/libnymea-app-core/models/interfacesproxy.cpp index ce4a85ea..708b17fc 100644 --- a/libnymea-app-core/models/interfacesproxy.cpp +++ b/libnymea-app-core/models/interfacesproxy.cpp @@ -5,7 +5,6 @@ #include "types/device.h" #include "devices.h" -#include "engine.h" InterfacesProxy::InterfacesProxy(QObject *parent): QSortFilterProxyModel(parent) { @@ -71,12 +70,11 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source bool found = false; for (int i = 0; i < m_devicesFilter->rowCount(); i++) { Device *d = m_devicesFilter->get(i); - DeviceClass *dc = Engine::instance()->deviceManager()->deviceClasses()->getDeviceClass(d->deviceClassId()); - if (!dc) { + if (!d->deviceClass()) { qWarning() << "Cannot find DeviceClass for device:" << d->id() << d->name(); return false; } - if (dc->interfaces().contains(interfaceName)) { + if (d->deviceClass()->interfaces().contains(interfaceName)) { found = true; break; } diff --git a/libnymea-app-core/models/tagsproxymodel.cpp b/libnymea-app-core/models/tagsproxymodel.cpp index 0522e8a0..34d18ce1 100644 --- a/libnymea-app-core/models/tagsproxymodel.cpp +++ b/libnymea-app-core/models/tagsproxymodel.cpp @@ -5,10 +5,23 @@ TagsProxyModel::TagsProxyModel(QObject *parent) : QSortFilterProxyModel(parent) { - setSourceModel(Engine::instance()->tagsManager()->tags()); - connect(Engine::instance()->tagsManager()->tags(), &Tags::countChanged, this, &TagsProxyModel::countChanged, Qt::QueuedConnection); - setSortRole(Tags::RoleValue); - sort(0); +} + +Tags *TagsProxyModel::tags() const +{ + return m_tags; +} + +void TagsProxyModel::setTags(Tags *tags) +{ + if (m_tags != tags) { + m_tags = tags; + setSourceModel(tags); + connect(tags, &Tags::countChanged, this, &TagsProxyModel::countChanged, Qt::QueuedConnection); + setSortRole(Tags::RoleValue); + sort(0); + emit tagsChanged(); + } } QString TagsProxyModel::filterTagId() const @@ -61,13 +74,13 @@ Tag *TagsProxyModel::get(int index) const if (index < 0 || index > rowCount()) { return nullptr; } - return Engine::instance()->tagsManager()->tags()->get(mapToSource(this->index(index, 0)).row()); + return m_tags->get(mapToSource(this->index(index, 0)).row()); } Tag *TagsProxyModel::findTag(const QString &tagId) const { for (int i = 0; i < rowCount(); i++) { - Tag *tag = Engine::instance()->tagsManager()->tags()->get(mapToSource(index(i, 0)).row()); + Tag *tag = m_tags->get(mapToSource(index(i, 0)).row()); if (tag->tagId() == tagId) { return tag; } @@ -78,7 +91,7 @@ Tag *TagsProxyModel::findTag(const QString &tagId) const bool TagsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { Q_UNUSED(source_parent) - Tag *tag = Engine::instance()->tagsManager()->tags()->get(source_row); + Tag *tag = m_tags->get(source_row); if (!m_filterTagId.isEmpty()) { if (tag->tagId() != m_filterTagId) { return false; @@ -99,8 +112,8 @@ bool TagsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_ bool TagsProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { - QString leftValue = Engine::instance()->tagsManager()->tags()->get(source_left.row())->value(); - QString rightValue = Engine::instance()->tagsManager()->tags()->get(source_right.row())->value(); + QString leftValue = m_tags->get(source_left.row())->value(); + QString rightValue = m_tags->get(source_right.row())->value(); bool okLeft, okRight;; qlonglong leftAsNumber = leftValue.toLongLong(&okLeft); qlonglong rightAsNumber = rightValue.toLongLong(&okRight); diff --git a/libnymea-app-core/models/tagsproxymodel.h b/libnymea-app-core/models/tagsproxymodel.h index 81769800..4d1205f5 100644 --- a/libnymea-app-core/models/tagsproxymodel.h +++ b/libnymea-app-core/models/tagsproxymodel.h @@ -4,10 +4,12 @@ #include class Tag; +class Tags; class TagsProxyModel : public QSortFilterProxyModel { Q_OBJECT + Q_PROPERTY(Tags* tags READ tags WRITE setTags NOTIFY tagsChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(QString filterTagId READ filterTagId WRITE setFilterTagId NOTIFY filterTagIdChanged) Q_PROPERTY(QString filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged) @@ -16,6 +18,9 @@ class TagsProxyModel : public QSortFilterProxyModel public: explicit TagsProxyModel(QObject *parent = nullptr); + Tags* tags() const; + void setTags(Tags* tags); + QString filterTagId() const; void setFilterTagId(const QString &filterTagId); @@ -33,12 +38,14 @@ protected: bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override; signals: + void tagsChanged(); void filterTagIdChanged(); void filterDeviceIdChanged(); void filterRuleIdChanged(); void countChanged(); private: + Tags *m_tags = nullptr; QString m_filterTagId; QString m_filterDeviceId; QString m_filterRuleId; diff --git a/nymea-app/ui/devicepages/DevicePageBase.qml b/nymea-app/ui/devicepages/DevicePageBase.qml index 20dfc825..60b87522 100644 --- a/nymea-app/ui/devicepages/DevicePageBase.qml +++ b/nymea-app/ui/devicepages/DevicePageBase.qml @@ -23,6 +23,7 @@ Page { TagsProxyModel { id: favoritesProxy + tags: Engine.tagsManager.tags filterDeviceId: root.device.id filterTagId: "favorites" } diff --git a/nymea-app/ui/mainviews/FavoritesView.qml b/nymea-app/ui/mainviews/FavoritesView.qml index 1a2cb5da..6dc03c49 100644 --- a/nymea-app/ui/mainviews/FavoritesView.qml +++ b/nymea-app/ui/mainviews/FavoritesView.qml @@ -13,6 +13,7 @@ Item { TagsProxyModel { id: tagsProxy + tags: Engine.tagsManager.tags filterTagId: "favorites" }