some work on interfaces
This commit is contained in:
parent
c86ab221f4
commit
021a43764f
@ -162,7 +162,7 @@ void DeviceManager::getPluginsResponse(const QVariantMap ¶ms)
|
|||||||
|
|
||||||
void DeviceManager::getPluginConfigResponse(const QVariantMap ¶ms)
|
void DeviceManager::getPluginConfigResponse(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
qDebug() << "plugin config response" << params;
|
// qDebug() << "plugin config response" << params;
|
||||||
Plugin *p = m_plugins->get(m_currentGetConfigIndex);
|
Plugin *p = m_plugins->get(m_currentGetConfigIndex);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
qDebug() << "Received a plugin config for a plugin we don't know";
|
qDebug() << "Received a plugin config for a plugin we don't know";
|
||||||
|
|||||||
@ -221,7 +221,7 @@ QVariantMap JsonTypes::packRule(Rule *rule)
|
|||||||
ret.insert("ruleId", rule->id());
|
ret.insert("ruleId", rule->id());
|
||||||
}
|
}
|
||||||
ret.insert("name", rule->name());
|
ret.insert("name", rule->name());
|
||||||
ret.insert("enabled", true);
|
ret.insert("enabled", rule->enabled());
|
||||||
|
|
||||||
if (rule->ruleActions()->rowCount() > 0) {
|
if (rule->ruleActions()->rowCount() > 0) {
|
||||||
QVariantList actions;
|
QVariantList actions;
|
||||||
|
|||||||
@ -42,6 +42,8 @@
|
|||||||
#include "types/eventdescriptors.h"
|
#include "types/eventdescriptors.h"
|
||||||
#include "types/eventdescriptor.h"
|
#include "types/eventdescriptor.h"
|
||||||
#include "types/rule.h"
|
#include "types/rule.h"
|
||||||
|
#include "types/interfaces.h"
|
||||||
|
#include "types/interface.h"
|
||||||
#include "models/logsmodel.h"
|
#include "models/logsmodel.h"
|
||||||
#include "models/valuelogsproxymodel.h"
|
#include "models/valuelogsproxymodel.h"
|
||||||
#include "basicconfiguration.h"
|
#include "basicconfiguration.h"
|
||||||
@ -122,6 +124,9 @@ int main(int argc, char *argv[])
|
|||||||
qmlRegisterUncreatableType<ParamDescriptor>(uri, 1, 0, "ParamDescriptor", "Uncreatable");
|
qmlRegisterUncreatableType<ParamDescriptor>(uri, 1, 0, "ParamDescriptor", "Uncreatable");
|
||||||
qmlRegisterUncreatableType<ParamDescriptors>(uri, 1, 0, "ParamDescriptors", "Uncreatable");
|
qmlRegisterUncreatableType<ParamDescriptors>(uri, 1, 0, "ParamDescriptors", "Uncreatable");
|
||||||
|
|
||||||
|
qmlRegisterUncreatableType<Interface>(uri, 1, 0, "Interface", "Uncreatable");
|
||||||
|
qmlRegisterType<Interfaces>(uri, 1, 0, "Interfaces");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<Plugin>(uri, 1, 0, "Plugin", "Can't create this in QML. Get it from the Plugins.");
|
qmlRegisterUncreatableType<Plugin>(uri, 1, 0, "Plugin", "Can't create this in QML. Get it from the Plugins.");
|
||||||
qmlRegisterUncreatableType<Plugins>(uri, 1, 0, "Plugins", "Can't create this in QML. Get it from the DeviceManager.");
|
qmlRegisterUncreatableType<Plugins>(uri, 1, 0, "Plugins", "Can't create this in QML. Get it from the DeviceManager.");
|
||||||
qmlRegisterType<PluginsProxy>(uri, 1, 0, "PluginsProxy");
|
qmlRegisterType<PluginsProxy>(uri, 1, 0, "PluginsProxy");
|
||||||
|
|||||||
@ -133,5 +133,6 @@
|
|||||||
<file>ui/fonts/Ubuntu-MI.ttf</file>
|
<file>ui/fonts/Ubuntu-MI.ttf</file>
|
||||||
<file>ui/fonts/Ubuntu-R.ttf</file>
|
<file>ui/fonts/Ubuntu-R.ttf</file>
|
||||||
<file>ui/fonts/Ubuntu-RI.ttf</file>
|
<file>ui/fonts/Ubuntu-RI.ttf</file>
|
||||||
|
<file>ui/components/InterfacesModels.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@ -77,23 +77,27 @@ void RuleManager::handleRulesNotification(const QVariantMap ¶ms)
|
|||||||
// qDebug() << "rules notification received" << params;
|
// qDebug() << "rules notification received" << params;
|
||||||
if (params.value("notification").toString() == "Rules.RuleAdded") {
|
if (params.value("notification").toString() == "Rules.RuleAdded") {
|
||||||
QVariantMap ruleMap = params.value("params").toMap().value("rule").toMap();
|
QVariantMap ruleMap = params.value("params").toMap().value("rule").toMap();
|
||||||
QUuid ruleId = ruleMap.value("id").toUuid();
|
m_rules->insert(parseRule(ruleMap));
|
||||||
QString name = ruleMap.value("name").toString();
|
|
||||||
bool enabled = ruleMap.value("enabled").toBool();
|
|
||||||
bool active = ruleMap.value("active").toBool();
|
|
||||||
Rule* rule = new Rule(ruleId, m_rules);
|
|
||||||
rule->setName(name);
|
|
||||||
rule->setEnabled(enabled);
|
|
||||||
rule->setActive(active);
|
|
||||||
parseEventDescriptors(ruleMap.value("eventDescriptors").toList(), rule);
|
|
||||||
StateEvaluator* stateEvaluator = parseStateEvaluator(ruleMap.value("stateEvaluator").toMap());
|
|
||||||
stateEvaluator->setParent(rule);
|
|
||||||
|
|
||||||
parseRuleActions(ruleMap.value("actions").toList(), rule);
|
|
||||||
m_rules->insert(rule);
|
|
||||||
} else if (params.value("notification").toString() == "Rules.RuleRemoved") {
|
} else if (params.value("notification").toString() == "Rules.RuleRemoved") {
|
||||||
QUuid ruleId = params.value("params").toMap().value("ruleId").toUuid();
|
QUuid ruleId = params.value("params").toMap().value("ruleId").toUuid();
|
||||||
m_rules->remove(ruleId);
|
m_rules->remove(ruleId);
|
||||||
|
} else if (params.value("notification").toString() == "Rules.RuleConfigurationChanged") {
|
||||||
|
QVariantMap ruleMap = params.value("params").toMap().value("rule").toMap();
|
||||||
|
QUuid ruleId = ruleMap.value("id").toUuid();
|
||||||
|
int idx = -1;
|
||||||
|
for (int i = 0; i < m_rules->rowCount(); i++) {
|
||||||
|
if (m_rules->get(i)->id() == ruleId) {
|
||||||
|
idx = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (idx == -1) {
|
||||||
|
qWarning() << "Got a rule update notification for a rule we don't know" << ruleId;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_rules->remove(ruleId);
|
||||||
|
m_rules->insert(parseRule(ruleMap));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Unhandled rule notification" << params;
|
qWarning() << "Unhandled rule notification" << params;
|
||||||
}
|
}
|
||||||
@ -132,7 +136,7 @@ void RuleManager::getRuleDetailsReply(const QVariantMap ¶ms)
|
|||||||
// qDebug() << "got rule details for rule" << ruleMap;
|
// qDebug() << "got rule details for rule" << ruleMap;
|
||||||
parseEventDescriptors(ruleMap.value("eventDescriptors").toList(), rule);
|
parseEventDescriptors(ruleMap.value("eventDescriptors").toList(), rule);
|
||||||
parseRuleActions(ruleMap.value("actions").toList(), rule);
|
parseRuleActions(ruleMap.value("actions").toList(), rule);
|
||||||
parseStateEvaluator(ruleMap.value("stateEvaluator").toMap());
|
parseStateEvaluator(ruleMap.value("stateEvaluator").toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleManager::onAddRuleReply(const QVariantMap ¶ms)
|
void RuleManager::onAddRuleReply(const QVariantMap ¶ms)
|
||||||
@ -152,6 +156,23 @@ void RuleManager::onEditRuleReply(const QVariantMap ¶ms)
|
|||||||
emit editRuleReply(params.value("params").toMap().value("ruleError").toString());
|
emit editRuleReply(params.value("params").toMap().value("ruleError").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rule *RuleManager::parseRule(const QVariantMap &ruleMap)
|
||||||
|
{
|
||||||
|
QUuid ruleId = ruleMap.value("id").toUuid();
|
||||||
|
QString name = ruleMap.value("name").toString();
|
||||||
|
bool enabled = ruleMap.value("enabled").toBool();
|
||||||
|
bool active = ruleMap.value("active").toBool();
|
||||||
|
Rule* rule = new Rule(ruleId);
|
||||||
|
rule->setName(name);
|
||||||
|
rule->setEnabled(enabled);
|
||||||
|
rule->setActive(active);
|
||||||
|
parseEventDescriptors(ruleMap.value("eventDescriptors").toList(), rule);
|
||||||
|
StateEvaluator* stateEvaluator = parseStateEvaluator(ruleMap.value("stateEvaluator").toMap());
|
||||||
|
stateEvaluator->setParent(rule);
|
||||||
|
parseRuleActions(ruleMap.value("actions").toList(), rule);
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
|
||||||
void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList, Rule *rule)
|
void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList, Rule *rule)
|
||||||
{
|
{
|
||||||
foreach (const QVariant &eventDescriptorVariant, eventDescriptorList) {
|
foreach (const QVariant &eventDescriptorVariant, eventDescriptorList) {
|
||||||
|
|||||||
@ -40,6 +40,7 @@ private slots:
|
|||||||
void onEditRuleReply(const QVariantMap ¶ms);
|
void onEditRuleReply(const QVariantMap ¶ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Rule *parseRule(const QVariantMap &ruleMap);
|
||||||
void parseEventDescriptors(const QVariantList &eventDescriptorList, Rule *rule);
|
void parseEventDescriptors(const QVariantList &eventDescriptorList, Rule *rule);
|
||||||
StateEvaluator* parseStateEvaluator(const QVariantMap &stateEvaluatorMap);
|
StateEvaluator* parseStateEvaluator(const QVariantMap &stateEvaluatorMap);
|
||||||
void parseRuleActions(const QVariantList &ruleActions, Rule *rule);
|
void parseRuleActions(const QVariantList &ruleActions, Rule *rule);
|
||||||
|
|||||||
@ -26,13 +26,16 @@ Page {
|
|||||||
onAddRuleReply: {
|
onAddRuleReply: {
|
||||||
if (ruleError == "RuleErrorNoError") {
|
if (ruleError == "RuleErrorNoError") {
|
||||||
pageStack.pop();
|
pageStack.pop();
|
||||||
|
} else {
|
||||||
|
errorDialog.createComponent(root, {text: ruleError })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onEditRuleReply: {
|
onEditRuleReply: {
|
||||||
print("have add rule reply")
|
|
||||||
if (ruleError == "RuleErrorNoError") {
|
if (ruleError == "RuleErrorNoError") {
|
||||||
pageStack.pop();
|
pageStack.pop();
|
||||||
|
} else {
|
||||||
|
errorDialog.createComponent(root, {text: ruleError })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@ Page {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
currentIndex: pageIndicator.currentIndex
|
currentIndex: pageIndicator.currentIndex
|
||||||
clip: true
|
// clip: true
|
||||||
|
|
||||||
DevicesPage {
|
DevicesPage {
|
||||||
width: parent.view.width
|
width: parent.view.width
|
||||||
|
|||||||
8
guh-control/ui/components/InterfacesModels.qml
Normal file
8
guh-control/ui/components/InterfacesModels.qml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import QtQuick 2.0
|
||||||
|
|
||||||
|
Item {
|
||||||
|
property ListModel eventTemplateModel: ListModel {
|
||||||
|
ListElement { interfaceName: "battery"; stateName: "batteryLevel"; stateDisplayName: "Battery level"; eventDisplayName: "Battery level changed" }
|
||||||
|
ListElement { interfaceName: "battery"; stateName: "batteryCritical"; stateDisplayName: "Battery critical"; eventDisplayName: "Battery critical changed" }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -96,6 +96,19 @@ Page {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
RowLayout {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Label {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
text: qsTr("This rule is enabled")
|
||||||
|
}
|
||||||
|
CheckBox {
|
||||||
|
checked: root.rule.enabled
|
||||||
|
onClicked: {
|
||||||
|
root.rule.enabled = checked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ThinDivider {}
|
ThinDivider {}
|
||||||
|
|||||||
@ -23,11 +23,12 @@ Page {
|
|||||||
id: header
|
id: header
|
||||||
onBackPressed: root.backPressed();
|
onBackPressed: root.backPressed();
|
||||||
|
|
||||||
property bool interfacesMode: false
|
property bool interfacesMode: root.eventDescriptor.interfaceName !== ""
|
||||||
onInterfacesModeChanged: root.buildInterface()
|
onInterfacesModeChanged: root.buildInterface()
|
||||||
|
|
||||||
HeaderButton {
|
HeaderButton {
|
||||||
imageSource: header.interfacesMode ? "../images/view-expand.svg" : "../images/view-collapse.svg"
|
imageSource: header.interfacesMode ? "../images/view-expand.svg" : "../images/view-collapse.svg"
|
||||||
|
visible: root.eventDescriptor.interfaceName === ""
|
||||||
onClicked: header.interfacesMode = !header.interfacesMode
|
onClicked: header.interfacesMode = !header.interfacesMode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,48 +40,39 @@ Page {
|
|||||||
ListElement { interfaceName: "weather"; text: "When it starts raining..."; event: "rain" }
|
ListElement { interfaceName: "weather"; text: "When it starts raining..."; event: "rain" }
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildInterface() {
|
Interfaces {
|
||||||
actualModel.clear()
|
id: interfacesModel
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildInterface() {
|
||||||
if (header.interfacesMode) {
|
if (header.interfacesMode) {
|
||||||
if (root.device) {
|
if (root.device) {
|
||||||
print("device supports interfaces", deviceClass.interfaces)
|
print("device supports interfaces", deviceClass.interfaces)
|
||||||
for (var i = 0; i < eventTemplateModel.count; i++) {
|
for (var i = 0; i < interfacesModel.count; i++) {
|
||||||
print("event is for interface", eventTemplateModel.get(i).interfaceName)
|
print("event is for interface", interfacesModel.get(i).name)
|
||||||
if (deviceClass.interfaces.indexOf(eventTemplateModel.get(i).interfaceName) >= 0) {
|
if (deviceClass.interfaces.indexOf(interfacesModel.get(i).name) >= 0) {
|
||||||
actualModel.append(eventTemplateModel.get(i))
|
actualModel.append(interfacesModel.get(i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (root.eventDescriptor.interfaceName !== "") {
|
} else if (root.eventDescriptor.interfaceName !== "") {
|
||||||
for (var i = 0; i < eventTemplateModel.count; i++) {
|
listView.model = interfacesModel.findByName(root.eventDescriptor.interfaceName).eventTypes
|
||||||
if (eventTemplateModel.get(i).interfaceName === root.eventDescriptor.interfaceName) {
|
|
||||||
actualModel.append(eventTemplateModel.get(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
console.warn("You need to set device or interfaceName");
|
console.warn("You need to set device or interfaceName");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (root.device) {
|
if (root.device) {
|
||||||
for (var i = 0; i < deviceClass.eventTypes.count; i++) {
|
listView.model = deviceClass.eventTypes;
|
||||||
actualModel.append({text: deviceClass.eventTypes.get(i).displayName, eventTypeId: deviceClass.eventTypes.get(i).id})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
|
||||||
id: actualModel
|
|
||||||
ListElement { text: ""; eventTypeId: "" }
|
|
||||||
}
|
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
|
id: listView
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
model: actualModel
|
|
||||||
|
|
||||||
delegate: ItemDelegate {
|
delegate: ItemDelegate {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
text: model.text
|
text: model.displayName
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (header.interfacesMode) {
|
if (header.interfacesMode) {
|
||||||
if (root.device) {
|
if (root.device) {
|
||||||
@ -98,8 +90,8 @@ Page {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (root.device) {
|
if (root.device) {
|
||||||
var eventType = root.deviceClass.eventTypes.getEventType(model.eventTypeId);
|
var eventType = root.deviceClass.eventTypes.getEventType(model.id);
|
||||||
root.eventDescriptor.eventTypeId = model.eventTypeId;
|
root.eventDescriptor.eventTypeId = model.id;
|
||||||
if (eventType.paramTypes.count > 0) {
|
if (eventType.paramTypes.count > 0) {
|
||||||
var paramsPage = pageStack.push(Qt.resolvedUrl("SelectEventDescriptorParamsPage.qml"), {eventDescriptor: root.eventDescriptor})
|
var paramsPage = pageStack.push(Qt.resolvedUrl("SelectEventDescriptorParamsPage.qml"), {eventDescriptor: root.eventDescriptor})
|
||||||
paramsPage.onBackPressed.connect(function() {pageStack.pop()});
|
paramsPage.onBackPressed.connect(function() {pageStack.pop()});
|
||||||
|
|||||||
@ -31,26 +31,23 @@ Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
Interfaces {
|
||||||
id: supportedInterfacesModel
|
id: interfacesModel
|
||||||
ListElement { interfaceName: "battery"; name: "Battery powered devices" }
|
|
||||||
ListElement { interfaceName: "temperatureSensor"; name: "Temperature sensors" }
|
|
||||||
ListElement { interfaceName: "light"; name: "Lights" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
model: thingButton.checked ? Engine.deviceManager.devices : supportedInterfacesModel
|
model: thingButton.checked ? Engine.deviceManager.devices : interfacesModel
|
||||||
clip: true
|
clip: true
|
||||||
delegate: ItemDelegate {
|
delegate: ItemDelegate {
|
||||||
text: model.name
|
text: thingButton.checked ? model.name : model.displayName
|
||||||
width: parent.width
|
width: parent.width
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (thingButton.checked) {
|
if (thingButton.checked) {
|
||||||
root.thingSelected(Engine.deviceManager.devices.get(index))
|
root.thingSelected(Engine.deviceManager.devices.get(index))
|
||||||
} else {
|
} else {
|
||||||
root.interfaceSelected(supportedInterfacesModel.get(index).interfaceName)
|
root.interfaceSelected(interfacesModel.get(index).name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,9 @@ HEADERS += types/types.h \
|
|||||||
types/stateevaluator.h \
|
types/stateevaluator.h \
|
||||||
types/statedescriptor.h \
|
types/statedescriptor.h \
|
||||||
types/paramdescriptor.h \
|
types/paramdescriptor.h \
|
||||||
types/paramdescriptors.h
|
types/paramdescriptors.h \
|
||||||
|
types/interface.h \
|
||||||
|
types/interfaces.h
|
||||||
|
|
||||||
SOURCES += types/vendor.cpp \
|
SOURCES += types/vendor.cpp \
|
||||||
types/vendors.cpp \
|
types/vendors.cpp \
|
||||||
@ -76,7 +78,9 @@ SOURCES += types/vendor.cpp \
|
|||||||
types/stateevaluator.cpp \
|
types/stateevaluator.cpp \
|
||||||
types/statedescriptor.cpp \
|
types/statedescriptor.cpp \
|
||||||
types/paramdescriptor.cpp \
|
types/paramdescriptor.cpp \
|
||||||
types/paramdescriptors.cpp
|
types/paramdescriptors.cpp \
|
||||||
|
types/interface.cpp \
|
||||||
|
types/interfaces.cpp
|
||||||
|
|
||||||
# install header file with relative subdirectory
|
# install header file with relative subdirectory
|
||||||
for(header, HEADERS) {
|
for(header, HEADERS) {
|
||||||
|
|||||||
@ -57,14 +57,14 @@ int EventTypes::rowCount(const QModelIndex &parent) const
|
|||||||
|
|
||||||
QVariant EventTypes::data(const QModelIndex &index, int role) const
|
QVariant EventTypes::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (index.row() < 0 || index.row() >= m_eventTypes.count())
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
EventType *eventType = m_eventTypes.at(index.row());
|
EventType *eventType = m_eventTypes.at(index.row());
|
||||||
if (role == NameRole) {
|
switch (role) {
|
||||||
return eventType->name();
|
case RoleId:
|
||||||
} else if (role == IdRole) {
|
|
||||||
return eventType->id();
|
return eventType->id();
|
||||||
|
case RoleName:
|
||||||
|
return eventType->name();
|
||||||
|
case RoleDisplayName:
|
||||||
|
return eventType->displayName();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@ -99,8 +99,9 @@ EventType *EventTypes::findByName(const QString &name) const
|
|||||||
QHash<int, QByteArray> EventTypes::roleNames() const
|
QHash<int, QByteArray> EventTypes::roleNames() const
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles[NameRole] = "name";
|
roles.insert(RoleId, "id");
|
||||||
roles[IdRole] = "id";
|
roles.insert(RoleName, "name");
|
||||||
|
roles.insert(RoleDisplayName, "displayName");
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,9 +34,10 @@ class EventTypes : public QAbstractListModel
|
|||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum EventTypeRole {
|
enum Roles {
|
||||||
NameRole = Qt::DisplayRole,
|
RoleId,
|
||||||
IdRole
|
RoleName,
|
||||||
|
RoleDisplayName
|
||||||
};
|
};
|
||||||
|
|
||||||
EventTypes(QObject *parent = 0);
|
EventTypes(QObject *parent = 0);
|
||||||
|
|||||||
41
libguh-common/types/interface.cpp
Normal file
41
libguh-common/types/interface.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include "interface.h"
|
||||||
|
|
||||||
|
#include "eventtypes.h"
|
||||||
|
#include "statetypes.h"
|
||||||
|
#include "actiontypes.h"
|
||||||
|
|
||||||
|
Interface::Interface(const QString &name, const QString &displayName, QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_name(name),
|
||||||
|
m_displayName(displayName),
|
||||||
|
m_eventTypes(new EventTypes(this)),
|
||||||
|
m_stateTypes(new StateTypes(this)),
|
||||||
|
m_actionTypes(new ActionTypes(this))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Interface::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Interface::displayName() const
|
||||||
|
{
|
||||||
|
return m_displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
EventTypes* Interface::eventTypes() const
|
||||||
|
{
|
||||||
|
return m_eventTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
StateTypes* Interface::stateTypes() const
|
||||||
|
{
|
||||||
|
return m_stateTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionTypes* Interface::actionTypes() const
|
||||||
|
{
|
||||||
|
return m_actionTypes;
|
||||||
|
}
|
||||||
36
libguh-common/types/interface.h
Normal file
36
libguh-common/types/interface.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef INTERFACE_H
|
||||||
|
#define INTERFACE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class EventTypes;
|
||||||
|
class StateTypes;
|
||||||
|
class ActionTypes;
|
||||||
|
|
||||||
|
class Interface : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(QString displayName READ displayName CONSTANT)
|
||||||
|
Q_PROPERTY(EventTypes* eventTypes READ eventTypes CONSTANT)
|
||||||
|
Q_PROPERTY(StateTypes* stateTypes READ stateTypes CONSTANT)
|
||||||
|
Q_PROPERTY(ActionTypes* actionTypes READ actionTypes CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Interface(const QString &name, const QString &displayName, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
QString displayName() const;
|
||||||
|
EventTypes* eventTypes() const;
|
||||||
|
StateTypes* stateTypes() const;
|
||||||
|
ActionTypes* actionTypes() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
QString m_displayName;
|
||||||
|
EventTypes* m_eventTypes = nullptr;
|
||||||
|
StateTypes* m_stateTypes = nullptr;
|
||||||
|
ActionTypes* m_actionTypes = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INTERFACE_H
|
||||||
78
libguh-common/types/interfaces.cpp
Normal file
78
libguh-common/types/interfaces.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include "interfaces.h"
|
||||||
|
#include "interface.h"
|
||||||
|
|
||||||
|
#include "eventtypes.h"
|
||||||
|
#include "eventtype.h"
|
||||||
|
|
||||||
|
Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
Interface* iface = nullptr;
|
||||||
|
EventType* ev = nullptr;
|
||||||
|
ParamType* pt = nullptr;
|
||||||
|
ParamTypes *pts = nullptr;
|
||||||
|
|
||||||
|
iface = new Interface("battery", "Battery powered devices");
|
||||||
|
ev = new EventType();
|
||||||
|
pts = new ParamTypes(ev);
|
||||||
|
ev->setParamTypes(pts);
|
||||||
|
|
||||||
|
ev->setName("batteryLevel");
|
||||||
|
ev->setDisplayName("Battery level changed");
|
||||||
|
pt = new ParamType("batteryLevel", QVariant::Int, 50);
|
||||||
|
pt->setMinValue(0);
|
||||||
|
pt->setMaxValue(100);
|
||||||
|
ev->paramTypes()->addParamType(pt);
|
||||||
|
iface->eventTypes()->addEventType(ev);
|
||||||
|
|
||||||
|
ev = new EventType();
|
||||||
|
pts = new ParamTypes(ev);
|
||||||
|
ev->setParamTypes(pts);
|
||||||
|
ev->setName("batteryCritical");
|
||||||
|
ev->setDisplayName("Battery level critical");
|
||||||
|
pt = new ParamType("batteryCritical", QVariant::Bool, true);
|
||||||
|
ev->paramTypes()->addParamType(pt);
|
||||||
|
iface->eventTypes()->addEventType(ev);
|
||||||
|
|
||||||
|
m_list.append(iface);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Interfaces::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return m_list.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant Interfaces::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
switch (role) {
|
||||||
|
case RoleName:
|
||||||
|
return m_list.at(index.row())->name();
|
||||||
|
case RoleDisplayName:
|
||||||
|
return m_list.at(index.row())->displayName();
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> Interfaces::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles.insert(RoleName, "name");
|
||||||
|
roles.insert(RoleDisplayName, "displayName");
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
Interface *Interfaces::get(int index) const
|
||||||
|
{
|
||||||
|
return m_list.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
Interface *Interfaces::findByName(const QString &name) const
|
||||||
|
{
|
||||||
|
foreach (Interface* iface, m_list) {
|
||||||
|
if (iface->name() == name) {
|
||||||
|
return iface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
31
libguh-common/types/interfaces.h
Normal file
31
libguh-common/types/interfaces.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef INTERFACES_H
|
||||||
|
#define INTERFACES_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
class Interface;
|
||||||
|
|
||||||
|
class Interfaces : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int count READ rowCount CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum Roles {
|
||||||
|
RoleName,
|
||||||
|
RoleDisplayName
|
||||||
|
};
|
||||||
|
explicit Interfaces(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
Q_INVOKABLE Interface* get(int index) const;
|
||||||
|
Q_INVOKABLE Interface* findByName(const QString &name) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Interface*> m_list;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INTERFACES_H
|
||||||
@ -13,7 +13,7 @@ class Rule : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid id READ id CONSTANT)
|
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||||
Q_PROPERTY(bool enabled READ enabled NOTIFY enabledChanged)
|
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
|
||||||
Q_PROPERTY(bool active READ active NOTIFY activeChanged)
|
Q_PROPERTY(bool active READ active NOTIFY activeChanged)
|
||||||
Q_PROPERTY(EventDescriptors* eventDescriptors READ eventDescriptors CONSTANT)
|
Q_PROPERTY(EventDescriptors* eventDescriptors READ eventDescriptors CONSTANT)
|
||||||
Q_PROPERTY(StateEvaluator* stateEvaluator READ stateEvaluator CONSTANT)
|
Q_PROPERTY(StateEvaluator* stateEvaluator READ stateEvaluator CONSTANT)
|
||||||
@ -46,7 +46,7 @@ signals:
|
|||||||
private:
|
private:
|
||||||
QUuid m_id;
|
QUuid m_id;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
bool m_enabled = false;
|
bool m_enabled = true;
|
||||||
bool m_active = false;
|
bool m_active = false;
|
||||||
EventDescriptors *m_eventDescriptors = nullptr;
|
EventDescriptors *m_eventDescriptors = nullptr;
|
||||||
StateEvaluator *m_stateEvaluator = nullptr;
|
StateEvaluator *m_stateEvaluator = nullptr;
|
||||||
|
|||||||
@ -8,8 +8,11 @@ Rules::Rules(QObject *parent) : QAbstractListModel(parent)
|
|||||||
|
|
||||||
void Rules::clear()
|
void Rules::clear()
|
||||||
{
|
{
|
||||||
|
beginResetModel();
|
||||||
qDeleteAll(m_list);
|
qDeleteAll(m_list);
|
||||||
m_list.clear();
|
m_list.clear();
|
||||||
|
endResetModel();
|
||||||
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Rules::rowCount(const QModelIndex &parent) const
|
int Rules::rowCount(const QModelIndex &parent) const
|
||||||
@ -45,9 +48,11 @@ QHash<int, QByteArray> Rules::roleNames() const
|
|||||||
|
|
||||||
void Rules::insert(Rule *rule)
|
void Rules::insert(Rule *rule)
|
||||||
{
|
{
|
||||||
|
rule->setParent(this);
|
||||||
beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
|
beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
|
||||||
m_list.append(rule);
|
m_list.append(rule);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rules::remove(const QUuid &ruleId)
|
void Rules::remove(const QUuid &ruleId)
|
||||||
@ -57,6 +62,7 @@ void Rules::remove(const QUuid &ruleId)
|
|||||||
beginRemoveRows(QModelIndex(), i, i);
|
beginRemoveRows(QModelIndex(), i, i);
|
||||||
m_list.takeAt(i)->deleteLater();
|
m_list.takeAt(i)->deleteLater();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
emit countChanged();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ class Rule;
|
|||||||
class Rules : public QAbstractListModel
|
class Rules : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
public:
|
public:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
RoleName,
|
RoleName,
|
||||||
@ -19,7 +20,7 @@ public:
|
|||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
@ -29,6 +30,9 @@ public:
|
|||||||
Q_INVOKABLE Rule* get(int index) const;
|
Q_INVOKABLE Rule* get(int index) const;
|
||||||
Q_INVOKABLE Rule* getRule(const QUuid &ruleId) const;
|
Q_INVOKABLE Rule* getRule(const QUuid &ruleId) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void countChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Rule*> m_list;
|
QList<Rule*> m_list;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user