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 <QQmlEngine>
26#include <QUuid>
27
28#include "units/Distance.h"
29
30namespace Flightlog {
31
38
39class Flight
40{
41 Q_GADGET
42 QML_VALUE_TYPE(flight)
43
44
45 Q_PROPERTY(QUuid uuid READ uuid)
46
48 Q_PROPERTY(QString departureICAO READ departureICAO WRITE setDepartureICAO)
49
51 Q_PROPERTY(QString arrivalICAO READ arrivalICAO WRITE setArrivalICAO)
52
54 Q_PROPERTY(QDateTime offBlockTime READ offBlockTime WRITE setOffBlockTime)
55
57 Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime)
58
60 Q_PROPERTY(QDateTime landingTime READ landingTime WRITE setLandingTime)
61
63 Q_PROPERTY(QDateTime onBlockTime READ onBlockTime WRITE setOnBlockTime)
64
66 Q_PROPERTY(QString pilotName READ pilotName WRITE setPilotName)
67
70
72 Q_PROPERTY(QString comments READ comments WRITE setComments)
73
75 Q_PROPERTY(int landingCount READ landingCount WRITE setLandingCount)
76
78 Q_PROPERTY(bool hasTrack READ hasTrack)
79
81 Q_PROPERTY(QString trackFile READ trackFile)
82
83public:
85 Flight() : m_id(QUuid::createUuid()) {}
86
96 explicit Flight(const QUuid& uuid) : m_id(uuid.isNull() ? QUuid::createUuid() : uuid) {}
97
98 //
99 // Getters
100 //
101
102 [[nodiscard]] auto uuid() const -> QUuid { return m_id; }
103
108 [[nodiscard]] auto departureICAO() const -> QString { return m_departureICAO; }
109
114 [[nodiscard]] auto arrivalICAO() const -> QString { return m_arrivalICAO; }
115
120 [[nodiscard]] auto offBlockTime() const -> QDateTime { return m_offBlockTime; }
121
126 [[nodiscard]] auto startTime() const -> QDateTime { return m_startTime; }
127
132 [[nodiscard]] auto landingTime() const -> QDateTime { return m_landingTime; }
133
138 [[nodiscard]] auto onBlockTime() const -> QDateTime { return m_onBlockTime; }
139
144 [[nodiscard]] auto pilotName() const -> QString { return m_pilotName; }
145
150 [[nodiscard]] auto aircraftCallsign() const -> QString { return m_aircraftCallsign; }
151
156 [[nodiscard]] auto comments() const -> QString { return m_comments; }
157
162 [[nodiscard]] auto landingCount() const -> int { return m_landingCount; }
163
168 [[nodiscard]] auto departureCoordinate() const -> QGeoCoordinate { return m_departureCoordinate; }
169
174 [[nodiscard]] auto arrivalCoordinate() const -> QGeoCoordinate { return m_arrivalCoordinate; }
175
180 [[nodiscard]] auto hasTrack() const -> bool { return !m_trackFile.isEmpty(); }
181
186 [[nodiscard]] auto trackFile() const -> QString { return m_trackFile; }
187
188 //
189 // Setters
190 //
191
196 void setDepartureICAO(const QString& icao) { m_departureICAO = icao; }
197
202 void setArrivalICAO(const QString& icao) { m_arrivalICAO = icao; }
203
208 void setOffBlockTime(const QDateTime& dt) { m_offBlockTime = dt; }
209
214 void setStartTime(const QDateTime& dt) { m_startTime = dt; }
215
220 void setLandingTime(const QDateTime& dt) { m_landingTime = dt; }
221
226 void setOnBlockTime(const QDateTime& dt) { m_onBlockTime = dt; }
227
232 void setPilotName(const QString& name) { m_pilotName = name; }
233
238 void setAircraftCallsign(const QString& callsign) { m_aircraftCallsign = callsign; }
239
244 void setComments(const QString& text) { m_comments = text; }
245
250 void setLandingCount(int count) { m_landingCount = count; }
251
256 void setDepartureCoordinate(const QGeoCoordinate& coord) { m_departureCoordinate = coord; }
257
262 void setArrivalCoordinate(const QGeoCoordinate& coord) { m_arrivalCoordinate = coord; }
263
276 void setTrackFile(const QString& fileName)
277 {
278 if (!fileName.isEmpty() && (fileName.contains(u'/') || fileName.contains(u'\\'))) {
279 return;
280 }
281 m_trackFile = fileName;
282 }
283
284 //
285 // Calculated properties
286 //
287
292 [[nodiscard]] Q_INVOKABLE Units::Distance distance() const;
293
298 [[nodiscard]] Q_INVOKABLE QString flightTime() const;
306 [[nodiscard]] Q_INVOKABLE QString blockTime() const;
311 [[nodiscard]] Q_INVOKABLE qint64 flightTimeSeconds() const;
312
318 Q_INVOKABLE bool operator==(const Flightlog::Flight& other) const;
319
320private:
321 QString m_departureICAO;
322 QString m_arrivalICAO;
323 QDateTime m_offBlockTime;
324 QDateTime m_startTime;
325 QDateTime m_landingTime;
326 QDateTime m_onBlockTime;
327 QString m_pilotName;
328 QString m_aircraftCallsign;
329 QString m_comments;
330 int m_landingCount {0};
331 QGeoCoordinate m_departureCoordinate;
332 QGeoCoordinate m_arrivalCoordinate;
333 QString m_trackFile;
334 QUuid m_id;
335};
336
337} // namespace Flightlog
A single flight log entry.
Definition Flight.h:40
auto pilotName() const -> QString
Getter function for property of the same name.
Definition Flight.h:144
auto arrivalCoordinate() const -> QGeoCoordinate
Coordinate of the arrival airport.
Definition Flight.h:174
void setArrivalICAO(const QString &icao)
Setter function for property of the same name.
Definition Flight.h:202
void setLandingTime(const QDateTime &dt)
Setter function for property of the same name.
Definition Flight.h:220
QDateTime landingTime
Landing time in UTC.
Definition Flight.h:60
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:132
QUuid uuid
Unique identity of this flight entry (stable across sorting and edits).
Definition Flight.h:45
void setPilotName(const QString &name)
Setter function for property of the same name.
Definition Flight.h:232
auto aircraftCallsign() const -> QString
Getter function for property of the same name.
Definition Flight.h:150
auto trackFile() const -> QString
Get the track file name.
Definition Flight.h:186
QString trackFile
Filename of the track file (relative to tracks directory).
Definition Flight.h:81
QDateTime startTime
Start (takeoff) time in UTC.
Definition Flight.h:57
auto departureCoordinate() const -> QGeoCoordinate
Coordinate of the departure airport.
Definition Flight.h:168
Flight()
Default constructor — generates a unique identity.
Definition Flight.h:85
auto onBlockTime() const -> QDateTime
Getter function for property of the same name.
Definition Flight.h:138
QString arrivalICAO
ICAO code of the arrival airport.
Definition Flight.h:51
auto arrivalICAO() const -> QString
Getter function for property of the same name.
Definition Flight.h:114
auto landingCount() const -> int
Getter function for property of the same name.
Definition Flight.h:162
auto startTime() const -> QDateTime
Getter function for property of the same name.
Definition Flight.h:126
QDateTime onBlockTime
On-block time in UTC (optional).
Definition Flight.h:63
void setAircraftCallsign(const QString &callsign)
Setter function for property of the same name.
Definition Flight.h:238
void setArrivalCoordinate(const QGeoCoordinate &coord)
Set arrival coordinate.
Definition Flight.h:262
QString aircraftCallsign
Aircraft callsign (e.g. D-KEBE, optional).
Definition Flight.h:69
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:244
QString comments
Free-text comments (optional).
Definition Flight.h:72
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:156
Flight(const QUuid &uuid)
Construct with a specific identity.
Definition Flight.h:96
Q_INVOKABLE bool operator==(const Flightlog::Flight &other) const
Comparison operator.
auto departureICAO() const -> QString
Getter function for property of the same name.
Definition Flight.h:108
int landingCount
Number of landings (touch-and-goes + final landing).
Definition Flight.h:75
QDateTime offBlockTime
Off-block time in UTC (optional).
Definition Flight.h:54
void setDepartureICAO(const QString &icao)
Setter function for property of the same name.
Definition Flight.h:196
void setOffBlockTime(const QDateTime &dt)
Setter function for property of the same name.
Definition Flight.h:208
void setDepartureCoordinate(const QGeoCoordinate &coord)
Set departure coordinate.
Definition Flight.h:256
void setStartTime(const QDateTime &dt)
Setter function for property of the same name.
Definition Flight.h:214
void setOnBlockTime(const QDateTime &dt)
Setter function for property of the same name.
Definition Flight.h:226
auto hasTrack() const -> bool
Check if this flight has a recorded GPS track.
Definition Flight.h:180
void setLandingCount(int count)
Setter function for property of the same name.
Definition Flight.h:250
QString departureICAO
ICAO code of the departure airport.
Definition Flight.h:48
QString pilotName
Pilot name (optional).
Definition Flight.h:66
bool hasTrack
Whether this flight has a recorded track.
Definition Flight.h:78
auto offBlockTime() const -> QDateTime
Getter function for property of the same name.
Definition Flight.h:120
void setTrackFile(const QString &fileName)
Set the track file name.
Definition Flight.h:276
Q_INVOKABLE qint64 flightTimeSeconds() const
Flight duration in seconds.
Convenience class for distance computations.
Definition Distance.h:35