| 1 | #ifndef PATHLISTMODEL_HXX |
| 2 | #define PATHLISTMODEL_HXX |
| 3 | |
| 4 | #include <vector> |
| 5 | |
| 6 | #include <QAbstractListModel> |
| 7 | |
| 8 | const int PathRole = Qt::UserRole + 1; |
| 9 | const int PathEnabledRole = Qt::UserRole + 2; |
| 10 | |
| 11 | class PathListModel : public QAbstractListModel |
| 12 | { |
| 13 | Q_OBJECT |
| 14 | |
| 15 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
| 16 | public: |
| 17 | |
| 18 | PathListModel(QObject* pr); |
| 19 | ~PathListModel() override; |
| 20 | |
| 21 | void loadFromSettings(QString key); |
| 22 | void saveToSettings(QString key) const; |
| 23 | |
| 24 | int rowCount(const QModelIndex& parent) const override; |
| 25 | |
| 26 | QVariant data(const QModelIndex& index, int role) const override; |
| 27 | |
| 28 | bool setData(const QModelIndex &index, const QVariant &value, int role) override; |
| 29 | |
| 30 | QHash<int, QByteArray> roleNames() const override; |
| 31 | |
| 32 | static QStringList readEnabledPaths(QString settingsKey); |
| 33 | |
| 34 | QStringList enabledPaths() const; |
| 35 | |
| 36 | int count(); |
| 37 | signals: |
| 38 | void enabledPathsChanged(); |
| 39 | void countChanged(); |
| 40 | |
| 41 | public slots: |
| 42 | void removePath(int index); |
| 43 | void appendPath(QString path); |
| 44 | |
| 45 | void swapIndices(int indexA, int indexB); |
| 46 | |
| 47 | private: |
| 48 | struct PathEntry { |
| 49 | QString path; |
| 50 | bool enabled = true; |
| 51 | }; |
| 52 | |
| 53 | std::vector<PathEntry> mPaths; |
| 54 | }; |
| 55 | |
| 56 | #endif // PATHLISTMODEL_HXX |