1/****************************************************************************
2**
3** Copyright (C) 2016 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 QQMLVALUETYPE_P_H
41#define QQMLVALUETYPE_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 "qqml.h"
55#include "qqmlproperty.h"
56#include "qqmlproperty_p.h"
57
58#include <private/qqmlnullablevalue_p.h>
59#include <private/qmetatype_p.h>
60
61#include <QtCore/qobject.h>
62#include <QtCore/qrect.h>
63#include <QtCore/qeasingcurve.h>
64#include <QtCore/qvariant.h>
65
66QT_BEGIN_NAMESPACE
67
68class Q_QML_PRIVATE_EXPORT QQmlValueType : public QAbstractDynamicMetaObject
69{
70public:
71 QQmlValueType() : metaType(QMetaType::UnknownType) {}
72 QQmlValueType(int userType, const QMetaObject *metaObject);
73 ~QQmlValueType();
74
75 void *create() const { return metaType.create(); }
76 void destroy(void *gadgetPtr) const { metaType.destroy(data: gadgetPtr); }
77
78 void construct(void *gadgetPtr, const void *copy) const { metaType.construct(where: gadgetPtr, copy); }
79 void destruct(void *gadgetPtr) const { metaType.destruct(data: gadgetPtr); }
80
81 int metaTypeId() const { return metaType.id(); }
82
83 // ---- dynamic meta object data interface
84 QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *) override;
85 void objectDestroyed(QObject *) override;
86 int metaCall(QObject *obj, QMetaObject::Call type, int _id, void **argv) override;
87 // ----
88
89public:
90 QMetaType metaType;
91 QMetaObject *dynamicMetaObject = nullptr;
92};
93
94class Q_QML_PRIVATE_EXPORT QQmlGadgetPtrWrapper : public QObject
95{
96 Q_OBJECT
97public:
98 static QQmlGadgetPtrWrapper *instance(QQmlEngine *engine, int index);
99
100 QQmlGadgetPtrWrapper(QQmlValueType *valueType, QObject *parent);
101 ~QQmlGadgetPtrWrapper();
102
103 void read(QObject *obj, int idx);
104 void write(QObject *obj, int idx, QQmlPropertyData::WriteFlags flags);
105 QVariant value();
106 void setValue(const QVariant &value);
107
108 int metaTypeId() const { return valueType()->metaTypeId(); }
109 int metaCall(QMetaObject::Call type, int id, void **argv);
110 QMetaProperty property(int index) { return valueType()->property(index); }
111
112private:
113 const QQmlValueType *valueType() const;
114
115 void *m_gadgetPtr = nullptr;
116};
117
118class Q_QML_PRIVATE_EXPORT QQmlValueTypeFactory
119{
120public:
121 static bool isValueType(int idx);
122 static QQmlValueType *valueType(int idx);
123 static const QMetaObject *metaObjectForMetaType(int type);
124
125 static void registerValueTypes(const char *uri, int versionMajor, int versionMinor);
126};
127
128struct QQmlPointFValueType
129{
130 QPointF v;
131 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
132 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
133 Q_GADGET
134public:
135 Q_INVOKABLE QString toString() const;
136 qreal x() const;
137 qreal y() const;
138 void setX(qreal);
139 void setY(qreal);
140};
141
142struct QQmlPointValueType
143{
144 QPoint v;
145 Q_PROPERTY(int x READ x WRITE setX FINAL)
146 Q_PROPERTY(int y READ y WRITE setY FINAL)
147 Q_GADGET
148public:
149 int x() const;
150 int y() const;
151 void setX(int);
152 void setY(int);
153};
154
155struct QQmlSizeFValueType
156{
157 QSizeF v;
158 Q_PROPERTY(qreal width READ width WRITE setWidth FINAL)
159 Q_PROPERTY(qreal height READ height WRITE setHeight FINAL)
160 Q_GADGET
161public:
162 Q_INVOKABLE QString toString() const;
163 qreal width() const;
164 qreal height() const;
165 void setWidth(qreal);
166 void setHeight(qreal);
167};
168
169struct QQmlSizeValueType
170{
171 QSize v;
172 Q_PROPERTY(int width READ width WRITE setWidth FINAL)
173 Q_PROPERTY(int height READ height WRITE setHeight FINAL)
174 Q_GADGET
175public:
176 int width() const;
177 int height() const;
178 void setWidth(int);
179 void setHeight(int);
180};
181
182struct QQmlRectFValueType
183{
184 QRectF v;
185 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
186 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
187 Q_PROPERTY(qreal width READ width WRITE setWidth FINAL)
188 Q_PROPERTY(qreal height READ height WRITE setHeight FINAL)
189 Q_PROPERTY(qreal left READ left DESIGNABLE false FINAL)
190 Q_PROPERTY(qreal right READ right DESIGNABLE false FINAL)
191 Q_PROPERTY(qreal top READ top DESIGNABLE false FINAL)
192 Q_PROPERTY(qreal bottom READ bottom DESIGNABLE false FINAL)
193 Q_GADGET
194public:
195 Q_INVOKABLE QString toString() const;
196 qreal x() const;
197 qreal y() const;
198 void setX(qreal);
199 void setY(qreal);
200
201 qreal width() const;
202 qreal height() const;
203 void setWidth(qreal);
204 void setHeight(qreal);
205
206 qreal left() const;
207 qreal right() const;
208 qreal top() const;
209 qreal bottom() const;
210};
211
212struct QQmlRectValueType
213{
214 QRect v;
215 Q_PROPERTY(int x READ x WRITE setX FINAL)
216 Q_PROPERTY(int y READ y WRITE setY FINAL)
217 Q_PROPERTY(int width READ width WRITE setWidth FINAL)
218 Q_PROPERTY(int height READ height WRITE setHeight FINAL)
219 Q_PROPERTY(int left READ left DESIGNABLE false FINAL)
220 Q_PROPERTY(int right READ right DESIGNABLE false FINAL)
221 Q_PROPERTY(int top READ top DESIGNABLE false FINAL)
222 Q_PROPERTY(int bottom READ bottom DESIGNABLE false FINAL)
223 Q_GADGET
224public:
225 int x() const;
226 int y() const;
227 void setX(int);
228 void setY(int);
229
230 int width() const;
231 int height() const;
232 void setWidth(int);
233 void setHeight(int);
234
235 int left() const;
236 int right() const;
237 int top() const;
238 int bottom() const;
239};
240
241struct QQmlEasingValueType
242{
243 QEasingCurve v;
244 Q_GADGET
245 QML_NAMED_ELEMENT(Easing)
246 QML_UNCREATABLE("Use the Type enum.")
247
248 Q_PROPERTY(QQmlEasingValueType::Type type READ type WRITE setType FINAL)
249 Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude FINAL)
250 Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot FINAL)
251 Q_PROPERTY(qreal period READ period WRITE setPeriod FINAL)
252 Q_PROPERTY(QVariantList bezierCurve READ bezierCurve WRITE setBezierCurve FINAL)
253public:
254 enum Type {
255 Linear = QEasingCurve::Linear,
256 InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad,
257 InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad,
258 InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic,
259 InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic,
260 InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart,
261 InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart,
262 InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint,
263 InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint,
264 InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine,
265 InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine,
266 InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo,
267 InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo,
268 InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc,
269 InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc,
270 InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic,
271 InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic,
272 InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack,
273 InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack,
274 InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce,
275 InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce,
276 InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve,
277 SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve,
278 Bezier = QEasingCurve::BezierSpline
279 };
280 Q_ENUM(Type)
281
282 Type type() const;
283 qreal amplitude() const;
284 qreal overshoot() const;
285 qreal period() const;
286 void setType(Type);
287 void setAmplitude(qreal);
288 void setOvershoot(qreal);
289 void setPeriod(qreal);
290 void setBezierCurve(const QVariantList &);
291 QVariantList bezierCurve() const;
292};
293
294struct QQmlPropertyValueType
295{
296 QQmlProperty v;
297 Q_PROPERTY(QObject *object READ object CONSTANT FINAL)
298 Q_PROPERTY(QString name READ name CONSTANT FINAL)
299 Q_GADGET
300public:
301 QObject *object() const;
302 QString name() const;
303};
304
305template<typename T>
306int qmlRegisterValueTypeEnums(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
307{
308 QByteArray name(T::staticMetaObject.className());
309
310 QByteArray pointerName(name + '*');
311
312 QQmlPrivate::RegisterType type = {
313 0,
314
315 qRegisterNormalizedMetaType<T *>(pointerName.constData()), 0, 0, nullptr,
316
317 QString(),
318
319 uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
320
321 nullptr, nullptr,
322
323 0, 0, 0,
324
325 nullptr, nullptr,
326
327 nullptr,
328 0
329 };
330
331 return QQmlPrivate::qmlregister(QQmlPrivate::TypeRegistration, &type);
332}
333
334QT_END_NAMESPACE
335
336#endif // QQMLVALUETYPE_P_H
337

source code of qtdeclarative/src/qml/qml/qqmlvaluetype_p.h