| 1 | // Copyright (C) 2025 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 | |
| 4 | #include <QtQmlModels/private/qqmlsortfilterproxymodel_p.h> |
| 5 | #include <QtQmlModels/private/qqmlfilterbase_p.h> |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | /*! |
| 10 | \qmltype Filter |
| 11 | \inherits QtObject |
| 12 | \inqmlmodule QtQml.Models |
| 13 | \since 6.10 |
| 14 | \preliminary |
| 15 | \brief Abstract base type providing functionality common to filters. |
| 16 | |
| 17 | Filter provides a set of common properties for all the filters that they |
| 18 | inherit from. |
| 19 | */ |
| 20 | |
| 21 | QQmlFilterBase::QQmlFilterBase(QQmlFilterBasePrivate *privObj, QObject *parent) |
| 22 | : QObject (*privObj, parent) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | /*! |
| 27 | \qmlproperty bool Filter::enabled |
| 28 | |
| 29 | This property enables the \l SortFilterProxyModel to consider this filter |
| 30 | while filtering the model data. |
| 31 | |
| 32 | The default value is \c true. |
| 33 | */ |
| 34 | bool QQmlFilterBase::enabled() const |
| 35 | { |
| 36 | Q_D(const QQmlFilterBase); |
| 37 | return d->m_enabled; |
| 38 | } |
| 39 | |
| 40 | void QQmlFilterBase::setEnabled(const bool enabled) |
| 41 | { |
| 42 | Q_D(QQmlFilterBase); |
| 43 | if (d->m_enabled == enabled) |
| 44 | return; |
| 45 | d->m_enabled = enabled; |
| 46 | invalidate(updateCache: true); |
| 47 | emit enabledChanged(); |
| 48 | } |
| 49 | |
| 50 | /*! |
| 51 | \qmlproperty bool Filter::invert |
| 52 | |
| 53 | This property inverts the filter, causing the data that would normally be |
| 54 | filtered out to be presented instead. |
| 55 | |
| 56 | The default value is \c false. |
| 57 | */ |
| 58 | bool QQmlFilterBase::invert() const |
| 59 | { |
| 60 | Q_D(const QQmlFilterBase); |
| 61 | return d->m_invert; |
| 62 | } |
| 63 | |
| 64 | void QQmlFilterBase::setInvert(const bool invert) |
| 65 | { |
| 66 | Q_D(QQmlFilterBase); |
| 67 | if (d->m_invert == invert) |
| 68 | return; |
| 69 | d->m_invert = invert; |
| 70 | invalidate(); |
| 71 | emit invertChanged(); |
| 72 | } |
| 73 | |
| 74 | /*! |
| 75 | \qmlproperty int Filter::column |
| 76 | |
| 77 | This property specifies which column in the model the filter should be |
| 78 | applied on. If the value is \c -1, the filter will be applied to all |
| 79 | the columns in the model. |
| 80 | |
| 81 | The default value is \c -1. |
| 82 | */ |
| 83 | int QQmlFilterBase::column() const |
| 84 | { |
| 85 | Q_D(const QQmlFilterBase); |
| 86 | return d->m_filterColumn; |
| 87 | } |
| 88 | |
| 89 | void QQmlFilterBase::setColumn(const int column) |
| 90 | { |
| 91 | Q_D(QQmlFilterBase); |
| 92 | if (d->m_filterColumn == column) |
| 93 | return; |
| 94 | d->m_filterColumn = column; |
| 95 | invalidate(); |
| 96 | emit columnChanged(); |
| 97 | } |
| 98 | |
| 99 | /*! |
| 100 | \internal |
| 101 | */ |
| 102 | void QQmlFilterBase::invalidate(bool updateCache) |
| 103 | { |
| 104 | // Update the cached filters and invalidate the model |
| 105 | if (updateCache) |
| 106 | emit invalidateCache(filter: this); |
| 107 | emit invalidateModel(); |
| 108 | } |
| 109 | |
| 110 | QT_END_NAMESPACE |
| 111 | |
| 112 | #include "moc_qqmlfilterbase_p.cpp" |
| 113 | |