Unified weather scenario names in single place

This commit is contained in:
Klaus Basan
2019-07-11 22:03:06 +02:00
committed by Mat Sutcliffe
parent ca23115394
commit 9ac457edb3
4 changed files with 57 additions and 10 deletions

View File

@@ -58,9 +58,9 @@ namespace BlackMisc
{
static const QVector<CWeatherScenario> 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() }
};

View File

@@ -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<CWeatherScenario> &getAllScenarios ();
static const QVector<CWeatherScenario> &getAllScenarios();
//! Get weather grid by fixed scenario
static const CWeatherGrid &getByScenario(const CWeatherScenario &scenario);

View File

@@ -18,6 +18,10 @@ namespace BlackMisc
qRegisterMetaType<ScenarioIndex>();
}
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

View File

@@ -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,