[qet] [1479] When editing a diagram, it is now possible to edit and/ or duplicate a title block template from the title block properties dialog.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1479
Author:   xavier
Date:     2012-01-25 08:29:50 +0100 (Wed, 25 Jan 2012)
Log Message:
-----------
When editing a diagram, it is now possible to edit and/or duplicate a title block template from the title block properties dialog.

Modified Paths:
--------------
    branches/0.3/sources/diagramview.cpp
    branches/0.3/sources/diagramview.h
    branches/0.3/sources/projectview.cpp
    branches/0.3/sources/projectview.h
    branches/0.3/sources/qetapp.cpp
    branches/0.3/sources/qetapp.h
    branches/0.3/sources/qetdiagrameditor.cpp
    branches/0.3/sources/titleblock/qettemplateeditor.cpp
    branches/0.3/sources/titleblock/qettemplateeditor.h
    branches/0.3/sources/titleblockpropertieswidget.cpp
    branches/0.3/sources/titleblockpropertieswidget.h

Modified: branches/0.3/sources/diagramview.cpp
===================================================================
--- branches/0.3/sources/diagramview.cpp	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/diagramview.cpp	2012-01-25 07:29:50 UTC (rev 1479)
@@ -455,6 +455,7 @@
 	
 	// construit le dialogue
 	QDialog popup(diagramEditor());
+	popup.setWindowModality(Qt::WindowModal);
 #ifdef Q_WS_MAC
 	popup.setWindowFlags(Qt::Sheet);
 #endif
@@ -473,6 +474,8 @@
 		// we have to parse again the TitleBlockProperties object, since the
 		// first parsing did not know of our templates
 		titleblock_infos -> setTitleBlockProperties(titleblock);
+		// relay the signal that requires a title block template edition
+		connect(titleblock_infos, SIGNAL(editTitleBlockTemplate(QString, bool)), this, SIGNAL(editTitleBlockTemplate(QString, bool)));
 	}
 	titleblock_infos -> setReadOnly(diagram_is_read_only);
 	

Modified: branches/0.3/sources/diagramview.h
===================================================================
--- branches/0.3/sources/diagramview.h	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/diagramview.h	2012-01-25 07:29:50 UTC (rev 1479)
@@ -103,6 +103,8 @@
 	void findElementRequired(const ElementsLocation &);
 	/// Signal emis lorsque l'utilisateur souhaite editer un element du schema
 	void editElementRequired(const ElementsLocation &);
+	/// Signal emitted when the user wants to edit and/or duplicate an existing title block template
+	void editTitleBlockTemplate(const QString &, bool);
 	
 	public slots:
 	void selectNothing();

Modified: branches/0.3/sources/projectview.cpp
===================================================================
--- branches/0.3/sources/projectview.cpp	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/projectview.cpp	2012-01-25 07:29:50 UTC (rev 1479)
@@ -313,6 +313,7 @@
 	connect(diagram, SIGNAL(titleChanged(DiagramView *, const QString &)), this, SLOT(updateTabTitle(DiagramView *, const QString &)));
 	connect(diagram, SIGNAL(findElementRequired(const ElementsLocation &)), this, SIGNAL(findElementRequired(const ElementsLocation &)));
 	connect(diagram, SIGNAL(editElementRequired(const ElementsLocation &)), this, SIGNAL(editElementRequired(const ElementsLocation &)));
+	connect(diagram, SIGNAL(editTitleBlockTemplate(const QString &, bool)), this, SLOT(editTitleBlockTemplateRequired(const QString &, bool)));
 	
 	// signale l'ajout du schema
 	emit(diagramAdded(diagram));
