swift
aircraftlights.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QStringBuilder>
7 
9 #include "misc/stringutils.h"
10 
11 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::aviation, CAircraftLights)
12 
13 namespace swift::misc::aviation
14 {
15  CAircraftLights::CAircraftLights(bool strobeOn, bool landingOn, bool taxiOn, bool beaconOn, bool navOn, bool logoOn)
16  : m_strobeOn(strobeOn), m_landingOn(landingOn), m_taxiOn(taxiOn), m_beaconOn(beaconOn), m_navOn(navOn),
17  m_logoOn(logoOn)
18  {}
19 
20  CAircraftLights::CAircraftLights(bool strobeOn, bool landingOn, bool taxiOn, bool beaconOn, bool navOn, bool logoOn,
21  bool recognition, bool cabin)
22  : m_strobeOn(strobeOn), m_landingOn(landingOn), m_taxiOn(taxiOn), m_beaconOn(beaconOn), m_navOn(navOn),
23  m_logoOn(logoOn), m_recognition(recognition), m_cabin(cabin)
24  {}
25 
27  {
28  return CAircraftLights { true, true, true, true, true, true, true, true };
29  }
30 
32  {
33  return CAircraftLights { false, false, false, false, false, false, false, false };
34  }
35 
36  QString CAircraftLights::convertToQString(bool i18n) const
37  {
38  Q_UNUSED(i18n);
39  const QString s = u"strobe: " % boolToYesNo(m_strobeOn) % u" landing: " % boolToYesNo(m_landingOn) %
40  u" taxi: " % boolToYesNo(m_taxiOn) % u" beacon: " % boolToYesNo(m_beaconOn) % u" nav: " %
41  boolToYesNo(m_navOn) % u" logo: " % boolToYesNo(m_logoOn) % u" recognition: " %
42  boolToYesNo(m_recognition) % u" cabin: " % boolToYesNo(m_cabin);
43  return s;
44  }
45 
47  {
48  if (index.isMyself()) { return QVariant::fromValue(*this); }
49 
50  const ColumnIndex i = index.frontCasted<ColumnIndex>();
51  switch (i)
52  {
53  case IndexIsNull: return QVariant::fromValue(this->isNull());
54  case IndexBeacon: return QVariant::fromValue(m_beaconOn);
55  case IndexLanding: return QVariant::fromValue(m_landingOn);
56  case IndexLogo: return QVariant::fromValue(m_logoOn);
57  case IndexNav: return QVariant::fromValue(m_navOn);
58  case IndexStrobe: return QVariant::fromValue(m_strobeOn);
59  case IndexTaxi: return QVariant::fromValue(m_taxiOn);
60  case IndexRecognition: return QVariant::fromValue(m_recognition);
61  case IndexCabin: return QVariant::fromValue(m_cabin);
62  default: return CValueObject::propertyByIndex(index);
63  }
64  }
65 
66  void CAircraftLights::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
67  {
68  if (index.isMyself())
69  {
70  (*this) = variant.value<CAircraftLights>();
71  return;
72  }
73 
74  const ColumnIndex i = index.frontCasted<ColumnIndex>();
75  switch (i)
76  {
77  case IndexIsNull: m_isNull = variant.toBool(); break;
78  case IndexBeacon: m_beaconOn = variant.toBool(); break;
79  case IndexLanding: m_landingOn = variant.toBool(); break;
80  case IndexLogo: m_logoOn = variant.toBool(); break;
81  case IndexNav: m_navOn = variant.toBool(); break;
82  case IndexStrobe: m_strobeOn = variant.toBool(); break;
83  case IndexTaxi: m_taxiOn = variant.toBool(); break;
84  case IndexCabin: m_cabin = variant.toBool(); break;
85  case IndexRecognition: m_recognition = variant.toBool(); break;
86  default: CValueObject::setPropertyByIndex(index, variant); break;
87  }
88  }
89 
91  {
92  const ColumnIndex i = index.frontCasted<ColumnIndex>();
93  switch (i)
94  {
95  case IndexIsNull: return Compare::compare(m_isNull, compareValue.isNull());
96  case IndexBeacon: return Compare::compare(m_beaconOn, compareValue.isBeaconOn());
97  case IndexLanding: return Compare::compare(m_landingOn, compareValue.isLandingOn());
98  case IndexLogo: return Compare::compare(m_logoOn, compareValue.isLogoOn());
99  case IndexNav: return Compare::compare(m_navOn, compareValue.isNavOn());
100  case IndexStrobe: return Compare::compare(m_strobeOn, compareValue.isStrobeOn());
101  case IndexTaxi: return Compare::compare(m_taxiOn, compareValue.isTaxiOn());
102  case IndexCabin: return Compare::compare(m_cabin, compareValue.isCabinOn());
103  case IndexRecognition: return Compare::compare(m_recognition, compareValue.isRecognitionOn());
104  default: break;
105  }
106  return 0;
107  }
108 
110  {
111  m_beaconOn = true;
112  m_landingOn = true;
113  m_logoOn = true;
114  m_navOn = true;
115  m_strobeOn = true;
116  m_taxiOn = true;
117  m_cabin = true;
118  m_recognition = true;
119  }
120 
122  {
123  m_beaconOn = false;
124  m_landingOn = false;
125  m_logoOn = false;
126  m_navOn = false;
127  m_strobeOn = false;
128  m_taxiOn = false;
129  m_recognition = false;
130  m_cabin = false;
131  }
132 } // namespace swift::misc::aviation
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.
Value object encapsulating information about aircraft's lights.
static CAircraftLights allLightsOn()
Returns object with all lights switched on.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
int comparePropertyByIndex(CPropertyIndexRef index, const CAircraftLights &compareValue) const
Compare by index.
bool isRecognitionOn() const
Recognition lights on?
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
CAircraftLights()=default
Default constructor.
bool isCabinOn() const
Cabin lights on?
bool isLandingOn() const
Landing lights on?
bool isBeaconOn() const
Beacon lights on?
static CAircraftLights allLightsOff()
Returns object with all lights switched off.
QString convertToQString(bool i18n=false) const
Cast as QString.
bool isNavOn() const
Nac lights on?
bool isLogoOn() const
Logo lights on?
bool isTaxiOn() const
Taxi lights on?
bool isStrobeOn() const
Strobes lights on?
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
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67