From 0a62a383bd59d8326e37e59d888f6e1de62a0946 Mon Sep 17 00:00:00 2001
From: Marco Bubke <marco.bubke@nokia.com>
Date: Mon, 8 Feb 2010 15:05:41 +0100
Subject: [PATCH] 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
---
 .../integration/designdocumentcontroller.cpp  | 40 +++++++++++++------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp
index bd0e94a3d25..9dcf8686d6b 100644
--- a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp
+++ b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp
@@ -627,13 +627,18 @@ void DesignDocumentController::paste()
         model->detachView(&view);
         m_d->model->attachView(&view);
 
-        ModelNode selectedNode;
+        ModelNode targetNode;
 
         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 &node2, selectedNodes) {
                 if (node.isAncestorOf(node2))
@@ -641,25 +646,36 @@ void DesignDocumentController::paste()
             }
 
         }
+
+        QList<ModelNode> pastedNodeList;
+
         foreach (const ModelNode &node, selectedNodes) {
-            QString defaultProperty(selectedNode.metaInfo().defaultProperty());
+            QString defaultProperty(targetNode.metaInfo().defaultProperty());
             ModelNode pastedNode(view.insertModel(node));
-            selectedNode.nodeListProperty(defaultProperty).reparentHere(pastedNode);
+            pastedNodeList.append(pastedNode);
+            targetNode.nodeListProperty(defaultProperty).reparentHere(pastedNode);
         }
+
+        view.setSelectedModelNodes(pastedNodeList);
     } else {
         model->detachView(&view);
         m_d->model->attachView(&view);
         ModelNode pastedNode(view.insertModel(rootNode));
-        ModelNode selectedNode;
+        ModelNode targetNode;
 
         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);
     }
 }
 
-- 
GitLab