@@ -808,6 +809,22 @@
 }
 
 /**
+	Require the edition of the \a template_name title blocke template.
+	@param template_name Name of the tempalte to be edited
+	@param duplicate If true, this methd will ask the user for a template name
+	in order to duplicate the \a template_name template
+*/
+void ProjectView::editTitleBlockTemplateRequired(const QString &template_name, bool duplicate) {
+	if (!project_) return;
+	emit(
+		editTitleBlockTemplate(
+			project_ -> embeddedTitleBlockTemplatesCollection() -> location(template_name),
+			duplicate
+		)
+	);
+}
+
+/**
 	@param diagram Schema a trouver
 	@return le DiagramView correspondant au schema passe en parametre, ou 0 si
 	le schema n'est pas trouve

Modified: branches/0.3/sources/projectview.h
===================================================================
--- branches/0.3/sources/projectview.h	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/projectview.h	2012-01-25 07:29:50 UTC (rev 1479)
@@ -18,6 +18,7 @@
 #ifndef PROJECT_VIEW_H
 #define PROJECT_VIEW_H
 #include <QtGui>
+#include "templatelocation.h"
 class QETProject;
 class DiagramView;
 class Diagram;
@@ -67,6 +68,7 @@
 	void updateWindowTitle();
 	void updateTabTitle(DiagramView *, const QString &);
 	void tabMoved(int, int);
+	void editTitleBlockTemplateRequired(const QString &, bool);
 	
 	signals:
 	void diagramAdded(DiagramView *);
@@ -75,9 +77,10 @@
 	void diagramActivated(DiagramView *);
 	void diagramOrderChanged(ProjectView *, int, int);
 	void projectClosed(ProjectView *);
-	// Pour relayer les signaux
+	// relayed signals
 	void findElementRequired(const ElementsLocation &);
 	void editElementRequired(const ElementsLocation &);
+	void editTitleBlockTemplate(const TitleBlockTemplateLocation &, bool);
 	
 	private:
 	void loadDiagrams();

Modified: branches/0.3/sources/qetapp.cpp
===================================================================
--- branches/0.3/sources/qetapp.cpp	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/qetapp.cpp	2012-01-25 07:29:50 UTC (rev 1479)
@@ -1013,9 +1013,14 @@
 /**
 	Launch a new title block template editor to edit the given template
 	@param location location of the title block template to be edited
+	
+	@param duplicate if true, the template is opened for duplication, which means
+	the user will be prompter for a new template name.
+	@see QETTitleBlockTemplateEditor::setOpenForDuplication()
 */
-void QETApp::openTitleBlockTemplate(const TitleBlockTemplateLocation &location) {
+void QETApp::openTitleBlockTemplate(const TitleBlockTemplateLocation &location, bool duplicate) {
 	QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
+	qet_template_editor -> setOpenForDuplication(duplicate);
 	qet_template_editor -> edit(location);
 	qet_template_editor -> showMaximized();
 }

Modified: branches/0.3/sources/qetapp.h
===================================================================
--- branches/0.3/sources/qetapp.h	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/qetapp.h	2012-01-25 07:29:50 UTC (rev 1479)
@@ -199,7 +199,7 @@
 	void openProjectFiles(const QStringList &);
 	void openElementFiles(const QStringList &);
 	void openElementLocations(const QList<ElementsLocation> &);
-	void openTitleBlockTemplate(const TitleBlockTemplateLocation &);
+	void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool = false);
 	void openTitleBlockTemplate(const QString &);
 	void configureQET();
 	void aboutQET();

Modified: branches/0.3/sources/qetdiagrameditor.cpp
===================================================================
--- branches/0.3/sources/qetdiagrameditor.cpp	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/qetdiagrameditor.cpp	2012-01-25 07:29:50 UTC (rev 1479)
@@ -1264,10 +1264,16 @@
 	
 	// gere les demandes consistant a retrouver un element dans le panel
 	connect(project_view, SIGNAL(findElementRequired(const ElementsLocation &)), this, SLOT(findElementInPanel(const ElementsLocation &)));
-
+	
 	// gere les demandes pour l'edition d'un element
 	connect(project_view, SIGNAL(editElementRequired(const ElementsLocation &)), this, SLOT(editElementInEditor(const ElementsLocation &)));
-		
+	
+	// handles requests to edit and/or duplicate an existing title block template
+	connect(
+		project_view, SIGNAL(editTitleBlockTemplate(const TitleBlockTemplateLocation &, bool)),
+		QETApp::instance(), SLOT(openTitleBlockTemplate(TitleBlockTemplateLocation, bool))
+	);
+	
 	// affiche la fenetre
 	if (maximise) project_view -> showMaximized();
 	else project_view -> show();

Modified: branches/0.3/sources/titleblock/qettemplateeditor.cpp
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-01-25 07:29:50 UTC (rev 1479)
@@ -34,6 +34,8 @@
 	QMainWindow(parent),
 	opened_from_file_(false),
 	read_only_(false),
