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) |
agsantos | e167208 | 2020-08-10 12:49:56 -0400 | [diff] [blame] | 32 | Q_PROPERTY(int preferencesCount READ preferencesCount) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 33 | public: |
agsantos | e167208 | 2020-08-10 12:49:56 -0400 | [diff] [blame] | 34 | enum Role { |
| 35 | PreferenceKey = Qt::UserRole + 1, |
| 36 | PreferenceName, |
| 37 | PreferenceSummary, |
| 38 | PreferenceType, |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame^] | 39 | PluginId, |
| 40 | PreferenceCurrentValue |
agsantos | e167208 | 2020-08-10 12:49:56 -0400 | [diff] [blame] | 41 | }; |
agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame] | 42 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 43 | typedef enum { |
agsantos | e167208 | 2020-08-10 12:49:56 -0400 | [diff] [blame] | 44 | LIST, |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame^] | 45 | USERLIST, |
agsantos | e167208 | 2020-08-10 12:49:56 -0400 | [diff] [blame] | 46 | DEFAULT, |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 47 | } Type; |
agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame] | 48 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 49 | Q_ENUM(Role) |
| 50 | |
agsantos | e167208 | 2020-08-10 12:49:56 -0400 | [diff] [blame] | 51 | explicit PreferenceItemListModel(QObject* parent = 0); |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 52 | ~PreferenceItemListModel(); |
| 53 | |
| 54 | /* |
| 55 | * QAbstractListModel override. |
| 56 | */ |
agsantos | e167208 | 2020-08-10 12:49:56 -0400 | [diff] [blame] | 57 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; |
| 58 | int columnCount(const QModelIndex& parent) const override; |
| 59 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 60 | /* |
| 61 | * Override role name as access point in qml. |
| 62 | */ |
| 63 | QHash<int, QByteArray> roleNames() const override; |
agsantos | e167208 | 2020-08-10 12:49:56 -0400 | [diff] [blame] | 64 | QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const; |
| 65 | QModelIndex parent(const QModelIndex& child) const; |
| 66 | Qt::ItemFlags flags(const QModelIndex& index) const; |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 67 | |
| 68 | /* |
agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame] | 69 | * 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] | 70 | */ |
| 71 | Q_INVOKABLE void reset(); |
| 72 | |
| 73 | QString pluginId() const; |
agsantos | e167208 | 2020-08-10 12:49:56 -0400 | [diff] [blame] | 74 | void setPluginId(const QString& pluginId); |
| 75 | int preferencesCount(); |
| 76 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 77 | private: |
| 78 | QString pluginId_; |
| 79 | }; |