Commit 0a62a383 authored by Marco Bubke's avatar Marco Bubke
Browse files

Improve Copy and Paste in Bauhaus

Now the items are pasted to the parent of selected node. It is too
selected after the paste.

Reviewed-by: Kai Koehne
parent e5e3c24e
...@@ -627,13 +627,18 @@ void DesignDocumentController::paste() ...@@ -627,13 +627,18 @@ void DesignDocumentController::paste()
model->detachView(&view); model->detachView(&view);
m_d->model->attachView(&view); m_d->model->attachView(&view);
ModelNode selectedNode; ModelNode targetNode;
if (!view.selectedModelNodes().isEmpty()) if (!view.selectedModelNodes().isEmpty())
selectedNode = view.selectedModelNodes().first(); targetNode = view.selectedModelNodes().first();
if (!targetNode.isValid())
targetNode = view.rootModelNode();
if (targetNode.parentProperty().isValid())
targetNode = targetNode.parentProperty().parentModelNode();
if (!selectedNode.isValid())
selectedNode = view.rootModelNode();
foreach (const ModelNode &node, selectedNodes) { foreach (const ModelNode &node, selectedNodes) {
foreach (const ModelNode &node2, selectedNodes) { foreach (const ModelNode &node2, selectedNodes) {
if (node.isAncestorOf(node2)) if (node.isAncestorOf(node2))
...@@ -641,25 +646,36 @@ void DesignDocumentController::paste() ...@@ -641,25 +646,36 @@ void DesignDocumentController::paste()
} }
} }
QList<ModelNode> pastedNodeList;
foreach (const ModelNode &node, selectedNodes) { foreach (const ModelNode &node, selectedNodes) {
QString defaultProperty(selectedNode.metaInfo().defaultProperty()); QString defaultProperty(targetNode.metaInfo().defaultProperty());
ModelNode pastedNode(view.insertModel(node)); ModelNode pastedNode(view.insertModel(node));
selectedNode.nodeListProperty(defaultProperty).reparentHere(pastedNode); pastedNodeList.append(pastedNode);
targetNode.nodeListProperty(defaultProperty).reparentHere(pastedNode);
} }
view.setSelectedModelNodes(pastedNodeList);
} else { } else {
model->detachView(&view); model->detachView(&view);
m_d->model->attachView(&view); m_d->model->attachView(&view);
ModelNode pastedNode(view.insertModel(rootNode)); ModelNode pastedNode(view.insertModel(rootNode));
ModelNode selectedNode; ModelNode targetNode;
if (!view.selectedModelNodes().isEmpty()) if (!view.selectedModelNodes().isEmpty())
selectedNode = view.selectedModelNodes().first(); targetNode = view.selectedModelNodes().first();
if (!targetNode.isValid())
targetNode = view.rootModelNode();
if (targetNode.parentProperty().isValid())
targetNode = targetNode.parentProperty().parentModelNode();
QString defaultProperty(targetNode.metaInfo().defaultProperty());
targetNode.nodeListProperty(defaultProperty).reparentHere(pastedNode);
if (!selectedNode.isValid())
selectedNode = view.rootModelNode();
QString defaultProperty(selectedNode.metaInfo().defaultProperty());
selectedNode.nodeListProperty(defaultProperty).reparentHere(pastedNode);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment