[qet] [1134] Added a combo box in the title block properties to choose the template that will render the title block .

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


Revision: 1134
Author:   xavier
Date:     2010-12-25 00:35:40 +0100 (Sat, 25 Dec 2010)
Log Message:
-----------
Added a combo box in the title block properties to choose the template that will render the title block.

Modified Paths:
--------------
    branches/0.3/sources/bordertitleblock.cpp
    branches/0.3/sources/bordertitleblock.h
    branches/0.3/sources/diagram.cpp
    branches/0.3/sources/diagram.h
    branches/0.3/sources/diagramview.cpp
    branches/0.3/sources/titleblockproperties.cpp
    branches/0.3/sources/titleblockproperties.h
    branches/0.3/sources/titleblockpropertieswidget.cpp
    branches/0.3/sources/titleblockpropertieswidget.h
    branches/0.3/sources/titleblocktemplate.cpp
    branches/0.3/sources/titleblocktemplate.h

Modified: branches/0.3/sources/bordertitleblock.cpp
===================================================================
--- branches/0.3/sources/bordertitleblock.cpp	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/bordertitleblock.cpp	2010-12-24 23:35:40 UTC (rev 1134)
@@ -99,6 +99,7 @@
 	ip.title = bi_title;
 	ip.folio = bi_folio;
 	ip.filename = bi_filename;
+	ip.template_name = titleBlockTemplateName();
 	return(ip);
 }
 
@@ -113,6 +114,7 @@
 	bi_filename = ip.filename;
 	updateDiagramContextForTitleBlock();
 	emit(needFolioData());
+	emit(needTitleBlockTemplate(ip.template_name));
 }
 
 /**
@@ -162,13 +164,21 @@
 }
 
 /**
+	@return The name of the template used to render the titleblock.
+*/
+QString BorderTitleBlock::titleBlockTemplateName() const {
+	QString tbt_name = titleblock_template_renderer -> titleBlockTemplate() -> name();
+	return((tbt_name == "default") ? "" : tbt_name);
+}
+
+/**
 	This slot may be used to inform this class that the given title block
 	template has changed. The title block-dedicated rendering cache will thus be
 	flushed.
 	@param template_name Name of the title block template that has changed
 */
 void BorderTitleBlock::titleBlockTemplateChanged(const QString &template_name) {
-	Q_UNUSED(template_name); // this class does not store the name of its template
+	if (titleBlockTemplateName() != template_name) return;
 	titleblock_template_renderer -> invalidateRenderedTemplate();
 }
 
