File indexing completed on 2024-04-28 04:37:05
0001 /* 0002 SPDX-FileCopyrightText: 2011 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "projectutils.h" 0008 #include <project/projectmodel.h> 0009 #include "path.h" 0010 0011 0012 namespace KDevelop { 0013 0014 ProjectItemContextImpl::ProjectItemContextImpl(const QList<ProjectBaseItem*>& items) 0015 : ProjectItemContext(items) 0016 { 0017 } 0018 0019 QList<QUrl> ProjectItemContextImpl::urls() const 0020 { 0021 QList<QUrl> urls; 0022 const auto items = this->items(); 0023 for (const auto& item : items) { 0024 const auto url = item->path().toUrl(); 0025 if (url.isValid()) { 0026 urls << url; 0027 } 0028 } 0029 return urls; 0030 } 0031 0032 /** 0033 * Runs the @p callback on all files that have @p projectItem as ancestor 0034 */ 0035 void forEachFile(const ProjectBaseItem* projectItem, 0036 const std::function<void(ProjectFileItem*)>& callback) 0037 { 0038 if (auto* file = projectItem->file()) { 0039 callback(file); 0040 return; 0041 } 0042 0043 const auto children = projectItem->children(); 0044 for (const auto *child : children) { 0045 forEachFile(child, callback); 0046 } 0047 } 0048 0049 QList<ProjectFileItem*> allFiles(const ProjectBaseItem* projectItem) 0050 { 0051 QList<ProjectFileItem*> files; 0052 forEachFile(projectItem, [&files](ProjectFileItem *fileItem) { 0053 files.append(fileItem); 0054 }); 0055 return files; 0056 } 0057 0058 }