Enroute Flight Navigation
A navigation app for VFR pilots
FlightLogStorage.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 <QObject>
24#include <QSqlQuery>
25#include <QStandardPaths>
26
27#include "flightlog/Flight.h"
28
29using namespace Qt::Literals::StringLiterals;
30
31namespace Flightlog {
32
47class FlightLogStorage : public QObject
48{
49 Q_OBJECT
50
51public:
59 explicit FlightLogStorage(QObject* parent);
60
63
68 [[nodiscard]] auto loadAll() -> QList<Flight>;
69
75 bool upsert(const Flight& flight);
76
82 bool upsertMany(const QList<Flight>& flights);
83
91 bool remove(const QUuid& uuid);
92
98 bool removeMany(const QList<QUuid>& uuids);
99
104 bool removeAll();
105
106signals:
114 void saveError(const QString& message);
115
116private:
117 Q_DISABLE_COPY_MOVE(FlightLogStorage)
118
119 // Open the database connection and ensure the schema exists
120 void openDatabase();
121
122 // Rename a corrupt file aside with a timestamp suffix and report the error
123 void quarantineFile(const QString& fileName, const QString& reason);
124
125 // Emit saveError() via a queued connection, safe to call from the constructor.
126 // Const so it can also be called from loadAll(); emitting a signal doesn't
127 // change any observable state of this object.
128 void reportError(const QString& message);
129
130 // Bind all fields of a flight to a prepared INSERT query, in column order
131 static void bindFlight(QSqlQuery& query, const Flight& flight);
132
133 QString m_databaseConnectionName;
134
135 const QString m_dbFileName {QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u"/userdata.db"_s};
136};
137
138} // namespace Flightlog
void saveError(const QString &message)
Emitted when a database operation fails.
bool upsertMany(const QList< Flight > &flights)
Insert or update multiple flights, in one transaction.
auto loadAll() -> QList< Flight >
Load all flights from the database.
bool upsert(const Flight &flight)
Insert a flight, or update it if its uuid already exists.
bool removeMany(const QList< QUuid > &uuids)
Delete multiple flights by uuid, in one transaction.
bool removeAll()
Delete every flight.
FlightLogStorage(QObject *parent)
Standard constructor.
bool remove(const QUuid &uuid)
Delete a flight by uuid.
~FlightLogStorage() override
Standard destructor.
A single flight log entry.
Definition Flight.h:40