forked from qt-creator/qt-creator
QmlDesigner: Restore the previously active 3D scene on scene creation
Store the last active scene in global 3D tool state and restore it when a scene is created after puppet relaunch. Change-Id: Ie2d69f6db6798ab383c66d38b2dea7eba13adc97 Fixes: QDS-2239 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -48,6 +48,8 @@ namespace QmlDesigner {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
const QString _globalStateId = QStringLiteral("@GTS"); // global tool state
|
const QString _globalStateId = QStringLiteral("@GTS"); // global tool state
|
||||||
|
const QString _lastSceneIdKey = QStringLiteral("lastSceneId");
|
||||||
|
const QString _rootSizeKey = QStringLiteral("rootSize");
|
||||||
|
|
||||||
GeneralHelper::GeneralHelper()
|
GeneralHelper::GeneralHelper()
|
||||||
: QObject()
|
: QObject()
|
||||||
@@ -280,6 +282,16 @@ QString GeneralHelper::globalStateId() const
|
|||||||
return _globalStateId;
|
return _globalStateId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GeneralHelper::lastSceneIdKey() const
|
||||||
|
{
|
||||||
|
return _lastSceneIdKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GeneralHelper::rootSizeKey() const
|
||||||
|
{
|
||||||
|
return _rootSizeKey;
|
||||||
|
}
|
||||||
|
|
||||||
bool GeneralHelper::isMacOS() const
|
bool GeneralHelper::isMacOS() const
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
|
@@ -78,6 +78,8 @@ public:
|
|||||||
Q_INVOKABLE void enableItemUpdate(QQuickItem *item, bool enable);
|
Q_INVOKABLE void enableItemUpdate(QQuickItem *item, bool enable);
|
||||||
Q_INVOKABLE QVariantMap getToolStates(const QString &sceneId);
|
Q_INVOKABLE QVariantMap getToolStates(const QString &sceneId);
|
||||||
QString globalStateId() const;
|
QString globalStateId() const;
|
||||||
|
QString lastSceneIdKey() const;
|
||||||
|
QString rootSizeKey() const;
|
||||||
|
|
||||||
bool isMacOS() const;
|
bool isMacOS() const;
|
||||||
|
|
||||||
|
@@ -367,6 +367,10 @@ void Qt5InformationNodeInstanceServer::updateActiveSceneToEditView3D()
|
|||||||
Q_ARG(QVariant, QVariant::fromValue(sceneId)));
|
Q_ARG(QVariant, QVariant::fromValue(sceneId)));
|
||||||
|
|
||||||
updateView3DRect(m_active3DView);
|
updateView3DRect(m_active3DView);
|
||||||
|
|
||||||
|
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
|
||||||
|
if (helper)
|
||||||
|
helper->storeToolState(helper->globalStateId(), helper->lastSceneIdKey(), QVariant(sceneId), 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,19 +808,9 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(const QList<ServerNodeIns
|
|||||||
add3DViewPorts(instanceList);
|
add3DViewPorts(instanceList);
|
||||||
add3DScenes(instanceList);
|
add3DScenes(instanceList);
|
||||||
|
|
||||||
// Find any scene to show
|
|
||||||
if (!m_3DSceneMap.isEmpty()) {
|
|
||||||
m_active3DScene = m_3DSceneMap.begin().key();
|
|
||||||
m_active3DView = findView3DForSceneRoot(m_active3DScene);
|
|
||||||
}
|
|
||||||
|
|
||||||
createEditView3D();
|
createEditView3D();
|
||||||
if (!m_editView3DRootItem) {
|
|
||||||
m_active3DScene = nullptr;
|
|
||||||
m_active3DView = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
QString lastSceneId;
|
||||||
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
|
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
|
||||||
if (helper) {
|
if (helper) {
|
||||||
auto it = toolStates.constBegin();
|
auto it = toolStates.constBegin();
|
||||||
@@ -824,9 +818,31 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(const QList<ServerNodeIns
|
|||||||
helper->initToolStates(it.key(), it.value());
|
helper->initToolStates(it.key(), it.value());
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
if (toolStates.contains(helper->globalStateId())
|
if (toolStates.contains(helper->globalStateId())) {
|
||||||
&& toolStates[helper->globalStateId()].contains("rootSize")) {
|
if (toolStates[helper->globalStateId()].contains(helper->rootSizeKey()))
|
||||||
m_editView3DRootItem->setSize(toolStates[helper->globalStateId()]["rootSize"].value<QSize>());
|
m_editView3DRootItem->setSize(toolStates[helper->globalStateId()][helper->rootSizeKey()].value<QSize>());
|
||||||
|
if (toolStates[helper->globalStateId()].contains(helper->lastSceneIdKey()))
|
||||||
|
lastSceneId = toolStates[helper->globalStateId()][helper->lastSceneIdKey()].toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find a scene to show
|
||||||
|
m_active3DScene = nullptr;
|
||||||
|
m_active3DView = nullptr;
|
||||||
|
if (m_editView3DRootItem && !m_3DSceneMap.isEmpty()) {
|
||||||
|
// Restore the previous scene if possible
|
||||||
|
if (!lastSceneId.isEmpty()) {
|
||||||
|
const auto keys = m_3DSceneMap.uniqueKeys();
|
||||||
|
for (const auto key : keys) {
|
||||||
|
m_active3DScene = key;
|
||||||
|
m_active3DView = findView3DForSceneRoot(m_active3DScene);
|
||||||
|
ServerNodeInstance sceneInstance = active3DSceneInstance();
|
||||||
|
if (lastSceneId == sceneInstance.id())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m_active3DScene = m_3DSceneMap.begin().key();
|
||||||
|
m_active3DView = findView3DForSceneRoot(m_active3DScene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1248,7 +1264,7 @@ void Qt5InformationNodeInstanceServer::update3DViewState(const Update3dViewState
|
|||||||
m_editView3DRootItem->setSize(command.size());
|
m_editView3DRootItem->setSize(command.size());
|
||||||
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
|
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
|
||||||
if (helper)
|
if (helper)
|
||||||
helper->storeToolState(helper->globalStateId(), "rootSize", QVariant(command.size()), 0);
|
helper->storeToolState(helper->globalStateId(), helper->rootSizeKey(), QVariant(command.size()), 0);
|
||||||
// Queue two renders to make sure icon gizmos update properly
|
// Queue two renders to make sure icon gizmos update properly
|
||||||
render3DEditView(2);
|
render3DEditView(2);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user