diff --git a/src/plugins/qmldesigner/core/instances/objectnodeinstance.cpp b/src/plugins/qmldesigner/core/instances/objectnodeinstance.cpp index eaf255ef83357a8368bcee2b3cfecf8bfe96da11..93c41d9f8bf228c910956567f7fa7c0df0411c8f 100644 --- a/src/plugins/qmldesigner/core/instances/objectnodeinstance.cpp +++ b/src/plugins/qmldesigner/core/instances/objectnodeinstance.cpp @@ -106,27 +106,30 @@ static void specialRemoveParentForQmlGraphicsItemChildren(QObject *object) void ObjectNodeInstance::destroy() { - // Remove from old property - if (object() && modelNode().isValid() && modelNode().parentProperty().isValid()) { - NodeAbstractProperty parentProperty = modelNode().parentProperty(); - ModelNode parentNode = parentProperty.parentModelNode(); - if (parentNode.isValid() && nodeInstanceView()->hasInstanceForNode(parentNode)) { - NodeInstance parentInstance = nodeInstanceView()->instanceForNode(parentNode); - if (parentInstance.isQmlGraphicsItem() && isChildrenProperty(parentProperty.name())) { - specialRemoveParentForQmlGraphicsItemChildren(object()); - } else { - removeFromOldProperty(object(), parentInstance.internalObject(), parentProperty.name()); + if (deleteHeldInstance()) { + // Remove from old property + if (object() && modelNode().isValid() && modelNode().parentProperty().isValid()) { + NodeAbstractProperty parentProperty = modelNode().parentProperty(); + ModelNode parentNode = parentProperty.parentModelNode(); + if (parentNode.isValid() && nodeInstanceView()->hasInstanceForNode(parentNode)) { + NodeInstance parentInstance = nodeInstanceView()->instanceForNode(parentNode); + if (parentInstance.isQmlGraphicsItem() && isChildrenProperty(parentProperty.name())) { + specialRemoveParentForQmlGraphicsItemChildren(object()); + } else { + removeFromOldProperty(object(), parentInstance.internalObject(), parentProperty.name()); + } } } - } - if (deleteHeldInstance() && object()) { - if (!object()->objectName().isEmpty()) { - context()->engine()->rootContext()->setContextProperty(object()->objectName(), 0); + if (!m_id.isEmpty()) { + context()->engine()->rootContext()->setContextProperty(m_id, 0); + } + + if (object()) { + QObject *obj = object(); + m_object.clear(); + delete obj; } - QObject *obj = object(); - m_object.clear(); - delete obj; } } @@ -152,15 +155,15 @@ void ObjectNodeInstance::setNodeInstance(NodeInstanceView *view) void ObjectNodeInstance::setId(const QString &id) { - if (!object()->objectName().isEmpty()) { - context()->engine()->rootContext()->setContextProperty(object()->objectName(), 0); + if (!m_id.isEmpty()) { + context()->engine()->rootContext()->setContextProperty(m_id, 0); } if (!id.isEmpty()) { context()->engine()->rootContext()->setContextProperty(id, object()); // will also force refresh of all bindings } - object()->setObjectName(id); + m_id = id; } bool ObjectNodeInstance::isQmlGraphicsItem() const diff --git a/src/plugins/qmldesigner/core/instances/objectnodeinstance.h b/src/plugins/qmldesigner/core/instances/objectnodeinstance.h index 10ddef70472feb228e42612008dd17a273e3c862..c1e639a2a1014c8fe4206d54c3f20b8ea66bcef9 100644 --- a/src/plugins/qmldesigner/core/instances/objectnodeinstance.h +++ b/src/plugins/qmldesigner/core/instances/objectnodeinstance.h @@ -174,6 +174,7 @@ private: QHash<QString, QVariant> m_resetValueHash; QHash<QString, NodeInstance> m_modelAbstractPropertyHash; ModelNode m_modelNode; + QString m_id; QWeakPointer<NodeInstanceView> m_nodeInstanceView; bool m_deleteHeldInstance;