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 <QStandardPaths>
25#include <QTimer>
26
27#include "geomaps/VAC.h"
28
29
30namespace GeoMaps
31{
32
45
46class VACLibrary : public QObject
47{
48 Q_OBJECT
49 QML_ELEMENT
50 QML_SINGLETON
51
52public:
57 VACLibrary(QObject *parent = nullptr);
58
60 ~VACLibrary() override;
61
62 //
63 // Properties
64 //
65
68
69
70 Q_PROPERTY(bool isEmpty READ isEmpty NOTIFY dataChanged)
71
77 Q_PROPERTY(QList<GeoMaps::VAC> vacs READ vacs NOTIFY dataChanged)
78
79
80 //
81 // Getter Methods
82 //
83
88 [[nodiscard]] bool hasManuallyImported() const { return !m_vacs.isEmpty(); }
89
94 [[nodiscard]] bool isEmpty() const { return m_vacs.isEmpty() && m_collectionVacs.isEmpty(); }
95
100 [[nodiscard]] QList<GeoMaps::VAC> vacs();
101
102
103 //
104 // Methods
105 //
106
111 Q_INVOKABLE void clear();
112
120 [[nodiscard]] Q_INVOKABLE GeoMaps::VAC get(const QString& name);
121
128 [[nodiscard]] Q_INVOKABLE QString importTripKit(const QString& fileName);
129
143 [[nodiscard]] Q_INVOKABLE GeoMaps::VAC materialize(const GeoMaps::VAC& vac);
144
154 [[nodiscard]] Q_INVOKABLE QString importVAC(GeoMaps::VAC vac);
155
162 Q_INVOKABLE void remove(const QString& name);
163
172 [[nodiscard]] Q_INVOKABLE QString rename(const QString& oldName, const QString& newName);
173
185 [[nodiscard]] Q_INVOKABLE QVector<GeoMaps::VAC> vacsByDistance(const QGeoCoordinate& position, const QString& filter);
186
196 [[nodiscard]] Q_INVOKABLE QVector<GeoMaps::VAC> vacs4Point(const QGeoCoordinate& position);
197
198signals:
201
209 void importTripKitStatus(double percent);
210
211private:
212 Q_DISABLE_COPY_MOVE(VACLibrary)
213
214 // This method cleans the VAC directory. It deletes all VAC from m_vacs that
215 // have no raster image files. It looks for unmanaged raster image files and
216 // either imports them or deletes them.
217 void janitor();
218
219 // This method re-reads the chart index from all VAC collection files
220 // managed by DataManagement::DataManager, rebuilds m_collectionVacs and
221 // deletes stale entries from the extraction cache.
222 void updateCollections();
223
224 // This method saves m_vacs to m_dataFile.
225 void save();
226
227 // This method returns the absolute path of a given VAC. Needed for iOS
228 // after App Update. See GeoMaps::VACLibrary::janitor
229 QString absolutePathForVac(const GeoMaps::VAC&);
230 QString absolutePathForVac(const QString& name);
231
232 QVector<GeoMaps::VAC> m_vacs;
233 QVector<GeoMaps::VAC> m_collectionVacs;
234 QString m_vacDirectory {QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u"/VAC"_s};
235 QString m_cacheDirectory {QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + u"/VAC"_s};
236 QFile m_dataFile {QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u"/VAC.data"_s};
237
238 // Compresses multiple change notifications from DataManager into a single
239 // call to updateCollections()
240 QTimer m_updateCollectionsTimer;
241
242};
243
244} // namespace GeoMaps
245
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:94
void dataChanged()
Notifier signal.
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:77
bool isEmpty
True if library is empty.
Definition VACLibrary.h:70
Q_INVOKABLE QVector< GeoMaps::VAC > vacs4Point(const QGeoCoordinate &position)
List of all VACs that contain a given point.
QList< GeoMaps::VAC > vacs()
Getter function for property of the same name.
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.
bool hasManuallyImported
True if the library contains manually imported charts.
Definition VACLibrary.h:67
Visual approach chart.
Definition VAC.h:45