From f39b81c8723f34363a0b0e54b758a81208ef73c4 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 7 Sep 2018 15:56:10 +0100 Subject: [PATCH] Launcher: update Advanced-weather handling Use the information from Environment/environment.xml to init the local-weather control properties. --- src/GUI/DefaultAircraftLocator.cxx | 42 ++++++++++++++++++++++-------- src/GUI/DefaultAircraftLocator.hxx | 12 ++++++--- src/GUI/qml/Environment.qml | 28 ++++++++++++++++++-- 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/src/GUI/DefaultAircraftLocator.cxx b/src/GUI/DefaultAircraftLocator.cxx index b14021a9d..bc6b952a9 100644 --- a/src/GUI/DefaultAircraftLocator.cxx +++ b/src/GUI/DefaultAircraftLocator.cxx @@ -93,6 +93,8 @@ WeatherScenariosModel::WeatherScenariosModel(QObject *pr) : continue; } + // omit the 'live data' option, we have a distinct UI for that, we'll + // pass --real-wxr option on launch if (scenario->getStringValue("local-weather/tile-type") == std::string("live")) { continue; } @@ -101,14 +103,18 @@ WeatherScenariosModel::WeatherScenariosModel(QObject *pr) : ws.name = QString::fromStdString(scenario->getStringValue("name")); ws.description = QString::fromStdString(scenario->getStringValue("description")).simplified(); ws.metar = QString::fromStdString(scenario->getStringValue("metar")); + if (scenario->hasChild("local-weather")) { + ws.localWeatherTileManagement = QString::fromStdString(scenario->getStringValue("local-weather/tile-management")); + ws.localWeatherTileType = QString::fromStdString(scenario->getStringValue("local-weather/tile-type")); + } m_scenarios.push_back(ws); } } } -int WeatherScenariosModel::rowCount(const QModelIndex &index) const +int WeatherScenariosModel::rowCount(const QModelIndex&) const { - return m_scenarios.size(); + return static_cast(m_scenarios.size()); } QVariant WeatherScenariosModel::data(const QModelIndex &index, int role) const @@ -139,28 +145,42 @@ QHash WeatherScenariosModel::roleNames() const return result; } -QString WeatherScenariosModel::metarForItem(int index) const +QString WeatherScenariosModel::metarForItem(quint32 index) const { - if ((index < 0) || (index >= m_scenarios.size())) { - return QString(); + if (index >= m_scenarios.size()) { + return {}; } return m_scenarios.at(index).metar; } -QString WeatherScenariosModel::descriptionForItem(int index) const +QString WeatherScenariosModel::descriptionForItem(quint32 index) const { - if ((index < 0) || (index >= m_scenarios.size())) { - return QString(); + if (index >= m_scenarios.size()) { + return {}; } return m_scenarios.at(index).description; } -QString WeatherScenariosModel::nameForItem(int index) const +QStringList WeatherScenariosModel::localWeatherData(quint32 index) const { - if ((index < 0) || (index >= m_scenarios.size())) { - return QString(); + if (index >= m_scenarios.size()) { + return {}; + } + + const auto& s = m_scenarios.at(index); + if (s.localWeatherTileManagement.isEmpty() || s.localWeatherTileType.isEmpty()) { + return {}; + } + + return QStringList() << s.localWeatherTileManagement << s.localWeatherTileType; +} + +QString WeatherScenariosModel::nameForItem(quint32 index) const +{ + if (index >= m_scenarios.size()) { + return {}; } return m_scenarios.at(index).name; diff --git a/src/GUI/DefaultAircraftLocator.hxx b/src/GUI/DefaultAircraftLocator.hxx index b68373d29..8830a0c95 100644 --- a/src/GUI/DefaultAircraftLocator.hxx +++ b/src/GUI/DefaultAircraftLocator.hxx @@ -46,17 +46,21 @@ public: QHash roleNames() const override; - Q_INVOKABLE QString metarForItem(int index) const; + Q_INVOKABLE QString metarForItem(quint32 index) const; - Q_INVOKABLE QString nameForItem(int index) const; + Q_INVOKABLE QString nameForItem(quint32 index) const; - Q_INVOKABLE QString descriptionForItem(int index) const; + Q_INVOKABLE QString descriptionForItem(quint32 index) const; + + Q_INVOKABLE QStringList localWeatherData(quint32 index) const; private: struct WeatherScenario { QString name; QString description; QString metar; + QString localWeatherTileType; + QString localWeatherTileManagement; }; std::vector m_scenarios; @@ -64,7 +68,7 @@ private: enum { NameRole = Qt::UserRole + 1, DescriptionRole, - MetarRole + MetarRole, }; }; diff --git a/src/GUI/qml/Environment.qml b/src/GUI/qml/Environment.qml index d72ca5514..29b30cd68 100644 --- a/src/GUI/qml/Environment.qml +++ b/src/GUI/qml/Environment.qml @@ -182,11 +182,24 @@ Item { // inside the sim _config.setProperty("/nasal/local_weather/enabled", advancedWeather.checked); + // Thorsten R advises that these are also needed for AW to startup + // correctly. + if (advancedWeather.checked) { + _config.setProperty("/sim/gui/dialogs/metar/mode/global-weather", !advancedWeather.checked); + _config.setProperty("/sim/gui/dialogs/metar/mode/local-weather", advancedWeather.checked); + _config.setProperty("/sim/gui/dialogs/metar/mode/manual-weather", advancedWeather.checked); + } + var index = weatherScenario.selectedIndex; // set description from the weather scenarios, so Local-weather // can run the appropriate simulation - if (!fetchMetar.checked) { + if (fetchMetar.checked) { + if (advancedWeather.checked) { + _config.setProperty("/local-weather/tmp/tile-management", "METAR"); + _config.setProperty("/local-weather/tmp/tile-type", "live"); + } + } else { if (weatherScenario.isCustomMETAR) { _config.setArg("metar", customMETAR.value) } else { @@ -198,7 +211,18 @@ Item { _config.setProperty("/environment/weather-scenario", _weatherScenarios.nameForItem(index)) - } + if (advancedWeather.checked) { + // set AW tile options + var s = _weatherScenarios.localWeatherData(index); + if (s.length === 0) { + console.warn("Weather scenario " + _weatherScenarios.nameForItem(index) + + " does not specify local weather data"); + } else { + _config.setProperty("/local-weather/tmp/tile-management", s[0]); + _config.setProperty("/local-weather/tmp/tile-type", s[1]); + } + } // of using Advanced (local) weather + } // of not using real-wxr } function summary()