| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/designer/qquickdesignercustomobjectdata.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | typedef QHash<QObject*, QQuickDesignerCustomObjectData*> CustomObjectDataHash; | - | ||||||||||||||||||
| 8 | namespace { namespace Q_QGS_s_designerObjectToDataHash { typedef CustomObjectDataHash Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
executed 2 times by 1 test: }guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 2 times by 1 test: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of blockExecuted by:
executed 42 times by 1 test: &holder.value;return &holder.value;Executed by:
executed 42 times by 1 test: } } } static QGlobalStatic<CustomObjectDataHash, Q_QGS_s_designerObjectToDataHash::innerFunction, Q_QGS_s_designerObjectToDataHash::guard> s_designerObjectToDataHash;return &holder.value;Executed by:
| 0-42 | ||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | struct HandleDestroyedFunctor { | - | ||||||||||||||||||
| 11 | QQuickDesignerCustomObjectData *data; | - | ||||||||||||||||||
| 12 | void operator()() { data->handleDestroyed(); } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 13 | }; | - | ||||||||||||||||||
| 14 | - | |||||||||||||||||||
| 15 | QQuickDesignerCustomObjectData::QQuickDesignerCustomObjectData(QObject *object) | - | ||||||||||||||||||
| 16 | : m_object(object) | - | ||||||||||||||||||
| 17 | { | - | ||||||||||||||||||
| 18 | if (object
| 0-4 | ||||||||||||||||||
| 19 | populateResetHashes(); | - | ||||||||||||||||||
| 20 | s_designerObjectToDataHash()->insert(object, this); | - | ||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | HandleDestroyedFunctor functor; | - | ||||||||||||||||||
| 23 | functor.data = this; | - | ||||||||||||||||||
| 24 | QObject::connect(object, &QObject::destroyed, functor); | - | ||||||||||||||||||
| 25 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 26 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | void QQuickDesignerCustomObjectData::registerData(QObject *object) | - | ||||||||||||||||||
| 29 | { | - | ||||||||||||||||||
| 30 | new QQuickDesignerCustomObjectData(object); | - | ||||||||||||||||||
| 31 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 32 | - | |||||||||||||||||||
| 33 | QQuickDesignerCustomObjectData *QQuickDesignerCustomObjectData::get(QObject *object) | - | ||||||||||||||||||
| 34 | { | - | ||||||||||||||||||
| 35 | return executed 34 times by 1 test: s_designerObjectToDataHash()->value(object);return s_designerObjectToDataHash()->value(object);Executed by:
executed 34 times by 1 test: return s_designerObjectToDataHash()->value(object);Executed by:
| 34 | ||||||||||||||||||
| 36 | } | - | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | QVariant QQuickDesignerCustomObjectData::getResetValue(QObject *object, const QQuickDesignerSupport::PropertyName &propertyName) | - | ||||||||||||||||||
| 39 | { | - | ||||||||||||||||||
| 40 | QQuickDesignerCustomObjectData* data = get(object); | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | if (data
| 4 | ||||||||||||||||||
| 43 | return executed 4 times by 1 test: data->getResetValue(propertyName);return data->getResetValue(propertyName);Executed by:
executed 4 times by 1 test: return data->getResetValue(propertyName);Executed by:
| 4 | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | return executed 4 times by 1 test: QVariant();return QVariant();Executed by:
executed 4 times by 1 test: return QVariant();Executed by:
| 4 | ||||||||||||||||||
| 46 | } | - | ||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | void QQuickDesignerCustomObjectData::doResetProperty(QObject *object, QQmlContext *context, const QQuickDesignerSupport::PropertyName &propertyName) | - | ||||||||||||||||||
| 49 | { | - | ||||||||||||||||||
| 50 | QQuickDesignerCustomObjectData* data = get(object); | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | if (data
| 0-8 | ||||||||||||||||||
| 53 | data->doResetProperty(context, propertyName); executed 8 times by 1 test: data->doResetProperty(context, propertyName);Executed by:
| 8 | ||||||||||||||||||
| 54 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | bool QQuickDesignerCustomObjectData::hasValidResetBinding(QObject *object, const QQuickDesignerSupport::PropertyName &propertyName) | - | ||||||||||||||||||
| 57 | { | - | ||||||||||||||||||
| 58 | QQuickDesignerCustomObjectData* data = get(object); | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | if (data
| 0-2 | ||||||||||||||||||
| 61 | return executed 2 times by 1 test: data->hasValidResetBinding(propertyName);return data->hasValidResetBinding(propertyName);Executed by:
executed 2 times by 1 test: return data->hasValidResetBinding(propertyName);Executed by:
| 2 | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 64 | } | - | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | bool QQuickDesignerCustomObjectData::hasBindingForProperty(QObject *object, | - | ||||||||||||||||||
| 67 | QQmlContext *context, | - | ||||||||||||||||||
| 68 | const QQuickDesignerSupport::PropertyName &propertyName, | - | ||||||||||||||||||
| 69 | bool *hasChanged) | - | ||||||||||||||||||
| 70 | { | - | ||||||||||||||||||
| 71 | QQuickDesignerCustomObjectData* data = get(object); | - | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | if (data
| 0-12 | ||||||||||||||||||
| 74 | return executed 12 times by 1 test: data->hasBindingForProperty(context, propertyName, hasChanged);return data->hasBindingForProperty(context, propertyName, hasChanged);Executed by:
executed 12 times by 1 test: return data->hasBindingForProperty(context, propertyName, hasChanged);Executed by:
| 12 | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 77 | } | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | void QQuickDesignerCustomObjectData::setPropertyBinding(QObject *object, | - | ||||||||||||||||||
| 80 | QQmlContext *context, | - | ||||||||||||||||||
| 81 | const QQuickDesignerSupport::PropertyName &propertyName, | - | ||||||||||||||||||
| 82 | const QString &expression) | - | ||||||||||||||||||
| 83 | { | - | ||||||||||||||||||
| 84 | QQuickDesignerCustomObjectData* data = get(object); | - | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | if (data
| 0-4 | ||||||||||||||||||
| 87 | data->setPropertyBinding(context, propertyName, expression); executed 4 times by 1 test: data->setPropertyBinding(context, propertyName, expression);Executed by:
| 4 | ||||||||||||||||||
| 88 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 89 | - | |||||||||||||||||||
| 90 | void QQuickDesignerCustomObjectData::keepBindingFromGettingDeleted(QObject *object, | - | ||||||||||||||||||
| 91 | QQmlContext *context, | - | ||||||||||||||||||
| 92 | const QQuickDesignerSupport::PropertyName &propertyName) | - | ||||||||||||||||||
| 93 | { | - | ||||||||||||||||||
| 94 | QQuickDesignerCustomObjectData* data = get(object); | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | if (data
| 0 | ||||||||||||||||||
| 97 | data->keepBindingFromGettingDeleted(context, propertyName); never executed: data->keepBindingFromGettingDeleted(context, propertyName); | 0 | ||||||||||||||||||
| 98 | } never executed: end of block | 0 | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | void QQuickDesignerCustomObjectData::populateResetHashes() | - | ||||||||||||||||||
| 101 | { | - | ||||||||||||||||||
| 102 | const QQuickDesignerSupport::PropertyNameList propertyNameList = | - | ||||||||||||||||||
| 103 | QQuickDesignerSupportProperties::propertyNameListForWritableProperties(object()); | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | const QMetaObject *mo = object()->metaObject(); | - | ||||||||||||||||||
| 106 | QByteArrayList deferredPropertyNames; | - | ||||||||||||||||||
| 107 | const int namesIndex = mo->indexOfClassInfo("DeferredPropertyNames"); | - | ||||||||||||||||||
| 108 | if (namesIndex != -1
| 0-4 | ||||||||||||||||||
| 109 | QMetaClassInfo classInfo = mo->classInfo(namesIndex); | - | ||||||||||||||||||
| 110 | deferredPropertyNames = QByteArray(classInfo.value()).split(','); | - | ||||||||||||||||||
| 111 | } never executed: end of block | 0 | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | for (const QQuickDesignerSupport::PropertyName &propertyName : propertyNameList) { | - | ||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | if (deferredPropertyNames.contains(propertyName)
| 0-240 | ||||||||||||||||||
| 116 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | QQmlProperty property(object(), QString::fromUtf8(propertyName), QQmlEngine::contextForObject(object())); | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | QQmlAbstractBinding::Ptr binding = QQmlAbstractBinding::Ptr(QQmlPropertyPrivate::binding(property)); | - | ||||||||||||||||||
| 121 | - | |||||||||||||||||||
| 122 | if (binding
| 2-238 | ||||||||||||||||||
| 123 | m_resetBindingHash.insert(propertyName, binding); | - | ||||||||||||||||||
| 124 | } executed 2 times by 1 test: else if (property.isWritable()end of blockExecuted by:
| 2-214 | ||||||||||||||||||
| 125 | m_resetValueHash.insert(propertyName, property.read()); | - | ||||||||||||||||||
| 126 | } executed 214 times by 1 test: end of blockExecuted by:
| 214 | ||||||||||||||||||
| 127 | } executed 240 times by 1 test: end of blockExecuted by:
| 240 | ||||||||||||||||||
| 128 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | QObject *QQuickDesignerCustomObjectData::object() const | - | ||||||||||||||||||
| 131 | { | - | ||||||||||||||||||
| 132 | return executed 516 times by 1 test: m_object;return m_object;Executed by:
executed 516 times by 1 test: return m_object;Executed by:
| 516 | ||||||||||||||||||
| 133 | } | - | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | QVariant QQuickDesignerCustomObjectData::getResetValue(const QQuickDesignerSupport::PropertyName &propertyName) const | - | ||||||||||||||||||
| 136 | { | - | ||||||||||||||||||
| 137 | return executed 4 times by 1 test: m_resetValueHash.value(propertyName);return m_resetValueHash.value(propertyName);Executed by:
executed 4 times by 1 test: return m_resetValueHash.value(propertyName);Executed by:
| 4 | ||||||||||||||||||
| 138 | } | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | void QQuickDesignerCustomObjectData::doResetProperty(QQmlContext *context, const QQuickDesignerSupport::PropertyName &propertyName) | - | ||||||||||||||||||
| 141 | { | - | ||||||||||||||||||
| 142 | QQmlProperty property(object(), QString::fromUtf8(propertyName), context); | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | if (!property.isValid()
| 0-8 | ||||||||||||||||||
| 145 | return; never executed: return; | 0 | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | QQmlAbstractBinding *binding = QQmlPropertyPrivate::binding(property); | - | ||||||||||||||||||
| 148 | if (binding
| 0-4 | ||||||||||||||||||
| 149 | binding->setEnabled(false, nullptr); | - | ||||||||||||||||||
| 150 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | if (hasValidResetBinding(propertyName)
| 4 | ||||||||||||||||||
| 154 | QQmlAbstractBinding *binding = getResetBinding(propertyName); | - | ||||||||||||||||||
| 155 | - | |||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | - | |||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | QQmlBinding *qmlBinding = dynamic_cast<QQmlBinding*>(binding); | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | if (qmlBinding
| 0-4 | ||||||||||||||||||
| 162 | qmlBinding->setTarget(property); executed 4 times by 1 test: qmlBinding->setTarget(property);Executed by:
| 4 | ||||||||||||||||||
| 163 | QQmlPropertyPrivate::setBinding(binding, QQmlPropertyPrivate::None, QQmlPropertyData::DontRemoveBinding); | - | ||||||||||||||||||
| 164 | if (qmlBinding
| 0-4 | ||||||||||||||||||
| 165 | qmlBinding->update(); executed 4 times by 1 test: qmlBinding->update();Executed by:
| 4 | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | } executed 4 times by 1 test: else if (property.isResettable()end of blockExecuted by:
| 0-4 | ||||||||||||||||||
| 168 | property.reset(); | - | ||||||||||||||||||
| 169 | } executed 4 times by 1 test: else if (property.propertyTypeCategory() == QQmlProperty::Listend of blockExecuted by:
| 0-4 | ||||||||||||||||||
| 170 | QQmlListReference list = qvariant_cast<QQmlListReference>(property.read()); | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | if (!QQuickDesignerSupportProperties::hasFullImplementedListInterface(list)
| 0 | ||||||||||||||||||
| 173 | QMessageLogger(__FILE__, 219, __PRETTY_FUNCTION__).warning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; | - | ||||||||||||||||||
| 174 | return; never executed: return; | 0 | ||||||||||||||||||
| 175 | } | - | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | list.clear(); | - | ||||||||||||||||||
| 178 | } never executed: else if (property.isWritable()end of block
| 0 | ||||||||||||||||||
| 179 | if (property.read() == getResetValue(propertyName)
| 0 | ||||||||||||||||||
| 180 | return; never executed: return; | 0 | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | property.write(getResetValue(propertyName)); | - | ||||||||||||||||||
| 183 | } never executed: end of block | 0 | ||||||||||||||||||
| 184 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | bool QQuickDesignerCustomObjectData::hasValidResetBinding(const QQuickDesignerSupport::PropertyName &propertyName) const | - | ||||||||||||||||||
| 187 | { | - | ||||||||||||||||||
| 188 | return executed 14 times by 1 test: m_resetBindingHash.contains(propertyName) && m_resetBindingHash.value(propertyName).data();return m_resetBindingHash.contains(propertyName) && m_resetBindingHash.value(propertyName).data();Executed by:
executed 14 times by 1 test: return m_resetBindingHash.contains(propertyName) && m_resetBindingHash.value(propertyName).data();Executed by:
| 14 | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | QQmlAbstractBinding *QQuickDesignerCustomObjectData::getResetBinding(const QQuickDesignerSupport::PropertyName &propertyName) const | - | ||||||||||||||||||
| 192 | { | - | ||||||||||||||||||
| 193 | return executed 6 times by 1 test: m_resetBindingHash.value(propertyName).data();return m_resetBindingHash.value(propertyName).data();Executed by:
executed 6 times by 1 test: return m_resetBindingHash.value(propertyName).data();Executed by:
| 6 | ||||||||||||||||||
| 194 | } | - | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | bool QQuickDesignerCustomObjectData::hasBindingForProperty(QQmlContext *context, | - | ||||||||||||||||||
| 197 | const QQuickDesignerSupport::PropertyName &propertyName, | - | ||||||||||||||||||
| 198 | bool *hasChanged) const | - | ||||||||||||||||||
| 199 | { | - | ||||||||||||||||||
| 200 | if (QQuickDesignerSupportProperties::isPropertyBlackListed(propertyName)
| 0-12 | ||||||||||||||||||
| 201 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | QQmlProperty property(object(), QString::fromUtf8(propertyName), context); | - | ||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | bool hasBinding = QQmlPropertyPrivate::binding(property); | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | if (hasChanged
| 0-12 | ||||||||||||||||||
| 208 | *hasChanged = hasBinding != m_hasBindingHash.value(propertyName, false); | - | ||||||||||||||||||
| 209 | if (*
| 0 | ||||||||||||||||||
| 210 | m_hasBindingHash.insert(propertyName, hasBinding); never executed: m_hasBindingHash.insert(propertyName, hasBinding); | 0 | ||||||||||||||||||
| 211 | } never executed: end of block | 0 | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | return executed 12 times by 1 test: QQmlPropertyPrivate::binding(property);return QQmlPropertyPrivate::binding(property);Executed by:
executed 12 times by 1 test: return QQmlPropertyPrivate::binding(property);Executed by:
| 12 | ||||||||||||||||||
| 214 | } | - | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | void QQuickDesignerCustomObjectData::setPropertyBinding(QQmlContext *context, | - | ||||||||||||||||||
| 217 | const QQuickDesignerSupport::PropertyName &propertyName, | - | ||||||||||||||||||
| 218 | const QString &expression) | - | ||||||||||||||||||
| 219 | { | - | ||||||||||||||||||
| 220 | QQmlProperty property(object(), QString::fromUtf8(propertyName), context); | - | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | if (!property.isValid()
| 0-4 | ||||||||||||||||||
| 223 | return; never executed: return; | 0 | ||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | if (property.isProperty()
| 0-4 | ||||||||||||||||||
| 226 | QQmlBinding *binding = QQmlBinding::create(&QQmlPropertyPrivate::get(property)->core, | - | ||||||||||||||||||
| 227 | expression, object(), QQmlContextData::get(context)); | - | ||||||||||||||||||
| 228 | binding->setTarget(property); | - | ||||||||||||||||||
| 229 | binding->setNotifyOnValueChanged(true); | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | QQmlPropertyPrivate::setBinding(binding, QQmlPropertyPrivate::None, QQmlPropertyData::DontRemoveBinding); | - | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | binding->update(); | - | ||||||||||||||||||
| 234 | if (binding->hasError()
| 0-4 | ||||||||||||||||||
| 235 | if (property.property().userType() == QVariant::String
| 0 | ||||||||||||||||||
| 236 | property.write(QVariant(QLatin1Char('#') + expression + QLatin1Char('#'))); never executed: property.write(QVariant(QLatin1Char('#') + expression + QLatin1Char('#'))); | 0 | ||||||||||||||||||
| 237 | } never executed: end of block | 0 | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | } executed 4 times by 1 test: else {end of blockExecuted by:
| 4 | ||||||||||||||||||
| 240 | QMessageLogger(__FILE__, 286, __PRETTY_FUNCTION__).warning() << __PRETTY_FUNCTION__ << ": Cannot set binding for property" << propertyName << ": property is unknown for type"; | - | ||||||||||||||||||
| 241 | } never executed: end of block | 0 | ||||||||||||||||||
| 242 | } | - | ||||||||||||||||||
| 243 | - | |||||||||||||||||||
| 244 | void QQuickDesignerCustomObjectData::keepBindingFromGettingDeleted(QQmlContext *context, | - | ||||||||||||||||||
| 245 | const QQuickDesignerSupport::PropertyName &propertyName) | - | ||||||||||||||||||
| 246 | { | - | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | (void)context; | - | ||||||||||||||||||
| 249 | (void)propertyName; | - | ||||||||||||||||||
| 250 | } never executed: end of block | 0 | ||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | void QQuickDesignerCustomObjectData::handleDestroyed() | - | ||||||||||||||||||
| 253 | { | - | ||||||||||||||||||
| 254 | s_designerObjectToDataHash()->remove(m_object); | - | ||||||||||||||||||
| 255 | delete this; | - | ||||||||||||||||||
| 256 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |