mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-22 23:26:15 +00:00
Changed: #1206 correct fix is to load the plugins and update ovqt example plugin.
This commit is contained in:
parent
17407f813c
commit
e019d92dea
15 changed files with 170 additions and 85 deletions
|
@ -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
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef IPLUGIN_H
|
||||
#define IPLUGIN_H
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#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
|
||||
|
|
|
@ -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<NLQT::CPluginSpec *> plugins() const = 0;
|
||||
|
||||
virtual CPluginSpec *pluginByName(const QString &name) const = 0;
|
||||
virtual QList<NLQT::IPluginSpec *> plugins() const = 0;
|
||||
|
||||
Q_SIGNALS:
|
||||
void objectAdded(QObject *obj);
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
Object Viewer Qt
|
||||
Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef IPLUGINSPEC_H
|
||||
#define IPLUGINSPEC_H
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
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
|
||||
|
|
@ -109,15 +109,16 @@ void CPluginManager::setPluginPaths(const QStringList &paths)
|
|||
readPluginPaths();
|
||||
}
|
||||
|
||||
QList<CPluginSpec *> CPluginManager::plugins() const
|
||||
QList<IPluginSpec *> 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())
|
||||
|
|
|
@ -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<CPluginSpec *> plugins() const;
|
||||
|
||||
virtual CPluginSpec *pluginByName(const QString &name) const;
|
||||
virtual QList<IPluginSpec *> plugins() const;
|
||||
|
||||
private:
|
||||
void setPluginState(CPluginSpec *spec, int destState);
|
||||
|
@ -60,6 +59,7 @@ private:
|
|||
mutable QReadWriteLock _lock;
|
||||
|
||||
QList<CPluginSpec *> _pluginSpecs;
|
||||
QList<IPluginSpec *> _ipluginSpecs;
|
||||
QStringList _pluginPaths;
|
||||
QList<QObject *> _allObjects;
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "plugin_spec.h"
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QPluginLoader>
|
||||
|
@ -40,10 +41,6 @@ CPluginSpec::CPluginSpec():
|
|||
{
|
||||
}
|
||||
|
||||
CPluginSpec::~CPluginSpec()
|
||||
{
|
||||
}
|
||||
|
||||
QString CPluginSpec::name() const
|
||||
{
|
||||
return _name;
|
||||
|
|
|
@ -20,48 +20,29 @@
|
|||
#ifndef PLUGINSPEC_H
|
||||
#define PLUGINSPEC_H
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QList>
|
||||
#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();
|
||||
|
|
|
@ -19,12 +19,24 @@
|
|||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="4">
|
||||
<widget class="QTreeWidget" name="pluginTreeWidget">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="indentation">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="itemsExpandable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>State</string>
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <QtGui/QTreeWidgetItem>
|
||||
|
||||
// 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<QTreeWidgetItem *> items;
|
||||
Q_FOREACH (CPluginSpec *spec, _pluginManager->plugins())
|
||||
Q_FOREACH (IPluginSpec *spec, _pluginManager->plugins())
|
||||
{
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList()
|
||||
<< ""
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <nel/misc/file.h>
|
||||
#include <nel/misc/path.h>
|
||||
#include <nel/misc/command.h>
|
||||
#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());
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
#include <QtCore/QObject>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QMenuBar>
|
||||
|
||||
#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<NLQT::CPluginSpec *> listPlug = pluginManager->plugins();
|
||||
QList<NLQT::IPluginSpec *> 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<QObject *> 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<QMenu *>(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<QMainWindow *>(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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue