forked from qt-creator/qt-creator
QmlDesigner: Ensure material library is created when needed
Added material library accessor to AbstractView, which creates the material library and moves existing materials under it in case it doesn't yet exist. Also added material assignment function to AbstractView. The reason these were added to AbstractView instead of being handled e.g. via custom notification in material editor is that they need to be called from multiple different views in the same transaction that triggers the need of material library. Fixes: QDS-7081 Change-Id: If2bb884f87d04c9f3599c2342df66ef51ec238ee Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -186,42 +186,17 @@ void Edit3DCanvas::dragEnterEvent(QDragEnterEvent *e)
|
||||
|
||||
void Edit3DCanvas::dropEvent(QDropEvent *e)
|
||||
{
|
||||
auto modelNode = QmlVisualNode::createQml3DNode(m_parent->view(), m_itemLibraryEntry, m_activeScene).modelNode();
|
||||
QTC_ASSERT(modelNode.isValid(), return);
|
||||
m_parent->view()->executeInTransaction(__FUNCTION__, [&] {
|
||||
auto modelNode = QmlVisualNode::createQml3DNode(m_parent->view(), m_itemLibraryEntry, m_activeScene).modelNode();
|
||||
QTC_ASSERT(modelNode.isValid(), return);
|
||||
|
||||
e->accept();
|
||||
m_parent->view()->setSelectedModelNode(modelNode);
|
||||
e->accept();
|
||||
m_parent->view()->setSelectedModelNode(modelNode);
|
||||
|
||||
// if added node is a Model, assign it a material
|
||||
if (modelNode.isSubclassOf("QtQuick3D.Model")) {
|
||||
ModelNode matLib = m_parent->view()->modelNodeForId(Constants::MATERIAL_LIB_ID);
|
||||
QTC_ASSERT(matLib.isValid(), return);
|
||||
|
||||
const QList<ModelNode> materials = matLib.directSubModelNodes();
|
||||
ModelNode material;
|
||||
if (materials.size() > 0) {
|
||||
for (const ModelNode &mat : materials) {
|
||||
if (mat.isSubclassOf("QtQuick3D.Material")) {
|
||||
material = mat;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if no valid material, create a new default material
|
||||
if (!material.isValid()) {
|
||||
NodeMetaInfo metaInfo = m_parent->view()->model()->metaInfo("QtQuick3D.DefaultMaterial");
|
||||
material = m_parent->view()->createModelNode("QtQuick3D.DefaultMaterial", metaInfo.majorVersion(),
|
||||
metaInfo.minorVersion());
|
||||
VariantProperty matNameProp = material.variantProperty("objectName");
|
||||
matNameProp.setValue("New Material");
|
||||
material.validId();
|
||||
matLib.defaultNodeListProperty().reparentHere(material);
|
||||
}
|
||||
|
||||
BindingProperty modelMatsProp = modelNode.bindingProperty("materials");
|
||||
modelMatsProp.setExpression(material.id());
|
||||
}
|
||||
// if added node is a Model, assign it a material
|
||||
if (modelNode.isSubclassOf("QtQuick3D.Model"))
|
||||
m_parent->view()->assignMaterialTo3dModel(modelNode);
|
||||
});
|
||||
}
|
||||
|
||||
void Edit3DCanvas::focusOutEvent(QFocusEvent *focusEvent)
|
||||
|
||||
Reference in New Issue
Block a user