diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index d048d9110..53a2dcb6e 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -79,6 +79,7 @@ namespace BlackMisc GlobalIndexCTemperatureLayer = 4400, GlobalIndexCGridPoint = 4500, GlobalIndexCVisibilityLayer = 4600, + GlobalIndexCWeatherScenario = 4700, GlobalIndexICoordinateGeodetic = 5000, GlobalIndexCCoordinateGeodetic = 5100, GlobalIndexCClient = 6000, diff --git a/src/blackmisc/weather/registermetadataweather.cpp b/src/blackmisc/weather/registermetadataweather.cpp index 8b45c2a85..5202d3a09 100644 --- a/src/blackmisc/weather/registermetadataweather.cpp +++ b/src/blackmisc/weather/registermetadataweather.cpp @@ -32,6 +32,7 @@ namespace BlackMisc CWeatherDataPluginInfo::registerMetadata(); CWeatherDataPluginInfoList::registerMetadata(); CWeatherGrid::registerMetadata(); + CWeatherScenario::registerMetadata(); CWindLayer::registerMetadata(); CWindLayerList::registerMetadata(); } diff --git a/src/blackmisc/weather/weather.h b/src/blackmisc/weather/weather.h index 7ad369f44..bbd5c162d 100644 --- a/src/blackmisc/weather/weather.h +++ b/src/blackmisc/weather/weather.h @@ -31,6 +31,7 @@ #include "blackmisc/weather/weatherdataplugininfo.h" #include "blackmisc/weather/weatherdataplugininfolist.h" #include "blackmisc/weather/weathergrid.h" +#include "blackmisc/weather/weatherscenario.h" #include "blackmisc/weather/windlayer.h" #include "blackmisc/weather/windlayerlist.h" diff --git a/src/blackmisc/weather/weathergrid.cpp b/src/blackmisc/weather/weathergrid.cpp index 676521c92..7ba220566 100644 --- a/src/blackmisc/weather/weathergrid.cpp +++ b/src/blackmisc/weather/weathergrid.cpp @@ -55,6 +55,28 @@ namespace BlackMisc return closest; } + const QVector &CWeatherGrid::getAllScenarios() + { + 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..." }, + }; + return scenarios; + } + + const CWeatherGrid &CWeatherGrid::getByScenario(const CWeatherScenario &scenario) + { + static const CWeatherGrid emptyGrid {}; + switch(scenario.getIndex()) + { + case CWeatherScenario::ClearSky: return getClearWeatherGrid(); + case CWeatherScenario::Thunderstorm: return getThunderStormGrid(); + default: Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown fixed scenario index requested."); return emptyGrid; + } + } + const CWeatherGrid &CWeatherGrid::getClearWeatherGrid() { static const CVisibilityLayer visibilityLayer( diff --git a/src/blackmisc/weather/weathergrid.h b/src/blackmisc/weather/weathergrid.h index 961fd5cd3..aee839023 100644 --- a/src/blackmisc/weather/weathergrid.h +++ b/src/blackmisc/weather/weathergrid.h @@ -17,6 +17,7 @@ #include "blackmisc/sequence.h" #include "blackmisc/variant.h" #include "blackmisc/weather/gridpoint.h" +#include "blackmisc/weather/weatherscenario.h" #include #include @@ -52,6 +53,12 @@ namespace BlackMisc //! \copydoc Geo::IGeoObjectList::findClosest CWeatherGrid findClosest(int number, const BlackMisc::Geo::ICoordinateGeodetic &coordinate) const; + //! Get all available weather scenarios + static const QVector &getAllScenarios (); + + //! Get weather grid by fixed scenario + static const CWeatherGrid &getByScenario(const CWeatherScenario &scenario); + //! Clear weather grid static const BlackMisc::Weather::CWeatherGrid &getClearWeatherGrid(); diff --git a/src/blackmisc/weather/weatherscenario.cpp b/src/blackmisc/weather/weatherscenario.cpp new file mode 100644 index 000000000..7bdd4b476 --- /dev/null +++ b/src/blackmisc/weather/weatherscenario.cpp @@ -0,0 +1,73 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackmisc/weather/weatherscenario.h" + +namespace BlackMisc +{ + namespace Weather + { + + void CWeatherScenario::registerMetadata() + { + CValueObject::registerMetadata(); + qRegisterMetaType(); + } + + CWeatherScenario::CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description) : + m_scenarioIndex(index), + m_scenarioName(name), + m_scenarioDescription(description) + { } + + CVariant CWeatherScenario::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexScenarioIndex: + return CVariant::fromValue(m_scenarioIndex); + case IndexScenarioName: + return CVariant::fromValue(m_scenarioName); + case IndexScenarioDescription: + return CVariant::fromValue(m_scenarioDescription); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CWeatherScenario::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexScenarioIndex: + setIndex(variant.value()); + break; + case IndexScenarioName: + setName(variant.value()); + break; + case IndexScenarioDescription: + setDescription(variant.value()); + break; + default: + CValueObject::setPropertyByIndex(index, variant); + break; + } + } + + QString CWeatherScenario::convertToQString(bool /** i18n **/) const + { + return m_scenarioName; + } + + } // namespace +} // namespace diff --git a/src/blackmisc/weather/weatherscenario.h b/src/blackmisc/weather/weatherscenario.h new file mode 100644 index 000000000..745d39a04 --- /dev/null +++ b/src/blackmisc/weather/weatherscenario.h @@ -0,0 +1,105 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_WEATHER_WEATHERSCENARIO_H +#define BLACKMISC_WEATHER_WEATHERSCENARIO_H + +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/valueobject.h" + +#include +#include + +namespace BlackMisc +{ + namespace Weather + { + /*! + * Value object for fixed weather scenario + */ + class BLACKMISC_EXPORT CWeatherScenario : public CValueObject + { + public: + //! Scenario Index + enum ScenarioIndex + { + ClearSky, + Thunderstorm, + RealWeather + }; + + //! Properties by index + enum ColumnIndex + { + IndexScenarioIndex = BlackMisc::CPropertyIndex::GlobalIndexCWeatherScenario, + IndexScenarioName, + IndexScenarioDescription + }; + + //! \copydoc BlackMisc::CValueObject::registerMetadata + static void registerMetadata(); + + //! Default constructor. + CWeatherScenario() = default; + + //! Constructor + CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description); + + //! Set scenario index + void setIndex(ScenarioIndex index) { m_scenarioIndex = index; } + + //! Get scenario index + ScenarioIndex getIndex() const { return m_scenarioIndex; } + + //! Set scenario name + void setName(const QString &name) { m_scenarioName = name; } + + //! Get scenario name + QString getName() const { return m_scenarioName; } + + //! Set scenario description + void setDescription(const QString &description) { m_scenarioDescription = description; } + + //! Get scenario description + QString getDescription() const { return m_scenarioDescription; } + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! Is scenario the real weather scenario? + static bool isRealWeatherScenario(const CWeatherScenario &scenario) { return scenario.getIndex() == RealWeather; } + + private: + ScenarioIndex m_scenarioIndex = ClearSky; + QString m_scenarioName; + QString m_scenarioDescription; + + BLACK_METACLASS( + CWeatherScenario, + BLACK_METAMEMBER(scenarioIndex), + BLACK_METAMEMBER(scenarioName), + BLACK_METAMEMBER(scenarioDescription) + ); + }; + + } //namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Weather::CWeatherScenario) +Q_DECLARE_METATYPE(BlackMisc::Weather::CWeatherScenario::ScenarioIndex) + +#endif //guard