2013-01-30 18:19:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** 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 Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qbsnodes.h"
|
|
|
|
|
|
|
|
|
|
#include "qbsproject.h"
|
|
|
|
|
|
2013-04-17 13:07:43 +02:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
|
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
2013-03-25 12:03:37 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2013-01-30 18:19:31 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <qbs.h>
|
|
|
|
|
|
|
|
|
|
#include <QDir>
|
2013-04-17 13:07:43 +02:00
|
|
|
#include <QStyle>
|
2013-01-30 18:19:31 +01:00
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
// Helpers:
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
namespace QbsProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2013-04-17 13:07:43 +02:00
|
|
|
QIcon generateIcon()
|
|
|
|
|
{
|
|
|
|
|
const QSize desiredSize = QSize(16, 16);
|
|
|
|
|
const QIcon projectBaseIcon(QString::fromLatin1(QtSupport::Constants::ICON_QT_PROJECT));
|
|
|
|
|
const QPixmap projectPixmap = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
|
|
|
|
|
projectBaseIcon,
|
|
|
|
|
desiredSize);
|
|
|
|
|
|
|
|
|
|
QIcon result;
|
|
|
|
|
result.addPixmap(projectPixmap);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QIcon QbsProjectNode::m_projectIcon = generateIcon();
|
|
|
|
|
QIcon QbsProductNode::m_productIcon = generateIcon();
|
|
|
|
|
QIcon QbsGroupNode::m_groupIcon = generateIcon();
|
|
|
|
|
|
2013-01-30 18:19:31 +01:00
|
|
|
class FileTreeNode {
|
|
|
|
|
public:
|
|
|
|
|
FileTreeNode(const QString &n, FileTreeNode *p = 0) :
|
|
|
|
|
parent(p), name(n)
|
|
|
|
|
{
|
|
|
|
|
if (p)
|
|
|
|
|
p->children.append(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~FileTreeNode()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(children);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileTreeNode *addPart(const QString &n)
|
|
|
|
|
{
|
|
|
|
|
foreach (FileTreeNode *c, children) {
|
|
|
|
|
if (c->name == n)
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
return new FileTreeNode(n, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isFile() { return children.isEmpty(); }
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
// Moves the node pointing to basedir to the root of the tree and deletes any now empty nodes.
|
|
|
|
|
static void reorder(FileTreeNode *node, const QString &basedir, FileTreeNode *root)
|
|
|
|
|
{
|
|
|
|
|
if (node != root && node->path() == basedir) {
|
|
|
|
|
// move node to root:
|
|
|
|
|
FileTreeNode *parent = node->parent;
|
|
|
|
|
if (parent)
|
|
|
|
|
parent->children.removeOne(node);
|
|
|
|
|
root->children.append(node);
|
|
|
|
|
node->parent = root;
|
|
|
|
|
if (basedir.startsWith(QLatin1Char('/')))
|
|
|
|
|
node->name = basedir.mid(1);
|
|
|
|
|
else
|
|
|
|
|
node->name = basedir;
|
|
|
|
|
|
|
|
|
|
// clean up now-empty nodes:
|
|
|
|
|
while (parent) {
|
|
|
|
|
if (parent->children.count() == 0) {
|
|
|
|
|
FileTreeNode *current = parent;
|
|
|
|
|
parent = current->parent;
|
|
|
|
|
parent->children.removeOne(current);
|
|
|
|
|
current->parent = 0;
|
|
|
|
|
delete current;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
foreach (FileTreeNode *n, node->children)
|
|
|
|
|
reorder(n, basedir, root);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-30 18:19:31 +01:00
|
|
|
static void simplify(FileTreeNode *node)
|
|
|
|
|
{
|
|
|
|
|
foreach (FileTreeNode *c, node->children)
|
|
|
|
|
simplify(c);
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
if (!node->parent)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-01-30 18:19:31 +01:00
|
|
|
if (node->children.count() == 1) {
|
|
|
|
|
FileTreeNode *child = node->children.at(0);
|
|
|
|
|
if (child->isFile())
|
|
|
|
|
return;
|
|
|
|
|
|
2013-03-25 12:03:37 +01:00
|
|
|
if (!Utils::HostOsInfo::isWindowsHost() || !node->name.isEmpty())
|
|
|
|
|
node->name = node->name + QLatin1Char('/') + child->name;
|
|
|
|
|
else
|
|
|
|
|
node->name = child->name;
|
2013-01-30 18:19:31 +01:00
|
|
|
node->children = child->children;
|
|
|
|
|
|
|
|
|
|
foreach (FileTreeNode *tmpChild, node->children)
|
|
|
|
|
tmpChild->parent = node;
|
|
|
|
|
|
|
|
|
|
child->children.clear();
|
|
|
|
|
child->parent = 0;
|
|
|
|
|
delete child;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString path()
|
|
|
|
|
{
|
|
|
|
|
QString p = name;
|
|
|
|
|
FileTreeNode *node = parent;
|
|
|
|
|
while (node) {
|
2013-03-25 12:03:37 +01:00
|
|
|
if (!Utils::HostOsInfo::isWindowsHost() || !node->name.isEmpty())
|
|
|
|
|
p = node->name + QLatin1Char('/') + p;
|
2013-01-30 18:19:31 +01:00
|
|
|
node = node->parent;
|
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<FileTreeNode *> children;
|
|
|
|
|
FileTreeNode *parent;
|
|
|
|
|
QString name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
// QbsFileNode:
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QbsFileNode::QbsFileNode(const QString &filePath, const ProjectExplorer::FileType fileType,
|
|
|
|
|
bool generated, int line) :
|
|
|
|
|
ProjectExplorer::FileNode(filePath, fileType, generated),
|
|
|
|
|
m_line(line)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
void QbsFileNode::setLine(int l)
|
|
|
|
|
{
|
|
|
|
|
m_line = l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// QbsBaseProjectNode:
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QbsBaseProjectNode::QbsBaseProjectNode(const QString &path) :
|
|
|
|
|
ProjectExplorer::ProjectNode(path)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
bool QbsBaseProjectNode::hasBuildTargets() const
|
|
|
|
|
{
|
|
|
|
|
foreach (ProjectNode *n, subProjectNodes())
|
|
|
|
|
if (n->hasBuildTargets())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::ProjectNode::ProjectAction> QbsBaseProjectNode::supportedActions(ProjectExplorer::Node *node) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(node);
|
|
|
|
|
return QList<ProjectExplorer::ProjectNode::ProjectAction>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsBaseProjectNode::canAddSubProject(const QString &proFilePath) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(proFilePath);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsBaseProjectNode::addSubProjects(const QStringList &proFilePaths)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(proFilePaths);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsBaseProjectNode::removeSubProjects(const QStringList &proFilePaths)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(proFilePaths);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsBaseProjectNode::addFiles(const ProjectExplorer::FileType fileType, const QStringList &filePaths, QStringList *notAdded)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(fileType);
|
|
|
|
|
Q_UNUSED(filePaths);
|
|
|
|
|
Q_UNUSED(notAdded);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsBaseProjectNode::removeFiles(const ProjectExplorer::FileType fileType, const QStringList &filePaths, QStringList *notRemoved)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(fileType);
|
|
|
|
|
Q_UNUSED(filePaths);
|
|
|
|
|
Q_UNUSED(notRemoved);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsBaseProjectNode::deleteFiles(const ProjectExplorer::FileType fileType, const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(fileType);
|
|
|
|
|
Q_UNUSED(filePaths);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsBaseProjectNode::renameFile(const ProjectExplorer::FileType fileType, const QString &filePath, const QString &newFilePath)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(fileType);
|
|
|
|
|
Q_UNUSED(filePath);
|
|
|
|
|
Q_UNUSED(newFilePath);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::RunConfiguration *> QbsBaseProjectNode::runConfigurationsFor(ProjectExplorer::Node *node)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(node);
|
|
|
|
|
return QList<ProjectExplorer::RunConfiguration *>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// QbsGroupNode:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
QbsGroupNode::QbsGroupNode(const qbs::GroupData *grp, const QString &productPath) :
|
2013-01-30 18:19:31 +01:00
|
|
|
QbsBaseProjectNode(QString()),
|
|
|
|
|
m_group(0)
|
|
|
|
|
{
|
2013-04-17 13:07:43 +02:00
|
|
|
setIcon(m_groupIcon);
|
2013-04-16 16:19:11 +02:00
|
|
|
setGroup(grp, productPath);
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsGroupNode::isEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<QbsProductNode *>(parentFolderNode())->isEnabled() && group()->isEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
void QbsGroupNode::setGroup(const qbs::GroupData *group, const QString &productPath)
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
2013-04-16 16:19:11 +02:00
|
|
|
if (group == m_group && productPath == m_productPath)
|
2013-01-30 18:19:31 +01:00
|
|
|
return;
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
m_productPath = productPath;
|
|
|
|
|
|
|
|
|
|
// Set Product file node used to jump to the product
|
2013-01-30 18:19:31 +01:00
|
|
|
setPath(group->location().fileName);
|
|
|
|
|
setDisplayName(group->name());
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
// set up file node...
|
2013-01-30 18:19:31 +01:00
|
|
|
QbsFileNode *indexFile = 0;
|
|
|
|
|
if (!m_group) {
|
|
|
|
|
indexFile = new QbsFileNode(group->location().fileName,
|
|
|
|
|
ProjectExplorer::ProjectFileType, false,
|
|
|
|
|
group->location().line);
|
|
|
|
|
addFileNodes(QList<ProjectExplorer::FileNode *>() << indexFile, this);
|
|
|
|
|
} else {
|
|
|
|
|
indexFile = static_cast<QbsFileNode *>(fileNodes().first());
|
|
|
|
|
indexFile->setPath(group->location().fileName);
|
|
|
|
|
indexFile->setLine(group->location().line);
|
|
|
|
|
indexFile->emitNodeUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
m_group = group;
|
|
|
|
|
|
|
|
|
|
setGroup(this, group, productPath, QList<ProjectExplorer::Node *>() << indexFile);
|
|
|
|
|
emitNodeUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QbsGroupNode::setGroup(QbsBaseProjectNode *root, const qbs::GroupData *group,
|
|
|
|
|
const QString &productPath, QList<ProjectExplorer::Node *> keepers)
|
|
|
|
|
{
|
2013-01-30 18:19:31 +01:00
|
|
|
// Build up a tree of nodes:
|
|
|
|
|
FileTreeNode *tree = new FileTreeNode(QString());
|
|
|
|
|
|
|
|
|
|
foreach (const QString &path, group->allFilePaths()) {
|
|
|
|
|
QStringList pathSegments = path.split(QLatin1Char('/'), QString::SkipEmptyParts);
|
|
|
|
|
|
|
|
|
|
FileTreeNode *root = tree;
|
|
|
|
|
while (!pathSegments.isEmpty())
|
|
|
|
|
root = root->addPart(pathSegments.takeFirst());
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
FileTreeNode::reorder(tree, productPath, tree);
|
2013-01-30 18:19:31 +01:00
|
|
|
FileTreeNode::simplify(tree);
|
2013-04-16 16:19:11 +02:00
|
|
|
setupFolders(root, root, tree, productPath, keepers);
|
2013-01-30 18:19:31 +01:00
|
|
|
delete tree;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
void QbsGroupNode::setupFolders(QbsBaseProjectNode *topLevel, ProjectExplorer::FolderNode *root,
|
|
|
|
|
FileTreeNode *node, const QString &baseDirPath,
|
|
|
|
|
QList<ProjectExplorer::Node *> keepers)
|
2013-01-30 18:19:31 +01:00
|
|
|
{
|
2013-04-16 16:19:11 +02:00
|
|
|
QList<ProjectExplorer::FileNode *> filesToRemove;
|
|
|
|
|
foreach (ProjectExplorer::FileNode *fn, root->fileNodes()) {
|
|
|
|
|
ProjectExplorer::Node *n = static_cast<ProjectExplorer::Node *>(fn);
|
|
|
|
|
if (!keepers.contains(n))
|
|
|
|
|
filesToRemove.append(fn);
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::FileNode *> filesToAdd;
|
|
|
|
|
|
2013-04-16 16:19:11 +02:00
|
|
|
QList<ProjectExplorer::Node *> foldersToKeep = keepers;
|
|
|
|
|
QList<ProjectExplorer::FolderNode *> foldersToRemove;
|
|
|
|
|
foreach (ProjectExplorer::FolderNode *fn, root->subFolderNodes()) {
|
|
|
|
|
ProjectExplorer::Node *n = static_cast<ProjectExplorer::Node *>(fn);
|
|
|
|
|
if (!keepers.contains(n))
|
|
|
|
|
foldersToRemove.append(fn);
|
|
|
|
|
}
|
2013-01-30 18:19:31 +01:00
|
|
|
|
|
|
|
|
// insert subfolders
|
|
|
|
|
foreach (FileTreeNode *c, node->children) {
|
|
|
|
|
QString path = c->path();
|
|
|
|
|
if (c->isFile()) {
|
|
|
|
|
ProjectExplorer::FileNode *fn = root->findFile(path);
|
|
|
|
|
if (fn) {
|
|
|
|
|
fn->emitNodeUpdated(); // enabled might have changed
|
|
|
|
|
filesToRemove.removeOne(fn);
|
|
|
|
|
} else {
|
|
|
|
|
fn = new ProjectExplorer::FileNode(path, ProjectExplorer::UnknownFileType, false);
|
|
|
|
|
filesToAdd.append(fn);
|
|
|
|
|
}
|
2013-04-16 16:19:11 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::FolderNode *fn = root->findSubFolder(path);
|
|
|
|
|
if (path == baseDirPath) {
|
|
|
|
|
setupFolders(topLevel, root, c, c->path(), foldersToKeep);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (path.startsWith(baseDirPath + QLatin1Char('/')))
|
|
|
|
|
path = path.mid(baseDirPath.length() + 1); // remove common prefix
|
|
|
|
|
|
|
|
|
|
if (fn) {
|
|
|
|
|
fn->emitNodeUpdated(); // enabled might have changed
|
|
|
|
|
foldersToRemove.removeOne(fn);
|
2013-01-30 18:19:31 +01:00
|
|
|
} else {
|
2013-04-16 16:19:11 +02:00
|
|
|
fn = new ProjectExplorer::FolderNode(path);
|
|
|
|
|
topLevel->addFolderNodes(QList<ProjectExplorer::FolderNode *>() << fn, root);
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
2013-04-16 16:19:11 +02:00
|
|
|
foldersToKeep.append(fn);
|
|
|
|
|
setupFolders(topLevel, fn, c, c->path());
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
2013-04-16 16:19:11 +02:00
|
|
|
topLevel->removeFileNodes(filesToRemove, root);
|
|
|
|
|
topLevel->removeFolderNodes(foldersToRemove, root);
|
|
|
|
|
topLevel->addFileNodes(filesToAdd, root);
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// QbsProductNode:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QbsProductNode::QbsProductNode(const qbs::ProductData *prd) :
|
|
|
|
|
QbsBaseProjectNode(prd->location().fileName),
|
|
|
|
|
m_product(0)
|
|
|
|
|
{
|
2013-04-17 13:07:43 +02:00
|
|
|
setIcon(m_productIcon);
|
2013-01-30 18:19:31 +01:00
|
|
|
setProduct(prd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QbsProductNode::isEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return product()->isEnabled();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QbsProductNode::setProduct(const qbs::ProductData *prd)
|
|
|
|
|
{
|
|
|
|
|
if (m_product == prd)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
setDisplayName(prd->name());
|
|
|
|
|
setPath(prd->location().fileName);
|
2013-04-16 16:19:11 +02:00
|
|
|
const QString &productPath = QFileInfo(prd->location().fileName).absolutePath();
|
2013-01-30 18:19:31 +01:00
|
|
|
|
|
|
|
|
// Set Product file node used to jump to the product
|
|
|
|
|
QList<ProjectExplorer::FileNode *> files = fileNodes();
|
2013-04-16 16:19:11 +02:00
|
|
|
QList<ProjectExplorer::Node *> toKeep;
|
2013-01-30 18:19:31 +01:00
|
|
|
if (files.isEmpty()) {
|
2013-04-16 16:19:11 +02:00
|
|
|
QbsFileNode *idx = new QbsFileNode(prd->location().fileName,
|
|
|
|
|
ProjectExplorer::ProjectFileType, false,
|
|
|
|
|
prd->location().line);
|
|
|
|
|
addFileNodes(QList<ProjectExplorer::FileNode *>() << idx, this);
|
|
|
|
|
toKeep.append(idx);
|
2013-01-30 18:19:31 +01:00
|
|
|
} else {
|
2013-04-16 16:19:11 +02:00
|
|
|
QbsFileNode *idx = static_cast<QbsFileNode *>(files.at(0));
|
|
|
|
|
idx->setPath(prd->location().fileName);
|
|
|
|
|
idx->setLine(prd->location().line);
|
|
|
|
|
toKeep.append(idx);
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::ProjectNode *> toAdd;
|
|
|
|
|
QList<ProjectExplorer::ProjectNode *> toRemove = subProjectNodes();
|
|
|
|
|
|
|
|
|
|
foreach (const qbs::GroupData &grp, prd->groups()) {
|
2013-04-16 16:19:11 +02:00
|
|
|
if (grp.name() == prd->name() && grp.location() == prd->location()) {
|
|
|
|
|
// Set implicit product group right onto this node:
|
|
|
|
|
QbsGroupNode::setGroup(this, &grp, productPath, toKeep);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-01-30 18:19:31 +01:00
|
|
|
QbsGroupNode *qn = findGroupNode(grp.name());
|
|
|
|
|
if (qn) {
|
|
|
|
|
toRemove.removeAll(qn);
|
2013-04-16 16:19:11 +02:00
|
|
|
toKeep.append(qn);
|
|
|
|
|
qn->setGroup(&grp, productPath);
|
2013-01-30 18:19:31 +01:00
|
|
|
} else {
|
2013-04-16 16:19:11 +02:00
|
|
|
qn = new QbsGroupNode(&grp, productPath);
|
|
|
|
|
toAdd.append(qn);
|
|
|
|
|
toKeep.append(qn);
|
2013-01-30 18:19:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addProjectNodes(toAdd);
|
|
|
|
|
removeProjectNodes(toRemove);
|
|
|
|
|
|
|
|
|
|
m_product = prd;
|
|
|
|
|
emitNodeUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QbsGroupNode *QbsProductNode::findGroupNode(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
foreach (ProjectExplorer::ProjectNode *n, subProjectNodes()) {
|
|
|
|
|
QbsGroupNode *qn = static_cast<QbsGroupNode *>(n);
|
|
|
|
|
if (qn->group()->name() == name)
|
|
|
|
|
return qn;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// QbsProjectNode:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
QbsProjectNode::QbsProjectNode(const QString &projectFile) :
|
|
|
|
|
QbsBaseProjectNode(projectFile),
|
|
|
|
|
m_project(0), m_projectData(0)
|
|
|
|
|
{
|
2013-04-17 13:07:43 +02:00
|
|
|
setIcon(m_projectIcon);
|
2013-01-30 18:19:31 +01:00
|
|
|
addFileNodes(QList<ProjectExplorer::FileNode *>()
|
|
|
|
|
<< new ProjectExplorer::FileNode(projectFile, ProjectExplorer::ProjectFileType, false), this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QbsProjectNode::~QbsProjectNode()
|
|
|
|
|
{
|
|
|
|
|
delete m_projectData;
|
|
|
|
|
delete m_project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QbsProjectNode::update(const qbs::Project *prj)
|
|
|
|
|
{
|
|
|
|
|
QList<ProjectExplorer::ProjectNode *> toAdd;
|
|
|
|
|
QList<ProjectExplorer::ProjectNode *> toRemove = subProjectNodes();
|
|
|
|
|
|
|
|
|
|
qbs::ProjectData *newData = 0;
|
|
|
|
|
|
|
|
|
|
if (prj) {
|
|
|
|
|
newData = new qbs::ProjectData(prj->projectData());
|
|
|
|
|
foreach (const qbs::ProductData &prd, newData->products()) {
|
|
|
|
|
QbsProductNode *qn = findProductNode(prd.name());
|
|
|
|
|
if (!qn) {
|
|
|
|
|
toAdd << new QbsProductNode(&prd);
|
|
|
|
|
} else {
|
|
|
|
|
qn->setProduct(&prd);
|
|
|
|
|
toRemove.removeOne(qn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete m_projectData;
|
|
|
|
|
m_projectData = newData;
|
|
|
|
|
|
2013-04-16 13:13:17 +02:00
|
|
|
delete m_project;
|
2013-01-30 18:19:31 +01:00
|
|
|
m_project = prj;
|
|
|
|
|
|
|
|
|
|
removeProjectNodes(toRemove);
|
|
|
|
|
addProjectNodes(toAdd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const qbs::Project *QbsProjectNode::project() const
|
|
|
|
|
{
|
|
|
|
|
return m_project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const qbs::ProjectData *QbsProjectNode::projectData() const
|
|
|
|
|
{
|
|
|
|
|
return m_projectData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QbsProductNode *QbsProjectNode::findProductNode(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
foreach (ProjectExplorer::ProjectNode *n, subProjectNodes()) {
|
|
|
|
|
QbsProductNode *qn = static_cast<QbsProductNode *>(n);
|
|
|
|
|
if (qn->product()->name() == name)
|
|
|
|
|
return qn;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QbsProjectManager
|