1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the tools applications of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qqmlpropertycachecreator_p.h" |
41 | |
42 | #include <private/qqmlengine_p.h> |
43 | |
44 | QT_BEGIN_NAMESPACE |
45 | |
46 | QAtomicInt QQmlPropertyCacheCreatorBase::classIndexCounter(0); |
47 | |
48 | |
49 | int QQmlPropertyCacheCreatorBase::metaTypeForPropertyType(QV4::CompiledData::BuiltinType type) |
50 | { |
51 | switch (type) { |
52 | case QV4::CompiledData::BuiltinType::Var: return QMetaType::QVariant; |
53 | case QV4::CompiledData::BuiltinType::Variant: return QMetaType::QVariant; |
54 | case QV4::CompiledData::BuiltinType::Int: return QMetaType::Int; |
55 | case QV4::CompiledData::BuiltinType::Bool: return QMetaType::Bool; |
56 | case QV4::CompiledData::BuiltinType::Real: return QMetaType::Double; |
57 | case QV4::CompiledData::BuiltinType::String: return QMetaType::QString; |
58 | case QV4::CompiledData::BuiltinType::Url: return QMetaType::QUrl; |
59 | case QV4::CompiledData::BuiltinType::Color: return QMetaType::QColor; |
60 | case QV4::CompiledData::BuiltinType::Font: return QMetaType::QFont; |
61 | case QV4::CompiledData::BuiltinType::Time: return QMetaType::QTime; |
62 | case QV4::CompiledData::BuiltinType::Date: return QMetaType::QDate; |
63 | case QV4::CompiledData::BuiltinType::DateTime: return QMetaType::QDateTime; |
64 | case QV4::CompiledData::BuiltinType::Rect: return QMetaType::QRectF; |
65 | case QV4::CompiledData::BuiltinType::Point: return QMetaType::QPointF; |
66 | case QV4::CompiledData::BuiltinType::Size: return QMetaType::QSizeF; |
67 | case QV4::CompiledData::BuiltinType::Vector2D: return QMetaType::QVector2D; |
68 | case QV4::CompiledData::BuiltinType::Vector3D: return QMetaType::QVector3D; |
69 | case QV4::CompiledData::BuiltinType::Vector4D: return QMetaType::QVector4D; |
70 | case QV4::CompiledData::BuiltinType::Matrix4x4: return QMetaType::QMatrix4x4; |
71 | case QV4::CompiledData::BuiltinType::Quaternion: return QMetaType::QQuaternion; |
72 | case QV4::CompiledData::BuiltinType::InvalidBuiltin: break; |
73 | }; |
74 | return QMetaType::UnknownType; |
75 | } |
76 | |
77 | QQmlBindingInstantiationContext::QQmlBindingInstantiationContext(int referencingObjectIndex, const QV4::CompiledData::Binding *instantiatingBinding, |
78 | const QString &instantiatingPropertyName, QQmlPropertyCache *referencingObjectPropertyCache) |
79 | : referencingObjectIndex(referencingObjectIndex) |
80 | , instantiatingBinding(instantiatingBinding) |
81 | , instantiatingPropertyName(instantiatingPropertyName) |
82 | , referencingObjectPropertyCache(referencingObjectPropertyCache) |
83 | { |
84 | } |
85 | |
86 | bool QQmlBindingInstantiationContext::resolveInstantiatingProperty() |
87 | { |
88 | if (!instantiatingBinding || instantiatingBinding->type != QV4::CompiledData::Binding::Type_GroupProperty) |
89 | return true; |
90 | |
91 | Q_ASSERT(referencingObjectIndex >= 0); |
92 | Q_ASSERT(referencingObjectPropertyCache); |
93 | Q_ASSERT(instantiatingBinding->propertyNameIndex != 0); |
94 | |
95 | bool notInRevision = false; |
96 | instantiatingProperty = QQmlPropertyResolver(referencingObjectPropertyCache) |
97 | .property(instantiatingPropertyName, ¬InRevision, |
98 | QQmlPropertyResolver::IgnoreRevision); |
99 | return instantiatingProperty != nullptr; |
100 | } |
101 | |
102 | QQmlRefPointer<QQmlPropertyCache> QQmlBindingInstantiationContext::instantiatingPropertyCache(QQmlEnginePrivate *enginePrivate) const |
103 | { |
104 | if (instantiatingProperty) { |
105 | if (instantiatingProperty->isQObject()) { |
106 | return enginePrivate->rawPropertyCacheForType(instantiatingProperty->propType(), instantiatingProperty->typeMinorVersion()); |
107 | } else if (const QMetaObject *vtmo = QQmlValueTypeFactory::metaObjectForMetaType(instantiatingProperty->propType())) { |
108 | return enginePrivate->cache(vtmo, instantiatingProperty->typeMinorVersion()); |
109 | } |
110 | } |
111 | return QQmlRefPointer<QQmlPropertyCache>(); |
112 | } |
113 | |
114 | void QQmlPendingGroupPropertyBindings::resolveMissingPropertyCaches(QQmlEnginePrivate *enginePrivate, QQmlPropertyCacheVector *propertyCaches) const |
115 | { |
116 | for (QQmlBindingInstantiationContext pendingBinding: *this) { |
117 | const int groupPropertyObjectIndex = pendingBinding.instantiatingBinding->value.objectIndex; |
118 | |
119 | if (propertyCaches->at(groupPropertyObjectIndex)) |
120 | continue; |
121 | |
122 | if (!pendingBinding.resolveInstantiatingProperty()) |
123 | continue; |
124 | |
125 | auto cache = pendingBinding.instantiatingPropertyCache(enginePrivate); |
126 | propertyCaches->set(groupPropertyObjectIndex, cache); |
127 | } |
128 | } |
129 | |
130 | QT_END_NAMESPACE |
131 | |