diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp index a1c3dced0..5b6904421 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.cpp @@ -36,13 +36,27 @@ using namespace Core; +CorePlugin::CorePlugin() +{ +} + +CorePlugin::~CorePlugin() +{ + Q_FOREACH(QObject *obj, _autoReleaseObjects) + { + _plugMan->removeObject(obj); + } + qDeleteAll(_autoReleaseObjects); + _autoReleaseObjects.clear(); +} + bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString) { Q_UNUSED(errorString); _plugMan = pluginManager; - oldOVQT = false; + _oldOVQT = false; - _plugMan->addObject(new CSearchPathsSettingsPage(this)); + addAutoReleasedObject(new CSearchPathsSettingsPage(this)); return true; } @@ -66,7 +80,7 @@ void CorePlugin::extensionsInitialized() connect(newAction, SIGNAL(triggered()), this, SLOT(execSettings())); connect(newAction2, SIGNAL(triggered()), _pluginView, SLOT(show())); - oldOVQT = true; + _oldOVQT = true; } else { @@ -93,7 +107,7 @@ void CorePlugin::extensionsInitialized() void CorePlugin::shutdown() { - if (!oldOVQT) + if (!_oldOVQT) { delete _mainWindow; delete _pluginView; @@ -102,7 +116,7 @@ void CorePlugin::shutdown() void CorePlugin::execSettings() { - CSettingsDialog settingsDialog(_plugMan); + CSettingsDialog settingsDialog(this); settingsDialog.show(); settingsDialog.execDialog(); } @@ -142,6 +156,12 @@ QList CorePlugin::dependencies() const return QList(); } +void CorePlugin::addAutoReleasedObject(QObject *obj) +{ + _plugMan->addObject(obj); + _autoReleaseObjects.prepend(obj); +} + QObject* CorePlugin::objectByName(const QString &name) const { Q_FOREACH (QObject *qobj, _plugMan->allObjects()) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.h index 0695a0acf..96cf21d30 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_plugin.h @@ -44,6 +44,9 @@ class CorePlugin : public QObject, public ExtensionSystem::IPlugin Q_INTERFACES(ExtensionSystem::IPlugin) public: + CorePlugin(); + virtual ~CorePlugin(); + bool initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString); void extensionsInitialized(); void shutdown(); @@ -56,6 +59,8 @@ public: QString description() const; QList dependencies() const; + void addAutoReleasedObject(QObject *obj); + QObject *objectByName(const QString &name) const; ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const; ExtensionSystem::IPluginManager *pluginManager() const @@ -63,20 +68,36 @@ public: return _plugMan; } - template - QList getObjects() const + template + QList getObjects() const { QList all = _plugMan->allObjects(); - QList objects; + QList objects; Q_FOREACH(QObject *obj, all) { - Type *typeObj = qobject_cast(obj); - if (typeObj) - objects.append(typeObj); + T *tObj = qobject_cast(obj); + if (tObj) + objects.append(tObj); } return objects; } + template + T *getObject() const + { + QList all = _plugMan->allObjects(); + T *result = 0; + Q_FOREACH(QObject *obj, all) + { + T *tObj = qobject_cast(obj); + if (tObj) + { + result = tObj; + break; + } + } + } + protected: NLMISC::CLibraryContext *_LibContext; @@ -87,8 +108,8 @@ private: ExtensionSystem::IPluginManager *_plugMan; ExtensionSystem::CPluginView *_pluginView; CMainWindow *_mainWindow; - - bool oldOVQT; + QList _autoReleaseObjects; + bool _oldOVQT; }; } // namespace Core 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 601159f8b..0aa82e187 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 @@ -25,6 +25,7 @@ // NeL includes #include + // Qt includes #include @@ -87,7 +88,7 @@ bool CMainWindow::showOptionsDialog(const QString &group, { if (!parent) parent = this; - CSettingsDialog _settingsDialog(_pluginManager, group, page, parent); + CSettingsDialog _settingsDialog(_corePlugin, group, page, parent); _settingsDialog.show(); return _settingsDialog.execDialog(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.cpp index 81719ee59..51449c4a5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.cpp @@ -29,7 +29,7 @@ namespace Core CSearchPathsSettingsPage::CSearchPathsSettingsPage(QObject *parent) : QObject(parent), - _currentPage(NULL) + _currentPage(0) { } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.cpp index 9a43b68a9..c1a1fca40 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.cpp @@ -16,7 +16,10 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// Project includes #include "settings_dialog.h" +#include "core_plugin.h" +#include "ioptions_page.h" // Qt includes #include @@ -33,7 +36,7 @@ Q_DECLARE_METATYPE(PageData); namespace Core { -CSettingsDialog::CSettingsDialog(ExtensionSystem::IPluginManager *pluginManager, +CSettingsDialog::CSettingsDialog(CorePlugin *corePlugin, const QString &categoryId, const QString &pageId, QWidget *parent) @@ -42,7 +45,7 @@ CSettingsDialog::CSettingsDialog(ExtensionSystem::IPluginManager *pluginManager, { _ui.setupUi(this); - _plugMan = pluginManager; + _plugMan = corePlugin->pluginManager(); QString initialCategory = categoryId; QString initialPage = pageId; @@ -59,14 +62,7 @@ CSettingsDialog::CSettingsDialog(ExtensionSystem::IPluginManager *pluginManager, QMap categories; - QList pages; - QList all = _plugMan->allObjects(); - Q_FOREACH(QObject *obj, all) - { - IOptionsPage *page = qobject_cast(obj); - if (page) - pages.append(page); - } + QList pages = corePlugin->getObjects(); int index = 0; Q_FOREACH(IOptionsPage *page, pages) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.h index 2ca58236a..ce461b234 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/settings_dialog.h @@ -25,11 +25,12 @@ #include // Project includes -#include "ioptions_page.h" #include "../../extension_system/iplugin.h" namespace Core { +class CorePlugin; +class IOptionsPage; /** @class CSettingsDialog @@ -40,7 +41,7 @@ class CSettingsDialog: public QDialog Q_OBJECT public: - CSettingsDialog(ExtensionSystem::IPluginManager *pluginManager, + CSettingsDialog(CorePlugin *corePlugin, const QString &initialCategory = QString(), const QString &initialPage = QString(), QWidget *parent = 0); @@ -60,7 +61,7 @@ private Q_SLOTS: void apply(); private: - QList _pages; + QList _pages; bool _applied; QString _currentCategory; QString _currentPage; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp index 07185c5fa..ba9df39c2 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/plugin1.cpp @@ -18,15 +18,24 @@ namespace Plugin { +MyPlugin::~MyPlugin() +{ + Q_FOREACH(QObject *obj, _autoReleaseObjects) + { + _plugMan->removeObject(obj); + } + qDeleteAll(_autoReleaseObjects); + _autoReleaseObjects.clear(); +} bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString) { Q_UNUSED(errorString); _plugMan = pluginManager; - _plugMan->addObject(new CExampleSettingsPage(this)); - _plugMan->addObject(new CExampleAppPage(this)); - _plugMan->addObject(new CCoreListener(this)); + addAutoReleasedObject(new CExampleSettingsPage(this)); + addAutoReleasedObject(new CExampleAppPage(this)); + addAutoReleasedObject(new CCoreListener(this)); return true; } @@ -69,6 +78,12 @@ QList MyPlugin::dependencies() const return QList(); } +void MyPlugin::addAutoReleasedObject(QObject *obj) +{ + _plugMan->addObject(obj); + _autoReleaseObjects.prepend(obj); +} + QObject* MyPlugin::objectByName(const QString &name) const { Q_FOREACH (QObject *qobj, _plugMan->allObjects()) 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 8c582f96a..a6374db60 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 @@ -32,6 +32,8 @@ class MyPlugin : public QObject, public ExtensionSystem::IPlugin Q_INTERFACES(ExtensionSystem::IPlugin) public: + virtual ~MyPlugin(); + bool initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString); void extensionsInitialized(); @@ -43,6 +45,8 @@ public: QString description() const; QList dependencies() const; + void addAutoReleasedObject(QObject *obj); + QObject *objectByName(const QString &name) const; ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const; @@ -51,7 +55,7 @@ protected: private: ExtensionSystem::IPluginManager *_plugMan; - + QList _autoReleaseObjects; }; class CExampleAppPage: public QObject, public Core::IAppPage diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/ovqt_sheet_builder/ovqt_sheet_builder.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/ovqt_sheet_builder/ovqt_sheet_builder.cpp index daf907d09..f9c660d94 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/ovqt_sheet_builder/ovqt_sheet_builder.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/ovqt_sheet_builder/ovqt_sheet_builder.cpp @@ -41,63 +41,63 @@ bool SheetBuilderPlugin::initialize(ExtensionSystem::IPluginManager *pluginManag *errorString = tr("Not found MainWindow Object Viewer Qt."); return false; } - QMenu *toolsMenu = qobject_cast(objectByName("ovqt.Menu.Tools")); - if (!toolsMenu) - { - *errorString = tr("Not found QMenu Tools."); - return false; - } + QMenu *toolsMenu = qobject_cast(objectByName("ovqt.Menu.Tools")); + if (!toolsMenu) + { + *errorString = tr("Not found QMenu Tools."); + return false; + } return true; } void SheetBuilderPlugin::extensionsInitialized() { - QMenu *toolsMenu = qobject_cast(objectByName("ovqt.Menu.Tools")); - nlassert(toolsMenu); + QMenu *toolsMenu = qobject_cast(objectByName("ovqt.Menu.Tools")); + nlassert(toolsMenu); - toolsMenu->addSeparator(); + toolsMenu->addSeparator(); - QAction *actBuilder = toolsMenu->addAction("Sheet builder"); - connect(actBuilder, SIGNAL(triggered()), this, SLOT(execBuilderDialog())); + QAction *actBuilder = toolsMenu->addAction("Sheet builder"); + connect(actBuilder, SIGNAL(triggered()), this, SLOT(execBuilderDialog())); } void SheetBuilderPlugin::execBuilderDialog() { - QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); - nlassert(wnd); + QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); + nlassert(wnd); - SheetBuilderDialog dlg(wnd); - dlg.exec(); + SheetBuilderDialog dlg(wnd); + dlg.exec(); } void SheetBuilderPlugin::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()); + // 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); + _LibContext = new NLMISC::CLibraryContext(*nelContext); } QString SheetBuilderPlugin::name() const { - return "Sheet builder"; + return "Sheet builder"; } QString SheetBuilderPlugin::version() const { - return "1.0"; + return "1.0"; } QString SheetBuilderPlugin::vendor() const { - return "kharvd"; + return "kharvd"; } QString SheetBuilderPlugin::description() const { - return "make_sheet_id equivalent"; + return "make_sheet_id equivalent"; } QList SheetBuilderPlugin::dependencies() const @@ -107,18 +107,18 @@ QList SheetBuilderPlugin::dependencies() const QObject* SheetBuilderPlugin::objectByName(const QString &name) const { - Q_FOREACH (QObject *qobj, _plugMan->allObjects()) - if (qobj->objectName() == name) - return qobj; - return 0; + Q_FOREACH (QObject *qobj, _plugMan->allObjects()) + if (qobj->objectName() == name) + return qobj; + return 0; } ExtensionSystem::IPluginSpec *SheetBuilderPlugin::pluginByName(const QString &name) const { - Q_FOREACH (ExtensionSystem::IPluginSpec *spec, _plugMan->plugins()) - if (spec->name() == name) - return spec; - return 0; + Q_FOREACH (ExtensionSystem::IPluginSpec *spec, _plugMan->plugins()) + if (spec->name() == name) + return spec; + return 0; } Q_EXPORT_PLUGIN(SheetBuilderPlugin)