forked from qt-creator/qt-creator
QmlDesigner: Fix potential crash
The new selected ModelNode (m_selectedNode) was set to early, since we defer the creation of the QML frontend. We have to set m_selectedNode when the QML frontend is actually created. Otherwise, we might access an uninitialized QML frontend. Change-Id: I630b103246c414c737c977e233180723df0c3160 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -389,6 +389,8 @@ void PropertyEditorView::resetView()
|
||||
if (model() == nullptr)
|
||||
return;
|
||||
|
||||
setSelelectedModelNode();
|
||||
|
||||
m_locked = true;
|
||||
|
||||
if (debug)
|
||||
@@ -526,21 +528,16 @@ void PropertyEditorView::removePropertyFromModel(const PropertyName &propertyNam
|
||||
m_locked = false;
|
||||
}
|
||||
|
||||
void PropertyEditorView::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
|
||||
const QList<ModelNode> &lastSelectedNodeList)
|
||||
void PropertyEditorView::selectedNodesChanged(const QList<ModelNode> &,
|
||||
const QList<ModelNode> &)
|
||||
{
|
||||
Q_UNUSED(lastSelectedNodeList);
|
||||
|
||||
if (selectedNodeList.isEmpty())
|
||||
select(ModelNode());
|
||||
else
|
||||
select(selectedNodeList.constFirst());
|
||||
select();
|
||||
}
|
||||
|
||||
void PropertyEditorView::nodeAboutToBeRemoved(const ModelNode &removedNode)
|
||||
{
|
||||
if (m_selectedNode.isValid() && removedNode.isValid() && m_selectedNode == removedNode)
|
||||
select(m_selectedNode.parentProperty().parentModelNode());
|
||||
select();
|
||||
}
|
||||
|
||||
void PropertyEditorView::modelAttached(Model *model)
|
||||
@@ -686,17 +683,27 @@ void PropertyEditorView::nodeIdChanged(const ModelNode& node, const QString& new
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyEditorView::select(const ModelNode &node)
|
||||
void PropertyEditorView::select()
|
||||
{
|
||||
if (m_qmlBackEndForCurrentType)
|
||||
m_qmlBackEndForCurrentType->emitSelectionToBeChanged();
|
||||
|
||||
if (QmlObjectNode(node).isValid())
|
||||
m_selectedNode = node;
|
||||
else
|
||||
delayedResetView();
|
||||
}
|
||||
|
||||
void PropertyEditorView::setSelelectedModelNode()
|
||||
{
|
||||
const auto selectedNodeList = selectedModelNodes();
|
||||
|
||||
m_selectedNode = ModelNode();
|
||||
|
||||
delayedResetView();
|
||||
if (selectedNodeList.isEmpty())
|
||||
return;
|
||||
|
||||
const ModelNode node = selectedNodeList.constFirst();
|
||||
|
||||
if (QmlObjectNode(node).isValid())
|
||||
m_selectedNode = node;
|
||||
}
|
||||
|
||||
bool PropertyEditorView::hasWidget() const
|
||||
|
@@ -105,7 +105,8 @@ private: //functions
|
||||
void updateSize();
|
||||
void setupPanes();
|
||||
|
||||
void select(const ModelNode& node);
|
||||
void select();
|
||||
void setSelelectedModelNode();
|
||||
|
||||
void delayedResetView();
|
||||
void setupQmlBackend();
|
||||
|
Reference in New Issue
Block a user