From 6dda55a8cd16857d1d50d22a4ff36d147905eaf0 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 18 May 2022 15:16:15 +0300 Subject: [PATCH] QmlDesigner: Show id-less scenes properly in 3D edit view Fixes: QDS-6942 Change-Id: I5b7fa966bf9d7321b1735ef0ea7cb904b82f542d Reviewed-by: Reviewed-by: Mahmoud Badri --- .../qt5informationnodeinstanceserver.cpp | 22 ++++++++++++++----- .../qt5informationnodeinstanceserver.h | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index a57df6bd9f0..1d266353db8 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -800,7 +800,7 @@ void Qt5InformationNodeInstanceServer::updateView3DRect(QObject *view3D) viewPortProperty.write(viewPortrect); } -void Qt5InformationNodeInstanceServer::updateActiveSceneToEditView3D() +void Qt5InformationNodeInstanceServer::updateActiveSceneToEditView3D(bool timerCall) { #ifdef QUICK3D_MODULE if (!m_editView3DSetupDone) @@ -816,12 +816,16 @@ void Qt5InformationNodeInstanceServer::updateActiveSceneToEditView3D() ServerNodeInstance sceneInstance = active3DSceneInstance(); const QString sceneId = sceneInstance.id(); - // QML item id is updated with separate call, so delay this update until we have it - if (m_active3DScene && sceneId.isEmpty()) { - m_active3DSceneUpdatePending = true; + // In case of newly created scene node, QML item id is updated with separate command immediately + // after the creation of the node, so delay this update for a moment in case we get it. + // The changeId command should already be waiting to be handled, so we can use very short + // interval timer. If we haven't gotten the scene id by the time the timer triggers, we can + // assume scene node doesn't have an id. + if (m_active3DScene && !timerCall && sceneId.isEmpty()) { + m_activeSceneIdUpdateTimer.start(); return; } else { - m_active3DSceneUpdatePending = false; + m_activeSceneIdUpdateTimer.stop(); } QMetaObject::invokeMethod(m_editView3DData.rootItem, "setActiveScene", Qt::QueuedConnection, @@ -1266,6 +1270,8 @@ Qt5InformationNodeInstanceServer::Qt5InformationNodeInstanceServer(NodeInstanceC m_inputEventTimer.setSingleShot(true); m_renderModelNodeImageViewTimer.setSingleShot(true); m_dynamicAddObjectTimer.setSingleShot(true); + m_activeSceneIdUpdateTimer.setInterval(20); + m_activeSceneIdUpdateTimer.setSingleShot(true); #ifdef FPS_COUNTER if (!_fpsTimer) { @@ -1291,6 +1297,7 @@ Qt5InformationNodeInstanceServer::~Qt5InformationNodeInstanceServer() m_inputEventTimer.stop(); m_renderModelNodeImageViewTimer.stop(); m_dynamicAddObjectTimer.stop(); + m_activeSceneIdUpdateTimer.stop(); if (m_editView3DData.rootItem) m_editView3DData.rootItem->disconnect(this); @@ -1724,6 +1731,9 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(const QList(m_3dHelper); @@ -2243,7 +2253,7 @@ void Qt5InformationNodeInstanceServer::changeIds(const ChangeIdsCommand &command #ifdef QUICK3D_MODULE if (m_editView3DSetupDone) { ServerNodeInstance sceneInstance = active3DSceneInstance(); - if (m_active3DSceneUpdatePending) { + if (m_activeSceneIdUpdateTimer.isActive()) { const QString sceneId = sceneInstance.id(); if (!sceneId.isEmpty()) updateActiveSceneToEditView3D(); diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h index 8f08dec3892..a86ce2a4615 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h @@ -129,7 +129,7 @@ private: const QList &propNames, ValuesModifiedCommand::TransactionOption option); void updateView3DRect(QObject *view3D); - void updateActiveSceneToEditView3D(); + void updateActiveSceneToEditView3D(bool timerCall = false); void removeNode3D(QObject *node); void resolveSceneRoots(); ServerNodeInstance active3DSceneInstance() const; @@ -165,7 +165,6 @@ private: QMultiHash m_3DSceneMap; // key: scene root, value: node QObject *m_active3DView = nullptr; QObject *m_active3DScene = nullptr; - bool m_active3DSceneUpdatePending = false; QSet m_parentChangedSet; QList m_completedComponentList; QList m_tokenList; @@ -175,6 +174,7 @@ private: QTimer m_renderModelNodeImageViewTimer; QTimer m_inputEventTimer; QTimer m_dynamicAddObjectTimer; + QTimer m_activeSceneIdUpdateTimer; #ifdef QUICK3D_PARTICLES_MODULE bool m_particleAnimationPlaying = true; AnimationDriver *m_particleAnimationDriver = nullptr;