[qet] qet/qet: [4790] Move methods used for autonum and sequential value, from conductor and element class, to autonum namespace.

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


Revision: 4790
Author:   blacksun
Date:     2016-11-22 18:21:53 +0100 (Tue, 22 Nov 2016)
Log Message:
-----------
Move methods used for autonum and sequential value, from conductor and element class, to autonum namespace.

Modified Paths:
--------------
    trunk/sources/autoNum/assignvariables.cpp
    trunk/sources/autoNum/assignvariables.h
    trunk/sources/diagramevent/diagrameventaddelement.cpp
    trunk/sources/qetgraphicsitem/conductor.cpp
    trunk/sources/qetgraphicsitem/conductor.h
    trunk/sources/qetgraphicsitem/element.cpp
    trunk/sources/qetgraphicsitem/element.h

Modified: trunk/sources/autoNum/assignvariables.cpp
===================================================================
--- trunk/sources/autoNum/assignvariables.cpp	2016-11-22 00:41:03 UTC (rev 4789)
+++ trunk/sources/autoNum/assignvariables.cpp	2016-11-22 17:21:53 UTC (rev 4790)
@@ -132,4 +132,106 @@
 		}
 	}
 
+	/**
+	 * @brief setSequentialToList
+	 * Append all sequential of type @type owned by @context in list
+	 * @param list : list to have value inserted
+	 * @param context : numerotation context to retrieve value
+	 * @param type : type of sequential (unit, unitfolio, ten, tenfolio, hundred, hundredfolio)
+	 */
+	void setSequentialToList(QStringList &list, NumerotationContext &context, QString type)
+	{
+		for (int i = 0; i < context.size(); i++)
+		{
+			if (context.itemAt(i).at(0) == type)
+			{
+				QString number;
+				if (type == "ten" || type == "tenfolio")
+					number = QString("%1").arg(context.itemAt(i).at(1).toInt(), 2, 10, QChar('0'));
+				else if (type == "hundred" || type == "hundredfolio")
+					number = QString("%1").arg(context.itemAt(i).at(1).toInt(), 3, 10, QChar('0'));
+				else number = QString::number(context.itemAt(i).at(1).toInt());
+					list.append(number);
+			}
+		}
+	}
+
+	/**
+	 * @brief setFolioSequentialToHash
+	 * Insert all value of @list in @hash with key @autoNumName
+	 * @param list : list to get values from
+	 * @param hash : hash to have values inserted
+	 * @param autoNumName : name to use as key of hash
+	 */
+	void setFolioSequentialToHash(QStringList &list, QHash<QString, QStringList> &hash, QString autoNumName)
+	{
+		if (hash.isEmpty() || !hash.contains(autoNumName))
+		{
+			QStringList max;
+			for (int i = 0; i < list.size(); i++)
+			{
+				max.append(list.at(i));
+			}
+			hash.insert(autoNumName,max);
+		}
+		else if (hash.contains(autoNumName))
+		{
+				//Load the String List and update it
+			QStringList max = hash.value(autoNumName);
+			for (int i = 0; i < list.size(); i++)
+			{
+				if ((list.at(i).toInt()) > max.at(i).toInt())
+				{
+					max.replace(i,list.at(i));
+					hash.remove(autoNumName);
+					hash.insert(autoNumName,max);
+				}
+			}
+		}
+	}
+
+	/**
+	 * @brief setSequential
+	 * Fill seqStruct
+	 * @param label : label of sequential to fill (%sequ_, %sequf_, %seqt_, ect....)
+	 * @param seqStruct : struct to fill
+	 * @param context : numerotation context use to know the current sequential num.
+	 * @param diagram : diagram where the sequential occur, notably use when label is folio type (%sequf_, %seqtf_, %seqhf_),
+	 * to keep up to date the current sequential of folio.
+	 * @param hashKey : the hash key used to store the sequential for folio type.
+	 */
+	void setSequential(QString label, sequenceStruct &seqStruct, NumerotationContext &context, Diagram *diagram, QString hashKey)
+	{
+		if (!context.isEmpty())
+		{
+			if (label.contains("%sequ_"))
+			{
+				autonum::setSequentialToList(seqStruct.unit, context,"unit");
+			}
+			if (label.contains("%sequf_"))
+			{
+				autonum::setSequentialToList(seqStruct.unit_folio, context,"unitfolio");
+				autonum::setFolioSequentialToHash(seqStruct.unit_folio, diagram->m_elmt_unitfolio_max, hashKey);
+			}
+			if (label.contains("%seqt_"))
+			{
+				autonum::setSequentialToList(seqStruct.ten, context,"ten");
+			}
+			if (label.contains("%seqtf_"))
+			{
+				autonum::setSequentialToList(seqStruct.ten_folio, context,"tenfolio");
+				autonum::setFolioSequentialToHash(seqStruct.ten_folio, diagram->m_elmt_tenfolio_max, hashKey);
+			}
+			if (label.contains("%seqh_"))
+			{
+				autonum::setSequentialToList(seqStruct.hundred, context,"hundred");
+			}
+			if (label.contains("%seqhf_"))
+			{
+				autonum::setSequentialToList(seqStruct.hundred_folio, context,"hundredfolio");
+				autonum::setFolioSequentialToHash(seqStruct.hundred_folio, diagram->m_elmt_hundredfolio_max, hashKey);
+			}
+		}
+	}
+
 }

Modified: trunk/sources/autoNum/assignvariables.h
===================================================================
--- trunk/sources/autoNum/assignvariables.h	2016-11-22 00:41:03 UTC (rev 4789)
+++ trunk/sources/autoNum/assignvariables.h	2016-11-22 17:21:53 UTC (rev 4790)
@@ -22,6 +22,8 @@
 #include <QPointF>
 #include <QStringList>
 
+#include "numerotationcontext.h"
+
 class Diagram;
 class Element;
 
@@ -59,8 +61,9 @@
 			const Element *m_element = nullptr;
 	};
 
-
-
+	void setSequentialToList(QStringList &list, NumerotationContext &nc, QString type);
+	void setFolioSequentialToHash(QStringList &list, QHash<QString, QStringList> &hash, QString autoNumName);
+	void setSequential(QString label, autonum::sequenceStruct &seqStruct, NumerotationContext &context, Diagram *diagram, QString hashKey);
 }
 
 #endif // ASSIGNVARIABLES_H

Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-11-22 00:41:03 UTC (rev 4789)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-11-22 17:21:53 UTC (rev 4790)
@@ -238,7 +238,7 @@
 		}
 	};
 	m_diagram -> undoStack().push(undo_object);
-	element->setSequential();
+	element->SetUpSequential();
 	element->freezeNewAddedElement();
 	element->updateLabel();
 }

Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp	2016-11-22 00:41:03 UTC (rev 4789)
+++ trunk/sources/qetgraphicsitem/conductor.cpp	2016-11-22 17:21:53 UTC (rev 4790)
@@ -1269,89 +1269,6 @@
 }
 
 /**
- * @brief Conductor::setSequential
- * Set sequential values to conductor
- */
-void Conductor::setSequential() {
-	if (diagram()==NULL) return;
-	QString conductor_currentAutoNum = diagram()->project()->conductorCurrentAutoNum();
-	QString formula = diagram()->project()->conductorAutoNumCurrentFormula();
-	QString label = this->text();
-	NumerotationContext nc = diagram()->project()->conductorAutoNum(conductor_currentAutoNum);
-	NumerotationContextCommands ncc (nc);
-	if (!nc.isEmpty()) {
-		if (label.contains("%sequ_"))
-			setSequentialToList(&m_autoNum_seq.unit,&nc,"unit");
-		if (label.contains("%sequf_")) {
-			setSequentialToList(&m_autoNum_seq.unit_folio,&nc,"unitfolio");
-			setFolioSequentialToHash(&m_autoNum_seq.unit_folio,&diagram()->m_cnd_unitfolio_max,conductor_currentAutoNum);
-		}
-		if (label.contains("%seqt_"))
-			setSequentialToList(&m_autoNum_seq.ten,&nc,"ten");
-		if (label.contains("%seqtf_")) {
-			setSequentialToList(&m_autoNum_seq.ten_folio,&nc,"tenfolio");
-			setFolioSequentialToHash(&m_autoNum_seq.ten_folio,&diagram()->m_cnd_tenfolio_max,conductor_currentAutoNum);
-		}
-		if (label.contains("%seqh_"))
-			setSequentialToList(&m_autoNum_seq.hundred,&nc,"hundred");
-		if (label.contains("%seqhf_")) {
-			setSequentialToList(&m_autoNum_seq.hundred_folio,&nc,"hundredfolio");
-			setFolioSequentialToHash(&m_autoNum_seq.hundred_folio,&diagram()->m_cnd_hundredfolio_max,conductor_currentAutoNum);
-		}
-	this->diagram()->project()->addConductorAutoNum(conductor_currentAutoNum,ncc.next());
-	}
-}
-
-/**
- * @brief Conductor::setSequentialToList
- * This class appends all sequential to selected list
- * @param list to have values inserted
- * @param nc to retrieve values from
- * @param sequential type
- */
-void Conductor::setSequentialToList(QStringList* list, NumerotationContext* nc, QString type) {
-	for (int i = 0; i < nc->size(); i++) {
-		if (nc->itemAt(i).at(0) == type) {
-			QString number;
-			if (type == "ten" || type == "tenfolio")
-				number = QString("%1").arg(nc->itemAt(i).at(1).toInt(), 2, 10, QChar('0'));
-			else if (type == "hundred" || type == "hundredfolio")
-				number = QString("%1").arg(nc->itemAt(i).at(1).toInt(), 3, 10, QChar('0'));
-			else number = QString::number(nc->itemAt(i).at(1).toInt());
-				list->append(number);
-		}
-	}
-}
-
-/**
- * @brief Conductor::setFolioSequentialToHash
- * This class inserts all conductors from list to hash
- * @param list to retrieve values from
- * @param hash to have values inserted
- * @param current element autonum to insert on hash
- */
-void Conductor::setFolioSequentialToHash(QStringList* list, QHash<QString, QStringList> *hash, QString conductor_currentAutoNum) {
-	if (hash->isEmpty() || (!(hash->contains(conductor_currentAutoNum)))) {
-		QStringList max;
-		for (int i = 0; i < list->size(); i++) {
-			max.append(list->at(i));
-		}
-		hash->insert(conductor_currentAutoNum,max);
-	}
-	else if (hash->contains(conductor_currentAutoNum)) {
-		//Load the String List and update it
-		QStringList max = hash->value(conductor_currentAutoNum);
-		for (int i = 0; i < list->size(); i++) {
-			if ((list->at(i).toInt()) > max.at(i).toInt()) {
-				max.replace(i,list->at(i));
-				hash->remove(conductor_currentAutoNum);
-				hash->insert(conductor_currentAutoNum,max);
-			}
-		}
-	}
-}
-
-/**
  * @brief Conductor::setOthersSequential
  * Copy sequentials from conductor in argument to this conductor
  * @param conductor to copy sequentials from
@@ -1375,13 +1292,23 @@
 void Conductor::setText(const QString &t)
 {
 	text_item->setPlainText(t);
-	if (setSeq)
+	if (setSeq && diagram())
 	{
-		setSequential();
+		QString conductor_currentAutoNum = diagram()->project()->conductorCurrentAutoNum();
+		NumerotationContext nc = diagram()->project()->conductorAutoNum(conductor_currentAutoNum);
+
+		autonum::setSequential(text(), m_autoNum_seq, nc, diagram(), conductor_currentAutoNum);
+
+		NumerotationContextCommands ncc (nc);
+		diagram()->project()->addConductorAutoNum(conductor_currentAutoNum, ncc.next());
+
 		setSeq = false;
 	}
-	QString label = autonum::AssignVariables::formulaToLabel(t, m_autoNum_seq, diagram());
-	text_item -> setPlainText(label);
+	if (diagram())
+	{
+		QString label = autonum::AssignVariables::formulaToLabel(t, m_autoNum_seq, diagram());
+		text_item -> setPlainText(label);
+	}
 }
 
 /**

Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h	2016-11-22 00:41:03 UTC (rev 4789)
+++ trunk/sources/qetgraphicsitem/conductor.h	2016-11-22 17:21:53 UTC (rev 4790)
@@ -96,10 +96,7 @@
 	QString text() const;
 	void setText(const QString &);
 	void refreshText();
-	void setSequential ();
 	void setOthersSequential (Conductor *);
-	void setSequentialToList(QStringList*, NumerotationContext*, QString);
-	void setFolioSequentialToHash(QStringList*, QHash<QString, QStringList>*, QString);
 
 	public:
 		static bool valideXml (QDomElement &);

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2016-11-22 00:41:03 UTC (rev 4789)
+++ trunk/sources/qetgraphicsitem/element.cpp	2016-11-22 17:21:53 UTC (rev 4790)
@@ -720,89 +720,23 @@
 }
 
 /**
- * @brief Element::setSequential
- * Set sequential values to element
+ * @brief Element::SetUpSequential
+ * Setup the sequential value of this element
  */
-void Element::setSequential() {
-	DiagramContext &dc = this->rElementInformations();
-	QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum();
-	QString formula = diagram()->project()->elementAutoNumCurrentFormula();
-	QString label = dc["label"].toString();
-	NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum);
-	NumerotationContextCommands ncc (nc);
-	if (!nc.isEmpty()) {
-		if (label.contains("%sequ_"))
-			setSequentialToList(&m_autoNum_seq.unit,&nc,"unit");
-		if (label.contains("%sequf_")) {
-			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(&m_autoNum_seq.ten,&nc,"ten");
-		if (label.contains("%seqtf_")) {
-			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(&m_autoNum_seq.hundred,&nc,"hundred");
-		if (label.contains("%seqhf_")) {
-			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());
-	}
-}
+void Element::SetUpSequential()
+{
+	if (diagram())
+	{
+		QString element_currentAutoNum = diagram()->project()->elementCurrentAutoNum();
+		NumerotationContext nc = diagram()->project()->elementAutoNum(element_currentAutoNum);
+		NumerotationContextCommands ncc (nc);
 
-/**
- * @brief Element::setSequentialToList
- * This class appends all sequential to selected list
- * @param list to have values inserted
- * @param nc to retrieve values from
- * @param sequential type
- */
-void Element::setSequentialToList(QStringList* list, NumerotationContext* nc, QString type) {
-	for (int i = 0; i < nc->size(); i++) {
-		if (nc->itemAt(i).at(0) == type) {
-			QString number;
-			if (type == "ten" || type == "tenfolio")
-				number = QString("%1").arg(nc->itemAt(i).at(1).toInt(), 2, 10, QChar('0'));
-			else if (type == "hundred" || type == "hundredfolio")
-				number = QString("%1").arg(nc->itemAt(i).at(1).toInt(), 3, 10, QChar('0'));
-			else number = QString::number(nc->itemAt(i).at(1).toInt());
-				list->append(number);
-		}
+		autonum::setSequential(elementInformations()["label"].toString(), m_autoNum_seq, nc, diagram(), element_currentAutoNum);
+		diagram()->project()->addElementAutoNum(element_currentAutoNum, ncc.next());
 	}
 }
 
 /**
- * @brief Element::setFolioSequentialToHash
- * This class inserts all elements from list to hash
- * @param list to retrieve values from
- * @param hash to have values inserted
- * @param current element autonum to insert on hash
- */
-void Element::setFolioSequentialToHash(QStringList* list, QHash<QString, QStringList> *hash, QString element_currentAutoNum) {
-	if (hash->isEmpty() || (!(hash->contains(element_currentAutoNum)))) {
-		QStringList max;
-		for (int i = 0; i < list->size(); i++) {
-			max.append(list->at(i));
-		}
-		hash->insert(element_currentAutoNum,max);
-	}
-	else if (hash->contains(element_currentAutoNum)) {
-		//Load the String List and update it
-		QStringList max = hash->value(element_currentAutoNum);
-		for (int i = 0; i < list->size(); i++) {
-			if ((list->at(i).toInt()) > max.at(i).toInt()) {
-				max.replace(i,list->at(i));
-				hash->remove(element_currentAutoNum);
-				hash->insert(element_currentAutoNum,max);
-			}
-		}
-	}
-}
-
-/**
  * @brief ElementTextItem::setTaggedText
  * Set text @newstr to the text tagged with @tagg.
  * If tagg is found return the text item, else return NULL.

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2016-11-22 00:41:03 UTC (rev 4789)
+++ trunk/sources/qetgraphicsitem/element.h	2016-11-22 17:21:53 UTC (rev 4790)
@@ -139,9 +139,7 @@
 		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);
+		void SetUpSequential ();
 		void setPrefix(QString);
 		QString getPrefix() const;
 		void freezeLabel();


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