khanat-opennel-code/code/studio/src/plugins/object_viewer/object_viewer_plugin.cpp
dfighter1985 d4ee31ed63 Destroy context when unloading plugins.
--HG--
branch : gsoc2014-dfighter
2014-06-09 17:40:06 +02:00

85 lines
No EOL
1.8 KiB
C++

// Project includes
#include "object_viewer_plugin.h"
#include "graphics_settings_page.h"
#include "sound_settings_page.h"
#include "vegetable_settings_page.h"
#include "modules.h"
#include "../core/core_constants.h"
// NeL includes
#include "nel/misc/debug.h"
// Qt includes
#include <QtCore/QObject>
namespace NLQT
{
ObjectViewerPlugin::~ObjectViewerPlugin()
{
Q_FOREACH(QObject *obj, _autoReleaseObjects)
{
_plugMan->removeObject(obj);
}
qDeleteAll(_autoReleaseObjects);
_autoReleaseObjects.clear();
Modules::release();
delete _LibContext;
_LibContext = NULL;
}
bool ObjectViewerPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString)
{
Q_UNUSED(errorString);
_plugMan = pluginManager;
Modules::init();
addAutoReleasedObject(new CObjectViewerContext());
addAutoReleasedObject(new GraphicsSettingsPage());
addAutoReleasedObject(new SoundSettingsPage());
addAutoReleasedObject(new VegetableSettingsPage());
return true;
}
void ObjectViewerPlugin::extensionsInitialized()
{
}
void ObjectViewerPlugin::shutdown()
{
// Modules::release();
}
void ObjectViewerPlugin::setNelContext(NLMISC::INelContext *nelContext)
{
#ifdef NL_OS_WINDOWS
// Ensure that a context doesn't exist yet.
// This only applies to platforms without PIC, e.g. Windows.
nlassert(!NLMISC::INelContext::isContextInitialised());
#endif // NL_OS_WINDOWS
_LibContext = new NLMISC::CLibraryContext(*nelContext);
}
void ObjectViewerPlugin::addAutoReleasedObject(QObject *obj)
{
_plugMan->addObject(obj);
_autoReleaseObjects.prepend(obj);
}
void CObjectViewerContext::open()
{
Modules::mainWin().open();
}
QUndoStack *CObjectViewerContext::undoStack()
{
return Modules::mainWin().getUndoStack();
}
QWidget *CObjectViewerContext::widget()
{
return &Modules::mainWin();
}
}
Q_EXPORT_PLUGIN(NLQT::ObjectViewerPlugin)