GenericProject: Code cleanup

Remove unused code from project node, access own members
directly, etc.

Change-Id: Icbffb4d3328757ffe3aa756ca1448fefba9bb00a
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
hjk
2017-03-15 13:40:21 +01:00
parent 6ecb1c4018
commit 4d3c297d02
8 changed files with 111 additions and 269 deletions

View File

@@ -30,11 +30,14 @@
#include "genericprojectconstants.h" #include "genericprojectconstants.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/buildinfo.h> #include <projectexplorer/buildinfo.h>
#include <projectexplorer/buildsteplist.h> #include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kitinformation.h> #include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h> #include <projectexplorer/toolchain.h>
#include <utils/mimetypes/mimedatabase.h> #include <utils/mimetypes/mimedatabase.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>

View File

@@ -29,15 +29,17 @@
#include "ui_genericmakestep.h" #include "ui_genericmakestep.h"
#include "genericbuildconfiguration.h" #include "genericbuildconfiguration.h"
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/buildsteplist.h> #include <projectexplorer/buildsteplist.h>
#include <projectexplorer/gnumakeparser.h> #include <projectexplorer/gnumakeparser.h>
#include <projectexplorer/kitinformation.h> #include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h> #include <projectexplorer/toolchain.h>
#include <qtsupport/qtkitinformation.h> #include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtparser.h> #include <qtsupport/qtparser.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>

View File

