blob: 1a744ac82b8e950c34b3214bc833f3847cddb5c6 [file] [log] [blame]
agsantos655d8e22020-08-10 17:36:47 -04001/**
2 * Copyright (C) 2020 by Savoir-faire Linux
3 * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
Sébastien Blin1f915762020-08-03 13:27:42 -04004 *
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
27class PreferenceItemListModel : public QAbstractListModel
28{
29 Q_OBJECT
agsantos655d8e22020-08-10 17:36:47 -040030
Sébastien Blin1f915762020-08-03 13:27:42 -040031 Q_PROPERTY(QString pluginId READ pluginId WRITE setPluginId)
agsantose1672082020-08-10 12:49:56 -040032 Q_PROPERTY(int preferencesCount READ preferencesCount)
Sébastien Blin1f915762020-08-03 13:27:42 -040033public:
agsantose1672082020-08-10 12:49:56 -040034 enum Role {
35 PreferenceKey = Qt::UserRole + 1,
36 PreferenceName,
37 PreferenceSummary,
38 PreferenceType,
agsantos78726ec2020-08-18 17:41:05 -040039 PluginId,
40 PreferenceCurrentValue
agsantose1672082020-08-10 12:49:56 -040041 };
agsantos655d8e22020-08-10 17:36:47 -040042
Sébastien Blin1f915762020-08-03 13:27:42 -040043 typedef enum {
agsantose1672082020-08-10 12:49:56 -040044 LIST,
agsantos78726ec2020-08-18 17:41:05 -040045 USERLIST,
agsantose1672082020-08-10 12:49:56 -040046 DEFAULT,
Sébastien Blin1f915762020-08-03 13:27:42 -040047 } Type;
agsantos655d8e22020-08-10 17:36:47 -040048
Sébastien Blin1f915762020-08-03 13:27:42 -040049 Q_ENUM(Role)
50
agsantose1672082020-08-10 12:49:56 -040051 explicit PreferenceItemListModel(QObject* parent = 0);
Sébastien Blin1f915762020-08-03 13:27:42 -040052 ~PreferenceItemListModel();
53
54 /*
55 * QAbstractListModel override.
56 */
agsantose1672082020-08-10 12:49:56 -040057 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 Blin1f915762020-08-03 13:27:42 -040060 /*
61 * Override role name as access point in qml.
62 */
63 QHash<int, QByteArray> roleNames() const override;
agsantose1672082020-08-10 12:49:56 -040064 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 Blin1f915762020-08-03 13:27:42 -040067
68 /*
agsantos655d8e22020-08-10 17:36:47 -040069 * This function is to reset the model when there's new plugin added or modified.
Sébastien Blin1f915762020-08-03 13:27:42 -040070 */
71 Q_INVOKABLE void reset();
72
73 QString pluginId() const;
agsantose1672082020-08-10 12:49:56 -040074 void setPluginId(const QString& pluginId);
75 int preferencesCount();
76
Sébastien Blin1f915762020-08-03 13:27:42 -040077private:
78 QString pluginId_;
79};