Enable Copy, Cut, and Paste in the Editor 3D

Task-number: QDS-1563
Change-Id: I22c3017b8c158d8bc084f050baef89fa8fffd365
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2020-03-12 15:55:30 +02:00
parent 38458c3e40
commit 11bd2f8deb
13 changed files with 108 additions and 23 deletions

View File

@@ -35,6 +35,8 @@
#include <qmldesignerplugin.h>
#include <viewmanager.h>
#include <nodeinstanceview.h>
#include "qmldesignerconstants.h"
#include "qmlvisualnode.h"
#include <projectexplorer/projecttree.h>
#include <projectexplorer/project.h>
@@ -44,6 +46,7 @@
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtsupportconstants.h>
#include <qtsupport/qtversionmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <coreplugin/editormanager/editormanager.h>
@@ -449,7 +452,7 @@ void DesignDocument::paste()
if (rootNode.type() == "empty")
return;
if (rootNode.id() == "designer__Selection") {
if (rootNode.id() == "designer__Selection") { // pasting multiple objects
currentModel()->attachView(&view);
ModelNode targetNode;
@@ -458,8 +461,22 @@ void DesignDocument::paste()
targetNode = view.selectedModelNodes().constFirst();
//In case we copy and paste a selection we paste in the parent item
if ((view.selectedModelNodes().count() == selectedNodes.count()) && targetNode.isValid() && targetNode.hasParentProperty())
if ((view.selectedModelNodes().count() == selectedNodes.count()) && targetNode.isValid() && targetNode.hasParentProperty()) {
targetNode = targetNode.parentProperty().parentModelNode();
} else {
// if selection is empty and copied nodes are all 3D nodes, paste them under the active scene
bool all3DNodes = std::find_if(selectedNodes.begin(), selectedNodes.end(),
[](const ModelNode &node) { return !node.isSubclassOf("QtQuick3D.Node"); })
== selectedNodes.end();
if (all3DNodes) {
int activeSceneId = rootModelNode().auxiliaryData("3d-active-scene").toInt();
if (activeSceneId != -1) {
NodeListProperty sceneNodeProperty
= QmlVisualNode::findSceneNodeProperty(rootModelNode().view(), activeSceneId);
targetNode = sceneNodeProperty.parentModelNode();
}
}
}
if (!targetNode.isValid())
targetNode = view.rootModelNode();
@@ -487,24 +504,35 @@ void DesignDocument::paste()
view.setSelectedModelNodes(pastedNodeList);
});
} else {
rewriterView()->executeInTransaction("DesignDocument::paste1", [this, &view, selectedNodes, rootNode](){
} else { // pasting single object
rewriterView()->executeInTransaction("DesignDocument::paste1", [this, &view, selectedNodes, rootNode]() {
currentModel()->attachView(&view);
ModelNode pastedNode(view.insertModel(rootNode));
ModelNode targetNode;
if (!view.selectedModelNodes().isEmpty())
if (!view.selectedModelNodes().isEmpty()) {
targetNode = view.selectedModelNodes().constFirst();
} else {
// if selection is empty and this is a 3D Node, paste it under the active scene
if (pastedNode.isSubclassOf("QtQuick3D.Node")) {
int activeSceneId = rootModelNode().auxiliaryData("3d-active-scene").toInt();
if (activeSceneId != -1) {
NodeListProperty sceneNodeProperty
= QmlVisualNode::findSceneNodeProperty(rootModelNode().view(), activeSceneId);
targetNode = sceneNodeProperty.parentModelNode();
}
}
}
if (!targetNode.isValid())
targetNode = view.rootModelNode();
if (targetNode.hasParentProperty() &&
(pastedNode.simplifiedTypeName() == targetNode.simplifiedTypeName()) &&
(pastedNode.variantProperty("width").value() == targetNode.variantProperty("width").value()) &&
(pastedNode.variantProperty("height").value() == targetNode.variantProperty("height").value()))
pastedNode.simplifiedTypeName() == targetNode.simplifiedTypeName() &&
pastedNode.variantProperty("width").value() == targetNode.variantProperty("width").value() &&
pastedNode.variantProperty("height").value() == targetNode.variantProperty("height").value()) {
targetNode = targetNode.parentProperty().parentModelNode();
}
PropertyName defaultProperty(targetNode.metaInfo().defaultPropertyName());