QmlProject: Move project tree generation out of the ProjectNodes

Change-Id: Ic0dbd0762f92191ee7d7eac47cb5385e1d3b9575
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2017-03-01 14:26:46 +01:00
parent f31d9b0b18
commit 5693a291e3
4 changed files with 22 additions and 23 deletions

View File

@@ -44,6 +44,8 @@
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <qtsupport/qtsupportconstants.h> #include <qtsupport/qtsupportconstants.h>
#include <utils/algorithm.h>
#include <QDebug> #include <QDebug>
using namespace Core; using namespace Core;
@@ -161,7 +163,7 @@ void QmlProject::parseProject(RefreshOptions options)
} }
} }
} }
rootProjectNode()->refresh(); generateProjectTree();
} }
if (options & Configuration) { if (options & Configuration) {
@@ -177,7 +179,7 @@ void QmlProject::refresh(RefreshOptions options)
parseProject(options); parseProject(options);
if (options & Files) if (options & Files)
rootProjectNode()->refresh(); generateProjectTree();
if (!modelManager()) if (!modelManager())
return; return;
@@ -382,5 +384,20 @@ Project::RestoreResult QmlProject::fromMap(const QVariantMap &map, QString *erro
return RestoreResult::Ok; return RestoreResult::Ok;
} }
void QmlProject::generateProjectTree()
{
QStringList allFiles = files();
QList<FileNode *> fileNodes = Utils::transform(allFiles, [this](const QString &f) {
FileType fileType = FileType::Source; // ### FIXME
if (f == projectFilePath().toString())
fileType = FileType::Project;
return new FileNode(Utils::FileName::fromString(f), fileType, false);
});
rootProjectNode()->makeEmpty();
rootProjectNode()->buildTree(fileNodes);
}
} // namespace QmlProjectManager } // namespace QmlProjectManager

View File

@@ -82,6 +82,7 @@ protected:
RestoreResult fromMap(const QVariantMap &map, QString *errorMessage) override; RestoreResult fromMap(const QVariantMap &map, QString *errorMessage) override;
private: private:
void generateProjectTree();
void refreshFiles(const QSet<QString> &added, const QSet<QString> &removed); void refreshFiles(const QSet<QString> &added, const QSet<QString> &removed);
void addedTarget(ProjectExplorer::Target *target); void addedTarget(ProjectExplorer::Target *target);
void onActiveTargetChanged(ProjectExplorer::Target *target); void onActiveTargetChanged(ProjectExplorer::Target *target);

View File

@@ -39,9 +39,8 @@ using namespace ProjectExplorer;
namespace QmlProjectManager { namespace QmlProjectManager {
namespace Internal { namespace Internal {
QmlProjectNode::QmlProjectNode(QmlProject *project) QmlProjectNode::QmlProjectNode(QmlProject *project) : ProjectNode(project->projectDirectory()),
: ProjectNode(project->projectDirectory()), m_project(project)
m_project(project)
{ {
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName()); setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
// make overlay // make overlay
@@ -53,22 +52,6 @@ QmlProjectNode::QmlProjectNode(QmlProject *project)
setIcon(QIcon(projectPixmap)); setIcon(QIcon(projectPixmap));
} }
void QmlProjectNode::refresh()
{
QStringList files = m_project->files();
files.removeAll(m_project->projectFilePath().toString());
QList<FileNode *> fileNodes = Utils::transform(files, [](const QString &f) {
FileType fileType = FileType::Source; // ### FIXME
return new FileNode(Utils::FileName::fromString(f), fileType, false);
});
fileNodes.append(new FileNode(m_project->projectFilePath(), FileType::Project, false));
makeEmpty();
buildTree(fileNodes);
}
bool QmlProjectNode::showInSimpleTree() const bool QmlProjectNode::showInSimpleTree() const
{ {
return true; return true;

View File

@@ -46,8 +46,6 @@ public:
virtual bool deleteFiles(const QStringList &filePaths) override; virtual bool deleteFiles(const QStringList &filePaths) override;
virtual bool renameFile(const QString &filePath, const QString &newFilePath) override; virtual bool renameFile(const QString &filePath, const QString &newFilePath) override;
void refresh();
private: private:
QmlProject *m_project; QmlProject *m_project;
}; };