some more work

This commit is contained in:
Michael Zanetti 2018-02-25 23:09:06 +01:00
parent ca4545766d
commit b910166d91
13 changed files with 90 additions and 48 deletions

View File

@ -247,10 +247,16 @@ QVariantMap JsonTypes::packRule(Rule *rule)
if (rule->eventDescriptors()->rowCount() > 0) { if (rule->eventDescriptors()->rowCount() > 0) {
QVariantList eventDescriptors; QVariantList eventDescriptors;
for (int i = 0; i < rule->eventDescriptors()->rowCount(); i++) { for (int i = 0; i < rule->eventDescriptors()->rowCount(); i++) {
QVariantMap eventDescriptor; QVariantMap eventDescriptorMap;
eventDescriptor.insert("eventTypeId", rule->eventDescriptors()->get(i)->eventTypeId()); EventDescriptor* eventDescriptor = rule->eventDescriptors()->get(i);
eventDescriptor.insert("deviceId", rule->eventDescriptors()->get(i)->deviceId()); if (!eventDescriptor->deviceId().isNull() && !eventDescriptor->eventTypeId().isNull()) {
if (rule->eventDescriptors()->get(i)->paramDescriptors()->rowCount() > 0) { eventDescriptorMap.insert("eventTypeId", eventDescriptor->eventTypeId());
eventDescriptorMap.insert("deviceId", eventDescriptor->deviceId());
} else {
eventDescriptorMap.insert("interface", eventDescriptor->interfaceName());
eventDescriptorMap.insert("interfaceEvent", eventDescriptor->interfaceEvent());
}
if (eventDescriptor->paramDescriptors()->rowCount() > 0) {
QVariantList paramDescriptors; QVariantList paramDescriptors;
for (int j = 0; j < rule->eventDescriptors()->get(i)->paramDescriptors()->rowCount(); j++) { for (int j = 0; j < rule->eventDescriptors()->get(i)->paramDescriptors()->rowCount(); j++) {
QVariantMap paramDescriptor; QVariantMap paramDescriptor;
@ -260,9 +266,9 @@ QVariantMap JsonTypes::packRule(Rule *rule)
paramDescriptor.insert("operator", operatorEnum.valueToKey(rule->eventDescriptors()->get(i)->paramDescriptors()->get(j)->operatorType())); paramDescriptor.insert("operator", operatorEnum.valueToKey(rule->eventDescriptors()->get(i)->paramDescriptors()->get(j)->operatorType()));
paramDescriptors.append(paramDescriptor); paramDescriptors.append(paramDescriptor);
} }
eventDescriptor.insert("paramDescriptors", paramDescriptors); eventDescriptorMap.insert("paramDescriptors", paramDescriptors);
} }
eventDescriptors.append(eventDescriptor); eventDescriptors.append(eventDescriptorMap);
} }
ret.insert("eventDescriptors", eventDescriptors); ret.insert("eventDescriptors", eventDescriptors);
} }

View File

@ -48,6 +48,14 @@
#include "models/valuelogsproxymodel.h" #include "models/valuelogsproxymodel.h"
#include "basicconfiguration.h" #include "basicconfiguration.h"
static QObject* interfacesModel_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new Interfaces();
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
@ -125,7 +133,7 @@ int main(int argc, char *argv[])
qmlRegisterUncreatableType<ParamDescriptors>(uri, 1, 0, "ParamDescriptors", "Uncreatable"); qmlRegisterUncreatableType<ParamDescriptors>(uri, 1, 0, "ParamDescriptors", "Uncreatable");
qmlRegisterUncreatableType<Interface>(uri, 1, 0, "Interface", "Uncreatable"); qmlRegisterUncreatableType<Interface>(uri, 1, 0, "Interface", "Uncreatable");
qmlRegisterType<Interfaces>(uri, 1, 0, "Interfaces"); qmlRegisterSingletonType<Interfaces>(uri, 1, 0, "Interfaces", interfacesModel_provider);
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.");

View File

