[qet] qet/qet: [4772] Element : variable assignement of label is now managed by an external class instead of the element itself

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


Revision: 4772
Author:   blacksun
Date:     2016-11-09 17:06:04 +0100 (Wed, 09 Nov 2016)
Log Message:
-----------
Element : variable assignement of label is now managed by an external class instead of the element itself

Modified Paths:
--------------
    trunk/sources/diagramcontext.h
    trunk/sources/nomenclature.cpp
    trunk/sources/qetgraphicsitem/commentitem.cpp
    trunk/sources/qetgraphicsitem/crossrefitem.cpp
    trunk/sources/qetgraphicsitem/element.cpp
    trunk/sources/qetgraphicsitem/element.h
    trunk/sources/qetgraphicsitem/masterelement.cpp
    trunk/sources/qetgraphicsitem/reportelement.cpp
    trunk/sources/qetgraphicsitem/simpleelement.cpp
    trunk/sources/qetgraphicsitem/slaveelement.cpp
    trunk/sources/qetgraphicsitem/terminalelement.cpp
    trunk/sources/ui/elementselectorwidget.cpp

Added Paths:
-----------
    trunk/sources/autoNum/assignvariables.cpp
    trunk/sources/autoNum/assignvariables.h

Added: trunk/sources/autoNum/assignvariables.cpp
===================================================================
--- trunk/sources/autoNum/assignvariables.cpp	                        (rev 0)
+++ trunk/sources/autoNum/assignvariables.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -0,0 +1,135 @@
+/*
+	Copyright 2006-2016 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "assignvariables.h"
+#include "diagram.h"
+#include "element.h"
+#include "diagramposition.h"
+#include <QVariant>
+
+namespace autonum
+{
+	/**
+	 * @brief AssignVariables::formulaToLabel
+	 * Return the @formula with variable assigned (ready to be displayed)
+	 * @param formula - the formula to work
+	 * @param seqStruct - struct where is stocked int values (struct is passed as a reference and modified by this static method)
+	 * @param diagram - the diagram where occure the formula.
+	 * @param elmt - parent element (if any) of the formula
+	 * @return the string with variable assigned.
+	 */
+	QString AssignVariables::formulaToLabel(QString formula, sequenceStruct &seqStruct, Diagram *diagram, Element *elmt)
+	{
+		AssignVariables av(formula, seqStruct, diagram, elmt);
+		seqStruct = av.m_seq_struct;
+		return av.m_assigned_label;
+	}
+
+	AssignVariables::AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, Element *elmt):
+	m_arg_formula(formula),
+	m_assigned_label(formula),
+	m_diagram(diagram),
+	m_seq_struct(seqStruct),
+	m_element(elmt)
+	{
+		if (m_diagram)
+		{
+			m_assigned_label.replace("%f",     QString::number(m_diagram->folioIndex()+1));
+			m_assigned_label.replace("%id",    QString::number(m_diagram->folioIndex()+1));
+			m_assigned_label.replace("%total", QString::number(m_diagram->border_and_titleblock.folioTotal()));
+			m_assigned_label.replace("%F",  m_diagram -> border_and_titleblock.folio());
+			m_assigned_label.replace("%M",  m_diagram -> border_and_titleblock.machine());
+			m_assigned_label.replace("%LM", m_diagram -> border_and_titleblock.locmach());
+
+
+			if (m_element)
+			{
+				m_assigned_label.replace("%c", QString::number(m_diagram->convertPosition(m_element->scenePos()).number()));
+				m_assigned_label.replace("%l", m_diagram->convertPosition(m_element->scenePos()).letter());
+				m_assigned_label.replace("%prefix", m_element->getPrefix());
+			}
+
+			assignTitleBlockVar();
+			assignProjectVar();
+			assignSequence();
+		}
+	}
+
+	void AssignVariables::assignTitleBlockVar()
+	{
+		for (int i = 0; i < m_diagram->border_and_titleblock.additionalFields().count(); i++)
+		{
+			QString folio_variable = m_diagram->border_and_titleblock.additionalFields().keys().at(i);
+			QVariant folio_value = m_diagram->border_and_titleblock.additionalFields().operator [](folio_variable);
+
+			if (m_assigned_label.contains(folio_variable)) {
+				m_assigned_label.replace("%{" + folio_variable + "}", folio_value.toString());
+				m_assigned_label.replace("%"  + folio_variable      , folio_value.toString());
+			}
+		}
+	}
+
+	void AssignVariables::assignProjectVar()
+	{
+		for (int i = 0; i < m_diagram->project()->projectProperties().count(); i++)
+		{
+			QString folio_variable = m_diagram->project()->projectProperties().keys().at(i);
+			QVariant folio_value = m_diagram->project()->projectProperties().operator [](folio_variable);
+
+			if (m_assigned_label.contains(folio_variable)) {
+				m_assigned_label.replace("%{" + folio_variable + "}", folio_value.toString());
+				m_assigned_label.replace("%"  + folio_variable      , folio_value.toString());
+			}
+		}
+	}
+
+	void AssignVariables::assignSequence()
+	{
+		int max = qMax(
+						qMax(
+							qMax(m_seq_struct.unit_folio.size(),
+								 m_seq_struct.ten_folio.size()),
+							qMax(m_seq_struct.hundred_folio.size(),
+								 m_seq_struct.unit.size())),
+						qMax(m_seq_struct.hundred.size(),
+							 m_seq_struct.ten.size())
+					);
+
+		for (int i=1; i<=max ; i++)
+		{
+			if (m_assigned_label.contains("%sequ_" + QString::number(i)) && !m_seq_struct.unit.isEmpty()) {
+				m_assigned_label.replace("%sequ_" + QString::number(i),m_seq_struct.unit.at(i-1));
+			}
+			if (m_assigned_label.contains("%seqt_" + QString::number(i)) && !m_seq_struct.ten.isEmpty()) {
+				m_assigned_label.replace("%seqt_" + QString::number(i),m_seq_struct.ten.at(i-1));
+			}
+			if (m_assigned_label.contains("%seqh_" + QString::number(i)) && !m_seq_struct.hundred.isEmpty()) {
+				m_assigned_label.replace("%seqh_" + QString::number(i),m_seq_struct.hundred.at(i-1));
+			}
+			if (m_assigned_label.contains("%sequf_" + QString::number(i)) && !m_seq_struct.unit_folio.isEmpty()) {
+				m_assigned_label.replace("%sequf_" + QString::number(i),m_seq_struct.unit_folio.at(i-1));
+			}
+			if (m_assigned_label.contains("%seqtf_" + QString::number(i)) && !m_seq_struct.ten_folio.isEmpty()) {
+				m_assigned_label.replace("%seqtf_" + QString::number(i),m_seq_struct.ten_folio.at(i-1));
+			}
+			if (m_assigned_label.contains("%seqhf_" + QString::number(i)) && !m_seq_struct.hundred_folio.isEmpty()) {
+				m_assigned_label.replace("%seqhf_" + QString::number(i),m_seq_struct.hundred_folio.at(i-1));
+			}
+		}
+	}
+
+}

