From e019d92deaa6c1025653e0bc959a42b1d3b5a454 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Fri, 3 Dec 2010 12:21:12 +0200 Subject: [PATCH] Changed: #1206 correct fix is to load the plugins and update ovqt example plugin. --- .../3d/object_viewer_qt/src/CMakeLists.txt | 2 +- .../src/extension_system/iplugin.h | 4 +- .../src/extension_system/iplugin_manager.h | 6 +- .../src/extension_system/iplugin_spec.h | 69 +++++++++++++++++++ .../src/extension_system/plugin_manager.cpp | 14 ++-- .../src/extension_system/plugin_manager.h | 6 +- .../src/extension_system/plugin_spec.cpp | 5 +- .../src/extension_system/plugin_spec.h | 45 ++++-------- .../src/extension_system/plugin_view.ui | 12 ++++ .../src/extension_system/plugn_view.cpp | 4 +- .../tools/3d/object_viewer_qt/src/main.cpp | 4 +- .../3d/object_viewer_qt/src/main_window.cpp | 11 +++ .../src/plugins/example/CMakeLists.txt | 3 +- .../src/plugins/example/plugin1.cpp | 58 +++++++++------- .../src/plugins/example/plugin1.h | 12 ++++ 15 files changed, 170 insertions(+), 85 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_spec.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt index 543f4b464..9bca4cc8e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt @@ -3,7 +3,7 @@ INCLUDE( ${QT_USE_FILE} ) FILE(GLOB OBJECT_VIEWER_SRC configuration.h entity.h object_viewer.h particle_editor.h modules.h sound_system.h particle_node.h ps_initial_pos.h dup_ps.h vegetable_editor.h vegetable_node.h - extension_system/plugin_spec.h + extension_system/iplugin_spec.h extension_system/plugin_spec.h extension_system/*.cpp *.cpp) SET(OBJECT_VIEWER_HDR main_window.h graphics_viewport.h animation_dialog.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin.h index 93f61629a..300b8cfb1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin.h @@ -20,7 +20,7 @@ #ifndef IPLUGIN_H #define IPLUGIN_H -#include +#include #include #include "iplugin_manager.h" @@ -52,6 +52,6 @@ public: }; //namespace NLQT -Q_DECLARE_INTERFACE(NLQT::IPlugin, "com.ryzom.dev.ObjectViewerQt.IPlugin/0.8") +Q_DECLARE_INTERFACE(NLQT::IPlugin, "com.ryzom.dev.ObjectViewerQt.IPlugin/0.9") #endif // IPLUGIN_H 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 4592c0f47..dbcdb8463 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 @@ -26,7 +26,7 @@ namespace NLQT { -class CPluginSpec; +class IPluginSpec; class IPluginManager: public QObject { @@ -44,9 +44,7 @@ public: virtual void loadPlugins() = 0; virtual QStringList getPluginPaths() const = 0; virtual void setPluginPaths(const QStringList &paths) = 0; - virtual QList plugins() const = 0; - - virtual CPluginSpec *pluginByName(const QString &name) const = 0; + virtual QList plugins() const = 0; Q_SIGNALS: void objectAdded(QObject *obj); diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_spec.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_spec.h new file mode 100644 index 000000000..c0d7ee67c --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/iplugin_spec.h @@ -0,0 +1,69 @@ +/* + Object Viewer Qt + Copyright (C) 2010 Dzmitry Kamiahin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +#ifndef IPLUGINSPEC_H +#define IPLUGINSPEC_H + +#include + +namespace NLQT +{ +class IPlugin; +class IPluginManager; + +struct State +{ + enum List + { + Invalid = 1, + Read, + Loaded, + Initialized, + Running, + Stopped, + Deleted + }; +}; + +class IPluginSpec +{ +public: + virtual ~IPluginSpec() {} + + virtual QString name() const = 0; + virtual QString version() const = 0; + virtual QString vendor() const = 0; + virtual QString description() const = 0; + + virtual QString location() const = 0; + virtual QString filePath() const = 0; + virtual QString fileName() const = 0; + + virtual IPlugin *plugin() const = 0; + + // state + virtual int getState() const = 0; + virtual bool hasError() const = 0; + virtual QString errorString() const = 0; +}; + +} // namespace NLQT + +#endif // IPLUGINSPEC_H + 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 4d8371636..f19ac10f9 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 @@ -109,15 +109,16 @@ void CPluginManager::setPluginPaths(const QStringList &paths) readPluginPaths(); } -QList CPluginManager::plugins() const +QList CPluginManager::plugins() const { - return _pluginSpecs; + return _ipluginSpecs; } void CPluginManager::readPluginPaths() { qDeleteAll(_pluginSpecs); _pluginSpecs.clear(); + _ipluginSpecs.clear(); QStringList pluginsList; QStringList searchPaths = _pluginPaths; @@ -144,19 +145,12 @@ void CPluginManager::readPluginPaths() spec->setFileName(pluginFile); spec->_pluginManager = this; _pluginSpecs.append(spec); + _ipluginSpecs.append(spec); } Q_EMIT pluginsChanged(); } -CPluginSpec *CPluginManager::pluginByName(const QString &name) const -{ - Q_FOREACH (CPluginSpec *spec, _pluginSpecs) - if (spec->name() == name) - return spec; - return 0; -} - void CPluginManager::setPluginState(CPluginSpec *spec, int destState) { if (spec->hasError()) 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 3fb92e282..774817e60 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 @@ -30,6 +30,7 @@ namespace NLQT { class IPlugin; +class CPluginSpec; class CPluginManager : public IPluginManager { @@ -48,9 +49,7 @@ public: virtual void loadPlugins(); virtual QStringList getPluginPaths() const; virtual void setPluginPaths(const QStringList &paths); - virtual QList plugins() const; - - virtual CPluginSpec *pluginByName(const QString &name) const; + virtual QList plugins() const; private: void setPluginState(CPluginSpec *spec, int destState); @@ -60,6 +59,7 @@ private: mutable QReadWriteLock _lock; QList _pluginSpecs; + QList _ipluginSpecs; QStringList _pluginPaths; QList _allObjects; diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.cpp b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.cpp index d4a11f7d9..c0d0308cd 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.cpp @@ -19,6 +19,7 @@ #include "plugin_spec.h" +#include #include #include #include @@ -40,10 +41,6 @@ CPluginSpec::CPluginSpec(): { } -CPluginSpec::~CPluginSpec() -{ -} - QString CPluginSpec::name() const { return _name; diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.h b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.h index 955ee9544..156b93898 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.h +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_spec.h @@ -20,48 +20,29 @@ #ifndef PLUGINSPEC_H #define PLUGINSPEC_H -#include -#include +#include "iplugin_spec.h" namespace NLQT { -class IPlugin; -class IPluginManager; -struct State -{ - enum List - { - Invalid = 1, - Read, - Loaded, - Initialized, - Running, - Stopped, - Deleted - }; -}; - -class CPluginSpec +class CPluginSpec: public IPluginSpec { public: - ~CPluginSpec(); + virtual QString name() const; + virtual QString version() const; + virtual QString vendor() const; + virtual QString description() const; - QString name() const; - QString version() const; - QString vendor() const; - QString description() const; + virtual QString location() const; + virtual QString filePath() const; + virtual QString fileName() const; - QString location() const; - QString filePath() const; - QString fileName() const; - - IPlugin *plugin() const; + virtual IPlugin *plugin() const; // state - int getState() const; - bool hasError() const; - QString errorString() const; + virtual int getState() const; + virtual bool hasError() const; + virtual QString errorString() const; private: CPluginSpec(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_view.ui b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_view.ui index 65c24dd55..8bf90fdf3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_view.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugin_view.ui @@ -19,12 +19,24 @@ + + true + + + 0 + false + + true + false + + true + State diff --git a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugn_view.cpp b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugn_view.cpp index 03423d9c2..7aa610dcb 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugn_view.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/extension_system/plugn_view.cpp @@ -28,7 +28,7 @@ #include // Project includes -#include "plugin_spec.h" +#include "iplugin_spec.h" #include "iplugin_manager.h" namespace NLQT @@ -55,7 +55,7 @@ void CPluginView::updateList() static QIcon errorIcon = QApplication::style()->standardIcon(QStyle::SP_DialogCancelButton); QList items; - Q_FOREACH (CPluginSpec *spec, _pluginManager->plugins()) + Q_FOREACH (IPluginSpec *spec, _pluginManager->plugins()) { QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << "" 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 98dbc4f06..22fd4472a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/main.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/main.cpp @@ -13,7 +13,7 @@ #include #include #include -#include "extension_system/plugin_spec.h" +#include "extension_system/iplugin_spec.h" // Project includes #include "modules.h" @@ -103,7 +103,7 @@ sint main(int argc, char **argv) Modules::plugMan().loadPlugins(); QStringList errors; - Q_FOREACH (NLQT::CPluginSpec *spec, Modules::plugMan().plugins()) + Q_FOREACH (NLQT::IPluginSpec *spec, Modules::plugMan().plugins()) if (spec->hasError()) errors.append(spec->fileName() + " : " + spec->errorString()); diff --git a/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp index 6391fba43..ba2eb1f31 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp @@ -354,19 +354,23 @@ void CMainWindow::createActions() void CMainWindow::createMenus() { _fileMenu = menuBar()->addMenu(tr("&File")); + _fileMenu->setObjectName("ovqt.Menu.File"); _fileMenu->addAction(_openAction); _fileMenu->addSeparator(); _fileMenu->addAction(_exitAction); _viewMenu = menuBar()->addMenu(tr("&View")); + _viewMenu->setObjectName("ovqt.Menu.View"); _viewMenu->addAction(_setBackColorAction); _viewMenu->addAction(_SetupFog->toggleViewAction()); _sceneMenu = menuBar()->addMenu(tr("&Scene")); + _sceneMenu->setObjectName("ovqt.Menu.Scene"); _sceneMenu->addAction(_resetSceneAction); _sceneMenu->addAction(_saveScreenshotAction); _toolsMenu = menuBar()->addMenu(tr("&Tools")); + _toolsMenu->setObjectName("ovqt.Menu.Tools"); _toolsMenu->addAction(_AnimationDialog->toggleViewAction()); _AnimationDialog->toggleViewAction()->setIcon(QIcon(":/images/anim.png")); @@ -411,9 +415,16 @@ void CMainWindow::createMenus() menuBar()->addSeparator(); _helpMenu = menuBar()->addMenu(tr("&Help")); + _helpMenu->setObjectName("ovqt.Menu.Help"); _helpMenu->addAction(_aboutAction); _helpMenu->addAction(_aboutQtAction); _helpMenu->addAction(_pluginViewAction); + + Modules::plugMan().addObject(_fileMenu); + Modules::plugMan().addObject(_viewMenu); + Modules::plugMan().addObject(_sceneMenu); + Modules::plugMan().addObject(_toolsMenu); + Modules::plugMan().addObject(_helpMenu); } void CMainWindow::createToolBars() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt index 01fd08260..ef5a633f9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/example/CMakeLists.txt @@ -6,8 +6,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} FILE(GLOB SRC *.cpp *.h) SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.h ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_manager.h - ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/plugin_spec.h - ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/plugin_spec.cpp) + ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) SET(OVQT_PLUG_EXAMPLE_HDR plugin1.h) 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 56c4b3d76..6508a79d5 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 @@ -3,9 +3,11 @@ #include #include #include +#include +#include #include -#include "../../extension_system/plugin_spec.h" +#include "../../extension_system/iplugin_spec.h" #include "nel/misc/debug.h" @@ -17,36 +19,30 @@ bool MyPlugin::initialize(NLQT::IPluginManager *pluginManager, QString *errorStr _plugMan = pluginManager; QString str; - QList listPlug = pluginManager->plugins(); + QList listPlug = pluginManager->plugins(); - Q_FOREACH (NLQT::CPluginSpec *plugSpec, listPlug) + Q_FOREACH (NLQT::IPluginSpec *plugSpec, listPlug) str += plugSpec->name(); - QMessageBox msgBox; - msgBox.setText(str); - msgBox.exec(); - - nlinfo("test message"); + nlinfo(str.toStdString().c_str()); return true; } void MyPlugin::extensionsInitialized() { - QString str; - QList listObjects = _plugMan->allObjects(); - - Q_FOREACH (QObject *qobj, listObjects) - { - if (qobj->objectName() == "CMainWindow") - { - QMainWindow *wnd = qobject_cast< QMainWindow* >(qobj); - str += qobj->objectName() + QString(": width=%1,height=%2").arg(wnd->width()).arg(wnd->height()); - } - } + QMenu *helpMenu = qobject_cast(objectByName("ovqt.Menu.Help")); + helpMenu->addSeparator(); + QAction *newAction = helpMenu->addAction("MyPlugin"); + + connect(newAction, SIGNAL(triggered()), this, SLOT(execMessageBox())); +} +void MyPlugin::execMessageBox() +{ + QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); QMessageBox msgBox; - msgBox.setText(str); + msgBox.setText(wnd->objectName() + QString(": width=%1,height=%2").arg(wnd->width()).arg(wnd->height())); msgBox.exec(); } @@ -63,17 +59,33 @@ QString MyPlugin::name() const QString MyPlugin::version() const { - return "0.1"; + return "0.2"; } QString MyPlugin::vendor() const { - return "dnk"; + return "dnk-88"; } QString MyPlugin::description() const { - return "Example plugin"; + return "Example ovqt plugin."; } +QObject* MyPlugin::objectByName(const QString &name) const +{ + Q_FOREACH (QObject *qobj, _plugMan->allObjects()) + if (qobj->objectName() == name) + return qobj; + return 0; +} + +NLQT::IPluginSpec *MyPlugin::pluginByName(const QString &name) const +{ + Q_FOREACH (NLQT::IPluginSpec *spec, _plugMan->plugins()) + if (spec->name() == name) + return spec; + return 0; +} + Q_EXPORT_PLUGIN(MyPlugin) 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 03436177e..02d80e1dc 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 @@ -11,6 +11,12 @@ namespace NLMISC { class CLibraryContext; } + +namespace NLQT +{ +class IPluginSpec; +} + namespace Plugin { @@ -29,6 +35,12 @@ public: QString version() const; QString vendor() const; QString description() const; + + QObject *objectByName(const QString &name) const; + NLQT::IPluginSpec *pluginByName(const QString &name) const; + +private Q_SLOTS: + void execMessageBox(); protected: NLMISC::CLibraryContext *_LibContext;