+	duplicate_(false),
+	first_activation_(true),
 	tb_template_(0),
 	logo_manager_(0)
 {
@@ -60,6 +62,22 @@
 }
 
 /**
+	@param true for this editor to prompt the user for a new template name as
+	soon as the window appears in order to duplicate the edited one.
+*/
+void QETTitleBlockTemplateEditor::setOpenForDuplication(bool duplicate) {
+	duplicate_ = duplicate;
+}
+
+/**
+	@return true if this editor will prompt the user for a new template name as
+	soon as the window appears in order to duplicate the edited one.
+*/
+bool QETTitleBlockTemplateEditor::openForDuplication() const {
+	return(duplicate_);
+}
+
+/**
 	@return true if the currently edited template can be closed. A template can be
 	closed if it has not been modified. If the template has been modified, this
 	method asks the user what he wants to do.
@@ -89,6 +107,20 @@
 }
 
 /**
+	@param event Object describing the received event.
+*/
+bool QETTitleBlockTemplateEditor::event(QEvent *event) {
+	if (first_activation_ && event -> type() == QEvent::WindowActivate) {
+		if (duplicate_ && !opened_from_file_ && location_.isValid()) {
+			// this editor is supposed to duplicate its current location
+			QTimer::singleShot(250, this, SLOT(duplicateCurrentLocation()));
+		}
+		first_activation_ = false;
+	}
+	return(QMainWindow::event(event));
+}
+
+/**
 	Handle the closing of the main window
 	@param qce The QCloseEvent event
 */
