some more work

pull/1/head
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) {
QVariantList eventDescriptors;
for (int i = 0; i < rule->eventDescriptors()->rowCount(); i++) {
QVariantMap eventDescriptor;
eventDescriptor.insert("eventTypeId", rule->eventDescriptors()->get(i)->eventTypeId());
eventDescriptor.insert("deviceId", rule->eventDescriptors()->get(i)->deviceId());
if (rule->eventDescriptors()->get(i)->paramDescriptors()->rowCount() > 0) {
QVariantMap eventDescriptorMap;
EventDescriptor* eventDescriptor = rule->eventDescriptors()->get(i);
if (!eventDescriptor->deviceId().isNull() && !eventDescriptor->eventTypeId().isNull()) {
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;
for (int j = 0; j < rule->eventDescriptors()->get(i)->paramDescriptors()->rowCount(); j++) {
QVariantMap paramDescriptor;
@ -260,9 +266,9 @@ QVariantMap JsonTypes::packRule(Rule *rule)
paramDescriptor.insert("operator", operatorEnum.valueToKey(rule->eventDescriptors()->get(i)->paramDescriptors()->get(j)->operatorType()));
paramDescriptors.append(paramDescriptor);
}
eventDescriptor.insert("paramDescriptors", paramDescriptors);
eventDescriptorMap.insert("paramDescriptors", paramDescriptors);
}
eventDescriptors.append(eventDescriptor);
eventDescriptors.append(eventDescriptorMap);
}
ret.insert("eventDescriptors", eventDescriptors);
}

View File

@ -48,6 +48,14 @@
#include "models/valuelogsproxymodel.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[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
@ -125,7 +133,7 @@ int main(int argc, char *argv[])
qmlRegisterUncreatableType<ParamDescriptors>(uri, 1, 0, "ParamDescriptors", "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<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";
return;
}
// qDebug() << "got rule details for rule" << ruleMap;
qDebug() << "got rule details for rule" << ruleMap;
parseEventDescriptors(ruleMap.value("eventDescriptors").toList(), rule);
parseRuleActions(ruleMap.value("actions").toList(), rule);
parseStateEvaluator(ruleMap.value("stateEvaluator").toMap());
@ -179,6 +179,8 @@ void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList,
EventDescriptor *eventDescriptor = new EventDescriptor(rule);
eventDescriptor->setDeviceId(eventDescriptorVariant.toMap().value("deviceId").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()) {
ParamDescriptor *paramDescriptor = new ParamDescriptor(paramDescriptorVariant.toMap().value("paramTypeId").toString(), paramDescriptorVariant.toMap().value("value"));
QMetaEnum operatorEnum = QMetaEnum::fromType<ParamDescriptor::ValueOperator>();

View File

@ -27,7 +27,8 @@ Page {
if (ruleError == "RuleErrorNoError") {
pageStack.pop();
} else {
errorDialog.createComponent(root, {text: ruleError })
var popup = errorDialog.createObject(root, {text: ruleError })
popup.open();
}
}
@ -35,7 +36,8 @@ Page {
if (ruleError == "RuleErrorNoError") {
pageStack.pop();
} 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
width: height
anchors.right: parent.right
@ -80,8 +82,13 @@ Page {
name: "../images/delete.svg"
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 {
id: eventDelegate
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 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 {
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
elide: Text.ElideRight
}
@ -142,6 +145,7 @@ Page {
model: root.rule.eventDescriptors.get(index).paramDescriptors
Label {
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
switch (model.operator) {
case ParamDescriptor.ValueOperatorEquals:
@ -175,7 +179,7 @@ Page {
}
}
swipe.right: Item {
swipe.right: MouseArea {
height: eventDelegate.height
width: height
anchors.right: parent.right
@ -185,7 +189,7 @@ Page {
name: "../images/delete.svg"
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
width: height
anchors.right: parent.right
@ -243,7 +247,7 @@ Page {
name: "../images/delete.svg"
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" }
}
Interfaces {
id: interfacesModel
}
function buildInterface() {
if (header.interfacesMode) {
if (root.device) {
print("device supports interfaces", deviceClass.interfaces)
for (var i = 0; i < interfacesModel.count; i++) {
print("event is for interface", interfacesModel.get(i).name)
if (deviceClass.interfaces.indexOf(interfacesModel.get(i).name) >= 0) {
actualModel.append(interfacesModel.get(i))
for (var i = 0; i < Interfaces.count; i++) {
print("event is for interface", Interfaces.get(i).name)
if (deviceClass.interfaces.indexOf(Interfaces.get(i).name) >= 0) {
actualModel.append(Interfaces.get(i))
}
}
} else if (root.eventDescriptor.interfaceName !== "") {
listView.model = interfacesModel.findByName(root.eventDescriptor.interfaceName).eventTypes
listView.model = Interfaces.findByName(root.eventDescriptor.interfaceName).eventTypes
} else {
console.warn("You need to set device or interfaceName");
}
@ -87,6 +83,20 @@ Page {
default:
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 {
if (root.device) {

View File

@ -11,7 +11,9 @@ Page {
property var eventDescriptor: 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 completed();

View File

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

View File

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

View File

@ -51,7 +51,10 @@ QString EventDescriptor::interfaceEvent() const
void EventDescriptor::setInterfaceEvent(const QString &interfaceEvent)
{
if (m_interfaceEvent != interfaceEvent) {
m_interfaceEvent = interfaceEvent;
emit interfaceEventChanged();
}
}
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(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)
@ -40,6 +40,7 @@ signals:
void deviceIdChanged();
void eventTypeIdChanged();
void interfaceNameChanged();
void interfaceEventChanged();
private:
QUuid m_deviceId;

View File

@ -20,6 +20,8 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent)
ev->setName("batteryLevel");
ev->setDisplayName("Battery level changed");
pt = new ParamType("batteryLevel", QVariant::Int, 50);
pt->setDisplayName("Battery Level");
qDebug() << "added param" << pt->type();
pt->setMinValue(0);
pt->setMaxValue(100);
ev->paramTypes()->addParamType(pt);
@ -31,6 +33,7 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent)
ev->setName("batteryCritical");
ev->setDisplayName("Battery level critical");
pt = new ParamType("batteryCritical", QVariant::Bool, true);
pt->setDisplayName("Battery critical");
ev->paramTypes()->addParamType(pt);
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) :
QObject(parent),
m_name(name),
m_type(type),
m_type(QVariant::typeToName(type)),
m_defaultValue(defaultValue),
m_readOnly(false)
{