Add CTemperatureLayer, CTemperatureLayerList and CWindLayerList classes

refs #556
This commit is contained in:
Roland Winklmeier
2016-01-13 20:41:09 +01:00
parent c47d56b984
commit 59508305ae
9 changed files with 341 additions and 0 deletions

View File

@@ -69,6 +69,7 @@ namespace BlackMisc
GlobalIndexCCloudLayer = 4100,
GlobalIndexCPresentWeather = 4200,
GlobalIndexCWindLayer = 4300,
GlobalIndexCTemperatureLayer = 4400,
GlobalIndexICoordinateGeodetic = 5000,
GlobalIndexCCoordinateGeodetic = 5100,
GlobalIndexCClient = 6000,

View File

@@ -22,7 +22,10 @@ namespace BlackMisc
CMetarSet::registerMetadata();
CPresentWeather::registerMetadata();
CPresentWeatherList::registerMetadata();
CTemperatureLayer::registerMetadata();
CTemperatureLayerList::registerMetadata();
CWindLayer::registerMetadata();
CWindLayerList::registerMetadata();
}
} // ns
} // ns

View File

@@ -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 <tuple>
#include <QRegularExpression>
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<ColumnIndex>();
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<CTemperatureLayer>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexLevel:
setLevel(variant.value<CAltitude>());
break;
case IndexTemperature:
setTemperature(variant.value<CTemperature>());
break;
case IndexRelativeHumidity:
setRelativeHumidity(variant.value<double>());
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

View File

@@ -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<CTemperatureLayer>
{
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

View File

@@ -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<CTemperatureLayer> &other) :
CSequence<CTemperatureLayer>(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

View File

@@ -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<CTemperatureLayer>,
public BlackMisc::Mixin::MetaType<CTemperatureLayerList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CTemperatureLayerList)
//! Default constructor.
CTemperatureLayerList() = default;
//! Construct from a base class object.
CTemperatureLayerList(const CSequence<CTemperatureLayer> &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<BlackMisc::Weather::CTemperatureLayer>)
#endif //guard

View File

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

View File

@@ -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<CWindLayer> &other) :
CSequence<CWindLayer>(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

View File

@@ -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<CWindLayer>,
public BlackMisc::Mixin::MetaType<CWindLayerList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CWindLayerList)
//! Default constructor.
CWindLayerList() = default;
//! Construct from a base class object.
CWindLayerList(const CSequence<CWindLayer> &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<BlackMisc::Weather::CWindLayer>)
#endif //guard