From 9d4b90da1aba56cf44b997620a9b33b1d4a2683e Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 4 Mar 2021 19:18:28 +0100 Subject: [PATCH] Add userProperties --- sources/borderproperties.cpp | 29 +- sources/borderproperties.h | 4 +- sources/bordertitleblock.cpp | 4 +- sources/bordertitleblock.h | 2 +- sources/conductorproperties.cpp | 84 ++--- sources/conductorproperties.h | 18 +- sources/diagram.cpp | 2 +- .../editor/graphicspart/abstractpartellipse.h | 4 +- .../graphicspart/customelementgraphicpart.cpp | 6 +- .../graphicspart/customelementgraphicpart.h | 2 +- sources/editor/graphicspart/partarc.cpp | 26 +- sources/editor/graphicspart/partarc.h | 4 +- .../graphicspart/partdynamictextfield.cpp | 50 +-- .../graphicspart/partdynamictextfield.h | 4 +- sources/editor/graphicspart/partellipse.cpp | 28 +- sources/editor/graphicspart/partellipse.h | 4 +- sources/editor/graphicspart/partline.cpp | 38 +-- sources/editor/graphicspart/partline.h | 10 +- sources/editor/graphicspart/partpolygon.cpp | 20 +- sources/editor/graphicspart/partpolygon.h | 6 +- sources/editor/graphicspart/partrectangle.cpp | 30 +- sources/editor/graphicspart/partrectangle.h | 4 +- sources/editor/graphicspart/partterminal.cpp | 16 +- sources/editor/graphicspart/partterminal.h | 4 +- sources/editor/graphicspart/parttext.cpp | 20 +- sources/editor/graphicspart/parttext.h | 4 +- sources/properties/elementdata.cpp | 7 +- sources/properties/elementdata.h | 4 +- sources/properties/propertiesinterface.cpp | 301 ++++++++++++++---- sources/properties/propertiesinterface.h | 81 ++++- sources/properties/terminaldata.cpp | 30 +- sources/properties/terminaldata.h | 4 +- sources/properties/xrefproperties.cpp | 29 +- sources/properties/xrefproperties.h | 4 +- sources/qetgraphicsitem/conductor.cpp | 43 ++- sources/qetgraphicsitem/conductor.h | 4 +- sources/qetgraphicsitem/conductortextitem.cpp | 8 +- sources/qetgraphicsitem/conductortextitem.h | 2 +- .../dynamicelementtextitem.cpp | 34 +- .../qetgraphicsitem/dynamicelementtextitem.h | 2 +- sources/qetgraphicsitem/independenttextitem.h | 2 +- sources/qetgraphicsitem/terminal.cpp | 25 +- sources/qetgraphicsitem/terminal.h | 4 +- sources/titleblockproperties.cpp | 58 ++-- sources/titleblockproperties.h | 5 +- 45 files changed, 617 insertions(+), 453 deletions(-) diff --git a/sources/borderproperties.cpp b/sources/borderproperties.cpp index 2901a9155..67a9388af 100644 --- a/sources/borderproperties.cpp +++ b/sources/borderproperties.cpp @@ -32,7 +32,7 @@ - 17 colonnes affichees de 60.0 px de large pour 20.0px de haut - 8 lignes affichees de 80.0 px de haut pour 20.0px de large */ -BorderProperties::BorderProperties() +BorderProperties::BorderProperties(): PropertiesInterface("border") { } @@ -80,7 +80,7 @@ bool BorderProperties::operator!=(const BorderProperties &bp) { } /** - @brief BorderProperties::toXml + @brief BorderProperties::toXmlPriv Exports dimensions as XML attributes added to element e. \~French Exporte les dimensions sous formes d'attributs XML ajoutes a l'element e. @@ -88,22 +88,17 @@ bool BorderProperties::operator!=(const BorderProperties &bp) { XML element to which attributes will be added \~French Element XML auquel seront ajoutes des attributs */ -QDomElement BorderProperties::toXml(QDomDocument &dom_doc) const { - - QDomElement e = dom_doc.createElement("border"); - - e.appendChild(createXmlProperty(dom_doc, "cols", columns_count)); - e.appendChild(createXmlProperty(dom_doc, "colsize", columns_width)); - e.appendChild(createXmlProperty(dom_doc, "rows", rows_count)); - e.appendChild(createXmlProperty(dom_doc, "rowsize", rows_height)); - e.appendChild(createXmlProperty(dom_doc, "displayrows", display_rows)); - e.appendChild(createXmlProperty(dom_doc, "displaycols", display_columns)); - - return e; +void BorderProperties::toXmlPriv(QDomElement& e) const { + e.appendChild(createXmlProperty("cols", columns_count)); + e.appendChild(createXmlProperty("colsize", columns_width)); + e.appendChild(createXmlProperty("rows", rows_count)); + e.appendChild(createXmlProperty("rowsize", rows_height)); + e.appendChild(createXmlProperty("displayrows", display_rows)); + e.appendChild(createXmlProperty("displaycols", display_columns)); } -/**RETURNS True - @brief BorderProperties::fromXml +/*!RETURNS True + @brief BorderProperties::fromXmlPriv Import dimensions from XML attributes of element e \~French Importe les dimensions a partir des attributs XML de l'element e @@ -111,7 +106,7 @@ QDomElement BorderProperties::toXml(QDomDocument &dom_doc) const { XML element whose attributes will be read \~French Element XML dont les attributs seront lus */ -bool BorderProperties::fromXml(const QDomElement &e) { +bool BorderProperties::fromXmlPriv(const QDomElement &e) { if (propertyInteger(e, "cols", &columns_count) == PropertyFlags::NoValidConversion || propertyDouble(e, "colsize", &columns_width) == PropertyFlags::NoValidConversion || diff --git a/sources/borderproperties.h b/sources/borderproperties.h index fec32bd07..0c5a305bc 100644 --- a/sources/borderproperties.h +++ b/sources/borderproperties.h @@ -37,8 +37,8 @@ class BorderProperties : public PropertiesInterface { bool operator==(const BorderProperties &); bool operator!=(const BorderProperties &); - QDomElement toXml(QDomDocument &dom_doc) const override; - bool fromXml(const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; + bool fromXmlPriv(const QDomElement &) override; static bool valideXml(QDomElement& e); void toSettings(QSettings &, const QString & = QString()) const override; void fromSettings(QSettings &, const QString & = QString()) override; diff --git a/sources/bordertitleblock.cpp b/sources/bordertitleblock.cpp index 97a18f7c9..9ac9bcb13 100644 --- a/sources/bordertitleblock.cpp +++ b/sources/bordertitleblock.cpp @@ -207,8 +207,8 @@ QRectF BorderTitleBlock::insideBorderRect() const Exports the title block current values to XML. @param xml_elmt the XML element attributes will be added to */ -void BorderTitleBlock::titleBlockToXml(QDomElement& doc) { - exportTitleBlock().toXml(doc); +QDomElement BorderTitleBlock::titleBlockToXml(QDomDocument& doc) { + return exportTitleBlock().toXml(doc); } /** diff --git a/sources/bordertitleblock.h b/sources/bordertitleblock.h index 8d27dea13..36c7952ae 100644 --- a/sources/bordertitleblock.h +++ b/sources/bordertitleblock.h @@ -174,7 +174,7 @@ class BorderTitleBlock : public QObject void setPreviousFolioNum(const QString &previous); void setNextFolioNum(const QString &next); - void titleBlockToXml(QDomElement &doc); + QDomElement titleBlockToXml(QDomDocument &doc); void titleBlockFromXml(const QDomElement &); void borderToXml(QDomElement &); void borderFromXml(const QDomElement &); diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 846600a52..2f0b31c66 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -23,7 +23,7 @@ /** Constructeur par defaut */ -SingleLineProperties::SingleLineProperties() +SingleLineProperties::SingleLineProperties(): PropertiesInterface("SingleLine") { } @@ -211,17 +211,14 @@ void SingleLineProperties::drawPen(QPainter *painter, ajoutes a l'element e. @param e Element XML auquel seront ajoutes des attributs */ -QDomElement SingleLineProperties::toXml(QDomDocument &doc) const { +void SingleLineProperties::toXmlPriv(QDomElement& e) const { - QDomElement e = doc.createElement("SingleLine"); - e.appendChild(createXmlProperty(doc, "ground", hasGround)); - e.appendChild(createXmlProperty(doc, "neutral", hasNeutral)); - e.appendChild(createXmlProperty(doc, "phase", phases)); + e.appendChild(createXmlProperty("ground", hasGround)); + e.appendChild(createXmlProperty("neutral", hasNeutral)); + e.appendChild(createXmlProperty("phase", phases)); if (isPen()) - e.appendChild(createXmlProperty(doc, "pen", true)); - - return e; + e.appendChild(createXmlProperty("pen", true)); } /** @@ -229,7 +226,7 @@ QDomElement SingleLineProperties::toXml(QDomDocument &doc) const { de l'element e @param e Element XML dont les attributs seront lus */ -bool SingleLineProperties::fromXml(const QDomElement &e) { +bool SingleLineProperties::fromXmlPriv(const QDomElement &e) { if (propertyBool(e, "ground", &hasGround) != PropertyFlags::Success || propertyBool(e, "neutral", &hasNeutral) != PropertyFlags::Success) return false; @@ -266,17 +263,7 @@ bool SingleLineProperties::valideXml(QDomElement& e) { multifilaire noir dont le texte est "_" */ ConductorProperties::ConductorProperties() : - type(Multi), - color(Qt::black), - text_color(Qt::black), - text("_"), - text_size(9), - cond_size(1), - verti_rotate_text(270), - horiz_rotate_text(0), - m_show_text(true), - m_one_text_per_folio(false), - style(Qt::SolidLine) + PropertiesInterface("defaultconductor") {} /** @@ -292,46 +279,45 @@ ConductorProperties::~ConductorProperties() Export conductor propertie, in the XML element 'e' @param e the xml element */ -QDomElement ConductorProperties::toXml(QDomDocument& doc) const +void ConductorProperties::toXmlPriv(QDomElement& e) const { - QDomElement e = doc.createElement("defaultconductor"); + e.appendChild(createXmlProperty("type", typeToString(type))); + e.appendChild(createXmlProperty("color", color)); - e.appendChild(createXmlProperty(doc, "type", typeToString(type))); - e.appendChild(createXmlProperty(doc, "color", color)); - - e.appendChild(createXmlProperty(doc, "bicolor", m_bicolor)); - e.appendChild(createXmlProperty(doc, "color2", m_color_2)); - e.appendChild(createXmlProperty(doc, "dash-size", m_dash_size)); + e.appendChild(createXmlProperty("bicolor", m_bicolor)); + e.appendChild(createXmlProperty("color2", m_color_2)); + e.appendChild(createXmlProperty("dash-size", m_dash_size)); if (type == Single) - e.appendChild(singleLineProperties.toXml(doc)); + { + QDomDocument doc; + e.appendChild(singleLineProperties.toXml(doc)); + } - e.appendChild(createXmlProperty(doc, "num", text)); - e.appendChild(createXmlProperty(doc, "text_color", text_color)); - e.appendChild(createXmlProperty(doc, "formula", m_formula)); - e.appendChild(createXmlProperty(doc, "function", m_function)); - e.appendChild(createXmlProperty(doc, "tension_protocol", m_tension_protocol)); - e.appendChild(createXmlProperty(doc, "conductor_color", m_wire_color)); - e.appendChild(createXmlProperty(doc, "conductor_section", m_wire_section)); - e.appendChild(createXmlProperty(doc, "numsize", text_size)); - e.appendChild(createXmlProperty(doc, "condsize", cond_size)); - e.appendChild(createXmlProperty(doc, "displaytext", m_show_text)); - e.appendChild(createXmlProperty(doc, "onetextperfolio", m_one_text_per_folio)); - e.appendChild(createXmlProperty(doc, "vertirotatetext", verti_rotate_text)); - e.appendChild(createXmlProperty(doc, "horizrotatetext", horiz_rotate_text)); + e.appendChild(createXmlProperty("num", text)); + e.appendChild(createXmlProperty("text_color", text_color)); + e.appendChild(createXmlProperty("formula", m_formula)); + e.appendChild(createXmlProperty("function", m_function)); + e.appendChild(createXmlProperty("tension_protocol", m_tension_protocol)); + e.appendChild(createXmlProperty("conductor_color", m_wire_color)); + e.appendChild(createXmlProperty("conductor_section", m_wire_section)); + e.appendChild(createXmlProperty("numsize", text_size)); + e.appendChild(createXmlProperty("condsize", cond_size)); + e.appendChild(createXmlProperty("displaytext", m_show_text)); + e.appendChild(createXmlProperty("onetextperfolio", m_one_text_per_folio)); + e.appendChild(createXmlProperty("vertirotatetext", verti_rotate_text)); + e.appendChild(createXmlProperty("horizrotatetext", horiz_rotate_text)); // TODO: implement //e.setAttribute("cable", m_cable); // e.setAttribute("bus", m_bus); QMetaEnum me = QMetaEnum::fromType(); - e.appendChild(createXmlProperty(doc, "horizontal-alignment", me.valueToKey(m_horizontal_alignment))); - e.appendChild(createXmlProperty(doc, "vertical-alignment", me.valueToKey(m_vertical_alignment))); + e.appendChild(createXmlProperty("horizontal-alignment", me.valueToKey(m_horizontal_alignment))); + e.appendChild(createXmlProperty("vertical-alignment", me.valueToKey(m_vertical_alignment))); QString conductor_style = writeStyle(); if (!conductor_style.isEmpty()) - e.appendChild(createXmlProperty(doc, "style", conductor_style)); - - return e; + e.appendChild(createXmlProperty("style", conductor_style)); } @@ -340,7 +326,7 @@ QDomElement ConductorProperties::toXml(QDomDocument& doc) const Import conductor propertie, from the attribute of the xml element 'e' @param e the xml document */ -bool ConductorProperties::fromXml(const QDomElement &e) +bool ConductorProperties::fromXmlPriv(const QDomElement &e) { // get conductor color propertyColor(e, "color", &color); diff --git a/sources/conductorproperties.h b/sources/conductorproperties.h index 77ec6a891..1e35f2b65 100644 --- a/sources/conductorproperties.h +++ b/sources/conductorproperties.h @@ -39,8 +39,8 @@ class SingleLineProperties: public PropertiesInterface { unsigned short int phasesCount(); bool isPen() const; void draw(QPainter *, QET::ConductorSegmentType, const QRectF &); - QDomElement toXml(QDomDocument& doc) const override; - bool fromXml(const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; + bool fromXmlPriv(const QDomElement &) override; static bool valideXml(QDomElement& element); void toSettings(QSettings &, const QString & = QString()) const; void fromSettings(QSettings &, const QString & = QString()); @@ -83,7 +83,7 @@ class ConductorProperties: public PropertiesInterface //Attributes - ConductorType type{ConductorType::Single}; + ConductorType type{ConductorType::Multi}; // TODO: set default values! QColor color{QColor(Qt::black)}, @@ -91,7 +91,7 @@ class ConductorProperties: public PropertiesInterface text_color{QColor(Qt::black)}; QString - text, + text{"_"}, m_function, m_tension_protocol, m_wire_color, @@ -105,11 +105,11 @@ class ConductorProperties: public PropertiesInterface double cond_size{1}, - verti_rotate_text, - horiz_rotate_text; + verti_rotate_text{270}, + horiz_rotate_text{0}; bool m_show_text{true}, - m_one_text_per_folio{true}, + m_one_text_per_folio{false}, m_bicolor = false; Qt::Alignment @@ -121,8 +121,8 @@ class ConductorProperties: public PropertiesInterface SingleLineProperties singleLineProperties; // methods - QDomElement toXml(QDomDocument &doc) const override; - bool fromXml(const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; + bool fromXmlPriv(const QDomElement &) override; static bool valideXml(QDomElement& element); void toSettings(QSettings &, const QString & = QString()) const override; void fromSettings(QSettings &, const QString & = QString()) override; diff --git a/sources/diagram.cpp b/sources/diagram.cpp index a49677840..66cd1f7ef 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -738,7 +738,7 @@ QDomDocument Diagram::toXml(bool whole_content) { // proprietes du schema if (whole_content) { // TODO: compare with old version - border_and_titleblock.titleBlockToXml(dom_root); + dom_root.appendChild(border_and_titleblock.titleBlockToXml(document)); border_and_titleblock.borderToXml(dom_root); // Default conductor properties diff --git a/sources/editor/graphicspart/abstractpartellipse.h b/sources/editor/graphicspart/abstractpartellipse.h index afc9f5d72..b2afe067c 100644 --- a/sources/editor/graphicspart/abstractpartellipse.h +++ b/sources/editor/graphicspart/abstractpartellipse.h @@ -79,8 +79,8 @@ class AbstractPartEllipse : public CustomElementGraphicPart protected: QList saved_points_; QRectF m_rect; - qreal m_start_angle; - qreal m_span_angle; + qreal m_start_angle{0}; + qreal m_span_angle{-1440}; QVector m_handler_vector; }; diff --git a/sources/editor/graphicspart/customelementgraphicpart.cpp b/sources/editor/graphicspart/customelementgraphicpart.cpp index 6cfb7b4ed..8eab68d5a 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.cpp +++ b/sources/editor/graphicspart/customelementgraphicpart.cpp @@ -162,7 +162,7 @@ void CustomElementGraphicPart::setAntialiased(const bool b) Each style separate by ; and name-style/value are separate by : @param qde : QDOmElement used to write the style. */ -void CustomElementGraphicPart::stylesToXml(QDomDocument &xml_document, QDomElement &qde) const +void CustomElementGraphicPart::stylesToXml(QDomElement &qde) const { QString css_like_styles; @@ -497,8 +497,8 @@ void CustomElementGraphicPart::stylesToXml(QDomDocument &xml_document, QDomEleme else if (_color == HTMLGrayBlackColor) css_like_styles += "HTMLGrayBlack"; else if (_color == NoneColor) css_like_styles += "none"; - qde.appendChild(createXmlProperty(xml_document, "style", css_like_styles)); - qde.appendChild(createXmlProperty(xml_document, "antialias", _antialiased ? "true" : "false")); + qde.appendChild(createXmlProperty("style", css_like_styles)); + qde.appendChild(createXmlProperty("antialias", _antialiased ? "true" : "false")); } diff --git a/sources/editor/graphicspart/customelementgraphicpart.h b/sources/editor/graphicspart/customelementgraphicpart.h index 1dd2ec3f2..0b7f0c70a 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.h +++ b/sources/editor/graphicspart/customelementgraphicpart.h @@ -303,7 +303,7 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar virtual void resetAllHandlerColor() {} protected: - void stylesToXml (QDomDocument &xml_document, QDomElement &) const; + void stylesToXml (QDomElement &) const; void stylesFromXml(const QDomElement &); void resetStyles (); void applyStylesToQPainter(QPainter &) const; diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index 0ae95aeac..4b1d145f7 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -29,10 +29,9 @@ @param parent : parent item */ PartArc::PartArc(QETElementEditor *editor, QGraphicsItem *parent) : - AbstractPartEllipse(editor, parent) + AbstractPartEllipse(editor, parent) { - m_start_angle = 0; - m_span_angle = -1440; + setTagName("arc"); } /** @@ -102,23 +101,22 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, @param xml_document : Xml document to use for create the xml element. @return : an xml element that describe this arc */ -QDomElement PartArc::toXml(QDomDocument &xml_document) const +void PartArc::toXmlPriv(QDomElement& e) const { - QDomElement xml_element = xml_document.createElement("arc"); + e.setTagName("arc"); QPointF top_left(sceneTopLeft()); - xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x())); - xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y())); - xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width())); - xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height())); + e.appendChild(createXmlProperty("x", top_left.x())); + e.appendChild(createXmlProperty("y", top_left.y())); + e.appendChild(createXmlProperty("width", rect().width())); + e.appendChild(createXmlProperty("height", rect().height())); //to maintain compatibility with the previous version, we write the angle in degrees. - xml_element.appendChild(createXmlProperty(xml_document, "start", m_start_angle / 16)); - xml_element.appendChild(createXmlProperty(xml_document, "angle", m_span_angle / 16)); + e.appendChild(createXmlProperty("start", m_start_angle / 16)); + e.appendChild(createXmlProperty("angle", m_span_angle / 16)); - stylesToXml(xml_document, xml_element); - return(xml_element); + stylesToXml(e); } /** @@ -126,7 +124,7 @@ QDomElement PartArc::toXml(QDomDocument &xml_document) const Import the properties of this arc from a xml element. @param qde : Xml document to use. */ -bool PartArc::fromXml(const QDomElement &qde) { +bool PartArc::fromXmlPriv(const QDomElement &qde) { stylesFromXml(qde); double x=0, y=0, w=0, h=0; diff --git a/sources/editor/graphicspart/partarc.h b/sources/editor/graphicspart/partarc.h index a131fab19..9da63a99f 100644 --- a/sources/editor/graphicspart/partarc.h +++ b/sources/editor/graphicspart/partarc.h @@ -51,8 +51,8 @@ class PartArc : public AbstractPartEllipse //Name and XML QString name() const override { return(QObject::tr("arc", "element part name")); } QString xmlName() const override { return(QString("arc")); } - QDomElement toXml (QDomDocument &) const override; - bool fromXml (const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; + bool fromXmlPriv (const QDomElement &) override; static bool valideXml(QDomElement& element); void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/} void fromSettings(QSettings &,const QString & = QString()) override{/*TODO: implement*/} diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp index 968ea2111..fa2894477 100644 --- a/sources/editor/graphicspart/partdynamictextfield.cpp +++ b/sources/editor/graphicspart/partdynamictextfield.cpp @@ -30,6 +30,7 @@ PartDynamicTextField::PartDynamicTextField(QETElementEditor *editor, QGraphicsIt CustomElementPart(editor), m_uuid(QUuid::createUuid()) { + setTagName(xmlName()); setDefaultTextColor(Qt::black); setFont(QETApp::dynamicTextsItemFont()); QSettings settings; @@ -93,71 +94,72 @@ void PartDynamicTextField::handleUserTransformation( @param dom_doc @return */ -QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const +void PartDynamicTextField::toXmlPriv(QDomElement& e) const { - QDomElement root_element = dom_doc.createElement(xmlName()); - root_element.appendChild(createXmlProperty(dom_doc, "x", pos().x())); - root_element.appendChild(createXmlProperty(dom_doc, "y", pos().y())); - root_element.appendChild(createXmlProperty(dom_doc, "z", zValue())); - root_element.appendChild(createXmlProperty(dom_doc, "rotation", QET::correctAngle(rotation()))); + e.appendChild(createXmlProperty("x", pos().x())); + e.appendChild(createXmlProperty("y", pos().y())); + e.appendChild(createXmlProperty("z", zValue())); + e.appendChild(createXmlProperty("rotation", QET::correctAngle(rotation()))); - root_element.appendChild(createXmlProperty(dom_doc, "font", font().toString())); - root_element.appendChild(createXmlProperty(dom_doc, "uuid", m_uuid)); - root_element.appendChild(createXmlProperty(dom_doc, "frame", m_frame)); - root_element.appendChild(createXmlProperty(dom_doc, "text_width", m_text_width)); + e.appendChild(createXmlProperty("font", font().toString())); + e.appendChild(createXmlProperty("uuid", m_uuid)); + e.appendChild(createXmlProperty("frame", m_frame)); + e.appendChild(createXmlProperty("text_width", m_text_width)); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); - root_element.appendChild(createXmlProperty(dom_doc, "text_from", me.valueToKey(m_text_from))); + e.appendChild(createXmlProperty("text_from", me.valueToKey(m_text_from))); me = QMetaEnum::fromType(); if(this -> alignment() &Qt::AlignRight) - root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignRight))); + e.appendChild(createXmlProperty("Halignment", me.valueToKey(Qt::AlignRight))); else if(this -> alignment() &Qt::AlignLeft) - root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignLeft))); + e.appendChild(createXmlProperty("Halignment", me.valueToKey(Qt::AlignLeft))); else if(this -> alignment() &Qt::AlignHCenter) - root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignHCenter))); + e.appendChild(createXmlProperty("Halignment", me.valueToKey(Qt::AlignHCenter))); if(this -> alignment() &Qt::AlignBottom) - root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignBottom))); + e.appendChild(createXmlProperty("Valignment", me.valueToKey(Qt::AlignBottom))); else if(this -> alignment() & Qt::AlignTop) - root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignTop))); + e.appendChild(createXmlProperty("Valignment", me.valueToKey(Qt::AlignTop))); else if(this -> alignment() &Qt::AlignVCenter) - root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignVCenter))); + e.appendChild(createXmlProperty("Valignment", me.valueToKey(Qt::AlignVCenter))); + QDomDocument dom_doc; QDomElement dom_text = dom_doc.createElement("text"); dom_text.appendChild(dom_doc.createTextNode(toPlainText())); - root_element.appendChild(dom_text); + e.appendChild(dom_text); //Info name + // TODO: move it into a property if(!m_info_name.isEmpty()) { QDomElement dom_info_name = dom_doc.createElement("info_name"); dom_info_name.appendChild(dom_doc.createTextNode(m_info_name)); - root_element.appendChild(dom_info_name); + e.appendChild(dom_info_name); } //Composite text + // TODO: move it into a property if(!m_composite_text.isEmpty()) { QDomElement dom_comp_text = dom_doc.createElement("composite_text"); dom_comp_text.appendChild(dom_doc.createTextNode(m_composite_text)); - root_element.appendChild(dom_comp_text); + e.appendChild(dom_comp_text); } //Color + // TODO: move it into a property if(color() != QColor(Qt::black)) { QDomElement dom_color = dom_doc.createElement("color"); dom_color.appendChild(dom_doc.createTextNode(color().name())); - root_element.appendChild(dom_color); + e.appendChild(dom_color); } - - return root_element; } /** @brief PartDynamicTextField::fromXml @param dom_elmt */ -bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt) +bool PartDynamicTextField::fromXmlPriv(const QDomElement &dom_elmt) { if (dom_elmt.tagName() != xmlName()) { qDebug() << "PartDynamicTextField::fromXml : Wrong tagg name"; diff --git a/sources/editor/graphicspart/partdynamictextfield.h b/sources/editor/graphicspart/partdynamictextfield.h index facee52cc..5563ff455 100644 --- a/sources/editor/graphicspart/partdynamictextfield.h +++ b/sources/editor/graphicspart/partdynamictextfield.h @@ -75,8 +75,8 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart void startUserTransformation(const QRectF &initial_selection_rect) override; void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override; - QDomElement toXml(QDomDocument &dom_doc) const override; - bool fromXml(const QDomElement &dom_elmt) override; + void toXmlPriv(QDomElement&) const override; + bool fromXmlPriv(const QDomElement &dom_elmt) override; void fromTextFieldXml(const QDomElement &dom_element); static bool valideXml(QDomElement& dom_elmt); void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/} diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index 393e2d21e..b7c24bc69 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -79,41 +79,37 @@ void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio } /** - @brief PartEllipse::toXml + @brief PartEllipse::toXmlPriv Export this ellipse in xml - @param xml_document : Xml document to use for create the xml element. @return : an xml element that describe this ellipse */ -QDomElement PartEllipse::toXml(QDomDocument &xml_document) const +void PartEllipse::toXmlPriv(QDomElement& e) const { - QDomElement xml_element; if (qFuzzyCompare(rect().width(), rect().height())) { - xml_element = xml_document.createElement("circle"); - xml_element.appendChild(createXmlProperty(xml_document, "diameter", rect().width())); + e.setTagName("circle"); + e.appendChild(createXmlProperty("diameter", rect().width())); } else { - xml_element = xml_document.createElement("ellipse"); - xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width())); - xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height())); + e.setTagName("ellipse"); + e.appendChild(createXmlProperty("width", rect().width())); + e.appendChild(createXmlProperty("height", rect().height())); } QPointF top_left(sceneTopLeft()); - xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x())); - xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y())); + e.appendChild(createXmlProperty("x", top_left.x())); + e.appendChild(createXmlProperty("y", top_left.y())); - stylesToXml(xml_document, xml_element); - - return(xml_element); + stylesToXml(e); } /** - @brief PartEllipse::fromXml + @brief PartEllipse::fromXmlPriv Import the properties of this ellipse from a xml element. @param qde : Xml document to use. */ -bool PartEllipse::fromXml(const QDomElement &qde) +bool PartEllipse::fromXmlPriv(const QDomElement &qde) { stylesFromXml(qde); double x=0, y=0, width=0, height=0; diff --git a/sources/editor/graphicspart/partellipse.h b/sources/editor/graphicspart/partellipse.h index 89852006c..8e99b7005 100644 --- a/sources/editor/graphicspart/partellipse.h +++ b/sources/editor/graphicspart/partellipse.h @@ -52,8 +52,8 @@ class PartEllipse : public AbstractPartEllipse //Name and XML QString name() const override { return(QObject::tr("ellipse", "element part name")); } QString xmlName() const override { return(QString("ellipse")); } - QDomElement toXml (QDomDocument &) const override; - bool fromXml (const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; + bool fromXmlPriv(const QDomElement &) override; static bool valideXml(QDomElement& element); void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/} void fromSettings(QSettings &,const QString & = QString()) override{/*TODO: implement*/} diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index 21b2e1607..73f8aa787 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -30,13 +30,10 @@ @param parent : parent item */ PartLine::PartLine(QETElementEditor *editor, QGraphicsItem *parent) : - CustomElementGraphicPart(editor, parent), - first_end(Qet::None), - first_length(1.5), - second_end(Qet::None), - second_length(1.5), - m_undo_command(nullptr) -{} + CustomElementGraphicPart(editor, parent) +{ + setTagName("line"); +} /// Destructeur PartLine::~PartLine() @@ -105,30 +102,27 @@ void PartLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, } /** - @brief PartLine::toXml + @brief PartLine::toXmlPriv Export this line in xml @param xml_document : Xml document to use for create the xml element. @return an xml element that describe this line */ -QDomElement PartLine::toXml(QDomDocument &xml_document) const +void PartLine::toXmlPriv(QDomElement& e) const { QPointF p1(sceneP1()); QPointF p2(sceneP2()); - QDomElement xml_element = xml_document.createElement("line"); + e.appendChild(createXmlProperty("x1", p1.x())); + e.appendChild(createXmlProperty("y1", p1.y())); + e.appendChild(createXmlProperty("x2", p2.x())); + e.appendChild(createXmlProperty("y2", p2.y())); - xml_element.appendChild(createXmlProperty(xml_document, "x1", p1.x())); - xml_element.appendChild(createXmlProperty(xml_document, "y1", p1.y())); - xml_element.appendChild(createXmlProperty(xml_document, "x2", p2.x())); - xml_element.appendChild(createXmlProperty(xml_document, "y2", p2.y())); - - xml_element.appendChild(createXmlProperty(xml_document, "end1", Qet::endTypeToString(first_end))); - xml_element.appendChild(createXmlProperty(xml_document, "length1", first_length)); - xml_element.appendChild(createXmlProperty(xml_document, "end2", Qet::endTypeToString(second_end))); - xml_element.appendChild(createXmlProperty(xml_document, "length2", second_length)); + e.appendChild(createXmlProperty("end1", Qet::endTypeToString(first_end))); + e.appendChild(createXmlProperty("length1", first_length)); + e.appendChild(createXmlProperty("end2", Qet::endTypeToString(second_end))); + e.appendChild(createXmlProperty("length2", second_length)); - stylesToXml(xml_document, xml_element); - return(xml_element); + stylesToXml(e); } /** @@ -136,7 +130,7 @@ QDomElement PartLine::toXml(QDomDocument &xml_document) const Import the properties of this line from a xml element. @param qde : Xml document to use */ -bool PartLine::fromXml(const QDomElement &qde) { +bool PartLine::fromXmlPriv(const QDomElement &qde) { stylesFromXml(qde); double x1 = 0, y1 = 0, x2 = 0, y2 = 0; diff --git a/sources/editor/graphicspart/partline.h b/sources/editor/graphicspart/partline.h index e48b5bd0f..f85042c65 100644 --- a/sources/editor/graphicspart/partline.h +++ b/sources/editor/graphicspart/partline.h @@ -70,8 +70,8 @@ class PartLine : public CustomElementGraphicPart void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override; QString name() const override { return(QObject::tr("ligne", "element part name")); } QString xmlName() const override { return(QString("line")); } - QDomElement toXml(QDomDocument &) const override; - bool fromXml(const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; + bool fromXmlPriv(const QDomElement &) override; bool valideXml(QDomElement& element) const; void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/} void fromSettings(QSettings &,const QString & = QString()) override{/*TODO: implement*/} @@ -117,15 +117,15 @@ class PartLine : public CustomElementGraphicPart QRectF secondEndCircleRect() const; /*****************/ - Qet::EndType first_end; + Qet::EndType first_end{Qet::EndType::None}; qreal first_length{1.5}; - Qet::EndType second_end; + Qet::EndType second_end{Qet::EndType::None}; qreal second_length{1.5}; QList saved_points_; QLineF m_line; int m_vector_index = -1; - QPropertyUndoCommand *m_undo_command; + QPropertyUndoCommand *m_undo_command{nullptr}; QVector m_handler_vector; }; #endif diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index 7a6c92415..dcf76d96e 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -35,6 +35,7 @@ PartPolygon::PartPolygon(QETElementEditor *editor, QGraphicsItem *parent) : m_closed(false), m_undo_command(nullptr) { + setTagName("polygon"); m_insert_point = new QAction(tr("Ajouter un point"), this); m_insert_point->setIcon(QET::Icons::Add); connect(m_insert_point, &QAction::triggered, this, &PartPolygon::insertPoint); @@ -89,7 +90,7 @@ void PartPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio Import the properties of this polygon from a xml element @param qde : Xml document to use */ -bool PartPolygon::fromXml(const QDomElement &qde) +bool PartPolygon::fromXmlPriv(const QDomElement &qde) { stylesFromXml(qde); @@ -123,26 +124,23 @@ bool PartPolygon::fromXml(const QDomElement &qde) } /** - @brief PartPolygon::toXml + @brief PartPolygon::toXmlPriv Export this polygin in xml - @param xml_document : Xml document to use for create the xml element - @return an xml element that describe this polygon + @param e: properties get part of this DomElement */ -QDomElement PartPolygon::toXml(QDomDocument &xml_document) const +void PartPolygon::toXmlPriv(QDomElement& e) const { - QDomElement xml_element = xml_document.createElement("polygon"); int i = 1; foreach(QPointF point, m_polygon) { point = mapToScene(point); - xml_element.appendChild(createXmlProperty(xml_document, QString("x%1").arg(i), point.x())); - xml_element.appendChild(createXmlProperty(xml_document, QString("y%1").arg(i), point.y())); + e.appendChild(createXmlProperty(QString("x%1").arg(i), point.x())); + e.appendChild(createXmlProperty(QString("y%1").arg(i), point.y())); ++ i; } - xml_element.appendChild(createXmlProperty(xml_document, "closed", m_closed)); + e.appendChild(createXmlProperty("closed", m_closed)); - stylesToXml(xml_document, xml_element); - return(xml_element); + stylesToXml(e); } bool PartPolygon::valideXml(QDomElement& element) { diff --git a/sources/editor/graphicspart/partpolygon.h b/sources/editor/graphicspart/partpolygon.h index 1052ed44d..96a337f1a 100644 --- a/sources/editor/graphicspart/partpolygon.h +++ b/sources/editor/graphicspart/partpolygon.h @@ -61,8 +61,8 @@ class PartPolygon : public CustomElementGraphicPart QString name() const override { return(QObject::tr("polygone", "element part name")); } QString xmlName() const override { return(QString("polygon")); } - bool fromXml(const QDomElement &) override; - QDomElement toXml(QDomDocument &) const override; + bool fromXmlPriv(const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; static bool valideXml(QDomElement& element); void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/} void fromSettings(QSettings &,const QString & = QString()) override{/*TODO: implement*/} @@ -109,7 +109,7 @@ class PartPolygon : public CustomElementGraphicPart void removePoint(); - bool m_closed; + bool m_closed{false}; QList saved_points_; QPolygonF m_polygon; QPropertyUndoCommand *m_undo_command; diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index 01411cefb..67917e28b 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -30,7 +30,9 @@ */ PartRectangle::PartRectangle(QETElementEditor *editor, QGraphicsItem *parent) : CustomElementGraphicPart(editor, parent) -{} +{ + setTagName("rect"); +} /** @brief PartRectangle::~PartRectangle @@ -80,20 +82,19 @@ void PartRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt } /** - @brief PartRectangle::toXml + @brief PartRectangle::toXmlPriv Export this rectangle in xml @param xml_document : Xml document to use for create the xml element. @return an xml element that describe this ellipse */ -QDomElement PartRectangle::toXml(QDomDocument &xml_document) const +void PartRectangle::toXmlPriv(QDomElement& e) const { - QDomElement xml_element = xml_document.createElement("rect"); QPointF top_left(sceneTopLeft()); - xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x())); - xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y())); - xml_element.appendChild(createXmlProperty(xml_document, "width", m_rect.width())); - xml_element.appendChild(createXmlProperty(xml_document, "height", m_rect.height())); + e.appendChild(createXmlProperty("x", top_left.x())); + e.appendChild(createXmlProperty("y", top_left.y())); + e.appendChild(createXmlProperty("width", m_rect.width())); + e.appendChild(createXmlProperty("height", m_rect.height())); QRectF rect = m_rect.normalized(); qreal x = m_xRadius; @@ -105,14 +106,13 @@ QDomElement PartRectangle::toXml(QDomDocument &xml_document) const y = rect.height()/2; } - xml_element.setAttribute("rx", QString::number(m_xRadius)); - xml_element.setAttribute("ry", QString::number(m_yRadius)); + e.setAttribute("rx", QString::number(m_xRadius)); + e.setAttribute("ry", QString::number(m_yRadius)); - xml_element.appendChild(createXmlProperty(xml_document, "rx", m_xRadius)); - xml_element.appendChild(createXmlProperty(xml_document, "ry", m_yRadius)); + e.appendChild(createXmlProperty("rx", m_xRadius)); + e.appendChild(createXmlProperty("ry", m_yRadius)); - stylesToXml(xml_document, xml_element); - return(xml_element); + stylesToXml(e); } /** @@ -120,7 +120,7 @@ QDomElement PartRectangle::toXml(QDomDocument &xml_document) const Import the properties of this rectangle from a xml element. @param qde : Xml document to use. */ -bool PartRectangle::fromXml(const QDomElement &qde) +bool PartRectangle::fromXmlPriv(const QDomElement &qde) { stylesFromXml(qde); diff --git a/sources/editor/graphicspart/partrectangle.h b/sources/editor/graphicspart/partrectangle.h index a1ac924c5..4fffb516f 100644 --- a/sources/editor/graphicspart/partrectangle.h +++ b/sources/editor/graphicspart/partrectangle.h @@ -60,8 +60,8 @@ class PartRectangle : public CustomElementGraphicPart QString name () const override { return(QObject::tr("rectangle", "element part name")); } QString xmlName () const override { return(QString("rect")); } - QDomElement toXml (QDomDocument &) const override; - bool fromXml (const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; + bool fromXmlPriv (const QDomElement &) override; static bool valideXml(QDomElement& element); void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/} void fromSettings(QSettings &,const QString & = QString()) override{/*TODO: implement*/} diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 5fced7821..1a79ca0a4 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -29,6 +29,7 @@ PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) : CustomElementGraphicPart(editor, parent) { + setTagName("terminal"); d = new TerminalData(this); d->m_name = tr("terminal"); d -> m_orientation = Qet::North; @@ -46,7 +47,7 @@ PartTerminal::~PartTerminal() Importe les proprietes d'une borne depuis un element XML @param xml_elmt Element XML a lire */ -bool PartTerminal::fromXml(const QDomElement &xml_elmt) { +bool PartTerminal::fromXmlPriv(const QDomElement &xml_elmt) { // update part and add uuid, which is used in the new version to connect terminals together // if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach @@ -67,21 +68,16 @@ bool PartTerminal::fromXml(const QDomElement &xml_elmt) { @param xml_document Document XML a utiliser pour creer l'element XML @return un element XML decrivant la borne */ -QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { +void PartTerminal::toXmlPriv(QDomElement& e) const { - QDomElement qdo = xml_document.createElement("terminal"); - - qdo.appendChild(createXmlProperty(xml_document, "uuid", d->m_uuid)); + e.appendChild(createXmlProperty("uuid", d->m_uuid)); d->m_pos = pos(); // Do not store terminal data in its own child - QDomElement terminalDataElement = d->toXml(xml_document); - for (int i=0; i < terminalDataElement.childNodes().length(); i++) { - qdo.appendChild(terminalDataElement.childNodes().at(i).cloneNode()); // cloneNode() is important, otherwise no deep clone is made - } + QDomDocument doc = e.ownerDocument(); + e.appendChild(d->toXml(doc)); - return qdo; } bool PartTerminal::valideXml(QDomElement& element) { diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index 3b6847057..4de842328 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -56,8 +56,8 @@ class PartTerminal : public CustomElementGraphicPart */ int type() const override { return Type; } QString xmlName() const override { return(QString("terminal")); } - bool fromXml(const QDomElement &) override; - QDomElement toXml(QDomDocument &) const override; + bool fromXmlPriv(const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; static bool valideXml(QDomElement& element); void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/} void fromSettings(QSettings &,const QString & = QString()) override{/*TODO: implement*/} diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp index 2a14b4802..ab3bd55ed 100644 --- a/sources/editor/graphicspart/parttext.cpp +++ b/sources/editor/graphicspart/parttext.cpp @@ -67,7 +67,7 @@ PartText::~PartText() Importe les proprietes d'un texte statique depuis un element XML @param xml_element Element XML a lire */ -bool PartText::fromXml(const QDomElement &xml_element) +bool PartText::fromXmlPriv(const QDomElement &xml_element) { int size; QString font; @@ -117,18 +117,16 @@ bool PartText::fromXml(const QDomElement &xml_element) @param xml_document Document XML a utiliser pour creer l'element XML @return un element XML decrivant le texte statique */ -QDomElement PartText::toXml(QDomDocument &xml_document) const +void PartText::toXmlPriv(QDomElement& e) const { - QDomElement xml_element = xml_document.createElement(xmlName()); + //QDomElement xml_element = xml_document.createElement(xmlName()); - xml_element.appendChild(createXmlProperty(xml_document, "x", pos().x())); - xml_element.appendChild(createXmlProperty(xml_document, "y", pos().y())); - xml_element.appendChild(createXmlProperty(xml_document, "text", toPlainText())); - xml_element.appendChild(createXmlProperty(xml_document, "font", font().toString())); - xml_element.appendChild(createXmlProperty(xml_document, "rotation", rotation())); - xml_element.appendChild(createXmlProperty(xml_document, "color", defaultTextColor().name())); - - return(xml_element); + e.appendChild(createXmlProperty("x", pos().x())); + e.appendChild(createXmlProperty("y", pos().y())); + e.appendChild(createXmlProperty("text", toPlainText())); + e.appendChild(createXmlProperty("font", font().toString())); + e.appendChild(createXmlProperty("rotation", rotation())); + e.appendChild(createXmlProperty("color", defaultTextColor().name())); } bool PartText::valideXml(QDomElement& element) { diff --git a/sources/editor/graphicspart/parttext.h b/sources/editor/graphicspart/parttext.h index 296ca3d81..2b5f67955 100644 --- a/sources/editor/graphicspart/parttext.h +++ b/sources/editor/graphicspart/parttext.h @@ -59,11 +59,11 @@ class PartText : public QGraphicsTextItem, public CustomElementPart { int type() const override { return Type; } QString name() const override { return(QObject::tr("texte", "element part name")); } QString xmlName() const override { return(QString("text")); } - bool fromXml(const QDomElement &) override; + bool fromXmlPriv(const QDomElement &) override; static bool valideXml(QDomElement& element); void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/} void fromSettings(QSettings &,const QString & = QString()) override{/*TODO: implement*/} - QDomElement toXml(QDomDocument &) const override; + void toXmlPriv(QDomElement&) const override; void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));} bool isUseless() const override; QRectF sceneGeometricRect() const override; diff --git a/sources/properties/elementdata.cpp b/sources/properties/elementdata.cpp index 1a500dd90..abf7e1c3b 100644 --- a/sources/properties/elementdata.cpp +++ b/sources/properties/elementdata.cpp @@ -29,9 +29,8 @@ void ElementData::fromSettings(QSettings &settings, const QString& prefix) { Q_UNUSED(prefix) } -QDomElement ElementData::toXml(QDomDocument &xml_element) const { - Q_UNUSED(xml_element) - return QDomElement(); +void ElementData::toXmlPriv(QDomElement& e) const { + Q_UNUSED(e) } /** @@ -42,7 +41,7 @@ QDomElement ElementData::toXml(QDomDocument &xml_element) const { * @param xml_element : tagName must be 'definition' * @return true is successfuly loaded */ -bool ElementData::fromXml(const QDomElement &xml_element) +bool ElementData::fromXmlPriv(const QDomElement &xml_element) { if(xml_element.tagName() != "definition" || xml_element.attribute("type") != "element") { diff --git a/sources/properties/elementdata.h b/sources/properties/elementdata.h index 9353efce7..2393445d7 100644 --- a/sources/properties/elementdata.h +++ b/sources/properties/elementdata.h @@ -87,8 +87,8 @@ class ElementData : public PropertiesInterface void toSettings(QSettings &settings, const QString& prefix = QString()) const override; void fromSettings(QSettings &settings, const QString& prefix = QString()) override; - QDomElement toXml(QDomDocument &xml_element) const override; - bool fromXml(const QDomElement &xml_element) override; + void toXmlPriv(QDomElement &) const override; + bool fromXmlPriv(const QDomElement &xml_element) override; QDomElement kindInfoToXml(QDomDocument &document); bool operator==(const ElementData &data) const; diff --git a/sources/properties/propertiesinterface.cpp b/sources/properties/propertiesinterface.cpp index c5f1ac260..67fc0c969 100644 --- a/sources/properties/propertiesinterface.cpp +++ b/sources/properties/propertiesinterface.cpp @@ -28,12 +28,23 @@ namespace { const QString stringS = "string"; const QString uuidS = "uuid"; const QString colorS = "color"; + + const QString userPropertiesS = "userProperties"; + + PropertiesInterface::PropertyFlags debug(PropertiesInterface::PropertyFlags flag, const QDomElement &e, const QString& attribute_name, const QString& attr, const QString& type) + { + if (flag == PropertiesInterface::PropertyFlags::NoValidConversion) + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << type << ". value: " << attr; + + return flag; + } } /** @brief PropertiesInterface::PropertiesInterface */ -PropertiesInterface::PropertiesInterface() +PropertiesInterface::PropertiesInterface(const QString &tagname): + mTagName(tagname) { } @@ -44,61 +55,91 @@ PropertiesInterface::~PropertiesInterface() { } +void PropertiesInterface::setTagName(const QString& tagname) +{ + mTagName = tagname; +} + +QDomElement PropertiesInterface::toXml (QDomDocument &xml_document) const +{ + QDomElement element = xml_document.createElement(mTagName); + toXmlPriv(element); + propertiesToXml(element); + + return element; +} + +bool PropertiesInterface::fromXml (const QDomElement &xml_element) +{ + if (!fromXmlPriv(xml_element)) + return false; + + if (!propertiesFromXml(xml_element)) + return false; +} + bool PropertiesInterface::valideXml(QDomElement& element) { qDebug(QString("ValideXml() is not implemented. File: %1, Line: %2").arg(__FILE__).arg(__LINE__).toStdString().data()); return false; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const QString value) { - QDomElement p = doc.createElement("property"); +QDomElement PropertiesInterface::createXmlProperty(const QString& name, const QString value) { + QDomDocument doc; + QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", stringS); p.setAttribute("value", value); return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const char* value) { - QDomElement p = doc.createElement("property"); +QDomElement PropertiesInterface::createXmlProperty(const QString& name, const char* value) { + QDomDocument doc; + QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", stringS); p.setAttribute("value", value); return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const int value) { - QDomElement p = doc.createElement("property"); +QDomElement PropertiesInterface::createXmlProperty(const QString& name, const int value) { + QDomDocument doc; + QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", integerS); p.setAttribute("value", QString::number(value)); return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const double value) { - QDomElement p = doc.createElement("property"); +QDomElement PropertiesInterface::createXmlProperty(const QString& name, const double value) { + QDomDocument doc; + QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", doubleS); p.setAttribute("value", QString::number(value)); return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const bool value) { - QDomElement p = doc.createElement("property"); +QDomElement PropertiesInterface::createXmlProperty(const QString& name, const bool value) { + QDomDocument doc; + QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", boolS); p.setAttribute("value", QString::number(value)); return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) { - QDomElement p = doc.createElement("property"); +QDomElement PropertiesInterface::createXmlProperty(const QString& name, const QUuid value) { + QDomDocument doc; + QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", uuidS); p.setAttribute("value", value.toString()); return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) { - QDomElement p = doc.createElement("property"); +QDomElement PropertiesInterface::createXmlProperty(const QString& name, const QColor value) { + QDomDocument doc; + QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", colorS); p.setAttribute("value", value.name()); @@ -167,18 +208,21 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QD return PropertyFlags::NotFound; } - // verifie la validite de l'attribut - bool ok; - int tmp = attr.toInt(&ok); - if (!ok) { - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr; - return PropertyFlags::NoValidConversion; - } + return debug(propertyInteger(attr, entier), e, attribute_name, attr, integerS); +} - if (entier != nullptr) - *entier = tmp; +PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QString& value, int* entier) { + // verifie la validite de l'attribut + bool ok; + int tmp = value.toInt(&ok); + if (!ok) { + return PropertyFlags::NoValidConversion; + } - return PropertyFlags::Success; + if (entier != nullptr) + *entier = tmp; + + return PropertyFlags::Success; } PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel) { @@ -189,18 +233,22 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDo return PropertyFlags::NotFound; } - // verifie la validite de l'attribut - bool ok; - double tmp = attr.toDouble(&ok); - if (!ok) { - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << doubleS << ". value: " << attr; - return PropertyFlags::NoValidConversion; - } + return debug(propertyDouble(attr, reel), e, attribute_name, attr, doubleS); +} - if (reel != nullptr) - *reel = tmp; +PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QString& value, double* reel) +{ + // verifie la validite de l'attribut + bool ok; + double tmp = value.toDouble(&ok); + if (!ok) { + return PropertyFlags::NoValidConversion; + } - return PropertyFlags::Success; + if (reel != nullptr) + *reel = tmp; + + return PropertyFlags::Success; } PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean) { @@ -211,24 +259,28 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE return PropertyFlags::NotFound; } - // verifie la validite de l'attribut - bool ok; - bool tmp = attr.toInt(&ok); - if (!ok) { - if (attr == "true" || attr == "1") - tmp = true; - else if (attr == "false" || attr == "0") - tmp = false; - else { - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr; - return PropertyFlags::NoValidConversion; - } - } + return debug(propertyBool(attr, boolean), e, attribute_name, attr, boolS); +} - if (boolean != nullptr) - *boolean = tmp; +PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QString& value, bool* boolean) +{ + // verifie la validite de l'attribut + bool ok; + bool tmp = value.toInt(&ok); + if (!ok) { + if (value == "true" || value == "1") + tmp = true; + else if (value == "false" || value == "0") + tmp = false; + else { + return PropertyFlags::NoValidConversion; + } + } - return PropertyFlags::Success; + if (boolean != nullptr) + *boolean = tmp; + + return PropertyFlags::Success; } PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color) { @@ -239,17 +291,21 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDom return PropertyFlags::NotFound; } - // verifie la validite de l'attribut - QColor tmp = QColor(attr); - if (!tmp.isValid()) { - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << colorS << ". value: " << attr; - return PropertyFlags::NoValidConversion; - } + return debug(propertyColor(attr, color), e, attribute_name, attr, colorS); +} - if (color != nullptr) - *color = tmp; +PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QString& value, QColor* color) +{ + // verifie la validite de l'attribut + QColor tmp = QColor(value); + if (!tmp.isValid()) { + return PropertyFlags::NoValidConversion; + } - return PropertyFlags::Success; + if (color != nullptr) + *color = tmp; + + return PropertyFlags::Success; } PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid) { @@ -259,16 +315,20 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomE return PropertyFlags::NotFound; } - if (QUuid(attr).isNull()){ - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << uuidS << ". value: " << attr; - return PropertyFlags::NoValidConversion; - } + return debug(propertyUuid(attr, uuid), e, attribute_name, attr, uuidS); +} + +PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QString& value, QUuid* uuid) +{ + if (QUuid(value).isNull()){ + return PropertyFlags::NoValidConversion; + } - if (uuid != nullptr) - *uuid = QUuid(attr); + if (uuid != nullptr) + *uuid = QUuid(value); - return PropertyFlags::Success; + return PropertyFlags::Success; } PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string) { @@ -336,3 +396,110 @@ QString PropertiesInterface::orientationToString(Qet::Orientation o) { } return(ret); } + +/*! + * \brief PropertiesInterface::propertiesToXml + * Write all user properties to the DomElement \p e + * \param e + */ +void PropertiesInterface::propertiesToXml(QDomElement& e) const +{ + QDomDocument doc = e.ownerDocument(); + auto up = doc.createElement(userPropertiesS); + for (auto i = properties.begin(); i != properties.end(); ++i) + { + auto type = i.value().type(); + switch(type) { + case QVariant::Type::String: + up.appendChild(createXmlProperty(i.key(), i.value().toString())); break; + case QVariant::Type::Int: + up.appendChild(createXmlProperty(i.key(), i.value().toInt())); break; + case QVariant::Type::Double: + up.appendChild(createXmlProperty(i.key(), i.value().toDouble())); break; + case QVariant::Type::Bool: + up.appendChild(createXmlProperty(i.key(), i.value().toBool())); break; +// case QVariant::Type::Color: +// // TODO: correct? +// up.appendChild(createXmlProperty(i.key(), i.value().toString())); break; + default: + break; + } + } + e.appendChild(up); +} + +/*! + * \brief PropertiesInterface::propertiesFromXml + * Read all user properties from the DomElement& e + * \param e + * \return + */ +bool PropertiesInterface::propertiesFromXml(const QDomElement& e) +{ + QDomNodeList l = e.childNodes(); + for (int i=0; i < l.count(); i++) + { + QDomElement userProperties = l.at(i).toElement(); + if (userProperties.tagName() != userPropertiesS) + continue; + + QDomElement userProperty; + for (int up_index = 0; up_index < userProperties.childNodes().length(); up_index++) + { + userProperty = userProperties.childNodes().at(up_index).toElement(); + + QString name = userProperty.attribute("name"); + QString type = userProperty.attribute("type"); + QString value = userProperty.attribute("value"); + + if (type == integerS) + { + int i; + if (propertyInteger(value, &i) == PropertyFlags::Success) + properties[name] = QVariant(i); + else + return false; + } + else if (type == doubleS) + { + double d; + if (propertyDouble(value, &d) == PropertyFlags::Success) + properties[name] = QVariant(d); + else + return false; + } + else if (type == boolS) + { + bool b; + if (propertyBool(value, &b) == PropertyFlags::Success) + properties[name] = QVariant(b); + else + return false; + } + else if (type == uuidS) + { + QUuid u; + if (propertyUuid(value, &u) == PropertyFlags::Success) + properties[name] = QVariant(u); + else + return false; + } + else if (type == colorS) + { + QColor c; + if (propertyColor(value, &c) == PropertyFlags::Success) + properties[name] = QVariant(c); + else + return false; + } + else if (type == stringS) + { + properties[name] = QVariant(value); + } + else + { + qDebug() << "Not a valid property type!"; + } + } + } +} diff --git a/sources/properties/propertiesinterface.h b/sources/properties/propertiesinterface.h index d1e03683c..c2d526d35 100644 --- a/sources/properties/propertiesinterface.h +++ b/sources/properties/propertiesinterface.h @@ -26,6 +26,52 @@ #include "sources/qet.h" #include +//struct Property { +// enum class Type { +// String, +// Int, +// Double, +// Bool, +// Uuid, +// Color +// }; +// Property(enum Type type, QVariant& value): type(type), value(value) {}; +// enum Type type; +// QVariant value; +//}; + +//class Property_T +//{ +//public: +// enum class Type { +// String, +// Int, +// Double, +// Bool, +// Uuid, +// Color +// }; +// Property_T(enum Type type): mType(type) +// {} +//public: +// enum Type mType; +//}; + +//class PropertyDouble: Property_T +//{ +//public: +// PropertyDouble(double& value): Property_T(Property_T::Type::Double), mValue(value) {}; +//public: +// double mValue; +//}; + +class DomElement: public QDomElement +{ +public: + DomElement(): QDomElement() {}; + DomElement(QDomElement& e): QDomElement(e) {}; +}; + /** @brief The PropertiesInterface class This class is an interface for have common way @@ -34,7 +80,7 @@ class PropertiesInterface { public: - PropertiesInterface(); + PropertiesInterface(const QString& tagname = "Properties"); virtual ~PropertiesInterface(); /** @brief toSettings @@ -60,26 +106,26 @@ class PropertiesInterface @param xml_document @return QDomElement */ - virtual QDomElement toXml (QDomDocument &xml_document) const =0; + virtual QDomElement toXml (QDomDocument &xml_document) const; /** @brief fromXml load properties to xml element @param xml_element @return true / false */ - virtual bool fromXml (const QDomElement &xml_element) =0; + virtual bool fromXml (const QDomElement &xml_element); static bool valideXml(QDomElement& element); /*! * Use this functions to add properties to the xml document */ - static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QString value); - static QDomElement createXmlProperty(QDomDocument &doc, const QString& name, const char* value); - static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value); - static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value); - static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value); - static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value); - static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QColor value); + static QDomElement createXmlProperty(const QString& name, const QString value); + static QDomElement createXmlProperty(const QString& name, const char* value); + static QDomElement createXmlProperty(const QString& name, const int value); + static QDomElement createXmlProperty(const QString& name, const double value); + static QDomElement createXmlProperty(const QString& name, const bool value); + static QDomElement createXmlProperty(const QString& name, const QUuid value); + static QDomElement createXmlProperty(const QString& name, const QColor value); static QDomElement property(const QDomElement& e, const QString& name); static bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); @@ -91,17 +137,23 @@ class PropertiesInterface // = 4 }; + static PropertyFlags propertyInteger(const QString& value, int* entry = nullptr); static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr); + static PropertyFlags propertyDouble(const QString& value, double* entry = nullptr); static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr); static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr); + static PropertyFlags propertyBool(const QString& value, bool* entry = nullptr); static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr); + static PropertyFlags propertyUuid(const QString& value, QUuid* entry = nullptr); static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr); + static PropertyFlags propertyColor(const QString& value, QColor* entry = nullptr); static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr); static bool validXmlProperty(const QDomElement& e); QVariant XmlProperty(const QDomElement& element); + void setTagName(const QString& tagname); /** Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w") @@ -118,6 +170,15 @@ class PropertiesInterface @return une chaine de caractere representant l'orientation */ static QString orientationToString(Qet::Orientation o); + +private: + virtual void toXmlPriv (QDomElement &e) const =0; + virtual bool fromXmlPriv (const QDomElement &e) =0; + void propertiesToXml(QDomElement& e) const; + bool propertiesFromXml (const QDomElement &e); + + QHash properties; + QString mTagName{""}; }; #endif // PROPERTIESINTERFACE_H diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 3f740f9a8..46744f5b1 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -21,13 +21,13 @@ #include TerminalData::TerminalData(): - PropertiesInterface() + PropertiesInterface("terminaldata") { init(); } TerminalData::TerminalData(QGraphicsObject *parent): - PropertiesInterface(), + PropertiesInterface("terminaldata"), q(parent) { init(); @@ -81,35 +81,33 @@ void TerminalData::fromSettings(QSettings &settings, const QString& prefix) } /** - @brief TerminalData::toXml + @brief TerminalData::toXmlPriv Save properties to xml element write the name, number, position and orientation of the terminal to xml_element @note This method is only called from the PartTerminal and should never called from the Terminal class - @param xml_document - @return xml_element : DomElement with + @param e: element to store the properties the name, number, position and orientation of the terminal */ -QDomElement TerminalData::toXml(QDomDocument &xml_document) const +void TerminalData::toXmlPriv(QDomElement& e) const { - QDomElement xml_element = xml_document.createElement("terminaldata"); + // TODO: + //QDomElement xml_element = xml_document.createElement("terminaldata"); // m_pos cannot be stored, because in the partterminal it will not be updated. // In PartTerminal m_pos is the position of the dock, in Terminal m_pos is the second side of the terminal // This is hold for legacy compability reason - xml_element.appendChild(createXmlProperty(xml_document, "x", m_pos.x())); - xml_element.appendChild(createXmlProperty(xml_document, "y", m_pos.y())); - xml_element.appendChild(createXmlProperty(xml_document, "name", m_name)); - xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation))); - xml_element.appendChild(createXmlProperty(xml_document, "type", typeToString(m_type))); - - return(xml_element); + e.appendChild(createXmlProperty("x", m_pos.x())); + e.appendChild(createXmlProperty("y", m_pos.y())); + e.appendChild(createXmlProperty("name", m_name)); + e.appendChild(createXmlProperty("orientation", orientationToString(m_orientation))); + e.appendChild(createXmlProperty("type", typeToString(m_type))); } /* - @brief TerminalData::fromXml + @brief TerminalData::fromXmlPriv load properties to xml element @note This method is only called from the PartTerminal @@ -117,7 +115,7 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const @param xml_element @return true if succeeded / false if the attribute is not real */ -bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True +bool TerminalData::fromXmlPriv(const QDomElement &xml_element) { qreal term_x = 0.0; qreal term_y = 0.0; diff --git a/sources/properties/terminaldata.h b/sources/properties/terminaldata.h index b08607be8..26d0fdbff 100644 --- a/sources/properties/terminaldata.h +++ b/sources/properties/terminaldata.h @@ -56,8 +56,8 @@ class TerminalData : public PropertiesInterface const QString& prefix = QString()) const override; void fromSettings(QSettings &settings, const QString& = QString()) override; - QDomElement toXml(QDomDocument &xml_element) const override; - bool fromXml(const QDomElement &xml_element) override; + void toXmlPriv(QDomElement &) const override; + bool fromXmlPriv(const QDomElement &xml_element) override; static bool valideXml(const QDomElement &xml_element); diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index 8b1a79ec3..d1fc888e3 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -28,6 +28,7 @@ */ XRefProperties::XRefProperties() { + setTagName("xref"); } /** @@ -92,36 +93,32 @@ void XRefProperties::fromSettings(QSettings &settings, @param xml_document : QDomElement to use for saving @return QDomElement */ -QDomElement XRefProperties::toXml(QDomDocument &xml_document) const +void XRefProperties::toXmlPriv(QDomElement& e) const { - QDomElement xml_element = xml_document.createElement("xref"); - - xml_element.appendChild(createXmlProperty(xml_document, "type", m_key)); - xml_element.appendChild(createXmlProperty(xml_document, "showpowerctc", m_show_power_ctc)); - xml_element.appendChild(createXmlProperty(xml_document, "displayhas", m_display == Cross? "cross" : "contacts")); - xml_element.appendChild(createXmlProperty(xml_document, "snapto", m_snap_to == Bottom? "bottom" : "label")); + e.appendChild(createXmlProperty("type", m_key)); + e.appendChild(createXmlProperty("showpowerctc", m_show_power_ctc)); + e.appendChild(createXmlProperty("displayhas", m_display == Cross? "cross" : "contacts")); + e.appendChild(createXmlProperty("snapto", m_snap_to == Bottom? "bottom" : "label")); QMetaEnum var = QMetaEnum::fromType(); - xml_element.appendChild(createXmlProperty(xml_document, "xrefpos", var.valueToKey(m_xref_pos))); - xml_element.appendChild(createXmlProperty(xml_document, "offset", m_offset)); - xml_element.appendChild(createXmlProperty(xml_document, "master_label", m_master_label)); - xml_element.appendChild(createXmlProperty(xml_document, "slave_label", m_slave_label)); + e.appendChild(createXmlProperty("xrefpos", var.valueToKey(m_xref_pos))); + e.appendChild(createXmlProperty("offset", m_offset)); + e.appendChild(createXmlProperty("master_label", m_master_label)); + e.appendChild(createXmlProperty("slave_label", m_slave_label)); foreach (QString key, m_prefix.keys()) { - xml_element.appendChild(createXmlProperty(xml_document, key + "prefix", m_prefix.value(key))); + e.appendChild(createXmlProperty(key + "prefix", m_prefix.value(key))); } - - return xml_element; } /** RETURNS True - @brief XRefProperties::fromXml + @brief XRefProperties::fromXmlPriv Load from xml @param xml_element: QDomElement to use for load */ -bool XRefProperties::fromXml(const QDomElement &xml_element) { +bool XRefProperties::fromXmlPriv(const QDomElement &xml_element) { if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc)) return false; diff --git a/sources/properties/xrefproperties.h b/sources/properties/xrefproperties.h index 37162c712..324e9795e 100644 --- a/sources/properties/xrefproperties.h +++ b/sources/properties/xrefproperties.h @@ -45,8 +45,8 @@ class XRefProperties : public PropertiesInterface void toSettings (QSettings &settings, const QString& = QString()) const override; void fromSettings (QSettings &settings, const QString& = QString()) override; - QDomElement toXml (QDomDocument &xml_document) const override; - bool fromXml(const QDomElement &xml_element) override; + void toXmlPriv(QDomElement&) const override; + bool fromXmlPriv(const QDomElement &xml_element) override; static QHash defaultProperties(); diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 445504b2a..27c844978 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -80,6 +80,7 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) : terminal1(p1), terminal2(p2) { + setTagName("conductor"); //set Zvalue at 11 to be upper than the DiagramImageItem and element setZValue(11); m_previous_z_value = zValue(); @@ -962,7 +963,7 @@ void Conductor::pointsToSegments(const QList& points_list) { @param dom_element @return true is loading success else return false */ -bool Conductor::fromXml(const QDomElement &dom_element) +bool Conductor::fromXmlPriv(const QDomElement &dom_element) { // TODO: seems to short! double x=0, y=0; @@ -990,7 +991,7 @@ bool Conductor::fromXml(const QDomElement &dom_element) // does not support legacy method /*! - @brief Conductor::toXml + @brief Conductor::toXmlPriv Exporte les caracteristiques du conducteur sous forme d'une element XML. @param dom_document : Le document XML a utiliser pour creer l'element XML @@ -999,12 +1000,10 @@ bool Conductor::fromXml(const QDomElement &dom_element) bornes dans le document XML et leur adresse en memoire @return Un element XML representant le conducteur */ -QDomElement Conductor::toXml(QDomDocument & doc) const { - QDomElement dom_element = doc.createElement("conductor"); +void Conductor::toXmlPriv(QDomElement& e) const { - - dom_element.appendChild(createXmlProperty(doc, "x", pos().x())); - dom_element.appendChild(createXmlProperty(doc, "y", pos().y())); + e.appendChild(createXmlProperty("x", pos().x())); + e.appendChild(createXmlProperty("y", pos().y())); // Terminal is uniquely identified by the uuid of the terminal and the element QUuid terminal = terminal1->uuid(); @@ -1013,10 +1012,10 @@ QDomElement Conductor::toXml(QDomDocument & doc) const { // legacy when the terminal does not have a valid uuid // do not store element1 information, because this is used to determine in the fromXml // process that legacy file format - dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal1->ID())); + e.appendChild(createXmlProperty("terminal1", terminal1->ID())); } else { - dom_element.appendChild(createXmlProperty(doc, "element1", terminalParent)); - dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal)); + e.appendChild(createXmlProperty("element1", terminalParent)); + e.appendChild(createXmlProperty("terminal1", terminal)); } terminal = terminal2->uuid(); @@ -1025,13 +1024,15 @@ QDomElement Conductor::toXml(QDomDocument & doc) const { // legacy when the terminal does not have a valid uuid // do not store element1 information, because this is used to determine in the fromXml // process that legacy file format - dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->ID())); + e.appendChild(createXmlProperty("terminal2", terminal2->ID())); } else { - dom_element.appendChild(createXmlProperty(doc, "element2", terminal2->parentElement()->uuid())); - dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid())); + e.appendChild(createXmlProperty("element2", terminal2->parentElement()->uuid())); + e.appendChild(createXmlProperty("terminal2", terminal2->uuid())); } - dom_element.appendChild(createXmlProperty(doc, "freezeLabel", m_freeze_label)); + e.appendChild(createXmlProperty("freezeLabel", m_freeze_label)); + + QDomDocument doc; // on n'exporte les segments du conducteur que si ceux-ci ont // ete modifies par l'utilisateur @@ -1042,25 +1043,23 @@ QDomElement Conductor::toXml(QDomDocument & doc) const { foreach(ConductorSegment *segment, segmentsList()) { current_segment = doc.createElement("segment"); - current_segment.appendChild(createXmlProperty(doc, "orientation", segment->isHorizontal() ? "horizontal": "vertical")); - current_segment.appendChild(createXmlProperty(doc, "length", segment -> length())); - dom_element.appendChild(current_segment); + current_segment.appendChild(createXmlProperty("orientation", segment->isHorizontal() ? "horizontal": "vertical")); + current_segment.appendChild(createXmlProperty("length", segment -> length())); + e.appendChild(current_segment); } } QDomElement dom_seq = m_autoNum_seq.toXml(doc); // swquentialNumbers tag - dom_element.appendChild(dom_seq); + e.appendChild(dom_seq); // Export the properties and text QDomElement conductorProperties = m_properties.toXml(doc); for (int i=0; i < conductorProperties.childNodes().count(); i++) { QDomNode node = conductorProperties.childNodes().at(i).cloneNode(); // cloneNode() is important! - dom_element.appendChild(node); + e.appendChild(node); } - m_text_item->toXml(doc, dom_element); - - return(dom_element); + m_text_item->toXml(e); } /** diff --git a/sources/qetgraphicsitem/conductor.h b/sources/qetgraphicsitem/conductor.h index ae66be5d3..4cd82ead4 100644 --- a/sources/qetgraphicsitem/conductor.h +++ b/sources/qetgraphicsitem/conductor.h @@ -102,8 +102,8 @@ class Conductor : public QGraphicsObject, public PropertiesInterface public: static bool valideXml (QDomElement &); - bool fromXml (const QDomElement &) override; - QDomElement toXml (QDomDocument &doc) const override; + bool fromXmlPriv(const QDomElement &) override; + void toXmlPriv(QDomElement&) const override; void toSettings(QSettings &, const QString & = QString()) const override {} void fromSettings(QSettings &, const QString & = QString()) override {} private: diff --git a/sources/qetgraphicsitem/conductortextitem.cpp b/sources/qetgraphicsitem/conductortextitem.cpp index 1b38e777e..2cba46c8f 100644 --- a/sources/qetgraphicsitem/conductortextitem.cpp +++ b/sources/qetgraphicsitem/conductortextitem.cpp @@ -61,14 +61,14 @@ Conductor *ConductorTextItem::parentConductor() const return(parent_conductor_); } -void ConductorTextItem::toXml(QDomDocument& doc, QDomElement& e) { +void ConductorTextItem::toXml(QDomElement& e) { if(moved_by_user_) { - e.appendChild(PropertiesInterface::createXmlProperty(doc, "userx", pos().x())); - e.appendChild(PropertiesInterface::createXmlProperty(doc, "usery", pos().y())); + e.appendChild(PropertiesInterface::createXmlProperty("userx", pos().x())); + e.appendChild(PropertiesInterface::createXmlProperty("usery", pos().y())); } if(rotate_by_user_) - e.appendChild(PropertiesInterface::createXmlProperty(doc, "rotation", rotation())); + e.appendChild(PropertiesInterface::createXmlProperty("rotation", rotation())); } diff --git a/sources/qetgraphicsitem/conductortextitem.h b/sources/qetgraphicsitem/conductortextitem.h index a40e0fec0..5a611ff28 100644 --- a/sources/qetgraphicsitem/conductortextitem.h +++ b/sources/qetgraphicsitem/conductortextitem.h @@ -42,7 +42,7 @@ class ConductorTextItem : public DiagramTextItem enum { Type = UserType + 1006 }; Conductor *parentConductor() const; void fromXml(const QDomElement &) override; - void toXml(QDomDocument& doc, QDomElement& e); + void toXml(QDomElement& e); int type() const override { return Type; } virtual bool wasMovedByUser() const; virtual bool wasRotateByUser() const; diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index 43c4e7e68..68ca7f201 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -86,36 +86,36 @@ DynamicElementTextItem::DynamicElementTextItem() @param dom_doc @return */ -QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const +QDomElement DynamicElementTextItem::toXml(QDomDocument& dom_doc) const { - QDomElement root_element = dom_doc.createElement(xmlTagName()); + QDomElement root_element = dom_doc.createElement(xmlTagName()); - root_element.setAttribute("x", QString::number(pos().x())); - root_element.setAttribute("y", QString::number(pos().y())); - root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation()))); - root_element.setAttribute("uuid", m_uuid.toString()); - root_element.setAttribute("frame", m_frame? "true" : "false"); - root_element.setAttribute("text_width", QString::number(m_text_width)); - root_element.setAttribute("font", font().toString()); - root_element.setAttribute("keep_visual_rotation", m_keep_visual_rotation ? "true" : "false"); + root_element.setAttribute("x", QString::number(pos().x())); + root_element.setAttribute("y", QString::number(pos().y())); + root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation()))); + root_element.setAttribute("uuid", m_uuid.toString()); + root_element.setAttribute("frame", m_frame? "true" : "false"); + root_element.setAttribute("text_width", QString::number(m_text_width)); + root_element.setAttribute("font", font().toString()); + root_element.setAttribute("keep_visual_rotation", m_keep_visual_rotation ? "true" : "false"); QMetaEnum me = textFromMetaEnum(); - root_element.setAttribute("text_from", me.valueToKey(m_text_from)); + root_element.setAttribute("text_from", me.valueToKey(m_text_from)); me = QMetaEnum::fromType(); if(this->alignment() &Qt::AlignRight) - root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight)); + root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight)); else if(this->alignment() &Qt::AlignLeft) - root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft)); + root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft)); else if(this->alignment() &Qt::AlignHCenter) - root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter)); + root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter)); if(this->alignment() &Qt::AlignBottom) - root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignBottom)); + root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignBottom)); else if(this->alignment() & Qt::AlignTop) - root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop)); + root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop)); else if(this->alignment() &Qt::AlignVCenter) - root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter)); + root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter)); QDomElement dom_text = dom_doc.createElement("text"); diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.h b/sources/qetgraphicsitem/dynamicelementtextitem.h index 93d2679e3..ed6860546 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.h +++ b/sources/qetgraphicsitem/dynamicelementtextitem.h @@ -82,7 +82,7 @@ class DynamicElementTextItem : public DiagramTextItem DynamicElementTextItem(const DynamicElementTextItem &); public: - QDomElement toXml(QDomDocument &dom_doc) const override; + QDomElement toXml(QDomDocument&) const override; void fromXml(const QDomElement &dom_elmt) override; Element *parentElement() const; diff --git a/sources/qetgraphicsitem/independenttextitem.h b/sources/qetgraphicsitem/independenttextitem.h index cdf38b016..88d9e9d48 100644 --- a/sources/qetgraphicsitem/independenttextitem.h +++ b/sources/qetgraphicsitem/independenttextitem.h @@ -40,7 +40,7 @@ class IndependentTextItem : public DiagramTextItem int type() const override { return Type; } void fromXml(const QDomElement &) override; - QDomElement toXml(QDomDocument &) const override; + QDomElement toXml(QDomDocument&) const override; protected: void focusOutEvent(QFocusEvent *event) override; diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 0e1f76de7..f36cd340b 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -92,6 +92,7 @@ void Terminal::init( QString name, bool hiddenName) { + setTagName("terminal"); // definition du pount d'amarrage pour un conducteur d->m_pos = pf; @@ -750,34 +751,22 @@ QList Terminal::conductors() const } /** - @brief Terminal::toXml + @brief Terminal::toXmlPriv Methode d'export en XML @param doc Le Document XML a utiliser pour creer l'element XML @return un QDomElement representant cette borne */ -QDomElement Terminal::toXml(QDomDocument &doc) const +void Terminal::toXmlPriv(QDomElement &qdo) const { - QDomElement qdo = doc.createElement("terminal"); - - qdo.appendChild(createXmlProperty(doc, "number", number_terminal_)); - qdo.appendChild(createXmlProperty(doc, "nameHidden", name_terminal_hidden)); - - // store terminal data too! + qdo.appendChild(createXmlProperty("number", number_terminal_)); + qdo.appendChild(createXmlProperty("nameHidden", name_terminal_hidden)); // Do not store terminal data in its own child // Bad hack. The problem is that in the diagrams the terminal is described by the position and in the Collection by the dock. QPointF tempPos = d->m_pos; d->m_pos = dock_elmt_; - QDomElement terminalDataElement = d->toXml(doc); + d->toXmlPriv(qdo); // TerminalData d->m_pos = tempPos; - - int childsCount = terminalDataElement.childNodes().count(); - for (int i=0; i < childsCount; i++) { - QDomNode node = terminalDataElement.childNodes().at(i).cloneNode(); // cloneNode() is important, otherwise no deep clone is made - qdo.appendChild(node); - } - - return(qdo); } /** @@ -812,7 +801,7 @@ bool Terminal::valideXml(const QDomElement &terminal) @return true si la borne "se reconnait" (memes coordonnes, meme orientation), false sinon */ -bool Terminal::fromXml(const QDomElement &terminal) { +bool Terminal::fromXmlPriv(const QDomElement &terminal) { propertyString(terminal, "number", &number_terminal_); propertyBool(terminal, "nameHidden", &name_terminal_hidden); diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index feb466333..3339266a0 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -100,8 +100,8 @@ class Terminal : public QGraphicsObject, public PropertiesInterface // methods related to XML import/export static bool valideXml(const QDomElement &); - bool fromXml (const QDomElement &) override; - QDomElement toXml (QDomDocument &) const override; + bool fromXmlPriv (const QDomElement &) override; + void toXmlPriv(QDomElement &) const override; void toSettings(QSettings &,const QString & = QString()) const override {/*TODO: implement*/} void fromSettings(QSettings &,const QString & = QString()) override{/*TODO: implement*/} diff --git a/sources/titleblockproperties.cpp b/sources/titleblockproperties.cpp index e42255dd7..ea5711c64 100644 --- a/sources/titleblockproperties.cpp +++ b/sources/titleblockproperties.cpp @@ -65,48 +65,40 @@ bool TitleBlockProperties::operator!=(const TitleBlockProperties &ip) { return(!(*this == ip)); } - /** - Exporte le cartouche sous formes d'attributs XML ajoutes a l'element e. - @param e Element XML auquel seront ajoutes des attributs + Exporte le cartouche sous formes d'attributs XML ajoutes a l'element e. + @param e Element XML auquel seront ajoutes des attributs */ -void TitleBlockProperties::toXml(QDomElement &e) const -{ - e.setAttribute("author", author); - e.setAttribute("title", title); - e.setAttribute("filename", filename); - e.setAttribute("plant", plant); - e.setAttribute("locmach", locmach); - e.setAttribute("indexrev",indexrev); - e.setAttribute("version", version); - e.setAttribute("folio", folio); - e.setAttribute("auto_page_num", auto_page_num); - e.setAttribute("date", exportDate()); - e.setAttribute("displayAt", (display_at == Qt::BottomEdge? "bottom" : "right")); - if (!template_name.isEmpty()) - { - e.setAttribute("titleblocktemplate", template_name); - e.setAttribute("titleblocktemplateCollection", QET::qetCollectionToString(collection)); - } - - if (context.keys().count()) { - QDomElement properties = e.ownerDocument().createElement("properties"); - context.toXml(properties); - e.appendChild(properties); - } -} +void TitleBlockProperties::toXmlPriv(QDomElement& e) const { + e.appendChild(createXmlProperty("author", author)); + e.appendChild(createXmlProperty("title", title)); + e.appendChild(createXmlProperty("filename", filename)); + e.appendChild(createXmlProperty("plant", plant)); + e.appendChild(createXmlProperty("locmach", locmach)); + e.appendChild(createXmlProperty("indexrev", indexrev)); + e.appendChild(createXmlProperty("version", version)); + e.appendChild(createXmlProperty("folio", folio)); + e.appendChild(createXmlProperty("date", exportDate())); + e.appendChild(createXmlProperty("display_at", display_at == Qt::BottomEdge? "bottom" : "right")); + if (!template_name.isEmpty()) + { + e.appendChild(createXmlProperty("titleblocktemplate", template_name)); + e.appendChild(createXmlProperty("titleblocktemplateCollection", QET::qetCollectionToString(collection))); + } + + if (context.keys().count()) { + QDomElement properties = e.ownerDocument().createElement("properties"); + context.toXml(properties); + e.appendChild(properties); + } -QDomElement TitleBlockProperties::toXml(QDomDocument &d) const { - Q_UNUSED(d) - qDebug() << "NOT IMPLEMENTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; - return QDomElement(); } /** RETURNS True Importe le cartouche a partir des attributs XML de l'element e @param e Element XML dont les attributs seront lus */ -bool TitleBlockProperties::fromXml(const QDomElement &e) { +bool TitleBlockProperties::fromXmlPriv(const QDomElement &e) { // reads the historical fields diff --git a/sources/titleblockproperties.h b/sources/titleblockproperties.h index 2fff586cc..eafd5dc6e 100644 --- a/sources/titleblockproperties.h +++ b/sources/titleblockproperties.h @@ -41,9 +41,8 @@ class TitleBlockProperties: public PropertiesInterface { bool operator==(const TitleBlockProperties &); bool operator!=(const TitleBlockProperties &); - QDomElement toXml(QDomDocument &e) const override; - void toXml(QDomElement &e) const; - bool fromXml(const QDomElement &) override; + void toXmlPriv(QDomElement &e) const override; + bool fromXmlPriv(const QDomElement &) override; void toSettings(QSettings &, const QString & = QString()) const override; void fromSettings(QSettings &, const QString & = QString()) override;