From a734e1b4e865209b3364e0a98c9ace3e87d244fe Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Thu, 2 Jun 2022 13:03:26 +0200 Subject: [PATCH] QmlDesigner: Move reparenting of materials into transaction Without a transaction we will reparse the document for each reparent. This will make the process very slow if there are e.g. 20 materials in the document. The new parent has to be created first. This cannot be part of the same transaction, because of limiations in the rewriter. Change-Id: Ie2c587d0f072b8163846c660dc2dd66bee7146c1 Reviewed-by: Mahmoud Badri --- .../materialeditor/materialeditorview.cpp | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp index 33d7b67b784..4a9487d9239 100644 --- a/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp +++ b/src/plugins/qmldesigner/components/materialeditor/materialeditorview.cpp @@ -99,16 +99,23 @@ void MaterialEditorView::ensureMaterialLibraryNode() m_materialLibrary.setIdWithoutRefactoring(Constants::MATERIAL_LIB_ID); rootModelNode().defaultNodeListProperty().reparentHere(m_materialLibrary); - // move all materials to under material library node - for (const ModelNode &node : materials) { - // if material has no name, set name to id - QString matName = node.variantProperty("objectName").value().toString(); - if (matName.isEmpty()) { - VariantProperty objNameProp = node.variantProperty("objectName"); - objNameProp.setValue(node.id()); - } + RewriterTransaction transaction = beginRewriterTransaction( + "MaterialEditorView::ensureMaterialLibraryNode"); - m_materialLibrary.defaultNodeListProperty().reparentHere(node); + try { + // move all materials to under material library node + for (const ModelNode &node : materials) { + // if material has no name, set name to id + QString matName = node.variantProperty("objectName").value().toString(); + if (matName.isEmpty()) { + VariantProperty objNameProp = node.variantProperty("objectName"); + objNameProp.setValue(node.id()); + } + + m_materialLibrary.defaultNodeListProperty().reparentHere(node); + } + } catch (Exception &e) { + e.showException(); } }