@@ -100,6 +132,29 @@
 }
 
 /**
+	Ask the user for a new template name in order to duplicate the currently
+	edited template.
+*/
+void QETTitleBlockTemplateEditor::duplicateCurrentLocation() {
+	// this method does not work for templates edited from the filesystem
+	if (opened_from_file_) return;
+	
+	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()),
+		&accepted
+	);
+	if (accepted) {
+		TitleBlockTemplateLocation new_template_location(new_template_name, location_.parentCollection());
+		saveAs(new_template_location);
+	}
+}
+
+/**
 	@param location Location of the tile block template to be edited.
 */
 bool QETTitleBlockTemplateEditor::edit(const TitleBlockTemplateLocation &location) {
@@ -665,13 +720,14 @@
 	currently edited template, false to allow full edition.
 */
 void QETTitleBlockTemplateEditor::setReadOnly(bool read_only) {
-	if (read_only == read_only_) return;
-	read_only_ = read_only;
-	if (logo_manager_) {
-		logo_manager_ -> setReadOnly(read_only_);
+	if (read_only != read_only_) {
+		read_only_ = read_only;
+		if (logo_manager_) {
+			logo_manager_ -> setReadOnly(read_only_);
+		}
+		template_cell_editor_widget_ -> setReadOnly(read_only_);
+		template_edition_area_view_ -> setReadOnly(read_only_);
 	}
-	template_cell_editor_widget_ -> setReadOnly(read_only_);
-	template_edition_area_view_ -> setReadOnly(read_only_);
 	updateActions();
 	updateEditorTitle();
 }

Modified: branches/0.3/sources/titleblock/qettemplateeditor.h
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.h	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/titleblock/qettemplateeditor.h	2012-01-25 07:29:50 UTC (rev 1479)
@@ -60,6 +60,13 @@
 	bool opened_from_file_;
 	/// whether the currently edited template is considered read only
 	bool read_only_;
+	/**
+		Whether to ask the user a new template name when the window appears in order
+		to rename the edited template.
+	*/
+	bool duplicate_;
+	/// Used to track the first activation of the editor main window.
+	bool first_activation_;
 	/// Template Object edited
 	TitleBlockTemplate *tb_template_;
 	/// Template preview
@@ -78,9 +85,12 @@
 	// methods
 	public:
 	TitleBlockTemplateLocation location() const;
+	void setOpenForDuplication(bool);
+	bool openForDuplication() const;
 	
 	protected:
 	bool canClose();
+	bool event(QEvent *);
 	void closeEvent(QCloseEvent *);
 	
 	private:
@@ -92,6 +102,7 @@
 	
 	public slots:
 	void selectedCellsChanged(QList<TitleBlockCell *>);
+	void duplicateCurrentLocation();
 	bool edit(const TitleBlockTemplateLocation &);
 	bool edit(QETProject *, const QString &);
 	bool edit(const QString &);

Modified: branches/0.3/sources/titleblockpropertieswidget.cpp
===================================================================
--- branches/0.3/sources/titleblockpropertieswidget.cpp	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/titleblockpropertieswidget.cpp	2012-01-25 07:29:50 UTC (rev 1479)
@@ -17,7 +17,6 @@
 */
 #include "titleblockpropertieswidget.h"
 #include "qeticons.h"
-#include "qetapp.h"
 
 /**
 	Constructeur
@@ -39,6 +38,7 @@
 	// by default, we do not display the template combo box
 	titleblock_template_label -> setVisible(false);
 	titleblock_template_name  -> setVisible(false);
+	titleblock_template_button_ -> setVisible(false);
 }
 
 /// Destructeur
@@ -65,10 +65,8 @@
 		prop.date = QDate::currentDate();
 	}
 	
-	int index = titleblock_template_name -> currentIndex();
-	if (index != -1) {
-		prop.template_name = titleblock_template_name -> itemData(index).toString();
-	}
+	QString current_template_name = currentTitleBlockTemplateName();
+	if (!current_template_name.isEmpty()) prop.template_name = current_template_name;
 	
 	for (int i = 0 ; i < additional_fields_table -> rowCount() ; ++ i) {
 		QTableWidgetItem *qtwi_name  = additional_fields_table -> item(i, 0);
@@ -176,9 +174,21 @@
 void TitleBlockPropertiesWidget::setTitleBlockTemplatesVisible(bool visible) {
 	titleblock_template_name  -> setVisible(visible);
 	titleblock_template_label -> setVisible(visible);
+	titleblock_template_button_ -> setVisible(visible);
 }
 
 /**
+	@return the name of the currenlty selected title block template.
+*/
+QString TitleBlockPropertiesWidget::currentTitleBlockTemplateName() const {
+	int index = titleblock_template_name -> currentIndex();
+	if (index != -1) {
+		return(titleblock_template_name -> itemData(index).toString());
+	}
+	return(QString());
+}
+
+/**
 	Adds a row in the additional fields table if needed.
 */
 void TitleBlockPropertiesWidget::checkTableRows() {
@@ -191,11 +201,45 @@
 }
 
 /**
+	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));
+}
+
+/**
+	Duplicate the currently selected title block template (the user is asked
+	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));
+}
+
+/**
 	Builds the various child widgets for this widget
 */
 void TitleBlockPropertiesWidget::initWidgets(const TitleBlockProperties &titleblock) {
+	// actions
+	titleblock_template_edit_ = new QAction(tr("\311diter ce mod\350le", "menu entry"), this);
+	titleblock_template_duplicate_ = new QAction(tr("Dupliquer et editer ce mod\350le", "menu entry"), this);
+	
+	connect(titleblock_template_edit_, SIGNAL(triggered()), this, SLOT(editCurrentTitleBlockTemplate()));
+	connect(titleblock_template_duplicate_, SIGNAL(triggered()), this, SLOT(duplicateCurrentTitleBlockTemplate()));
+	
+	// menu
+	titleblock_template_menu_ = new QMenu(tr("Title block templates actions"));
+	titleblock_template_menu_ -> addAction(titleblock_template_edit_);
+	titleblock_template_menu_ -> addAction(titleblock_template_duplicate_);
+	
+	// widgets
 	titleblock_template_label = new QLabel(tr("Mod\350le :"), this);
 	titleblock_template_name = new QComboBox(this);
+	titleblock_template_button_ = new QPushButton(QET::Icons::TitleBlock, QString());
+	titleblock_template_button_ -> setMenu(titleblock_template_menu_);
 	
 	titleblock_title    = new QLineEdit(this);
 	titleblock_author   = new QLineEdit(this);
@@ -301,6 +345,7 @@
 	QHBoxLayout *template_layout = new QHBoxLayout();
 	template_layout -> addWidget(titleblock_template_label);
 	template_layout -> addWidget(titleblock_template_name);
+	template_layout -> addWidget(titleblock_template_button_);
 	template_layout -> setStretch(0, 1);
 	template_layout -> setStretch(1, 500);
 	

Modified: branches/0.3/sources/titleblockpropertieswidget.h
===================================================================
--- branches/0.3/sources/titleblockpropertieswidget.h	2012-01-24 07:11:19 UTC (rev 1478)
+++ branches/0.3/sources/titleblockpropertieswidget.h	2012-01-25 07:29:50 UTC (rev 1479)
@@ -41,10 +41,13 @@
 	void setReadOnly(bool);
 	void setTitleBlockTemplatesList(const QList<QString> &);
 	void setTitleBlockTemplatesVisible(bool);
+	QString currentTitleBlockTemplateName() const;
 	
 	// slots:
 	private slots:
 	void checkTableRows();
+	void editCurrentTitleBlockTemplate();
+	void duplicateCurrentTitleBlockTemplate();
 	
 	// private methods
 	private:
@@ -52,11 +55,18 @@
 	void initLayouts();
 	int nameLessRowsCount() const;
 	
+	signals:
+	void editTitleBlockTemplate(const QString &, bool);
+	
 	// attributs
 	private:
 	QStackedLayout *stack_layout;
 	QLabel       *titleblock_template_label;
 	QComboBox    *titleblock_template_name;
+	QPushButton  *titleblock_template_button_;
+	QMenu        *titleblock_template_menu_;
+	QAction      *titleblock_template_edit_;
+	QAction      *titleblock_template_duplicate_;
 	QLineEdit    *titleblock_title;
 	QLineEdit    *titleblock_author;
 	QDateEdit    *titleblock_date;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/