Add support for the color temperature picker in param delegates

This commit is contained in:
Michael Zanetti 2020-10-19 01:19:42 +02:00
parent fcc65c522c
commit 1d7f27a26c
14 changed files with 77 additions and 29 deletions

View File

@ -427,7 +427,7 @@ QVariantList RuleManager::packEventDescriptors(EventDescriptors *eventDescriptor
QVariantList paramDescriptors;
for (int j = 0; j < eventDescriptor->paramDescriptors()->rowCount(); j++) {
QVariantMap paramDescriptor;
if (!eventDescriptor->paramDescriptors()->get(j)->paramTypeId().isEmpty()) {
if (!eventDescriptor->paramDescriptors()->get(j)->paramTypeId().isNull()) {
paramDescriptor.insert("paramTypeId", eventDescriptor->paramDescriptors()->get(j)->paramTypeId());
} else {
paramDescriptor.insert("paramName", eventDescriptor->paramDescriptors()->get(j)->paramName());

View File

@ -49,7 +49,6 @@ ActionType *ActionTypes::get(int index) const
ActionType *ActionTypes::getActionType(const QUuid &actionTypeId) const
{
foreach (ActionType *actionType, m_actionTypes) {
qDebug() << "checking:" << actionType->id();
if (actionType->id() == actionTypeId) {
return actionType;
}

View File

@ -30,7 +30,7 @@
#include "param.h"
Param::Param(const QString &paramTypeId, const QVariant &value, QObject *parent) :
Param::Param(const QUuid &paramTypeId, const QVariant &value, QObject *parent) :
QObject(parent),
m_paramTypeId(paramTypeId),
m_value(value)
@ -43,12 +43,12 @@ Param::Param(QObject *parent):
}
QString Param::paramTypeId() const
QUuid Param::paramTypeId() const
{
return m_paramTypeId;
}
void Param::setParamTypeId(const QString &paramTypeId)
void Param::setParamTypeId(const QUuid &paramTypeId)
{
if (m_paramTypeId != paramTypeId) {
m_paramTypeId = paramTypeId;

View File

@ -32,21 +32,21 @@
#define PARAM_H
#include <QObject>
#include <QString>
#include <QUuid>
#include <QVariant>
class Param : public QObject
{
Q_OBJECT
Q_PROPERTY(QString paramTypeId READ paramTypeId WRITE setParamTypeId NOTIFY paramTypeIdChanged)
Q_PROPERTY(QUuid paramTypeId READ paramTypeId WRITE setParamTypeId NOTIFY paramTypeIdChanged)
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
public:
Param(const QString &paramTypeId = QString(), const QVariant &value = QVariant(), QObject *parent = nullptr);
Param(const QUuid &paramTypeId = QString(), const QVariant &value = QVariant(), QObject *parent = nullptr);
Param(QObject *parent);
QString paramTypeId() const;
void setParamTypeId(const QString &paramTypeId);
QUuid paramTypeId() const;
void setParamTypeId(const QUuid &paramTypeId);
QVariant value() const;
void setValue(const QVariant &value);
@ -56,7 +56,7 @@ signals:
void valueChanged();
protected:
QString m_paramTypeId;
QUuid m_paramTypeId;
QVariant m_value;
};

View File

@ -48,10 +48,10 @@ ParamType *ParamTypes::get(int index) const
return nullptr;
}
ParamType *ParamTypes::getParamType(const QString &id) const
ParamType *ParamTypes::getParamType(const QUuid &id) const
{
foreach (ParamType *paramType, m_paramTypes) {
if (paramType->id() == QUuid(id)) {
if (paramType->id() == id) {
return paramType;
}
}

View File

@ -59,7 +59,7 @@ public:
QList<ParamType *> paramTypes();
Q_INVOKABLE ParamType *get(int index) const;
Q_INVOKABLE ParamType *getParamType(const QString &id) const;
Q_INVOKABLE ParamType *getParamType(const QUuid &id) const;
Q_INVOKABLE ParamType *findByName(const QString &name) const;
int rowCount(const QModelIndex & parent = QModelIndex()) const;

View File

@ -74,9 +74,10 @@ void RuleActionParams::addRuleActionParam(RuleActionParam *ruleActionParam)
beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
m_list.append(ruleActionParam);
endInsertRows();
emit countChanged();
}
void RuleActionParams::setRuleActionParam(const QString &paramTypeId, const QVariant &value)
void RuleActionParams::setRuleActionParam(const QUuid &paramTypeId, const QVariant &value)
{
foreach (RuleActionParam *rap, m_list) {
if (rap->paramTypeId() == paramTypeId) {
@ -174,6 +175,9 @@ void RuleActionParams::setRuleActionParamStateByName(const QString &paramName, c
RuleActionParam *RuleActionParams::get(int index) const
{
if (index < 0 || index >= m_list.count()) {
return nullptr;
}
return m_list.at(index);
}
@ -187,6 +191,15 @@ bool RuleActionParams::hasRuleActionParam(const QString &paramTypeId) const
return false;
}
void RuleActionParams::clear()
{
beginResetModel();
qDeleteAll(m_list);
m_list.clear();
endResetModel();
emit countChanged();
}
bool RuleActionParams::operator==(RuleActionParams *other) const
{
if (rowCount() != other->rowCount()) {

View File

@ -56,7 +56,7 @@ public:
void addRuleActionParam(RuleActionParam* ruleActionParam);
Q_INVOKABLE void setRuleActionParam(const QString &paramTypeId, const QVariant &value);
Q_INVOKABLE void setRuleActionParam(const QUuid &paramTypeId, const QVariant &value);
Q_INVOKABLE void setRuleActionParamByName(const QString &paramName, const QVariant &value);
Q_INVOKABLE void setRuleActionParamEvent(const QString &paramTypeId, const QString &eventTypeId, const QString &eventParamTypeId);
Q_INVOKABLE void setRuleActionParamEventByName(const QString &paramName, const QString &eventTypeId, const QString &eventParamTypeId);
@ -67,6 +67,8 @@ public:
Q_INVOKABLE bool hasRuleActionParam(const QString &paramTypeId) const;
Q_INVOKABLE void clear();
bool operator==(RuleActionParams *other) const;
signals:

View File

@ -67,7 +67,7 @@ ItemDelegate {
Layout.fillWidth: true// sourceComponent === textFieldComponent || sourceComponent === stringComponent
sourceComponent: {
print("Loading ParamDelegate");
print("Writable:", root.writable, "type:", root.paramType.type, "min:", root.paramType.minValue, "max:", root.paramType.maxValue)
print("Writable:", root.writable, "type:", root.paramType.type, "min:", root.paramType.minValue, "max:", root.paramType.maxValue, "value:", root.param.value)
if (!root.writable) {
return stringComponent;
}
@ -77,6 +77,9 @@ ItemDelegate {
return boolComponent;
case "uint":
case "int":
if (root.paramType.name == "colorTemperature") {
return null;
}
case "double":
if (root.paramType.allowedValues.length > 0) {
return comboBoxComponent;
@ -103,13 +106,11 @@ ItemDelegate {
Loader {
Layout.fillWidth: true
sourceComponent: {
if (root.paramType.name == "colorTemperature") {
return colorTemperaturePickerComponent;
}
switch (root.paramType.type.toLowerCase()) {
// case "int":
// case "double":
// if (root.paramType.minValue !== undefined && root.paramType.maxValue !== undefined) {
// return sliderComponent
// }
// break;
case "color":
return colorPickerComponent
}
@ -312,6 +313,32 @@ ItemDelegate {
}
}
Component {
id: colorTemperaturePickerComponent
ColorPickerCt {
id: colorPickerCt
implicitHeight: 50
minCt: root.paramType.minValue
maxCt: root.paramType.maxValue
ct: root.param.value !== undefined
? root.param.value
: root.paramType.defaultValue
? root.paramType.defaultValue
: root.paramType.minValue
onCtChanged: {
root.param.value = ct
}
touchDelegate: Rectangle {
height: colorPickerCt.height
width: 5
color: app.accentColor
}
}
}
Component {
id: colorPreviewComponent
Rectangle {

View File

@ -220,7 +220,7 @@ DevicePageBase {
touchDelegate: Rectangle {
height: pickerCt.height
width: 5
color: app.foregroundColor
color: app.accentColor
}
property var lastSentTime: new Date()

View File

@ -72,6 +72,9 @@ NymeaListItemDelegate {
case "bool":
text = ruleActionParam.value === true ? qsTr("True") : qsTr("False")
break;
case "color":
text = "<font color=\"" + ruleActionParam.value + "\">⬤</font>"
break;
default:
text = ruleActionParam.value
}

View File

@ -175,7 +175,10 @@ Page {
} else {
var actionType = root.deviceClass.actionTypes.getActionType(model.actionTypeId);
console.log("ActionType", actionType.id, "selected. Has", actionType.paramTypes.count, "params");
root.ruleAction.actionTypeId = actionType.id;
if (root.ruleAction.actionTypeId !== actionType.id) {
root.ruleAction.actionTypeId = actionType.id;
root.ruleAction.ruleActionParams.clear();
}
root.ruleAction.browserItemId = "";
root.ruleAction.interfaceAction = "";
if (actionType.paramTypes.count > 0) {

View File

@ -38,14 +38,14 @@ import Nymea 1.0
Page {
id: root
// Needs to be set and have rule.ruleActions filled in with deviceId and actionTypeId or interfaceName and interfaceAction
property var ruleAction: null
property RuleAction ruleAction: null
// optionally a rule which will be used to propose events params as param values
property var rule: null
readonly property var device: ruleAction && ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null
readonly property Device device: ruleAction && ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null
readonly property var iface: ruleAction && ruleAction.interfaceName ? Interfaces.findByName(ruleAction.interfaceName) : null
readonly property var actionType: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId).actionTypes.getActionType(ruleAction.actionTypeId)
readonly property var actionType: device ? device.deviceClass.actionTypes.getActionType(ruleAction.actionTypeId)
: iface ? iface.actionTypes.findByName(ruleAction.interfaceAction) : null
signal backPressed();
@ -125,6 +125,7 @@ Page {
paramType: root.actionType.paramTypes.get(index)
enabled: staticParamRadioButton.checked
nameVisible: false
value: root.ruleAction.ruleActionParams.get(index).value
visible: staticParamRadioButton.checked
placeholderText: qsTr("Insert value here")
}

View File

@ -63,7 +63,7 @@ SwipeDelegate {
ColorIcon {
Layout.preferredHeight: childEvaluatorsRepeater.count > 0 ? app.iconSize * .6 : app.iconSize
Layout.preferredWidth: height
name: root.stateEvaluator.stateDescriptor.interfaceName.length === 0 ? "../images/state.svg" : "../images/state-interface.svg"
name: root.stateEvaluator && root.stateEvaluator.stateDescriptor.interfaceName.length === 0 ? "../images/state.svg" : "../images/state-interface.svg"
color: app.accentColor
}