forked from qt-creator/qt-creator
ProjectExplorer: Use more algorithms
Make heavy use of lambdas Change-Id: I53197d0ffb4ae8eec076f15335cc22b74e1def1d Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -56,6 +56,40 @@ void erase(QList<T> &container, F predicate)
|
|||||||
container.end());
|
container.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename F>
|
||||||
|
bool contains(const T &container, F function)
|
||||||
|
{
|
||||||
|
typename T::const_iterator end = container.end();
|
||||||
|
typename T::const_iterator begin = container.begin();
|
||||||
|
|
||||||
|
typename T::const_iterator it = std::find_if(begin, end, function);
|
||||||
|
return it != end;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename F>
|
||||||
|
typename T::value_type findOr(const T &container, typename T::value_type other, F function)
|
||||||
|
{
|
||||||
|
typename T::const_iterator end = container.end();
|
||||||
|
typename T::const_iterator begin = container.begin();
|
||||||
|
|
||||||
|
typename T::const_iterator it = std::find_if(begin, end, function);
|
||||||
|
if (it == end)
|
||||||
|
return other;
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename F>
|
||||||
|
typename T::value_type maxElementOr(const T &container, typename T::value_type other, F function)
|
||||||
|
{
|
||||||
|
typename T::const_iterator end = container.end();
|
||||||
|
typename T::const_iterator begin = container.begin();
|
||||||
|
|
||||||
|
typename T::const_iterator it = std::max_element(begin, end, function);
|
||||||
|
if (it == end)
|
||||||
|
return other;
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
// Note: add overloads for other container types as needed
|
// Note: add overloads for other container types as needed
|
||||||
template<typename T, typename F>
|
template<typename T, typename F>
|
||||||
Q_REQUIRED_RESULT
|
Q_REQUIRED_RESULT
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include "icore.h"
|
#include "icore.h"
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@@ -50,7 +51,6 @@
|
|||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
enum { debugMimeDB = 0 };
|
enum { debugMimeDB = 0 };
|
||||||
@@ -898,16 +898,14 @@ struct RemovePred : std::unary_function<MimeType::IMagicMatcherSharedPointer, bo
|
|||||||
MimeType::IMagicMatcherList MimeType::magicRuleMatchers() const
|
MimeType::IMagicMatcherList MimeType::magicRuleMatchers() const
|
||||||
{
|
{
|
||||||
IMagicMatcherList ruleMatchers = m_d->magicMatchers;
|
IMagicMatcherList ruleMatchers = m_d->magicMatchers;
|
||||||
ruleMatchers.erase(std::remove_if(ruleMatchers.begin(), ruleMatchers.end(), RemovePred(true)),
|
Utils::erase(ruleMatchers, RemovePred(true));
|
||||||
ruleMatchers.end());
|
|
||||||
return ruleMatchers;
|
return ruleMatchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MimeType::setMagicRuleMatchers(const IMagicMatcherList &matchers)
|
void MimeType::setMagicRuleMatchers(const IMagicMatcherList &matchers)
|
||||||
{
|
{
|
||||||
m_d->magicMatchers.erase(std::remove_if(m_d->magicMatchers.begin(), m_d->magicMatchers.end(),
|
Utils::erase(m_d->magicMatchers, RemovePred(false));
|
||||||
RemovePred(false)),
|
|
||||||
m_d->magicMatchers.end());
|
|
||||||
m_d->magicMatchers.append(matchers);
|
m_d->magicMatchers.append(matchers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include <texteditor/itexteditor.h>
|
#include <texteditor/itexteditor.h>
|
||||||
#include <utils/filesearch.h>
|
#include <utils/filesearch.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
@@ -90,11 +91,11 @@ Utils::FileIterator *AllProjectsFind::filesForProjects(const QStringList &nameFi
|
|||||||
QStringList filteredFiles;
|
QStringList filteredFiles;
|
||||||
if (!filterRegs.isEmpty()) {
|
if (!filterRegs.isEmpty()) {
|
||||||
foreach (const QString &file, projectFiles) {
|
foreach (const QString &file, projectFiles) {
|
||||||
foreach (QRegExp reg, filterRegs) {
|
if (Utils::anyOf(filterRegs,
|
||||||
if (reg.exactMatch(file) || reg.exactMatch(QFileInfo(file).fileName())) {
|
[&file](QRegExp reg) {
|
||||||
filteredFiles.append(file);
|
return (reg.exactMatch(file) || reg.exactMatch(QFileInfo(file).fileName()));
|
||||||
break;
|
})) {
|
||||||
}
|
filteredFiles.append(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -43,6 +43,7 @@
|
|||||||
#include <extensionsystem/invoker.h>
|
#include <extensionsystem/invoker.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@@ -231,10 +232,9 @@ void AppOutputPane::updateCloseActions()
|
|||||||
|
|
||||||
bool AppOutputPane::aboutToClose() const
|
bool AppOutputPane::aboutToClose() const
|
||||||
{
|
{
|
||||||
foreach (const RunControlTab &rt, m_runControlTabs)
|
return Utils::allOf(m_runControlTabs, [](const RunControlTab &rt) {
|
||||||
if (rt.runControl->isRunning() && !rt.runControl->promptToStop())
|
return !rt.runControl->isRunning() || rt.runControl->promptToStop();
|
||||||
return false;
|
});
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppOutputPane::aboutToUnloadSession()
|
void AppOutputPane::aboutToUnloadSession()
|
||||||
@@ -599,10 +599,9 @@ void AppOutputPane::slotRunControlFinished2(RunControl *sender)
|
|||||||
|
|
||||||
bool AppOutputPane::isRunning() const
|
bool AppOutputPane::isRunning() const
|
||||||
{
|
{
|
||||||
foreach (const RunControlTab &rt, m_runControlTabs)
|
return Utils::anyOf(m_runControlTabs, [](const RunControlTab &rt) {
|
||||||
if (rt.runControl->isRunning())
|
return rt.runControl->isRunning();
|
||||||
return true;
|
});
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppOutputPane::canNext() const
|
bool AppOutputPane::canNext() const
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@@ -154,10 +155,9 @@ Utils::AbstractMacroExpander *BuildConfiguration::macroExpander()
|
|||||||
|
|
||||||
QList<Core::Id> BuildConfiguration::knownStepLists() const
|
QList<Core::Id> BuildConfiguration::knownStepLists() const
|
||||||
{
|
{
|
||||||
QList<Core::Id> result;
|
return Utils::transform(m_stepLists, [](BuildStepList *list) {
|
||||||
foreach (BuildStepList *list, m_stepLists)
|
return list->id();
|
||||||
result.append(list->id());
|
});
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildStepList *BuildConfiguration::stepList(Core::Id id) const
|
BuildStepList *BuildConfiguration::stepList(Core::Id id) const
|
||||||
@@ -344,16 +344,11 @@ IBuildConfigurationFactory *IBuildConfigurationFactory::find(Kit *k, const QStri
|
|||||||
{
|
{
|
||||||
QList<IBuildConfigurationFactory *> factories
|
QList<IBuildConfigurationFactory *> factories
|
||||||
= ExtensionSystem::PluginManager::instance()->getObjects<IBuildConfigurationFactory>();
|
= ExtensionSystem::PluginManager::instance()->getObjects<IBuildConfigurationFactory>();
|
||||||
IBuildConfigurationFactory *factory = 0;
|
|
||||||
int priority = -1;
|
return Utils::maxElementOr(factories, 0,
|
||||||
foreach (IBuildConfigurationFactory *i, factories) {
|
[&k, &projectPath](IBuildConfigurationFactory *a, IBuildConfigurationFactory *b) {
|
||||||
int iPriority = i->priority(k, projectPath);
|
return a->priority(k, projectPath) > b->priority(k, projectPath);
|
||||||
if (iPriority > priority) {
|
});
|
||||||
factory = i;
|
|
||||||
priority = iPriority;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return factory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create
|
// create
|
||||||
@@ -361,16 +356,11 @@ IBuildConfigurationFactory * IBuildConfigurationFactory::find(Target *parent)
|
|||||||
{
|
{
|
||||||
QList<IBuildConfigurationFactory *> factories
|
QList<IBuildConfigurationFactory *> factories
|
||||||
= ExtensionSystem::PluginManager::getObjects<IBuildConfigurationFactory>();
|
= ExtensionSystem::PluginManager::getObjects<IBuildConfigurationFactory>();
|
||||||
IBuildConfigurationFactory *factory = 0;
|
|
||||||
int priority = -1;
|
return Utils::maxElementOr(factories, 0,
|
||||||
foreach (IBuildConfigurationFactory *i, factories) {
|
[&parent](IBuildConfigurationFactory *a, IBuildConfigurationFactory *b) {
|
||||||
int iPriority = i->priority(parent);
|
return a->priority(parent) > b->priority(parent);
|
||||||
if (iPriority > priority) {
|
});
|
||||||
factory = i;
|
|
||||||
priority = iPriority;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return factory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clone
|
// clone
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@@ -118,8 +119,9 @@ void DeviceSettingsWidget::initGui()
|
|||||||
const QList<IDeviceFactory *> &factories
|
const QList<IDeviceFactory *> &factories
|
||||||
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
|
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
|
||||||
|
|
||||||
bool hasDeviceFactories = std::any_of(factories.constBegin(), factories.constEnd(),
|
bool hasDeviceFactories = Utils::anyOf(factories, [](IDeviceFactory *factory) {
|
||||||
[](IDeviceFactory *factory) { return factory->canCreate(); });
|
return factory->canCreate();
|
||||||
|
});
|
||||||
|
|
||||||
m_ui->addConfigButton->setEnabled(hasDeviceFactories);
|
m_ui->addConfigButton->setEnabled(hasDeviceFactories);
|
||||||
|
|
||||||
|
@@ -43,6 +43,7 @@
|
|||||||
#include <projectexplorer/kitmanager.h>
|
#include <projectexplorer/kitmanager.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class ProjectExplorer::Project
|
\class ProjectExplorer::Project
|
||||||
@@ -226,20 +227,16 @@ void Project::setActiveTarget(Target *target)
|
|||||||
|
|
||||||
Target *Project::target(const Core::Id id) const
|
Target *Project::target(const Core::Id id) const
|
||||||
{
|
{
|
||||||
foreach (Target *target, d->m_targets) {
|
return Utils::findOr(d->m_targets, 0, [&id](Target *target) {
|
||||||
if (target->id() == id)
|
return target->id() == id;
|
||||||
return target;
|
});
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Target *Project::target(Kit *k) const
|
Target *Project::target(Kit *k) const
|
||||||
{
|
{
|
||||||
foreach (Target *target, d->m_targets) {
|
return Utils::findOr(d->m_targets, 0, [&k](Target *target) {
|
||||||
if (target->kit() == k)
|
return target->kit() == k;
|
||||||
return target;
|
});
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Project::supportsKit(Kit *k, QString *errorMessage) const
|
bool Project::supportsKit(Kit *k, QString *errorMessage) const
|
||||||
@@ -501,12 +498,9 @@ void Project::setup(QList<const BuildInfo *> infoList)
|
|||||||
continue;
|
continue;
|
||||||
Target *t = target(k);
|
Target *t = target(k);
|
||||||
if (!t) {
|
if (!t) {
|
||||||
foreach (Target *i, toRegister) {
|
t = Utils::findOr(toRegister, 0, [&k](Target *i){
|
||||||
if (i->kit() == k) {
|
return i->kit() == k;
|
||||||
t = i;
|
});
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!t) {
|
if (!t) {
|
||||||
t = new Target(this, k);
|
t = new Target(this, k);
|
||||||
|
@@ -49,6 +49,7 @@
|
|||||||
#include <utils/runextensions.h>
|
#include <utils/runextensions.h>
|
||||||
#include <utils/synchronousprocess.h>
|
#include <utils/synchronousprocess.h>
|
||||||
#include <utils/winutils.h>
|
#include <utils/winutils.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
@@ -479,16 +480,14 @@ QStringList BaseQtVersion::warningReason() const
|
|||||||
ToolChain *BaseQtVersion::preferredToolChain(const FileName &ms) const
|
ToolChain *BaseQtVersion::preferredToolChain(const FileName &ms) const
|
||||||
{
|
{
|
||||||
const FileName spec = ms.isEmpty() ? mkspec() : ms;
|
const FileName spec = ms.isEmpty() ? mkspec() : ms;
|
||||||
ToolChain *possibleTc = 0;
|
|
||||||
foreach (ToolChain *tc, ToolChainManager::toolChains()) {
|
QList<ToolChain *> toolchains = ToolChainManager::toolChains();
|
||||||
if (!qtAbis().contains(tc->targetAbi()))
|
return Utils::findOr(toolchains,
|
||||||
continue;
|
toolchains.isEmpty() ? 0 : toolchains.first(),
|
||||||
if (tc->suggestedMkspecList().contains(spec))
|
[&spec, this](ToolChain *tc) {
|
||||||
return tc; // perfect match
|
return qtAbis().contains(tc->targetAbi())
|
||||||
if (!possibleTc)
|
&& tc->suggestedMkspecList().contains(spec);
|
||||||
possibleTc = tc; // first possible match
|
});
|
||||||
}
|
|
||||||
return possibleTc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileName BaseQtVersion::qmakeCommand() const
|
FileName BaseQtVersion::qmakeCommand() const
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include <qtsupport/qtversionmanager.h>
|
#include <qtsupport/qtversionmanager.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@@ -262,11 +263,9 @@ static QString fixStringForTags(const QString &string)
|
|||||||
|
|
||||||
static QStringList trimStringList(const QStringList &stringlist)
|
static QStringList trimStringList(const QStringList &stringlist)
|
||||||
{
|
{
|
||||||
QStringList returnList;
|
return Utils::transform(stringlist, [](const QString &string) {
|
||||||
foreach (const QString &string, stringlist)
|
return string.trimmed();
|
||||||
returnList << string.trimmed();
|
});
|
||||||
|
|
||||||
return returnList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString relativeOrInstallPath(const QString &path, const QString &manifestPath,
|
static QString relativeOrInstallPath(const QString &path, const QString &manifestPath,
|
||||||
@@ -540,13 +539,12 @@ void ExamplesListModel::updateQtVersions()
|
|||||||
// try to select the previously selected Qt version, or
|
// try to select the previously selected Qt version, or
|
||||||
// select examples corresponding to 'highest' Qt version
|
// select examples corresponding to 'highest' Qt version
|
||||||
int currentQtId = m_exampleSetModel->getQtId(currentIndex);
|
int currentQtId = m_exampleSetModel->getQtId(currentIndex);
|
||||||
BaseQtVersion *newQtVersion = 0;
|
BaseQtVersion *newQtVersion = Utils::findOr(m_qtVersions,
|
||||||
foreach (BaseQtVersion *version, m_qtVersions) {
|
0,
|
||||||
if (version->uniqueId() == currentQtId) {
|
[¤tQtId](BaseQtVersion *version) {
|
||||||
newQtVersion = version;
|
return version->uniqueId() == currentQtId;
|
||||||
break;
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!newQtVersion)
|
if (!newQtVersion)
|
||||||
newQtVersion = findHighestQtVersion();
|
newQtVersion = findHighestQtVersion();
|
||||||
currentIndex = m_exampleSetModel->indexForQtVersion(newQtVersion);
|
currentIndex = m_exampleSetModel->indexForQtVersion(newQtVersion);
|
||||||
@@ -753,11 +751,9 @@ void ExamplesListModelFilter::updateFilter()
|
|||||||
|
|
||||||
bool containsSubString(const QStringList &list, const QString &substr, Qt::CaseSensitivity cs)
|
bool containsSubString(const QStringList &list, const QString &substr, Qt::CaseSensitivity cs)
|
||||||
{
|
{
|
||||||
foreach (const QString &elem, list)
|
return Utils::contains(list, [&substr, &cs](const QString &elem) {
|
||||||
if (elem.contains(substr, cs))
|
return elem.contains(substr, cs);
|
||||||
return true;
|
});
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExamplesListModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool ExamplesListModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
|
@@ -45,6 +45,7 @@
|
|||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/runextensions.h>
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -609,13 +610,11 @@ void QtOptionsPageWidget::addQtDir()
|
|||||||
if (BuildableHelperLibrary::isQtChooser(fi))
|
if (BuildableHelperLibrary::isQtChooser(fi))
|
||||||
qtVersion = FileName::fromString(BuildableHelperLibrary::qtChooserToQmakePath(fi.symLinkTarget()));
|
qtVersion = FileName::fromString(BuildableHelperLibrary::qtChooserToQmakePath(fi.symLinkTarget()));
|
||||||
|
|
||||||
BaseQtVersion *version = 0;
|
BaseQtVersion *version = Utils::findOr(m_versions,
|
||||||
foreach (BaseQtVersion *v, m_versions) {
|
0,
|
||||||
if (v->qmakeCommand() == qtVersion) {
|
[&qtVersion](BaseQtVersion *v) {
|
||||||
version = v;
|
return v->qmakeCommand() == qtVersion;
|
||||||
break;
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
if (version) {
|
if (version) {
|
||||||
// Already exist
|
// Already exist
|
||||||
QMessageBox::warning(this, tr("Qt Version Already Known"),
|
QMessageBox::warning(this, tr("Qt Version Already Known"),
|
||||||
|
Reference in New Issue
Block a user