[qet] [4666] Fix Multiple Folio Sequential Autonumberings.

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


Revision: 4666
Author:   dfochi
Date:     2016-08-25 18:28:11 +0200 (Thu, 25 Aug 2016)
Log Message:
-----------
Fix Multiple Folio Sequential Autonumberings. Corrects save/open behavior for folio sequentials in projects with multiple autonums

Modified Paths:
--------------
    trunk/sources/diagram.cpp
    trunk/sources/diagram.h
    trunk/sources/projectview.cpp
    trunk/sources/ui/autonumberingdockwidget.cpp

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2016-08-25 11:15:54 UTC (rev 4665)
+++ trunk/sources/diagram.cpp	2016-08-25 16:28:11 UTC (rev 4666)
@@ -480,20 +480,19 @@
 		//Folio Sequential Variables
 		if (!m_elmt_unitfolio_max.isEmpty() || !m_elmt_tenfolio_max.isEmpty() || !m_elmt_hundredfolio_max.isEmpty()) {
 			QDomElement folioContainedAutonum = document.createElement("elementautonumfoliosequentials");
-			QHash<QString, QStringList>::iterator i;
 			if (!m_elmt_unitfolio_max.isEmpty()) {
 				QDomElement elmtfolioseq = document.createElement("elementunitfolioseq");
-				elementFolioSequentialsToXml(&m_elmt_unitfolio_max, &elmtfolioseq, "sequf_");
-				folioContainedAutonum.appendChild(elmtfolioseq);	
+				elementFolioSequentialsToXml(&m_elmt_unitfolio_max, &elmtfolioseq, "sequf_", "unitfolioseq", &document);
+				folioContainedAutonum.appendChild(elmtfolioseq);
 			}
 			if (!m_elmt_tenfolio_max.isEmpty()) {
 				QDomElement elmtfolioseq = document.createElement("elementtenfolioseq");
-				elementFolioSequentialsToXml(&m_elmt_tenfolio_max, &elmtfolioseq, "seqtf_");
+				elementFolioSequentialsToXml(&m_elmt_tenfolio_max, &elmtfolioseq, "seqtf_", "tenfolioseq", &document);
 				folioContainedAutonum.appendChild(elmtfolioseq);
 			}
 			if (!m_elmt_hundredfolio_max.isEmpty()) {
 				QDomElement elmtfolioseq = document.createElement("elementhundredfolioseq");
-				elementFolioSequentialsToXml(&m_elmt_hundredfolio_max, &elmtfolioseq, "seqhf_");
+				elementFolioSequentialsToXml(&m_elmt_hundredfolio_max, &elmtfolioseq, "seqhf_", "hundredfolioseq", &document);
 				folioContainedAutonum.appendChild(elmtfolioseq);
 			}
 			racine.appendChild(folioContainedAutonum);
@@ -601,13 +600,15 @@
 + * @param hash to retrieve content with content
 + * @param sequential type
 + */
-void Diagram::elementFolioSequentialsToXml(QHash<QString, QStringList> *hash, QDomElement *domElement, QString seq_type) {
+void Diagram::elementFolioSequentialsToXml(QHash<QString, QStringList> *hash, QDomElement *domElement, QString seq_type, QString type, QDomDocument *doc) {
 	QHash<QString, QStringList>::iterator i;
 	for (i = hash->begin(); i != hash->end(); i++) {
-		domElement->setAttribute("title", i.key());
+		QDomElement folioseq = doc->createElement(type);
+		folioseq.setAttribute("title", i.key());
 		for (int j = 0; j < i.value().size(); j++) {
-			domElement->setAttribute(seq_type + QString::number(j+1), i.value().at(j));
+			folioseq.setAttribute(seq_type + QString::number(j+1), i.value().at(j));
 		}
+		domElement->appendChild(folioseq);
 	}
 }
 
@@ -701,9 +702,9 @@
 		// Load Freeze New Element
 		m_freeze_new_elements_ = root.attribute("freezeNewElement").toInt();
 
-		elementFolioSequentialsFromXml(root, &m_elmt_unitfolio_max, "elementunitfolioseq","sequf_");
-		elementFolioSequentialsFromXml(root, &m_elmt_tenfolio_max, "elementtenfolioseq","seqtf_");
-		elementFolioSequentialsFromXml(root, &m_elmt_hundredfolio_max, "elementhundredfolioseq","seqhf_");
+		elementFolioSequentialsFromXml(root, &m_elmt_unitfolio_max, "elementunitfolioseq","sequf_","unitfolioseq");
+		elementFolioSequentialsFromXml(root, &m_elmt_tenfolio_max, "elementtenfolioseq","seqtf_", "tenfolioseq");
+		elementFolioSequentialsFromXml(root, &m_elmt_hundredfolio_max, "elementhundredfolioseq","seqhf_", "hundredfolioseq");
 	}
 
 	// if child haven't got a child, loading is finish (diagram is empty)
@@ -884,17 +885,20 @@
  * @param hash to be loaded with content
  * @param folioSeq type
  * @param seq type
+ * @param type of sequential
  */
-void Diagram::elementFolioSequentialsFromXml(const QDomElement &root, QHash<QString, QStringList>* hash, QString folioSeq, QString seq) {
+void Diagram::elementFolioSequentialsFromXml(const QDomElement &root, QHash<QString, QStringList>* hash, QString folioSeq, QString seq, QString type) {
 	foreach (QDomElement folioSeqAutoNum, QET::findInDomElement(root, "elementautonumfoliosequentials", folioSeq)) {
-		QString title = folioSeqAutoNum.attribute("title");
-		QStringList unit;
-		int i = 1;
-		while (folioSeqAutoNum.hasAttribute(seq + QString::number(i))) {
-			unit << folioSeqAutoNum.attribute(seq + QString::number(i));
-			i++;
+		for(QDomElement folioseq = folioSeqAutoNum.firstChildElement(type); !folioseq.isNull(); folioseq = folioseq.nextSiblingElement(type)) {
+			QString title = folioseq.attribute("title");
+			QStringList list;
+			int i = 1;
+			while (folioseq.hasAttribute(seq + QString::number(i))) {
+				list << folioseq.attribute(seq + QString::number(i));
+				i++;
+			}
+			hash->insert(title,list);
 		}
-		hash->insert(title,unit);
 	}
 }
 

Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h	2016-08-25 11:15:54 UTC (rev 4665)
+++ trunk/sources/diagram.h	2016-08-25 16:28:11 UTC (rev 4666)
@@ -158,8 +158,8 @@
 	void write(const QDomElement &);
 	bool wasWritten() const;
 	QDomElement writeXml(QDomDocument &) const;
-	void elementFolioSequentialsToXml(QHash<QString, QStringList>*, QDomElement *, QString);
-	void elementFolioSequentialsFromXml(const QDomElement&, QHash<QString, QStringList>*, QString, QString);
+	void elementFolioSequentialsToXml(QHash<QString, QStringList>*, QDomElement *, QString, QString, QDomDocument *);
+	void elementFolioSequentialsFromXml(const QDomElement&, QHash<QString, QStringList>*, QString, QString, QString);
 
 	// methods related to graphics items addition/removal on the diagram
 	void initElementsLinks();

Modified: trunk/sources/projectview.cpp
===================================================================
--- trunk/sources/projectview.cpp	2016-08-25 11:15:54 UTC (rev 4665)
+++ trunk/sources/projectview.cpp	2016-08-25 16:28:11 UTC (rev 4666)
@@ -897,6 +897,8 @@
 		addDiagram(sv);
 	}
 
+	this->currentDiagram()->diagram()->loadElmtFolioSeq();
+
 	// If project have the folios list, move it at the beginning of the project
 	if (m_project -> getFolioSheetsQuantity()) {
 		for (int i = 0; i < m_project->getFolioSheetsQuantity(); i++)

Modified: trunk/sources/ui/autonumberingdockwidget.cpp
===================================================================
--- trunk/sources/ui/autonumberingdockwidget.cpp	2016-08-25 11:15:54 UTC (rev 4665)
+++ trunk/sources/ui/autonumberingdockwidget.cpp	2016-08-25 16:28:11 UTC (rev 4666)
@@ -154,7 +154,7 @@
 
 			//Element
 		QString element_formula = project_->elementAutoNumFormula();
-		QString active_element_autonum = project_->elementAutoNumHash().key(element_formula);
+		QString active_element_autonum = project_->elementCurrentAutoNum();
 		int el_index = ui->m_element_cb->findText(active_element_autonum);
 		ui->m_element_cb->setCurrentIndex(el_index);
 


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