Improve qml material creation & management

Node graph drag&drop creates material instance
Material updates after qml generation
Fix bug with overwriting node graph data

Change-Id: If25f9c80b239f49042d0b42b32e1973256551030
Reviewed-by: spyro-adb <adb@spyro-soft.com>
This commit is contained in:
Andrzej Biniek
2024-12-19 22:51:41 +01:00
committed by spyro-adb
parent af4a816086
commit 2b55b046ae
7 changed files with 48 additions and 1 deletions

View File

@@ -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();

View File

@@ -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();

View File

@@ -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,

View File

@@ -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();

View File

@@ -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);

View File

@@ -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();
}
}
}

View File

@@ -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();
}