mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-20 06:06:13 +00:00
Changed: #1206 Settings are located in a centralized place(plugin manager). Update core and example plugin.
This commit is contained in:
parent
d306700e6e
commit
8b03a1d829
13 changed files with 142 additions and 97 deletions
|
@ -183,7 +183,7 @@ CCameraControl::CCameraControl(QWidget *parent)
|
||||||
|
|
||||||
CCameraControl::~CCameraControl()
|
CCameraControl::~CCameraControl()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < _cameraList.size(); ++i)
|
for(size_t i = 0; i < _cameraList.size(); ++i)
|
||||||
delete _cameraList[i];
|
delete _cameraList[i];
|
||||||
_cameraList.clear();
|
_cameraList.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
#include <QtCore/QSettings>
|
||||||
|
|
||||||
namespace ExtensionSystem
|
namespace ExtensionSystem
|
||||||
{
|
{
|
||||||
|
@ -54,6 +55,10 @@ public:
|
||||||
virtual void setPluginPaths(const QStringList &paths) = 0;
|
virtual void setPluginPaths(const QStringList &paths) = 0;
|
||||||
virtual QList<ExtensionSystem::IPluginSpec *> plugins() const = 0;
|
virtual QList<ExtensionSystem::IPluginSpec *> plugins() const = 0;
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
virtual void setSettings(QSettings *settings) = 0;
|
||||||
|
virtual QSettings *settings() const = 0;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void objectAdded(QObject *obj);
|
void objectAdded(QObject *obj);
|
||||||
void aboutToRemoveObject(QObject *obj);
|
void aboutToRemoveObject(QObject *obj);
|
||||||
|
|
|
@ -28,14 +28,16 @@
|
||||||
namespace ExtensionSystem
|
namespace ExtensionSystem
|
||||||
{
|
{
|
||||||
|
|
||||||
CPluginManager::CPluginManager(QObject *parent):
|
CPluginManager::CPluginManager(QObject *parent)
|
||||||
IPluginManager(parent)
|
:IPluginManager(parent),
|
||||||
|
_settings(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CPluginManager::~CPluginManager()
|
CPluginManager::~CPluginManager()
|
||||||
{
|
{
|
||||||
stopAll();
|
stopAll();
|
||||||
|
deleteAll();
|
||||||
qDeleteAll(_pluginSpecs);
|
qDeleteAll(_pluginSpecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +94,10 @@ void CPluginManager::loadPlugins()
|
||||||
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
|
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
|
||||||
setPluginState(spec, State::Initialized);
|
setPluginState(spec, State::Initialized);
|
||||||
|
|
||||||
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
|
QListIterator<CPluginSpec *> it(_pluginSpecs);
|
||||||
setPluginState(spec, State::Running);
|
it.toBack();
|
||||||
|
while (it.hasPrevious())
|
||||||
|
setPluginState(it.previous(), State::Running);
|
||||||
|
|
||||||
Q_EMIT pluginsChanged();
|
Q_EMIT pluginsChanged();
|
||||||
}
|
}
|
||||||
|
@ -114,6 +118,24 @@ QList<IPluginSpec *> CPluginManager::plugins() const
|
||||||
return _ipluginSpecs;
|
return _ipluginSpecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPluginManager::setSettings(QSettings *settings)
|
||||||
|
{
|
||||||
|
_settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings *CPluginManager::settings() const
|
||||||
|
{
|
||||||
|
return _settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPluginManager::readSettings()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPluginManager::writeSettings()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void CPluginManager::readPluginPaths()
|
void CPluginManager::readPluginPaths()
|
||||||
{
|
{
|
||||||
qDeleteAll(_pluginSpecs);
|
qDeleteAll(_pluginSpecs);
|
||||||
|
@ -176,9 +198,16 @@ void CPluginManager::stopAll()
|
||||||
{
|
{
|
||||||
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
|
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
|
||||||
setPluginState(spec, State::Stopped);
|
setPluginState(spec, State::Stopped);
|
||||||
|
}
|
||||||
|
|
||||||
Q_FOREACH (CPluginSpec *spec, _pluginSpecs)
|
void CPluginManager::deleteAll()
|
||||||
setPluginState(spec, State::Deleted);
|
{
|
||||||
|
QListIterator<CPluginSpec *> it(_pluginSpecs);
|
||||||
|
it.toBack();
|
||||||
|
while (it.hasPrevious())
|
||||||
|
{
|
||||||
|
setPluginState(it.previous(), State::Deleted);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace NLQT
|
}; // namespace NLQT
|
|
@ -51,13 +51,21 @@ public:
|
||||||
virtual void setPluginPaths(const QStringList &paths);
|
virtual void setPluginPaths(const QStringList &paths);
|
||||||
virtual QList<IPluginSpec *> plugins() const;
|
virtual QList<IPluginSpec *> plugins() const;
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
virtual void setSettings(QSettings *settings);
|
||||||
|
virtual QSettings *settings() const;
|
||||||
|
void readSettings();
|
||||||
|
void writeSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setPluginState(CPluginSpec *spec, int destState);
|
void setPluginState(CPluginSpec *spec, int destState);
|
||||||
void readPluginPaths();
|
void readPluginPaths();
|
||||||
void stopAll();
|
void stopAll();
|
||||||
|
void deleteAll();
|
||||||
|
|
||||||
mutable QReadWriteLock _lock;
|
mutable QReadWriteLock _lock;
|
||||||
|
|
||||||
|
QSettings *_settings;
|
||||||
QList<CPluginSpec *> _pluginSpecs;
|
QList<CPluginSpec *> _pluginSpecs;
|
||||||
QList<IPluginSpec *> _ipluginSpecs;
|
QList<IPluginSpec *> _ipluginSpecs;
|
||||||
QStringList _pluginPaths;
|
QStringList _pluginPaths;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
|
#include <QtCore/QSettings>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QSplashScreen>
|
#include <QtGui/QSplashScreen>
|
||||||
|
@ -112,11 +113,14 @@ sint main(int argc, char **argv)
|
||||||
|
|
||||||
#if defined(NL_OS_MAC)
|
#if defined(NL_OS_MAC)
|
||||||
QDir::setCurrent(qApp->applicationDirPath() + QString("/../Resources"));
|
QDir::setCurrent(qApp->applicationDirPath() + QString("/../Resources"));
|
||||||
CLibrary::addLibPath(
|
CLibrary::addLibPath((qApp->applicationDirPath() + QString("/../PlugIns/nel")).toStdString());
|
||||||
(qApp->applicationDirPath() + QString("/../PlugIns/nel")).toStdString());
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Modules::init();
|
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
|
// load and set remap extensions from config
|
||||||
Modules::config().configRemapExtensions();
|
Modules::config().configRemapExtensions();
|
||||||
|
@ -141,8 +145,7 @@ sint main(int argc, char **argv)
|
||||||
errors.append(spec->fileName() + " : " + spec->errorString());
|
errors.append(spec->fileName() + " : " + spec->errorString());
|
||||||
|
|
||||||
if (!errors.isEmpty())
|
if (!errors.isEmpty())
|
||||||
QMessageBox::warning(0,
|
QMessageBox::warning(0, QCoreApplication::translate("Application", "Object Viewer Qt - Plugin loader messages"),
|
||||||
QCoreApplication::translate("Application", "Object Viewer Qt - Plugin loader messages"),
|
|
||||||
errors.join(QString::fromLatin1("\n\n")));
|
errors.join(QString::fromLatin1("\n\n")));
|
||||||
|
|
||||||
splash->finish(&Modules::mainWin());
|
splash->finish(&Modules::mainWin());
|
||||||
|
|
|
@ -40,23 +40,21 @@ bool CorePlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStr
|
||||||
{
|
{
|
||||||
Q_UNUSED(errorString);
|
Q_UNUSED(errorString);
|
||||||
_plugMan = pluginManager;
|
_plugMan = pluginManager;
|
||||||
// for old ovqt
|
oldOVQT = false;
|
||||||
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
|
|
||||||
if (!wnd)
|
|
||||||
{
|
|
||||||
*errorString = tr("Not found QMainWindow Object Viewer Qt.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_plugMan->addObject(new CSearchPathsSettingsPage(wnd));
|
_plugMan->addObject(new CSearchPathsSettingsPage(this));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CorePlugin::extensionsInitialized()
|
void CorePlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
// for old ovqt
|
|
||||||
_pluginView = new ExtensionSystem::CPluginView(_plugMan);
|
_pluginView = new ExtensionSystem::CPluginView(_plugMan);
|
||||||
|
|
||||||
|
// for old ovqt
|
||||||
|
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
|
||||||
|
if (wnd)
|
||||||
|
{
|
||||||
|
_pluginView = new ExtensionSystem::CPluginView(_plugMan);
|
||||||
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
|
QMenu *toolsMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
|
||||||
QMenu *helpMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Help"));
|
QMenu *helpMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Help"));
|
||||||
nlassert(toolsMenu);
|
nlassert(toolsMenu);
|
||||||
|
@ -68,7 +66,10 @@ void CorePlugin::extensionsInitialized()
|
||||||
|
|
||||||
connect(newAction, SIGNAL(triggered()), this, SLOT(execSettings()));
|
connect(newAction, SIGNAL(triggered()), this, SLOT(execSettings()));
|
||||||
connect(newAction2, SIGNAL(triggered()), _pluginView, SLOT(show()));
|
connect(newAction2, SIGNAL(triggered()), _pluginView, SLOT(show()));
|
||||||
|
oldOVQT = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_mainWindow = new CMainWindow(_plugMan);
|
_mainWindow = new CMainWindow(_plugMan);
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
_mainWindow->setAttribute(Qt::WA_TranslucentBackground);
|
_mainWindow->setAttribute(Qt::WA_TranslucentBackground);
|
||||||
|
@ -88,12 +89,16 @@ void CorePlugin::extensionsInitialized()
|
||||||
}
|
}
|
||||||
_mainWindow->show();
|
_mainWindow->show();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CorePlugin::shutdown()
|
void CorePlugin::shutdown()
|
||||||
|
{
|
||||||
|
if (!oldOVQT)
|
||||||
{
|
{
|
||||||
delete _mainWindow;
|
delete _mainWindow;
|
||||||
delete _pluginView;
|
delete _pluginView;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CorePlugin::execSettings()
|
void CorePlugin::execSettings()
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,6 +58,21 @@ public:
|
||||||
|
|
||||||
QObject *objectByName(const QString &name) const;
|
QObject *objectByName(const QString &name) const;
|
||||||
ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const;
|
ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const;
|
||||||
|
ExtensionSystem::IPluginManager *pluginManager() const { return _plugMan; }
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
|
QList<Type *> getObjects() const
|
||||||
|
{
|
||||||
|
QList<QObject *> all = _plugMan->allObjects();
|
||||||
|
QList<Type *> objects;
|
||||||
|
Q_FOREACH(QObject *obj, all)
|
||||||
|
{
|
||||||
|
Type *typeObj = qobject_cast<Type *>(obj);
|
||||||
|
if (typeObj)
|
||||||
|
objects.append(typeObj);
|
||||||
|
}
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NLMISC::CLibraryContext *_LibContext;
|
NLMISC::CLibraryContext *_LibContext;
|
||||||
|
@ -69,6 +84,8 @@ private:
|
||||||
ExtensionSystem::IPluginManager *_plugMan;
|
ExtensionSystem::IPluginManager *_plugMan;
|
||||||
ExtensionSystem::CPluginView *_pluginView;
|
ExtensionSystem::CPluginView *_pluginView;
|
||||||
CMainWindow *_mainWindow;
|
CMainWindow *_mainWindow;
|
||||||
|
|
||||||
|
bool oldOVQT;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
|
@ -96,6 +96,11 @@ void CMainWindow::about()
|
||||||
"<p> Author: dnk-88 <p>Compiled on %1 %2").arg(__DATE__).arg(__TIME__));
|
"<p> Author: dnk-88 <p>Compiled on %1 %2").arg(__DATE__).arg(__TIME__));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMainWindow::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
QMainWindow::closeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void CMainWindow::createActions()
|
void CMainWindow::createActions()
|
||||||
{
|
{
|
||||||
_openAction = new QAction(tr("&Open..."), this);
|
_openAction = new QAction(tr("&Open..."), this);
|
||||||
|
|
|
@ -50,6 +50,8 @@ private Q_SLOTS:
|
||||||
const QString &page = QString(),
|
const QString &page = QString(),
|
||||||
QWidget *parent = 0);
|
QWidget *parent = 0);
|
||||||
void about();
|
void about();
|
||||||
|
protected:
|
||||||
|
virtual void closeEvent(QCloseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createActions();
|
void createActions();
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="margin">
|
<property name="margin">
|
||||||
<number>9</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QGroupBox" name="searchPathsGroupBox">
|
<widget class="QGroupBox" name="searchPathsGroupBox">
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<property name="margin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
|
|
@ -24,42 +24,13 @@ bool MyPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QStrin
|
||||||
Q_UNUSED(errorString);
|
Q_UNUSED(errorString);
|
||||||
_plugMan = pluginManager;
|
_plugMan = pluginManager;
|
||||||
|
|
||||||
QMainWindow *wnd = qobject_cast<QMainWindow *>(objectByName("CMainWindow"));
|
_plugMan->addObject(new CExampleSettingsPage(this));
|
||||||
_plugMan->addObject(new CExampleSettingsPage(wnd));
|
_plugMan->addObject(new CExampleAppPage(this));
|
||||||
if (!wnd)
|
|
||||||
{
|
|
||||||
*errorString = tr("Not found QMainWindow Object Viewer Qt.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
QMenu *helpMenu = qobject_cast<QMenu *>(objectByName("ovqt.Menu.Tools"));
|
|
||||||
if (!helpMenu)
|
|
||||||
{
|
|
||||||
*errorString = tr("Not found QMenu Help.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_plugMan->addObject(new CExampleAppPage());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyPlugin::extensionsInitialized()
|
void MyPlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
QMenu *helpMenu = qobject_cast<QMenu *>(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<QMainWindow *>(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)
|
void MyPlugin::setNelContext(NLMISC::INelContext *nelContext)
|
||||||
|
|
|
@ -46,9 +46,6 @@ public:
|
||||||
QObject *objectByName(const QString &name) const;
|
QObject *objectByName(const QString &name) const;
|
||||||
ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const;
|
ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const;
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void execMessageBox();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NLMISC::CLibraryContext *_LibContext;
|
NLMISC::CLibraryContext *_LibContext;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue