Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmlopenmetaobject.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 QtQml 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 "qqmlopenmetaobject_p.h" | - | ||||||||||||
41 | #include <private/qqmlpropertycache_p.h> | - | ||||||||||||
42 | #include <private/qqmldata_p.h> | - | ||||||||||||
43 | #include <private/qmetaobjectbuilder_p.h> | - | ||||||||||||
44 | #include <private/qv8engine_p.h> | - | ||||||||||||
45 | #include <qqmlengine.h> | - | ||||||||||||
46 | #include <qdebug.h> | - | ||||||||||||
47 | - | |||||||||||||
48 | QT_BEGIN_NAMESPACE | - | ||||||||||||
49 | - | |||||||||||||
50 | - | |||||||||||||
51 | class QQmlOpenMetaObjectTypePrivate | - | ||||||||||||
52 | { | - | ||||||||||||
53 | public: | - | ||||||||||||
54 | QQmlOpenMetaObjectTypePrivate() : mem(nullptr), cache(nullptr), engine(nullptr) {} executed 5054 times by 19 tests: end of block Executed by:
| 5054 | ||||||||||||
55 | - | |||||||||||||
56 | void init(const QMetaObject *metaObj); | - | ||||||||||||
57 | - | |||||||||||||
58 | int propertyOffset; | - | ||||||||||||
59 | int signalOffset; | - | ||||||||||||
60 | QHash<QByteArray, int> names; | - | ||||||||||||
61 | QMetaObjectBuilder mob; | - | ||||||||||||
62 | QMetaObject *mem; | - | ||||||||||||
63 | QQmlPropertyCache *cache; | - | ||||||||||||
64 | QQmlEngine *engine; | - | ||||||||||||
65 | QSet<QQmlOpenMetaObject*> referers; | - | ||||||||||||
66 | }; | - | ||||||||||||
67 | - | |||||||||||||
68 | QQmlOpenMetaObjectType::QQmlOpenMetaObjectType(const QMetaObject *base, QQmlEngine *engine) | - | ||||||||||||
69 | : QQmlCleanup(engine), d(new QQmlOpenMetaObjectTypePrivate) | - | ||||||||||||
70 | { | - | ||||||||||||
71 | d->engine = engine; | - | ||||||||||||
72 | d->init(base); | - | ||||||||||||
73 | } executed 5054 times by 19 tests: end of block Executed by:
| 5054 | ||||||||||||
74 | - | |||||||||||||
75 | QQmlOpenMetaObjectType::~QQmlOpenMetaObjectType() | - | ||||||||||||
76 | { | - | ||||||||||||
77 | if (d->mem)
| 0-5048 | ||||||||||||
78 | free(d->mem); executed 5048 times by 17 tests: free(d->mem); Executed by:
| 5048 | ||||||||||||
79 | if (d->cache)
| 166-4882 | ||||||||||||
80 | d->cache->release(); executed 166 times by 3 tests: d->cache->release(); Executed by:
| 166 | ||||||||||||
81 | delete d; | - | ||||||||||||
82 | } executed 5048 times by 17 tests: end of block Executed by:
| 5048 | ||||||||||||
83 | - | |||||||||||||
84 | void QQmlOpenMetaObjectType::clear() | - | ||||||||||||
85 | { | - | ||||||||||||
86 | d->engine = nullptr; | - | ||||||||||||
87 | } executed 81 times by 3 tests: end of block Executed by:
| 81 | ||||||||||||
88 | - | |||||||||||||
89 | int QQmlOpenMetaObjectType::propertyOffset() const | - | ||||||||||||
90 | { | - | ||||||||||||
91 | return d->propertyOffset; executed 22 times by 1 test: return d->propertyOffset; Executed by:
| 22 | ||||||||||||
92 | } | - | ||||||||||||
93 | - | |||||||||||||
94 | int QQmlOpenMetaObjectType::signalOffset() const | - | ||||||||||||
95 | { | - | ||||||||||||
96 | return d->signalOffset; executed 4 times by 1 test: return d->signalOffset; Executed by:
| 4 | ||||||||||||
97 | } | - | ||||||||||||
98 | - | |||||||||||||
99 | int QQmlOpenMetaObjectType::propertyCount() const | - | ||||||||||||
100 | { | - | ||||||||||||
101 | return d->names.count(); never executed: return d->names.count(); | 0 | ||||||||||||
102 | } | - | ||||||||||||
103 | - | |||||||||||||
104 | QByteArray QQmlOpenMetaObjectType::propertyName(int idx) const | - | ||||||||||||
105 | { | - | ||||||||||||
106 | Q_ASSERT(idx >= 0 && idx < d->names.count()); | - | ||||||||||||
107 | - | |||||||||||||
108 | return d->mob.property(idx).name(); never executed: return d->mob.property(idx).name(); | 0 | ||||||||||||
109 | } | - | ||||||||||||
110 | - | |||||||||||||
111 | QMetaObject *QQmlOpenMetaObjectType::metaObject() const | - | ||||||||||||
112 | { | - | ||||||||||||
113 | return d->mem; | - | ||||||||||||
114 | } | - | ||||||||||||
115 | - | |||||||||||||
116 | void QQmlOpenMetaObjectType::createProperties(const QVector<QByteArray> &names) | - | ||||||||||||
117 | { | - | ||||||||||||
118 | for (int i = 0; i < names.count(); ++i) {
| 36-104 | ||||||||||||
119 | const QByteArray &name = names.at(i); | - | ||||||||||||
120 | const int id = d->mob.propertyCount(); | - | ||||||||||||
121 | d->mob.addSignal("__" + QByteArray::number(id) + "()"); | - | ||||||||||||
122 | QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id); | - | ||||||||||||
123 | propertyCreated(id, build); | - | ||||||||||||
124 | d->names.insert(name, id); | - | ||||||||||||
125 | } executed 104 times by 1 test: end of block Executed by:
| 104 | ||||||||||||
126 | free(d->mem); | - | ||||||||||||
127 | d->mem = d->mob.toMetaObject(); | - | ||||||||||||
128 | QSet<QQmlOpenMetaObject*>::iterator it = d->referers.begin(); | - | ||||||||||||
129 | while (it != d->referers.end()) {
| 36 | ||||||||||||
130 | QQmlOpenMetaObject *omo = *it; | - | ||||||||||||
131 | *static_cast<QMetaObject *>(omo) = *d->mem; | - | ||||||||||||
132 | if (d->cache)
| 0-36 | ||||||||||||
133 | d->cache->update(omo); never executed: d->cache->update(omo); | 0 | ||||||||||||
134 | ++it; | - | ||||||||||||
135 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||
136 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||
137 | - | |||||||||||||
138 | int QQmlOpenMetaObjectType::createProperty(const QByteArray &name) | - | ||||||||||||
139 | { | - | ||||||||||||
140 | int id = d->mob.propertyCount(); | - | ||||||||||||
141 | d->mob.addSignal("__" + QByteArray::number(id) + "()"); | - | ||||||||||||
142 | QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id); | - | ||||||||||||
143 | propertyCreated(id, build); | - | ||||||||||||
144 | free(d->mem); | - | ||||||||||||
145 | d->mem = d->mob.toMetaObject(); | - | ||||||||||||
146 | d->names.insert(name, id); | - | ||||||||||||
147 | QSet<QQmlOpenMetaObject*>::iterator it = d->referers.begin(); | - | ||||||||||||
148 | while (it != d->referers.end()) {
| 3554-3724 | ||||||||||||
149 | QQmlOpenMetaObject *omo = *it; | - | ||||||||||||
150 | *static_cast<QMetaObject *>(omo) = *d->mem; | - | ||||||||||||
151 | if (d->cache)
| 10-3544 | ||||||||||||
152 | d->cache->update(omo); executed 10 times by 2 tests: d->cache->update(omo); Executed by:
| 10 | ||||||||||||
153 | ++it; | - | ||||||||||||
154 | } executed 3554 times by 10 tests: end of block Executed by:
| 3554 | ||||||||||||
155 | - | |||||||||||||
156 | return d->propertyOffset + id; executed 3724 times by 11 tests: return d->propertyOffset + id; Executed by:
| 3724 | ||||||||||||
157 | } | - | ||||||||||||
158 | - | |||||||||||||
159 | void QQmlOpenMetaObjectType::propertyCreated(int id, QMetaPropertyBuilder &builder) | - | ||||||||||||
160 | { | - | ||||||||||||
161 | if (d->referers.count())
| 176-3652 | ||||||||||||
162 | (*d->referers.begin())->propertyCreated(id, builder); executed 3652 times by 10 tests: (*d->referers.begin())->propertyCreated(id, builder); Executed by:
| 3652 | ||||||||||||
163 | } executed 3828 times by 11 tests: end of block Executed by:
| 3828 | ||||||||||||
164 | - | |||||||||||||
165 | void QQmlOpenMetaObjectTypePrivate::init(const QMetaObject *metaObj) | - | ||||||||||||
166 | { | - | ||||||||||||
167 | if (!mem) {
| 0-5054 | ||||||||||||
168 | mob.setSuperClass(metaObj); | - | ||||||||||||
169 | mob.setClassName(metaObj->className()); | - | ||||||||||||
170 | mob.setFlags(QMetaObjectBuilder::DynamicMetaObject); | - | ||||||||||||
171 | - | |||||||||||||
172 | mem = mob.toMetaObject(); | - | ||||||||||||
173 | - | |||||||||||||
174 | propertyOffset = mem->propertyOffset(); | - | ||||||||||||
175 | signalOffset = mem->methodOffset(); | - | ||||||||||||
176 | } executed 5054 times by 19 tests: end of block Executed by:
| 5054 | ||||||||||||
177 | } executed 5054 times by 19 tests: end of block Executed by:
| 5054 | ||||||||||||
178 | - | |||||||||||||
179 | //---------------------------------------------------------------------------- | - | ||||||||||||
180 | - | |||||||||||||
181 | class QQmlOpenMetaObjectPrivate | - | ||||||||||||
182 | { | - | ||||||||||||
183 | public: | - | ||||||||||||
184 | QQmlOpenMetaObjectPrivate(QQmlOpenMetaObject *_q, bool _autoCreate, QObject *obj) | - | ||||||||||||
185 | : q(_q), object(obj), autoCreate(_autoCreate) {} executed 6658 times by 18 tests: end of block Executed by:
| 6658 | ||||||||||||
186 | - | |||||||||||||
187 | struct Property { | - | ||||||||||||
188 | private: | - | ||||||||||||
189 | QVariant m_value; | - | ||||||||||||
190 | QPointer<QObject> qobjectTracker; | - | ||||||||||||
191 | public: | - | ||||||||||||
192 | bool valueSet = false; | - | ||||||||||||
193 | - | |||||||||||||
194 | QVariant value() const { | - | ||||||||||||
195 | if (QMetaType::typeFlags(m_value.userType()) & QMetaType::PointerToQObject | - | ||||||||||||
196 | && qobjectTracker.isNull())
| 50-906 | ||||||||||||
197 | return QVariant::fromValue<QObject*>(nullptr); executed 50 times by 2 tests: return QVariant::fromValue<QObject*>(nullptr); Executed by:
| 50 | ||||||||||||
198 | return m_value; executed 15904 times by 9 tests: return m_value; Executed by:
| 15904 | ||||||||||||
199 | } | - | ||||||||||||
200 | QVariant &valueRef() { return m_value; } executed 6 times by 1 test: return m_value; Executed by:
| 6 | ||||||||||||
201 | void setValue(const QVariant &v) { | - | ||||||||||||
202 | m_value = v; | - | ||||||||||||
203 | valueSet = true; | - | ||||||||||||
204 | if (QMetaType::typeFlags(v.userType()) & QMetaType::PointerToQObject)
| 648-11452 | ||||||||||||
205 | qobjectTracker = m_value.value<QObject*>(); executed 648 times by 8 tests: qobjectTracker = m_value.value<QObject*>(); Executed by:
| 648 | ||||||||||||
206 | } executed 12100 times by 9 tests: end of block Executed by:
| 12100 | ||||||||||||
207 | }; | - | ||||||||||||
208 | - | |||||||||||||
209 | inline void setPropertyValue(int idx, const QVariant &value) { | - | ||||||||||||
210 | if (data.count() <= idx)
| 18-6718 | ||||||||||||
211 | data.resize(idx + 1); executed 18 times by 2 tests: data.resize(idx + 1); Executed by:
| 18 | ||||||||||||
212 | data[idx].setValue(value); | - | ||||||||||||
213 | } executed 6736 times by 5 tests: end of block Executed by:
| 6736 | ||||||||||||
214 | - | |||||||||||||
215 | inline Property &propertyRef(int idx) { | - | ||||||||||||
216 | if (data.count() <= idx)
| 5364-10542 | ||||||||||||
217 | data.resize(idx + 1); executed 5364 times by 9 tests: data.resize(idx + 1); Executed by:
| 5364 | ||||||||||||
218 | Property &prop = data[idx]; | - | ||||||||||||
219 | if (!prop.valueSet)
| 5364-10542 | ||||||||||||
220 | prop.setValue(q->initialValue(idx)); executed 5364 times by 9 tests: prop.setValue(q->initialValue(idx)); Executed by:
| 5364 | ||||||||||||
221 | return prop; executed 15906 times by 9 tests: return prop; Executed by:
| 15906 | ||||||||||||
222 | } | - | ||||||||||||
223 | - | |||||||||||||
224 | inline QVariant propertyValue(int idx) { | - | ||||||||||||
225 | auto &prop = propertyRef(idx); | - | ||||||||||||
226 | return prop.value(); executed 15900 times by 9 tests: return prop.value(); Executed by:
| 15900 | ||||||||||||
227 | } | - | ||||||||||||
228 | - | |||||||||||||
229 | inline QVariant &propertyValueRef(int idx) { | - | ||||||||||||
230 | auto &prop = propertyRef(idx); | - | ||||||||||||
231 | return prop.valueRef(); executed 6 times by 1 test: return prop.valueRef(); Executed by:
| 6 | ||||||||||||
232 | } | - | ||||||||||||
233 | - | |||||||||||||
234 | inline bool hasProperty(int idx) const { | - | ||||||||||||
235 | if (idx >= data.count())
| 0 | ||||||||||||
236 | return false; never executed: return false; | 0 | ||||||||||||
237 | return data[idx].valueSet; never executed: return data[idx].valueSet; | 0 | ||||||||||||
238 | } | - | ||||||||||||
239 | - | |||||||||||||
240 | QQmlOpenMetaObject *q; | - | ||||||||||||
241 | QAbstractDynamicMetaObject *parent = nullptr; | - | ||||||||||||
242 | QVector<Property> data; | - | ||||||||||||
243 | QObject *object; | - | ||||||||||||
244 | QQmlRefPointer<QQmlOpenMetaObjectType> type; | - | ||||||||||||
245 | bool autoCreate; | - | ||||||||||||
246 | bool cacheProperties = false; | - | ||||||||||||
247 | }; | - | ||||||||||||
248 | - | |||||||||||||
249 | QQmlOpenMetaObject::QQmlOpenMetaObject(QObject *obj, const QMetaObject *base, bool automatic) | - | ||||||||||||
250 | : d(new QQmlOpenMetaObjectPrivate(this, automatic, obj)) | - | ||||||||||||
251 | { | - | ||||||||||||
252 | d->type.adopt(new QQmlOpenMetaObjectType(base ? base : obj->metaObject(), nullptr)); | - | ||||||||||||
253 | d->type->d->referers.insert(this); | - | ||||||||||||
254 | - | |||||||||||||
255 | QObjectPrivate *op = QObjectPrivate::get(obj); | - | ||||||||||||
256 | d->parent = static_cast<QAbstractDynamicMetaObject *>(op->metaObject); | - | ||||||||||||
257 | *static_cast<QMetaObject *>(this) = *d->type->d->mem; | - | ||||||||||||
258 | op->metaObject = this; | - | ||||||||||||
259 | } executed 4768 times by 17 tests: end of block Executed by:
| 4768 | ||||||||||||
260 | - | |||||||||||||
261 | QQmlOpenMetaObject::QQmlOpenMetaObject(QObject *obj, QQmlOpenMetaObjectType *type, bool automatic) | - | ||||||||||||
262 | : d(new QQmlOpenMetaObjectPrivate(this, automatic, obj)) | - | ||||||||||||
263 | { | - | ||||||||||||
264 | d->type = type; | - | ||||||||||||
265 | d->type->d->referers.insert(this); | - | ||||||||||||
266 | - | |||||||||||||
267 | QObjectPrivate *op = QObjectPrivate::get(obj); | - | ||||||||||||
268 | d->parent = static_cast<QAbstractDynamicMetaObject *>(op->metaObject); | - | ||||||||||||
269 | *static_cast<QMetaObject *>(this) = *d->type->d->mem; | - | ||||||||||||
270 | op->metaObject = this; | - | ||||||||||||
271 | } executed 1890 times by 4 tests: end of block Executed by:
| 1890 | ||||||||||||
272 | - | |||||||||||||
273 | QQmlOpenMetaObject::~QQmlOpenMetaObject() | - | ||||||||||||
274 | { | - | ||||||||||||
275 | if (d->parent)
| 0-6658 | ||||||||||||
276 | delete d->parent; never executed: delete d->parent; | 0 | ||||||||||||
277 | d->type->d->referers.remove(this); | - | ||||||||||||
278 | delete d; | - | ||||||||||||
279 | } executed 6658 times by 18 tests: end of block Executed by:
| 6658 | ||||||||||||
280 | - | |||||||||||||
281 | QQmlOpenMetaObjectType *QQmlOpenMetaObject::type() const | - | ||||||||||||
282 | { | - | ||||||||||||
283 | return d->type.data(); executed 36 times by 1 test: return d->type.data(); Executed by:
| 36 | ||||||||||||
284 | } | - | ||||||||||||
285 | - | |||||||||||||
286 | void QQmlOpenMetaObject::emitPropertyNotification(const QByteArray &propertyName) | - | ||||||||||||
287 | { | - | ||||||||||||
288 | QHash<QByteArray, int>::ConstIterator iter = d->type->d->names.constFind(propertyName); | - | ||||||||||||
289 | if (iter == d->type->d->names.constEnd())
| 0-4 | ||||||||||||
290 | return; never executed: return; | 0 | ||||||||||||
291 | activate(d->object, *iter + d->type->d->signalOffset, nullptr); | - | ||||||||||||
292 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
293 | - | |||||||||||||
294 | int QQmlOpenMetaObject::metaCall(QObject *o, QMetaObject::Call c, int id, void **a) | - | ||||||||||||
295 | { | - | ||||||||||||
296 | Q_ASSERT(d->object == o); | - | ||||||||||||
297 | - | |||||||||||||
298 | if (( c == QMetaObject::ReadProperty || c == QMetaObject::WriteProperty)
| 4-5448 | ||||||||||||
299 | && id >= d->type->d->propertyOffset) {
| 1482-4038 | ||||||||||||
300 | int propId = id - d->type->d->propertyOffset; | - | ||||||||||||
301 | if (c == QMetaObject::ReadProperty) {
| 72-1410 | ||||||||||||
302 | propertyRead(propId); | - | ||||||||||||
303 | *reinterpret_cast<QVariant *>(a[0]) = d->propertyValue(propId); | - | ||||||||||||
304 | } else if (c == QMetaObject::WriteProperty) { executed 1410 times by 9 tests: end of block Executed by:
| 0-1410 | ||||||||||||
305 | if (propId >= d->data.count() || d->data.at(propId).value() != *reinterpret_cast<QVariant *>(a[0])) {
| 4-54 | ||||||||||||
306 | propertyWrite(propId); | - | ||||||||||||
307 | d->setPropertyValue(propId, propertyWriteValue(propId, *reinterpret_cast<QVariant *>(a[0]))); | - | ||||||||||||
308 | propertyWritten(propId); | - | ||||||||||||
309 | activate(o, d->type->d->signalOffset + propId, nullptr); | - | ||||||||||||
310 | } executed 68 times by 3 tests: end of block Executed by:
| 68 | ||||||||||||
311 | } executed 72 times by 3 tests: end of block Executed by:
| 72 | ||||||||||||
312 | return -1; executed 1482 times by 9 tests: return -1; Executed by:
| 1482 | ||||||||||||
313 | } else { | - | ||||||||||||
314 | if (d->parent)
| 0-4042 | ||||||||||||
315 | return d->parent->metaCall(o, c, id, a); never executed: return d->parent->metaCall(o, c, id, a); | 0 | ||||||||||||
316 | else | - | ||||||||||||
317 | return o->qt_metacall(c, id, a); executed 4042 times by 4 tests: return o->qt_metacall(c, id, a); Executed by:
| 4042 | ||||||||||||
318 | } | - | ||||||||||||
319 | } | - | ||||||||||||
320 | - | |||||||||||||
321 | QAbstractDynamicMetaObject *QQmlOpenMetaObject::parent() const | - | ||||||||||||
322 | { | - | ||||||||||||
323 | return d->parent; never executed: return d->parent; | 0 | ||||||||||||
324 | } | - | ||||||||||||
325 | - | |||||||||||||
326 | QVariant QQmlOpenMetaObject::value(int id) const | - | ||||||||||||
327 | { | - | ||||||||||||
328 | return d->propertyValue(id); executed 5454 times by 3 tests: return d->propertyValue(id); Executed by:
| 5454 | ||||||||||||
329 | } | - | ||||||||||||
330 | - | |||||||||||||
331 | void QQmlOpenMetaObject::setValue(int id, const QVariant &value) | - | ||||||||||||
332 | { | - | ||||||||||||
333 | d->setPropertyValue(id, propertyWriteValue(id, value)); | - | ||||||||||||
334 | activate(d->object, id + d->type->d->signalOffset, nullptr); | - | ||||||||||||
335 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||
336 | - | |||||||||||||
337 | QVariant QQmlOpenMetaObject::value(const QByteArray &name) const | - | ||||||||||||
338 | { | - | ||||||||||||
339 | QHash<QByteArray, int>::ConstIterator iter = d->type->d->names.constFind(name); | - | ||||||||||||
340 | if (iter == d->type->d->names.cend())
| 268-2162 | ||||||||||||
341 | return QVariant(); executed 2162 times by 3 tests: return QVariant(); Executed by:
| 2162 | ||||||||||||
342 | - | |||||||||||||
343 | return d->propertyValue(*iter); executed 268 times by 3 tests: return d->propertyValue(*iter); Executed by:
| 268 | ||||||||||||
344 | } | - | ||||||||||||
345 | - | |||||||||||||
346 | QVariant &QQmlOpenMetaObject::valueRef(const QByteArray &name) | - | ||||||||||||
347 | { | - | ||||||||||||
348 | QHash<QByteArray, int>::ConstIterator iter = d->type->d->names.constFind(name); | - | ||||||||||||
349 | Q_ASSERT(iter != d->type->d->names.cend()); | - | ||||||||||||
350 | - | |||||||||||||
351 | return d->propertyValueRef(*iter); executed 6 times by 1 test: return d->propertyValueRef(*iter); Executed by:
| 6 | ||||||||||||
352 | } | - | ||||||||||||
353 | - | |||||||||||||
354 | bool QQmlOpenMetaObject::setValue(const QByteArray &name, const QVariant &val, bool force) | - | ||||||||||||
355 | { | - | ||||||||||||
356 | QHash<QByteArray, int>::ConstIterator iter = d->type->d->names.constFind(name); | - | ||||||||||||
357 | - | |||||||||||||
358 | int id = -1; | - | ||||||||||||
359 | if (iter == d->type->d->names.cend()) {
| 3138-5654 | ||||||||||||
360 | id = createProperty(name.constData(), "") - d->type->d->propertyOffset; | - | ||||||||||||
361 | } else { executed 3138 times by 4 tests: end of block Executed by:
| 3138 | ||||||||||||
362 | id = *iter; | - | ||||||||||||
363 | } executed 5654 times by 5 tests: end of block Executed by:
| 5654 | ||||||||||||
364 | - | |||||||||||||
365 | if (id >= 0) {
| 0-8792 | ||||||||||||
366 | if (!force && d->propertyValue(id) == val)
| 24-8768 | ||||||||||||
367 | return false; executed 2136 times by 5 tests: return false; Executed by:
| 2136 | ||||||||||||
368 | - | |||||||||||||
369 | d->setPropertyValue(id, val); | - | ||||||||||||
370 | activate(d->object, id + d->type->d->signalOffset, nullptr); | - | ||||||||||||
371 | return true; executed 6656 times by 5 tests: return true; Executed by:
| 6656 | ||||||||||||
372 | } | - | ||||||||||||
373 | - | |||||||||||||
374 | return false; never executed: return false; | 0 | ||||||||||||
375 | } | - | ||||||||||||
376 | - | |||||||||||||
377 | // returns true if this value has been initialized by a call to either value() or setValue() | - | ||||||||||||
378 | bool QQmlOpenMetaObject::hasValue(int id) const | - | ||||||||||||
379 | { | - | ||||||||||||
380 | return d->hasProperty(id); never executed: return d->hasProperty(id); | 0 | ||||||||||||
381 | } | - | ||||||||||||
382 | - | |||||||||||||
383 | void QQmlOpenMetaObject::setCached(bool c) | - | ||||||||||||
384 | { | - | ||||||||||||
385 | if (c == d->cacheProperties || !d->type->d->engine)
| 0-1890 | ||||||||||||
386 | return; never executed: return; | 0 | ||||||||||||
387 | - | |||||||||||||
388 | d->cacheProperties = c; | - | ||||||||||||
389 | - | |||||||||||||
390 | QQmlData *qmldata = QQmlData::get(d->object, true); | - | ||||||||||||
391 | if (d->cacheProperties) {
| 0-1890 | ||||||||||||
392 | if (!d->type->d->cache)
| 168-1722 | ||||||||||||
393 | d->type->d->cache = new QQmlPropertyCache(this); executed 168 times by 4 tests: d->type->d->cache = new QQmlPropertyCache(this); Executed by:
| 168 | ||||||||||||
394 | qmldata->propertyCache = d->type->d->cache; | - | ||||||||||||
395 | d->type->d->cache->addref(); | - | ||||||||||||
396 | } else { executed 1890 times by 4 tests: end of block Executed by:
| 1890 | ||||||||||||
397 | if (d->type->d->cache)
| 0 | ||||||||||||
398 | d->type->d->cache->release(); never executed: d->type->d->cache->release(); | 0 | ||||||||||||
399 | qmldata->propertyCache = nullptr; | - | ||||||||||||
400 | } never executed: end of block | 0 | ||||||||||||
401 | } | - | ||||||||||||
402 | - | |||||||||||||
403 | - | |||||||||||||
404 | int QQmlOpenMetaObject::createProperty(const char *name, const char *) | - | ||||||||||||
405 | { | - | ||||||||||||
406 | if (d->autoCreate) {
| 0-3546 | ||||||||||||
407 | int result = d->type->createProperty(name); | - | ||||||||||||
408 | - | |||||||||||||
409 | if (QQmlData *ddata = QQmlData::get(d->object, /*create*/false)) {
| 422-3124 | ||||||||||||
410 | if (ddata->propertyCache) {
| 2-420 | ||||||||||||
411 | ddata->propertyCache->release(); | - | ||||||||||||
412 | ddata->propertyCache = nullptr; | - | ||||||||||||
413 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
414 | } executed 422 times by 9 tests: end of block Executed by:
| 422 | ||||||||||||
415 | - | |||||||||||||
416 | return result; executed 3546 times by 9 tests: return result; Executed by:
| 3546 | ||||||||||||
417 | } else | - | ||||||||||||
418 | return -1; never executed: return -1; | 0 | ||||||||||||
419 | } | - | ||||||||||||
420 | - | |||||||||||||
421 | void QQmlOpenMetaObject::propertyRead(int) | - | ||||||||||||
422 | { | - | ||||||||||||
423 | } | - | ||||||||||||
424 | - | |||||||||||||
425 | void QQmlOpenMetaObject::propertyWrite(int) | - | ||||||||||||
426 | { | - | ||||||||||||
427 | } | - | ||||||||||||
428 | - | |||||||||||||
429 | QVariant QQmlOpenMetaObject::propertyWriteValue(int, const QVariant &value) | - | ||||||||||||
430 | { | - | ||||||||||||
431 | return value; executed 70 times by 2 tests: return value; Executed by:
| 70 | ||||||||||||
432 | } | - | ||||||||||||
433 | - | |||||||||||||
434 | void QQmlOpenMetaObject::propertyWritten(int) | - | ||||||||||||
435 | { | - | ||||||||||||
436 | } | - | ||||||||||||
437 | - | |||||||||||||
438 | void QQmlOpenMetaObject::propertyCreated(int, QMetaPropertyBuilder &) | - | ||||||||||||
439 | { | - | ||||||||||||
440 | } | - | ||||||||||||
441 | - | |||||||||||||
442 | QVariant QQmlOpenMetaObject::initialValue(int) | - | ||||||||||||
443 | { | - | ||||||||||||
444 | return QVariant(); executed 4996 times by 5 tests: return QVariant(); Executed by:
| 4996 | ||||||||||||
445 | } | - | ||||||||||||
446 | - | |||||||||||||
447 | int QQmlOpenMetaObject::count() const | - | ||||||||||||
448 | { | - | ||||||||||||
449 | return d->type->d->names.count(); executed 7274 times by 2 tests: return d->type->d->names.count(); Executed by:
| 7274 | ||||||||||||
450 | } | - | ||||||||||||
451 | - | |||||||||||||
452 | QByteArray QQmlOpenMetaObject::name(int idx) const | - | ||||||||||||
453 | { | - | ||||||||||||
454 | Q_ASSERT(idx >= 0 && idx < d->type->d->names.count()); | - | ||||||||||||
455 | - | |||||||||||||
456 | return d->type->d->mob.property(idx).name(); executed 1542 times by 8 tests: return d->type->d->mob.property(idx).name(); Executed by:
| 1542 | ||||||||||||
457 | } | - | ||||||||||||
458 | - | |||||||||||||
459 | QObject *QQmlOpenMetaObject::object() const | - | ||||||||||||
460 | { | - | ||||||||||||
461 | return d->object; executed 386 times by 8 tests: return d->object; Executed by:
| 386 | ||||||||||||
462 | } | - | ||||||||||||
463 | - | |||||||||||||
464 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |