Commit 41445b4c authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.instances: fix NodeInstance::parent()

We iterare now over all parents until we find
an instance
parent 8af7efa3
......@@ -59,6 +59,7 @@ namespace Internal {
class ObjectNodeInstance;
class QmlGraphicsItemNodeInstance;
class QmlPropertyChangesNodeInstance;
class GraphicsObjectNodeInstance;
class QmlStateNodeInstance;
}
......@@ -72,6 +73,7 @@ class CORESHARED_EXPORT NodeInstance
friend CORESHARED_EXPORT bool operator==(const NodeInstance &first, const NodeInstance &second);
friend CORESHARED_EXPORT class NodeMetaInfo;
friend class QmlDesigner::Internal::QmlGraphicsItemNodeInstance;
friend class QmlDesigner::Internal::GraphicsObjectNodeInstance;
friend class QmlDesigner::Internal::ObjectNodeInstance;
friend class QmlDesigner::Internal::QmlPropertyChangesNodeInstance;
friend class QmlDesigner::Internal::QmlStateNodeInstance;
......
......@@ -251,7 +251,6 @@ void NodeInstance::reparent(const NodeInstance &oldParentInstance, const QString
m_nodeInstance->reparent(oldParentInstance, oldParentProperty, newParentInstance, newParentProperty);
}
/*!
\brief Returns the parent NodeInstance of this NodeInstance.
......@@ -261,7 +260,7 @@ void NodeInstance::reparent(const NodeInstance &oldParentInstance, const QString
*/
NodeInstance NodeInstance::parent() const
{
return m_nodeInstance->nodeInstanceView()->instanceForObject(m_nodeInstance->parent());
return m_nodeInstance->nodeInstanceParentForObject(m_nodeInstance->parent());
}
bool NodeInstance::hasParent() const
......
......@@ -962,6 +962,30 @@ bool ObjectNodeInstance::resetStateProperty(const NodeInstance &/*target*/, cons
return false;
}
NodeInstance ObjectNodeInstance::nodeInstanceParentForObject(QObject *currentObject) const
{
if (!currentObject) //this should not happen! warning?
return NodeInstance();
if (nodeInstanceView()->hasInstanceForObject(currentObject))
return nodeInstanceView()->instanceForObject(currentObject);
//Maybe the object has been reparented inside a component and we
//do not keep track of the parent?
//In this case we iterate until we find a parent we keep track of,
//parent() gets 0
QObject* parentObject;
QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(currentObject);
if (graphicsObject)
parentObject = graphicsObject->parentItem()->toGraphicsObject();
else
parentObject = currentObject->parent();
return nodeInstanceParentForObject(parentObject);
}
}
}
......@@ -175,6 +175,8 @@ public:
static void removeAnimationsFromComponents(QObject *object, QObjectList &inspectedObjectList);
NodeInstance nodeInstanceParentForObject(QObject *currentObject) const;
protected:
static QObject *createInstance(const NodeMetaInfo &metaInfo, QDeclarativeContext *parentContext);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment