Changed: #1303 Added undo/redo framework in core plugin.
--HG-- branch : gsoc2011-worldeditorqt
This commit is contained in:
parent
79c5f51c0e
commit
279d765e38
16 changed files with 101 additions and 7 deletions
code/nel/tools/3d/object_viewer_qt/src/plugins
core
example
landscape_editor
landscape_editor_plugin.cpplandscape_editor_plugin.hlandscape_editor_window.cpplandscape_editor_window.h
object_viewer
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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()
|
|||
"<p> Ryzom Core team <p>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<ICoreListener *> listeners = m_pluginManager->getObjects<ICoreListener>();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -86,6 +86,11 @@ public:
|
|||
return m_simpleViewer;
|
||||
}
|
||||
|
||||
virtual QUndoStack *undoStack()
|
||||
{
|
||||
return m_simpleViewer->m_undoStack;
|
||||
}
|
||||
|
||||
virtual void open()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
// Qt includes
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <QtGui/QUndoStack>
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -94,9 +94,9 @@ public:
|
|||
return QIcon();
|
||||
}
|
||||
|
||||
virtual void open()
|
||||
{
|
||||
}
|
||||
virtual void open();
|
||||
|
||||
virtual QUndoStack *undoStack();
|
||||
|
||||
virtual QWidget *widget();
|
||||
|
||||
|
|
|
@ -28,14 +28,19 @@
|
|||
|
||||
// Qt includes
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtGui/QFileDialog>
|
||||
|
||||
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();
|
||||
|
|
|
@ -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 <QtGui/QUndoStack>
|
||||
|
||||
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 */
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ CMainWindow::CMainWindow(QWidget *parent)
|
|||
_isSoundInitialized = true;
|
||||
}
|
||||
|
||||
_undoStack = new QUndoStack(this);
|
||||
_SkeletonTreeModel = new CSkeletonTreeModel(this);
|
||||
|
||||
createDialogs();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
// Qt includes
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QUndoStack>
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/config_file.h>
|
||||
|
@ -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;
|
||||
|
|
|
@ -37,7 +37,7 @@ void Modules::init()
|
|||
|
||||
void Modules::release()
|
||||
{
|
||||
delete _mainWindow;
|
||||
// delete _mainWindow;
|
||||
_mainWindow = NULL;
|
||||
delete _particleEditor;
|
||||
_particleEditor = NULL;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -77,6 +77,8 @@ public:
|
|||
return QIcon();
|
||||
}
|
||||
|
||||
virtual QUndoStack *undoStack();
|
||||
|
||||
virtual void open();
|
||||
|
||||
virtual QWidget *widget();
|
||||
|
|
Loading…
Reference in a new issue