@@ -32,11 +32,13 @@
#include <coreplugin/documentmanager.h> #include <coreplugin/documentmanager.h>
#include <coreplugin/icontext.h> #include <coreplugin/icontext.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cpptools/cpptoolsconstants.h> #include <cpptools/cpptoolsconstants.h>
#include <cpptools/cppmodelmanager.h> #include <cpptools/cppmodelmanager.h>
#include <cpptools/projectinfo.h> #include <cpptools/projectinfo.h>
#include <cpptools/cppprojectupdater.h> #include <cpptools/cppprojectupdater.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/abi.h> #include <projectexplorer/abi.h>
#include <projectexplorer/buildsteplist.h> #include <projectexplorer/buildsteplist.h>
#include <projectexplorer/customexecutablerunconfiguration.h> #include <projectexplorer/customexecutablerunconfiguration.h>
@@ -44,13 +46,20 @@
#include <projectexplorer/kitinformation.h> #include <projectexplorer/kitinformation.h>
#include <projectexplorer/kitmanager.h> #include <projectexplorer/kitmanager.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/target.h>
#include <qtsupport/baseqtversion.h> #include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h> #include <qtsupport/qtkitinformation.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QDir> #include <QDir>
#include <QHash>
#include <QSet>
#include <QStringList>
using namespace Core; using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -59,6 +68,89 @@ using namespace Utils;
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {
////////////////////////////////////////////////////////////////////////////////////
//
// GenericProjectFile
//
////////////////////////////////////////////////////////////////////////////////////
class GenericProjectFile : public Core::IDocument
{
public:
GenericProjectFile(GenericProject *parent, const FileName &fileName,
GenericProject::RefreshOptions options) :
m_project(parent),
m_options(options)
{
setId("Generic.ProjectFile");
setMimeType(Constants::GENERICMIMETYPE);
setFilePath(fileName);
}
ReloadBehavior reloadBehavior(ChangeTrigger, ChangeType) const final
{
return BehaviorSilent;
}
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override
{
Q_UNUSED(errorString);
Q_UNUSED(flag);
if (type == TypePermissions)
return true;
m_project->refresh(m_options);
return true;
}
private:
GenericProject *m_project = nullptr;
GenericProject::RefreshOptions m_options;
};
////////////////////////////////////////////////////////////////////////////////////
//
// GenericProjectNode
//
////////////////////////////////////////////////////////////////////////////////////
class GenericProjectNode : public ProjectNode
{
public:
explicit GenericProjectNode(GenericProject *project) :
ProjectNode(project->projectDirectory()),
m_project(project)
{
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
}
bool showInSimpleTree() const override { return true; }
QList<ProjectExplorer::ProjectAction> supportedActions(Node *) const override
{
return {AddNewFile, AddExistingFile, AddExistingDirectory, RemoveFile, Rename};
}
bool addFiles(const QStringList &filePaths, QStringList * = 0) override
{
return m_project->addFiles(filePaths);
}
bool removeFiles(const QStringList &filePaths, QStringList * = 0) override
{
return m_project->removeFiles(filePaths);
}
bool renameFile(const QString &filePath, const QString &newFilePath) override
{
return m_project->renameFile(filePath, newFilePath);
}
private:
GenericProject *m_project = nullptr;
};
//////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////
// //
// GenericProject // GenericProject
@@ -97,21 +189,6 @@ GenericProject::~GenericProject()
delete m_cppCodeModelUpdater; delete m_cppCodeModelUpdater;
} }
QString GenericProject::filesFileName() const
{
return m_filesFileName;
}
QString GenericProject::includesFileName() const
{
return m_includesFileName;
}
QString GenericProject::configFileName() const
{
return m_configFileName;
}
static QStringList readLines(const QString &absoluteFileName) static QStringList readLines(const QString &absoluteFileName)
{ {
QStringList lines; QStringList lines;
@@ -134,7 +211,7 @@ static QStringList readLines(const QString &absoluteFileName)
bool GenericProject::saveRawFileList(const QStringList &rawFileList) bool GenericProject::saveRawFileList(const QStringList &rawFileList)
{ {
bool result = saveRawList(rawFileList, filesFileName()); bool result = saveRawList(rawFileList, m_filesFileName);
refresh(GenericProject::Files); refresh(GenericProject::Files);
return result; return result;
} }
@@ -168,7 +245,7 @@ bool GenericProject::addFiles(const QStringList &filePaths)
for (const QString &filePath : filePaths) for (const QString &filePath : filePaths)
insertSorted(&newList, baseDir.relativeFilePath(filePath)); insertSorted(&newList, baseDir.relativeFilePath(filePath));
const QSet<QString> includes = projectIncludePaths().toSet(); const QSet<QString> includes = m_projectIncludePaths.toSet();
QSet<QString> toAdd; QSet<QString> toAdd;
for (const QString &filePath : filePaths) { for (const QString &filePath : filePaths) {
@@ -186,8 +263,8 @@ bool GenericProject::addFiles(const QStringList &filePaths)
m_rawProjectIncludePaths.append(relative); m_rawProjectIncludePaths.append(relative);
} }
bool result = saveRawList(newList, filesFileName()); bool result = saveRawList(newList, m_filesFileName);
result &= saveRawList(m_rawProjectIncludePaths, includesFileName()); result &= saveRawList(m_rawProjectIncludePaths, m_includesFileName);
refresh(GenericProject::Everything); refresh(GenericProject::Everything);
return result; return result;
@@ -238,12 +315,12 @@ void GenericProject::parseProject(RefreshOptions options)
{ {
if (options & Files) { if (options & Files) {
m_rawListEntries.clear(); m_rawListEntries.clear();
m_rawFileList = readLines(filesFileName()); m_rawFileList = readLines(m_filesFileName);
m_files = processEntries(m_rawFileList, &m_rawListEntries); m_files = processEntries(m_rawFileList, &m_rawListEntries);
} }
if (options & Configuration) { if (options & Configuration) {
m_rawProjectIncludePaths = readLines(includesFileName()); m_rawProjectIncludePaths = readLines(m_includesFileName);
m_projectIncludePaths = processEntries(m_rawProjectIncludePaths); m_projectIncludePaths = processEntries(m_rawProjectIncludePaths);
// TODO: Possibly load some configuration from the project file // TODO: Possibly load some configuration from the project file
@@ -261,7 +338,7 @@ void GenericProject::refresh(RefreshOptions options)
if (options & Files) { if (options & Files) {
auto newRoot = new GenericProjectNode(this); auto newRoot = new GenericProjectNode(this);
for (const QString &f : files()) { for (const QString &f : m_files) {
FileType fileType = FileType::Source; // ### FIXME FileType fileType = FileType::Source; // ### FIXME
if (f.endsWith(".qrc")) if (f.endsWith(".qrc"))
fileType = FileType::Resource; fileType = FileType::Resource;
@@ -362,9 +439,9 @@ void GenericProject::refreshCppCodeModel()
rpp.setDisplayName(displayName()); rpp.setDisplayName(displayName());
rpp.setProjectFileLocation(projectFilePath().toString()); rpp.setProjectFileLocation(projectFilePath().toString());
rpp.setQtVersion(activeQtVersion); rpp.setQtVersion(activeQtVersion);
rpp.setIncludePaths(projectIncludePaths()); rpp.setIncludePaths(m_projectIncludePaths);
rpp.setConfigFileName(configFileName()); rpp.setConfigFileName(m_configFileName);
rpp.setFiles(files()); rpp.setFiles(m_files);
const CppTools::ProjectUpdateInfo projectInfoUpdate(this, cToolChain, cxxToolChain, k, {rpp}); const CppTools::ProjectUpdateInfo projectInfoUpdate(this, cToolChain, cxxToolChain, k, {rpp});
m_cppCodeModelUpdater->update(projectInfoUpdate); m_cppCodeModelUpdater->update(projectInfoUpdate);
@@ -392,11 +469,6 @@ void GenericProject::activeBuildConfigurationWasChanged()
refresh(Everything); refresh(Everything);
} }
QStringList GenericProject::projectIncludePaths() const
{
return m_projectIncludePaths;
}
QStringList GenericProject::files() const QStringList GenericProject::files() const
{ {
return m_files; return m_files;
@@ -455,38 +527,5 @@ Project::RestoreResult GenericProject::fromMap(const QVariantMap &map, QString *
return RestoreResult::Ok; return RestoreResult::Ok;
} }
////////////////////////////////////////////////////////////////////////////////////
//
// GenericProjectFile
//
////////////////////////////////////////////////////////////////////////////////////
GenericProjectFile::GenericProjectFile(GenericProject *parent, const Utils::FileName &fileName,
GenericProject::RefreshOptions options) :
m_project(parent),
m_options(options)
{
setId("Generic.ProjectFile");
setMimeType(Constants::GENERICMIMETYPE);
setFilePath(fileName);
}
IDocument::ReloadBehavior GenericProjectFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
{
Q_UNUSED(state);
Q_UNUSED(type);
return BehaviorSilent;
}
bool GenericProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType type)
{
Q_UNUSED(errorString);
Q_UNUSED(flag);
if (type == TypePermissions)
return true;
m_project->refresh(m_options);
return true;
}
} // namespace Internal } // namespace Internal
} // namespace GenericProjectManager } // namespace GenericProjectManager

View File

@@ -25,16 +25,7 @@
#pragma once #pragma once
#include "genericprojectnodes.h"
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/buildconfiguration.h>
#include <coreplugin/idocument.h>
#include <QFuture>
namespace CppTools { class CppProjectUpdater; } namespace CppTools { class CppProjectUpdater; }
@@ -51,10 +42,6 @@ public:
explicit GenericProject(const Utils::FileName &filename); explicit GenericProject(const Utils::FileName &filename);
~GenericProject() override; ~GenericProject() override;
QString filesFileName() const;
QString includesFileName() const;
QString configFileName() const;
QString displayName() const override; QString displayName() const override;
QStringList files(FilesMode fileMode) const override; QStringList files(FilesMode fileMode) const override;
@@ -74,7 +61,6 @@ public:
void refresh(RefreshOptions options); void refresh(RefreshOptions options);
QStringList projectIncludePaths() const;
QStringList files() const; QStringList files() const;
protected: protected:
@@ -108,19 +94,5 @@ private:
ProjectExplorer::Target *m_activeTarget = nullptr; ProjectExplorer::Target *m_activeTarget = nullptr;
}; };
class GenericProjectFile : public Core::IDocument
{
public:
GenericProjectFile(GenericProject *parent, const Utils::FileName &fileName,
GenericProject::RefreshOptions options);
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
private:
GenericProject *m_project;
GenericProject::RefreshOptions m_options;
};
} // namespace Internal } // namespace Internal
} // namespace GenericProjectManager } // namespace GenericProjectManager

View File

@@ -3,20 +3,20 @@ include(../../qtcreatorplugin.pri)
HEADERS = genericproject.h \ HEADERS = genericproject.h \
genericprojectplugin.h \ genericprojectplugin.h \
genericprojectconstants.h \ genericprojectconstants.h \
genericprojectnodes.h \
genericprojectwizard.h \ genericprojectwizard.h \
genericprojectfileseditor.h \ genericprojectfileseditor.h \
genericmakestep.h \ genericmakestep.h \
genericbuildconfiguration.h \ genericbuildconfiguration.h \
filesselectionwizardpage.h filesselectionwizardpage.h
SOURCES = genericproject.cpp \ SOURCES = genericproject.cpp \
genericprojectplugin.cpp \ genericprojectplugin.cpp \
genericprojectnodes.cpp \
genericprojectwizard.cpp \ genericprojectwizard.cpp \
genericprojectfileseditor.cpp \ genericprojectfileseditor.cpp \
genericmakestep.cpp \ genericmakestep.cpp \
genericbuildconfiguration.cpp \ genericbuildconfiguration.cpp \
filesselectionwizardpage.cpp filesselectionwizardpage.cpp
FORMS += genericmakestep.ui FORMS += genericmakestep.ui
equals(TEST, 1) { equals(TEST, 1) {

View File

@@ -30,8 +30,6 @@ QtcPlugin {
"genericprojectconstants.h", "genericprojectconstants.h",
"genericprojectfileseditor.cpp", "genericprojectfileseditor.cpp",
"genericprojectfileseditor.h", "genericprojectfileseditor.h",
"genericprojectnodes.cpp",
"genericprojectnodes.h",
"genericprojectplugin.cpp", "genericprojectplugin.cpp",
"genericprojectplugin.h", "genericprojectplugin.h",
"genericprojectwizard.cpp", "genericprojectwizard.cpp",

View File

@@ -1,113 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 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 "genericprojectnodes.h"
#include "genericproject.h"
#include <coreplugin/idocument.h>
#include <projectexplorer/projectexplorer.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <QFileInfo>
using namespace ProjectExplorer;
namespace GenericProjectManager {
namespace Internal {
GenericProjectNode::GenericProjectNode(GenericProject *project) :
ProjectNode(project->projectDirectory()),
m_project(project)
{
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
}
QHash<QString, QStringList> sortFilesIntoPaths(const QString &base, const QSet<QString> &files)
{
QHash<QString, QStringList> filesInPath;
const QDir baseDir(base);
foreach (const QString &absoluteFileName, files) {
QFileInfo fileInfo(absoluteFileName);
Utils::FileName absoluteFilePath = Utils::FileName::fromString(fileInfo.path());
QString relativeFilePath;
if (absoluteFilePath.isChildOf(baseDir)) {
relativeFilePath = absoluteFilePath.relativeChildPath(Utils::FileName::fromString(base)).toString();
} else {
// `file' is not part of the project.
relativeFilePath = baseDir.relativeFilePath(absoluteFilePath.toString());
if (relativeFilePath.endsWith('/'))
relativeFilePath.chop(1);
}
if (relativeFilePath == ".")
relativeFilePath.clear();
filesInPath[relativeFilePath].append(absoluteFileName);
}
return filesInPath;
}
bool GenericProjectNode::showInSimpleTree() const
{
return true;
}
QList<ProjectAction> GenericProjectNode::supportedActions(Node *node) const
{
Q_UNUSED(node);
return {
AddNewFile,
AddExistingFile,
AddExistingDirectory,
RemoveFile,
Rename
};
}
bool GenericProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
{
Q_UNUSED(notAdded)
return m_project->addFiles(filePaths);
}
bool GenericProjectNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
{
Q_UNUSED(notRemoved)
return m_project->removeFiles(filePaths);
}
bool GenericProjectNode::renameFile(const QString &filePath, const QString &newFilePath)
{
return m_project->renameFile(filePath, newFilePath);
}
} // namespace Internal
} // namespace GenericProjectManager

View File

@@ -1,59 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 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 <projectexplorer/projectnodes.h>
#include <QStringList>
#include <QHash>
#include <QSet>
namespace Core { class IDocument; }
namespace GenericProjectManager {
namespace Internal {
class GenericProject;
class GenericProjectNode : public ProjectExplorer::ProjectNode
{
public:
explicit GenericProjectNode(GenericProject *project);
bool showInSimpleTree() const override;
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
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;
private:
GenericProject *const m_project;
};
} // namespace Internal
} // namespace GenericProjectManager