Browse Source

MissionCommandUIInfo: Add min() and max() fields

QGC4.4
Nick Exton 1 year ago committed by Don Gagne
parent
commit
498772ae0a
  1. 23
      src/MissionManager/MissionCommandUIInfo.cc
  2. 8
      src/MissionManager/MissionCommandUIInfo.h

23
src/MissionManager/MissionCommandUIInfo.cc

@ -24,6 +24,8 @@ const char* MissionCommandUIInfo::_friendlyNameJsonKey = "friendlyName" @@ -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"; @@ -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 @@ -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 @@ -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 @@ -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 @@ -418,6 +434,7 @@ bool MissionCommandUIInfo::loadJsonInfo(const QJsonObject& jsonObject, bool requ
} else {
paramInfo->_defaultValue = paramInfo->_nanUnchanged ? std::numeric_limits<double>::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 @@ -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;
}

8
src/MissionManager/MissionCommandUIInfo.h

@ -55,6 +55,8 @@ public: @@ -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: @@ -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: @@ -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: @@ -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;

Loading…
Cancel
Save