Add support for the color temperature picker in param delegates
This commit is contained in:
parent
fcc65c522c
commit
1d7f27a26c
@ -427,7 +427,7 @@ QVariantList RuleManager::packEventDescriptors(EventDescriptors *eventDescriptor
|
|||||||
QVariantList paramDescriptors;
|
QVariantList paramDescriptors;
|
||||||
for (int j = 0; j < eventDescriptor->paramDescriptors()->rowCount(); j++) {
|
for (int j = 0; j < eventDescriptor->paramDescriptors()->rowCount(); j++) {
|
||||||
QVariantMap paramDescriptor;
|
QVariantMap paramDescriptor;
|
||||||
if (!eventDescriptor->paramDescriptors()->get(j)->paramTypeId().isEmpty()) {
|
if (!eventDescriptor->paramDescriptors()->get(j)->paramTypeId().isNull()) {
|
||||||
paramDescriptor.insert("paramTypeId", eventDescriptor->paramDescriptors()->get(j)->paramTypeId());
|
paramDescriptor.insert("paramTypeId", eventDescriptor->paramDescriptors()->get(j)->paramTypeId());
|
||||||
} else {
|
} else {
|
||||||
paramDescriptor.insert("paramName", eventDescriptor->paramDescriptors()->get(j)->paramName());
|
paramDescriptor.insert("paramName", eventDescriptor->paramDescriptors()->get(j)->paramName());
|
||||||
|
|||||||
@ -49,7 +49,6 @@ ActionType *ActionTypes::get(int index) const
|
|||||||
ActionType *ActionTypes::getActionType(const QUuid &actionTypeId) const
|
ActionType *ActionTypes::getActionType(const QUuid &actionTypeId) const
|
||||||
{
|
{
|
||||||
foreach (ActionType *actionType, m_actionTypes) {
|
foreach (ActionType *actionType, m_actionTypes) {
|
||||||
qDebug() << "checking:" << actionType->id();
|
|
||||||
if (actionType->id() == actionTypeId) {
|
if (actionType->id() == actionTypeId) {
|
||||||
return actionType;
|
return actionType;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
|
||||||
Param::Param(const QString ¶mTypeId, const QVariant &value, QObject *parent) :
|
Param::Param(const QUuid ¶mTypeId, const QVariant &value, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_paramTypeId(paramTypeId),
|
m_paramTypeId(paramTypeId),
|
||||||
m_value(value)
|
m_value(value)
|
||||||
@ -43,12 +43,12 @@ Param::Param(QObject *parent):
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Param::paramTypeId() const
|
QUuid Param::paramTypeId() const
|
||||||
{
|
{
|
||||||
return m_paramTypeId;
|
return m_paramTypeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Param::setParamTypeId(const QString ¶mTypeId)
|
void Param::setParamTypeId(const QUuid ¶mTypeId)
|
||||||
{
|
{
|
||||||
if (m_paramTypeId != paramTypeId) {
|
if (m_paramTypeId != paramTypeId) {
|
||||||
m_paramTypeId = paramTypeId;
|
m_paramTypeId = paramTypeId;
|
||||||
|
|||||||
@ -32,21 +32,21 @@
|
|||||||
#define PARAM_H
|
#define PARAM_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QUuid>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
class Param : public QObject
|
class Param : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
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)
|
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Param(const QString ¶mTypeId = QString(), const QVariant &value = QVariant(), QObject *parent = nullptr);
|
Param(const QUuid ¶mTypeId = QString(), const QVariant &value = QVariant(), QObject *parent = nullptr);
|
||||||
Param(QObject *parent);
|
Param(QObject *parent);
|
||||||
|
|
||||||
QString paramTypeId() const;
|
QUuid paramTypeId() const;
|
||||||
void setParamTypeId(const QString ¶mTypeId);
|
void setParamTypeId(const QUuid ¶mTypeId);
|
||||||
|
|
||||||
QVariant value() const;
|
QVariant value() const;
|
||||||
void setValue(const QVariant &value);
|
void setValue(const QVariant &value);
|
||||||
@ -56,7 +56,7 @@ signals:
|
|||||||
void valueChanged();
|
void valueChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_paramTypeId;
|
QUuid m_paramTypeId;
|
||||||
QVariant m_value;
|
QVariant m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -48,10 +48,10 @@ ParamType *ParamTypes::get(int index) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParamType *ParamTypes::getParamType(const QString &id) const
|
ParamType *ParamTypes::getParamType(const QUuid &id) const
|
||||||
{
|
{
|
||||||
foreach (ParamType *paramType, m_paramTypes) {
|
foreach (ParamType *paramType, m_paramTypes) {
|
||||||
if (paramType->id() == QUuid(id)) {
|
if (paramType->id() == id) {
|
||||||
return paramType;
|
return paramType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public:
|
|||||||
QList<ParamType *> paramTypes();
|
QList<ParamType *> paramTypes();
|
||||||
|
|
||||||
Q_INVOKABLE ParamType *get(int index) const;
|
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;
|
Q_INVOKABLE ParamType *findByName(const QString &name) const;
|
||||||
|
|
||||||
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
|||||||
@ -74,9 +74,10 @@ void RuleActionParams::addRuleActionParam(RuleActionParam *ruleActionParam)
|
|||||||
beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
|
beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
|
||||||
m_list.append(ruleActionParam);
|
m_list.append(ruleActionParam);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleActionParams::setRuleActionParam(const QString ¶mTypeId, const QVariant &value)
|
void RuleActionParams::setRuleActionParam(const QUuid ¶mTypeId, const QVariant &value)
|
||||||
{
|
{
|
||||||
foreach (RuleActionParam *rap, m_list) {
|
foreach (RuleActionParam *rap, m_list) {
|
||||||
if (rap->paramTypeId() == paramTypeId) {
|
if (rap->paramTypeId() == paramTypeId) {
|
||||||
@ -174,6 +175,9 @@ void RuleActionParams::setRuleActionParamStateByName(const QString ¶mName, c
|
|||||||
|
|
||||||
RuleActionParam *RuleActionParams::get(int index) const
|
RuleActionParam *RuleActionParams::get(int index) const
|
||||||
{
|
{
|
||||||
|
if (index < 0 || index >= m_list.count()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
return m_list.at(index);
|
return m_list.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +191,15 @@ bool RuleActionParams::hasRuleActionParam(const QString ¶mTypeId) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RuleActionParams::clear()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
qDeleteAll(m_list);
|
||||||
|
m_list.clear();
|
||||||
|
endResetModel();
|
||||||
|
emit countChanged();
|
||||||
|
}
|
||||||
|
|
||||||
bool RuleActionParams::operator==(RuleActionParams *other) const
|
bool RuleActionParams::operator==(RuleActionParams *other) const
|
||||||
{
|
{
|
||||||
if (rowCount() != other->rowCount()) {
|
if (rowCount() != other->rowCount()) {
|
||||||
|
|||||||
@ -56,7 +56,7 @@ public:
|
|||||||
|
|
||||||
void addRuleActionParam(RuleActionParam* ruleActionParam);
|
void addRuleActionParam(RuleActionParam* ruleActionParam);
|
||||||
|
|
||||||
Q_INVOKABLE void setRuleActionParam(const QString ¶mTypeId, const QVariant &value);
|
Q_INVOKABLE void setRuleActionParam(const QUuid ¶mTypeId, const QVariant &value);
|
||||||
Q_INVOKABLE void setRuleActionParamByName(const QString ¶mName, const QVariant &value);
|
Q_INVOKABLE void setRuleActionParamByName(const QString ¶mName, const QVariant &value);
|
||||||
Q_INVOKABLE void setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId);
|
Q_INVOKABLE void setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId);
|
||||||
Q_INVOKABLE void setRuleActionParamEventByName(const QString ¶mName, const QString &eventTypeId, const QString &eventParamTypeId);
|
Q_INVOKABLE void setRuleActionParamEventByName(const QString ¶mName, const QString &eventTypeId, const QString &eventParamTypeId);
|
||||||
@ -67,6 +67,8 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE bool hasRuleActionParam(const QString ¶mTypeId) const;
|
Q_INVOKABLE bool hasRuleActionParam(const QString ¶mTypeId) const;
|
||||||
|
|
||||||
|
Q_INVOKABLE void clear();
|
||||||
|
|
||||||
bool operator==(RuleActionParams *other) const;
|
bool operator==(RuleActionParams *other) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@ -67,7 +67,7 @@ ItemDelegate {
|
|||||||
Layout.fillWidth: true// sourceComponent === textFieldComponent || sourceComponent === stringComponent
|
Layout.fillWidth: true// sourceComponent === textFieldComponent || sourceComponent === stringComponent
|
||||||
sourceComponent: {
|
sourceComponent: {
|
||||||
print("Loading ParamDelegate");
|
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) {
|
if (!root.writable) {
|
||||||
return stringComponent;
|
return stringComponent;
|
||||||
}
|
}
|
||||||
@ -77,6 +77,9 @@ ItemDelegate {
|
|||||||
return boolComponent;
|
return boolComponent;
|
||||||
case "uint":
|
case "uint":
|
||||||
case "int":
|
case "int":
|
||||||
|
if (root.paramType.name == "colorTemperature") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
case "double":
|
case "double":
|
||||||
if (root.paramType.allowedValues.length > 0) {
|
if (root.paramType.allowedValues.length > 0) {
|
||||||
return comboBoxComponent;
|
return comboBoxComponent;
|
||||||
@ -103,13 +106,11 @@ ItemDelegate {
|
|||||||
Loader {
|
Loader {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
sourceComponent: {
|
sourceComponent: {
|
||||||
|
if (root.paramType.name == "colorTemperature") {
|
||||||
|
return colorTemperaturePickerComponent;
|
||||||
|
}
|
||||||
|
|
||||||
switch (root.paramType.type.toLowerCase()) {
|
switch (root.paramType.type.toLowerCase()) {
|
||||||
// case "int":
|
|
||||||
// case "double":
|
|
||||||
// if (root.paramType.minValue !== undefined && root.paramType.maxValue !== undefined) {
|
|
||||||
// return sliderComponent
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
case "color":
|
case "color":
|
||||||
return colorPickerComponent
|
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 {
|
Component {
|
||||||
id: colorPreviewComponent
|
id: colorPreviewComponent
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|||||||
@ -220,7 +220,7 @@ DevicePageBase {
|
|||||||
touchDelegate: Rectangle {
|
touchDelegate: Rectangle {
|
||||||
height: pickerCt.height
|
height: pickerCt.height
|
||||||
width: 5
|
width: 5
|
||||||
color: app.foregroundColor
|
color: app.accentColor
|
||||||
}
|
}
|
||||||
|
|
||||||
property var lastSentTime: new Date()
|
property var lastSentTime: new Date()
|
||||||
|
|||||||
@ -72,6 +72,9 @@ NymeaListItemDelegate {
|
|||||||
case "bool":
|
case "bool":
|
||||||
text = ruleActionParam.value === true ? qsTr("True") : qsTr("False")
|
text = ruleActionParam.value === true ? qsTr("True") : qsTr("False")
|
||||||
break;
|
break;
|
||||||
|
case "color":
|
||||||
|
text = "<font color=\"" + ruleActionParam.value + "\">⬤</font>"
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
text = ruleActionParam.value
|
text = ruleActionParam.value
|
||||||
}
|
}
|
||||||
|
|||||||
@ -175,7 +175,10 @@ Page {
|
|||||||
} else {
|
} else {
|
||||||
var actionType = root.deviceClass.actionTypes.getActionType(model.actionTypeId);
|
var actionType = root.deviceClass.actionTypes.getActionType(model.actionTypeId);
|
||||||
console.log("ActionType", actionType.id, "selected. Has", actionType.paramTypes.count, "params");
|
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.browserItemId = "";
|
||||||
root.ruleAction.interfaceAction = "";
|
root.ruleAction.interfaceAction = "";
|
||||||
if (actionType.paramTypes.count > 0) {
|
if (actionType.paramTypes.count > 0) {
|
||||||
|
|||||||
@ -38,14 +38,14 @@ import Nymea 1.0
|
|||||||
Page {
|
Page {
|
||||||
id: root
|
id: root
|
||||||
// Needs to be set and have rule.ruleActions filled in with deviceId and actionTypeId or interfaceName and interfaceAction
|
// 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
|
// optionally a rule which will be used to propose events params as param values
|
||||||
property var rule: null
|
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 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
|
: iface ? iface.actionTypes.findByName(ruleAction.interfaceAction) : null
|
||||||
|
|
||||||
signal backPressed();
|
signal backPressed();
|
||||||
@ -125,6 +125,7 @@ Page {
|
|||||||
paramType: root.actionType.paramTypes.get(index)
|
paramType: root.actionType.paramTypes.get(index)
|
||||||
enabled: staticParamRadioButton.checked
|
enabled: staticParamRadioButton.checked
|
||||||
nameVisible: false
|
nameVisible: false
|
||||||
|
value: root.ruleAction.ruleActionParams.get(index).value
|
||||||
visible: staticParamRadioButton.checked
|
visible: staticParamRadioButton.checked
|
||||||
placeholderText: qsTr("Insert value here")
|
placeholderText: qsTr("Insert value here")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,7 @@ SwipeDelegate {
|
|||||||
ColorIcon {
|
ColorIcon {
|
||||||
Layout.preferredHeight: childEvaluatorsRepeater.count > 0 ? app.iconSize * .6 : app.iconSize
|
Layout.preferredHeight: childEvaluatorsRepeater.count > 0 ? app.iconSize * .6 : app.iconSize
|
||||||
Layout.preferredWidth: height
|
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
|
color: app.accentColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user