Enroute Flight Navigation
A navigation app for VFR pilots
Librarian.h
1/***************************************************************************
2 * Copyright (C) 2020-2023 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 <QDir>
24#include <QQmlEngine>
25#include <QRegularExpression>
26#include <QSettings>
27
28#include "FileLibraryModel.h"
29#include "GlobalObject.h"
30#include "navigation/Aircraft.h"
31#include "navigation/FlightRoute.h"
32#include "units/ByteSize.h"
33
34
40
41class Librarian : public QObject {
42 Q_OBJECT
43 QML_ELEMENT
44 QML_SINGLETON
45
46
48 Q_PROPERTY(QString manualLocation READ manualLocation CONSTANT)
49
50
51 Q_PROPERTY(FileLibraryModel* aircraftModel READ aircraftModel CONSTANT)
52
54 Q_PROPERTY(FileLibraryModel* routesModel READ routesModel CONSTANT)
55
56public:
61 explicit Librarian(QObject *parent = nullptr);
62
63 // No default constructor, important for QML singleton
64 explicit Librarian() = delete;
65
66 // Standard destructor
67 ~Librarian() override = default;
68
69
70 // factory function for QML singleton
71 static Librarian* create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/)
72 {
74 }
75
77 enum Library : quint8 {
80
83 };
84 Q_ENUM(Library)
85
86
87
91 [[nodiscard]] FileLibraryModel* aircraftModel() const { return m_aircraftModel; }
92
97 [[nodiscard]] FileLibraryModel* routesModel() const { return m_routesModel; }
98
108 [[nodiscard]] FileLibraryModel* model(Librarian::Library library) const;
109
110
117 [[nodiscard]] Q_INVOKABLE static bool contains(const Navigation::Aircraft& acft);
118
128 [[nodiscard]] Q_INVOKABLE static bool contains(const QObject* route);
129
136 [[nodiscard]] Q_INVOKABLE static QString directory(Librarian::Library library) ;
137
146 [[nodiscard]] Q_INVOKABLE static bool exists(Librarian::Library library, const QString& baseName) ;
147
157 [[nodiscard]] Q_INVOKABLE static QString fullPath(Librarian::Library library, const QString& baseName) ;
158
178 [[nodiscard]] Q_INVOKABLE static Navigation::FlightRoute* get(Librarian::Library library, const QString& baseName);
179
185 [[nodiscard]] static QString manualLocation();
186
203 Q_INVOKABLE static QString getStringFromRessource(const QString& name);
204
215 Q_INVOKABLE static Units::ByteSize getStringHashFromRessource(const QString& name);
216
227 [[nodiscard]] Q_INVOKABLE static QString import(Librarian::Library library, const QString& fileName) ;
228
235 Q_INVOKABLE static void remove(Librarian::Library library, const QString& baseName) ;
236
247 Q_INVOKABLE static void rename(Librarian::Library library, const QString& oldName, const QString& newName);
248
268 Q_INVOKABLE bool matches(const QString& text, const QString& filter);
269
280 QString simplifySpecialChars(const QString& string);
281
282private:
283 Q_DISABLE_COPY_MOVE(Librarian)
284
285 FileLibraryModel* m_aircraftModel {nullptr};
286 FileLibraryModel* m_routesModel {nullptr};
287
288 // Caches used to speed up the method simplifySpecialChars
289 QRegularExpression specialChars {QStringLiteral("[^a-zA-Z0-9]")};
290 QHash<QString, QString> simplifySpecialChars_cache;
291
292};
List of the entries of a file-based library.
static Q_INVOKABLE Librarian * librarian()
Pointer to appplication-wide static librarian instance.
static QString manualLocation()
Location of the user manual.
QML_SINGLETONQString manualLocation
Location of the user manual, see manualLocation().
Definition Librarian.h:48
QString simplifySpecialChars(const QString &string)
Simplifies string by transforming and removing special characters.
Q_INVOKABLE bool matches(const QString &text, const QString &filter)
Checks if a text matches a filter string, in a fuzzy way.
static Q_INVOKABLE QString directory(Librarian::Library library)
Name of the directory containing the given.
static Q_INVOKABLE bool contains(const QObject *route)
Check if a flight route exists in the library.
static Q_INVOKABLE QString getStringFromRessource(const QString &name)
Exposes string stored in QRessource to QML.
FileLibraryModel * routesModel() const
Getter function for the property with the same name.
Definition Librarian.h:97
static Q_INVOKABLE QString fullPath(Librarian::Library library, const QString &baseName)
Full path of a library entry.
FileLibraryModel * aircraftModel() const
Getter function for the property with the same name.
Definition Librarian.h:91
static Q_INVOKABLE void rename(Librarian::Library library, const QString &oldName, const QString &newName)
Renames an entry in a library.
Librarian(QObject *parent=nullptr)
Default constructor.
static Q_INVOKABLE bool contains(const Navigation::Aircraft &acft)
Check if an object exists in the library.
static Q_INVOKABLE void remove(Librarian::Library library, const QString &baseName)
Removes an entry from a library.
FileLibraryModel * aircraftModel
Model listing the entries of the aircraft library, see model().
Definition Librarian.h:51
static Q_INVOKABLE Navigation::FlightRoute * get(Librarian::Library library, const QString &baseName)
Constructs an object from library entry.
Library
Type of library.
Definition Librarian.h:77
@ Aircraft
Aircraft library.
Definition Librarian.h:79
@ Routes
Flight route library.
Definition Librarian.h:82
FileLibraryModel * routesModel
Model listing the entries of the flight route library, see model().
Definition Librarian.h:54
static Q_INVOKABLE Units::ByteSize getStringHashFromRessource(const QString &name)
Exposes the hash of string stored in QRessource to QML.
static Q_INVOKABLE bool exists(Librarian::Library library, const QString &baseName)
Check if an entry with the given name exists in the library.
FileLibraryModel * model(Librarian::Library library) const
Model listing the entries of a library.
This extremely simple class holds a few numbers that describe an aircraft.
Definition Aircraft.h:35
Intended flight route.
Definition FlightRoute.h:60
Convenience class for size_t.
Definition ByteSize.h:37