@ -133,7 +133,7 @@ void RuleManager::getRuleDetailsReply(const QVariantMap &params)
qDebug() << "Got rule details for a rule we don't know"; qDebug() << "Got rule details for a rule we don't know";
return; return;
} }
// 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());
@ -179,6 +179,8 @@ void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList,
EventDescriptor *eventDescriptor = new EventDescriptor(rule); EventDescriptor *eventDescriptor = new EventDescriptor(rule);
eventDescriptor->setDeviceId(eventDescriptorVariant.toMap().value("deviceId").toUuid()); eventDescriptor->setDeviceId(eventDescriptorVariant.toMap().value("deviceId").toUuid());
eventDescriptor->setEventTypeId(eventDescriptorVariant.toMap().value("eventTypeId").toUuid()); eventDescriptor->setEventTypeId(eventDescriptorVariant.toMap().value("eventTypeId").toUuid());
eventDescriptor->setInterfaceName(eventDescriptorVariant.toMap().value("interface").toString());
eventDescriptor->setInterfaceEvent(eventDescriptorVariant.toMap().value("interfaceEvent").toString());
foreach (const QVariant &paramDescriptorVariant, eventDescriptorVariant.toMap().value("paramDescriptors").toList()) { foreach (const QVariant &paramDescriptorVariant, eventDescriptorVariant.toMap().value("paramDescriptors").toList()) {
ParamDescriptor *paramDescriptor = new ParamDescriptor(paramDescriptorVariant.toMap().value("paramTypeId").toString(), paramDescriptorVariant.toMap().value("value")); ParamDescriptor *paramDescriptor = new ParamDescriptor(paramDescriptorVariant.toMap().value("paramTypeId").toString(), paramDescriptorVariant.toMap().value("value"));
QMetaEnum operatorEnum = QMetaEnum::fromType<ParamDescriptor::ValueOperator>(); QMetaEnum operatorEnum = QMetaEnum::fromType<ParamDescriptor::ValueOperator>();

View File

@ -27,7 +27,8 @@ Page {
if (ruleError == "RuleErrorNoError") { if (ruleError == "RuleErrorNoError") {
pageStack.pop(); pageStack.pop();
} else { } else {
errorDialog.createComponent(root, {text: ruleError }) var popup = errorDialog.createObject(root, {text: ruleError })
popup.open();
} }
} }
@ -35,7 +36,8 @@ Page {
if (ruleError == "RuleErrorNoError") { if (ruleError == "RuleErrorNoError") {
pageStack.pop(); pageStack.pop();
} else { } else {
errorDialog.createComponent(root, {text: ruleError }) var popup = errorDialog.createObject(root, {text: ruleError })
popup.open();
} }
} }
} }
@ -70,7 +72,7 @@ Page {
}) })
} }
swipe.right: Item { swipe.right: MouseArea {
height: ruleDelegate.height height: ruleDelegate.height
width: height width: height
anchors.right: parent.right anchors.right: parent.right
@ -80,8 +82,13 @@ Page {
name: "../images/delete.svg" name: "../images/delete.svg"
color: "red" color: "red"
} }
SwipeDelegate.onClicked: Engine.ruleManager.removeRule(model.id) onClicked: Engine.ruleManager.removeRule(model.id)
} }
} }
} }
Component {
id: errorDialog
ErrorDialog {}
}
} }

View File

@ -126,12 +126,15 @@ Page {
delegate: SwipeDelegate { delegate: SwipeDelegate {
id: eventDelegate id: eventDelegate
Layout.fillWidth: true Layout.fillWidth: true
property var device: Engine.deviceManager.devices.getDevice(root.rule.eventDescriptors.get(index).deviceId) readonly property var eventDescriptor: root.rule.eventDescriptors.get(index)
property var device: Engine.deviceManager.devices.getDevice(eventDescriptor.deviceId)
property var deviceClass: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null property var deviceClass: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
property var eventType: deviceClass ? deviceClass.eventTypes.getEventType(root.rule.eventDescriptors.get(index).eventTypeId) : null property var iface: eventDescriptor.interfaceName ? Interfaces.findByName(eventDescriptor.interfaceName) : null
property var eventType: deviceClass ? deviceClass.eventTypes.getEventType(eventDescriptor.eventTypeId)
: iface ? iface.eventTypes.findByName(eventDescriptor.interfaceEvent) : null
contentItem: ColumnLayout { contentItem: ColumnLayout {
Label { Label {
text: qsTr("%1 - %2").arg(eventDelegate.device.name).arg(eventDelegate.eventType.displayName) text: qsTr("%1 - %2").arg(eventDelegate.device ? eventDelegate.device.name : eventDelegate.iface.displayName).arg(eventDelegate.eventType.displayName)
Layout.fillWidth: true Layout.fillWidth: true
elide: Text.ElideRight elide: Text.ElideRight
} }
@ -142,6 +145,7 @@ Page {
model: root.rule.eventDescriptors.get(index).paramDescriptors model: root.rule.eventDescriptors.get(index).paramDescriptors
Label { Label {
text: { text: {
print("***", eventDelegate.iface, eventDelegate.eventDescriptor.interfaceName, Interfaces.findByName(eventDelegate.eventDescriptor.interfaceName), eventDescriptor.interfaceName ? Interfaces.findByName(eventDescriptor.interfaceName) : null)
var ret = eventDelegate.eventType.paramTypes.getParamType(model.id).displayName var ret = eventDelegate.eventType.paramTypes.getParamType(model.id).displayName
switch (model.operator) { switch (model.operator) {
case ParamDescriptor.ValueOperatorEquals: case ParamDescriptor.ValueOperatorEquals:
@ -175,7 +179,7 @@ Page {
} }
} }
swipe.right: Item { swipe.right: MouseArea {
height: eventDelegate.height height: eventDelegate.height
width: height width: height
anchors.right: parent.right anchors.right: parent.right
@ -185,7 +189,7 @@ Page {
name: "../images/delete.svg" name: "../images/delete.svg"
color: "red" color: "red"
} }
SwipeDelegate.onClicked: root.rule.eventDescriptors.removeEventDescriptor(index) onClicked: root.rule.eventDescriptors.removeEventDescriptor(index)
} }
} }
} }
@ -233,7 +237,7 @@ Page {
} }
} }
} }
swipe.right: Item { swipe.right: MouseArea {
height: actionDelegate.height height: actionDelegate.height
width: height width: height
anchors.right: parent.right anchors.right: parent.right
@ -243,7 +247,7 @@ Page {
name: "../images/delete.svg" name: "../images/delete.svg"
color: "red" color: "red"
} }
SwipeDelegate.onClicked: root.rule.ruleActions.removeRuleAction(index) onClicked: root.rule.ruleActions.removeRuleAction(index)
} }
} }
} }

