[qet] [4032] Add attribut "uuid" for .elmt file.

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


Revision: 4032
Author:   blacksun
Date:     2015-06-28 18:30:13 +0200 (Sun, 28 Jun 2015)
Log Message:
-----------
Add attribut "uuid" for .elmt file.

Modified Paths:
--------------
    trunk/sources/editor/elementscene.cpp
    trunk/sources/elementdefinition.cpp

Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp	2015-06-28 12:37:10 UTC (rev 4031)
+++ trunk/sources/editor/elementscene.cpp	2015-06-28 16:30:13 UTC (rev 4032)
@@ -256,35 +256,40 @@
 }
 
 /**
-	Exporte l'element en XML
-	@param all_parts Booleen (a vrai par defaut) indiquant si le XML genere doit
-	representer tout l'element ou seulement les elements selectionnes
-	@return un document XML decrivant l'element
-*/
-const QDomDocument ElementScene::toXml(bool all_parts) {
+ * @brief ElementScene::toXml
+ * Export this element as a xml file
+ * @param all_parts (true by default) if true, export the entire element in xml,
+ * if false, only export the selected parts.
+ * @return an xml document that describe the element.
+ */
+const QDomDocument ElementScene::toXml(bool all_parts)
+{
 	QRectF size= elementSceneGeometricRect();
-	//if the element doesn't contains the origin point of the scene
-	//we move the element to the origin for solve this default before saving
-	if (!size.contains(0,0) && all_parts) {
+
+		//if the element doesn't contains the origin point of the scene
+		//we move the element to the origin for solve this default before saving
+	if (!size.contains(0,0) && all_parts)
+	{
 		centerElementToOrigine();
-		//recalcul the size after movement
+			//recalcul the size after movement
 		size= elementSceneGeometricRect();
 	}
 
-	//define the size of the element by the upper multiple of 10
+		//define the size of the element by the upper multiple of 10
 	int upwidth = ((qRound(size.width())/10)*10)+10;
 	if ((qRound(size.width())%10) > 6) upwidth+=10;
 
 	int upheight = ((qRound(size.height())/10)*10)+10;
 	if ((qRound(size.height())%10) > 6) upheight+=10;
 
-	//the margin between the real size of the element and the rectangle that delimits
+		//the margin between the real size of the element and the rectangle that delimits
 	int xmargin = qRound(upwidth - size.width());
 	int ymargin = qRound(upheight - size.height());
 
-	// document XML
+		// document XML
 	QDomDocument xml_document;
-	// racine du document XML
+
+		//Root of xml document
 	QDomElement root = xml_document.createElement("definition");
 	root.setAttribute("type",        "element");
 	root.setAttribute("width",       QString("%1").arg(upwidth));
@@ -294,27 +299,36 @@
 	root.setAttribute("orientation", "dyyy"); //we keep the orientation for compatibility with previous version of qet
 	root.setAttribute("version", QET::version);
 	root.setAttribute("link_type", m_elmt_type);
+
+		//Uuid used to compare two elements
+	QDomElement uuid = xml_document.createElement("uuid");
+	uuid.setAttribute("uuid", QUuid::createUuid().toString());
+	root.appendChild(uuid);
 	
-	// noms de l'element
+		//names of element
 	root.appendChild(_names.toXml(xml_document));
 
-	if (m_elmt_type == "slave" || m_elmt_type == "master") {
+	if (m_elmt_type == "slave" || m_elmt_type == "master")
+	{
 		QDomElement kindInfo = xml_document.createElement("kindInformations");
 		m_elmt_kindInfo.toXml(kindInfo, "kindInformation");
 		root.appendChild(kindInfo);
 	}
 	
-	// informations complementaires de l'element
+		//complementary information about the element
 	QDomElement informations_element = xml_document.createElement("informations");
 	root.appendChild(informations_element);
 	informations_element.appendChild(xml_document.createTextNode(informations()));
 	
 	QDomElement description = xml_document.createElement("description");
-	// description de l'element
-	foreach(QGraphicsItem *qgi, zItems()) {
-		// si l'export ne concerne que la selection, on ignore les parties non selectionnees
+
+		//the graphic description of the element
+	foreach(QGraphicsItem *qgi, zItems())
+	{
+			//If the export concerns only the selection, the not selected part is ignored
 		if (!all_parts && !qgi -> isSelected()) continue;
-		if (CustomElementPart *ce = dynamic_cast<CustomElementPart *>(qgi)) {
+		if (CustomElementPart *ce = dynamic_cast<CustomElementPart *>(qgi))
+		{
 			if (ce -> isUseless()) continue;
 			description.appendChild(ce -> toXml(xml_document));
 		}

Modified: trunk/sources/elementdefinition.cpp
===================================================================
--- trunk/sources/elementdefinition.cpp	2015-06-28 12:37:10 UTC (rev 4031)
+++ trunk/sources/elementdefinition.cpp	2015-06-28 16:30:13 UTC (rev 4032)
@@ -218,16 +218,25 @@
 }
 
 /**
-	@return true si cette definition d'element est egale (en termes de contenu)
-	a la definition d'element other, false sinon.
-*/
-bool ElementDefinition::equals(ElementDefinition &other) {
-	/*
-		Pour le moment, cette methode compare simplement l'export au format
-		texte des documents XML. Cela peut entrainer de faux positifs.
-		Exemple : un espace de plus ou de moins dans le XML n'en change pas
-		forcement la semantique. Mais cela changera l'export au format texte.
-	*/
+ * @brief ElementDefinition::equals
+ * @param other : ElementDefinition to compare with this
+ * @return true if this element definition and other element definition is the same, else false
+ */
+bool ElementDefinition::equals(ElementDefinition &other)
+{
+		//Compare the uuid of the elements
+	QList <QDomElement> this_uuid_dom = QET::findInDomElement(xml(), "uuid");
+	QList <QDomElement> other_uuid_dom = QET::findInDomElement(other.xml(), "uuid");
+	if ((this_uuid_dom.size() == 1) && (other_uuid_dom.size() == 1))
+		return this_uuid_dom.first().attribute("uuid") == other_uuid_dom.first().attribute("uuid") ? true : false;
+
+		//********
+		//The code below is used to keep compatibility with previous version of qet
+		//The uuid store in .elmt file, to compare two elements was created at version svn 4032
+		///@TODO remove this code at version 0.6 or 0.7 (all users should already used the version with uuid)
+		//********
+		//Compare the xml definition transformed in QString. This method can return a false positive (notably with Qt5,
+		//because the attributes of the xml isn't at the same order,with two instance of qet, for the same element)
 	QDomDocument this_xml_document;
 	this_xml_document.appendChild(this_xml_document.importNode(xml(), true));
 	QString this_text = this_xml_document.toString(0);


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