KCMUtils

kpluginproxymodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Alexander Lohnau <[email protected]>
3  SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5 
6 #include "kpluginproxymodel.h"
7 #include "kpluginmodel.h"
8 
9 KPluginProxyModel::KPluginProxyModel(QObject *parent)
11 {
12  sort(0);
13  setCategorizedModel(true);
14 }
15 
16 KPluginProxyModel::~KPluginProxyModel() = default;
17 
18 QString KPluginProxyModel::query() const
19 {
20  return m_query;
21 }
22 
23 void KPluginProxyModel::setQuery(const QString &query)
24 {
25  if (m_query != query) {
26  m_query = query;
27  invalidate();
28  Q_EMIT queryChanged();
29  }
30 }
31 
32 bool KPluginProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
33 {
34  if (m_query.isEmpty()) {
35  return true;
36  }
37 
38  const QModelIndex index = sourceModel()->index(sourceRow, 0);
39 
40  const QString name = index.data(KPluginModel::NameRole).toString();
41 
42  if (name.contains(m_query, Qt::CaseInsensitive)) {
43  return true;
44  }
45 
46  const QString description = index.data(KPluginModel::DescriptionRole).toString();
47 
48  if (description.contains(m_query, Qt::CaseInsensitive)) {
49  return true;
50  }
51 
52  return false;
53 }
54 
55 bool KPluginProxyModel::subSortLessThan(const QModelIndex &left, const QModelIndex &right) const
56 {
57  return left.data(KPluginModel::NameRole).toString().compare(right.data(KPluginModel::NameRole).toString(), Qt::CaseInsensitive) < 0;
58 }
QTextStream & right(QTextStream &stream)
CaseInsensitive
QTextStream & left(QTextStream &stream)
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
QVariant data(int role) const const
QString name(StandardShortcut id)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:17:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.