Enroute Flight Navigation
A navigation app for VFR pilots
FlightRecorder.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 <QGeoPath>
24#include <QStandardPaths>
25
26#include "flightlog/Flight.h"
27#include "flightlog/FlightDetector.h"
28#include "flightlog/TrackPoint.h"
29#include "positioning/PositionInfo.h"
30#include "units/Distance.h"
31
32using namespace Qt::Literals::StringLiterals;
33
34namespace Flightlog {
35
55class FlightRecorder : public QObject
56{
57 Q_OBJECT
58
59public:
64 explicit FlightRecorder(QObject* parent = nullptr);
65
67 ~FlightRecorder() override = default;
68
80 const Positioning::PositionInfo& info,
81 Units::Distance pressureAltitude = {});
82
93 bool saveTrack(Flight& flight);
94
101
110 [[nodiscard]] auto loadTrackPath(const Flight& flight) const -> QList<QGeoCoordinate>;
111
119 [[nodiscard]] QByteArray exportToIGC(const Flight& flight) const;
120
129 void removeTrack(Flight& flight);
130
138 [[nodiscard]] auto trackGeoPath() const -> QGeoPath;
139
150 static auto toIGC(const Flight& flight, const QList<TrackPoint>& track) -> QByteArray;
151
161 static auto trackFromIGC(const QByteArray& igcData, const QDate& date = {}) -> QList<TrackPoint>;
162
163signals:
169
170private:
171 Q_DISABLE_COPY_MOVE(FlightRecorder)
172
173 // Build a TrackPoint from position info and optional pressure altitude
174 static auto makeTrackPoint(const Positioning::PositionInfo& info, Units::Distance pressureAltitude) -> TrackPoint;
175
176 // Check if a point should be recorded based on distance/time thresholds
177 [[nodiscard]] auto shouldRecord(const Positioning::PositionInfo& info) const -> bool;
178
179 // Record a point if thresholds are met
180 void recordFiltered(const Positioning::PositionInfo& info, Units::Distance pressureAltitude);
181
182 // Last recorded point for distance/time filtering
183 QGeoCoordinate m_lastCoordinate;
184 QDateTime m_lastTimestamp;
185
186 // Previous detection state for transition detection
188
189 // Accumulated track points
190 QList<TrackPoint> m_track;
191
192 // Cached geo path kept in sync with m_track for O(1) reads
193 QGeoPath m_geoPath;
194
195 // Recording thresholds
196 static constexpr auto minDistance = Units::Distance::fromM(300.0);
197 static constexpr auto minTimeInterval = Units::Timespan::fromS(10);
198 static constexpr int maxTrackPoints = 100'000;
199
200 // Tracks directory
201 const QString m_trackDir {QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u"/tracks"_s};
202};
203
204} // namespace Flightlog
DetectionState
Detection state for automatic takeoff/landing detection.
void processPositionUpdate(FlightDetector::DetectionState state, const Positioning::PositionInfo &info, Units::Distance pressureAltitude={})
Process a position update with the current detection state.
auto trackGeoPath() const -> QGeoPath
Get the current track as a list of coordinates.
auto loadTrackPath(const Flight &flight) const -> QList< QGeoCoordinate >
Load a track's coordinates from an IGC file.
QByteArray exportToIGC(const Flight &flight) const
Export a flight's track via the platform share dialog.
FlightRecorder(QObject *parent=nullptr)
Standard constructor.
static auto trackFromIGC(const QByteArray &igcData, const QDate &date={}) -> QList< TrackPoint >
Parse track points from IGC file content.
static auto toIGC(const Flight &flight, const QList< TrackPoint > &track) -> QByteArray
Generate IGC file content from flight metadata and track points.
bool saveTrack(Flight &flight)
Save the recorded track to an IGC file.
~FlightRecorder() override=default
Standard destructor.
void clearTrack()
Clear the in-memory track data.
void removeTrack(Flight &flight)
Delete the track file from disk.
void trackGeoPathChanged()
Emitted when a new track point has been recorded.
A single flight log entry.
Definition Flight.h:41
Geographic position.
Convenience class for distance computations.
Definition Distance.h:35
static Q_INVOKABLE constexpr Units::Distance fromM(double distanceInM)
Constructs a distance.
Definition Distance.h:56
static constexpr auto fromS(double timeInS)
Constructs a time.
Definition Timespan.h:71
A single point along a recorded flight track.
Definition TrackPoint.h:35