From 2baf67ae565e85dac36af21cee9d40d193ea5cc8 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Wed, 11 Dec 2019 10:20:54 +0300 Subject: [PATCH] Change decimal futzing to bias towards specifically set decimal places value --- src/FactSystem/Fact.cc | 2 +- src/FactSystem/FactMetaData.cc | 35 +++++++++++++++++----------------- src/FactSystem/FactMetaData.h | 4 ++-- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/FactSystem/Fact.cc b/src/FactSystem/Fact.cc index 391f79b1c..66794d4f6 100644 --- a/src/FactSystem/Fact.cc +++ b/src/FactSystem/Fact.cc @@ -519,7 +519,7 @@ int Fact::decimalPlaces(void) const return _metaData->decimalPlaces(); } else { qWarning() << kMissingMetadata << name(); - return FactMetaData::defaultDecimalPlaces; + return FactMetaData::kDefaultDecimalPlaces; } } diff --git a/src/FactSystem/FactMetaData.cc b/src/FactSystem/FactMetaData.cc index 4316a9473..2568fda70 100644 --- a/src/FactSystem/FactMetaData.cc +++ b/src/FactSystem/FactMetaData.cc @@ -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) { - actualDecimalPlaces = incrementDecimalPlaces; - } else { - // Adjust decimal places for cooked translation - int settingsDecimalPlaces = _decimalPlaces == unknownDecimalPlaces ? defaultDecimalPlaces : _decimalPlaces; - double ctest = _rawTranslator(1.0).toDouble(); - - settingsDecimalPlaces += -log10(ctest); + if (_decimalPlaces == kUnknownDecimalPlaces) { + if (incrementDecimalPlaces != kUnknownDecimalPlaces) { + actualDecimalPlaces = incrementDecimalPlaces; + } else { + // Adjust decimal places for cooked translation + int settingsDecimalPlaces = _decimalPlaces == kUnknownDecimalPlaces ? kDefaultDecimalPlaces : _decimalPlaces; + double ctest = _rawTranslator(1.0).toDouble(); - settingsDecimalPlaces = qMin(25, settingsDecimalPlaces); - settingsDecimalPlaces = qMax(0, settingsDecimalPlaces); + settingsDecimalPlaces += -log10(ctest); - actualDecimalPlaces = qMax(settingsDecimalPlaces, incrementDecimalPlaces); + settingsDecimalPlaces = qMin(25, settingsDecimalPlaces); + settingsDecimalPlaces = qMax(0, settingsDecimalPlaces); + } + } else { + actualDecimalPlaces = _decimalPlaces; } return actualDecimalPlaces; diff --git a/src/FactSystem/FactMetaData.h b/src/FactSystem/FactMetaData.h index 04a7837f1..a96e1fbae 100644 --- a/src/FactSystem/FactMetaData.h +++ b/src/FactSystem/FactMetaData.h @@ -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); -- 2.22.0