Qt 6.x
The Qt SDK
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
20{
22}
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 return QVariant(metaType(), m_gadgetPtr);
59}
60
62{
63 Q_ASSERT(m_gadgetPtr);
64 Q_ASSERT(metaType() == value.metaType());
65 const QQmlValueType *type = valueType();
66 type->destruct(m_gadgetPtr);
67 type->construct(m_gadgetPtr, value.constData());
68}
69
71{
72 Q_ASSERT(m_gadgetPtr);
73 const QMetaObject *metaObject = valueType()->staticMetaObject();
75 metaObject->d.static_metacall(static_cast<QObject *>(m_gadgetPtr), type, id, argv);
76 return id;
77}
78
79const QQmlValueType *QQmlGadgetPtrWrapper::valueType() const
80{
82 return static_cast<const QQmlValueType *>(d->metaObject);
83}
84
86{
87 if (!m_dynamicMetaObject) {
88 QMetaObjectBuilder builder(m_staticMetaObject);
89
90 // Do not set PropertyAccessInStaticMetaCall here. QQmlGadgetPtrWrapper likes to
91 // to intercept the metacalls since it needs to use its gadgetPtr.
92 // For QQmlValueType::metaObject() we use the base type that has the flag.
93
94 m_dynamicMetaObject = builder.toMetaObject();
95 }
96 return m_dynamicMetaObject;
97}
98
100{
101}
102
103int QQmlValueType::metaCall(QObject *object, QMetaObject::Call type, int _id, void **argv)
104{
105 return static_cast<QQmlGadgetPtrWrapper *>(object)->metaCall(type, _id, argv);
106}
107
109{
110 return QString::asprintf("QPointF(%g, %g)", v.x(), v.y());
111}
112
114{
115 return v.x();
116}
117
119{
120 return v.y();
121}
122
124{
125 v.setX(x);
126}
127
129{
130 v.setY(y);
131}
132
133
135{
136 return QString::asprintf("QPoint(%d, %d)", v.x(), v.y());
137}
138
140{
141 return v.x();
142}
143
145{
146 return v.y();
147}
148
150{
151 v.setX(x);
152}
153
155{
156 v.setY(y);
157}
158
159
161{
162 return QString::asprintf("QSizeF(%g, %g)", v.width(), v.height());
163}
164
166{
167 return v.width();
168}
169
171{
172 return v.height();
173}
174
176{
177 v.setWidth(w);
178}
179
181{
182 v.setHeight(h);
183}
184
185
187{
188 return QString::asprintf("QSize(%d, %d)", v.width(), v.height());
189}
190
192{
193 return v.width();
194}
195
197{
198 return v.height();
199}
200
202{
203 v.setWidth(w);
204}
205
207{
208 v.setHeight(h);
209}
210
212{
213 return QString::asprintf("QRectF(%g, %g, %g, %g)", v.x(), v.y(), v.width(), v.height());
214}
215
217{
218 return v.x();
219}
220
222{
223 return v.y();
224}
225
227{
228 v.moveLeft(x);
229}
230
232{
233 v.moveTop(y);
234}
235
237{
238 return v.width();
239}
240
242{
243 return v.height();
244}
245
247{
248 v.setWidth(w);
249}
250
252{
253 v.setHeight(h);
254}
255
257{
258 return v.left();
259}
260
262{
263 return v.right();
264}
265
267{
268 return v.top();
269}
270
272{
273 return v.bottom();
274}
275
276
278{
279 return QString::asprintf("QRect(%d, %d, %d, %d)", v.x(), v.y(), v.width(), v.height());
280}
281
283{
284 return v.x();
285}
286
288{
289 return v.y();
290}
291
293{
294 v.moveLeft(x);
295}
296
298{
299 v.moveTop(y);
300}
301
303{
304 return v.width();
305}
306
308{
309 return v.height();
310}
311
313{
314 v.setWidth(w);
315}
316
318{
319 v.setHeight(h);
320}
321
323{
324 return v.left();
325}
326
328{
329 return v.right();
330}
331
333{
334 return v.top();
335}
336
338{
339 return v.bottom();
340}
341
342#if QT_CONFIG(easingcurve)
343QQmlEasingEnums::Type QQmlEasingValueType::type() const
344{
345 return (QQmlEasingEnums::Type)v.type();
346}
347
348qreal QQmlEasingValueType::amplitude() const
349{
350 return v.amplitude();
351}
352
353qreal QQmlEasingValueType::overshoot() const
354{
355 return v.overshoot();
356}
357
358qreal QQmlEasingValueType::period() const
359{
360 return v.period();
361}
362
363void QQmlEasingValueType::setType(QQmlEasingEnums::Type type)
364{
365 v.setType((QEasingCurve::Type)type);
366}
367
368void QQmlEasingValueType::setAmplitude(qreal amplitude)
369{
370 v.setAmplitude(amplitude);
371}
372
373void QQmlEasingValueType::setOvershoot(qreal overshoot)
374{
375 v.setOvershoot(overshoot);
376}
377
378void QQmlEasingValueType::setPeriod(qreal period)
379{
380 v.setPeriod(period);
381}
382
383void QQmlEasingValueType::setBezierCurve(const QVariantList &customCurveVariant)
384{
385 if (customCurveVariant.isEmpty())
386 return;
387
388 if ((customCurveVariant.size() % 6) != 0)
389 return;
390
391 auto convert = [](const QVariant &v, qreal &r) {
392 bool ok;
393 r = v.toReal(&ok);
394 return ok;
395 };
396
398 for (int i = 0, ei = customCurveVariant.size(); i < ei; i += 6) {
399 qreal c1x, c1y, c2x, c2y, c3x, c3y;
400 if (!convert(customCurveVariant.at(i ), c1x)) return;
401 if (!convert(customCurveVariant.at(i + 1), c1y)) return;
402 if (!convert(customCurveVariant.at(i + 2), c2x)) return;
403 if (!convert(customCurveVariant.at(i + 3), c2y)) return;
404 if (!convert(customCurveVariant.at(i + 4), c3x)) return;
405 if (!convert(customCurveVariant.at(i + 5), c3y)) return;
406
407 const QPointF c1(c1x, c1y);
408 const QPointF c2(c2x, c2y);
409 const QPointF c3(c3x, c3y);
410
411 newEasingCurve.addCubicBezierSegment(c1, c2, c3);
412 }
413
414 v = newEasingCurve;
415}
416
417QVariantList QQmlEasingValueType::bezierCurve() const
418{
419 QVariantList rv;
420 const QVector<QPointF> points = v.toCubicSpline();
421 rv.reserve(points.size() * 2);
422 for (const auto &point : points)
423 rv << QVariant(point.x()) << QVariant(point.y());
424 return rv;
425}
426#endif // easingcurve
427
428
430
431#include "moc_qqmlvaluetype_p.cpp"
\inmodule QtCore
Type
The type of easing curve.
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void reserve(qsizetype size)
Definition qlist.h:746
QMetaObject * toMetaObject() const
Converts this meta object builder into a concrete QMetaObject.
\inmodule QtCore
Definition qmetatype.h:320
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:153
\inmodule QtCore
Definition qobject.h:90
\inmodule QtCore\reentrant
Definition qpoint.h:214
QQmlGadgetPtrWrapper * valueTypeInstance(QMetaType type)
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:127
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
Definition qstring.cpp:7005
\inmodule QtCore
Definition qvariant.h:64
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]
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:92
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
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent