| 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 | #ifndef QQMLFILTERBASE_H |
| 5 | #define QQMLFILTERBASE_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/QObject> |
| 19 | #include <QtCore/QAbstractItemModel> |
| 20 | #include <QtQml/private/qqmlcustomparser_p.h> |
| 21 | #include <QtQmlModels/private/qtqmlmodelsglobal_p.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | class QQmlSortFilterProxyModel; |
| 26 | class QQmlFilterBasePrivate; |
| 27 | |
| 28 | class Q_QMLMODELS_EXPORT QQmlFilterBase: public QObject |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL) |
| 32 | Q_PROPERTY(bool invert READ invert WRITE setInvert NOTIFY invertChanged FINAL) |
| 33 | Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged FINAL) |
| 34 | QML_NAMED_ELEMENT(FilterBase) |
| 35 | QML_UNCREATABLE("" ) |
| 36 | QML_ADDED_IN_VERSION(6, 10) |
| 37 | |
| 38 | public: |
| 39 | explicit QQmlFilterBase(QQmlFilterBasePrivate *privObj, QObject *parent = nullptr); |
| 40 | virtual ~QQmlFilterBase() = default; |
| 41 | |
| 42 | bool enabled() const; |
| 43 | void setEnabled(const bool bEnable); |
| 44 | |
| 45 | bool invert() const; |
| 46 | void setInvert(const bool bInvert); |
| 47 | |
| 48 | int column() const; |
| 49 | void setColumn(const int column); |
| 50 | |
| 51 | virtual bool filterAcceptsRowInternal(int, const QModelIndex&, const QQmlSortFilterProxyModel *) const { return true; } |
| 52 | virtual bool filterAcceptsColumnInternal(int, const QModelIndex&, const QQmlSortFilterProxyModel *) const { return true; } |
| 53 | virtual void update(const QQmlSortFilterProxyModel *) { /* do nothing */ }; |
| 54 | |
| 55 | Q_SIGNALS: |
| 56 | void invalidateModel(); |
| 57 | void invalidateCache(QQmlFilterBase *filter); |
| 58 | void enabledChanged(); |
| 59 | void invertChanged(); |
| 60 | void columnChanged(); |
| 61 | |
| 62 | public slots: |
| 63 | void invalidate(bool updateCache = false); |
| 64 | |
| 65 | private: |
| 66 | Q_DECLARE_PRIVATE(QQmlFilterBase) |
| 67 | }; |
| 68 | |
| 69 | class QQmlFilterBasePrivate: public QObjectPrivate |
| 70 | { |
| 71 | Q_DECLARE_PUBLIC(QQmlFilterBase) |
| 72 | |
| 73 | private: |
| 74 | bool m_enabled = true; |
| 75 | bool m_invert = false; |
| 76 | int m_filterColumn = -1; |
| 77 | }; |
| 78 | |
| 79 | QT_END_NAMESPACE |
| 80 | |
| 81 | #endif // QQMLFILTERBASE_H |
| 82 | |