File indexing completed on 2026-07-12 11:20:43
0001 /* 0002 SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include "kpluginproxymodel.h" 0007 #include "kpluginmodel.h" 0008 0009 KPluginProxyModel::KPluginProxyModel(QObject *parent) 0010 : KCategorizedSortFilterProxyModel(parent) 0011 { 0012 sort(0); 0013 setCategorizedModel(true); 0014 } 0015 0016 KPluginProxyModel::~KPluginProxyModel() = default; 0017 0018 QString KPluginProxyModel::query() const 0019 { 0020 return m_query; 0021 } 0022 0023 void KPluginProxyModel::setQuery(const QString &query) 0024 { 0025 if (m_query != query) { 0026 m_query = query; 0027 invalidate(); 0028 Q_EMIT queryChanged(); 0029 } 0030 } 0031 0032 bool KPluginProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const 0033 { 0034 if (m_query.isEmpty()) { 0035 return true; 0036 } 0037 0038 const QModelIndex index = sourceModel()->index(sourceRow, 0); 0039 0040 const QString name = index.data(KPluginModel::NameRole).toString(); 0041 0042 if (name.contains(m_query, Qt::CaseInsensitive)) { 0043 return true; 0044 } 0045 0046 const QString description = index.data(KPluginModel::DescriptionRole).toString(); 0047 0048 if (description.contains(m_query, Qt::CaseInsensitive)) { 0049 return true; 0050 } 0051 0052 return false; 0053 } 0054 0055 bool KPluginProxyModel::subSortLessThan(const QModelIndex &left, const QModelIndex &right) const 0056 { 0057 return left.data(KPluginModel::NameRole).toString().compare(right.data(KPluginModel::NameRole).toString(), Qt::CaseInsensitive) < 0; 0058 } 0059 0060 #include "moc_kpluginproxymodel.cpp"