Changeset View
Changeset View
Standalone View
Standalone View
kcms/notifications/filterproxymodel.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "filterproxymodel.h" | ||||
22 | | ||||
23 | #include "sourcesmodel.h" | ||||
24 | | ||||
25 | FilterProxyModel::FilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent) | ||||
26 | { | ||||
27 | setRecursiveFilteringEnabled(true); | ||||
28 | } | ||||
29 | | ||||
30 | FilterProxyModel::~FilterProxyModel() = default; | ||||
31 | | ||||
32 | QString FilterProxyModel::query() const | ||||
33 | { | ||||
34 | return m_query; | ||||
35 | } | ||||
36 | | ||||
37 | void FilterProxyModel::setQuery(const QString &query) | ||||
38 | { | ||||
39 | if (m_query != query) { | ||||
40 | m_query = query; | ||||
41 | invalidateFilter(); | ||||
42 | emit queryChanged(); | ||||
43 | } | ||||
44 | } | ||||
45 | | ||||
46 | bool FilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | ||||
47 | { | ||||
48 | if (m_query.isEmpty()) { | ||||
49 | return true; | ||||
50 | } | ||||
51 | | ||||
52 | const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent); | ||||
53 | | ||||
54 | const QString display = idx.data(Qt::DisplayRole).toString(); | ||||
55 | if (display.contains(m_query, Qt::CaseInsensitive)) { | ||||
56 | return true; | ||||
57 | } | ||||
58 | | ||||
59 | return false; | ||||
60 | } |