Enroute Flight Navigation
A navigation app for VFR pilots
VACLibrary.h
1/***************************************************************************
2 * Copyright (C) 2024-2025 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 <QFile>
24#include <QProperty>
25#include <QStandardPaths>
26#include <QTimer>
27
28#include "geomaps/VAC.h"
29
30
31namespace GeoMaps
32{
33
46
47class VACLibrary : public QObject
48{
49 Q_OBJECT
50 QML_ELEMENT
51 QML_SINGLETON
52
53public:
58 VACLibrary(QObject *parent = nullptr);
59
61 ~VACLibrary() override;
62
63 //
64 // Properties
65 //
66
69
70
71 Q_PROPERTY(bool isEmpty READ isEmpty BINDABLE bindableIsEmpty NOTIFY isEmptyChanged)
72
78 Q_PROPERTY(QList<GeoMaps::VAC> vacs READ vacs BINDABLE bindableVacs NOTIFY vacsChanged)
79
80
81 //
82 // Getter Methods
83 //
84
89 [[nodiscard]] bool hasManuallyImported() const { return m_hasManuallyImported.value(); }
90
95 [[nodiscard]] QBindable<bool> bindableHasManuallyImported() const { return &m_hasManuallyImported; }
96
101 [[nodiscard]] bool isEmpty() const { return m_isEmpty.value(); }
102
107 [[nodiscard]] QBindable<bool> bindableIsEmpty() const { return &m_isEmpty; }
108
113 [[nodiscard]] QList<GeoMaps::VAC> vacs() const { return m_sortedVacs.value(); }
114
119 [[nodiscard]] QBindable<QList<GeoMaps::VAC>> bindableVacs() const { return &m_sortedVacs; }
120
121
122 //
123 // Methods
124 //
125
130 Q_INVOKABLE void clear();
131
139 [[nodiscard]] Q_INVOKABLE GeoMaps::VAC get(const QString& name);
140
147 [[nodiscard]] Q_INVOKABLE QString importTripKit(const QString& fileName);
148
162 [[nodiscard]] Q_INVOKABLE GeoMaps::VAC materialize(const GeoMaps::VAC& vac);
163
173 [[nodiscard]] Q_INVOKABLE QString importVAC(GeoMaps::VAC vac);
174
181 Q_INVOKABLE void remove(const QString& name);
182
191 [[nodiscard]] Q_INVOKABLE QString rename(const QString& oldName, const QString& newName);
192
204 [[nodiscard]] Q_INVOKABLE QVector<GeoMaps::VAC> vacsByDistance(const QGeoCoordinate& position, const QString& filter);
205
215 [[nodiscard]] Q_INVOKABLE QVector<GeoMaps::VAC> vacs4Point(const QGeoCoordinate& position);
216
217signals:
220
223
226
234 void importTripKitStatus(double percent);
235
236private:
237 Q_DISABLE_COPY_MOVE(VACLibrary)
238
239 // This method cleans the VAC directory. It deletes all VAC from m_vacs that
240 // have no raster image files. It looks for unmanaged raster image files and
241 // either imports them or deletes them.
242 void janitor();
243
244 // This method re-reads the chart index from all VAC collection files
245 // managed by DataManagement::DataManager, rebuilds m_collectionVacs and
246 // deletes stale entries from the extraction cache.
247 void updateCollections();
248
249 // This method saves m_vacs to m_dataFile.
250 void save();
251
252 // This method returns the absolute path of a given VAC. Needed for iOS
253 // after App Update. See GeoMaps::VACLibrary::janitor
254 QString absolutePathForVac(const GeoMaps::VAC&);
255 QString absolutePathForVac(const QString& name);
256
257 // Source data: manually imported charts and charts from VAC collections.
258 // These are bindable so that the derived properties below update through
259 // automatic dependency tracking. Mutations must follow the rules for
260 // bindable properties: modify a local copy, then assign it back in a
261 // single write (see "Qt Bindable Properties" in the Qt documentation).
262 QProperty<QVector<GeoMaps::VAC>> m_vacs;
263 QProperty<QVector<GeoMaps::VAC>> m_collectionVacs;
264
265 // Derived properties, computed through bindings set up in the constructor
266 Q_OBJECT_BINDABLE_PROPERTY(GeoMaps::VACLibrary, QVector<GeoMaps::VAC>, m_sortedVacs, &GeoMaps::VACLibrary::vacsChanged)
267 Q_OBJECT_BINDABLE_PROPERTY(GeoMaps::VACLibrary, bool, m_isEmpty, &GeoMaps::VACLibrary::isEmptyChanged)
268 Q_OBJECT_BINDABLE_PROPERTY(GeoMaps::VACLibrary, bool, m_hasManuallyImported, &GeoMaps::VACLibrary::hasManuallyImportedChanged)
269
270 QString m_vacDirectory {QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u"/VAC"_s};
271 QString m_cacheDirectory {QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u"/VAC"_s};
272 QFile m_dataFile {QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u"/VAC.data"_s};
273
274 // Compresses multiple change notifications from DataManager into a single
275 // call to updateCollections()
276 QTimer m_updateCollectionsTimer;
277
278};
279
280} // namespace GeoMaps
281
Library of visual approach charts.
Definition VACLibrary.h:48
QBindable< bool > bindableIsEmpty() const
Getter function for property of the same name.
Definition VACLibrary.h:107
Q_INVOKABLE QVector< GeoMaps::VAC > vacsByDistance(const QGeoCoordinate &position, const QString &filter)
List of all VACs installed.
Q_INVOKABLE void clear()
Removes all VACs.
Q_INVOKABLE GeoMaps::VAC get(const QString &name)
Obtain VACs from the library.
Q_INVOKABLE void remove(const QString &name)
Remove one VACs.
bool isEmpty() const
Getter function for property of the same name.
Definition VACLibrary.h:101
Q_INVOKABLE QString importVAC(GeoMaps::VAC vac)
Import VAC.
~VACLibrary() override
Destructor.
VACLibrary(QObject *parent=nullptr)
Constructor.
QList< GeoMaps::VAC > vacs
List of all VACs installed.
Definition VACLibrary.h:78
QBindable< bool > bindableHasManuallyImported() const
Getter function for property of the same name.
Definition VACLibrary.h:95
void hasManuallyImportedChanged()
Notifier signal.
bool isEmpty
True if library is empty.
Definition VACLibrary.h:71
QList< GeoMaps::VAC > vacs() const
Getter function for property of the same name.
Definition VACLibrary.h:113
QBindable< QList< GeoMaps::VAC > > bindableVacs() const
Getter function for property of the same name.
Definition VACLibrary.h:119
void isEmptyChanged()
Notifier signal.
Q_INVOKABLE QVector< GeoMaps::VAC > vacs4Point(const QGeoCoordinate &position)
List of all VACs that contain a given point.
Q_INVOKABLE GeoMaps::VAC materialize(const GeoMaps::VAC &vac)
Obtain a VAC whose fileName points to a raster image file.
Q_INVOKABLE QString rename(const QString &oldName, const QString &newName)
Rename a VACs.
Q_INVOKABLE QString importTripKit(const QString &fileName)
Import trip kit.
void importTripKitStatus(double percent)
Progress report when importing a trip kit.
void vacsChanged()
Notifier signal.
bool hasManuallyImported
True if the library contains manually imported charts.
Definition VACLibrary.h:68
Visual approach chart.
Definition VAC.h:45