diff --git a/src/QmlControls/FactValueGrid.cc b/src/QmlControls/FactValueGrid.cc index b0c9a108cae68b36aa705ea3c51f0ca7d10152a3..dd17b649d0e43f7859bd57474ba2c3d7bbc082cb 100644 --- a/src/QmlControls/FactValueGrid.cc +++ b/src/QmlControls/FactValueGrid.cc @@ -14,19 +14,21 @@ #include -const char* FactValueGrid::_rowsKey = "rows"; -const char* FactValueGrid::_fontSizeKey = "fontSize"; -const char* FactValueGrid::_versionKey = "version"; -const char* FactValueGrid::_factGroupNameKey = "groupName"; -const char* FactValueGrid::_factNameKey = "factName"; -const char* FactValueGrid::_textKey = "text"; -const char* FactValueGrid::_showUnitsKey = "showUnits"; -const char* FactValueGrid::_iconKey = "icon"; -const char* FactValueGrid::_rangeTypeKey = "rangeType"; -const char* FactValueGrid::_rangeValuesKey = "rangeValues"; -const char* FactValueGrid::_rangeColorsKey = "rangeColors"; -const char* FactValueGrid::_rangeIconsKey = "rangeIcons"; -const char* FactValueGrid::_rangeOpacitiesKey = "rangeOpacities"; +const char* FactValueGrid::_columnsKey = "columns"; +const char* FactValueGrid::_rowsKey = "rows"; +const char* FactValueGrid::_rowCountKey = "rowCount"; +const char* FactValueGrid::_fontSizeKey = "fontSize"; +const char* FactValueGrid::_versionKey = "version"; +const char* FactValueGrid::_factGroupNameKey = "factGroupName"; +const char* FactValueGrid::_factNameKey = "factName"; +const char* FactValueGrid::_textKey = "text"; +const char* FactValueGrid::_showUnitsKey = "showUnits"; +const char* FactValueGrid::_iconKey = "icon"; +const char* FactValueGrid::_rangeTypeKey = "rangeType"; +const char* FactValueGrid::_rangeValuesKey = "rangeValues"; +const char* FactValueGrid::_rangeColorsKey = "rangeColors"; +const char* FactValueGrid::_rangeIconsKey = "rangeIcons"; +const char* FactValueGrid::_rangeOpacitiesKey = "rangeOpacities"; const char* FactValueGrid::_deprecatedGroupKey = "ValuesWidget"; @@ -272,9 +274,9 @@ void FactValueGrid::_saveSettings(void) settings.setValue(_versionKey, 1); 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++) { QmlObjectListModel* columns = _columns->value(colIndex); @@ -324,11 +326,11 @@ void FactValueGrid::_loadSettings(void) _fontSize = settings.value(_fontSizeKey, DefaultFontSize).value(); // Initial setup of empty items - int cColumns = settings.value(_rowsKey).toInt(); - int cModelLists = settings.beginReadArray(_rowsKey); - if (cModelLists && cColumns) { + int cRows = settings.value(_rowCountKey).toInt(); + int cModelLists = settings.beginReadArray(_columnsKey); + if (cModelLists && cRows) { appendColumn(); - for (int itemIndex=1; itemIndex -const QString HorizontalFactValueGrid::_toolbarUserSettingsGroup ("TelemetryBarUserSettingsWIP01"); -const QString HorizontalFactValueGrid::telemetryBarDefaultSettingsGroup ("TelemetryBarDefaultSettingsWIP01"); +const QString HorizontalFactValueGrid::_toolbarUserSettingsGroup ("TelemetryBarUserSettingsWIP02"); +const QString HorizontalFactValueGrid::telemetryBarDefaultSettingsGroup ("TelemetryBarDefaultSettingsWIP02"); HorizontalFactValueGrid::HorizontalFactValueGrid(QQuickItem* parent) : FactValueGrid(parent) diff --git a/src/QmlControls/InstrumentValueData.cc b/src/QmlControls/InstrumentValueData.cc index efde15431d44202e026b7cbebc8b0a3a628107f2..01ad0979bd64b7fdfe6fce3e0c2015bee318be3f 100644 --- a/src/QmlControls/InstrumentValueData.cc +++ b/src/QmlControls/InstrumentValueData.cc @@ -42,37 +42,31 @@ InstrumentValueData::InstrumentValueData(FactValueGrid* factValueGrid, QObject* void InstrumentValueData::_activeVehicleChanged(Vehicle* activeVehicle) { - if (!activeVehicle) { - activeVehicle = qgcApp()->toolbox()->multiVehicleManager()->offlineEditingVehicle(); + if (_activeVehicle) { + disconnect(_activeVehicle, &Vehicle::factGroupNamesChanged, this, &InstrumentValueData::_lookForMissingFact); } - if (_fact) { - disconnect(_fact, &Fact::rawValueChanged, this, &InstrumentValueData::_updateColor); + if (!activeVehicle) { + activeVehicle = qgcApp()->toolbox()->multiVehicleManager()->offlineEditingVehicle(); } _activeVehicle = activeVehicle; + connect(_activeVehicle, &Vehicle::factGroupNamesChanged, this, &InstrumentValueData::_lookForMissingFact); emit factGroupNamesChanged(); - if (_fact) { - _fact = nullptr; - - 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); + if (!_factGroupName.isEmpty() && !_factName.isEmpty()) { + _setFactWorker(); } +} - _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(); + } } void InstrumentValueData::clearFact(void) @@ -92,7 +86,7 @@ void InstrumentValueData::clearFact(void) emit showUnitsChanged (_showUnits); } -void InstrumentValueData::setFact(const QString& factGroupName, const QString& factName) +void InstrumentValueData::_setFactWorker(void) { if (_fact) { disconnect(_fact, &Fact::rawValueChanged, this, &InstrumentValueData::_updateRanges); @@ -100,19 +94,18 @@ void InstrumentValueData::setFact(const QString& factGroupName, const QString& f } FactGroup* factGroup = nullptr; - if (factGroupName == vehicleFactGroupName) { + if (_factGroupName == vehicleFactGroupName) { factGroup = _activeVehicle; } else { - factGroup = _activeVehicle->getFactGroup(factGroupName); + factGroup = _activeVehicle->getFactGroup(_factGroupName); } - _factGroupName = factGroupName; QString nonEmptyFactName; if (factGroup) { - if (factName.isEmpty()) { + if (_factName.isEmpty()) { nonEmptyFactName = factValueNames()[0]; } else { - nonEmptyFactName = factName; + nonEmptyFactName = _factName; } _fact = factGroup->getFact(nonEmptyFactName); } @@ -120,9 +113,6 @@ void InstrumentValueData::setFact(const QString& factGroupName, const QString& f if (_fact) { _factName = nonEmptyFactName; connect(_fact, &Fact::rawValueChanged, this, &InstrumentValueData::_updateRanges); - } else { - _factGroupName.clear(); - _factName.clear(); } emit factValueNamesChanged (); @@ -132,6 +122,13 @@ void InstrumentValueData::setFact(const QString& factGroupName, const QString& f _updateRanges(); } +void InstrumentValueData::setFact(const QString& factGroupName, const QString& factName) +{ + _factGroupName = factGroupName; + _factName = factName; + + _setFactWorker(); +} void InstrumentValueData::setText(const QString& text) { @@ -364,6 +361,8 @@ QStringList InstrumentValueData::factGroupNames(void) const QStringList InstrumentValueData::factValueNames(void) const { + QStringList valueNames; + FactGroup* factGroup = nullptr; if (_factGroupName == vehicleFactGroupName) { factGroup = _activeVehicle; @@ -371,9 +370,11 @@ QStringList InstrumentValueData::factValueNames(void) const factGroup = _activeVehicle->getFactGroup(_factGroupName); } - QStringList valueNames = factGroup->factNames(); - for (QString& name: valueNames) { - name[0] = name[0].toUpper(); + if (factGroup) { + valueNames = factGroup->factNames(); + for (QString& name: valueNames) { + name[0] = name[0].toUpper(); + } } return valueNames; diff --git a/src/QmlControls/InstrumentValueData.h b/src/QmlControls/InstrumentValueData.h index 4598d1b218608e701b3613632977001224e94b53..81436617f721e345faa7ed2d3ec604a253206846 100644 --- a/src/QmlControls/InstrumentValueData.h +++ b/src/QmlControls/InstrumentValueData.h @@ -105,12 +105,14 @@ private slots: void _resetRangeInfo (void); void _updateRanges (void); void _activeVehicleChanged (Vehicle* activeVehicle); + void _lookForMissingFact (void); private: int _currentRangeIndex (const QVariant& value); void _updateColor (void); void _updateIcon (void); void _updateOpacity (void); + void _setFactWorker (void); FactValueGrid* _factValueGrid = nullptr; Vehicle* _activeVehicle = nullptr; diff --git a/src/QmlControls/InstrumentValueEditDialog.qml b/src/QmlControls/InstrumentValueEditDialog.qml index def76a1088f5d5f10fa69325c466d7c54f6140a2..3cb33b83e5ba850ce540ee588959c1c61cac6ab7 100644 --- a/src/QmlControls/InstrumentValueEditDialog.qml +++ b/src/QmlControls/InstrumentValueEditDialog.qml @@ -27,169 +27,185 @@ QGCPopupDialog { property var instrumentValueData: dialogProperties.instrumentValueData - QGCPalette { id: qgcPal; colorGroupEnabled: parent.enabled } - QGCPalette { id: qgcPalDisabled; colorGroupEnabled: false } - - GridLayout { - rowSpacing: _margins - columnSpacing: _margins - columns: 2 - - QGCComboBox { - id: factGroupCombo - Layout.fillWidth: true - model: instrumentValueData.factGroupNames - sizeToContents: true - Component.onCompleted: currentIndex = find(instrumentValueData.factGroupName) - onActivated: { - instrumentValueData.setFact(currentText, "") - instrumentValueData.icon = "" - instrumentValueData.text = instrumentValueData.fact.shortDescription - } - Connections { - target: instrumentValueData - onFactGroupNameChanged: factGroupCombo.currentIndex = factGroupCombo.find(instrumentValueData.factGroupName) - } + QGCPalette { id: qgcPal; colorGroupEnabled: parent.enabled } + QGCPalette { id: qgcPalDisabled; colorGroupEnabled: false } + + Loader { + sourceComponent: instrumentValueData.fact ? editorComponent : noFactComponent + } + + Component { + id: noFactComponent + + QGCLabel { + text: qsTr("Valuec requires a connected vehicle for setup.") } + } - QGCComboBox { - id: factNamesCombo - Layout.fillWidth: true - model: instrumentValueData.factValueNames - sizeToContents: true - Component.onCompleted: currentIndex = find(instrumentValueData.factName) - onActivated: { - instrumentValueData.setFact(instrumentValueData.factGroupName, currentText) - instrumentValueData.icon = "" - instrumentValueData.text = instrumentValueData.fact.shortDescription - } - Connections { - target: instrumentValueData - onFactNameChanged: factNamesCombo.currentIndex = factNamesCombo.find(instrumentValueData.factName) + Component { + id: editorComponent + + GridLayout { + rowSpacing: _margins + columnSpacing: _margins + columns: 2 + + QGCComboBox { + id: factGroupCombo + Layout.fillWidth: true + model: instrumentValueData.factGroupNames + sizeToContents: true + Component.onCompleted: currentIndex = find(instrumentValueData.factGroupName) + onActivated: { + instrumentValueData.setFact(currentText, "") + instrumentValueData.icon = "" + instrumentValueData.text = instrumentValueData.fact.shortDescription + } + Connections { + target: instrumentValueData + onFactGroupNameChanged: factGroupCombo.currentIndex = factGroupCombo.find(instrumentValueData.factGroupName) + } } - } - QGCRadioButton { - id: iconRadio - text: qsTr("Icon") - Component.onCompleted: checked = instrumentValueData.icon != "" - onClicked: { - instrumentValueData.text = "" - instrumentValueData.icon = instrumentValueData.factValueGrid.iconNames[0] - var updateFunction = function(icon){ instrumentValueData.icon = icon } - mainWindow.showPopupDialogFromComponent(iconPickerDialog, { iconNames: instrumentValueData.factValueGrid.iconNames, icon: instrumentValueData.icon, updateIconFunction: updateFunction }) + QGCComboBox { + id: factNamesCombo + Layout.fillWidth: true + model: instrumentValueData.factValueNames + sizeToContents: true + Component.onCompleted: currentIndex = find(instrumentValueData.factName) + onActivated: { + instrumentValueData.setFact(instrumentValueData.factGroupName, currentText) + instrumentValueData.icon = "" + instrumentValueData.text = instrumentValueData.fact.shortDescription + } + Connections { + target: instrumentValueData + onFactNameChanged: factNamesCombo.currentIndex = factNamesCombo.find(instrumentValueData.factName) + } } - } - QGCColoredImage { - id: valueIcon - Layout.alignment: Qt.AlignHCenter - height: ScreenTools.implicitComboBoxHeight - width: height - source: "/InstrumentValueIcons/" + (instrumentValueData.icon ? instrumentValueData.icon : instrumentValueData.factValueGrid.iconNames[0]) - sourceSize.height: height - fillMode: Image.PreserveAspectFit - mipmap: true - smooth: true - color: enabled ? qgcPal.text : qgcPalDisabled.text - enabled: iconRadio.checked - - MouseArea { - anchors.fill: parent + QGCRadioButton { + id: iconRadio + text: qsTr("Icon") + Component.onCompleted: checked = instrumentValueData.icon != "" onClicked: { + instrumentValueData.text = "" + instrumentValueData.icon = instrumentValueData.factValueGrid.iconNames[0] var updateFunction = function(icon){ instrumentValueData.icon = icon } mainWindow.showPopupDialogFromComponent(iconPickerDialog, { iconNames: instrumentValueData.factValueGrid.iconNames, icon: instrumentValueData.icon, updateIconFunction: updateFunction }) } } - Rectangle { - anchors.fill: valueIcon - color: qgcPal.text - visible: valueIcon.status === Image.Error + QGCColoredImage { + id: valueIcon + Layout.alignment: Qt.AlignHCenter + height: ScreenTools.implicitComboBoxHeight + width: height + source: "/InstrumentValueIcons/" + (instrumentValueData.icon ? instrumentValueData.icon : instrumentValueData.factValueGrid.iconNames[0]) + sourceSize.height: height + fillMode: Image.PreserveAspectFit + mipmap: true + smooth: true + color: enabled ? qgcPal.text : qgcPalDisabled.text + enabled: iconRadio.checked + + MouseArea { + anchors.fill: parent + onClicked: { + var updateFunction = function(icon){ instrumentValueData.icon = icon } + mainWindow.showPopupDialogFromComponent(iconPickerDialog, { iconNames: instrumentValueData.factValueGrid.iconNames, icon: instrumentValueData.icon, updateIconFunction: updateFunction }) + } + } + + Rectangle { + anchors.fill: valueIcon + color: qgcPal.text + visible: valueIcon.status === Image.Error + } } - } - QGCRadioButton { - id: textRadio - text: qsTr("Text") - Component.onCompleted: checked = instrumentValueData.icon == "" - onClicked: { - instrumentValueData.icon = "" - instrumentValueData.text = instrumentValueData.fact ? instrumentValueData.fact.shortDescription : qsTr("Label") + QGCRadioButton { + id: textRadio + text: qsTr("Text") + Component.onCompleted: checked = instrumentValueData.icon == "" + onClicked: { + instrumentValueData.icon = "" + instrumentValueData.text = instrumentValueData.fact ? instrumentValueData.fact.shortDescription : qsTr("Label") + } } - } - QGCTextField { - id: labelTextField - Layout.fillWidth: true - Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 10 - text: instrumentValueData.text - enabled: textRadio.checked - onEditingFinished: instrumentValueData.text = text - } + QGCTextField { + id: labelTextField + Layout.fillWidth: true + Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 10 + text: instrumentValueData.text + enabled: textRadio.checked + onEditingFinished: instrumentValueData.text = text + } - QGCLabel { text: qsTr("Size") } + QGCLabel { text: qsTr("Size") } - QGCComboBox { - id: fontSizeCombo - Layout.fillWidth: true - model: instrumentValueData.factValueGrid.fontSizeNames - currentIndex: instrumentValueData.factValueGrid.fontSize - sizeToContents: true - onActivated: instrumentValueData.factValueGrid.fontSize = index - } + QGCComboBox { + id: fontSizeCombo + Layout.fillWidth: true + model: instrumentValueData.factValueGrid.fontSizeNames + currentIndex: instrumentValueData.factValueGrid.fontSize + sizeToContents: true + onActivated: instrumentValueData.factValueGrid.fontSize = index + } - QGCCheckBox { - Layout.columnSpan: 2 - text: qsTr("Show Units") - checked: instrumentValueData.showUnits - onClicked: instrumentValueData.showUnits = checked - } + QGCCheckBox { + Layout.columnSpan: 2 + text: qsTr("Show Units") + checked: instrumentValueData.showUnits + onClicked: instrumentValueData.showUnits = checked + } - QGCLabel { text: qsTr("Range") } + QGCLabel { text: qsTr("Range") } - QGCComboBox { - id: rangeTypeCombo - Layout.fillWidth: true - model: instrumentValueData.rangeTypeNames - currentIndex: instrumentValueData.rangeType - sizeToContents: true - onActivated: instrumentValueData.rangeType = index - } + QGCComboBox { + id: rangeTypeCombo + Layout.fillWidth: true + model: instrumentValueData.rangeTypeNames + currentIndex: instrumentValueData.rangeType + sizeToContents: true + onActivated: instrumentValueData.rangeType = index + } - Loader { - id: rangeLoader - Layout.columnSpan: 2 - Layout.fillWidth: true - Layout.preferredWidth: item ? item.width : 0 - Layout.preferredHeight: item ? item.height : 0 - - property var instrumentValueData: root.instrumentValueData - - function updateSourceComponent() { - switch (instrumentValueData.rangeType) { - case InstrumentValueData.NoRangeInfo: - sourceComponent = undefined - break - case InstrumentValueData.ColorRange: - sourceComponent = colorRangeDialog - break - case InstrumentValueData.OpacityRange: - sourceComponent = opacityRangeDialog - break - case InstrumentValueData.IconSelectRange: - sourceComponent = iconRangeDialog - break + Loader { + id: rangeLoader + Layout.columnSpan: 2 + Layout.fillWidth: true + Layout.preferredWidth: item ? item.width : 0 + Layout.preferredHeight: item ? item.height : 0 + + property var instrumentValueData: root.instrumentValueData + + function updateSourceComponent() { + switch (instrumentValueData.rangeType) { + case InstrumentValueData.NoRangeInfo: + sourceComponent = undefined + break + case InstrumentValueData.ColorRange: + sourceComponent = colorRangeDialog + break + case InstrumentValueData.OpacityRange: + sourceComponent = opacityRangeDialog + break + case InstrumentValueData.IconSelvalueedectRange: + sourceComponent = iconRangeDialog + break + } } - } - Component.onCompleted: updateSourceComponent() + Component.onCompleted: updateSourceComponent() - Connections { - target: instrumentValueData - onRangeTypeChanged: rangeLoader.updateSourceComponent() - } + Connections { + target: instrumentValueData + onRangeTypeChanged: rangeLoader.updateSourceComponent() + } + } } } @@ -313,7 +329,7 @@ QGCPopupDialog { id: iconRangeDialog Item { - width: childrenRect.width + width: childrenRect.widthvalueed height: childrenRect.height function updateRangeValue(index, text) { @@ -545,4 +561,3 @@ QGCPopupDialog { } } } - diff --git a/src/QmlControls/InstrumentValueValue.qml b/src/QmlControls/InstrumentValueValue.qml index 535fffe6d57adae04b6fcfce13806be0b6b5aa07..2d8e107606a6e3001b191aa305aeaf4bb2a1d03f 100644 --- a/src/QmlControls/InstrumentValueValue.qml +++ b/src/QmlControls/InstrumentValueValue.qml @@ -23,7 +23,6 @@ ColumnLayout { property bool settingsUnlocked: false 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 _rgFontSizeRatios: [ 1, ScreenTools.smallFontPointRatio, ScreenTools.mediumFontPointRatio, ScreenTools.largeFontPointRatio ] property real _doubleDescent: ScreenTools.defaultFontDescent * 2 @@ -32,17 +31,21 @@ ColumnLayout { property real _tightHeight: _rgFontSizeTightHeights[instrumentValueData.factValueGrid.fontSize] property real _fontSize: _rgFontSizes[instrumentValueData.factValueGrid.fontSize] property real _horizontalLabelSpacing: ScreenTools.defaultFontPixelWidth - property bool _valueVisible: instrumentValueData.fact property real _width: 0 property real _height: 0 QGCLabel { id: label - Layout.alignment: _verticalOrientation ? Qt.AlignHCenter : Qt.AlignVCenter + Layout.alignment: Qt.AlignVCenter font.pointSize: _fontSize - text: instrumentValueData.fact.enumOrValueString + (instrumentValueData.showUnits ? " " + instrumentValueData.fact.units : "") - visible: _valueVisible + text: valueText() - QGCPalette { id: qgcPal; colorGroupEnabled: enabled } + function valueText() { + if (instrumentValueData.fact) { + return instrumentValueData.fact.enumOrValueString + (instrumentValueData.showUnits ? " " + instrumentValueData.fact.units : "") + } else { + return qsTr("--.--") + } + } } }