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 <mahmoud.badri@qt.io>
This commit is contained in:
Thomas Hartmann
2022-06-02 13:03:26 +02:00
parent 87b0f2a354
commit a734e1b4e8

View File

@@ -99,6 +99,10 @@ void MaterialEditorView::ensureMaterialLibraryNode()
m_materialLibrary.setIdWithoutRefactoring(Constants::MATERIAL_LIB_ID);
rootModelNode().defaultNodeListProperty().reparentHere(m_materialLibrary);
RewriterTransaction transaction = beginRewriterTransaction(
"MaterialEditorView::ensureMaterialLibraryNode");
try {
// move all materials to under material library node
for (const ModelNode &node : materials) {
// if material has no name, set name to id
@@ -110,6 +114,9 @@ void MaterialEditorView::ensureMaterialLibraryNode()
m_materialLibrary.defaultNodeListProperty().reparentHere(node);
}
} catch (Exception &e) {
e.showException();
}
}
MaterialEditorView::~MaterialEditorView()