Added: trunk/sources/autoNum/assignvariables.h
===================================================================
--- trunk/sources/autoNum/assignvariables.h	                        (rev 0)
+++ trunk/sources/autoNum/assignvariables.h	2016-11-09 16:06:04 UTC (rev 4772)
@@ -0,0 +1,66 @@
+/*
+	Copyright 2006-2016 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef ASSIGNVARIABLES_H
+#define ASSIGNVARIABLES_H
+
+#include <QString>
+#include <QPointF>
+#include <QStringList>
+
+class Diagram;
+class Element;
+
+namespace autonum
+{
+	struct sequenceStruct {
+			QStringList unit;
+			QStringList unit_folio;
+			QStringList ten;
+			QStringList ten_folio;
+			QStringList hundred;
+			QStringList hundred_folio;
+	};
+
+	/**
+	 * @brief The AssignVariables class
+	 * This class assign variable of a formula string.
+	 * Return the final string used to be displayed from a formula string.
+	 */
+	class AssignVariables
+	{
+		public:
+			static QString formulaToLabel (QString formula, sequenceStruct &seqStruct, Diagram *diagram, Element *elmt = nullptr);
+
+		private:
+			AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, Element *elmt = nullptr);
+			void assignTitleBlockVar();
+			void assignProjectVar();
+			void assignSequence();
+
+			Diagram *m_diagram  = nullptr;
+			QString m_arg_formula;
+			QString m_assigned_label;
+			sequenceStruct m_seq_struct;
+			Element *m_element = nullptr;
+	};
+
+
+
+}
+
+#endif // ASSIGNVARIABLES_H

