diff --git a/src/MissionManager/MissionCommandUIInfo.cc b/src/MissionManager/MissionCommandUIInfo.cc index 391b822..3f1083b 100644 --- a/src/MissionManager/MissionCommandUIInfo.cc +++ b/src/MissionManager/MissionCommandUIInfo.cc @@ -24,6 +24,8 @@ const char* MissionCommandUIInfo::_friendlyNameJsonKey = "friendlyName" const char* MissionCommandUIInfo::_idJsonKey = "id"; const char* MissionCommandUIInfo::_labelJsonKey = "label"; const char* MissionCommandUIInfo::_mavCmdInfoJsonKey = "mavCmdInfo"; +const char* MissionCommandUIInfo::_maxJsonKey = "max"; +const char* MissionCommandUIInfo::_minJsonKey = "min"; const char* MissionCommandUIInfo::_param1JsonKey = "param1"; const char* MissionCommandUIInfo::_param2JsonKey = "param2"; const char* MissionCommandUIInfo::_param3JsonKey = "param3"; @@ -46,6 +48,8 @@ const char* MissionCommandUIInfo::_advancedCategory = "Advanced"; MissionCmdParamInfo::MissionCmdParamInfo(QObject* parent) : QObject(parent) + , _min (FactMetaData::minForType(FactMetaData::valueTypeDouble).toDouble()) + , _max (FactMetaData::maxForType(FactMetaData::valueTypeDouble).toDouble()) { } @@ -66,6 +70,8 @@ const MissionCmdParamInfo& MissionCmdParamInfo::operator=(const MissionCmdParamI _param = other._param; _units = other._units; _nanUnchanged = other._nanUnchanged; + _min = other._min; + _max = other._max; return *this; } @@ -370,7 +376,9 @@ bool MissionCommandUIInfo::loadJsonInfo(const QJsonObject& jsonObject, bool requ QJsonObject paramObject = jsonObject.value(paramKey).toObject(); QStringList allParamKeys; - allParamKeys << _defaultJsonKey << _decimalPlacesJsonKey << _enumStringsJsonKey << _enumValuesJsonKey << _labelJsonKey << _unitsJsonKey << _nanUnchangedJsonKey; + allParamKeys << _defaultJsonKey << _decimalPlacesJsonKey << _enumStringsJsonKey << _enumValuesJsonKey + << _labelJsonKey << _unitsJsonKey << _nanUnchangedJsonKey + << _minJsonKey << _maxJsonKey; // Look for unknown keys in param object for (const QString& key: paramObject.keys()) { @@ -405,6 +413,14 @@ bool MissionCommandUIInfo::loadJsonInfo(const QJsonObject& jsonObject, bool requ paramInfo->_nanUnchanged = paramObject.value(_nanUnchangedJsonKey).toBool(false); paramInfo->_enumStrings = paramObject.value(_enumStringsJsonKey).toString().split(",", Qt::SkipEmptyParts); + // The min and max values are defaulted correctly already, so only set them if a value is present in the JSON. + if (paramObject.value(_minJsonKey).isDouble()) { + paramInfo->_min = paramObject.value(_minJsonKey).toDouble(); + } + if (paramObject.value(_maxJsonKey).isDouble()) { + paramInfo->_max = paramObject.value(_maxJsonKey).toDouble(); + } + if (paramObject.contains(_defaultJsonKey)) { if (paramInfo->_nanUnchanged) { paramInfo->_defaultValue = JsonHelper::possibleNaNJsonValue(paramObject[_defaultJsonKey]); @@ -418,6 +434,7 @@ bool MissionCommandUIInfo::loadJsonInfo(const QJsonObject& jsonObject, bool requ } else { paramInfo->_defaultValue = paramInfo->_nanUnchanged ? std::numeric_limits::quiet_NaN() : 0; } + QStringList enumValues = paramObject.value(_enumValuesJsonKey).toString().split(",", Qt::SkipEmptyParts); for (const QString &enumValue: enumValues) { bool convertOk; @@ -445,7 +462,9 @@ bool MissionCommandUIInfo::loadJsonInfo(const QJsonObject& jsonObject, bool requ << paramInfo->_units << paramInfo->_enumStrings << paramInfo->_enumValues - << paramInfo->_nanUnchanged; + << paramInfo->_nanUnchanged + << paramInfo->_min + << paramInfo->_max; _paramInfoMap[i] = paramInfo; } diff --git a/src/MissionManager/MissionCommandUIInfo.h b/src/MissionManager/MissionCommandUIInfo.h index ac052e0..0a09d2f 100644 --- a/src/MissionManager/MissionCommandUIInfo.h +++ b/src/MissionManager/MissionCommandUIInfo.h @@ -55,6 +55,8 @@ public: Q_PROPERTY(int param READ param CONSTANT) Q_PROPERTY(QString units READ units CONSTANT) Q_PROPERTY(bool nanUnchanged READ nanUnchanged CONSTANT) + Q_PROPERTY(double min READ min CONSTANT) + Q_PROPERTY(double max READ max CONSTANT) int decimalPlaces (void) const { return _decimalPlaces; } double defaultValue (void) const { return _defaultValue; } @@ -64,6 +66,8 @@ public: int param (void) const { return _param; } QString units (void) const { return _units; } bool nanUnchanged (void) const { return _nanUnchanged; } + double min (void) const { return _min; } + double max (void) const { return _max; } private: int _decimalPlaces; @@ -74,6 +78,8 @@ private: int _param; QString _units; bool _nanUnchanged; + double _min; + double _max; friend class MissionCommandTree; friend class MissionCommandUIInfo; @@ -185,6 +191,8 @@ private: static const char* _idJsonKey; static const char* _labelJsonKey; static const char* _mavCmdInfoJsonKey; + static const char* _maxJsonKey; + static const char* _minJsonKey; static const char* _param1JsonKey; static const char* _param2JsonKey; static const char* _param3JsonKey;