blob: 76cd461d2d730594254632ecd23d254b78a04f9a [file] [log] [blame]
swissChilia44bf722022-04-16 18:41:54 -07001#pragma once
2
3#include <QAbstractListModel>
4#include <qqml.h>
5#include <QSettings>
6
7class RecentModel : public QAbstractListModel
8{
9 Q_OBJECT
10 QML_ELEMENT
11
12public:
13 explicit RecentModel(QObject *parent = nullptr);
14 RecentModel(const RecentModel &other, QObject *parent = nullptr);
15
16 enum
17 {
18 PathRole = Qt::UserRole + 1
19 };
20
21 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
22
23 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
24
25 QHash<int, QByteArray> roleNames() const override;
26
27 Q_INVOKABLE void add(QString path);
28 Q_INVOKABLE void remove(QString path);
29
30private:
31 QStringList _recents;
32 QSettings _settings;
33};
34
35Q_DECLARE_METATYPE(RecentModel)
36Q_DECLARE_METATYPE(RecentModel *)