From 8b03a1d829ba2f14a1de561555d27120ac3d7648 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Sat, 12 Feb 2011 18:07:05 +0200 Subject: [PATCH] Changed: #1206 Settings are located in a centralized place(plugin manager). Update core and example plugin. --- .../object_viewer_qt/src/camera_control.cpp | 2 +- .../src/extension_system/iplugin_manager.h | 13 ++- .../src/extension_system/plugin_manager.cpp | 41 +++++++-- .../src/extension_system/plugin_manager.h | 8 ++ .../tools/3d/object_viewer_qt/src/main.cpp | 25 +++--- .../src/plugins/core/core_plugin.cpp | 85 ++++++++++--------- .../src/plugins/core/core_plugin.h | 17 ++++ .../src/plugins/core/main_window.cpp | 5 ++ .../src/plugins/core/main_window.h | 2 + .../core/search_paths_settings_page.ui | 2 +- .../plugins/example/example_settings_page.ui | 3 + .../src/plugins/example/plugin1.cpp | 33 +------ .../src/plugins/example/plugin1.h | 3 - 13 files changed, 142 insertions(+), 97 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp b/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp index 72b04129e..916158cc6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp @@ -183,7 +183,7 @@ CCameraControl::CCameraControl(QWidget *parent) CCameraControl::~CCameraControl() { - for(int i = 0; i < _cameraList.size(); ++i) + for(size_t i = 0; i < _cameraList.size(); ++i) delete _cameraList[i]; _cameraList.clear(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h index 18605f133..4874d6b47 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_manager.h @@ -23,16 +23,17 @@ #include #include #include +#include namespace ExtensionSystem { class IPluginSpec; /** -@interface IPluginManager -@brief Interface for plugin system that manages the plugins, their life cycle and their registered objects. -@details The plugin manager is used for the following tasks: -- Manage plugins and their state +@interface IPluginManager +@brief Interface for plugin system that manages the plugins, their life cycle and their registered objects. +@details The plugin manager is used for the following tasks: +- Manage plugins and their state - Manipulate a 'common object pool' */ class IPluginManager: public QObject @@ -53,6 +54,10 @@ public: virtual QStringList getPluginPaths() const = 0; virtual void setPluginPaths(const QStringList &paths) = 0; virtual QList plugins() const = 0; + + // Settings + virtual void setSettings(QSettings *settings) = 0; + virtual QSettings *settings() const = 0; Q_SIGNALS: void objectAdded(QObject *obj); diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp index d400cc6aa..b6e70fdf5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.cpp @@ -28,14 +28,16 @@ namespace ExtensionSystem { -CPluginManager::CPluginManager(QObject *parent): - IPluginManager(parent) +CPluginManager::CPluginManager(QObject *parent) + :IPluginManager(parent), + _settings(0) { } CPluginManager::~CPluginManager() { stopAll(); + deleteAll(); qDeleteAll(_pluginSpecs); } @@ -92,8 +94,10 @@ void CPluginManager::loadPlugins() Q_FOREACH (CPluginSpec *spec, _pluginSpecs) setPluginState(spec, State::Initialized); - Q_FOREACH (CPluginSpec *spec, _pluginSpecs) - setPluginState(spec, State::Running); + QListIterator it(_pluginSpecs); + it.toBack(); + while (it.hasPrevious()) + setPluginState(it.previous(), State::Running); Q_EMIT pluginsChanged(); } @@ -114,6 +118,24 @@ QList CPluginManager::plugins() const return _ipluginSpecs; } +void CPluginManager::setSettings(QSettings *settings) +{ + _settings = settings; +} + +QSettings *CPluginManager::settings() const +{ + return _settings; +} + +void CPluginManager::readSettings() +{ +} + +void CPluginManager::writeSettings() +{ +} + void CPluginManager::readPluginPaths() { qDeleteAll(_pluginSpecs); @@ -176,9 +198,16 @@ void CPluginManager::stopAll() { Q_FOREACH (CPluginSpec *spec, _pluginSpecs) setPluginState(spec, State::Stopped); +} - Q_FOREACH (CPluginSpec *spec, _pluginSpecs) - setPluginState(spec, State::Deleted); +void CPluginManager::deleteAll() +{ + QListIterator it(_pluginSpecs); + it.toBack(); + while (it.hasPrevious()) + { + setPluginState(it.previous(), State::Deleted); + } } }; // namespace NLQT \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.h index 39e1044c0..eeef76836 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.h +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_manager.h @@ -50,14 +50,22 @@ public: virtual QStringList getPluginPaths() const; virtual void setPluginPaths(const QStringList &paths); virtual QList plugins() const; + + // Settings + virtual void setSettings(QSettings *settings); + virtual QSettings *settings() const; + void readSettings(); + void writeSettings(); private: void setPluginState(CPluginSpec *spec, int destState); void readPluginPaths(); void stopAll(); + void deleteAll(); mutable QReadWriteLock _lock; + QSettings *_settings; QList _pluginSpecs; QList _ipluginSpecs; QStringList _pluginPaths; diff --git a/code/nel/tools/3d/object_viewer_qt/src/main.cpp b/code/nel/tools/3d/object_viewer_qt/src/main.cpp index e0671f478..b97e07c0a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/main.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/main.cpp @@ -21,6 +21,7 @@ // Qt includes #include +#include #include #include #include @@ -112,11 +113,14 @@ sint main(int argc, char **argv) #if defined(NL_OS_MAC) QDir::setCurrent(qApp->applicationDirPath() + QString("/../Resources")); - CLibrary::addLibPath( - (qApp->applicationDirPath() + QString("/../PlugIns/nel")).toStdString()); + CLibrary::addLibPath((qApp->applicationDirPath() + QString("/../PlugIns/nel")).toStdString()); #endif Modules::init(); + QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, + QLatin1String("Ryzom Core"), QLatin1String("ObjectViewerQt")); + + Modules::plugMan().setSettings(settings); // load and set remap extensions from config Modules::config().configRemapExtensions(); @@ -129,21 +133,20 @@ sint main(int argc, char **argv) #if !defined(NL_OS_MAC) Modules::plugMan().setPluginPaths(QStringList() << QString("./plugins")); #else - Modules::plugMan().setPluginPaths(QStringList() << - qApp->applicationDirPath() + QString("/../PlugIns/ovqt")); + Modules::plugMan().setPluginPaths(QStringList() << + qApp->applicationDirPath() + QString("/../PlugIns/ovqt")); #endif Modules::plugMan().loadPlugins(); - + QStringList errors; Q_FOREACH (ExtensionSystem::IPluginSpec *spec, Modules::plugMan().plugins()) - if (spec->hasError()) - errors.append(spec->fileName() + " : " + spec->errorString()); - + if (spec->hasError()) + errors.append(spec->fileName() + " : " + spec->errorString()); + if (!errors.isEmpty()) - QMessageBox::warning(0, - QCoreApplication::translate("Application", "Object Viewer Qt - Plugin loader messages"), - errors.join(QString::fromLatin1("\n\n"))); + QMessageBox::warning(0, QCoreApplication::translate("Application", "Object Viewer Qt - Plugin loader messages"), + errors.join(QString::fromLatin1("\n\n"))); splash->finish(&Modules::mainWin()); int result = app.exec(); 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 40ced76e5..fc30b3ce3 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 @@ -40,59 +40,64 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr { Q_UNUSED(errorString); _plugMan = pluginManager; - // for old ovqt - QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); - if (!wnd) - { - *errorString = tr("Not found QMainWindow Object Viewer Qt."); - return false; - } + oldOVQT = false; - _plugMan->addObject(new CSearchPathsSettingsPage(wnd)); + _plugMan->addObject(new CSearchPathsSettingsPage(this)); return true; } void CorePlugin::extensionsInitialized() { - // for old ovqt _pluginView = new ExtensionSystem::CPluginView(_plugMan); - - QMenu *toolsMenu = qobject_cast(objectByName("ovqt.Menu.Tools")); - QMenu *helpMenu = qobject_cast(objectByName("ovqt.Menu.Help")); - nlassert(toolsMenu); - nlassert(helpMenu); - - QAction *newAction = toolsMenu->addAction(tr("New settings")); - QAction *newAction2 = helpMenu->addAction(tr("About plugins")); - newAction->setIcon(QIcon(Constants::ICON_SETTINGS)); - - connect(newAction, SIGNAL(triggered()), this, SLOT(execSettings())); - connect(newAction2, SIGNAL(triggered()), _pluginView, SLOT(show())); - - _mainWindow = new CMainWindow(_plugMan); -#ifdef Q_WS_X11 - _mainWindow->setAttribute(Qt::WA_TranslucentBackground); - _mainWindow->setAttribute(Qt::WA_NoSystemBackground, false); - QPalette pal = _mainWindow->palette(); - QColor bg = pal.window().color(); - bg.setAlpha(180); - pal.setColor(QPalette::Window, bg); - _mainWindow->setPalette(pal); - _mainWindow->ensurePolished(); // workaround Oxygen filling the background - _mainWindow->setAttribute(Qt::WA_StyledBackground, false); -#endif - if (QtWin::isCompositionEnabled()) + + // for old ovqt + QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); + if (wnd) { - QtWin::extendFrameIntoClientArea(_mainWindow); - _mainWindow->setContentsMargins(0, 0, 0, 0); + _pluginView = new ExtensionSystem::CPluginView(_plugMan); + QMenu *toolsMenu = qobject_cast(objectByName("ovqt.Menu.Tools")); + QMenu *helpMenu = qobject_cast(objectByName("ovqt.Menu.Help")); + nlassert(toolsMenu); + nlassert(helpMenu); + + QAction *newAction = toolsMenu->addAction(tr("New settings")); + QAction *newAction2 = helpMenu->addAction(tr("About plugins")); + newAction->setIcon(QIcon(Constants::ICON_SETTINGS)); + + connect(newAction, SIGNAL(triggered()), this, SLOT(execSettings())); + connect(newAction2, SIGNAL(triggered()), _pluginView, SLOT(show())); + oldOVQT = true; + } + else + { + _mainWindow = new CMainWindow(_plugMan); +#ifdef Q_WS_X11 + _mainWindow->setAttribute(Qt::WA_TranslucentBackground); + _mainWindow->setAttribute(Qt::WA_NoSystemBackground, false); + QPalette pal = _mainWindow->palette(); + QColor bg = pal.window().color(); + bg.setAlpha(180); + pal.setColor(QPalette::Window, bg); + _mainWindow->setPalette(pal); + _mainWindow->ensurePolished(); // workaround Oxygen filling the background + _mainWindow->setAttribute(Qt::WA_StyledBackground, false); +#endif + if (QtWin::isCompositionEnabled()) + { + QtWin::extendFrameIntoClientArea(_mainWindow); + _mainWindow->setContentsMargins(0, 0, 0, 0); + } + _mainWindow->show(); } - _mainWindow->show(); } void CorePlugin::shutdown() { - delete _mainWindow; - delete _pluginView; + if (!oldOVQT) + { + delete _mainWindow; + delete _pluginView; + } } void CorePlugin::execSettings() 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 1092bacaf..252b6549a 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 @@ -58,6 +58,21 @@ public: QObject *objectByName(const QString &name) const; ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const; + ExtensionSystem::IPluginManager *pluginManager() const { return _plugMan; } + + template + QList getObjects() const + { + QList all = _plugMan->allObjects(); + QList objects; + Q_FOREACH(QObject *obj, all) + { + Type *typeObj = qobject_cast(obj); + if (typeObj) + objects.append(typeObj); + } + return objects; + } protected: NLMISC::CLibraryContext *_LibContext; @@ -69,6 +84,8 @@ private: ExtensionSystem::IPluginManager *_plugMan; ExtensionSystem::CPluginView *_pluginView; CMainWindow *_mainWindow; + + 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 fe75db99c..b077b25c2 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 @@ -96,6 +96,11 @@ void CMainWindow::about() "

