LeechCraft 0.6.70-18808-g3467692359
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
12namespace LC::Util
13{
15 : FixedStringFilterProxyModel { Qt::CaseInsensitive, parent }
16 {
17 }
18
19 FixedStringFilterProxyModel::FixedStringFilterProxyModel (Qt::CaseSensitivity cs, QObject *parent)
20 : QSortFilterProxyModel { parent }
21 {
22 Filter_.setCaseSensitivity (cs);
23 setRecursiveFilteringEnabled (true);
24 }
25
27 {
28 if (cs == Filter_.caseSensitivity ())
29 return;
30
31 beginFilterChange ();
32 Filter_.setCaseSensitivity (cs);
33 endFilterChange (Direction::Rows);
34 }
35
37 {
38 return Filter_.caseSensitivity ();
39 }
40
42 {
43 if (roles == Roles_)
44 return;
45
46 beginFilterChange ();
47 Roles_ = roles;
48 endFilterChange (Direction::Rows);
49 }
50
52 {
53 return Roles_;
54 }
55
57 {
58 if (columns == Columns_)
59 return;
60
61 beginFilterChange ();
62 Columns_ = columns;
63 endFilterChange (Direction::Rows);
64 }
65
67 {
68 return Columns_;
69 }
70
72 {
73 if (Filter_.pattern () == filter)
74 return;
75
76 beginFilterChange ();
77 Filter_.setPattern (filter);
78 UpdateDerivedFilter (filter);
79 endFilterChange (Direction::Rows);
80 }
81
83 {
84 return Filter_.pattern ();
85 }
86
88 {
89 return !Filter_.patternView ().isEmpty ();
90 }
91
92 bool FixedStringFilterProxyModel::IsMatch (const QString& text) const
93 {
94 return Filter_.indexIn (text) >= 0;
95 }
96
98 {
99 }
100
101 bool FixedStringFilterProxyModel::filterAcceptsRow (int row, const QModelIndex& parent) const
102 {
103 if (!IsFilterSet ())
104 return true;
105
106 const auto checkColumn = [&, this] (int col)
107 {
108 const auto& idx = sourceModel ()->index (row, col, parent);
109 return std::ranges::any_of (Roles_,
110 [this, &idx] (int role) { return IsMatch (idx.data (role).toString ()); });
111 };
112
113 return Columns_.isEmpty () ?
114 std::ranges::any_of (std::views::iota (0, sourceModel ()->columnCount (parent)), checkColumn) :
115 std::ranges::any_of (Columns_, checkColumn);
116 }
117}
bool filterAcceptsRow(int row, const QModelIndex &parent) const override