forked from qt-creator/qt-creator
Even more algorithm usage in ProjectExplorer
Add Utils::transform and anyOf that take a member function pointer. Remove bestElementOr it's unused. Use declval<T> in transform's return type, because msvc does evaluate T() and for types that don't have simple constructor this fails. Add std::remove_reference since decltype returns a reference for lvalues. Change-Id: I22248b226748eeb27af0d300182d574438d7f756 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#define ALGORITHM_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
#ifndef Q_REQUIRED_RESULT
|
||||
@@ -46,6 +47,20 @@
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
//////////////////
|
||||
// anyOf
|
||||
/////////////////
|
||||
|
||||
// anyOf taking a member function pointer
|
||||
template<typename T, typename R, typename S>
|
||||
bool anyOf(const T &container, R (S::*predicate)() const)
|
||||
{
|
||||
static_assert(std::is_convertible<typename T::iterator::value_type, S *>::value
|
||||
|| std::is_convertible<typename T::iterator::value_type, S>::value,
|
||||
"elements of the container must be convertible to the member function pointer's class.");
|
||||
static_assert(std::is_convertible<R, bool>::value, "return type of predicate needs to be convertible to bool");
|
||||
return std::any_of(container.begin(), container.end(), std::mem_fn(predicate));
|
||||
}
|
||||
|
||||
template<typename T, typename F>
|
||||
bool anyOf(const T &container, F predicate)
|
||||
@@ -53,12 +68,18 @@ bool anyOf(const T &container, F predicate)
|
||||
return std::any_of(container.begin(), container.end(), predicate);
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// allOf
|
||||
/////////////////
|
||||
template<typename T, typename F>
|
||||
bool allOf(const T &container, F predicate)
|
||||
{
|
||||
return std::all_of(container.begin(), container.end(), predicate);
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// erase
|
||||
/////////////////
|
||||
template<typename T, typename F>
|
||||
void erase(QList<T> &container, F predicate)
|
||||
{
|
||||
@@ -66,6 +87,9 @@ void erase(QList<T> &container, F predicate)
|
||||
container.end());
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// contains
|
||||
/////////////////
|
||||
template<typename T, typename F>
|
||||
bool contains(const T &container, F function)
|
||||
{
|
||||
@@ -76,6 +100,9 @@ bool contains(const T &container, F function)
|
||||
return it != end;
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// findOr
|
||||
/////////////////
|
||||
template<typename T, typename F>
|
||||
typename T::value_type findOr(const T &container, typename T::value_type other, F function)
|
||||
{
|
||||
@@ -89,23 +116,45 @@ typename T::value_type findOr(const T &container, typename T::value_type other,
|
||||
}
|
||||
|
||||
template<typename T, typename F>
|
||||
typename T::value_type bestElementOr(const T &container, typename T::value_type other, F function)
|
||||
typename T::value_type findOrDefault(const T &container, F function)
|
||||
{
|
||||
typename T::const_iterator end = container.end();
|
||||
typename T::const_iterator begin = container.begin();
|
||||
return findOr(container, typename T::value_type(), function);
|
||||
}
|
||||
|
||||
typename T::const_iterator it = std::min_element(begin, end, function);
|
||||
if (it == end)
|
||||
return other;
|
||||
return *it;
|
||||
//////////////////
|
||||
// transform
|
||||
/////////////////
|
||||
|
||||
// transform taking a member function pointer
|
||||
template<typename T, typename R, typename S>
|
||||
Q_REQUIRED_RESULT
|
||||
auto transform(const QList<T> &container, R (S::*p)() const) -> QList<R>
|
||||
{
|
||||
static_assert(std::is_convertible<T, S *>::value
|
||||
|| std::is_convertible<T, S>::value,
|
||||
"elements of container must be convertible to S");
|
||||
QList<R> result;
|
||||
result.reserve(container.size());
|
||||
std::transform(container.begin(), container.end(),
|
||||
std::back_inserter(result),
|
||||
std::mem_fn(p));
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace {
|
||||
// needed for msvc 2010, that doesn't have a declval
|
||||
// can be removed once we stop supporting it
|
||||
template<typename T>
|
||||
T &&declval();
|
||||
}
|
||||
|
||||
// Note: add overloads for other container types as needed
|
||||
template<typename T, typename F>
|
||||
Q_REQUIRED_RESULT
|
||||
auto transform(const QList<T> &container, F function) -> QList<decltype(function(T()))>
|
||||
auto transform(const QList<T> &container, F function)
|
||||
-> QList<typename std::remove_reference<decltype(function(declval<T>()))>::type>
|
||||
{
|
||||
QList<decltype(function(T()))> result;
|
||||
QList<typename std::remove_reference<decltype(function(declval<T>()))>::type> result;
|
||||
result.reserve(container.size());
|
||||
std::transform(container.begin(), container.end(),
|
||||
std::back_inserter(result),
|
||||
@@ -113,6 +162,9 @@ auto transform(const QList<T> &container, F function) -> QList<decltype(function
|
||||
return result;
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// sort
|
||||
/////////////////
|
||||
template <typename Container>
|
||||
inline void sort(Container &c)
|
||||
{
|
||||
|
||||
@@ -156,17 +156,14 @@ Utils::AbstractMacroExpander *BuildConfiguration::macroExpander()
|
||||
|
||||
QList<Core::Id> BuildConfiguration::knownStepLists() const
|
||||
{
|
||||
return Utils::transform(m_stepLists, [](BuildStepList *list) {
|
||||
return list->id();
|
||||
});
|
||||
return Utils::transform(m_stepLists, &BuildStepList::id);
|
||||
}
|
||||
|
||||
BuildStepList *BuildConfiguration::stepList(Core::Id id) const
|
||||
{
|
||||
foreach (BuildStepList *list, m_stepLists)
|
||||
if (id == list->id())
|
||||
return list;
|
||||
return 0;
|
||||
return Utils::findOrDefault(m_stepLists, [id](BuildStepList *list) {
|
||||
return id == list->id();
|
||||
});
|
||||
}
|
||||
|
||||
QVariantMap BuildConfiguration::toMap() const
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "target.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
@@ -121,11 +122,9 @@ bool BuildStepList::isEmpty() const
|
||||
|
||||
bool BuildStepList::contains(Core::Id id) const
|
||||
{
|
||||
foreach (BuildStep *bs, steps()) {
|
||||
if (bs->id() == id)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Utils::anyOf(steps(), [id](BuildStep *bs){
|
||||
return bs->id() == id;
|
||||
});
|
||||
}
|
||||
|
||||
void BuildStepList::cloneSteps(BuildStepList *source)
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "projectexplorerconstants.h"
|
||||
#include "toolchainmanager.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/detailswidget.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/pathchooser.h>
|
||||
@@ -218,17 +219,14 @@ IOutputParser *CustomToolChain::outputParser() const
|
||||
|
||||
QStringList CustomToolChain::headerPathsList() const
|
||||
{
|
||||
QStringList list;
|
||||
foreach (const HeaderPath &headerPath, m_systemHeaderPaths)
|
||||
list << headerPath.path();
|
||||
return list;
|
||||
return Utils::transform(m_systemHeaderPaths, &HeaderPath::path);
|
||||
}
|
||||
|
||||
void CustomToolChain::setHeaderPaths(const QStringList &list)
|
||||
{
|
||||
m_systemHeaderPaths.clear();
|
||||
foreach (const QString &headerPath, list)
|
||||
m_systemHeaderPaths << HeaderPath(headerPath.trimmed(), HeaderPath::GlobalHeaderPath);
|
||||
m_systemHeaderPaths = Utils::transform(list, [](const QString &headerPath) {
|
||||
return HeaderPath(headerPath.trimmed(), HeaderPath::GlobalHeaderPath);
|
||||
});
|
||||
}
|
||||
|
||||
void CustomToolChain::setCompilerCommand(const FileName &path)
|
||||
@@ -272,9 +270,7 @@ const QStringList &CustomToolChain::cxx11Flags() const
|
||||
|
||||
void CustomToolChain::setMkspecs(const QString &specs)
|
||||
{
|
||||
m_mkspecs.clear();
|
||||
foreach (const QString &spec, specs.split(QLatin1Char(',')))
|
||||
m_mkspecs << FileName::fromString(spec);
|
||||
m_mkspecs = Utils::transform(specs.split(QLatin1Char(',')), &FileName::fromString);
|
||||
}
|
||||
|
||||
QString CustomToolChain::mkspecs() const
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include "deployablefile.h"
|
||||
#include "projectexplorer_export.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QSet>
|
||||
|
||||
@@ -60,11 +62,9 @@ public:
|
||||
|
||||
DeployableFile deployableForLocalFile(const QString &localFilePath) const
|
||||
{
|
||||
foreach (const DeployableFile &d, m_files) {
|
||||
if (d.localFilePath().toString() == localFilePath)
|
||||
return d;
|
||||
}
|
||||
return DeployableFile();
|
||||
return Utils::findOrDefault(m_files, [&localFilePath](const DeployableFile &d) {
|
||||
return d.localFilePath().toString() == localFilePath;
|
||||
});
|
||||
}
|
||||
|
||||
bool operator==(const DeploymentData &other) const
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <utils/persistentsettings.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/portlist.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QHash>
|
||||
@@ -368,11 +369,9 @@ IDevice::Ptr DeviceManager::mutableDevice(Core::Id id) const
|
||||
|
||||
bool DeviceManager::hasDevice(const QString &name) const
|
||||
{
|
||||
foreach (const IDevice::Ptr &device, d->devices) {
|
||||
if (device->displayName() == name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Utils::anyOf(d->devices, [&name](const IDevice::Ptr &device) {
|
||||
return device->displayName() == name;
|
||||
});
|
||||
}
|
||||
|
||||
IDevice::ConstPtr DeviceManager::find(Core::Id id) const
|
||||
|
||||
@@ -119,9 +119,7 @@ void DeviceSettingsWidget::initGui()
|
||||
const QList<IDeviceFactory *> &factories
|
||||
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
|
||||
|
||||
bool hasDeviceFactories = Utils::anyOf(factories, [](IDeviceFactory *factory) {
|
||||
return factory->canCreate();
|
||||
});
|
||||
bool hasDeviceFactories = Utils::anyOf(factories, &IDeviceFactory::canCreate);
|
||||
|
||||
m_ui->addConfigButton->setEnabled(hasDeviceFactories);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "projectexplorerconstants.h"
|
||||
#include "toolchainmanager.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
@@ -682,9 +683,7 @@ QVariantMap GccToolChain::toMap() const
|
||||
data.insert(QLatin1String(compilerPlatformCodeGenFlagsKeyC), m_platformCodeGenFlags);
|
||||
data.insert(QLatin1String(compilerPlatformLinkerFlagsKeyC), m_platformLinkerFlags);
|
||||
data.insert(QLatin1String(targetAbiKeyC), m_targetAbi.toString());
|
||||
QStringList abiList;
|
||||
foreach (const Abi &a, m_supportedAbis)
|
||||
abiList.append(a.toString());
|
||||
QStringList abiList = Utils::transform(m_supportedAbis, &Abi::toString);
|
||||
data.insert(QLatin1String(supportedAbisKeyC), abiList);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <projectexplorer/abi.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
@@ -130,12 +131,11 @@ QVariant ToolChainKitInformation::defaultValue(Kit *k) const
|
||||
|
||||
Abi abi = Abi::hostAbi();
|
||||
|
||||
foreach (ToolChain *tc, tcList) {
|
||||
if (tc->targetAbi() == abi)
|
||||
return tc->id();
|
||||
}
|
||||
ToolChain *tc = Utils::findOr(tcList, tcList.first(), [&abi](ToolChain *tc) {
|
||||
return tc->targetAbi() == abi;
|
||||
});
|
||||
|
||||
return tcList.at(0)->id();
|
||||
return tc->id();
|
||||
}
|
||||
|
||||
QList<Task> ToolChainKitInformation::validate(const Kit *k) const
|
||||
|
||||
@@ -409,19 +409,16 @@ Kit *KitManager::find(Core::Id id)
|
||||
if (!id.isValid())
|
||||
return 0;
|
||||
|
||||
foreach (Kit *k, kits()) {
|
||||
if (k->id() == id)
|
||||
return k;
|
||||
}
|
||||
return 0;
|
||||
return Utils::findOrDefault(kits(), [id](Kit *k) {
|
||||
return k->id() == id;
|
||||
});
|
||||
}
|
||||
|
||||
Kit *KitManager::find(const KitMatcher &matcher)
|
||||
{
|
||||
foreach (Kit *k, d->m_kitList)
|
||||
if (matcher.matches(k))
|
||||
return k;
|
||||
return 0;
|
||||
return Utils::findOrDefault(d->m_kitList, [&matcher](Kit *k) {
|
||||
return matcher.matches(k);
|
||||
});
|
||||
}
|
||||
|
||||
Kit *KitManager::defaultKit()
|
||||
@@ -509,10 +506,8 @@ bool KitManager::registerKit(ProjectExplorer::Kit *k)
|
||||
|
||||
QTC_ASSERT(k->id().isValid(), return false);
|
||||
|
||||
foreach (Kit *current, kits()) {
|
||||
if (k == current)
|
||||
return false;
|
||||
}
|
||||
if (kits().contains(k))
|
||||
return false;
|
||||
|
||||
k->setDisplayName(uniqueKitName(k, k->displayName(), kits()));
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "kitmanager.h"
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QApplication>
|
||||
@@ -253,11 +254,9 @@ KitManagerConfigWidget *KitModel::widget(const QModelIndex &index)
|
||||
|
||||
bool KitModel::isDirty() const
|
||||
{
|
||||
foreach (KitNode *n, m_manualRoot->childNodes) {
|
||||
if (n->widget->isDirty())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Utils::anyOf(m_manualRoot->childNodes, [](KitNode *n) {
|
||||
return n->widget->isDirty();
|
||||
});
|
||||
}
|
||||
|
||||
bool KitModel::isDirty(Kit *k) const
|
||||
@@ -371,15 +370,12 @@ QModelIndex KitModel::index(KitNode *node, int column) const
|
||||
|
||||
KitNode *KitModel::findWorkingCopy(Kit *k) const
|
||||
{
|
||||
foreach (KitNode *n, m_autoRoot->childNodes) {
|
||||
if (n->widget->workingCopy() == k)
|
||||
return n;
|
||||
}
|
||||
foreach (KitNode *n, m_manualRoot->childNodes) {
|
||||
if (n->widget->workingCopy() == k)
|
||||
return n;
|
||||
}
|
||||
return 0;
|
||||
auto compareWorkingCopy = [&k](KitNode *n){ return n->widget->workingCopy() == k; };
|
||||
|
||||
KitNode *n = Utils::findOrDefault(m_autoRoot->childNodes, compareWorkingCopy);
|
||||
if (!n)
|
||||
n = Utils::findOrDefault(m_manualRoot->childNodes, compareWorkingCopy);
|
||||
return n;
|
||||
}
|
||||
|
||||
KitNode *KitModel::createNode(KitNode *parent, Kit *k)
|
||||
|
||||
@@ -864,12 +864,8 @@ void MiniProjectTargetSelector::doLayout(bool keepSize)
|
||||
onlySummary = true;
|
||||
} else {
|
||||
if (visibleLineCount < 3) {
|
||||
foreach (Project *p, SessionManager::projects()) {
|
||||
if (p->needsConfiguration()) {
|
||||
visibleLineCount = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Utils::anyOf(SessionManager::projects(), &Project::needsConfiguration))
|
||||
visibleLineCount = 3;
|
||||
}
|
||||
if (visibleLineCount)
|
||||
summaryLabelHeight = visibleLineCount * QFontMetrics(m_summaryLabel->font()).height()
|
||||
|
||||
@@ -227,14 +227,14 @@ void Project::setActiveTarget(Target *target)
|
||||
|
||||
Target *Project::target(Core::Id id) const
|
||||
{
|
||||
return Utils::findOr(d->m_targets, 0, [&id](Target *target) {
|
||||
return Utils::findOrDefault(d->m_targets, [&id](Target *target) {
|
||||
return target->id() == id;
|
||||
});
|
||||
}
|
||||
|
||||
Target *Project::target(Kit *k) const
|
||||
{
|
||||
return Utils::findOr(d->m_targets, 0, [&k](Target *target) {
|
||||
return Utils::findOrDefault(d->m_targets, [&k](Target *target) {
|
||||
return target->kit() == k;
|
||||
});
|
||||
}
|
||||
@@ -499,7 +499,7 @@ void Project::setup(QList<const BuildInfo *> infoList)
|
||||
continue;
|
||||
Target *t = target(k);
|
||||
if (!t) {
|
||||
t = Utils::findOr(toRegister, 0, [&k](Target *i){
|
||||
t = Utils::findOrDefault(toRegister, [&k](Target *i){
|
||||
return i->kit() == k;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1490,13 +1490,7 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
|
||||
}
|
||||
updateActions();
|
||||
|
||||
bool switchToProjectsMode = false;
|
||||
foreach (Project *p, openedPro) {
|
||||
if (p->needsConfiguration()) {
|
||||
switchToProjectsMode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool switchToProjectsMode = Utils::anyOf(openedPro, &Project::needsConfiguration);
|
||||
|
||||
if (!openedPro.isEmpty()) {
|
||||
if (switchToProjectsMode)
|
||||
@@ -2260,12 +2254,11 @@ void ProjectExplorerPlugin::runProjectContextMenu()
|
||||
|
||||
bool ProjectExplorerPlugin::hasBuildSettings(Project *pro)
|
||||
{
|
||||
foreach (Project *project, SessionManager::projectOrder(pro))
|
||||
if (project
|
||||
return Utils::anyOf(SessionManager::projectOrder(pro), [](Project *project) {
|
||||
return project
|
||||
&& project->activeTarget()
|
||||
&& project->activeTarget()->activeBuildConfiguration())
|
||||
return true;
|
||||
return false;
|
||||
&& project->activeTarget()->activeBuildConfiguration();
|
||||
});
|
||||
}
|
||||
|
||||
QPair<bool, QString> ProjectExplorerPlugin::buildSettingsEnabled(Project *pro)
|
||||
@@ -2352,12 +2345,11 @@ bool ProjectExplorerPlugin::coreAboutToClose()
|
||||
|
||||
bool ProjectExplorerPlugin::hasDeploySettings(Project *pro)
|
||||
{
|
||||
foreach (Project *project, SessionManager::projectOrder(pro))
|
||||
if (project->activeTarget()
|
||||
return Utils::anyOf(SessionManager::projectOrder(pro), [](Project *project) {
|
||||
return project->activeTarget()
|
||||
&& project->activeTarget()->activeDeployConfiguration()
|
||||
&& !project->activeTarget()->activeDeployConfiguration()->stepList()->isEmpty())
|
||||
return true;
|
||||
return false;
|
||||
&& !project->activeTarget()->activeDeployConfiguration()->stepList()->isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
void ProjectExplorerPlugin::runProject(Project *pro, RunMode mode, const bool forceSkipDeploy)
|
||||
@@ -2539,15 +2531,14 @@ void ProjectExplorerPlugin::updateDeployActions()
|
||||
|
||||
bool enableDeploySessionAction = true;
|
||||
if (d->m_projectExplorerSettings.buildBeforeDeploy) {
|
||||
foreach (Project *project, SessionManager::projectOrder(0)) {
|
||||
if (project
|
||||
&& project->activeTarget()
|
||||
auto hasDisabledBuildConfiguration = [](Project *project) {
|
||||
return project && project->activeTarget()
|
||||
&& project->activeTarget()->activeBuildConfiguration()
|
||||
&& !project->activeTarget()->activeBuildConfiguration()->isEnabled()) {
|
||||
enableDeploySessionAction = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
&& !project->activeTarget()->activeBuildConfiguration()->isEnabled();
|
||||
};
|
||||
|
||||
if (Utils::anyOf(SessionManager::projectOrder(0), hasDisabledBuildConfiguration))
|
||||
enableDeploySessionAction = false;
|
||||
}
|
||||
if (!hasProjects || !hasDeploySettings(0) || BuildManager::isBuilding())
|
||||
enableDeploySessionAction = false;
|
||||
@@ -2885,9 +2876,7 @@ void ProjectExplorerPlugin::addNewFile()
|
||||
QVariantMap map;
|
||||
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(d->m_currentNode));
|
||||
if (d->m_currentProject) {
|
||||
QList<Id> profileIds;
|
||||
foreach (Target *target, d->m_currentProject->targets())
|
||||
profileIds << target->id();
|
||||
QList<Id> profileIds = Utils::transform(d->m_currentProject->targets(), &Target::id);
|
||||
map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds));
|
||||
}
|
||||
ICore::showNewItemDialog(tr("New File", "Title of dialog"),
|
||||
@@ -2907,9 +2896,7 @@ void ProjectExplorerPlugin::addNewSubproject()
|
||||
QVariantMap map;
|
||||
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(d->m_currentNode));
|
||||
if (d->m_currentProject) {
|
||||
QList<Id> profileIds;
|
||||
foreach (Target *target, d->m_currentProject->targets())
|
||||
profileIds << target->id();
|
||||
QList<Id> profileIds = Utils::transform(d->m_currentProject->targets(), &Target::id);
|
||||
map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds));
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "projectnodes.h"
|
||||
#include "projectwizardpage.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
@@ -128,9 +130,7 @@ void ProjectFileWizardExtension::firstExtensionPageShown(
|
||||
if (debugExtension)
|
||||
qDebug() << Q_FUNC_INFO << files.size();
|
||||
|
||||
QStringList fileNames;
|
||||
foreach (const GeneratedFile &f, files)
|
||||
fileNames.push_back(f.path());
|
||||
QStringList fileNames = Utils::transform(files, &GeneratedFile::path);
|
||||
m_context->page->setFiles(fileNames);
|
||||
|
||||
QStringList filePaths;
|
||||
@@ -140,8 +140,7 @@ void ProjectFileWizardExtension::firstExtensionPageShown(
|
||||
filePaths << generatedProjectFilePath(files);
|
||||
} else {
|
||||
projectAction = ProjectExplorer::AddNewFile;
|
||||
foreach (const GeneratedFile &gf, files)
|
||||
filePaths << gf.path();
|
||||
filePaths = Utils::transform(files, &GeneratedFile::path);
|
||||
}
|
||||
|
||||
Node *contextNode = extraValues.value(QLatin1String(Constants::PREFERRED_PROJECT_NODE)).value<Node *>();
|
||||
@@ -204,9 +203,7 @@ bool ProjectFileWizardExtension::processProject(
|
||||
}
|
||||
*removeOpenProjectAttribute = true;
|
||||
} else {
|
||||
QStringList filePaths;
|
||||
foreach (const GeneratedFile &generatedFile, files)
|
||||
filePaths << generatedFile.path();
|
||||
QStringList filePaths = Utils::transform(files, &GeneratedFile::path);
|
||||
if (!folder->addFiles(filePaths)) {
|
||||
*errorMessage = tr("Failed to add one or more files to project\n\"%1\" (%2).").
|
||||
arg(folder->path(), filePaths.join(QString(QLatin1Char(','))));
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
namespace Internal {
|
||||
@@ -67,20 +68,18 @@ int SessionModel::rowCount(const QModelIndex &) const
|
||||
|
||||
QStringList pathsToBaseNames(const QStringList &paths)
|
||||
{
|
||||
QStringList stringList;
|
||||
foreach (const QString &path, paths)
|
||||
stringList.append(QFileInfo(path).completeBaseName());
|
||||
return stringList;
|
||||
return Utils::transform(paths, [](const QString &path) {
|
||||
return QFileInfo(path).completeBaseName();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
QStringList pathsWithTildeHomePath(const QStringList &paths)
|
||||
{
|
||||
QStringList stringList;
|
||||
foreach (const QString &path, paths)
|
||||
stringList.append(Utils::withTildeHomePath(QDir::toNativeSeparators(path)));
|
||||
return stringList;
|
||||
return Utils::transform(paths, [](const QString &path) {
|
||||
return Utils::withTildeHomePath(QDir::toNativeSeparators(path));
|
||||
});
|
||||
}
|
||||
|
||||
QVariant SessionModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/QtConcurrentTools>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QHBoxLayout>
|
||||
@@ -111,27 +112,15 @@ bool SelectableFilesModel::filter(Tree *t)
|
||||
if (m_files.contains(t->fullPath))
|
||||
return false;
|
||||
|
||||
bool showFilterMatch = false;
|
||||
|
||||
//First loop through show file filters and
|
||||
//if any of them match, cotinue checking.
|
||||
foreach (const Glob &g, m_showFilesFilter) {
|
||||
if (g.isMatch(t->name)) {
|
||||
showFilterMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto matchesTreeName = [t](const Glob &g) {
|
||||
return g.isMatch(t->name);
|
||||
};
|
||||
|
||||
//If none of the "show file" filters match just return
|
||||
if (!showFilterMatch)
|
||||
if (!Utils::anyOf(m_showFilesFilter, matchesTreeName))
|
||||
return true;
|
||||
|
||||
foreach (const Glob &g, m_hideFilesFilter) {
|
||||
if (g.isMatch(t->name))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return Utils::anyOf(m_hideFilesFilter, matchesTreeName);
|
||||
}
|
||||
|
||||
void SelectableFilesModel::buildTree(const QString &baseDir, Tree *tree, QFutureInterface<void> &fi, int symlinkDepth)
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
|
||||
#include <texteditor/itexteditor.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/stylehelper.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
@@ -512,11 +513,9 @@ Project *SessionManager::projectForNode(Node *node)
|
||||
|
||||
Q_ASSERT(rootProjectNode);
|
||||
|
||||
foreach (Project *p, d->m_projects)
|
||||
if (p->rootProjectNode() == rootProjectNode)
|
||||
return p;
|
||||
|
||||
return 0;
|
||||
return Utils::findOrDefault(d->m_projects, [rootProjectNode](Project *p) {
|
||||
return p->rootProjectNode() == rootProjectNode;
|
||||
});
|
||||
}
|
||||
|
||||
QList<Node *> SessionManager::nodesForFile(const QString &fileName, Project *project)
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QIcon>
|
||||
@@ -218,9 +219,7 @@ void Target::addBuildConfiguration(BuildConfiguration *configuration)
|
||||
|
||||
// Check that we don't have a configuration with the same displayName
|
||||
QString configurationDisplayName = configuration->displayName();
|
||||
QStringList displayNames;
|
||||
foreach (const BuildConfiguration *bc, d->m_buildConfigurations)
|
||||
displayNames << bc->displayName();
|
||||
QStringList displayNames = Utils::transform(d->m_buildConfigurations, &BuildConfiguration::displayName);
|
||||
configurationDisplayName = Project::makeUnique(configurationDisplayName, displayNames);
|
||||
if (configurationDisplayName != configuration->displayName()) {
|
||||
if (configuration->usesDefaultDisplayName())
|
||||
@@ -302,9 +301,7 @@ void Target::addDeployConfiguration(DeployConfiguration *dc)
|
||||
|
||||
// Check that we don't have a configuration with the same displayName
|
||||
QString configurationDisplayName = dc->displayName();
|
||||
QStringList displayNames;
|
||||
foreach (const DeployConfiguration *current, d->m_deployConfigurations)
|
||||
displayNames << current->displayName();
|
||||
QStringList displayNames = Utils::transform(d->m_deployConfigurations, &DeployConfiguration::displayName);
|
||||
configurationDisplayName = Project::makeUnique(configurationDisplayName, displayNames);
|
||||
dc->setDisplayName(configurationDisplayName);
|
||||
|
||||
@@ -405,9 +402,7 @@ void Target::addRunConfiguration(RunConfiguration* runConfiguration)
|
||||
|
||||
// Check that we don't have a configuration with the same displayName
|
||||
QString configurationDisplayName = runConfiguration->displayName();
|
||||
QStringList displayNames;
|
||||
foreach (const RunConfiguration *rc, d->m_runConfigurations)
|
||||
displayNames << rc->displayName();
|
||||
QStringList displayNames = Utils::transform(d->m_runConfigurations, &RunConfiguration::displayName);
|
||||
configurationDisplayName = Project::makeUnique(configurationDisplayName, displayNames);
|
||||
runConfiguration->setDisplayName(configurationDisplayName);
|
||||
|
||||
@@ -624,13 +619,10 @@ void Target::updateDefaultRunConfigurations()
|
||||
|
||||
// Create new RCs and put them into newConfigured/newUnconfigured
|
||||
foreach (Core::Id id, autoCreateFactoryIds) {
|
||||
IRunConfigurationFactory *factory = 0;
|
||||
foreach (IRunConfigurationFactory *i, rcFactories) {
|
||||
if (i->canCreate(this, id)) {
|
||||
factory = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
IRunConfigurationFactory *factory = Utils::findOrDefault(rcFactories,
|
||||
[this, id] (IRunConfigurationFactory *i) {
|
||||
return i->canCreate(this, id);
|
||||
});
|
||||
if (!factory)
|
||||
continue;
|
||||
|
||||
@@ -687,12 +679,10 @@ void Target::updateDefaultRunConfigurations()
|
||||
RunConfiguration *selected = newConfigured.at(0);
|
||||
// Try to find a runconfiguration that matches the project name. That is a good
|
||||
// candidate for something to run initially.
|
||||
foreach (RunConfiguration *rc, newConfigured) {
|
||||
if (rc->displayName() == project()->displayName()) {
|
||||
selected = rc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
selected = Utils::findOr(newConfigured, selected,
|
||||
[this] (RunConfiguration *rc) {
|
||||
return rc->displayName() == project()->displayName();
|
||||
});
|
||||
setActiveRunConfiguration(selected);
|
||||
} else if (!newUnconfigured.isEmpty()){
|
||||
setActiveRunConfiguration(newUnconfigured.at(0));
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/wizard.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QLabel>
|
||||
@@ -261,10 +262,7 @@ void TargetSetupPage::setKitSelected(Core::Id id, bool selected)
|
||||
|
||||
bool TargetSetupPage::isComplete() const
|
||||
{
|
||||
foreach (TargetSetupWidget *widget, m_widgets)
|
||||
if (widget->isKitSelected())
|
||||
return true;
|
||||
return false;
|
||||
return Utils::anyOf(m_widgets, &TargetSetupWidget::isKitSelected);
|
||||
}
|
||||
|
||||
void TargetSetupPage::setupWidgets()
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/persistentsettings.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
@@ -313,11 +314,9 @@ ToolChain *ToolChainManager::findToolChain(const QString &id)
|
||||
if (id.isEmpty())
|
||||
return 0;
|
||||
|
||||
foreach (ToolChain *tc, d->m_toolChains) {
|
||||
if (tc->id() == id)
|
||||
return tc;
|
||||
}
|
||||
return 0;
|
||||
return Utils::findOrDefault(d->m_toolChains, [&id](ToolChain *tc) {
|
||||
return tc->id() == id;
|
||||
});
|
||||
}
|
||||
|
||||
FileName ToolChainManager::defaultDebugger(const Abi &abi)
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <utils/detailswidget.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
@@ -245,20 +246,18 @@ ToolChainConfigWidget *ToolChainModel::widget(const QModelIndex &index)
|
||||
|
||||
bool ToolChainModel::isDirty() const
|
||||
{
|
||||
foreach (ToolChainNode *n, m_manualRoot->childNodes) {
|
||||
if (n->changed)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Utils::anyOf(m_manualRoot->childNodes,
|
||||
[](ToolChainNode *n) {
|
||||
return n->changed;
|
||||
});
|
||||
}
|
||||
|
||||
bool ToolChainModel::isDirty(ToolChain *tc) const
|
||||
{
|
||||
foreach (ToolChainNode *n, m_manualRoot->childNodes) {
|
||||
if (n->toolChain == tc && n->changed)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Utils::anyOf(m_manualRoot->childNodes,
|
||||
[tc](ToolChainNode *n) {
|
||||
return n->toolChain == tc && n->changed;
|
||||
});
|
||||
}
|
||||
|
||||
void ToolChainModel::setDirty()
|
||||
@@ -328,13 +327,7 @@ void ToolChainModel::apply()
|
||||
|
||||
void ToolChainModel::markForRemoval(ToolChain *tc)
|
||||
{
|
||||
ToolChainNode *node = 0;
|
||||
foreach (ToolChainNode *n, m_manualRoot->childNodes) {
|
||||
if (n->toolChain == tc) {
|
||||
node = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ToolChainNode *node = findToolChain(m_manualRoot->childNodes, tc);
|
||||
if (node) {
|
||||
emit beginRemoveRows(index(m_manualRoot), m_manualRoot->childNodes.indexOf(node), m_manualRoot->childNodes.indexOf(node));
|
||||
m_manualRoot->childNodes.removeOne(node);
|
||||
@@ -380,17 +373,23 @@ ToolChainNode *ToolChainModel::createNode(ToolChainNode *parent, ToolChain *tc,
|
||||
return node;
|
||||
}
|
||||
|
||||
ToolChainNode *ToolChainModel::findToolChain(const QList<ToolChainNode *> &container, ToolChain *tc)
|
||||
{
|
||||
return Utils::findOrDefault(container, [tc] (ToolChainNode *n) {
|
||||
return n->toolChain == tc;
|
||||
});
|
||||
}
|
||||
|
||||
void ToolChainModel::addToolChain(ToolChain *tc)
|
||||
{
|
||||
QList<ToolChainNode *> nodes = m_toAddList;
|
||||
foreach (ToolChainNode *n, nodes) {
|
||||
if (n->toolChain == tc) {
|
||||
m_toAddList.removeOne(n);
|
||||
// do not delete n: Still used elsewhere!
|
||||
return;
|
||||
}
|
||||
ToolChainNode *n = findToolChain(m_toAddList, tc);
|
||||
if (n) {
|
||||
m_toAddList.removeOne(n);
|
||||
// do not delete n: Still used elsewhere!
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ToolChainNode *parent = m_manualRoot;
|
||||
if (tc->isAutoDetected())
|
||||
parent = m_autoRoot;
|
||||
@@ -405,13 +404,11 @@ void ToolChainModel::addToolChain(ToolChain *tc)
|
||||
|
||||
void ToolChainModel::removeToolChain(ToolChain *tc)
|
||||
{
|
||||
QList<ToolChainNode *> nodes = m_toRemoveList;
|
||||
foreach (ToolChainNode *n, nodes) {
|
||||
if (n->toolChain == tc) {
|
||||
m_toRemoveList.removeOne(n);
|
||||
delete n;
|
||||
return;
|
||||
}
|
||||
ToolChainNode *n = findToolChain(m_toRemoveList, tc);
|
||||
if (n) {
|
||||
m_toRemoveList.removeOne(n);
|
||||
delete n;
|
||||
return;
|
||||
}
|
||||
|
||||
ToolChainNode *parent = m_manualRoot;
|
||||
|
||||
@@ -98,6 +98,8 @@ private slots:
|
||||
private:
|
||||
QModelIndex index(ToolChainNode *, int column = 0) const;
|
||||
ToolChainNode *createNode(ToolChainNode *parent, ToolChain *tc, bool changed);
|
||||
static ToolChainNode *findToolChain(const QList<ToolChainNode *> &container, ToolChain *tc);
|
||||
|
||||
|
||||
ToolChainNode *m_root;
|
||||
ToolChainNode *m_autoRoot;
|
||||
|
||||
@@ -804,6 +804,7 @@ bool QmakePriFileNode::deploysFolder(const QString &folder) const
|
||||
const QChar slash = QLatin1Char('/');
|
||||
if (!f.endsWith(slash))
|
||||
f.append(slash);
|
||||
|
||||
foreach (const QString &wf, m_watchedFolders) {
|
||||
if (f.startsWith(wf)
|
||||
&& (wf.endsWith(slash)
|
||||
@@ -955,9 +956,7 @@ bool QmakePriFileNode::removeSubProjects(const QStringList &proFilePaths)
|
||||
QStringList failedOriginalFiles;
|
||||
changeFiles(QLatin1String(Constants::PROFILE_MIMETYPE), proFilePaths, &failedOriginalFiles, RemoveFromProFile);
|
||||
|
||||
QStringList simplifiedProFiles;
|
||||
foreach (const QString &proFile, failedOriginalFiles)
|
||||
simplifiedProFiles.append(simplifyProFilePath(proFile));
|
||||
QStringList simplifiedProFiles = Utils::transform(failedOriginalFiles, &simplifyProFilePath);
|
||||
|
||||
QStringList failedSimplifiedFiles;
|
||||
changeFiles(QLatin1String(Constants::PROFILE_MIMETYPE), simplifiedProFiles, &failedSimplifiedFiles, RemoveFromProFile);
|
||||
|
||||
@@ -264,9 +264,7 @@ static QString fixStringForTags(const QString &string)
|
||||
|
||||
static QStringList trimStringList(const QStringList &stringlist)
|
||||
{
|
||||
return Utils::transform(stringlist, [](const QString &string) {
|
||||
return string.trimmed();
|
||||
});
|
||||
return Utils::transform(stringlist, &QString::trimmed);
|
||||
}
|
||||
|
||||
static QString relativeOrInstallPath(const QString &path, const QString &manifestPath,
|
||||
@@ -782,10 +780,9 @@ bool ExamplesListModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex
|
||||
const QStringList tags = sourceModel()->index(sourceRow, 0, sourceParent).data(Tags).toStringList();
|
||||
|
||||
if (!m_filterTags.isEmpty()) {
|
||||
foreach (const QString &tag, m_filterTags)
|
||||
if (!tags.contains(tag, Qt::CaseInsensitive))
|
||||
return false;
|
||||
return true;
|
||||
return Utils::allOf(m_filterTags, [tags](const QString &filterTag) {
|
||||
return tags.contains(filterTag);
|
||||
});
|
||||
}
|
||||
|
||||
if (!m_searchString.isEmpty()) {
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
@@ -50,9 +51,7 @@ QtKitConfigWidget::QtKitConfigWidget(ProjectExplorer::Kit *k, const ProjectExplo
|
||||
m_combo = new QComboBox;
|
||||
m_combo->addItem(tr("None"), -1);
|
||||
|
||||
QList<int> versionIds;
|
||||
foreach (BaseQtVersion *v, QtVersionManager::versions())
|
||||
versionIds.append(v->uniqueId());
|
||||
QList<int> versionIds = Utils::transform(QtVersionManager::versions(), &BaseQtVersion::uniqueId);
|
||||
versionsChanged(versionIds, QList<int>(), QList<int>());
|
||||
|
||||
m_manageButton = new QPushButton(KitConfigWidget::msgManage());
|
||||
|
||||
@@ -151,9 +151,7 @@ QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent)
|
||||
m_manualItem->setFirstColumnSpanned(true);
|
||||
m_manualItem->setFlags(Qt::ItemIsEnabled);
|
||||
|
||||
QList<int> additions;
|
||||
foreach (BaseQtVersion *v, QtVersionManager::versions())
|
||||
additions.append(v->uniqueId());
|
||||
QList<int> additions = transform(QtVersionManager::versions(), &BaseQtVersion::uniqueId);
|
||||
|
||||
updateQtVersions(additions, QList<int>(), QList<int>());
|
||||
|
||||
|
||||
@@ -641,13 +641,9 @@ FileName QtVersionManager::findQMakeBinaryFromMakefile(const QString &makefile)
|
||||
|
||||
BaseQtVersion *QtVersionManager::qtVersionForQMakeBinary(const FileName &qmakePath)
|
||||
{
|
||||
foreach (BaseQtVersion *version, versions()) {
|
||||
if (version->qmakeCommand() == qmakePath) {
|
||||
return version;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return Utils::findOrDefault(versions(), [&qmakePath](BaseQtVersion *v) {
|
||||
return v->qmakeCommand() == qmakePath;
|
||||
});
|
||||
}
|
||||
|
||||
void dumpQMakeAssignments(const QList<QMakeAssignment> &list)
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFile>
|
||||
@@ -333,11 +334,9 @@ UiCodeModelManager::~UiCodeModelManager()
|
||||
|
||||
static UiCodeModelSupport *findUiFile(const QList<UiCodeModelSupport *> &range, const QString &uiFile)
|
||||
{
|
||||
foreach (UiCodeModelSupport *support, range) {
|
||||
if (support->uiFileName() == uiFile)
|
||||
return support;
|
||||
}
|
||||
return 0;
|
||||
return Utils::findOrDefault(range, [uiFile](UiCodeModelSupport *support) {
|
||||
return support->uiFileName() == uiFile;
|
||||
});
|
||||
}
|
||||
|
||||
void UiCodeModelManager::update(ProjectExplorer::Project *project, QHash<QString, QString> uiHeaders)
|
||||
|
||||
Reference in New Issue
Block a user