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 <QSettings>
26
27#include "FileLibraryModel.h"
28#include "GlobalObject.h"
29#include "navigation/Aircraft.h"
30#include "navigation/FlightRoute.h"
31#include "units/ByteSize.h"
32
33
39
40class Librarian : public QObject {
41 Q_OBJECT
42 QML_ELEMENT
43 QML_SINGLETON
44
45
47 Q_PROPERTY(QString manualLocation READ manualLocation CONSTANT)
48
49
50 Q_PROPERTY(FileLibraryModel* aircraftModel READ aircraftModel CONSTANT)
51
53 Q_PROPERTY(FileLibraryModel* routesModel READ routesModel CONSTANT)
54
55public:
60 explicit Librarian(QObject *parent = nullptr);
61
62 // No default constructor, important for QML singleton
63 explicit Librarian() = delete;
64
65 // Standard destructor
66 ~Librarian() override = default;
67
68
69 // factory function for QML singleton
70 static Librarian* create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/)
71 {
73 }
74
76 enum Library : quint8 {
79
82 };
83 Q_ENUM(Library)
84
85
86
90 [[nodiscard]] FileLibraryModel* aircraftModel() const { return m_aircraftModel; }
91
96 [[nodiscard]] FileLibraryModel* routesModel() const { return m_routesModel; }
97
107 [[nodiscard]] FileLibraryModel* model(Librarian::Library library) const;
108
109
116 [[nodiscard]] Q_INVOKABLE static bool contains(const Navigation::Aircraft& acft);
117
127 [[nodiscard]] Q_INVOKABLE static bool contains(const QObject* route);
128
135 [[nodiscard]] Q_INVOKABLE static QString directory(Librarian::Library library) ;
136
145 [[nodiscard]] Q_INVOKABLE static bool exists(Librarian::Library library, const QString& baseName) ;
146
156 [[nodiscard]] Q_INVOKABLE static QString fullPath(Librarian::Library library, const QString& baseName) ;
157
177 [[nodiscard]] Q_INVOKABLE static Navigation::FlightRoute* get(Librarian::Library library, const QString& baseName);
178
184 [[nodiscard]] static QString manualLocation();
185
202 Q_INVOKABLE static QString getStringFromRessource(const QString& name);
203
214 Q_INVOKABLE static Units::ByteSize getStringHashFromRessource(const QString& name);
215
226 [[nodiscard]] Q_INVOKABLE static QString import(Librarian::Library library, const QString& fileName) ;
227
234 Q_INVOKABLE static void remove(Librarian::Library library, const QString& baseName) ;
235
246 Q_INVOKABLE static void rename(Librarian::Library library, const QString& oldName, const QString& newName);
247
267 Q_INVOKABLE bool matches(const QString& text, const QString& filter);
268
279 QString simplifySpecialChars(const QString& string);
280
292 [[nodiscard]] static QString simplify(const QString& string);
293
304 [[nodiscard]] static QStringList filterWords(const QString& filter);
305
315 [[nodiscard]] static bool matchesWords(const QString& simplifiedText, const QStringList& words);
316
317private:
318 Q_DISABLE_COPY_MOVE(Librarian)
319
320 FileLibraryModel* m_aircraftModel {nullptr};
321 FileLibraryModel* m_routesModel {nullptr};
322
323 // Cache used to speed up the method simplifySpecialChars
324 QHash<QString, QString> simplifySpecialChars_cache;
325
326};
List of the entries of a file-based library.
static Q_INVOKABLE Librarian * librarian()
Pointer to appplication-wide static librarian instance.
static QStringList filterWords(const QString &filter)
Splits a filter into simplified words.
static QString manualLocation()
Location of the user manual.
QML_SINGLETONQString manualLocation
Location of the user manual, see manualLocation().
Definition Librarian.h:47
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 QString simplify(const QString &string)
Simplifies a string without caching.
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:96
static bool matchesWords(const QString &simplifiedText, const QStringList &words)
Checks a simplified text against simplified filter words.
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:90
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:50
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:76
@ Aircraft
Aircraft library.
Definition Librarian.h:78
@ Routes
Flight route library.
Definition Librarian.h:81
FileLibraryModel * routesModel
Model listing the entries of the flight route library, see model().
Definition Librarian.h:53
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