Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwineffects/effectsfilterproxymodel.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | */ | ||||
17 | | ||||
18 | #include "effectsfilterproxymodel.h" | ||||
19 | | ||||
20 | #include "effectmodel.h" | ||||
21 | | ||||
22 | namespace KWin | ||||
23 | { | ||||
24 | | ||||
25 | EffectsFilterProxyModel::EffectsFilterProxyModel(QObject *parent) | ||||
26 | : QSortFilterProxyModel(parent) | ||||
27 | { | ||||
28 | } | ||||
29 | | ||||
30 | EffectsFilterProxyModel::~EffectsFilterProxyModel() | ||||
31 | { | ||||
32 | } | ||||
33 | | ||||
34 | QString EffectsFilterProxyModel::query() const | ||||
35 | { | ||||
36 | return m_query; | ||||
37 | } | ||||
38 | | ||||
39 | void EffectsFilterProxyModel::setQuery(const QString &query) | ||||
40 | { | ||||
41 | if (m_query != query) { | ||||
42 | m_query = query; | ||||
43 | emit queryChanged(); | ||||
44 | invalidateFilter(); | ||||
45 | } | ||||
46 | } | ||||
47 | | ||||
48 | bool EffectsFilterProxyModel::excludeInternal() const | ||||
49 | { | ||||
50 | return m_excludeInternal; | ||||
51 | } | ||||
52 | | ||||
53 | void EffectsFilterProxyModel::setExcludeInternal(bool exclude) | ||||
54 | { | ||||
55 | if (m_excludeInternal != exclude) { | ||||
56 | m_excludeInternal = exclude; | ||||
57 | emit excludeInternalChanged(); | ||||
58 | invalidateFilter(); | ||||
59 | } | ||||
60 | } | ||||
61 | | ||||
62 | bool EffectsFilterProxyModel::excludeUnsupported() const | ||||
63 | { | ||||
64 | return m_excludeUnsupported; | ||||
65 | } | ||||
66 | | ||||
67 | void EffectsFilterProxyModel::setExcludeUnsupported(bool exclude) | ||||
68 | { | ||||
69 | if (m_excludeUnsupported != exclude) { | ||||
70 | m_excludeUnsupported = exclude; | ||||
71 | emit excludeUnsupportedChanged(); | ||||
72 | invalidateFilter(); | ||||
73 | } | ||||
74 | } | ||||
75 | | ||||
76 | bool EffectsFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const | ||||
77 | { | ||||
78 | const QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent); | ||||
79 | | ||||
80 | if (!m_query.isEmpty()) { | ||||
81 | const bool matches = idx.data(EffectModel::NameRole).toString().contains(m_query, Qt::CaseInsensitive) || | ||||
82 | idx.data(EffectModel::DescriptionRole).toString().contains(m_query, Qt::CaseInsensitive) || | ||||
83 | idx.data(EffectModel::CategoryRole).toString().contains(m_query, Qt::CaseInsensitive); | ||||
84 | if (!matches) { | ||||
85 | return false; | ||||
86 | } | ||||
87 | } | ||||
88 | | ||||
89 | if (m_excludeInternal) { | ||||
90 | if (idx.data(EffectModel::InternalRole).toBool()) { | ||||
91 | return false; | ||||
92 | } | ||||
93 | } | ||||
94 | | ||||
95 | if (m_excludeUnsupported) { | ||||
96 | if (!idx.data(EffectModel::SupportedRole).toBool()) { | ||||
97 | return false; | ||||
98 | } | ||||
99 | } | ||||
100 | | ||||
101 | return true; | ||||
102 | } | ||||
103 | | ||||
104 | } // namespace KWin |