agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2020 by Savoir-faire Linux |
| 3 | * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include <QAbstractItemModel> |
| 22 | |
| 23 | #include "api/pluginmodel.h" |
| 24 | |
| 25 | #include "lrcinstance.h" |
| 26 | |
| 27 | class PreferenceItemListModel : public QAbstractListModel |
| 28 | { |
| 29 | Q_OBJECT |
agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame] | 30 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 31 | Q_PROPERTY(QString pluginId READ pluginId WRITE setPluginId) |
| 32 | public: |
| 33 | enum Role { PreferenceKey = Qt::UserRole + 1, PreferenceName, PreferenceSummary, PreferenceType, PreferenceDefaultValue, PreferenceEntries, PreferenceEntryValues}; |
agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame] | 34 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 35 | typedef enum { |
| 36 | LIST, |
| 37 | DEFAULT, |
| 38 | } Type; |
agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame] | 39 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 40 | Q_ENUM(Role) |
| 41 | |
| 42 | explicit PreferenceItemListModel(QObject *parent = 0); |
| 43 | ~PreferenceItemListModel(); |
| 44 | |
| 45 | /* |
| 46 | * QAbstractListModel override. |
| 47 | */ |
| 48 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 49 | int columnCount(const QModelIndex &parent) const override; |
| 50 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 51 | /* |
| 52 | * Override role name as access point in qml. |
| 53 | */ |
| 54 | QHash<int, QByteArray> roleNames() const override; |
| 55 | QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const; |
| 56 | QModelIndex parent(const QModelIndex &child) const; |
| 57 | Qt::ItemFlags flags(const QModelIndex &index) const; |
| 58 | |
| 59 | /* |
agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame] | 60 | * This function is to reset the model when there's new plugin added or modified. |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 61 | */ |
| 62 | Q_INVOKABLE void reset(); |
| 63 | |
| 64 | QString pluginId() const; |
| 65 | void setPluginId(const QString &pluginId); |
| 66 | // signals: |
| 67 | // void pluginIdChanged(); |
| 68 | private: |
| 69 | QString pluginId_; |
| 70 | }; |