Model for viewing and editing a set of views in list form.
More...
#include <Workspace/Presentation/recentfilesmodel.h>
Inherits QAbstractListModel.
The model is a list model, where each item in the list represents a recently opened file. Callers can add files to the list (addFile(), and it will automatically manage inserting files them in a 'most recently used' order. The recently opened files are stored in a QSettings object, under the specified tag name. This makes the model persist between sessions.
Callers can also clear the list, and remove files that don't exist from the list.
◆ RecentFilesModel()
RecentFilesModel |
( |
QSettings & |
settings, |
|
|
const QString & |
recentSettingsTagName, |
|
|
QObject * |
parent = nullptr |
|
) |
| |
- Parameters
-
settings | The settings in which the list of recently opened files are to be stored / retrieved from. |
recentSettingsTagName | The tag name of the item under which we're storing the list of recently opened files in the settings. |
parent | The parent of this model. |
◆ ~RecentFilesModel()
◆ addFile()
void addFile |
( |
const QString & |
fileName | ) |
|
- Parameters
-
fileName | The fileName to add to the model. |
Adds a new file name to the model, ensuring that it is at the top of the list. If the file name already exists in the list, it will be removed from its old location and re-inserted at the top of the list.
◆ clear()
Clears the list, removing all files from it.
◆ data()
QVariant data |
( |
const QModelIndex & |
index, |
|
|
int |
role = Qt::DisplayRole |
|
) |
| const |
|
override |
- Parameters
-
index | The index of the node in the model from which we want to retrieve data. |
role | The role we are going to be using the data for. In our case, we only accept Qt::DisplayRole. |
- Returns
- a QVariant containing the index's data in the form of a string.
Retrieves the data from the model at the provided index / role as a QVariant. Since our data is an ordered list of strings, we will always be returning strings here.
◆ flags()
Qt::ItemFlags flags |
( |
const QModelIndex & |
index | ) |
const |
|
override |
◆ isEmpty()
- Returns
- True if model has no recent files, false otherwise.
◆ maxEntries()
◆ removeFile()
bool removeFile |
( |
const QString & |
fileName | ) |
|
Remove a specific file from the list
- Parameters
-
fileName | The file to remove |
- Returns
- If the files was found in the list and removed.
◆ removeIfNotExist()
void removeIfNotExist |
( |
| ) |
|
Removes all files in the model that do not exist on disk.
◆ rowCount()
int rowCount |
( |
const QModelIndex & |
parent = QModelIndex() | ) |
const |
|
override |
- Parameters
-
parent | The index of the model under which we're counting its child rows. |
Returns the number of rows in the model under a given parent (since this is a list model, a number greater than zero will only be returned if parent is invalid, i.e. the root node).
◆ setMaxEntries()
void setMaxEntries |
( |
int |
m | ) |
|