Commit 3c413fc3 authored by Daniel Teske's avatar Daniel Teske

Rewrite ::getObjects usage to use predicate version

This makes the code easier to read and shorter.

Change-Id: I6d582bd9861aa0208565301f61f098e9313b6c89
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent ce1a691a
......@@ -1380,11 +1380,10 @@ EditorManager::ExternalEditorList
template <class EditorFactoryLike>
EditorFactoryLike *findById(const Core::Id &id)
{
const QList<EditorFactoryLike *> factories = ExtensionSystem::PluginManager::getObjects<EditorFactoryLike>();
foreach (EditorFactoryLike *efl, factories)
if (id == efl->id())
return efl;
return 0;
return ExtensionSystem::PluginManager::getObject<EditorFactoryLike>(
[&id](EditorFactoryLike *efl) {
return id == efl->id();
});
}
IEditor *EditorManager::createEditor(const Id &editorId, const QString &fileName)
......
......@@ -795,14 +795,10 @@ void MainWindow::openFile()
static QList<IDocumentFactory*> getNonEditorDocumentFactories()
{
const QList<IDocumentFactory*> allFileFactories =
ExtensionSystem::PluginManager::getObjects<IDocumentFactory>();
QList<IDocumentFactory*> nonEditorFileFactories;
foreach (IDocumentFactory *factory, allFileFactories) {
if (!qobject_cast<IEditorFactory *>(factory))
nonEditorFileFactories.append(factory);
}
return nonEditorFileFactories;
return ExtensionSystem::PluginManager::getObjects<IDocumentFactory>(
[](IDocumentFactory *factory) {
return !qobject_cast<IEditorFactory *>(factory);
});
}
static IDocumentFactory *findDocumentFactory(const QList<IDocumentFactory*> &fileFactories,
......
......@@ -127,12 +127,10 @@ TextEditor::Indenter *CppCodeStylePreferencesFactory::createIndenter() const
TextEditor::ISnippetProvider *CppCodeStylePreferencesFactory::snippetProvider() const
{
const QList<TextEditor::ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::getObjects<TextEditor::ISnippetProvider>();
foreach (TextEditor::ISnippetProvider *provider, providers)
if (provider->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID))
return provider;
return 0;
return ExtensionSystem::PluginManager::getObject<TextEditor::ISnippetProvider>(
[](TextEditor::ISnippetProvider *provider) {
return provider->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
});
}
QString CppCodeStylePreferencesFactory::previewText() const
......
......@@ -486,15 +486,10 @@ void CppCodeStylePreferencesWidget::updatePreview()
void CppCodeStylePreferencesWidget::decorateEditors(const TextEditor::FontSettings &fontSettings)
{
const ISnippetProvider *provider = 0;
const QList<ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::getObjects<ISnippetProvider>();
foreach (const ISnippetProvider *current, providers) {
if (current->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID)) {
provider = current;
break;
}
}
const ISnippetProvider *provider = ExtensionSystem::PluginManager::getObject<ISnippetProvider>(
[](ISnippetProvider *current) {
return current->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
});
foreach (TextEditor::SnippetEditorWidget *editor, m_previews) {
editor->baseTextDocument()->setFontSettings(fontSettings);
......
......@@ -332,13 +332,10 @@ IBuildConfigurationFactory::~IBuildConfigurationFactory()
// restore
IBuildConfigurationFactory *IBuildConfigurationFactory::find(Target *parent, const QVariantMap &map)
{
QList<IBuildConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IBuildConfigurationFactory>();
foreach (IBuildConfigurationFactory *factory, factories) {
if (factory->canRestore(parent, map))
return factory;
}
return 0;
return ExtensionSystem::PluginManager::getObject<IBuildConfigurationFactory>(
[&parent, map](IBuildConfigurationFactory *factory) {
return factory->canRestore(parent, map);
});
}
// setup
......@@ -378,12 +375,9 @@ IBuildConfigurationFactory * IBuildConfigurationFactory::find(Target *parent)
// clone
IBuildConfigurationFactory *IBuildConfigurationFactory::find(Target *parent, BuildConfiguration *bc)
{
QList<IBuildConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IBuildConfigurationFactory>();
foreach (IBuildConfigurationFactory *factory, factories) {
if (factory->canClone(parent, bc))
return factory;
}
return 0;
return ExtensionSystem::PluginManager::getObject<IBuildConfigurationFactory>(
[&parent, &bc](IBuildConfigurationFactory *factory) {
return factory->canClone(parent, bc);
});
}
} // namespace ProjectExplorer
......@@ -44,20 +44,18 @@ namespace {
IBuildStepFactory *findCloneFactory(BuildStepList *parent, BuildStep *source)
{
QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::getObjects<IBuildStepFactory>();
foreach (IBuildStepFactory *factory, factories)
if (factory->canClone(parent, source))
return factory;
return 0;
return ExtensionSystem::PluginManager::getObject<IBuildStepFactory>(
[&parent, &source](IBuildStepFactory *factory) {
return factory->canClone(parent, source);
});
}
IBuildStepFactory *findRestoreFactory(BuildStepList *parent, const QVariantMap &map)
{
QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::getObjects<IBuildStepFactory>();
foreach (IBuildStepFactory *factory, factories)
if (factory->canRestore(parent, map))
return factory;
return 0;
return ExtensionSystem::PluginManager::getObject<IBuildStepFactory>(
[&parent, &map](IBuildStepFactory *factory) {
return factory->canRestore(parent, map);
});
}
const char STEPS_COUNT_KEY[] = "ProjectExplorer.BuildStepList.StepsCount";
......
......@@ -335,15 +335,16 @@ CustomWizard::CustomWizardContextPtr CustomWizard::context() const
CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizardParametersPtr &p,
const Core::IWizard::Data &b)
{
ICustomWizardFactory * factory = ExtensionSystem::PluginManager::getObject<ICustomWizardFactory>(
[&p, &b](ICustomWizardFactory *factory) {
return ((p->klass.isEmpty() && b.kind == factory->kind())
|| (!p->klass.isEmpty() && p->klass == factory->klass()));
});
CustomWizard *rc = 0;
QList<ICustomWizardFactory *> factories = ExtensionSystem::PluginManager::getObjects<ICustomWizardFactory>();
foreach (ICustomWizardFactory *tmp, factories) {
if ((p->klass.isEmpty() && b.kind == tmp->kind())
|| (!p->klass.isEmpty() && p->klass == tmp->klass())) {
rc = tmp->create();
break;
}
}
if (factory)
rc = factory->create();
if (!rc) {
qWarning("Unable to create custom wizard for class %s.", qPrintable(p->klass));
return 0;
......
......@@ -227,36 +227,26 @@ DeployConfiguration *DeployConfigurationFactory::clone(Target *parent, DeployCon
DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, const QVariantMap &map)
{
QList<DeployConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<DeployConfigurationFactory>();
foreach (DeployConfigurationFactory *factory, factories) {
if (factory->canRestore(parent, map))
return factory;
}
return 0;
return ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>(
[&parent, &map](DeployConfigurationFactory *factory) {
return factory->canRestore(parent, map);
});
}
QList<DeployConfigurationFactory *> DeployConfigurationFactory::find(Target *parent)
{
QList<DeployConfigurationFactory *> result;
QList<DeployConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<DeployConfigurationFactory>();
foreach (DeployConfigurationFactory *factory, factories) {
if (!factory->availableCreationIds(parent).isEmpty())
result << factory;
}
return result;
return ExtensionSystem::PluginManager::getObjects<DeployConfigurationFactory>(
[&parent](DeployConfigurationFactory *factory) {
return !factory->availableCreationIds(parent).isEmpty();
});
}
DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, DeployConfiguration *dc)
{
QList<DeployConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<DeployConfigurationFactory>();
foreach (DeployConfigurationFactory *factory, factories) {
if (factory->canClone(parent, dc))
return factory;
}
return 0;
return ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>(
[&parent, &dc](DeployConfigurationFactory *factory) {
return factory->canClone(parent, dc);
});
}
bool DeployConfigurationFactory::canHandle(Target *parent) const
......
......@@ -324,16 +324,16 @@ void DeviceManager::setDefaultDevice(Core::Id id)
const IDeviceFactory *DeviceManager::restoreFactory(const QVariantMap &map)
{
const QList<IDeviceFactory *> &factories
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
foreach (const IDeviceFactory * const factory, factories) {
if (factory->canRestore(map))
return factory;
}
qWarning("Warning: No factory found for device '%s' of type '%s'.",
qPrintable(IDevice::idFromMap(map).toString()),
qPrintable(IDevice::typeFromMap(map).toString()));
return 0;
IDeviceFactory *factory = ExtensionSystem::PluginManager::getObject<IDeviceFactory>(
[&map](IDeviceFactory *factory) {
return factory->canRestore(map);
});
if (!factory)
qWarning("Warning: No factory found for device '%s' of type '%s'.",
qPrintable(IDevice::idFromMap(map).toString()),
qPrintable(IDevice::typeFromMap(map).toString()));
return factory;
}
DeviceManager::DeviceManager(bool isInstance) : d(new DeviceManagerPrivate)
......
......@@ -125,15 +125,12 @@ void DeviceSettingsWidget::initGui()
m_ui->configurationComboBox->setModel(m_deviceManagerModel);
m_ui->nameLineEdit->setValidator(m_nameValidator);
bool hasDeviceFactories = false;
const QList<IDeviceFactory *> &factories
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
foreach (const IDeviceFactory *f, factories) {
if (f->canCreate()) {
hasDeviceFactories = true;
break;
}
}
bool hasDeviceFactories = std::any_of(factories.constBegin(), factories.constEnd(),
[](IDeviceFactory *factory) { return factory->canCreate(); });
m_ui->addConfigButton->setEnabled(hasDeviceFactories);
int lastIndex = Core::ICore::settings()
......
......@@ -89,13 +89,10 @@ bool IDeviceFactory::canCreate() const
IDeviceFactory *IDeviceFactory::find(Core::Id type)
{
QList<IDeviceFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
foreach (IDeviceFactory *factory, factories) {
if (factory->availableCreationIds().contains(type))
return factory;
}
return 0;
return ExtensionSystem::PluginManager::getObject<IDeviceFactory>(
[&type](IDeviceFactory *factory) {
return factory->availableCreationIds().contains(type);
});
}
IDeviceFactory::IDeviceFactory(QObject *parent) : QObject(parent)
......
......@@ -293,14 +293,13 @@ KitInformation::ItemList DeviceTypeKitInformation::toUserOutput(const Kit *k) co
Core::Id type = deviceTypeId(k);
QString typeDisplayName = tr("Unknown device type");
if (type.isValid()) {
QList<IDeviceFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
foreach (IDeviceFactory *factory, factories) {
if (factory->availableCreationIds().contains(type)) {
typeDisplayName = factory->displayNameForId(type);
break;
}
}
IDeviceFactory *factory = ExtensionSystem::PluginManager::getObject<IDeviceFactory>(
[&type](IDeviceFactory *factory) {
return factory->availableCreationIds().contains(type);
});
if (factory)
typeDisplayName = factory->displayNameForId(type);
}
return ItemList() << qMakePair(tr("Device type"), typeDisplayName);
}
......
......@@ -2445,11 +2445,10 @@ void ProjectExplorerPlugin::activeRunConfigurationChanged()
// NBS TODO implement more than one runner
IRunControlFactory *ProjectExplorerPlugin::findRunControlFactory(RunConfiguration *config, RunMode mode)
{
const QList<IRunControlFactory *> factories = ExtensionSystem::PluginManager::getObjects<IRunControlFactory>();
foreach (IRunControlFactory *f, factories)
if (f->canRun(config, mode))
return f;
return 0;
return ExtensionSystem::PluginManager::getObject<IRunControlFactory>(
[&config, &mode](IRunControlFactory *factory) {
return factory->canRun(config, mode);
});
}
void ProjectExplorerPlugin::updateDeployActions()
......
......@@ -429,36 +429,26 @@ RunConfiguration *IRunConfigurationFactory::restore(Target *parent, const QVaria
IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, const QVariantMap &map)
{
QList<IRunConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IRunConfigurationFactory>();
foreach (IRunConfigurationFactory *factory, factories) {
if (factory->canRestore(parent, map))
return factory;
}
return 0;
return ExtensionSystem::PluginManager::getObject<IRunConfigurationFactory>(
[&parent, &map](IRunConfigurationFactory *factory) {
return factory->canRestore(parent, map);
});
}
IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, RunConfiguration *rc)
{
QList<IRunConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IRunConfigurationFactory>();
foreach (IRunConfigurationFactory *factory, factories) {
if (factory->canClone(parent, rc))
return factory;
}
return 0;
return ExtensionSystem::PluginManager::getObject<IRunConfigurationFactory>(
[&parent, rc](IRunConfigurationFactory *factory) {
return factory->canClone(parent, rc);
});
}
QList<IRunConfigurationFactory *> IRunConfigurationFactory::find(Target *parent)
{
QList<IRunConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IRunConfigurationFactory>();
QList<IRunConfigurationFactory *> result;
foreach (IRunConfigurationFactory *factory, factories) {
if (!factory->availableCreationIds(parent).isEmpty())
result << factory;
}
return result;
return ExtensionSystem::PluginManager::getObjects<IRunConfigurationFactory>(
[&parent](IRunConfigurationFactory *factory) {
return !factory->availableCreationIds(parent).isEmpty();
});
}
/*!
......
......@@ -501,7 +501,8 @@ QWidget *ToolChainOptionsPage::widget()
this, SLOT(toolChainSelectionChanged()));
// Get toolchainfactories:
m_factories = ExtensionSystem::PluginManager::getObjects<ToolChainFactory>();
m_factories = ExtensionSystem::PluginManager::getObjects<ToolChainFactory>(
[](ToolChainFactory *factory) { return factory->canCreate();});
// Set up add menu:
QMenu *addMenu = new QMenu(m_addButton);
......@@ -509,14 +510,12 @@ QWidget *ToolChainOptionsPage::widget()
connect(mapper, SIGNAL(mapped(QObject*)), this, SLOT(createToolChain(QObject*)));
foreach (ToolChainFactory *factory, m_factories) {
if (factory->canCreate()) {
QAction *action = new QAction(addMenu);
action->setText(factory->displayName());
connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
mapper->setMapping(action, static_cast<QObject *>(factory));
addMenu->addAction(action);
}
QAction *action = new QAction(addMenu);
action->setText(factory->displayName());
connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
mapper->setMapping(action, static_cast<QObject *>(factory));
addMenu->addAction(action);
}
connect(m_cloneButton, SIGNAL(clicked()), mapper, SLOT(map()));
mapper->setMapping(m_cloneButton, static_cast<QObject *>(0));
......
......@@ -42,13 +42,10 @@ QmakeRunConfigurationFactory *QmakeRunConfigurationFactory::find(ProjectExplorer
if (!t)
return 0;
QList<QmakeRunConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<QmakeRunConfigurationFactory>();
foreach (QmakeRunConfigurationFactory *factory, factories) {
if (factory->canHandle(t))
return factory;
}
return 0;
return ExtensionSystem::PluginManager::getObject<QmakeRunConfigurationFactory>(
[&t](QmakeRunConfigurationFactory *factory) {
return factory->canHandle(t);
});
}
} // namespace QmakeProjectManager
......@@ -92,12 +92,10 @@ TextEditor::Indenter *QmlJSCodeStylePreferencesFactory::createIndenter() const
TextEditor::ISnippetProvider *QmlJSCodeStylePreferencesFactory::snippetProvider() const
{
const QList<TextEditor::ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::getObjects<TextEditor::ISnippetProvider>();
foreach (TextEditor::ISnippetProvider *provider, providers)
if (provider->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID))
return provider;
return 0;
return ExtensionSystem::PluginManager::getObject<TextEditor::ISnippetProvider>(
[](TextEditor::ISnippetProvider *provider) {
return provider->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID);
});
}
QString QmlJSCodeStylePreferencesFactory::previewText() const
......
......@@ -61,14 +61,13 @@ QmlJSCodeStylePreferencesWidget::QmlJSCodeStylePreferencesWidget(QWidget *parent
{
m_ui->setupUi(this);
const QList<ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::getObjects<ISnippetProvider>();
foreach (ISnippetProvider *provider, providers) {
if (provider->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID)) {
provider->decorateEditor(m_ui->previewTextEdit);
break;
}
}
ISnippetProvider *provider = ExtensionSystem::PluginManager::getObject<ISnippetProvider>(
[](ISnippetProvider *provider) {
return provider->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID);
});
if (provider)
provider->decorateEditor(m_ui->previewTextEdit);
decorateEditor(TextEditorSettings::fontSettings());
connect(TextEditorSettings::instance(), SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
......@@ -97,15 +96,10 @@ void QmlJSCodeStylePreferencesWidget::setPreferences(TextEditor::ICodeStylePrefe
void QmlJSCodeStylePreferencesWidget::decorateEditor(const TextEditor::FontSettings &fontSettings)
{
const ISnippetProvider *provider = 0;
const QList<ISnippetProvider *> &providers =
ExtensionSystem::PluginManager::getObjects<ISnippetProvider>();
foreach (const ISnippetProvider *current, providers) {
if (current->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID)) {
provider = current;
break;
}
}
const ISnippetProvider *provider = ExtensionSystem::PluginManager::getObject<ISnippetProvider>(
[](ISnippetProvider *current) {
return current->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID);
});
m_ui->previewTextEdit->baseTextDocument()->setFontSettings(fontSettings);
if (provider)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment