[qet] qet/qet: [4807] Conductor :

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


Revision: 4807
Author:   blacksun
Date:     2016-12-12 11:52:44 +0100 (Mon, 12 Dec 2016)
Log Message:
-----------
Conductor :
Use method toXml and fromXml of sequentialNumbers.
Use m_freeze_label instead of m_frozen_label to save the frozen status of the text item.

Modified Paths:
--------------
    trunk/sources/diagram.cpp
    trunk/sources/diagram.h
    trunk/sources/diagramevent/diagrameventaddelement.cpp
    trunk/sources/projectconfigpages.cpp
    trunk/sources/qetgraphicsitem/conductor.cpp
    trunk/sources/qetgraphicsitem/conductor.h
    trunk/sources/qetgraphicsitem/element.cpp
    trunk/sources/qetproject.cpp
    trunk/sources/qetproject.h

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2016-12-12 07:14:50 UTC (rev 4806)
+++ trunk/sources/diagram.cpp	2016-12-12 10:52:44 UTC (rev 4807)
@@ -868,10 +868,6 @@
 					addItem(c);
 					c -> fromXml(f);
 					added_conductors << c;
-					if (item_paste) {
-						c->m_frozen_label = f.attribute("frozenlabel");
-						qDebug() << "Frozen Label" << f.attribute("frozenlabel");
-					}
 				}
 				else
 					delete c;
@@ -1489,23 +1485,13 @@
  * @brief Diagram::freezeConductors
  * Freeze every existent conductor label.
  */
-void Diagram::freezeConductors() {
+void Diagram::freezeConductors(bool freeze) {
 	foreach (Conductor *cnd, conductors()) {
-		cnd->setFreezeLabel(true);
+		cnd->setFreezeLabel(freeze);
 	}
 }
 
 /**
- * @brief Diagram::unfreezeConductors
- * Unfreeze every existent conductor label.
- */
-void Diagram::unfreezeConductors() {
-	foreach (Conductor *cnd, conductors()) {
-		cnd->setFreezeLabel(false);
-	}
-}
-
-/**
  * @brief Diagram::setfreezeNewConductors
  * Set new conductor label to be frozen.
  */

Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h	2016-12-12 07:14:50 UTC (rev 4806)
+++ trunk/sources/diagram.h	2016-12-12 10:52:44 UTC (rev 4807)
@@ -222,9 +222,8 @@
 	void setFreezeNewElements(bool);
 	bool freezeNewElements();
 
-	//methods related to conductor label Update Policy
-	void freezeConductors();
-	void unfreezeConductors();
+		//methods related to conductor label Update Policy
+	void freezeConductors(bool freeze);
 	void setFreezeNewConductors(bool);
 	bool freezeNewConductors();
 

Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-12-12 07:14:50 UTC (rev 4806)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-12-12 10:52:44 UTC (rev 4807)
@@ -230,7 +230,7 @@
 			//Autonum the new conductor, the undo command associated for this, have for parent undo_object
 		ConductorAutoNumerotation can  (conductor, m_diagram, undo_object);
 		can.numerate();
-		if (m_diagram->freezeNewConductors() || m_diagram->project()->freezeNewConductors()) {
+		if (m_diagram->freezeNewConductors() || m_diagram->project()->isFreezeNewConductors()) {
 			conductor->setFreezeLabel(true);
 		}
 	};

Modified: trunk/sources/projectconfigpages.cpp
===================================================================
--- trunk/sources/projectconfigpages.cpp	2016-12-12 07:14:50 UTC (rev 4806)
+++ trunk/sources/projectconfigpages.cpp	2016-12-12 10:52:44 UTC (rev 4807)
@@ -623,29 +623,29 @@
 	//Allow Both Existent and New Conductors
 	if (m_amw->ui->m_both_conductor_rb->isChecked()) {
 		//Unfreeze Existent and New Conductors
-		project()->unfreezeExistentConductorLabel(from,to);
-		project()->unfreezeNewConductorLabel(from,to);
+		project()->freezeExistentConductorLabel(false, from,to);
+		project()->freezeNewConductorLabel(false, from,to);
 		project()->setFreezeNewConductors(false);
 	}
 	//Allow Only New
 	else if (m_amw->ui->m_new_conductor_rb->isChecked()) {
 		//Freeze Existent and Unfreeze New Conductors
-		project()->freezeExistentConductorLabel(from,to);
-		project()->unfreezeNewConductorLabel(from,to);
+		project()->freezeExistentConductorLabel(true, from,to);
+		project()->freezeNewConductorLabel(false, from,to);
 		project()->setFreezeNewConductors(false);
 	}
 	//Allow Only Existent
 	else if (m_amw->ui->m_existent_conductor_rb->isChecked()) {
 		//Freeze Existent and Unfreeze New Conductors
-		project()->unfreezeExistentConductorLabel(from,to);
-		project()->freezeNewConductorLabel(from,to);
+		project()->freezeExistentConductorLabel(false, from,to);
+		project()->freezeNewConductorLabel(true, from,to);
 		project()->setFreezeNewConductors(true);
 	}
 	//Disable
 	else if (m_amw->ui->m_disable_conductor_rb->isChecked()) {
 		//Freeze Existent and New Elements, Set Freeze Element Project Wide
-		project()->freezeExistentConductorLabel(from,to);
-		project()->freezeNewConductorLabel(from,to);
+		project()->freezeExistentConductorLabel(true, from,to);
+		project()->freezeNewConductorLabel(true, from,to);
 		project()->setFreezeNewConductors(true);
 	}
 

Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp	2016-12-12 07:14:50 UTC (rev 4806)
+++ trunk/sources/qetgraphicsitem/conductor.cpp	2016-12-12 10:52:44 UTC (rev 4807)
@@ -36,6 +36,36 @@
 QPen Conductor::conductor_pen = QPen();
 QBrush Conductor::conductor_brush = QBrush();
 
+
+class ConductorXmlRetroCompatibility
+{
+		friend class Conductor;
+
+		static void loadSequential(const QDomElement &dom_element, QString seq, QStringList* list)
+		{
+			int i = 0;
+			while (!dom_element.attribute(seq + QString::number(i+1)).isEmpty())
+			{
+					list->append(dom_element.attribute(seq + QString::number(i+1)));
+					i++;
+			}
+		}
+
+		static void loadSequential(const QDomElement &dom_element, Conductor *conductor)
+		{
+			autonum::sequentialNumbers sn;
+
+			loadSequential(dom_element,"sequ_",&sn.unit);
+			loadSequential(dom_element,"sequf_",&sn.unit_folio);
+			loadSequential(dom_element,"seqt_",&sn.ten);
+			loadSequential(dom_element,"seqtf_",&sn.ten_folio);
+			loadSequential(dom_element,"seqh_",&sn.hundred);
+			loadSequential(dom_element,"seqhf_",&sn.hundred_folio);
+
+			conductor->rSequenceNum() = sn;
+		}
+};
+
 /**
  * @brief Conductor::Conductor
  * Default constructor.
@@ -818,25 +848,24 @@
  * @param e
  * @return true is loading success else return false
  */
-bool Conductor::fromXml(QDomElement &e) {
-	setPos(e.attribute("x", 0).toDouble(),
-		   e.attribute("y", 0).toDouble());
+bool Conductor::fromXml(QDomElement &dom_element)
+{
+	setPos(dom_element.attribute("x", 0).toDouble(),
+		   dom_element.attribute("y", 0).toDouble());
 
-	bool return_ = pathFromXml(e);
+	bool return_ = pathFromXml(dom_element);
 
-	text_item -> fromXml(e);
+	text_item -> fromXml(dom_element);
 	ConductorProperties pr;
-	pr.fromXml(e);
+	pr.fromXml(dom_element);
 
-	//Load Sequential Values
-	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 Sequential Values
+	if (dom_element.hasAttribute("sequ_1") || dom_element.hasAttribute("sequf_1") || dom_element.hasAttribute("seqt_1") || dom_element.hasAttribute("seqtf_1") || dom_element.hasAttribute("seqh_1") || dom_element.hasAttribute("sequf_1"))
+		ConductorXmlRetroCompatibility::loadSequential(dom_element, this);
+	else
+		m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers"));
 
-	m_frozen_label = e.attribute("frozenlabel");
+	m_freeze_label = dom_element.attribute("freezeLabel") == "true"? true : false;
 
 	setProperties(pr);
 
@@ -844,23 +873,6 @@
 }
 
 /**
-	Load Sequentials to display on conductor label
-	@param QDomElement to set Attributes
-	@param Qstring seq to be retrieved
-	@param QStringList list to be inserted values
-*/
-void Conductor::loadSequential(QDomElement* e, QString seq, QStringList* list)
-{
-		//Load Sequential Values
-	int i = 0;
-	while (!e->attribute(seq + QString::number(i+1)).isEmpty())
-	{
-		list->append(e->attribute(seq + QString::number(i+1)));
-		i++;
-	}
-}
-
-/**
 	Exporte les caracteristiques du conducteur sous forme d'une element XML.
 	@param d Le document XML a utiliser pour creer l'element XML
 	@param table_adr_id Hash stockant les correspondances entre les ids des
@@ -867,65 +879,39 @@
 	bornes dans le document XML et leur adresse en memoire
 	@return Un element XML representant le conducteur
 */
-QDomElement Conductor::toXml(QDomDocument &d, QHash<Terminal *, int> &table_adr_id) const {
-	QDomElement e = d.createElement("conductor");
+QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int> &table_adr_id) const
+{
+	QDomElement dom_element = dom_document.createElement("conductor");
 
-	e.setAttribute("x", QString::number(pos().x()));
-	e.setAttribute("y", QString::number(pos().y()));
-	e.setAttribute("terminal1", table_adr_id.value(terminal1));
-	e.setAttribute("terminal2", table_adr_id.value(terminal2));
+	dom_element.setAttribute("x", QString::number(pos().x()));
+	dom_element.setAttribute("y", QString::number(pos().y()));
+	dom_element.setAttribute("terminal1", table_adr_id.value(terminal1));
+	dom_element.setAttribute("terminal2", table_adr_id.value(terminal2));
+	dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
 	
 	// on n'exporte les segments du conducteur que si ceux-ci ont
 	// ete modifies par l'utilisateur
-	if (modified_path) {
+	if (modified_path)
+	{
 		// parcours et export des segments
 		QDomElement current_segment;
-		foreach(ConductorSegment *segment, segmentsList()) {
-			current_segment = d.createElement("segment");
+		foreach(ConductorSegment *segment, segmentsList())
+		{
+			current_segment = dom_document.createElement("segment");
 			current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
 			current_segment.setAttribute("length", QString("%1").arg(segment -> length()));
-			e.appendChild(current_segment);
+			dom_element.appendChild(current_segment);
 		}
 	}
 
-	// Save Conductor sequential values to Xml
-	// Save Unit Sequential Values
-	for (int i = 0; i < m_autoNum_seq.unit.size(); i++) {
-			e.setAttribute("sequ_" + QString::number(i+1),m_autoNum_seq.unit.at(i));
-	}
-
-	// Save UnitFolio Sequential Values
-	for (int i = 0; i < m_autoNum_seq.unit_folio.size(); i++) {
-			e.setAttribute("sequf_" + QString::number(i+1),m_autoNum_seq.unit_folio.at(i));
-	}
-
-	// Save Ten Sequential Values
-	for (int i = 0; i < m_autoNum_seq.ten.size(); i++) {
-			e.setAttribute("seqt_" + QString::number(i+1),m_autoNum_seq.ten.at(i));
-	}
-
-	// Save TenFolio Sequential Values
-	for (int i = 0; i < m_autoNum_seq.ten_folio.size(); i++) {
-			e.setAttribute("seqtf_" + QString::number(i+1),m_autoNum_seq.ten_folio.at(i));
-	}
-
-	// Save Hundred Sequential Values
-	for (int i = 0; i < m_autoNum_seq.hundred.size(); i++) {
-			e.setAttribute("seqh_" + QString::number(i+1),m_autoNum_seq.hundred.at(i));
-	}
-
-	// Save Hundred Sequential Values
-	for (int i = 0; i < m_autoNum_seq.hundred_folio.size(); i++) {
-			e.setAttribute("seqhf_" + QString::number(i+1),m_autoNum_seq.hundred_folio.at(i));
-	}
-
-	if (m_frozen_label != "") e.setAttribute("frozenlabel", m_frozen_label);
+	QDomElement dom_seq = m_autoNum_seq.toXml(dom_document);
+	dom_element.appendChild(dom_seq);
 	
-	// Export the properties and text
-	m_properties. toXml(e);
-	text_item -> toXml(e);
+		// Export the properties and text
+	m_properties. toXml(dom_element);
+	text_item -> toXml(dom_element);
 
-	return(e);
+	return(dom_element);
 }
 
 /**
@@ -1313,18 +1299,11 @@
 	setText(m_properties.text);
 	text_item -> setFontSize(m_properties.text_size);
 
-	 if (terminal1 != NULL && terminal1->diagram() != NULL) {
-		if (terminal1->diagram()->item_paste)
-			m_frozen_label = "";
-		else
-			m_frozen_label = m_properties.text;
-	}
-
-	setFreezeLabel(m_freeze_label);
 	if (m_properties.type != ConductorProperties::Multi)
 		text_item -> setVisible(false);
 	else
 		text_item -> setVisible(m_properties.m_show_text);
+
 	calculateTextItemPosition();
 	update();
 
@@ -1732,17 +1711,4 @@
  */
 void Conductor::setFreezeLabel(bool freeze) {
 	m_freeze_label = freeze;
-
-	if (m_freeze_label) {
-		QString freezelabel = this->text_item->toPlainText();
-		m_frozen_label = m_properties.text;
-		this->setText(freezelabel);
-		this->m_properties.text = freezelabel;
-	}
-	else {
-		if (m_frozen_label.isEmpty())
-			return;
-		this->setText(m_frozen_label);
-		m_properties.text = m_frozen_label;
-	}
 }

Modified: trunk/sources/qetgraphicsitem/conductor.h
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.h	2016-12-12 07:14:50 UTC (rev 4806)
+++ trunk/sources/qetgraphicsitem/conductor.h	2016-12-12 10:52:44 UTC (rev 4807)
@@ -123,7 +123,6 @@
 
 	public:
 		void setFreezeLabel(bool freeze);
-		QString m_frozen_label;
 	
 	public slots:
 		void displayedTextChanged();
@@ -187,7 +186,6 @@
 		static QPointF extendTerminal(const QPointF &, Qet::Orientation, qreal = 9.0);
 		static Qt::Corner movementType(const QPointF &, const QPointF &);
 		static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &);
-		void loadSequential(QDomElement* e, QString seq, QStringList* list);
 };
 
 Conductor * longuestConductorInPotential (Conductor *conductor, bool all_diagram = false);

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2016-12-12 07:14:50 UTC (rev 4806)
+++ trunk/sources/qetgraphicsitem/element.cpp	2016-12-12 10:52:44 UTC (rev 4807)
@@ -860,7 +860,7 @@
  * Freeze this label if needed
  */
 void Element::freezeNewAddedElement() {
-	if (this->diagram()->freezeNewElements() || this->diagram()->project()->freezeNewElements()) {
+	if (this->diagram()->freezeNewElements() || this->diagram()->project()->isFreezeNewElements()) {
 		freezeLabel(true);
 	}
 	else return;

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2016-12-12 07:14:50 UTC (rev 4806)
+++ trunk/sources/qetproject.cpp	2016-12-12 10:52:44 UTC (rev 4807)
@@ -596,53 +596,29 @@
  * @param from - first folio index to apply freeze
  * @param to - last folio index to apply freeze
  */
-void QETProject::freezeExistentConductorLabel(int from, int to) {
+void QETProject::freezeExistentConductorLabel(bool freeze, int from, int to) {
 	for (int i = from; i <= to; i++) {
-		diagrams_.at(i)->freezeConductors();
+		diagrams_.at(i)->freezeConductors(freeze);
 	}
 }
 
 /**
- * @brief QETProject::unfreezeExistentConductorLabel
- * Unfreeze Existent Conductors in the selected folios
- * @param from - first folio index to apply unfreeze
- * @param to - last folio index to apply unfreeze
- */
-void QETProject::unfreezeExistentConductorLabel(int from, int to) {
-	for (int i = from; i <= to; i++) {
-		diagrams_.at(i)->unfreezeConductors();
-	}
-}
-
-/**
  * @brief QETProject::freezeNewConductorLabel
  * Freeze New Conductors in the selected folios
  * @param from - first folio index to apply freeze
  * @param to - last folio index to apply freeze
  */
-void QETProject::freezeNewConductorLabel(int from, int to) {
+void QETProject::freezeNewConductorLabel(bool freeze, int from, int to) {
 	for (int i = from; i <= to; i++) {
-		diagrams_.at(i)->setFreezeNewConductors(true);
+		diagrams_.at(i)->setFreezeNewConductors(freeze);
 	}
 }
 
 /**
- * @brief QETProject::unfreezeNewElementLabel
- * Unfreeze New Conductors in the selected folios
- * @param from - first folio index to apply unfreeze
- * @param to - last folio index to apply unfreeze
- */
-void QETProject::unfreezeNewConductorLabel(int from, int to) {
-	for (int i = from; i <= to; i++) {
-		diagrams_.at(i)->setFreezeNewConductors(false);
-	}
-}
-
-/**
- * @brief QETProject::freezeNewConductors
+ * @brief QETProject::isFreezeNewConductors
  * @return freeze new conductors Project Wide status
  */
-bool QETProject::freezeNewConductors() {
+bool QETProject::isFreezeNewConductors() {
 	return m_freeze_new_conductors;
 }
 
@@ -682,7 +658,7 @@
  * @brief QETProject::freezeNewElements
  * @return freeze new elements Project Wide status
  */
-bool QETProject::freezeNewElements() {
+bool QETProject::isFreezeNewElements() {
 	return m_freeze_new_elements;
 }
 

Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h	2016-12-12 07:14:50 UTC (rev 4806)
+++ trunk/sources/qetproject.h	2016-12-12 10:52:44 UTC (rev 4807)
@@ -131,15 +131,13 @@
 			//Element
 		void freezeExistentElementLabel(bool freeze, int from, int to);
 		void freezeNewElementLabel(bool freeze, int from, int to);
-		bool freezeNewElements();
+		bool isFreezeNewElements();
 		void setFreezeNewElements(bool);
 
 			//Conductor
-		void freezeExistentConductorLabel(int,int);
-		void unfreezeExistentConductorLabel(int,int);
-		void freezeNewConductorLabel(int,int);
-		void unfreezeNewConductorLabel(int,int);
-		bool freezeNewConductors();
+		void freezeExistentConductorLabel(bool freeze, int from, int to);
+		void freezeNewConductorLabel(bool freeze, int from, int to);
+		bool isFreezeNewConductors();
 		void setFreezeNewConductors(bool);
 
 		bool autoConductor () const;


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