1 | /* |
2 | SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #ifndef CATEGORIESMODEL_H |
8 | #define CATEGORIESMODEL_H |
9 | |
10 | #include <QAbstractListModel> |
11 | |
12 | #include "enginebase.h" |
13 | #include "provider.h" |
14 | |
15 | /** |
16 | * @short A model which shows the categories found in an Engine |
17 | * @since 5.63 |
18 | */ |
19 | class CategoriesModel : public QAbstractListModel |
20 | { |
21 | Q_OBJECT |
22 | public: |
23 | explicit CategoriesModel(KNSCore::EngineBase *parent); |
24 | ~CategoriesModel() override; |
25 | |
26 | enum Roles { |
27 | NameRole = Qt::UserRole + 1, |
28 | IdRole, |
29 | DisplayNameRole, |
30 | }; |
31 | Q_ENUM(Roles) |
32 | |
33 | QHash<int, QByteArray> roleNames() const override; |
34 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
35 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
36 | |
37 | /** |
38 | * Get the display name for the category with the id passed to the function |
39 | * |
40 | * @param id The ID of the category you want to get the display name for |
41 | * @return The display name (or the translated string "Unknown Category" for the requested category |
42 | */ |
43 | Q_INVOKABLE QString idToDisplayName(const QString &id) const; |
44 | |
45 | private: |
46 | KNSCore::EngineBase *const m_engine; |
47 | }; |
48 | |
49 | #endif // CATEGORIESMODEL_H |
50 | |