KCMUtils

kpluginmodel.h
1/*
2 SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
3 SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KPLUGINMODEL_H
9#define KPLUGINMODEL_H
10
11#include "kcmutilscore_export.h"
12
13#include <QAbstractListModel>
14#include <QList>
15
16#include <KPluginMetaData>
17#include <memory>
18
19class KConfigGroup;
20class KPluginModelPrivate;
21
22class KCMUTILSCORE_EXPORT KPluginModel : public QAbstractListModel
23{
24 Q_OBJECT
25
26public:
27 enum Roles {
28 NameRole = Qt::DisplayRole,
29 IconRole = Qt::DecorationRole,
30 EnabledRole = Qt::CheckStateRole,
31 DescriptionRole = Qt::UserRole + 1,
32 IsChangeableRole,
33 MetaDataRole,
34 ConfigRole,
35 IdRole,
36 EnabledByDefaultRole,
37 SortableRole, /// @internal
38 };
39
40 explicit KPluginModel(QObject *parent = nullptr);
41 ~KPluginModel() override;
42
43 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
44 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
45 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
46 QHash<int, QByteArray> roleNames() const override;
47
48 bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
49
50 void addPlugins(const QList<KPluginMetaData> &plugins, const QString &categoryLabel);
51
52 /**
53 * Add plugins that should not be sorted automatically based on their name
54 * This is useful in case your app has a custom sorting mechanism or implements reordering of plugins
55 *
56 * @since 6.0
57 */
58 void addUnsortablePlugins(const QList<KPluginMetaData> &plugins, const QString &categoryLabel);
59 /// @since 6.0
60 void removePlugin(const KPluginMetaData &data);
61 void clear();
62 void setConfig(const KConfigGroup &config);
63 void save();
64 void load();
65 void defaults();
66 bool isSaveNeeded();
67
68 /**
69 * Returns the KPluginMetaData object of the plugin's config module. If no plugin is found or the plugin does not have a config, the resulting
70 * KPluginMetaData object will be invalid.
71 * @since 5.94
72 */
73 KPluginMetaData findConfigForPluginId(const QString &pluginId) const;
74
75 Q_SIGNAL void defaulted(bool isDefaulted);
76 Q_SIGNAL void isSaveNeededChanged();
77
78private:
79 const std::unique_ptr<KPluginModelPrivate> d;
80 friend class KPluginProxyModel;
81 QStringList getOrderedCategoryLabels();
82};
83#endif
QAction * load(const QObject *recvr, const char *slot, QObject *parent)
KGuiItem defaults()
KGuiItem clear()
const QList< QKeySequence > & save()
virtual QVariant data(const QModelIndex &index, int role) const const=0
virtual bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
virtual QHash< int, QByteArray > roleNames() const const
virtual int rowCount(const QModelIndex &parent) const const=0
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:56 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.