From 110278550d80d2ab22028db9c9074070a764ba91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20P=C3=A9rez=20Alonso?= Date: Sat, 15 Nov 2025 20:32:57 +0100 Subject: [PATCH 1/2] Initialize Fact QVariant as invalid Adjusted the default Fact _rawValue from 0 to QVariant::Invalid and updated _variantToString to return placeholders for Facts that haven't received a value yet. This makes it possible to distinguish them from those that are legitimately 0 (or the equivalent for their type). It also avoids starting every Fact's QVariant lifecycle as an integer, which is incorrect in most cases. Related code that set initial values for a few VehicleFactGroup Facts (Hobbs meter, altitude above terrain, flight distance & time) has been updated or removed for consistency. --- src/FactSystem/Fact.cc | 12 ++++++++++++ src/FactSystem/Fact.h | 2 +- src/Vehicle/FactGroups/VehicleFactGroup.cc | 2 +- src/Vehicle/Vehicle.cc | 5 ----- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/FactSystem/Fact.cc b/src/FactSystem/Fact.cc index 8e3ec8a7c7e9..cb4a7370f8ec 100644 --- a/src/FactSystem/Fact.cc +++ b/src/FactSystem/Fact.cc @@ -321,6 +321,18 @@ QStringList Fact::selectedBitmaskStrings() const QString Fact::_variantToString(const QVariant &variant, int decimalPlaces) const { + if (!variant.isValid()) { + switch (type()) { + case FactMetaData::valueTypeFloat: + case FactMetaData::valueTypeDouble: + return QStringLiteral("--.--"); + case FactMetaData::valueTypeElapsedTimeInSeconds: + return QStringLiteral("--:--:--"); + default: + return QStringLiteral("-"); + } + } + QString valueString; switch (type()) { diff --git a/src/FactSystem/Fact.h b/src/FactSystem/Fact.h index 8f4f460bde08..74362c2f738c 100644 --- a/src/FactSystem/Fact.h +++ b/src/FactSystem/Fact.h @@ -191,7 +191,7 @@ class Fact : public QObject QString _name; int _componentId = -1; - QVariant _rawValue = 0; + QVariant _rawValue; // QVariant::Invalid FactMetaData::ValueType_t _type = FactMetaData::valueTypeInt32; FactMetaData *_metaData = nullptr; bool _sendValueChangedSignals = true; diff --git a/src/Vehicle/FactGroups/VehicleFactGroup.cc b/src/Vehicle/FactGroups/VehicleFactGroup.cc index 0bc4d4fb2cc7..9ea23471dd57 100644 --- a/src/Vehicle/FactGroups/VehicleFactGroup.cc +++ b/src/Vehicle/FactGroups/VehicleFactGroup.cc @@ -49,7 +49,7 @@ VehicleFactGroup::VehicleFactGroup(QObject *parent) _addFact(&_throttlePctFact); _addFact(&_imuTempFact); - _hobbsFact.setRawValue(QStringLiteral("0000:00:00")); + _hobbsFact.setRawValue(QStringLiteral("----:--:--")); } void VehicleFactGroup::handleMessage(Vehicle *vehicle, const mavlink_message_t &message) diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index b9fad0df7b6a..a11ec8cf8cab 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -256,9 +256,6 @@ void Vehicle::_commonInit(LinkInterface* link) connect(this, &Vehicle::homePositionChanged, this, &Vehicle::_updateDistanceHeadingHome); connect(this, &Vehicle::hobbsMeterChanged, this, &Vehicle::_updateHobbsMeter); connect(this, &Vehicle::coordinateChanged, this, &Vehicle::_updateAltAboveTerrain); - // Initialize alt above terrain to Nan so frontend can display it correctly in case the terrain query had no response - _altitudeAboveTerrFact.setRawValue(qQNaN()); - connect(this, &Vehicle::vehicleTypeChanged, this, &Vehicle::inFwdFlightChanged); connect(this, &Vehicle::vtolInFwdFlightChanged, this, &Vehicle::inFwdFlightChanged); @@ -351,8 +348,6 @@ void Vehicle::_commonInit(LinkInterface* link) } } - _flightDistanceFact.setRawValue(0); - _flightTimeFact.setRawValue(0); _flightTimeUpdater.setInterval(1000); _flightTimeUpdater.setSingleShot(false); connect(&_flightTimeUpdater, &QTimer::timeout, this, &Vehicle::_updateFlightTime); From ee8c88346eb071790f484ad59a97e4a753185575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20P=C3=A9rez=20Alonso?= Date: Mon, 17 Nov 2025 18:29:17 +0100 Subject: [PATCH 2/2] Improve Fact placeholder String support Implemented Fact::placeholderString to centralize the placeholder String generation logic and take into account the number of decimal places. Changed various hardcoded fallback Strings in QML for consistency with the new placeholder String format. --- src/FactSystem/Fact.cc | 32 ++++++++++++++-------- src/FactSystem/Fact.h | 3 ++ src/FlightDisplay/ProximityRadarValues.qml | 2 +- src/QmlControls/GPSIndicatorPage.qml | 2 +- src/QmlControls/InstrumentValueValue.qml | 2 +- src/UI/toolbar/EscIndicatorPage.qml | 2 +- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/FactSystem/Fact.cc b/src/FactSystem/Fact.cc index cb4a7370f8ec..7e9f28cd76c4 100644 --- a/src/FactSystem/Fact.cc +++ b/src/FactSystem/Fact.cc @@ -322,15 +322,7 @@ QStringList Fact::selectedBitmaskStrings() const QString Fact::_variantToString(const QVariant &variant, int decimalPlaces) const { if (!variant.isValid()) { - switch (type()) { - case FactMetaData::valueTypeFloat: - case FactMetaData::valueTypeDouble: - return QStringLiteral("--.--"); - case FactMetaData::valueTypeElapsedTimeInSeconds: - return QStringLiteral("--:--:--"); - default: - return QStringLiteral("-"); - } + return placeholderString(decimalPlaces); } QString valueString; @@ -340,7 +332,7 @@ QString Fact::_variantToString(const QVariant &variant, int decimalPlaces) const { const float fValue = variant.toFloat(); if (qIsNaN(fValue)) { - valueString = QStringLiteral("--.--"); + valueString = placeholderString(decimalPlaces); } else { valueString = QStringLiteral("%1").arg(fValue, 0, 'f', decimalPlaces); } @@ -350,7 +342,7 @@ QString Fact::_variantToString(const QVariant &variant, int decimalPlaces) const { const double dValue = variant.toDouble(); if (qIsNaN(dValue)) { - valueString = QStringLiteral("--.--"); + valueString = placeholderString(decimalPlaces); } else { valueString = QStringLiteral("%1").arg(dValue, 0, 'f', decimalPlaces); } @@ -363,7 +355,7 @@ QString Fact::_variantToString(const QVariant &variant, int decimalPlaces) const { const double dValue = variant.toDouble(); if (qIsNaN(dValue)) { - valueString = QStringLiteral("--:--:--"); + valueString = placeholderString(decimalPlaces); } else { QTime time(0, 0, 0, 0); time = time.addSecs(dValue); @@ -379,6 +371,22 @@ QString Fact::_variantToString(const QVariant &variant, int decimalPlaces) const return valueString; } +QString Fact::placeholderString(int decimalPlaces) const { + switch (type()) { + case FactMetaData::valueTypeFloat: + case FactMetaData::valueTypeDouble: + if (decimalPlaces <= 0) { + return QStringLiteral("-"); + } + return QStringLiteral("-.") + + QString(decimalPlaces, QLatin1Char('-')); + case FactMetaData::valueTypeElapsedTimeInSeconds: + return QStringLiteral("--:--:--"); + default: + return QStringLiteral("-"); + } +} + QString Fact::rawValueStringFullPrecision() const { return _variantToString(rawValue(), 18); diff --git a/src/FactSystem/Fact.h b/src/FactSystem/Fact.h index 74362c2f738c..06607f4fc72a 100644 --- a/src/FactSystem/Fact.h +++ b/src/FactSystem/Fact.h @@ -56,6 +56,7 @@ class Fact : public QObject Q_PROPERTY(QVariant value READ cookedValue WRITE setCookedValue NOTIFY valueChanged) Q_PROPERTY(QVariant rawValue READ rawValue WRITE setRawValue NOTIFY rawValueChanged) Q_PROPERTY(bool valueEqualsDefault READ valueEqualsDefault NOTIFY valueChanged) + Q_PROPERTY(QString placeholderString READ placeholderString CONSTANT) Q_PROPERTY(QString valueString READ cookedValueString NOTIFY valueChanged) Q_PROPERTY(QString enumOrValueString READ enumOrValueString NOTIFY valueChanged) Q_PROPERTY(double increment READ cookedIncrement CONSTANT) @@ -116,6 +117,8 @@ class Fact : public QObject FactMetaData::ValueType_t type() const { return _type; } QString cookedUnits() const; QString rawUnits() const; + QString placeholderString(int decimalPlaces) const; + QString placeholderString() const { return placeholderString(decimalPlaces()); } QString rawValueString() const; QString cookedValueString() const; bool valueEqualsDefault() const; diff --git a/src/FlightDisplay/ProximityRadarValues.qml b/src/FlightDisplay/ProximityRadarValues.qml index 20e912b87eba..9b198dfeaafc 100644 --- a/src/FlightDisplay/ProximityRadarValues.qml +++ b/src/FlightDisplay/ProximityRadarValues.qml @@ -40,7 +40,7 @@ QtObject { property var rgRotationValueStrings: [ rotationNoneValueString, rotationYaw45ValueString, rotationYaw90ValueString, rotationYaw135ValueString, rotationYaw180ValueString, rotationYaw225ValueString, rotationYaw270ValueString, rotationYaw315ValueString ] property var _distanceSensors: vehicle ? vehicle.distanceSensors : null - property string _noValueStr: qsTr("--.--") + property string _noValueStr: qsTr("-") onRotationNoneValueChanged: rotationValueChanged() onRotationYaw45ValueChanged: rotationValueChanged() diff --git a/src/QmlControls/GPSIndicatorPage.qml b/src/QmlControls/GPSIndicatorPage.qml index 3849c97df4f5..f6b991d4b11a 100644 --- a/src/QmlControls/GPSIndicatorPage.qml +++ b/src/QmlControls/GPSIndicatorPage.qml @@ -21,7 +21,7 @@ ToolIndicatorPage { property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle property string na: qsTr("N/A", "No data to display") - property string valueNA: qsTr("--.--", "No data to display") + property string valueNA: qsTr("-", "No data to display") property var rtkSettings: QGroundControl.settingsManager.rtkSettings property var useFixedPosition: rtkSettings.useFixedBasePosition.rawValue property var manufacturer: rtkSettings.baseReceiverManufacturers.rawValue diff --git a/src/QmlControls/InstrumentValueValue.qml b/src/QmlControls/InstrumentValueValue.qml index 1bf3e199cfeb..2ba2711180ae 100644 --- a/src/QmlControls/InstrumentValueValue.qml +++ b/src/QmlControls/InstrumentValueValue.qml @@ -43,7 +43,7 @@ ColumnLayout { if (instrumentValueData.fact) { return instrumentValueData.fact.enumOrValueString + (instrumentValueData.showUnits ? " " + instrumentValueData.fact.units : "") } else { - return qsTr("--.--") + return qsTr("-") } } } diff --git a/src/UI/toolbar/EscIndicatorPage.qml b/src/UI/toolbar/EscIndicatorPage.qml index d3430d6f2348..fe84c18c3307 100644 --- a/src/UI/toolbar/EscIndicatorPage.qml +++ b/src/UI/toolbar/EscIndicatorPage.qml @@ -20,7 +20,7 @@ ToolIndicatorPage { property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle property string na: qsTr("N/A", "No data to display") - property string valueNA: qsTr("--.--", "No data to display") + property string valueNA: qsTr("-", "No data to display") property var _escs: activeVehicle ? activeVehicle.escs : null property int _onlineBitmask: _escs ? _escs.get(0).info.rawValue : 0