LeechCraft 0.6.70-17793-g6e56308e78
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 Filter_.setCaseSensitivity (cs);
32 invalidateFilter ();
33 }
34
36 {
37 return Filter_.caseSensitivity ();
38 }
39
41 {
42 if (roles == Roles_)
43 return;
44
45 Roles_ = roles;
46 invalidateFilter ();
47 }
48
50 {
51 return Roles_;
52 }
53
55 {
56 if (columns == Columns_)
57 return;
58
59 Columns_ = columns;
60 invalidateFilter ();
61 }
62
64 {
65 return Columns_;
66 }
67
69 {
70 if (Filter_.pattern () == filter)
71 return;
72
73 Filter_.setPattern (filter);
74 invalidateFilter ();
75 }
76
78 {
79 return Filter_.pattern ();
80 }
81
83 {
84 return !Filter_.patternView ().isEmpty ();
85 }
86
87 bool FixedStringFilterProxyModel::IsMatch (const QString& text) const
88 {
89 return Filter_.indexIn (text) >= 0;
90 }
91
92 bool FixedStringFilterProxyModel::filterAcceptsRow (int row, const QModelIndex& parent) const
93 {
94 if (!IsFilterSet ())
95 return true;
96
97 const auto checkColumn = [&, this] (int col)
98 {
99 const auto& idx = sourceModel ()->index (row, col, parent);
100 return std::ranges::any_of (Roles_,
101 [this, &idx] (int role) { return IsMatch (idx.data (role).toString ()); });
102 };
103
104 return Columns_.isEmpty () ?
105 std::ranges::any_of (std::views::iota (0, sourceModel ()->columnCount (parent)), checkColumn) :
106 std::ranges::any_of (Columns_, checkColumn);
107 }
108}
bool filterAcceptsRow(int row, const QModelIndex &parent) const override