Commit 2baf67ae authored by DonLakeFlyer's avatar DonLakeFlyer

parent c133b717
......@@ -519,7 +519,7 @@ int Fact::decimalPlaces(void) const
return _metaData->decimalPlaces();
} else {
qWarning() << kMissingMetadata << name();
return FactMetaData::defaultDecimalPlaces;
return FactMetaData::kDefaultDecimalPlaces;
}
}
......
......@@ -88,7 +88,7 @@ const char* FactMetaData::_qgcRebootRequiredJsonKey = "qgcRebootRequired";
FactMetaData::FactMetaData(QObject* parent)
: QObject (parent)
, _type (valueTypeInt32)
, _decimalPlaces (unknownDecimalPlaces)
, _decimalPlaces (kUnknownDecimalPlaces)
, _rawDefaultValue (0)
, _defaultValueAvailable(false)
, _rawMax (_maxForType())
......@@ -112,7 +112,7 @@ FactMetaData::FactMetaData(QObject* parent)
FactMetaData::FactMetaData(ValueType_t type, QObject* parent)
: QObject (parent)
, _type (type)
, _decimalPlaces (unknownDecimalPlaces)
, _decimalPlaces (kUnknownDecimalPlaces)
, _rawDefaultValue (0)
, _defaultValueAvailable(false)
, _rawMax (_maxForType())
......@@ -142,7 +142,7 @@ FactMetaData::FactMetaData(const FactMetaData& other, QObject* parent)
FactMetaData::FactMetaData(ValueType_t type, const QString name, QObject* parent)
: QObject (parent)
, _type (type)
, _decimalPlaces (unknownDecimalPlaces)
, _decimalPlaces (kUnknownDecimalPlaces)
, _rawDefaultValue (0)
, _defaultValueAvailable(false)
, _rawMax (_maxForType())
......@@ -1023,8 +1023,8 @@ double FactMetaData::cookedIncrement(void) const
int FactMetaData::decimalPlaces(void) const
{
int actualDecimalPlaces = defaultDecimalPlaces;
int incrementDecimalPlaces = unknownDecimalPlaces;
int actualDecimalPlaces = kDefaultDecimalPlaces;
int incrementDecimalPlaces = kUnknownDecimalPlaces;
// First determine decimal places from increment
double increment = _rawTranslator(this->rawIncrement()).toDouble();
......@@ -1041,20 +1041,21 @@ int FactMetaData::decimalPlaces(void) const
}
}
// Correct decimal places is the larger of the two, increment or meta data value
if (incrementDecimalPlaces != unknownDecimalPlaces && _decimalPlaces == unknownDecimalPlaces) {
if (_decimalPlaces == kUnknownDecimalPlaces) {
if (incrementDecimalPlaces != kUnknownDecimalPlaces) {
actualDecimalPlaces = incrementDecimalPlaces;
} else {
// Adjust decimal places for cooked translation
int settingsDecimalPlaces = _decimalPlaces == unknownDecimalPlaces ? defaultDecimalPlaces : _decimalPlaces;
int settingsDecimalPlaces = _decimalPlaces == kUnknownDecimalPlaces ? kDefaultDecimalPlaces : _decimalPlaces;
double ctest = _rawTranslator(1.0).toDouble();
settingsDecimalPlaces += -log10(ctest);
settingsDecimalPlaces = qMin(25, settingsDecimalPlaces);
settingsDecimalPlaces = qMax(0, settingsDecimalPlaces);
actualDecimalPlaces = qMax(settingsDecimalPlaces, incrementDecimalPlaces);
}
} else {
actualDecimalPlaces = _decimalPlaces;
}
return actualDecimalPlaces;
......
......@@ -166,8 +166,8 @@ public:
/// @returns false: Convertion failed
bool clampValue(const QVariant& cookedValue, QVariant& typedValue);
static const int defaultDecimalPlaces = 3; ///< Default value for decimal places if not specified/known
static const int unknownDecimalPlaces = -1; ///< Number of decimal places to specify is not known
static const int kDefaultDecimalPlaces = 3; ///< Default value for decimal places if not specified/known
static const int kUnknownDecimalPlaces = -1; ///< Number of decimal places to specify is not known
static ValueType_t stringToType(const QString& typeString, bool& unknownType);
static size_t typeToSize(ValueType_t type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment