Added a TagWatcher component
This commit is contained in:
parent
3f65cffc81
commit
dc041ca939
@ -128,6 +128,7 @@
|
|||||||
#include "zigbee/zigbeenetwork.h"
|
#include "zigbee/zigbeenetwork.h"
|
||||||
#include "zigbee/zigbeenetworks.h"
|
#include "zigbee/zigbeenetworks.h"
|
||||||
#include "applogcontroller.h"
|
#include "applogcontroller.h"
|
||||||
|
#include "tagwatcher.h"
|
||||||
|
|
||||||
#include <QtQml/qqml.h>
|
#include <QtQml/qqml.h>
|
||||||
|
|
||||||
@ -266,6 +267,7 @@ void registerQmlTypes() {
|
|||||||
qmlRegisterType<TagsProxyModel>(uri, 1, 0, "TagsProxyModel");
|
qmlRegisterType<TagsProxyModel>(uri, 1, 0, "TagsProxyModel");
|
||||||
qmlRegisterType<TagListModel>(uri, 1, 0, "TagListModel");
|
qmlRegisterType<TagListModel>(uri, 1, 0, "TagListModel");
|
||||||
qmlRegisterType<TagListProxyModel>(uri, 1, 0, "TagListProxyModel");
|
qmlRegisterType<TagListProxyModel>(uri, 1, 0, "TagListProxyModel");
|
||||||
|
qmlRegisterType<TagWatcher>(uri, 1, 0, "TagWatcher");
|
||||||
|
|
||||||
qmlRegisterType<BtWiFiSetup>(uri, 1, 0, "BtWiFiSetup");
|
qmlRegisterType<BtWiFiSetup>(uri, 1, 0, "BtWiFiSetup");
|
||||||
qmlRegisterType<BluetoothDiscovery>(uri, 1, 0, "BluetoothDiscovery");
|
qmlRegisterType<BluetoothDiscovery>(uri, 1, 0, "BluetoothDiscovery");
|
||||||
|
|||||||
@ -21,6 +21,7 @@ INCLUDEPATH += \
|
|||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/models/scriptsproxymodel.cpp \
|
$$PWD/models/scriptsproxymodel.cpp \
|
||||||
|
$$PWD/tagwatcher.cpp \
|
||||||
$${PWD}/logging.cpp \
|
$${PWD}/logging.cpp \
|
||||||
$${PWD}/applogcontroller.cpp \
|
$${PWD}/applogcontroller.cpp \
|
||||||
$${PWD}/wifisetup/btwifisetup.cpp \
|
$${PWD}/wifisetup/btwifisetup.cpp \
|
||||||
@ -167,6 +168,7 @@ SOURCES += \
|
|||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/models/scriptsproxymodel.h \
|
$$PWD/models/scriptsproxymodel.h \
|
||||||
|
$$PWD/tagwatcher.h \
|
||||||
$${PWD}/logging.h \
|
$${PWD}/logging.h \
|
||||||
$${PWD}/applogcontroller.h \
|
$${PWD}/applogcontroller.h \
|
||||||
$${PWD}/wifisetup/btwifisetup.h \
|
$${PWD}/wifisetup/btwifisetup.h \
|
||||||
|
|||||||
@ -34,9 +34,6 @@
|
|||||||
|
|
||||||
#include <QJsonDocument>
|
#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),
|
||||||
|
|||||||
117
libnymea-app/tagwatcher.cpp
Normal file
117
libnymea-app/tagwatcher.cpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#include "tagwatcher.h"
|
||||||
|
#include "types/tag.h"
|
||||||
|
|
||||||
|
TagWatcher::TagWatcher(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Tags *TagWatcher::tags() const
|
||||||
|
{
|
||||||
|
return m_tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TagWatcher::setTags(Tags *tags)
|
||||||
|
{
|
||||||
|
if (m_tags != tags) {
|
||||||
|
if (m_tags) {
|
||||||
|
disconnect(m_tags, &Tags::countChanged, this, &TagWatcher::update);
|
||||||
|
}
|
||||||
|
m_tags = tags;
|
||||||
|
emit tagsChanged();
|
||||||
|
|
||||||
|
if (m_tags) {
|
||||||
|
connect(m_tags, &Tags::countChanged, this, &TagWatcher::update);
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid TagWatcher::thingId() const
|
||||||
|
{
|
||||||
|
return m_thingId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TagWatcher::setThingId(const QUuid &thingId)
|
||||||
|
{
|
||||||
|
if (m_thingId != thingId) {
|
||||||
|
m_thingId = thingId;
|
||||||
|
emit thingIdChanged();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid TagWatcher::ruleId() const
|
||||||
|
{
|
||||||
|
return m_ruleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TagWatcher::setRuleId(const QUuid &ruleId)
|
||||||
|
{
|
||||||
|
if (m_ruleId != ruleId) {
|
||||||
|
m_ruleId = ruleId;
|
||||||
|
emit ruleIdChanged();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TagWatcher::tagId() const
|
||||||
|
{
|
||||||
|
return m_tagId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TagWatcher::setTagId(const QString &tagId)
|
||||||
|
{
|
||||||
|
if (m_tagId != tagId) {
|
||||||
|
m_tagId = tagId;
|
||||||
|
emit tagIdChanged();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Tag *TagWatcher::tag() const
|
||||||
|
{
|
||||||
|
return m_tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TagWatcher::update()
|
||||||
|
{
|
||||||
|
qCDebug(dcTags) << "Updating tag for watcher:" << m_tags << m_thingId << m_tagId;
|
||||||
|
if (!m_tags) {
|
||||||
|
updateTag(nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_thingId.isNull() && m_ruleId.isNull()) {
|
||||||
|
updateTag(nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_tagId.isEmpty()) {
|
||||||
|
updateTag(nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tag *tag = nullptr;
|
||||||
|
for (int i = 0; i < m_tags->rowCount(); i++) {
|
||||||
|
Tag *t = m_tags->get(i);
|
||||||
|
if (t->tagId() != m_tagId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (t->thingId() != m_thingId && t->ruleId() != m_ruleId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tag = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTag(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TagWatcher::updateTag(Tag *tag)
|
||||||
|
{
|
||||||
|
if (m_tag != tag) {
|
||||||
|
m_tag = tag;
|
||||||
|
emit tagChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
53
libnymea-app/tagwatcher.h
Normal file
53
libnymea-app/tagwatcher.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef TAGWATCHER_H
|
||||||
|
#define TAGWATCHER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
#include "types/tags.h"
|
||||||
|
|
||||||
|
class TagWatcher : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(Tags* tags READ tags WRITE setTags NOTIFY tagsChanged)
|
||||||
|
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
||||||
|
Q_PROPERTY(QUuid ruleId READ ruleId WRITE setRuleId NOTIFY ruleIdChanged)
|
||||||
|
Q_PROPERTY(QString tagId READ tagId WRITE setTagId NOTIFY tagIdChanged)
|
||||||
|
Q_PROPERTY(Tag* tag READ tag NOTIFY tagChanged)
|
||||||
|
public:
|
||||||
|
explicit TagWatcher(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
Tags* tags() const;
|
||||||
|
void setTags(Tags *tags);
|
||||||
|
|
||||||
|
QUuid thingId() const;
|
||||||
|
void setThingId(const QUuid &thingId);
|
||||||
|
|
||||||
|
QUuid ruleId() const;
|
||||||
|
void setRuleId(const QUuid &ruleId);
|
||||||
|
|
||||||
|
QString tagId() const;
|
||||||
|
void setTagId(const QString &tagId);
|
||||||
|
|
||||||
|
Tag* tag() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void tagsChanged();
|
||||||
|
void tagIdChanged();
|
||||||
|
void thingIdChanged();
|
||||||
|
void ruleIdChanged();
|
||||||
|
void tagChanged();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void update();
|
||||||
|
void updateTag(Tag *tag);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Tags* m_tags = nullptr;
|
||||||
|
QUuid m_thingId;
|
||||||
|
QUuid m_ruleId;
|
||||||
|
QString m_tagId;
|
||||||
|
Tag *m_tag = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TAGWATCHER_H
|
||||||
@ -32,6 +32,9 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
|
NYMEA_LOGGING_CATEGORY(dcTags, "Tags")
|
||||||
|
|
||||||
Tag::Tag(const QString &tagId, const QString &value, QObject *parent):
|
Tag::Tag(const QString &tagId, const QString &value, QObject *parent):
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_tagId(tagId),
|
m_tagId(tagId),
|
||||||
|
|||||||
@ -33,6 +33,9 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(dcTags)
|
||||||
|
|
||||||
class Tag : public QObject
|
class Tag : public QObject
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user