| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> |
| 3 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | #ifndef KPLUGINPROXYMODEL_H |
| 7 | #define KPLUGINPROXYMODEL_H |
| 8 | |
| 9 | #include "kcmutilscore_export.h" |
| 10 | #include "kpluginmodel.h" |
| 11 | |
| 12 | #include <KCategorizedSortFilterProxyModel> |
| 13 | |
| 14 | class Q_DECL_HIDDEN KPluginProxyModel : public KCategorizedSortFilterProxyModel |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged) |
| 18 | Q_PROPERTY(QAbstractListModel *model WRITE setModel) |
| 19 | public: |
| 20 | explicit KPluginProxyModel(QObject *parent = nullptr); |
| 21 | ~KPluginProxyModel() override; |
| 22 | |
| 23 | QString query() const; |
| 24 | void setQuery(const QString &query); |
| 25 | void setModel(QAbstractListModel *model) |
| 26 | { |
| 27 | setSourceModel(model); |
| 28 | m_model = qobject_cast<KPluginModel *>(object: model); |
| 29 | Q_ASSERT(m_model); |
| 30 | } |
| 31 | |
| 32 | Q_SIGNALS: |
| 33 | void queryChanged(); |
| 34 | |
| 35 | protected: |
| 36 | bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; |
| 37 | bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override; |
| 38 | int compareCategories(const QModelIndex &left, const QModelIndex &right) const override; |
| 39 | |
| 40 | private: |
| 41 | QString m_query; |
| 42 | KPluginModel *m_model; |
| 43 | }; |
| 44 | |
| 45 | #endif |
| 46 | |