KCMUtils

kpluginmodel.h
1 /*
2  SPDX-FileCopyrightText: 2021 Nicolas Fella <[email protected]>
3  SPDX-FileCopyrightText: 2021 Alexander Lohnau <[email protected]>
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 <QVector>
15 
16 #include <KPluginMetaData>
17 #include <memory>
18 
19 class KConfigGroup;
20 class KPluginModelPrivate;
21 
22 class KCMUTILSCORE_EXPORT KPluginModel : public QAbstractListModel
23 {
24  Q_OBJECT
25 
26 public:
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  };
38 
39  explicit KPluginModel(QObject *parent = nullptr);
40  ~KPluginModel() override;
41 
42  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
43  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
44  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
45  QHash<int, QByteArray> roleNames() const override;
46 
47  void addPlugins(const QVector<KPluginMetaData> &plugins, const QString &categoryLabel);
48  void clear();
49  void setConfig(const KConfigGroup &config);
50  void save();
51  void load();
52  void defaults();
53  bool isSaveNeeded();
54 
55  /**
56  * 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
57  * KPluginMetaData object will be invalid.
58  * @since 5.94
59  */
60  KPluginMetaData findConfigForPluginId(const QString &pluginId) const;
61 
62  Q_SIGNAL void defaulted(bool isDefaulted);
63  Q_SIGNAL void isSaveNeededChanged();
64 
65 private:
66  const std::unique_ptr<KPluginModelPrivate> d;
67 };
68 #endif
DisplayRole
virtual int rowCount(const QModelIndex &parent) const const=0
virtual QVariant data(const QModelIndex &index, int role) const const=0
QAction * load(const QObject *recvr, const char *slot, QObject *parent)
KGuiItem defaults()
virtual QHash< int, QByteArray > roleNames() const const
QAction * clear(const QObject *recvr, const char *slot, QObject *parent)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QAction * save(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Jun 26 2022 03:51:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.