diff --git a/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml b/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml index 004950eef3a..fb5c69ff71b 100644 --- a/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml +++ b/share/qtcreator/qmldesigner/nodegrapheditor/Main.qml @@ -164,7 +164,14 @@ Item { anchors.centerIn: parent onSave: { + if (NodeGraphEditorBackend.nodeGraphEditorModel.currentFileName != "") { + updateGraphData(); + NodeGraphEditorBackend.nodeGraphEditorModel.saveFile(NodeGraphEditorBackend.nodeGraphEditorModel.currentFileName); + NodeGraphEditorBackend.nodeGraphEditorModel.createQmlComponent(graphView.graph); + } + graphView.graph.clearGraph(); + NodeGraphEditorBackend.nodeGraphEditorModel.currentFileName = fileName; graphView.graph.insertNode(Nodes.Components.material); NodeGraphEditorBackend.nodeGraphEditorModel.createQmlComponent(graphView.graph); updateGraphData(); diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp index 58508381e8e..345a470c389 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.cpp @@ -2492,6 +2492,30 @@ ModelNode handleItemLibraryEffectDrop(const QString &effectPath, const ModelNode return newModelNode; } + +ModelNode handleItemLibraryNodeGraphDrop(const QString &nodeGraphPath, const ModelNode &targetNode) +{ + AbstractView *view = targetNode.view(); + QTC_ASSERT(view, return {}); + ModelNode newMatNode; + + const QString materialName = QFileInfo(nodeGraphPath).baseName(); + QString newId = view->model()->generateNewId(materialName, "material"); + newMatNode = view->createModelNode(materialName.toUtf8(), 1, 0); + newMatNode.setIdWithRefactoring(newId); + VariantProperty objNameProp = newMatNode.variantProperty("objectName"); + objNameProp.setValue(materialName); + ModelNode matLib = Utils3D::materialLibraryNode(view); + if (!matLib.isValid()) + return ModelNode{}; + + matLib.defaultNodeListProperty().reparentHere(newMatNode); + + Utils3D::selectMaterial(newMatNode); + view->resetPuppet(); + return newMatNode; +} + void handleTextureDrop(const QMimeData *mimeData, const ModelNode &targetModelNode) { AbstractView *view = targetModelNode.view(); diff --git a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h index e2bc8980421..a280202ece9 100644 --- a/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h +++ b/src/plugins/qmldesigner/components/componentcore/modelnodeoperations.h @@ -224,6 +224,9 @@ Utils::FilePath getImagesDefaultDirectory(); //Item Library and Assets related drop operations QMLDESIGNERCOMPONENTS_EXPORT ModelNode handleItemLibraryEffectDrop(const QString &effectPath, const ModelNode &targetNode); + +QMLDESIGNERCOMPONENTS_EXPORT ModelNode handleItemLibraryNodeGraphDrop(const QString &nodeGraphPath, + const ModelNode &targetNode); void handleTextureDrop(const QMimeData *mimeData, const ModelNode &targetModelNode); void handleMaterialDrop(const QMimeData *mimeData, const ModelNode &targetNode); ModelNode handleItemLibraryImageDrop(const QString &imagePath, diff --git a/src/plugins/qmldesigner/components/navigator/nameitemdelegate.cpp b/src/plugins/qmldesigner/components/navigator/nameitemdelegate.cpp index 67cf08f01a2..44079e0fa75 100644 --- a/src/plugins/qmldesigner/components/navigator/nameitemdelegate.cpp +++ b/src/plugins/qmldesigner/components/navigator/nameitemdelegate.cpp @@ -234,7 +234,11 @@ void NameItemDelegate::paint(QPainter *painter, Model *model = node.model(); validDrop = isValid3dTextureTarget() || metaInfo.isBasedOn(model->qtQuickImageMetaInfo(), model->qtQuickBorderImageMetaInfo()); - } else { + } else if (dragType == Constants::MIME_TYPE_ASSET_NODEGRAPH) { + Model *model = node.model(); + validDrop = (node.id() == Constants::MATERIAL_LIB_ID); + } + else { const NodeMetaInfo dragInfo = node.model()->metaInfo(dragType); ChooseFromPropertyListFilter *filter = new ChooseFromPropertyListFilter(dragInfo, metaInfo, true); validDrop = !filter->propertyList.isEmpty(); diff --git a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp index d3a057e8edd..9658efd2846 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp @@ -695,6 +695,11 @@ bool NavigatorTreeModel::dropMimeData(const QMimeData *mimeData, assetPath, modelNodeForIndex(rowModelIndex)); moveNodesAfter = false; } + else if (assetType == Constants::MIME_TYPE_ASSET_NODEGRAPH) { + currNode = ModelNodeOperations::handleItemLibraryNodeGraphDrop( + assetPath, modelNodeForIndex(rowModelIndex)); + moveNodesAfter = false; + } if (currNode.isValid()) addedNodes.append(currNode); diff --git a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp index 98d39070c65..bf4efd0bf03 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp @@ -554,6 +554,9 @@ void NavigatorView::dragStarted(QMimeData *mimeData) } else if (assetType == Constants::MIME_TYPE_ASSET_IMAGE) { m_widget->setDragType(Constants::MIME_TYPE_ASSET_IMAGE); m_widget->update(); + } else if (assetType == Constants::MIME_TYPE_ASSET_NODEGRAPH) { + m_widget->setDragType(Constants::MIME_TYPE_ASSET_NODEGRAPH); + m_widget->update(); } } } diff --git a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.cpp b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.cpp index 6f96339905d..ac431d70a14 100644 --- a/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.cpp +++ b/src/plugins/qmldesigner/components/nodegrapheditor/nodegrapheditormodel.cpp @@ -281,6 +281,7 @@ R"(} Utils::FilePath path = DocumentManager::currentResourcePath().pathAppended(m_currentFileName + ".qml"); qCritical() << path.toString(); writeToFile(s.toUtf8(), path.toString(), FileType::Text); + m_editorView->resetPuppet(); }