@@ -181,7 +191,7 @@
 	@param new_template (Optional) title block template to use instead
 */
 void BorderTitleBlock::titleBlockTemplateRemoved(const QString &removed_template_name, const TitleBlockTemplate *new_template) {
-	Q_UNUSED(removed_template_name); // this class does not store the name of its template
+	if (titleBlockTemplateName() != removed_template_name) return;
 	
 	if (new_template) {
 		setTitleBlockTemplate(new_template);

Modified: branches/0.3/sources/bordertitleblock.h
===================================================================
--- branches/0.3/sources/bordertitleblock.h	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/bordertitleblock.h	2010-12-24 23:35:40 UTC (rev 1134)
@@ -152,6 +152,7 @@
 	
 	const TitleBlockTemplate *titleBlockTemplate();
 	void setTitleBlockTemplate(const TitleBlockTemplate *);
+	QString titleBlockTemplateName() const;
 	
 	public slots:
 	void titleBlockTemplateChanged(const QString &);
@@ -192,6 +193,13 @@
 	*/
 	void needFolioData();
 	
+	/**
+		Signal emitted when this object needs to set a specific title block
+		template. This object cannot handle the job since it does not know of
+		its parent project.
+	*/
+	void needTitleBlockTemplate(const QString &);
+	
 	// attributs
 	private:
 	// informations du cartouche

Modified: branches/0.3/sources/diagram.cpp
===================================================================
--- branches/0.3/sources/diagram.cpp	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/diagram.cpp	2010-12-24 23:35:40 UTC (rev 1134)
@@ -63,6 +63,11 @@
 	// initialise les objets gerant les deplacements
 	elements_mover_ = new ElementsMover();           // deplacements d'elements/conducteurs/textes
 	element_texts_mover_ = new ElementTextsMover();  // deplacements d'ElementTextItem
+	
+	connect(
+		&border_and_titleblock, SIGNAL(needTitleBlockTemplate(const QString &)),
+		this, SLOT(setTitleBlockTemplate(const QString &))
+	);
 }
 
 /**
@@ -272,6 +277,7 @@
 		if (!border_and_titleblock.title().isNull())     racine.setAttribute("title",    border_and_titleblock.title());
 		if (!border_and_titleblock.fileName().isNull())  racine.setAttribute("filename", border_and_titleblock.fileName());
 		if (!border_and_titleblock.folio().isNull())     racine.setAttribute("folio",    border_and_titleblock.folio());
+		
 		racine.setAttribute("cols",    border_and_titleblock.nbColumns());
 		racine.setAttribute("colsize", QString("%1").arg(border_and_titleblock.columnsWidth()));
 		racine.setAttribute("rows",    border_and_titleblock.nbRows());
@@ -280,8 +286,9 @@
 		racine.setAttribute("height",  QString("%1").arg(border_and_titleblock.diagramHeight()));
 		racine.setAttribute("displaycols", border_and_titleblock.columnsAreDisplayed() ? "true" : "false");
 		racine.setAttribute("displayrows", border_and_titleblock.rowsAreDisplayed()    ? "true" : "false");
-		if (!titleblock_template_name_.isEmpty()) {
-			racine.setAttribute("titleblocktemplate", titleblock_template_name_);
+		QString current_template_name = border_and_titleblock.titleBlockTemplateName();
+		if (!current_template_name.isEmpty()) {
+			racine.setAttribute("titleblocktemplate", current_template_name);
 		}
 		
 		// type de conducteur par defaut
@@ -422,14 +429,7 @@
 		border_and_titleblock.setDate(QDate::fromString(root.attribute("date"), "yyyyMMdd"));
 		border_and_titleblock.setFileName(root.attribute("filename"));
 		border_and_titleblock.setFolio(root.attribute("folio"));
-		if (root.hasAttribute("titleblocktemplate") && project_) {
-			QString titleblock_template_name = root.attribute("titleblocktemplate");
-			const TitleBlockTemplate *titleblock_template = project_ -> getTemplateByName(titleblock_template_name);
-			if (titleblock_template) {
-				titleblock_template_name_ = titleblock_template_name;
-				border_and_titleblock.setTitleBlockTemplate(titleblock_template);
-			}
-		}
+		setTitleBlockTemplate(root.attribute("titleblocktemplate", ""));
 		
 		bool ok;
 		// nombre de colonnes
@@ -772,9 +772,9 @@
 	@param template_name Name of the title block template that has changed
 */
 void Diagram::titleBlockTemplateChanged(const QString &template_name) {
-	if (titleblock_template_name_ == template_name) {
-		border_and_titleblock.titleBlockTemplateChanged(template_name);
-	}
+	if (border_and_titleblock.titleBlockTemplateName() != template_name) return;
+	
+	border_and_titleblock.titleBlockTemplateChanged(template_name);
 	update();
 }
 
@@ -787,15 +787,26 @@
 	@param new_template (Optional) Name of the title block template to use instead
 */
 void Diagram::titleBlockTemplateRemoved(const QString &template_name, const QString &new_template) {
-	if (titleblock_template_name_ == template_name) {
-		const TitleBlockTemplate *final_template = project_ -> getTemplateByName(new_template);
-		titleblock_template_name_ = final_template ? new_template : QString();
-		border_and_titleblock.titleBlockTemplateRemoved(template_name, final_template);
-		update();
-	}
+	if (border_and_titleblock.titleBlockTemplateName() != template_name) return;
+	
+	const TitleBlockTemplate *final_template = project_ -> getTemplateByName(new_template);
+	border_and_titleblock.titleBlockTemplateRemoved(template_name, final_template);
+	update();
 }
 
 /**
+	Set the template to use to render the title block of this diagram.
+	@param template_name Name of the title block template.
+*/
+void Diagram::setTitleBlockTemplate(const QString &template_name) {
+	if (!project_) return;
+	
+	QString current_name = border_and_titleblock.titleBlockTemplateName();
+	const TitleBlockTemplate *titleblock_template = project_ -> getTemplateByName(template_name);
+	border_and_titleblock.titleBlockTemplateRemoved(current_name, titleblock_template);
+}
+
+/**
 	Selectionne tous les objets du schema
 */
 void Diagram::selectAll() {

Modified: branches/0.3/sources/diagram.h
===================================================================
--- branches/0.3/sources/diagram.h	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/diagram.h	2010-12-24 23:35:40 UTC (rev 1134)
@@ -85,7 +85,6 @@
 	QDomDocument xml_document;
 	QETProject *project_;
 	bool read_only_;
-	QString titleblock_template_name_;
 	
 	// methodes
 	protected:
@@ -171,6 +170,7 @@
 	void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
 	void titleBlockTemplateChanged(const QString &);
 	void titleBlockTemplateRemoved(const QString &, const QString & = QString());
+	void setTitleBlockTemplate(const QString &);
 	
 	// fonctions relative a la selection sur le schema
 	void selectAll();

Modified: branches/0.3/sources/diagramview.cpp
===================================================================
--- branches/0.3/sources/diagramview.cpp	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/diagramview.cpp	2010-12-24 23:35:40 UTC (rev 1134)
@@ -426,7 +426,15 @@
 	
 	BorderPropertiesWidget *border_infos = new BorderPropertiesWidget(border, &popup);
 	border_infos -> setReadOnly(diagram_is_read_only);
+	
 	TitleBlockPropertiesWidget  *titleblock_infos  = new TitleBlockPropertiesWidget(titleblock, false, &popup);
+	if (QETProject *parent_project = scene -> project()) {
+		titleblock_infos -> setTitleBlockTemplatesList(parent_project -> embeddedTitleBlockTemplates());
+		titleblock_infos -> setTitleBlockTemplatesVisible(true);
+		// we have to parse again the TitleBlockProperties object, since the
+		// first parsing did not know of our templates
+		titleblock_infos -> setTitleBlockProperties(titleblock);
+	}
 	titleblock_infos -> setReadOnly(diagram_is_read_only);
 	
 	// boutons

Modified: branches/0.3/sources/titleblockproperties.cpp
===================================================================
--- branches/0.3/sources/titleblockproperties.cpp	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/titleblockproperties.cpp	2010-12-24 23:35:40 UTC (rev 1134)
@@ -43,7 +43,8 @@
 		ip.author == author &&\
 		ip.date == date &&\
 		ip.filename == filename &&\
-		ip.folio == folio
+		ip.folio == folio &&\
+		ip.template_name == template_name
 	);
 }
 
