forked from qt-creator/qt-creator
Qbs: Move ProductNode setup into QbsNodeTreeBuilder
Move closer to a setup where the project tree API can change. This patch also makes sure "Generated files" will be below the product file of each product and above any Groups/folders/files. Change-Id: I728289372d40b809105f55adbe50fd424b19e0a0 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -482,23 +482,13 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
|
||||
// QbsProductNode:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
QbsProductNode::QbsProductNode(const qbs::Project &project, const qbs::ProductData &prd) :
|
||||
QbsBaseProjectNode(Utils::FileName::fromString(prd.location().filePath())),
|
||||
m_generatedFilesNode(new QbsFolderNode(Utils::FileName::fromString(prd.buildDirectory()),
|
||||
ProjectExplorer::NodeType::Folder,
|
||||
QCoreApplication::translate("QbsProductNode", "Generated files"), true))
|
||||
QbsProductNode::QbsProductNode(const qbs::ProductData &prd) :
|
||||
QbsBaseProjectNode(Utils::FileName::fromString(prd.location().filePath()))
|
||||
{
|
||||
if (m_productIcon.isNull())
|
||||
m_productIcon = generateIcon(QString::fromLatin1(Constants::QBS_PRODUCT_OVERLAY_ICON));
|
||||
|
||||
setIcon(m_productIcon);
|
||||
|
||||
addNode(m_generatedFilesNode);
|
||||
addNode(new QbsFileNode(Utils::FileName::fromString(prd.location().filePath()),
|
||||
ProjectExplorer::FileType::Project, false,
|
||||
prd.location().line()));
|
||||
|
||||
setQbsProductData(project, prd);
|
||||
}
|
||||
|
||||
bool QbsProductNode::showInSimpleTree() const
|
||||
@@ -562,44 +552,6 @@ bool QbsProductNode::renameFile(const QString &filePath, const QString &newFileP
|
||||
return prjNode->project()->renameFileInProduct(filePath, newFilePath, m_qbsProductData, grp);
|
||||
}
|
||||
|
||||
void QbsProductNode::setQbsProductData(const qbs::Project &project, const qbs::ProductData prd)
|
||||
{
|
||||
if (m_qbsProductData == prd)
|
||||
return;
|
||||
|
||||
setEnabled(prd.isEnabled());
|
||||
|
||||
setDisplayName(QbsProject::productDisplayName(project, prd));
|
||||
setAbsoluteFilePathAndLine(Utils::FileName::fromString(prd.location().filePath()).parentDir(),
|
||||
line());
|
||||
const QString &productPath = QFileInfo(prd.location().filePath()).absolutePath();
|
||||
|
||||
// Find the QbsFileNode we added earlier:
|
||||
QbsFileNode *idx = 0;
|
||||
foreach (ProjectExplorer::FileNode *fn, fileNodes()) {
|
||||
idx = dynamic_cast<QbsFileNode *>(fn);
|
||||
if (idx)
|
||||
break;
|
||||
}
|
||||
QTC_ASSERT(idx, return);
|
||||
idx->setAbsoluteFilePathAndLine(Utils::FileName::fromString(prd.location().filePath()),
|
||||
prd.location().line());
|
||||
|
||||
foreach (const qbs::GroupData &grp, prd.groups()) {
|
||||
if (grp.name() == prd.name() && grp.location() == prd.location()) {
|
||||
// Set implicit product group right onto this node:
|
||||
QbsNodeTreeBuilder::setupArtifacts(this, grp.allSourceArtifacts());
|
||||
continue;
|
||||
}
|
||||
addNode(QbsNodeTreeBuilder::buildGroupNodeTree(grp, productPath, prd.isEnabled()));
|
||||
}
|
||||
|
||||
if (prd.isEnabled())
|
||||
QbsNodeTreeBuilder::setupArtifacts(this, prd.generatedArtifacts());
|
||||
|
||||
m_qbsProductData = prd;
|
||||
}
|
||||
|
||||
QList<ProjectExplorer::RunConfiguration *> QbsProductNode::runConfigurations() const
|
||||
{
|
||||
QList<ProjectExplorer::RunConfiguration *> result;
|
||||
@@ -653,7 +605,7 @@ void QbsProjectNode::update(const qbs::Project &qbsProject, const qbs::ProjectDa
|
||||
}
|
||||
|
||||
foreach (const qbs::ProductData &prd, prjData.products())
|
||||
addNode(new QbsProductNode(qbsProject, prd));
|
||||
addNode(QbsNodeTreeBuilder::buildProductNodeTree(qbsProject, prd));
|
||||
|
||||
if (!prjData.name().isEmpty())
|
||||
setDisplayName(prjData.name());
|
||||
@@ -687,26 +639,6 @@ void QbsProjectNode::ctor()
|
||||
addNode(new ProjectExplorer::FileNode(filePath(), ProjectExplorer::FileType::Project, false));
|
||||
}
|
||||
|
||||
QbsProductNode *QbsProjectNode::findProductNode(const QString &uniqueName)
|
||||
{
|
||||
for (ProjectExplorer::Node *n : nodes()) {
|
||||
if (QbsProductNode *qn = dynamic_cast<QbsProductNode *>(n))
|
||||
if (QbsProject::uniqueProductName(qn->qbsProductData()) == uniqueName)
|
||||
return qn;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QbsProjectNode *QbsProjectNode::findProjectNode(const QString &name)
|
||||
{
|
||||
for (ProjectExplorer::Node *n : nodes()) {
|
||||
if (QbsProjectNode *qn = dynamic_cast<QbsProjectNode *>(n))
|
||||
if (qn->qbsProjectData().name() == name)
|
||||
return qn;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// QbsRootProjectNode:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
@@ -124,7 +124,7 @@ private:
|
||||
class QbsProductNode : public QbsBaseProjectNode
|
||||
{
|
||||
public:
|
||||
explicit QbsProductNode(const qbs::Project &project, const qbs::ProductData &prd);
|
||||
explicit QbsProductNode(const qbs::ProductData &prd);
|
||||
|
||||
bool showInSimpleTree() const override;
|
||||
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
|
||||
@@ -132,7 +132,6 @@ public:
|
||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
|
||||
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||
|
||||
void setQbsProductData(const qbs::Project &project, const qbs::ProductData prd);
|
||||
const qbs::ProductData qbsProductData() const { return m_qbsProductData; }
|
||||
|
||||
QList<ProjectExplorer::RunConfiguration *> runConfigurations() const override;
|
||||
@@ -141,7 +140,6 @@ private:
|
||||
QbsGroupNode *findGroupNode(const QString &name);
|
||||
|
||||
qbs::ProductData m_qbsProductData;
|
||||
ProjectExplorer::FolderNode * const m_generatedFilesNode;
|
||||
static QIcon m_productIcon;
|
||||
};
|
||||
|
||||
@@ -167,9 +165,6 @@ protected:
|
||||
private:
|
||||
void ctor();
|
||||
|
||||
QbsProductNode *findProductNode(const QString &uniqueName);
|
||||
QbsProjectNode *findProjectNode(const QString &name);
|
||||
|
||||
static QIcon m_projectIcon;
|
||||
qbs::ProjectData m_projectData;
|
||||
};
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "qbsnodetreebuilder.h"
|
||||
|
||||
#include "qbsproject.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -45,6 +47,63 @@ void setupArtifacts(ProjectExplorer::FolderNode *root, const QList<qbs::Artifact
|
||||
root->compress();
|
||||
}
|
||||
|
||||
QbsProjectManager::Internal::QbsGroupNode
|
||||
*buildGroupNodeTree(const qbs::GroupData &grp, const QString &productPath, bool productIsEnabled)
|
||||
{
|
||||
QTC_ASSERT(grp.isValid(), return nullptr);
|
||||
|
||||
auto result = new QbsProjectManager::Internal::QbsGroupNode(grp, productPath);
|
||||
|
||||
result->setEnabled(productIsEnabled && grp.isEnabled());
|
||||
result->setAbsoluteFilePathAndLine(
|
||||
Utils::FileName::fromString(grp.location().filePath()).parentDir(), -1);
|
||||
result->setDisplayName(grp.name());
|
||||
result->addNode(new QbsProjectManager::Internal::QbsFileNode(
|
||||
Utils::FileName::fromString(grp.location().filePath()),
|
||||
ProjectExplorer::FileType::Project, false,
|
||||
grp.location().line()));
|
||||
|
||||
::setupArtifacts(result, grp.allSourceArtifacts());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void setupQbsProductData(QbsProjectManager::Internal::QbsProductNode *node,
|
||||
const qbs::ProductData &prd, const qbs::Project &project)
|
||||
{
|
||||
using namespace QbsProjectManager::Internal;
|
||||
node->makeEmpty();
|
||||
|
||||
node->setEnabled(prd.isEnabled());
|
||||
|
||||
node->setDisplayName(QbsProject::productDisplayName(project, prd));
|
||||
node->setAbsoluteFilePathAndLine(Utils::FileName::fromString(prd.location().filePath()).parentDir(), -1);
|
||||
const QString &productPath = QFileInfo(prd.location().filePath()).absolutePath();
|
||||
|
||||
// Add QbsFileNode:
|
||||
node->addNode(new QbsFileNode(Utils::FileName::fromString(prd.location().filePath()),
|
||||
ProjectExplorer::FileType::Project, false,
|
||||
prd.location().line()));
|
||||
|
||||
|
||||
foreach (const qbs::GroupData &grp, prd.groups()) {
|
||||
if (grp.name() == prd.name() && grp.location() == prd.location()) {
|
||||
// Set implicit product group right onto this node:
|
||||
setupArtifacts(node, grp.allSourceArtifacts());
|
||||
continue;
|
||||
}
|
||||
node->addNode(buildGroupNodeTree(grp, productPath, prd.isEnabled()));
|
||||
}
|
||||
|
||||
// Add "Generated Files" Node:
|
||||
auto genFiles
|
||||
= new ProjectExplorer::VirtualFolderNode(node->filePath(),
|
||||
ProjectExplorer::Node::DefaultProjectFilePriority - 10);
|
||||
genFiles->setDisplayName(QCoreApplication::translate("QbsProductNode", "Generated files"));
|
||||
node->addNode(genFiles);
|
||||
setupArtifacts(genFiles, prd.generatedArtifacts());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace QbsProjectManager {
|
||||
@@ -71,31 +130,14 @@ ProjectExplorer::FileType QbsNodeTreeBuilder::fileType(const qbs::ArtifactData &
|
||||
return ProjectExplorer::FileType::Unknown;
|
||||
}
|
||||
|
||||
QbsGroupNode *QbsNodeTreeBuilder::buildGroupNodeTree(const qbs::GroupData &grp,
|
||||
const QString &productPath,
|
||||
bool productIsEnabled)
|
||||
QbsProductNode *QbsNodeTreeBuilder::buildProductNodeTree(const qbs::Project &project,
|
||||
const qbs::ProductData &prd)
|
||||
{
|
||||
QTC_ASSERT(grp.isValid(), return nullptr);
|
||||
|
||||
auto result = new QbsGroupNode(grp, productPath);
|
||||
|
||||
result->setEnabled(productIsEnabled && grp.isEnabled());
|
||||
result->setAbsoluteFilePathAndLine(
|
||||
Utils::FileName::fromString(grp.location().filePath()).parentDir(), -1);
|
||||
result->setDisplayName(grp.name());
|
||||
result->addNode(new QbsFileNode(Utils::FileName::fromString(grp.location().filePath()),
|
||||
ProjectExplorer::FileType::Project, false,
|
||||
grp.location().line()));
|
||||
|
||||
::setupArtifacts(result, grp.allSourceArtifacts());
|
||||
auto result = new QbsProductNode(prd);
|
||||
|
||||
setupQbsProductData(result, prd, project);
|
||||
return result;
|
||||
}
|
||||
|
||||
void QbsNodeTreeBuilder::setupArtifacts(QbsBaseProjectNode *node, const QList<qbs::ArtifactData> &artifacts)
|
||||
{
|
||||
::setupArtifacts(node, artifacts);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QbsProjectManager
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
static QbsGroupNode *buildGroupNodeTree(const qbs::GroupData &grp, const QString &productPath,
|
||||
bool productIsEnabled);
|
||||
static void setupArtifacts(QbsBaseProjectNode *node, const QList<qbs::ArtifactData> &artifacts);
|
||||
static QbsProductNode *buildProductNodeTree(const qbs::Project &project, const qbs::ProductData &prd);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user