-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Initialize Fact QVariant as invalid #13642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize Fact QVariant as invalid #13642
Conversation
|
Looking forward to Copilot thrashing this |
There was a problem hiding this 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
_rawValuefrom integer 0 toQVariant::Invalid - Added invalid QVariant handling in
_variantToStringwith 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 |
There was a problem hiding this 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.
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.
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.
ee8c883 to
95f114b
Compare
|
All done. I changed all instances of what previously was a single dash for a double dash, including a couple you didn't mention for consistency. I think a triple dash might be better, but it's easy enough to change in the future. |
|
Thanks Ruben |

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.
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
Before:
After:
Checklist:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.