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: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2022-12-16 13:28:43 +02:00
committed by Mahmoud Badri
parent 08d4eab619
commit 970af9e64d

View File

@@ -53,28 +53,41 @@ void Qt5PreviewNodeInstanceServer::collectItemChangesAndSendChangeCommands()
QQuickDesignerSupport::polishItems(quickWindow()); QQuickDesignerSupport::polishItems(quickWindow());
QVector<ImageContainer> imageContainerVector; QVector<ImageContainer> 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<ServerNodeInstance> 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)); imageContainerVector.append(ImageContainer(0, renderPreviewImage(), -1));
QList<ServerNodeInstance> stateInstances = rootNodeInstance().stateInstances(); QList<ServerNodeInstance> stateInstances = rootNodeInstance().stateInstances();
const QList<ServerNodeInstance> groupInstances = allGroupStateInstances(); const QList<ServerNodeInstance> groupInstances = allGroupStateInstances();
for (ServerNodeInstance instance : groupInstances) { for (const ServerNodeInstance &instance : groupInstances)
stateInstances.append(instance.stateInstances()); stateInstances.append(instance.stateInstances());
}
for (ServerNodeInstance instance : std::as_const(stateInstances)) { for (ServerNodeInstance instance : std::as_const(stateInstances)) {
instance.activateState(); instance.activateState();
QImage previewImage = renderPreviewImage(); QImage previewImage = renderPreviewImage();
if (!previewImage.isNull()) if (!previewImage.isNull())
imageContainerVector.append(ImageContainer(instance.instanceId(), imageContainerVector.append(ImageContainer(instance.instanceId(),
renderPreviewImage(), renderPreviewImage(),
instance.instanceId())); instance.instanceId()));
instance.deactivateState(); instance.deactivateState();
} }
nodeInstanceClient()->statePreviewImagesChanged( nodeInstanceClient()->statePreviewImagesChanged(
StatePreviewImageChangedCommand(imageContainerVector)); StatePreviewImageChangedCommand(imageContainerVector));
slowDownRenderTimer(); slowDownRenderTimer();
handleExtraRender(); handleExtraRender();