forked from qt-creator/qt-creator
IFeatureProvider: Add register method for IFeatureProviders to IWizardFactory
and avoid putting those objects into the object pool. Change-Id: I46c5ed93a9e80532b3cbd7dba2e52b28b1595aa3 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include "mimedatabase.h"
|
||||
#include "modemanager.h"
|
||||
#include "infobar.h"
|
||||
#include "iwizardfactory.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
@@ -60,6 +61,8 @@ CorePlugin::CorePlugin() : m_editMode(0), m_designMode(0)
|
||||
|
||||
CorePlugin::~CorePlugin()
|
||||
{
|
||||
IWizardFactory::destroyFeatureProvider();
|
||||
|
||||
delete m_findPlugin;
|
||||
delete m_locator;
|
||||
|
||||
|
||||
@@ -42,10 +42,8 @@ namespace Core {
|
||||
|
||||
class CORE_EXPORT FeatureSet;
|
||||
|
||||
class CORE_EXPORT IFeatureProvider : public QObject
|
||||
class CORE_EXPORT IFeatureProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
IFeatureProvider() {}
|
||||
virtual ~IFeatureProvider() {}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
@@ -145,6 +146,10 @@
|
||||
|
||||
using namespace Core;
|
||||
|
||||
namespace {
|
||||
static QList<IFeatureProvider *> s_providerList;
|
||||
}
|
||||
|
||||
/* A utility to find all wizards supporting a view mode and matching a predicate */
|
||||
template <class Predicate>
|
||||
QList<IWizardFactory*> findWizardFactories(Predicate predicate)
|
||||
@@ -201,10 +206,7 @@ bool IWizardFactory::isAvailable(const QString &platformName) const
|
||||
foreach (const QString &n, plugins)
|
||||
availableFeatures |= Feature(Core::Id::fromString(n));
|
||||
|
||||
const QList<Core::IFeatureProvider *> featureManagers
|
||||
= ExtensionSystem::PluginManager::getObjects<Core::IFeatureProvider>();
|
||||
|
||||
foreach (const Core::IFeatureProvider *featureManager, featureManagers)
|
||||
foreach (const Core::IFeatureProvider *featureManager, s_providerList)
|
||||
availableFeatures |= featureManager->availableFeatures(platformName);
|
||||
|
||||
return availableFeatures.contains(requiredFeatures());
|
||||
@@ -226,10 +228,7 @@ QStringList IWizardFactory::allAvailablePlatforms()
|
||||
{
|
||||
QStringList platforms;
|
||||
|
||||
const QList<Core::IFeatureProvider*> featureManagers =
|
||||
ExtensionSystem::PluginManager::getObjects<Core::IFeatureProvider>();
|
||||
|
||||
foreach (const Core::IFeatureProvider *featureManager, featureManagers)
|
||||
foreach (const Core::IFeatureProvider *featureManager, s_providerList)
|
||||
platforms.append(featureManager->availablePlatforms());
|
||||
|
||||
return platforms;
|
||||
@@ -237,13 +236,22 @@ QStringList IWizardFactory::allAvailablePlatforms()
|
||||
|
||||
QString IWizardFactory::displayNameForPlatform(const QString &string)
|
||||
{
|
||||
const QList<Core::IFeatureProvider*> featureManagers =
|
||||
ExtensionSystem::PluginManager::getObjects<Core::IFeatureProvider>();
|
||||
|
||||
foreach (const Core::IFeatureProvider *featureManager, featureManagers) {
|
||||
foreach (const Core::IFeatureProvider *featureManager, s_providerList) {
|
||||
QString displayName = featureManager->displayNameForPlatform(string);
|
||||
if (!displayName.isEmpty())
|
||||
return displayName;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
void IWizardFactory::registerFeatureProvider(IFeatureProvider *provider)
|
||||
{
|
||||
QTC_ASSERT(!s_providerList.contains(provider), return);
|
||||
s_providerList.append(provider);
|
||||
}
|
||||
|
||||
void IWizardFactory::destroyFeatureProvider()
|
||||
{
|
||||
qDeleteAll(s_providerList);
|
||||
s_providerList.clear();
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
|
||||
namespace Core {
|
||||
|
||||
namespace Internal { class CorePlugin; }
|
||||
|
||||
class CORE_EXPORT IWizardFactory
|
||||
: public QObject
|
||||
{
|
||||
@@ -94,7 +96,11 @@ public:
|
||||
static QStringList allAvailablePlatforms();
|
||||
static QString displayNameForPlatform(const QString &string);
|
||||
|
||||
static void registerFeatureProvider(IFeatureProvider *provider);
|
||||
|
||||
private:
|
||||
static void destroyFeatureProvider();
|
||||
|
||||
IWizardFactory::WizardKind m_kind;
|
||||
QIcon m_icon;
|
||||
QString m_description;
|
||||
@@ -105,6 +111,8 @@ private:
|
||||
FeatureSet m_requiredFeatures;
|
||||
WizardFlags m_flags;
|
||||
QString m_descriptionImage;
|
||||
|
||||
friend class Internal::CorePlugin;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
||||
Reference in New Issue
Block a user