LeechCraft 0.6.70-19424-g027e980fd1
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
fixedstringfilterproxymodel.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
10#include <ranges>
11#include <QtDebug>
12
13namespace LC::Util
14{
15 namespace
16 {
17 void ReportIgnoredQtFilter (const QObject *model, const char *qtFilter, const char *replacement)
18 {
19 qCritical ().nospace () << model << ": FixedStringFilterProxyModel ignores QSortFilterProxyModel's "
20 << qtFilter << ", use " << replacement << " instead";
21 }
22 }
23
25 : FixedStringFilterProxyModel { Qt::CaseInsensitive, parent }
26 {
27 }
28
29 FixedStringFilterProxyModel::FixedStringFilterProxyModel (Qt::CaseSensitivity cs, QObject *parent)
30 : QSortFilterProxyModel { parent }
31 {
32 Filter_.setCaseSensitivity (cs);
33 setRecursiveFilteringEnabled (true);
34
35 FilterRegexGuard_ = bindableFilterRegularExpression ().addNotifier ([this]
36 {
37 ReportIgnoredQtFilter (this,
38 "filter regular expression and case sensitivity",
39 "SetFilterString () and SetCaseSensitivity ()");
40 });
41 FilterKeyColumnGuard_ = bindableFilterKeyColumn ().addNotifier ([this]
42 { ReportIgnoredQtFilter (this, "filter key column", "SetFilterColumns ()"); });
43 connect (this,
44 &QSortFilterProxyModel::filterRoleChanged,
45 this,
46 [this] { ReportIgnoredQtFilter (this, "filter role", "SetFilterRoles ()"); });
47 }
48
50 {
51 if (cs == Filter_.caseSensitivity ())
52 return;
53
54 beginFilterChange ();
55 Filter_.setCaseSensitivity (cs);
56 endFilterChange (Direction::Rows);
57 }
58
60 {
61 return Filter_.caseSensitivity ();
62 }
63
65 {
66 if (roles == Roles_)
67 return;
68
69 beginFilterChange ();
70 Roles_ = roles;
71 endFilterChange (Direction::Rows);
72 }
73
75 {
76 return Roles_;
77 }
78
80 {
81 if (columns == Columns_)
82 return;
83
84 beginFilterChange ();
85 Columns_ = columns;
86 endFilterChange (Direction::Rows);
87 }
88
90 {
91 return Columns_;
92 }
93
95 {
96 if (Filter_.pattern () == filter)
97 return;
98
99 beginFilterChange ();
100 Filter_.setPattern (filter);
101 UpdateDerivedFilter (filter);
102 endFilterChange (Direction::Rows);
103 }
104
106 {
107 return Filter_.pattern ();
108 }
109
111 {
112 return !Filter_.patternView ().isEmpty ();
113 }
114
115 bool FixedStringFilterProxyModel::IsMatch (const QString& text) const
116 {
117 return Filter_.indexIn (text) >= 0;
118 }
119
121 {
122 }
123
124 bool FixedStringFilterProxyModel::filterAcceptsRow (int row, const QModelIndex& parent) const
125 {
126 if (!IsFilterSet ())
127 return true;
128
129 const auto checkColumn = [&, this] (int col)
130 {
131 const auto& idx = sourceModel ()->index (row, col, parent);
132 return std::ranges::any_of (Roles_,
133 [this, &idx] (int role) { return IsMatch (idx.data (role).toString ()); });
134 };
135
136 return Columns_.isEmpty () ?
137 std::ranges::any_of (std::views::iota (0, sourceModel ()->columnCount (parent)), checkColumn) :
138 std::ranges::any_of (Columns_, checkColumn);
139 }
140}
bool filterAcceptsRow(int row, const QModelIndex &parent) const override