Commit 8cb57c73 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Qbs: Move setup code for QbsProjectNodes into QbsNodeTreeBuilder



Change-Id: Ice5b445db916648bb8fb0d0f31bafe1d53e11182
Reviewed-by: Christian Kandeler's avatarChristian Kandeler <christian.kandeler@qt.io>
parent 5ed7728d
......@@ -584,14 +584,13 @@ QbsGroupNode *QbsProductNode::findGroupNode(const QString &name)
// QbsProjectNode:
// --------------------------------------------------------------------
QbsProjectNode::QbsProjectNode(const Utils::FileName &path) :
QbsBaseProjectNode(path)
QbsProjectNode::QbsProjectNode(const Utils::FileName &projectDirectory) :
QbsBaseProjectNode(projectDirectory)
{
if (m_projectIcon.isNull())
m_projectIcon = generateIcon(QString::fromLatin1(ProjectExplorer::Constants::FILEOVERLAY_QT));
setIcon(m_projectIcon);
addNode(new ProjectExplorer::FileNode(filePath(), ProjectExplorer::FileType::Project, false));
}
QbsProjectNode::~QbsProjectNode()
......@@ -599,26 +598,6 @@ QbsProjectNode::~QbsProjectNode()
// do not delete m_project
}
void QbsProjectNode::update(const qbs::Project &qbsProject, const qbs::ProjectData &prjData)
{
foreach (const qbs::ProjectData &subData, prjData.subProjects()) {
auto subProject =
new QbsProjectNode(Utils::FileName::fromString(subData.location().filePath()));
subProject->update(qbsProject, subData);
addNode(subProject);
}
foreach (const qbs::ProductData &prd, prjData.products())
addNode(QbsNodeTreeBuilder::buildProductNodeTree(qbsProject, prd));
if (!prjData.name().isEmpty())
setDisplayName(prjData.name());
else
setDisplayName(project()->displayName());
m_projectData = prjData;
}
QbsProject *QbsProjectNode::project() const
{
return static_cast<QbsProjectNode *>(parentFolderNode())->project();
......@@ -634,12 +613,17 @@ bool QbsProjectNode::showInSimpleTree() const
return true;
}
void QbsProjectNode::setProjectData(const qbs::ProjectData &data)
{
m_projectData = data;
}
// --------------------------------------------------------------------
// QbsRootProjectNode:
// --------------------------------------------------------------------
QbsRootProjectNode::QbsRootProjectNode(QbsProject *project) :
QbsProjectNode(project->projectFilePath()),
QbsProjectNode(project->projectDirectory()),
m_project(project),
m_buildSystemFiles(new ProjectExplorer::FolderNode(project->projectDirectory(),
ProjectExplorer::NodeType::Folder,
......@@ -661,7 +645,7 @@ void QbsRootProjectNode::update()
QbsGroupNode::setupFiles(m_buildSystemFiles, qbs::GroupData(), projectBuildSystemFiles,
base.toString(), false);
update(m_project->qbsProject(), m_project->qbsProjectData());
QbsNodeTreeBuilder::setupProjectNode(this, m_project->qbsProjectData(), m_project->qbsProject());
}
static QSet<QString> referencedBuildSystemFiles(const qbs::ProjectData &data)
......
......@@ -35,6 +35,7 @@ namespace QbsProjectManager {
namespace Internal {
class FileTreeNode;
class QbsNodeTreeBuilder;
class QbsProject;
class QbsProjectFile;
......@@ -150,7 +151,7 @@ private:
class QbsProjectNode : public QbsBaseProjectNode
{
public:
explicit QbsProjectNode(const Utils::FileName &absoluteFilePath);
explicit QbsProjectNode(const Utils::FileName &projectDirectory);
~QbsProjectNode() override;
virtual QbsProject *project() const;
......@@ -159,12 +160,13 @@ public:
bool showInSimpleTree() const override;
protected:
void update(const qbs::Project &qbsProject, const qbs::ProjectData &prjData);
private:
void setProjectData(const qbs::ProjectData &data);
static QIcon m_projectIcon;
qbs::ProjectData m_projectData;
friend class QbsNodeTreeBuilder;
};
// --------------------------------------------------------------------
......@@ -176,7 +178,6 @@ class QbsRootProjectNode : public QbsProjectNode
public:
explicit QbsRootProjectNode(QbsProject *project);
using QbsProjectNode::update;
void update();
QbsProject *project() const override { return m_project; }
......
......@@ -104,6 +104,15 @@ void setupQbsProductData(QbsProjectManager::Internal::QbsProductNode *node,
setupArtifacts(genFiles, prd.generatedArtifacts());
}
QbsProjectManager::Internal::QbsProductNode *
buildProductNodeTree(const qbs::Project &project, const qbs::ProductData &prd)
{
auto result = new QbsProjectManager::Internal::QbsProductNode(prd);
setupQbsProductData(result, prd, project);
return result;
}
} // namespace
namespace QbsProjectManager {
......@@ -130,14 +139,38 @@ ProjectExplorer::FileType QbsNodeTreeBuilder::fileType(const qbs::ArtifactData &
return ProjectExplorer::FileType::Unknown;
}
QbsProductNode *QbsNodeTreeBuilder::buildProductNodeTree(const qbs::Project &project,
const qbs::ProductData &prd)
QbsProjectNode *QbsNodeTreeBuilder::buildProjectNodeTree(const qbs::Project &qbsProject,
const qbs::ProjectData &prjData)
{
auto result = new QbsProductNode(prd);
Utils::FileName filePath = Utils::FileName::fromString(prjData.location().filePath());
auto result = new QbsProjectNode(filePath.parentDir());
result->setProjectData(prjData);
result->addNode(new ProjectExplorer::FileNode(filePath, ProjectExplorer::FileType::Project, false));
setupProjectNode(result, prjData, qbsProject);
setupQbsProductData(result, prd, project);
return result;
}
void QbsNodeTreeBuilder::setupProjectNode(QbsProjectNode *node, const qbs::ProjectData &prjData,
const qbs::Project &qbsProject)
{
foreach (const qbs::ProjectData &subData, prjData.subProjects()) {
auto subProject =
new QbsProjectNode(Utils::FileName::fromString(subData.location().filePath()).parentDir());
setupProjectNode(subProject, subData, qbsProject);
node->addNode(subProject);
}
foreach (const qbs::ProductData &prd, prjData.products())
node->addNode(buildProductNodeTree(qbsProject, prd));
if (!prjData.name().isEmpty())
node->setDisplayName(prjData.name());
else
node->setDisplayName(node->project()->displayName());
}
} // namespace Internal
} // namespace QbsProjectManager
......@@ -41,9 +41,10 @@ class QbsNodeTreeBuilder
public:
static ProjectExplorer::FileType fileType(const qbs::ArtifactData &artifact);
static QbsGroupNode *buildGroupNodeTree(const qbs::GroupData &grp, const QString &productPath,
bool productIsEnabled);
static QbsProductNode *buildProductNodeTree(const qbs::Project &project, const qbs::ProductData &prd);
static QbsProjectNode *buildProjectNodeTree(const qbs::Project &qbsProject,
const qbs::ProjectData &prjData);
static void setupProjectNode(QbsProjectNode *node, const qbs::ProjectData &prjData, const qbs::Project &qbsProject);
};
} // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment