Unverified Commit a60e221e authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #9021 from DonLakeFlyer/DynamicFactGroup

Fix bugs related to dynamic fact groups
parents eb07fbba 31930fd3
...@@ -14,10 +14,12 @@ ...@@ -14,10 +14,12 @@
#include <QSettings> #include <QSettings>
const char* FactValueGrid::_columnsKey = "columns";
const char* FactValueGrid::_rowsKey = "rows"; const char* FactValueGrid::_rowsKey = "rows";
const char* FactValueGrid::_rowCountKey = "rowCount";
const char* FactValueGrid::_fontSizeKey = "fontSize"; const char* FactValueGrid::_fontSizeKey = "fontSize";
const char* FactValueGrid::_versionKey = "version"; const char* FactValueGrid::_versionKey = "version";
const char* FactValueGrid::_factGroupNameKey = "groupName"; const char* FactValueGrid::_factGroupNameKey = "factGroupName";
const char* FactValueGrid::_factNameKey = "factName"; const char* FactValueGrid::_factNameKey = "factName";
const char* FactValueGrid::_textKey = "text"; const char* FactValueGrid::_textKey = "text";
const char* FactValueGrid::_showUnitsKey = "showUnits"; const char* FactValueGrid::_showUnitsKey = "showUnits";
...@@ -272,9 +274,9 @@ void FactValueGrid::_saveSettings(void) ...@@ -272,9 +274,9 @@ void FactValueGrid::_saveSettings(void)
settings.setValue(_versionKey, 1); settings.setValue(_versionKey, 1);
settings.setValue(_fontSizeKey, _fontSize); settings.setValue(_fontSizeKey, _fontSize);
settings.setValue(_rowsKey, _rowCount); settings.setValue(_rowCountKey, _rowCount);
settings.beginWriteArray(_rowsKey); settings.beginWriteArray(_columnsKey);
for (int colIndex=0; colIndex<_columns->count(); colIndex++) { for (int colIndex=0; colIndex<_columns->count(); colIndex++) {
QmlObjectListModel* columns = _columns->value<QmlObjectListModel*>(colIndex); QmlObjectListModel* columns = _columns->value<QmlObjectListModel*>(colIndex);
...@@ -324,11 +326,11 @@ void FactValueGrid::_loadSettings(void) ...@@ -324,11 +326,11 @@ void FactValueGrid::_loadSettings(void)
_fontSize = settings.value(_fontSizeKey, DefaultFontSize).value<FontSize>(); _fontSize = settings.value(_fontSizeKey, DefaultFontSize).value<FontSize>();
// Initial setup of empty items // Initial setup of empty items
int cColumns = settings.value(_rowsKey).toInt(); int cRows = settings.value(_rowCountKey).toInt();
int cModelLists = settings.beginReadArray(_rowsKey); int cModelLists = settings.beginReadArray(_columnsKey);
if (cModelLists && cColumns) { if (cModelLists && cRows) {
appendColumn(); appendColumn();
for (int itemIndex=1; itemIndex<cColumns; itemIndex++) { for (int rowIndex=1; rowIndex<cRows; rowIndex++) {
appendRow(); appendRow();
} }
for (int colIndex=1; colIndex<cModelLists; colIndex++) { for (int colIndex=1; colIndex<cModelLists; colIndex++) {
......
...@@ -104,7 +104,9 @@ private: ...@@ -104,7 +104,9 @@ private:
static const QStringList _fontSizeNames; static const QStringList _fontSizeNames;
static const char* _versionKey; static const char* _versionKey;
static const char* _columnsKey;
static const char* _rowsKey; static const char* _rowsKey;
static const char* _rowCountKey;
static const char* _fontSizeKey; static const char* _fontSizeKey;
static const char* _factGroupNameKey; static const char* _factGroupNameKey;
static const char* _factNameKey; static const char* _factNameKey;
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <QSettings> #include <QSettings>
const QString HorizontalFactValueGrid::_toolbarUserSettingsGroup ("TelemetryBarUserSettingsWIP01"); const QString HorizontalFactValueGrid::_toolbarUserSettingsGroup ("TelemetryBarUserSettingsWIP02");
const QString HorizontalFactValueGrid::telemetryBarDefaultSettingsGroup ("TelemetryBarDefaultSettingsWIP01"); const QString HorizontalFactValueGrid::telemetryBarDefaultSettingsGroup ("TelemetryBarDefaultSettingsWIP02");
HorizontalFactValueGrid::HorizontalFactValueGrid(QQuickItem* parent) HorizontalFactValueGrid::HorizontalFactValueGrid(QQuickItem* parent)
: FactValueGrid(parent) : FactValueGrid(parent)
......
...@@ -42,37 +42,31 @@ InstrumentValueData::InstrumentValueData(FactValueGrid* factValueGrid, QObject* ...@@ -42,37 +42,31 @@ InstrumentValueData::InstrumentValueData(FactValueGrid* factValueGrid, QObject*
void InstrumentValueData::_activeVehicleChanged(Vehicle* activeVehicle) void InstrumentValueData::_activeVehicleChanged(Vehicle* activeVehicle)
{ {
if (!activeVehicle) { if (_activeVehicle) {
activeVehicle = qgcApp()->toolbox()->multiVehicleManager()->offlineEditingVehicle(); disconnect(_activeVehicle, &Vehicle::factGroupNamesChanged, this, &InstrumentValueData::_lookForMissingFact);
} }
if (_fact) { if (!activeVehicle) {
disconnect(_fact, &Fact::rawValueChanged, this, &InstrumentValueData::_updateColor); activeVehicle = qgcApp()->toolbox()->multiVehicleManager()->offlineEditingVehicle();
} }
_activeVehicle = activeVehicle; _activeVehicle = activeVehicle;
connect(_activeVehicle, &Vehicle::factGroupNamesChanged, this, &InstrumentValueData::_lookForMissingFact);
emit factGroupNamesChanged(); emit factGroupNamesChanged();
if (_fact) { if (!_factGroupName.isEmpty() && !_factName.isEmpty()) {
_fact = nullptr; _setFactWorker();
FactGroup* factGroup = nullptr;
if (_factGroupName == vehicleFactGroupName) {
factGroup = _activeVehicle;
} else {
factGroup = _activeVehicle->getFactGroup(_factGroupName);
}
if (factGroup) {
_fact = factGroup->getFact(_factName);
} }
emit factChanged(_fact); }
connect(_fact, &Fact::rawValueChanged, this, &InstrumentValueData::_updateRanges); void InstrumentValueData::_lookForMissingFact(void)
{
// This is called when new fact groups show up on the vehicle. We need to see if we can fill in any
// facts which may have been missing up to now.
if (!_fact) {
_setFactWorker();
} }
_updateRanges();
} }
void InstrumentValueData::clearFact(void) void InstrumentValueData::clearFact(void)
...@@ -92,7 +86,7 @@ void InstrumentValueData::clearFact(void) ...@@ -92,7 +86,7 @@ void InstrumentValueData::clearFact(void)
emit showUnitsChanged (_showUnits); emit showUnitsChanged (_showUnits);
} }
void InstrumentValueData::setFact(const QString& factGroupName, const QString& factName) void InstrumentValueData::_setFactWorker(void)
{ {
if (_fact) { if (_fact) {
disconnect(_fact, &Fact::rawValueChanged, this, &InstrumentValueData::_updateRanges); disconnect(_fact, &Fact::rawValueChanged, this, &InstrumentValueData::_updateRanges);
...@@ -100,19 +94,18 @@ void InstrumentValueData::setFact(const QString& factGroupName, const QString& f ...@@ -100,19 +94,18 @@ void InstrumentValueData::setFact(const QString& factGroupName, const QString& f
} }
FactGroup* factGroup = nullptr; FactGroup* factGroup = nullptr;
if (factGroupName == vehicleFactGroupName) { if (_factGroupName == vehicleFactGroupName) {
factGroup = _activeVehicle; factGroup = _activeVehicle;
} else { } else {
factGroup = _activeVehicle->getFactGroup(factGroupName); factGroup = _activeVehicle->getFactGroup(_factGroupName);
} }
_factGroupName = factGroupName;
QString nonEmptyFactName; QString nonEmptyFactName;
if (factGroup) { if (factGroup) {
if (factName.isEmpty()) { if (_factName.isEmpty()) {
nonEmptyFactName = factValueNames()[0]; nonEmptyFactName = factValueNames()[0];
} else { } else {
nonEmptyFactName = factName; nonEmptyFactName = _factName;
} }
_fact = factGroup->getFact(nonEmptyFactName); _fact = factGroup->getFact(nonEmptyFactName);
} }
...@@ -120,9 +113,6 @@ void InstrumentValueData::setFact(const QString& factGroupName, const QString& f ...@@ -120,9 +113,6 @@ void InstrumentValueData::setFact(const QString& factGroupName, const QString& f
if (_fact) { if (_fact) {
_factName = nonEmptyFactName; _factName = nonEmptyFactName;
connect(_fact, &Fact::rawValueChanged, this, &InstrumentValueData::_updateRanges); connect(_fact, &Fact::rawValueChanged, this, &InstrumentValueData::_updateRanges);
} else {
_factGroupName.clear();
_factName.clear();
} }
emit factValueNamesChanged (); emit factValueNamesChanged ();
...@@ -132,6 +122,13 @@ void InstrumentValueData::setFact(const QString& factGroupName, const QString& f ...@@ -132,6 +122,13 @@ void InstrumentValueData::setFact(const QString& factGroupName, const QString& f
_updateRanges(); _updateRanges();
} }
void InstrumentValueData::setFact(const QString& factGroupName, const QString& factName)
{
_factGroupName = factGroupName;
_factName = factName;
_setFactWorker();
}
void InstrumentValueData::setText(const QString& text) void InstrumentValueData::setText(const QString& text)
{ {
...@@ -364,6 +361,8 @@ QStringList InstrumentValueData::factGroupNames(void) const ...@@ -364,6 +361,8 @@ QStringList InstrumentValueData::factGroupNames(void) const
QStringList InstrumentValueData::factValueNames(void) const QStringList InstrumentValueData::factValueNames(void) const
{ {
QStringList valueNames;
FactGroup* factGroup = nullptr; FactGroup* factGroup = nullptr;
if (_factGroupName == vehicleFactGroupName) { if (_factGroupName == vehicleFactGroupName) {
factGroup = _activeVehicle; factGroup = _activeVehicle;
...@@ -371,10 +370,12 @@ QStringList InstrumentValueData::factValueNames(void) const ...@@ -371,10 +370,12 @@ QStringList InstrumentValueData::factValueNames(void) const
factGroup = _activeVehicle->getFactGroup(_factGroupName); factGroup = _activeVehicle->getFactGroup(_factGroupName);
} }
QStringList valueNames = factGroup->factNames(); if (factGroup) {
valueNames = factGroup->factNames();
for (QString& name: valueNames) { for (QString& name: valueNames) {
name[0] = name[0].toUpper(); name[0] = name[0].toUpper();
} }
}
return valueNames; return valueNames;
} }
...@@ -105,12 +105,14 @@ private slots: ...@@ -105,12 +105,14 @@ private slots:
void _resetRangeInfo (void); void _resetRangeInfo (void);
void _updateRanges (void); void _updateRanges (void);
void _activeVehicleChanged (Vehicle* activeVehicle); void _activeVehicleChanged (Vehicle* activeVehicle);
void _lookForMissingFact (void);
private: private:
int _currentRangeIndex (const QVariant& value); int _currentRangeIndex (const QVariant& value);
void _updateColor (void); void _updateColor (void);
void _updateIcon (void); void _updateIcon (void);
void _updateOpacity (void); void _updateOpacity (void);
void _setFactWorker (void);
FactValueGrid* _factValueGrid = nullptr; FactValueGrid* _factValueGrid = nullptr;
Vehicle* _activeVehicle = nullptr; Vehicle* _activeVehicle = nullptr;
......
...@@ -30,6 +30,21 @@ QGCPopupDialog { ...@@ -30,6 +30,21 @@ QGCPopupDialog {
QGCPalette { id: qgcPal; colorGroupEnabled: parent.enabled } QGCPalette { id: qgcPal; colorGroupEnabled: parent.enabled }
QGCPalette { id: qgcPalDisabled; colorGroupEnabled: false } QGCPalette { id: qgcPalDisabled; colorGroupEnabled: false }
Loader {
sourceComponent: instrumentValueData.fact ? editorComponent : noFactComponent
}
Component {
id: noFactComponent
QGCLabel {
text: qsTr("Valuec requires a connected vehicle for setup.")
}
}
Component {
id: editorComponent
GridLayout { GridLayout {
rowSpacing: _margins rowSpacing: _margins
columnSpacing: _margins columnSpacing: _margins
...@@ -177,7 +192,7 @@ QGCPopupDialog { ...@@ -177,7 +192,7 @@ QGCPopupDialog {
case InstrumentValueData.OpacityRange: case InstrumentValueData.OpacityRange:
sourceComponent = opacityRangeDialog sourceComponent = opacityRangeDialog
break break
case InstrumentValueData.IconSelectRange: case InstrumentValueData.IconSelvalueedectRange:
sourceComponent = iconRangeDialog sourceComponent = iconRangeDialog
break break
} }
...@@ -192,6 +207,7 @@ QGCPopupDialog { ...@@ -192,6 +207,7 @@ QGCPopupDialog {
} }
} }
}
Component { Component {
id: colorRangeDialog id: colorRangeDialog
...@@ -313,7 +329,7 @@ QGCPopupDialog { ...@@ -313,7 +329,7 @@ QGCPopupDialog {
id: iconRangeDialog id: iconRangeDialog
Item { Item {
width: childrenRect.width width: childrenRect.widthvalueed
height: childrenRect.height height: childrenRect.height
function updateRangeValue(index, text) { function updateRangeValue(index, text) {
...@@ -545,4 +561,3 @@ QGCPopupDialog { ...@@ -545,4 +561,3 @@ QGCPopupDialog {
} }
} }
} }
...@@ -23,7 +23,6 @@ ColumnLayout { ...@@ -23,7 +23,6 @@ ColumnLayout {
property bool settingsUnlocked: false property bool settingsUnlocked: false
property alias contentWidth: label.contentWidth property alias contentWidth: label.contentWidth
property bool _verticalOrientation: instrumentValueData.factValueGrid.orientation === FactValueGrid.VerticalOrientation
property var _rgFontSizes: [ ScreenTools.defaultFontPointSize, ScreenTools.smallFontPointSize, ScreenTools.mediumFontPointSize, ScreenTools.largeFontPointSize ] property var _rgFontSizes: [ ScreenTools.defaultFontPointSize, ScreenTools.smallFontPointSize, ScreenTools.mediumFontPointSize, ScreenTools.largeFontPointSize ]
property var _rgFontSizeRatios: [ 1, ScreenTools.smallFontPointRatio, ScreenTools.mediumFontPointRatio, ScreenTools.largeFontPointRatio ] property var _rgFontSizeRatios: [ 1, ScreenTools.smallFontPointRatio, ScreenTools.mediumFontPointRatio, ScreenTools.largeFontPointRatio ]
property real _doubleDescent: ScreenTools.defaultFontDescent * 2 property real _doubleDescent: ScreenTools.defaultFontDescent * 2
...@@ -32,17 +31,21 @@ ColumnLayout { ...@@ -32,17 +31,21 @@ ColumnLayout {
property real _tightHeight: _rgFontSizeTightHeights[instrumentValueData.factValueGrid.fontSize] property real _tightHeight: _rgFontSizeTightHeights[instrumentValueData.factValueGrid.fontSize]
property real _fontSize: _rgFontSizes[instrumentValueData.factValueGrid.fontSize] property real _fontSize: _rgFontSizes[instrumentValueData.factValueGrid.fontSize]
property real _horizontalLabelSpacing: ScreenTools.defaultFontPixelWidth property real _horizontalLabelSpacing: ScreenTools.defaultFontPixelWidth
property bool _valueVisible: instrumentValueData.fact
property real _width: 0 property real _width: 0
property real _height: 0 property real _height: 0
QGCLabel { QGCLabel {
id: label id: label
Layout.alignment: _verticalOrientation ? Qt.AlignHCenter : Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
font.pointSize: _fontSize font.pointSize: _fontSize
text: instrumentValueData.fact.enumOrValueString + (instrumentValueData.showUnits ? " " + instrumentValueData.fact.units : "") text: valueText()
visible: _valueVisible
QGCPalette { id: qgcPal; colorGroupEnabled: enabled } function valueText() {
if (instrumentValueData.fact) {
return instrumentValueData.fact.enumOrValueString + (instrumentValueData.showUnits ? " " + instrumentValueData.fact.units : "")
} else {
return qsTr("--.--")
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment