IWizardFactory: Create wizards with factoryCreators

Do not use the object pool to hold potential wizards. Register
FactoryCreator functions with IWizardFactory instead and use
those to create the wizards when necessary.

This saves us a couple of cycles during startup since we can now
delay construction of all wizards and it makes us more flexible
wrt. managing the lifecycle of the wizard factories.

Change-Id: I95d6a6dfcdf0fd995e1934a9fefcd96c6a676753
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2015-05-22 17:16:36 +02:00
parent b5e3f2e57b
commit 25f2f8e1ee
13 changed files with 85 additions and 58 deletions

View File

@@ -147,16 +147,18 @@
using namespace Core;
namespace {
static QList<IFeatureProvider *> s_providerList;
QList<IWizardFactory *> s_allFactories;
QList<IWizardFactory::FactoryCreator> s_factoryCreators;
bool s_areFactoriesLoaded = false;
}
/* A utility to find all wizards supporting a view mode and matching a predicate */
template <class Predicate>
QList<IWizardFactory*> findWizardFactories(Predicate predicate)
{
// Hack: Trigger delayed creation of wizards
ICore::emitNewItemsDialogRequested();
// Filter all wizards
const QList<IWizardFactory*> allFactories = IWizardFactory::allWizardFactories();
QList<IWizardFactory*> rc;
@@ -169,9 +171,33 @@ template <class Predicate>
QList<IWizardFactory*> IWizardFactory::allWizardFactories()
{
// Hack: Trigger delayed creation of wizards
ICore::emitNewItemsDialogRequested();
return ExtensionSystem::PluginManager::getObjects<IWizardFactory>();
if (!s_areFactoriesLoaded) {
QTC_ASSERT(s_allFactories.isEmpty(), return s_allFactories);
s_areFactoriesLoaded = true;
QHash<Id, IWizardFactory *> sanityCheck;
foreach (const FactoryCreator &fc, s_factoryCreators) {
QList<IWizardFactory *> tmp = fc();
foreach (IWizardFactory *newFactory, tmp) {
QTC_ASSERT(newFactory, continue);
IWizardFactory *existingFactory = sanityCheck.value(newFactory->id());
QTC_ASSERT(existingFactory != newFactory, continue);
if (existingFactory) {
qWarning("%s", qPrintable(tr("Factory with id=\"%1\" already registered. Deleting.")
.arg(existingFactory->id().toString())));
delete newFactory;
continue;
}
sanityCheck.insert(newFactory->id(), newFactory);
s_allFactories << newFactory;
}
}
}
return s_allFactories;
}
// Utility to find all registered wizards of a certain kind
@@ -211,6 +237,11 @@ QStringList IWizardFactory::supportedPlatforms() const
return stringList;
}
void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator &creator)
{
s_factoryCreators << creator;
}
QStringList IWizardFactory::allAvailablePlatforms()
{
QStringList platforms;
@@ -257,3 +288,9 @@ FeatureSet IWizardFactory::pluginFeatures() const
}
return plugins;
}
void IWizardFactory::initialize()
{
connect(ICore::instance(), &ICore::coreAboutToClose,
ICore::instance(), []() { qDeleteAll(s_allFactories); s_allFactories.clear(); });
}