From 279d765e38cb0087017553ec80dc3d2ae168bc52 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Fri, 27 May 2011 19:21:16 +0300 Subject: [PATCH] Changed: #1303 Added undo/redo framework in core plugin. --HG-- branch : gsoc2011-worldeditorqt --- .../src/plugins/core/context_manager.cpp | 3 +++ .../src/plugins/core/icontext.h | 3 +++ .../src/plugins/core/main_window.cpp | 18 +++++++++++++ .../src/plugins/core/main_window.h | 4 +++ .../src/plugins/example/plugin1.h | 5 ++++ .../src/plugins/example/simple_viewer.cpp | 2 ++ .../src/plugins/example/simple_viewer.h | 4 ++- .../landscape_editor_plugin.cpp | 10 ++++++++ .../landscape_editor_plugin.h | 6 ++--- .../landscape_editor_window.cpp | 25 +++++++++++++++++++ .../landscape_editor_window.h | 7 ++++++ .../src/plugins/object_viewer/main_window.cpp | 1 + .../src/plugins/object_viewer/main_window.h | 7 ++++++ .../src/plugins/object_viewer/modules.cpp | 2 +- .../object_viewer/object_viewer_plugin.cpp | 9 +++++-- .../object_viewer/object_viewer_plugin.h | 2 ++ 16 files changed, 101 insertions(+), 7 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp index 23dbe02f4..68e28429d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/context_manager.cpp @@ -102,6 +102,7 @@ void ContextManager::aboutToRemoveObject(QObject *obj) void ContextManager::addContextObject(IContext *context) { d->m_contexts.push_back(context); + d->m_mainWindow->addContextObject(context); QWidget *tabWidget = new QWidget(d->m_tabWidget); d->m_tabWidget->addTab(tabWidget, context->icon(), context->trName()); @@ -113,6 +114,8 @@ void ContextManager::addContextObject(IContext *context) void ContextManager::removeContextObject(IContext *context) { + d->m_mainWindow->removeContextObject(context); + const int index = indexOf(context->id()); QWidget *widget = d->m_tabWidget->widget(index); d->m_tabWidget->removeTab(index); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icontext.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icontext.h index c6784dafe..8af601418 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icontext.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/icontext.h @@ -28,6 +28,7 @@ QT_BEGIN_NAMESPACE class QWidget; +class QUndoStack; QT_END_NAMESPACE namespace Core @@ -57,6 +58,8 @@ public: /// The widget will be destroyed by the widget hierarchy when the main window closes virtual QWidget *widget() = 0; + virtual QUndoStack *undoStack() = 0; + virtual void open() = 0; }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp index 1c8850508..55d6d4579 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.cpp @@ -99,6 +99,9 @@ bool MainWindow::initialize(QString *errorString) void MainWindow::extensionsInitialized() { readSettings(); + connect(m_contextManager, SIGNAL(currentContextChanged(Core::IContext*)), + this, SLOT(updateContext(Core::IContext*))); + updateContext(m_contextManager->currentContext()); show(); } @@ -122,6 +125,16 @@ ExtensionSystem::IPluginManager *MainWindow::pluginManager() const return m_pluginManager; } +void MainWindow::addContextObject(IContext *context) +{ + m_undoGroup->addStack(context->undoStack()); +} + +void MainWindow::removeContextObject(IContext *context) +{ + m_undoGroup->removeStack(context->undoStack()); +} + void MainWindow::open() { m_contextManager->currentContext()->open(); @@ -148,6 +161,11 @@ void MainWindow::about() "

Ryzom Core team

