[qet] [4586] Conductor now support variables.

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


Revision: 4586
Author:   dfochi
Date:     2016-07-20 23:54:54 +0200 (Wed, 20 Jul 2016)
Log Message:
-----------
Conductor now support variables. (%F, %id, %total, %f and titleblock and project variables). Minor: labels that use %F update when folio field is changed

Modified Paths:
--------------
    trunk/sources/bordertitleblock.h
    trunk/sources/diagram.cpp
    trunk/sources/diagram.h
    trunk/sources/qetgraphicsitem/conductor.cpp
    trunk/sources/qetgraphicsitem/conductor.h

Modified: trunk/sources/bordertitleblock.h
===================================================================
--- trunk/sources/bordertitleblock.h	2016-07-20 15:07:21 UTC (rev 4585)
+++ trunk/sources/bordertitleblock.h	2016-07-20 21:54:54 UTC (rev 4586)
@@ -138,7 +138,10 @@
 		}
 	}
 	/// @param author the new value of the "Folio" field
-	void setFolio(const QString &folio) { btb_folio_ = folio; }
+	void setFolio(const QString &folio) {
+		btb_folio_ = folio;
+		emit (titleBlockFolioChanged());
+	}
 	void setFolioData(int, int, QString = NULL, const DiagramContext & = DiagramContext());
 	/// @param author the new value of the "File" field
 	void setFileName(const QString &filename) { btb_filename_ = filename; }
@@ -191,6 +194,12 @@
 		Signal emitted after the title has changed
 	*/
 	void diagramTitleChanged(const QString &);
+
+	/**
+	 @brief titleBlockFolioChanged
+		Signal emitted after Folio has changed
+	*/
+	void titleBlockFolioChanged();
 	
 	/**
 		Signal emitted when the title block requires its data to be updated in order

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2016-07-20 15:07:21 UTC (rev 4585)
+++ trunk/sources/diagram.cpp	2016-07-20 21:54:54 UTC (rev 4586)
@@ -78,6 +78,7 @@
 	connect(&border_and_titleblock, SIGNAL(needTitleBlockTemplate(const QString &)), this, SLOT(setTitleBlockTemplate(const QString &)));
 	connect(&border_and_titleblock, SIGNAL(diagramTitleChanged(const QString &)),    this, SLOT(titleChanged(const QString &)));
 	connect(&border_and_titleblock, SIGNAL(borderChanged(QRectF,QRectF)), this, SLOT(adjustSceneRect()));
+	connect(&border_and_titleblock, SIGNAL(titleBlockFolioChanged()), this, SLOT(updateLabels()));
 	adjustSceneRect();
 }
 
@@ -1057,6 +1058,22 @@
 }
 
 /**
+ * @brief Diagram::updateLabels
+ * Update elements and conductors that reference folio field
+ * in their labels.
+ */
+void Diagram::updateLabels() {
+	foreach (Element *elmt, elements()) {
+		if (elmt->elementInformations()["label"].toString().contains(("%F")))
+			elmt->updateLabel();
+	}
+	foreach (Conductor *cnd, content().conductors()) {
+		if (cnd->properties().text.contains("%F"))
+			cnd->setText(cnd->properties().text);
+	}
+}
+
+/**
 	@return le titre du cartouche
 */
 QString Diagram::title() const {

Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h	2016-07-20 15:07:21 UTC (rev 4585)
+++ trunk/sources/diagram.h	2016-07-20 21:54:54 UTC (rev 4586)
@@ -215,12 +215,13 @@
 		void titleBlockTemplateChanged(const QString &);
 		void titleBlockTemplateRemoved(const QString &, const QString & = QString());
 		void setTitleBlockTemplate(const QString &);
+		void updateLabels();
 	
 		// methods related to graphics items selection
 		void selectAll();
 		void deselectAll();
 		void invertSelection();
-	
+
 	signals:
 		void showDiagram (Diagram *);
 		void written();

Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp	2016-07-20 15:07:21 UTC (rev 4585)
+++ trunk/sources/qetgraphicsitem/conductor.cpp	2016-07-20 21:54:54 UTC (rev 4586)
@@ -1191,16 +1191,58 @@
 
 /// @return le texte du conducteur
 QString Conductor::text() const {
-	return(text_item -> toPlainText());
+	QString label = text_item->toPlainText();
+	return(label);
 }
 
 /**
+ * @brief Conductor::assignVariables
+ * Apply variables to conductor label
+ * @param label to be processed
+ * @return label with variables assigned
+ */
+QString Conductor::assignVariables(QString label) {
+	//Titleblock Variables
+		for (int i = 0; i < diagram()->border_and_titleblock.additionalFields().count(); i++)
+	{
+		QString folio_variable = diagram()->border_and_titleblock.additionalFields().keys().at(i);
+		QVariant folio_value = diagram()->border_and_titleblock.additionalFields().operator [](folio_variable);
+
+		if (label.contains(folio_variable)) {
+			label.replace("%{" + folio_variable + "}", folio_value.toString());
+			label.replace("%"  + folio_variable      , folio_value.toString());
+		}
+	}
+
+	//Project Variables
+	for (int i = 0; i < diagram()->project()->projectProperties().count(); i++)
+	{
+		QString folio_variable = diagram()->project()->projectProperties().keys().at(i);
+		QVariant folio_value = diagram()->project()->projectProperties().operator [](folio_variable);
+
+		if (label.contains(folio_variable)) {
+			label.replace("%{" + folio_variable + "}", folio_value.toString());
+			label.replace("%"  + folio_variable      , folio_value.toString());
+		}
+	}
+
+	//Default Variables
+	label.replace("%f", QString::number(diagram()->folioIndex()+1));
+	label.replace("%F", diagram() -> border_and_titleblock.folio());
+	label.replace("%id", QString::number(diagram()->folioIndex()+1));
+	label.replace("%total", QString::number(diagram()->border_and_titleblock.folioTotal()));
+	return label;
+}
+
+
+/**
  * @brief Conductor::setText
  * The text of this conductor
  * @param t
  */
 void Conductor::setText(const QString &t) {
-	text_item -> setPlainText(t);
+	QString label = assignVariables(t);
+	text_item -> setPlainText(label);
 }
 
 /**
@@ -1269,7 +1311,7 @@
  */
 void Conductor::displayedTextChanged()
 {
-	if ((text_item->toPlainText() == properties_.text) || !diagram()) return;
+	if ((text_item->toPlainText() == assignVariables(properties_.text)) || !diagram()) return;
 
 	QVariant old_value, new_value;
 	old_value.setValue(properties_);

Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h	2016-07-20 15:07:21 UTC (rev 4585)
+++ trunk/sources/qetgraphicsitem/conductor.h	2016-07-20 21:54:54 UTC (rev 4586)
@@ -92,6 +92,7 @@
 	ConductorSegment *middleSegment();
 	QPointF posForText(Qt::Orientations &flag);
 	QString text() const;
+	QString assignVariables(QString) ;
 	void setText(const QString &);
 
 	public:


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