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,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 {
@ -117,4 +125,6 @@ Page {
} }
} }
} }
}
} }

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]
} }
} }