Skip to content

Conversation

@rubenp02
Copy link
Contributor

Initialize Fact QVariant as invalid

Description

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.

Note: While I believe these changes are in the right direction, and an improvement over the old code, they may be incomplete (I've only focused on testing the VehicleFactGroup) and there's a decent chance of unforseen bugs. Anything that relied on default facts being integer 0 is now broken.

Telemetry bar before/after

The following screenshots use these telemetry bar settings, that include all Facts from the VehicleFactGroup:

Click to show telemetry bar settings used
[TelemetryBarUserSettings-1]
version=1
fontSize=2
rowCount=4
columns\1\rows\1\text=Roll
columns\1\rows\1\showUnits=true
columns\1\rows\1\icon=
columns\1\rows\1\rangeType=0
columns\1\rows\1\factGroupName=Vehicle
columns\1\rows\1\factName=Roll
columns\1\rows\size=4
columns\2\rows\1\text=Pitch
columns\2\rows\1\showUnits=true
columns\2\rows\1\icon=
columns\2\rows\1\rangeType=0
columns\2\rows\1\factGroupName=Vehicle
columns\2\rows\1\factName=Pitch
columns\2\rows\size=4
columns\3\rows\1\text=Heading
columns\3\rows\1\showUnits=true
columns\3\rows\1\icon=
columns\3\rows\1\rangeType=0
columns\3\rows\1\factGroupName=Vehicle
columns\3\rows\1\factName=Heading
columns\3\rows\size=4
columns\4\rows\1\text=Roll Rate
columns\4\rows\1\showUnits=true
columns\4\rows\1\icon=
columns\4\rows\1\rangeType=0
columns\4\rows\1\factGroupName=Vehicle
columns\4\rows\1\factName=RollRate
columns\4\rows\size=4
columns\size=8
columns\1\rows\2\text=
columns\1\rows\2\showUnits=true
columns\1\rows\2\icon=
columns\1\rows\2\rangeType=0
columns\1\rows\2\factGroupName=Vehicle
columns\1\rows\2\factName=AirSpeedSetpoint
columns\1\rows\3\text=
columns\1\rows\3\showUnits=true
columns\1\rows\3\icon=
columns\1\rows\3\rangeType=0
columns\1\rows\3\factGroupName=Vehicle
columns\1\rows\3\factName=RangeFinderDist
columns\1\rows\4\text=Heading to Home
columns\1\rows\4\showUnits=true
columns\2\rows\2\text=Climb Rate
columns\1\rows\4\icon=
columns\2\rows\2\showUnits=true
columns\1\rows\4\rangeType=0
columns\2\rows\2\icon=
columns\1\rows\4\factGroupName=Vehicle
columns\2\rows\2\rangeType=0
columns\1\rows\4\factName=HeadingToHome
columns\2\rows\2\factGroupName=Vehicle
columns\2\rows\2\factName=ClimbRate
columns\2\rows\3\text=Flight Distance
columns\2\rows\3\showUnits=true
columns\3\rows\2\text=Alt (Rel)
columns\2\rows\3\icon=
columns\3\rows\2\showUnits=true
columns\2\rows\3\rangeType=0
columns\3\rows\2\icon=
columns\2\rows\3\factGroupName=Vehicle
columns\3\rows\2\rangeType=0
columns\2\rows\3\factName=FlightDistance
columns\3\rows\2\factGroupName=Vehicle
columns\3\rows\2\factName=AltitudeRelative
columns\2\rows\4\text=Heading from Home
columns\2\rows\4\showUnits=true
columns\2\rows\4\icon=
columns\4\rows\2\text=Alt (AMSL)
columns\2\rows\4\rangeType=0
columns\4\rows\2\showUnits=true
columns\2\rows\4\factGroupName=Vehicle
columns\4\rows\2\icon=
columns\2\rows\4\factName=HeadingFromHome
columns\4\rows\2\rangeType=0
columns\4\rows\2\factGroupName=Vehicle
columns\3\rows\3\text=Flight Time
columns\4\rows\2\factName=AltitudeAMSL
columns\3\rows\3\showUnits=true
columns\3\rows\3\icon=
columns\3\rows\3\rangeType=0
columns\3\rows\3\factGroupName=Vehicle
columns\3\rows\3\factName=FlightTime
columns\3\rows\4\text=Heading from GCS
columns\3\rows\4\showUnits=true
columns\4\rows\3\text=Distance to Home
columns\3\rows\4\icon=
columns\4\rows\3\showUnits=true
columns\3\rows\4\rangeType=0
columns\4\rows\3\icon=
columns\3\rows\4\factGroupName=Vehicle
columns\4\rows\3\rangeType=0
columns\3\rows\4\factName=HeadingFromGCS
columns\4\rows\3\factGroupName=Vehicle
columns\4\rows\3\factName=DistanceToHome
columns\4\rows\4\text=Distance to GCS
columns\4\rows\4\showUnits=true
columns\4\rows\4\icon=
columns\4\rows\4\rangeType=0
columns\4\rows\4\factGroupName=Vehicle
columns\4\rows\4\factName=DistanceToGCS
columns\5\rows\1\text=Pitch Rate
columns\5\rows\1\showUnits=true
columns\5\rows\1\icon=
columns\5\rows\1\rangeType=0
columns\5\rows\1\factGroupName=Vehicle
columns\5\rows\1\factName=PitchRate
columns\5\rows\2\text=Alt (Above Terrain)
columns\5\rows\2\showUnits=true
columns\5\rows\2\icon=
columns\5\rows\2\rangeType=0
columns\5\rows\2\factGroupName=Vehicle
columns\5\rows\2\factName=AltitudeAboveTerr
columns\5\rows\3\text=Time to Home
columns\5\rows\3\showUnits=true
columns\5\rows\3\icon=
columns\5\rows\3\rangeType=0
columns\5\rows\3\factGroupName=Vehicle
columns\5\rows\3\factName=TimeToHome
columns\5\rows\4\text=Hobbs Meter
columns\5\rows\4\showUnits=true
columns\5\rows\4\icon=
columns\5\rows\4\rangeType=0
columns\5\rows\4\factGroupName=Vehicle
columns\5\rows\4\factName=Hobbs
columns\5\rows\size=4
columns\6\rows\1\text=Yaw Rate
columns\6\rows\1\showUnits=true
columns\6\rows\1\icon=
columns\6\rows\1\rangeType=0
columns\6\rows\1\factGroupName=Vehicle
columns\6\rows\1\factName=YawRate
columns\6\rows\2\text=
columns\6\rows\2\showUnits=true
columns\6\rows\2\icon=
columns\6\rows\2\rangeType=0
columns\6\rows\2\factGroupName=Vehicle
columns\6\rows\2\factName=AltitudeTuning
columns\6\rows\3\text=Mission Item Index
columns\6\rows\3\showUnits=true
columns\6\rows\3\icon=
columns\6\rows\3\rangeType=0
columns\6\rows\3\factGroupName=Vehicle
columns\6\rows\3\factName=MissionItemIndex
columns\6\rows\4\text=Throttle %
columns\6\rows\4\showUnits=true
columns\6\rows\4\icon=
columns\6\rows\4\rangeType=0
columns\6\rows\4\factGroupName=Vehicle
columns\6\rows\4\factName=ThrottlePct
columns\6\rows\size=4
columns\7\rows\1\text=Ground Speed
columns\7\rows\1\showUnits=true
columns\7\rows\1\icon=
columns\7\rows\1\rangeType=0
columns\7\rows\1\factGroupName=Vehicle
columns\7\rows\1\factName=GroundSpeed
columns\7\rows\2\text=
columns\7\rows\2\showUnits=true
columns\7\rows\2\icon=
columns\7\rows\2\rangeType=0
columns\7\rows\2\factGroupName=Vehicle
columns\7\rows\2\factName=AltitudeTuningSetpoint
columns\7\rows\3\text=Next WP Heading
columns\7\rows\3\showUnits=true
columns\7\rows\3\icon=
columns\7\rows\3\rangeType=0
columns\7\rows\3\factGroupName=Vehicle
columns\7\rows\3\factName=HeadingToNextWP
columns\7\rows\4\text=Imu temperature
columns\7\rows\4\showUnits=true
columns\7\rows\4\icon=
columns\7\rows\4\rangeType=0
columns\7\rows\4\factGroupName=Vehicle
columns\7\rows\4\factName=ImuTemp
columns\7\rows\size=4
columns\8\rows\1\text=Air Speed
columns\8\rows\1\showUnits=true
columns\8\rows\1\icon=
columns\8\rows\1\rangeType=0
columns\8\rows\1\factGroupName=Vehicle
columns\8\rows\1\factName=AirSpeed
columns\8\rows\2\text=
columns\8\rows\2\showUnits=true
columns\8\rows\2\icon=
columns\8\rows\2\rangeType=0
columns\8\rows\2\factGroupName=Vehicle
columns\8\rows\2\factName=XTrackError
columns\8\rows\3\text=Next WP distance
columns\8\rows\3\showUnits=true
columns\8\rows\3\icon=
columns\8\rows\3\rangeType=0
columns\8\rows\3\factGroupName=Vehicle
columns\8\rows\3\factName=DistanceToNextWP
columns\8\rows\4\text=Alt (Rel)
columns\8\rows\4\showUnits=true
columns\8\rows\4\icon=
columns\8\rows\4\rangeType=0
columns\8\rows\4\factGroupName=Vehicle
columns\8\rows\4\factName=AltitudeRelative
columns\8\rows\size=4

Before:

imagen

After:

imagen

Checklist:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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.
Copilot AI review requested due to automatic review settings November 15, 2025 20:38
@rubenp02
Copy link
Contributor Author

Looking forward to Copilot thrashing this

Copilot finished reviewing on behalf of rubenp02 November 15, 2025 20:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the Fact system's initialization by using invalid QVariant instead of defaulting to integer 0, making it possible to distinguish uninitialized Facts from those with legitimate zero values. This change also corrects the QVariant lifecycle, avoiding the incorrect initial state where all Facts started as integers.

Key Changes:

  • Changed Fact's default _rawValue from integer 0 to QVariant::Invalid
  • Added invalid QVariant handling in _variantToString with type-appropriate placeholders
  • Updated Hobbs meter placeholder from "0000:00:00" to "----:--:--" for consistency

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/FactSystem/Fact.h Changed default _rawValue initialization from 0 to invalid QVariant with clarifying comment
src/FactSystem/Fact.cc Added invalid QVariant check in _variantToString returning type-appropriate placeholders ("--.--" for floats/doubles, "--:--:--" for elapsed time, "-" for others)
src/Vehicle/FactGroups/VehicleFactGroup.cc Updated Hobbs meter placeholder string from "0000:00:00" to "----:--:--" to indicate uninitialized state
src/Vehicle/Vehicle.cc Removed redundant initializations for altitude above terrain (NaN), flight distance (0), and flight time (0) that are now handled by invalid QVariant default or explicit initialization when needed

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.
@rubenp02
Copy link
Contributor Author

I've pushed a small improvement: the number of decimal places is now taken into account for the placeholder String generation, which is also now centralized. For consistency, I've also changed a couple places in the QML where placeholder strings were hardcoded just in case the corresponding Facts weren't available at all (which is a bit unrealistic given that they're just loaded from JSON, but whatever). Here's how it's looking now:

After after:

init-fact-qvariant-as-invalid-after-after

@rubenp02 rubenp02 requested a review from Copilot November 17, 2025 17:49
Copilot finished reviewing on behalf of rubenp02 November 17, 2025 17:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

return valueString;
}

QString Fact::placeholderString(int decimalPlaces) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better named invalidValueString. What do you think?

case FactMetaData::valueTypeFloat:
case FactMetaData::valueTypeDouble:
if (decimalPlaces <= 0) {
return QStringLiteral("-");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that using '--' for this would make it clearer this is a missing value. Given the fact that '-' can kinda mean negative and may confuse folks.

case FactMetaData::valueTypeElapsedTimeInSeconds:
return QStringLiteral("--:--:--");
default:
return QStringLiteral("-");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here '--' is clearer.


property var _distanceSensors: vehicle ? vehicle.distanceSensors : null
property string _noValueStr: qsTr("--.--")
property string _noValueStr: qsTr("-")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are shown with decimal places in the ui when available. So I would keep the --.-- to make it clearer.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are also shown normally with decimal places. So I would keep it as is to make it more clear. That said, given the way the control works this string is never shown since that sections of values is hidden when no vehicle is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants