ProjectExplorer: Further tree node related simplification

Drop the list sorting and difference generation which is not
needed in the "build from scratch" setup.

This also removes some of the intermediately introduced
convienience functions and fixes a regression that led to
missing project files.

Change-Id: I39d1966324917f466fb347da3a52552393ca4a01
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2017-01-27 09:01:58 +01:00
parent 468695c30a
commit 30bf801629
8 changed files with 81 additions and 461 deletions

View File

@@ -326,7 +326,7 @@ QbsGroupNode::QbsGroupNode(const qbs::GroupData &grp, const QString &productPath
ProjectExplorer::FileType::Project, false,
grp.location().line()));
updateQbsGroupData(grp, productPath, true, true);
updateQbsGroupData(grp, productPath, true);
}
QList<ProjectExplorer::ProjectAction> QbsGroupNode::supportedActions(ProjectExplorer::Node *node) const
@@ -392,19 +392,11 @@ bool QbsGroupNode::renameFile(const QString &filePath, const QString &newFilePat
}
void QbsGroupNode::updateQbsGroupData(const qbs::GroupData &grp, const QString &productPath,
bool productWasEnabled, bool productIsEnabled)
bool productIsEnabled)
{
QTC_ASSERT(grp.isValid(), return);
if (grp == m_qbsGroupData && productPath == m_productPath)
return;
bool groupWasEnabled = productWasEnabled && m_qbsGroupData.isValid()
&& m_qbsGroupData.isEnabled();
bool groupIsEnabled = productIsEnabled && grp.isEnabled();
bool updateExisting = groupWasEnabled != groupIsEnabled;
setEnabled(groupIsEnabled);
setEnabled(productIsEnabled && grp.isEnabled());
m_productPath = productPath;
m_qbsGroupData = grp;
@@ -422,14 +414,11 @@ void QbsGroupNode::updateQbsGroupData(const qbs::GroupData &grp, const QString &
idx->setAbsoluteFilePathAndLine(Utils::FileName::fromString(grp.location().filePath()),
grp.location().line());
setupFiles(this, grp, grp.allFilePaths(), productPath, updateExisting, false);
if (updateExisting)
emitNodeUpdated();
setupFiles(this, grp, grp.allFilePaths(), productPath, false);
}
void QbsGroupNode::setupFiles(ProjectExplorer::FolderNode *root, const qbs::GroupData &group,
const QStringList &files, const QString &productPath, bool updateExisting, bool generated)
const QStringList &files, const QString &productPath, bool generated)
{
// Build up a tree of nodes:
FileTreeNode tree;
@@ -451,14 +440,13 @@ void QbsGroupNode::setupFiles(ProjectExplorer::FolderNode *root, const qbs::Grou
foreach (const qbs::ArtifactData &sa, group.allSourceArtifacts())
fileTypeHash[sa.filePath()] = fileType(sa);
setupFolder(root, fileTypeHash, &tree, productPath, updateExisting, generated);
setupFolder(root, fileTypeHash, &tree, productPath, generated);
}
void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
const QHash<QString, ProjectExplorer::FileType> &fileTypeHash,
const FileTreeNode *fileTree,
const QString &baseDir,
bool updateExisting,
bool generated)
{
// We only need to care about FileNodes and FolderNodes here. Everything else is
@@ -466,23 +454,6 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
// QbsGroupNodes are managed by the QbsProductNode.
// The buildsystem file is either managed by QbsProductNode or by updateQbsGroupData(...).
QList<ProjectExplorer::FileNode *> filesToRemove;
foreach (ProjectExplorer::FileNode *fn, root->fileNodes()) {
if (!dynamic_cast<QbsFileNode *>(fn))
filesToRemove << fn;
}
QList<ProjectExplorer::FileNode *> filesToAdd;
QList<ProjectExplorer::FolderNode *> foldersToRemove;
foreach (ProjectExplorer::FolderNode *fn, root->folderNodes()) {
if (fn->nodeType() == ProjectExplorer::NodeType::Project)
continue; // Skip ProjectNodes mixed into the folders...
const auto * const qbsFolder = dynamic_cast<QbsFolderNode *>(fn);
if (qbsFolder && qbsFolder->isGeneratedFilesFolder())
continue;
foldersToRemove.append(fn);
}
foreach (FileTreeNode *c, fileTree->children) {
Utils::FileName path = Utils::FileName::fromString(c->path());
const ProjectExplorer::FileType newFileType =
@@ -499,13 +470,9 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
fn = f;
break;
}
if (fn) {
filesToRemove.removeOne(fn);
if (updateExisting)
fn->emitNodeUpdated();
} else {
if (!fn) {
fn = new ProjectExplorer::FileNode(path, newFileType, generated);
filesToAdd.append(fn);
root->addFileNode(fn);
}
continue;
} else {
@@ -526,24 +493,17 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
ProjectExplorer::NodeType::Folder,
displayNameFromPath(c->path(), baseDir), false);
}
root->addFolderNodes(QList<FolderNode *>() << fn);
root->addFolderNode(fn);
} else {
foldersToRemove.removeOne(fn);
if (updateExisting)
fn->emitNodeUpdated();
fn->setDisplayName(displayNameFromPath(c->path(), baseDir));
}
if (isQrcFile)
static_cast<ResourceTopLevelNode *>(fn)->update();
else
setupFolder(fn, fileTypeHash, c, c->path(), updateExisting, generated);
setupFolder(fn, fileTypeHash, c, c->path(), generated);
}
}
root->removeFileNodes(filesToRemove);
root->removeFolderNodes(foldersToRemove);
root->addFileNodes(filesToAdd);
}
ProjectExplorer::FileType QbsGroupNode::fileType(const qbs::ArtifactData &artifact)
@@ -658,10 +618,6 @@ void QbsProductNode::setQbsProductData(const qbs::Project &project, const qbs::P
if (m_qbsProductData == prd)
return;
bool productWasEnabled = m_qbsProductData.isValid() && m_qbsProductData.isEnabled();
bool productIsEnabled = prd.isEnabled();
bool updateExisting = productWasEnabled != productIsEnabled;
setEnabled(prd.isEnabled());
setDisplayName(QbsProject::productDisplayName(project, prd));
@@ -679,38 +635,23 @@ void QbsProductNode::setQbsProductData(const qbs::Project &project, const qbs::P
idx->setAbsoluteFilePathAndLine(Utils::FileName::fromString(prd.location().filePath()),
prd.location().line());
QList<ProjectExplorer::ProjectNode *> toRemove = projectNodes();
foreach (const qbs::GroupData &grp, prd.groups()) {
if (grp.name() == prd.name() && grp.location() == prd.location()) {
// Set implicit product group right onto this node:
QbsGroupNode::setupFiles(this, grp, grp.allFilePaths(), productPath, updateExisting,
false);
QbsGroupNode::setupFiles(this, grp, grp.allFilePaths(), productPath, false);
continue;
}
QbsGroupNode *gn = findGroupNode(grp.name());
if (gn) {
toRemove.removeOne(gn);
gn->updateQbsGroupData(grp, productPath, productWasEnabled, productIsEnabled);
} else {
gn = new QbsGroupNode(grp, productPath);
addProjectNode(gn);
}
addProjectNode(new QbsGroupNode(grp, productPath));
}
if (prd.isEnabled()) {
const QStringList generatedFiles
= Utils::transform(prd.generatedArtifacts(), &qbs::ArtifactData::filePath);
QbsGroupNode::setupFiles(m_generatedFilesNode, qbs::GroupData(), generatedFiles,
prd.buildDirectory(), true, true);
prd.buildDirectory(), true);
}
for (ProjectNode *node : toRemove)
removeProjectNode(node);
m_qbsProductData = prd;
if (updateExisting)
emitNodeUpdated();
}
QList<ProjectExplorer::RunConfiguration *> QbsProductNode::runConfigurations() const
@@ -758,8 +699,6 @@ QbsProjectNode::~QbsProjectNode()
void QbsProjectNode::update(const qbs::Project &qbsProject, const qbs::ProjectData &prjData)
{
QTC_ASSERT(isEmpty(), makeEmpty());
foreach (const qbs::ProjectData &subData, prjData.subProjects()) {
auto subProject =
new QbsProjectNode(Utils::FileName::fromString(subData.location().filePath()));
@@ -847,7 +786,7 @@ void QbsRootProjectNode::update()
projectBuildSystemFiles.append(f);
}
QbsGroupNode::setupFiles(m_buildSystemFiles, qbs::GroupData(), projectBuildSystemFiles,
base.toString(), false, false);
base.toString(), false);
update(m_project->qbsProject(), m_project->qbsProjectData());
}

