From 6cd403a996bed7a4d4726f75ce6cf086233a354f Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 29 Jun 2016 13:22:38 +0300 Subject: Open the correct scene when opening the embedded editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie308ea0bc5024c539caca4e4d514bbf214c9dc6e Reviewed-by: Tomi Korpipää --- creatorplugin/qt3dsceneeditorplugin.cpp | 6 ++++-- creatorplugin/qt3dsceneeditorwidget.cpp | 12 ++++++++---- creatorplugin/qt3dsceneeditorwidget.h | 4 +++- editorlib/qml/EditorContent.qml | 25 ++++++++++++++----------- editorlib/qml/PluginMain.qml | 9 +++++++++ 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/creatorplugin/qt3dsceneeditorplugin.cpp b/creatorplugin/qt3dsceneeditorplugin.cpp index 51c43f6..d8ccedd 100644 --- a/creatorplugin/qt3dsceneeditorplugin.cpp +++ b/creatorplugin/qt3dsceneeditorplugin.cpp @@ -43,8 +43,10 @@ #include #include +#include #include +#include namespace Qt3DSceneEditor { namespace Internal { @@ -155,8 +157,8 @@ void Qt3DSceneEditorPlugin::createSceneEditorWidget() void Qt3DSceneEditorPlugin::showSceneEditor() { - m_sceneEditorWidget->initialize(); - // TODO: load the scene (probably as parameter to initialize) + m_sceneEditorWidget->initialize( + QUrl::fromLocalFile(Core::EditorManager::currentDocument()->filePath().toString())); } void Qt3DSceneEditorPlugin::hideSceneEditor() diff --git a/creatorplugin/qt3dsceneeditorwidget.cpp b/creatorplugin/qt3dsceneeditorwidget.cpp index eab05f2..bc8b46a 100644 --- a/creatorplugin/qt3dsceneeditorwidget.cpp +++ b/creatorplugin/qt3dsceneeditorwidget.cpp @@ -29,8 +29,9 @@ #include "qt3dsceneeditorwidget.h" #include "../editorlib/src/qt3dsceneeditor.h" -#include -#include +#include +#include +#include using namespace Qt3DSceneEditor; @@ -40,6 +41,7 @@ namespace Internal { Qt3DSceneEditorWidget::Qt3DSceneEditorWidget(QWidget *parent) : QWidget(parent) , m_sceneEditor(nullptr) + , m_rootItem(nullptr) { } @@ -53,6 +55,7 @@ void Qt3DSceneEditorWidget::setup() m_sceneEditor = new QQuickWidget(this); m_sceneEditor->setResizeMode(QQuickWidget::SizeRootObjectToView); m_sceneEditor->setSource(QUrl(QStringLiteral("qrc:/qt3deditorlib/PluginMain.qml"))); + m_rootItem = m_sceneEditor->rootObject(); QVBoxLayout *layout = new QVBoxLayout(); layout->setMargin(0); @@ -63,14 +66,15 @@ void Qt3DSceneEditorWidget::setup() show(); } -void Qt3DSceneEditorWidget::initialize() +void Qt3DSceneEditorWidget::initialize(const QUrl &fileName) { if (m_initStatus == NotInitialized) { m_initStatus = Initializing; setup(); } - m_initStatus = Initialized; + + QMetaObject::invokeMethod(m_rootItem, "loadScene", Q_ARG(QVariant, fileName)); } } // namespace Internal diff --git a/creatorplugin/qt3dsceneeditorwidget.h b/creatorplugin/qt3dsceneeditorwidget.h index 09a9138..e4cc693 100644 --- a/creatorplugin/qt3dsceneeditorwidget.h +++ b/creatorplugin/qt3dsceneeditorwidget.h @@ -32,6 +32,7 @@ QT_BEGIN_NAMESPACE class QQuickWidget; +class QQuickItem; QT_END_NAMESPACE namespace Qt3DSceneEditor { @@ -46,7 +47,7 @@ public: ~Qt3DSceneEditorWidget(); - void initialize(); + void initialize(const QUrl &fileName); private: // functions enum InitializeStatus { NotInitialized, Initializing, Initialized }; @@ -55,6 +56,7 @@ private: // functions private: // variables InitializeStatus m_initStatus = NotInitialized; QQuickWidget *m_sceneEditor; + QQuickItem *m_rootItem; }; } // namespace Internal diff --git a/editorlib/qml/EditorContent.qml b/editorlib/qml/EditorContent.qml index 4ab123d..e005d0a 100644 --- a/editorlib/qml/EditorContent.qml +++ b/editorlib/qml/EditorContent.qml @@ -105,6 +105,14 @@ Item { } } + function loadScene(fileUrl, folder) { + if (editorScene.loadScene(fileUrl)) { + entityTree.selectSceneRoot() + editorContent.saveFolder = folder + editorContent.saveFileUrl = fileUrl + } + } + function fileSave() { if (saveFileUrl == "") { saveFileDialog.folder = saveFolder @@ -220,6 +228,11 @@ Item { } } + function resetCameraToDefault() { + editorScene.freeView = true + editorScene.resetFreeViewCamera() + } + Settings { // Save view panel sizes // Use detailed category name, as plugin saves settings under QtCreator application @@ -264,11 +277,7 @@ Item { title: qsTr("Load Scene") + editorScene.emptyString nameFilters: [qsTr("Qt3D Scenes (*.qt3d.qrc)") + editorScene.emptyString] onAccepted: { - if (editorScene.loadScene(fileUrl)) { - entityTree.selectSceneRoot() - editorContent.saveFolder = folder - editorContent.saveFileUrl = fileUrl - } + editorContent.loadScene(fileUrl, folder) } } @@ -686,12 +695,6 @@ Item { editorScene.saveScene(editorContent.saveFileUrl, true) } } - - function resetCameraToDefault() { - editorScene.freeView = true - editorScene.resetFreeViewCamera() - } - } } diff --git a/editorlib/qml/PluginMain.qml b/editorlib/qml/PluginMain.qml index 5570c4b..2c0777f 100644 --- a/editorlib/qml/PluginMain.qml +++ b/editorlib/qml/PluginMain.qml @@ -29,6 +29,15 @@ import QtQuick 2.5 Rectangle { color: editorContent.paneBackgroundColor + property url previouslyLoadedUrl: "" + + function loadScene(url) { + if (url !== previouslyLoadedUrl) { + var folder = url.toString(); + folder = decodeURIComponent(folder.replace(/\/[^\/]*$/, "")); + editorContent.loadScene(url, folder) + } + } EditorContent { id: editorContent -- cgit v1.2.3