forked from qt-creator/qt-creator
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user