Enroute Flight Navigation
A navigation app for VFR pilots
Waypoint.h
1/***************************************************************************
2 * Copyright (C) 2019-2024 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QGeoCoordinate>
24#include <QJsonObject>
25#include <QMap>
26#include <QQmlEngine>
27#include <QXmlStreamWriter>
28
29#include "units/Angle.h"
30
31
32namespace GeoMaps {
33
41
43{
44 Q_GADGET
45 QML_VALUE_TYPE(waypoint)
46
47
48 friend size_t qHash(const GeoMaps::Waypoint& waypoint);
49
50public:
62
72 Waypoint(const QGeoCoordinate& coordinate, const QString& name = {});
73
82 explicit Waypoint(const QJsonObject& geoJSONObject);
83
84
85 //
86 // PROPERTIES
87 //
88
95 Q_PROPERTY(QString category READ category CONSTANT)
96
97
102 Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate)
103
109 Q_PROPERTY(QString extendedName READ extendedName)
110
116 Q_PROPERTY(QString ICAOCode READ ICAOCode CONSTANT)
117
123 Q_PROPERTY(QString icon READ icon CONSTANT)
124
125 /* \brief Validity
126 *
127 * This property is set to true if the waypoint has a valid coordinate and
128 * if the properties satisfy the specifications outlined
129 * [here](https://github.com/Akaflieg-Freiburg/enrouteServer/wiki/GeoJSON-files-used-in-enroute-flight-navigation).
130 */
131 Q_PROPERTY(bool isValid READ isValid)
132
137 Q_PROPERTY(QString name READ name WRITE setName)
138
143 Q_PROPERTY(QString notes READ notes WRITE setNotes)
144
150 Q_PROPERTY(QString shortName READ shortName CONSTANT)
151
152 /* \brief Verbose description of waypoint properties
153 *
154 * This property holds a list of strings in meaningful order that describe
155 * the waypoint properties. This includes airport frequency, runway
156 * information, etc. The data is returned as a list of strings where the
157 * first four letters of each string indicate the type of data with an
158 * abbreviation that will be understood by pilots ("RWY ", "ELEV", etc.).
159 * The rest of the string will then contain the actual data.
160 */
161 Q_PROPERTY(QList<QString> tabularDescription READ tabularDescription)
162
170 Q_PROPERTY(QString twoLineTitle READ twoLineTitle)
171
178 Q_PROPERTY(QString type READ type CONSTANT)
179
184 Q_PROPERTY(Units::Angle variation READ variation CONSTANT)
185
186
187 //
188 // GETTER METHODS
189 //
190
195 [[nodiscard]] auto category() const -> QString
196 {
197 return m_properties.value(QStringLiteral("CAT")).toString();
198 }
199
204 [[nodiscard]] auto coordinate() const -> QGeoCoordinate
205 {
206 return m_coordinate;
207 }
208
213 [[nodiscard]] auto extendedName() const -> QString;
214
219 [[nodiscard]] auto ICAOCode() const -> QString
220 {
221 return m_properties.value(QStringLiteral("COD")).toString();
222 }
223
228 [[nodiscard]] auto icon() const -> QString;
229
234 [[nodiscard]] auto isValid() const -> bool;
235
240 [[nodiscard]] auto name() const -> QString
241 {
242 return m_properties.value(QStringLiteral("NAM")).toString();
243 }
244
249 [[nodiscard]] auto notes() const -> QString
250 {
251 return m_properties.value(QStringLiteral("NOT")).toString();
252 }
253
258 [[nodiscard]] auto shortName() const -> QString
259 {
260 if (ICAOCode().isEmpty()) {
261 return name();
262 }
263 return ICAOCode();
264 }
265
270 [[nodiscard]] auto tabularDescription() const -> QList<QString>;
271
276 [[nodiscard]] auto twoLineTitle() const -> QString;
277
282 [[nodiscard]] auto type() const -> QString
283 {
284 return m_properties.value(QStringLiteral("TYP")).toString();
285 }
286
291 [[nodiscard]] auto variation() const -> Units::Angle;
292
293
294 //
295 // SETTER METHODS
296 //
297
302 void setCoordinate(const QGeoCoordinate& newCoordinate)
303 {
304 m_coordinate = newCoordinate;
305 }
306
311 void setName(const QString &newName)
312 {
313 m_properties.insert(QStringLiteral("NAM"), newName);
314 }
315
320 void setNotes(const QString &newNotes)
321 {
322 m_properties.insert(QStringLiteral("NOT"), newNotes);
323 }
324
325
326 //
327 // METHODS
328 //
329
336 [[nodiscard]] Q_INVOKABLE bool operator==(const GeoMaps::Waypoint& other) const = default;
337
344 [[nodiscard]] Q_INVOKABLE bool operator!=(const GeoMaps::Waypoint& other) const = default;
345
352 [[nodiscard]] Q_INVOKABLE GeoMaps::Waypoint copy() const
353 {
354 return *this;
355 }
356
364 [[nodiscard]] Q_INVOKABLE bool isNear(const GeoMaps::Waypoint& other) const;
365
375 [[nodiscard]] QJsonObject toJSON() const;
376
384 void toGPX(QXmlStreamWriter& stream) const;
385
386protected:
387 QGeoCoordinate m_coordinate;
388 QMap<QString, QVariant> m_properties;
389};
390
397auto qHash(const GeoMaps::Waypoint& waypoint) -> size_t;
398
399} // namespace GeoMaps
400
401// Declare meta types
402Q_DECLARE_METATYPE(GeoMaps::Waypoint)
Waypoint, such as an airfield, a navaid station or a reporting point.
Definition Waypoint.h:43
QString icon
Suggested icon for use in GUI.
Definition Waypoint.h:123
Waypoint()
Constructs an invalid way point.
auto shortName() const -> QString
Getter method for property with same name.
Definition Waypoint.h:258
void setNotes(const QString &newNotes)
Set notes.
Definition Waypoint.h:320
QString name
Name of the waypoint.
Definition Waypoint.h:137
friend size_t qHash(const GeoMaps::Waypoint &waypoint)
qHash
QString category
Category of the waypoint.
Definition Waypoint.h:95
QString type
Type of the waypoint.
Definition Waypoint.h:178
Q_INVOKABLE bool operator!=(const GeoMaps::Waypoint &other) const =default
Comparison.
void toGPX(QXmlStreamWriter &stream) const
Serialization to GPX object.
Q_INVOKABLE bool operator==(const GeoMaps::Waypoint &other) const =default
Comparison.
Q_INVOKABLE GeoMaps::Waypoint copy() const
Deep copy.
Definition Waypoint.h:352
Units::Angle variation
Magnetic variation at the waypoint.
Definition Waypoint.h:184
QString extendedName
Extended name of the waypoint.
Definition Waypoint.h:109
QJsonObject toJSON() const
Serialization to GeoJSON object.
QString twoLineTitle
Two-line description of the waypoint name, for use in GUI.
Definition Waypoint.h:170
void setName(const QString &newName)
Set name.
Definition Waypoint.h:311
auto variation() const -> Units::Angle
Get variation.
auto tabularDescription() const -> QList< QString >
Getter method for property with the same name.
Q_INVOKABLE bool isNear(const GeoMaps::Waypoint &other) const
Check if other waypoint is geographically near *this.
QString ICAOCode
ICAO Code of the waypoint.
Definition Waypoint.h:116
auto extendedName() const -> QString
Getter function for property with the same name.
QGeoCoordinate coordinate
Coordinate of the waypoint.
Definition Waypoint.h:102
Waypoint(const QJsonObject &geoJSONObject)
Constructs a waypoint from a GeoJSON object.
auto notes() const -> QString
Getter method for property with same name.
Definition Waypoint.h:249
auto icon() const -> QString
Getter method for property with the same name.
QString shortName
Short name of the waypoint.
Definition Waypoint.h:150
QString notes
Notes attached to the waypoint.
Definition Waypoint.h:143
auto coordinate() const -> QGeoCoordinate
Getter function for property with the same name.
Definition Waypoint.h:204
void setCoordinate(const QGeoCoordinate &newCoordinate)
Set coordinate.
Definition Waypoint.h:302
Conversion between units used in aviation.
Definition Angle.h:34