@@ -66,6 +67,9 @@
 	e.setAttribute("filename", filename);
 	e.setAttribute("folio",    folio);
 	e.setAttribute("date",     exportDate());
+	if (!template_name.isEmpty()) {
+		e.setAttribute("titleblocktemplate", template_name);
+	}
 }
 
 /**
@@ -78,6 +82,7 @@
 	if (e.hasAttribute("filename"))    filename = e.attribute("filename");
 	if (e.hasAttribute("folio"))       folio    = e.attribute("folio");
 	if (e.hasAttribute("date"))        setDateFromString(e.attribute("date"));
+	if (e.hasAttribute("titleblocktemplate")) template_name = e.attribute("titleblocktemplate");
 }
 
 /**

Modified: branches/0.3/sources/titleblockproperties.h
===================================================================
--- branches/0.3/sources/titleblockproperties.h	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/titleblockproperties.h	2010-12-24 23:35:40 UTC (rev 1134)
@@ -50,6 +50,7 @@
 	QString filename;         ///< Nom de fichier affiche par le cartouche
 	QString folio;            ///< Folio affiche par le cartouche
 	DateManagement useDate;   ///< Indique s'il faut utiliser ou non l'attribut date
+	QString template_name;    ///< Name of the template used to render the title block - an empty string means "the default template provided by the application"
 	
 	private:
 	QString exportDate() const;

Modified: branches/0.3/sources/titleblockpropertieswidget.cpp
===================================================================
--- branches/0.3/sources/titleblockpropertieswidget.cpp	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/titleblockpropertieswidget.cpp	2010-12-24 23:35:40 UTC (rev 1134)
@@ -16,6 +16,7 @@
 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "titleblockpropertieswidget.h"
+#include "qeticons.h"
 #include "qetapp.h"
 
 /**
@@ -32,6 +33,9 @@
 	titleblock_infos -> setMinimumSize(300, 330);
 	this_layout -> addWidget(titleblock_infos);
 	
+	titleblock_template_label = new QLabel(tr("Mod\350le :"));
+	titleblock_template_name = new QComboBox();
+	
 	titleblock_title = new QLineEdit(this);
 	titleblock_author = new QLineEdit(this);
 	
@@ -68,23 +72,28 @@
 	folio_tip -> setWordWrap(true);
 	
 	QGridLayout *layout_champs = new QGridLayout(titleblock_infos);
-	
-	layout_champs -> addWidget(new QLabel(tr("Titre : ")),   0, 0);
-	layout_champs -> addWidget(titleblock_title,                  0, 1);
-	layout_champs -> addWidget(new QLabel(tr("Auteur : ")),  1, 0);
-	layout_champs -> addWidget(titleblock_author,                 1, 1);
-	layout_champs -> addWidget(new QLabel(tr("Date : ")),    2, 0, Qt::AlignTop);
-	layout_champs -> addLayout(layout_date,                  2, 1);
-	layout_champs -> addWidget(new QLabel(tr("Fichier : ")), 3, 0);
-	layout_champs -> addWidget(titleblock_filename,               3, 1);
-	layout_champs -> addWidget(new QLabel(tr("Folio : ")),   4, 0);
-	layout_champs -> addWidget(titleblock_folio,                  4, 1);
-	layout_champs -> addWidget(folio_tip,                    5, 1, Qt::AlignTop);
+	layout_champs -> addWidget(titleblock_template_label,    0, 0);
+	layout_champs -> addWidget(titleblock_template_name,     0, 1);
+	layout_champs -> addWidget(new QLabel(tr("Titre : ")),   1, 0);
+	layout_champs -> addWidget(titleblock_title,             1, 1);
+	layout_champs -> addWidget(new QLabel(tr("Auteur : ")),  2, 0);
+	layout_champs -> addWidget(titleblock_author,            2, 1);
+	layout_champs -> addWidget(new QLabel(tr("Date : ")),    3, 0, Qt::AlignTop);
+	layout_champs -> addLayout(layout_date,                  3, 1);
+	layout_champs -> addWidget(new QLabel(tr("Fichier : ")), 4, 0);
+	layout_champs -> addWidget(titleblock_filename,          4, 1);
+	layout_champs -> addWidget(new QLabel(tr("Folio : ")),   5, 0);
+	layout_champs -> addWidget(titleblock_folio,             5, 1);
+	layout_champs -> addWidget(folio_tip,                    6, 1, Qt::AlignTop);
 	layout_champs -> setRowStretch(5, 500);
 	
 	titleblock_current_date -> setVisible(display_current_date = current);
 	setTitleBlockProperties(titleblock);
 	setLayout(this_layout);
+	
+	// by default, we do not display the template combo box
+	titleblock_template_label -> setVisible(false);
+	titleblock_template_name  -> setVisible(false);
 }
 
 /// Destructeur
@@ -110,6 +119,12 @@
 		prop.useDate = TitleBlockProperties::CurrentDate;
 		prop.date = QDate::currentDate();
 	}
+	
+	int index = titleblock_template_name -> currentIndex();
+	if (index != -1) {
+		prop.template_name = titleblock_template_name -> itemData(index).toString();
+	}
+	
 	return(prop);
 }
 
@@ -146,6 +161,13 @@
 			}
 		}
 	}
+	
+	if (!titleblock.template_name.isEmpty()) {
+		int matching_index = titleblock_template_name -> findData(titleblock.template_name);
+		if (matching_index != -1) {
+			titleblock_template_name -> setCurrentIndex(matching_index);
+		}
+	}
 }
 
 /**
@@ -174,4 +196,27 @@
 	titleblock_no_date      -> setDisabled(ro);
 	titleblock_current_date -> setDisabled(ro);
 	titleblock_fixed_date   -> setDisabled(ro);
+	titleblock_template_label -> setDisabled(ro);
+	titleblock_template_name  -> setDisabled(ro);
 }
+
+/**
+	@param templates List of template names the dedicated combo box should
+	display.
+*/
+void TitleBlockPropertiesWidget::setTitleBlockTemplatesList(const QList<QString> &templates) {
+	titleblock_template_name -> clear();
+	titleblock_template_name -> addItem(QET::Icons::TitleBlock, tr("Mod\350le par d\351faut"), QString());
+	foreach (QString template_name, templates) {
+		titleblock_template_name -> addItem(QET::Icons::TitleBlock, template_name, template_name);
+	}
+}
+
+/**
+	@param visible true to display the title block templates list, false to
+	hide it.
+*/
+void TitleBlockPropertiesWidget::setTitleBlockTemplatesVisible(bool visible) {
+	titleblock_template_name  -> setVisible(visible);
+	titleblock_template_label -> setVisible(visible);
+}

