Enroute Flight Navigation
A navigation app for VFR pilots
Flight.h
1/***************************************************************************
2 * Copyright (C) 2026 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 <QDateTime>
24#include <QGeoCoordinate>
25#include <QJsonObject>
26#include <QQmlEngine>
27#include <QUuid>
28
29#include "units/Distance.h"
30
31namespace Flightlog {
32
39
40class Flight
41{
42 Q_GADGET
43 QML_VALUE_TYPE(flight)
44
45
46 Q_PROPERTY(QUuid uuid READ uuid)
47
49 Q_PROPERTY(QString departureICAO READ departureICAO WRITE setDepartureICAO)
50
52 Q_PROPERTY(QString arrivalICAO READ arrivalICAO WRITE setArrivalICAO)
53
55 Q_PROPERTY(QDateTime offBlockTime READ offBlockTime WRITE setOffBlockTime)
56
58 Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime)
59
61 Q_PROPERTY(QDateTime landingTime READ landingTime WRITE setLandingTime)
62
64 Q_PROPERTY(QDateTime onBlockTime READ onBlockTime WRITE setOnBlockTime)
65
67 Q_PROPERTY(QString pilotName READ pilotName WRITE setPilotName)
68
71
73 Q_PROPERTY(QString comments READ comments WRITE setComments)
74
76 Q_PROPERTY(int landingCount READ landingCount WRITE setLandingCount)
77
79 Q_PROPERTY(bool hasTrack READ hasTrack)
80
82 Q_PROPERTY(QString trackFile READ trackFile)
83
84public:
86 Flight() : m_id(QUuid::createUuid()) {}
87
88 //
89 // Getters
90 //
91
92 [[nodiscard]] auto uuid() const -> QUuid { return m_id; }
93
98 [[nodiscard]] auto departureICAO() const -> QString { return m_departureICAO; }
99
104 [[nodiscard]] auto arrivalICAO() const -> QString { return m_arrivalICAO; }
105
110 [[nodiscard]] auto offBlockTime() const -> QDateTime { return m_offBlockTime; }
111
116 [[nodiscard]] auto startTime() const -> QDateTime { return m_startTime; }
117
122 [[nodiscard]] auto landingTime() const -> QDateTime { return m_landingTime; }
123
128 [[nodiscard]] auto onBlockTime() const -> QDateTime { return m_onBlockTime; }
129
134 [[nodiscard]] auto pilotName() const -> QString { return m_pilotName; }
135
140 [[nodiscard]] auto aircraftCallsign() const -> QString { return m_aircraftCallsign; }
141
146 [[nodiscard]] auto comments() const -> QString { return m_comments; }
147
152 [[nodiscard]] auto landingCount() const -> int { return m_landingCount; }
153
158 [[nodiscard]] auto departureCoordinate() const -> QGeoCoordinate { return m_departureCoordinate; }
159
164 [[nodiscard]] auto arrivalCoordinate() const -> QGeoCoordinate { return m_arrivalCoordinate; }
165
170 [[nodiscard]] auto hasTrack() const -> bool { return !m_trackFile.isEmpty(); }
171
176 [[nodiscard]] auto trackFile() const -> QString { return m_trackFile; }
177
178 //
179 // Setters
180 //
181
186 void setDepartureICAO(const QString& icao) { m_departureICAO = icao; }
187
192 void setArrivalICAO(const QString& icao) { m_arrivalICAO = icao; }
193
198 void setOffBlockTime(const QDateTime& dt) { m_offBlockTime = dt; }
199
204 void setStartTime(const QDateTime& dt) { m_startTime = dt; }
205
210 void setLandingTime(const QDateTime& dt) { m_landingTime = dt; }
211
216 void setOnBlockTime(const QDateTime& dt) { m_onBlockTime = dt; }
217
222 void setPilotName(const QString& name) { m_pilotName = name; }
223
228 void setAircraftCallsign(const QString& callsign) { m_aircraftCallsign = callsign; }
229
234 void setComments(const QString& text) { m_comments = text; }
235
240 void setLandingCount(int count) { m_landingCount = count; }
241
246 void setDepartureCoordinate(const QGeoCoordinate& coord) { m_departureCoordinate = coord; }
247
252 void setArrivalCoordinate(const QGeoCoordinate& coord) { m_arrivalCoordinate = coord; }
253
258 void setTrackFile(const QString& fileName) { m_trackFile = fileName; }
259
260 //
261 // Calculated properties
262 //
263
268 [[nodiscard]] Q_INVOKABLE Units::Distance distance() const;
269
274 [[nodiscard]] Q_INVOKABLE QString flightTime() const;
282 [[nodiscard]] Q_INVOKABLE QString blockTime() const;
287 [[nodiscard]] Q_INVOKABLE qint64 flightTimeSeconds() const;
288
289 //
290 // Serialization
291 //
292
297 [[nodiscard]] auto toJSON() const -> QJsonObject;
298
304 static auto fromJSON(const QJsonObject& json) -> Flight;
305
311 Q_INVOKABLE bool operator==(const Flightlog::Flight& other) const;
312
313private:
314 QString m_departureICAO;
315 QString m_arrivalICAO;
316 QDateTime m_offBlockTime;
317 QDateTime m_startTime;
318 QDateTime m_landingTime;
319 QDateTime m_onBlockTime;
320 QString m_pilotName;
321 QString m_aircraftCallsign;
322 QString m_comments;
323 int m_landingCount {0};
324 QGeoCoordinate m_departureCoordinate;
325 QGeoCoordinate m_arrivalCoordinate;
326 QString m_trackFile;
327 QUuid m_id;
328};
329
330} // namespace Flightlog
auto pilotName() const -> QString
Getter function for property of the same name.
Definition Flight.h:134
auto arrivalCoordinate() const -> QGeoCoordinate
Coordinate of the arrival airport.
Definition Flight.h:164
void setArrivalICAO(const QString &icao)
Setter function for property of the same name.
Definition Flight.h:192
auto toJSON() const -> QJsonObject
Serialize to JSON.
void setLandingTime(const QDateTime &dt)
Setter function for property of the same name.
Definition Flight.h:210
QDateTime landingTime
Landing time in UTC.
Definition Flight.h:61
Q_INVOKABLE QString blockTime() const
Block time as a formatted string.
auto landingTime() const -> QDateTime
Getter function for property of the same name.
Definition Flight.h:122
QUuid uuid
Unique identity of this flight entry (stable across sorting and edits).
Definition Flight.h:46
void setPilotName(const QString &name)
Setter function for property of the same name.
Definition Flight.h:222
auto aircraftCallsign() const -> QString
Getter function for property of the same name.
Definition Flight.h:140
auto trackFile() const -> QString
Get the track file name.
Definition Flight.h:176
QString trackFile
Filename of the track file (relative to tracks directory).
Definition Flight.h:82
QDateTime startTime
Start (takeoff) time in UTC.
Definition Flight.h:58
auto departureCoordinate() const -> QGeoCoordinate
Coordinate of the departure airport.
Definition Flight.h:158
Flight()
Default constructor — generates a unique identity.
Definition Flight.h:86
auto onBlockTime() const -> QDateTime
Getter function for property of the same name.
Definition Flight.h:128
QString arrivalICAO
ICAO code of the arrival airport.
Definition Flight.h:52
auto arrivalICAO() const -> QString
Getter function for property of the same name.
Definition Flight.h:104
auto landingCount() const -> int
Getter function for property of the same name.
Definition Flight.h:152
auto startTime() const -> QDateTime
Getter function for property of the same name.
Definition Flight.h:116
QDateTime onBlockTime
On-block time in UTC (optional).
Definition Flight.h:64
void setAircraftCallsign(const QString &callsign)
Setter function for property of the same name.
Definition Flight.h:228
void setArrivalCoordinate(const QGeoCoordinate &coord)
Set arrival coordinate.
Definition Flight.h:252
QString aircraftCallsign
Aircraft callsign (e.g. D-KEBE, optional).
Definition Flight.h:70
Q_INVOKABLE Units::Distance distance() const
Direct distance between departure and arrival airports.
void setComments(const QString &text)
Setter function for property of the same name.
Definition Flight.h:234
QString comments
Free-text comments (optional).
Definition Flight.h:73
Q_INVOKABLE QString flightTime() const
Flight duration as a human-readable string (H:MM).
auto comments() const -> QString
Getter function for property of the same name.
Definition Flight.h:146
auto departureICAO() const -> QString
Getter function for property of the same name.
Definition Flight.h:98
int landingCount
Number of landings (touch-and-goes + final landing).
Definition Flight.h:76
QDateTime offBlockTime
Off-block time in UTC (optional).
Definition Flight.h:55
void setDepartureICAO(const QString &icao)
Setter function for property of the same name.
Definition Flight.h:186
void setOffBlockTime(const QDateTime &dt)
Setter function for property of the same name.
Definition Flight.h:198
void setDepartureCoordinate(const QGeoCoordinate &coord)
Set departure coordinate.
Definition Flight.h:246
void setStartTime(const QDateTime &dt)
Setter function for property of the same name.
Definition Flight.h:204
void setOnBlockTime(const QDateTime &dt)
Setter function for property of the same name.
Definition Flight.h:216
auto hasTrack() const -> bool
Check if this flight has a recorded GPS track.
Definition Flight.h:170
void setLandingCount(int count)
Setter function for property of the same name.
Definition Flight.h:240
static auto fromJSON(const QJsonObject &json) -> Flight
Deserialize from JSON.
QString departureICAO
ICAO code of the departure airport.
Definition Flight.h:49
QString pilotName
Pilot name (optional).
Definition Flight.h:67
bool hasTrack
Whether this flight has a recorded track.
Definition Flight.h:79
auto offBlockTime() const -> QDateTime
Getter function for property of the same name.
Definition Flight.h:110
void setTrackFile(const QString &fileName)
Set the track file name.
Definition Flight.h:258
Q_INVOKABLE qint64 flightTimeSeconds() const
Flight duration in seconds.
Convenience class for distance computations.
Definition Distance.h:35