mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
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:
@@ -256,35 +256,40 @@ void ElementScene::setGrid(int x_g, int y_g) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Exporte l'element en XML
|
* @brief ElementScene::toXml
|
||||||
@param all_parts Booleen (a vrai par defaut) indiquant si le XML genere doit
|
* Export this element as a xml file
|
||||||
representer tout l'element ou seulement les elements selectionnes
|
* @param all_parts (true by default) if true, export the entire element in xml,
|
||||||
@return un document XML decrivant l'element
|
* if false, only export the selected parts.
|
||||||
*/
|
* @return an xml document that describe the element.
|
||||||
const QDomDocument ElementScene::toXml(bool all_parts) {
|
*/
|
||||||
|
const QDomDocument ElementScene::toXml(bool all_parts)
|
||||||
|
{
|
||||||
QRectF size= elementSceneGeometricRect();
|
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 the element doesn't contains the origin point of the scene
|
||||||
if (!size.contains(0,0) && all_parts) {
|
//we move the element to the origin for solve this default before saving
|
||||||
|
if (!size.contains(0,0) && all_parts)
|
||||||
|
{
|
||||||
centerElementToOrigine();
|
centerElementToOrigine();
|
||||||
//recalcul the size after movement
|
//recalcul the size after movement
|
||||||
size= elementSceneGeometricRect();
|
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;
|
int upwidth = ((qRound(size.width())/10)*10)+10;
|
||||||
if ((qRound(size.width())%10) > 6) upwidth+=10;
|
if ((qRound(size.width())%10) > 6) upwidth+=10;
|
||||||
|
|
||||||
int upheight = ((qRound(size.height())/10)*10)+10;
|
int upheight = ((qRound(size.height())/10)*10)+10;
|
||||||
if ((qRound(size.height())%10) > 6) upheight+=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 xmargin = qRound(upwidth - size.width());
|
||||||
int ymargin = qRound(upheight - size.height());
|
int ymargin = qRound(upheight - size.height());
|
||||||
|
|
||||||
// document XML
|
// document XML
|
||||||
QDomDocument xml_document;
|
QDomDocument xml_document;
|
||||||
// racine du document XML
|
|
||||||
|
//Root of xml document
|
||||||
QDomElement root = xml_document.createElement("definition");
|
QDomElement root = xml_document.createElement("definition");
|
||||||
root.setAttribute("type", "element");
|
root.setAttribute("type", "element");
|
||||||
root.setAttribute("width", QString("%1").arg(upwidth));
|
root.setAttribute("width", QString("%1").arg(upwidth));
|
||||||
@@ -294,27 +299,36 @@ const QDomDocument ElementScene::toXml(bool all_parts) {
|
|||||||
root.setAttribute("orientation", "dyyy"); //we keep the orientation for compatibility with previous version of qet
|
root.setAttribute("orientation", "dyyy"); //we keep the orientation for compatibility with previous version of qet
|
||||||
root.setAttribute("version", QET::version);
|
root.setAttribute("version", QET::version);
|
||||||
root.setAttribute("link_type", m_elmt_type);
|
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));
|
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");
|
QDomElement kindInfo = xml_document.createElement("kindInformations");
|
||||||
m_elmt_kindInfo.toXml(kindInfo, "kindInformation");
|
m_elmt_kindInfo.toXml(kindInfo, "kindInformation");
|
||||||
root.appendChild(kindInfo);
|
root.appendChild(kindInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// informations complementaires de l'element
|
//complementary information about the element
|
||||||
QDomElement informations_element = xml_document.createElement("informations");
|
QDomElement informations_element = xml_document.createElement("informations");
|
||||||
root.appendChild(informations_element);
|
root.appendChild(informations_element);
|
||||||
informations_element.appendChild(xml_document.createTextNode(informations()));
|
informations_element.appendChild(xml_document.createTextNode(informations()));
|
||||||
|
|
||||||
QDomElement description = xml_document.createElement("description");
|
QDomElement description = xml_document.createElement("description");
|
||||||
// description de l'element
|
|
||||||
foreach(QGraphicsItem *qgi, zItems()) {
|
//the graphic description of the element
|
||||||
// si l'export ne concerne que la selection, on ignore les parties non selectionnees
|
foreach(QGraphicsItem *qgi, zItems())
|
||||||
|
{
|
||||||
|
//If the export concerns only the selection, the not selected part is ignored
|
||||||
if (!all_parts && !qgi -> isSelected()) continue;
|
if (!all_parts && !qgi -> isSelected()) continue;
|
||||||
if (CustomElementPart *ce = dynamic_cast<CustomElementPart *>(qgi)) {
|
if (CustomElementPart *ce = dynamic_cast<CustomElementPart *>(qgi))
|
||||||
|
{
|
||||||
if (ce -> isUseless()) continue;
|
if (ce -> isUseless()) continue;
|
||||||
description.appendChild(ce -> toXml(xml_document));
|
description.appendChild(ce -> toXml(xml_document));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,16 +218,25 @@ ElementDefinition *ElementDefinition::toElement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return true si cette definition d'element est egale (en termes de contenu)
|
* @brief ElementDefinition::equals
|
||||||
a la definition d'element other, false sinon.
|
* @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) {
|
*/
|
||||||
/*
|
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.
|
//Compare the uuid of the elements
|
||||||
Exemple : un espace de plus ou de moins dans le XML n'en change pas
|
QList <QDomElement> this_uuid_dom = QET::findInDomElement(xml(), "uuid");
|
||||||
forcement la semantique. Mais cela changera l'export au format texte.
|
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;
|
QDomDocument this_xml_document;
|
||||||
this_xml_document.appendChild(this_xml_document.importNode(xml(), true));
|
this_xml_document.appendChild(this_xml_document.importNode(xml(), true));
|
||||||
QString this_text = this_xml_document.toString(0);
|
QString this_text = this_xml_document.toString(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user