View File

@ -40,22 +40,18 @@ Page {
ListElement { interfaceName: "weather"; text: "When it starts raining..."; event: "rain" } ListElement { interfaceName: "weather"; text: "When it starts raining..."; event: "rain" }
} }
Interfaces {
id: interfacesModel
}
function buildInterface() { 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 < interfacesModel.count; i++) { for (var i = 0; i < Interfaces.count; i++) {
print("event is for interface", interfacesModel.get(i).name) print("event is for interface", Interfaces.get(i).name)
if (deviceClass.interfaces.indexOf(interfacesModel.get(i).name) >= 0) { if (deviceClass.interfaces.indexOf(Interfaces.get(i).name) >= 0) {
actualModel.append(interfacesModel.get(i)) actualModel.append(Interfaces.get(i))
} }
} }
} else if (root.eventDescriptor.interfaceName !== "") { } else if (root.eventDescriptor.interfaceName !== "") {
listView.model = interfacesModel.findByName(root.eventDescriptor.interfaceName).eventTypes listView.model = Interfaces.findByName(root.eventDescriptor.interfaceName).eventTypes
} else { } else {
console.warn("You need to set device or interfaceName"); console.warn("You need to set device or interfaceName");
} }
@ -87,6 +83,20 @@ Page {
default: default:
console.warn("FIXME: Unhandled interface event"); console.warn("FIXME: Unhandled interface event");
} }
} else if (root.eventDescriptor.interfaceName != "") {
root.eventDescriptor.interfaceEvent = model.name;
if (listView.model.get(index).paramTypes.count > 0) {
var paramsPage = pageStack.push(Qt.resolvedUrl("SelectEventDescriptorParamsPage.qml"), {eventDescriptor: root.eventDescriptor})
paramsPage.onBackPressed.connect(function() {pageStack.pop()});
paramsPage.onCompleted.connect(function() {
pageStack.pop();
root.done();
})
} else {
root.done();
}
} else {
console.warn("Neither deviceId not interfaceName set. Cannot continue...");
} }
} else { } else {
if (root.device) { if (root.device) {

View File

@ -11,7 +11,9 @@ Page {
property var eventDescriptor: null property var eventDescriptor: null
readonly property var device: eventDescriptor && eventDescriptor.deviceId ? Engine.deviceManager.devices.getDevice(eventDescriptor.deviceId) : null readonly property var device: eventDescriptor && eventDescriptor.deviceId ? Engine.deviceManager.devices.getDevice(eventDescriptor.deviceId) : null
readonly property var eventType: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId).eventTypes.getEventType(eventDescriptor.eventTypeId) : null readonly property var iface: eventDescriptor && eventDescriptor.interfaceName ? Interfaces.findByName(eventDescriptor.interfaceName) : null
readonly property var eventType: device ? Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId).eventTypes.getEventType(eventDescriptor.eventTypeId)
: iface ? iface.eventTypes.findByName(eventDescriptor.interfaceEvent) : null
signal backPressed(); signal backPressed();
signal completed(); signal completed();

View File

@ -31,14 +31,10 @@ Page {
} }
} }
Interfaces {
id: interfacesModel
}
ListView { ListView {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
model: thingButton.checked ? Engine.deviceManager.devices : interfacesModel model: thingButton.checked ? Engine.deviceManager.devices : Interfaces
clip: true clip: true
delegate: ItemDelegate { delegate: ItemDelegate {
text: thingButton.checked ? model.name : model.displayName text: thingButton.checked ? model.name : model.displayName
@ -47,7 +43,7 @@ Page {
if (thingButton.checked) { if (thingButton.checked) {
root.thingSelected(Engine.deviceManager.devices.get(index)) root.thingSelected(Engine.deviceManager.devices.get(index))
} else { } else {
root.interfaceSelected(interfacesModel.get(index).name) root.interfaceSelected(Interfaces.get(index).name)
} }
} }
} }

View File

@ -20,12 +20,12 @@ ItemDelegate {
ComboBox { ComboBox {
Layout.fillWidth: true Layout.fillWidth: true
model: { model: {
switch (paramType.type) { switch (paramType.type.toLowerCase()) {
case "Bool": case "bool":
case "String": case "string":
return ["is", "is not"]; return ["is", "is not"];
case "Int": case "int":
case "Double": case "double":
return ["is", "is not", "is greater", "is smaller", "is greater or equal", "is smaller or equal"] return ["is", "is not", "is greater", "is smaller", "is greater or equal", "is smaller or equal"]
} }
} }
@ -61,16 +61,16 @@ ItemDelegate {
sourceComponent: { sourceComponent: {
print("Datatye is:", paramType.type, paramType.minValue, paramType.maxValue) print("Datatye is:", paramType.type, paramType.minValue, paramType.maxValue)
switch (paramType.type) { switch (paramType.type.toLowerCase()) {
case "Bool": case "bool":
return boolComponent; return boolComponent;
case "Int": case "int":
case "Double": case "double":
if (paramType.minValue !== undefined && paramType.maxValue !== undefined) { if (paramType.minValue !== undefined && paramType.maxValue !== undefined) {
return labelComponent; return labelComponent;
} }
return textFieldComponent; return textFieldComponent;
case "String": case "string":
if (paramType.allowedValues.length > 0) { if (paramType.allowedValues.length > 0) {
return comboBoxComponent return comboBoxComponent
} }

View File

@ -51,7 +51,10 @@ QString EventDescriptor::interfaceEvent() const
void EventDescriptor::setInterfaceEvent(const QString &interfaceEvent) void EventDescriptor::setInterfaceEvent(const QString &interfaceEvent)
{ {
m_interfaceEvent = interfaceEvent; if (m_interfaceEvent != interfaceEvent) {
m_interfaceEvent = interfaceEvent;
emit interfaceEventChanged();
}
} }
ParamDescriptors *EventDescriptor::paramDescriptors() const ParamDescriptors *EventDescriptor::paramDescriptors() const

View File

@ -13,7 +13,7 @@ class EventDescriptor : public QObject
Q_PROPERTY(QUuid eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged) Q_PROPERTY(QUuid 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 CONSTANT) Q_PROPERTY(QString interfaceEvent READ interfaceEvent WRITE setInterfaceEvent NOTIFY interfaceEventChanged)
Q_PROPERTY(ParamDescriptors* paramDescriptors READ paramDescriptors CONSTANT) Q_PROPERTY(ParamDescriptors* paramDescriptors READ paramDescriptors CONSTANT)
@ -40,6 +40,7 @@ signals:
void deviceIdChanged(); void deviceIdChanged();
void eventTypeIdChanged(); void eventTypeIdChanged();
void interfaceNameChanged(); void interfaceNameChanged();
void interfaceEventChanged();
private: private:
QUuid m_deviceId; QUuid m_deviceId;

View File

@ -20,6 +20,8 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent)
ev->setName("batteryLevel"); ev->setName("batteryLevel");
ev->setDisplayName("Battery level changed"); ev->setDisplayName("Battery level changed");
pt = new ParamType("batteryLevel", QVariant::Int, 50); pt = new ParamType("batteryLevel", QVariant::Int, 50);
pt->setDisplayName("Battery Level");
qDebug() << "added param" << pt->type();
pt->setMinValue(0); pt->setMinValue(0);
pt->setMaxValue(100); pt->setMaxValue(100);
ev->paramTypes()->addParamType(pt); ev->paramTypes()->addParamType(pt);
@ -31,6 +33,7 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent)
ev->setName("batteryCritical"); ev->setName("batteryCritical");
ev->setDisplayName("Battery level critical"); ev->setDisplayName("Battery level critical");
pt = new ParamType("batteryCritical", QVariant::Bool, true); pt = new ParamType("batteryCritical", QVariant::Bool, true);
pt->setDisplayName("Battery critical");
ev->paramTypes()->addParamType(pt); ev->paramTypes()->addParamType(pt);
iface->eventTypes()->addEventType(ev); iface->eventTypes()->addEventType(ev);

View File

@ -31,7 +31,7 @@ ParamType::ParamType(QObject *parent) :
ParamType::ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue, QObject *parent) : ParamType::ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue, QObject *parent) :
QObject(parent), QObject(parent),
m_name(name), m_name(name),
m_type(type), m_type(QVariant::typeToName(type)),
m_defaultValue(defaultValue), m_defaultValue(defaultValue),
m_readOnly(false) m_readOnly(false)
{ {