From 9ac457edb3416571512dcb13bc06ca5d66eb2872 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 11 Jul 2019 22:03:06 +0200 Subject: [PATCH] Unified weather scenario names in single place --- src/blackmisc/weather/weathergrid.cpp | 10 +++--- src/blackmisc/weather/weathergrid.h | 3 +- src/blackmisc/weather/weatherscenario.cpp | 41 ++++++++++++++++++++++- src/blackmisc/weather/weatherscenario.h | 13 +++++-- 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/blackmisc/weather/weathergrid.cpp b/src/blackmisc/weather/weathergrid.cpp index 0d428413b..297029048 100644 --- a/src/blackmisc/weather/weathergrid.cpp +++ b/src/blackmisc/weather/weathergrid.cpp @@ -58,9 +58,9 @@ namespace BlackMisc { static const QVector scenarios = { - { CWeatherScenario::ClearSky, "Clear Sky", "Clear sky, no clouds" }, - { CWeatherScenario::Thunderstorm, "Thunderstorm", "Raining, lightning, several cloud layers" }, - { CWeatherScenario::RealWeather, "Realtime Weather", "As real as it gets..." }, + { CWeatherScenario::ClearSky }, + { CWeatherScenario::Thunderstorm }, + { CWeatherScenario::RealWeather }, }; return scenarios; } @@ -68,7 +68,7 @@ namespace BlackMisc const CWeatherGrid &CWeatherGrid::getByScenario(const CWeatherScenario &scenario) { static const CWeatherGrid emptyGrid {}; - switch(scenario.getIndex()) + switch (scenario.getIndex()) { case CWeatherScenario::ClearSky: return getClearWeatherGrid(); case CWeatherScenario::Thunderstorm: return getThunderStormGrid(); @@ -107,7 +107,7 @@ namespace BlackMisc {}, CCloudLayerList { cloudLayer }, CTemperatureLayerList { temperatureLayer }, - CVisibilityLayerList { visibilityLayer } , + CVisibilityLayerList { visibilityLayer }, CWindLayerList { windLayer }, { CAltitude::standardISASeaLevelPressure() } }; diff --git a/src/blackmisc/weather/weathergrid.h b/src/blackmisc/weather/weathergrid.h index 3fb12c7b5..7ef34d8ac 100644 --- a/src/blackmisc/weather/weathergrid.h +++ b/src/blackmisc/weather/weathergrid.h @@ -24,7 +24,6 @@ namespace BlackMisc { namespace Geo { class ICoordinateGeodetic; } - namespace Weather { /*! @@ -51,7 +50,7 @@ namespace BlackMisc CWeatherGrid findClosest(int number, const BlackMisc::Geo::ICoordinateGeodetic &coordinate) const; //! Get all available weather scenarios - static const QVector &getAllScenarios (); + static const QVector &getAllScenarios(); //! Get weather grid by fixed scenario static const CWeatherGrid &getByScenario(const CWeatherScenario &scenario); diff --git a/src/blackmisc/weather/weatherscenario.cpp b/src/blackmisc/weather/weatherscenario.cpp index 85ad3d488..86f86cbc5 100644 --- a/src/blackmisc/weather/weatherscenario.cpp +++ b/src/blackmisc/weather/weatherscenario.cpp @@ -18,6 +18,10 @@ namespace BlackMisc qRegisterMetaType(); } + CWeatherScenario::CWeatherScenario(CWeatherScenario::ScenarioIndex index) : + CWeatherScenario::CWeatherScenario(index, enumToString(index), enumToDescription(index)) + { } + CWeatherScenario::CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description) : m_scenarioIndex(index), m_scenarioName(name), @@ -53,10 +57,45 @@ namespace BlackMisc } } - QString CWeatherScenario::convertToQString(bool /** i18n **/) const + QString CWeatherScenario::convertToQString(bool i18n) const { + Q_UNUSED(i18n); return m_scenarioName; } + const QString &CWeatherScenario::enumToString(CWeatherScenario::ScenarioIndex index) + { + static const QString cs("Clear Sky"); + static const QString thunder("Thunderstorm"); + static const QString real("Realtime Weather"); + switch (index) + { + case ClearSky: return cs; + case Thunderstorm: return thunder; + case RealWeather: return real; + default: break; + } + + static const QString unknown("???"); + return unknown; + } + + const QString &CWeatherScenario::enumToDescription(CWeatherScenario::ScenarioIndex index) + { + static const QString cs("Clear sky, no clouds"); + static const QString thunder("Raining, lightning, several cloud layers"); + static const QString real("As real as it gets..."); + switch (index) + { + case ClearSky: return cs; + case Thunderstorm: return thunder; + case RealWeather: return real; + default: break; + } + + static const QString unknown("???"); + return unknown; + } + } // namespace } // namespace diff --git a/src/blackmisc/weather/weatherscenario.h b/src/blackmisc/weather/weatherscenario.h index 5eae3b425..f1e236ce5 100644 --- a/src/blackmisc/weather/weatherscenario.h +++ b/src/blackmisc/weather/weatherscenario.h @@ -49,6 +49,9 @@ namespace BlackMisc //! Default constructor. CWeatherScenario() = default; + //! Constructor + CWeatherScenario(ScenarioIndex index); + //! Constructor CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description); @@ -82,10 +85,16 @@ namespace BlackMisc //! Is scenario the real weather scenario? static bool isRealWeatherScenario(const CWeatherScenario &scenario) { return scenario.getIndex() == RealWeather; } + //! As string + static const QString &enumToString(ScenarioIndex index); + + //! As string + static const QString &enumToDescription(ScenarioIndex index); + private: ScenarioIndex m_scenarioIndex = ClearSky; - QString m_scenarioName {"Clear Sky"}; - QString m_scenarioDescription {"Clear Sky default"}; + QString m_scenarioName = enumToString(ClearSky); + QString m_scenarioDescription = enumToDescription(ClearSky); BLACK_METACLASS( CWeatherScenario,