Fix updating the tags proxy on dataChanged
This commit is contained in:
parent
5e82026021
commit
85bcd5481c
@ -33,6 +33,9 @@
|
||||
#include "tagsmanager.h"
|
||||
#include "types/tag.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcTags)
|
||||
|
||||
TagsProxyModel::TagsProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
|
||||
{
|
||||
}
|
||||
@ -51,6 +54,9 @@ void TagsProxyModel::setTags(Tags *tags)
|
||||
invalidateFilter();
|
||||
emit countChanged();
|
||||
}, Qt::QueuedConnection);
|
||||
connect(tags, &Tags::dataChanged, this, [=](){
|
||||
emit countChanged();
|
||||
}, Qt::QueuedConnection);
|
||||
setSortRole(Tags::RoleValue);
|
||||
sort(0);
|
||||
emit tagsChanged();
|
||||
@ -141,6 +147,8 @@ bool TagsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_
|
||||
{
|
||||
Q_UNUSED(source_parent)
|
||||
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()) {
|
||||
QRegExp exp(m_filterTagId);
|
||||
if (!exp.exactMatch(tag->tagId())) {
|
||||
@ -158,11 +166,11 @@ bool TagsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_
|
||||
}
|
||||
}
|
||||
if (!m_filterValue.isEmpty()) {
|
||||
qDebug() << "**************************************************************" << tag->value() << m_filterValue;
|
||||
if (tag->value() != m_filterValue) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
qCDebug(dcTags) << "Accepted!";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,11 @@
|
||||
#include "types/tag.h"
|
||||
#include "engine.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
|
||||
#include "logging.h"
|
||||
NYMEA_LOGGING_CATEGORY(dcTags, "Tags")
|
||||
|
||||
TagsManager::TagsManager(JsonRpcClient *jsonClient, QObject *parent):
|
||||
JsonHandler(parent),
|
||||
m_jsonClient(jsonClient),
|
||||
@ -116,7 +121,7 @@ int TagsManager::untagRule(const QString &ruleId, const QString &tagId)
|
||||
|
||||
void TagsManager::handleTagsNotification(const QVariantMap ¶ms)
|
||||
{
|
||||
qDebug() << "Have tags notification" << params;
|
||||
qCDebug(dcTags()) << "Tags notification:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
|
||||
|
||||
QVariantMap tagMap = params.value("params").toMap().value("tag").toMap();
|
||||
if (tagMap.value("appId").toString() != "nymea:app") {
|
||||
@ -171,12 +176,12 @@ void TagsManager::getTagsReply(int /*commandId*/, const QVariantMap ¶ms)
|
||||
|
||||
void TagsManager::addTagReply(int commandId, const QVariantMap ¶ms)
|
||||
{
|
||||
qDebug() << "AddTag reply" << commandId << params;
|
||||
qCDebug(dcTags()) << "AddTag reply" << commandId << params;
|
||||
}
|
||||
|
||||
void TagsManager::removeTagReply(int commandId, const QVariantMap ¶ms)
|
||||
{
|
||||
qDebug() << "RemoveTag reply" << commandId << params;
|
||||
qCDebug(dcTags()) << "RemoveTag reply" << commandId << params;
|
||||
}
|
||||
|
||||
Tag* TagsManager::unpackTag(const QVariantMap &tagMap)
|
||||
@ -193,7 +198,7 @@ Tag* TagsManager::unpackTag(const QVariantMap &tagMap)
|
||||
tag = new Tag(tagId, value);
|
||||
tag->setRuleId(ruleId);
|
||||
} else {
|
||||
qWarning() << "Invalid tag. Neither thingId nor ruleId are set. Skipping...";
|
||||
qCWarning(dcTags()) << "Invalid tag. Neither thingId nor ruleId are set. Skipping...";
|
||||
tag->deleteLater();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -33,6 +33,10 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <QLoggingCategory>
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcTags)
|
||||
|
||||
|
||||
Tags::Tags(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
|
||||
@ -148,7 +152,7 @@ void Tags::clear()
|
||||
|
||||
void Tags::tagValueChanged()
|
||||
{
|
||||
qDebug() << "Tag value in mode changed";
|
||||
qCInfo(dcTags) << "Tag value in model changed";
|
||||
Tag *tag = static_cast<Tag*>(sender());
|
||||
int idx = m_list.indexOf(tag);
|
||||
emit dataChanged(index(idx, 0), index(idx, 0), {RoleValue});
|
||||
|
||||
Reference in New Issue
Block a user