From 970af9e64d1ef92987b366f4f2bd0604619de3cb Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 16 Dec 2022 13:28:43 +0200 Subject: [PATCH] QmlDesigner: Fix state preview rendering with multiple View3Ds Multiple View3Ds with shared resources such as materials don't always properly dirty themselves when a shared resource changes. Work around this issue by rendering the base state twice if there are multiple View3Ds. Fixes: QDS-8618 Change-Id: I3840a082ff8e55557afe5a5f139382d82cd6b184 Reviewed-by: Reviewed-by: Thomas Hartmann --- .../qt5previewnodeinstanceserver.cpp | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp b/src/tools/qml2puppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp index 6f3fced1b78..125a128594d 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp +++ b/src/tools/qml2puppet/qml2puppet/instances/qt5previewnodeinstanceserver.cpp @@ -53,28 +53,41 @@ void Qt5PreviewNodeInstanceServer::collectItemChangesAndSendChangeCommands() QQuickDesignerSupport::polishItems(quickWindow()); QVector imageContainerVector; + + // Base state needs to be rendered twice to properly render shared resources, + // if there is more than one View3D and at least one of them is dirty. + bool dirtyView3d = false; + const QList view3dInstances = allView3DInstances(); + for (const auto &instance : view3dInstances) { + if (QQuickDesignerSupport::isDirty(instance.rootQuickItem(), + QQuickDesignerSupport::ContentUpdateMask)) { + dirtyView3d = true; + break; + } + } + if (dirtyView3d) + renderPreviewImage(); imageContainerVector.append(ImageContainer(0, renderPreviewImage(), -1)); - QList stateInstances = rootNodeInstance().stateInstances(); + QList stateInstances = rootNodeInstance().stateInstances(); - const QList groupInstances = allGroupStateInstances(); + const QList groupInstances = allGroupStateInstances(); - for (ServerNodeInstance instance : groupInstances) { - stateInstances.append(instance.stateInstances()); - } + for (const ServerNodeInstance &instance : groupInstances) + stateInstances.append(instance.stateInstances()); - for (ServerNodeInstance instance : std::as_const(stateInstances)) { - instance.activateState(); - QImage previewImage = renderPreviewImage(); - if (!previewImage.isNull()) - imageContainerVector.append(ImageContainer(instance.instanceId(), - renderPreviewImage(), - instance.instanceId())); - instance.deactivateState(); - } + for (ServerNodeInstance instance : std::as_const(stateInstances)) { + instance.activateState(); + QImage previewImage = renderPreviewImage(); + if (!previewImage.isNull()) + imageContainerVector.append(ImageContainer(instance.instanceId(), + renderPreviewImage(), + instance.instanceId())); + instance.deactivateState(); + } nodeInstanceClient()->statePreviewImagesChanged( - StatePreviewImageChangedCommand(imageContainerVector)); + StatePreviewImageChangedCommand(imageContainerVector)); slowDownRenderTimer(); handleExtraRender();