[qet] qet/qet: [5406] Fix : in some condition, dynamic text are not at the same position when open a project.

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


Revision: 5406
Author:   blacksun
Date:     2018-06-21 19:57:33 +0200 (Thu, 21 Jun 2018)
Log Message:
-----------
Fix : in some condition, dynamic text are not at the same position when open a project.

Modified Paths:
--------------
    trunk/sources/qet.h
    trunk/sources/qetgraphicsitem/customelement.cpp
    trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp
    trunk/sources/qetgraphicsitem/element.cpp

Modified: trunk/sources/qet.h
===================================================================
--- trunk/sources/qet.h	2018-06-21 15:36:03 UTC (rev 5405)
+++ trunk/sources/qet.h	2018-06-21 17:57:33 UTC (rev 5406)
@@ -32,6 +32,13 @@
 	const QString displayedVersion = "0.70-dev";
 	QString license();
 	
+		//Describe the current state of a graphic item
+	enum GraphicsItemState {
+		GIOK,				 ///<General state
+		GIBuildingFromXml, ///<Item is currently building from a xml description (element)
+		GILoadingFromXml	 ///<Item is loading her properties from a xml description.
+	};
+	
 		/// List the various kind of changes for the zValue
 	enum DepthOption {
 		BringForward, ///< Bring item to the foreground so they have the highest zValue

Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp	2018-06-21 15:36:03 UTC (rev 5405)
+++ trunk/sources/qetgraphicsitem/customelement.cpp	2018-06-21 17:57:33 UTC (rev 5406)
@@ -88,11 +88,14 @@
 		- 8 : Aucune partie du dessin n'a pu etre chargee
 	@return true si le chargement a reussi, false sinon
 */
-bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
+bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state)
+{
+	m_state = QET::GIBuildingFromXml;
 
 	if (xml_def_elmt.tagName() != "definition" || xml_def_elmt.attribute("type") != "element")
 	{
 		if (state) *state = 4;
+		m_state = QET::GIOK;
 		return(false);
 	}
 
@@ -121,6 +124,7 @@
 		!validOrientationAttribute(xml_def_elmt)
 	) {
 		if (state) *state = 5;
+		m_state = QET::GIOK;
 		return(false);
 	}
 
@@ -131,6 +135,7 @@
 	if (xml_def_elmt.firstChild().isNull())
 	{
 		if (state) *state = 6;
+		m_state = QET::GIOK;
 		return(false);
 	}
 
@@ -203,7 +208,7 @@
 				{
 					if (state)
 						*state = 7;
-					
+					m_state = QET::GIOK;
 					return(false);
 				}
 			}
@@ -220,7 +225,7 @@
 	{
 		if (state)
 			*state = 8;
-		
+		m_state = QET::GIOK;
 		return(false);
 	}
 	else
@@ -227,7 +232,7 @@
 	{
 		if (state)
 			*state = 0;
-		
+		m_state = QET::GIOK;
 		return(true);
 	}
 }

Modified: trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp	2018-06-21 15:36:03 UTC (rev 5405)
+++ trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp	2018-06-21 17:57:33 UTC (rev 5406)
@@ -1314,20 +1314,29 @@
 
 void DynamicElementTextItem::setPlainText(const QString &text)
 {
-	if(toPlainText() == text)
+	if (toPlainText() == text)
 		return;
 	
-	prepareAlignment();
+	bool update_alignment = true;
+	if (diagram() && (diagram()->project()->state() == QETProject::ProjectParsingRunning))
+		update_alignment = false;
+	if (m_parent_element.data()->state() == QET::GIBuildingFromXml ||
+		m_parent_element.data()->state() == QET::GILoadingFromXml)
+		update_alignment = false;
 	
+	if (update_alignment) {
+		prepareAlignment();
+	}
+	
 	DiagramTextItem::setPlainText(text);
 	
 		//User define a text width
-	if(m_text_width > 0)
+	if (m_text_width > 0)
 	{
-		if(document()->size().width() > m_text_width)
+		if (document()->size().width() > m_text_width)
 		{
 			document()->setTextWidth(m_text_width);
-			if(document()->size().width() > m_text_width)
+			if (document()->size().width() > m_text_width)
 			{
 				document()->setTextWidth(document()->idealWidth());
 			}
@@ -1334,11 +1343,14 @@
 		}
 	}
 	
-	finishAlignment();
+	if (update_alignment) {
+		finishAlignment();
+	}
 	
-	if(m_Xref_item)
+	if (m_Xref_item) {
 		m_Xref_item->autoPos();
-	else if(m_slave_Xref_item)
+	}
+	else if (m_slave_Xref_item)
 	{
 		QRectF r = boundingRect();
 		QPointF pos(r.center().x() - m_slave_Xref_item->boundingRect().width()/2,

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2018-06-21 15:36:03 UTC (rev 5405)
+++ trunk/sources/qetgraphicsitem/element.cpp	2018-06-21 17:57:33 UTC (rev 5406)
@@ -356,6 +356,7 @@
  */
 bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool handle_inputs_rotation)
 {
+	m_state = QET::GILoadingFromXml;
 	/*
 		les bornes vont maintenant etre recensees pour associer leurs id a leur adresse reelle
 		ce recensement servira lors de la mise en place des fils
@@ -383,13 +384,20 @@
 		}
 	}
 	
-	if (terminals_non_trouvees > 0) {
+	if (terminals_non_trouvees > 0)
+	{
+		m_state = QET::GIOK;
 		return(false);
-	} else {
+	} 
+	else
+	{
 		// verifie que les associations id / adr n'entrent pas en conflit avec table_id_adr
-		foreach(int id_trouve, priv_id_adr.keys()) {
-			if (table_id_adr.contains(id_trouve)) {
+		foreach(int id_trouve, priv_id_adr.keys())
+		{
+			if (table_id_adr.contains(id_trouve))
+			{
 				// cet element possede un id qui est deja reference (= conflit)
+				m_state = QET::GIOK;
 				return(false);
 			}
 		}
@@ -597,7 +605,10 @@
 							//Create the comment item
 						DynamicElementTextItem *comment_text = nullptr;
 						if (m_link_type !=PreviousReport || m_link_type !=NextReport)
+						{
+							m_state = QET::GIOK;
 							return(true);
+						}
 						if(!comment.isEmpty() && c)
 						{
 							comment_text = new DynamicElementTextItem(this);
@@ -613,7 +624,10 @@
 							//create the location item
 						DynamicElementTextItem *location_text = nullptr;
 						if (m_link_type !=PreviousReport || m_link_type !=NextReport)
+						{
+							m_state = QET::GIOK;
 							return(true);
+						}
 						if(!location.isEmpty() && lo)
 						{
 							location_text = new DynamicElementTextItem(this);
@@ -628,7 +642,10 @@
 						
 						QPointF pos = deti->pos();
 						if (m_link_type !=PreviousReport || m_link_type !=NextReport)
+						{
+							m_state = QET::GIOK;
 							return(true);
+						}
 							//Create the group
 						ElementTextItemGroup *group = addTextGroup(tr("Label + commentaire"));
 						addTextToGroup(deti, group);
@@ -691,7 +708,7 @@
 			}
 		}
 	}
-    
+    m_state = QET::GIOK;
 	return(true);
 }
 


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