View File

@@ -96,8 +96,7 @@ public:
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0) override;
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0) override;
bool renameFile(const QString &filePath, const QString &newFilePath) override;
void updateQbsGroupData(const qbs::GroupData &grp, const QString &productPath,
bool productWasEnabled, bool productIsEnabled);
void updateQbsGroupData(const qbs::GroupData &grp, const QString &productPath, bool productIsEnabled);
qbs::GroupData qbsGroupData() const { return m_qbsGroupData; }
@@ -105,13 +104,13 @@ public:
// group can be invalid
static void setupFiles(FolderNode *root, const qbs::GroupData &group, const QStringList &files,
const QString &productPath, bool updateExisting, bool generated);
const QString &productPath, bool generated);
private:
static void setupFolder(ProjectExplorer::FolderNode *folder,
const QHash<QString, ProjectExplorer::FileType> &fileTypeHash,
const FileTreeNode *subFileTree, const QString &baseDir,
bool updateExisting, bool generated);
bool generated);
static ProjectExplorer::FileType fileType(const qbs::ArtifactData &artifact);
qbs::GroupData m_qbsGroupData;

View File

@@ -320,7 +320,7 @@ bool QbsProject::addFilesToProduct(QbsBaseProjectNode *node, const QStringList &
if (notAdded->count() != filePaths.count()) {
m_projectData = m_qbsProject.projectData();
QbsGroupNode::setupFiles(node, reRetrieveGroupData(productData, groupData),
allPaths, QFileInfo(productFilePath).absolutePath(), true, false);
allPaths, QFileInfo(productFilePath).absolutePath(), false);
rootProjectNode()->update();
emit fileListChanged();
}
@@ -349,7 +349,7 @@ bool QbsProject::removeFilesFromProduct(QbsBaseProjectNode *node, const QStringL
if (notRemoved->count() != filePaths.count()) {
m_projectData = m_qbsProject.projectData();
QbsGroupNode::setupFiles(node, reRetrieveGroupData(productData, groupData), allPaths,
QFileInfo(productFilePath).absolutePath(), true, false);
QFileInfo(productFilePath).absolutePath(), false);
rootProjectNode()->update();
emit fileListChanged();
}