QmlDesigner: fixes crash in nodeinstances

There was a subtle bug in propertyReseting() that caused a gradient
property of a Rectangle not to be removed, if the gradient was deleted.
Deleting the gradient triggered a reparenting operation in the
nodeinstances where the resetProperty() of the oldParent was not
executed properly.

This caused a dangling pointer in QDeclarativeRectangle.

Reviewed-by: Marco Bubke
This commit is contained in:
Thomas Hartmann
2010-04-19 15:16:36 +02:00
parent 4ca6422bd7
commit 981ce88008
3 changed files with 10 additions and 9 deletions

View File

@@ -153,7 +153,6 @@ void NodeInstanceView::nodeAboutToBeRemoved(const ModelNode &removedNode)
void NodeInstanceView::nodeRemoved(const ModelNode &/*removedNode*/, const NodeAbstractProperty &/*parentProperty*/, PropertyChangeFlags /*propertyChange*/) void NodeInstanceView::nodeRemoved(const ModelNode &/*removedNode*/, const NodeAbstractProperty &/*parentProperty*/, PropertyChangeFlags /*propertyChange*/)
{ {
} }
/*! \brief Notifing the view that a AbstractProperty was added to a ModelNode. /*! \brief Notifing the view that a AbstractProperty was added to a ModelNode.

View File

@@ -375,7 +375,9 @@ void ObjectNodeInstance::removeFromOldProperty(QObject *object, QObject *oldPare
if (isList(metaProperty)) { if (isList(metaProperty)) {
removeObjectFromList(metaProperty, object, nodeInstanceView()->engine()); removeObjectFromList(metaProperty, object, nodeInstanceView()->engine());
} else if (isObject(metaProperty)) { } else if (isObject(metaProperty)) {
resetProperty(object, oldParentProperty); if (nodeInstanceView()->hasInstanceForObject(oldParent)) {
nodeInstanceView()->instanceForObject(oldParent).resetProperty(oldParentProperty);
}
} }
object->setParent(0); object->setParent(0);
@@ -500,13 +502,13 @@ void ObjectNodeInstance::deleteObjectsInList(const QDeclarativeProperty &metaPro
void ObjectNodeInstance::resetProperty(const QString &name) void ObjectNodeInstance::resetProperty(const QString &name)
{ {
resetProperty(object(), name); doResetProperty(name);
if (name == "font.pixelSize") if (name == "font.pixelSize")
resetProperty(object(), "font.pointSize"); doResetProperty("font.pointSize");
if (name == "font.pointSize") if (name == "font.pointSize")
resetProperty(object(), "font.pixelSize"); doResetProperty("font.pixelSize");
} }
NodeInstance ObjectNodeInstance::instanceForNode(const ModelNode &node, const QString &fullname) NodeInstance ObjectNodeInstance::instanceForNode(const ModelNode &node, const QString &fullname)
@@ -543,11 +545,11 @@ void ObjectNodeInstance::refreshProperty(const QString &name)
property.write(oldValue); property.write(oldValue);
} }
void ObjectNodeInstance::resetProperty(QObject *object, const QString &propertyName) void ObjectNodeInstance::doResetProperty(const QString &propertyName)
{ {
m_modelAbstractPropertyHash.remove(propertyName); m_modelAbstractPropertyHash.remove(propertyName);
QDeclarativeProperty metaProperty(object, propertyName, context()); QDeclarativeProperty metaProperty(object(), propertyName, context());
if (!metaProperty.isValid()) if (!metaProperty.isValid())
return; return;
@@ -557,7 +559,7 @@ void ObjectNodeInstance::resetProperty(QObject *object, const QString &propertyN
QUrl url = oldValue.toUrl(); QUrl url = oldValue.toUrl();
QString path = url.toLocalFile(); QString path = url.toLocalFile();
if (QFileInfo(path).exists() && nodeInstanceView()) if (QFileInfo(path).exists() && nodeInstanceView())
nodeInstanceView()->removeFilePropertyFromFileSystemWatcher(object, propertyName, path); nodeInstanceView()->removeFilePropertyFromFileSystemWatcher(object(), propertyName, path);
} }

View File

@@ -171,7 +171,7 @@ public:
protected: protected:
static QObject* createObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context); static QObject* createObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context);
void resetProperty(QObject *object, const QString &propertyName); void doResetProperty(const QString &propertyName);
NodeInstance instanceForNode(const ModelNode &node, const QString &fullname); NodeInstance instanceForNode(const ModelNode &node, const QString &fullname);
void removeFromOldProperty(QObject *object, QObject *oldParent, const QString &oldParentProperty); void removeFromOldProperty(QObject *object, QObject *oldParent, const QString &oldParentProperty);