swift
airport.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_AVIATION_AIRPORT_H
7 #define SWIFT_MISC_AVIATION_AIRPORT_H
8 
9 #include <array>
10 
11 #include <QMetaType>
12 #include <QString>
13 #include <QVector3D>
14 
16 #include "misc/country.h"
17 #include "misc/db/datastore.h"
19 #include "misc/geo/latitude.h"
20 #include "misc/geo/longitude.h"
21 #include "misc/metaclass.h"
22 #include "misc/pq/length.h"
23 #include "misc/propertyindexref.h"
24 #include "misc/swiftmiscexport.h"
25 #include "misc/valueobject.h"
26 
27 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::aviation, CAirport)
28 
29 namespace swift::misc::aviation
30 {
33  public CValueObject<CAirport>,
36  {
37  public:
40  {
41  IndexIcao = swift::misc::CPropertyIndexRef::GlobalIndexCAirport,
42  IndexLocation,
43  IndexDescriptiveName,
44  IndexPosition,
45  IndexCountry,
46  IndexElevation,
47  IndexOperating,
48  };
49 
51  CAirport() = default;
52 
54  CAirport(const QString &icao);
55 
58 
61  const QString &descriptiveName);
62 
64  const CAirportIcaoCode &getIcao() const { return m_icao; }
65 
67  const QString &getIcaoAsString() const { return m_icao.asString(); }
68 
70  void setIcao(const CAirportIcaoCode &icao) { m_icao = icao; }
71 
73  const QString &getLocation() const { return m_location; }
74 
76  QString getLocationPlusOptionalName() const;
77 
79  void setLocation(const QString &location) { this->m_location = location; }
80 
82  bool matchesLocation(const QString &location) const;
83 
85  const QString &getDescriptiveName() const { return m_descriptiveName; }
86 
88  void setDescriptiveName(const QString &name) { this->m_descriptiveName = name; }
89 
91  bool matchesDescriptiveName(const QString &name) const;
92 
94  const swift::misc::geo::CCoordinateGeodetic &getPosition() const { return m_position; }
95 
97  void setPosition(const swift::misc::geo::CCoordinateGeodetic &position) { this->m_position = position; }
98 
100  const CCountry &getCountry() const { return m_country; }
101 
103  void setCountry(const CCountry &country) { this->m_country = country; }
104 
107  const swift::misc::aviation::CAltitude &getElevation() const { return this->geodeticHeight(); }
108 
112  {
113  this->m_position.setGeodeticHeight(elevation);
114  }
115 
117  bool isOperating() const { return m_operating; }
118 
120  void setOperating(bool operating) { m_operating = operating; }
121 
123  void updateMissingParts(const CAirport &airport);
124 
127  {
128  return this->m_position.geodeticHeight();
129  }
130 
132  bool hasValidIcaoCode() const { return !this->getIcao().isEmpty(); }
133 
135  virtual bool isNull() const override;
136 
138  virtual swift::misc::geo::CLatitude latitude() const override { return this->getPosition().latitude(); }
139 
141  virtual swift::misc::geo::CLongitude longitude() const override { return this->getPosition().longitude(); }
142 
144  virtual QVector3D normalVector() const override { return this->getPosition().normalVector(); }
145 
147  virtual std::array<double, 3> normalVectorDouble() const override
148  {
149  return this->getPosition().normalVectorDouble();
150  }
151 
153  QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
154 
156  void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
157 
159  int comparePropertyByIndex(CPropertyIndexRef index, const CAirport &compareValue) const;
160 
162  QString convertToQString(bool i18n = false) const;
163 
165  static CAirport fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString());
166 
167  private:
168  QString m_location;
169  QString m_descriptiveName;
170  bool m_operating = true;
171  CAirportIcaoCode m_icao;
172  swift::misc::CCountry m_country;
174 
176  CAirport,
177  SWIFT_METAMEMBER(icao),
178  SWIFT_METAMEMBER(location),
179  SWIFT_METAMEMBER(descriptiveName),
180  SWIFT_METAMEMBER(position),
181  SWIFT_METAMEMBER(country),
182  SWIFT_METAMEMBER(operating),
183  // ICoordinateWithRelativePosition
184  SWIFT_METAMEMBER(relativeDistance),
185  SWIFT_METAMEMBER(relativeBearing),
186  // IDatastoreObjectWithIntegerKey
187  SWIFT_METAMEMBER(dbKey),
188  SWIFT_METAMEMBER(timestampMSecsSinceEpoch));
189  };
190 } // namespace swift::misc::aviation
191 
192 Q_DECLARE_METATYPE(swift::misc::aviation::CAirport)
193 
194 #endif // SWIFT_MISC_AVIATION_AIRPORT_H
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Value object encapsulating information about an airpot.
Definition: airport.h:36
virtual std::array< double, 3 > normalVectorDouble() const
Normal vector with double precision.
Definition: airport.h:147
void setPosition(const swift::misc::geo::CCoordinateGeodetic &position)
Set position.
Definition: airport.h:97
const swift::misc::aviation::CAltitude & geodeticHeight() const
Height, ellipsoidal or geodetic height (used in GPS)
Definition: airport.h:126
void setElevation(const swift::misc::aviation::CAltitude &elevation)
Elevation.
Definition: airport.h:111
virtual swift::misc::geo::CLongitude longitude() const
Longitude.
Definition: airport.h:141
void setLocation(const QString &location)
Set location.
Definition: airport.h:79
virtual QVector3D normalVector() const
Normal vector.
Definition: airport.h:144
void setIcao(const CAirportIcaoCode &icao)
Set ICAO code.
Definition: airport.h:70
const QString & getLocation() const
Get location (e.g. "London")
Definition: airport.h:73
void setDescriptiveName(const QString &name)
Set descriptive name.
Definition: airport.h:88
CAirport()=default
Default constructor.
const CCountry & getCountry() const
Get the country.
Definition: airport.h:100
void setOperating(bool operating)
Sets the value of.
Definition: airport.h:120
bool hasValidIcaoCode() const
Valid ICAO code.
Definition: airport.h:132
const swift::misc::aviation::CAltitude & getElevation() const
Elevation.
Definition: airport.h:107
const swift::misc::geo::CCoordinateGeodetic & getPosition() const
Get the position.
Definition: airport.h:94
const QString & getDescriptiveName() const
Get descriptive name.
Definition: airport.h:85
const CAirportIcaoCode & getIcao() const
Get ICAO code.
Definition: airport.h:64
const QString & getIcaoAsString() const
Get ICAO code as string.
Definition: airport.h:67
virtual swift::misc::geo::CLatitude latitude() const
Latitude.
Definition: airport.h:138
ColumnIndex
Properties by index.
Definition: airport.h:40
bool isOperating() const
Is the airport still active?
Definition: airport.h:117
void setCountry(const CCountry &country)
Set the country.
Definition: airport.h:103
Value object encapsulating information of airport ICAO data.
Altitude as used in aviation, can be AGL or MSL altitude.
Definition: altitude.h:52
Class from which a derived class can inherit datastore-related functions.
Definition: datastore.h:70
Interface (actually more an abstract class) of coordinates and relative position to something (normal...
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65