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 "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});
|
||||||
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -112,6 +112,7 @@ void RuleManager::getRulesReply(const QVariantMap ¶ms)
|
|||||||
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();
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -26,8 +26,14 @@ Page {
|
|||||||
onBackPressed: root.backPressed();
|
onBackPressed: root.backPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
Flickable {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
contentHeight: contentCol.height
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
id: contentCol
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
id: delegateRepeater
|
id: delegateRepeater
|
||||||
model: root.actionType.paramTypes
|
model: root.actionType.paramTypes
|
||||||
@ -92,6 +98,8 @@ Page {
|
|||||||
text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.paramDescriptor.displayName
|
text: eventDescriptorParamsFilterModel.device.name + " - " + eventDescriptorParamsFilterModel.eventType.displayName + " - " + eventDescriptorParamsFilterModel.paramDescriptor.displayName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThinDivider {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Item {
|
Item {
|
||||||
@ -118,3 +126,5 @@ Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -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":
|
||||||
|
|||||||
@ -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]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user