more work on ruleactionparams and rules in general
This commit is contained in:
parent
8b9eb39b80
commit
143900a19a
@ -1,6 +1,8 @@
|
||||
#include "rules.h"
|
||||
#include "rule.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Rules::Rules(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
|
||||
@ -51,6 +53,9 @@ void Rules::insert(Rule *rule)
|
||||
rule->setParent(this);
|
||||
beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
|
||||
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();
|
||||
emit countChanged();
|
||||
}
|
||||
@ -85,3 +90,18 @@ Rule *Rules::getRule(const QUuid &ruleId) const
|
||||
}
|
||||
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});
|
||||
}
|
||||
|
||||
@ -33,6 +33,9 @@ public:
|
||||
signals:
|
||||
void countChanged();
|
||||
|
||||
private slots:
|
||||
void ruleChanged();
|
||||
|
||||
private:
|
||||
QList<Rule*> m_list;
|
||||
};
|
||||
|
||||
@ -112,6 +112,7 @@ void RuleManager::getRulesReply(const QVariantMap ¶ms)
|
||||
qWarning() << "Error getting rules:" << params.value("error").toString();
|
||||
return;
|
||||
}
|
||||
qDebug() << "Get Rules reply" << params;
|
||||
foreach (const QVariant &ruleDescriptionVariant, params.value("params").toMap().value("ruleDescriptions").toList()) {
|
||||
QUuid ruleId = ruleDescriptionVariant.toMap().value("id").toUuid();
|
||||
QString name = ruleDescriptionVariant.toMap().value("name").toString();
|
||||
|
||||
@ -56,7 +56,7 @@ Page {
|
||||
height: app.iconSize
|
||||
width: height
|
||||
name: "../images/magic.svg"
|
||||
color: !model.enabled ? "gray" : (model.active ? "red" : app.guhAccent)
|
||||
color: !model.enabled ? "red" : (model.active ? app.guhAccent : "grey")
|
||||
}
|
||||
|
||||
Label {
|
||||
|
||||
@ -26,95 +26,105 @@ Page {
|
||||
onBackPressed: root.backPressed();
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Flickable {
|
||||
anchors.fill: parent
|
||||
Repeater {
|
||||
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 ""
|
||||
}
|
||||
contentHeight: contentCol.height
|
||||
|
||||
property alias paramType: paramDelegate.paramType
|
||||
property alias value: paramDelegate.value
|
||||
property alias eventType: eventDescriptorParamsFilterModel.eventType
|
||||
property alias eventParamTypeId: eventDescriptorParamsFilterModel.paramTypeId
|
||||
ColumnLayout {
|
||||
id: contentCol
|
||||
width: parent.width
|
||||
|
||||
RadioButton {
|
||||
id: staticParamRadioButton
|
||||
text: qsTr("Use static value as parameter")
|
||||
checked: true
|
||||
}
|
||||
ParamDelegate {
|
||||
id: paramDelegate
|
||||
Repeater {
|
||||
id: delegateRepeater
|
||||
model: root.actionType.paramTypes
|
||||
delegate: ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
paramType: root.actionType.paramTypes.get(index)
|
||||
enabled: staticParamRadioButton.checked
|
||||
}
|
||||
property string type: {
|
||||
if (staticParamRadioButton.checked) {
|
||||
return "static"
|
||||
}
|
||||
if (eventParamRadioButton.checked) {
|
||||
return "event"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
delegate: ItemDelegate {
|
||||
width: parent.width
|
||||
text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.eventType.paramTypes.getParamType(model.id).displayName
|
||||
ParamDelegate {
|
||||
id: paramDelegate
|
||||
Layout.fillWidth: true
|
||||
paramType: root.actionType.paramTypes.get(index)
|
||||
enabled: staticParamRadioButton.checked
|
||||
}
|
||||
contentItem: Label {
|
||||
id: eventParamsComboBoxContentItem
|
||||
anchors.fill: parent
|
||||
anchors.margins: app.margins
|
||||
text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.paramDescriptor.displayName
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
ThinDivider {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
Button {
|
||||
text: "OK"
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: app.margins
|
||||
onClicked: {
|
||||
var params = [];
|
||||
for (var i = 0; i < delegateRepeater.count; i++) {
|
||||
var paramDelegate = delegateRepeater.itemAt(i);
|
||||
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)
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
Button {
|
||||
text: "OK"
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: app.margins
|
||||
onClicked: {
|
||||
var params = [];
|
||||
for (var i = 0; i < delegateRepeater.count; i++) {
|
||||
var paramDelegate = delegateRepeater.itemAt(i);
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ ApplicationWindow {
|
||||
return Qt.resolvedUrl("images/mediaplayer-app-symbolic.svg")
|
||||
case "button":
|
||||
case "longpressbutton":
|
||||
case "multibutton":
|
||||
case "simplemultibutton":
|
||||
case "longpressmultibutton":
|
||||
return Qt.resolvedUrl("images/system-shutdown.svg")
|
||||
case "weather":
|
||||
|
||||
@ -61,7 +61,7 @@ ItemDelegate {
|
||||
Layout.fillWidth: true
|
||||
|
||||
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()) {
|
||||
case "bool":
|
||||
return boolComponent;
|
||||
@ -158,8 +158,7 @@ ItemDelegate {
|
||||
id: comboBoxComponent
|
||||
ComboBox {
|
||||
model: paramType.allowedValues
|
||||
currentIndex: root.paramType.value
|
||||
onActivated: {
|
||||
onCurrentIndexChanged: {
|
||||
root.value = paramType.allowedValues[index]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user