Changed: #1303 Added undo/redo framework in core plugin.

This commit is contained in:
dnk-88 2011-05-27 19:21:16 +03:00
parent fbbdb15ad2
commit d7ce82b4bf
16 changed files with 101 additions and 7 deletions

View file

@ -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);

View file

@ -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;
};

View file

@ -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>();

View file

@ -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);

View file

@ -86,6 +86,11 @@ public:
return m_simpleViewer;
}
virtual QUndoStack *undoStack()
{
return m_simpleViewer->m_undoStack;
}
virtual void open()
{
}

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -94,9 +94,9 @@ public:
return QIcon();
}
virtual void open()
{
}
virtual void open();
virtual QUndoStack *undoStack();
virtual QWidget *widget();

View file

@ -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();

View file

@ -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 */

View file

@ -89,6 +89,7 @@ CMainWindow::CMainWindow(QWidget *parent)
_isSoundInitialized = true;
}
_undoStack = new QUndoStack(this);
_SkeletonTreeModel = new CSkeletonTreeModel(this);
createDialogs();

View file

@ -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;

View file

@ -37,7 +37,7 @@ void Modules::init()
void Modules::release()
{
delete _mainWindow;
// delete _mainWindow;
_mainWindow = NULL;
delete _particleEditor;
_particleEditor = NULL;

View file

@ -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();

View file

@ -77,6 +77,8 @@ public:
return QIcon();
}
virtual QUndoStack *undoStack();
virtual void open();
virtual QWidget *widget();