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
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
4#ifndef QQMLVALUETYPEWRAPPER_P_H
5#define QQMLVALUETYPEWRAPPER_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 <QtCore/qglobal.h>
19#include <private/qtqmlglobal_p.h>
20
21#include <private/qv4referenceobject_p.h>
22#include <private/qqmlpropertycache_p.h>
23#include <private/qqmltype_p_p.h>
24#include <private/qqmltypewrapper_p.h>
25#include <private/qv4object_p.h>
26#include <private/qv4qobjectwrapper_p.h>
27#include <private/qv4sequenceobject_p.h>
28#include <private/qv4value_p.h>
29#include <private/qv4referenceobject_p.h>
30
32
33class QQmlValueType;
34
35namespace QV4 {
36
37namespace Heap {
38
39#define QQmlValueTypeWrapperMembers(class, Member)
40
43
44 void init(
45 const void *data, QMetaType metaType, const QMetaObject *metaObject,
46 Object *object, int property, Flags flags)
47 {
48 ReferenceObject::init(object, property, flags);
49 setMetaType(metaType);
50 setMetaObject(metaObject);
51 if (data)
53 }
54
55 QQmlValueTypeWrapper *detached() const;
56
57 void destroy();
58
59 QMetaType metaType() const
60 {
61 Q_ASSERT(m_metaType != nullptr);
62 return QMetaType(m_metaType);
63 }
64
65 void setGadgetPtr(void *gadgetPtr) { m_gadgetPtr = gadgetPtr; }
66 void *gadgetPtr() const { return m_gadgetPtr; }
67
68 const QMetaObject *metaObject() const { return m_metaObject; }
69
70 void setData(const void *data)
71 {
72 const QMetaType type = metaType();
73 void *gadget = gadgetPtr();
74 if (gadget) {
75 type.destruct(gadget);
76 } else {
77 gadget = ::operator new(type.sizeOf());
78 setGadgetPtr(gadget);
79 }
80 type.construct(gadget, data);
81 }
82
83 QVariant toVariant() const;
84
85 void *storagePointer();
86 bool setVariant(const QVariant &variant);
87
88 bool readReference();
89 bool writeBack(int propertyIndex = QV4::ReferenceObject::AllProperties);
90
91private:
92 void setMetaObject(const QMetaObject *metaObject) { m_metaObject = metaObject; }
93 void setMetaType(QMetaType metaType)
94 {
95 Q_ASSERT(metaType.isValid());
96 m_metaType = metaType.iface();
97 }
98
99 void *m_gadgetPtr;
100 const QtPrivate::QMetaTypeInterface *m_metaType;
101 const QMetaObject *m_metaObject;
102};
103
104}
105
106struct Q_QML_EXPORT QQmlValueTypeWrapper : public ReferenceObject
107{
109 V4_PROTOTYPE(valueTypeWrapperPrototype)
111
112public:
113
114 static ReturnedValue create(
115 ExecutionEngine *engine, const void *data, const QMetaObject *metaObject,
116 QMetaType type, Heap::Object *object, int property, Heap::ReferenceObject::Flags flags);
117 static ReturnedValue create(
118 ExecutionEngine *engine, Heap::QQmlValueTypeWrapper *cloneFrom, Heap::Object *object);
119 static ReturnedValue create(
121
122 QVariant toVariant() const;
123
124 template<typename ValueType>
125 ValueType *cast()
126 {
127 if (QMetaType::fromType<ValueType>() != d()->metaType())
128 return nullptr;
129 if (d()->isReference() && !readReferenceValue())
130 return nullptr;
131 return static_cast<ValueType *>(d()->gadgetPtr());
132 }
133
134 bool toGadget(void *data) const;
135 bool isEqual(const QVariant& value) const;
136 int typeId() const;
137 QMetaType type() const;
138 bool write(QObject *target, int propertyIndex) const;
139 bool readReferenceValue() const { return d()->readReference(); }
140 const QMetaObject *metaObject() const { return d()->metaObject(); }
141
142 QQmlPropertyData dataForPropertyKey(PropertyKey id) const;
143
144 static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty);
145 static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver);
146 static bool virtualIsEqualTo(Managed *m, Managed *other);
147 static bool virtualHasProperty(const Managed *m, PropertyKey id);
148 static PropertyAttributes virtualGetOwnProperty(const Managed *m, PropertyKey id, Property *p);
149 static OwnPropertyKeyIterator *virtualOwnPropertyKeys(const Object *m, Value *target);
150 static ReturnedValue method_toString(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc);
151 static ReturnedValue virtualResolveLookupGetter(const Object *object, ExecutionEngine *engine, Lookup *lookup);
152 static bool virtualResolveLookupSetter(Object *object, ExecutionEngine *engine, Lookup *lookup, const Value &value);
153 static ReturnedValue lookupGetter(Lookup *lookup, ExecutionEngine *engine, const Value &object);
154 static bool lookupSetter(QV4::Lookup *l, QV4::ExecutionEngine *engine,
155 QV4::Value &object, const QV4::Value &value);
156
157 static void initProto(ExecutionEngine *v4);
158 static int virtualMetacall(Object *object, QMetaObject::Call call, int index, void **a);
159};
160
161}
162
164
165#endif // QV8VALUETYPEWRAPPER_P_H
166
167
static bool isEqual(const aiUVTransform &a, const aiUVTransform &b)
\inmodule QtCore
Definition qmetatype.h:341
const QtPrivate::QMetaTypeInterface * iface() const
Definition qmetatype.h:771
bool isValid() const
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
quint64 ReturnedValue
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
Flags
GLboolean GLboolean GLboolean b
const GLfloat * m
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLenum target
GLbitfield flags
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, JSToQVariantConversionBehavior conversionBehavior, V4ObjectSet *visitedObjects)
#define V4_NEEDS_DESTROY
#define DECLARE_HEAP_OBJECT(name, base)
#define DECLARE_MARKOBJECTS(class)
#define V4_PROTOTYPE(p)
#define V4_OBJECT2(DataClass, superClass)
const char property[13]
Definition qwizard.cpp:101
gzip write("uncompressed data")
mimeData setData("text/csv", csvData)
obj metaObject() -> className()
QVariant variant
[1]
QSharedPointer< T > other(t)
[5]
view create()
QJSEngine engine
[0]
\inmodule QtCore
const QMetaObject * metaObject() const
static constexpr const int AllProperties