Value object for fixed weather scenario

This value object can be used to load, save and distribute fixed
weather scenarios.

refs #663
This commit is contained in:
Roland Winklmeier
2016-06-05 22:40:18 +02:00
parent 027b344d11
commit de0729faad
7 changed files with 210 additions and 0 deletions

View File

@@ -79,6 +79,7 @@ namespace BlackMisc
GlobalIndexCTemperatureLayer = 4400,
GlobalIndexCGridPoint = 4500,
GlobalIndexCVisibilityLayer = 4600,
GlobalIndexCWeatherScenario = 4700,
GlobalIndexICoordinateGeodetic = 5000,
GlobalIndexCCoordinateGeodetic = 5100,
GlobalIndexCClient = 6000,

View File

@@ -32,6 +32,7 @@ namespace BlackMisc
CWeatherDataPluginInfo::registerMetadata();
CWeatherDataPluginInfoList::registerMetadata();
CWeatherGrid::registerMetadata();
CWeatherScenario::registerMetadata();
CWindLayer::registerMetadata();
CWindLayerList::registerMetadata();
}

View File

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

View File

@@ -55,6 +55,28 @@ namespace BlackMisc
return closest;
}
const QVector<CWeatherScenario> &CWeatherGrid::getAllScenarios()
{
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..." },
};
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(

View File

@@ -17,6 +17,7 @@
#include "blackmisc/sequence.h"
#include "blackmisc/variant.h"
#include "blackmisc/weather/gridpoint.h"
#include "blackmisc/weather/weatherscenario.h"
#include <QMetaType>
#include <initializer_list>
@@ -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<CWeatherScenario> &getAllScenarios ();
//! Get weather grid by fixed scenario
static const CWeatherGrid &getByScenario(const CWeatherScenario &scenario);
//! Clear weather grid
static const BlackMisc::Weather::CWeatherGrid &getClearWeatherGrid();

View File

@@ -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<CWeatherScenario>::registerMetadata();
qRegisterMetaType<ScenarioIndex>();
}
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<ColumnIndex>();
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<CWeatherScenario>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexScenarioIndex:
setIndex(variant.value<ScenarioIndex>());
break;
case IndexScenarioName:
setName(variant.value<QString>());
break;
case IndexScenarioDescription:
setDescription(variant.value<QString>());
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
QString CWeatherScenario::convertToQString(bool /** i18n **/) const
{
return m_scenarioName;
}
} // namespace
} // namespace

View File

@@ -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 <QMetaType>
#include <QVector>
namespace BlackMisc
{
namespace Weather
{
/*!
* Value object for fixed weather scenario
*/
class BLACKMISC_EXPORT CWeatherScenario : public CValueObject<CWeatherScenario>
{
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