File indexing completed on 2024-04-14 03:54:09

0001 /*
0002     SPDX-FileCopyrightText: 2019 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef CATEGORIESMODEL_H
0008 #define CATEGORIESMODEL_H
0009 
0010 #include <QAbstractListModel>
0011 
0012 #include "enginebase.h"
0013 #include "provider.h"
0014 
0015 /**
0016  * @short A model which shows the categories found in an Engine
0017  * @since 5.63
0018  */
0019 class CategoriesModel : public QAbstractListModel
0020 {
0021     Q_OBJECT
0022 public:
0023     explicit CategoriesModel(KNSCore::EngineBase *parent);
0024     ~CategoriesModel() override;
0025 
0026     enum Roles {
0027         NameRole = Qt::UserRole + 1,
0028         IdRole,
0029         DisplayNameRole,
0030     };
0031     Q_ENUM(Roles)
0032 
0033     QHash<int, QByteArray> roleNames() const override;
0034     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0035     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0036 
0037     /**
0038      * Get the display name for the category with the id passed to the function
0039      *
0040      * @param id The ID of the category you want to get the display name for
0041      * @return The display name (or the translated string "Unknown Category" for the requested category
0042      */
0043     Q_INVOKABLE QString idToDisplayName(const QString &id) const;
0044 
0045 private:
0046     KNSCore::EngineBase *const m_engine;
0047 };
0048 
0049 #endif // CATEGORIESMODEL_H