diff --git a/sources/ElementsCollection/elementscollectionmodel.cpp b/sources/ElementsCollection/elementscollectionmodel.cpp index 6e4686076..00ef0d2eb 100644 --- a/sources/ElementsCollection/elementscollectionmodel.cpp +++ b/sources/ElementsCollection/elementscollectionmodel.cpp @@ -503,6 +503,10 @@ void ElementsCollectionModel::addProject(QETProject *project, bool set_data) connect(project->embeddedElementCollection(), &XmlElementCollection::directoryRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection); + connect(project, &QETProject::projectTitleChanged, + this, &ElementsCollectionModel::projectNameChanged); + connect(project, &QETProject::projectFilePathChanged, + this, &ElementsCollectionModel::projectNameChanged); } /** @@ -534,6 +538,10 @@ void ElementsCollectionModel::removeProject(QETProject *project) &XmlElementCollection::directoryRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection); + disconnect(project, &QETProject::projectTitleChanged, + this, &ElementsCollectionModel::projectNameChanged); + disconnect(project, &QETProject::projectFilePathChanged, + this, &ElementsCollectionModel::projectNameChanged); } } @@ -774,3 +782,15 @@ void ElementsCollectionModel::updateItem(const QString& path) eci->setUpData(); } } + +/** + @brief ElementsCollectionModel::projectNameChanged + Update the displayed name of the collection of project, + when its title or its file path changed. + @param project +*/ +void ElementsCollectionModel::projectNameChanged(QETProject *project) +{ + if (XmlProjectElementCollectionItem *xpeci = m_project_hash.value(project)) + xpeci->updateProjectName(); +} diff --git a/sources/ElementsCollection/elementscollectionmodel.h b/sources/ElementsCollection/elementscollectionmodel.h index c2a7297ae..a46e994bf 100644 --- a/sources/ElementsCollection/elementscollectionmodel.h +++ b/sources/ElementsCollection/elementscollectionmodel.h @@ -73,6 +73,7 @@ class ElementsCollectionModel : public QStandardItemModel void elementIntegratedToCollection (const QString& path); void itemRemovedFromCollection (const QString& path); void updateItem (const QString& path); + void projectNameChanged (QETProject *project); private: QList m_project_list; diff --git a/sources/ElementsCollection/xmlprojectelementcollectionitem.cpp b/sources/ElementsCollection/xmlprojectelementcollectionitem.cpp index a647d265e..d79fcbb6f 100644 --- a/sources/ElementsCollection/xmlprojectelementcollectionitem.cpp +++ b/sources/ElementsCollection/xmlprojectelementcollectionitem.cpp @@ -21,6 +21,8 @@ #include "../qetproject.h" #include "xmlelementcollection.h" +#include + /** @brief XmlProjectElementCollectionItem::XmlProjectElementCollectionItem Constructor @@ -58,10 +60,7 @@ QString XmlProjectElementCollectionItem::localName() return text(); if (isCollectionRoot()) { - if (m_project->title().isEmpty()) - setText(QObject::tr("Projet sans titre")); - else - setText(m_project->title()); + updateProjectName(); } else { ElementsLocation location (embeddedPath(), m_project); @@ -71,6 +70,25 @@ QString XmlProjectElementCollectionItem::localName() return text(); } +/** + @brief XmlProjectElementCollectionItem::updateProjectName + Set the displayed name of the collection root from the project : + its title, or its file name when it has no title, like the project panel. + Does nothing if this item is not the root of the collection. +*/ +void XmlProjectElementCollectionItem::updateProjectName() +{ + if (!isCollectionRoot() || !m_project) + return; + + if (!m_project->title().isEmpty()) + setText(m_project->title()); + else if (!m_project->filePath().isEmpty()) + setText(QFileInfo(m_project->filePath()).completeBaseName()); + else + setText(QObject::tr("Projet sans titre")); +} + /** @brief XmlProjectElementCollectionItem::name @return The collection name of this item diff --git a/sources/ElementsCollection/xmlprojectelementcollectionitem.h b/sources/ElementsCollection/xmlprojectelementcollectionitem.h index 92864b92e..b795c6f16 100644 --- a/sources/ElementsCollection/xmlprojectelementcollectionitem.h +++ b/sources/ElementsCollection/xmlprojectelementcollectionitem.h @@ -45,6 +45,7 @@ class XmlProjectElementCollectionItem : public ElementCollectionItem bool isCollectionRoot() const override; void addChildAtPath(const QString &collection_name) override; QETProject * project() const; + void updateProjectName(); void setProject (QETProject *project, bool set_data = true,