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

13
src/FactSystem/FactMetaData.h

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

Loading…
Cancel
Save