swift
Loading...
Searching...
No Matches
windlayer.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
8
9using namespace swift::misc::physical_quantities;
10using namespace swift::misc::aviation;
11
12SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::weather, CWindLayer)
13
14namespace swift::misc::weather
15{
16
17 CWindLayer::CWindLayer(const CAltitude &level, const CAngle &direction, const CSpeed &speed,
18 const CSpeed &gustSpeed)
19 : m_level(level), m_directionMain(direction), m_speed(speed), m_gustSpeed(gustSpeed)
20 {}
21
23 {
24 if (index.isMyself())
25 {
26 return QVariant::fromValue(*this);
27 }
28 const auto i = index.frontCasted<ColumnIndex>();
29 switch (i)
30 {
31 case IndexLevel: return QVariant::fromValue(m_level);
32 case IndexDirection: return QVariant::fromValue(m_directionMain);
33 case IndexDirectionVariable: return QVariant::fromValue(m_directionVariable);
34 case IndexSpeed: return QVariant::fromValue(m_speed);
35 case IndexGustSpeed: return QVariant::fromValue(m_gustSpeed);
36 default: return CValueObject::propertyByIndex(index);
37 }
38 }
39
41 {
42 if (index.isMyself())
43 {
44 (*this) = variant.value<CWindLayer>();
45 return;
46 }
47 const auto i = index.frontCasted<ColumnIndex>();
48 switch (i)
49 {
50 case IndexLevel: setLevel(variant.value<CAltitude>()); break;
51 case IndexDirection: setDirection(variant.value<CAngle>()); break;
52 case IndexDirectionVariable: setDirectionVariable(variant.toBool()); break;
53 case IndexSpeed: setSpeed(variant.value<CSpeed>()); break;
54 case IndexGustSpeed: setGustSpeed(variant.value<CSpeed>()); break;
55 default: CValueObject::setPropertyByIndex(index, variant); break;
56 }
57 }
58
60 {
61 QString windAsString = QString("Wind: ");
62 if (m_directionVariable)
63 windAsString += "variable ";
64 else
65 windAsString += QStringLiteral("%1 ").arg(m_directionMain.toQString());
66
67 if (m_directionFrom != CAngle() && m_directionTo != CAngle())
68 {
69 windAsString += QStringLiteral("variable between %1 and %2 ")
70 .arg(m_directionFrom.toQString(), m_directionTo.toQString());
71 }
72
73 windAsString += QStringLiteral("at %2").arg(m_speed.toQString());
74 if (m_gustSpeed.value() > 0.5) windAsString += QStringLiteral(" and gusts at %1").arg(m_gustSpeed.toQString());
75 return windAsString;
76 }
77
78} // 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
Physical unit angle (radians, degrees).
Definition angle.h:23
void setDirection(const physical_quantities::CAngle &main)
Set direction.
Definition windlayer.h:54
CWindLayer()=default
Default constructor.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition windlayer.cpp:40
ColumnIndex
Properties by index.
Definition windlayer.h:32
void setGustSpeed(const physical_quantities::CSpeed &gustSpeed)
Set gust speed.
Definition windlayer.h:95
QString convertToQString(bool i18n=false) const
Cast as QString.
Definition windlayer.cpp:59
void setDirectionVariable(bool variable=true)
Set direction to variable.
Definition windlayer.h:83
void setLevel(const swift::misc::aviation::CAltitude &level)
Set level.
Definition windlayer.h:48
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
Definition windlayer.cpp:22
void setSpeed(const physical_quantities::CSpeed &speed)
Set speed.
Definition windlayer.h:89
QString arg(Args &&... args) const const
QVariant fromValue(T &&value)
bool toBool() const const
T value() const &const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition valueobject.h:67