Add attribut "uuid" for .elmt file.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4032 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-06-28 16:30:13 +00:00
parent 748e9bd186
commit 557a2eaa87
2 changed files with 54 additions and 31 deletions

View File

@@ -256,16 +256,20 @@ void ElementScene::setGrid(int x_g, int y_g) {
}
/**
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 (!size.contains(0,0) && all_parts)
{
centerElementToOrigine();
//recalcul the size after movement
size= elementSceneGeometricRect();
@@ -284,7 +288,8 @@ const QDomDocument ElementScene::toXml(bool all_parts) {
// 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));
@@ -295,26 +300,35 @@ const QDomDocument ElementScene::toXml(bool all_parts) {
root.setAttribute("version", QET::version);
root.setAttribute("link_type", m_elmt_type);
// noms de l'element
//Uuid used to compare two elements
QDomElement uuid = xml_document.createElement("uuid");
uuid.setAttribute("uuid", QUuid::createUuid().toString());
root.appendChild(uuid);
//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));
}

View File

@@ -218,16 +218,25 @@ ElementDefinition *ElementDefinition::toElement() {
}
/**
@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);