1 | |
2 | /* |
3 | * infokcmmodel.h |
4 | * |
5 | * Copyright (C) 2010 David Hubner <hubnerd@ntlworld.com> |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
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, write to the Free Software |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | * |
21 | */ |
22 | |
23 | #ifndef INFOKCMMODEL |
24 | #define INFOKCMMODEL |
25 | |
26 | //KDE |
27 | #include <KService> |
28 | |
29 | //QT |
30 | #include <QObject> |
31 | #include <QStringList> |
32 | #include <QAbstractItemModel> |
33 | #include <QModelIndex> |
34 | #include <QVariant> |
35 | #include <QString> |
36 | |
37 | //Local |
38 | #include "kcmtreeitem.h" |
39 | |
40 | class KcmTreeItem; |
41 | |
42 | class InfoKcmModel : public QAbstractItemModel |
43 | { |
44 | Q_OBJECT |
45 | |
46 | public: |
47 | |
48 | /** |
49 | * Create InfoKcmModel object. |
50 | * Abstract data model to display KCM's for a tree view |
51 | * |
52 | * @param parent objects parent |
53 | */ |
54 | InfoKcmModel(QObject *parent); |
55 | |
56 | ~InfoKcmModel(); |
57 | |
58 | /** |
59 | * Get index of item in model |
60 | * |
61 | * @param row row position |
62 | * @param column column position |
63 | * @param parent parent of object |
64 | * @return index of object |
65 | */ |
66 | QModelIndex index(int row, int column, const QModelIndex& parent) const; |
67 | QModelIndex index(int row, int column, KcmTreeItem *parent) const; |
68 | |
69 | /** |
70 | * Get parent of item in model |
71 | */ |
72 | QModelIndex parent(const QModelIndex& index) const; |
73 | |
74 | /** |
75 | * Get amount of rows under parent |
76 | */ |
77 | int rowCount(const QModelIndex& parent) const; |
78 | |
79 | /** |
80 | * Get amount of columns under parent |
81 | */ |
82 | int columnCount(const QModelIndex& parent) const; |
83 | |
84 | /** |
85 | * Get the stored data for a role |
86 | * |
87 | * @param index objects index |
88 | * @param role role to retrieve data about |
89 | */ |
90 | QVariant data(const QModelIndex& index, int role) const; |
91 | |
92 | /** |
93 | * Get header information |
94 | */ |
95 | QVariant (int, Qt::Orientation, int) const; |
96 | |
97 | /** |
98 | * Get set flags for a treeitem |
99 | */ |
100 | Qt::ItemFlags flags(const QModelIndex &) const; |
101 | |
102 | /** |
103 | * Get the first valid item on the treeview |
104 | * Checks main root items only |
105 | * |
106 | * @return index of valid item |
107 | */ |
108 | QModelIndex firstValid() const; |
109 | |
110 | /** |
111 | * Get all KCM keywords for all KCMs stored in the model |
112 | */ |
113 | QStringList allChildrenKeywords(); |
114 | |
115 | /** |
116 | * Get QModelIndex of a KcmTreeItem |
117 | */ |
118 | QModelIndex indexOf(KcmTreeItem *item); |
119 | |
120 | private: |
121 | |
122 | /** |
123 | * Init tree items |
124 | */ |
125 | void createTreeItems(); |
126 | |
127 | /** |
128 | * Get a certain KCM's keywords |
129 | */ |
130 | QStringList childrenKeywords(KcmTreeItem *kcmItem); |
131 | |
132 | KService::List m_moduleList; |
133 | KcmTreeItem *m_root; |
134 | }; |
135 | |
136 | #endif // INFOKCMMODEL |
137 | |