more work on rules
This commit is contained in:
parent
a7d9e081f0
commit
8b9eb39b80
@ -5,12 +5,12 @@ EventDescriptor::EventDescriptor(QObject *parent) : QObject(parent)
|
|||||||
m_paramDescriptors = new ParamDescriptors(this);
|
m_paramDescriptors = new ParamDescriptors(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid EventDescriptor::deviceId() const
|
QString EventDescriptor::deviceId() const
|
||||||
{
|
{
|
||||||
return m_deviceId;
|
return m_deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventDescriptor::setDeviceId(const QUuid &deviceId)
|
void EventDescriptor::setDeviceId(const QString &deviceId)
|
||||||
{
|
{
|
||||||
if (m_deviceId != deviceId) {
|
if (m_deviceId != deviceId) {
|
||||||
m_deviceId = deviceId;
|
m_deviceId = deviceId;
|
||||||
@ -18,12 +18,12 @@ void EventDescriptor::setDeviceId(const QUuid &deviceId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid EventDescriptor::eventTypeId() const
|
QString EventDescriptor::eventTypeId() const
|
||||||
{
|
{
|
||||||
return m_eventTypeId;
|
return m_eventTypeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventDescriptor::setEventTypeId(const QUuid &eventTypeId)
|
void EventDescriptor::setEventTypeId(const QString &eventTypeId)
|
||||||
{
|
{
|
||||||
if (m_eventTypeId != eventTypeId) {
|
if (m_eventTypeId != eventTypeId) {
|
||||||
m_eventTypeId = eventTypeId;
|
m_eventTypeId = eventTypeId;
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
class EventDescriptor : public QObject
|
class EventDescriptor : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
||||||
Q_PROPERTY(QUuid eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged)
|
Q_PROPERTY(QString eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged)
|
||||||
|
|
||||||
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
|
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
|
||||||
Q_PROPERTY(QString interfaceEvent READ interfaceEvent WRITE setInterfaceEvent NOTIFY interfaceEventChanged)
|
Q_PROPERTY(QString interfaceEvent READ interfaceEvent WRITE setInterfaceEvent NOTIFY interfaceEventChanged)
|
||||||
@ -20,11 +20,11 @@ class EventDescriptor : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit EventDescriptor(QObject *parent = nullptr);
|
explicit EventDescriptor(QObject *parent = nullptr);
|
||||||
|
|
||||||
QUuid deviceId() const;
|
QString deviceId() const;
|
||||||
void setDeviceId(const QUuid &deviceId);
|
void setDeviceId(const QString &deviceId);
|
||||||
|
|
||||||
QUuid eventTypeId() const;
|
QString eventTypeId() const;
|
||||||
void setEventTypeId(const QUuid &eventTypeId);
|
void setEventTypeId(const QString &eventTypeId);
|
||||||
|
|
||||||
QString interfaceName() const;
|
QString interfaceName() const;
|
||||||
void setInterfaceName(const QString &interfaceName);
|
void setInterfaceName(const QString &interfaceName);
|
||||||
@ -43,8 +43,8 @@ signals:
|
|||||||
void interfaceEventChanged();
|
void interfaceEventChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_deviceId;
|
QString m_deviceId;
|
||||||
QUuid m_eventTypeId;
|
QString m_eventTypeId;
|
||||||
|
|
||||||
QString m_interfaceName;
|
QString m_interfaceName;
|
||||||
QString m_interfaceEvent;
|
QString m_interfaceEvent;
|
||||||
|
|||||||
@ -36,7 +36,10 @@ QHash<int, QByteArray> ParamDescriptors::roleNames() const
|
|||||||
|
|
||||||
ParamDescriptor *ParamDescriptors::get(int index) const
|
ParamDescriptor *ParamDescriptors::get(int index) const
|
||||||
{
|
{
|
||||||
return m_list.at(index);
|
if (index >= 0 && index < m_list.count()) {
|
||||||
|
return m_list.at(index);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParamDescriptor *ParamDescriptors::createNewParamDescriptor() const
|
ParamDescriptor *ParamDescriptors::createNewParamDescriptor() const
|
||||||
|
|||||||
@ -88,7 +88,9 @@ void Rule::setStateEvaluator(StateEvaluator *stateEvaluator)
|
|||||||
m_stateEvaluator->deleteLater();
|
m_stateEvaluator->deleteLater();
|
||||||
}
|
}
|
||||||
m_stateEvaluator = stateEvaluator;
|
m_stateEvaluator = stateEvaluator;
|
||||||
m_stateEvaluator->setParent(this);
|
if (m_stateEvaluator) { // Might be a nullptr now if cleared
|
||||||
|
m_stateEvaluator->setParent(this);
|
||||||
|
}
|
||||||
emit stateEvaluatorChanged();
|
emit stateEvaluatorChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,32 @@ void RuleActionParam::setValue(const QVariant &value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString RuleActionParam::eventTypeId() const
|
||||||
|
{
|
||||||
|
return m_eventTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleActionParam::setEventTypeId(const QString &eventTypeId)
|
||||||
|
{
|
||||||
|
if (m_eventTypeId != eventTypeId) {
|
||||||
|
m_eventTypeId = eventTypeId;
|
||||||
|
emit eventTypeIdChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString RuleActionParam::eventParamTypeId() const
|
||||||
|
{
|
||||||
|
return m_eventParamTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleActionParam::setEventParamTypeId(const QString &eventParamTypeId)
|
||||||
|
{
|
||||||
|
if (m_eventParamTypeId != eventParamTypeId) {
|
||||||
|
m_eventParamTypeId = eventParamTypeId;
|
||||||
|
emit eventParamTypeIdChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RuleActionParam *RuleActionParam::clone() const
|
RuleActionParam *RuleActionParam::clone() const
|
||||||
{
|
{
|
||||||
RuleActionParam *ret = new RuleActionParam();
|
RuleActionParam *ret = new RuleActionParam();
|
||||||
|
|||||||
@ -10,6 +10,8 @@ class RuleActionParam : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid paramTypeId READ paramTypeId NOTIFY paramTypeIdChanged)
|
Q_PROPERTY(QUuid paramTypeId READ paramTypeId NOTIFY paramTypeIdChanged)
|
||||||
Q_PROPERTY(QVariant value READ value NOTIFY valueChanged)
|
Q_PROPERTY(QVariant value READ value NOTIFY valueChanged)
|
||||||
|
Q_PROPERTY(QString eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged)
|
||||||
|
Q_PROPERTY(QString eventParamTypeId READ eventParamTypeId WRITE setEventParamTypeId NOTIFY eventParamTypeIdChanged)
|
||||||
public:
|
public:
|
||||||
explicit RuleActionParam(QObject *parent = nullptr);
|
explicit RuleActionParam(QObject *parent = nullptr);
|
||||||
|
|
||||||
@ -19,14 +21,25 @@ public:
|
|||||||
QVariant value() const;
|
QVariant value() const;
|
||||||
void setValue(const QVariant &value);
|
void setValue(const QVariant &value);
|
||||||
|
|
||||||
|
QString eventTypeId() const;
|
||||||
|
void setEventTypeId(const QString &eventTypeId);
|
||||||
|
|
||||||
|
QString eventParamTypeId() const;
|
||||||
|
void setEventParamTypeId(const QString &eventParamTypeId);
|
||||||
|
|
||||||
RuleActionParam* clone() const;
|
RuleActionParam* clone() const;
|
||||||
signals:
|
signals:
|
||||||
void paramTypeIdChanged();
|
void paramTypeIdChanged();
|
||||||
void valueChanged();
|
void valueChanged();
|
||||||
|
void eventTypeIdChanged();
|
||||||
|
void eventParamTypeIdChanged();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_paramTypeId;
|
QUuid m_paramTypeId;
|
||||||
QVariant m_value;
|
QVariant m_value;
|
||||||
|
QString m_eventTypeId;
|
||||||
|
QString m_eventParamTypeId;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RULEACTIONPARAM_H
|
#endif // RULEACTIONPARAM_H
|
||||||
|
|||||||
@ -20,6 +20,10 @@ QVariant RuleActionParams::data(const QModelIndex &index, int role) const
|
|||||||
return m_list.at(index.row())->paramTypeId();
|
return m_list.at(index.row())->paramTypeId();
|
||||||
case RoleValue:
|
case RoleValue:
|
||||||
return m_list.at(index.row())->value();
|
return m_list.at(index.row())->value();
|
||||||
|
case RoleEventTypeId:
|
||||||
|
return m_list.at(index.row())->eventTypeId();
|
||||||
|
case RoleEventParamTypeId:
|
||||||
|
return m_list.at(index.row())->eventParamTypeId();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@ -29,6 +33,8 @@ QHash<int, QByteArray> RuleActionParams::roleNames() const
|
|||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles.insert(RoleParamTypeId, "paramTypeId");
|
roles.insert(RoleParamTypeId, "paramTypeId");
|
||||||
roles.insert(RoleValue, "value");
|
roles.insert(RoleValue, "value");
|
||||||
|
roles.insert(RoleEventTypeId, "eventTypeId");
|
||||||
|
roles.insert(RoleEventParamTypeId, "eventParamTypeId");
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +62,22 @@ void RuleActionParams::setRuleActionParam(const QString ¶mTypeId, const QVar
|
|||||||
addRuleActionParam(rap);
|
addRuleActionParam(rap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RuleActionParams::setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId)
|
||||||
|
{
|
||||||
|
foreach (RuleActionParam *rap, m_list) {
|
||||||
|
if (rap->paramTypeId() == paramTypeId) {
|
||||||
|
rap->setEventTypeId(eventTypeId);
|
||||||
|
rap->setEventParamTypeId(eventParamTypeId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RuleActionParam *rap = new RuleActionParam(this);
|
||||||
|
rap->setParamTypeId(paramTypeId);
|
||||||
|
rap->setEventTypeId(eventTypeId);
|
||||||
|
rap->setEventParamTypeId(eventParamTypeId);
|
||||||
|
addRuleActionParam(rap);
|
||||||
|
}
|
||||||
|
|
||||||
RuleActionParam *RuleActionParams::get(int index) const
|
RuleActionParam *RuleActionParams::get(int index) const
|
||||||
{
|
{
|
||||||
return m_list.at(index);
|
return m_list.at(index);
|
||||||
|
|||||||
@ -12,7 +12,9 @@ class RuleActionParams : public QAbstractListModel
|
|||||||
public:
|
public:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
RoleParamTypeId,
|
RoleParamTypeId,
|
||||||
RoleValue
|
RoleValue,
|
||||||
|
RoleEventTypeId,
|
||||||
|
RoleEventParamTypeId
|
||||||
};
|
};
|
||||||
Q_ENUM(Roles)
|
Q_ENUM(Roles)
|
||||||
|
|
||||||
@ -25,6 +27,7 @@ public:
|
|||||||
void addRuleActionParam(RuleActionParam* ruleActionParam);
|
void addRuleActionParam(RuleActionParam* ruleActionParam);
|
||||||
|
|
||||||
Q_INVOKABLE void setRuleActionParam(const QString ¶mTypeId, const QVariant &value);
|
Q_INVOKABLE void setRuleActionParam(const QString ¶mTypeId, const QVariant &value);
|
||||||
|
Q_INVOKABLE void setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId);
|
||||||
Q_INVOKABLE RuleActionParam* get(int index) const;
|
Q_INVOKABLE RuleActionParam* get(int index) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@ -158,7 +158,7 @@ void JsonRpcClient::sendRequest(const QVariantMap &request)
|
|||||||
{
|
{
|
||||||
QVariantMap newRequest = request;
|
QVariantMap newRequest = request;
|
||||||
newRequest.insert("token", m_token);
|
newRequest.insert("token", m_token);
|
||||||
// qDebug() << "Sending request" << QJsonDocument::fromVariant(newRequest).toJson();
|
qDebug() << "Sending request" << qUtf8Printable(QJsonDocument::fromVariant(newRequest).toJson());
|
||||||
m_connection->sendData(QJsonDocument::fromVariant(newRequest).toJson());
|
m_connection->sendData(QJsonDocument::fromVariant(newRequest).toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -256,7 +256,12 @@ QVariantList JsonTypes::packRuleActions(RuleActions *ruleActions)
|
|||||||
for (int j = 0; j < ruleActions->get(i)->ruleActionParams()->rowCount(); j++) {
|
for (int j = 0; j < ruleActions->get(i)->ruleActionParams()->rowCount(); j++) {
|
||||||
QVariantMap ruleActionParam;
|
QVariantMap ruleActionParam;
|
||||||
ruleActionParam.insert("paramTypeId", ruleActions->get(i)->ruleActionParams()->get(j)->paramTypeId());
|
ruleActionParam.insert("paramTypeId", ruleActions->get(i)->ruleActionParams()->get(j)->paramTypeId());
|
||||||
ruleActionParam.insert("value", ruleActions->get(i)->ruleActionParams()->get(j)->value());
|
if (!ruleActions->get(i)->ruleActionParams()->get(j)->eventTypeId().isEmpty() && !ruleActions->get(i)->ruleActionParams()->get(j)->eventParamTypeId().isEmpty()) {
|
||||||
|
ruleActionParam.insert("eventTypeId", ruleActions->get(i)->ruleActionParams()->get(j)->eventTypeId());
|
||||||
|
ruleActionParam.insert("eventParamTypeId", ruleActions->get(i)->ruleActionParams()->get(j)->eventParamTypeId());
|
||||||
|
} else {
|
||||||
|
ruleActionParam.insert("value", ruleActions->get(i)->ruleActionParams()->get(j)->value());
|
||||||
|
}
|
||||||
ruleActionParams.append(ruleActionParam);
|
ruleActionParams.append(ruleActionParam);
|
||||||
}
|
}
|
||||||
ruleAction.insert("ruleActionParams", ruleActionParams);
|
ruleAction.insert("ruleActionParams", ruleActionParams);
|
||||||
|
|||||||
@ -49,6 +49,7 @@
|
|||||||
#include "types/stateevaluators.h"
|
#include "types/stateevaluators.h"
|
||||||
#include "models/logsmodel.h"
|
#include "models/logsmodel.h"
|
||||||
#include "models/valuelogsproxymodel.h"
|
#include "models/valuelogsproxymodel.h"
|
||||||
|
#include "models/eventdescriptorparamsfiltermodel.h"
|
||||||
#include "basicconfiguration.h"
|
#include "basicconfiguration.h"
|
||||||
|
|
||||||
static QObject* interfacesModel_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
static QObject* interfacesModel_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||||
@ -150,6 +151,8 @@ int main(int argc, char *argv[])
|
|||||||
qmlRegisterType<NymeaDiscovery>(uri, 1, 0, "NymeaDiscovery");
|
qmlRegisterType<NymeaDiscovery>(uri, 1, 0, "NymeaDiscovery");
|
||||||
qmlRegisterUncreatableType<DiscoveryModel>(uri, 1, 0, "DiscoveryModel", "Get it from NymeaDiscovery");
|
qmlRegisterUncreatableType<DiscoveryModel>(uri, 1, 0, "DiscoveryModel", "Get it from NymeaDiscovery");
|
||||||
|
|
||||||
|
qmlRegisterType<EventDescriptorParamsFilterModel>(uri, 1, 0, "EventDescriptorParamsFilterModel");
|
||||||
|
|
||||||
qmlRegisterType<LogsModel>(uri, 1, 0, "LogsModel");
|
qmlRegisterType<LogsModel>(uri, 1, 0, "LogsModel");
|
||||||
qmlRegisterType<ValueLogsProxyModel>(uri, 1, 0, "ValueLogsProxyModel");
|
qmlRegisterType<ValueLogsProxyModel>(uri, 1, 0, "ValueLogsProxyModel");
|
||||||
qmlRegisterUncreatableType<LogEntry>(uri, 1, 0, "LogEntry", "Get them from LogsModel");
|
qmlRegisterUncreatableType<LogEntry>(uri, 1, 0, "LogEntry", "Get them from LogsModel");
|
||||||
|
|||||||
@ -37,7 +37,8 @@ HEADERS += engine.h \
|
|||||||
models/valuelogsproxymodel.h \
|
models/valuelogsproxymodel.h \
|
||||||
discovery/nymeadiscovery.h \
|
discovery/nymeadiscovery.h \
|
||||||
logmanager.h \
|
logmanager.h \
|
||||||
basicconfiguration.h
|
basicconfiguration.h \
|
||||||
|
models/eventdescriptorparamsfiltermodel.h
|
||||||
|
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
@ -70,7 +71,8 @@ SOURCES += main.cpp \
|
|||||||
models/valuelogsproxymodel.cpp \
|
models/valuelogsproxymodel.cpp \
|
||||||
discovery/nymeadiscovery.cpp \
|
discovery/nymeadiscovery.cpp \
|
||||||
logmanager.cpp \
|
logmanager.cpp \
|
||||||
basicconfiguration.cpp
|
basicconfiguration.cpp \
|
||||||
|
models/eventdescriptorparamsfiltermodel.cpp
|
||||||
|
|
||||||
withavahi {
|
withavahi {
|
||||||
DEFINES += WITH_AVAHI
|
DEFINES += WITH_AVAHI
|
||||||
|
|||||||
86
mea/models/eventdescriptorparamsfiltermodel.cpp
Normal file
86
mea/models/eventdescriptorparamsfiltermodel.cpp
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#include "eventdescriptorparamsfiltermodel.h"
|
||||||
|
|
||||||
|
#include "types/eventdescriptor.h"
|
||||||
|
#include "engine.h"
|
||||||
|
|
||||||
|
EventDescriptorParamsFilterModel::EventDescriptorParamsFilterModel(QObject *parent) : QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//int EventDescriptorParamsFilterModel::rowCount(const QModelIndex &parent) const
|
||||||
|
//{
|
||||||
|
// Q_UNUSED(parent)
|
||||||
|
// if (!m_eventDescriptor) {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// foreach (const Param ¶m, m_eventDescriptor->paramDescriptors()->rowCount())
|
||||||
|
//}
|
||||||
|
|
||||||
|
EventDescriptor *EventDescriptorParamsFilterModel::eventDescriptor() const
|
||||||
|
{
|
||||||
|
return m_eventDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDescriptorParamsFilterModel::setEventDescriptor(EventDescriptor *eventDescriptor)
|
||||||
|
{
|
||||||
|
if (m_eventDescriptor != eventDescriptor) {
|
||||||
|
m_eventDescriptor = eventDescriptor;
|
||||||
|
emit eventDescriptorChanged();
|
||||||
|
Device *d = Engine::instance()->deviceManager()->devices()->getDevice(eventDescriptor->deviceId());
|
||||||
|
if (!d) {
|
||||||
|
qDebug() << "Can't find a device for this descriptor...";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DeviceClass* dc = Engine::instance()->deviceManager()->deviceClasses()->getDeviceClass(d->deviceClassId());
|
||||||
|
if (!dc) {
|
||||||
|
qDebug() << "Uh oh... No deviceClass for a device!?!11";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EventType* et = dc->eventTypes()->getEventType(eventDescriptor->eventTypeId());
|
||||||
|
if (!et) {
|
||||||
|
qDebug() << "Couldn't find eventtype";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSourceModel(et->paramTypes());
|
||||||
|
qDebug() << "have set source model" << et->paramTypes()->rowCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant::Type EventDescriptorParamsFilterModel::type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventDescriptorParamsFilterModel::setType(QVariant::Type type)
|
||||||
|
{
|
||||||
|
if (type != m_type) {
|
||||||
|
m_type = type;
|
||||||
|
emit typeChanged();
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamDescriptor *EventDescriptorParamsFilterModel::get(int idx) const
|
||||||
|
{
|
||||||
|
// qDebug() << "...." << m_eventDescriptor->paramDescriptors()->get(mapToSource(index(idx, 0)).row())->paramTypeId()
|
||||||
|
return m_eventDescriptor->paramDescriptors()->get(mapToSource(index(idx, 0)).row());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EventDescriptorParamsFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(source_parent)
|
||||||
|
ParamType *pd = dynamic_cast<ParamTypes*>(sourceModel())->get(source_row);
|
||||||
|
|
||||||
|
Device *device = Engine::instance()->deviceManager()->devices()->getDevice(m_eventDescriptor->deviceId());
|
||||||
|
if (!device) {
|
||||||
|
qDebug() << "rejecting entry" << pd->id();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
qDebug() << "accepting entty:" << pd->id();
|
||||||
|
// DeviceClass dc = Engine::instance()->deviceManager()->deviceClasses()->getDeviceClass(device->deviceClassId());
|
||||||
|
// if (dc.paramTypes()->getParamType(pd->paramTypeId())->type() == m_type) {
|
||||||
|
return true;
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
}
|
||||||
44
mea/models/eventdescriptorparamsfiltermodel.h
Normal file
44
mea/models/eventdescriptorparamsfiltermodel.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef EVENTDESCRIPTORPARAMSFILTERMODEL_H
|
||||||
|
#define EVENTDESCRIPTORPARAMSFILTERMODEL_H
|
||||||
|
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
class EventDescriptor;
|
||||||
|
class ParamDescriptor;
|
||||||
|
|
||||||
|
class EventDescriptorParamsFilterModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
// Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
|
Q_PROPERTY(EventDescriptor* eventDescriptor READ eventDescriptor WRITE setEventDescriptor NOTIFY eventDescriptorChanged)
|
||||||
|
Q_PROPERTY(QVariant::Type type READ type WRITE setType NOTIFY typeChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit EventDescriptorParamsFilterModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
// int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
// QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
|
||||||
|
EventDescriptor* eventDescriptor() const;
|
||||||
|
void setEventDescriptor(EventDescriptor* eventDescriptor);
|
||||||
|
|
||||||
|
QVariant::Type type() const;
|
||||||
|
void setType(QVariant::Type type);
|
||||||
|
|
||||||
|
Q_INVOKABLE ParamDescriptor* get(int idx) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void eventDescriptorChanged();
|
||||||
|
void typeChanged();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
EventDescriptor* m_eventDescriptor = nullptr;
|
||||||
|
QVariant::Type m_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EVENTDESCRIPTORPARAMSFILTERMODEL_H
|
||||||
@ -29,12 +29,12 @@ void RulesFilterModel::setRules(Rules *rules)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid RulesFilterModel::filterDeviceId() const
|
QString RulesFilterModel::filterDeviceId() const
|
||||||
{
|
{
|
||||||
return m_filterDeviceId;
|
return m_filterDeviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RulesFilterModel::setFilterDeviceId(const QUuid &filterDeviceId)
|
void RulesFilterModel::setFilterDeviceId(const QString &filterDeviceId)
|
||||||
{
|
{
|
||||||
if (m_filterDeviceId != filterDeviceId) {
|
if (m_filterDeviceId != filterDeviceId) {
|
||||||
m_filterDeviceId = filterDeviceId;
|
m_filterDeviceId = filterDeviceId;
|
||||||
@ -62,7 +62,7 @@ bool RulesFilterModel::filterAcceptsRow(int source_row, const QModelIndex &sourc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found && rule->stateEvaluator()->containsDevice(m_filterDeviceId)) {
|
if (!found && rule->stateEvaluator() && rule->stateEvaluator()->containsDevice(m_filterDeviceId)) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ class RulesFilterModel : public QSortFilterProxyModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(Rules* rules READ rules WRITE setRules NOTIFY rulesChanged)
|
Q_PROPERTY(Rules* rules READ rules WRITE setRules NOTIFY rulesChanged)
|
||||||
Q_PROPERTY(QUuid filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged)
|
Q_PROPERTY(QString filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RulesFilterModel(QObject *parent = nullptr);
|
explicit RulesFilterModel(QObject *parent = nullptr);
|
||||||
@ -19,8 +19,8 @@ public:
|
|||||||
Rules* rules() const;
|
Rules* rules() const;
|
||||||
void setRules(Rules* rules);
|
void setRules(Rules* rules);
|
||||||
|
|
||||||
QUuid filterDeviceId() const;
|
QString filterDeviceId() const;
|
||||||
void setFilterDeviceId(const QUuid &filterDeviceId);
|
void setFilterDeviceId(const QString &filterDeviceId);
|
||||||
|
|
||||||
Q_INVOKABLE Rule* get(int index) const;
|
Q_INVOKABLE Rule* get(int index) const;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Rules *m_rules = nullptr;
|
Rules *m_rules = nullptr;
|
||||||
QUuid m_filterDeviceId;
|
QString m_filterDeviceId;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RULESFILTERMODEL_H
|
#endif // RULESFILTERMODEL_H
|
||||||
|
|||||||
@ -158,7 +158,7 @@ void RuleManager::removeRuleReply(const QVariantMap ¶ms)
|
|||||||
|
|
||||||
void RuleManager::onEditRuleReply(const QVariantMap ¶ms)
|
void RuleManager::onEditRuleReply(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
qDebug() << "Edit rule reply:" << params.value("params").toMap().value("ruleError").toString();
|
qDebug() << "Edit rule reply:" << params; //params.value("params").toMap().value("ruleError").toString();
|
||||||
emit editRuleReply(params.value("params").toMap().value("ruleError").toString());
|
emit editRuleReply(params.value("params").toMap().value("ruleError").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,8 +183,8 @@ void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList,
|
|||||||
{
|
{
|
||||||
foreach (const QVariant &eventDescriptorVariant, eventDescriptorList) {
|
foreach (const QVariant &eventDescriptorVariant, eventDescriptorList) {
|
||||||
EventDescriptor *eventDescriptor = new EventDescriptor(rule);
|
EventDescriptor *eventDescriptor = new EventDescriptor(rule);
|
||||||
eventDescriptor->setDeviceId(eventDescriptorVariant.toMap().value("deviceId").toUuid());
|
eventDescriptor->setDeviceId(eventDescriptorVariant.toMap().value("deviceId").toString());
|
||||||
eventDescriptor->setEventTypeId(eventDescriptorVariant.toMap().value("eventTypeId").toUuid());
|
eventDescriptor->setEventTypeId(eventDescriptorVariant.toMap().value("eventTypeId").toString());
|
||||||
eventDescriptor->setInterfaceName(eventDescriptorVariant.toMap().value("interface").toString());
|
eventDescriptor->setInterfaceName(eventDescriptorVariant.toMap().value("interface").toString());
|
||||||
eventDescriptor->setInterfaceEvent(eventDescriptorVariant.toMap().value("interfaceEvent").toString());
|
eventDescriptor->setInterfaceEvent(eventDescriptorVariant.toMap().value("interfaceEvent").toString());
|
||||||
foreach (const QVariant ¶mDescriptorVariant, eventDescriptorVariant.toMap().value("paramDescriptors").toList()) {
|
foreach (const QVariant ¶mDescriptorVariant, eventDescriptorVariant.toMap().value("paramDescriptors").toList()) {
|
||||||
@ -199,20 +199,20 @@ void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList,
|
|||||||
|
|
||||||
StateEvaluator *RuleManager::parseStateEvaluator(const QVariantMap &stateEvaluatorMap)
|
StateEvaluator *RuleManager::parseStateEvaluator(const QVariantMap &stateEvaluatorMap)
|
||||||
{
|
{
|
||||||
qDebug() << "bla" << stateEvaluatorMap;
|
if (!stateEvaluatorMap.contains("stateDescriptor")) {
|
||||||
StateEvaluator *stateEvaluator = new StateEvaluator(this);
|
return nullptr;
|
||||||
if (stateEvaluatorMap.contains("stateDescriptor")) {
|
|
||||||
QVariantMap sdMap = stateEvaluatorMap.value("stateDescriptor").toMap();
|
|
||||||
QMetaEnum operatorEnum = QMetaEnum::fromType<StateDescriptor::ValueOperator>();
|
|
||||||
StateDescriptor::ValueOperator op = (StateDescriptor::ValueOperator)operatorEnum.keyToValue(sdMap.value("operator").toByteArray());
|
|
||||||
StateDescriptor *sd = new StateDescriptor(sdMap.value("deviceId").toUuid(), op, sdMap.value("stateTypeId").toUuid(), sdMap.value("value"), stateEvaluator);
|
|
||||||
stateEvaluator->setStateDescriptor(sd);
|
|
||||||
}
|
}
|
||||||
|
StateEvaluator *stateEvaluator = new StateEvaluator(this);
|
||||||
|
QVariantMap sdMap = stateEvaluatorMap.value("stateDescriptor").toMap();
|
||||||
|
QMetaEnum operatorEnum = QMetaEnum::fromType<StateDescriptor::ValueOperator>();
|
||||||
|
StateDescriptor::ValueOperator op = (StateDescriptor::ValueOperator)operatorEnum.keyToValue(sdMap.value("operator").toByteArray());
|
||||||
|
StateDescriptor *sd = new StateDescriptor(sdMap.value("deviceId").toUuid(), op, sdMap.value("stateTypeId").toUuid(), sdMap.value("value"), stateEvaluator);
|
||||||
|
stateEvaluator->setStateDescriptor(sd);
|
||||||
|
|
||||||
foreach (const QVariant &childEvaluatorVariant, stateEvaluatorMap.value("childEvaluators").toList()) {
|
foreach (const QVariant &childEvaluatorVariant, stateEvaluatorMap.value("childEvaluators").toList()) {
|
||||||
stateEvaluator->childEvaluators()->addStateEvaluator(parseStateEvaluator(childEvaluatorVariant.toMap()));
|
stateEvaluator->childEvaluators()->addStateEvaluator(parseStateEvaluator(childEvaluatorVariant.toMap()));
|
||||||
}
|
}
|
||||||
QMetaEnum operatorEnum = QMetaEnum::fromType<StateEvaluator::StateOperator>();
|
operatorEnum = QMetaEnum::fromType<StateEvaluator::StateOperator>();
|
||||||
stateEvaluator->setStateOperator((StateEvaluator::StateOperator)operatorEnum.keyToValue(stateEvaluatorMap.value("operator").toByteArray()));
|
stateEvaluator->setStateOperator((StateEvaluator::StateOperator)operatorEnum.keyToValue(stateEvaluatorMap.value("operator").toByteArray()));
|
||||||
return stateEvaluator;
|
return stateEvaluator;
|
||||||
}
|
}
|
||||||
@ -227,6 +227,8 @@ void RuleManager::parseRuleActions(const QVariantList &ruleActions, Rule *rule)
|
|||||||
RuleActionParam *param = new RuleActionParam();
|
RuleActionParam *param = new RuleActionParam();
|
||||||
param->setParamTypeId(ruleActionParamVariant.toMap().value("paramTypeId").toUuid());
|
param->setParamTypeId(ruleActionParamVariant.toMap().value("paramTypeId").toUuid());
|
||||||
param->setValue(ruleActionParamVariant.toMap().value("value"));
|
param->setValue(ruleActionParamVariant.toMap().value("value"));
|
||||||
|
param->setEventTypeId(ruleActionParamVariant.toMap().value("eventTypeId").toString());
|
||||||
|
param->setEventParamTypeId(ruleActionParamVariant.toMap().value("eventParamTypeId").toString());
|
||||||
ruleAction->ruleActionParams()->addRuleActionParam(param);
|
ruleAction->ruleActionParams()->addRuleActionParam(param);
|
||||||
}
|
}
|
||||||
rule->actions()->addRuleAction(ruleAction);
|
rule->actions()->addRuleAction(ruleAction);
|
||||||
@ -243,6 +245,8 @@ void RuleManager::parseRuleExitActions(const QVariantList &ruleActions, Rule *ru
|
|||||||
RuleActionParam *param = new RuleActionParam();
|
RuleActionParam *param = new RuleActionParam();
|
||||||
param->setParamTypeId(ruleActionParamVariant.toMap().value("paramTypeId").toUuid());
|
param->setParamTypeId(ruleActionParamVariant.toMap().value("paramTypeId").toUuid());
|
||||||
param->setValue(ruleActionParamVariant.toMap().value("value"));
|
param->setValue(ruleActionParamVariant.toMap().value("value"));
|
||||||
|
param->setEventTypeId(ruleActionParamVariant.toMap().value("eventTypeId").toString());
|
||||||
|
param->setEventParamTypeId(ruleActionParamVariant.toMap().value("eventParamTypeId").toString());
|
||||||
ruleAction->ruleActionParams()->addRuleActionParam(param);
|
ruleAction->ruleActionParams()->addRuleActionParam(param);
|
||||||
}
|
}
|
||||||
rule->exitActions()->addRuleAction(ruleAction);
|
rule->exitActions()->addRuleAction(ruleAction);
|
||||||
|
|||||||
@ -79,7 +79,7 @@ Page {
|
|||||||
|
|
||||||
function selectRuleActionData(ruleActions, ruleAction) {
|
function selectRuleActionData(ruleActions, ruleAction) {
|
||||||
print("opening with ruleAction", ruleAction)
|
print("opening with ruleAction", ruleAction)
|
||||||
var ruleActionPage = pageStack.push(Qt.resolvedUrl("SelectRuleActionPage.qml"), {text: "Select action", ruleAction: ruleAction });
|
var ruleActionPage = pageStack.push(Qt.resolvedUrl("SelectRuleActionPage.qml"), {text: "Select action", ruleAction: ruleAction, rule: rule });
|
||||||
ruleActionPage.onBackPressed.connect(function() {
|
ruleActionPage.onBackPressed.connect(function() {
|
||||||
pageStack.pop(root);
|
pageStack.pop(root);
|
||||||
ruleAction.destroy();
|
ruleAction.destroy();
|
||||||
@ -289,7 +289,8 @@ Page {
|
|||||||
Repeater {
|
Repeater {
|
||||||
model: actionDelegate.ruleAction.ruleActionParams
|
model: actionDelegate.ruleAction.ruleActionParams
|
||||||
Label {
|
Label {
|
||||||
text: actionDelegate.actionType.paramTypes.getParamType(model.paramTypeId).displayName + " -> " + model.value
|
text: actionDelegate.actionType.paramTypes.getParamType(model.paramTypeId).displayName + " -> " +
|
||||||
|
(model.eventParamTypeId.length > 0 ? "value from event" : model.value)
|
||||||
font.pixelSize: app.smallFont
|
font.pixelSize: app.smallFont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,10 +28,26 @@ Page {
|
|||||||
Repeater {
|
Repeater {
|
||||||
id: delegateRepeater
|
id: delegateRepeater
|
||||||
model: root.eventType.paramTypes
|
model: root.eventType.paramTypes
|
||||||
delegate: ParamDescriptorDelegateBase {
|
delegate: ColumnLayout {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
paramType: root.eventType.paramTypes.get(index)
|
property alias paramType: paramDescriptorDelegate.paramType
|
||||||
value: paramType.defaultValue
|
property alias value: paramDescriptorDelegate.value
|
||||||
|
property alias considerParam: paramCheckBox.checked
|
||||||
|
CheckBox {
|
||||||
|
id: paramCheckBox
|
||||||
|
text: "Only consider event if"
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.leftMargin: app.margins
|
||||||
|
Layout.rightMargin: app.margins
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamDescriptorDelegateBase {
|
||||||
|
id: paramDescriptorDelegate
|
||||||
|
enabled: paramCheckBox.checked
|
||||||
|
Layout.fillWidth: true
|
||||||
|
paramType: root.eventType.paramTypes.get(index)
|
||||||
|
value: paramType.defaultValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Item {
|
Item {
|
||||||
@ -46,7 +62,9 @@ Page {
|
|||||||
var params = [];
|
var params = [];
|
||||||
for (var i = 0; i < delegateRepeater.count; i++) {
|
for (var i = 0; i < delegateRepeater.count; i++) {
|
||||||
var paramDelegate = delegateRepeater.itemAt(i);
|
var paramDelegate = delegateRepeater.itemAt(i);
|
||||||
root.eventDescriptor.paramDescriptors.setParamDescriptor(paramDelegate.paramType.id, paramDelegate.value, paramDelegate.operatorType)
|
if (paramDelegate.considerParam) {
|
||||||
|
root.eventDescriptor.paramDescriptors.setParamDescriptor(paramDelegate.paramType.id, paramDelegate.value, paramDelegate.operatorType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
root.completed()
|
root.completed()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,9 @@ Page {
|
|||||||
// a ruleAction object needs to be set and prefilled with either deviceId or interfaceName
|
// a ruleAction object needs to be set and prefilled with either deviceId or interfaceName
|
||||||
property var ruleAction: null
|
property var ruleAction: null
|
||||||
|
|
||||||
|
// optionally, a rule which will be used when determining params for the actions
|
||||||
|
property var rule: null
|
||||||
|
|
||||||
readonly property var device: ruleAction && ruleAction.deviceId ? Engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null
|
readonly property var device: ruleAction && ruleAction.deviceId ? Engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null
|
||||||
readonly property var deviceClass: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
|
readonly property var deviceClass: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
|
||||||
|
|
||||||
@ -23,7 +26,7 @@ Page {
|
|||||||
id: header
|
id: header
|
||||||
onBackPressed: root.backPressed();
|
onBackPressed: root.backPressed();
|
||||||
|
|
||||||
property bool interfacesMode: root.ruleAction.interfaceName !== ""
|
property bool interfacesMode: false//root.ruleAction.interfaceName !== ""
|
||||||
onInterfacesModeChanged: root.buildInterface()
|
onInterfacesModeChanged: root.buildInterface()
|
||||||
|
|
||||||
HeaderButton {
|
HeaderButton {
|
||||||
@ -87,7 +90,7 @@ Page {
|
|||||||
} else if (root.ruleAction.interfaceName != "") {
|
} else if (root.ruleAction.interfaceName != "") {
|
||||||
root.ruleAction.interfaceAction = model.name;
|
root.ruleAction.interfaceAction = model.name;
|
||||||
if (listView.model.get(index).paramTypes.count > 0) {
|
if (listView.model.get(index).paramTypes.count > 0) {
|
||||||
var paramsPage = pageStack.push(Qt.resolvedUrl("SelectRuleActionParamsPage.qml"), {ruleAction: root.ruleAction})
|
var paramsPage = pageStack.push(Qt.resolvedUrl("SelectRuleActionParamsPage.qml"), {ruleAction: root.ruleAction, rule: root.rule})
|
||||||
paramsPage.onBackPressed.connect(function() {pageStack.pop()});
|
paramsPage.onBackPressed.connect(function() {pageStack.pop()});
|
||||||
paramsPage.onCompleted.connect(function() {
|
paramsPage.onCompleted.connect(function() {
|
||||||
pageStack.pop();
|
pageStack.pop();
|
||||||
@ -105,7 +108,7 @@ Page {
|
|||||||
console.log("ActionType", actionType.id, "selected. Has", actionType.paramTypes.count, "params");
|
console.log("ActionType", actionType.id, "selected. Has", actionType.paramTypes.count, "params");
|
||||||
root.ruleAction.actionTypeId = actionType.id;
|
root.ruleAction.actionTypeId = actionType.id;
|
||||||
if (actionType.paramTypes.count > 0) {
|
if (actionType.paramTypes.count > 0) {
|
||||||
var paramsPage = pageStack.push(Qt.resolvedUrl("SelectRuleActionParamsPage.qml"), {ruleAction: root.ruleAction})
|
var paramsPage = pageStack.push(Qt.resolvedUrl("SelectRuleActionParamsPage.qml"), {ruleAction: root.ruleAction, rule: root.rule})
|
||||||
paramsPage.onBackPressed.connect(function() { pageStack.pop(); });
|
paramsPage.onBackPressed.connect(function() { pageStack.pop(); });
|
||||||
paramsPage.onCompleted.connect(function() {
|
paramsPage.onCompleted.connect(function() {
|
||||||
pageStack.pop();
|
pageStack.pop();
|
||||||
|
|||||||
@ -7,8 +7,11 @@ import Mea 1.0
|
|||||||
|
|
||||||
Page {
|
Page {
|
||||||
id: root
|
id: root
|
||||||
// Needs to be set and filled in with deviceId and actionTypeId or interfaceName and interfaceAction
|
// Needs to be set and have rule.ruleActions filled in with deviceId and actionTypeId or interfaceName and interfaceAction
|
||||||
property var ruleAction
|
property var ruleAction: null
|
||||||
|
|
||||||
|
// optionally a rule which will be used to propse event's params as param values
|
||||||
|
property var rule: null
|
||||||
|
|
||||||
readonly property var device: ruleAction && ruleAction.deviceId ? Engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null
|
readonly property var device: ruleAction && ruleAction.deviceId ? Engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null
|
||||||
readonly property var iface: ruleAction && ruleAction.interfaceName ? Interfaces.findByName(ruleAction.interfaceName) : null
|
readonly property var iface: ruleAction && ruleAction.interfaceName ? Interfaces.findByName(ruleAction.interfaceName) : null
|
||||||
@ -28,9 +31,67 @@ Page {
|
|||||||
Repeater {
|
Repeater {
|
||||||
id: delegateRepeater
|
id: delegateRepeater
|
||||||
model: root.actionType.paramTypes
|
model: root.actionType.paramTypes
|
||||||
delegate: ParamDelegate {
|
delegate: ColumnLayout {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
paramType: root.actionType.paramTypes.get(index)
|
property string type: {
|
||||||
|
if (staticParamRadioButton.checked) {
|
||||||
|
return "static"
|
||||||
|
}
|
||||||
|
if (eventParamRadioButton.checked) {
|
||||||
|
return "event"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
property alias paramType: paramDelegate.paramType
|
||||||
|
property alias value: paramDelegate.value
|
||||||
|
property alias eventType: eventDescriptorParamsFilterModel.eventType
|
||||||
|
property alias eventParamTypeId: eventDescriptorParamsFilterModel.paramTypeId
|
||||||
|
|
||||||
|
RadioButton {
|
||||||
|
id: staticParamRadioButton
|
||||||
|
text: qsTr("Use static value as parameter")
|
||||||
|
checked: true
|
||||||
|
}
|
||||||
|
ParamDelegate {
|
||||||
|
id: paramDelegate
|
||||||
|
Layout.fillWidth: true
|
||||||
|
paramType: root.actionType.paramTypes.get(index)
|
||||||
|
enabled: staticParamRadioButton.checked
|
||||||
|
}
|
||||||
|
|
||||||
|
RadioButton {
|
||||||
|
id: eventParamRadioButton
|
||||||
|
text: qsTr("Use event parameter")
|
||||||
|
visible: eventParamsComboBox.count > 0
|
||||||
|
}
|
||||||
|
ComboBox {
|
||||||
|
id: eventParamsComboBox
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.margins: app.margins
|
||||||
|
enabled: eventParamRadioButton.checked
|
||||||
|
visible: count > 0
|
||||||
|
Component.onCompleted: currentIndex = 0;
|
||||||
|
model: EventDescriptorParamsFilterModel {
|
||||||
|
id: eventDescriptorParamsFilterModel
|
||||||
|
eventDescriptor: root.rule.eventDescriptors.count === 1 ? root.rule.eventDescriptors.get(0) : null
|
||||||
|
property var device: Engine.deviceManager.devices.getDevice(eventDescriptor.deviceId)
|
||||||
|
property var deviceClass: Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId)
|
||||||
|
property var eventType: deviceClass.eventTypes.getEventType(eventDescriptor.eventTypeId)
|
||||||
|
property var paramDescriptor: eventDescriptorParamsFilterModel.eventType.paramTypes.get(eventParamsComboBox.currentIndex)
|
||||||
|
property var paramTypeId: paramDescriptor.id
|
||||||
|
}
|
||||||
|
delegate: ItemDelegate {
|
||||||
|
width: parent.width
|
||||||
|
text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.eventType.paramTypes.getParamType(model.id).displayName
|
||||||
|
}
|
||||||
|
contentItem: Label {
|
||||||
|
id: eventParamsComboBoxContentItem
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.margins: app.margins
|
||||||
|
text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.paramDescriptor.displayName
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Item {
|
Item {
|
||||||
@ -45,7 +106,12 @@ Page {
|
|||||||
var params = [];
|
var params = [];
|
||||||
for (var i = 0; i < delegateRepeater.count; i++) {
|
for (var i = 0; i < delegateRepeater.count; i++) {
|
||||||
var paramDelegate = delegateRepeater.itemAt(i);
|
var paramDelegate = delegateRepeater.itemAt(i);
|
||||||
root.ruleAction.ruleActionParams.setRuleActionParam(paramDelegate.paramType.id, paramDelegate.value)
|
if (paramDelegate.type === "static") {
|
||||||
|
root.ruleAction.ruleActionParams.setRuleActionParam(paramDelegate.paramType.id, paramDelegate.value)
|
||||||
|
} else if (paramDelegate.type === "event") {
|
||||||
|
print("adding event based rule action param", paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId)
|
||||||
|
root.ruleAction.ruleActionParams.setRuleActionParamEvent(paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
root.completed()
|
root.completed()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,10 @@ SwipeDelegate {
|
|||||||
Label {
|
Label {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
property string operatorString: {
|
property string operatorString: {
|
||||||
|
if (!root.stateEvaluator) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
switch (root.stateEvaluator.stateDescriptor.valueOperator) {
|
switch (root.stateEvaluator.stateDescriptor.valueOperator) {
|
||||||
case StateDescriptor.ValueOperatorEquals:
|
case StateDescriptor.ValueOperatorEquals:
|
||||||
return "=";
|
return "=";
|
||||||
|
|||||||
@ -30,15 +30,15 @@ SwipeDelegate {
|
|||||||
ComboBox {
|
ComboBox {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
model: ["and all of those", "or any of those"]
|
model: ["and all of those", "or any of those"]
|
||||||
currentIndex: root.stateEvaluator.stateOperator === StateEvaluator.StateOperatorAnd ? 0 : 1
|
currentIndex: root.stateEvaluator && root.stateEvaluator.stateOperator === StateEvaluator.StateOperatorAnd ? 0 : 1
|
||||||
visible: root.stateEvaluator.childEvaluators.count > 0
|
visible: root.stateEvaluator && root.stateEvaluator.childEvaluators.count > 0
|
||||||
onActivated: {
|
onActivated: {
|
||||||
root.stateEvaluator.stateOperator = index == 0 ? StateEvaluator.StateOperatorAnd : StateEvaluator.StateOperatorOr
|
root.stateEvaluator.stateOperator = index == 0 ? StateEvaluator.StateOperatorAnd : StateEvaluator.StateOperatorOr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: root.stateEvaluator.childEvaluators
|
model: root.stateEvaluator ? root.stateEvaluator.childEvaluators : null
|
||||||
delegate: SimpleStateEvaluatorDelegate {
|
delegate: SimpleStateEvaluatorDelegate {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
stateEvaluator: root.stateEvaluator.childEvaluators.get(index)
|
stateEvaluator: root.stateEvaluator.childEvaluators.get(index)
|
||||||
|
|||||||
Reference in New Issue
Block a user