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

View File

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

View File

@ -4,10 +4,12 @@
#include <QSortFilterProxyModel>
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;

View File

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

View File

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