Enroute Flight Navigation
A navigation app for VFR pilots
Librarian Class Reference

Manage libraries and text assets. More...

#include <Librarian.h>

Public Types

enum  Library : quint8 { Aircraft , Routes }
 Type of library. More...

Public Member Functions

 Librarian (QObject *parent=nullptr)
 Default constructor.
FileLibraryModel * aircraftModel () const
 Getter function for the property with the same name.
FileLibraryModel * routesModel () const
 Getter function for the property with the same name.
FileLibraryModel * model (Librarian::Library library) const
 Model listing the entries of a library.
Q_INVOKABLE bool matches (const QString &text, const QString &filter)
 Checks if a text matches a filter string, in a fuzzy way.
QString simplifySpecialChars (const QString &string)
 Simplifies string by transforming and removing special characters.

Static Public Member Functions

static Q_INVOKABLE bool contains (const Navigation::Aircraft &acft)
 Check if an object exists in the library.
static Q_INVOKABLE bool contains (const QObject *route)
 Check if a flight route exists in the library.
static Q_INVOKABLE QString directory (Librarian::Library library)
 Name of the directory containing the given.
static Q_INVOKABLE bool exists (Librarian::Library library, const QString &baseName)
 Check if an entry with the given name exists in the library.
static Q_INVOKABLE QString fullPath (Librarian::Library library, const QString &baseName)
 Full path of a library entry.
static Q_INVOKABLE Navigation::FlightRoute * get (Librarian::Library library, const QString &baseName)
 Constructs an object from library entry.
static QString manualLocation ()
 Location of the user manual.
static Q_INVOKABLE QString getStringFromRessource (const QString &name)
 Exposes string stored in QRessource to QML.
static Q_INVOKABLE Units::ByteSize getStringHashFromRessource (const QString &name)
 Exposes the hash of string stored in QRessource to QML.
static Q_INVOKABLE QString import (Librarian::Library library, const QString &fileName)
 Import a file into a library.
static Q_INVOKABLE void remove (Librarian::Library library, const QString &baseName)
 Removes an entry from a library.
static Q_INVOKABLE void rename (Librarian::Library library, const QString &oldName, const QString &newName)
 Renames an entry in a library.
static QString simplify (const QString &string)
 Simplifies a string without caching.
static QStringList filterWords (const QString &filter)
 Splits a filter into simplified words.
static bool matchesWords (const QString &simplifiedText, const QStringList &words)
 Checks a simplified text against simplified filter words.

Properties

QML_SINGLETONQString manualLocation
 Location of the user manual, see manualLocation().
FileLibraryModel * aircraftModel
 Model listing the entries of the aircraft library, see model().
FileLibraryModel * routesModel
 Model listing the entries of the flight route library, see model().

Detailed Description

Manage libraries and text assets.

This class manages libraries of aircrafts and routes, as well as text assets, and exposes these objects to QML.

Definition at line 40 of file Librarian.h.

Member Enumeration Documentation

◆ Library

enum Librarian::Library : quint8

Type of library.

Enumerator
Aircraft 

Aircraft library.

Routes 

Flight route library.

Definition at line 76 of file Librarian.h.

Constructor & Destructor Documentation

◆ Librarian()

Librarian::Librarian ( QObject * parent = nullptr)
explicit

Default constructor.

Parameters
parentThe standard QObject parent pointer

Member Function Documentation

◆ aircraftModel()

FileLibraryModel * Librarian::aircraftModel ( ) const
inlinenodiscard

Getter function for the property with the same name.

Returns
Property aircraftModel

Definition at line 90 of file Librarian.h.

◆ contains() [1/2]

Q_INVOKABLE bool Librarian::contains ( const Navigation::Aircraft & acft)
staticnodiscard

Check if an object exists in the library.

Parameters
acftAircraft object
Returns
True if the aircraft exists in the library.

◆ contains() [2/2]

Q_INVOKABLE bool Librarian::contains ( const QObject * route)
staticnodiscard

Check if a flight route exists in the library.

At the moment, only flight routes are supported.

Parameters
routePointer to the route
Returns
True if the object is of type Navigation::FlightRoute and exists in the library.

◆ directory()

Q_INVOKABLE QString Librarian::directory ( Librarian::Library library)
staticnodiscard

Name of the directory containing the given.

Parameters
libraryThe library that is accessed
Returns
Name of the directory, without trailing slash

◆ exists()

Q_INVOKABLE bool Librarian::exists ( Librarian::Library library,
const QString & baseName )
staticnodiscard

Check if an entry with the given name exists in the library.

Parameters
libraryThe library that is accessed
baseNameFile name, without path and without extension
Returns
True if the file exists

◆ filterWords()

QStringList Librarian::filterWords ( const QString & filter)
staticnodiscard

Splits a filter into simplified words.

Splits the filter at whitespace and simplifies every word with simplify(). Words that are empty after simplification are dropped.

Parameters
filterFilter text as typed by the user
Returns
Simplified, non-empty words. Empty if the filter contains no searchable characters.

◆ fullPath()

Q_INVOKABLE QString Librarian::fullPath ( Librarian::Library library,
const QString & baseName )
staticnodiscard

Full path of a library entry.

