FileInProjectFinder: Use FileNameList for file names

This simplifies code and reduces the number of conversions between
QString and Utils::FileName.

Change-Id: I47bd86b9ae09b1da37b4e5e604761367ac1ab26b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Tim Jenssen
2018-05-24 11:17:04 +02:00
parent 3fa66ca6e0
commit b5a4e88485
6 changed files with 18 additions and 18 deletions

View File

@@ -95,7 +95,7 @@ QString FileInProjectFinder::projectDirectory() const
return m_projectDir;
}
void FileInProjectFinder::setProjectFiles(const QStringList &projectFiles)
void FileInProjectFinder::setProjectFiles(const Utils::FileNameList &projectFiles)
{
if (m_projectFiles == projectFiles)
return;
@@ -309,9 +309,9 @@ QString FileInProjectFinder::findInSearchPath(const QString &searchPath, const Q
QStringList FileInProjectFinder::filesWithSameFileName(const QString &fileName) const
{
QStringList result;
foreach (const QString &f, m_projectFiles) {
if (FileName::fromString(f).fileName() == fileName)
result << f;
foreach (const FileName &f, m_projectFiles) {
if (f.fileName() == fileName)
result << f.toString();
}
return result;
}
@@ -319,8 +319,8 @@ QStringList FileInProjectFinder::filesWithSameFileName(const QString &fileName)
QStringList FileInProjectFinder::pathSegmentsWithSameName(const QString &pathSegment) const
{
QStringList result;
for (const QString &f : m_projectFiles) {
QDir dir = FileName::fromString(f).toFileInfo().absoluteDir();
for (const FileName &f : m_projectFiles) {
QDir dir = f.toFileInfo().absoluteDir();
do {
if (dir.dirName() == pathSegment) {
if (result.isEmpty() || result.last() != dir.path())

View File

@@ -26,6 +26,7 @@
#pragma once
#include <utils/utils_global.h>
#include <utils/fileutils.h>
#include <QHash>
#include <QStringList>
@@ -48,7 +49,7 @@ public:
void setProjectDirectory(const QString &absoluteProjectPath);
QString projectDirectory() const;
void setProjectFiles(const QStringList &projectFiles);
void setProjectFiles(const Utils::FileNameList &projectFiles);
void setSysroot(const QString &sysroot);
QString findFile(const QUrl &fileUrl, bool *success = nullptr) const;
@@ -73,7 +74,7 @@ private:
QString m_projectDir;
QString m_sysroot;
QStringList m_projectFiles;
Utils::FileNameList m_projectFiles;
QStringList m_searchDirectories;
mutable QHash<QString,QString> m_cache;
};

View File

@@ -33,6 +33,7 @@
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/runconfiguration.h>
#include <texteditor/textmark.h>
#include <utils/fileutils.h>
#include <QObject>
#include <QProcess>
@@ -143,7 +144,7 @@ public:
ProjectExplorer::Abi toolChainAbi;
QString projectSourceDirectory;
QStringList projectSourceFiles;
Utils::FileNameList projectSourceFiles;
// Used by Script debugging
QString interpreter;

View File

@@ -277,7 +277,7 @@ void DebuggerRunTool::setStartMode(DebuggerStartMode startMode)
projects.insert(0, startupProject);
}
foreach (Project *project, projects)
m_runParameters.projectSourceFiles.append(transform(project->files(Project::SourceFiles), &FileName::toString));
m_runParameters.projectSourceFiles.append(project->files(Project::SourceFiles));
if (!projects.isEmpty())
m_runParameters.projectSourceDirectory = projects.first()->projectDirectory().toString();
@@ -863,7 +863,7 @@ DebuggerRunTool::DebuggerRunTool(RunControl *runControl, Kit *kit, bool allowTer
Project *project = runConfig ? runConfig->target()->project() : nullptr;
if (project) {
m_runParameters.projectSourceDirectory = project->projectDirectory().toString();
m_runParameters.projectSourceFiles = transform(project->files(Project::SourceFiles), &FileName::toString);
m_runParameters.projectSourceFiles = project->files(Project::SourceFiles);
}
m_runParameters.toolChainAbi = ToolChainKitInformation::targetAbi(kit);

View File

@@ -1413,20 +1413,18 @@ void BaseQtVersion::populateQmlFileFinder(FileInProjectFinder *finder, const Tar
QTC_CHECK(projects.isEmpty() || startupProject);
QString projectDirectory;
QStringList sourceFiles;
Utils::FileNameList sourceFiles;
// Sort files from startupProject to the front of the list ...
if (startupProject) {
projectDirectory = startupProject->projectDirectory().toString();
sourceFiles.append(Utils::transform(startupProject->files(ProjectExplorer::Project::SourceFiles),
&Utils::FileName::toString));
sourceFiles.append(startupProject->files(ProjectExplorer::Project::SourceFiles));
}
// ... then add all the other projects' files.
for (const ProjectExplorer::Project *project : projects) {
if (project != startupProject)
sourceFiles.append(Utils::transform(project->files(ProjectExplorer::Project::SourceFiles),
&Utils::FileName::toString));
sourceFiles.append(project->files(ProjectExplorer::Project::SourceFiles));
}
// If no target was given, but we've found a startupProject, then try to deduce a

View File

@@ -87,7 +87,7 @@ QtOutputFormatter::QtOutputFormatter(Project *project)
: d(new Internal::QtOutputFormatterPrivate(project))
{
if (project) {
d->projectFinder.setProjectFiles(Utils::transform(project->files(Project::SourceFiles), &Utils::FileName::toString));
d->projectFinder.setProjectFiles(project->files(Project::SourceFiles));
d->projectFinder.setProjectDirectory(project->projectDirectory().toString());
connect(project, &Project::fileListChanged,
@@ -281,7 +281,7 @@ void QtOutputFormatter::openEditor(const QString &fileName, int line, int column
void QtOutputFormatter::updateProjectFileList()
{
if (d->project)
d->projectFinder.setProjectFiles(transform(d->project->files(Project::SourceFiles), &FileName::toString));
d->projectFinder.setProjectFiles(d->project->files(Project::SourceFiles));
}
} // namespace QtSupport