swissChili | a44bf72 | 2022-04-16 18:41:54 -0700 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <QAbstractListModel> |
| 4 | #include <qqml.h> |
| 5 | #include <QSettings> |
| 6 | |
| 7 | class RecentModel : public QAbstractListModel |
| 8 | { |
| 9 | Q_OBJECT |
| 10 | QML_ELEMENT |
| 11 | |
| 12 | public: |
| 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 | |
| 30 | private: |
| 31 | QStringList _recents; |
| 32 | QSettings _settings; |
| 33 | }; |
| 34 | |
| 35 | Q_DECLARE_METATYPE(RecentModel) |
| 36 | Q_DECLARE_METATYPE(RecentModel *) |