forked from qt-creator/qt-creator
qbs: Move setup of Group node tree into QbsNodeTreeBuilder
Move code to set up the tree of project nodes out of the project nodes themselves. This makes them easier to manage and will enable creator to change to a less update-intense project tree. Change-Id: I2d0702d257e87543f47ebfb456344423ebe4f871 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "qbsnodes.h"
|
#include "qbsnodes.h"
|
||||||
|
|
||||||
|
#include "qbsnodetreebuilder.h"
|
||||||
#include "qbsproject.h"
|
#include "qbsproject.h"
|
||||||
#include "qbsprojectmanagerconstants.h"
|
#include "qbsprojectmanagerconstants.h"
|
||||||
#include "qbsrunconfiguration.h"
|
#include "qbsrunconfiguration.h"
|
||||||
@@ -322,11 +323,8 @@ QbsGroupNode::QbsGroupNode(const qbs::GroupData &grp, const QString &productPath
|
|||||||
|
|
||||||
setIcon(m_groupIcon);
|
setIcon(m_groupIcon);
|
||||||
|
|
||||||
addNode(new QbsFileNode(Utils::FileName::fromString(grp.location().filePath()),
|
m_productPath = productPath;
|
||||||
ProjectExplorer::FileType::Project, false,
|
m_qbsGroupData = grp;
|
||||||
grp.location().line()));
|
|
||||||
|
|
||||||
updateQbsGroupData(grp, productPath, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ProjectExplorer::ProjectAction> QbsGroupNode::supportedActions(ProjectExplorer::Node *node) const
|
QList<ProjectExplorer::ProjectAction> QbsGroupNode::supportedActions(ProjectExplorer::Node *node) const
|
||||||
@@ -391,32 +389,6 @@ bool QbsGroupNode::renameFile(const QString &filePath, const QString &newFilePat
|
|||||||
prdNode->qbsProductData(), m_qbsGroupData);
|
prdNode->qbsProductData(), m_qbsGroupData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QbsGroupNode::updateQbsGroupData(const qbs::GroupData &grp, const QString &productPath,
|
|
||||||
bool productIsEnabled)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(grp.isValid(), return);
|
|
||||||
|
|
||||||
setEnabled(productIsEnabled && grp.isEnabled());
|
|
||||||
|
|
||||||
m_productPath = productPath;
|
|
||||||
m_qbsGroupData = grp;
|
|
||||||
|
|
||||||
setAbsoluteFilePathAndLine(Utils::FileName::fromString(grp.location().filePath()), line());
|
|
||||||
setDisplayName(grp.name());
|
|
||||||
|
|
||||||
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(grp.location().filePath()),
|
|
||||||
grp.location().line());
|
|
||||||
|
|
||||||
setupFiles(this, grp, grp.allFilePaths(), productPath, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QbsGroupNode::setupFiles(ProjectExplorer::FolderNode *root, const qbs::GroupData &group,
|
void QbsGroupNode::setupFiles(ProjectExplorer::FolderNode *root, const qbs::GroupData &group,
|
||||||
const QStringList &files, const QString &productPath, bool generated)
|
const QStringList &files, const QString &productPath, bool generated)
|
||||||
{
|
{
|
||||||
@@ -438,7 +410,7 @@ void QbsGroupNode::setupFiles(ProjectExplorer::FolderNode *root, const qbs::Grou
|
|||||||
|
|
||||||
QHash<QString, ProjectExplorer::FileType> fileTypeHash;
|
QHash<QString, ProjectExplorer::FileType> fileTypeHash;
|
||||||
foreach (const qbs::ArtifactData &sa, group.allSourceArtifacts())
|
foreach (const qbs::ArtifactData &sa, group.allSourceArtifacts())
|
||||||
fileTypeHash[sa.filePath()] = fileType(sa);
|
fileTypeHash[sa.filePath()] = Internal::QbsNodeTreeBuilder::fileType(sa);
|
||||||
|
|
||||||
setupFolder(root, fileTypeHash, &tree, productPath, generated);
|
setupFolder(root, fileTypeHash, &tree, productPath, generated);
|
||||||
}
|
}
|
||||||
@@ -506,27 +478,6 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectExplorer::FileType QbsGroupNode::fileType(const qbs::ArtifactData &artifact)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(artifact.isValid(), return ProjectExplorer::FileType::Unknown);
|
|
||||||
|
|
||||||
if (artifact.fileTags().contains(QLatin1String("c"))
|
|
||||||
|| artifact.fileTags().contains(QLatin1String("cpp"))
|
|
||||||
|| artifact.fileTags().contains(QLatin1String("objc"))
|
|
||||||
|| artifact.fileTags().contains(QLatin1String("objcpp"))) {
|
|
||||||
return ProjectExplorer::FileType::Source;
|
|
||||||
}
|
|
||||||
if (artifact.fileTags().contains(QLatin1String("hpp")))
|
|
||||||
return ProjectExplorer::FileType::Header;
|
|
||||||
if (artifact.fileTags().contains(QLatin1String("qrc")))
|
|
||||||
return ProjectExplorer::FileType::Resource;
|
|
||||||
if (artifact.fileTags().contains(QLatin1String("ui")))
|
|
||||||
return ProjectExplorer::FileType::Form;
|
|
||||||
if (artifact.fileTags().contains(QLatin1String("scxml")))
|
|
||||||
return ProjectExplorer::FileType::StateChart;
|
|
||||||
return ProjectExplorer::FileType::Unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// QbsProductNode:
|
// QbsProductNode:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -619,7 +570,8 @@ void QbsProductNode::setQbsProductData(const qbs::Project &project, const qbs::P
|
|||||||
setEnabled(prd.isEnabled());
|
setEnabled(prd.isEnabled());
|
||||||
|
|
||||||
setDisplayName(QbsProject::productDisplayName(project, prd));
|
setDisplayName(QbsProject::productDisplayName(project, prd));
|
||||||
setAbsoluteFilePathAndLine(Utils::FileName::fromString(prd.location().filePath()), line());
|
setAbsoluteFilePathAndLine(Utils::FileName::fromString(prd.location().filePath()).parentDir(),
|
||||||
|
line());
|
||||||
const QString &productPath = QFileInfo(prd.location().filePath()).absolutePath();
|
const QString &productPath = QFileInfo(prd.location().filePath()).absolutePath();
|
||||||
|
|
||||||
// Find the QbsFileNode we added earlier:
|
// Find the QbsFileNode we added earlier:
|
||||||
@@ -636,18 +588,14 @@ void QbsProductNode::setQbsProductData(const qbs::Project &project, const qbs::P
|
|||||||
foreach (const qbs::GroupData &grp, prd.groups()) {
|
foreach (const qbs::GroupData &grp, prd.groups()) {
|
||||||
if (grp.name() == prd.name() && grp.location() == prd.location()) {
|
if (grp.name() == prd.name() && grp.location() == prd.location()) {
|
||||||
// Set implicit product group right onto this node:
|
// Set implicit product group right onto this node:
|
||||||
QbsGroupNode::setupFiles(this, grp, grp.allFilePaths(), productPath, false);
|
QbsNodeTreeBuilder::setupArtifacts(this, grp.allSourceArtifacts());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
addNode(new QbsGroupNode(grp, productPath));
|
addNode(QbsNodeTreeBuilder::buildGroupNodeTree(grp, productPath, prd.isEnabled()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prd.isEnabled()) {
|
if (prd.isEnabled())
|
||||||
const QStringList generatedFiles
|
QbsNodeTreeBuilder::setupArtifacts(this, prd.generatedArtifacts());
|
||||||
= Utils::transform(prd.generatedArtifacts(), &qbs::ArtifactData::filePath);
|
|
||||||
QbsGroupNode::setupFiles(m_generatedFilesNode, qbs::GroupData(), generatedFiles,
|
|
||||||
prd.buildDirectory(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_qbsProductData = prd;
|
m_qbsProductData = prd;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ public:
|
|||||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
|
||||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
|
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
|
||||||
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||||
void updateQbsGroupData(const qbs::GroupData &grp, const QString &productPath, bool productIsEnabled);
|
|
||||||
|
|
||||||
qbs::GroupData qbsGroupData() const { return m_qbsGroupData; }
|
qbs::GroupData qbsGroupData() const { return m_qbsGroupData; }
|
||||||
|
|
||||||
@@ -111,7 +110,6 @@ private:
|
|||||||
const QHash<QString, ProjectExplorer::FileType> &fileTypeHash,
|
const QHash<QString, ProjectExplorer::FileType> &fileTypeHash,
|
||||||
const FileTreeNode *subFileTree, const QString &baseDir,
|
const FileTreeNode *subFileTree, const QString &baseDir,
|
||||||
bool generated);
|
bool generated);
|
||||||
static ProjectExplorer::FileType fileType(const qbs::ArtifactData &artifact);
|
|
||||||
|
|
||||||
qbs::GroupData m_qbsGroupData;
|
qbs::GroupData m_qbsGroupData;
|
||||||
QString m_productPath;
|
QString m_productPath;
|
||||||
|
|||||||
101
src/plugins/qbsprojectmanager/qbsnodetreebuilder.cpp
Normal file
101
src/plugins/qbsprojectmanager/qbsnodetreebuilder.cpp
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2017 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "qbsnodetreebuilder.h"
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void setupArtifacts(ProjectExplorer::FolderNode *root, const QList<qbs::ArtifactData> &artifacts)
|
||||||
|
{
|
||||||
|
QList<ProjectExplorer::FileNode *> fileNodes
|
||||||
|
= Utils::transform(artifacts, [](const qbs::ArtifactData &ad) {
|
||||||
|
const Utils::FileName path = Utils::FileName::fromString(ad.filePath());
|
||||||
|
const ProjectExplorer::FileType type =
|
||||||
|
QbsProjectManager::Internal::QbsNodeTreeBuilder::fileType(ad);
|
||||||
|
const bool isGenerated = ad.isGenerated();
|
||||||
|
return new ProjectExplorer::FileNode(path, type, isGenerated);
|
||||||
|
});
|
||||||
|
|
||||||
|
root->buildTree(fileNodes);
|
||||||
|
root->compress();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace QbsProjectManager {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
ProjectExplorer::FileType QbsNodeTreeBuilder::fileType(const qbs::ArtifactData &artifact)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(artifact.isValid(), return ProjectExplorer::FileType::Unknown);
|
||||||
|
|
||||||
|
if (artifact.fileTags().contains("c")
|
||||||
|
|| artifact.fileTags().contains("cpp")
|
||||||
|
|| artifact.fileTags().contains("objc")
|
||||||
|
|| artifact.fileTags().contains("objcpp")) {
|
||||||
|
return ProjectExplorer::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;
|
||||||
|
return ProjectExplorer::FileType::Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
QbsGroupNode *QbsNodeTreeBuilder::buildGroupNodeTree(const qbs::GroupData &grp,
|
||||||
|
const QString &productPath,
|
||||||
|
bool productIsEnabled)
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QbsNodeTreeBuilder::setupArtifacts(QbsBaseProjectNode *node, const QList<qbs::ArtifactData> &artifacts)
|
||||||
|
{
|
||||||
|
::setupArtifacts(node, artifacts);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QbsProjectManager
|
||||||
50
src/plugins/qbsprojectmanager/qbsnodetreebuilder.h
Normal file
50
src/plugins/qbsprojectmanager/qbsnodetreebuilder.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2017 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "qbsnodes.h"
|
||||||
|
|
||||||
|
#include <qbs.h>
|
||||||
|
|
||||||
|
namespace QbsProjectManager {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// QbsNodeTreeBuilder:
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
class QbsNodeTreeBuilder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ProjectExplorer::FileType fileType(const qbs::ArtifactData &artifact);
|
||||||
|
|
||||||
|
static QbsGroupNode *buildGroupNodeTree(const qbs::GroupData &grp, const QString &productPath,
|
||||||
|
bool productIsEnabled);
|
||||||
|
static void setupArtifacts(QbsBaseProjectNode *node, const QList<qbs::ArtifactData> &artifacts);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QbsProjectManager
|
||||||
@@ -29,6 +29,7 @@ HEADERS = \
|
|||||||
qbsinfopage.h \
|
qbsinfopage.h \
|
||||||
qbslogsink.h \
|
qbslogsink.h \
|
||||||
qbsnodes.h \
|
qbsnodes.h \
|
||||||
|
qbsnodetreebuilder.h \
|
||||||
qbsparser.h \
|
qbsparser.h \
|
||||||
qbspmlogging.h \
|
qbspmlogging.h \
|
||||||
qbsprofilessettingspage.h \
|
qbsprofilessettingspage.h \
|
||||||
@@ -53,6 +54,7 @@ SOURCES = \
|
|||||||
qbsinfopage.cpp \
|
qbsinfopage.cpp \
|
||||||
qbslogsink.cpp \
|
qbslogsink.cpp \
|
||||||
qbsnodes.cpp \
|
qbsnodes.cpp \
|
||||||
|
qbsnodetreebuilder.cpp \
|
||||||
qbsparser.cpp \
|
qbsparser.cpp \
|
||||||
qbspmlogging.cpp \
|
qbspmlogging.cpp \
|
||||||
qbsprofilessettingspage.cpp \
|
qbsprofilessettingspage.cpp \
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ QtcPlugin {
|
|||||||
"qbslogsink.h",
|
"qbslogsink.h",
|
||||||
"qbsnodes.cpp",
|
"qbsnodes.cpp",
|
||||||
"qbsnodes.h",
|
"qbsnodes.h",
|
||||||
|
"qbsnodetreebuilder.cpp",
|
||||||
|
"qbsnodetreebuilder.h",
|
||||||
"qbsparser.cpp",
|
"qbsparser.cpp",
|
||||||
"qbsparser.h",
|
"qbsparser.h",
|
||||||
"qbspmlogging.cpp",
|
"qbspmlogging.cpp",
|
||||||
|
|||||||
Reference in New Issue
Block a user