Commit 09515894 authored by Tobias Hunger's avatar Tobias Hunger

Project: Unify handling of displayName

Unify the handling of displayName with a proper changed signal across
all projects.

Change-Id: I7e503528854b85f6f38de4b0943775f82a0d6123
Reviewed-by: Alessandro Portale's avatarAlessandro Portale <alessandro.portale@qt.io>
parent 28c8da4f
......@@ -75,6 +75,7 @@ AutotoolsProject::AutotoolsProject(const Utils::FileName &fileName) :
setId(Constants::AUTOTOOLS_PROJECT_ID);
setProjectContext(Core::Context(Constants::PROJECT_CONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setDisplayName(projectDirectory().fileName());
}
AutotoolsProject::~AutotoolsProject()
......@@ -90,11 +91,6 @@ AutotoolsProject::~AutotoolsProject()
}
}
QString AutotoolsProject::displayName() const
{
return projectFilePath().toFileInfo().absoluteDir().dirName();
}
QString AutotoolsProject::defaultBuildDirectory(const QString &projectPath)
{
return QFileInfo(projectPath).absolutePath();
......
......@@ -57,7 +57,6 @@ public:
explicit AutotoolsProject(const Utils::FileName &fileName);
~AutotoolsProject() override;
QString displayName() const override;
static QString defaultBuildDirectory(const QString &projectPath);
QStringList buildTargets() const;
......
......@@ -79,6 +79,7 @@ CMakeProject::CMakeProject(const FileName &fileName) : Project(Constants::CMAKEM
setId(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
setProjectContext(Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setDisplayName(projectDirectory().fileName());
connect(this, &CMakeProject::activeTargetChanged, this, &CMakeProject::handleActiveTargetChanged);
connect(&m_treeScanner, &TreeScanner::finished, this, &CMakeProject::handleTreeScanningFinished);
......@@ -145,8 +146,10 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
Kit *k = t->kit();
auto newRoot = bc->generateProjectTree(m_allFiles);
if (newRoot)
if (newRoot) {
setRootProjectNode(newRoot);
setDisplayName(newRoot->displayName());
}
updateApplicationAndDeploymentTargets();
updateTargetRunConfigurations(t);
......@@ -296,12 +299,6 @@ bool CMakeProject::hasBuildTarget(const QString &title) const
return anyOf(buildTargets(), [title](const CMakeBuildTarget &ct) { return ct.title == title; });
}
QString CMakeProject::displayName() const
{
auto root = dynamic_cast<CMakeProjectNode *>(rootProjectNode());
return root ? root->displayName() : projectDirectory().fileName();
}
Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *errorMessage)
{
RestoreResult result = Project::fromMap(map, errorMessage);
......
......@@ -86,8 +86,6 @@ public:
explicit CMakeProject(const Utils::FileName &filename);
~CMakeProject() final;
QString displayName() const final;
QStringList buildTargetTitles(bool runnable = false) const;
bool hasBuildTarget(const QString &title) const;
......
......@@ -42,13 +42,10 @@ TestProject::TestProject(const QString &name, QObject *parent) :
{
setParent(parent);
setId(Core::Id::fromString(name));
setDisplayName(name);
qRegisterMetaType<QSet<QString> >();
}
TestProject::~TestProject()
{
}
ModelManagerTestHelper::ModelManagerTestHelper(QObject *parent,
bool testOnlyForCleanedProjects)
: QObject(parent)
......
......@@ -41,9 +41,6 @@ class CPPTOOLS_EXPORT TestProject: public ProjectExplorer::Project
public:
TestProject(const QString &name, QObject *parent);
~TestProject() override;
QString displayName() const override { return m_name; }
private:
QString m_name;
......
......@@ -72,6 +72,7 @@ GenericProject::GenericProject(const Utils::FileName &fileName) :
setId(Constants::GENERICPROJECT_ID);
setProjectContext(Context(GenericProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setDisplayName(fileName.toFileInfo().completeBaseName());
const QFileInfo fileInfo = projectFilePath().toFileInfo();
const QDir dir = fileInfo.dir();
......@@ -395,11 +396,6 @@ QStringList GenericProject::projectIncludePaths() const
return m_projectIncludePaths;
}
QString GenericProject::displayName() const
{
return projectFilePath().toFileInfo().completeBaseName();
}
QStringList GenericProject::buildTargets() const
{
const QStringList targets = { "all", "clean" };
......
......@@ -53,8 +53,6 @@ public:
QString includesFileName() const;
QString configFileName() const;
QString displayName() const override;
QStringList buildTargets() const;
bool addFiles(const QStringList &filePaths);
......
......@@ -57,6 +57,7 @@ const int MIN_TIME_BETWEEN_PROJECT_SCANS = 4500;
NimProject::NimProject(const FileName &fileName) : Project(Constants::C_NIM_MIMETYPE, fileName)
{
setId(Constants::C_NIMPROJECT_ID);
setDisplayName(fileName.toFileInfo().completeBaseName());
m_projectScanTimer.setSingleShot(true);
connect(&m_projectScanTimer, &QTimer::timeout, this, &NimProject::collectProjectFiles);
......@@ -66,11 +67,6 @@ NimProject::NimProject(const FileName &fileName) : Project(Constants::C_NIM_MIME
collectProjectFiles();
}
QString NimProject::displayName() const
{
return projectFilePath().toFileInfo().completeBaseName();
}
bool NimProject::needsConfiguration() const
{
return targets().empty();
......
......@@ -41,7 +41,6 @@ class NimProject : public ProjectExplorer::Project
public:
explicit NimProject(const Utils::FileName &fileName);
QString displayName() const override;
bool needsConfiguration() const override;
bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage) const override;
Utils::FileNameList nimFiles() const;
......
......@@ -141,6 +141,8 @@ public:
QVariantMap m_pluginSettings;
Internal::UserFileAccessor *m_accessor = nullptr;
QString m_displayName;
Kit::Predicate m_requiredKitPredicate;
Kit::Predicate m_preferredKitPredicate;
......@@ -178,6 +180,11 @@ Project::~Project()
delete d;
}
QString Project::displayName() const
{
return d->m_displayName;
}
Core::Id Project::id() const
{
QTC_CHECK(d->m_id.isValid());
......@@ -455,6 +462,14 @@ bool Project::setupTarget(Target *t)
return true;
}
void Project::setDisplayName(const QString &name)
{
if (name == d->m_displayName)
return;
d->m_displayName = name;
emit displayNameChanged();
}
void Project::setId(Core::Id id)
{
d->m_id = id;
......
......@@ -92,7 +92,7 @@ public:
const ProjectDocument::ProjectCallback &callback = {});
~Project() override;
virtual QString displayName() const = 0;
QString displayName() const;
Core::Id id() const;
Core::IDocument *document() const;
......@@ -164,6 +164,7 @@ public:
Utils::MacroExpander *macroExpander() const;
signals:
void displayNameChanged();
void fileListChanged();
// Note: activeTarget can be 0 (if no targets are defined).
......@@ -190,6 +191,7 @@ protected:
virtual RestoreResult fromMap(const QVariantMap &map, QString *errorMessage);
virtual bool setupTarget(Target *t);
void setDisplayName(const QString &name);
void setRequiredKitPredicate(const Kit::Predicate &predicate);
void setPreferredKitPredicate(const Kit::Predicate &predicate);
......
......@@ -94,8 +94,6 @@ class PythonProject : public Project
public:
explicit PythonProject(const Utils::FileName &filename);
QString displayName() const override;
bool addFiles(const QStringList &filePaths);
bool removeFiles(const QStringList &filePaths);
bool setFiles(const QStringList &filePaths);
......@@ -377,11 +375,7 @@ PythonProject::PythonProject(const FileName &fileName) :
setId(PythonProjectId);
setProjectContext(Context(PythonProjectContext));
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
}
QString PythonProject::displayName() const
{
return projectFilePath().toFileInfo().completeBaseName();
setDisplayName(fileName.toFileInfo().completeBaseName());
}
static QStringList readLines(const QString &absoluteFileName)
......
......@@ -132,6 +132,8 @@ QbsProject::QbsProject(const FileName &fileName) :
setProjectContext(Context(Constants::PROJECT_ID));
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setDisplayName(fileName.toFileInfo().completeBaseName());
connect(this, &Project::activeTargetChanged, this, &QbsProject::changeActiveTarget);
connect(this, &Project::addedTarget, this, &QbsProject::targetWasAdded);
connect(this, &Project::removedTarget, this, &QbsProject::targetWasRemoved);
......@@ -158,11 +160,6 @@ QbsProject::~QbsProject()
qDeleteAll(m_extraCompilers);
}
QString QbsProject::displayName() const
{
return projectFilePath().toFileInfo().completeBaseName();
}
QbsRootProjectNode *QbsProject::rootProjectNode() const
{
return static_cast<QbsRootProjectNode *>(Project::rootProjectNode());
......
......@@ -61,7 +61,6 @@ public:
explicit QbsProject(const Utils::FileName &filename);
~QbsProject() override;
QString displayName() const override;
QbsRootProjectNode *rootProjectNode() const override;
QStringList filesGeneratedFrom(const QString &sourceFile) const override;
......
......@@ -169,6 +169,7 @@ QmakeProject::QmakeProject(const FileName &fileName) :
setProjectContext(Core::Context(QmakeProjectManager::Constants::PROJECT_ID));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setRequiredKitPredicate(QtSupport::QtKitInformation::qtVersionPredicate());
setDisplayName(fileName.toFileInfo().completeBaseName());
const QTextCodec *codec = Core::EditorManager::defaultTextCodec();
m_qmakeVfs->setTextCodec(codec);
......@@ -575,11 +576,6 @@ bool QmakeProject::supportsKit(Kit *k, QString *errorMessage) const
return version;
}
QString QmakeProject::displayName() const
{
return projectFilePath().toFileInfo().completeBaseName();
}
// Find the folder that contains a file with a certain name (recurse down)
static FolderNode *folderOf(FolderNode *in, const FileName &fileName)
{
......
......@@ -65,8 +65,6 @@ public:
QmakeProFile *rootProFile() const;
QString displayName() const final;
bool supportsKit(ProjectExplorer::Kit *k, QString *errorMesage) const final;
QmakeProFileNode *rootProjectNode() const final;
......
......@@ -61,6 +61,7 @@ QmlProject::QmlProject(const Utils::FileName &fileName) :
setId("QmlProjectManager.QmlProject");
setProjectContext(Context(QmlProjectManager::Constants::PROJECTCONTEXT));
setProjectLanguages(Context(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID));
setDisplayName(fileName.toFileInfo().completeBaseName());
}
QmlProject::~QmlProject()
......@@ -239,11 +240,6 @@ void QmlProject::refreshFiles(const QSet<QString> &/*added*/, const QSet<QString
}
}
QString QmlProject::displayName() const
{
return projectFilePath().toFileInfo().completeBaseName();
}
bool QmlProject::supportsKit(Kit *k, QString *errorMessage) const
{
Id deviceType = DeviceTypeKitInformation::deviceTypeId(k);
......
......@@ -46,8 +46,6 @@ public:
explicit QmlProject(const Utils::FileName &filename);
~QmlProject() override;
QString displayName() const override;
bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage) const override;
Internal::QmlProjectNode *rootProjectNode() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment