diff --git a/sources/projectview.cpp b/sources/projectview.cpp index ca368b91d..4f18691f1 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -643,11 +643,12 @@ bool ProjectView::saveAll() { } /** - Propose a l'utilisateur de nettoyer le projet ; cela inclut la possibilite : - * de supprimer les elements inutilises dans le projet - * de supprimer les categories vides - @return le nombre de traitements effectues (0 si rien n'a ete fait, 1 ou - 2 sinon) + Allow the user to clean the project, which includes: + * deleting unused title block templates + * deleting unused elements + * deleting empty categories + @return an integer value above zero if elements and/or categories were + cleaned. */ int ProjectView::cleanProject() { if (!project_) return(0); @@ -663,10 +664,12 @@ int ProjectView::cleanProject() { } // construit un petit dialogue pour parametrer le nettoyage + QCheckBox *clean_tbt = new QCheckBox(tr("Supprimer les mod\350les de cartouche inutilisés dans le projet")); QCheckBox *clean_elements = new QCheckBox(tr("Supprimer les \351l\351ments inutilis\351s dans le projet")); QCheckBox *clean_categories = new QCheckBox(tr("Supprimer les cat\351gories vides")); QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + clean_tbt -> setChecked(true); clean_elements -> setChecked(true); clean_categories -> setChecked(true); @@ -677,6 +680,7 @@ int ProjectView::cleanProject() { clean_dialog.setWindowTitle(tr("Nettoyer le projet", "window title")); QVBoxLayout *clean_dialog_layout = new QVBoxLayout(); + clean_dialog_layout -> addWidget(clean_tbt); clean_dialog_layout -> addWidget(clean_elements); clean_dialog_layout -> addWidget(clean_categories); clean_dialog_layout -> addWidget(buttons); @@ -687,6 +691,9 @@ int ProjectView::cleanProject() { int clean_count = 0; if (clean_dialog.exec() == QDialog::Accepted) { + if (clean_tbt -> isChecked()) { + project_ -> cleanUnusedTitleBlocKTemplates(); + } if (clean_elements -> isChecked()) { InteractiveMoveElementsHandler *handler = new InteractiveMoveElementsHandler(this); project_ -> cleanUnusedElements(handler); diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 4a3f3f80c..faf64cbb8 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -740,6 +740,13 @@ bool QETProject::usesTitleBlockTemplate(const TitleBlockTemplateLocation &locati return(false); } +/** + Delete all title block templates not used in the project +*/ +void QETProject::cleanUnusedTitleBlocKTemplates() { + titleblocks_.deleteUnusedTitleBlocKTemplates(); +} + /** Supprime tous les elements inutilises dans le projet @param handler Gestionnaire d'erreur diff --git a/sources/qetproject.h b/sources/qetproject.h index a485bfb07..fd44bfe85 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -109,6 +109,7 @@ class QETProject : public QObject { QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler); bool usesElement(const ElementsLocation &); bool usesTitleBlockTemplate(const TitleBlockTemplateLocation &); + void cleanUnusedTitleBlocKTemplates(); void cleanUnusedElements(MoveElementsHandler *); void cleanEmptyCategories(MoveElementsHandler *); bool projectWasModified(); diff --git a/sources/titleblock/templatescollection.cpp b/sources/titleblock/templatescollection.cpp index b6db574eb..e038e0d92 100644 --- a/sources/titleblock/templatescollection.cpp +++ b/sources/titleblock/templatescollection.cpp @@ -287,6 +287,19 @@ void TitleBlockTemplatesProjectCollection::fromXml(const QDomElement &xml_elemen } } +/** + Delete all title block templates not used within the parent project +*/ +void TitleBlockTemplatesProjectCollection::deleteUnusedTitleBlocKTemplates() { + if (!project_) return; + + foreach (QString template_name, templates()) { + if (!project_ -> usesTitleBlockTemplate(location(template_name))) { + removeTemplate(template_name); + } + } +} + /** Constructor @param path Path of the directory containing the collection diff --git a/sources/titleblock/templatescollection.h b/sources/titleblock/templatescollection.h index 39d6d1632..26e10d704 100644 --- a/sources/titleblock/templatescollection.h +++ b/sources/titleblock/templatescollection.h @@ -96,6 +96,7 @@ class TitleBlockTemplatesProjectCollection : public TitleBlockTemplatesCollectio virtual TitleBlockTemplateLocation location(const QString & = QString()); virtual bool isReadOnly(const QString & = QString()) const; virtual void fromXml(const QDomElement &); + virtual void deleteUnusedTitleBlocKTemplates(); // attributes private: