File indexing completed on 2024-09-08 05:00:58
0001 // SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include "qqml.h" 0007 #include "quicksetting.h" 0008 0009 #include <KPluginMetaData> 0010 0011 #include <QAbstractListModel> 0012 #include <QQmlListProperty> 0013 0014 /** 0015 * @short A list model for serving quick settings metadata. 0016 * 0017 * @author Devin Lin <devin@kde.org> 0018 **/ 0019 class SavedQuickSettingsModel : public QAbstractListModel 0020 { 0021 Q_OBJECT 0022 QML_ELEMENT 0023 0024 public: 0025 SavedQuickSettingsModel(QObject *parent = nullptr); 0026 0027 enum { 0028 NameRole, /**< The name of the quick setting. */ 0029 IdRole, /**< The plugin id of the quick setting package. */ 0030 IconRole, /**< The icon of the quick setting. */ 0031 }; 0032 0033 QVariant data(const QModelIndex &index, int role) const override; 0034 int rowCount(const QModelIndex &parent) const override; 0035 QHash<int, QByteArray> roleNames() const override; 0036 0037 Q_INVOKABLE void moveRow(int oldIndex, int newIndex); 0038 Q_INVOKABLE void insertRow(KPluginMetaData metaData, int index); 0039 Q_INVOKABLE KPluginMetaData takeRow(int index); 0040 Q_INVOKABLE void removeRow(int index); 0041 0042 QList<KPluginMetaData> list() const; 0043 0044 public Q_SLOTS: 0045 void updateData(QList<KPluginMetaData> data); 0046 0047 Q_SIGNALS: 0048 void dataUpdated(QList<KPluginMetaData> data); 0049 0050 private: 0051 QList<KPluginMetaData> m_data; 0052 };