From b97639158c13a94d54c37799e96b928e6a6f3ef1 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 26 Feb 2019 08:04:01 +0100 Subject: [PATCH] Qbs: Some code cosmetics Mostly namespaces, whitespace, avoidance of repetitive code. Change-Id: I49185464b6e7baadeb519799f06c7f50e8039366 Reviewed-by: Christian Kandeler --- .../qbsprojectmanager/qbsnodetreebuilder.cpp | 114 +++++++++--------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/src/plugins/qbsprojectmanager/qbsnodetreebuilder.cpp b/src/plugins/qbsprojectmanager/qbsnodetreebuilder.cpp index e9e2ecd754d..857008bb7ee 100644 --- a/src/plugins/qbsprojectmanager/qbsnodetreebuilder.cpp +++ b/src/plugins/qbsprojectmanager/qbsnodetreebuilder.cpp @@ -30,36 +30,43 @@ #include #include -namespace { +using namespace ProjectExplorer; +using namespace Utils; -ProjectExplorer::FileType fileType(const qbs::ArtifactData &artifact) +namespace QbsProjectManager { +namespace Internal { + +namespace { + +FileType fileType(const qbs::ArtifactData &artifact) { - QTC_ASSERT(artifact.isValid(), return ProjectExplorer::FileType::Unknown); + QTC_ASSERT(artifact.isValid(), return FileType::Unknown); - if (artifact.fileTags().contains("c") - || artifact.fileTags().contains("cpp") - || artifact.fileTags().contains("objc") - || artifact.fileTags().contains("objcpp")) { - return ProjectExplorer::FileType::Source; + const QStringList fileTags = artifact.fileTags(); + if (fileTags.contains("c") + || fileTags.contains("cpp") + || fileTags.contains("objc") + || fileTags.contains("objcpp")) { + return FileType::Source; } - if (artifact.fileTags().contains("hpp")) - return ProjectExplorer::FileType::Header; - if (artifact.fileTags().contains("qrc")) - return ProjectExplorer::FileType::Resource; - if (artifact.fileTags().contains("ui")) - return ProjectExplorer::FileType::Form; - if (artifact.fileTags().contains("scxml")) - return ProjectExplorer::FileType::StateChart; - if (artifact.fileTags().contains("qt.qml.qml")) - return ProjectExplorer::FileType::QML; - return ProjectExplorer::FileType::Unknown; + if (fileTags.contains("hpp")) + return FileType::Header; + if (fileTags.contains("qrc")) + return FileType::Resource; + if (fileTags.contains("ui")) + return FileType::Form; + if (fileTags.contains("scxml")) + return FileType::StateChart; + if (fileTags.contains("qt.qml.qml")) + return FileType::QML; + return FileType::Unknown; } -void setupArtifacts(ProjectExplorer::FolderNode *root, const QList &artifacts) +void setupArtifacts(FolderNode *root, const QList &artifacts) { for (const qbs::ArtifactData &ad : artifacts) { - const Utils::FileName path = Utils::FileName::fromString(ad.filePath()); - const ProjectExplorer::FileType type = fileType(ad); + const FileName path = FileName::fromString(ad.filePath()); + const FileType type = fileType(ad); const bool isGenerated = ad.isGenerated(); // A list of human-readable file types that we can reasonably expect @@ -73,7 +80,7 @@ void setupArtifacts(ProjectExplorer::FolderNode *root, const QList(path, type); + auto node = std::make_unique(path, type); node->setIsGenerated(isGenerated); node->setListInProject(!isGenerated || ad.fileTags().toSet().intersects(sourceTags)); root->addNestedNode(std::move(node)); @@ -81,41 +88,38 @@ void setupArtifacts(ProjectExplorer::FolderNode *root, const QListcompress(); } -std::unique_ptr +std::unique_ptr buildGroupNodeTree(const qbs::GroupData &grp, const QString &productPath, bool productIsEnabled) { QTC_ASSERT(grp.isValid(), return nullptr); - auto result = std::make_unique(grp, productPath); + auto result = std::make_unique(grp, productPath); result->setEnabled(productIsEnabled && grp.isEnabled()); result->setAbsoluteFilePathAndLine( - Utils::FileName::fromString(grp.location().filePath()).parentDir(), -1); + FileName::fromString(grp.location().filePath()).parentDir(), -1); result->setDisplayName(grp.name()); - result->addNode(std::make_unique( - Utils::FileName::fromString(grp.location().filePath()), - ProjectExplorer::FileType::Project, + result->addNode(std::make_unique( + FileName::fromString(grp.location().filePath()), + FileType::Project, grp.location().line())); - ::setupArtifacts(result.get(), grp.allSourceArtifacts()); + setupArtifacts(result.get(), grp.allSourceArtifacts()); return result; } -void setupQbsProductData(QbsProjectManager::Internal::QbsProductNode *node, - const qbs::ProductData &prd) +void setupQbsProductData(QbsProductNode *node, const qbs::ProductData &prd) { - using namespace QbsProjectManager::Internal; - node->setEnabled(prd.isEnabled()); node->setDisplayName(prd.fullDisplayName()); - node->setAbsoluteFilePathAndLine(Utils::FileName::fromString(prd.location().filePath()).parentDir(), -1); + node->setAbsoluteFilePathAndLine(FileName::fromString(prd.location().filePath()).parentDir(), -1); const QString &productPath = QFileInfo(prd.location().filePath()).absolutePath(); // Add QbsFileNode: - node->addNode(std::make_unique(Utils::FileName::fromString(prd.location().filePath()), - ProjectExplorer::FileType::Project, + node->addNode(std::make_unique(FileName::fromString(prd.location().filePath()), + FileType::Project, prd.location().line())); @@ -129,33 +133,30 @@ void setupQbsProductData(QbsProjectManager::Internal::QbsProductNode *node, } // Add "Generated Files" Node: - auto genFiles = std::make_unique(node->filePath()); - genFiles->setPriority(ProjectExplorer::Node::DefaultProjectFilePriority - 10); + auto genFiles = std::make_unique(node->filePath()); + genFiles->setPriority(Node::DefaultProjectFilePriority - 10); genFiles->setDisplayName(QCoreApplication::translate("QbsProductNode", "Generated files")); setupArtifacts(genFiles.get(), prd.generatedArtifacts()); node->addNode(std::move(genFiles)); } -std::unique_ptr -buildProductNodeTree(const qbs::ProductData &prd) +std::unique_ptr buildProductNodeTree(const qbs::ProductData &prd) { - auto result = std::make_unique(prd); + auto result = std::make_unique(prd); setupQbsProductData(result.get(), prd); return result; } -void setupProjectNode(QbsProjectManager::Internal::QbsProjectNode *node, const qbs::ProjectData &prjData, +void setupProjectNode(QbsProjectNode *node, const qbs::ProjectData &prjData, const qbs::Project &qbsProject) { - using namespace QbsProjectManager::Internal; - node->addNode(std::make_unique(Utils::FileName::fromString(prjData.location().filePath()), - ProjectExplorer::FileType::Project, + node->addNode(std::make_unique(FileName::fromString(prjData.location().filePath()), + FileType::Project, prjData.location().line())); foreach (const qbs::ProjectData &subData, prjData.subProjects()) { - auto subProject = - std::make_unique( - Utils::FileName::fromString(subData.location().filePath()).parentDir()); + auto subProject = std::make_unique( + FileName::fromString(subData.location().filePath()).parentDir()); setupProjectNode(subProject.get(), subData, qbsProject); node->addNode(std::move(subProject)); } @@ -202,9 +203,6 @@ QStringList unreferencedBuildSystemFiles(const qbs::Project &p) } // namespace -namespace QbsProjectManager { -namespace Internal { - std::unique_ptr QbsNodeTreeBuilder::buildTree(QbsProject *project) { if (!project->qbsProjectData().isValid()) @@ -212,16 +210,16 @@ std::unique_ptr QbsNodeTreeBuilder::buildTree(QbsProject *pr auto root = std::make_unique(project); setupProjectNode(root.get(), project->qbsProjectData(), project->qbsProject()); - auto buildSystemFiles - = std::make_unique(project->projectDirectory()); + + auto buildSystemFiles = std::make_unique(project->projectDirectory()); buildSystemFiles->setDisplayName(QCoreApplication::translate("QbsRootProjectNode", "Qbs files")); - Utils::FileName base = project->projectDirectory(); - const QStringList &files = unreferencedBuildSystemFiles(project->qbsProject()); + const FileName base = project->projectDirectory(); + const QStringList files = unreferencedBuildSystemFiles(project->qbsProject()); for (const QString &f : files) { - const Utils::FileName filePath = Utils::FileName::fromString(f); + const FileName filePath = FileName::fromString(f); if (filePath.isChildOf(base)) - buildSystemFiles->addNestedNode(std::make_unique(filePath, ProjectExplorer::FileType::Project)); + buildSystemFiles->addNestedNode(std::make_unique(filePath, FileType::Project)); } buildSystemFiles->compress(); root->addNode(std::move(buildSystemFiles));