Compiled on %1 %2").arg(__DATE__).arg(__TIME__)); } +void MainWindow::updateContext(Core::IContext *context) +{ + m_undoGroup->setActiveStack(context->undoStack()); +} + void MainWindow::closeEvent(QCloseEvent *event) { QList listeners = m_pluginManager->getObjects(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h index cd34098a7..74ec08957 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/main_window.h @@ -56,6 +56,9 @@ public: ExtensionSystem::IPluginManager *pluginManager() const; + void addContextObject(IContext *context); + void removeContextObject(IContext *context); + public Q_SLOTS: bool showOptionsDialog(const QString &group = QString(), const QString &page = QString(), @@ -64,6 +67,7 @@ public Q_SLOTS: private Q_SLOTS: void open(); void about(); + void updateContext(Core::IContext *context); protected: virtual void closeEvent(QCloseEvent *event); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.h index f9d5c2d9d..5077ff59e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.h @@ -86,6 +86,11 @@ public: return m_simpleViewer; } + virtual QUndoStack *undoStack() + { + return m_simpleViewer->m_undoStack; + } + virtual void open() { } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp index e128710c4..1f6df9117 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.cpp @@ -37,6 +37,8 @@ CSimpleViewer::CSimpleViewer(QWidget *parent) gridLayout->setContentsMargins(0, 0, 0, 0); NLQT::QNLWidget *_nelWidget = new NLQT::QNLWidget(this); gridLayout->addWidget(_nelWidget, 0, 0, 1, 1); + + m_undoStack = new QUndoStack(this); } bool CCoreListener::closeMainWindow() const diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h index bbff7e9e0..14b782c22 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/simple_viewer.h @@ -25,7 +25,7 @@ // Qt includes #include - +#include class QWidget; namespace Plugin @@ -37,6 +37,8 @@ class CSimpleViewer : public QWidget public: CSimpleViewer(QWidget *parent = 0); virtual ~CSimpleViewer() {} + + QUndoStack *m_undoStack; }; class CCoreListener : public Core::ICoreListener diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.cpp index 2c51a5d68..ac7782343 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.cpp @@ -108,6 +108,16 @@ LandscapeEditorContext::LandscapeEditorContext(QObject *parent) m_landEditorWindow = new LandscapeEditorWindow(); } +QUndoStack *LandscapeEditorContext::undoStack() +{ + return m_landEditorWindow->undoStack(); +} + +void LandscapeEditorContext::open() +{ + m_landEditorWindow->open(); +} + QWidget *LandscapeEditorContext::widget() { return m_landEditorWindow; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.h index 20db2eb15..67a3172ee 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_plugin.h @@ -94,9 +94,9 @@ public: return QIcon(); } - virtual void open() - { - } + virtual void open(); + + virtual QUndoStack *undoStack(); virtual QWidget *widget(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp index ef4f81a1c..4b075adfc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp @@ -28,14 +28,19 @@ // Qt includes #include +#include namespace LandscapeEditor { +QString _lastDir; LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent) : QMainWindow(parent) { m_ui.setupUi(this); + + m_undoStack = new QUndoStack(this); + createMenus(); readSettings(); } @@ -45,6 +50,26 @@ LandscapeEditorWindow::~LandscapeEditorWindow() writeSettings(); } +QUndoStack *LandscapeEditorWindow::undoStack() const +{ + return m_undoStack; +} + +void LandscapeEditorWindow::open() +{ + QStringList fileNames = QFileDialog::getOpenFileNames(this, + tr("Open NeL Ligo land file"), _lastDir, + tr("All NeL Ligo land files (*.land)")); + + setCursor(Qt::WaitCursor); + if (!fileNames.isEmpty()) + { + QStringList list = fileNames; + _lastDir = QFileInfo(list.front()).absolutePath(); + } + setCursor(Qt::ArrowCursor); +} + void LandscapeEditorWindow::createMenus() { Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h index 0af41961f..cc17e6cbc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h @@ -18,9 +18,11 @@ #ifndef LANDSCAPE_EDITOR_WINDOW_H #define LANDSCAPE_EDITOR_WINDOW_H +// Project includes #include "ui_landscape_editor_window.h" // Qt includes +#include namespace LandscapeEditor { @@ -33,14 +35,19 @@ public: LandscapeEditorWindow(QWidget *parent = 0); ~LandscapeEditorWindow(); + QUndoStack *undoStack() const; + Q_SIGNALS: public Q_SLOTS: + void open(); + private Q_SLOTS: private: void createMenus(); void readSettings(); void writeSettings(); + QUndoStack *m_undoStack; Ui::LandscapeEditorWindow m_ui; }; /* class LandscapeEditorWindow */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/main_window.cpp index d9b732521..dd8a4bb1e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/main_window.cpp @@ -89,6 +89,7 @@ CMainWindow::CMainWindow(QWidget *parent) _isSoundInitialized = true; } + _undoStack = new QUndoStack(this); _SkeletonTreeModel = new CSkeletonTreeModel(this); createDialogs(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/main_window.h index 6da360901..5a392c191 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/main_window.h @@ -25,6 +25,7 @@ // Qt includes #include #include +#include // NeL includes #include @@ -72,6 +73,11 @@ public: return _SkeletonTreeModel; } + QUndoStack *getUndoStack() const + { + return _undoStack; + } + public Q_SLOTS: void open(); void resetScene(); @@ -132,6 +138,7 @@ private: QAction *_resetSceneAction; QAction *_saveScreenshotAction; QLabel *_statusInfo; + QUndoStack *_undoStack; float _fps; uint _numTri; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/modules.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/modules.cpp index 76afed779..605f484f7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/modules.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/modules.cpp @@ -37,7 +37,7 @@ void Modules::init() void Modules::release() { - delete _mainWindow; +// delete _mainWindow; _mainWindow = NULL; delete _particleEditor; _particleEditor = NULL; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/object_viewer_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/object_viewer_plugin.cpp index 193ad8fac..f82789e66 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/object_viewer_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/object_viewer_plugin.cpp @@ -22,7 +22,7 @@ ObjectViewerPlugin::~ObjectViewerPlugin() } qDeleteAll(_autoReleaseObjects); _autoReleaseObjects.clear(); - //Modules::release(); + Modules::release(); } bool ObjectViewerPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString) @@ -43,7 +43,7 @@ void ObjectViewerPlugin::extensionsInitialized() void ObjectViewerPlugin::shutdown() { - Modules::release(); +// Modules::release(); } void ObjectViewerPlugin::setNelContext(NLMISC::INelContext *nelContext) @@ -94,6 +94,11 @@ void CObjectViewerContext::open() Modules::mainWin().open(); } +QUndoStack *CObjectViewerContext::undoStack() +{ + return Modules::mainWin().getUndoStack(); +} + QWidget *CObjectViewerContext::widget() { return &Modules::mainWin(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/object_viewer_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/object_viewer_plugin.h index e7f9b8197..b5f9c2881 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/object_viewer_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/object_viewer_plugin.h @@ -77,6 +77,8 @@ public: return QIcon(); } + virtual QUndoStack *undoStack(); + virtual void open(); virtual QWidget *widget();