Changeset View
Changeset View
Standalone View
Standalone View
kcms/style/stylesmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Kai Uwe Broulik <kde@pbroulik.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #pragma once | ||||
22 | | ||||
23 | #include <QAbstractListModel> | ||||
24 | #include <QString> | ||||
25 | #include <QVector> | ||||
26 | | ||||
27 | struct StylesModelData | ||||
28 | { | ||||
29 | QString display; | ||||
30 | QString styleName; | ||||
31 | QString description; | ||||
32 | QString configPage; | ||||
33 | }; | ||||
34 | Q_DECLARE_TYPEINFO(StylesModelData, Q_MOVABLE_TYPE); | ||||
35 | | ||||
36 | class StylesModel : public QAbstractListModel | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | | ||||
40 | Q_PROPERTY(QString selectedStyle READ selectedStyle WRITE setSelectedStyle NOTIFY selectedStyleChanged) | ||||
41 | Q_PROPERTY(int selectedStyleIndex READ selectedStyleIndex NOTIFY selectedStyleIndexChanged) | ||||
42 | | ||||
43 | public: | ||||
44 | StylesModel(QObject *parent); | ||||
45 | ~StylesModel() override; | ||||
46 | | ||||
47 | enum Roles { | ||||
48 | StyleNameRole = Qt::UserRole + 1, | ||||
49 | DescriptionRole, | ||||
50 | ConfigurableRole | ||||
51 | }; | ||||
52 | | ||||
53 | int rowCount(const QModelIndex &parent) const override; | ||||
54 | QVariant data(const QModelIndex &index, int role) const override; | ||||
55 | QHash<int, QByteArray> roleNames() const override; | ||||
56 | | ||||
57 | QString selectedStyle() const; | ||||
58 | void setSelectedStyle(const QString &style); | ||||
59 | | ||||
60 | int indexOfStyle(const QString &style) const; | ||||
61 | int selectedStyleIndex() const; | ||||
62 | | ||||
63 | QString styleConfigPage(const QString &style) const; | ||||
64 | | ||||
65 | void load(); | ||||
66 | | ||||
67 | Q_SIGNALS: | ||||
68 | void selectedStyleChanged(const QString &style); | ||||
69 | void selectedStyleIndexChanged(); | ||||
70 | | ||||
71 | private: | ||||
72 | QString m_selectedStyle; | ||||
73 | | ||||
74 | QVector<StylesModelData> m_data; | ||||
75 | | ||||
76 | }; |