Author: dnk-88

Compiled on %1 %2").arg(__DATE__).arg(__TIME__)); } +void CMainWindow::closeEvent(QCloseEvent *event) +{ + QMainWindow::closeEvent(event); +} + void CMainWindow::createActions() { _openAction = new QAction(tr("&Open..."), this); 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 517da92d2..3f2555d82 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 @@ -50,6 +50,8 @@ private Q_SLOTS: const QString &page = QString(), QWidget *parent = 0); void about(); +protected: + virtual void closeEvent(QCloseEvent *event); private: void createActions(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.ui index 469846d02..f0d08e40b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/search_paths_settings_page.ui @@ -15,7 +15,7 @@ - 9 + 0 diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.ui index 224a783fa..b839d98ce 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/example_settings_page.ui @@ -14,6 +14,9 @@ Form + + 0 + 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 a93a8b95c..b77be4892 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 @@ -24,42 +24,13 @@ bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStrin Q_UNUSED(errorString); _plugMan = pluginManager; - QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); - _plugMan->addObject(new CExampleSettingsPage(wnd)); - if (!wnd) - { - *errorString = tr("Not found QMainWindow Object Viewer Qt."); - return false; - } - QMenu *helpMenu = qobject_cast(objectByName("ovqt.Menu.Tools")); - if (!helpMenu) - { - *errorString = tr("Not found QMenu Help."); - return false; - } - _plugMan->addObject(new CExampleAppPage()); + _plugMan->addObject(new CExampleSettingsPage(this)); + _plugMan->addObject(new CExampleAppPage(this)); return true; } void MyPlugin::extensionsInitialized() { - QMenu *helpMenu = qobject_cast(objectByName("ovqt.Menu.Help")); - nlassert(helpMenu); - - helpMenu->addSeparator(); - QAction *newAction = helpMenu->addAction("MyPlugin"); - - connect(newAction, SIGNAL(triggered()), this, SLOT(execMessageBox())); -} - -void MyPlugin::execMessageBox() -{ - QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); - nlassert(wnd); - - QMessageBox msgBox; - msgBox.setText(wnd->objectName() + QString(": width=%1,height=%2").arg(wnd->width()).arg(wnd->height())); - msgBox.exec(); } void MyPlugin::setNelContext(NLMISC::INelContext *nelContext) 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 291d3238f..8c582f96a 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 @@ -46,9 +46,6 @@ public: QObject *objectByName(const QString &name) const; ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const; -private Q_SLOTS: - void execMessageBox(); - protected: NLMISC::CLibraryContext *_LibContext;