forked from qt-creator/qt-creator
Qbs: Some code cosmetics
Mostly namespaces, whitespace, avoidance of repetitive code. Change-Id: I49185464b6e7baadeb519799f06c7f50e8039366 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -30,36 +30,43 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
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")
|
const QStringList fileTags = artifact.fileTags();
|
||||||
|| artifact.fileTags().contains("cpp")
|
if (fileTags.contains("c")
|
||||||
|| artifact.fileTags().contains("objc")
|
|| fileTags.contains("cpp")
|
||||||
|| artifact.fileTags().contains("objcpp")) {
|
|| fileTags.contains("objc")
|
||||||
return ProjectExplorer::FileType::Source;
|
|| fileTags.contains("objcpp")) {
|
||||||
|
return FileType::Source;
|
||||||
}
|
}
|
||||||
if (artifact.fileTags().contains("hpp"))
|
if (fileTags.contains("hpp"))
|
||||||
return ProjectExplorer::FileType::Header;
|
return FileType::Header;
|
||||||
if (artifact.fileTags().contains("qrc"))
|
if (fileTags.contains("qrc"))
|
||||||
return ProjectExplorer::FileType::Resource;
|
return FileType::Resource;
|
||||||
if (artifact.fileTags().contains("ui"))
|
if (fileTags.contains("ui"))
|
||||||
return ProjectExplorer::FileType::Form;
|
return FileType::Form;
|
||||||
if (artifact.fileTags().contains("scxml"))
|
if (fileTags.contains("scxml"))
|
||||||
return ProjectExplorer::FileType::StateChart;
|
return FileType::StateChart;
|
||||||
if (artifact.fileTags().contains("qt.qml.qml"))
|
if (fileTags.contains("qt.qml.qml"))
|
||||||
return ProjectExplorer::FileType::QML;
|
return FileType::QML;
|
||||||
return ProjectExplorer::FileType::Unknown;
|
return FileType::Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupArtifacts(ProjectExplorer::FolderNode *root, const QList<qbs::ArtifactData> &artifacts)
|
void setupArtifacts(FolderNode *root, const QList<qbs::ArtifactData> &artifacts)
|
||||||
{
|
{
|
||||||
for (const qbs::ArtifactData &ad : artifacts) {
|
for (const qbs::ArtifactData &ad : artifacts) {
|
||||||
const Utils::FileName path = Utils::FileName::fromString(ad.filePath());
|
const FileName path = FileName::fromString(ad.filePath());
|
||||||
const ProjectExplorer::FileType type = fileType(ad);
|
const FileType type = fileType(ad);
|
||||||
const bool isGenerated = ad.isGenerated();
|
const bool isGenerated = ad.isGenerated();
|
||||||
|
|
||||||
// A list of human-readable file types that we can reasonably expect
|
// A list of human-readable file types that we can reasonably expect
|
||||||
@@ -73,7 +80,7 @@ void setupArtifacts(ProjectExplorer::FolderNode *root, const QList<qbs::Artifact
|
|||||||
QLatin1String("linkerscript"),
|
QLatin1String("linkerscript"),
|
||||||
QLatin1String("qrc"), QLatin1String("java.java")
|
QLatin1String("qrc"), QLatin1String("java.java")
|
||||||
};
|
};
|
||||||
auto node = std::make_unique<ProjectExplorer::FileNode>(path, type);
|
auto node = std::make_unique<FileNode>(path, type);
|
||||||
node->setIsGenerated(isGenerated);
|
node->setIsGenerated(isGenerated);
|
||||||
node->setListInProject(!isGenerated || ad.fileTags().toSet().intersects(sourceTags));
|
node->setListInProject(!isGenerated || ad.fileTags().toSet().intersects(sourceTags));
|
||||||
root->addNestedNode(std::move(node));
|
root->addNestedNode(std::move(node));
|
||||||
@@ -81,41 +88,38 @@ void setupArtifacts(ProjectExplorer::FolderNode *root, const QList<qbs::Artifact
|
|||||||
root->compress();
|
root->compress();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<QbsProjectManager::Internal::QbsGroupNode>
|
std::unique_ptr<QbsGroupNode>
|
||||||
buildGroupNodeTree(const qbs::GroupData &grp, const QString &productPath, bool productIsEnabled)
|
buildGroupNodeTree(const qbs::GroupData &grp, const QString &productPath, bool productIsEnabled)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(grp.isValid(), return nullptr);
|
QTC_ASSERT(grp.isValid(), return nullptr);
|
||||||
|
|
||||||
auto result = std::make_unique<QbsProjectManager::Internal::QbsGroupNode>(grp, productPath);
|
auto result = std::make_unique<QbsGroupNode>(grp, productPath);
|
||||||
|
|
||||||
result->setEnabled(productIsEnabled && grp.isEnabled());
|
result->setEnabled(productIsEnabled && grp.isEnabled());
|
||||||
result->setAbsoluteFilePathAndLine(
|
result->setAbsoluteFilePathAndLine(
|
||||||
Utils::FileName::fromString(grp.location().filePath()).parentDir(), -1);
|
FileName::fromString(grp.location().filePath()).parentDir(), -1);
|
||||||
result->setDisplayName(grp.name());
|
result->setDisplayName(grp.name());
|
||||||
result->addNode(std::make_unique<QbsProjectManager::Internal::QbsFileNode>(
|
result->addNode(std::make_unique<QbsFileNode>(
|
||||||
Utils::FileName::fromString(grp.location().filePath()),
|
FileName::fromString(grp.location().filePath()),
|
||||||
ProjectExplorer::FileType::Project,
|
FileType::Project,
|
||||||
grp.location().line()));
|
grp.location().line()));
|
||||||
|
|
||||||
::setupArtifacts(result.get(), grp.allSourceArtifacts());
|
setupArtifacts(result.get(), grp.allSourceArtifacts());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupQbsProductData(QbsProjectManager::Internal::QbsProductNode *node,
|
void setupQbsProductData(QbsProductNode *node, const qbs::ProductData &prd)
|
||||||
const qbs::ProductData &prd)
|
|
||||||
{
|
{
|
||||||
using namespace QbsProjectManager::Internal;
|
|
||||||
|
|
||||||
node->setEnabled(prd.isEnabled());
|
node->setEnabled(prd.isEnabled());
|
||||||
|
|
||||||
node->setDisplayName(prd.fullDisplayName());
|
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();
|
const QString &productPath = QFileInfo(prd.location().filePath()).absolutePath();
|
||||||
|
|
||||||
// Add QbsFileNode:
|
// Add QbsFileNode:
|
||||||
node->addNode(std::make_unique<QbsFileNode>(Utils::FileName::fromString(prd.location().filePath()),
|
node->addNode(std::make_unique<QbsFileNode>(FileName::fromString(prd.location().filePath()),
|
||||||
ProjectExplorer::FileType::Project,
|
FileType::Project,
|
||||||
prd.location().line()));
|
prd.location().line()));
|
||||||
|
|
||||||
|
|
||||||
@@ -129,33 +133,30 @@ void setupQbsProductData(QbsProjectManager::Internal::QbsProductNode *node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add "Generated Files" Node:
|
// Add "Generated Files" Node:
|
||||||
auto genFiles = std::make_unique<ProjectExplorer::VirtualFolderNode>(node->filePath());
|
auto genFiles = std::make_unique<VirtualFolderNode>(node->filePath());
|
||||||
genFiles->setPriority(ProjectExplorer::Node::DefaultProjectFilePriority - 10);
|
genFiles->setPriority(Node::DefaultProjectFilePriority - 10);
|
||||||
genFiles->setDisplayName(QCoreApplication::translate("QbsProductNode", "Generated files"));
|
genFiles->setDisplayName(QCoreApplication::translate("QbsProductNode", "Generated files"));
|
||||||
setupArtifacts(genFiles.get(), prd.generatedArtifacts());
|
setupArtifacts(genFiles.get(), prd.generatedArtifacts());
|
||||||
node->addNode(std::move(genFiles));
|
node->addNode(std::move(genFiles));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<QbsProjectManager::Internal::QbsProductNode>
|
std::unique_ptr<QbsProductNode> buildProductNodeTree(const qbs::ProductData &prd)
|
||||||
buildProductNodeTree(const qbs::ProductData &prd)
|
|
||||||
{
|
{
|
||||||
auto result = std::make_unique<QbsProjectManager::Internal::QbsProductNode>(prd);
|
auto result = std::make_unique<QbsProductNode>(prd);
|
||||||
|
|
||||||
setupQbsProductData(result.get(), prd);
|
setupQbsProductData(result.get(), prd);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupProjectNode(QbsProjectManager::Internal::QbsProjectNode *node, const qbs::ProjectData &prjData,
|
void setupProjectNode(QbsProjectNode *node, const qbs::ProjectData &prjData,
|
||||||
const qbs::Project &qbsProject)
|
const qbs::Project &qbsProject)
|
||||||
{
|
{
|
||||||
using namespace QbsProjectManager::Internal;
|
node->addNode(std::make_unique<QbsFileNode>(FileName::fromString(prjData.location().filePath()),
|
||||||
node->addNode(std::make_unique<QbsFileNode>(Utils::FileName::fromString(prjData.location().filePath()),
|
FileType::Project,
|
||||||
ProjectExplorer::FileType::Project,
|
|
||||||
prjData.location().line()));
|
prjData.location().line()));
|
||||||
foreach (const qbs::ProjectData &subData, prjData.subProjects()) {
|
foreach (const qbs::ProjectData &subData, prjData.subProjects()) {
|
||||||
auto subProject =
|
auto subProject = std::make_unique<QbsProjectNode>(
|
||||||
std::make_unique<QbsProjectManager::Internal::QbsProjectNode>(
|
FileName::fromString(subData.location().filePath()).parentDir());
|
||||||
Utils::FileName::fromString(subData.location().filePath()).parentDir());
|
|
||||||
setupProjectNode(subProject.get(), subData, qbsProject);
|
setupProjectNode(subProject.get(), subData, qbsProject);
|
||||||
node->addNode(std::move(subProject));
|
node->addNode(std::move(subProject));
|
||||||
}
|
}
|
||||||
@@ -202,9 +203,6 @@ QStringList unreferencedBuildSystemFiles(const qbs::Project &p)
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace QbsProjectManager {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
std::unique_ptr<QbsRootProjectNode> QbsNodeTreeBuilder::buildTree(QbsProject *project)
|
std::unique_ptr<QbsRootProjectNode> QbsNodeTreeBuilder::buildTree(QbsProject *project)
|
||||||
{
|
{
|
||||||
if (!project->qbsProjectData().isValid())
|
if (!project->qbsProjectData().isValid())
|
||||||
@@ -212,16 +210,16 @@ std::unique_ptr<QbsRootProjectNode> QbsNodeTreeBuilder::buildTree(QbsProject *pr
|
|||||||
|
|
||||||
auto root = std::make_unique<QbsRootProjectNode>(project);
|
auto root = std::make_unique<QbsRootProjectNode>(project);
|
||||||
setupProjectNode(root.get(), project->qbsProjectData(), project->qbsProject());
|
setupProjectNode(root.get(), project->qbsProjectData(), project->qbsProject());
|
||||||
auto buildSystemFiles
|
|
||||||
= std::make_unique<ProjectExplorer::FolderNode>(project->projectDirectory());
|
auto buildSystemFiles = std::make_unique<FolderNode>(project->projectDirectory());
|
||||||
buildSystemFiles->setDisplayName(QCoreApplication::translate("QbsRootProjectNode", "Qbs files"));
|
buildSystemFiles->setDisplayName(QCoreApplication::translate("QbsRootProjectNode", "Qbs files"));
|
||||||
|
|
||||||
Utils::FileName base = project->projectDirectory();
|
const FileName base = project->projectDirectory();
|
||||||
const QStringList &files = unreferencedBuildSystemFiles(project->qbsProject());
|
const QStringList files = unreferencedBuildSystemFiles(project->qbsProject());
|
||||||
for (const QString &f : files) {
|
for (const QString &f : files) {
|
||||||
const Utils::FileName filePath = Utils::FileName::fromString(f);
|
const FileName filePath = FileName::fromString(f);
|
||||||
if (filePath.isChildOf(base))
|
if (filePath.isChildOf(base))
|
||||||
buildSystemFiles->addNestedNode(std::make_unique<ProjectExplorer::FileNode>(filePath, ProjectExplorer::FileType::Project));
|
buildSystemFiles->addNestedNode(std::make_unique<FileNode>(filePath, FileType::Project));
|
||||||
}
|
}
|
||||||
buildSystemFiles->compress();
|
buildSystemFiles->compress();
|
||||||
root->addNode(std::move(buildSystemFiles));
|
root->addNode(std::move(buildSystemFiles));
|
||||||
|
Reference in New Issue
Block a user