Skip to content

Commit 6684883

Browse files
rubenp02DonLakeFlyer
authored andcommitted
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.
1 parent b44a33f commit 6684883

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/FactSystem/Fact.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,18 @@ QStringList Fact::selectedBitmaskStrings() const
321321

322322
QString Fact::_variantToString(const QVariant &variant, int decimalPlaces) const
323323
{
324+
if (!variant.isValid()) {
325+
switch (type()) {
326+
case FactMetaData::valueTypeFloat:
327+
case FactMetaData::valueTypeDouble:
328+
return QStringLiteral("--.--");
329+
case FactMetaData::valueTypeElapsedTimeInSeconds:
330+
return QStringLiteral("--:--:--");
331+
default:
332+
return QStringLiteral("-");
333+
}
334+
}
335+
324336
QString valueString;
325337

326338
const auto stripNegativeZero = [](QString &candidate) {

src/FactSystem/Fact.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class Fact : public QObject
191191

192192
QString _name;
193193
int _componentId = -1;
194-
QVariant _rawValue = 0;
194+
QVariant _rawValue; // QVariant::Invalid
195195
FactMetaData::ValueType_t _type = FactMetaData::valueTypeInt32;
196196
FactMetaData *_metaData = nullptr;
197197
bool _sendValueChangedSignals = true;

src/Vehicle/FactGroups/VehicleFactGroup.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ VehicleFactGroup::VehicleFactGroup(QObject *parent)
4949
_addFact(&_throttlePctFact);
5050
_addFact(&_imuTempFact);
5151

52-
_hobbsFact.setRawValue(QStringLiteral("0000:00:00"));
52+
_hobbsFact.setRawValue(QStringLiteral("----:--:--"));
5353
}
5454

5555
void VehicleFactGroup::handleMessage(Vehicle *vehicle, const mavlink_message_t &message)

src/Vehicle/Vehicle.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ void Vehicle::_commonInit(LinkInterface* link)
252252
connect(this, &Vehicle::homePositionChanged, this, &Vehicle::_updateDistanceHeadingHome);
253253
connect(this, &Vehicle::hobbsMeterChanged, this, &Vehicle::_updateHobbsMeter);
254254
connect(this, &Vehicle::coordinateChanged, this, &Vehicle::_updateAltAboveTerrain);
255-
// Initialize alt above terrain to Nan so frontend can display it correctly in case the terrain query had no response
256-
_altitudeAboveTerrFact.setRawValue(qQNaN());
257-
258255
connect(this, &Vehicle::vehicleTypeChanged, this, &Vehicle::inFwdFlightChanged);
259256
connect(this, &Vehicle::vtolInFwdFlightChanged, this, &Vehicle::inFwdFlightChanged);
260257

@@ -347,8 +344,6 @@ void Vehicle::_commonInit(LinkInterface* link)
347344
}
348345
}
349346

350-
_flightDistanceFact.setRawValue(0);
351-
_flightTimeFact.setRawValue(0);
352347
_flightTimeUpdater.setInterval(1000);
353348
_flightTimeUpdater.setSingleShot(false);
354349
connect(&_flightTimeUpdater, &QTimer::timeout, this, &Vehicle::_updateFlightTime);

0 commit comments

Comments
 (0)