swift
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 
9 using namespace swift::misc::physical_quantities;
10 using namespace swift::misc::aviation;
11 
12 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::weather, CWindLayer)
13 
14 namespace 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()) { return QVariant::fromValue(*this); }
25  ColumnIndex i = index.frontCasted<ColumnIndex>();
26  switch (i)
27  {
28  case IndexLevel: return QVariant::fromValue(m_level);
29  case IndexDirection: return QVariant::fromValue(m_directionMain);
30  case IndexDirectionVariable: return QVariant::fromValue(m_directionVariable);
31  case IndexSpeed: return QVariant::fromValue(m_speed);
32  case IndexGustSpeed: return QVariant::fromValue(m_gustSpeed);
33  default: return CValueObject::propertyByIndex(index);
34  }
35  }
36 
37  void CWindLayer::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
38  {
39  if (index.isMyself())
40  {
41  (*this) = variant.value<CWindLayer>();
42  return;
43  }
44  ColumnIndex i = index.frontCasted<ColumnIndex>();
45  switch (i)
46  {
47  case IndexLevel: setLevel(variant.value<CAltitude>()); break;
48  case IndexDirection: setDirection(variant.value<CAngle>()); break;
49  case IndexDirectionVariable: setDirectionVariable(variant.toBool()); break;
50  case IndexSpeed: setSpeed(variant.value<CSpeed>()); break;
51  case IndexGustSpeed: setGustSpeed(variant.value<CSpeed>()); break;
52  default: CValueObject::setPropertyByIndex(index, variant); break;
53  }
54  }
55 
56  QString CWindLayer::convertToQString(bool ) const
57  {
58  QString windAsString = QString("Wind: ");
59  if (m_directionVariable)
60  windAsString += "variable ";
61  else
62  windAsString += QStringLiteral("%1 ").arg(m_directionMain.toQString());
63 
64  if (m_directionFrom != CAngle() && m_directionTo != CAngle())
65  {
66  windAsString += QStringLiteral("variable between %1 and %2 ")
67  .arg(m_directionFrom.toQString(), m_directionTo.toQString());
68  }
69 
70  windAsString += QStringLiteral("at %2").arg(m_speed.toQString());
71  if (m_gustSpeed.value() > 0.5) windAsString += QStringLiteral(" and gusts at %1").arg(m_gustSpeed.toQString());
72  return windAsString;
73  }
74 
75 } // 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
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: mixinindex.h:160
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:167
QString toQString(bool i18n=false) const
Cast as QString.
Definition: mixinstring.h:76
Physical unit angle (radians, degrees)
Definition: angle.h:23
double value(MU unit) const
Value in given unit.
Value object for a wind layer.
Definition: windlayer.h:28
void setDirection(const physical_quantities::CAngle &main)
Set direction.
Definition: windlayer.h:54
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: windlayer.cpp:37
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:56
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
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67