Commit c7262637 authored by DoinLakeFlyer's avatar DoinLakeFlyer

parent 5ad2b7f8
...@@ -53,8 +53,6 @@ void FactGroup::_setupTimer() ...@@ -53,8 +53,6 @@ void FactGroup::_setupTimer()
Fact* FactGroup::getFact(const QString& name) Fact* FactGroup::getFact(const QString& name)
{ {
Fact* fact = nullptr;
if (name.contains(".")) { if (name.contains(".")) {
QStringList parts = name.split("."); QStringList parts = name.split(".");
if (parts.count() != 2) { if (parts.count() != 2) {
...@@ -71,11 +69,14 @@ Fact* FactGroup::getFact(const QString& name) ...@@ -71,11 +69,14 @@ Fact* FactGroup::getFact(const QString& name)
return factGroup->getFact(parts[1]); return factGroup->getFact(parts[1]);
} }
if (_nameToFactMap.contains(name)) { Fact* fact = nullptr;
fact = _nameToFactMap[name]; QString camelCaseName = _camelCase(name);
if (_nameToFactMap.contains(camelCaseName)) {
fact = _nameToFactMap[camelCaseName];
QQmlEngine::setObjectOwnership(fact, QQmlEngine::CppOwnership); QQmlEngine::setObjectOwnership(fact, QQmlEngine::CppOwnership);
} else { } else {
qWarning() << "Unknown Fact" << name; qWarning() << "Unknown Fact" << camelCaseName;
} }
return fact; return fact;
...@@ -83,13 +84,14 @@ Fact* FactGroup::getFact(const QString& name) ...@@ -83,13 +84,14 @@ Fact* FactGroup::getFact(const QString& name)
FactGroup* FactGroup::getFactGroup(const QString& name) FactGroup* FactGroup::getFactGroup(const QString& name)
{ {
FactGroup* factGroup = nullptr; FactGroup* factGroup = nullptr;
QString camelCaseName = _camelCase(name);
if (_nameToFactGroupMap.contains(name)) { if (_nameToFactGroupMap.contains(camelCaseName)) {
factGroup = _nameToFactGroupMap[name]; factGroup = _nameToFactGroupMap[camelCaseName];
QQmlEngine::setObjectOwnership(factGroup, QQmlEngine::CppOwnership); QQmlEngine::setObjectOwnership(factGroup, QQmlEngine::CppOwnership);
} else { } else {
qWarning() << "Unknown FactGroup" << name; qWarning() << "Unknown FactGroup" << camelCaseName;
} }
return factGroup; return factGroup;
...@@ -142,3 +144,9 @@ void FactGroup::setLiveUpdates(bool liveUpdates) ...@@ -142,3 +144,9 @@ void FactGroup::setLiveUpdates(bool liveUpdates)
fact->setSendValueChangedSignals(liveUpdates); fact->setSendValueChangedSignals(liveUpdates);
} }
} }
QString FactGroup::_camelCase(const QString& text)
{
return text[0].toLower() + text.right(text.length() - 1);
}
...@@ -44,25 +44,26 @@ public: ...@@ -44,25 +44,26 @@ public:
QStringList factNames(void) const { return _factNames; } QStringList factNames(void) const { return _factNames; }
QStringList factGroupNames(void) const { return _nameToFactGroupMap.keys(); } QStringList factGroupNames(void) const { return _nameToFactGroupMap.keys(); }
protected:
void _addFact(Fact* fact, const QString& name);
void _addFactGroup(FactGroup* factGroup, const QString& name);
void _loadFromJsonArray(const QJsonArray jsonArray);
int _updateRateMSecs; ///< Update rate for Fact::valueChanged signals, 0: immediate update
protected slots: protected slots:
virtual void _updateAllValues(void); virtual void _updateAllValues(void);
private:
void _setupTimer();
QTimer _updateTimer;
protected: protected:
void _addFact (Fact* fact, const QString& name);
void _addFactGroup (FactGroup* factGroup, const QString& name);
void _loadFromJsonArray (const QJsonArray jsonArray);
int _updateRateMSecs; ///< Update rate for Fact::valueChanged signals, 0: immediate update
QMap<QString, Fact*> _nameToFactMap; QMap<QString, Fact*> _nameToFactMap;
QMap<QString, FactGroup*> _nameToFactGroupMap; QMap<QString, FactGroup*> _nameToFactGroupMap;
QMap<QString, FactMetaData*> _nameToFactMetaDataMap; QMap<QString, FactMetaData*> _nameToFactMetaDataMap;
QStringList _factNames; QStringList _factNames;
private:
void _setupTimer (void);
QString _camelCase (const QString& text);
QTimer _updateTimer;
}; };
#endif #endif
This diff is collapsed.
...@@ -29,6 +29,7 @@ const char* InstrumentValue::_fontSizeKey = "fontSize"; ...@@ -29,6 +29,7 @@ const char* InstrumentValue::_fontSizeKey = "fontSize";
const char* InstrumentValue::_showUnitsKey = "showUnits"; const char* InstrumentValue::_showUnitsKey = "showUnits";
const char* InstrumentValue::_iconKey = "icon"; const char* InstrumentValue::_iconKey = "icon";
const char* InstrumentValue::_iconPositionKey = "iconPosition"; const char* InstrumentValue::_iconPositionKey = "iconPosition";
const char* InstrumentValue::_vehicleFactGroupName = "Vehicle";
QStringList InstrumentValue::_iconNames; QStringList InstrumentValue::_iconNames;
...@@ -234,28 +235,32 @@ void ValuesWidgetController::_loadSettings(void) ...@@ -234,28 +235,32 @@ void ValuesWidgetController::_loadSettings(void)
QStringList largeValues = settings.value(_deprecatedLargeValuesKey).toStringList(); QStringList largeValues = settings.value(_deprecatedLargeValuesKey).toStringList();
QStringList smallValues = settings.value(_deprecatedSmallValuesKey).toStringList(); QStringList smallValues = settings.value(_deprecatedSmallValuesKey).toStringList();
QStringList altitudeProperties = { "altitudeRelative" , "altitudeAMSL" }; QStringList altitudeProperties = { "AltitudeRelative" , "AltitudeAMSL" };
int rowIndex = -1; int rowIndex = -1;
int valueCount = 0; int valueCount = 0;
QmlObjectListModel* rowModel = nullptr; QmlObjectListModel* rowModel = nullptr;
for (const QString& largeValue: largeValues) { for (const QString& largeValue: largeValues) {
QStringList parts = largeValue.split("."); QStringList parts = largeValue.split(".");
QString factGroupName = _pascalCase(parts[0]);
QString factName = _pascalCase(parts[1]);
rowModel = appendRow(false /* addBlankColumn */); rowModel = appendRow(false /* addBlankColumn */);
rowIndex++; rowIndex++;
InstrumentValue* colValue = appendColumn(rowIndex); InstrumentValue* colValue = appendColumn(rowIndex);
colValue->setFact(parts[0], parts[1], QString()); colValue->setFact(factGroupName, factName);
colValue->setLabel(colValue->fact()->shortDescription()); colValue->setLabel(colValue->fact()->shortDescription());
colValue->setShowUnits(true); colValue->setShowUnits(true);
colValue->setFontSize(altitudeProperties.contains(parts[1]) ? InstrumentValue::LargeFontSize : InstrumentValue::DefaultFontSize); colValue->setFontSize(altitudeProperties.contains(factName) ? InstrumentValue::LargeFontSize : InstrumentValue::DefaultFontSize);
} }
valueCount = 0; valueCount = 0;
rowModel = nullptr; rowModel = nullptr;
for (const QString& smallValue: smallValues) { for (const QString& smallValue: smallValues) {
QStringList parts = smallValue.split("."); QStringList parts = smallValue.split(".");
QString factGroupName = _pascalCase(parts[0]);
QString factName = _pascalCase(parts[1]);
if (!(valueCount++ & 1)) { if (!(valueCount++ & 1)) {
rowModel = appendRow(false /* addBlankColumn */); rowModel = appendRow(false /* addBlankColumn */);
...@@ -263,7 +268,7 @@ void ValuesWidgetController::_loadSettings(void) ...@@ -263,7 +268,7 @@ void ValuesWidgetController::_loadSettings(void)
} }
InstrumentValue* colValue = appendColumn(rowIndex); InstrumentValue* colValue = appendColumn(rowIndex);
colValue->setFact(parts[0], parts[1], QString()); colValue->setFact(factGroupName, factName);
colValue->setLabel(colValue->fact()->shortDescription()); colValue->setLabel(colValue->fact()->shortDescription());
colValue->setShowUnits(true); colValue->setShowUnits(true);
colValue->setFontSize(InstrumentValue::SmallFontSize); colValue->setFontSize(InstrumentValue::SmallFontSize);
...@@ -332,6 +337,11 @@ void ValuesWidgetController::setValuesModelParentController(ValuesWidgetControll ...@@ -332,6 +337,11 @@ void ValuesWidgetController::setValuesModelParentController(ValuesWidgetControll
} }
} }
QString ValuesWidgetController::_pascalCase(const QString& text)
{
return text[0].toUpper() + text.right(text.length() - 1);
}
InstrumentValue::InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlObjectListModel* rowModel) InstrumentValue::InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlObjectListModel* rowModel)
: QObject (rowModel) : QObject (rowModel)
, _activeVehicle(activeVehicle) , _activeVehicle(activeVehicle)
...@@ -342,17 +352,27 @@ InstrumentValue::InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlO ...@@ -342,17 +352,27 @@ InstrumentValue::InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlO
QDir iconDir(":/InstrumentValueIcons/"); QDir iconDir(":/InstrumentValueIcons/");
_iconNames = iconDir.entryList(); _iconNames = iconDir.entryList();
} }
activeVehicleChanged(_activeVehicle);
} }
void InstrumentValue::activeVehicleChanged(Vehicle* activeVehicle) void InstrumentValue::activeVehicleChanged(Vehicle* activeVehicle)
{ {
_activeVehicle = activeVehicle; _activeVehicle = activeVehicle;
_factGroupNames.clear();
_factGroupNames = _activeVehicle->factGroupNames();
for (QString& name: _factGroupNames) {
name[0] = name[0].toUpper();
}
_factGroupNames.prepend(_vehicleFactGroupName);
emit factGroupNamesChanged(_factGroupNames);
if (_fact) { if (_fact) {
_fact = nullptr; _fact = nullptr;
FactGroup* factGroup = nullptr; FactGroup* factGroup = nullptr;
if (_factGroupName == QStringLiteral("Vehicle")) { if (_factGroupName == _vehicleFactGroupName) {
factGroup = _activeVehicle; factGroup = _activeVehicle;
} else { } else {
factGroup = _activeVehicle->getFactGroup(_factGroupName); factGroup = _activeVehicle->getFactGroup(_factGroupName);
...@@ -365,37 +385,47 @@ void InstrumentValue::activeVehicleChanged(Vehicle* activeVehicle) ...@@ -365,37 +385,47 @@ void InstrumentValue::activeVehicleChanged(Vehicle* activeVehicle)
} }
} }
void InstrumentValue::setFact(QString factGroupName, QString factName, QString label) void InstrumentValue::setFact(const QString& factGroupName, const QString& factName)
{ {
if (_fact) { if (_fact) {
_fact = nullptr; _fact = nullptr;
} }
FactGroup* factGroup = nullptr; FactGroup* factGroup = nullptr;
if (factGroupName == QStringLiteral("Vehicle")) { if (factGroupName == _vehicleFactGroupName) {
factGroup = _activeVehicle; factGroup = _activeVehicle;
} else { } else {
factGroup = _activeVehicle->getFactGroup(factGroupName); factGroup = _activeVehicle->getFactGroup(factGroupName);
} }
_factValueNames.clear();
_factValueNames = factGroup->factNames();
for (QString& name: _factValueNames) {
name[0] = name[0].toUpper();
}
QString nonEmptyFactName;
if (factGroup) { if (factGroup) {
_fact = factGroup->getFact(factName); if (factName.isEmpty()) {
nonEmptyFactName = _factValueNames[0];
} else {
nonEmptyFactName = factName;
}
_fact = factGroup->getFact(nonEmptyFactName);
} }
if (_fact) { if (_fact) {
_factName = factName;
_factGroupName = factGroupName; _factGroupName = factGroupName;
_label = label; _factName = nonEmptyFactName;
} else { } else {
_factName.clear(); _factName.clear();
_factGroupName.clear(); _factGroupName.clear();
_label.clear();
} }
emit labelChanged(_label); emit factChanged (_fact);
emit factChanged(_fact); emit factNameChanged (_factName);
emit factNameChanged(_factName); emit factGroupNameChanged (_factGroupName);
emit factGroupNameChanged(_factGroupName); emit factValueNamesChanged (_factValueNames);
} }
void InstrumentValue::_setFontSize(FontSize fontSize) void InstrumentValue::_setFontSize(FontSize fontSize)
...@@ -423,7 +453,7 @@ void InstrumentValue::saveToSettings(QSettings& settings) const ...@@ -423,7 +453,7 @@ void InstrumentValue::saveToSettings(QSettings& settings) const
{ {
if (_fact) { if (_fact) {
settings.setValue(_factGroupNameKey, _factGroupName); settings.setValue(_factGroupNameKey, _factGroupName);
settings.setValue(_factNameKey, _fact->name()); settings.setValue(_factNameKey, _factName);
} else { } else {
settings.setValue(_factGroupNameKey, ""); settings.setValue(_factGroupNameKey, "");
settings.setValue(_factNameKey, ""); settings.setValue(_factNameKey, "");
...@@ -446,7 +476,7 @@ void InstrumentValue::readFromSettings(const QSettings& settings) ...@@ -446,7 +476,7 @@ void InstrumentValue::readFromSettings(const QSettings& settings)
QString factName = settings.value(_factNameKey).toString(); QString factName = settings.value(_factNameKey).toString();
if (!factName.isEmpty()) { if (!factName.isEmpty()) {
setFact(_factGroupName, factName, _label); setFact(_factGroupName, factName);
} }
emit factChanged (_fact); emit factChanged (_fact);
......
...@@ -38,7 +38,10 @@ public: ...@@ -38,7 +38,10 @@ public:
InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlObjectListModel* rowModel); 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 factGroupName MEMBER _factGroupName NOTIFY factGroupNameChanged)
Q_PROPERTY(QString factName MEMBER _factName NOTIFY factNameChanged)
Q_PROPERTY(Fact* fact READ fact NOTIFY factChanged) Q_PROPERTY(Fact* fact READ fact NOTIFY factChanged)
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) 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(QString icon READ icon WRITE setIcon NOTIFY iconChanged) ///< If !isEmpty icon will be show instead of label
...@@ -49,8 +52,8 @@ public: ...@@ -49,8 +52,8 @@ public:
Q_PROPERTY(QStringList fontSizeNames MEMBER _fontSizeNames CONSTANT) Q_PROPERTY(QStringList fontSizeNames MEMBER _fontSizeNames CONSTANT)
Q_PROPERTY(bool showUnits READ showUnits WRITE setShowUnits NOTIFY showUnitsChanged) Q_PROPERTY(bool showUnits READ showUnits WRITE setShowUnits NOTIFY showUnitsChanged)
Q_INVOKABLE void setFact(QString factGroupName, QString factName, QString label); Q_INVOKABLE void setFact(const QString& factGroupName, const QString& factName);
Q_INVOKABLE void clearFact(void); Q_INVOKABLE void clearFact(void);
Fact* fact (void) { return _fact; } Fact* fact (void) { return _fact; }
FontSize fontSize (void) const { return _fontSize; } FontSize fontSize (void) const { return _fontSize; }
...@@ -76,6 +79,8 @@ signals: ...@@ -76,6 +79,8 @@ signals:
void showUnitsChanged (bool showUnits); void showUnitsChanged (bool showUnits);
void iconChanged (const QString& icon); void iconChanged (const QString& icon);
void iconPositionChanged (IconPosition iconPosition); void iconPositionChanged (IconPosition iconPosition);
void factGroupNamesChanged (const QStringList& factGroupNames);
void factValueNamesChanged (const QStringList& factValueNames);
private: private:
void _setFontSize (FontSize fontSize); void _setFontSize (FontSize fontSize);
...@@ -90,6 +95,8 @@ private: ...@@ -90,6 +95,8 @@ private:
FontSize _fontSize = DefaultFontSize; FontSize _fontSize = DefaultFontSize;
QString _icon; QString _icon;
IconPosition _iconPosition = IconLeft; IconPosition _iconPosition = IconLeft;
QStringList _factGroupNames;
QStringList _factValueNames;
static const QStringList _iconPositionNames; static const QStringList _iconPositionNames;
static QStringList _iconNames; static QStringList _iconNames;
...@@ -102,6 +109,7 @@ private: ...@@ -102,6 +109,7 @@ private:
static const char* _showUnitsKey; static const char* _showUnitsKey;
static const char* _iconKey; static const char* _iconKey;
static const char* _iconPositionKey; static const char* _iconPositionKey;
static const char* _vehicleFactGroupName;
}; };
Q_DECLARE_METATYPE(InstrumentValue::FontSize) Q_DECLARE_METATYPE(InstrumentValue::FontSize)
...@@ -146,7 +154,7 @@ private: ...@@ -146,7 +154,7 @@ private:
InstrumentValue* _createNewInstrumentValueWorker (Vehicle* activeVehicle, InstrumentValue::FontSize fontSize, QmlObjectListModel* rowModel); InstrumentValue* _createNewInstrumentValueWorker (Vehicle* activeVehicle, InstrumentValue::FontSize fontSize, QmlObjectListModel* rowModel);
void _loadSettings (void); void _loadSettings (void);
void _connectSignalsToController (InstrumentValue* value, ValuesWidgetController* controller); void _connectSignalsToController (InstrumentValue* value, ValuesWidgetController* controller);
QString _pascalCase (const QString& text);
MultiVehicleManager* _multiVehicleMgr = nullptr; MultiVehicleManager* _multiVehicleMgr = nullptr;
QmlObjectListModel* _valuesModel = nullptr; QmlObjectListModel* _valuesModel = nullptr;
......
...@@ -417,21 +417,21 @@ QmlObjectListModel* QGCCorePlugin::valuesWidgetDefaultSettings(ValuesWidgetContr ...@@ -417,21 +417,21 @@ QmlObjectListModel* QGCCorePlugin::valuesWidgetDefaultSettings(ValuesWidgetContr
QmlObjectListModel* columnModel = controller.appendRow(); QmlObjectListModel* columnModel = controller.appendRow();
InstrumentValue* colValue = columnModel->value<InstrumentValue*>(0); InstrumentValue* colValue = columnModel->value<InstrumentValue*>(0);
colValue->setFact("Vehicle", "altitudeRelative", QString()); colValue->setFact("Vehicle", "AltitudeRelative");
colValue->setLabel(colValue->fact()->shortDescription()); colValue->setLabel(colValue->fact()->shortDescription());
colValue->setShowUnits(true); colValue->setShowUnits(true);
colValue->setFontSize(InstrumentValue::LargeFontSize); colValue->setFontSize(InstrumentValue::LargeFontSize);
columnModel = controller.appendRow(); columnModel = controller.appendRow();
colValue = columnModel->value<InstrumentValue*>(0); colValue = columnModel->value<InstrumentValue*>(0);
colValue->setFact("Vehicle", "groundSpeed", QString()); colValue->setFact("Vehicle", "GroundSpeed");
colValue->setLabel(colValue->fact()->shortDescription()); colValue->setLabel(colValue->fact()->shortDescription());
colValue->setShowUnits(true); colValue->setShowUnits(true);
colValue->setFontSize(InstrumentValue::DefaultFontSize); colValue->setFontSize(InstrumentValue::DefaultFontSize);
columnModel = controller.appendRow(); columnModel = controller.appendRow();
colValue = columnModel->value<InstrumentValue*>(0); colValue = columnModel->value<InstrumentValue*>(0);
colValue->setFact("Vehicle", "flightTime", QString()); colValue->setFact("Vehicle", "FlightTime");
colValue->setLabel(colValue->fact()->shortDescription()); colValue->setLabel(colValue->fact()->shortDescription());
colValue->setShowUnits(false); colValue->setShowUnits(false);
colValue->setFontSize(InstrumentValue::DefaultFontSize); colValue->setFontSize(InstrumentValue::DefaultFontSize);
......
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