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

List of the entries of a file-based library. More...

#include <FileLibraryModel.h>

Public Types

enum  Role : int { NameRole = Qt::UserRole + 1 }
 Model roles. More...

Public Slots

void refresh ()
 Rescans the directory.

Public Member Functions

 FileLibraryModel (QString directory, QString suffix, QObject *parent=nullptr)
 Standard constructor.
QStringList names () const
 Base names of the library entries.
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 Re-implemented from QAbstractListModel.
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 Re-implemented from QAbstractListModel.
QHash< int, QByteArray > roleNames () const override
 Re-implemented from QAbstractListModel.

Detailed Description

List of the entries of a file-based library.

A file-based library is a directory that holds one file per entry, all with the same suffix. This model lists the base names of these files under the role 'name', sorted case-insensitively.

The directory is watched with a QFileSystemWatcher, so that the model follows every writer, including those that do not go through Librarian. Changes to the directory are coalesced and applied with row-granular model signals. Writers inside the app call refresh() to apply their changes immediately.

Instances are owned by Librarian, see Librarian::aircraftModel and Librarian::routesModel. In QML, bind a view to one of them through a NameFilterProxyModel.

Definition at line 46 of file FileLibraryModel.h.

Member Enumeration Documentation

◆ Role

Model roles.

Enumerator
NameRole 

Base name of the entry, a QString.

Definition at line 54 of file FileLibraryModel.h.

Constructor & Destructor Documentation

◆ FileLibraryModel()

FileLibraryModel::FileLibraryModel ( QString directory,
QString suffix,
QObject * parent = nullptr )
explicit

Standard constructor.

Parameters
directoryDirectory holding the library files. Created if it does not exist.
suffixSuffix of the library files, including the dot, such as ".json"
parentThe standard QObject parent pointer

Member Function Documentation

◆ data()

QVariant FileLibraryModel::data ( const QModelIndex & index,
int role = Qt::DisplayRole ) const
nodiscardoverride

Re-implemented from QAbstractListModel.

Parameters
indexModel index
roleOne of the roles in FileLibraryModel::Role
Returns
Data for the role, or an invalid QVariant

◆ names()

QStringList FileLibraryModel::names ( ) const
inlinenodiscard

Base names of the library entries.

Returns
Names, in model order

Definition at line 83 of file FileLibraryModel.h.

◆ refresh

void FileLibraryModel::refresh ( )
slot

Rescans the directory.

Compares the directory content with the model and announces the difference with row-granular signals. This is called automatically when the directory changes; writers inside the app call it to apply their changes without delay.

◆ roleNames()

QHash< int, QByteArray > FileLibraryModel::roleNames ( ) const
nodiscardoverride

Re-implemented from QAbstractListModel.

Returns
Names of the roles in FileLibraryModel::Role

◆ rowCount()

int FileLibraryModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
nodiscardoverride

Re-implemented from QAbstractListModel.

Parameters
parentParent index, invalid for the list itself
Returns
Number of entries, or zero for a valid parent

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