Browse Source

FactMetadata: Make minForType() and minForType() public static

And make minIsDefaultForType() and maxIsDefaultForType() dynamic rather
than using a flag.
QGC4.4
Nick Exton 1 year ago committed by Don Gagne
parent
commit
76784fd38d
  1. 22
      src/FactSystem/FactMetaData.cc
  2. 13
      src/FactSystem/FactMetaData.h

22
src/FactSystem/FactMetaData.cc

@ -153,9 +153,7 @@ FactMetaData::FactMetaData(QObject* parent)
, _rawDefaultValue (0) , _rawDefaultValue (0)
, _defaultValueAvailable(false) , _defaultValueAvailable(false)
, _rawMax (_maxForType()) , _rawMax (_maxForType())
, _maxIsDefaultForType (true)
, _rawMin (_minForType()) , _rawMin (_minForType())
, _minIsDefaultForType (true)
, _rawTranslator (_defaultTranslator) , _rawTranslator (_defaultTranslator)
, _cookedTranslator (_defaultTranslator) , _cookedTranslator (_defaultTranslator)
, _vehicleRebootRequired(false) , _vehicleRebootRequired(false)
@ -177,9 +175,7 @@ FactMetaData::FactMetaData(ValueType_t type, QObject* parent)
, _rawDefaultValue (0) , _rawDefaultValue (0)
, _defaultValueAvailable(false) , _defaultValueAvailable(false)
, _rawMax (_maxForType()) , _rawMax (_maxForType())
, _maxIsDefaultForType (true)
, _rawMin (_minForType()) , _rawMin (_minForType())
, _minIsDefaultForType (true)
, _rawTranslator (_defaultTranslator) , _rawTranslator (_defaultTranslator)
, _cookedTranslator (_defaultTranslator) , _cookedTranslator (_defaultTranslator)
, _vehicleRebootRequired(false) , _vehicleRebootRequired(false)
@ -207,9 +203,7 @@ FactMetaData::FactMetaData(ValueType_t type, const QString name, QObject* parent
, _rawDefaultValue (0) , _rawDefaultValue (0)
, _defaultValueAvailable(false) , _defaultValueAvailable(false)
, _rawMax (_maxForType()) , _rawMax (_maxForType())
, _maxIsDefaultForType (true)
, _rawMin (_minForType()) , _rawMin (_minForType())
, _minIsDefaultForType (true)
, _name (name) , _name (name)
, _rawTranslator (_defaultTranslator) , _rawTranslator (_defaultTranslator)
, _cookedTranslator (_defaultTranslator) , _cookedTranslator (_defaultTranslator)
@ -238,9 +232,7 @@ const FactMetaData& FactMetaData::operator=(const FactMetaData& other)
_group = other._group; _group = other._group;
_longDescription = other._longDescription; _longDescription = other._longDescription;
_rawMax = other._rawMax; _rawMax = other._rawMax;
_maxIsDefaultForType = other._maxIsDefaultForType;
_rawMin = other._rawMin; _rawMin = other._rawMin;
_minIsDefaultForType = other._minIsDefaultForType;
_name = other._name; _name = other._name;
_shortDescription = other._shortDescription; _shortDescription = other._shortDescription;
_type = other._type; _type = other._type;
@ -292,7 +284,6 @@ void FactMetaData::setRawMin(const QVariant& rawMin)
{ {
if (isInRawMinLimit(rawMin)) { if (isInRawMinLimit(rawMin)) {
_rawMin = rawMin; _rawMin = rawMin;
_minIsDefaultForType = false;
} else { } else {
qWarning() << "Attempt to set min below allowable value for fact: " << name() qWarning() << "Attempt to set min below allowable value for fact: " << name()
<< ", value attempted: " << rawMin << ", value attempted: " << rawMin
@ -305,9 +296,10 @@ void FactMetaData::setRawMax(const QVariant& rawMax)
{ {
if (isInRawMaxLimit(rawMax)) { if (isInRawMaxLimit(rawMax)) {
_rawMax = rawMax; _rawMax = rawMax;
_maxIsDefaultForType = false;
} else { } else {
qWarning() << "Attempt to set max above allowable value"; qWarning() << "Attempt to set max above allowable value for fact: " << name()
<< ", value attempted: " << rawMax
<< ", type: " << type() << ", max for type: " << _maxForType();
_rawMax = _maxForType(); _rawMax = _maxForType();
} }
} }
@ -372,9 +364,9 @@ bool FactMetaData::isInRawMaxLimit(const QVariant& variantValue) const
return true; return true;
} }
QVariant FactMetaData::_minForType(void) const QVariant FactMetaData::minForType(ValueType_t type)
{ {
switch (_type) { switch (type) {
case valueTypeUint8: case valueTypeUint8:
return QVariant(std::numeric_limits<unsigned char>::min()); return QVariant(std::numeric_limits<unsigned char>::min());
case valueTypeInt8: case valueTypeInt8:
@ -409,9 +401,9 @@ QVariant FactMetaData::_minForType(void) const
return QVariant(); return QVariant();
} }
QVariant FactMetaData::_maxForType(void) const QVariant FactMetaData::maxForType(ValueType_t type)
{ {
switch (_type) { switch (type) {
case valueTypeUint8: case valueTypeUint8:
return QVariant(std::numeric_limits<unsigned char>::max()); return QVariant(std::numeric_limits<unsigned char>::max());
case valueTypeInt8: case valueTypeInt8:

13
src/FactSystem/FactMetaData.h

@ -124,10 +124,10 @@ public:
QString longDescription (void) const { return _longDescription;} QString longDescription (void) const { return _longDescription;}
QVariant rawMax (void) const { return _rawMax; } QVariant rawMax (void) const { return _rawMax; }
QVariant cookedMax (void) const; QVariant cookedMax (void) const;
bool maxIsDefaultForType (void) const { return _maxIsDefaultForType; } bool maxIsDefaultForType (void) const { return _rawMax == _maxForType(); }
QVariant rawMin (void) const { return _rawMin; } QVariant rawMin (void) const { return _rawMin; }
QVariant cookedMin (void) const; QVariant cookedMin (void) const;
bool minIsDefaultForType (void) const { return _minIsDefaultForType; } bool minIsDefaultForType (void) const { return _rawMin == _minForType(); }
QString name (void) const { return _name; } QString name (void) const { return _name; }
QString shortDescription (void) const { return _shortDescription; } QString shortDescription (void) const { return _shortDescription; }
ValueType_t type (void) const { return _type; } ValueType_t type (void) const { return _type; }
@ -212,11 +212,14 @@ public:
static QString typeToString(ValueType_t type); static QString typeToString(ValueType_t type);
static size_t typeToSize(ValueType_t type); static size_t typeToSize(ValueType_t type);
static QVariant minForType(ValueType_t type);
static QVariant maxForType(ValueType_t type);
static const char* qgcFileType; static const char* qgcFileType;
private: private:
QVariant _minForType (void) const; QVariant _minForType (void) const { return minForType(_type); };
QVariant _maxForType (void) const; QVariant _maxForType (void) const { return maxForType(_type); };
void _setAppSettingsTranslators (void); void _setAppSettingsTranslators (void);
/// Clamp a value to be within cookedMin and cookedMax /// Clamp a value to be within cookedMin and cookedMax
@ -320,9 +323,7 @@ private:
QString _group; QString _group;
QString _longDescription; QString _longDescription;
QVariant _rawMax; QVariant _rawMax;
bool _maxIsDefaultForType;
QVariant _rawMin; QVariant _rawMin;
bool _minIsDefaultForType;
QString _name; QString _name;
QString _shortDescription; QString _shortDescription;
QString _rawUnits; QString _rawUnits;

Loading…
Cancel
Save