From a1e9e6b70bda12d3a5e80733812bcfe9ec4aa97c Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 30 Nov 2020 16:48:47 +0200 Subject: [PATCH] QmlPuppet: Fix preview tooltip image creation for material components There is an unknown issue causing the first premade material from QtQuick3D.Materials library encountered in the scene to fail to load properly as a component. In scene creation this is worked around by falling back on primitive creation, but the same issue prevents loading the component for preview image generation purposes. Luckily, materials can be shared freely between views, so we don't need to actually load the component in this case. We can use the existing material instance just like with non-component materials. As a side effect, this change also fixes the issue where premade custom material previews didn't reflect the changes in material properties, like other materials do. Change-Id: I7f1d6863fe96734a610d725f2f71e252f03a4428 Fixes: QDS-3114 Reviewed-by: Mahmoud Badri Reviewed-by: Thomas Hartmann --- .../instances/qt5informationnodeinstanceserver.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index b59ff161cdf..6879ddacdfe 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -700,7 +700,13 @@ void Qt5InformationNodeInstanceServer::doRenderModelNode3DImageView() renderImage = m_modelNodePreviewImageCache[m_modelNodePreviewImageCommand.componentPath()]; } else { QObject *instanceObj = nullptr; - if (!m_modelNodePreviewImageCommand.componentPath().isEmpty()) { + bool createdFromComponent = false; + ServerNodeInstance instance = instanceForId(m_modelNodePreviewImageCommand.instanceId()); + if (!m_modelNodePreviewImageCommand.componentPath().isEmpty() + && instance.isSubclassOf("QQuick3DNode")) { + // Create a new instance for Node components, as using Nodes in multiple + // import scenes simultaneously isn't supported. And even if it was, we still + // wouldn't want the children of the Node to appear in the preview. QQmlComponent component(engine()); component.loadUrl(QUrl::fromLocalFile(m_modelNodePreviewImageCommand.componentPath())); instanceObj = qobject_cast(component.create()); @@ -708,8 +714,8 @@ void Qt5InformationNodeInstanceServer::doRenderModelNode3DImageView() qWarning() << "Could not create preview component: " << component.errors(); return; } + createdFromComponent = true; } else { - ServerNodeInstance instance = instanceForId(m_modelNodePreviewImageCommand.instanceId()); instanceObj = instance.internalObject(); } QSize renderSize = m_modelNodePreviewImageCommand.size(); @@ -758,7 +764,7 @@ void Qt5InformationNodeInstanceServer::doRenderModelNode3DImageView() ready = QQmlProperty::read(m_modelNode3DImageViewData.rootItem, "ready").value(); } QMetaObject::invokeMethod(m_modelNode3DImageViewData.rootItem, "destroyView"); - if (!m_modelNodePreviewImageCommand.componentPath().isEmpty()) { + if (createdFromComponent) { // If component changes, puppet will need a reset anyway, so we can cache the image m_modelNodePreviewImageCache.insert(m_modelNodePreviewImageCommand.componentPath(), renderImage); delete instanceObj;