Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/FactSystem/Fact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,18 @@ QStringList Fact::selectedBitmaskStrings() const

QString Fact::_variantToString(const QVariant &variant, int decimalPlaces) const
{
if (!variant.isValid()) {
return placeholderString(decimalPlaces);
}

QString valueString;

switch (type()) {
case FactMetaData::valueTypeFloat:
{
const float fValue = variant.toFloat();
if (qIsNaN(fValue)) {
valueString = QStringLiteral("--.--");
valueString = placeholderString(decimalPlaces);
} else {
valueString = QStringLiteral("%1").arg(fValue, 0, 'f', decimalPlaces);
}
Expand All @@ -338,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);
}
Expand All @@ -351,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);
Expand All @@ -367,6 +371,22 @@ QString Fact::_variantToString(const QVariant &variant, int decimalPlaces) const
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?

switch (type()) {
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.

}
return QStringLiteral("-.") +
QString(decimalPlaces, QLatin1Char('-'));
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.

}
}

QString Fact::rawValueStringFullPrecision() const
{
return _variantToString(rawValue(), 18);
Expand Down
5 changes: 4 additions & 1 deletion src/FactSystem/Fact.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -191,7 +194,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;
Expand Down
2 changes: 1 addition & 1 deletion src/FlightDisplay/ProximityRadarValues.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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("-")
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.


onRotationNoneValueChanged: rotationValueChanged()
onRotationYaw45ValueChanged: rotationValueChanged()
Expand Down
2 changes: 1 addition & 1 deletion src/QmlControls/GPSIndicatorPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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.

property var rtkSettings: QGroundControl.settingsManager.rtkSettings
property var useFixedPosition: rtkSettings.useFixedBasePosition.rawValue
property var manufacturer: rtkSettings.baseReceiverManufacturers.rawValue
Expand Down
2 changes: 1 addition & 1 deletion src/QmlControls/InstrumentValueValue.qml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ColumnLayout {
if (instrumentValueData.fact) {
return instrumentValueData.fact.enumOrValueString + (instrumentValueData.showUnits ? " " + instrumentValueData.fact.units : "")
} else {
return qsTr("--.--")
return qsTr("-")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/UI/toolbar/EscIndicatorPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Vehicle/FactGroups/VehicleFactGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions src/Vehicle/Vehicle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
Loading