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_recognitionOn(recognition), m_cabinOn(cabin)
24  {}
25 
26  CAircraftLights::CAircraftLights(bool strobeOn, bool landingOn, bool taxiOn, bool beaconOn, bool navOn, bool logoOn,
27  bool recognition, bool cabin, bool wing)
28  : m_strobeOn(strobeOn), m_landingOn(landingOn), m_taxiOn(taxiOn), m_beaconOn(beaconOn), m_navOn(navOn),
29  m_logoOn(logoOn), m_recognitionOn(recognition), m_cabinOn(cabin), m_wingOn(wing)
30  {}
31 
33  {
34  return CAircraftLights { true, true, true, true, true, true, true, true, true };
35  }
36 
38  {
39  return CAircraftLights { false, false, false, false, false, false, false, false, false };
40  }
41 
43  {
44  Q_UNUSED(i18n);
45  const QString s = u"strobe: " % boolToYesNo(m_strobeOn) % u" landing: " % boolToYesNo(m_landingOn) %
46  u" taxi: " % boolToYesNo(m_taxiOn) % u" beacon: " % boolToYesNo(m_beaconOn) % u" nav: " %
47  boolToYesNo(m_navOn) % u" logo: " % boolToYesNo(m_logoOn) % u" recognition: " %
48  boolToYesNo(m_recognitionOn) % u" cabin: " % boolToYesNo(m_cabinOn) % u" cabin: " %
49  boolToYesNo(m_wingOn);
50  return s;
51  }
52 
54  {
55  if (index.isMyself()) { return QVariant::fromValue(*this); }
56 
57  const auto i = index.frontCasted<ColumnIndex>();
58  switch (i)
59  {
60  case IndexIsNull: return QVariant::fromValue(this->isNull());
61  case IndexBeacon: return QVariant::fromValue(m_beaconOn);
62  case IndexLanding: return QVariant::fromValue(m_landingOn);
63  case IndexLogo: return QVariant::fromValue(m_logoOn);
64  case IndexNav: return QVariant::fromValue(m_navOn);
65  case IndexStrobe: return QVariant::fromValue(m_strobeOn);
66  case IndexTaxi: return QVariant::fromValue(m_taxiOn);
67  case IndexRecognition: return QVariant::fromValue(m_recognitionOn);
68  case IndexCabin: return QVariant::fromValue(m_cabinOn);
69  case IndexWing: return QVariant::fromValue(m_wingOn);
70  default: return CValueObject::propertyByIndex(index);
71  }
72  }
73 
75  {
76  if (index.isMyself())
77  {
78  (*this) = variant.value<CAircraftLights>();
79  return;
80  }
81 
82  const auto i = index.frontCasted<ColumnIndex>();
83  switch (i)
84  {
85  case IndexIsNull: m_isNull = variant.toBool(); break;
86  case IndexBeacon: m_beaconOn = variant.toBool(); break;
87  case IndexLanding: m_landingOn = variant.toBool(); break;
88  case IndexLogo: m_logoOn = variant.toBool(); break;
89  case IndexNav: m_navOn = variant.toBool(); break;
90  case IndexStrobe: m_strobeOn = variant.toBool(); break;
91  case IndexTaxi: m_taxiOn = variant.toBool(); break;
92  case IndexCabin: m_cabinOn = variant.toBool(); break;
93  case IndexRecognition: m_recognitionOn = variant.toBool(); break;
94  case IndexWing: m_wingOn = variant.toBool(); break;
95  default: CValueObject::setPropertyByIndex(index, variant); break;
96  }
97  }
98 
100  {
101  const auto i = index.frontCasted<ColumnIndex>();
102  switch (i)
103  {
104  case IndexIsNull: return Compare::compare(m_isNull, compareValue.isNull());
105  case IndexBeacon: return Compare::compare(m_beaconOn, compareValue.isBeaconOn());
106  case IndexLanding: return Compare::compare(m_landingOn, compareValue.isLandingOn());
107  case IndexLogo: return Compare::compare(m_logoOn, compareValue.isLogoOn());
108  case IndexNav: return Compare::compare(m_navOn, compareValue.isNavOn());
109  case IndexStrobe: return Compare::compare(m_strobeOn, compareValue.isStrobeOn());
110  case IndexTaxi: return Compare::compare(m_taxiOn, compareValue.isTaxiOn());
111  case IndexCabin: return Compare::compare(m_cabinOn, compareValue.isCabinOn());
112  case IndexRecognition: return Compare::compare(m_recognitionOn, compareValue.isRecognitionOn());
113  case IndexWing: return Compare::compare(m_wingOn, compareValue.isWingOn());
114  default: break;
115  }
116  return 0;
117  }
118 
120  {
121  m_beaconOn = true;
122  m_landingOn = true;
123  m_logoOn = true;
124  m_navOn = true;
125  m_strobeOn = true;
126  m_taxiOn = true;
127  m_cabinOn = true;
128  m_recognitionOn = true;
129  m_wingOn = true;
130  }
131 
133  {
134  m_beaconOn = false;
135  m_landingOn = false;
136  m_logoOn = false;
137  m_navOn = false;
138  m_strobeOn = false;
139  m_taxiOn = false;
140  m_recognitionOn = false;
141  m_cabinOn = false;
142  m_wingOn = false;
143  }
144 } // 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 isWingOn() const
Wing light 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:158
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:165
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.
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