Modified: branches/0.3/sources/titleblockpropertieswidget.h
===================================================================
--- branches/0.3/sources/titleblockpropertieswidget.h	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/titleblockpropertieswidget.h	2010-12-24 23:35:40 UTC (rev 1134)
@@ -39,6 +39,8 @@
 	bool displayCurrentDate() const;
 	bool isReadOnly() const;
 	void setReadOnly(bool);
+	void setTitleBlockTemplatesList(const QList<QString> &);
+	void setTitleBlockTemplatesVisible(bool);
 	
 	// attributs
 	private:
@@ -51,5 +53,7 @@
 	QRadioButton *titleblock_current_date;
 	QRadioButton *titleblock_fixed_date;
 	bool display_current_date;
+	QLabel       *titleblock_template_label;
+	QComboBox    *titleblock_template_name;
 };
 #endif

Modified: branches/0.3/sources/titleblocktemplate.cpp
===================================================================
--- branches/0.3/sources/titleblocktemplate.cpp	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/titleblocktemplate.cpp	2010-12-24 23:35:40 UTC (rev 1134)
@@ -66,6 +66,10 @@
 	if (xml_element.tagName() != "titleblocktemplate") {
 		return(false);
 	}
+	if (!xml_element.hasAttribute("name")) {
+		return(false);
+	}
+	name_ = xml_element.attribute("name");
 	
 	loadLogos(xml_element, true);
 	loadGrid(xml_element);
@@ -422,6 +426,13 @@
 }
 
 /**
+	@return the name of this template
+*/
+QString TitleBlockTemplate::name() const {
+	return(name_);
+}
+
+/**
 	@param total_width The total width of the titleblock to render
 	@return the list of the columns widths for this rendering
 */

Modified: branches/0.3/sources/titleblocktemplate.h
===================================================================
--- branches/0.3/sources/titleblocktemplate.h	2010-12-24 21:00:11 UTC (rev 1133)
+++ branches/0.3/sources/titleblocktemplate.h	2010-12-24 23:35:40 UTC (rev 1134)
@@ -57,8 +57,7 @@
 	public:
 	bool loadFromXmlFile(const QString &);
 	bool loadFromXmlElement(const QDomElement &);
-	void setContext(const DiagramContext &);
-	
+	QString name() const;
 	QList<int> columnsWidth(int) const;
 	int height() const;
 	
@@ -83,6 +82,7 @@
 	// attributs
 	private:
 	QDomDocument xml_description_;
+	QString name_;
 	QHash<QString, QSvgRenderer *> vector_logos_;
 	QHash<QString, QPixmap *>      bitmap_logos_;
 	QList<int> rows_heights_;


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