Merge PR #574: Fix updating the tags proxy on dataChanged

This commit is contained in:
Jenkins nymea 2021-03-25 19:57:33 +01:00
commit b1f7c4de8a
3 changed files with 23 additions and 6 deletions

View File

@ -33,6 +33,9 @@
#include "tagsmanager.h" #include "tagsmanager.h"
#include "types/tag.h" #include "types/tag.h"
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(dcTags)
TagsProxyModel::TagsProxyModel(QObject *parent) : QSortFilterProxyModel(parent) TagsProxyModel::TagsProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
{ {
} }
@ -51,6 +54,9 @@ void TagsProxyModel::setTags(Tags *tags)
invalidateFilter(); invalidateFilter();
emit countChanged(); emit countChanged();
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
connect(tags, &Tags::dataChanged, this, [=](){
emit countChanged();
}, Qt::QueuedConnection);
setSortRole(Tags::RoleValue); setSortRole(Tags::RoleValue);
sort(0); sort(0);
emit tagsChanged(); emit tagsChanged();
@ -141,6 +147,8 @@ bool TagsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_
{ {
Q_UNUSED(source_parent) Q_UNUSED(source_parent)
Tag *tag = m_tags->get(source_row); Tag *tag = m_tags->get(source_row);
qCDebug(dcTags) << "Filtering tag. ID:" << tag->tagId() << "Thing:" << tag->thingId() << "Value:" << tag->value();
qCDebug(dcTags) << "Filter: ID:" << m_filterTagId << "Thing:" << m_filterThingId << "value:" << m_filterValue;
if (!m_filterTagId.isEmpty()) { if (!m_filterTagId.isEmpty()) {
QRegExp exp(m_filterTagId); QRegExp exp(m_filterTagId);
if (!exp.exactMatch(tag->tagId())) { if (!exp.exactMatch(tag->tagId())) {
@ -158,11 +166,11 @@ bool TagsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_
} }
} }
if (!m_filterValue.isEmpty()) { if (!m_filterValue.isEmpty()) {
qDebug() << "**************************************************************" << tag->value() << m_filterValue;
if (tag->value() != m_filterValue) { if (tag->value() != m_filterValue) {
return false; return false;
} }
} }
qCDebug(dcTags) << "Accepted!";
return true; return true;
} }

View File

@ -32,6 +32,11 @@
#include "types/tag.h" #include "types/tag.h"
#include "engine.h" #include "engine.h"
#include <QJsonDocument>
#include "logging.h"
NYMEA_LOGGING_CATEGORY(dcTags, "Tags")
TagsManager::TagsManager(JsonRpcClient *jsonClient, QObject *parent): TagsManager::TagsManager(JsonRpcClient *jsonClient, QObject *parent):
JsonHandler(parent), JsonHandler(parent),
m_jsonClient(jsonClient), m_jsonClient(jsonClient),
@ -116,7 +121,7 @@ int TagsManager::untagRule(const QString &ruleId, const QString &tagId)
void TagsManager::handleTagsNotification(const QVariantMap &params) void TagsManager::handleTagsNotification(const QVariantMap &params)
{ {
qDebug() << "Have tags notification" << params; qCDebug(dcTags()) << "Tags notification:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
QVariantMap tagMap = params.value("params").toMap().value("tag").toMap(); QVariantMap tagMap = params.value("params").toMap().value("tag").toMap();
if (tagMap.value("appId").toString() != "nymea:app") { if (tagMap.value("appId").toString() != "nymea:app") {
@ -171,12 +176,12 @@ void TagsManager::getTagsReply(int /*commandId*/, const QVariantMap &params)
void TagsManager::addTagReply(int commandId, const QVariantMap &params) void TagsManager::addTagReply(int commandId, const QVariantMap &params)
{ {
qDebug() << "AddTag reply" << commandId << params; qCDebug(dcTags()) << "AddTag reply" << commandId << params;
} }
void TagsManager::removeTagReply(int commandId, const QVariantMap &params) void TagsManager::removeTagReply(int commandId, const QVariantMap &params)
{ {
qDebug() << "RemoveTag reply" << commandId << params; qCDebug(dcTags()) << "RemoveTag reply" << commandId << params;
} }
Tag* TagsManager::unpackTag(const QVariantMap &tagMap) Tag* TagsManager::unpackTag(const QVariantMap &tagMap)
@ -193,7 +198,7 @@ Tag* TagsManager::unpackTag(const QVariantMap &tagMap)
tag = new Tag(tagId, value); tag = new Tag(tagId, value);
tag->setRuleId(ruleId); tag->setRuleId(ruleId);
} else { } else {
qWarning() << "Invalid tag. Neither thingId nor ruleId are set. Skipping..."; qCWarning(dcTags()) << "Invalid tag. Neither thingId nor ruleId are set. Skipping...";
tag->deleteLater(); tag->deleteLater();
return nullptr; return nullptr;
} }

View File

@ -33,6 +33,10 @@
#include <QDebug> #include <QDebug>
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(dcTags)
Tags::Tags(QObject *parent) : QAbstractListModel(parent) Tags::Tags(QObject *parent) : QAbstractListModel(parent)
{ {
@ -148,7 +152,7 @@ void Tags::clear()
void Tags::tagValueChanged() void Tags::tagValueChanged()
{ {
qDebug() << "Tag value in mode changed"; qCInfo(dcTags) << "Tag value in model changed";
Tag *tag = static_cast<Tag*>(sender()); Tag *tag = static_cast<Tag*>(sender());
int idx = m_list.indexOf(tag); int idx = m_list.indexOf(tag);
emit dataChanged(index(idx, 0), index(idx, 0), {RoleValue}); emit dataChanged(index(idx, 0), index(idx, 0), {RoleValue});