mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-24 17:58:45 +00:00
Changed: #1206 Update core and example plugin. Plugin should delete your own objects from the pool.
This commit is contained in:
parent
4c7c4f8a21
commit
daf2fe51b3
9 changed files with 121 additions and 63 deletions
|
@ -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<QString> CorePlugin::dependencies() const
|
|||
return QList<QString>();
|
||||
}
|
||||
|
||||
void CorePlugin::addAutoReleasedObject(QObject *obj)
|
||||
{
|
||||
_plugMan->addObject(obj);
|
||||
_autoReleaseObjects.prepend(obj);
|
||||
}
|
||||
|
||||
QObject* CorePlugin::objectByName(const QString &name) const
|
||||
{
|
||||
Q_FOREACH (QObject *qobj, _plugMan->allObjects())
|
||||
|
|
|
@ -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<QString> 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 <typename Type>
|
||||
QList<Type *> getObjects() const
|
||||
template <typename T>
|
||||
QList<T *> getObjects() const
|
||||
{
|
||||
QList<QObject *> all = _plugMan->allObjects();
|
||||
QList<Type *> objects;
|
||||
QList<T *> objects;
|
||||
Q_FOREACH(QObject *obj, all)
|
||||
{
|
||||
Type *typeObj = qobject_cast<Type *>(obj);
|
||||
if (typeObj)
|
||||
objects.append(typeObj);
|
||||
T *tObj = qobject_cast<T *>(obj);
|
||||
if (tObj)
|
||||
objects.append(tObj);
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *getObject() const
|
||||
{
|
||||
QList<QObject *> all = _plugMan->allObjects();
|
||||
T *result = 0;
|
||||
Q_FOREACH(QObject *obj, all)
|
||||
{
|
||||
T *tObj = qobject_cast<T *>(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<QObject *> _autoReleaseObjects;
|
||||
bool _oldOVQT;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
// NeL includes
|
||||
#include <nel/misc/debug.h>
|
||||
|
||||
// Qt includes
|
||||
#include <QtGui/QtGui>
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Core
|
|||
|
||||
CSearchPathsSettingsPage::CSearchPathsSettingsPage(QObject *parent)
|
||||
: QObject(parent),
|
||||
_currentPage(NULL)
|
||||
_currentPage(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Project includes
|
||||
#include "settings_dialog.h"
|
||||
#include "core_plugin.h"
|
||||
#include "ioptions_page.h"
|
||||
|
||||
// Qt includes
|
||||
#include <QtGui/QHeaderView>
|
||||
|
@ -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<QString, QTreeWidgetItem *> categories;
|
||||
|
||||
QList<IOptionsPage *> pages;
|
||||
QList<QObject *> all = _plugMan->allObjects();
|
||||
Q_FOREACH(QObject *obj, all)
|
||||
{
|
||||
IOptionsPage *page = qobject_cast<IOptionsPage *>(obj);
|
||||
if (page)
|
||||
pages.append(page);
|
||||
}
|
||||
QList<IOptionsPage *> pages = corePlugin->getObjects<IOptionsPage>();
|
||||
|
||||
int index = 0;
|
||||
Q_FOREACH(IOptionsPage *page, pages)
|
||||
|
|
|
@ -25,11 +25,12 @@
|
|||
#include <QtCore/QList>
|
||||
|
||||
// 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<Core::IOptionsPage*> _pages;
|
||||
QList<IOptionsPage *> _pages;
|
||||
bool _applied;
|
||||
QString _currentCategory;
|
||||
QString _currentPage;
|
||||
|
|
|
@ -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<QString> MyPlugin::dependencies() const
|
|||
return QList<QString>();
|
||||
}
|
||||
|
||||
void MyPlugin::addAutoReleasedObject(QObject *obj)
|
||||
{
|
||||
_plugMan->addObject(obj);
|
||||
_autoReleaseObjects.prepend(obj);
|
||||
}
|
||||
|
||||
QObject* MyPlugin::objectByName(const QString &name) const
|
||||
{
|
||||
Q_FOREACH (QObject *qobj, _plugMan->allObjects())
|
||||
|
|
|
@ -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<QString> 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<QObject *> _autoReleaseObjects;
|
||||
};
|
||||
|
||||
class CExampleAppPage: public QObject, public Core::IAppPage
|
||||
|
|
Loading…
Reference in a new issue