OpenCoverage

qquickdesignercustomobjectdata.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/designer/qquickdesignercustomobjectdata.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "qquickdesignersupportmetainfo_p.h"-
41#include "qquickdesignersupportproperties_p.h"-
42-
43#include "qquickdesignercustomobjectdata_p.h"-
44-
45#include <QGlobalStatic>-
46#include <QQmlContext>-
47#include <QQmlEngine>-
48-
49#include <private/qqmlbinding_p.h>-
50-
51QT_BEGIN_NAMESPACE-
52-
53typedef QHash<QObject*, QQuickDesignerCustomObjectData*> CustomObjectDataHash;-
54Q_GLOBAL_STATIC(CustomObjectDataHash, s_designerObjectToDataHash)
executed 2 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
executed 2 times by 1 test: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_qquickdesignersupport
executed 42 times by 1 test: return &holder.value;
Executed by:
  • tst_qquickdesignersupport
guard.load() =...c::InitializedDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-42
55-
56struct HandleDestroyedFunctor {-
57 QQuickDesignerCustomObjectData *data;-
58 void operator()() { data->handleDestroyed(); }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
4
59};-
60-
61QQuickDesignerCustomObjectData::QQuickDesignerCustomObjectData(QObject *object)-
62 : m_object(object)-
63{-
64 if (object) {
objectDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-4
65 populateResetHashes();-
66 s_designerObjectToDataHash()->insert(object, this);-
67-
68 HandleDestroyedFunctor functor;-
69 functor.data = this;-
70 QObject::connect(object, &QObject::destroyed, functor);-
71 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
4
72}
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
4
73-
74void QQuickDesignerCustomObjectData::registerData(QObject *object)-
75{-
76 new QQuickDesignerCustomObjectData(object);-
77}
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
4
78-
79QQuickDesignerCustomObjectData *QQuickDesignerCustomObjectData::get(QObject *object)-
80{-
81 return s_designerObjectToDataHash()->value(object);
executed 34 times by 1 test: return s_designerObjectToDataHash()->value(object);
Executed by:
  • tst_qquickdesignersupport
34
82}-
83-
84QVariant QQuickDesignerCustomObjectData::getResetValue(QObject *object, const QQuickDesignerSupport::PropertyName &propertyName)-
85{-
86 QQuickDesignerCustomObjectData* data = get(object);-
87-
88 if (data)
dataDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
4
89 return data->getResetValue(propertyName);
executed 4 times by 1 test: return data->getResetValue(propertyName);
Executed by:
  • tst_qquickdesignersupport
4
90-
91 return QVariant();
executed 4 times by 1 test: return QVariant();
Executed by:
  • tst_qquickdesignersupport
4
92}-
93-
94void QQuickDesignerCustomObjectData::doResetProperty(QObject *object, QQmlContext *context, const QQuickDesignerSupport::PropertyName &propertyName)-
95{-
96 QQuickDesignerCustomObjectData* data = get(object);-
97-
98 if (data)
dataDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-8
99 data->doResetProperty(context, propertyName);
executed 8 times by 1 test: data->doResetProperty(context, propertyName);
Executed by:
  • tst_qquickdesignersupport
8
100}
executed 8 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
8
101-
102bool QQuickDesignerCustomObjectData::hasValidResetBinding(QObject *object, const QQuickDesignerSupport::PropertyName &propertyName)-
103{-
104 QQuickDesignerCustomObjectData* data = get(object);-
105-
106 if (data)
dataDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-2
107 return data->hasValidResetBinding(propertyName);
executed 2 times by 1 test: return data->hasValidResetBinding(propertyName);
Executed by:
  • tst_qquickdesignersupport
2
108-
109 return false;
never executed: return false;
0
110}-
111-
112bool QQuickDesignerCustomObjectData::hasBindingForProperty(QObject *object,-
113 QQmlContext *context,-
114 const QQuickDesignerSupport::PropertyName &propertyName,-
115 bool *hasChanged)-
116{-
117 QQuickDesignerCustomObjectData* data = get(object);-
118-
119 if (data)
dataDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-12
120 return data->hasBindingForProperty(context, propertyName, hasChanged);
executed 12 times by 1 test: return data->hasBindingForProperty(context, propertyName, hasChanged);
Executed by:
  • tst_qquickdesignersupport
12
121-
122 return false;
never executed: return false;
0
123}-
124-
125void QQuickDesignerCustomObjectData::setPropertyBinding(QObject *object,-
126 QQmlContext *context,-
127 const QQuickDesignerSupport::PropertyName &propertyName,-
128 const QString &expression)-
129{-
130 QQuickDesignerCustomObjectData* data = get(object);-
131-
132 if (data)
dataDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-4
133 data->setPropertyBinding(context, propertyName, expression);
executed 4 times by 1 test: data->setPropertyBinding(context, propertyName, expression);
Executed by:
  • tst_qquickdesignersupport
4
134}
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
4
135-
136void QQuickDesignerCustomObjectData::keepBindingFromGettingDeleted(QObject *object,-
137 QQmlContext *context,-
138 const QQuickDesignerSupport::PropertyName &propertyName)-
139{-
140 QQuickDesignerCustomObjectData* data = get(object);-
141-
142 if (data)
dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
143 data->keepBindingFromGettingDeleted(context, propertyName);
never executed: data->keepBindingFromGettingDeleted(context, propertyName);
0
144}
never executed: end of block
0
145-
146void QQuickDesignerCustomObjectData::populateResetHashes()-
147{-
148 const QQuickDesignerSupport::PropertyNameList propertyNameList =-
149 QQuickDesignerSupportProperties::propertyNameListForWritableProperties(object());-
150-
151 const QMetaObject *mo = object()->metaObject();-
152 QByteArrayList deferredPropertyNames;-
153 const int namesIndex = mo->indexOfClassInfo("DeferredPropertyNames");-
154 if (namesIndex != -1) {
namesIndex != -1Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
0-4
155 QMetaClassInfo classInfo = mo->classInfo(namesIndex);-
156 deferredPropertyNames = QByteArray(classInfo.value()).split(',');-
157 }
never executed: end of block
0
158-
159 for (const QQuickDesignerSupport::PropertyName &propertyName : propertyNameList) {-
160-
161 if (deferredPropertyNames.contains(propertyName))
deferredProper...(propertyName)Description
TRUEnever evaluated
FALSEevaluated 240 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
0-240
162 continue;
never executed: continue;
0
163-
164 QQmlProperty property(object(), QString::fromUtf8(propertyName), QQmlEngine::contextForObject(object()));-
165-
166 QQmlAbstractBinding::Ptr binding = QQmlAbstractBinding::Ptr(QQmlPropertyPrivate::binding(property));-
167-
168 if (binding) {
bindingDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEevaluated 238 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
2-238
169 m_resetBindingHash.insert(propertyName, binding);-
170 } else if (property.isWritable()) {
executed 2 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
property.isWritable()Description
TRUEevaluated 214 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEevaluated 24 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
2-214
171 m_resetValueHash.insert(propertyName, property.read());-
172 }
executed 214 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
214
173 }
executed 240 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
240
174}
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
4
175-
176QObject *QQuickDesignerCustomObjectData::object() const-
177{-
178 return m_object;
executed 516 times by 1 test: return m_object;
Executed by:
  • tst_qquickdesignersupport
516
179}-
180-
181QVariant QQuickDesignerCustomObjectData::getResetValue(const QQuickDesignerSupport::PropertyName &propertyName) const-
182{-
183 return m_resetValueHash.value(propertyName);
executed 4 times by 1 test: return m_resetValueHash.value(propertyName);
Executed by:
  • tst_qquickdesignersupport
4
184}-
185-
186void QQuickDesignerCustomObjectData::doResetProperty(QQmlContext *context, const QQuickDesignerSupport::PropertyName &propertyName)-
187{-
188 QQmlProperty property(object(), QString::fromUtf8(propertyName), context);-
189-
190 if (!property.isValid())
!property.isValid()Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
0-8
191 return;
never executed: return;
0
192-
193 QQmlAbstractBinding *binding = QQmlPropertyPrivate::binding(property);-
194 if (binding && !(hasValidResetBinding(propertyName) && getResetBinding(propertyName) == binding)) {
bindingDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
hasValidResetB...(propertyName)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
getResetBindin...me) == bindingDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
0-4
195 binding->setEnabled(false, nullptr);-
196 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
4
197-
198-
199 if (hasValidResetBinding(propertyName)) {
hasValidResetB...(propertyName)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
4
200 QQmlAbstractBinding *binding = getResetBinding(propertyName);-
201-
202#if defined(QT_NO_DYNAMIC_CAST)-
203 QQmlBinding *qmlBinding = static_cast<QQmlBinding*>(binding);-
204#else-
205 QQmlBinding *qmlBinding = dynamic_cast<QQmlBinding*>(binding);-
206#endif-
207 if (qmlBinding)
qmlBindingDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-4
208 qmlBinding->setTarget(property);
executed 4 times by 1 test: qmlBinding->setTarget(property);
Executed by:
  • tst_qquickdesignersupport
4
209 QQmlPropertyPrivate::setBinding(binding, QQmlPropertyPrivate::None, QQmlPropertyData::DontRemoveBinding);-
210 if (qmlBinding)
qmlBindingDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-4
211 qmlBinding->update();
executed 4 times by 1 test: qmlBinding->update();
Executed by:
  • tst_qquickdesignersupport
4
212-
213 } else if (property.isResettable()) {
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
property.isResettable()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-4
214 property.reset();-
215 } else if (property.propertyTypeCategory() == QQmlProperty::List) {
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
property.prope...Property::ListDescription
TRUEnever evaluated
FALSEnever evaluated
0-4
216 QQmlListReference list = qvariant_cast<QQmlListReference>(property.read());-
217-
218 if (!QQuickDesignerSupportProperties::hasFullImplementedListInterface(list)) {
!QQuickDesigne...nterface(list)Description
TRUEnever evaluated
FALSEnever evaluated
0
219 qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!";-
220 return;
never executed: return;
0
221 }-
222-
223 list.clear();-
224 } else if (property.isWritable()) {
never executed: end of block
property.isWritable()Description
TRUEnever evaluated
FALSEnever evaluated
0
225 if (property.read() == getResetValue(propertyName))
property.read(...(propertyName)Description
TRUEnever evaluated
FALSEnever evaluated
0
226 return;
never executed: return;
0
227-
228 property.write(getResetValue(propertyName));-
229 }
never executed: end of block
0
230}
executed 8 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
8
231-
232bool QQuickDesignerCustomObjectData::hasValidResetBinding(const QQuickDesignerSupport::PropertyName &propertyName) const-
233{-
234 return m_resetBindingHash.contains(propertyName) && m_resetBindingHash.value(propertyName).data();
executed 14 times by 1 test: return m_resetBindingHash.contains(propertyName) && m_resetBindingHash.value(propertyName).data();
Executed by:
  • tst_qquickdesignersupport
14
235}-
236-
237QQmlAbstractBinding *QQuickDesignerCustomObjectData::getResetBinding(const QQuickDesignerSupport::PropertyName &propertyName) const-
238{-
239 return m_resetBindingHash.value(propertyName).data();
executed 6 times by 1 test: return m_resetBindingHash.value(propertyName).data();
Executed by:
  • tst_qquickdesignersupport
6
240}-
241-
242bool QQuickDesignerCustomObjectData::hasBindingForProperty(QQmlContext *context,-
243 const QQuickDesignerSupport::PropertyName &propertyName,-
244 bool *hasChanged) const-
245{-
246 if (QQuickDesignerSupportProperties::isPropertyBlackListed(propertyName))
QQuickDesigner...(propertyName)Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
0-12
247 return false;
never executed: return false;
0
248-
249 QQmlProperty property(object(), QString::fromUtf8(propertyName), context);-
250-
251 bool hasBinding = QQmlPropertyPrivate::binding(property);-
252-
253 if (hasChanged) {
hasChangedDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
0-12
254 *hasChanged = hasBinding != m_hasBindingHash.value(propertyName, false);-
255 if (*hasChanged)
*hasChangedDescription
TRUEnever evaluated
FALSEnever evaluated
0
256 m_hasBindingHash.insert(propertyName, hasBinding);
never executed: m_hasBindingHash.insert(propertyName, hasBinding);
0
257 }
never executed: end of block
0
258-
259 return QQmlPropertyPrivate::binding(property);
executed 12 times by 1 test: return QQmlPropertyPrivate::binding(property);
Executed by:
  • tst_qquickdesignersupport
12
260}-
261-
262void QQuickDesignerCustomObjectData::setPropertyBinding(QQmlContext *context,-
263 const QQuickDesignerSupport::PropertyName &propertyName,-
264 const QString &expression)-
265{-
266 QQmlProperty property(object(), QString::fromUtf8(propertyName), context);-
267-
268 if (!property.isValid())
!property.isValid()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
0-4
269 return;
never executed: return;
0
270-
271 if (property.isProperty()) {
property.isProperty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
FALSEnever evaluated
0-4
272 QQmlBinding *binding = QQmlBinding::create(&QQmlPropertyPrivate::get(property)->core,-
273 expression, object(), QQmlContextData::get(context));-
274 binding->setTarget(property);-
275 binding->setNotifyOnValueChanged(true);-
276-
277 QQmlPropertyPrivate::setBinding(binding, QQmlPropertyPrivate::None, QQmlPropertyData::DontRemoveBinding);-
278 //Refcounting is taking take care of deletion-
279 binding->update();-
280 if (binding->hasError()) {
binding->hasError()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickdesignersupport
0-4
281 if (property.property().userType() == QVariant::String)
property.prope...ariant::StringDescription
TRUEnever evaluated
FALSEnever evaluated
0
282 property.write(QVariant(QLatin1Char('#') + expression + QLatin1Char('#')));
never executed: property.write(QVariant(QLatin1Char('#') + expression + QLatin1Char('#')));
0
283 }
never executed: end of block
0
284-
285 } else {
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
4
286 qWarning() << Q_FUNC_INFO << ": Cannot set binding for property" << propertyName << ": property is unknown for type";-
287 }
never executed: end of block
0
288}-
289-
290void QQuickDesignerCustomObjectData::keepBindingFromGettingDeleted(QQmlContext *context,-
291 const QQuickDesignerSupport::PropertyName &propertyName)-
292{-
293 //Refcounting is taking care-
294 Q_UNUSED(context)-
295 Q_UNUSED(propertyName)-
296}
never executed: end of block
0
297-
298void QQuickDesignerCustomObjectData::handleDestroyed()-
299{-
300 s_designerObjectToDataHash()->remove(m_object);-
301 delete this;-
302}
executed 4 times by 1 test: end of block
Executed by:
  • tst_qquickdesignersupport
4
303-
304QT_END_NAMESPACE-
305-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0