LeechCraft 0.6.70-17739-g0d7a960ef4
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 Filter_.setCaseSensitivity (cs);
29 invalidateFilter ();
30 }
31
33 {
34 return Filter_.caseSensitivity ();
35 }
36
38 {
39 Roles_ = roles;
40 invalidateFilter ();
41 }
42
44 {
45 return Roles_;
46 }
47
49 {
50 Columns_ = columns;
51 invalidateFilter ();
52 }
53
55 {
56 return Columns_;
57 }
58
60 {
61 Filter_.setPattern (filter);
62 invalidateFilter ();
63 }
64
66 {
67 return Filter_.pattern ();
68 }
69
71 {
72 return !Filter_.patternView ().isEmpty ();
73 }
74
75 bool FixedStringFilterProxyModel::IsMatch (const QString& text) const
76 {
77 return Filter_.indexIn (text) >= 0;
78 }
79
80 bool FixedStringFilterProxyModel::filterAcceptsRow (int row, const QModelIndex& parent) const
81 {
82 if (!IsFilterSet ())
83 return true;
84
85 const auto checkColumn = [&, this] (int col)
86 {
87 const auto& idx = sourceModel ()->index (row, col, parent);
88 return std::ranges::any_of (Roles_,
89 [this, &idx] (int role) { return IsMatch (idx.data (role).toString ()); });
90 };
91
92 return Columns_.isEmpty () ?
93 std::ranges::any_of (std::views::iota (0, sourceModel ()->columnCount (parent)), checkColumn) :
94 std::ranges::any_of (Columns_, checkColumn);
95 }
96}
bool filterAcceptsRow(int row, const QModelIndex &parent) const override