Modified: trunk/sources/diagramcontext.h
===================================================================
--- trunk/sources/diagramcontext.h	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/diagramcontext.h	2016-11-09 16:06:04 UTC (rev 4772)
@@ -26,8 +26,24 @@
 /**
 	This class represents a diagram context, i.e. the data (a list of key/value
 	pairs) of a diagram at a given time. It is notably used by titleblock templates
-	to fetch the informations they need to do their rendering.
+	to fetch the informations they need to do their rendering, or element for retrieve information about itself
 */
+
+/**
+ * Key for element :
+ * label                          -> label or identification of element
+ * designation                    -> exhaustive comment used to explain what the element does.
+ * comment                        -> a little comment wich can be displayed in the folio
+ * manufacturer                   -> the manufacturer of the element
+ * manufacturer-reference         -> the manufacturer reference of the element
+ * auxiliary1                     -> auxiliary 1 of element
+ * auxiliary2                     -> auxiliary 2 of element
+ * machine-manufacturer-reference -> reference of the manufacturer machine
+ * function                       -> the function of element
+ * location                       -> the location of the element
+ * frozenLabel                    -> label locked at a given time
+ *
+ */
 class DiagramContext {
 	public:
 	enum KeyOrder {

Modified: trunk/sources/nomenclature.cpp
===================================================================
--- trunk/sources/nomenclature.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/nomenclature.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -19,6 +19,7 @@
 
 #include "nomenclature.h"
 #include "elementprovider.h"
+#include "assignvariables.h"
 #define PR(x) qDebug() << #x " = " << x;
 
 /**
@@ -101,24 +102,24 @@
 
 	if(m_list_diagram.isEmpty()) return data;
 
-	foreach (Diagram *d, m_list_diagram) {
-		//Get only simple, master and unlinked slave element.
-		ElementProvider ep(d);
-		QSettings settings;
-		QList <Element *> list_elements;
-		
-		if (settings.value("nomenclature/terminal-exportlist", true).toBool()){
-		list_elements << ep.find(Element::Simple | Element::Master | Element::Terminale);
-		
-		}else{
-		
-		list_elements << ep.find(Element::Simple | Element::Master);
-		
-		}
-		
-		list_elements << ep.freeElement(Element::Slave);
-
-		foreach (Element *elmt, list_elements) {
+	foreach (Diagram *d, m_list_diagram) {
+		//Get only simple, master and unlinked slave element.
+		ElementProvider ep(d);
+		QSettings settings;
+		QList <Element *> list_elements;
+		
+		if (settings.value("nomenclature/terminal-exportlist", true).toBool()){
+		list_elements << ep.find(Element::Simple | Element::Master | Element::Terminale);
+		
+		}else{
+		
+		list_elements << ep.find(Element::Simple | Element::Master);
+		
+		}
+		
+		list_elements << ep.freeElement(Element::Slave);
+
+		foreach (Element *elmt, list_elements) {
 			data += getElementInfo(elmt);
 		}
 	}
@@ -142,15 +143,16 @@
 	info += diagram -> border_and_titleblock.folio() + ";";
 	info += elmt -> name() + ";";
 	info += elmt-> diagram()-> convertPosition(elmt -> scenePos()).toString() + ";";
-	info += elmt->assignVariables(elmt_info["label"].toString(), elmt) + ";";
-	info += elmt->assignVariables(elmt_info["designation"].toString(), elmt) + ";";
-	info += elmt->assignVariables(elmt_info["comment"].toString(), elmt) + ";";
-	info += elmt->assignVariables(elmt_info["manufacturer"].toString(), elmt) + ";";
-	info += elmt->assignVariables(elmt_info["manufacturer-reference"].toString(), elmt) + ";";
-	info += elmt->assignVariables(elmt_info["auxiliary1"].toString(), elmt) + ";";
-	info += elmt->assignVariables(elmt_info["auxiliary2"].toString(), elmt) + ";";
-	info += elmt->assignVariables(elmt_info["machine-manufacturer-reference"].toString(), elmt) + ";";
-	info += elmt->assignVariables(elmt_info["location"].toString(), elmt) + ";";
-	info += elmt->assignVariables(elmt_info["function"].toString(), elmt) + "\n";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["label"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["designation"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["comment"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["manufacturer"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["manufacturer-reference"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["auxiliary1"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["auxiliary2"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["machine-manufacturer-reference"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["location"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
+	info += autonum::AssignVariables::formulaToLabel(elmt_info["function"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + "\n";
+
 	return info;
 }

Modified: trunk/sources/qetgraphicsitem/commentitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/commentitem.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/qetgraphicsitem/commentitem.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -151,9 +151,9 @@
  * Draw Info to item text.
  * (draw this item in a QPicture)
  */
-void CommentItem::addInfo(QPainter &painter, QString type){
-
-	QString text = m_element -> assignVariables(m_element -> elementInformations()[type].toString(), m_element);
+void CommentItem::addInfo(QPainter &painter, QString type)
+{
+	QString text = autonum::AssignVariables::formulaToLabel(m_element -> elementInformations()[type].toString(), m_element->rSequenceStruct(), m_element->diagram(), m_element);
 	bool must_show  = m_element -> elementInformations().keyMustShow(type);
 
 	if (!text.isEmpty() && must_show)

Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -539,7 +539,7 @@
  */
 void CrossRefItem::AddExtraInfo(QPainter &painter, QString type)
 {
-	QString text = m_element -> assignVariables(m_element -> elementInformations()[type].toString(), m_element);
+	QString text = autonum::AssignVariables::formulaToLabel(m_element -> elementInformations()[type].toString(), m_element->rSequenceStruct(), m_element->diagram(), m_element);
 	bool must_show  = m_element -> elementInformations().keyMustShow(type);
 
 	if (!text.isEmpty() && must_show)

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/qetgraphicsitem/element.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -430,12 +430,12 @@
 	m_prefix = e.attribute("prefix");
 
 	//Load Sequential Values
-	loadSequential(&e,"sequ_",&seq_unit);
-	loadSequential(&e,"sequf_",&seq_unitfolio);
-	loadSequential(&e,"seqt_",&seq_ten);
-	loadSequential(&e,"seqtf_",&seq_tenfolio);
-	loadSequential(&e,"seqh_",&seq_hundred);
-	loadSequential(&e,"seqhf_",&seq_hundredfolio);
+	loadSequential(&e,"sequ_",&m_autoNum_seq.unit);
+	loadSequential(&e,"sequf_",&m_autoNum_seq.unit_folio);
+	loadSequential(&e,"seqt_",&m_autoNum_seq.ten);
+	loadSequential(&e,"seqtf_",&m_autoNum_seq.ten_folio);
+	loadSequential(&e,"seqh_",&m_autoNum_seq.hundred);
+	loadSequential(&e,"seqhf_",&m_autoNum_seq.hundred_folio);
 
 	//load informations
 	m_element_informations.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
@@ -492,33 +492,33 @@
 
 	// Save Element sequential values to Xml
 	// Save Unit Sequential Values
-	for (int i = 0; i < seq_unit.size(); i++) {
-			element.setAttribute("sequ_" + QString::number(i+1),seq_unit.at(i));
+	for (int i = 0; i < m_autoNum_seq.unit.size(); i++) {
+			element.setAttribute("sequ_" + QString::number(i+1),m_autoNum_seq.unit.at(i));
 	}
 
 	// Save UnitFolio Sequential Values
-	for (int i = 0; i < seq_unitfolio.size(); i++) {
-			element.setAttribute("sequf_" + QString::number(i+1),seq_unitfolio.at(i));
+	for (int i = 0; i < m_autoNum_seq.unit_folio.size(); i++) {
+			element.setAttribute("sequf_" + QString::number(i+1),m_autoNum_seq.unit_folio.at(i));
 	}
 
 	// Save Ten Sequential Values
-	for (int i = 0; i < seq_ten.size(); i++) {
-			element.setAttribute("seqt_" + QString::number(i+1),seq_ten.at(i));
+	for (int i = 0; i < m_autoNum_seq.ten.size(); i++) {
+			element.setAttribute("seqt_" + QString::number(i+1),m_autoNum_seq.ten.at(i));
 	}
 
 	// Save TenFolio Sequential Values
-	for (int i = 0; i < seq_tenfolio.size(); i++) {
-			element.setAttribute("seqtf_" + QString::number(i+1),seq_tenfolio.at(i));
+	for (int i = 0; i < m_autoNum_seq.ten_folio.size(); i++) {
+			element.setAttribute("seqtf_" + QString::number(i+1),m_autoNum_seq.ten_folio.at(i));
 	}
 
 	// Save Hundred Sequential Values
-	for (int i = 0; i < seq_hundred.size(); i++) {
-			element.setAttribute("seqh_" + QString::number(i+1),seq_hundred.at(i));
+	for (int i = 0; i < m_autoNum_seq.hundred.size(); i++) {
+			element.setAttribute("seqh_" + QString::number(i+1),m_autoNum_seq.hundred.at(i));
 	}
 
 	// Save Hundred Sequential Values
-	for (int i = 0; i < seq_hundredfolio.size(); i++) {
-			element.setAttribute("seqhf_" + QString::number(i+1),seq_hundredfolio.at(i));
+	for (int i = 0; i < m_autoNum_seq.hundred_folio.size(); i++) {
+			element.setAttribute("seqhf_" + QString::number(i+1),m_autoNum_seq.hundred_folio.at(i));
 	}
 	
 	// position, selection et orientation
@@ -720,52 +720,6 @@
 }
 
 /**
- * @brief Element::assignVariables()
- * Assign variables values
- * @param label, string to be changed
- * @param elmt, element to extract variables values
- */
-QString Element::assignVariables(QString label, Element *elmt){
-
-	//Titleblock Variables
-	for (int i = 0; i < elmt->diagram()->border_and_titleblock.additionalFields().count(); i++)
-	{
-		QString folio_variable = elmt->diagram()->border_and_titleblock.additionalFields().keys().at(i);
-		QVariant folio_value = elmt->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 < elmt->diagram()->project()->projectProperties().count(); i++)
-	{
-		QString folio_variable = elmt->diagram()->project()->projectProperties().keys().at(i);
-		QVariant folio_value = elmt->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(elmt->diagram()->folioIndex()+1));
-	label.replace("%F", elmt->diagram() -> border_and_titleblock.folio());
-	label.replace("%M", elmt->diagram() -> border_and_titleblock.machine());
-	label.replace("%LM", elmt->diagram() -> border_and_titleblock.locmach());
-	label.replace("%c", QString::number(elmt->diagram() -> convertPosition(elmt -> scenePos()).number()));
-	label.replace("%l", elmt->diagram() -> convertPosition(elmt -> scenePos()).letter());
-	label.replace("%id", QString::number(elmt->diagram()->folioIndex()+1));
-	label.replace("%total", QString::number(elmt->diagram()->border_and_titleblock.folioTotal()));
-	label.replace("%prefix", elmt->getPrefix());
-	label = assignSeq(label, elmt);
-	return label;
-}
-
-/**
  * @brief Element::setSequential
  * Set sequential values to element
  */
@@ -778,22 +732,22 @@
 	NumerotationContextCommands ncc (nc);
 	if (!nc.isEmpty()) {
 		if (label.contains("%sequ_"))
-			setSequentialToList(&seq_unit,&nc,"unit");
+			setSequentialToList(&m_autoNum_seq.unit,&nc,"unit");
 		if (label.contains("%sequf_")) {
-			setSequentialToList(&seq_unitfolio,&nc,"unitfolio");
-			setFolioSequentialToHash(&seq_unitfolio,&diagram()->m_elmt_unitfolio_max,element_currentAutoNum);
+			setSequentialToList(&m_autoNum_seq.unit_folio,&nc,"unitfolio");
+			setFolioSequentialToHash(&m_autoNum_seq.unit_folio,&diagram()->m_elmt_unitfolio_max,element_currentAutoNum);
 		}
 		if (label.contains("%seqt_"))
-			setSequentialToList(&seq_ten,&nc,"ten");
+			setSequentialToList(&m_autoNum_seq.ten,&nc,"ten");
 		if (label.contains("%seqtf_")) {
-			setSequentialToList(&seq_tenfolio,&nc,"tenfolio");
-			setFolioSequentialToHash(&seq_tenfolio,&diagram()->m_elmt_tenfolio_max,element_currentAutoNum);
+			setSequentialToList(&m_autoNum_seq.ten_folio,&nc,"tenfolio");
+			setFolioSequentialToHash(&m_autoNum_seq.ten_folio,&diagram()->m_elmt_tenfolio_max,element_currentAutoNum);
 		}
 		if (label.contains("%seqh_"))
-			setSequentialToList(&seq_hundred,&nc,"hundred");
+			setSequentialToList(&m_autoNum_seq.hundred,&nc,"hundred");
 		if (label.contains("%seqhf_")) {
-			setSequentialToList(&seq_hundredfolio,&nc,"hundredfolio");
-			setFolioSequentialToHash(&seq_hundredfolio,&diagram()->m_elmt_hundredfolio_max,element_currentAutoNum);
+			setSequentialToList(&m_autoNum_seq.hundred_folio,&nc,"hundredfolio");
+			setFolioSequentialToHash(&m_autoNum_seq.hundred_folio,&diagram()->m_elmt_hundredfolio_max,element_currentAutoNum);
 		}
 	this->diagram()->project()->addElementAutoNum(element_currentAutoNum,ncc.next());
 	}
@@ -849,38 +803,6 @@
 }
 
 /**
- * @brief Element::assignSeq
- * Replace sequential values to element label
- * @param label to be replaced
- * @return replaced label
- */
-QString Element::assignSeq(QString label, Element* elmt) {
-	for (int i = 1; i <= qMax(qMax(qMax(elmt->seq_unitfolio.size(), elmt->seq_tenfolio.size()),qMax(elmt->seq_hundredfolio.size(),elmt->seq_unit.size())),qMax(elmt->seq_hundred.size(),elmt->seq_ten.size())); i++) {
-		// "&& !seq.isEmpty()" introduced in the methods below to avoid crash when copying and paste elements
-		// that contain folio sequential in their labels. Needs further debugging.
-		if (label.contains("%sequ_" + QString::number(i)) && !elmt->seq_unit.isEmpty()) {
-			label.replace("%sequ_" + QString::number(i),elmt->seq_unit.at(i-1));
-		}
-		if (label.contains("%seqt_" + QString::number(i)) && !elmt->seq_ten.isEmpty()) {
-			label.replace("%seqt_" + QString::number(i),elmt->seq_ten.at(i-1));
-		}
-		if (label.contains("%seqh_" + QString::number(i)) && !elmt->seq_hundred.isEmpty()) {
-			label.replace("%seqh_" + QString::number(i),elmt->seq_hundred.at(i-1));
-		}
-		if (label.contains("%sequf_" + QString::number(i)) && !elmt->seq_unitfolio.isEmpty()) {
-			label.replace("%sequf_" + QString::number(i),elmt->seq_unitfolio.at(i-1));
-		}
-		if (label.contains("%seqtf_" + QString::number(i)) && !elmt->seq_tenfolio.isEmpty()) {
-			label.replace("%seqtf_" + QString::number(i),elmt->seq_tenfolio.at(i-1));
-		}
-		if (label.contains("%seqhf_" + QString::number(i)) && !elmt->seq_hundredfolio.isEmpty()) {
-			label.replace("%seqhf_" + QString::number(i),elmt->seq_hundredfolio.at(i-1));
-		}
-	}
-	return label;
-}
-
-/**
  * @brief ElementTextItem::setTaggedText
  * Set text @newstr to the text tagged with @tagg.
  * If tagg is found return the text item, else return NULL.
@@ -917,11 +839,14 @@
  * @brief Element::freezeLabel
  * Freeze this element label
  */
-void Element::freezeLabel() {
+void Element::freezeLabel()
+{
 	DiagramContext &dc = this->rElementInformations();
 	QString freezelabel = dc["label"].toString();
-	QString label = assignVariables(freezelabel,this);
-	if (!(label == freezelabel)) {
+	QString label = autonum::AssignVariables::formulaToLabel(freezelabel, m_autoNum_seq, diagram(),this );
+
+	if (!(label == freezelabel))
+	{
 		dc.addValue("frozenlabel", freezelabel);
 		dc.addValue("label",label);
 		this->setTaggedText("label", label);
@@ -933,14 +858,14 @@
  * @brief Element::unfreezeLabel
  * Unfreeze this element label
  */
-void Element::unfreezeLabel() {
+void Element::unfreezeLabel()
+{
 	DiagramContext &dc = this->rElementInformations();
-	QString label = dc["label"].toString();
 	QString frozenlabel = dc["frozenlabel"].toString();
 	if (frozenlabel == "") return;
 	dc.addValue("frozenlabel", "");
 	dc.addValue("label",frozenlabel);
-	frozenlabel = assignVariables(frozenlabel,this);
+	frozenlabel = autonum::AssignVariables::formulaToLabel(frozenlabel, m_autoNum_seq, diagram(),this );
 	this->setTaggedText("label", frozenlabel);
 	this->setElementInformations(dc);
 }

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/qetgraphicsitem/element.h	2016-11-09 16:06:04 UTC (rev 4772)
@@ -21,6 +21,7 @@
 #include "qet.h"
 #include "qetgraphicsitem.h"
 #include "diagramcontext.h"
+#include "assignvariables.h"
 
 class ElementTextItem;
 class QETProject;
@@ -134,8 +135,10 @@
 		DiagramContext  kindInformations       () const             {return kind_informations_;}	//@kind_information_ is used to store more information
 																									//about the herited class like contactelement for know
 																									// kind of contact (simple tempo) or number of contact show by the element.
-		QString assignVariables (QString, Element *);
-		QString assignSeq (QString, Element*);
+
+		autonum::sequenceStruct sequenceStruct () const {return m_autoNum_seq;}
+		autonum::sequenceStruct& rSequenceStruct()      {return m_autoNum_seq;}
+
 		void setSequential ();
 		void setSequentialToList(QStringList*, NumerotationContext*, QString);
 		void setFolioSequentialToHash(QStringList*, QHash<QString, QStringList>*, QString);
@@ -148,6 +151,7 @@
 	//ATTRIBUTES
 	protected:
 		DiagramContext m_element_informations, kind_informations_;
+		autonum::sequenceStruct m_autoNum_seq;
 
 	/**
 		Draw this element
@@ -187,14 +191,6 @@
 
 	// orientation-related methods
 	int orientation() const;
-	
-	// Lists containing Sequentials
-	QStringList seq_unit;
-	QStringList seq_unitfolio;
-	QStringList seq_ten;
-	QStringList seq_tenfolio;
-	QStringList seq_hundred;
-	QStringList seq_hundredfolio;
 
 	protected:
 		void drawAxes(QPainter *, const QStyleOptionGraphicsItem *);

Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -129,7 +129,7 @@
  */
 void MasterElement::folioIdChange() {
 	DiagramContext dc =elementInformations();
-	setTaggedText("label", assignVariables(dc["label"].toString(), this), true);
+	setTaggedText("label", autonum::AssignVariables::formulaToLabel(dc["label"].toString(), m_autoNum_seq, diagram(), this), true);
 }
 
 /**
@@ -151,8 +151,7 @@
  */
 void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info) {
 	QString newstr = new_info["label"].toString();
-	Element	*elmt = this;
-	newstr = assignVariables(newstr, elmt);
+	newstr = autonum::AssignVariables::formulaToLabel(newstr, m_autoNum_seq, diagram(), this);
 
 		//Label of element
 	if (old_info["label"].toString() != newstr) {

Modified: trunk/sources/qetgraphicsitem/reportelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/qetgraphicsitem/reportelement.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -219,7 +219,7 @@
 	{
 		Element *elmt = connected_elements.at(0);
 		QString label = label_;
-		label = assignVariables(label,elmt);
+		label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
 		m_text_field -> setPlainText(label);
 	}
 	else

Modified: trunk/sources/qetgraphicsitem/simpleelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/qetgraphicsitem/simpleelement.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -61,9 +61,10 @@
  * @brief SimpleElement::folioIdChange
  * Use to update the label of this item when the foio id change
  */
-void SimpleElement::folioIdChange() {
+void SimpleElement::folioIdChange()
+{
 	DiagramContext dc =elementInformations();
-	setTaggedText("label", assignVariables(dc["label"].toString(), this), true);
+	setTaggedText("label", autonum::AssignVariables::formulaToLabel(dc["label"].toString(), m_autoNum_seq, diagram(), this));
 }
 
 /**
@@ -82,10 +83,9 @@
  * @brief SimpleElement::updateLabel
  * update label of this element
  */
-void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info) {
-	QString label = new_info["label"].toString();
-	Element *elmt = this;
-	label = assignVariables(label,elmt);
+void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
+{
+	QString label = autonum::AssignVariables::formulaToLabel(new_info["label"].toString(), m_autoNum_seq, diagram(), this);
 
 		//Label of element
 	if (old_info["label"].toString() != label) {

Modified: trunk/sources/qetgraphicsitem/slaveelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/slaveelement.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/qetgraphicsitem/slaveelement.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -134,16 +134,17 @@
 	bool no_editable = false;
 
 	//must be linked to set the label of master
-	if (linkedElements().count()) {
+	if (linkedElements().count())
+	{
 		no_editable = true;
 		Element *elmt = linkedElements().first();
 		label = elmt -> elementInformations()["label"].toString();
 		XRefProperties xrp = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
 		Xreflabel = xrp.slaveLabel();
-		Xreflabel = assignVariables(Xreflabel, elmt);
-		label = assignVariables(label, elmt);
+		Xreflabel = autonum::AssignVariables::formulaToLabel(Xreflabel, elmt->rSequenceStruct(), elmt->diagram(), elmt);
+		label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
 	}
-	else label = assignVariables(label, this);
+	else label = autonum::AssignVariables::formulaToLabel(label, m_autoNum_seq, diagram(), this);
 
 	// set the new label
 	ElementTextItem *eti = setTaggedText("label", label, no_editable);

Modified: trunk/sources/qetgraphicsitem/terminalelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/terminalelement.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/qetgraphicsitem/terminalelement.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -68,10 +68,9 @@
  * @brief SimpleElement::updateLabel
  * update label of this element
  */
-void TerminalElement::updateLabel(DiagramContext old_info, DiagramContext new_info) {
-	QString label = new_info["label"].toString();
-	Element *elmt = this;
-	label = assignVariables(label,elmt);
+void TerminalElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
+{
+	QString label = autonum::AssignVariables::formulaToLabel(new_info["label"].toString(), m_autoNum_seq, diagram(), this);
 
 	//Label of element
 	if (old_info["label"].toString() != label) {

Modified: trunk/sources/ui/elementselectorwidget.cpp
===================================================================
--- trunk/sources/ui/elementselectorwidget.cpp	2016-11-07 15:11:12 UTC (rev 4771)
+++ trunk/sources/ui/elementselectorwidget.cpp	2016-11-09 16:06:04 UTC (rev 4772)
@@ -24,6 +24,7 @@
 #include "terminal.h"
 #include "conductor.h"
 #include "qet.h"
+#include "assignvariables.h"
 
 /**
  * @brief ElementSelectorWidget::ElementSelectorWidget
@@ -134,13 +135,13 @@
 			DiagramContext dc = elmt -> elementInformations();
 
 			if (!dc["label"].toString().isEmpty())
-				button_text = elmt->assignVariables(dc["label"].toString(), elmt) + " ";
+				button_text = autonum::AssignVariables::formulaToLabel(dc["label"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + " ";
 
 			if (!dc["comment"].toString().isEmpty())
-				button_text += elmt->assignVariables(dc["comment"].toString(), elmt);
+				button_text = autonum::AssignVariables::formulaToLabel(dc["comment"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt);
 
 			if (!dc["location"].toString().isEmpty())
-				button_text += elmt->assignVariables(dc["location"].toString(), elmt);
+				button_text = autonum::AssignVariables::formulaToLabel(dc["location"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt);
 
 			if (!button_text.isEmpty())
 				button_text += "\n";


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