QmlDesigner: Don't create duplicate default texture instance

Whenever an operation involving an asset image would result in
creation of a new texture node, it now checks first if
a matching texture node already exists and uses that instead.

Fixes: QDS-8435
Change-Id: I3d091aafcd09afdec897bc4da79789c1d84056e8
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2022-11-25 17:01:53 +02:00
parent 7d13c82750
commit 5544cdc276
5 changed files with 64 additions and 16 deletions

View File

@@ -75,20 +75,29 @@ WidgetInfo ContentLibraryView::widgetInfo()
return;
NodeMetaInfo metaInfo = model()->metaInfo("QtQuick3D.Texture");
ModelNode newTexNode = createModelNode("QtQuick3D.Texture", metaInfo.majorVersion(),
metaInfo.minorVersion());
newTexNode.validId();
VariantProperty sourceProp = newTexNode.variantProperty("source");
sourceProp.setValue(QLatin1String("images/%1").arg(texPath.split('/').last()));
matLib.defaultNodeListProperty().reparentHere(newTexNode);
QString sourceVal = QLatin1String("images/%1").arg(texPath.split('/').last());
ModelNode texNode = getTextureDefaultInstance(sourceVal);
if (!texNode.isValid()) {
texNode = createModelNode("QtQuick3D.Texture", metaInfo.majorVersion(),
metaInfo.minorVersion());
texNode.validId();
VariantProperty sourceProp = texNode.variantProperty("source");
sourceProp.setValue(sourceVal);
matLib.defaultNodeListProperty().reparentHere(texNode);
}
// assign the texture as scene environment's light probe
if (mode == ContentLibraryWidget::AddTextureMode::LightProbe && m_activeSceneEnv.isValid()) {
BindingProperty lightProbeProp = m_activeSceneEnv.bindingProperty("lightProbe");
lightProbeProp.setExpression(newTexNode.id());
lightProbeProp.setExpression(texNode.id());
VariantProperty bgModeProp = m_activeSceneEnv.variantProperty("backgroundMode");
bgModeProp.setValue(QVariant::fromValue(Enumeration("SceneEnvironment", "SkyBox")));
}
QTimer::singleShot(0, this, [this, texNode]() {
if (model() && texNode.isValid())
emitCustomNotification("selected_texture_changed", {texNode});
});
});
});