Launcher: update Advanced-weather handling
Use the information from Environment/environment.xml to init the local-weather control properties.
This commit is contained in:
parent
0747c2b373
commit
f39b81c872
3 changed files with 65 additions and 17 deletions
|
@ -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<int>(m_scenarios.size());
|
||||
}
|
||||
|
||||
QVariant WeatherScenariosModel::data(const QModelIndex &index, int role) const
|
||||
|
@ -139,28 +145,42 @@ QHash<int, QByteArray> 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;
|
||||
|
|
|
@ -46,17 +46,21 @@ public:
|
|||
|
||||
QHash<int, QByteArray> 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<WeatherScenario> m_scenarios;
|
||||
|
@ -64,7 +68,7 @@ private:
|
|||
enum {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
DescriptionRole,
|
||||
MetarRole
|
||||
MetarRole,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue