File indexing completed on 2024-04-28 16:49:52
0001 /* 0002 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractItemModel> 0010 0011 #include "process_attribute_model.h" 0012 0013 namespace KSysGuard 0014 { 0015 class CGroup; 0016 0017 class CGroupDataModelPrivate; 0018 0019 /** 0020 * @brief The CGroupDataModel class is a list model of all cgroups from a given root 0021 * Data is exposed as per ProcessDataModel with configurable columns 0022 * 0023 * Data is refreshed on a timer 0024 */ 0025 class Q_DECL_EXPORT CGroupDataModel : public QAbstractItemModel 0026 { 0027 Q_OBJECT 0028 /** 0029 * @copydoc ProcessDataModel::availableAttributes 0030 */ 0031 Q_PROPERTY(QStringList availableAttributes READ availableAttributes CONSTANT) 0032 /** 0033 * @copydoc ProcessDataModel::enabledAttributes 0034 */ 0035 Q_PROPERTY(QStringList enabledAttributes READ enabledAttributes WRITE setEnabledAttributes NOTIFY enabledAttributesChanged) 0036 /** 0037 * @copydoc ProcessDataModel::attributesModel 0038 */ 0039 Q_PROPERTY(QObject *attributesModel READ attributesModel CONSTANT) 0040 /** 0041 * @copydoc ProcessDataModel::enabled 0042 */ 0043 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) 0044 /** 0045 * @copydoc setRoot 0046 */ 0047 Q_PROPERTY(QString setRoot READ root WRITE setRoot NOTIFY rootChanged) 0048 0049 Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged) 0050 0051 public: 0052 CGroupDataModel(QObject *parent = nullptr); 0053 CGroupDataModel(const QString &root, QObject *parent = nullptr); 0054 ~CGroupDataModel() override; 0055 0056 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0057 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0058 QVariant data(const QModelIndex &index, int role) const override; 0059 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0060 QModelIndex index(int row, int column, const QModelIndex &parent) const override; 0061 QModelIndex parent(const QModelIndex &child) const override; 0062 QHash<int, QByteArray> roleNames() const override; 0063 0064 /** 0065 * @copydoc ProcessDataModel::availableAttributes 0066 */ 0067 QStringList availableAttributes() const; 0068 /** 0069 * @copydoc ProcessDataModel::enabledAttributes 0070 */ 0071 QStringList enabledAttributes() const; 0072 /** 0073 * @copydoc ProcessDataModel::setEnabledAttributes 0074 */ 0075 void setEnabledAttributes(const QStringList &enabledAttributes); 0076 0077 QModelIndex getQModelIndex(CGroup *cgroup, int column) const; 0078 0079 /** 0080 * @copydoc ProcessDataModel::attributesModel 0081 */ 0082 ProcessAttributeModel *attributesModel(); 0083 /** 0084 * @copydoc ProcessDataModel::isEnabled 0085 */ 0086 bool isEnabled() const; 0087 /** 0088 * @copydoc ProcessDataModel::setEnabled 0089 */ 0090 void setEnabled(bool isEnabled); 0091 0092 QString root() const; 0093 /** 0094 * Set the root cgroup to start listing from 0095 * e.g "user.slice/user-1000.slice" 0096 * 0097 * The default is blank 0098 */ 0099 void setRoot(const QString &root); 0100 0101 /** 0102 * Trigger an update of the model 0103 */ 0104 void update(); 0105 0106 bool isAvailable() const; 0107 0108 Q_SIGNALS: 0109 void enabledAttributesChanged(); 0110 void enabledChanged(); 0111 void rootChanged(); 0112 void availableChanged(); 0113 0114 protected: 0115 virtual bool filterAcceptsCGroup(const QString &id); 0116 0117 private: 0118 QScopedPointer<CGroupDataModelPrivate> d; 0119 void update(CGroup *node); 0120 }; 0121 0122 }