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 "GlobalObject.h"
29#include "navigation/Aircraft.h"
30#include "units/ByteSize.h"
31
32
38
39class Librarian : public QObject {
40 Q_OBJECT
41 QML_ELEMENT
42 QML_SINGLETON
43
44public:
49 explicit Librarian(QObject *parent = nullptr);
50
51 // No default constructor, important for QML singleton
52 explicit Librarian() = delete;
53
54 // Standard destructor
55 ~Librarian() override = default;
56
57
58 // factory function for QML singleton
59 static Librarian* create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/)
60 {
62 }
63
65 enum Library : quint8 {
68
71 };
72 Q_ENUM(Library)
73
74
75
81 [[nodiscard]] Q_INVOKABLE static bool contains(const Navigation::Aircraft& acft);
82
92 [[nodiscard]] Q_INVOKABLE static bool contains(const QObject* route);
93
100 [[nodiscard]] Q_INVOKABLE static QString directory(Librarian::Library library) ;
101
114 Q_INVOKABLE QStringList entries(Librarian::Library library, const QString& filter=QString());
115
124 [[nodiscard]] Q_INVOKABLE static bool exists(Librarian::Library library, const QString& baseName) ;
125
135 [[nodiscard]] Q_INVOKABLE static QString fullPath(Librarian::Library library, const QString& baseName) ;
136
156 [[nodiscard]] Q_INVOKABLE static QObject* get(Librarian::Library library, const QString& baseName) ;
157
174 Q_INVOKABLE static QString getStringFromRessource(const QString& name);
175
186 Q_INVOKABLE static Units::ByteSize getStringHashFromRessource(const QString& name);
187
198 [[nodiscard]] Q_INVOKABLE static QString import(Librarian::Library library, const QString& fileName) ;
199
206 Q_INVOKABLE static void remove(Librarian::Library library, const QString& baseName) ;
207
218 Q_INVOKABLE static void rename(Librarian::Library library, const QString& oldName, const QString& newName);
219
232 QStringList permissiveFilter(const QStringList &input, const QString &filter);
233
244 QString simplifySpecialChars(const QString& string);
245
246private:
247 Q_DISABLE_COPY_MOVE(Librarian)
248
249 // Caches used to speed up the method simplifySpecialChars
250 QRegularExpression specialChars {QStringLiteral("[^a-zA-Z0-9]")};
251 QHash<QString, QString> simplifySpecialChars_cache;
252
253};
static Q_INVOKABLE Librarian * librarian()
Pointer to appplication-wide static librarian instance.
QString simplifySpecialChars(const QString &string)
Simplifies string by transforming and removing special characters.
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.
static Q_INVOKABLE QString fullPath(Librarian::Library library, const QString &baseName)
Full path of a library entry.
QStringList permissiveFilter(const QStringList &input, const QString &filter)
Filters a QStringList in a fuzzy way.
static Q_INVOKABLE void rename(Librarian::Library library, const QString &oldName, const QString &newName)
Renames an entry in a library.
static Q_INVOKABLE QObject * get(Librarian::Library library, const QString &baseName)
Constructs an object from library entry.
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.
Q_INVOKABLE QStringList entries(Librarian::Library library, const QString &filter=QString())
Lists all entries in the library whose name contains the string 'filter'.
Library
Type of library.
Definition Librarian.h:65
@ Aircraft
Aircraft library.
Definition Librarian.h:67
@ Routes
Flight route library.
Definition Librarian.h:70
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.
This extremely simple class holds a few numbers that describe an aircraft.
Definition Aircraft.h:35
Convenience class for size_t.
Definition ByteSize.h:37