From 3a45625d69c11d04ba712e26100943b6a5a73ab4 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Fri, 25 Sep 2026 17:24:17 +1200 Subject: [PATCH] Fix bugtracker #95: collections pane shows "Untitled project" for a titleless project The root of a project's embedded collection showed "Projet sans titre" whenever the project had no title, while the project panel shows the file name. Fall back to the file name the same way, and only use "Projet sans titre" for a project that has neither. The name was also computed once, so changing the project title or saving it under a new name left the pane stale until the collections were reloaded. Update it on projectTitleChanged and projectFilePathChanged. Co-Authored-By: Claude Opus 5.5 --- .../elementscollectionmodel.cpp | 20 ++++++++++++++ .../elementscollectionmodel.h | 1 + .../xmlprojectelementcollectionitem.cpp | 26 ++++++++++++++++--- .../xmlprojectelementcollectionitem.h | 1 + 4 files changed, 44 insertions(+), 4 deletions(-) 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,