Store value type of rule values
This commit is contained in:
parent
b2f17b868e
commit
4fadd37938
@ -237,12 +237,26 @@ RuleEngine::RuleEngine(QObject *parent) :
|
||||
if (groupName.startsWith("ParamDescriptor-")) {
|
||||
settings.beginGroup(groupName);
|
||||
QString strippedGroupName = groupName.remove(QRegExp("^ParamDescriptor-"));
|
||||
|
||||
QVariant value = settings.value("value");
|
||||
if (settings.contains("valueType")) {
|
||||
QVariant::Type valueType = (QVariant::Type)settings.value("valueType").toInt();
|
||||
// Note: only warn, and continue with the QVariant guessed type
|
||||
if (valueType == QVariant::Invalid) {
|
||||
qCWarning(dcRuleEngine()) << name << idString << "Could not load the value type of the param descriptor" << strippedGroupName << ". The value type will be guessed by QVariant.";
|
||||
} else if (!value.canConvert(valueType)) {
|
||||
qCWarning(dcRuleEngine()) << "Error loading rule" << name << idString << ". Could not convert the param descriptor value" << value << "to the stored type" << valueType;
|
||||
} else {
|
||||
value.convert(valueType);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ParamTypeId(strippedGroupName).isNull()) {
|
||||
ParamDescriptor paramDescriptor(ParamTypeId(strippedGroupName), settings.value("value"));
|
||||
ParamDescriptor paramDescriptor(ParamTypeId(strippedGroupName), value);
|
||||
paramDescriptor.setOperatorType((Types::ValueOperator)settings.value("operator").toInt());
|
||||
params.append(paramDescriptor);
|
||||
} else {
|
||||
ParamDescriptor paramDescriptor(strippedGroupName, settings.value("value"));
|
||||
ParamDescriptor paramDescriptor(strippedGroupName, value);
|
||||
paramDescriptor.setOperatorType((Types::ValueOperator)settings.value("operator").toInt());
|
||||
params.append(paramDescriptor);
|
||||
}
|
||||
@ -280,6 +294,18 @@ RuleEngine::RuleEngine(QObject *parent) :
|
||||
EventTypeId eventTypeId = EventTypeId(settings.value("eventTypeId", EventTypeId()).toString());
|
||||
ParamTypeId eventParamTypeId = ParamTypeId(settings.value("eventParamTypeId", ParamTypeId()).toString());
|
||||
QVariant value = settings.value("value");
|
||||
if (settings.contains("valueType")) {
|
||||
QVariant::Type valueType = (QVariant::Type)settings.value("valueType").toInt();
|
||||
// Note: only warn, and continue with the QVariant guessed type
|
||||
if (valueType == QVariant::Invalid) {
|
||||
qCWarning(dcRuleEngine()) << name << idString << "Could not load the value type of the rule action param " << strippedParamTypeIdString << ". The value type will be guessed by QVariant.";
|
||||
} else if (!value.canConvert(valueType)) {
|
||||
qCWarning(dcRuleEngine()) << "Error loading rule" << name << idString << ". Could not convert the rule action param value" << value << "to the stored type" << valueType;
|
||||
} else {
|
||||
value.convert(valueType);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ParamTypeId(strippedParamTypeIdString).isNull()) {
|
||||
RuleActionParam param(ParamTypeId(strippedParamTypeIdString),
|
||||
value,
|
||||
@ -323,6 +349,18 @@ RuleEngine::RuleEngine(QObject *parent) :
|
||||
settings.beginGroup(paramTypeIdString);
|
||||
QString strippedParamTypeIdString = paramTypeIdString.remove(QRegExp("^RuleActionParam-"));
|
||||
QVariant value = settings.value("value");
|
||||
if (settings.contains("valueType")) {
|
||||
QVariant::Type valueType = (QVariant::Type)settings.value("valueType").toInt();
|
||||
// Note: only warn, and continue with the QVariant guessed type
|
||||
if (valueType == QVariant::Invalid) {
|
||||
qCWarning(dcRuleEngine()) << name << idString << "Could not load the value type of the rule action param " << strippedParamTypeIdString << ". The value type will be guessed by QVariant.";
|
||||
} else if (!value.canConvert(valueType)) {
|
||||
qCWarning(dcRuleEngine()) << "Error loading rule" << name << idString << ". Could not convert the rule action param value" << value << "to the stored type" << valueType;
|
||||
} else {
|
||||
value.convert(valueType);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ParamTypeId(strippedParamTypeIdString).isNull()) {
|
||||
RuleActionParam param(ParamTypeId(strippedParamTypeIdString), value);
|
||||
params.append(param);
|
||||
@ -1397,6 +1435,7 @@ void RuleEngine::saveRule(const Rule &rule)
|
||||
} else {
|
||||
settings.beginGroup("ParamDescriptor-" + paramDescriptor.paramName());
|
||||
}
|
||||
settings.setValue("valueType", (int)paramDescriptor.value().type());
|
||||
settings.setValue("value", paramDescriptor.value());
|
||||
settings.setValue("operator", paramDescriptor.operatorType());
|
||||
settings.endGroup();
|
||||
@ -1426,6 +1465,7 @@ void RuleEngine::saveRule(const Rule &rule)
|
||||
} else {
|
||||
settings.beginGroup("RuleActionParam-" + param.paramName());
|
||||
}
|
||||
settings.setValue("valueType", (int)param.value().type());
|
||||
settings.setValue("value", param.value());
|
||||
if (param.eventTypeId() != EventTypeId()) {
|
||||
settings.setValue("eventTypeId", param.eventTypeId().toString());
|
||||
@ -1456,6 +1496,7 @@ void RuleEngine::saveRule(const Rule &rule)
|
||||
} else {
|
||||
settings.beginGroup("RuleActionParam-" + param.paramName());
|
||||
}
|
||||
settings.setValue("valueType", (int)param.value().type());
|
||||
settings.setValue("value", param.value());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
@ -219,6 +219,7 @@ void StateEvaluator::dumpToSettings(NymeaSettings &settings, const QString &grou
|
||||
settings.setValue("interface", m_stateDescriptor.interface());
|
||||
settings.setValue("interfaceState", m_stateDescriptor.interfaceState());
|
||||
settings.setValue("value", m_stateDescriptor.stateValue());
|
||||
settings.setValue("valueType", (int)m_stateDescriptor.stateValue().type());
|
||||
settings.setValue("operator", m_stateDescriptor.operatorType());
|
||||
settings.endGroup();
|
||||
|
||||
@ -242,6 +243,18 @@ StateEvaluator StateEvaluator::loadFromSettings(NymeaSettings &settings, const Q
|
||||
StateTypeId stateTypeId(settings.value("stateTypeId").toString());
|
||||
DeviceId deviceId(settings.value("deviceId").toString());
|
||||
QVariant stateValue = settings.value("value");
|
||||
if (settings.contains("valueType")) {
|
||||
QVariant::Type valueType = (QVariant::Type)settings.value("valueType").toInt();
|
||||
// Note: only warn, and continue with the QVariant guessed type
|
||||
if (valueType == QVariant::Invalid) {
|
||||
qCWarning(dcRuleEngine()) << "Could not load the value type of the state evaluator. The value type will be guessed by QVariant" << stateValue;
|
||||
} else if (!stateValue.canConvert(valueType)) {
|
||||
qCWarning(dcRuleEngine()) << "Could not convert the state evaluator value" << stateValue << "to the stored type" << valueType << ". The value type will be guessed by QVariant.";
|
||||
} else {
|
||||
stateValue.convert(valueType);
|
||||
}
|
||||
}
|
||||
|
||||
QString interface = settings.value("interface").toString();
|
||||
QString interfaceState = settings.value("interfaceState").toString();
|
||||
Types::ValueOperator valueOperator = (Types::ValueOperator)settings.value("operator").toInt();
|
||||
|
||||
Reference in New Issue
Block a user