more work on ruleactionparams and rules in general

This commit is contained in:
Michael Zanetti 2018-03-13 18:09:34 +01:00
parent 8b9eb39b80
commit 143900a19a
7 changed files with 114 additions and 81 deletions

View File

@ -1,6 +1,8 @@
#include "rules.h" #include "rules.h"
#include "rule.h" #include "rule.h"
#include <QDebug>
Rules::Rules(QObject *parent) : QAbstractListModel(parent) Rules::Rules(QObject *parent) : QAbstractListModel(parent)
{ {
@ -51,6 +53,9 @@ void Rules::insert(Rule *rule)
rule->setParent(this); 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);
connect(rule, &Rule::enabledChanged, this, &Rules::ruleChanged);
connect(rule, &Rule::activeChanged, this, &Rules::ruleChanged);
connect(rule, &Rule::nameChanged, this, &Rules::ruleChanged);
endInsertRows(); endInsertRows();
emit countChanged(); emit countChanged();
} }
@ -85,3 +90,18 @@ Rule *Rules::getRule(const QUuid &ruleId) const
} }
return nullptr; return nullptr;
} }
void Rules::ruleChanged()
{
Rule *rule = dynamic_cast<Rule*>(sender());
if (!rule) {
return;
}
int idx = m_list.indexOf(rule);
if (idx < 0) {
qDebug() << "Rule not found in list. Discarding changed event.";
return;
}
QModelIndex modelIndex = index(idx);
emit dataChanged(modelIndex, modelIndex, {RoleActive, RoleEnabled, RoleName});
}

View File

@ -33,6 +33,9 @@ public:
signals: signals:
void countChanged(); void countChanged();
private slots:
void ruleChanged();
private: private:
QList<Rule*> m_list; QList<Rule*> m_list;
}; };

View File

