7 changed files with 1100 additions and 339 deletions
@ -0,0 +1,510 @@ |
|||||||
|
/****************************************************************************
|
||||||
|
* |
||||||
|
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||||
|
* |
||||||
|
* QGroundControl is licensed according to the terms in the file |
||||||
|
* COPYING.md in the root of the source code directory. |
||||||
|
* |
||||||
|
****************************************************************************/ |
||||||
|
|
||||||
|
|
||||||
|
#include "InstrumentValue.h" |
||||||
|
#include "QGCApplication.h" |
||||||
|
#include "QGCCorePlugin.h" |
||||||
|
|
||||||
|
#include <QSettings> |
||||||
|
|
||||||
|
const char* InstrumentValue::_versionKey = "version"; |
||||||
|
const char* InstrumentValue::_factGroupNameKey = "groupName"; |
||||||
|
const char* InstrumentValue::_factNameKey = "factName"; |
||||||
|
const char* InstrumentValue::_labelKey = "label"; |
||||||
|
const char* InstrumentValue::_fontSizeKey = "fontSize"; |
||||||
|
const char* InstrumentValue::_showUnitsKey = "showUnits"; |
||||||
|
const char* InstrumentValue::_iconKey = "icon"; |
||||||
|
const char* InstrumentValue::_iconPositionKey = "iconPosition"; |
||||||
|
const char* InstrumentValue::_rangeTypeKey = "rangeType"; |
||||||
|
const char* InstrumentValue::_rangeValuesKey = "rangeValues"; |
||||||
|
const char* InstrumentValue::_rangeColorsKey = "rangeColors"; |
||||||
|
const char* InstrumentValue::_rangeIconsKey = "rangeIcons"; |
||||||
|
const char* InstrumentValue::_rangeOpacitiesKey = "rangeOpacities"; |
||||||
|
const char* InstrumentValue::_vehicleFactGroupName = "Vehicle"; |
||||||
|
|
||||||
|
QStringList InstrumentValue::_iconNames; |
||||||
|
|
||||||
|
// Important: The indices of these strings must match the InstrumentValue::IconPosition enumconst QStringList InstrumentValue::_iconPositionNames
|
||||||
|
const QStringList InstrumentValue::_iconPositionNames = { |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "Above"), |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "Left"), |
||||||
|
}; |
||||||
|
|
||||||
|
// Important: The indices of these strings must match the InstrumentValue::FontSize enum
|
||||||
|
const QStringList InstrumentValue::_fontSizeNames = { |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "Default"), |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "Small"), |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "Medium"), |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "Large"), |
||||||
|
}; |
||||||
|
|
||||||
|
// Important: The indices of these strings must match the InstrumentValue::RangeType enum
|
||||||
|
const QStringList InstrumentValue::_rangeTypeNames = { |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "None"), |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "Color"), |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "Opacity"), |
||||||
|
QT_TRANSLATE_NOOP("InstrumentValue", "Icon"), |
||||||
|
}; |
||||||
|
|
||||||
|
InstrumentValue::InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlObjectListModel* rowModel) |
||||||
|
: QObject (rowModel) |
||||||
|
, _activeVehicle(activeVehicle) |
||||||
|
, _rowModel (rowModel) |
||||||
|
, _fontSize (fontSize) |
||||||
|
{ |
||||||
|
if (_iconNames.isEmpty()) { |
||||||
|
QDir iconDir(":/InstrumentValueIcons/"); |
||||||
|
_iconNames = iconDir.entryList(); |
||||||
|
} |
||||||
|
|
||||||
|
activeVehicleChanged(_activeVehicle); |
||||||
|
|
||||||
|
connect(this, &InstrumentValue::rangeTypeChanged, this, &InstrumentValue::_resetRangeInfo); |
||||||
|
connect(this, &InstrumentValue::rangeTypeChanged, this, &InstrumentValue::_updateRanges); |
||||||
|
connect(this, &InstrumentValue::rangeValuesChanged, this, &InstrumentValue::_updateRanges); |
||||||
|
connect(this, &InstrumentValue::rangeColorsChanged, this, &InstrumentValue::_updateRanges); |
||||||
|
connect(this, &InstrumentValue::rangeOpacitiesChanged, this, &InstrumentValue::_updateRanges); |
||||||
|
connect(this, &InstrumentValue::rangeIconsChanged, this, &InstrumentValue::_updateRanges); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::activeVehicleChanged(Vehicle* activeVehicle) |
||||||
|
{ |
||||||
|
if (_fact) { |
||||||
|
disconnect(_fact, &Fact::rawValueChanged, this, &InstrumentValue::_updateColor); |
||||||
|
} |
||||||
|
|
||||||
|
_activeVehicle = activeVehicle; |
||||||
|
|
||||||
|
_factGroupNames.clear(); |
||||||
|
_factGroupNames = _activeVehicle->factGroupNames(); |
||||||
|
for (QString& name: _factGroupNames) { |
||||||
|
name[0] = name[0].toUpper(); |
||||||
|
} |
||||||
|
_factGroupNames.prepend(_vehicleFactGroupName); |
||||||
|
emit factGroupNamesChanged(_factGroupNames); |
||||||
|
|
||||||
|
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, &InstrumentValue::_updateRanges); |
||||||
|
} |
||||||
|
|
||||||
|
_updateRanges(); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setFact(const QString& factGroupName, const QString& factName) |
||||||
|
{ |
||||||
|
if (_fact) { |
||||||
|
disconnect(_fact, &Fact::rawValueChanged, this, &InstrumentValue::_updateRanges); |
||||||
|
_fact = nullptr; |
||||||
|
} |
||||||
|
|
||||||
|
FactGroup* factGroup = nullptr; |
||||||
|
if (factGroupName == _vehicleFactGroupName) { |
||||||
|
factGroup = _activeVehicle; |
||||||
|
} else { |
||||||
|
factGroup = _activeVehicle->getFactGroup(factGroupName); |
||||||
|
} |
||||||
|
|
||||||
|
_factValueNames.clear(); |
||||||
|
_factValueNames = factGroup->factNames(); |
||||||
|
for (QString& name: _factValueNames) { |
||||||
|
name[0] = name[0].toUpper(); |
||||||
|
} |
||||||
|
|
||||||
|
QString nonEmptyFactName; |
||||||
|
if (factGroup) { |
||||||
|
if (factName.isEmpty()) { |
||||||
|
nonEmptyFactName = _factValueNames[0]; |
||||||
|
} else { |
||||||
|
nonEmptyFactName = factName; |
||||||
|
} |
||||||
|
_fact = factGroup->getFact(nonEmptyFactName); |
||||||
|
} |
||||||
|
|
||||||
|
if (_fact) { |
||||||
|
_factGroupName = factGroupName; |
||||||
|
_factName = nonEmptyFactName; |
||||||
|
|
||||||
|
connect(_fact, &Fact::rawValueChanged, this, &InstrumentValue::_updateRanges); |
||||||
|
} else { |
||||||
|
_factName.clear(); |
||||||
|
_factGroupName.clear(); |
||||||
|
} |
||||||
|
|
||||||
|
emit factChanged (_fact); |
||||||
|
emit factNameChanged (_factName); |
||||||
|
emit factGroupNameChanged (_factGroupName); |
||||||
|
emit factValueNamesChanged (_factValueNames); |
||||||
|
|
||||||
|
_updateRanges(); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::_setFontSize(FontSize fontSize) |
||||||
|
{ |
||||||
|
if (fontSize != _fontSize) { |
||||||
|
_fontSize = fontSize; |
||||||
|
emit fontSizeChanged(fontSize); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setFontSize(FontSize fontSize) |
||||||
|
{ |
||||||
|
_setFontSize(fontSize); |
||||||
|
|
||||||
|
// All other items in row must change to match
|
||||||
|
for (int i=0; i<_rowModel->count(); i++) { |
||||||
|
InstrumentValue* instrumentValue = _rowModel->value<InstrumentValue*>(i); |
||||||
|
if (instrumentValue != this) { |
||||||
|
instrumentValue->_setFontSize(fontSize); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::saveToSettings(QSettings& settings) const |
||||||
|
{ |
||||||
|
settings.setValue(_versionKey, 1); |
||||||
|
settings.setValue(_labelKey, _label); |
||||||
|
settings.setValue(_fontSizeKey, _fontSize); |
||||||
|
settings.setValue(_showUnitsKey, _showUnits); |
||||||
|
settings.setValue(_iconKey, _icon); |
||||||
|
settings.setValue(_iconPositionKey, _iconPosition); |
||||||
|
settings.setValue(_rangeTypeKey, _rangeType); |
||||||
|
|
||||||
|
if (_rangeType != NoRangeInfo) { |
||||||
|
settings.setValue(_rangeValuesKey, _rangeValues); |
||||||
|
} |
||||||
|
|
||||||
|
switch (_rangeType) { |
||||||
|
case NoRangeInfo: |
||||||
|
break; |
||||||
|
case ColorRange: |
||||||
|
settings.setValue(_rangeColorsKey, _rangeColors); |
||||||
|
break; |
||||||
|
case OpacityRange: |
||||||
|
settings.setValue(_rangeOpacitiesKey, _rangeOpacities); |
||||||
|
break; |
||||||
|
case IconSelectRange: |
||||||
|
settings.setValue(_rangeIconsKey, _rangeIcons); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
if (_fact) { |
||||||
|
settings.setValue(_factGroupNameKey, _factGroupName); |
||||||
|
settings.setValue(_factNameKey, _factName); |
||||||
|
} else { |
||||||
|
settings.setValue(_factGroupNameKey, ""); |
||||||
|
settings.setValue(_factNameKey, ""); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::readFromSettings(const QSettings& settings) |
||||||
|
{ |
||||||
|
_factGroupName = settings.value(_factGroupNameKey, QString()).toString(); |
||||||
|
_label = settings.value(_labelKey, QString()).toString(); |
||||||
|
_fontSize = settings.value(_fontSizeKey, DefaultFontSize).value<FontSize>(); |
||||||
|
_showUnits = settings.value(_showUnitsKey, true).toBool(); |
||||||
|
_icon = settings.value(_iconKey, QString()).toString(); |
||||||
|
_iconPosition = settings.value(_iconPositionKey, IconLeft).value<IconPosition>(); |
||||||
|
_rangeType = settings.value(_rangeTypeKey, NoRangeInfo).value<RangeType>(); |
||||||
|
|
||||||
|
// Do this now, since the signal will cause _resetRangeInfo to be called trashing values
|
||||||
|
emit rangeTypeChanged(_rangeType); |
||||||
|
|
||||||
|
_rangeValues.clear(); |
||||||
|
_rangeColors.clear(); |
||||||
|
_rangeOpacities.clear(); |
||||||
|
_rangeIcons.clear(); |
||||||
|
if (_rangeType != NoRangeInfo) { |
||||||
|
_rangeValues = settings.value(_rangeValuesKey).value<QVariantList>(); |
||||||
|
} |
||||||
|
switch (_rangeType) { |
||||||
|
case NoRangeInfo: |
||||||
|
break; |
||||||
|
case ColorRange: |
||||||
|
_rangeColors = settings.value(_rangeColorsKey).value<QVariantList>(); |
||||||
|
break; |
||||||
|
case OpacityRange: |
||||||
|
_rangeOpacities = settings.value(_rangeOpacitiesKey).value<QVariantList>(); |
||||||
|
break; |
||||||
|
case IconSelectRange: |
||||||
|
_rangeIcons = settings.value(_rangeIconsKey).value<QVariantList>(); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
QString factName = settings.value(_factNameKey).toString(); |
||||||
|
if (!factName.isEmpty()) { |
||||||
|
setFact(_factGroupName, factName); |
||||||
|
} |
||||||
|
|
||||||
|
emit factChanged (_fact); |
||||||
|
emit factGroupNameChanged (_factGroupName); |
||||||
|
emit labelChanged (_label); |
||||||
|
emit fontSizeChanged (_fontSize); |
||||||
|
emit showUnitsChanged (_showUnits); |
||||||
|
emit iconChanged (_icon); |
||||||
|
emit iconPositionChanged (_iconPosition); |
||||||
|
emit rangeValuesChanged (_rangeValues); |
||||||
|
emit rangeColorsChanged (_rangeColors); |
||||||
|
emit rangeOpacitiesChanged (_rangeOpacities); |
||||||
|
emit rangeIconsChanged (_rangeIcons); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setLabel(const QString& label) |
||||||
|
{ |
||||||
|
if (label != _label) { |
||||||
|
_label = label; |
||||||
|
emit labelChanged(label); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setShowUnits(bool showUnits) |
||||||
|
{ |
||||||
|
if (showUnits != _showUnits) { |
||||||
|
_showUnits = showUnits; |
||||||
|
emit showUnitsChanged(showUnits); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::clearFact(void) |
||||||
|
{ |
||||||
|
_fact = nullptr; |
||||||
|
_factGroupName.clear(); |
||||||
|
_label.clear(); |
||||||
|
_icon.clear(); |
||||||
|
_showUnits = true; |
||||||
|
|
||||||
|
emit factChanged (_fact); |
||||||
|
emit factGroupNameChanged (_factGroupName); |
||||||
|
emit labelChanged (_label); |
||||||
|
emit iconChanged (_icon); |
||||||
|
emit showUnitsChanged (_showUnits); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setIcon(const QString& icon) |
||||||
|
{ |
||||||
|
if (icon != _icon) { |
||||||
|
_icon = icon; |
||||||
|
emit iconChanged(_icon); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setIconPosition(IconPosition iconPosition) |
||||||
|
{ |
||||||
|
if (iconPosition != _iconPosition) { |
||||||
|
_iconPosition = iconPosition; |
||||||
|
emit iconPositionChanged(iconPosition); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setRangeType(RangeType rangeType) |
||||||
|
{ |
||||||
|
if (rangeType != _rangeType) { |
||||||
|
_rangeType = rangeType; |
||||||
|
emit rangeTypeChanged(rangeType); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setRangeValues(const QVariantList& rangeValues) |
||||||
|
{ |
||||||
|
_rangeValues = rangeValues; |
||||||
|
emit rangeValuesChanged(rangeValues); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setRangeColors (const QVariantList& rangeColors) |
||||||
|
{ |
||||||
|
_rangeColors = rangeColors; |
||||||
|
emit rangeColorsChanged(rangeColors); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setRangeIcons(const QVariantList& rangeIcons) |
||||||
|
{ |
||||||
|
_rangeIcons = rangeIcons; |
||||||
|
emit rangeIconsChanged(rangeIcons); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::setRangeOpacities(const QVariantList& rangeOpacities) |
||||||
|
{ |
||||||
|
_rangeOpacities = rangeOpacities; |
||||||
|
emit rangeOpacitiesChanged(rangeOpacities); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::_resetRangeInfo(void) |
||||||
|
{ |
||||||
|
_rangeValues.clear(); |
||||||
|
_rangeColors.clear(); |
||||||
|
_rangeOpacities.clear(); |
||||||
|
_rangeIcons.clear(); |
||||||
|
|
||||||
|
if (_rangeType != NoRangeInfo) { |
||||||
|
_rangeValues = { 0.0, 100.0 }; |
||||||
|
} |
||||||
|
for (int i=0; i<_rangeValues.count() + 1; i++) { |
||||||
|
switch (_rangeType) { |
||||||
|
case NoRangeInfo: |
||||||
|
break; |
||||||
|
case ColorRange: |
||||||
|
_rangeColors.append(QColor("green")); |
||||||
|
break; |
||||||
|
case OpacityRange: |
||||||
|
_rangeOpacities.append(1.0); |
||||||
|
break; |
||||||
|
case IconSelectRange: |
||||||
|
_rangeIcons.append(_iconNames[0]); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
emit rangeValuesChanged (_rangeValues); |
||||||
|
emit rangeColorsChanged (_rangeColors); |
||||||
|
emit rangeOpacitiesChanged (_rangeOpacities); |
||||||
|
emit rangeIconsChanged (_rangeIcons); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::addRangeValue(void) |
||||||
|
{ |
||||||
|
_rangeValues.append(_rangeValues.last().toDouble() + 1); |
||||||
|
|
||||||
|
switch (_rangeType) { |
||||||
|
case NoRangeInfo: |
||||||
|
break; |
||||||
|
case ColorRange: |
||||||
|
_rangeColors.append(QColor("green")); |
||||||
|
break; |
||||||
|
case OpacityRange: |
||||||
|
_rangeOpacities.append(1.0); |
||||||
|
break; |
||||||
|
case IconSelectRange: |
||||||
|
_rangeIcons.append(_iconNames[0]); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
emit rangeValuesChanged (_rangeValues); |
||||||
|
emit rangeColorsChanged (_rangeColors); |
||||||
|
emit rangeOpacitiesChanged (_rangeOpacities); |
||||||
|
emit rangeIconsChanged (_rangeIcons); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::removeRangeValue(int index) |
||||||
|
{ |
||||||
|
if (_rangeValues.count() < 2 || index <0 || index >= _rangeValues.count()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
_rangeValues.removeAt(index); |
||||||
|
|
||||||
|
switch (_rangeType) { |
||||||
|
case NoRangeInfo: |
||||||
|
break; |
||||||
|
case ColorRange: |
||||||
|
_rangeColors.removeAt(index + 1); |
||||||
|
break; |
||||||
|
case OpacityRange: |
||||||
|
_rangeOpacities.removeAt(index + 1); |
||||||
|
break; |
||||||
|
case IconSelectRange: |
||||||
|
_rangeIcons.removeAt(index + 1); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
emit rangeValuesChanged (_rangeValues); |
||||||
|
emit rangeColorsChanged (_rangeColors); |
||||||
|
emit rangeOpacitiesChanged (_rangeOpacities); |
||||||
|
emit rangeIconsChanged (_rangeIcons); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::_updateRanges(void) |
||||||
|
{ |
||||||
|
_updateColor(); |
||||||
|
_updateIcon(); |
||||||
|
_updateOpacity(); |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::_updateColor(void) |
||||||
|
{ |
||||||
|
QColor newColor; |
||||||
|
|
||||||
|
int rangeIndex = -1; |
||||||
|
|
||||||
|
if (_rangeType == ColorRange && _fact) { |
||||||
|
rangeIndex =_currentRangeIndex(_fact->rawValue().toDouble()); |
||||||
|
} |
||||||
|
if (rangeIndex != -1) { |
||||||
|
newColor = _rangeColors[rangeIndex].value<QColor>(); |
||||||
|
} |
||||||
|
|
||||||
|
if (newColor != _currentColor) { |
||||||
|
_currentColor = newColor; |
||||||
|
emit currentColorChanged(_currentColor); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::_updateOpacity(void) |
||||||
|
{ |
||||||
|
double newOpacity = 1.0; |
||||||
|
|
||||||
|
int rangeIndex = -1; |
||||||
|
|
||||||
|
if (_rangeType == OpacityRange && _fact) { |
||||||
|
rangeIndex =_currentRangeIndex(_fact->rawValue().toDouble()); |
||||||
|
} |
||||||
|
if (rangeIndex != -1) { |
||||||
|
newOpacity = _rangeOpacities[rangeIndex].toDouble(); |
||||||
|
} |
||||||
|
|
||||||
|
if (!qFuzzyCompare(newOpacity, _currentOpacity)) { |
||||||
|
_currentOpacity = newOpacity; |
||||||
|
emit currentOpacityChanged(newOpacity); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void InstrumentValue::_updateIcon(void) |
||||||
|
{ |
||||||
|
QString newIcon; |
||||||
|
|
||||||
|
int rangeIndex = -1; |
||||||
|
|
||||||
|
if (_rangeType == IconSelectRange && _fact) { |
||||||
|
rangeIndex =_currentRangeIndex(_fact->rawValue().toDouble()); |
||||||
|
} |
||||||
|
if (rangeIndex != -1) { |
||||||
|
newIcon = _rangeIcons[rangeIndex].toString(); |
||||||
|
} |
||||||
|
|
||||||
|
if (newIcon != _currentIcon) { |
||||||
|
_currentIcon = newIcon; |
||||||
|
emit currentIconChanged(newIcon); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int InstrumentValue::_currentRangeIndex(const QVariant& value) |
||||||
|
{ |
||||||
|
if (qIsNaN(value.toDouble())) { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
for (int i=0; i<_rangeValues.count(); i++) { |
||||||
|
if (value.toDouble() <= _rangeValues[i].toDouble()) { |
||||||
|
return i; |
||||||
|
} |
||||||
|
} |
||||||
|
return _rangeValues.count(); |
||||||
|
} |
@ -0,0 +1,187 @@ |
|||||||
|
/****************************************************************************
|
||||||
|
* |
||||||
|
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||||
|
* |
||||||
|
* QGroundControl is licensed according to the terms in the file |
||||||
|
* COPYING.md in the root of the source code directory. |
||||||
|
* |
||||||
|
****************************************************************************/ |
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "FactSystem.h" |
||||||
|
#include "QmlObjectListModel.h" |
||||||
|
#include "QGCApplication.h" |
||||||
|
|
||||||
|
#include <QObject> |
||||||
|
|
||||||
|
class InstrumentValue : public QObject |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
enum FontSize { |
||||||
|
DefaultFontSize=0, |
||||||
|
SmallFontSize, |
||||||
|
MediumFontSize, |
||||||
|
LargeFontSize, |
||||||
|
}; |
||||||
|
Q_ENUMS(FontSize) |
||||||
|
|
||||||
|
enum IconPosition { |
||||||
|
IconAbove = 0, |
||||||
|
IconLeft, |
||||||
|
}; |
||||||
|
Q_ENUMS(IconPosition) |
||||||
|
|
||||||
|
enum RangeType { |
||||||
|
NoRangeInfo = 0, |
||||||
|
ColorRange, |
||||||
|
OpacityRange, |
||||||
|
IconSelectRange, |
||||||
|
}; |
||||||
|
Q_ENUMS(RangeType) |
||||||
|
|
||||||
|
InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlObjectListModel* rowModel); |
||||||
|
|
||||||
|
Q_PROPERTY(QStringList factGroupNames MEMBER _factGroupNames NOTIFY factGroupNamesChanged) |
||||||
|
Q_PROPERTY(QStringList factValueNames MEMBER _factValueNames NOTIFY factValueNamesChanged) |
||||||
|
Q_PROPERTY(QString factGroupName MEMBER _factGroupName NOTIFY factGroupNameChanged) |
||||||
|
Q_PROPERTY(QString factName MEMBER _factName NOTIFY factNameChanged) |
||||||
|
Q_PROPERTY(Fact* fact READ fact NOTIFY factChanged) |
||||||
|
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) |
||||||
|
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged) ///< If !isEmpty icon will be show instead of label
|
||||||
|
Q_PROPERTY(IconPosition iconPosition READ iconPosition WRITE setIconPosition NOTIFY iconPositionChanged) |
||||||
|
Q_PROPERTY(QStringList iconPositionNames MEMBER _iconPositionNames CONSTANT) |
||||||
|
Q_PROPERTY(QStringList iconNames MEMBER _iconNames CONSTANT) |
||||||
|
Q_PROPERTY(FontSize fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) |
||||||
|
Q_PROPERTY(QStringList fontSizeNames MEMBER _fontSizeNames CONSTANT) |
||||||
|
Q_PROPERTY(bool showUnits READ showUnits WRITE setShowUnits NOTIFY showUnitsChanged) |
||||||
|
Q_PROPERTY(QStringList rangeTypeNames MEMBER _rangeTypeNames CONSTANT) |
||||||
|
Q_PROPERTY(RangeType rangeType READ rangeType WRITE setRangeType NOTIFY rangeTypeChanged) |
||||||
|
Q_PROPERTY(QVariantList rangeValues READ rangeValues WRITE setRangeValues NOTIFY rangeValuesChanged) |
||||||
|
Q_PROPERTY(QVariantList rangeColors READ rangeColors WRITE setRangeColors NOTIFY rangeColorsChanged) |
||||||
|
Q_PROPERTY(QVariantList rangeIcons READ rangeIcons WRITE setRangeIcons NOTIFY rangeIconsChanged) |
||||||
|
Q_PROPERTY(QVariantList rangeOpacities READ rangeOpacities WRITE setRangeOpacities NOTIFY rangeOpacitiesChanged) |
||||||
|
Q_PROPERTY(QColor currentColor MEMBER _currentColor NOTIFY currentColorChanged) |
||||||
|
Q_PROPERTY(double currentOpacity MEMBER _currentOpacity NOTIFY currentOpacityChanged) |
||||||
|
Q_PROPERTY(QString currentIcon MEMBER _currentIcon NOTIFY currentIconChanged) |
||||||
|
|
||||||
|
Q_INVOKABLE void setFact (const QString& factGroupName, const QString& factName); |
||||||
|
Q_INVOKABLE void clearFact (void); |
||||||
|
Q_INVOKABLE bool isValidColor (const QColor& color) { return color.isValid(); } |
||||||
|
Q_INVOKABLE QColor invalidColor (void) { return QColor(); } |
||||||
|
Q_INVOKABLE void addRangeValue (void); |
||||||
|
Q_INVOKABLE void removeRangeValue(int index); |
||||||
|
|
||||||
|
Fact* fact (void) { return _fact; } |
||||||
|
FontSize fontSize (void) const { return _fontSize; } |
||||||
|
QString label (void) const { return _label; } |
||||||
|
bool showUnits (void) const { return _showUnits; } |
||||||
|
QString icon (void) const { return _icon; } |
||||||
|
IconPosition iconPosition (void) const { return _iconPosition; } |
||||||
|
RangeType rangeType (void) const { return _rangeType; } |
||||||
|
QVariantList rangeValues (void) const { return _rangeValues; } |
||||||
|
QVariantList rangeColors (void) const { return _rangeColors; } |
||||||
|
QVariantList rangeIcons (void) const { return _rangeIcons; } |
||||||
|
QVariantList rangeOpacities (void) const { return _rangeOpacities; } |
||||||
|
void setFontSize (FontSize fontSize); |
||||||
|
void setLabel (const QString& label); |
||||||
|
void setShowUnits (bool showUnits); |
||||||
|
void setIcon (const QString& icon); |
||||||
|
void setIconPosition (IconPosition iconPosition); |
||||||
|
void setRangeType (RangeType rangeType); |
||||||
|
void setRangeValues (const QVariantList& rangeValues); |
||||||
|
void setRangeColors (const QVariantList& rangeColors); |
||||||
|
void setRangeIcons (const QVariantList& rangeIcons); |
||||||
|
void setRangeOpacities (const QVariantList& rangeOpacities); |
||||||
|
void activeVehicleChanged (Vehicle* activeVehicle); |
||||||
|
void saveToSettings (QSettings& settings) const; |
||||||
|
void readFromSettings (const QSettings& settings); |
||||||
|
|
||||||
|
signals: |
||||||
|
void factChanged (Fact* fact); |
||||||
|
void factNameChanged (const QString& factName); |
||||||
|
void factGroupNameChanged (const QString& factGroup); |
||||||
|
void labelChanged (QString label); |
||||||
|
void fontSizeChanged (FontSize fontSize); |
||||||
|
void showUnitsChanged (bool showUnits); |
||||||
|
void iconChanged (const QString& icon); |
||||||
|
void iconPositionChanged (IconPosition iconPosition); |
||||||
|
void factGroupNamesChanged (const QStringList& factGroupNames); |
||||||
|
void factValueNamesChanged (const QStringList& factValueNames); |
||||||
|
void rangeTypeChanged (RangeType rangeType); |
||||||
|
void rangeValuesChanged (const QVariantList& rangeValues); |
||||||
|
void rangeColorsChanged (const QVariantList& rangeColors); |
||||||
|
void rangeIconsChanged (const QVariantList& rangeIcons); |
||||||
|
void rangeOpacitiesChanged (const QVariantList& rangeOpacities); |
||||||
|
void currentColorChanged (const QColor& currentColor); |
||||||
|
void currentOpacityChanged (double currentOpacity); |
||||||
|
void currentIconChanged (const QString& currentIcon); |
||||||
|
|
||||||
|
private slots: |
||||||
|
void _resetRangeInfo (void); |
||||||
|
void _updateRanges (void); |
||||||
|
|
||||||
|
private: |
||||||
|
void _setFontSize (FontSize fontSize); |
||||||
|
int _currentRangeIndex (const QVariant& value); |
||||||
|
void _updateColor (void); |
||||||
|
void _updateIcon (void); |
||||||
|
void _updateOpacity (void); |
||||||
|
|
||||||
|
Vehicle* _activeVehicle = nullptr; |
||||||
|
QmlObjectListModel* _rowModel = nullptr; |
||||||
|
Fact* _fact = nullptr; |
||||||
|
QString _factName; |
||||||
|
QString _factGroupName; |
||||||
|
QString _label; |
||||||
|
bool _showUnits = true; |
||||||
|
FontSize _fontSize = DefaultFontSize; |
||||||
|
QString _icon; |
||||||
|
IconPosition _iconPosition = IconLeft; |
||||||
|
QStringList _factGroupNames; |
||||||
|
QStringList _factValueNames; |
||||||
|
QColor _currentColor; |
||||||
|
double _currentOpacity = 1.0; |
||||||
|
QString _currentIcon; |
||||||
|
|
||||||
|
// Ranges allow you to specifiy semantics to apply when a value is within a certain range.
|
||||||
|
// The limits for each section of the range are specified in _rangeValues. With the first
|
||||||
|
// element indicating a range from that value to -infinity and the last element indicating
|
||||||
|
// a range from the value to +infinity.
|
||||||
|
//
|
||||||
|
// The semantics to apply are defined by the _rangeType value. With the semantic lists having
|
||||||
|
// a specific value for each section of the range. There should be _rangeValues.count() + 2
|
||||||
|
// semantic values in the apppropriate list.
|
||||||
|
RangeType _rangeType = NoRangeInfo; |
||||||
|
QVariantList _rangeValues; ///< double values which indicate range setpoints
|
||||||
|
QVariantList _rangeColors; ///< QColor
|
||||||
|
QVariantList _rangeIcons; ///< QString resource name
|
||||||
|
QVariantList _rangeOpacities; /// double opacity value
|
||||||
|
|
||||||
|
// These are user facing string for the various enums.
|
||||||
|
static const QStringList _rangeTypeNames; |
||||||
|
static const QStringList _iconPositionNames; |
||||||
|
static QStringList _iconNames; |
||||||
|
static const QStringList _fontSizeNames; |
||||||
|
|
||||||
|
static const char* _versionKey; |
||||||
|
static const char* _factGroupNameKey; |
||||||
|
static const char* _factNameKey; |
||||||
|
static const char* _labelKey; |
||||||
|
static const char* _fontSizeKey; |
||||||
|
static const char* _showUnitsKey; |
||||||
|
static const char* _iconKey; |
||||||
|
static const char* _iconPositionKey; |
||||||
|
static const char* _rangeTypeKey; |
||||||
|
static const char* _rangeValuesKey; |
||||||
|
static const char* _rangeColorsKey; |
||||||
|
static const char* _rangeIconsKey; |
||||||
|
static const char* _rangeOpacitiesKey; |
||||||
|
static const char* _vehicleFactGroupName; |
||||||
|
}; |
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(InstrumentValue::FontSize) |
||||||
|
Q_DECLARE_METATYPE(InstrumentValue::IconPosition) |
||||||
|
Q_DECLARE_METATYPE(InstrumentValue::RangeType) |
Loading…
Reference in new issue