1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQMLDELEGATECOMPONENT_P_H
41#define QQMLDELEGATECOMPONENT_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
55#include <QtQmlModels/private/qqmlabstractdelegatecomponent_p.h>
56#include <QtQml/qqmlcomponent.h>
57
58QT_REQUIRE_CONFIG(qml_delegate_model);
59
60QT_BEGIN_NAMESPACE
61
62class QQmlDelegateChoice : public QObject
63{
64 Q_OBJECT
65 Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
66 Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged)
67 Q_PROPERTY(int index READ row WRITE setRow NOTIFY indexChanged)
68 Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged)
69 Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
70 Q_CLASSINFO("DefaultProperty", "delegate")
71 QML_NAMED_ELEMENT(DelegateChoice)
72public:
73 QVariant roleValue() const;
74 void setRoleValue(const QVariant &roleValue);
75
76 int row() const;
77 void setRow(int r);
78
79 int column() const;
80 void setColumn(int c);
81
82 QQmlComponent *delegate() const;
83 void setDelegate(QQmlComponent *delegate);
84
85 virtual bool match(int row, int column, const QVariant &value) const;
86
87signals:
88 void roleValueChanged();
89 void rowChanged();
90 void indexChanged();
91 void columnChanged();
92 void delegateChanged();
93 void changed();
94
95private:
96 QVariant m_value;
97 int m_row = -1;
98 int m_column = -1;
99 QQmlComponent *m_delegate = nullptr;
100};
101
102class QQmlDelegateChooser : public QQmlAbstractDelegateComponent
103{
104 Q_OBJECT
105 Q_PROPERTY(QString role READ role WRITE setRole NOTIFY roleChanged)
106 Q_PROPERTY(QQmlListProperty<QQmlDelegateChoice> choices READ choices CONSTANT)
107 Q_CLASSINFO("DefaultProperty", "choices")
108 QML_NAMED_ELEMENT(DelegateChooser)
109
110public:
111 QString role() const { return m_role; }
112 void setRole(const QString &role);
113
114 virtual QQmlListProperty<QQmlDelegateChoice> choices();
115 static void choices_append(QQmlListProperty<QQmlDelegateChoice> *, QQmlDelegateChoice *);
116 static int choices_count(QQmlListProperty<QQmlDelegateChoice> *);
117 static QQmlDelegateChoice *choices_at(QQmlListProperty<QQmlDelegateChoice> *, int);
118 static void choices_clear(QQmlListProperty<QQmlDelegateChoice> *);
119 static void choices_replace(QQmlListProperty<QQmlDelegateChoice> *, int, QQmlDelegateChoice *);
120 static void choices_removeLast(QQmlListProperty<QQmlDelegateChoice> *);
121
122 QQmlComponent *delegate(QQmlAdaptorModel *adaptorModel, int row, int column = -1) const override;
123
124signals:
125 void roleChanged();
126
127private:
128 QString m_role;
129 QList<QQmlDelegateChoice *> m_choices;
130};
131
132QT_END_NAMESPACE
133
134QML_DECLARE_TYPE(QQmlDelegateChoice)
135QML_DECLARE_TYPE(QQmlDelegateChooser)
136
137#endif // QQMLDELEGATECOMPONENT_P_H
138

source code of qtdeclarative/src/imports/labsmodels/qqmldelegatecomponent_p.h