swift
Loading...
Searching...
No Matches
cloudlayer.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QHash>
7
8using namespace swift::misc::aviation;
9
10SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::weather, CCloudLayer)
11
12namespace swift::misc::weather
13{
14
15 CCloudLayer::CCloudLayer(const CAltitude &base, const CAltitude &top, Coverage coverage) : m_base(base), m_top(top)
16 {
17 setCoverage(coverage);
18 }
19
20 CCloudLayer::CCloudLayer(const CAltitude &base, const CAltitude &top, double precipitationRate,
21 Precipitation precipitation, Clouds clouds, Coverage coverage)
22 : m_base(base), m_top(top), m_precipitationRate(precipitationRate), m_precipitation(precipitation),
23 m_clouds(clouds)
24 {
25 setCoverage(coverage);
26 }
27
28 void CCloudLayer::setCoverage(Coverage coverage) { m_coveragePercent = 100 * coverage / 4; }
29
31 {
32 if (m_coveragePercent > 85)
33 {
34 return Overcast;
35 }
36 if (m_coveragePercent > 60 && m_coveragePercent <= 85)
37 {
38 return Broken;
39 }
40 if (m_coveragePercent > 30 && m_coveragePercent <= 60)
41 {
42 return Scattered;
43 }
44 if (m_coveragePercent > 10 && m_coveragePercent <= 30)
45 {
46 return Few;
47 }
48 return None;
49 }
50
52 {
53 if (index.isMyself())
54 {
55 return QVariant::fromValue(*this);
56 }
57 switch (index.frontCasted<ColumnIndex>())
58 {
59 case IndexBase: return QVariant::fromValue(m_base);
60 case IndexTop: return QVariant::fromValue(m_top);
61 case IndexPrecipitationRate: return QVariant::fromValue(m_precipitationRate);
62 case IndexPrecipitation: return QVariant::fromValue(m_precipitation);
63 case IndexClouds: return QVariant::fromValue(m_clouds);
64 case IndexCoveragePercent: return QVariant::fromValue(m_coveragePercent);
65 default: return CValueObject::propertyByIndex(index);
66 }
67 }
68
70 {
71 if (index.isMyself())
72 {
73 (*this) = variant.value<CCloudLayer>();
74 return;
75 }
76 switch (index.frontCasted<ColumnIndex>())
77 {
78 case IndexBase: setBase(variant.value<CAltitude>()); break;
79 case IndexTop: setTop(variant.value<CAltitude>()); break;
80 case IndexPrecipitationRate: setPrecipitationRate(variant.value<int>()); break;
81 case IndexPrecipitation: setPrecipitation(variant.value<Precipitation>()); break;
82 case IndexClouds: setClouds(variant.value<Clouds>()); break;
83 case IndexCoveragePercent: setCoveragePercent(variant.value<int>()); break;
84 default: CValueObject::setPropertyByIndex(index, variant); break;
85 }
86 }
87
89 {
90 static const QHash<Coverage, QString> hash = {
91 { None, "" }, { Few, "few" }, { Scattered, "scattered" }, { Broken, "broken" }, { Overcast, "overcast" }
92 };
93
94 return QStringLiteral("%1 from %2 to %3").arg(hash.value(getCoverage()), m_base.toQString(), m_top.toQString());
95 }
96
97} // namespace swift::misc::weather
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
Altitude as used in aviation, can be AGL or MSL altitude.
Definition altitude.h:52
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition mixinindex.h:167
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition mixinindex.h:180
Precipitation
Precipitation Type.
Definition cloudlayer.h:53
void setBase(const misc::aviation::CAltitude &base)
Set base.
Definition cloudlayer.h:82
QString convertToQString(bool i18n=false) const
Cast as QString.
CCloudLayer()=default
Default constructor.
void setCoverage(Coverage coverage)
Set coverage.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
ColumnIndex
Properties by index.
Definition cloudlayer.h:62
Coverage getCoverage() const
Get coverage.
void setPrecipitationRate(double rate)
Set precipitation rate in mm/h.
Definition cloudlayer.h:94
void setClouds(Clouds type)
Set cloud type.
Definition cloudlayer.h:106
void setCoveragePercent(int coverage)
Set coverage in %.
Definition cloudlayer.h:118
void setPrecipitation(Precipitation type)
Set precipitation.
Definition cloudlayer.h:100
void setTop(const misc::aviation::CAltitude &top)
Set layer top.
Definition cloudlayer.h:88
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
T value(const Key &key) const const
QVariant fromValue(T &&value)
T value() const &const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition valueobject.h:67