Unified weather scenario names in single place

This commit is contained in:
Klaus Basan
2019-07-11 22:03:06 +02:00
parent 6e6c1751ea
commit 2f9fbbdfa5
4 changed files with 57 additions and 10 deletions

View File

@@ -58,9 +58,9 @@ namespace BlackMisc
{ {
static const QVector<CWeatherScenario> scenarios = static const QVector<CWeatherScenario> scenarios =
{ {
{ CWeatherScenario::ClearSky, "Clear Sky", "Clear sky, no clouds" }, { CWeatherScenario::ClearSky },
{ CWeatherScenario::Thunderstorm, "Thunderstorm", "Raining, lightning, several cloud layers" }, { CWeatherScenario::Thunderstorm },
{ CWeatherScenario::RealWeather, "Realtime Weather", "As real as it gets..." }, { CWeatherScenario::RealWeather },
}; };
return scenarios; return scenarios;
} }
@@ -68,7 +68,7 @@ namespace BlackMisc
const CWeatherGrid &CWeatherGrid::getByScenario(const CWeatherScenario &scenario) const CWeatherGrid &CWeatherGrid::getByScenario(const CWeatherScenario &scenario)
{ {
static const CWeatherGrid emptyGrid {}; static const CWeatherGrid emptyGrid {};
switch(scenario.getIndex()) switch (scenario.getIndex())
{ {
case CWeatherScenario::ClearSky: return getClearWeatherGrid(); case CWeatherScenario::ClearSky: return getClearWeatherGrid();
case CWeatherScenario::Thunderstorm: return getThunderStormGrid(); case CWeatherScenario::Thunderstorm: return getThunderStormGrid();
@@ -107,7 +107,7 @@ namespace BlackMisc
{}, {},
CCloudLayerList { cloudLayer }, CCloudLayerList { cloudLayer },
CTemperatureLayerList { temperatureLayer }, CTemperatureLayerList { temperatureLayer },
CVisibilityLayerList { visibilityLayer } , CVisibilityLayerList { visibilityLayer },
CWindLayerList { windLayer }, CWindLayerList { windLayer },
{ CAltitude::standardISASeaLevelPressure() } { CAltitude::standardISASeaLevelPressure() }
}; };

View File

@@ -24,7 +24,6 @@
namespace BlackMisc namespace BlackMisc
{ {
namespace Geo { class ICoordinateGeodetic; } namespace Geo { class ICoordinateGeodetic; }
namespace Weather namespace Weather
{ {
/*! /*!
@@ -51,7 +50,7 @@ namespace BlackMisc
CWeatherGrid findClosest(int number, const BlackMisc::Geo::ICoordinateGeodetic &coordinate) const; CWeatherGrid findClosest(int number, const BlackMisc::Geo::ICoordinateGeodetic &coordinate) const;
//! Get all available weather scenarios //! Get all available weather scenarios
static const QVector<CWeatherScenario> &getAllScenarios (); static const QVector<CWeatherScenario> &getAllScenarios();
//! Get weather grid by fixed scenario //! Get weather grid by fixed scenario
static const CWeatherGrid &getByScenario(const CWeatherScenario &scenario); static const CWeatherGrid &getByScenario(const CWeatherScenario &scenario);

View File

@@ -18,6 +18,10 @@ namespace BlackMisc
qRegisterMetaType<ScenarioIndex>(); qRegisterMetaType<ScenarioIndex>();
} }
CWeatherScenario::CWeatherScenario(CWeatherScenario::ScenarioIndex index) :
CWeatherScenario::CWeatherScenario(index, enumToString(index), enumToDescription(index))
{ }
CWeatherScenario::CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description) : CWeatherScenario::CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description) :
m_scenarioIndex(index), m_scenarioIndex(index),
m_scenarioName(name), 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; 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
} // namespace } // namespace

View File

@@ -49,6 +49,9 @@ namespace BlackMisc
//! Default constructor. //! Default constructor.
CWeatherScenario() = default; CWeatherScenario() = default;
//! Constructor
CWeatherScenario(ScenarioIndex index);
//! Constructor //! Constructor
CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description); CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description);
@@ -82,10 +85,16 @@ namespace BlackMisc
//! Is scenario the real weather scenario? //! Is scenario the real weather scenario?
static bool isRealWeatherScenario(const CWeatherScenario &scenario) { return scenario.getIndex() == RealWeather; } 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: private:
ScenarioIndex m_scenarioIndex = ClearSky; ScenarioIndex m_scenarioIndex = ClearSky;
QString m_scenarioName {"Clear Sky"}; QString m_scenarioName = enumToString(ClearSky);
QString m_scenarioDescription {"Clear Sky default"}; QString m_scenarioDescription = enumToDescription(ClearSky);
BLACK_METACLASS( BLACK_METACLASS(
CWeatherScenario, CWeatherScenario,