From 2678b75b14f11cc3a60a5201dc780341a3a4637a Mon Sep 17 00:00:00 2001 From: xavier Date: Wed, 25 Jan 2012 18:02:17 +0000 Subject: [PATCH] Title block properties dialog: the templates list is now dynamically updated. Also, it is now possible to edit and/or duplicate the default template. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1480 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagramview.cpp | 2 +- sources/titleblock/qettemplateeditor.cpp | 11 +++++- sources/titleblockpropertieswidget.cpp | 49 ++++++++++++++++++++---- sources/titleblockpropertieswidget.h | 5 +++ 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index a42c6c3ea..c88c83ca1 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -469,7 +469,7 @@ void DiagramView::editDiagramProperties() { TitleBlockPropertiesWidget *titleblock_infos = new TitleBlockPropertiesWidget(titleblock, false, &popup); if (QETProject *parent_project = scene -> project()) { - titleblock_infos -> setTitleBlockTemplatesList(parent_project -> embeddedTitleBlockTemplates()); + titleblock_infos -> setTitleBlockTemplatesCollection(parent_project -> embeddedTitleBlockTemplatesCollection()); titleblock_infos -> setTitleBlockTemplatesVisible(true); // we have to parse again the TitleBlockProperties object, since the // first parsing did not know of our templates diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index bf7d4b078..59fe4bde8 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -111,7 +111,7 @@ bool QETTitleBlockTemplateEditor::canClose() { */ bool QETTitleBlockTemplateEditor::event(QEvent *event) { if (first_activation_ && event -> type() == QEvent::WindowActivate) { - if (duplicate_ && !opened_from_file_ && location_.isValid()) { + if (duplicate_ && !opened_from_file_ && location_.parentCollection()) { // this editor is supposed to duplicate its current location QTimer::singleShot(250, this, SLOT(duplicateCurrentLocation())); } @@ -139,13 +139,20 @@ void QETTitleBlockTemplateEditor::duplicateCurrentLocation() { // this method does not work for templates edited from the filesystem if (opened_from_file_) return; + QString proposed_name; + if (location_.name().isEmpty()) { + proposed_name = tr("nouveau_modele", "template name suggestion when duplicating the default one"); + } else { + proposed_name = QString("%1_copy").arg(location_.name()); + } + bool accepted = false; QString new_template_name = QInputDialog::getText( this, tr("Dupliquer un mod\350le de cartouche", "input dialog title"), tr("Pour dupliquer ce mod\350le, entrez le nom voulu pour sa copie", "input dialog text"), QLineEdit::Normal, - QString("%1_copy").arg(location_.name()), + proposed_name, &accepted ); if (accepted) { diff --git a/sources/titleblockpropertieswidget.cpp b/sources/titleblockpropertieswidget.cpp index c0bebbd47..922f5cf62 100644 --- a/sources/titleblockpropertieswidget.cpp +++ b/sources/titleblockpropertieswidget.cpp @@ -17,6 +17,7 @@ */ #include "titleblockpropertieswidget.h" #include "qeticons.h" +#include "templatescollection.h" /** Constructeur @@ -26,7 +27,8 @@ */ TitleBlockPropertiesWidget::TitleBlockPropertiesWidget(const TitleBlockProperties &titleblock, bool current, QWidget *parent) : QWidget(parent), - display_current_date(false) + display_current_date(false), + tbt_collection_(0) { initWidgets(titleblock); initLayouts(); @@ -167,6 +169,21 @@ void TitleBlockPropertiesWidget::setTitleBlockTemplatesList(const QList } } +/** + @param tbt_collection Collection from which title block templates should be read. +*/ +void TitleBlockPropertiesWidget::setTitleBlockTemplatesCollection(TitleBlockTemplatesCollection *tbt_collection) { + if (!tbt_collection) return; + if (tbt_collection_ && tbt_collection != tbt_collection_) { + // forget any connection with the previous collection + disconnect(tbt_collection_, 0, this, 0); + } + + tbt_collection_ = tbt_collection; + updateTemplateList(); + connect(tbt_collection_, SIGNAL(changed(TitleBlockTemplatesCollection*, QString)), this, SLOT(updateTemplateList())); +} + /** @param visible true to display the title block templates list, false to hide it. @@ -188,6 +205,17 @@ QString TitleBlockPropertiesWidget::currentTitleBlockTemplateName() const { return(QString()); } +/** + Set the currently selected title block template. + @param template_name Template to be selected +*/ +void TitleBlockPropertiesWidget::setCurrentTitleBlockTemplateName(const QString &template_name) { + int matching_index = titleblock_template_name -> findData(template_name); + if (matching_index != -1) { + titleblock_template_name -> setCurrentIndex(matching_index); + } +} + /** Adds a row in the additional fields table if needed. */ @@ -200,13 +228,22 @@ void TitleBlockPropertiesWidget::checkTableRows() { } } +/** + Update the title block templates list. +*/ +void TitleBlockPropertiesWidget::updateTemplateList() { + if (!tbt_collection_) return; + + QString current_template_name = currentTitleBlockTemplateName(); + setTitleBlockTemplatesList(tbt_collection_ -> templates()); + setCurrentTitleBlockTemplateName(current_template_name); +} + /** Edit the currently selected title block template */ void TitleBlockPropertiesWidget::editCurrentTitleBlockTemplate() { - QString current_template_name = currentTitleBlockTemplateName(); - if (current_template_name.isEmpty()) return; - emit(editTitleBlockTemplate(current_template_name, false)); + emit(editTitleBlockTemplate(currentTitleBlockTemplateName(), false)); } /** @@ -214,9 +251,7 @@ void TitleBlockPropertiesWidget::editCurrentTitleBlockTemplate() { for a name), then edit it. */ void TitleBlockPropertiesWidget::duplicateCurrentTitleBlockTemplate() { - QString current_template_name = currentTitleBlockTemplateName(); - if (current_template_name.isEmpty()) return; - emit(editTitleBlockTemplate(current_template_name, true)); + emit(editTitleBlockTemplate(currentTitleBlockTemplateName(), true)); } /** diff --git a/sources/titleblockpropertieswidget.h b/sources/titleblockpropertieswidget.h index 5af064465..6b24b6d8d 100644 --- a/sources/titleblockpropertieswidget.h +++ b/sources/titleblockpropertieswidget.h @@ -19,6 +19,7 @@ #define TITLEBLOCK_PROPERTIES_WIDGET_H #include #include "titleblockproperties.h" +class TitleBlockTemplatesCollection; /** Ce widget permet d'editer un objet TitleBlockProperties, c'est-a-dire les valeurs affichees par le cartouche d'un schema. @@ -40,12 +41,15 @@ class TitleBlockPropertiesWidget : public QWidget { bool isReadOnly() const; void setReadOnly(bool); void setTitleBlockTemplatesList(const QList &); + void setTitleBlockTemplatesCollection(TitleBlockTemplatesCollection *); void setTitleBlockTemplatesVisible(bool); QString currentTitleBlockTemplateName() const; + void setCurrentTitleBlockTemplateName(const QString &); // slots: private slots: void checkTableRows(); + void updateTemplateList(); void editCurrentTitleBlockTemplate(); void duplicateCurrentTitleBlockTemplate(); @@ -80,5 +84,6 @@ class TitleBlockPropertiesWidget : public QWidget { QLabel *additional_fields_label; QTableWidget *additional_fields_table; QTabBar *tabbar; + TitleBlockTemplatesCollection *tbt_collection_; }; #endif