From 1db9dd058e66e55163b85aecc5a63171bc3461d4 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 30 Jun 2021 11:33:33 +0200 Subject: [PATCH] QtSupport: Use FilePaths in BaseQtVersion::isInSourceDirectory ... and isSubProject. Take the opportunity to rename them into isInQtSourceDirectory and a isQtSubProject to make its limited scope clearer. An open question is why this is only used for qmake projects. Change-Id: If36f9457583eac17e149624ec46e5de10dd4a5a5 Reviewed-by: Christian Stenger --- .../qmakebuildconfiguration.cpp | 2 +- .../qmakeprojectmanager/qmakeproject.cpp | 2 +- src/plugins/qtsupport/baseqtversion.cpp | 31 +++++++++---------- src/plugins/qtsupport/baseqtversion.h | 4 +-- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp index a4f9963a30e..b84aa0036bf 100644 --- a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp +++ b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp @@ -757,7 +757,7 @@ static BuildInfo createBuildInfo(const Kit *k, const FilePath &projectPath, // Leave info.buildDirectory unset; // check if this project is in the source directory: - if (version && version->isInSourceDirectory(projectPath)) { + if (version && version->isInQtSourceDirectory(projectPath)) { // assemble build directory QString projectDirectory = projectPath.toFileInfo().absolutePath(); QDir qtSourceDir = QDir(version->sourcePath().toString()); diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index 3babadd0dc7..a1ff1f21f11 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -746,7 +746,7 @@ Tasks QmakeProject::projectIssues(const Kit *k) const // that is not the one from the current kit. const QList qtsContainingThisProject = QtVersionManager::versions([filePath = projectFilePath()](const BaseQtVersion *qt) { - return qt->isValid() && qt->isSubProject(filePath); + return qt->isValid() && qt->isQtSubProject(filePath); }); if (!qtsContainingThisProject.isEmpty() && !qtsContainingThisProject.contains(const_cast(qtFromKit))) { diff --git a/src/plugins/qtsupport/baseqtversion.cpp b/src/plugins/qtsupport/baseqtversion.cpp index a1c5331c270..0ba9d049672 100644 --- a/src/plugins/qtsupport/baseqtversion.cpp +++ b/src/plugins/qtsupport/baseqtversion.cpp @@ -1961,35 +1961,32 @@ FilePath BaseQtVersionPrivate::sourcePath(const QHash &versio return FilePath::fromUserInput(QFileInfo(sourcePath).canonicalFilePath()); } -bool BaseQtVersion::isInSourceDirectory(const FilePath &filePath) +bool BaseQtVersion::isInQtSourceDirectory(const FilePath &filePath) const { - const FilePath &source = sourcePath(); + FilePath source = sourcePath(); if (source.isEmpty()) return false; - QDir dir = QDir(source.toString()); - if (dir.dirName() == "qtbase") - dir.cdUp(); - return filePath.isChildOf(dir); + if (source.fileName() == "qtbase") + source = source.parentDir(); + return filePath.isChildOf(source); } -bool BaseQtVersion::isSubProject(const FilePath &filePath) const +bool BaseQtVersion::isQtSubProject(const FilePath &filePath) const { - const FilePath &source = sourcePath(); + FilePath source = sourcePath(); if (!source.isEmpty()) { - QDir dir = QDir(source.toString()); - if (dir.dirName() == "qtbase") - dir.cdUp(); - - if (filePath.isChildOf(dir)) + if (source.fileName() == "qtbase") + source = source.parentDir(); + if (filePath.isChildOf(source)) return true; } - const QString examples = examplesPath().toString(); - if (!examples.isEmpty() && filePath.isChildOf(QDir(examples))) + const FilePath examples = examplesPath(); + if (!examples.isEmpty() && filePath.isChildOf(examples)) return true; - const QString demos = demosPath().toString(); - if (!demos.isEmpty() && filePath.isChildOf(QDir(demos))) + const FilePath demos = demosPath(); + if (!demos.isEmpty() && filePath.isChildOf(demos)) return true; return false; diff --git a/src/plugins/qtsupport/baseqtversion.h b/src/plugins/qtsupport/baseqtversion.h index e58523f2ee5..9ea9af4b1d9 100644 --- a/src/plugins/qtsupport/baseqtversion.h +++ b/src/plugins/qtsupport/baseqtversion.h @@ -128,8 +128,8 @@ public: Utils::FilePath sourcePath() const; // returns source path for installed qt packages and empty string for self build qt Utils::FilePath qtPackageSourcePath() const; - bool isInSourceDirectory(const Utils::FilePath &filePath); - bool isSubProject(const Utils::FilePath &filePath) const; + bool isInQtSourceDirectory(const Utils::FilePath &filePath) const; + bool isQtSubProject(const Utils::FilePath &filePath) const; Utils::FilePath rccCommand() const; // used by UiCodeModelSupport