Commit 8cf5f75c authored by DoinLakeFlyer's avatar DoinLakeFlyer

parent 1aba5c4b
......@@ -65,11 +65,21 @@ InstrumentValue::InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlO
}
activeVehicleChanged(_activeVehicle);
connect(this, &InstrumentValue::rangeTypeChanged, this, &InstrumentValue::_resetRangeInfo);
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();
......@@ -94,12 +104,17 @@ void InstrumentValue::activeVehicleChanged(Vehicle* activeVehicle)
_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;
}
......@@ -129,6 +144,8 @@ void InstrumentValue::setFact(const QString& factGroupName, const QString& factN
if (_fact) {
_factGroupName = factGroupName;
_factName = nonEmptyFactName;
connect(_fact, &Fact::rawValueChanged, this, &InstrumentValue::_updateRanges);
} else {
_factName.clear();
_factGroupName.clear();
......@@ -138,6 +155,8 @@ void InstrumentValue::setFact(const QString& factGroupName, const QString& factN
emit factNameChanged (_factName);
emit factGroupNameChanged (_factGroupName);
emit factValueNamesChanged (_factValueNames);
_updateRanges();
}
void InstrumentValue::_setFontSize(FontSize fontSize)
......@@ -412,3 +431,80 @@ void InstrumentValue::removeRangeValue(int index)
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();
}
......@@ -63,6 +63,9 @@ public:
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);
......@@ -112,12 +115,20 @@ signals:
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;
......@@ -131,6 +142,9 @@ private:
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
......
......@@ -166,15 +166,37 @@ Column {
id: valueIcon
height: _rgFontSizeTightHeights[object.fontSize]
width: height
source: object.icon ? "/InstrumentValueIcons/" + object.icon : ""
source: icon
sourceSize.height: height
fillMode: Image.PreserveAspectFit
mipmap: true
smooth: true
color: qgcPal.text
color: object.isValidColor(object.currentColor) ? object.currentColor : qgcPal.text
opacity: object.currentOpacity
visible: object.icon
onWidthChanged: columnItem.recalcPositions()
onHeightChanged: columnItem.recalcPositions()
property string icon
readonly property string iconPrefix: "/InstrumentValueIcons/"
function updateIcon() {
if (object.rangeType == InstrumentValue.IconSelectRange) {
icon = iconPrefix + object.currentIcon
} else if (object.icon) {
icon = iconPrefix + object.icon
} else {
icon = ""
}
}
Connections {
target: object
onRangeTypeChanged: valueIcon.updateIcon()
onCurrentIconChanged: valueIcon.updateIcon()
onIconChanged: valueIcon.updateIcon()
}
Component.onCompleted: updateIcon();
}
QGCLabel {
......
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