Commit 93c537e8 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

kdevplastform/project: port foreach -> range-based for

parent f8b05257
......@@ -237,13 +237,13 @@ void AbstractFileManagerPluginPrivate::addJobItems(FileManagerListJob* job,
}
// add new rows
foreach ( const Path& path, files ) {
for (const Path& path : qAsConst(files)) {
ProjectFileItem* file = q->createFileItem( baseItem->project(), path, baseItem );
if (file) {
emit q->fileAdded( file );
}
}
foreach ( const Path& path, folders ) {
for (const Path& path : qAsConst(folders)) {
ProjectFolderItem* folder = q->createFolderItem( baseItem->project(), path, baseItem );
if (folder) {
emit q->folderAdded( folder );
......@@ -279,7 +279,8 @@ void AbstractFileManagerPluginPrivate::created(const QString& path_)
}
if ( info.isDir() ) {
bool found = false;
foreach ( ProjectFolderItem* folder, p->foldersForPath(indexedPath) ) {
const auto folderItems = p->foldersForPath(indexedPath);
for (ProjectFolderItem* folder : folderItems) {
// exists already in this project, happens e.g. when we restart the dirwatcher
// or if we delete and remove folders consecutively https://bugs.kde.org/show_bug.cgi?id=260741
qCDebug(FILEMANAGER) << "force reload of" << path << folder;
......@@ -294,7 +295,8 @@ void AbstractFileManagerPluginPrivate::created(const QString& path_)
// also gets triggered for kate's backup files
continue;
}
foreach ( ProjectFolderItem* parentItem, p->foldersForPath(indexedParent) ) {
const auto parentItems = p->foldersForPath(indexedParent);
for (ProjectFolderItem* parentItem : parentItems) {
if ( info.isDir() ) {
ProjectFolderItem* folder = q->createFolderItem( p, path, parentItem );
if (folder) {
......@@ -319,7 +321,7 @@ void AbstractFileManagerPluginPrivate::deleted(const QString& path_)
return;
}
// ensure that the path is not inside a stopped folder
foreach(const QString& folder, m_stoppedFolders) {
for (const QString& folder : qAsConst(m_stoppedFolders)) {
if (path_.startsWith(folder)) {
return;
}
......@@ -346,10 +348,12 @@ void AbstractFileManagerPluginPrivate::deleted(const QString& path_)
// FIXME: how should this be handled? see unit test
continue;
}
foreach ( ProjectFolderItem* item, p->foldersForPath(indexed) ) {
const auto folderItems = p->foldersForPath(indexed);
for (ProjectFolderItem* item : folderItems) {
delete item;
}
foreach ( ProjectFileItem* item, p->filesForPath(indexed) ) {
const auto fileItems = p->filesForPath(indexed);
for (ProjectFileItem* item : fileItems) {
emit q->fileRemoved(item);
ifDebug(qCDebug(FILEMANAGER) << "removing file" << item;)
delete item;
......@@ -369,7 +373,8 @@ bool AbstractFileManagerPluginPrivate::rename(ProjectBaseItem* item, const Path&
return false;
}
}
foreach ( ProjectFolderItem* parent, item->project()->foldersForPath(IndexedString(newPath.parent().pathOrUrl())) ) {
const auto parentItems = item->project()->foldersForPath(IndexedString(newPath.parent().pathOrUrl()));
for (ProjectFolderItem* parent : parentItems) {
if ( parent->folder() ) {
stopWatcher(parent);
const Path source = item->path();
......
......@@ -213,7 +213,7 @@ void BuilderJob::updateJobName()
// Whether there are jobs without any specific item
bool hasNullItems = false;
foreach( const SubJobData& subjob, d->m_metadata ) {
for (const SubJobData& subjob : qAsConst(d->m_metadata)) {
if( subjob.item ) {
if( !registeredItems.contains( subjob.item ) ) {
registeredItems.append( subjob.item );
......@@ -230,7 +230,7 @@ void BuilderJob::updateJobName()
if( !hasNullItems ) {
QStringList itemNamesList;
itemNamesList.reserve(registeredItems.size());
foreach( ProjectBaseItem* item, registeredItems ) {
for (ProjectBaseItem* item : qAsConst(registeredItems)) {
itemNamesList << item->text();
}
itemNames = itemNamesList.join(QStringLiteral(", "));
......@@ -241,7 +241,7 @@ void BuilderJob::updateJobName()
QString methodNames;
QStringList methodNamesList;
methodNamesList.reserve(buildTypes.size());
foreach( BuildType type, buildTypes ) {
for (BuildType type : qAsConst(buildTypes)) {
methodNamesList << d->buildTypeToString( type );
}
methodNames = methodNamesList.join( QStringLiteral( ", " ) );
......
......@@ -170,7 +170,8 @@ bool KDevelop::renameUrl(const KDevelop::IProject* project, const QUrl& oldname,
// save files that where opened in this folder under the new name
Path oldBasePath(oldname);
Path newBasePath(newname);
foreach (auto doc, ICore::self()->documentController()->openDocuments()) {
const auto documents = ICore::self()->documentController()->openDocuments();
for (auto* doc : documents) {
auto textDoc = doc->textDocument();
if (textDoc && oldname.isParentOf(doc->url())) {
const auto path = Path(textDoc->url());
......
......@@ -47,7 +47,8 @@ public:
void import(ProjectFolderItem* folder)
{
foreach(ProjectFolderItem* sub, m_importer->parse(folder)) {
const auto subs = m_importer->parse(folder);
for (ProjectFolderItem* sub : subs) {
if(!cancel) {
import(sub);
}
......
......@@ -136,7 +136,7 @@ void ProjectBuildSetModel::storeToSession( ISession* session )
// Store the item ordering cache
QVariantList sessionBuildItems;
sessionBuildItems.reserve(d->orderingCache.size());
foreach (const QStringList& item, d->orderingCache) {
for (const QStringList& item : qAsConst(d->orderingCache)) {
sessionBuildItems.append( item );
}
KConfigGroup sessionBuildSetConfig = session->config()->group( "Buildset" );
......@@ -351,7 +351,7 @@ void ProjectBuildSetModel::projectClosed( KDevelop::IProject* project )
void ProjectBuildSetModel::saveToProject( KDevelop::IProject* project ) const
{
QVariantList paths;
foreach (const BuildItem& item, d->items) {
for (const BuildItem& item : qAsConst(d->items)) {
if( item.itemProject() == project->name() )
paths.append(item.itemPath());
}
......
......@@ -47,9 +47,11 @@ using namespace KDevelop;
ProjectChangesModel::ProjectChangesModel(QObject* parent)
: VcsFileChangesModel(parent)
{
foreach(IProject* p, ICore::self()->projectController()->projects())
const auto projects = ICore::self()->projectController()->projects();
for (IProject* p : projects) {
addProject(p);
}
connect(ICore::self()->projectController(), &IProjectController::projectOpened,
this, &ProjectChangesModel::addProject);
connect(ICore::self()->projectController(), &IProjectController::projectClosing,
......
......@@ -90,8 +90,8 @@ void ProjectConfigSkeleton::setDefaults()
{
qCDebug(PROJECT) << "Setting Defaults";
KConfig cfg( d->m_projectTempFile );
Q_FOREACH( KConfigSkeletonItem* item, items() )
{
const auto items = this->items();
for (KConfigSkeletonItem* item : items) {
item->swapDefault();
if( cfg.hasGroup( item->group() ) )
{
......@@ -110,8 +110,8 @@ bool ProjectConfigSkeleton::useDefaults( bool b )
if( b )
{
KConfig cfg( d->m_projectTempFile );
Q_FOREACH( KConfigSkeletonItem* item, items() )
{
const auto items = this->items();
for (KConfigSkeletonItem* item : items) {
item->swapDefault();
if( cfg.hasGroup( item->group() ) )
{
......@@ -125,8 +125,8 @@ bool ProjectConfigSkeleton::useDefaults( bool b )
{
KConfig cfg( d->m_developerTempFile );
KConfig defCfg( d->m_projectTempFile );
Q_FOREACH( KConfigSkeletonItem* item, items() )
{
const auto items = this->items();
for (KConfigSkeletonItem* item : items) {
if( cfg.hasGroup( item->group() ) )
{
KConfigGroup grp = cfg.group( item->group() );
......
......@@ -140,7 +140,8 @@ ProjectFilterManager::ProjectFilterManager(QObject* parent)
connect(ICore::self()->pluginController(), &IPluginController::unloadingPlugin,
this, [&] (IPlugin* plugin) { d->unloadingPlugin(plugin); });
foreach(IPlugin* plugin, ICore::self()->pluginController()->loadedPlugins()) {
const auto plugins = ICore::self()->pluginController()->loadedPlugins();
for (IPlugin* plugin : plugins) {
d->pluginLoaded(plugin);
}
}
......@@ -154,7 +155,7 @@ void ProjectFilterManager::add(IProject* project)
{
QVector<Filter> filters;
filters.reserve(d->m_filterProvider.size());
foreach(IProjectFilterProvider* provider, d->m_filterProvider) {
for (IProjectFilterProvider* provider : qAsConst(d->m_filterProvider)) {
Filter filter;
filter.provider = provider;
filter.filter = provider->createFilter(project);
......@@ -175,12 +176,10 @@ bool ProjectFilterManager::isManaged(IProject* project) const
bool ProjectFilterManager::isValid(const Path& path, bool isFolder, IProject* project) const
{
foreach(const Filter& filter, d->m_filters[project]) {
if (!filter.filter->isValid(path, isFolder)) {
return false;
}
}
return true;
const auto filters = d->m_filters[project];
return std::all_of(filters.begin(), filters.end(), [&](const Filter& filter) {
return (filter.filter->isValid(path, isFolder));
});
}
QVector< QSharedPointer< IProjectFilter > > ProjectFilterManager::filtersForProject(IProject* project) const
......
......@@ -133,13 +133,12 @@ QValidator::State ProjectItemValidator::validate(QString& input, int& pos) const
{
// Check for a project whose name beings with the input
QString first = path.first();
foreach( KDevelop::IProject* project, KDevelop::ICore::self()->projectController()->projects() )
{
if( project->name().startsWith( first, Qt::CaseInsensitive ) )
{
state = QValidator::Intermediate;
break;
}
const auto projects = KDevelop::ICore::self()->projectController()->projects();
bool matchesAnyName = std::any_of(projects.begin(), projects.end(), [&](KDevelop::IProject* project) {
return (project->name().startsWith(first, Qt::CaseInsensitive));
});
if (matchesAnyName) {
state = QValidator::Intermediate;
}
}
return state;
......
......@@ -116,7 +116,8 @@ public:
ProjectBaseItem::RenameStatus renameBaseItem(ProjectBaseItem* item, const QString& newName)
{
if (item->parent()) {
foreach(ProjectBaseItem* sibling, item->parent()->children()) {
const auto siblings = item->parent()->children();
for (ProjectBaseItem* sibling : siblings) {
if (sibling->text() == newName) {
return ProjectBaseItem::ExistingItemSameName;
}
......@@ -249,7 +250,7 @@ void ProjectBaseItem::removeRows(int row, int count)
//NOTE: we unset parent, row and model manually to speed up the deletion
if (row == 0 && count == d->children.size()) {
// optimize if we want to delete all
foreach(ProjectBaseItem* item, d->children) {
for (ProjectBaseItem* item : qAsConst(d->children)) {
item->d_func()->parent = nullptr;
item->d_func()->row = -1;
item->setModel( nullptr );
......@@ -343,7 +344,7 @@ void ProjectBaseItem::setModel( ProjectModel* model )
model->d->pathLookupTable.insert(d->m_pathIndex, this);
}
foreach( ProjectBaseItem* item, d->children ) {
for (ProjectBaseItem* item : qAsConst(d->children)) {
item->setModel( model );
}
}
......@@ -630,8 +631,8 @@ void ProjectFolderItem::propagateRename( const Path& newBase ) const
{
Path path = newBase;
path.addPath(QStringLiteral("dummy"));
foreach( KDevelop::ProjectBaseItem* child, children() )
{
const auto children = this->children();
for (KDevelop::ProjectBaseItem* child : children) {
path.setLastPathSegment( child->text() );
child->setPath( path );
......@@ -649,15 +650,11 @@ ProjectBaseItem::RenameStatus ProjectFolderItem::rename(const QString& newName)
bool ProjectFolderItem::hasFileOrFolder(const QString& name) const
{
foreach ( ProjectBaseItem* item, children() )
{
if ( (item->type() == Folder || item->type() == File || item->type() == BuildFolder)
&& name == item->baseName() )
{
return true;
}
}
return false;
const auto children = this->children();
return std::any_of(children.begin(), children.end(), [&](ProjectBaseItem* item) {
return ((item->type() == Folder || item->type() == File || item->type() == BuildFolder)
&& name == item->baseName());
});
}
bool ProjectBaseItem::isProjectRoot() const
......@@ -1096,8 +1093,8 @@ ProjectBaseItem* ProjectModel::itemForPath(const IndexedString& path) const
void ProjectVisitor::visit( ProjectModel* model )
{
foreach( ProjectBaseItem* item, model->topItems() )
{
const auto topItems = model->topItems();
for (ProjectBaseItem* item : topItems) {
visit( item->project() );
}
}
......@@ -1114,20 +1111,20 @@ void ProjectVisitor::visit ( ProjectBuildFolderItem* folder )
void ProjectVisitor::visit ( ProjectExecutableTargetItem* exec )
{
foreach( ProjectFileItem* item, exec->fileList() )
{
const auto fileItems = exec->fileList();
for (ProjectFileItem* item : fileItems) {
visit( item );
}
}
void ProjectVisitor::visit ( ProjectFolderItem* folder )
{
foreach( ProjectFileItem* item, folder->fileList() )
{
const auto fileItems = folder->fileList();
for (ProjectFileItem* item : fileItems) {
visit( item );
}
foreach( ProjectTargetItem* item, folder->targetList() )
{
const auto targetItems = folder->targetList();
for (ProjectTargetItem* item : targetItems) {
if( item->type() == ProjectBaseItem::LibraryTarget )
{
visit( dynamic_cast<ProjectLibraryTargetItem*>( item ) );
......@@ -1136,8 +1133,8 @@ void ProjectVisitor::visit ( ProjectFolderItem* folder )
visit( dynamic_cast<ProjectExecutableTargetItem*>( item ) );
}
}
foreach( ProjectFolderItem* item, folder->folderList() )
{
const auto folderItems = folder->folderList();
for (ProjectFolderItem* item : folderItems) {
if( item->type() == ProjectBaseItem::BuildFolder )
{
visit( dynamic_cast<ProjectBuildFolderItem*>( item ) );
......@@ -1154,8 +1151,8 @@ void ProjectVisitor::visit ( ProjectFileItem* )
void ProjectVisitor::visit ( ProjectLibraryTargetItem* lib )
{
foreach( ProjectFileItem* item, lib->fileList() )
{
const auto fileItems = lib->fileList();
for (ProjectFileItem* item : fileItems) {
visit( item );
}
}
......
......@@ -33,7 +33,8 @@ ProjectItemContextImpl::ProjectItemContextImpl(const QList<ProjectBaseItem*>& it
QList<QUrl> ProjectItemContextImpl::urls() const
{
QList<QUrl> urls;
foreach (const auto& item, items()) {
const auto items = this->items();
for (const auto& item : items) {
const auto url = item->path().toUrl();
if (url.isValid()) {
urls << url;
......
......@@ -479,9 +479,9 @@ void TestProjectModel::testItemsForPath()
model->appendRow(root);
auto items = model->itemsForPath(IndexedString(path.pathOrUrl()));
const auto items = model->itemsForPath(IndexedString(path.pathOrUrl()));
QCOMPARE(items.size(), matches);
foreach(ProjectBaseItem* item, items) {
for (ProjectBaseItem* item : items) {
QVERIFY(item->path() == path);
}
......
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