| 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 QQMLSORTERBASE_H |
| 5 | #define QQMLSORTERBASE_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 <QtQml/qqml.h> |
| 19 | #include <QtCore/QObject> |
| 20 | #include <QtCore/QAbstractItemModel> |
| 21 | #include <QtQmlModels/private/qtqmlmodelsglobal_p.h> |
| 22 | #include <QtQml/private/qqmlcustomparser_p.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QQmlSortFilterProxyModel; |
| 27 | class QQmlSorterBasePrivate; |
| 28 | |
| 29 | class Q_QMLMODELS_EXPORT QQmlSorterBase : public QObject |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL) |
| 33 | Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged FINAL) |
| 34 | Q_PROPERTY(int priority READ priority WRITE setPriority NOTIFY priorityChanged FINAL) |
| 35 | Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged FINAL) |
| 36 | QML_NAMED_ELEMENT(SorterBase) |
| 37 | QML_UNCREATABLE("" ) |
| 38 | QML_ADDED_IN_VERSION(6, 10) |
| 39 | |
| 40 | public: |
| 41 | explicit QQmlSorterBase(QQmlSorterBasePrivate *privObj, QObject *parent = nullptr); |
| 42 | virtual ~QQmlSorterBase() = default; |
| 43 | |
| 44 | bool enabled() const; |
| 45 | void setEnabled(const bool enabled); |
| 46 | |
| 47 | Qt::SortOrder sortOrder() const; |
| 48 | void setSortOrder(const Qt::SortOrder sortOrder); |
| 49 | |
| 50 | int priority() const; |
| 51 | void setPriority(const int priority); |
| 52 | |
| 53 | int column() const; |
| 54 | void setColumn(const int column); |
| 55 | |
| 56 | virtual QPartialOrdering compare(const QModelIndex&, const QModelIndex&, const QQmlSortFilterProxyModel *) const = 0; |
| 57 | virtual void update(const QQmlSortFilterProxyModel *) { /* do nothing */ } |
| 58 | |
| 59 | Q_SIGNALS: |
| 60 | void enabledChanged(); |
| 61 | void sortOrderChanged(); |
| 62 | void priorityChanged(); |
| 63 | void columnChanged(); |
| 64 | void invalidateModel(); |
| 65 | void invalidateCache(QQmlSorterBase *filter); |
| 66 | |
| 67 | public slots: |
| 68 | void invalidate(bool updateCache = true); |
| 69 | |
| 70 | private: |
| 71 | Q_DECLARE_PRIVATE(QQmlSorterBase) |
| 72 | }; |
| 73 | |
| 74 | class QQmlSorterBasePrivate: public QObjectPrivate |
| 75 | { |
| 76 | Q_DECLARE_PUBLIC(QQmlSorterBase) |
| 77 | |
| 78 | public: |
| 79 | QQmlSorterBasePrivate() = default; |
| 80 | virtual ~QQmlSorterBasePrivate() = default; |
| 81 | |
| 82 | bool m_enabled = true; |
| 83 | Qt::SortOrder m_sortOrder = Qt::AscendingOrder; |
| 84 | int m_sorterPriority = std::numeric_limits<int>::max(); |
| 85 | int m_sortColumn = 0; |
| 86 | }; |
| 87 | |
| 88 | QT_END_NAMESPACE |
| 89 | |
| 90 | #endif // QQMLSORTERBASE_H |
| 91 | |