1/*
2 SPDX-FileCopyrightText: 2021 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 KNSCORE_PROVIDERSMODELL_H
8#define KNSCORE_PROVIDERSMODELL_H
9
10#include <QAbstractListModel>
11
12#include "enginebase.h"
13
14#include "knewstuffcore_export.h"
15
16#include <memory>
17
18namespace KNSCore
19{
20class ProvidersModelPrivate;
21/*!
22 * \class KNSCore::ProvidersModel
23 * \inmodule KNewStuffCore
24 *
25 * \brief A model which holds information on all known Providers for a specific Engine.
26 *
27 * \since 5.85
28 */
29class KNEWSTUFFCORE_EXPORT ProvidersModel : public QAbstractListModel
30{
31 Q_OBJECT
32 /*
33 * The Engine for which this model displays Providers
34 */
35 Q_PRIVATE_PROPERTY(d, EngineBase *engine READ getEngine WRITE setEngine NOTIFY engineChanged)
36public:
37 explicit ProvidersModel(QObject *parent = nullptr);
38 ~ProvidersModel() override;
39
40 /*!
41 * \enum KNSCore::ProvidersModel::Roles
42 *
43 * \value IdRole
44 * \value NameRole,
45 * \value VersionRole,
46 * \value WebsiteRole,
47 * \value HostRole,
48 * \value ContactEmailRole,
49 * \value SupportsSslRole,
50 * \value IconRole,
51 * \value ObjectRole
52 * The actual Provider object. Do not hold this locally and expect it to disappear at a moment's notice.
53 */
54 enum Roles {
55 IdRole = Qt::UserRole + 1,
56 NameRole,
57 VersionRole,
58 WebsiteRole,
59 HostRole,
60 ContactEmailRole,
61 SupportsSslRole,
62 IconRole,
63 ObjectRole,
64 };
65 Q_ENUM(Roles)
66
67 QHash<int, QByteArray> roleNames() const override;
68 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
69 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
70
71 // TODO KF7: Port property to back to public getter/setter, narrow types to EngineBase
72 QObject *engine() const;
73 void setEngine(QObject *engine);
74 Q_SIGNAL void engineChanged();
75
76private:
77 std::unique_ptr<ProvidersModelPrivate> d;
78};
79}
80
81#endif // KNSCORE_PROVIDERSMODELL_H
82

source code of knewstuff/src/core/providersmodel.h