Commit dcafe3c8 authored by Marco Bubke's avatar Marco Bubke Committed by Kai Koehne
Browse files

Fix crash for lasting Ids

Now we remove the Id on removing the object.

Task-Number: BAUHAUS-552
parent e113814a
......@@ -111,6 +111,7 @@ public:
private slots:
void emitParentChanged(QObject *child);
void refreshLocalFileProperty(const QString &path);
void removeIdFromContext(QObject *object);
private: // functions
NodeInstance rootNodeInstance() const;
......@@ -126,7 +127,7 @@ private: // functions
void insertInstanceNodeRelationship(const ModelNode &node, const NodeInstance &instance);
void removeInstanceNodeRelationship(const ModelNode &node);
QDeclarativeEngine *engine() const;
QDeclarativeEngine *engine();
Internal::ChildrenChangeEventFilter *childrenChangeEventFilter();
void removeInstanceAndSubInstances(const ModelNode &node);
......
......@@ -190,6 +190,8 @@ NodeInstance NodeInstance::create(NodeInstanceView *nodeInstanceView, const Mode
instance.setId(node.id());
QObject::connect(instance.internalObject(), SIGNAL(destroyed(QObject*)), nodeInstanceView, SLOT(removeIdFromContext(QObject*)));
foreach (const VariantProperty &property, node.variantProperties()) {
if (property.isDynamic())
instance.setPropertyDynamicVariant(property.name(), property.dynamicTypeName(), property.value());
......
......@@ -92,18 +92,11 @@ d too.
NodeInstanceView::NodeInstanceView(QObject *parent)
: AbstractView(parent),
m_graphicsView(new QGraphicsView),
m_engine(new QDeclarativeEngine(this)),
m_blockStatePropertyChanges(false)
{
m_graphicsView->setAttribute(Qt::WA_DontShowOnScreen, true);
m_graphicsView->setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
m_graphicsView->setScene(new QGraphicsScene(m_graphicsView.data()));
Q_ASSERT(!m_engine.isNull());
QDeclarativeEnginePrivate *privateQDeclarativeEngine = QDeclarativeEnginePrivate::get(m_engine.data());
Q_ASSERT(privateQDeclarativeEngine);
privateQDeclarativeEngine->scriptEngine.setProcessEventsInterval(100);
}
......@@ -135,6 +128,7 @@ void NodeInstanceView::modelAboutToBeDetached(Model * model)
{
removeAllInstanceNodeRelationships();
AbstractView::modelAboutToBeDetached(model);
delete m_engine.data();
}
......@@ -526,8 +520,10 @@ void NodeInstanceView::insertInstanceNodeRelationship(const ModelNode &node, con
m_objectInstanceHash.insert(instance.internalObject(), instance);
}
QDeclarativeEngine *NodeInstanceView::engine() const
QDeclarativeEngine *NodeInstanceView::engine()
{
if (m_engine.isNull())
m_engine = new QDeclarativeEngine(this);
return m_engine.data();
}
......@@ -545,6 +541,7 @@ void NodeInstanceView::removeInstanceNodeRelationship(const ModelNode &node)
{
Q_ASSERT(m_nodeInstanceHash.contains(node));
NodeInstance instance = instanceForNode(node);
removeIdFromContext(instance.internalObject());
m_objectInstanceHash.remove(instanceForNode(node).internalObject());
m_nodeInstanceHash.remove(node);
instance.makeInvalid();
......@@ -698,4 +695,14 @@ void NodeInstanceView::refreshLocalFileProperty(const QString &path)
}
}
void NodeInstanceView::removeIdFromContext(QObject *object)
{
if (hasInstanceForObject(object)) {
NodeInstance instance = instanceForObject(object);
QString id = instance.modelNode().id();
if (!id.isEmpty())
engine()->rootContext()->setContextProperty(id, 0);
}
}
}
......@@ -128,16 +128,14 @@ void ObjectNodeInstance::destroy()
}
}
if (!m_id.isEmpty()) {
context()->engine()->rootContext()->setContextProperty(m_id, 0);
}
if (object()) {
QObject *obj = object();
m_object.clear();
delete obj;
}
}
m_metaObject = 0;
}
ModelNode ObjectNodeInstance::modelNode() const
......
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