File indexing completed on 2024-06-02 03:55:02

0001 /*
0002     SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef KPLUGINPROXYMODEL_H
0007 #define KPLUGINPROXYMODEL_H
0008 
0009 #include "kcmutilscore_export.h"
0010 #include "kpluginmodel.h"
0011 
0012 #include <KCategorizedSortFilterProxyModel>
0013 
0014 class Q_DECL_HIDDEN KPluginProxyModel : public KCategorizedSortFilterProxyModel
0015 {
0016     Q_OBJECT
0017     Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged)
0018     Q_PROPERTY(QAbstractListModel *model WRITE setModel)
0019 public:
0020     explicit KPluginProxyModel(QObject *parent = nullptr);
0021     ~KPluginProxyModel() override;
0022 
0023     QString query() const;
0024     void setQuery(const QString &query);
0025     void setModel(QAbstractListModel *model)
0026     {
0027         setSourceModel(model);
0028         m_model = qobject_cast<KPluginModel *>(model);
0029         Q_ASSERT(m_model);
0030     }
0031 
0032 Q_SIGNALS:
0033     void queryChanged();
0034 
0035 protected:
0036     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
0037     bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override;
0038     int compareCategories(const QModelIndex &left, const QModelIndex &right) const override;
0039 
0040 private:
0041     QString m_query;
0042     KPluginModel *m_model;
0043 };
0044 
0045 #endif