Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qqmlanyoffilter.cpp
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
<
QtQmlModels
/
private
/
qqmlanyoffilter_p
.
h
>
6
#
include
<
QtQmlModels
/
private
/
qqmlsortfilterproxymodel_p
.
h
>
7
8
QT_BEGIN_NAMESPACE
9
10
/*!
11
\qmltype AnyOfFilter
12
\inherits FilterBase
13
\inqmlmodule QtQml.Models
14
\since 6.12
15
\preliminary
16
\brief Combines multiple filters using logical OR in a
17
\l SortFilterProxyModel.
18
19
AnyOfFilter groups a set of child filters and finds a matching row or column
20
for least one of child filter in the group. This is useful when you have many
21
independent conditions to include a row, without requiring all conditions to
22
be satisfied.
23
24
The following snippet shows how AnyOfFilter can be used to include
25
rows where \c status is either \c "active" or \c "pending":
26
27
\qml
28
SortFilterProxyModel {
29
sourceModel: model
30
filters: [
31
AnyOfFilter {
32
ValueFilter {
33
roleName: "status"
34
value: "active"
35
}
36
ValueFilter {
37
roleName: "status"
38
value: "pending"
39
}
40
}
41
]
42
}
43
\endqml
44
*/
45
46
/*!
47
\qmlproperty list<FilterBase> AnyOfFilter::filters
48
49
The list of child filters evaluated with logical OR. A row is accepted
50
if at least one filter in this list accepts it.
51
52
This is the default property, so filters can be declared as direct
53
children without the \c filters keyword:
54
55
\qml
56
AnyOfFilter {
57
ValueFilter { roleName: "status"; value: "active" }
58
ValueFilter { roleName: "status"; value: "pending" }
59
}
60
\endqml
61
*/
62
63
QQmlAnyOfFilter::QQmlAnyOfFilter(QObject *parent) :
64
QQmlCompositeFilterBase(
new
QQmlAnyOfFilterPrivate, parent)
65
{
66
67
}
68
69
/*!
70
\internal
71
*/
72
bool
QQmlAnyOfFilter::filterAcceptsRowInternal(
int
row,
const
QModelIndex& sourceParent,
const
QQmlSortFilterProxyModel *proxyModel)
const
73
{
74
Q_D(
const
QQmlAnyOfFilter);
75
const
auto
&filters = d->m_effectiveFilters;
76
return
std::any_of(filters.begin(), filters.end(),
77
[row, &sourceParent, proxyModel](
const
QQmlFilterBase *filter) {
78
const
bool
filterStatus = filter->filterAcceptsRowInternal(row, sourceParent, proxyModel);
79
return
filter->isInverted() != filterStatus;
80
});
81
}
82
83
bool
QQmlAnyOfFilter::filterAcceptsColumnInternal(
int
column,
const
QModelIndex& sourceParent,
const
QQmlSortFilterProxyModel *proxyModel)
const
84
{
85
Q_D(
const
QQmlAnyOfFilter);
86
const
auto
&filters = d->m_effectiveFilters;
87
return
std::any_of(filters.begin(), filters.end(),
88
[column, &sourceParent, proxyModel](
const
QQmlFilterBase *filter) {
89
if
(!filter->supportColumnFiltering())
90
return
true
;
91
const
bool
filterStatus = filter->filterAcceptsColumnInternal(column, sourceParent, proxyModel);
92
return
filter->isInverted() != filterStatus;
93
});
94
}
95
96
QT_END_NAMESPACE
97
98
#
include
"moc_qqmlanyoffilter_p.cpp"
qtdeclarative
src
qmlmodels
sfpm
filters
qqmlanyoffilter.cpp
Generated on
for Qt by
1.18.0