Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlvaluetype.cpp
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#include "qqmlvaluetype_p.h"
5
6#include <QtCore/qmutex.h>
7#include <private/qqmlglobal_p.h>
8#include <QtCore/qdebug.h>
9#include <private/qqmlengine_p.h>
10#include <private/qmetaobjectbuilder_p.h>
11
13
15{
16 ::free(m_dynamicMetaObject);
17}
18
23
25 : QObject(parent), m_gadgetPtr(valueType->create())
26{
28 Q_ASSERT(!d->metaObject);
29 d->metaObject = valueType;
30}
31
33{
35 static_cast<const QQmlValueType *>(d->metaObject)->destroy(m_gadgetPtr);
36 d->metaObject = nullptr;
37}
38
40{
41 Q_ASSERT(m_gadgetPtr);
42 void *a[] = { m_gadgetPtr, nullptr };
44}
45
47 QObject *obj, int idx, QQmlPropertyData::WriteFlags flags, int internalIndex) const
48{
49 Q_ASSERT(m_gadgetPtr);
50 int status = -1;
51 void *a[] = { m_gadgetPtr, nullptr, &status, &flags, &internalIndex };
53}
54
56{
57 Q_ASSERT(m_gadgetPtr);
58
59 const QMetaType m = metaType();
60 return m == QMetaType::fromType<QVariant>()
61 ? *static_cast<const QVariant *>(m_gadgetPtr)
62 : QVariant(m, m_gadgetPtr);
63}
64
66{
67 Q_ASSERT(m_gadgetPtr);
68
69 const QMetaType m = metaType();
70 m.destruct(m_gadgetPtr);
71 if (m == QMetaType::fromType<QVariant>()) {
72 m.construct(m_gadgetPtr, &value);
73 } else {
74 Q_ASSERT(m == value.metaType());
75 m.construct(m_gadgetPtr, value.constData());
76 }
77}
78
80{
81 Q_ASSERT(m_gadgetPtr);
82 const QMetaObject *metaObject = valueType()->staticMetaObject();
84 metaObject->d.static_metacall(static_cast<QObject *>(m_gadgetPtr), type, id, argv);
85 return id;
86}
87
88const QQmlValueType *QQmlGadgetPtrWrapper::valueType() const
89{
91 return static_cast<const QQmlValueType *>(d->metaObject);
92}
93
95{
96 if (!m_dynamicMetaObject) {
97 QMetaObjectBuilder builder(m_staticMetaObject);
98
99 // Do not set PropertyAccessInStaticMetaCall here. QQmlGadgetPtrWrapper likes to
100 // to intercept the metacalls since it needs to use its gadgetPtr.
101 // For QQmlValueType::metaObject() we use the base type that has the flag.
102
103 m_dynamicMetaObject = builder.toMetaObject();
104 }
105 return m_dynamicMetaObject;
106}
107
111
112int QQmlValueType::metaCall(QObject *object, QMetaObject::Call type, int _id, void **argv)
113{
114 return static_cast<QQmlGadgetPtrWrapper *>(object)->metaCall(type, _id, argv);
115}
116
118{
119 return QString::asprintf("QPointF(%g, %g)", v.x(), v.y());
120}
121
123{
124 return v.x();
125}
126
128{
129 return v.y();
130}
131
133{
134 v.setX(x);
135}
136
138{
139 v.setY(y);
140}
141
142
144{
145 return QString::asprintf("QPoint(%d, %d)", v.x(), v.y());
146}
147
149{
150 return v.x();
151}
152
154{
155 return v.y();
156}
157
159{
160 v.setX(x);
161}
162
164{
165 v.setY(y);
166}
167
168
170{
171 return QString::asprintf("QSizeF(%g, %g)", v.width(), v.height());
172}
173
175{
176 return v.width();
177}
178
180{
181 return v.height();
182}
183
185{
186 v.setWidth(w);
187}
188
190{
191 v.setHeight(h);
192}
193
194
196{
197 return QString::asprintf("QSize(%d, %d)", v.width(), v.height());
198}
199
201{
202 return v.width();
203}
204
206{
207 return v.height();
208}
209
211{
212 v.setWidth(w);
213}
214
216{
217 v.setHeight(h);
218}
219
221{
222 return QString::asprintf("QRectF(%g, %g, %g, %g)", v.x(), v.y(), v.width(), v.height());
223}
224
226{
227 return v.x();
228}
229
231{
232 return v.y();
233}
234
236{
237 v.moveLeft(x);
238}
239
241{
242 v.moveTop(y);
243}
244
246{
247 return v.width();
248}
249
251{
252 return v.height();
253}
254
256{
257 v.setWidth(w);
258}
259
261{
262 v.setHeight(h);
263}
264
266{
267 return v.left();
268}
269
271{
272 return v.right();
273}
274
276{
277 return v.top();
278}
279
281{
282 return v.bottom();
283}
284
285
287{
288 return QString::asprintf("QRect(%d, %d, %d, %d)", v.x(), v.y(), v.width(), v.height());
289}
290
292{
293 return v.x();
294}
295
297{
298 return v.y();
299}
300
302{
303 v.moveLeft(x);
304}
305
307{
308 v.moveTop(y);
309}
310
312{
313 return v.width();
314}
315
317{
318 return v.height();
319}
320
322{
323 v.setWidth(w);
324}
325
327{
328 v.setHeight(h);
329}
330
332{
333 return v.left();
334}
335
337{
338 return v.right();
339}
340
342{
343 return v.top();
344}
345
347{
348 return v.bottom();
349}
350
351#if QT_CONFIG(easingcurve)
352QQmlEasingEnums::Type QQmlEasingValueType::type() const
353{
354 return (QQmlEasingEnums::Type)v.type();
355}
356
357qreal QQmlEasingValueType::amplitude() const
358{
359 return v.amplitude();
360}
361
362qreal QQmlEasingValueType::overshoot() const
363{
364 return v.overshoot();
365}
366
367qreal QQmlEasingValueType::period() const
368{
369 return v.period();
370}
371
372void QQmlEasingValueType::setType(QQmlEasingEnums::Type type)
373{
374 v.setType((QEasingCurve::Type)type);
375}
376
377void QQmlEasingValueType::setAmplitude(qreal amplitude)
378{
379 v.setAmplitude(amplitude);
380}
381
382void QQmlEasingValueType::setOvershoot(qreal overshoot)
383{
384 v.setOvershoot(overshoot);
385}
386
387void QQmlEasingValueType::setPeriod(qreal period)
388{
389 v.setPeriod(period);
390}
391
392void QQmlEasingValueType::setBezierCurve(const QVariantList &customCurveVariant)
393{
394 if (customCurveVariant.isEmpty())
395 return;
396
397 if ((customCurveVariant.size() % 6) != 0)
398 return;
399
400 auto convert = [](const QVariant &v, qreal &r) {
401 bool ok;
402 r = v.toReal(&ok);
403 return ok;
404 };
405
407 for (int i = 0, ei = customCurveVariant.size(); i < ei; i += 6) {
408 qreal c1x, c1y, c2x, c2y, c3x, c3y;
409 if (!convert(customCurveVariant.at(i ), c1x)) return;
410 if (!convert(customCurveVariant.at(i + 1), c1y)) return;
411 if (!convert(customCurveVariant.at(i + 2), c2x)) return;
412 if (!convert(customCurveVariant.at(i + 3), c2y)) return;
413 if (!convert(customCurveVariant.at(i + 4), c3x)) return;
414 if (!convert(customCurveVariant.at(i + 5), c3y)) return;
415
416 const QPointF c1(c1x, c1y);
417 const QPointF c2(c2x, c2y);
418 const QPointF c3(c3x, c3y);
419
420 newEasingCurve.addCubicBezierSegment(c1, c2, c3);
421 }
422
423 v = newEasingCurve;
424}
425
426QVariantList QQmlEasingValueType::bezierCurve() const
427{
428 QVariantList rv;
429 const QVector<QPointF> points = v.toCubicSpline();
430 rv.reserve(points.size() * 2);
431 for (const auto &point : points)
432 rv << QVariant(point.x()) << QVariant(point.y());
433 return rv;
434}
435#endif // easingcurve
436
437
439
440#include "moc_qqmlvaluetype_p.cpp"
\inmodule QtCore
Type
The type of easing curve.
void reserve(qsizetype size)
Definition qlist.h:753
QMetaObject * toMetaObject() const
Converts this meta object builder into a concrete QMetaObject.
\inmodule QtCore
Definition qmetatype.h:341
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qpoint.h:217
static QQmlEnginePrivate * get(QQmlEngine *e)
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
QQmlGadgetPtrWrapper(QQmlValueType *valueType, QObject *parent=nullptr)
QVariant value() const
void setValue(const QVariant &value)
static QQmlGadgetPtrWrapper * instance(QQmlEngine *engine, QMetaType type)
int metaCall(QMetaObject::Call type, int id, void **argv)
void write(QObject *obj, int idx, QQmlPropertyData::WriteFlags flags, int internalIndex=QV4::ReferenceObject::AllProperties) const
void read(QObject *obj, int idx)
QMetaType metaType() const
static void resolveGadgetMethodOrPropertyIndex(QMetaObject::Call type, const QMetaObject **metaObject, int *index)
void objectDestroyed(QObject *) override
QMetaObject * toDynamicMetaObject(QObject *) override
const QMetaObject * staticMetaObject() const
int metaCall(QObject *obj, QMetaObject::Call type, int _id, void **argv) override
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
Definition qstring.cpp:7263
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLboolean r
[2]
GLenum GLuint id
[7]
GLuint object
[3]
GLenum type
GLbitfield flags
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLfixed GLfixed GLint GLint GLfixed points
GLhandleARB obj
[2]
static constexpr To convert(const std::array< Mapping, N > &mapping, From Mapping::*from, To Mapping::*to, From value, To defaultValue)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
double qreal
Definition qtypes.h:187
obj metaObject() -> className()
MyCustomStruct c2
view create()
QJSEngine engine
[0]
\inmodule QtCore
static int metacall(QObject *, Call, int, void **)
Q_INVOKABLE QString toString() const
Q_INVOKABLE QString toString() const
Q_INVOKABLE QString toString() const
Q_INVOKABLE QString toString() const
Q_INVOKABLE QString toString() const
Q_INVOKABLE QString toString() const