From 59508305ae8cda6e967cf043dd0c47f483607672 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Wed, 13 Jan 2016 20:41:09 +0100 Subject: [PATCH] Add CTemperatureLayer, CTemperatureLayerList and CWindLayerList classes refs #556 --- src/blackmisc/propertyindex.h | 1 + .../weather/registermetadataweather.cpp | 3 + src/blackmisc/weather/temperaturelayer.cpp | 74 +++++++++++++++ src/blackmisc/weather/temperaturelayer.h | 90 +++++++++++++++++++ .../weather/temperaturelayerlist.cpp | 33 +++++++ src/blackmisc/weather/temperaturelayerlist.h | 52 +++++++++++ src/blackmisc/weather/weather.h | 3 + src/blackmisc/weather/windlayerlist.cpp | 33 +++++++ src/blackmisc/weather/windlayerlist.h | 52 +++++++++++ 9 files changed, 341 insertions(+) create mode 100644 src/blackmisc/weather/temperaturelayer.cpp create mode 100644 src/blackmisc/weather/temperaturelayer.h create mode 100644 src/blackmisc/weather/temperaturelayerlist.cpp create mode 100644 src/blackmisc/weather/temperaturelayerlist.h create mode 100644 src/blackmisc/weather/windlayerlist.cpp create mode 100644 src/blackmisc/weather/windlayerlist.h diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index c8b5bf402..8bdbe07d6 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -69,6 +69,7 @@ namespace BlackMisc GlobalIndexCCloudLayer = 4100, GlobalIndexCPresentWeather = 4200, GlobalIndexCWindLayer = 4300, + GlobalIndexCTemperatureLayer = 4400, GlobalIndexICoordinateGeodetic = 5000, GlobalIndexCCoordinateGeodetic = 5100, GlobalIndexCClient = 6000, diff --git a/src/blackmisc/weather/registermetadataweather.cpp b/src/blackmisc/weather/registermetadataweather.cpp index 2e4f607d6..353da7eff 100644 --- a/src/blackmisc/weather/registermetadataweather.cpp +++ b/src/blackmisc/weather/registermetadataweather.cpp @@ -22,7 +22,10 @@ namespace BlackMisc CMetarSet::registerMetadata(); CPresentWeather::registerMetadata(); CPresentWeatherList::registerMetadata(); + CTemperatureLayer::registerMetadata(); + CTemperatureLayerList::registerMetadata(); CWindLayer::registerMetadata(); + CWindLayerList::registerMetadata(); } } // ns } // ns diff --git a/src/blackmisc/weather/temperaturelayer.cpp b/src/blackmisc/weather/temperaturelayer.cpp new file mode 100644 index 000000000..a9a4544b8 --- /dev/null +++ b/src/blackmisc/weather/temperaturelayer.cpp @@ -0,0 +1,74 @@ +/* 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/temperaturelayer.h" +#include "blackmisc/propertyindex.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include "blackmisc/variant.h" + +#include +#include + +using namespace BlackMisc::Aviation; +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackMisc +{ + namespace Weather + { + + CTemperatureLayer::CTemperatureLayer(const CAltitude &level, const CTemperature &value, double relativeHumidity) : + m_level(level), m_temperature(value), m_relativeHumidity(relativeHumidity) + { } + + CVariant CTemperatureLayer::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexLevel: + return CVariant::fromValue(m_level); + case IndexTemperature: + return CVariant::fromValue(m_temperature); + case IndexRelativeHumidity: + return CVariant::fromValue(m_relativeHumidity); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CTemperatureLayer::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexLevel: + setLevel(variant.value()); + break; + case IndexTemperature: + setTemperature(variant.value()); + break; + case IndexRelativeHumidity: + setRelativeHumidity(variant.value()); + break; + default: + CValueObject::setPropertyByIndex(variant, index); + break; + } + } + + QString CTemperatureLayer::convertToQString(bool /** i18n **/) const + { + return QString("%1 %2 at %3").arg(m_temperature.toQString(), QString::number(m_relativeHumidity), m_level.toQString()); + } + + } // namespace +} // namespace diff --git a/src/blackmisc/weather/temperaturelayer.h b/src/blackmisc/weather/temperaturelayer.h new file mode 100644 index 000000000..2b968c02a --- /dev/null +++ b/src/blackmisc/weather/temperaturelayer.h @@ -0,0 +1,90 @@ +/* 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_TEMPERATURELAYER_H +#define BLACKMISC_WEATHER_TEMPERATURELAYER_H + +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/valueobject.h" +#include "blackmisc/propertyindex.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include "blackmisc/aviation/altitude.h" +#include "blackmisc/pq/temperature.h" + +namespace BlackMisc +{ + namespace Weather + { + /*! + * Value object for a temperature layer + */ + class BLACKMISC_EXPORT CTemperatureLayer : public CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexTemperatureLayer = BlackMisc::CPropertyIndex::GlobalIndexCTemperatureLayer, + IndexLevel, + IndexTemperature, + IndexRelativeHumidity + }; + + //! Default constructor. + CTemperatureLayer() = default; + + //! Constructor + CTemperatureLayer(const BlackMisc::Aviation::CAltitude &level, const PhysicalQuantities::CTemperature &value, double relativeHumidity); + + //! Set level + void setLevel(const BlackMisc::Aviation::CAltitude &level) { m_level = level; } + + //! Get level + BlackMisc::Aviation::CAltitude getLevel() const { return m_level; } + + //! Set temperature + void setTemperature(const PhysicalQuantities::CTemperature &value) { m_temperature = value; } + + //! Get temperature + PhysicalQuantities::CTemperature getTemperature() const { return m_temperature; } + + //! Set relative humidity + void setRelativeHumidity(double value) { m_relativeHumidity = value; } + + //! Get relative humidity + double getRelativeHumidity() const { return m_relativeHumidity; } + + //! \copydoc CValueObject::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc CValueObject::setPropertyByIndex + void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index); + + //! \copydoc CValueObject::convertToQString + QString convertToQString(bool i18n = false) const; + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CTemperatureLayer) + BlackMisc::Aviation::CAltitude m_level; + PhysicalQuantities::CTemperature m_temperature; + double m_relativeHumidity = 0; + }; + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Weather::CTemperatureLayer) +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Weather::CTemperatureLayer, ( + attr(o.m_level), + attr(o.m_temperature), + attr(o.m_relativeHumidity) +)) + +#endif // guard diff --git a/src/blackmisc/weather/temperaturelayerlist.cpp b/src/blackmisc/weather/temperaturelayerlist.cpp new file mode 100644 index 000000000..3d367a1d1 --- /dev/null +++ b/src/blackmisc/weather/temperaturelayerlist.cpp @@ -0,0 +1,33 @@ +/* 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 "temperaturelayerlist.h" + +using namespace BlackMisc::Aviation; + +namespace BlackMisc +{ + namespace Weather + { + CTemperatureLayerList::CTemperatureLayerList(const CSequence &other) : + CSequence(other) + { } + + bool CTemperatureLayerList::containsLevel(const CAltitude &level) const + { + return contains(&CTemperatureLayer::getLevel, level); + } + + CTemperatureLayer CTemperatureLayerList::findByLevel(const CAltitude &level) const + { + return findFirstByOrDefault(&CTemperatureLayer::getLevel, level); + } + + } // namespace +} // namespace diff --git a/src/blackmisc/weather/temperaturelayerlist.h b/src/blackmisc/weather/temperaturelayerlist.h new file mode 100644 index 000000000..9a91cc163 --- /dev/null +++ b/src/blackmisc/weather/temperaturelayerlist.h @@ -0,0 +1,52 @@ +/* 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_TEMPERATURELAYERLIST_H +#define BLACKMISC_WEATHER_TEMPERATURELAYERLIST_H + +#include "temperaturelayer.h" +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/sequence.h" + +namespace BlackMisc +{ + namespace Weather + { + /*! + * Value object encapsulating a set of temperature layers + */ + class BLACKMISC_EXPORT CTemperatureLayerList : + public CSequence, + public BlackMisc::Mixin::MetaType + { + public: + BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CTemperatureLayerList) + + //! Default constructor. + CTemperatureLayerList() = default; + + //! Construct from a base class object. + CTemperatureLayerList(const CSequence &other); + + //! Contains temperature layer with level? + bool containsLevel(const BlackMisc::Aviation::CAltitude &level) const; + + //! Find cloud layer by level + CTemperatureLayer findByLevel(const BlackMisc::Aviation::CAltitude &level) const; + }; + + } //namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Weather::CTemperatureLayerList) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/weather/weather.h b/src/blackmisc/weather/weather.h index d6cb47a5f..234703945 100644 --- a/src/blackmisc/weather/weather.h +++ b/src/blackmisc/weather/weather.h @@ -23,6 +23,9 @@ #include "blackmisc/weather/metarset.h" #include "blackmisc/weather/presentweather.h" #include "blackmisc/weather/presentweatherlist.h" +#include "blackmisc/weather/temperaturelayer.h" +#include "blackmisc/weather/temperaturelayerlist.h" #include "blackmisc/weather/windlayer.h" +#include "blackmisc/weather/windlayerlist.h" #endif // guard diff --git a/src/blackmisc/weather/windlayerlist.cpp b/src/blackmisc/weather/windlayerlist.cpp new file mode 100644 index 000000000..c62af6a49 --- /dev/null +++ b/src/blackmisc/weather/windlayerlist.cpp @@ -0,0 +1,33 @@ +/* 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 "windlayerlist.h" + +using namespace BlackMisc::Aviation; + +namespace BlackMisc +{ + namespace Weather + { + CWindLayerList::CWindLayerList(const CSequence &other) : + CSequence(other) + { } + + bool CWindLayerList::containsLevel(const CAltitude &level) const + { + return contains(&CWindLayer::getLevel, level); + } + + CWindLayer CWindLayerList::findByLevel(const CAltitude &level) const + { + return findFirstByOrDefault(&CWindLayer::getLevel, level); + } + + } // namespace +} // namespace diff --git a/src/blackmisc/weather/windlayerlist.h b/src/blackmisc/weather/windlayerlist.h new file mode 100644 index 000000000..90566ae2c --- /dev/null +++ b/src/blackmisc/weather/windlayerlist.h @@ -0,0 +1,52 @@ +/* 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_WINDLAYERLIST_H +#define BLACKMISC_WEATHER_WINDLAYERLIST_H + +#include "windlayer.h" +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/sequence.h" + +namespace BlackMisc +{ + namespace Weather + { + /*! + * Value object encapsulating a set of wind layers + */ + class BLACKMISC_EXPORT CWindLayerList : + public CSequence, + public BlackMisc::Mixin::MetaType + { + public: + BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CWindLayerList) + + //! Default constructor. + CWindLayerList() = default; + + //! Construct from a base class object. + CWindLayerList(const CSequence &other); + + //! Contains cloud layer with level? + bool containsLevel(const BlackMisc::Aviation::CAltitude &level) const; + + //! Find cloud layer by level + CWindLayer findByLevel(const BlackMisc::Aviation::CAltitude &level) const; + }; + + } //namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Weather::CWindLayerList) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard