Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/designer/qqmldesignermetaobject.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 QtQuick module 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 "qqmldesignermetaobject_p.h" | - | ||||||||||||
41 | - | |||||||||||||
42 | #include <QSharedPointer> | - | ||||||||||||
43 | #include <QMetaProperty> | - | ||||||||||||
44 | #include <QtCore/private/qnumeric_p.h> | - | ||||||||||||
45 | #include <QDebug> | - | ||||||||||||
46 | - | |||||||||||||
47 | #include <private/qqmlengine_p.h> | - | ||||||||||||
48 | #include <private/qqmlpropertycache_p.h> | - | ||||||||||||
49 | - | |||||||||||||
50 | QT_BEGIN_NAMESPACE | - | ||||||||||||
51 | - | |||||||||||||
52 | static QHash<QDynamicMetaObjectData *, bool> nodeInstanceMetaObjectList; | - | ||||||||||||
53 | static void (*notifyPropertyChangeCallBack)(QObject*, const QQuickDesignerSupport::PropertyName &propertyName) = nullptr; | - | ||||||||||||
54 | - | |||||||||||||
55 | struct MetaPropertyData { | - | ||||||||||||
56 | inline QPair<QVariant, bool> &getDataRef(int idx) { | - | ||||||||||||
57 | while (m_data.count() <= idx)
| 8-88 | ||||||||||||
58 | m_data << QPair<QVariant, bool>(QVariant(), false); executed 88 times by 1 test: m_data << QPair<QVariant, bool>(QVariant(), false); Executed by:
| 88 | ||||||||||||
59 | return m_data[idx]; executed 8 times by 1 test: return m_data[idx]; Executed by:
| 8 | ||||||||||||
60 | } | - | ||||||||||||
61 | - | |||||||||||||
62 | inline QVariant &getData(int idx) { | - | ||||||||||||
63 | QPair<QVariant, bool> &prop = getDataRef(idx); | - | ||||||||||||
64 | if (!prop.second) {
| 0-4 | ||||||||||||
65 | prop.first = QVariant(); | - | ||||||||||||
66 | prop.second = true; | - | ||||||||||||
67 | } never executed: end of block | 0 | ||||||||||||
68 | return prop.first; executed 4 times by 1 test: return prop.first; Executed by:
| 4 | ||||||||||||
69 | } | - | ||||||||||||
70 | - | |||||||||||||
71 | inline bool hasData(int idx) const { | - | ||||||||||||
72 | if (idx >= m_data.count())
| 0 | ||||||||||||
73 | return false; never executed: return false; | 0 | ||||||||||||
74 | return m_data[idx].second; never executed: return m_data[idx].second; | 0 | ||||||||||||
75 | } | - | ||||||||||||
76 | - | |||||||||||||
77 | inline int count() { return m_data.count(); } executed 2 times by 1 test: return m_data.count(); Executed by:
| 2 | ||||||||||||
78 | - | |||||||||||||
79 | QVector<QPair<QVariant, bool> > m_data; | - | ||||||||||||
80 | }; | - | ||||||||||||
81 | - | |||||||||||||
82 | static QQmlPropertyCache *cacheForObject(QObject *object, QQmlEngine *engine) | - | ||||||||||||
83 | { | - | ||||||||||||
84 | QQmlVMEMetaObject *metaObject = QQmlVMEMetaObject::get(object); | - | ||||||||||||
85 | if (metaObject)
| 2 | ||||||||||||
86 | return metaObject->cache.data(); executed 2 times by 1 test: return metaObject->cache.data(); Executed by:
| 2 | ||||||||||||
87 | - | |||||||||||||
88 | return QQmlEnginePrivate::get(engine)->cache(object); executed 2 times by 1 test: return QQmlEnginePrivate::get(engine)->cache(object); Executed by:
| 2 | ||||||||||||
89 | } | - | ||||||||||||
90 | - | |||||||||||||
91 | QQmlDesignerMetaObject* QQmlDesignerMetaObject::getNodeInstanceMetaObject(QObject *object, QQmlEngine *engine) | - | ||||||||||||
92 | { | - | ||||||||||||
93 | //Avoid setting up multiple MetaObjects on the same QObject | - | ||||||||||||
94 | QObjectPrivate *op = QObjectPrivate::get(object); | - | ||||||||||||
95 | QDynamicMetaObjectData *parent = op->metaObject; | - | ||||||||||||
96 | if (nodeInstanceMetaObjectList.contains(parent))
| 2-4 | ||||||||||||
97 | return static_cast<QQmlDesignerMetaObject *>(parent); executed 2 times by 1 test: return static_cast<QQmlDesignerMetaObject *>(parent); Executed by:
| 2 | ||||||||||||
98 | - | |||||||||||||
99 | // we just create one and the ownership goes automatically to the object in nodeinstance see init method | - | ||||||||||||
100 | - | |||||||||||||
101 | QQmlData *ddata = QQmlData::get(object, false); | - | ||||||||||||
102 | - | |||||||||||||
103 | const bool hadVMEMetaObject = ddata ? ddata->hasVMEMetaObject : false;
| 0-4 | ||||||||||||
104 | QQmlDesignerMetaObject *mo = new QQmlDesignerMetaObject(object, engine); | - | ||||||||||||
105 | //If our parent is not a VMEMetaObject we just set the flag to false again | - | ||||||||||||
106 | if (ddata)
| 0-4 | ||||||||||||
107 | ddata->hasVMEMetaObject = hadVMEMetaObject; executed 4 times by 1 test: ddata->hasVMEMetaObject = hadVMEMetaObject; Executed by:
| 4 | ||||||||||||
108 | return mo; executed 4 times by 1 test: return mo; Executed by:
| 4 | ||||||||||||
109 | } | - | ||||||||||||
110 | - | |||||||||||||
111 | void QQmlDesignerMetaObject::init(QObject *object, QQmlEngine *engine) | - | ||||||||||||
112 | { | - | ||||||||||||
113 | //Creating QQmlOpenMetaObjectType | - | ||||||||||||
114 | m_type = new QQmlOpenMetaObjectType(metaObjectParent(), engine); | - | ||||||||||||
115 | m_type->addref(); | - | ||||||||||||
116 | //Assigning type to this | - | ||||||||||||
117 | copyTypeMetaObject(); | - | ||||||||||||
118 | - | |||||||||||||
119 | //Assign this to object | - | ||||||||||||
120 | QObjectPrivate *op = QObjectPrivate::get(object); | - | ||||||||||||
121 | op->metaObject = this; | - | ||||||||||||
122 | - | |||||||||||||
123 | cache = QQmlEnginePrivate::get(engine)->cache(this); | - | ||||||||||||
124 | - | |||||||||||||
125 | nodeInstanceMetaObjectList.insert(this, true); | - | ||||||||||||
126 | hasAssignedMetaObjectData = true; | - | ||||||||||||
127 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
128 | - | |||||||||||||
129 | QQmlDesignerMetaObject::QQmlDesignerMetaObject(QObject *object, QQmlEngine *engine) | - | ||||||||||||
130 | : QQmlVMEMetaObject(engine->handle(), object, cacheForObject(object, engine), /*qml compilation unit*/nullptr, /*qmlObjectId*/-1), | - | ||||||||||||
131 | m_context(engine->contextForObject(object)), | - | ||||||||||||
132 | m_data(new MetaPropertyData) | - | ||||||||||||
133 | { | - | ||||||||||||
134 | init(object, engine); | - | ||||||||||||
135 | - | |||||||||||||
136 | QQmlData *ddata = QQmlData::get(object, false); | - | ||||||||||||
137 | //Assign cache to object | - | ||||||||||||
138 | if (ddata && ddata->propertyCache) {
| 0-4 | ||||||||||||
139 | cache->setParent(ddata->propertyCache); | - | ||||||||||||
140 | cache->invalidate(engine, this); | - | ||||||||||||
141 | ddata->propertyCache->release(); | - | ||||||||||||
142 | ddata->propertyCache = cache.data(); | - | ||||||||||||
143 | ddata->propertyCache->addref(); | - | ||||||||||||
144 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
145 | - | |||||||||||||
146 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
147 | - | |||||||||||||
148 | QQmlDesignerMetaObject::~QQmlDesignerMetaObject() | - | ||||||||||||
149 | { | - | ||||||||||||
150 | m_type->release(); | - | ||||||||||||
151 | - | |||||||||||||
152 | nodeInstanceMetaObjectList.remove(this); | - | ||||||||||||
153 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
154 | - | |||||||||||||
155 | void QQmlDesignerMetaObject::createNewDynamicProperty(const QString &name) | - | ||||||||||||
156 | { | - | ||||||||||||
157 | int id = m_type->createProperty(name.toUtf8()); | - | ||||||||||||
158 | copyTypeMetaObject(); | - | ||||||||||||
159 | setValue(id, QVariant()); | - | ||||||||||||
160 | Q_ASSERT(id >= 0); | - | ||||||||||||
161 | Q_UNUSED(id); | - | ||||||||||||
162 | - | |||||||||||||
163 | //Updating cache | - | ||||||||||||
164 | QQmlPropertyCache *oldParent = cache->parent(); | - | ||||||||||||
165 | QQmlEnginePrivate::get(m_context->engine())->cache(this)->invalidate(m_context->engine(), this); | - | ||||||||||||
166 | cache->setParent(oldParent); | - | ||||||||||||
167 | - | |||||||||||||
168 | QQmlProperty property(myObject(), name, m_context); | - | ||||||||||||
169 | Q_ASSERT(property.isValid()); | - | ||||||||||||
170 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
171 | - | |||||||||||||
172 | void QQmlDesignerMetaObject::setValue(int id, const QVariant &value) | - | ||||||||||||
173 | { | - | ||||||||||||
174 | QPair<QVariant, bool> &prop = m_data->getDataRef(id); | - | ||||||||||||
175 | prop.first = propertyWriteValue(id, value); | - | ||||||||||||
176 | prop.second = true; | - | ||||||||||||
177 | QMetaObject::activate(myObject(), id + m_type->signalOffset(), nullptr); | - | ||||||||||||
178 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
179 | - | |||||||||||||
180 | QVariant QQmlDesignerMetaObject::propertyWriteValue(int, const QVariant &value) | - | ||||||||||||
181 | { | - | ||||||||||||
182 | return value; executed 4 times by 1 test: return value; Executed by:
| 4 | ||||||||||||
183 | } | - | ||||||||||||
184 | - | |||||||||||||
185 | const QAbstractDynamicMetaObject *QQmlDesignerMetaObject::dynamicMetaObjectParent() const | - | ||||||||||||
186 | { | - | ||||||||||||
187 | if (QQmlVMEMetaObject::parent.isT1())
| 12-14 | ||||||||||||
188 | return QQmlVMEMetaObject::parent.asT1()->toDynamicMetaObject(QQmlVMEMetaObject::object); executed 14 times by 1 test: return QQmlVMEMetaObject::parent.asT1()->toDynamicMetaObject(QQmlVMEMetaObject::object); Executed by:
| 14 | ||||||||||||
189 | else | - | ||||||||||||
190 | return nullptr; executed 12 times by 1 test: return nullptr; Executed by:
| 12 | ||||||||||||
191 | } | - | ||||||||||||
192 | - | |||||||||||||
193 | const QMetaObject *QQmlDesignerMetaObject::metaObjectParent() const | - | ||||||||||||
194 | { | - | ||||||||||||
195 | if (QQmlVMEMetaObject::parent.isT1())
| 2 | ||||||||||||
196 | return QQmlVMEMetaObject::parent.asT1()->toDynamicMetaObject(QQmlVMEMetaObject::object); executed 2 times by 1 test: return QQmlVMEMetaObject::parent.asT1()->toDynamicMetaObject(QQmlVMEMetaObject::object); Executed by:
| 2 | ||||||||||||
197 | - | |||||||||||||
198 | return QQmlVMEMetaObject::parent.asT2(); executed 2 times by 1 test: return QQmlVMEMetaObject::parent.asT2(); Executed by:
| 2 | ||||||||||||
199 | } | - | ||||||||||||
200 | - | |||||||||||||
201 | int QQmlDesignerMetaObject::propertyOffset() const | - | ||||||||||||
202 | { | - | ||||||||||||
203 | return cache->propertyOffset(); executed 2 times by 1 test: return cache->propertyOffset(); Executed by:
| 2 | ||||||||||||
204 | } | - | ||||||||||||
205 | - | |||||||||||||
206 | int QQmlDesignerMetaObject::openMetaCall(QObject *o, QMetaObject::Call call, int id, void **a) | - | ||||||||||||
207 | { | - | ||||||||||||
208 | if ((call == QMetaObject::ReadProperty || call == QMetaObject::WriteProperty)
| 0-10 | ||||||||||||
209 | && id >= m_type->propertyOffset()) {
| 6-10 | ||||||||||||
210 | int propId = id - m_type->propertyOffset(); | - | ||||||||||||
211 | if (call == QMetaObject::ReadProperty) {
| 2-4 | ||||||||||||
212 | //propertyRead(propId); | - | ||||||||||||
213 | *reinterpret_cast<QVariant *>(a[0]) = m_data->getData(propId); | - | ||||||||||||
214 | } else if (call == QMetaObject::WriteProperty) { executed 4 times by 1 test: end of block Executed by:
| 0-4 | ||||||||||||
215 | if (propId <= m_data->count() || m_data->m_data[propId].first != *reinterpret_cast<QVariant *>(a[0])) {
| 0-2 | ||||||||||||
216 | //propertyWrite(propId); | - | ||||||||||||
217 | QPair<QVariant, bool> &prop = m_data->getDataRef(propId); | - | ||||||||||||
218 | prop.first = propertyWriteValue(propId, *reinterpret_cast<QVariant *>(a[0])); | - | ||||||||||||
219 | prop.second = true; | - | ||||||||||||
220 | //propertyWritten(propId); | - | ||||||||||||
221 | activate(myObject(), m_type->signalOffset() + propId, nullptr); | - | ||||||||||||
222 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
223 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
224 | return -1; executed 6 times by 1 test: return -1; Executed by:
| 6 | ||||||||||||
225 | } else { | - | ||||||||||||
226 | QAbstractDynamicMetaObject *directParent = parent(); | - | ||||||||||||
227 | if (directParent)
| 4-6 | ||||||||||||
228 | return directParent->metaCall(o, call, id, a); executed 4 times by 1 test: return directParent->metaCall(o, call, id, a); Executed by:
| 4 | ||||||||||||
229 | else | - | ||||||||||||
230 | return myObject()->qt_metacall(call, id, a); executed 6 times by 1 test: return myObject()->qt_metacall(call, id, a); Executed by:
| 6 | ||||||||||||
231 | } | - | ||||||||||||
232 | } | - | ||||||||||||
233 | - | |||||||||||||
234 | int QQmlDesignerMetaObject::metaCall(QObject *o, QMetaObject::Call call, int id, void **a) | - | ||||||||||||
235 | { | - | ||||||||||||
236 | Q_ASSERT(myObject() == o); | - | ||||||||||||
237 | - | |||||||||||||
238 | int metaCallReturnValue = -1; | - | ||||||||||||
239 | - | |||||||||||||
240 | const QMetaProperty propertyById = QQmlVMEMetaObject::property(id); | - | ||||||||||||
241 | - | |||||||||||||
242 | if (call == QMetaObject::WriteProperty
| 6-10 | ||||||||||||
243 | && propertyById.userType() == QMetaType::QVariant
| 2-4 | ||||||||||||
244 | && reinterpret_cast<QVariant *>(a[0])->type() == QVariant::Double
| 0-2 | ||||||||||||
245 | && qt_is_nan(reinterpret_cast<QVariant *>(a[0])->toDouble())) {
| 0 | ||||||||||||
246 | return -1; never executed: return -1; | 0 | ||||||||||||
247 | } | - | ||||||||||||
248 | - | |||||||||||||
249 | if (call == QMetaObject::WriteProperty
| 6-10 | ||||||||||||
250 | && propertyById.userType() == QMetaType::Double
| 0-6 | ||||||||||||
251 | && qt_is_nan(*reinterpret_cast<double*>(a[0]))) {
| 0 | ||||||||||||
252 | return -1; never executed: return -1; | 0 | ||||||||||||
253 | } | - | ||||||||||||
254 | - | |||||||||||||
255 | if (call == QMetaObject::WriteProperty
| 6-10 | ||||||||||||
256 | && propertyById.userType() == QMetaType::Float
| 0-6 | ||||||||||||
257 | && qt_is_nan(*reinterpret_cast<float*>(a[0]))) {
| 0 | ||||||||||||
258 | return -1; never executed: return -1; | 0 | ||||||||||||
259 | } | - | ||||||||||||
260 | - | |||||||||||||
261 | QVariant oldValue; | - | ||||||||||||
262 | - | |||||||||||||
263 | if (call == QMetaObject::WriteProperty && !propertyById.hasNotifySignal())
| 2-10 | ||||||||||||
264 | { | - | ||||||||||||
265 | oldValue = propertyById.read(myObject()); | - | ||||||||||||
266 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
267 | - | |||||||||||||
268 | QAbstractDynamicMetaObject *directParent = parent(); | - | ||||||||||||
269 | if (directParent && id < directParent->propertyOffset()) {
| 0-10 | ||||||||||||
270 | metaCallReturnValue = directParent->metaCall(o, call, id, a); | - | ||||||||||||
271 | } else { never executed: end of block | 0 | ||||||||||||
272 | openMetaCall(o, call, id, a); | - | ||||||||||||
273 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||
274 | - | |||||||||||||
275 | - | |||||||||||||
276 | if (call == QMetaObject::WriteProperty
| 6-10 | ||||||||||||
277 | && !propertyById.hasNotifySignal()
| 2-4 | ||||||||||||
278 | && oldValue != propertyById.read(myObject()))
| 0-2 | ||||||||||||
279 | notifyPropertyChange(id); executed 2 times by 1 test: notifyPropertyChange(id); Executed by:
| 2 | ||||||||||||
280 | - | |||||||||||||
281 | return metaCallReturnValue; executed 16 times by 1 test: return metaCallReturnValue; Executed by:
| 16 | ||||||||||||
282 | } | - | ||||||||||||
283 | - | |||||||||||||
284 | void QQmlDesignerMetaObject::notifyPropertyChange(int id) | - | ||||||||||||
285 | { | - | ||||||||||||
286 | const QMetaProperty propertyById = property(id); | - | ||||||||||||
287 | - | |||||||||||||
288 | if (id < propertyOffset()) {
| 0-2 | ||||||||||||
289 | if (notifyPropertyChangeCallBack)
| 0-2 | ||||||||||||
290 | notifyPropertyChangeCallBack(myObject(), propertyById.name()); executed 2 times by 1 test: notifyPropertyChangeCallBack(myObject(), propertyById.name()); Executed by:
| 2 | ||||||||||||
291 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
292 | if (notifyPropertyChangeCallBack)
| 0 | ||||||||||||
293 | notifyPropertyChangeCallBack(myObject(), name(id - propertyOffset())); never executed: notifyPropertyChangeCallBack(myObject(), name(id - propertyOffset())); | 0 | ||||||||||||
294 | } never executed: end of block | 0 | ||||||||||||
295 | } | - | ||||||||||||
296 | - | |||||||||||||
297 | int QQmlDesignerMetaObject::count() const | - | ||||||||||||
298 | { | - | ||||||||||||
299 | return m_type->propertyCount(); never executed: return m_type->propertyCount(); | 0 | ||||||||||||
300 | } | - | ||||||||||||
301 | - | |||||||||||||
302 | QByteArray QQmlDesignerMetaObject::name(int idx) const | - | ||||||||||||
303 | { | - | ||||||||||||
304 | return m_type->propertyName(idx); never executed: return m_type->propertyName(idx); | 0 | ||||||||||||
305 | } | - | ||||||||||||
306 | - | |||||||||||||
307 | void QQmlDesignerMetaObject::copyTypeMetaObject() | - | ||||||||||||
308 | { | - | ||||||||||||
309 | *static_cast<QMetaObject *>(this) = *m_type->metaObject(); | - | ||||||||||||
310 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
311 | - | |||||||||||||
312 | void QQmlDesignerMetaObject::registerNotifyPropertyChangeCallBack(void (*callback)(QObject *, const QQuickDesignerSupport::PropertyName &)) | - | ||||||||||||
313 | { | - | ||||||||||||
314 | notifyPropertyChangeCallBack = callback; | - | ||||||||||||
315 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
316 | - | |||||||||||||
317 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |