1// Copyright (C) 2018 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 QQMLDELEGATECOMPONENT_P_H
5#define QQMLDELEGATECOMPONENT_P_H
6
7#include "qqmlmodelsglobal_p.h"
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
21#include <QtQmlModels/private/qqmlabstractdelegatecomponent_p.h>
22#include <QtQml/qqmlcomponent.h>
23
24QT_REQUIRE_CONFIG(qml_delegate_model);
25
26QT_BEGIN_NAMESPACE
27
28class Q_LABSQMLMODELS_PRIVATE_EXPORT QQmlDelegateChoice : public QObject
29{
30 Q_OBJECT
31 Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged FINAL)
32 Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged FINAL)
33 Q_PROPERTY(int index READ row WRITE setRow NOTIFY indexChanged FINAL)
34 Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged FINAL)
35 Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL)
36 Q_CLASSINFO("DefaultProperty", "delegate")
37 QML_NAMED_ELEMENT(DelegateChoice)
38 QML_ADDED_IN_VERSION(1, 0)
39
40public:
41 QVariant roleValue() const;
42 void setRoleValue(const QVariant &roleValue);
43
44 int row() const;
45 void setRow(int r);
46
47 int column() const;
48 void setColumn(int c);
49
50 QQmlComponent *delegate() const;
51 void setDelegate(QQmlComponent *delegate);
52
53 virtual bool match(int row, int column, const QVariant &value) const;
54
55Q_SIGNALS:
56 void roleValueChanged();
57 void rowChanged();
58 void indexChanged();
59 void columnChanged();
60 void delegateChanged();
61 void changed();
62
63private:
64 QVariant m_value;
65 int m_row = -1;
66 int m_column = -1;
67 QQmlComponent *m_delegate = nullptr;
68};
69
70class Q_LABSQMLMODELS_PRIVATE_EXPORT QQmlDelegateChooser : public QQmlAbstractDelegateComponent
71{
72 Q_OBJECT
73 Q_PROPERTY(QString role READ role WRITE setRole NOTIFY roleChanged FINAL)
74 Q_PROPERTY(QQmlListProperty<QQmlDelegateChoice> choices READ choices CONSTANT FINAL)
75 Q_CLASSINFO("DefaultProperty", "choices")
76 QML_NAMED_ELEMENT(DelegateChooser)
77 QML_ADDED_IN_VERSION(1, 0)
78
79public:
80 QString role() const { return m_role; }
81 void setRole(const QString &role);
82
83 virtual QQmlListProperty<QQmlDelegateChoice> choices();
84 static void choices_append(QQmlListProperty<QQmlDelegateChoice> *, QQmlDelegateChoice *);
85 static qsizetype choices_count(QQmlListProperty<QQmlDelegateChoice> *);
86 static QQmlDelegateChoice *choices_at(QQmlListProperty<QQmlDelegateChoice> *, qsizetype);
87 static void choices_clear(QQmlListProperty<QQmlDelegateChoice> *);
88 static void choices_replace(QQmlListProperty<QQmlDelegateChoice> *, qsizetype,
89 QQmlDelegateChoice *);
90 static void choices_removeLast(QQmlListProperty<QQmlDelegateChoice> *);
91
92 QQmlComponent *delegate(QQmlAdaptorModel *adaptorModel, int row, int column = -1) const override;
93
94Q_SIGNALS:
95 void roleChanged();
96
97private:
98 QString m_role;
99 QList<QQmlDelegateChoice *> m_choices;
100};
101
102QT_END_NAMESPACE
103
104QML_DECLARE_TYPE(QQmlDelegateChoice)
105QML_DECLARE_TYPE(QQmlDelegateChooser)
106
107#endif // QQMLDELEGATECOMPONENT_P_H
108

source code of qtdeclarative/src/labs/models/qqmldelegatecomponent_p.h