diff --git a/src/plugins/genericprojectmanager/genericproject.cpp b/src/plugins/genericprojectmanager/genericproject.cpp index fb6dedb36f8be2b743b387262f3d5cacd3d5d3be..77b1e009687a3fd6a06aa11b8ce4cf8673ea419c 100644 --- a/src/plugins/genericprojectmanager/genericproject.cpp +++ b/src/plugins/genericprojectmanager/genericproject.cpp @@ -111,9 +111,7 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName) qDebug() << Q_FUNC_INFO; _file = new GenericProjectFile(this, fileName); - _rootNode = new GenericProjectNode(_file); - - refresh(); + _rootNode = new GenericProjectNode(this, _file); } GenericProject::~GenericProject() @@ -124,6 +122,15 @@ GenericProject::~GenericProject() delete _toolChain; } +void GenericProject::parseProject() +{ + QSettings projectInfo(_fileName, QSettings::IniFormat); + + _files = convertToAbsoluteFiles(projectInfo.value(QLatin1String("files")).toStringList()); + _generated = convertToAbsoluteFiles(projectInfo.value(QLatin1String("generated")).toStringList()); + _defines = projectInfo.value(QLatin1String("defines")).toStringList(); +} + void GenericProject::refresh() { qDebug() << Q_FUNC_INFO; @@ -150,21 +157,48 @@ void GenericProject::refresh() allIncludePaths.append(headerPath.path()); } - allIncludePaths += _rootNode->includePaths(); + allIncludePaths += includePaths(); pinfo.frameworkPaths = allFrameworkPaths; pinfo.includePaths = allIncludePaths; // ### add _defines. - pinfo.sourceFiles = _rootNode->files(); - pinfo.sourceFiles += _rootNode->generated(); + pinfo.sourceFiles = files(); + pinfo.sourceFiles += generated(); modelManager->updateProjectInfo(pinfo); modelManager->updateSourceFiles(pinfo.sourceFiles); } } -void GenericProject::setToolChain(const QString &toolChainId) +QStringList GenericProject::convertToAbsoluteFiles(const QStringList &paths) const +{ + const QDir projectDir(QFileInfo(_fileName).dir()); + QStringList absolutePaths; + foreach (const QString &file, paths) { + QFileInfo fileInfo(projectDir, file); + absolutePaths.append(fileInfo.absoluteFilePath()); + } + absolutePaths.removeDuplicates(); + return absolutePaths; +} + +QStringList GenericProject::files() const +{ return _files; } + +QStringList GenericProject::generated() const +{ return _generated; } + +QStringList GenericProject::includePaths() const +{ return _includePaths; } + +void GenericProject::setIncludePaths(const QStringList &includePaths) +{ _includePaths = convertToAbsoluteFiles(includePaths); } + +QStringList GenericProject::defines() const +{ return _defines; } + +void GenericProject::setToolChainId(const QString &toolChainId) { using namespace ProjectExplorer; @@ -310,7 +344,7 @@ QStringList GenericProject::files(FilesMode fileMode) const { qDebug() << Q_FUNC_INFO; - return _rootNode->files(); + return _files; // ### TODO: handle generated files here. } QStringList GenericProject::targets() const @@ -357,10 +391,11 @@ void GenericProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsRead if (toolChainId.isEmpty()) toolChainId = QLatin1String("gcc"); - setToolChain(toolChainId.toLower()); // ### move + setToolChainId(toolChainId.toLower()); // ### move + setIncludePaths(reader.restoreValue(QLatin1String("includePaths")).toStringList()); - const QStringList includePaths = reader.restoreValue(QLatin1String("includePaths")).toStringList(); - _rootNode->setIncludePaths(includePaths); + parseProject(); + refresh(); } void GenericProject::saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer) @@ -370,7 +405,7 @@ void GenericProject::saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter Project::saveSettingsImpl(writer); writer.saveValue("toolChain", _toolChainId); - writer.saveValue("includePaths", _rootNode->includePaths()); + writer.saveValue("includePaths", _includePaths); } //////////////////////////////////////////////////////////////////////////////////// @@ -394,7 +429,7 @@ GenericBuildSettingsWidget::GenericBuildSettingsWidget(GenericProject *project) toolChainChooser->addItems(ProjectExplorer::ToolChain::supportedToolChains()); toolChainChooser->setCurrentIndex(toolChainChooser->findText(_project->toolChainId())); fl->addRow(tr("Tool chain:"), toolChainChooser); - connect(toolChainChooser, SIGNAL(activated(QString)), _project, SLOT(setToolChain(QString))); + connect(toolChainChooser, SIGNAL(activated(QString)), _project, SLOT(setToolChainId(QString))); // include paths QListView *includePathsView = new QListView; diff --git a/src/plugins/genericprojectmanager/genericproject.h b/src/plugins/genericprojectmanager/genericproject.h index 1673a494f6767d21a7d9b5bda6e2c1c976251afe..6d9e1e3482232b7ff3687dd498771e51ae14346a 100644 --- a/src/plugins/genericprojectmanager/genericproject.h +++ b/src/plugins/genericprojectmanager/genericproject.h @@ -76,24 +76,38 @@ public: MakeStep *makeStep() const; QString buildParser(const QString &buildConfiguration) const; + QStringList convertToAbsoluteFiles(const QStringList &paths) const; + + QStringList includePaths() const; + void setIncludePaths(const QStringList &includePaths); + + QStringList files() const; + QStringList generated() const; + QStringList defines() const; + QString toolChainId() const; public Q_SLOTS: - void setToolChain(const QString &toolChainId); - -private: - void refresh(); + void setToolChainId(const QString &toolChainId); protected: virtual void saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer); virtual void restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader); private: + void parseProject(); + void refresh(); + Manager *_manager; QString _fileName; GenericProjectFile *_file; QString _projectName; + QStringList _files; + QStringList _generated; + QStringList _includePaths; + QStringList _defines; + GenericProjectNode* _rootNode; ProjectExplorer::ToolChain *_toolChain; QString _toolChainId; diff --git a/src/plugins/genericprojectmanager/genericprojectnodes.cpp b/src/plugins/genericprojectmanager/genericprojectnodes.cpp index fb1261fd4e5d12ae6afcb173ea394da4346d1755..85dc20819e0ebdb05bc71f7bf12ee831c0d85d7d 100644 --- a/src/plugins/genericprojectmanager/genericprojectnodes.cpp +++ b/src/plugins/genericprojectmanager/genericprojectnodes.cpp @@ -28,6 +28,8 @@ **************************************************************************/ #include "genericprojectnodes.h" +#include "genericproject.h" + #include <QDir> #include <QFileInfo> #include <QSettings> @@ -36,8 +38,9 @@ using namespace GenericProjectManager; using namespace GenericProjectManager::Internal; -GenericProjectNode::GenericProjectNode(Core::IFile *projectFile) +GenericProjectNode::GenericProjectNode(GenericProject *project, Core::IFile *projectFile) : ProjectExplorer::ProjectNode(QFileInfo(projectFile->fileName()).absolutePath()), + _project(project), _projectFile(projectFile) {} @@ -50,17 +53,6 @@ Core::IFile *GenericProjectNode::projectFile() const QString GenericProjectNode::projectFilePath() const { return _projectFile->fileName(); } -static QStringList convertToAbsoluteFiles(const QDir &dir, const QStringList &paths) -{ - QStringList absolutePaths; - foreach (const QString &file, paths) { - QFileInfo fileInfo(dir, file); - absolutePaths.append(fileInfo.absoluteFilePath()); - } - absolutePaths.removeDuplicates(); - return absolutePaths; -} - void GenericProjectNode::refresh() { using namespace ProjectExplorer; @@ -69,13 +61,6 @@ void GenericProjectNode::refresh() removeFileNodes(fileNodes(), this); removeFolderNodes(subFolderNodes(), this); - QDir projectPath(path()); - QSettings projectInfo(projectFilePath(), QSettings::IniFormat); - - _files = convertToAbsoluteFiles(projectPath, projectInfo.value(QLatin1String("files")).toStringList()); - _generated = convertToAbsoluteFiles(projectPath, projectInfo.value(QLatin1String("generated")).toStringList()); - _defines = projectInfo.value(QLatin1String("defines")).toStringList(); - FileNode *projectFileNode = new FileNode(projectFilePath(), ProjectFileType, /* generated = */ false); @@ -84,7 +69,7 @@ void GenericProjectNode::refresh() QStringList filePaths; QHash<QString, QStringList> filesInPath; - foreach (const QString &absoluteFileName, _files) { + foreach (const QString &absoluteFileName, _project->files()) { QFileInfo fileInfo(absoluteFileName); const QString absoluteFilePath = fileInfo.path(); @@ -144,96 +129,6 @@ ProjectExplorer::FolderNode *GenericProjectNode::findOrCreateFolderByName(const return findOrCreateFolderByName(components, components.length()); } -#if 0 -void GenericProjectNode::refresh() -{ - using namespace ProjectExplorer; - - removeFileNodes(fileNodes(), this); - removeFolderNodes(subFolderNodes(), this); - - QDir projectPath(path()); - - QSettings projectInfo(projectFilePath(), QSettings::IniFormat); - - _files = convertToAbsoluteFiles(projectPath, projectInfo.value(QLatin1String("files")).toStringList()); - _generated = convertToAbsoluteFiles(projectPath, projectInfo.value(QLatin1String("generated")).toStringList()); - _includePaths = convertToAbsoluteFiles(projectPath, projectInfo.value(QLatin1String("includes")).toStringList()); - _defines = projectInfo.value(QLatin1String("defines")).toStringList(); - _toolChainId = projectInfo.value(QLatin1String("toolchain"), QLatin1String("gcc")).toString().toLower(); - - FileNode *projectFileNode = new FileNode(projectFilePath(), ProjectFileType, - /* generated = */ false); - addFileNodes(QList<FileNode *>() << projectFileNode, this); - - QHash<QString, FolderNode *> folders; - QHash<FolderNode *, QStringList> filesInFolder; - QList<FolderNode *> folderNodes; - - foreach (const QString &file, _files) { - QFileInfo fileInfo(projectPath, file); - - if (! fileInfo.isFile()) - continue; // not a file. - - QString folderPath = fileInfo.canonicalPath(); - if (! folderPath.startsWith(path())) { - qDebug() << "*** skip:" << folderPath; - continue; - } - - folderPath = folderPath.mid(path().length() + 1); - - FolderNode *folder = folders.value(folderPath); - if (! folder) { - folder = new FolderNode(folderPath); - folders.insert(folderPath, folder); - - folderNodes.append(folder); - } - - filesInFolder[folder].append(fileInfo.canonicalFilePath()); - } - - addFolderNodes(folderNodes, this); - - QHashIterator<FolderNode *, QStringList> it(filesInFolder); - while (it.hasNext()) { - it.next(); - - FolderNode *folder = it.key(); - QStringList files = it.value(); - - QList<FileNode *> fileNodes; - foreach (const QString &filePath, files) { - QFileInfo fileInfo(projectPath, filePath); - - FileNode *fileNode = new FileNode(fileInfo.absoluteFilePath(), - SourceType, /*generated = */ false); - - fileNodes.append(fileNode); - } - - addFileNodes(fileNodes, folder); - } -} -#endif - -QStringList GenericProjectNode::files() const -{ return _files; } - -QStringList GenericProjectNode::generated() const -{ return _generated; } - -QStringList GenericProjectNode::includePaths() const -{ return _includePaths; } - -void GenericProjectNode::setIncludePaths(const QStringList &includePaths) -{ _includePaths = convertToAbsoluteFiles(QDir(path()), includePaths); } - -QStringList GenericProjectNode::defines() const -{ return _defines; } - bool GenericProjectNode::hasTargets() const { qDebug() << Q_FUNC_INFO; diff --git a/src/plugins/genericprojectmanager/genericprojectnodes.h b/src/plugins/genericprojectmanager/genericprojectnodes.h index 5298cb543896f2462a1a388894663e2864dcadde..1c1b2cad2d23da052cc29bb38161d6c14681a936 100644 --- a/src/plugins/genericprojectmanager/genericprojectnodes.h +++ b/src/plugins/genericprojectmanager/genericprojectnodes.h @@ -38,10 +38,12 @@ namespace GenericProjectManager { namespace Internal { +class GenericProject; + class GenericProjectNode : public ProjectExplorer::ProjectNode { public: - GenericProjectNode(Core::IFile *projectFile); + GenericProjectNode(GenericProject *project, Core::IFile *projectFile); virtual ~GenericProjectNode(); Core::IFile *projectFile() const; @@ -69,23 +71,13 @@ public: void refresh(); - QStringList includePaths() const; - void setIncludePaths(const QStringList &includePaths); - - QStringList files() const; - QStringList generated() const; - QStringList defines() const; - private: FolderNode *findOrCreateFolderByName(const QString &filePath); FolderNode *findOrCreateFolderByName(const QStringList &components, int end); private: + GenericProject *_project; Core::IFile *_projectFile; - QStringList _files; - QStringList _generated; - QStringList _includePaths; - QStringList _defines; QHash<QString, FolderNode *> _folderByName; };