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 QQMLSORTERCOMPOSITOR_H
5#define QQMLSORTERCOMPOSITOR_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 <QtQmlModels/private/qqmlsorterbase_p.h>
19
20QT_BEGIN_NAMESPACE
21
22class QQmlSortFilterProxyModel;
23class QQmlSorterCompositorPrivate;
24
25class QQmlSorterCompositor: public QQmlSorterBase
26{
27 Q_OBJECT
28 QML_ANONYMOUS
29 QML_ADDED_IN_VERSION(6, 10)
30
31public:
32 explicit QQmlSorterCompositor(QObject *parent = nullptr);
33 ~QQmlSorterCompositor() override;
34
35 QList<QQmlSorterBase *> sorters();
36 QQmlListProperty<QQmlSorterBase> sortersListProperty();
37
38 static void append(QQmlListProperty<QQmlSorterBase> *sorterComp, QQmlSorterBase *sorter);
39 static qsizetype count(QQmlListProperty<QQmlSorterBase> *sorterComp);
40 static QQmlSorterBase* at(QQmlListProperty<QQmlSorterBase> *sorterComp, qsizetype index);
41 static void clear(QQmlListProperty<QQmlSorterBase> *sorterComp);
42
43 QPartialOrdering compare(const QModelIndex &, const QModelIndex &, const QQmlSortFilterProxyModel *) const override { return QPartialOrdering::Unordered; };
44 bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight, const QQmlSortFilterProxyModel *proxyModel) const;
45 void updateSorters();
46 void updateEffectiveSorters();
47
48private:
49 void append(QQmlSorterBase *sorter);
50 qsizetype count();
51 QQmlSorterBase* at(qsizetype index);
52 void clear();
53
54public slots:
55 void updateCache();
56
57private:
58 Q_DECLARE_PRIVATE(QQmlSorterCompositor)
59};
60
61class QQmlSorterCompositorPrivate: public QQmlSorterBasePrivate
62{
63 Q_DECLARE_PUBLIC(QQmlSorterCompositor)
64
65public:
66 void init();
67 void setPrimarySorter(QQmlSorterBase *sorter);
68 QPointer<QQmlSorterBase> primarySorter() const { return m_primarySorter; }
69 void resetPrimarySorter();
70
71 // Holds sorters in the same order as declared in the qml
72 QList<QQmlSorterBase *> m_sorters;
73 // Holds effective sorters that will be evaluated with the
74 // model content
75 QList<QQmlSorterBase *> m_effectiveSorters;
76 QQmlSortFilterProxyModel *m_sfpmModel = nullptr;
77 QPointer<QQmlSorterBase> m_primarySorter;
78};
79
80QT_END_NAMESPACE
81
82#endif // QQMLSORTERCOMPOSITOR_H
83

source code of qtdeclarative/src/qmlmodels/sfpm/sorters/qqmlsortercompositor_p.h