@ -112,6 +112,7 @@ void RuleManager::getRulesReply(const QVariantMap &params)
qWarning() << "Error getting rules:" << params.value("error").toString(); qWarning() << "Error getting rules:" << params.value("error").toString();
return; return;
} }
qDebug() << "Get Rules reply" << params;
foreach (const QVariant &ruleDescriptionVariant, params.value("params").toMap().value("ruleDescriptions").toList()) { foreach (const QVariant &ruleDescriptionVariant, params.value("params").toMap().value("ruleDescriptions").toList()) {
QUuid ruleId = ruleDescriptionVariant.toMap().value("id").toUuid(); QUuid ruleId = ruleDescriptionVariant.toMap().value("id").toUuid();
QString name = ruleDescriptionVariant.toMap().value("name").toString(); QString name = ruleDescriptionVariant.toMap().value("name").toString();

View File

@ -56,7 +56,7 @@ Page {
height: app.iconSize height: app.iconSize
width: height width: height
name: "../images/magic.svg" name: "../images/magic.svg"
color: !model.enabled ? "gray" : (model.active ? "red" : app.guhAccent) color: !model.enabled ? "red" : (model.active ? app.guhAccent : "grey")
} }
Label { Label {

View File

@ -26,95 +26,105 @@ Page {
onBackPressed: root.backPressed(); onBackPressed: root.backPressed();
} }
ColumnLayout { Flickable {
anchors.fill: parent anchors.fill: parent
Repeater { contentHeight: contentCol.height
id: delegateRepeater
model: root.actionType.paramTypes
delegate: ColumnLayout {
Layout.fillWidth: true
property string type: {
if (staticParamRadioButton.checked) {
return "static"
}
if (eventParamRadioButton.checked) {
return "event"
}
return ""
}
property alias paramType: paramDelegate.paramType ColumnLayout {
property alias value: paramDelegate.value id: contentCol
property alias eventType: eventDescriptorParamsFilterModel.eventType width: parent.width
property alias eventParamTypeId: eventDescriptorParamsFilterModel.paramTypeId
RadioButton { Repeater {
id: staticParamRadioButton id: delegateRepeater
text: qsTr("Use static value as parameter") model: root.actionType.paramTypes
checked: true delegate: ColumnLayout {
}
ParamDelegate {
id: paramDelegate
Layout.fillWidth: true Layout.fillWidth: true
paramType: root.actionType.paramTypes.get(index) property string type: {
enabled: staticParamRadioButton.checked if (staticParamRadioButton.checked) {
} return "static"
}
if (eventParamRadioButton.checked) {
return "event"
}
return ""
}
RadioButton { property alias paramType: paramDelegate.paramType
id: eventParamRadioButton property alias value: paramDelegate.value
text: qsTr("Use event parameter") property alias eventType: eventDescriptorParamsFilterModel.eventType
visible: eventParamsComboBox.count > 0 property alias eventParamTypeId: eventDescriptorParamsFilterModel.paramTypeId
}
ComboBox { RadioButton {
id: eventParamsComboBox id: staticParamRadioButton
Layout.fillWidth: true text: qsTr("Use static value as parameter")
Layout.margins: app.margins checked: true
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 { ParamDelegate {
width: parent.width id: paramDelegate
text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.eventType.paramTypes.getParamType(model.id).displayName Layout.fillWidth: true
paramType: root.actionType.paramTypes.get(index)
enabled: staticParamRadioButton.checked
} }
contentItem: Label {
id: eventParamsComboBoxContentItem RadioButton {
anchors.fill: parent id: eventParamRadioButton
anchors.margins: app.margins text: qsTr("Use event parameter")
text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.paramDescriptor.displayName 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
}
}
ThinDivider {}
} }
} }
} Item {
Item { Layout.fillWidth: true
Layout.fillWidth: true Layout.fillHeight: true
Layout.fillHeight: true }
} Button {
Button { text: "OK"
text: "OK" Layout.fillWidth: true
Layout.fillWidth: true Layout.margins: app.margins
Layout.margins: app.margins onClicked: {
onClicked: { 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); if (paramDelegate.type === "static") {
if (paramDelegate.type === "static") { root.ruleAction.ruleActionParams.setRuleActionParam(paramDelegate.paramType.id, paramDelegate.value)
root.ruleAction.ruleActionParams.setRuleActionParam(paramDelegate.paramType.id, paramDelegate.value) } else if (paramDelegate.type === "event") {
} else if (paramDelegate.type === "event") { print("adding event based rule action param", paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId)
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.ruleAction.ruleActionParams.setRuleActionParamEvent(paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId) }
} }
root.completed()
} }
root.completed()
} }
} }
} }
} }

View File

@ -142,7 +142,7 @@ ApplicationWindow {
return Qt.resolvedUrl("images/mediaplayer-app-symbolic.svg") return Qt.resolvedUrl("images/mediaplayer-app-symbolic.svg")
case "button": case "button":
case "longpressbutton": case "longpressbutton":
case "multibutton": case "simplemultibutton":
case "longpressmultibutton": case "longpressmultibutton":
return Qt.resolvedUrl("images/system-shutdown.svg") return Qt.resolvedUrl("images/system-shutdown.svg")
case "weather": case "weather":

View File

@ -61,7 +61,7 @@ ItemDelegate {
Layout.fillWidth: true Layout.fillWidth: true
sourceComponent: { sourceComponent: {
print("Datatye is:", paramType.type, paramType.minValue, paramType.maxValue) print("Datatye is:", paramType.type, paramType.minValue, paramType.maxValue, paramType.allowedValues)
switch (paramType.type.toLowerCase()) { switch (paramType.type.toLowerCase()) {
case "bool": case "bool":
return boolComponent; return boolComponent;
@ -158,8 +158,7 @@ ItemDelegate {
id: comboBoxComponent id: comboBoxComponent
ComboBox { ComboBox {
model: paramType.allowedValues model: paramType.allowedValues
currentIndex: root.paramType.value onCurrentIndexChanged: {
onActivated: {
root.value = paramType.allowedValues[index] root.value = paramType.allowedValues[index]
} }
} }