Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlvaluetype_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QQMLVALUETYPE_P_H
5#define QQMLVALUETYPE_P_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/private/qqmlproperty_p.h>
19
20#include <private/qqmlnullablevalue_p.h>
21#include <private/qmetatype_p.h>
22
23#include <QtCore/qobject.h>
24#include <QtCore/qrect.h>
25#if QT_CONFIG(easingcurve)
26#include <QtCore/qeasingcurve.h>
27#endif
28#include <QtCore/qvariant.h>
29
31
32class Q_QML_EXPORT QQmlValueType : public QDynamicMetaObjectData
33{
34public:
35 QQmlValueType() = default;
36 QQmlValueType(QMetaType type, const QMetaObject *staticMetaObject)
37 : m_metaType(type), m_staticMetaObject(staticMetaObject)
38 {}
39 ~QQmlValueType();
40
41 void *create() const { return m_metaType.create(); }
42 void destroy(void *gadgetPtr) const { m_metaType.destroy(gadgetPtr); }
43
44 void construct(void *gadgetPtr, const void *copy) const { m_metaType.construct(gadgetPtr, copy); }
45 void destruct(void *gadgetPtr) const { m_metaType.destruct(gadgetPtr); }
46
47 QMetaType metaType() const { return m_metaType; }
48 const QMetaObject *staticMetaObject() const { return m_staticMetaObject; }
49
50 // ---- dynamic meta object data interface
51#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
52 const QMetaObject *toDynamicMetaObject(QObject *) const override;
53#else
54 QMetaObject *toDynamicMetaObject(QObject *) override;
55#endif
56 void objectDestroyed(QObject *) override;
57 int metaCall(QObject *obj, QMetaObject::Call type, int _id, void **argv) override;
58 // ----
59
60private:
61 QMetaType m_metaType;
62 const QMetaObject *m_staticMetaObject = nullptr;
63 QT7_ONLY(mutable const)
64 QMetaObject *m_dynamicMetaObject = nullptr;
65};
66
67class Q_QML_EXPORT QQmlGadgetPtrWrapper : public QObject
68{
69 Q_OBJECT
70public:
71 static QQmlGadgetPtrWrapper *instance(QQmlEngine *engine, QMetaType type);
72
73 QQmlGadgetPtrWrapper(QQmlValueType *valueType, QObject *parent = nullptr);
74 ~QQmlGadgetPtrWrapper();
75
76 void read(QObject *obj, int idx);
77 void write(QObject *obj, int idx, QQmlPropertyData::WriteFlags flags, int internalIndex) const;
78 QVariant value() const;
79 void setValue(const QVariant &value);
80
81 QMetaType metaType() const { return valueType()->metaType(); }
82 int metaCall(QMetaObject::Call type, int id, void **argv);
83
84 QMetaProperty property(int index) const
85 {
86 return valueType()->staticMetaObject()->property(index);
87 }
88
89 QVariant readOnGadget(const QMetaProperty &property) const
90 {
91 return property.readOnGadget(m_gadgetPtr);
92 }
93
94 void writeOnGadget(const QMetaProperty &property, const QVariant &value)
95 {
96 property.writeOnGadget(m_gadgetPtr, value);
97 }
98
99 void writeOnGadget(const QMetaProperty &property, QVariant &&value)
100 {
101 property.writeOnGadget(m_gadgetPtr, std::move(value));
102 }
103
104private:
105 const QQmlValueType *valueType() const;
106 void *m_gadgetPtr = nullptr;
107};
108
109struct Q_QML_EXPORT QQmlPointFValueType : private QPointF
110{
111 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
112 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
113 Q_GADGET
114 QML_VALUE_TYPE(point)
115 QML_FOREIGN(QPointF)
116 QML_EXTENDED(QQmlPointFValueType)
117 QML_STRUCTURED_VALUE
118
119public:
120 Q_INVOKABLE QQmlPointFValueType() = default;
121 Q_INVOKABLE QQmlPointFValueType(const QPointF &point) : QPointF(point) {}
122 Q_INVOKABLE QQmlPointFValueType(const QPoint &point) : QPointF(point) {}
123 Q_INVOKABLE QString toString() const;
124 qreal x() const;
125 qreal y() const;
126 void setX(qreal);
127 void setY(qreal);
128};
129
130struct Q_QML_EXPORT QQmlPointValueType : private QPoint
131{
132 Q_PROPERTY(int x READ x WRITE setX FINAL)
133 Q_PROPERTY(int y READ y WRITE setY FINAL)
134 Q_GADGET
135 QML_ANONYMOUS
136 QML_FOREIGN(QPoint)
137 QML_EXTENDED(QQmlPointValueType)
138 QML_STRUCTURED_VALUE
139
140public:
141 QQmlPointValueType() = default;
142 Q_INVOKABLE QQmlPointValueType(const QPoint &point) : QPoint(point) {}
143 Q_INVOKABLE QQmlPointValueType(const QPointF &point) : QPoint(point.toPoint()) {}
144 Q_INVOKABLE QString toString() const;
145 int x() const;
146 int y() const;
147 void setX(int);
148 void setY(int);
149};
150
151struct Q_QML_EXPORT QQmlSizeFValueType : private QSizeF
152{
153 Q_PROPERTY(qreal width READ width WRITE setWidth FINAL)
154 Q_PROPERTY(qreal height READ height WRITE setHeight FINAL)
155 Q_GADGET
156 QML_VALUE_TYPE(size)
157 QML_FOREIGN(QSizeF)
158 QML_EXTENDED(QQmlSizeFValueType)
159 QML_STRUCTURED_VALUE
160
161public:
162 Q_INVOKABLE QQmlSizeFValueType() = default;
163 Q_INVOKABLE QQmlSizeFValueType(const QSizeF &size) : QSizeF(size) {}
164 Q_INVOKABLE QQmlSizeFValueType(const QSize &size) : QSizeF(size) {}
165 Q_INVOKABLE QString toString() const;
166 qreal width() const;
167 qreal height() const;
168 void setWidth(qreal);
169 void setHeight(qreal);
170};
171
172struct Q_QML_EXPORT QQmlSizeValueType : private QSize
173{
174 Q_PROPERTY(int width READ width WRITE setWidth FINAL)
175 Q_PROPERTY(int height READ height WRITE setHeight FINAL)
176 Q_GADGET
177 QML_ANONYMOUS
178 QML_FOREIGN(QSize)
179 QML_EXTENDED(QQmlSizeValueType)
180 QML_STRUCTURED_VALUE
181
182public:
183 QQmlSizeValueType() = default;
184 Q_INVOKABLE QQmlSizeValueType(const QSize &size) : QSize(size) {}
185 Q_INVOKABLE QQmlSizeValueType(const QSizeF &size) : QSize(size.toSize()) {}
186 Q_INVOKABLE QString toString() const;
187 int width() const;
188 int height() const;
189 void setWidth(int);
190 void setHeight(int);
191};
192
193struct Q_QML_EXPORT QQmlRectFValueType : private QRectF
194{
195 Q_PROPERTY(qreal x READ x WRITE setX FINAL)
196 Q_PROPERTY(qreal y READ y WRITE setY FINAL)
197 Q_PROPERTY(qreal width READ width WRITE setWidth FINAL)
198 Q_PROPERTY(qreal height READ height WRITE setHeight FINAL)
199 Q_PROPERTY(qreal left READ left DESIGNABLE false FINAL)
200 Q_PROPERTY(qreal right READ right DESIGNABLE false FINAL)
201 Q_PROPERTY(qreal top READ top DESIGNABLE false FINAL)
202 Q_PROPERTY(qreal bottom READ bottom DESIGNABLE false FINAL)
203 Q_GADGET
204 QML_VALUE_TYPE(rect)
205 QML_FOREIGN(QRectF)
206 QML_EXTENDED(QQmlRectFValueType)
207 QML_STRUCTURED_VALUE
208
209public:
210 Q_INVOKABLE QQmlRectFValueType() = default;
211 Q_INVOKABLE QQmlRectFValueType(const QRectF &rect) : QRectF(rect) {}
212 Q_INVOKABLE QQmlRectFValueType(const QRect &rect) : QRectF(rect) {}
213 Q_INVOKABLE QString toString() const;
214 qreal x() const;
215 qreal y() const;
216 void setX(qreal);
217 void setY(qreal);
218
219 qreal width() const;
220 qreal height() const;
221 void setWidth(qreal);
222 void setHeight(qreal);
223
224 qreal left() const;
225 qreal right() const;
226 qreal top() const;
227 qreal bottom() const;
228};
229
230struct Q_QML_EXPORT QQmlRectValueType : private QRect
231{
232 Q_PROPERTY(int x READ x WRITE setX FINAL)
233 Q_PROPERTY(int y READ y WRITE setY FINAL)
234 Q_PROPERTY(int width READ width WRITE setWidth FINAL)
235 Q_PROPERTY(int height READ height WRITE setHeight FINAL)
236 Q_PROPERTY(int left READ left DESIGNABLE false FINAL)
237 Q_PROPERTY(int right READ right DESIGNABLE false FINAL)
238 Q_PROPERTY(int top READ top DESIGNABLE false FINAL)
239 Q_PROPERTY(int bottom READ bottom DESIGNABLE false FINAL)
240 Q_GADGET
241 QML_ANONYMOUS
242 QML_FOREIGN(QRect)
243 QML_EXTENDED(QQmlRectValueType)
244 QML_STRUCTURED_VALUE
245
246public:
247 QQmlRectValueType() = default;
248 Q_INVOKABLE QQmlRectValueType(const QRect &rect) : QRect(rect) {}
249 Q_INVOKABLE QQmlRectValueType(const QRectF &rect) : QRect(rect.toRect()) {}
250 Q_INVOKABLE QString toString() const;
251 int x() const;
252 int y() const;
253 void setX(int);
254 void setY(int);
255
256 int width() const;
257 int height() const;
258 void setWidth(int);
259 void setHeight(int);
260
261 int left() const;
262 int right() const;
263 int top() const;
264 int bottom() const;
265};
266
267struct Q_QML_EXPORT QQmlMarginsFValueType : private QMarginsF
268{
269 Q_PROPERTY(qreal left READ left WRITE setLeft FINAL)
270 Q_PROPERTY(qreal right READ right WRITE setRight FINAL)
271 Q_PROPERTY(qreal top READ top WRITE setTop FINAL)
272 Q_PROPERTY(qreal bottom READ bottom WRITE setBottom FINAL)
273 Q_GADGET
274 QML_ANONYMOUS
275 QML_FOREIGN(QMarginsF)
276 QML_EXTENDED(QQmlMarginsFValueType)
277 QML_STRUCTURED_VALUE
278
279public:
280 QQmlMarginsFValueType() = default;
281 Q_INVOKABLE QQmlMarginsFValueType(const QMarginsF &margins) : QMarginsF(margins) {}
282 Q_INVOKABLE QQmlMarginsFValueType(const QMargins &margins) : QMarginsF(margins) {}
283 Q_INVOKABLE QString toString() const;
284 qreal left() const;
285 qreal right() const;
286 qreal top() const;
287 qreal bottom() const;
288 void setLeft(qreal);
289 void setRight(qreal);
290 void setTop(qreal);
291 void setBottom(qreal);
292};
293
294struct Q_QML_EXPORT QQmlMarginsValueType : private QMargins
295{
296 Q_PROPERTY(int left READ left WRITE setLeft FINAL)
297 Q_PROPERTY(int right READ right WRITE setRight FINAL)
298 Q_PROPERTY(int top READ top WRITE setTop FINAL)
299 Q_PROPERTY(int bottom READ bottom WRITE setBottom FINAL)
300 Q_GADGET
301 QML_ANONYMOUS
302 QML_FOREIGN(QMargins)
303 QML_EXTENDED(QQmlMarginsValueType)
304 QML_STRUCTURED_VALUE
305
306public:
307 QQmlMarginsValueType() = default;
308 Q_INVOKABLE QQmlMarginsValueType(const QMargins &margins) : QMargins(margins) {}
309 Q_INVOKABLE QQmlMarginsValueType(const QMarginsF &margins) : QMargins(margins.toMargins()) {}
310 Q_INVOKABLE QString toString() const;
311 int left() const;
312 int right() const;
313 int top() const;
314 int bottom() const;
315 void setLeft(int);
316 void setRight(int);
317 void setTop(int);
318 void setBottom(int);
319};
320
321#if QT_CONFIG(easingcurve)
322// Easing type that provides enums and convenience valueForProgress function.
323class Q_QML_EXPORT QQmlEasing : public QObject
324{
325 Q_OBJECT
326 QML_NAMED_ELEMENT(Easing)
327 QML_SINGLETON
328
329public:
330 enum Type {
331 Linear = QEasingCurve::Linear,
332 InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad,
333 InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad,
334 InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic,
335 InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic,
336 InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart,
337 InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart,
338 InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint,
339 InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint,
340 InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine,
341 InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine,
342 InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo,
343 InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo,
344 InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc,
345 InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc,
346 InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic,
347 InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic,
348 InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack,
349 InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack,
350 InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce,
351 InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce,
352 InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve,
353 SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve,
354 BezierSpline = QEasingCurve::BezierSpline,
355
356 Bezier = BezierSpline // Evil! Don't use this!
357 };
358 Q_ENUM(Type)
359
360 Q_INVOKABLE qreal valueForProgress(QQmlEasing::Type type, qreal progress) const;
361};
362
363struct Q_QML_EXPORT QQmlEasingValueType : private QEasingCurve
364{
365 Q_GADGET
366 QML_VALUE_TYPE(easingCurve)
367 QML_FOREIGN(QEasingCurve)
368 QML_EXTENDED(QQmlEasingValueType)
369 QML_STRUCTURED_VALUE
370
371 Q_PROPERTY(QQmlEasing::Type type READ type WRITE setType FINAL)
372 Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude FINAL)
373 Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot FINAL)
374 Q_PROPERTY(qreal period READ period WRITE setPeriod FINAL)
375 Q_PROPERTY(QList<qreal> bezierCurve READ bezierCurve WRITE setBezierCurve FINAL)
376
377public:
378 Q_INVOKABLE QQmlEasingValueType() = default;
379 Q_INVOKABLE QQmlEasingValueType(QQmlEasing::Type type);
380 Q_INVOKABLE QQmlEasingValueType(const QEasingCurve &easing) : QEasingCurve(easing) {}
381
382 Q_INVOKABLE qreal valueForProgress(qreal progress);
383
384 QQmlEasing::Type type() const;
385 qreal amplitude() const;
386 qreal overshoot() const;
387 qreal period() const;
388 void setType(QQmlEasing::Type);
389 void setAmplitude(qreal);
390 void setOvershoot(qreal);
391 void setPeriod(qreal);
392 void setBezierCurve(const QList<qreal> &);
393 QList<qreal> bezierCurve() const;
394};
395#endif
396
404
405QT_END_NAMESPACE
406
407#endif // QQMLVALUETYPE_P_H