diff --git a/libnymea-core/jsonrpc/jsontypes.cpp b/libnymea-core/jsonrpc/jsontypes.cpp index 8e1727ac..ae91456c 100644 --- a/libnymea-core/jsonrpc/jsontypes.cpp +++ b/libnymea-core/jsonrpc/jsontypes.cpp @@ -188,7 +188,7 @@ void JsonTypes::init() s_ruleActionParam.insert("o:value", basicTypeRef()); s_ruleActionParam.insert("o:eventTypeId", basicTypeToString(Uuid)); s_ruleActionParam.insert("o:eventParamTypeId", basicTypeToString(Uuid)); - s_ruleActionParam.insert("o:deviceId", basicTypeToString(Uuid)); + s_ruleActionParam.insert("o:stateDeviceId", basicTypeToString(Uuid)); s_ruleActionParam.insert("o:stateTypeId", basicTypeToString(Uuid)); // ParamDescriptor @@ -619,7 +619,7 @@ QVariantMap JsonTypes::packRuleActionParam(const RuleActionParam &ruleActionPara variantMap.insert("eventTypeId", ruleActionParam.eventTypeId().toString()); variantMap.insert("eventParamTypeId", ruleActionParam.eventParamTypeId().toString()); } else if (ruleActionParam.isStateBased()) { - variantMap.insert("deviceId", ruleActionParam.deviceId().toString()); + variantMap.insert("stateDeviceId", ruleActionParam.stateDeviceId().toString()); variantMap.insert("stateTypeId", ruleActionParam.stateTypeId().toString()); } else { variantMap.insert("value", ruleActionParam.value()); @@ -1444,7 +1444,7 @@ RuleActionParam JsonTypes::unpackRuleActionParam(const QVariantMap &ruleActionPa param.setValue(ruleActionParamMap.value("value")); param.setEventTypeId(EventTypeId(ruleActionParamMap.value("eventTypeId").toString())); param.setEventParamTypeId(ParamTypeId(ruleActionParamMap.value("eventParamTypeId").toString())); - param.setDeviceId(DeviceId(ruleActionParamMap.value("deviceId").toString())); + param.setStateDeviceId(DeviceId(ruleActionParamMap.value("stateDeviceId").toString())); param.setStateTypeId(StateTypeId(ruleActionParamMap.value("stateTypeId").toString())); return param; } @@ -1466,7 +1466,7 @@ ParamDescriptor JsonTypes::unpackParamDescriptor(const QVariantMap ¶mMap) QMetaObject metaObject = Types::staticMetaObject; int enumIndex = metaObject.indexOfEnumerator("ValueOperator"); QMetaEnum metaEnum = metaObject.enumerator(enumIndex); - Types::ValueOperator valueOperator = (Types::ValueOperator)metaEnum.keyToValue(operatorString.toLatin1().data()); + Types::ValueOperator valueOperator = static_cast(metaEnum.keyToValue(operatorString.toLatin1().data())); if (paramMap.contains("paramTypeId")) { ParamDescriptor param = ParamDescriptor(ParamTypeId(paramMap.value("paramTypeId").toString()), paramMap.value("value")); @@ -1507,7 +1507,7 @@ StateEvaluator JsonTypes::unpackStateEvaluator(const QVariantMap &stateEvaluator { StateEvaluator ret(unpackStateDescriptor(stateEvaluatorMap.value("stateDescriptor").toMap())); if (stateEvaluatorMap.contains("operator")) { - ret.setOperatorType((Types::StateOperator)s_stateOperator.indexOf(stateEvaluatorMap.value("operator").toString())); + ret.setOperatorType(static_cast(s_stateOperator.indexOf(stateEvaluatorMap.value("operator").toString()))); } else { ret.setOperatorType(Types::StateOperatorAnd); } @@ -1528,7 +1528,7 @@ StateDescriptor JsonTypes::unpackStateDescriptor(const QVariantMap &stateDescrip QString interface(stateDescriptorMap.value("interface").toString()); QString interfaceState(stateDescriptorMap.value("interfaceState").toString()); QVariant value = stateDescriptorMap.value("value"); - Types::ValueOperator operatorType = (Types::ValueOperator)s_valueOperator.indexOf(stateDescriptorMap.value("operator").toString()); + Types::ValueOperator operatorType = static_cast(s_valueOperator.indexOf(stateDescriptorMap.value("operator").toString())); if (!deviceId.isNull() && !stateTypeId.isNull()) { StateDescriptor stateDescriptor(stateTypeId, deviceId, value, operatorType); return stateDescriptor; @@ -1547,10 +1547,10 @@ LogFilter JsonTypes::unpackLogFilter(const QVariantMap &logFilterMap) QVariantMap timeFilterMap = timeFilter.toMap(); QDateTime startDate; QDateTime endDate; if (timeFilterMap.contains("startDate")) - startDate = QDateTime::fromTime_t(timeFilterMap.value("startDate").toInt()); + startDate = QDateTime::fromTime_t(timeFilterMap.value("startDate").toUInt()); if (timeFilterMap.contains("endDate")) - endDate = QDateTime::fromTime_t(timeFilterMap.value("endDate").toInt()); + endDate = QDateTime::fromTime_t(timeFilterMap.value("endDate").toUInt()); filter.addTimeFilter(startDate, endDate); } @@ -1559,19 +1559,19 @@ LogFilter JsonTypes::unpackLogFilter(const QVariantMap &logFilterMap) if (logFilterMap.contains("loggingSources")) { QVariantList loggingSources = logFilterMap.value("loggingSources").toList(); foreach (const QVariant &source, loggingSources) { - filter.addLoggingSource((Logging::LoggingSource)s_loggingSource.indexOf(source.toString())); + filter.addLoggingSource(static_cast(s_loggingSource.indexOf(source.toString()))); } } if (logFilterMap.contains("loggingLevels")) { QVariantList loggingLevels = logFilterMap.value("loggingLevels").toList(); foreach (const QVariant &level, loggingLevels) { - filter.addLoggingLevel((Logging::LoggingLevel)s_loggingLevel.indexOf(level.toString())); + filter.addLoggingLevel(static_cast(s_loggingLevel.indexOf(level.toString()))); } } if (logFilterMap.contains("eventTypes")) { QVariantList eventTypes = logFilterMap.value("eventTypes").toList(); foreach (const QVariant &eventType, eventTypes) { - filter.addLoggingEventType((Logging::LoggingEventType)s_loggingEventType.indexOf(eventType.toString())); + filter.addLoggingEventType(static_cast(s_loggingEventType.indexOf(eventType.toString()))); } } if (logFilterMap.contains("typeIds")) { @@ -1605,7 +1605,7 @@ LogFilter JsonTypes::unpackLogFilter(const QVariantMap &logFilterMap) /*! Returns a \l{RepeatingOption} created from the given \a repeatingOptionMap. */ RepeatingOption JsonTypes::unpackRepeatingOption(const QVariantMap &repeatingOptionMap) { - RepeatingOption::RepeatingMode mode = (RepeatingOption::RepeatingMode)s_repeatingMode.indexOf(repeatingOptionMap.value("mode").toString()); + RepeatingOption::RepeatingMode mode = static_cast(s_repeatingMode.indexOf(repeatingOptionMap.value("mode").toString())); QList weekDays; if (repeatingOptionMap.contains("weekDays")) { diff --git a/libnymea-core/nymeacore.cpp b/libnymea-core/nymeacore.cpp index e2b402b7..377382d9 100644 --- a/libnymea-core/nymeacore.cpp +++ b/libnymea-core/nymeacore.cpp @@ -446,9 +446,9 @@ void NymeaCore::executeRuleActions(const QList ruleActions) if (ruleActionParam.isValueBased()) { params.append(Param(ruleActionParam.paramTypeId(), ruleActionParam.value())); } else if (ruleActionParam.isStateBased()) { - Device *stateDevice = m_deviceManager->findConfiguredDevice(ruleActionParam.deviceId()); + Device *stateDevice = m_deviceManager->findConfiguredDevice(ruleActionParam.stateDeviceId()); if (!stateDevice) { - qCWarning(dcRuleEngine()) << "Cannot find device" << ruleActionParam.deviceId() << "required by rule action" << ruleAction.id(); + qCWarning(dcRuleEngine()) << "Cannot find device" << ruleActionParam.stateDeviceId() << "required by rule action" << ruleAction.id(); ok = false; break; } @@ -490,9 +490,9 @@ void NymeaCore::executeRuleActions(const QList ruleActions) if (ruleActionParam.isValueBased()) { params.append(Param(paramType.id(), ruleActionParam.value())); } else if (ruleActionParam.isStateBased()) { - Device *stateDevice = m_deviceManager->findConfiguredDevice(ruleActionParam.deviceId()); + Device *stateDevice = m_deviceManager->findConfiguredDevice(ruleActionParam.stateDeviceId()); if (!stateDevice) { - qCWarning(dcRuleEngine()) << "Cannot find device" << ruleActionParam.deviceId() << "required by rule action" << ruleAction.id(); + qCWarning(dcRuleEngine()) << "Cannot find device" << ruleActionParam.stateDeviceId() << "required by rule action" << ruleAction.id(); ok = false; break; } diff --git a/libnymea-core/ruleengine.cpp b/libnymea-core/ruleengine.cpp index dc9b870c..524fca02 100644 --- a/libnymea-core/ruleengine.cpp +++ b/libnymea-core/ruleengine.cpp @@ -414,11 +414,11 @@ RuleEngine::RuleError RuleEngine::addRule(const Rule &rule, bool fromEdit) } foreach (const ParamType &ifaceActionParamType, ifaceActionType.paramTypes()) { if (!action.ruleActionParams().hasParam(ifaceActionParamType.name())) { - qCWarning(dcRuleEngine()) << "Cannot create rule. Interface action" << iface.name() << ":" << action.interfaceAction() << "requires a" << ifaceActionParamType.name() << "param of type" << QVariant::typeToName(ifaceActionParamType.type()); + qCWarning(dcRuleEngine()) << "Cannot create rule. Interface action" << iface.name() << ":" << action.interfaceAction() << "requires a" << ifaceActionParamType.name() << "param of type" << QVariant::typeToName(static_cast(ifaceActionParamType.type())); return RuleError::RuleErrorMissingParameter; } - if (!action.ruleActionParam(ifaceActionParamType.name()).value().canConvert(ifaceActionParamType.type())) { - qCWarning(dcRuleEngine()) << "Cannot create rule. Interface action parameter" << iface.name() << ":" << action.interfaceAction() << ":" << ifaceActionParamType.name() << "has wrong type. Expected" << QVariant::typeToName(ifaceActionParamType.type()); + if (!action.ruleActionParam(ifaceActionParamType.name()).value().canConvert(static_cast(ifaceActionParamType.type()))) { + qCWarning(dcRuleEngine()) << "Cannot create rule. Interface action parameter" << iface.name() << ":" << action.interfaceAction() << ":" << ifaceActionParamType.name() << "has wrong type. Expected" << QVariant::typeToName(static_cast(ifaceActionParamType.type())); return RuleError::RuleErrorInvalidParameter; } } @@ -443,7 +443,7 @@ RuleEngine::RuleError RuleEngine::addRule(const Rule &rule, bool fromEdit) return RuleErrorTypesNotMatching; } } else if (ruleActionParam.isStateBased()) { - Device *d = NymeaCore::instance()->deviceManager()->findConfiguredDevice(ruleActionParam.deviceId()); + Device *d = NymeaCore::instance()->deviceManager()->findConfiguredDevice(ruleActionParam.stateDeviceId()); if (!d) { qCWarning(dcRuleEngine()) << "Cannot create Rule. DeviceId from RuleAction" << action.actionTypeId() << "not found in system."; return RuleErrorDeviceNotFound; @@ -512,11 +512,11 @@ RuleEngine::RuleError RuleEngine::addRule(const Rule &rule, bool fromEdit) } foreach (const ParamType &ifaceActionParamType, ifaceActionType.paramTypes()) { if (!ruleExitAction.ruleActionParams().hasParam(ifaceActionParamType.name())) { - qCWarning(dcRuleEngine()) << "Cannot create rule. Interface action" << iface.name() << ":" << ruleExitAction.interfaceAction() << "requires a" << ifaceActionParamType.name() << "param of type" << QVariant::typeToName(ifaceActionParamType.type()); + qCWarning(dcRuleEngine()) << "Cannot create rule. Interface action" << iface.name() << ":" << ruleExitAction.interfaceAction() << "requires a" << ifaceActionParamType.name() << "param of type" << QVariant::typeToName(static_cast(ifaceActionParamType.type())); return RuleError::RuleErrorMissingParameter; } - if (!ruleExitAction.ruleActionParam(ifaceActionParamType.name()).value().canConvert(ifaceActionParamType.type())) { - qCWarning(dcRuleEngine()) << "Cannot create rule. Interface action parameter" << iface.name() << ":" << ruleExitAction.interfaceAction() << ":" << ifaceActionParamType.name() << "has wrong type. Expected" << QVariant::typeToName(ifaceActionParamType.type()); + if (!ruleExitAction.ruleActionParam(ifaceActionParamType.name()).value().canConvert(static_cast(ifaceActionParamType.type()))) { + qCWarning(dcRuleEngine()) << "Cannot create rule. Interface action parameter" << iface.name() << ":" << ruleExitAction.interfaceAction() << ":" << ifaceActionParamType.name() << "has wrong type. Expected" << QVariant::typeToName(static_cast(ifaceActionParamType.type())); return RuleError::RuleErrorInvalidParameter; } } @@ -528,7 +528,7 @@ RuleEngine::RuleError RuleEngine::addRule(const Rule &rule, bool fromEdit) qCWarning(dcRuleEngine) << "Cannot create rule. Exit actions cannot be event based."; return RuleErrorInvalidRuleActionParameter; } else if (ruleActionParam.isStateBased()) { - Device *d = NymeaCore::instance()->deviceManager()->findConfiguredDevice(ruleActionParam.deviceId()); + Device *d = NymeaCore::instance()->deviceManager()->findConfiguredDevice(ruleActionParam.stateDeviceId()); if (!d) { qCWarning(dcRuleEngine()) << "Cannot create Rule. DeviceId from RuleAction" << ruleExitAction.actionTypeId() << "not found in system."; return RuleErrorDeviceNotFound; @@ -1192,7 +1192,7 @@ void RuleEngine::saveRule(const Rule &rule) } else { settings.beginGroup("ParamDescriptor-" + paramDescriptor.paramName()); } - settings.setValue("valueType", (int)paramDescriptor.value().type()); + settings.setValue("valueType", static_cast(paramDescriptor.value().type())); settings.setValue("value", paramDescriptor.value()); settings.setValue("operator", paramDescriptor.operatorType()); settings.endGroup(); @@ -1228,7 +1228,7 @@ void RuleEngine::saveRule(const Rule &rule) settings.setValue("eventTypeId", param.eventTypeId().toString()); settings.setValue("eventParamTypeId", param.eventParamTypeId()); } else if (param.isStateBased()) { - settings.setValue("deviceId", param.deviceId().toString()); + settings.setValue("stateDeviceId", param.stateDeviceId().toString()); settings.setValue("stateTypeId", param.stateTypeId()); } settings.endGroup(); @@ -1256,7 +1256,7 @@ void RuleEngine::saveRule(const Rule &rule) } else { settings.beginGroup("RuleActionParam-" + param.paramName()); } - settings.setValue("valueType", (int)param.value().type()); + settings.setValue("valueType", static_cast(param.value().type())); settings.setValue("value", param.value()); settings.endGroup(); } @@ -1383,24 +1383,24 @@ void RuleEngine::init() QVariant value = settings.value("value"); if (settings.contains("valueType")) { - QVariant::Type valueType = (QVariant::Type)settings.value("valueType").toInt(); + QVariant::Type valueType = static_cast(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)) { + } else if (!value.canConvert(static_cast(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); + value.convert(static_cast(valueType)); } } if (!ParamTypeId(strippedGroupName).isNull()) { ParamDescriptor paramDescriptor(ParamTypeId(strippedGroupName), value); - paramDescriptor.setOperatorType((Types::ValueOperator)settings.value("operator").toInt()); + paramDescriptor.setOperatorType(static_cast(settings.value("operator").toInt())); params.append(paramDescriptor); } else { ParamDescriptor paramDescriptor(strippedGroupName, value); - paramDescriptor.setOperatorType((Types::ValueOperator)settings.value("operator").toInt()); + paramDescriptor.setOperatorType(static_cast(settings.value("operator").toInt())); params.append(paramDescriptor); } settings.endGroup(); @@ -1436,18 +1436,18 @@ void RuleEngine::init() QString strippedParamTypeIdString = paramTypeIdString.remove(QRegExp("^RuleActionParam-")); EventTypeId eventTypeId = EventTypeId(settings.value("eventTypeId", EventTypeId()).toString()); ParamTypeId eventParamTypeId = ParamTypeId(settings.value("eventParamTypeId", ParamTypeId()).toString()); - DeviceId deviceId = DeviceId(settings.value("deviceId", DeviceId()).toString()); + DeviceId stateDeviceId = DeviceId(settings.value("stateDeviceId", DeviceId()).toString()); StateTypeId stateTypeId = StateTypeId(settings.value("stateTypeId", StateTypeId()).toString()); QVariant value = settings.value("value"); if (settings.contains("valueType")) { - QVariant::Type valueType = (QVariant::Type)settings.value("valueType").toInt(); + QVariant::Type valueType = static_cast(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)) { + } else if (!value.canConvert(static_cast(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); + value.convert(static_cast(valueType)); } } @@ -1461,7 +1461,7 @@ void RuleEngine::init() } param.setEventTypeId(eventTypeId); param.setEventParamTypeId(eventParamTypeId); - param.setDeviceId(deviceId); + param.setStateDeviceId(stateDeviceId); param.setStateTypeId(stateTypeId); params.append(param); params.append(param); @@ -1496,14 +1496,14 @@ void RuleEngine::init() QString strippedParamTypeIdString = paramTypeIdString.remove(QRegExp("^RuleActionParam-")); QVariant value = settings.value("value"); if (settings.contains("valueType")) { - QVariant::Type valueType = (QVariant::Type)settings.value("valueType").toInt(); + QVariant::Type valueType = static_cast(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)) { + } else if (!value.canConvert(static_cast(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); + value.convert(static_cast(valueType)); } } diff --git a/libnymea/types/ruleactionparam.cpp b/libnymea/types/ruleactionparam.cpp index 91737fae..31c92b50 100644 --- a/libnymea/types/ruleactionparam.cpp +++ b/libnymea/types/ruleactionparam.cpp @@ -79,11 +79,11 @@ RuleActionParam::RuleActionParam(const ParamTypeId ¶mTypeId, const EventType } -/*! Constructs a \l{RuleActionParam} with the given \a paramTypeId, \a deviceId and \a stateTypeId. +/*! Constructs a \l{RuleActionParam} with the given \a paramTypeId, \a stateDeviceId and \a stateTypeId. * \sa Param, Event, */ -RuleActionParam::RuleActionParam(const ParamTypeId ¶mTypeId, const DeviceId &deviceId, const StateTypeId &stateTypeId): +RuleActionParam::RuleActionParam(const ParamTypeId ¶mTypeId, const DeviceId &stateDeviceId, const StateTypeId &stateTypeId): m_paramTypeId(paramTypeId), - m_deviceId(deviceId), + m_stateDeviceId(stateDeviceId), m_stateTypeId(stateTypeId) { @@ -108,11 +108,11 @@ RuleActionParam::RuleActionParam(const QString ¶mName, const EventTypeId &ev } -/*! Constructs a \l{RuleActionParam} with the given \a paramName, \a deviceId and \a stateTypeId. +/*! Constructs a \l{RuleActionParam} with the given \a paramName, \a stateDeviceId and \a stateTypeId. * \sa Param, Event, */ -RuleActionParam::RuleActionParam(const QString ¶mName, const DeviceId &deviceId, const StateTypeId &stateTypeId): +RuleActionParam::RuleActionParam(const QString ¶mName, const DeviceId &stateDeviceId, const StateTypeId &stateTypeId): m_paramName(paramName), - m_deviceId(deviceId), + m_stateDeviceId(stateDeviceId), m_stateTypeId(stateTypeId) { @@ -167,15 +167,15 @@ void RuleActionParam::setEventParamTypeId(const ParamTypeId &eventParamTypeId) } /*! Returns the deviceId identifying the device to use a state value from. */ -DeviceId RuleActionParam::deviceId() const +DeviceId RuleActionParam::stateDeviceId() const { - return m_deviceId; + return m_stateDeviceId; } /*! Sets the deviceId identifying the device to use a state value from. */ -void RuleActionParam::setDeviceId(const DeviceId &deviceId) +void RuleActionParam::setStateDeviceId(const DeviceId &stateDeviceId) { - m_deviceId = deviceId; + m_stateDeviceId = stateDeviceId; } /*! Returns the stateTypeId identifying the state to use the value. */ @@ -211,7 +211,7 @@ bool RuleActionParam::isEventBased() const bool RuleActionParam::isStateBased() const { - return !m_deviceId.isNull() && !m_stateTypeId.isNull(); + return !m_stateDeviceId.isNull() && !m_stateTypeId.isNull(); } /*! Writes the paramTypeId, value, eventId and eventParamTypeId of the given \a ruleActionParam to \a dbg. */ diff --git a/libnymea/types/ruleactionparam.h b/libnymea/types/ruleactionparam.h index efbfd71f..20257546 100644 --- a/libnymea/types/ruleactionparam.h +++ b/libnymea/types/ruleactionparam.h @@ -38,10 +38,10 @@ public: RuleActionParam(const Param ¶m = Param()); RuleActionParam(const ParamTypeId ¶mTypeId, const QVariant &value = QVariant()); RuleActionParam(const ParamTypeId ¶mTypeId, const EventTypeId &eventTypeId, const ParamTypeId &eventParamTypeId); - RuleActionParam(const ParamTypeId ¶mTypeId, const DeviceId &deviceId, const StateTypeId &stateTypeId); + RuleActionParam(const ParamTypeId ¶mTypeId, const DeviceId &stateDeviceId, const StateTypeId &stateTypeId); RuleActionParam(const QString ¶mName, const QVariant &value = QVariant()); RuleActionParam(const QString ¶mName, const EventTypeId &eventTypeId, const ParamTypeId &eventParamTypeId); - RuleActionParam(const QString ¶mName, const DeviceId &deviceId, const StateTypeId &stateTypeId); + RuleActionParam(const QString ¶mName, const DeviceId &stateDeviceId, const StateTypeId &stateTypeId); ParamTypeId paramTypeId() const; QString paramName() const; @@ -60,8 +60,8 @@ public: ParamTypeId eventParamTypeId() const; void setEventParamTypeId(const ParamTypeId &eventParamTypeId); - DeviceId deviceId() const; - void setDeviceId(const DeviceId &deviceId); + DeviceId stateDeviceId() const; + void setStateDeviceId(const DeviceId &deviceId); StateTypeId stateTypeId() const; void setStateTypeId(const StateTypeId &stateTypeId); @@ -74,7 +74,7 @@ private: EventTypeId m_eventTypeId; ParamTypeId m_eventParamTypeId; - DeviceId m_deviceId; + DeviceId m_stateDeviceId; StateTypeId m_stateTypeId; };