interfaces- and tagsproxymodel are not accessing the engine any more

This commit is contained in:
Michael Zanetti 2018-08-31 21:00:36 +02:00
parent af71bb25c5
commit 18f573fce2
5 changed files with 33 additions and 13 deletions

View File

@ -5,7 +5,6 @@
#include "types/device.h" #include "types/device.h"
#include "devices.h" #include "devices.h"
#include "engine.h"
InterfacesProxy::InterfacesProxy(QObject *parent): QSortFilterProxyModel(parent) InterfacesProxy::InterfacesProxy(QObject *parent): QSortFilterProxyModel(parent)
{ {
@ -71,12 +70,11 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source
bool found = false; bool found = false;
for (int i = 0; i < m_devicesFilter->rowCount(); i++) { for (int i = 0; i < m_devicesFilter->rowCount(); i++) {
Device *d = m_devicesFilter->get(i); Device *d = m_devicesFilter->get(i);
DeviceClass *dc = Engine::instance()->deviceManager()->deviceClasses()->getDeviceClass(d->deviceClassId()); if (!d->deviceClass()) {
if (!dc) {
qWarning() << "Cannot find DeviceClass for device:" << d->id() << d->name(); qWarning() << "Cannot find DeviceClass for device:" << d->id() << d->name();
return false; return false;
} }
if (dc->interfaces().contains(interfaceName)) { if (d->deviceClass()->interfaces().contains(interfaceName)) {
found = true; found = true;
break; break;
} }

View File

@ -5,10 +5,23 @@
TagsProxyModel::TagsProxyModel(QObject *parent) : QSortFilterProxyModel(parent) 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); Tags *TagsProxyModel::tags() const
sort(0); {
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 QString TagsProxyModel::filterTagId() const
@ -61,13 +74,13 @@ Tag *TagsProxyModel::get(int index) const
if (index < 0 || index > rowCount()) { if (index < 0 || index > rowCount()) {
return nullptr; 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 Tag *TagsProxyModel::findTag(const QString &tagId) const
{ {
for (int i = 0; i < rowCount(); i++) { 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) { if (tag->tagId() == tagId) {
return tag; return tag;
} }
@ -78,7 +91,7 @@ Tag *TagsProxyModel::findTag(const QString &tagId) const
bool TagsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const bool TagsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{ {
Q_UNUSED(source_parent) 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 (!m_filterTagId.isEmpty()) {
if (tag->tagId() != m_filterTagId) { if (tag->tagId() != m_filterTagId) {
return false; 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 bool TagsProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{ {
QString leftValue = Engine::instance()->tagsManager()->tags()->get(source_left.row())->value(); QString leftValue = m_tags->get(source_left.row())->value();
QString rightValue = Engine::instance()->tagsManager()->tags()->get(source_right.row())->value(); QString rightValue = m_tags->get(source_right.row())->value();
bool okLeft, okRight;; bool okLeft, okRight;;
qlonglong leftAsNumber = leftValue.toLongLong(&okLeft); qlonglong leftAsNumber = leftValue.toLongLong(&okLeft);
qlonglong rightAsNumber = rightValue.toLongLong(&okRight); qlonglong rightAsNumber = rightValue.toLongLong(&okRight);

View File

@ -4,10 +4,12 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
class Tag; class Tag;
class Tags;
class TagsProxyModel : public QSortFilterProxyModel class TagsProxyModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(Tags* tags READ tags WRITE setTags NOTIFY tagsChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(QString filterTagId READ filterTagId WRITE setFilterTagId NOTIFY filterTagIdChanged) Q_PROPERTY(QString filterTagId READ filterTagId WRITE setFilterTagId NOTIFY filterTagIdChanged)
Q_PROPERTY(QString filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged) Q_PROPERTY(QString filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged)
@ -16,6 +18,9 @@ class TagsProxyModel : public QSortFilterProxyModel
public: public:
explicit TagsProxyModel(QObject *parent = nullptr); explicit TagsProxyModel(QObject *parent = nullptr);
Tags* tags() const;
void setTags(Tags* tags);
QString filterTagId() const; QString filterTagId() const;
void setFilterTagId(const QString &filterTagId); void setFilterTagId(const QString &filterTagId);
@ -33,12 +38,14 @@ protected:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override; bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
signals: signals:
void tagsChanged();
void filterTagIdChanged(); void filterTagIdChanged();
void filterDeviceIdChanged(); void filterDeviceIdChanged();
void filterRuleIdChanged(); void filterRuleIdChanged();
void countChanged(); void countChanged();
private: private:
Tags *m_tags = nullptr;
QString m_filterTagId; QString m_filterTagId;
QString m_filterDeviceId; QString m_filterDeviceId;
QString m_filterRuleId; QString m_filterRuleId;

View File

@ -23,6 +23,7 @@ Page {
TagsProxyModel { TagsProxyModel {
id: favoritesProxy id: favoritesProxy
tags: Engine.tagsManager.tags
filterDeviceId: root.device.id filterDeviceId: root.device.id
filterTagId: "favorites" filterTagId: "favorites"
} }

View File

@ -13,6 +13,7 @@ Item {
TagsProxyModel { TagsProxyModel {
id: tagsProxy id: tagsProxy
tags: Engine.tagsManager.tags
filterTagId: "favorites" filterTagId: "favorites"
} }