Parameters
libraryThe library that is accessed
baseNameName of the entry, without path and without extension
Returns
Full path of the entry, with extension

◆ get()

Q_INVOKABLE Navigation::FlightRoute * Librarian::get ( Librarian::Library library,
const QString & baseName )
staticnodiscard

Constructs an object from library entry.

This method constructs an object from a library entry.

If the entry is a route, the route is construted with aircraft and wind set to nullptr, so that no wind computations are possible. It is, however, possible to export the flight route (for instance to GeoJSON or GPX format).

Ownership is transferred to the caller, so it is up to the caller to delete the flight route once it is no longer used. Note that QML does that automatically.

Parameters
libraryThe library that is accessed
baseNameFile name, without path and without extension
Returns
Pointer to the object, or a nullptr in case of error.

◆ getStringFromRessource()

Q_INVOKABLE QString Librarian::getStringFromRessource ( const QString & name)
static

Exposes string stored in QRessource to QML.

This method reads a string from a file stored in the QRessource system. The method expects that the file contains a string in UTF8 encoding. There are a few special strings that are not read from QRessource, but are stored internally and that will be translated. These are the following.

  • ":text/whatsnew.html" A text that describes new features in the current program version
Parameters
nameName of the file in the QRessource, such as ":text/bugReport.html"
Returns
File content as a QString

◆ getStringHashFromRessource()

Q_INVOKABLE Units::ByteSize Librarian::getStringHashFromRessource ( const QString & name)
static

Exposes the hash of string stored in QRessource to QML.

This method reads a string from a file stored in the QRessource system. The method expects that the file contains a string in UTF8 encoding.

Parameters
nameName of the file in the QRessource, such as ":text/bugReport.html"
Returns
Hash of file content

◆ import()

Q_INVOKABLE QString Librarian::import ( Librarian::Library library,
const QString & fileName )
staticnodiscard

Import a file into a library.

This method imports a file into a library.

Parameters
libraryThe library to import the file. At the moment, only routs is supported.
fileNameFull file name
Returns
An empty string in case of success, or else a human-readable, translated error message.

◆ manualLocation()

QString Librarian::manualLocation ( )
staticnodiscard

Location of the user manual.

Returns
Directory that holds the HTML version of the manual, as a path or URL suitable for the platform

◆ matches()

Q_INVOKABLE bool Librarian::matches ( const QString & text,
const QString & filter )

Checks if a text matches a filter string, in a fuzzy way.

This method splits the filter into words at whitespace. The text matches if it contains every one of these words. The comparison ignores case and special characters, so that "Zürich" matches "u", "Ü", "ù" and "zurich". An empty filter matches every text.

This is the single filter primitive of this app. Lists over item models use it through Ui::NameFilterProxyModel; ad-hoc lists use it from QML, as in

model: Array.from(SomeSingleton.items).filter((i) => Librarian.matches(i.name, filterField.filter))

Parameters
textText that is searched
filterFilter, possibly consisting of several words
Returns
True if the text matches the filter

◆ matchesWords()

bool Librarian::matchesWords ( const QString & simplifiedText,
const QStringList & words )
staticnodiscard

Checks a simplified text against simplified filter words.

Parameters
simplifiedTextText, already simplified with simplify()
wordsFilter words, as returned by filterWords()
Returns
True if the text contains every word, ignoring case. An empty word list matches every text.

◆ model()

FileLibraryModel * Librarian::model ( Librarian::Library library) const
nodiscard

Model listing the entries of a library.

The model follows the library directory and announces changes with row-granular signals. It is owned by this instance.

Parameters
libraryThe library
Returns
Pointer to the model

◆ remove()

Q_INVOKABLE void Librarian::remove ( Librarian::Library library,
const QString & baseName )
static

Removes an entry from a library.

Parameters
libraryThe library that is accessed
baseNameFile name, without path and without extension

◆ rename()

Q_INVOKABLE void Librarian::rename ( Librarian::Library library,
const QString & oldName,
const QString & newName )
static

Renames an entry in a library.

Parameters
libraryThe library that is accessed
oldNameName of the file that is to be renamed, without path and without extension
newNameNew file name, without path and without extension. A file with that name must not exist in the library

◆ routesModel()

FileLibraryModel * Librarian::routesModel ( ) const
inlinenodiscard

Getter function for the property with the same name.

Returns
Property routesModel

Definition at line 96 of file Librarian.h.

◆ simplify()

QString Librarian::simplify ( const QString & string)
staticnodiscard

Simplifies a string without caching.

Transforms the string to QString::NormalizationForm_KD and removes every character outside a-z, A-Z and 0-9. This is the stateless core of simplifySpecialChars(). It has no side effects and is safe to call from worker threads, for instance to precompute search keys for item models.

Parameters
stringInput string
Returns
Simplified string

◆ simplifySpecialChars()

QString Librarian::simplifySpecialChars ( const QString & string)

Simplifies string by transforming and removing special characters.

This helper method simplifies a unicode string, by transforming it to QString::NormalizationForm_KD and then removing all 'special' character. The results are cached for better performance.

Parameters
stringInput string
Returns
Simplified string

The documentation for this class was generated from the following file: