| 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 | |
| 14 | /** |
| 15 | * @short A model which shows the categories found in an Engine |
| 16 | * @since 5.63 |
| 17 | */ |
| 18 | class CategoriesModel : public QAbstractListModel |
| 19 | { |
| 20 | Q_OBJECT |
| 21 | public: |
| 22 | explicit CategoriesModel(KNSCore::EngineBase *parent); |
| 23 | ~CategoriesModel() override; |
| 24 | |
| 25 | enum Roles { |
| 26 | NameRole = Qt::UserRole + 1, |
| 27 | IdRole, |
| 28 | DisplayNameRole, |
| 29 | }; |
| 30 | Q_ENUM(Roles) |
| 31 | |
| 32 | QHash<int, QByteArray> roleNames() const override; |
| 33 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 34 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 35 | |
| 36 | /** |
| 37 | * Get the display name for the category with the id passed to the function |
| 38 | * |
| 39 | * @param id The ID of the category you want to get the display name for |
| 40 | * @return The display name (or the translated string "Unknown Category" for the requested category |
| 41 | */ |
| 42 | Q_INVOKABLE QString idToDisplayName(const QString &id) const; |
| 43 | |
| 44 | private: |
| 45 | KNSCore::EngineBase *const m_engine; |
| 46 | }; |
| 47 | |
| 48 | #endif // CATEGORIESMODEL_H |
| 49 | |