7#include <private/qqmlcomponent_p.h>
8#include <private/qqmlnotifier_p.h>
9#include <private/qqmlobjectcreator_p.h>
10#include <private/qqmlproperty_p.h>
11#include <private/qqmlproperty_p.h>
12#include <private/qqmlpropertybinding_p.h>
13#include <private/qqmlpropertytopropertybinding_p.h>
14#include <private/qqmltypeloader_p.h>
15#include <private/qqmlvaluetypeproxybinding_p.h>
16#include <private/qqmlvme_p.h>
17#include <private/qv4functionobject_p.h>
18#include <private/qv4generatorobject_p.h>
19#include <private/qv4qmlcontext_p.h>
20#include <private/qv4resolvedtypereference_p.h>
22#include <QtCore/qqueue.h>
23#include <QtCore/qset.h>
31 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &cu,
34 if (f->executableCompilationUnit() != cu)
37 const QV4::CompiledData::Object *obj = cu->objectAt(objectIndex);
38 for (
auto binding = obj->bindingsBegin(), end = obj->bindingsEnd(); binding != end; ++binding) {
39 switch (binding->type()) {
40 case QV4::CompiledData::Binding::Type_GroupedProperty:
41 case QV4::CompiledData::Binding::Type_AttachedProperty:
42 case QV4::CompiledData::Binding::Type_Object:
43 if (functionBelongsToObject(f, cu, binding->value.objectIndex))
46 case QV4::CompiledData::Binding::Type_Script:
47 if (cu->runtimeFunctions[binding->value.compiledScriptIndex] == f)
60 const std::vector<CompositeLevel> &internalUnits,
63 const QQmlData *ddata = QQmlData::get(target);
67 for (QQmlRefPointer<QQmlContextData> context = ddata->outerContext; context;
68 context = context->parent()) {
69 const QQmlRefPointer<QV4::ExecutableCompilationUnit> ctxCu = context->typeCompilationUnit();
76 if (std::any_of(internalUnits.begin(), internalUnits.end(),
77 [&](
const CompositeLevel &level) {
78 return level.oldCu == ctxCu || level.newCu == ctxCu;
91 const std::vector<CompositeLevel> &internalUnits, QObject *target)
96 for (
const auto &internalUnit : internalUnits) {
97 if (functionBelongsToObject(f, internalUnit.oldCu, internalUnit.objectIndex)
98 || functionBelongsToObject(f, internalUnit.newCu, internalUnit.objectIndex)) {
103 return !rebuildReachesUnitViaContext(f->executableCompilationUnit(), internalUnits, target);
110 const std::vector<CompositeLevel> &internalUnits, QObject *target)
115 for (
const auto &internalUnit : internalUnits) {
116 if (internalUnit.oldCu == cu || internalUnit.newCu == cu)
120 return !rebuildReachesUnitViaContext(cu, internalUnits, target);
128 const std::vector<CompositeLevel> &internalUnits, QObject *target)
133 if (
const QQmlAbstractBinding *abstractBinding = binding.asAbstractBinding()) {
134 switch (abstractBinding->kind()) {
135 case QQmlAbstractBinding::QmlBinding: {
136 const auto *qmlBinding =
static_cast<
const QQmlBinding *>(abstractBinding);
137 if (
const QV4::Function *f = qmlBinding->function())
138 return isExternalFunction(f, internalUnits, target);
140 return isExternalUnitBinding(qmlBinding->compilationUnit(), internalUnits, target);
142 case QQmlAbstractBinding::ValueTypeProxy: {
145 const auto *proxy =
static_cast<
const QQmlValueTypeProxyBinding *>(abstractBinding);
146 for (QQmlAbstractBinding *sub = proxy->subBindings(); sub; sub = sub->nextBinding()) {
147 if (sub->kind() != QQmlAbstractBinding::QmlBinding)
149 if (!isExternalFunction(
static_cast<
const QQmlBinding *>(sub)->function(),
150 internalUnits, target)) {
156 case QQmlAbstractBinding::PropertyToPropertyBinding:
162 if (
const QPropertyBindingPrivate *priv =
163 QPropertyBindingPrivate::get(binding.asUntypedPropertyBinding())) {
164 if (priv->isQmlBinding()) {
166 const auto base =
static_cast<
const QQmlPropertyBindingBase *>(priv);
167 if (base->bindingKind() == QQmlPropertyBindingBase::BindingKind::JavaScript) {
168 if (
const QQmlPropertyBindingJS *jsExpr =
169 static_cast<
const QQmlPropertyBinding *>(base)->jsExpression()) {
170 return isExternalFunction(jsExpr->function(), internalUnits, target);
173 }
else if (
const auto cu = QQmlTranslationPropertyBinding::compilationUnit(priv)) {
177 return isExternalUnitBinding(cu, internalUnits, target);
186 if (
const QQmlAbstractBinding *abstractBinding = binding.asAbstractBinding()) {
187 if (abstractBinding->kind() == QQmlAbstractBinding::PropertyToPropertyBinding) {
188 return static_cast<
const QQmlPropertyToUnbindablePropertyBinding *>(abstractBinding)
191 }
else if (
const QPropertyBindingPrivate *priv =
192 QPropertyBindingPrivate::get(binding.asUntypedPropertyBinding());
193 priv && priv->isQmlBinding()) {
194 const auto base =
static_cast<
const QQmlPropertyBindingBase *>(priv);
195 if (base->bindingKind() == QQmlPropertyBindingBase::BindingKind::PropertyToProperty)
196 return static_cast<
const QQmlPropertyToBindablePropertyBinding *>(priv)->source();
202 const QV4::CompiledData::Binding *binding)
204 switch (binding->type()) {
205 case QV4::CompiledData::Binding::Type_Number: {
206 const double d = unit->bindingValueAsNumber(binding);
207 return QV4::Value::isInt32(d) ? QVariant(
int(d)) : QVariant(d);
209 case QV4::CompiledData::Binding::Type_Boolean:
210 return QVariant(
bool(binding->value.b));
211 case QV4::CompiledData::Binding::Type_Translation:
212 case QV4::CompiledData::Binding::Type_TranslationById:
213 case QV4::CompiledData::Binding::Type_String:
214 return unit->bindingValueAsString(binding);
215 case QV4::CompiledData::Binding::Type_Null:
216 return QVariant::fromValue(
nullptr);
225 const QV4::CompiledData::Binding *binding)
227 return literalBindingValue(unit, binding);
231 QMetaType propertyType)
233 if (propertyType == QMetaType::fromType<QVariant>() || value.metaType() == propertyType)
236 QV4::Scope scope(v4);
237 QV4::ScopedValue v(scope, v4->metaTypeToJS(value.metaType(), value.constData()));
238 QVariant result(propertyType);
239 v4->metaTypeFromJS(v, propertyType, result.data());
244 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
int cuIndex,
245 QHash<QString, QVariant> *constantValues, QDuplicateTracker<QObject *> *seenChildren)
247 Q_ASSERT(constantValues);
249 if (!unit || cuIndex >= unit->objectCount())
252 const QV4::CompiledData::Object *obj = unit->objectAt(cuIndex);
253 const QQmlPropertyCache::ConstPtr cache = unit->propertyCachesPtr()->at(cuIndex);
255 for (
auto binding = obj->bindingsBegin(), end = obj->bindingsEnd(); binding != end; ++binding) {
257 const QString name = targetPropertyName(unit, cuIndex, binding);
261 switch (binding->type()) {
262 case QV4::CompiledData::Binding::Type_AttachedProperty:
263 attachedContext(unit, binding, seenChildren);
265 case QV4::CompiledData::Binding::Type_GroupedProperty:
266 childContext(unit, cuIndex, binding, seenChildren);
272 if (unit->bindingIsSignalHandler(cuIndex,
int(binding - obj->bindingsBegin())))
275 if (unit->bindingIsCustomParser(cuIndex,
int(binding - obj->bindingsBegin())))
278 const qsizetype size = constantValues->size();
279 QVariant &value = (*constantValues)[name];
280 if (constantValues->size() == size)
286 value = literalBindingValue(unit, binding);
289 for (
int propertyIndex = 0, end = obj->propertyCount(); propertyIndex != end; ++propertyIndex) {
290 const qsizetype size = constantValues->size();
292 (*constantValues)[unit->stringAt(obj->propertyTable()[propertyIndex].nameIndex())];
293 if (constantValues->size() != size)
294 value = QVariant(cache->property(cache->propertyOffset() + propertyIndex)->propType());
299 QDuplicateTracker<QObject *> *seenChildren)
302 QHash<QString, QVariant> constantValues;
303 recordBindingValues(unit, objectIndex, &constantValues, seenChildren);
305 if (prefix.isEmpty()) {
306 const QQmlData *ddata = QQmlData::get(m_object);
307 if (ddata->compilationUnit) {
308 recordBindingValues(ddata->compilationUnit, ddata->cuObjectIndex, &constantValues,
312 if (ddata->hasVMEMetaObject) {
313 for (QQmlVMEMetaObject *vmeMeta =
static_cast<QQmlVMEMetaObject *>(
314 QObjectPrivate::get(m_object)->metaObject);
315 vmeMeta; vmeMeta = vmeMeta->parentVMEMetaObject()) {
316 if (
auto cu = vmeMeta->compilationUnit())
317 recordBindingValues(cu, vmeMeta->qmlObjectId(), &constantValues, seenChildren);
327 const QMetaObject *mo = m_object->metaObject();
328 for (
int i = 0, count = mo->propertyCount(); i < count; ++i) {
329 const QMetaProperty metaProp = mo->property(i);
330 const QString propName = QString::fromUtf8(metaProp.name());
332 const QQmlProperty qProp(m_object, propName);
333 if (!qProp.isValid())
339 if (qProp.propertyMetaType().flags().testFlag(QMetaType::PointerToQObject)) {
340 if (QObject *child = qProp.read().value<QObject *>()) {
341 if (QQmlData *childDdata = QQmlData::get(child)) {
342 if (
const auto &childCU = childDdata->compilationUnit; childCU
343 && std::find_if(internalUnits.begin(), internalUnits.end(),
344 [&](
const CompositeLevel &level) {
345 return level.newCu == childCU || level.oldCu == childCU;
347 != internalUnits.end()) {
348 childContext(propName, child, childCU, childDdata->cuObjectIndex,
355 const auto it = constantValues.constFind(propName);
356 if (it == constantValues.cend()) {
358 const QQmlAnyBinding binding = QQmlAnyBinding::ofProperty(qProp);
359 if (isExternalBinding(binding, internalUnits, m_object)) {
360 QQmlAnyBinding taken = QQmlAnyBinding::takeFrom(qProp);
361 m_storedBindings.push_back(
362 { propName, std::move(taken), propertyToPropertySource(binding) });
368 const QQmlAnyBinding binding = QQmlAnyBinding::ofProperty(qProp);
369 if (isExternalBinding(binding, internalUnits, m_object)) {
370 QQmlAnyBinding taken = QQmlAnyBinding::takeFrom(qProp);
371 m_storedBindings.push_back(
372 { propName, std::move(taken), propertyToPropertySource(binding) });
381 if (!it->isValid()) {
391 const QVariant expected = coerceToPropertyType(unit->engine, *it, qProp.propertyMetaType());
392 if (
const QVariant current = qProp.read(); current != expected)
393 m_storedValues.push_back({ propName, current });
396 const auto stashBoundSignal = [&](QQmlBoundSignal *boundSignal) {
397 const QByteArray signature =
398 QMetaObjectPrivate::signal(m_object->metaObject(), boundSignal->signalIndex())
400 QQmlNotifierEndpoint *next = boundSignal->nextEndpoint();
401 boundSignal->disconnect();
402 m_storedSignalHandlers.push_back(
403 { QString::fromUtf8(signature), std::unique_ptr<QQmlBoundSignal>(boundSignal) });
412 if (QQmlNotifyList *list = QQmlData::get(m_object)->notifyList.loadRelaxed()) {
419 for (quint16 i = 0, end = list->notifiesSize; i < end; ++i) {
420 for (QQmlNotifierEndpoint *ep = list->notifies[i]; ep;) {
421 if (ep->callbackType() != QQmlNotifierEndpoint::QQmlBoundSignal) {
422 ep = ep->nextEndpoint();
426 QQmlBoundSignal *boundSignal =
static_cast<QQmlBoundSignal *>(ep);
427 QQmlBoundSignalExpression *expr = boundSignal->expression();
429 ep = stashBoundSignal(boundSignal);
433 const QV4::Function *f = expr->function();
435 ep = stashBoundSignal(boundSignal);
439 bool isInternal =
false;
440 for (
const CompositeLevel &internalUnit : internalUnits) {
441 if (functionBelongsToObject(f, internalUnit.oldCu, internalUnit.objectIndex)
442 || functionBelongsToObject(f, internalUnit.newCu,
443 internalUnit.objectIndex)) {
449 ep = isInternal ? ep->nextEndpoint() : stashBoundSignal(boundSignal);
455 for (
auto &[name, child] : m_children) {
457 child->stashExternalState(internalUnits, seenChildren);
469 for (
auto &[name, child] : m_children) {
475 if (!child->prefix.isEmpty()) {
476 child->m_object = m_object;
477 child->refreshObjects();
481 if (QObject *newObj = m_object->property(name.toUtf8()).value<QObject *>())
482 child->m_object = newObj;
484 child->refreshObjects();
494 for (
auto &stored : m_storedBindings) {
502 if (stored.sourceGuard.isNull()) {
504 if (
auto *abstractBinding = stored.binding.asAbstractBinding()) {
505 isPTP = abstractBinding->kind()
506 == QQmlAbstractBinding::PropertyToPropertyBinding;
507 }
else if (
const QPropertyBindingPrivate *priv = QPropertyBindingPrivate::get(
508 stored.binding.asUntypedPropertyBinding())) {
509 const auto base =
static_cast<
const QQmlPropertyBindingBase *>(priv);
510 isPTP = base->bindingKind()
511 == QQmlPropertyBindingBase::BindingKind::PropertyToProperty;
517 QQmlProperty qProp(m_object, stored.propertyName);
518 if (!qProp.isValid())
525 if (
auto *abstractBinding = stored.binding.asAbstractBinding()) {
526 if (abstractBinding->targetObject() != qProp.object())
527 abstractBinding->setTarget(qProp);
530 stored.binding.installOn(qProp);
532 m_storedBindings.clear();
535 for (
auto &stored : m_storedValues) {
536 const QMetaObject *mo = m_object->metaObject();
537 const int idx = mo->indexOfProperty(stored.propertyName.toUtf8().constData());
542 QQmlProperty qProp(m_object, stored.propertyName);
543 if (!qProp.isValid())
545 QQmlAnyBinding currentBinding = QQmlAnyBinding::ofProperty(qProp);
549 mo->property(idx).write(m_object, stored.value);
551 m_storedValues.clear();
555 if (!m_storedSignalHandlers.empty()) {
556 QQmlEngine *engine = unit->engine->qmlEngine();
557 for (
auto &stored : m_storedSignalHandlers) {
558 const QMetaObject *metaObject = m_object->metaObject();
559 const int signalIndex = QMetaObjectPrivate::signalIndex(
560 metaObject->method(metaObject->indexOfSignal(stored.signature.toUtf8())));
561 if (signalIndex >= 0)
562 QQmlData::connectEndpoint(stored.handler.release(), m_object, signalIndex, engine);
565 m_storedSignalHandlers.clear();
568 for (
auto &[name, child] : m_children) {
570 child->restoreExternalState();
579 const QQmlData *ddata = QQmlData::get(object);
581 QQmlContextData *context = ddata->ownContext ? ddata->ownContext.data() : ddata->context;
583 return context->asQQmlContext()->objectForName(name);
588 int objectIndex,
const QV4::CompiledData::Binding *binding,
589 QDuplicateTracker<QObject *> *seenChildren)
591 const QString name = unit->stringAt(binding->propertyNameIndex);
593 const size_t size = m_children.size();
594 std::unique_ptr<BindingPatchContext> &child = m_children[name];
595 if (size == m_children.size())
601 const QByteArray nameUtf8 = name.toUtf8();
602 QObject *groupObject =
nullptr;
603 if (m_object->metaObject()->indexOfProperty(nameUtf8.constData()) >= 0) {
607 groupObject = m_object->property(nameUtf8).value<QObject *>();
608 }
else if (unit->bindingIsDeferred(
609 objectIndex,
int(binding - unit->objectAt(objectIndex)->bindingTable()))) {
617 groupObject = idTarget(m_object, name);
621 if (seenChildren->hasSeen(groupObject))
623 child = std::make_unique<BindingPatchContext>(groupObject, unit,
624 binding->value.objectIndex);
626 child = std::make_unique<BindingPatchContext>(m_object, unit, binding->value.objectIndex,
634 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
635 int objectIndex, QDuplicateTracker<QObject *> *seenChildren)
637 const size_t size = m_children.size();
638 std::unique_ptr<BindingPatchContext> &child = m_children[name];
639 if (size == m_children.size()) {
640 Q_ASSERT(!child || child->m_object == object);
644 if (!seenChildren || seenChildren->hasSeen(object))
647 child = std::make_unique<BindingPatchContext>(object, unit, objectIndex);
653 const QV4::CompiledData::Binding *binding,
654 QDuplicateTracker<QObject *> *seenChildren)
656 const QString name = unit->stringAt(binding->propertyNameIndex);
658 const size_t size = m_children.size();
659 std::unique_ptr<BindingPatchContext> &child = m_children[name];
660 if (size == m_children.size())
666 QV4::ResolvedTypeReference *typeRef = unit->resolvedType(binding->propertyNameIndex);
668 QQmlAttachedPropertiesFunc func =
669 typeRef->type().attachedPropertiesFunction(unit->engine->typeLoader());
672 if (QObject *attached = QQmlData::get(m_object)->attachedProperties()->value(func)) {
673 if (seenChildren->hasSeen(attached))
675 child = std::make_unique<BindingPatchContext>(attached, unit, binding->value.objectIndex);
681 const QV4::CompiledData::Change &change)
683 Q_ASSERT(change.type == QV4::CompiledData::ChangeType::BindingChanged);
685 if (!m_object || objectIndex < 0 || objectIndex >= unit->objectCount())
688 if (objectIndex == change.objectIndex) {
689 patchBinding(newUnit, change);
693 QDuplicateTracker<QObject *> seenChildren;
694 const QV4::CompiledData::Object *obj = unit->objectAt(objectIndex);
695 for (
auto binding = obj->bindingsBegin(), end = obj->bindingsEnd(); binding != end; ++binding) {
697 switch (binding->type()) {
698 case QV4::CompiledData::Binding::Type_GroupedProperty:
699 child = childContext(unit, objectIndex, binding, &seenChildren);
701 case QV4::CompiledData::Binding::Type_AttachedProperty:
702 child = attachedContext(unit, binding, &seenChildren);
707 if (child && child->applyBindingChange(newUnit, change))
715 const std::vector<QQmlRefPointer<QV4::ExecutableCompilationUnit>> &unitsToUnparent,
716 const std::vector<CompositeLevel> &internalUnits)
718 QQmlData *ddata = QQmlData::get(m_object);
720 const auto levelFor = [&internalUnits](
721 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldCu,
int oldIndex) {
722 for (
const CompositeLevel &level : internalUnits) {
723 if (level.oldCu == oldCu && level.objectIndex == oldIndex)
729 const QHash<QQmlAttachedPropertiesFunc, QObject *> *attachedProperties =
730 ddata->hasExtendedData() ? ddata->attachedProperties() :
nullptr;
731 QObjectList children = m_object->children();
735 const auto newEnd = std::remove_if(children.begin(), children.end(), [&](QObject *child) {
736 const QQmlData *childDdata = QQmlData::get(child);
740 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &cu = childDdata->compilationUnit;
744 if (std::find(unitsToUnparent.begin(), unitsToUnparent.end(), cu) == unitsToUnparent.end())
747 if (!attachedProperties)
750 for (QObject *attached : *attachedProperties) {
751 if (attached == child)
757 children.erase(newEnd, children.end());
764 for (QObject *child : children)
765 clearBindingsRecursive(child);
768 resetBindings(unit, objectIndex, level.newCu, level.objectIndex);
770 for (QQmlVMEMetaObject *vmeMeta = ddata->hasVMEMetaObject
771 ?
static_cast<QQmlVMEMetaObject *>(QObjectPrivate::get(m_object)->metaObject)
773 vmeMeta; vmeMeta = vmeMeta->parentVMEMetaObject()) {
774 const CompositeLevel level = levelFor(vmeMeta->compilationUnit(), vmeMeta->qmlObjectId());
775 resetBindings(vmeMeta->compilationUnit(), vmeMeta->qmlObjectId(), level.newCu,
782 while (QQmlBoundSignal *signalHandler = ddata->signalHandlers)
783 delete signalHandler;
788 for (QObject *child : children)
801 const QMetaObject *mo = object->metaObject();
802 if (
const int classInfoIndex = mo->indexOfClassInfo(
"ParentProperty"); classInfoIndex >= 0) {
803 const QMetaClassInfo classInfo = mo->classInfo(classInfoIndex);
804 if (
const int propertyIndex = mo->indexOfProperty(classInfo.value()); propertyIndex >= 0) {
805 const QMetaProperty property = mo->property(propertyIndex);
806 if ((!property.isResettable() || !property.reset(object)) && property.isWritable())
807 property.write(object, QVariant(property.metaType()));
816 QQml_setParent_noEvent(object,
nullptr);
817 QQmlData::markAsDeleted(object);
818 object->deleteLater();
823 QQueue<QObject *> queue;
824 queue.enqueue(object);
826 while (!queue.isEmpty()) {
827 QObject *next = queue.dequeue();
828 queue.append(next->children());
830 QQmlData *ddata = QQmlData::get(next);
834 while (ddata->bindings)
835 QQmlPropertyPrivate::removeBinding(ddata->bindings);
840 const QMetaObject *mo = next->metaObject();
841 for (
int i = 0, n = mo->propertyCount(); i < n; ++i) {
842 if (!ddata->hasBindingBit(i))
844 const QMetaProperty prop = mo->property(i);
845 if (!prop.isBindable())
847 QUntypedBindable bindable = prop.bindable(next);
848 if (bindable.hasBinding())
849 bindable.takeBinding();
855 for (QQmlBoundSignal *sig = ddata->signalHandlers; sig; sig = sig->m_nextSignal)
856 sig->setEnabled(
false);
864 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &unit,
int cuIndex)
866 ReboundBindings bindings;
867 if (!unit || cuIndex < 0 || cuIndex >= unit->objectCount())
870 const QV4::CompiledData::Object *obj = unit->objectAt(cuIndex);
872 for (
auto binding = obj->bindingsBegin(), end = obj->bindingsEnd(); binding != end; ++binding)
873 bindings.insert(BindingPatchContext::targetPropertyName(unit, cuIndex, binding), binding);
880 const QString &name, QV4::CompiledData::Binding::Type type)
882 const QV4::CompiledData::Binding *newBinding = rebound.value(name);
883 return (newBinding && newBinding->type() == type) ? newBinding->value.objectIndex : -1;
887 int objectIndex,
const QV4::CompiledData::Binding *binding,
const QString &name,
888 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
889 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
890 const ReboundBindings &rebound)
892 QQmlProperty prop(m_object, prefix + name);
893 QQmlPropertyIndex propIdx = QQmlPropertyPrivate::propertyIndex(prop);
894 if (propIdx.coreIndex() < 0) {
898 Q_ASSERT(binding->isGroupedProperty());
900 child->resetBindings(
901 oldUnit, binding->value.objectIndex, newUnit,
902 reboundSubObjectIndex(rebound, name,
903 QV4::CompiledData::Binding::Type_GroupedProperty));
908 const QMetaType type = prop.propertyMetaType();
910 const QMetaType::TypeFlags flags = type.flags();
911 if (flags.testFlag(QMetaType::IsQmlList)) {
914 QQmlListReference list = prop.read().value<QQmlListReference>();
917 }
else if (flags.testFlag(QMetaType::PointerToQObject) && binding->isGroupedProperty()) {
919 child->resetBindings(
920 oldUnit, binding->value.objectIndex, newUnit,
921 reboundSubObjectIndex(rebound, name,
922 QV4::CompiledData::Binding::Type_GroupedProperty));
928 if (rebound.contains(name))
931 if ((!prop.isResettable() || !prop.reset()) && prop.isWritable())
932 prop.write(QVariant(type));
936 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &oldUnit,
int cuIndex,
937 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
int newCuIndex)
939 const QV4::CompiledData::Object *obj = oldUnit->objectAt(cuIndex);
941 const ReboundBindings rebound = reboundBindings(newUnit, newCuIndex);
943 for (
auto binding = obj->bindingsBegin(), end = obj->bindingsEnd(); binding != end; ++binding) {
944 const QString name = targetPropertyName(oldUnit, cuIndex, binding);
948 if (binding->isAttachedProperty()) {
951 if (!QQmlData::get(m_object)->hasExtendedData())
955 attached->resetBindings(
956 oldUnit, binding->value.objectIndex, newUnit,
957 reboundSubObjectIndex(rebound, name,
958 QV4::CompiledData::Binding::Type_AttachedProperty));
964 if (oldUnit->bindingIsCustomParser(cuIndex,
int(binding - obj->bindingsBegin())))
968 if (!oldUnit->bindingIsSignalHandler(cuIndex,
int(binding - obj->bindingsBegin())))
969 resetBinding(cuIndex, binding, name, oldUnit, newUnit, rebound);
976 int objectIndex,
const QV4::CompiledData::Binding *binding)
978 if (binding->propertyNameIndex != 0)
979 return unit->stringAt(binding->propertyNameIndex);
980 const QQmlPropertyCache::ConstPtr cache = unit->propertyCachesPtr()->at(objectIndex);
981 return cache ? cache->defaultPropertyName() : QString();
985 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &newUnit,
986 const QV4::CompiledData::Change &change)
988 const QV4::CompiledData::Binding *newBinding =
989 newUnit->objectAt(change.objectIndex)->bindingTable() + change.newIndex;
990 const QVariant newValue = literalBindingValue(newUnit, newBinding);
991 if (!newValue.isValid())
994 const QQmlProperty qProp(m_object,
995 prefix + targetPropertyName(newUnit, change.objectIndex, newBinding));
996 if (!qProp.isValid())
999 QV4::ExecutionEngine *v4 = unit->engine;
1000 const QMetaType metaType = qProp.propertyMetaType();
1002 const QV4::CompiledData::Binding *oldBinding =
1003 unit->objectAt(change.objectIndex)->bindingTable() + change.oldIndex;
1004 const QVariant expectedOld =
1005 coerceToPropertyType(v4, literalBindingValue(unit, oldBinding), metaType);
1006 if (qProp.read() == expectedOld)
1007 qProp.write(coerceToPropertyType(v4, newValue, metaType));
void restoreExternalState()
bool applyBindingChange(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &newUnit, const QV4::CompiledData::Change &change)
void reset(const std::vector< QQmlRefPointer< QV4::ExecutableCompilationUnit > > &unitsToUnparent, const std::vector< CompositeLevel > &internalUnits)
BindingPatchContext * attachedContext(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, const QV4::CompiledData::Binding *binding, QDuplicateTracker< QObject * > *seenChildren)
BindingPatchContext * childContext(const QString &name, QObject *object, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, int objectIndex, QDuplicateTracker< QObject * > *seenChildren)
void stashExternalState(const std::vector< CompositeLevel > &internalUnits, QDuplicateTracker< QObject * > *seenChildren)
BindingPatchContext * childContext(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, int objectIndex, const QV4::CompiledData::Binding *binding, QDuplicateTracker< QObject * > *seenChildren)
static QVariant literalBindingValue(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, const QV4::CompiledData::Binding *binding)
static bool isExternalFunction(const QV4::Function *f, const std::vector< CompositeLevel > &internalUnits, QObject *target)
static QVariant coerceToPropertyType(QV4::ExecutionEngine *v4, const QVariant &value, QMetaType propertyType)
static ReboundBindings reboundBindings(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &unit, int cuIndex)
static bool functionBelongsToObject(const QV4::Function *f, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &cu, int objectIndex)
static QObject * propertyToPropertySource(const QQmlAnyBinding &binding)
static int reboundSubObjectIndex(const ReboundBindings &rebound, const QString &name, QV4::CompiledData::Binding::Type type)
static bool isExternalUnitBinding(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &cu, const std::vector< CompositeLevel > &internalUnits, QObject *target)
static QObject * idTarget(QObject *object, const QString &name)
static bool isExternalBinding(const QQmlAnyBinding &binding, const std::vector< CompositeLevel > &internalUnits, QObject *target)
static bool rebuildReachesUnitViaContext(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &cu, const std::vector< CompositeLevel > &internalUnits, QObject *target)
Combined button and popup list for selecting options.