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
qqmlvaluetypewrapper_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// Qt-Security score:significant
4
5#ifndef QQMLVALUETYPEWRAPPER_P_H
6#define QQMLVALUETYPEWRAPPER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qglobal.h>
20#include <private/qtqmlglobal_p.h>
21
22#include <private/qv4referenceobject_p.h>
23
24QT_BEGIN_NAMESPACE
25
26class QQmlValueType;
27
28namespace QV4 {
29
30namespace Heap {
31
32#define QQmlValueTypeWrapperMembers(class, Member)
33
35 DECLARE_MARKOBJECTS(QQmlValueTypeWrapper);
36
37 void init(
38 const void *data, QMetaType metaType, const QMetaObject *metaObject,
39 Object *object, int property, Flags flags)
40 {
41 ReferenceObject::init(object, property, flags | IsDirty);
42 setMetaType(metaType);
43 setMetaObject(metaObject);
44 if (data)
45 setData(data);
46 }
47
48 QQmlValueTypeWrapper *detached() const;
49
50 void destroy();
51
52 QMetaType metaType() const
53 {
54 Q_ASSERT(m_metaType != nullptr);
55 return QMetaType(m_metaType);
56 }
57
58 void setGadgetPtr(void *gadgetPtr) { m_gadgetPtr = gadgetPtr; }
59 void *gadgetPtr() const { return m_gadgetPtr; }
60
61 const QMetaObject *metaObject() const { return m_metaObject; }
62
63 void setData(const void *data)
64 {
65 const QMetaType type = metaType();
66 void *gadget = gadgetPtr();
67 if (gadget) {
68 type.destruct(gadget);
69 } else {
70 gadget = ::operator new(type.sizeOf());
71 setGadgetPtr(gadget);
72 }
73 type.construct(gadget, data);
74 }
75
76 QVariant toVariant() const;
77
78 void *storagePointer();
79 bool setVariant(const QVariant &variant);
80
81 bool readReference();
82 bool writeBack(int propertyIndex = QV4::ReferenceObject::AllProperties);
83
84private:
85 void setMetaObject(const QMetaObject *metaObject) { m_metaObject = metaObject; }
86 void setMetaType(QMetaType metaType)
87 {
88 Q_ASSERT(metaType.isValid());
89 m_metaType = metaType.iface();
90 }
91
92 void *m_gadgetPtr;
93 const QtPrivate::QMetaTypeInterface *m_metaType;
94 const QMetaObject *m_metaObject;
95};
96
97}
98
99struct Q_QML_EXPORT QQmlValueTypeWrapper : public ReferenceObject
100{
105
106public:
107
108 static ReturnedValue create(
109 ExecutionEngine *engine, const void *data, const QMetaObject *metaObject,
111 static ReturnedValue create(
113 static ReturnedValue create(
115
116 QVariant toVariant() const;
117
118 template <typename ValueType>
120 {
121 if (QMetaType::fromType<ValueType>() != d()->metaType())
122 return nullptr;
123 if (d()->isReference() && !readReferenceValue())
124 return nullptr;
125 return static_cast<ValueType *>(d()->gadgetPtr());
126 }
127
128 bool toGadget(void *data) const;
129 bool isEqual(const QVariant& value) const;
130 int typeId() const;
131 QMetaType type() const;
132 bool write(QObject *target, int propertyIndex) const;
133 bool readReferenceValue() const { return d()->readReference(); }
134 const QMetaObject *metaObject() const { return d()->metaObject(); }
135
137
139 static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver);
140 static bool virtualIsEqualTo(Managed *m, Managed *other);
141 static bool virtualHasProperty(const Managed *m, PropertyKey id);
144 static ReturnedValue method_toString(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
147
148 static void initProto(ExecutionEngine *v4);
149 static int virtualMetacall(Object *object, QMetaObject::Call call, int index, void **a);
150
154};
155
156}
157
158QT_END_NAMESPACE
159
160#endif // QQMLVALUETYPEWRAPPER_P_H
Combined button and popup list for selecting options.
DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext)
Definition qjsvalue.h:24
static Heap::ReferenceObject::Flags referenceFlags(const QMetaObject *metaObject, int index)
static void doStaticReadCall(const QMetaObject *metaObject, Heap::QQmlValueTypeWrapper *valueTypeWrapper, int index, void **args)
#define VALUE_TYPE_LOAD(metatype, cpptype, constructor)
PropertyKey next(const Object *o, Property *pd=nullptr, PropertyAttributes *attrs=nullptr) override
~QQmlValueTypeWrapperOwnPropertyKeyIterator() override=default