forked from qt-creator/qt-creator
QmlDesigner: Remove PluginManagerPrivate
Change-Id: Ieb10bb6e3f5733bb123514adecbd251496aa4b34 Reviewed-by: Alessandro Portale <alessandro.portale@nokia.com>
This commit is contained in:
committed by
Alessandro Portale
parent
8f909fec6f
commit
037f055473
@@ -30,7 +30,6 @@
|
||||
|
||||
#include "pluginmanager.h"
|
||||
#include "iplugin.h"
|
||||
#include "pluginpath.h"
|
||||
#include <metainfo.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -56,90 +55,30 @@ enum { debug = 0 };
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
// Initialize and create instance of a plugin from scratch,
|
||||
// that is, make sure the library is loaded and has an instance
|
||||
// of the IPlugin type. Once something fails, mark it as failed
|
||||
// ignore it from then on.
|
||||
//static IPlugin *instance(PluginData &p)
|
||||
//{
|
||||
// // Go stale once something fails
|
||||
// if (p.failed)
|
||||
// return 0;
|
||||
// // Pull up the plugin, retrieve IPlugin instance.
|
||||
// if (!p.instanceGuard) {
|
||||
// p.instance = 0;
|
||||
// QPluginLoader loader(p.path);
|
||||
// if (!(loader.isLoaded() || loader.load())) {
|
||||
// p.failed = true;
|
||||
// p.errorMessage = loader.errorString();
|
||||
// return 0;
|
||||
// }
|
||||
// QObject *object = loader.instance();
|
||||
// if (!object) {
|
||||
// p.failed = true;
|
||||
// p.errorMessage = QCoreApplication::translate("PluginManager", "Failed to create instance.");
|
||||
// return 0;
|
||||
// }
|
||||
// IPlugin *iplugin = qobject_cast<IPlugin *>(object);
|
||||
// if (!iplugin) {
|
||||
// p.failed = true;
|
||||
// p.errorMessage = QCoreApplication::translate("PluginManager", "Not a QmlDesigner plugin.");
|
||||
// delete object;
|
||||
// return 0;
|
||||
// }
|
||||
// p.instanceGuard = object;
|
||||
// p.instance = iplugin;
|
||||
// }
|
||||
// // Ensure it is initialized
|
||||
// if (!p.instance->isInitialized()) {
|
||||
// if (!p.instance->initialize(&p.errorMessage)) {
|
||||
// p.failed = true;
|
||||
// delete p.instance;
|
||||
// p.instance = 0;
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
// return p.instance;
|
||||
//}
|
||||
|
||||
|
||||
// ---- PluginManager[Private]
|
||||
class PluginManagerPrivate {
|
||||
public:
|
||||
typedef QList<PluginPath> PluginPathList;
|
||||
PluginPathList m_paths;
|
||||
};
|
||||
|
||||
PluginManager::PluginManager() :
|
||||
d(new PluginManagerPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
PluginManager::~PluginManager()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
PluginManager::IPluginList PluginManager::instances()
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << '>' << Q_FUNC_INFO << QLibraryInfo::buildKey();
|
||||
IPluginList rc;
|
||||
const PluginManagerPrivate::PluginPathList::iterator end = d->m_paths.end();
|
||||
for (PluginManagerPrivate::PluginPathList::iterator it = d->m_paths.begin(); it != end; ++it)
|
||||
const PluginPathList::iterator end = m_paths.end();
|
||||
for (PluginPathList::iterator it = m_paths.begin(); it != end; ++it)
|
||||
it->getInstances(&rc);
|
||||
if (debug)
|
||||
qDebug() << '<' << Q_FUNC_INFO << rc.size();
|
||||
return rc;
|
||||
}
|
||||
|
||||
PluginManager::PluginManager()
|
||||
{
|
||||
}
|
||||
|
||||
void PluginManager::setPluginPaths(const QStringList &paths)
|
||||
{
|
||||
foreach (const QString &path, paths) {
|
||||
const QDir dir(path);
|
||||
if (!dir.exists())
|
||||
continue;
|
||||
d->m_paths.push_back(PluginPath(dir));
|
||||
m_paths.push_back(PluginPath(dir));
|
||||
}
|
||||
|
||||
// also register path in widgetpluginmanager
|
||||
@@ -149,8 +88,8 @@ void PluginManager::setPluginPaths(const QStringList &paths)
|
||||
QAbstractItemModel *PluginManager::createModel(QObject *parent)
|
||||
{
|
||||
QStandardItemModel *model = new QStandardItemModel(parent);
|
||||
const PluginManagerPrivate::PluginPathList::iterator end = d->m_paths.end();
|
||||
for (PluginManagerPrivate::PluginPathList::iterator it = d->m_paths.begin(); it != end; ++it)
|
||||
const PluginPathList::iterator end = m_paths.end();
|
||||
for (PluginPathList::iterator it = m_paths.begin(); it != end; ++it)
|
||||
model->appendRow(it->createModelItem());
|
||||
return model;
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#ifndef PLUGINMANAGER_H
|
||||
#define PLUGINMANAGER_H
|
||||
|
||||
#include "pluginpath.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
@@ -45,8 +46,6 @@ namespace QmlDesigner {
|
||||
|
||||
class IPlugin;
|
||||
|
||||
class PluginManagerPrivate;
|
||||
|
||||
// PluginManager: Loads the plugin libraries on demand "as lazy as
|
||||
// possible", that is, directories are scanned and
|
||||
// instances are created only when instances() is called.
|
||||
@@ -54,11 +53,13 @@ class PluginManagerPrivate;
|
||||
class PluginManager
|
||||
{
|
||||
Q_DISABLE_COPY(PluginManager)
|
||||
|
||||
typedef QList<PluginPath> PluginPathList;
|
||||
|
||||
public:
|
||||
typedef QList<IPlugin *> IPluginList;
|
||||
|
||||
PluginManager();
|
||||
~PluginManager();
|
||||
|
||||
void setPluginPaths(const QStringList &paths);
|
||||
|
||||
@@ -66,12 +67,13 @@ public:
|
||||
|
||||
QDialog *createAboutPluginDialog(QWidget *parent);
|
||||
|
||||
private:
|
||||
private: // functions
|
||||
// Convenience to create a model for an "About Plugins"
|
||||
// dialog. Forces plugin initialization.
|
||||
QAbstractItemModel *createModel(QObject *parent = 0);
|
||||
|
||||
PluginManagerPrivate *d;
|
||||
private: // variables
|
||||
PluginPathList m_paths;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -29,6 +29,8 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "pluginpath.h"
|
||||
#include "pluginmanager.h"
|
||||
|
||||
#include <iplugin.h>
|
||||
#include <QLibrary>
|
||||
#include <QWeakPointer>
|
||||
|
@@ -31,8 +31,6 @@
|
||||
#ifndef PLUGINPATH_H
|
||||
#define PLUGINPATH_H
|
||||
|
||||
#include "pluginmanager.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QWeakPointer>
|
||||
#include <QList>
|
||||
@@ -72,11 +70,13 @@ struct PluginData {
|
||||
// IPlugins.
|
||||
|
||||
class PluginPath {
|
||||
|
||||
typedef QList<IPlugin *> IPluginList;
|
||||
public:
|
||||
explicit PluginPath(const QDir &path);
|
||||
|
||||
|
||||
void getInstances(PluginManager::IPluginList *list);
|
||||
void getInstances(IPluginList *list);
|
||||
|
||||
QDir path() const { return m_path; }
|
||||
|
||||
|
Reference in New Issue
Block a user