diff --git a/sources/borderproperties.cpp b/sources/borderproperties.cpp index 67a9388af..eaa7b21c6 100644 --- a/sources/borderproperties.cpp +++ b/sources/borderproperties.cpp @@ -16,6 +16,7 @@ along with QElectroTech. If not, see . */ #include "borderproperties.h" +#include "qetxml.h" /** @brief BorderProperties::BorderProperties @@ -89,12 +90,12 @@ bool BorderProperties::operator!=(const BorderProperties &bp) { \~French Element XML auquel seront ajoutes des attributs */ 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)); + e.appendChild(QETXML::createXmlProperty("cols", columns_count)); + e.appendChild(QETXML::createXmlProperty("colsize", columns_width)); + e.appendChild(QETXML::createXmlProperty("rows", rows_count)); + e.appendChild(QETXML::createXmlProperty("rowsize", rows_height)); + e.appendChild(QETXML::createXmlProperty("displayrows", display_rows)); + e.appendChild(QETXML::createXmlProperty("displaycols", display_columns)); } /*!RETURNS True @@ -108,12 +109,12 @@ void BorderProperties::toXmlPriv(QDomElement& e) const { */ bool BorderProperties::fromXmlPriv(const QDomElement &e) { - if (propertyInteger(e, "cols", &columns_count) == PropertyFlags::NoValidConversion || - propertyDouble(e, "colsize", &columns_width) == PropertyFlags::NoValidConversion || - propertyInteger(e, "rows", &rows_count) == PropertyFlags::NoValidConversion || - propertyDouble(e, "rowsize", &rows_height) == PropertyFlags::NoValidConversion || - propertyBool(e, "displaycols", &display_columns) == PropertyFlags::NoValidConversion || - propertyBool(e, "displayrows", &display_rows) == PropertyFlags::NoValidConversion) + if (QETXML::propertyInteger(e, "cols", &columns_count) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(e, "colsize", &columns_width) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyInteger(e, "rows", &rows_count) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(e, "rowsize", &rows_height) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyBool(e, "displaycols", &display_columns) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyBool(e, "displayrows", &display_rows) == QETXML::PropertyFlags::NoValidConversion) return false; return true; @@ -121,12 +122,12 @@ bool BorderProperties::fromXmlPriv(const QDomElement &e) { bool BorderProperties::valideXml(QDomElement& e) { - if (propertyInteger(e, "cols") == PropertyFlags::Success || - propertyDouble(e, "colsize") == PropertyFlags::Success || - propertyInteger(e, "rows") == PropertyFlags::Success || - propertyDouble(e, "rowsize") == PropertyFlags::Success || - propertyBool(e, "displaycols") == PropertyFlags::Success || - propertyBool(e, "displayrows") == PropertyFlags::Success) + if (QETXML::propertyInteger(e, "cols") == QETXML::PropertyFlags::Success || + QETXML::propertyDouble(e, "colsize") == QETXML::PropertyFlags::Success || + QETXML::propertyInteger(e, "rows") == QETXML::PropertyFlags::Success || + QETXML::propertyDouble(e, "rowsize") == QETXML::PropertyFlags::Success || + QETXML::propertyBool(e, "displaycols") == QETXML::PropertyFlags::Success || + QETXML::propertyBool(e, "displayrows") == QETXML::PropertyFlags::Success) return true; return false; } diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 2f0b31c66..5aebf2f30 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -20,6 +20,8 @@ #include #include #include + +#include "qetxml.h" /** Constructeur par defaut */ @@ -213,12 +215,12 @@ void SingleLineProperties::drawPen(QPainter *painter, */ void SingleLineProperties::toXmlPriv(QDomElement& e) const { - e.appendChild(createXmlProperty("ground", hasGround)); - e.appendChild(createXmlProperty("neutral", hasNeutral)); - e.appendChild(createXmlProperty("phase", phases)); + e.appendChild(QETXML::createXmlProperty("ground", hasGround)); + e.appendChild(QETXML::createXmlProperty("neutral", hasNeutral)); + e.appendChild(QETXML::createXmlProperty("phase", phases)); if (isPen()) - e.appendChild(createXmlProperty("pen", true)); + e.appendChild(QETXML::createXmlProperty("pen", true)); } /** @@ -227,17 +229,17 @@ void SingleLineProperties::toXmlPriv(QDomElement& e) const { @param e Element XML dont les attributs seront lus */ bool SingleLineProperties::fromXmlPriv(const QDomElement &e) { - if (propertyBool(e, "ground", &hasGround) != PropertyFlags::Success || - propertyBool(e, "neutral", &hasNeutral) != PropertyFlags::Success) + if (QETXML::propertyBool(e, "ground", &hasGround) != QETXML::PropertyFlags::Success || + QETXML::propertyBool(e, "neutral", &hasNeutral) != QETXML::PropertyFlags::Success) return false; int phase; - if (propertyInteger(e, "phase", &phase) != PropertyFlags::Success) + if (QETXML::propertyInteger(e, "phase", &phase) != QETXML::PropertyFlags::Success) return false; setPhasesCount(phase); bool pen; - if (propertyBool(e, "pen", &pen) != PropertyFlags::Success) + if (QETXML::propertyBool(e, "pen", &pen) != QETXML::PropertyFlags::Success) return false; is_pen = (hasGround && hasNeutral && pen); @@ -245,14 +247,14 @@ bool SingleLineProperties::fromXmlPriv(const QDomElement &e) { } bool SingleLineProperties::valideXml(QDomElement& e) { - if (propertyBool(e, "ground") != PropertyFlags::Success || - propertyBool(e, "neutral") != PropertyFlags::Success) + if (QETXML::propertyBool(e, "ground") != QETXML::PropertyFlags::Success || + QETXML::propertyBool(e, "neutral") != QETXML::PropertyFlags::Success) return false; - if (propertyInteger(e, "phase") != PropertyFlags::Success) + if (QETXML::propertyInteger(e, "phase") != QETXML::PropertyFlags::Success) return false; - if (propertyBool(e, "pen") != PropertyFlags::Success) + if (QETXML::propertyBool(e, "pen") != QETXML::PropertyFlags::Success) return false; return true; @@ -282,12 +284,12 @@ ConductorProperties::~ConductorProperties() void ConductorProperties::toXmlPriv(QDomElement& e) const { - e.appendChild(createXmlProperty("type", typeToString(type))); - e.appendChild(createXmlProperty("color", color)); + e.appendChild(QETXML::createXmlProperty("type", typeToString(type))); + e.appendChild(QETXML::createXmlProperty("color", color)); - e.appendChild(createXmlProperty("bicolor", m_bicolor)); - e.appendChild(createXmlProperty("color2", m_color_2)); - e.appendChild(createXmlProperty("dash-size", m_dash_size)); + e.appendChild(QETXML::createXmlProperty("bicolor", m_bicolor)); + e.appendChild(QETXML::createXmlProperty("color2", m_color_2)); + e.appendChild(QETXML::createXmlProperty("dash-size", m_dash_size)); if (type == Single) { @@ -295,29 +297,29 @@ void ConductorProperties::toXmlPriv(QDomElement& e) const e.appendChild(singleLineProperties.toXml(doc)); } - 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)); + e.appendChild(QETXML::createXmlProperty("num", text)); + e.appendChild(QETXML::createXmlProperty("text_color", text_color)); + e.appendChild(QETXML::createXmlProperty("formula", m_formula)); + e.appendChild(QETXML::createXmlProperty("function", m_function)); + e.appendChild(QETXML::createXmlProperty("tension_protocol", m_tension_protocol)); + e.appendChild(QETXML::createXmlProperty("conductor_color", m_wire_color)); + e.appendChild(QETXML::createXmlProperty("conductor_section", m_wire_section)); + e.appendChild(QETXML::createXmlProperty("numsize", text_size)); + e.appendChild(QETXML::createXmlProperty("condsize", cond_size)); + e.appendChild(QETXML::createXmlProperty("displaytext", m_show_text)); + e.appendChild(QETXML::createXmlProperty("onetextperfolio", m_one_text_per_folio)); + e.appendChild(QETXML::createXmlProperty("vertirotatetext", verti_rotate_text)); + e.appendChild(QETXML::createXmlProperty("horizrotatetext", horiz_rotate_text)); // TODO: implement //e.setAttribute("cable", m_cable); // e.setAttribute("bus", m_bus); QMetaEnum me = QMetaEnum::fromType(); - e.appendChild(createXmlProperty("horizontal-alignment", me.valueToKey(m_horizontal_alignment))); - e.appendChild(createXmlProperty("vertical-alignment", me.valueToKey(m_vertical_alignment))); + e.appendChild(QETXML::createXmlProperty("horizontal-alignment", me.valueToKey(m_horizontal_alignment))); + e.appendChild(QETXML::createXmlProperty("vertical-alignment", me.valueToKey(m_vertical_alignment))); QString conductor_style = writeStyle(); if (!conductor_style.isEmpty()) - e.appendChild(createXmlProperty("style", conductor_style)); + e.appendChild(QETXML::createXmlProperty("style", conductor_style)); } @@ -329,18 +331,18 @@ void ConductorProperties::toXmlPriv(QDomElement& e) const bool ConductorProperties::fromXmlPriv(const QDomElement &e) { // get conductor color - propertyColor(e, "color", &color); - propertyBool(e, "bicolor", &m_bicolor); - propertyColor(e, "color2", &m_color_2); - propertyInteger(e, "dash-size", &m_dash_size); + QETXML::propertyColor(e, "color", &color); + QETXML::propertyBool(e, "bicolor", &m_bicolor); + QETXML::propertyColor(e, "color2", &m_color_2); + QETXML::propertyInteger(e, "dash-size", &m_dash_size); // read style of conductor QString style_string; - propertyString(e, "style", &style_string); + QETXML::propertyString(e, "style", &style_string); readStyle(style_string); QString type_t; - if (propertyString(e, "type", &type_t) == PropertyFlags::Success) { + if (QETXML::propertyString(e, "type", &type_t) == QETXML::PropertyFlags::Success) { if (type_t == typeToString(Single)) { // get specific properties for single conductor @@ -358,55 +360,55 @@ bool ConductorProperties::fromXmlPriv(const QDomElement &e) } } - propertyString(e, "num", &text); + QETXML::propertyString(e, "num", &text); // TODO: implement: //m_cable = e.attribute("cable"); //m_bus = e.attribute("bus"); // get text color - propertyColor(e, "text_color", &text_color); - propertyString(e, "formula", &m_formula); - propertyString(e, "function", &m_function); - propertyString(e, "tension_protocol", &m_tension_protocol); - propertyString(e, "conductor_color", &m_wire_color); - propertyString(e, "conductor_section", &m_wire_section); - propertyInteger(e, "numsize", &text_size); - propertyDouble(e, "condsize", &cond_size); - propertyBool(e, "displaytext", &m_show_text); - propertyBool(e, "onetextperfolio", &m_one_text_per_folio); - propertyDouble(e, "vertirotatetext", &verti_rotate_text); - propertyDouble(e, "horizrotatetext", &horiz_rotate_text); + QETXML::propertyColor(e, "text_color", &text_color); + QETXML::propertyString(e, "formula", &m_formula); + QETXML::propertyString(e, "function", &m_function); + QETXML::propertyString(e, "tension_protocol", &m_tension_protocol); + QETXML::propertyString(e, "conductor_color", &m_wire_color); + QETXML::propertyString(e, "conductor_section", &m_wire_section); + QETXML::propertyInteger(e, "numsize", &text_size); + QETXML::propertyDouble(e, "condsize", &cond_size); + QETXML::propertyBool(e, "displaytext", &m_show_text); + QETXML::propertyBool(e, "onetextperfolio", &m_one_text_per_folio); + QETXML::propertyDouble(e, "vertirotatetext", &verti_rotate_text); + QETXML::propertyDouble(e, "horizrotatetext", &horiz_rotate_text); QMetaEnum me = QMetaEnum::fromType(); QString alinment_temp; - if (propertyString(e, "horizontal-alignment", &alinment_temp) == PropertyFlags::Success) + if (QETXML::propertyString(e, "horizontal-alignment", &alinment_temp) == QETXML::PropertyFlags::Success) m_horizontal_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); - if (propertyString(e, "vertical-alignment", &alinment_temp) == PropertyFlags::Success) + if (QETXML::propertyString(e, "vertical-alignment", &alinment_temp) == QETXML::PropertyFlags::Success) m_vertical_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); return true; } bool ConductorProperties::valideXml(QDomElement& e) { - if (propertyColor(e, "color") || - propertyBool(e, "bicolor") || - propertyColor(e, "color2") || - propertyInteger(e, "dash-size") || - propertyString(e, "type") || - propertyString(e, "num") || - propertyColor(e, "text_color") || - propertyString(e, "formula") || - propertyString(e, "function") || - propertyString(e, "tension_protocol") || - propertyString(e, "conductor_color") || - propertyString(e, "conductor_section") || - propertyInteger(e, "numsize") || - propertyDouble(e, "condsize") || - propertyBool(e, "displaytext") || - propertyBool(e, "onetextperfolio") || - propertyDouble(e, "vertirotatetext") || - propertyDouble(e, "horizrotatetext") || - propertyString(e, "horizontal-alignment") || - propertyString(e, "vertical-alignment")) + if (QETXML::propertyColor(e, "color") || + QETXML::propertyBool(e, "bicolor") || + QETXML::propertyColor(e, "color2") || + QETXML::propertyInteger(e, "dash-size") || + QETXML::propertyString(e, "type") || + QETXML::propertyString(e, "num") || + QETXML::propertyColor(e, "text_color") || + QETXML::propertyString(e, "formula") || + QETXML::propertyString(e, "function") || + QETXML::propertyString(e, "tension_protocol") || + QETXML::propertyString(e, "conductor_color") || + QETXML::propertyString(e, "conductor_section") || + QETXML::propertyInteger(e, "numsize") || + QETXML::propertyDouble(e, "condsize") || + QETXML::propertyBool(e, "displaytext") || + QETXML::propertyBool(e, "onetextperfolio") || + QETXML::propertyDouble(e, "vertirotatetext") || + QETXML::propertyDouble(e, "horizrotatetext") || + QETXML::propertyString(e, "horizontal-alignment") || + QETXML::propertyString(e, "vertical-alignment")) return false; return true; } diff --git a/sources/diagram.cpp b/sources/diagram.cpp index fbdf0d459..21ef998f7 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -44,6 +44,8 @@ #include #include +#include "qetxml.h" + int Diagram::xGrid = 10; int Diagram::yGrid = 10; int Diagram::xKeyGrid = 10; @@ -1102,7 +1104,7 @@ Terminal* findTerminal(int conductor_index, QString terminal_index = "terminal" + QString::number(conductor_index); QUuid element_uuid; - if (PropertiesInterface::propertyUuid(conductor, element_index, &element_uuid) == PropertiesInterface::PropertyFlags::Success) { + if (QETXML::propertyUuid(conductor, element_index, &element_uuid) == QETXML::PropertyFlags::Success) { // element1 did not exist in the conductor part of the xml until prior 0.7 // It is used as an indicator that uuid's are used to identify terminals bool element_found = false; @@ -1111,7 +1113,7 @@ Terminal* findTerminal(int conductor_index, continue; element_found = true; QUuid terminal_uuid; - PropertiesInterface::propertyUuid(conductor, terminal_index, &terminal_uuid); + QETXML::propertyUuid(conductor, terminal_index, &terminal_uuid); for (auto terminal: element->terminals()) { if (terminal->uuid() != terminal_uuid) continue; @@ -1137,7 +1139,7 @@ Terminal* findTerminal(int conductor_index, } else { // Backward compatibility. Until version 0.7 a generated id is used to link the terminal. int id_p1 = -1; - if (PropertiesInterface::propertyInteger(conductor, terminal_index, &id_p1) != PropertiesInterface::PropertyFlags::Success) { + if (QETXML::propertyInteger(conductor, terminal_index, &id_p1) != QETXML::PropertyFlags::Success) { qDebug() << "diagramm.cpp:findTerminal(): Reading Id was not successfull"; } if (!table_adr_id.contains(id_p1)) { diff --git a/sources/editor/graphicspart/customelementgraphicpart.cpp b/sources/editor/graphicspart/customelementgraphicpart.cpp index 8eab68d5a..bd2c66e70 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.cpp +++ b/sources/editor/graphicspart/customelementgraphicpart.cpp @@ -20,6 +20,8 @@ #include "../../QPropertyUndoCommand/qpropertyundocommand.h" #include "../elementscene.h" +#include "../../qetxml.h" + #include /** @@ -497,8 +499,8 @@ void CustomElementGraphicPart::stylesToXml(QDomElement &qde) const else if (_color == HTMLGrayBlackColor) css_like_styles += "HTMLGrayBlack"; else if (_color == NoneColor) css_like_styles += "none"; - qde.appendChild(createXmlProperty("style", css_like_styles)); - qde.appendChild(createXmlProperty("antialias", _antialiased ? "true" : "false")); + qde.appendChild(QETXML::createXmlProperty("style", css_like_styles)); + qde.appendChild(QETXML::createXmlProperty("antialias", _antialiased ? "true" : "false")); } @@ -512,7 +514,7 @@ void CustomElementGraphicPart::stylesFromXml(const QDomElement &qde) resetStyles(); QString style_string; - propertyString(qde, "style", &style_string); + QETXML::propertyString(qde, "style", &style_string); //Get the list of pair style/value #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index 4b1d145f7..719203844 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -22,6 +22,8 @@ #include "../../QetGraphicsItemModeler/qetgraphicshandlerutility.h" #include "../elementscene.h" +#include "../../qetxml.h" + /** @brief PartArc::PartArc Constructor @@ -106,14 +108,14 @@ void PartArc::toXmlPriv(QDomElement& e) const e.setTagName("arc"); QPointF top_left(sceneTopLeft()); - 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())); + e.appendChild(QETXML::createXmlProperty("x", top_left.x())); + e.appendChild(QETXML::createXmlProperty("y", top_left.y())); + e.appendChild(QETXML::createXmlProperty("width", rect().width())); + e.appendChild(QETXML::createXmlProperty("height", rect().height())); //to maintain compatibility with the previous version, we write the angle in degrees. - e.appendChild(createXmlProperty("start", m_start_angle / 16)); - e.appendChild(createXmlProperty("angle", m_span_angle / 16)); + e.appendChild(QETXML::createXmlProperty("start", m_start_angle / 16)); + e.appendChild(QETXML::createXmlProperty("angle", m_span_angle / 16)); stylesToXml(e); @@ -128,21 +130,21 @@ bool PartArc::fromXmlPriv(const QDomElement &qde) { stylesFromXml(qde); double x=0, y=0, w=0, h=0; - if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "width", &w) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "height", &h) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "x", &x) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "y", &y) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "width", &w) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "height", &h) == QETXML::PropertyFlags::NoValidConversion) return false; m_rect = QRectF(mapFromScene(x, y), QSizeF(w, h) ); m_start_angle = 0; - if (propertyDouble(qde, "start", &m_start_angle) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "start", &m_start_angle) == QETXML::PropertyFlags::NoValidConversion) return false; m_start_angle *= 16; m_span_angle = -1440; - if (propertyDouble(qde, "angle", &m_span_angle) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "angle", &m_span_angle) == QETXML::PropertyFlags::NoValidConversion) return false; m_span_angle *= 16; @@ -151,12 +153,12 @@ bool PartArc::fromXmlPriv(const QDomElement &qde) { bool PartArc::valideXml(QDomElement& element) { - if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion || - propertyDouble(element, "y") == PropertyFlags::NoValidConversion || - propertyDouble(element, "width") == PropertyFlags::NoValidConversion || - propertyDouble(element, "height") == PropertyFlags::NoValidConversion || - propertyDouble(element, "start") == PropertyFlags::NoValidConversion || - propertyDouble(element, "angle") == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(element, "x") == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(element, "y") == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(element, "width") == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(element, "height") == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(element, "start") == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(element, "angle") == QETXML::PropertyFlags::NoValidConversion) return false; return true; } diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp index fa2894477..57f8c6ad8 100644 --- a/sources/editor/graphicspart/partdynamictextfield.cpp +++ b/sources/editor/graphicspart/partdynamictextfield.cpp @@ -21,6 +21,8 @@ #include "../../qetapp.h" #include "../elementscene.h" +#include "../../qetxml.h" + #include #include #include @@ -97,33 +99,33 @@ void PartDynamicTextField::handleUserTransformation( void PartDynamicTextField::toXmlPriv(QDomElement& e) const { - e.appendChild(createXmlProperty("x", pos().x())); - e.appendChild(createXmlProperty("y", pos().y())); - e.appendChild(createXmlProperty("z", zValue())); - e.appendChild(createXmlProperty("rotation", QET::correctAngle(rotation()))); + e.appendChild(QETXML::createXmlProperty("x", pos().x())); + e.appendChild(QETXML::createXmlProperty("y", pos().y())); + e.appendChild(QETXML::createXmlProperty("z", zValue())); + e.appendChild(QETXML::createXmlProperty("rotation", QET::correctAngle(rotation()))); - 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)); + e.appendChild(QETXML::createXmlProperty("font", font().toString())); + e.appendChild(QETXML::createXmlProperty("uuid", m_uuid)); + e.appendChild(QETXML::createXmlProperty("frame", m_frame)); + e.appendChild(QETXML::createXmlProperty("text_width", m_text_width)); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); - e.appendChild(createXmlProperty("text_from", me.valueToKey(m_text_from))); + e.appendChild(QETXML::createXmlProperty("text_from", me.valueToKey(m_text_from))); me = QMetaEnum::fromType(); if(this -> alignment() &Qt::AlignRight) - e.appendChild(createXmlProperty("Halignment", me.valueToKey(Qt::AlignRight))); + e.appendChild(QETXML::createXmlProperty("Halignment", me.valueToKey(Qt::AlignRight))); else if(this -> alignment() &Qt::AlignLeft) - e.appendChild(createXmlProperty("Halignment", me.valueToKey(Qt::AlignLeft))); + e.appendChild(QETXML::createXmlProperty("Halignment", me.valueToKey(Qt::AlignLeft))); else if(this -> alignment() &Qt::AlignHCenter) - e.appendChild(createXmlProperty("Halignment", me.valueToKey(Qt::AlignHCenter))); + e.appendChild(QETXML::createXmlProperty("Halignment", me.valueToKey(Qt::AlignHCenter))); if(this -> alignment() &Qt::AlignBottom) - e.appendChild(createXmlProperty("Valignment", me.valueToKey(Qt::AlignBottom))); + e.appendChild(QETXML::createXmlProperty("Valignment", me.valueToKey(Qt::AlignBottom))); else if(this -> alignment() & Qt::AlignTop) - e.appendChild(createXmlProperty("Valignment", me.valueToKey(Qt::AlignTop))); + e.appendChild(QETXML::createXmlProperty("Valignment", me.valueToKey(Qt::AlignTop))); else if(this -> alignment() &Qt::AlignVCenter) - e.appendChild(createXmlProperty("Valignment", me.valueToKey(Qt::AlignVCenter))); + e.appendChild(QETXML::createXmlProperty("Valignment", me.valueToKey(Qt::AlignVCenter))); QDomDocument dom_doc; QDomElement dom_text = dom_doc.createElement("text"); @@ -167,10 +169,10 @@ bool PartDynamicTextField::fromXmlPriv(const QDomElement &dom_elmt) } double x=0, y=0, z=0, rot=0; - if (propertyDouble(dom_elmt, "x", &x) == PropertyFlags::NoValidConversion || - propertyDouble(dom_elmt, "y", &y) == PropertyFlags::NoValidConversion || - propertyDouble(dom_elmt, "z", &z) == PropertyFlags::NoValidConversion || - propertyDouble(dom_elmt, "rotation", &rot) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(dom_elmt, "x", &x) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(dom_elmt, "y", &y) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(dom_elmt, "z", &z) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(dom_elmt, "rotation", &rot) == QETXML::PropertyFlags::NoValidConversion) return false; QGraphicsTextItem::setPos(x, y); @@ -178,7 +180,7 @@ bool PartDynamicTextField::fromXmlPriv(const QDomElement &dom_elmt) QGraphicsTextItem::setRotation(rot); QString font; - if (propertyString(dom_elmt, "font", &font) == PropertyFlags::Success) + if (QETXML::propertyString(dom_elmt, "font", &font) == QETXML::PropertyFlags::Success) { QFont font_; font_.fromString(font); @@ -191,24 +193,24 @@ bool PartDynamicTextField::fromXmlPriv(const QDomElement &dom_elmt) setFont(QETApp::dynamicTextsItemFont(9)); } - propertyUuid(dom_elmt, "uuid", &m_uuid); + QETXML::propertyUuid(dom_elmt, "uuid", &m_uuid); bool frame; - propertyBool(dom_elmt, "frame", &frame); + QETXML::propertyBool(dom_elmt, "frame", &frame); double text_width=-1; - propertyDouble(dom_elmt, "text_width", &text_width); + QETXML::propertyDouble(dom_elmt, "text_width", &text_width); setTextWidth(text_width); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); QString text_from; - propertyString(dom_elmt, "text_from", &text_from); + QETXML::propertyString(dom_elmt, "text_from", &text_from); m_text_from = DynamicElementTextItem::TextFrom(me.keyToValue(text_from.toStdString().data())); me = QMetaEnum::fromType(); QString alignment; - if(propertyString(dom_elmt, "Halignment", &alignment) != PropertyFlags::NotFound) + if(QETXML::propertyString(dom_elmt, "Halignment", &alignment) != QETXML::PropertyFlags::NotFound) setAlignment(Qt::Alignment(me.keyToValue(alignment.toStdString().data()))); - if(propertyString(dom_elmt, "Valignment", &alignment) != PropertyFlags::NotFound) + if(QETXML::propertyString(dom_elmt, "Valignment", &alignment) != QETXML::PropertyFlags::NotFound) setAlignment(Qt::Alignment( me.keyToValue(dom_elmt.attribute("Valignment").toStdString().data())) | this -> alignment()); @@ -240,21 +242,21 @@ bool PartDynamicTextField::fromXmlPriv(const QDomElement &dom_elmt) } bool PartDynamicTextField::valideXml(QDomElement& dom_elmt) { - if (propertyDouble(dom_elmt, "x") == PropertyFlags::NoValidConversion || - propertyDouble(dom_elmt, "y") == PropertyFlags::NoValidConversion || - propertyDouble(dom_elmt, "z") == PropertyFlags::NoValidConversion || - propertyDouble(dom_elmt, "rotation") == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(dom_elmt, "x") == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(dom_elmt, "y") == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(dom_elmt, "z") == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(dom_elmt, "rotation") == QETXML::PropertyFlags::NoValidConversion) return false; - if (propertyUuid(dom_elmt, "uuid") == PropertyFlags::NoValidConversion) + if (QETXML::propertyUuid(dom_elmt, "uuid") == QETXML::PropertyFlags::NoValidConversion) return false; - if (propertyString(dom_elmt, "text_from")) + if (QETXML::propertyString(dom_elmt, "text_from")) return false; - if(propertyString(dom_elmt, "Halignment") == PropertyFlags::NotFound) + if(QETXML::propertyString(dom_elmt, "Halignment") == QETXML::PropertyFlags::NotFound) return false; - if(propertyString(dom_elmt, "Valignment") == PropertyFlags::NotFound) + if(QETXML::propertyString(dom_elmt, "Valignment") == QETXML::PropertyFlags::NotFound) return false; return true; diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index b7c24bc69..c34c9f036 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -22,6 +22,8 @@ #include "../../QetGraphicsItemModeler/qetgraphicshandlerutility.h" #include "../elementscene.h" +#include "../../qetxml.h" + /** @brief PartEllipse::PartEllipse Constructor @@ -88,18 +90,18 @@ void PartEllipse::toXmlPriv(QDomElement& e) const if (qFuzzyCompare(rect().width(), rect().height())) { e.setTagName("circle"); - e.appendChild(createXmlProperty("diameter", rect().width())); + e.appendChild(QETXML::createXmlProperty("diameter", rect().width())); } else { e.setTagName("ellipse"); - e.appendChild(createXmlProperty("width", rect().width())); - e.appendChild(createXmlProperty("height", rect().height())); + e.appendChild(QETXML::createXmlProperty("width", rect().width())); + e.appendChild(QETXML::createXmlProperty("height", rect().height())); } QPointF top_left(sceneTopLeft()); - e.appendChild(createXmlProperty("x", top_left.x())); - e.appendChild(createXmlProperty("y", top_left.y())); + e.appendChild(QETXML::createXmlProperty("x", top_left.x())); + e.appendChild(QETXML::createXmlProperty("y", top_left.y())); stylesToXml(e); } @@ -116,19 +118,19 @@ bool PartEllipse::fromXmlPriv(const QDomElement &qde) if (qde.tagName() == "ellipse") { - if (propertyDouble(qde, "width", &width) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "height", &height) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "width", &width) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "height", &height) == QETXML::PropertyFlags::NoValidConversion) return false; } else { - if (propertyDouble(qde, "diameter", &width) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "diameter", &width) == QETXML::PropertyFlags::NoValidConversion) return false; height = width; } - if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "x", &x) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "y", &y) == QETXML::PropertyFlags::NoValidConversion) return false; m_rect = QRectF(mapFromScene(x, y), QSizeF(width, height)); @@ -139,18 +141,18 @@ bool PartEllipse::fromXmlPriv(const QDomElement &qde) bool PartEllipse::valideXml(QDomElement& element) { if (element.tagName() == "ellipse") { - if (propertyDouble(element, "width") & PropertyFlags::NoValidConversion || - propertyDouble(element, "height") & PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(element, "width") & QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(element, "height") & QETXML::PropertyFlags::NoValidConversion) return false; } else { - if (propertyDouble(element, "diameter") & PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(element, "diameter") & QETXML::PropertyFlags::NoValidConversion) return false; } - if ((propertyDouble(element, "x") & PropertyFlags::NoValidConversion) || - (propertyDouble(element, "y") & PropertyFlags::NoValidConversion)) + if ((QETXML::propertyDouble(element, "x") & QETXML::PropertyFlags::NoValidConversion) || + (QETXML::propertyDouble(element, "y") & QETXML::PropertyFlags::NoValidConversion)) return false; return true; diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index 73f8aa787..108071e3b 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -21,6 +21,8 @@ #include "../../QetGraphicsItemModeler/qetgraphicshandleritem.h" #include "../elementscene.h" +#include "../../qetxml.h" + #include /** @@ -112,15 +114,15 @@ void PartLine::toXmlPriv(QDomElement& e) const QPointF p1(sceneP1()); QPointF p2(sceneP2()); - e.appendChild(createXmlProperty("x1", p1.x())); - e.appendChild(createXmlProperty("y1", p1.y())); - e.appendChild(createXmlProperty("x2", p2.x())); - e.appendChild(createXmlProperty("y2", p2.y())); + e.appendChild(QETXML::createXmlProperty("x1", p1.x())); + e.appendChild(QETXML::createXmlProperty("y1", p1.y())); + e.appendChild(QETXML::createXmlProperty("x2", p2.x())); + e.appendChild(QETXML::createXmlProperty("y2", p2.y())); - 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)); + e.appendChild(QETXML::createXmlProperty("end1", Qet::endTypeToString(first_end))); + e.appendChild(QETXML::createXmlProperty("length1", first_length)); + e.appendChild(QETXML::createXmlProperty("end2", Qet::endTypeToString(second_end))); + e.appendChild(QETXML::createXmlProperty("length2", second_length)); stylesToXml(e); } @@ -134,41 +136,41 @@ bool PartLine::fromXmlPriv(const QDomElement &qde) { stylesFromXml(qde); double x1 = 0, y1 = 0, x2 = 0, y2 = 0; - if (propertyDouble(qde, "x1", &x1) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y1", &y1) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "x2", &x2) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y2", &y2) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "x1", &x1) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "y1", &y1) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "x2", &x2) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "y2", &y2) == QETXML::PropertyFlags::NoValidConversion) return false; m_line = QLineF(mapFromScene(x1, y1), mapFromScene(x2, y2)); QString s; - if (propertyString(qde, "end1", &s) != PropertyFlags::Success) + if (QETXML::propertyString(qde, "end1", &s) != QETXML::PropertyFlags::Success) return false; first_end = Qet::endTypeFromString(s); - if (propertyString(qde, "end2", &s) != PropertyFlags::Success) + if (QETXML::propertyString(qde, "end2", &s) != QETXML::PropertyFlags::Success) return false; first_end = Qet::endTypeFromString(s); - if (propertyDouble(qde, "length1", &first_length) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "length2", &second_length) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "length1", &first_length) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "length2", &second_length) == QETXML::PropertyFlags::NoValidConversion) return false; return true; } bool PartLine::valideXml(QDomElement& element) const { - if (propertyDouble(element, "x1") || - propertyDouble(element, "y1") || - propertyDouble(element, "x2") || - propertyDouble(element, "y2") || - propertyString(element, "end1") || - propertyString(element, "end2") || - propertyDouble(element, "length1") || - propertyDouble(element, "length2") ) + if (QETXML::propertyDouble(element, "x1") || + QETXML::propertyDouble(element, "y1") || + QETXML::propertyDouble(element, "x2") || + QETXML::propertyDouble(element, "y2") || + QETXML::propertyString(element, "end1") || + QETXML::propertyString(element, "end2") || + QETXML::propertyDouble(element, "length1") || + QETXML::propertyDouble(element, "length2") ) return false; return true; diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index dcf76d96e..d6267d41c 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -24,6 +24,8 @@ #include "../elementscene.h" #include "../ui/qetelementeditor.h" +#include "../../qetxml.h" + /** @brief PartPolygon::PartPolygon Constructor @@ -98,8 +100,8 @@ bool PartPolygon::fromXmlPriv(const QDomElement &qde) int i = 1; while(true) { - if (propertyDouble(qde, QString("x%1").arg(i)) == PropertyFlags::Success && - propertyDouble(qde, QString("y%1").arg(i)) == PropertyFlags::Success) + if (QETXML::propertyDouble(qde, QString("x%1").arg(i)) == QETXML::PropertyFlags::Success && + QETXML::propertyDouble(qde, QString("y%1").arg(i)) == QETXML::PropertyFlags::Success) i++; else break; @@ -109,15 +111,15 @@ bool PartPolygon::fromXmlPriv(const QDomElement &qde) double x, y; for (int j = 1 ; j < i ; ++ j) { - error_counter += propertyDouble(qde, QString("x%1").arg(j), &x); - error_counter += propertyDouble(qde, QString("y%1").arg(j), &y); + error_counter += QETXML::propertyDouble(qde, QString("x%1").arg(j), &x); + error_counter += QETXML::propertyDouble(qde, QString("y%1").arg(j), &y); if (error_counter) return false; temp_polygon << QPointF(x, y); } m_polygon = temp_polygon; - if (propertyBool(qde, "closed", &m_closed) != PropertyFlags::Success) + if (QETXML::propertyBool(qde, "closed", &m_closed) != QETXML::PropertyFlags::Success) return false; return true; @@ -133,12 +135,12 @@ void PartPolygon::toXmlPriv(QDomElement& e) const int i = 1; foreach(QPointF point, m_polygon) { point = mapToScene(point); - e.appendChild(createXmlProperty(QString("x%1").arg(i), point.x())); - e.appendChild(createXmlProperty(QString("y%1").arg(i), point.y())); + e.appendChild(QETXML::createXmlProperty(QString("x%1").arg(i), point.x())); + e.appendChild(QETXML::createXmlProperty(QString("y%1").arg(i), point.y())); ++ i; } - e.appendChild(createXmlProperty("closed", m_closed)); + e.appendChild(QETXML::createXmlProperty("closed", m_closed)); stylesToXml(e); } diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index 67917e28b..9923bd950 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -22,6 +22,8 @@ #include "../../QetGraphicsItemModeler/qetgraphicshandlerutility.h" #include "../elementscene.h" +#include "../../qetxml.h" + /** @brief PartRectangle::PartRectangle Constructor @@ -91,10 +93,10 @@ void PartRectangle::toXmlPriv(QDomElement& e) const { QPointF top_left(sceneTopLeft()); - 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())); + e.appendChild(QETXML::createXmlProperty("x", top_left.x())); + e.appendChild(QETXML::createXmlProperty("y", top_left.y())); + e.appendChild(QETXML::createXmlProperty("width", m_rect.width())); + e.appendChild(QETXML::createXmlProperty("height", m_rect.height())); QRectF rect = m_rect.normalized(); qreal x = m_xRadius; @@ -109,8 +111,8 @@ void PartRectangle::toXmlPriv(QDomElement& e) const e.setAttribute("rx", QString::number(m_xRadius)); e.setAttribute("ry", QString::number(m_yRadius)); - e.appendChild(createXmlProperty("rx", m_xRadius)); - e.appendChild(createXmlProperty("ry", m_yRadius)); + e.appendChild(QETXML::createXmlProperty("rx", m_xRadius)); + e.appendChild(QETXML::createXmlProperty("ry", m_yRadius)); stylesToXml(e); } @@ -125,22 +127,22 @@ bool PartRectangle::fromXmlPriv(const QDomElement &qde) stylesFromXml(qde); double x=0, y=0, w=0, h=0, rx=0, ry=0; - if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "x", &x) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "y", &y) == QETXML::PropertyFlags::NoValidConversion) return false; setPos(mapFromScene(x, y)); - if (propertyDouble(qde, "width", &w) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "height", &h) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "width", &w) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "height", &h) == QETXML::PropertyFlags::NoValidConversion) return false; QRectF rect(QPointF(0,0), QSizeF(w, h)); setRect(rect.normalized()); - if (propertyDouble(qde, "rx", &rx) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "ry", &ry) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(qde, "rx", &rx) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(qde, "ry", &ry) == QETXML::PropertyFlags::NoValidConversion) return false; setXRadius(rx); @@ -151,12 +153,12 @@ bool PartRectangle::fromXmlPriv(const QDomElement &qde) bool PartRectangle::valideXml(QDomElement& element) { // parameters have default values so no value is not a non valid xml element - if ((propertyDouble(element, "x") & PropertyFlags::NoValidConversion) | - (propertyDouble(element, "y") & PropertyFlags::NoValidConversion) | - (propertyDouble(element, "width") & PropertyFlags::NoValidConversion) | - (propertyDouble(element, "height") & PropertyFlags::NoValidConversion) | - (propertyDouble(element, "rx") & PropertyFlags::NoValidConversion) | - (propertyDouble(element, "ry") & PropertyFlags::NoValidConversion)) + if ((QETXML::propertyDouble(element, "x") & QETXML::PropertyFlags::NoValidConversion) | + (QETXML::propertyDouble(element, "y") & QETXML::PropertyFlags::NoValidConversion) | + (QETXML::propertyDouble(element, "width") & QETXML::PropertyFlags::NoValidConversion) | + (QETXML::propertyDouble(element, "height") & QETXML::PropertyFlags::NoValidConversion) | + (QETXML::propertyDouble(element, "rx") & QETXML::PropertyFlags::NoValidConversion) | + (QETXML::propertyDouble(element, "ry") & QETXML::PropertyFlags::NoValidConversion)) return false; return true; } diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 1a79ca0a4..5c176e6de 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -19,6 +19,8 @@ #include "../../qetgraphicsitem/terminal.h" +#include "../../qetxml.h" + /** @brief PartTerminal::PartTerminal @param editor : @@ -52,7 +54,7 @@ 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 // to identify terminals - propertyUuid(xml_elmt, "uuid", &d->m_uuid); + QETXML::propertyUuid(xml_elmt, "uuid", &d->m_uuid); if (!d->fromXml(xml_elmt)) return false; @@ -70,7 +72,7 @@ bool PartTerminal::fromXmlPriv(const QDomElement &xml_elmt) { */ void PartTerminal::toXmlPriv(QDomElement& e) const { - e.appendChild(createXmlProperty("uuid", d->m_uuid)); + e.appendChild(QETXML::createXmlProperty("uuid", d->m_uuid)); d->m_pos = pos(); diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp index ab3bd55ed..bbd3f1781 100644 --- a/sources/editor/graphicspart/parttext.cpp +++ b/sources/editor/graphicspart/parttext.cpp @@ -23,6 +23,8 @@ #include "../elementscene.h" #include "../ui/texteditor.h" +#include "../../qetxml.h" + /** Constructeur @param editor L'editeur d'element concerne @@ -72,7 +74,7 @@ bool PartText::fromXmlPriv(const QDomElement &xml_element) int size; QString font; - if (propertyInteger(xml_element, "size", &size) != PropertyFlags::NotFound) + if (QETXML::propertyInteger(xml_element, "size", &size) != QETXML::PropertyFlags::NotFound) { if (size < 1) { size = 20; @@ -81,7 +83,7 @@ bool PartText::fromXmlPriv(const QDomElement &xml_element) font_.setPointSize(size); setFont(font_); } - else if (propertyString(xml_element, "font", &font) != PropertyFlags::NotFound) + else if (QETXML::propertyString(xml_element, "font", &font) != QETXML::PropertyFlags::NotFound) { QFont font_; font_.fromString(font); @@ -92,20 +94,20 @@ bool PartText::fromXmlPriv(const QDomElement &xml_element) QColor color; QString text; - propertyColor(xml_element, "color", &color); + QETXML::propertyColor(xml_element, "color", &color); setDefaultTextColor(color); - propertyString(xml_element, "text", &text); + QETXML::propertyString(xml_element, "text", &text); setPlainText(text); double x=0, y=0, rot=0; - if (propertyDouble(xml_element, "x", &x) == PropertyFlags::NoValidConversion || - propertyDouble(xml_element, "y", &y) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(xml_element, "x", &x) == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(xml_element, "y", &y) == QETXML::PropertyFlags::NoValidConversion) return false; setPos(x, y); - if (propertyDouble(xml_element, "rotation", &rot) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(xml_element, "rotation", &rot) == QETXML::PropertyFlags::NoValidConversion) return false; setRotation(rot); @@ -121,33 +123,33 @@ void PartText::toXmlPriv(QDomElement& e) const { //QDomElement xml_element = xml_document.createElement(xmlName()); - 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())); + e.appendChild(QETXML::createXmlProperty("x", pos().x())); + e.appendChild(QETXML::createXmlProperty("y", pos().y())); + e.appendChild(QETXML::createXmlProperty("text", toPlainText())); + e.appendChild(QETXML::createXmlProperty("font", font().toString())); + e.appendChild(QETXML::createXmlProperty("rotation", rotation())); + e.appendChild(QETXML::createXmlProperty("color", defaultTextColor().name())); } bool PartText::valideXml(QDomElement& element) { - if (propertyInteger(element, "size") == PropertyFlags::NotFound || - propertyString(element, "font") == PropertyFlags::NotFound) { + if (QETXML::propertyInteger(element, "size") == QETXML::PropertyFlags::NotFound || + QETXML::propertyString(element, "font") == QETXML::PropertyFlags::NotFound) { return false; } - if (propertyString(element, "color") == PropertyFlags::NoValidConversion) + if (QETXML::propertyString(element, "color") == QETXML::PropertyFlags::NoValidConversion) return false; - if (propertyString(element, "text")) + if (QETXML::propertyString(element, "text")) return false; - if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion || - propertyDouble(element, "y") == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(element, "x") == QETXML::PropertyFlags::NoValidConversion || + QETXML::propertyDouble(element, "y") == QETXML::PropertyFlags::NoValidConversion) return false; - if (propertyDouble(element, "rotation", 0) == PropertyFlags::NoValidConversion) + if (QETXML::propertyDouble(element, "rotation", 0) == QETXML::PropertyFlags::NoValidConversion) return false; return true; diff --git a/sources/properties/propertiesinterface.cpp b/sources/properties/propertiesinterface.cpp index a10cf9108..1899595b2 100644 --- a/sources/properties/propertiesinterface.cpp +++ b/sources/properties/propertiesinterface.cpp @@ -17,27 +17,14 @@ */ #include "propertiesinterface.h" #include +#include "../qetxml.h" /*! * Available property types */ namespace { - const QString integerS = "int"; - const QString doubleS = "double"; - const QString boolS = "bool"; - 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; - } } /** @@ -90,287 +77,6 @@ bool PropertiesInterface::valideXml(QDomElement& element) { return false; } -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(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(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(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(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(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(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()); - return p; -} - -QDomElement PropertiesInterface::property(const QDomElement& e, const QString& name) { - for (int i=0; i < e.childNodes().count(); i++) { - QDomElement child = e.childNodes().at(i).toElement(); - if (!validXmlProperty(child)) - continue; // there might also non property childs - - if (child.attribute("name") == name) - return child; - } - return QDomElement(); -} - -/*! - * \brief PropertiesInterface::attribute - * Returns the property with the name \p attribute_name and type \p type - * \param e Xml element which contains the property - * \param attribute_name - * \param type Type of the property - * \param attr - * \return - */ -bool PropertiesInterface::attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr) { - QDomElement p = property(e, attribute_name); - if (p.isNull()) { - // check if legacy property is available, - // where the property is inside the element as attribute - if (!e.hasAttribute(attribute_name)) { - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "Property " << attribute_name << "is not available"; - return false; - } - - *attr = e.attribute(attribute_name); - - } else { - if (p.attribute("type") != type) { - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ", Property: " << attribute_name << "(" << p.attribute("type") << ") has not type: " << type; - return false; - } - - *attr = p.attribute("value"); - - } - return true; -} - -/*! - * \brief PropertiesInterface::propertyInteger - * Reads an interger from the XML element. - * \param e DomElement which contains the property attribute - * \param attribute_name Name of the attribute - * \param entier Return value if success - * \return True if reading an integer was successful, else False. If the attribute was not found, - * \p entier is not valid and the return value is False - */ -PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QDomElement &e, const QString& attribute_name, int* entier) { - - QString attr; - - if (!attribute(e, attribute_name, integerS, &attr)) { - return PropertyFlags::NotFound; - } - - return debug(propertyInteger(attr, entier), e, attribute_name, attr, integerS); -} - -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; - } - - if (entier != nullptr) - *entier = tmp; - - return PropertyFlags::Success; -} - -PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel) { - - QString attr; - - if (!attribute(e, attribute_name, doubleS, &attr)) { - return PropertyFlags::NotFound; - } - - return debug(propertyDouble(attr, reel), e, attribute_name, attr, doubleS); -} - -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; - } - - if (reel != nullptr) - *reel = tmp; - - return PropertyFlags::Success; -} - -PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean) { - - QString attr; - - if (!attribute(e, attribute_name, boolS, &attr)) { - return PropertyFlags::NotFound; - } - - return debug(propertyBool(attr, boolean), e, attribute_name, attr, boolS); -} - -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; - } - } - - if (boolean != nullptr) - *boolean = tmp; - - return PropertyFlags::Success; -} - -PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color) { - - QString attr; - - if (!attribute(e, attribute_name, colorS, &attr)) { - return PropertyFlags::NotFound; - } - - return debug(propertyColor(attr, color), e, attribute_name, attr, colorS); -} - -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; - } - - if (color != nullptr) - *color = tmp; - - return PropertyFlags::Success; -} - -PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid) { - QString attr; - - if (!attribute(e, attribute_name, uuidS, &attr)) { - return PropertyFlags::NotFound; - } - - 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(value); - - return PropertyFlags::Success; -} - -PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string) { - - QString attr; - if (!attribute(e, attribute_name, stringS, &attr)) { - return PropertyFlags::NotFound; - } - - // verifie la validite de l'attribut - if (string != nullptr) - *string = attr; - - return PropertyFlags::Success; -} - -/*! - * \brief PropertiesInterface::validXmlProperty - * Check if the Xml element contains the needed fields - * \param e Xml Property - * \return True if name, type, value attribute are available, else false - */ -bool PropertiesInterface::validXmlProperty(const QDomElement& e) { - if (!e.hasAttribute("name")) - return false; - - if (!e.hasAttribute("type")) - return false; - - if (!e.hasAttribute("value")) - return false; - - return true; -} - /** Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w") en orientation. Si la chaine fait plusieurs caracteres, seul le @@ -444,15 +150,15 @@ void PropertiesInterface::propertiesToXml(QDomElement& e) const auto type = i.value().type(); switch(type) { case QVariant::Type::String: - up.appendChild(createXmlProperty(i.key(), i.value().toString())); break; + up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toString())); break; case QVariant::Type::Int: - up.appendChild(createXmlProperty(i.key(), i.value().toInt())); break; + up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toInt())); break; case QVariant::Type::Double: - up.appendChild(createXmlProperty(i.key(), i.value().toDouble())); break; + up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toDouble())); break; case QVariant::Type::Bool: - up.appendChild(createXmlProperty(i.key(), i.value().toBool())); break; + up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toBool())); break; case QVariant::Type::Color: - up.appendChild(createXmlProperty(i.key(), QColor(i.value().value()))); break; + up.appendChild(QETXML::createXmlProperty(i.key(), QColor(i.value().value()))); break; default: break; } @@ -484,47 +190,47 @@ bool PropertiesInterface::propertiesFromXml(const QDomElement& e) QString type = userProperty.attribute("type"); QString value = userProperty.attribute("value"); - if (type == integerS) + if (type == QETXML::integerS) { int i; - if (propertyInteger(value, &i) == PropertyFlags::Success) + if (QETXML::propertyInteger(value, &i) == QETXML::PropertyFlags::Success) properties[name] = QVariant(i); else return false; } - else if (type == doubleS) + else if (type == QETXML::doubleS) { double d; - if (propertyDouble(value, &d) == PropertyFlags::Success) + if (QETXML::propertyDouble(value, &d) == QETXML::PropertyFlags::Success) properties[name] = QVariant(d); else return false; } - else if (type == boolS) + else if (type == QETXML::boolS) { bool b; - if (propertyBool(value, &b) == PropertyFlags::Success) + if (QETXML::propertyBool(value, &b) == QETXML::PropertyFlags::Success) properties[name] = QVariant(b); else return false; } - else if (type == uuidS) + else if (type == QETXML::uuidS) { QUuid u; - if (propertyUuid(value, &u) == PropertyFlags::Success) + if (QETXML::propertyUuid(value, &u) == QETXML::PropertyFlags::Success) properties[name] = QVariant(u); else return false; } - else if (type == colorS) + else if (type == QETXML::colorS) { QColor c; - if (propertyColor(value, &c) == PropertyFlags::Success) + if (QETXML::propertyColor(value, &c) == QETXML::PropertyFlags::Success) properties[name] = QVariant(c); else return false; } - else if (type == stringS) + else if (type == QETXML::stringS) { properties[name] = QVariant(value); } diff --git a/sources/properties/propertiesinterface.h b/sources/properties/propertiesinterface.h index 0f2c54219..0d2b6d119 100644 --- a/sources/properties/propertiesinterface.h +++ b/sources/properties/propertiesinterface.h @@ -112,43 +112,6 @@ class PropertiesInterface static bool valideXml(QDomElement& element); - /*! - * Use this functions to add properties to the xml document - */ - 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); - - enum PropertyFlags { - Success = 0, - NotFound = 1, - NoValidConversion = 2, - // = 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); QString tagName() const; diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 46744f5b1..db9cd5719 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -20,6 +20,8 @@ #include #include +#include "../qetxml.h" + TerminalData::TerminalData(): PropertiesInterface("terminaldata") { @@ -99,11 +101,11 @@ void TerminalData::toXmlPriv(QDomElement& e) const // 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 - 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))); + e.appendChild(QETXML::createXmlProperty("x", m_pos.x())); + e.appendChild(QETXML::createXmlProperty("y", m_pos.y())); + e.appendChild(QETXML::createXmlProperty("name", m_name)); + e.appendChild(QETXML::createXmlProperty("orientation", orientationToString(m_orientation))); + e.appendChild(QETXML::createXmlProperty("type", typeToString(m_type))); } /* @@ -123,10 +125,10 @@ bool TerminalData::fromXmlPriv(const QDomElement &xml_element) // reads the position of the terminal // lit la position de la borne - if (propertyDouble(xml_element, "x", &term_x)) + if (QETXML::propertyDouble(xml_element, "x", &term_x)) return false; - if (propertyDouble(xml_element, "y", &term_y)) + if (QETXML::propertyDouble(xml_element, "y", &term_y)) return false; m_pos = QPointF(term_x, term_y); @@ -139,12 +141,12 @@ bool TerminalData::fromXmlPriv(const QDomElement &xml_element) // older version of qet. So use the legacy approach - //if (propertyString(xml_element, "name", &m_name)) + //if (QETXML::propertyString(xml_element, "name", &m_name)) // return false; - propertyString(xml_element, "name", &m_name); // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20" + QETXML::propertyString(xml_element, "name", &m_name); // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20" QString o; - if (propertyString(xml_element, "orientation", &o)) + if (QETXML::propertyString(xml_element, "orientation", &o)) return false; // read the orientation of the terminal @@ -152,29 +154,29 @@ bool TerminalData::fromXmlPriv(const QDomElement &xml_element) m_orientation = orientationFromString(o); QString type; - if (propertyString(xml_element, "type", &type) == PropertyFlags::Success) + if (QETXML::propertyString(xml_element, "type", &type) == QETXML::PropertyFlags::Success) m_type = typeFromString(type); return true; } bool TerminalData::valideXml(const QDomElement& xml_element) { - if (propertyDouble(xml_element, "x")) + if (QETXML::propertyDouble(xml_element, "x")) return false; // Old projects do not have this property. -// if (propertyString(xml_element, "type")) +// if (QETXML::propertyString(xml_element, "type")) // return false; // legacy elements do not have an uuid -// if (propertyUuid(xml_element, "uuid")) +// if (QETXML::propertyUuid(xml_element, "uuid")) // return false; - //if (propertyString(xml_element, "name")) // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20" + //if (QETXML::propertyString(xml_element, "name")) // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20" // return false; - if (propertyString(xml_element, "orientation")) + if (QETXML::propertyString(xml_element, "orientation")) return false; return true; } diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index d1fc888e3..5395c8381 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -22,6 +22,8 @@ #include #include +#include "../qetxml.h" + /** @brief XRefProperties::XRefProperties Default Constructor @@ -96,20 +98,20 @@ void XRefProperties::fromSettings(QSettings &settings, void XRefProperties::toXmlPriv(QDomElement& e) const { - 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")); + e.appendChild(QETXML::createXmlProperty("type", m_key)); + e.appendChild(QETXML::createXmlProperty("showpowerctc", m_show_power_ctc)); + e.appendChild(QETXML::createXmlProperty("displayhas", m_display == Cross? "cross" : "contacts")); + e.appendChild(QETXML::createXmlProperty("snapto", m_snap_to == Bottom? "bottom" : "label")); QMetaEnum var = QMetaEnum::fromType(); - 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)); + e.appendChild(QETXML::createXmlProperty("xrefpos", var.valueToKey(m_xref_pos))); + e.appendChild(QETXML::createXmlProperty("offset", m_offset)); + e.appendChild(QETXML::createXmlProperty("master_label", m_master_label)); + e.appendChild(QETXML::createXmlProperty("slave_label", m_slave_label)); foreach (QString key, m_prefix.keys()) { - e.appendChild(createXmlProperty(key + "prefix", m_prefix.value(key))); + e.appendChild(QETXML::createXmlProperty(key + "prefix", m_prefix.value(key))); } } @@ -120,32 +122,32 @@ void XRefProperties::toXmlPriv(QDomElement& e) const */ bool XRefProperties::fromXmlPriv(const QDomElement &xml_element) { - if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc)) + if (QETXML::propertyBool(xml_element, "showpowerctc", &m_show_power_ctc)) return false; QString display; - if (propertyString(xml_element, "displayhas", &display) != PropertyFlags::NotFound) { + if (QETXML::propertyString(xml_element, "displayhas", &display) != QETXML::PropertyFlags::NotFound) { display == "cross"? m_display = Cross : m_display = Contacts; } QString snap; - if (propertyString(xml_element, "snapto", &snap) != PropertyFlags::NotFound) { + if (QETXML::propertyString(xml_element, "snapto", &snap) != QETXML::PropertyFlags::NotFound) { snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label; } QString xrefpos; - if (propertyString(xml_element, "xrefpos", &xrefpos) != PropertyFlags::NotFound) { + if (QETXML::propertyString(xml_element, "xrefpos", &xrefpos) != QETXML::PropertyFlags::NotFound) { QMetaEnum var = QMetaEnum::fromType(); m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xrefpos.toStdString().data())); } // TODO: why it compiles without this true?? - propertyInteger(xml_element, "offset", &m_offset); - propertyString(xml_element, "master_label", &m_master_label); - propertyString(xml_element, "slave_label", &m_slave_label); + QETXML::propertyInteger(xml_element, "offset", &m_offset); + QETXML::propertyString(xml_element, "master_label", &m_master_label); + QETXML::propertyString(xml_element, "slave_label", &m_slave_label); QString value; foreach (QString key, m_prefix_keys) { - if (!propertyString(xml_element, key + "prefix", &value)) + if (!QETXML::propertyString(xml_element, key + "prefix", &value)) m_prefix.insert(key, value); } return true; diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 27c844978..638a55210 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -31,6 +31,8 @@ #include "element.h" #include "../QetGraphicsItemModeler/qetgraphicshandleritem.h" +#include "../qetxml.h" + #include #include @@ -583,11 +585,11 @@ ConductorTextItem *Conductor::textItem() const bool Conductor::valideXml(QDomElement &e){ // // TODO: seems to short! (see fromXML) -// if (propertyDouble(e, "x") || -// propertyDouble(e, "y")) +// if (QETXML::propertyDouble(e, "x") || +// QETXML::propertyDouble(e, "y")) // return false; -// if (propertyBool(e, "freezeLabel")) +// if (QETXML::propertyBool(e, "freezeLabel")) // return false; return true; @@ -967,8 +969,8 @@ bool Conductor::fromXmlPriv(const QDomElement &dom_element) { // TODO: seems to short! double x=0, y=0; - propertyDouble(dom_element, "x", &x); - propertyDouble(dom_element, "y", &y); + QETXML::propertyDouble(dom_element, "x", &x); + QETXML::propertyDouble(dom_element, "y", &y); setPos(x, y); bool return_ = pathFromXml(dom_element); @@ -983,7 +985,7 @@ bool Conductor::fromXmlPriv(const QDomElement &dom_element) else m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers")); - propertyBool(dom_element, "freezeLabel", &m_freeze_label); + QETXML::propertyBool(dom_element, "freezeLabel", &m_freeze_label); setProperties(pr); return return_; @@ -1002,8 +1004,8 @@ bool Conductor::fromXmlPriv(const QDomElement &dom_element) */ void Conductor::toXmlPriv(QDomElement& e) const { - e.appendChild(createXmlProperty("x", pos().x())); - e.appendChild(createXmlProperty("y", pos().y())); + e.appendChild(QETXML::createXmlProperty("x", pos().x())); + e.appendChild(QETXML::createXmlProperty("y", pos().y())); // Terminal is uniquely identified by the uuid of the terminal and the element QUuid terminal = terminal1->uuid(); @@ -1012,10 +1014,10 @@ void Conductor::toXmlPriv(QDomElement& e) 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 - e.appendChild(createXmlProperty("terminal1", terminal1->ID())); + e.appendChild(QETXML::createXmlProperty("terminal1", terminal1->ID())); } else { - e.appendChild(createXmlProperty("element1", terminalParent)); - e.appendChild(createXmlProperty("terminal1", terminal)); + e.appendChild(QETXML::createXmlProperty("element1", terminalParent)); + e.appendChild(QETXML::createXmlProperty("terminal1", terminal)); } terminal = terminal2->uuid(); @@ -1024,13 +1026,13 @@ void Conductor::toXmlPriv(QDomElement& e) 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 - e.appendChild(createXmlProperty("terminal2", terminal2->ID())); + e.appendChild(QETXML::createXmlProperty("terminal2", terminal2->ID())); } else { - e.appendChild(createXmlProperty("element2", terminal2->parentElement()->uuid())); - e.appendChild(createXmlProperty("terminal2", terminal2->uuid())); + e.appendChild(QETXML::createXmlProperty("element2", terminal2->parentElement()->uuid())); + e.appendChild(QETXML::createXmlProperty("terminal2", terminal2->uuid())); } - e.appendChild(createXmlProperty("freezeLabel", m_freeze_label)); + e.appendChild(QETXML::createXmlProperty("freezeLabel", m_freeze_label)); QDomDocument doc; @@ -1043,8 +1045,8 @@ void Conductor::toXmlPriv(QDomElement& e) const { foreach(ConductorSegment *segment, segmentsList()) { current_segment = doc.createElement("segment"); - current_segment.appendChild(createXmlProperty("orientation", segment->isHorizontal() ? "horizontal": "vertical")); - current_segment.appendChild(createXmlProperty("length", segment -> length())); + current_segment.appendChild(QETXML::createXmlProperty("orientation", segment->isHorizontal() ? "horizontal": "vertical")); + current_segment.appendChild(QETXML::createXmlProperty("length", segment -> length())); e.appendChild(current_segment); } } @@ -1138,12 +1140,12 @@ bool Conductor::pathFromXml(const QDomElement &e) { // le segment doit avoir une longueur qreal segment_length; - if (propertyDouble(current_segment, "length", & segment_length)) + if (QETXML::propertyDouble(current_segment, "length", & segment_length)) continue; bool isHorizontal = false; QString orientation; - if (propertyString(current_segment, "orientation", &orientation) == PropertyFlags::Success) { + if (QETXML::propertyString(current_segment, "orientation", &orientation) == QETXML::PropertyFlags::Success) { if (orientation == "horizontal") isHorizontal = true; } else { diff --git a/sources/qetgraphicsitem/conductortextitem.cpp b/sources/qetgraphicsitem/conductortextitem.cpp index 2cba46c8f..f47bd4656 100644 --- a/sources/qetgraphicsitem/conductortextitem.cpp +++ b/sources/qetgraphicsitem/conductortextitem.cpp @@ -21,6 +21,8 @@ #include "../diagramcommands.h" #include "../qetgraphicsitem/conductor.h" +#include "../qetxml.h" + /** Constructeur @param parent_conductor Conducteur auquel ce texte est rattache @@ -64,11 +66,11 @@ Conductor *ConductorTextItem::parentConductor() const void ConductorTextItem::toXml(QDomElement& e) { if(moved_by_user_) { - e.appendChild(PropertiesInterface::createXmlProperty("userx", pos().x())); - e.appendChild(PropertiesInterface::createXmlProperty("usery", pos().y())); + e.appendChild(QETXML::createXmlProperty("userx", pos().x())); + e.appendChild(QETXML::createXmlProperty("usery", pos().y())); } if(rotate_by_user_) - e.appendChild(PropertiesInterface::createXmlProperty("rotation", rotation())); + e.appendChild(QETXML::createXmlProperty("rotation", rotation())); } @@ -80,14 +82,14 @@ void ConductorTextItem::toXml(QDomElement& e) { void ConductorTextItem::fromXml(const QDomElement &e) { double userx=0, usery=0; - if (PropertiesInterface::propertyDouble(e, "userx", &userx) == PropertiesInterface::PropertyFlags::Success && - PropertiesInterface::propertyDouble(e, "usery", &usery) == PropertiesInterface::PropertyFlags::Success) { + if (QETXML::propertyDouble(e, "userx", &userx) == QETXML::PropertyFlags::Success && + QETXML::propertyDouble(e, "usery", &usery) == QETXML::PropertyFlags::Success) { setPos(userx, usery); moved_by_user_ = true; } double rotation; - if (PropertiesInterface::propertyDouble(e, "rotation", &rotation) == PropertiesInterface::PropertyFlags::Success) { + if (QETXML::propertyDouble(e, "rotation", &rotation) == QETXML::PropertyFlags::Success) { setRotation(rotation); rotate_by_user_ = true; } diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index f36cd340b..ab012a2d5 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -25,6 +25,8 @@ #include "../qetgraphicsitem/element.h" #include "conductortextitem.h" +#include "../qetxml.h" + #include QColor Terminal::neutralColor = QColor(Qt::blue); @@ -758,8 +760,8 @@ QList Terminal::conductors() const */ void Terminal::toXmlPriv(QDomElement &qdo) const { - qdo.appendChild(createXmlProperty("number", number_terminal_)); - qdo.appendChild(createXmlProperty("nameHidden", name_terminal_hidden)); + qdo.appendChild(QETXML::createXmlProperty("number", number_terminal_)); + qdo.appendChild(QETXML::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. @@ -780,10 +782,10 @@ bool Terminal::valideXml(const QDomElement &terminal) if (terminal.tagName() != "terminal") return(false); // affuteuse_250h.qet contains in line 8398 terminals which do not have this -// if (propertyString(terminal, "number")) +// if (QETXML::propertyString(terminal, "number")) // return false; // affuteuse_250h.qet contains in line 8398 terminals which do not have this -// if (propertyBool(terminal, "nameHidden")) +// if (QETXML::propertyBool(terminal, "nameHidden")) // return false; if (!TerminalData::valideXml(terminal)) @@ -802,9 +804,9 @@ bool Terminal::valideXml(const QDomElement &terminal) (memes coordonnes, meme orientation), false sinon */ bool Terminal::fromXmlPriv(const QDomElement &terminal) { - propertyString(terminal, "number", &number_terminal_); + QETXML::propertyString(terminal, "number", &number_terminal_); - propertyBool(terminal, "nameHidden", &name_terminal_hidden); + QETXML::propertyBool(terminal, "nameHidden", &name_terminal_hidden); if(!d->fromXml(terminal)) return false; diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 00e0b80ee..dc49251c5 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -39,6 +39,8 @@ #include #include +#include "qetxml.h" + static int BACKUP_INTERVAL = 120000; //interval in ms of backup = 2min /** @@ -1533,7 +1535,7 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project) XRefProperties xrp; xrp.fromXml(elmt); QString type; - if (PropertiesInterface::propertyString(elmt, "type", &type) == PropertiesInterface::PropertyFlags::Success) + if (QETXML::propertyString(elmt, "type", &type) == QETXML::PropertyFlags::Success) m_default_xref_properties.insert(type, xrp); else qDebug() << "xref Property was not added to m_default_xref_properties."; diff --git a/sources/qetxml.cpp b/sources/qetxml.cpp index 58e8255c3..42df0846d 100644 --- a/sources/qetxml.cpp +++ b/sources/qetxml.cpp @@ -581,3 +581,299 @@ QVector QETXML::findInDomElement(const QDomElement &dom_elmt, const } return(return_list); } + +namespace QETXML { + +PropertyFlags debugReadXml(PropertyFlags flag, const QDomElement &e, const QString& attribute_name, const QString& attr, const QString& type) +{ + if (flag == QETXML::PropertyFlags::NoValidConversion) + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << type << ". value: " << attr; + + return flag; +} + +QDomElement 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 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; +} + +/*! + * \brief propertyInteger + * Reads an interger from the XML element. + * \param e DomElement which contains the property attribute + * \param attribute_name Name of the attribute + * \param entier Return value if success + * \return True if reading an integer was successful, else False. If the attribute was not found, + * \p entier is not valid and the return value is False + */ +QDomElement 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 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 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 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 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()); + return p; +} + +/*! + * \brief PropertiesInterface::propertyInteger + * Reads an interger from the XML element. + * \param e DomElement which contains the property attribute + * \param attribute_name Name of the attribute + * \param entier Return value if success + * \return True if reading an integer was successful, else False. If the attribute was not found, + * \p entier is not valid and the return value is False + */ +PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int* entier) { + + QString attr; + + if (!attribute(e, attribute_name, integerS, &attr)) { + return PropertyFlags::NotFound; + } + + return debugReadXml(propertyInteger(attr, entier), e, attribute_name, attr, integerS); +} + +PropertyFlags propertyInteger(const QString& value, int* entier) { + // verifie la validite de l'attribut + bool ok; + int tmp = value.toInt(&ok); + if (!ok) { + return QETXML::PropertyFlags::NoValidConversion; + } + + if (entier != nullptr) + *entier = tmp; + + return PropertyFlags::Success; +} + +PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel) { + + QString attr; + + if (!attribute(e, attribute_name, doubleS, &attr)) { + return PropertyFlags::NotFound; + } + + return debugReadXml(propertyDouble(attr, reel), e, attribute_name, attr, doubleS); +} + +PropertyFlags propertyDouble(const QString& value, double* reel) +{ + // verifie la validite de l'attribut + bool ok; + double tmp = value.toDouble(&ok); + if (!ok) { + return QETXML::PropertyFlags::NoValidConversion; + } + + if (reel != nullptr) + *reel = tmp; + + return PropertyFlags::Success; +} + +PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean) { + + QString attr; + + if (!attribute(e, attribute_name, boolS, &attr)) { + return PropertyFlags::NotFound; + } + + return debugReadXml(propertyBool(attr, boolean), e, attribute_name, attr, boolS); +} + +PropertyFlags 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 QETXML::PropertyFlags::NoValidConversion; + } + } + + if (boolean != nullptr) + *boolean = tmp; + + return PropertyFlags::Success; +} + +PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color) { + + QString attr; + + if (!attribute(e, attribute_name, colorS, &attr)) { + return PropertyFlags::NotFound; + } + + return debugReadXml(propertyColor(attr, color), e, attribute_name, attr, colorS); +} + +PropertyFlags propertyColor(const QString& value, QColor* color) +{ + // verifie la validite de l'attribut + QColor tmp = QColor(value); + if (!tmp.isValid()) { + return QETXML::PropertyFlags::NoValidConversion; + } + + if (color != nullptr) + *color = tmp; + + return PropertyFlags::Success; +} + +PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid) { + QString attr; + + if (!attribute(e, attribute_name, uuidS, &attr)) { + return PropertyFlags::NotFound; + } + + return debugReadXml(propertyUuid(attr, uuid), e, attribute_name, attr, uuidS); +} + +PropertyFlags propertyUuid(const QString& value, QUuid* uuid) +{ + if (QUuid(value).isNull()){ + return QETXML::PropertyFlags::NoValidConversion; + } + + + if (uuid != nullptr) + *uuid = QUuid(value); + + return PropertyFlags::Success; +} + +PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string) { + + QString attr; + if (!attribute(e, attribute_name, stringS, &attr)) { + return PropertyFlags::NotFound; + } + + // verifie la validite de l'attribut + if (string != nullptr) + *string = attr; + + return PropertyFlags::Success; +} + +QDomElement property(const QDomElement& e, const QString& name) { + for (int i=0; i < e.childNodes().count(); i++) { + QDomElement child = e.childNodes().at(i).toElement(); + if (!validXmlProperty(child)) + continue; // there might also non property childs + + if (child.attribute("name") == name) + return child; + } + return QDomElement(); +} + +/*! + * \brief PropertiesInterface::attribute + * Returns the property with the name \p attribute_name and type \p type + * \param e Xml element which contains the property + * \param attribute_name + * \param type Type of the property + * \param attr + * \return + */ +bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr) { + QDomElement p = property(e, attribute_name); + if (p.isNull()) { + // check if legacy property is available, + // where the property is inside the element as attribute + if (!e.hasAttribute(attribute_name)) { + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "Property " << attribute_name << "is not available"; + return false; + } + + *attr = e.attribute(attribute_name); + + } else { + if (p.attribute("type") != type) { + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ", Property: " << attribute_name << "(" << p.attribute("type") << ") has not type: " << type; + return false; + } + + *attr = p.attribute("value"); + + } + return true; +} + +bool validXmlProperty(const QDomElement& e) { + if (!e.hasAttribute("name")) + return false; + + if (!e.hasAttribute("type")) + return false; + + if (!e.hasAttribute("value")) + return false; + + return true; +} + +} diff --git a/sources/qetxml.h b/sources/qetxml.h index 0c4ae7e95..6c84c74e9 100644 --- a/sources/qetxml.h +++ b/sources/qetxml.h @@ -89,6 +89,54 @@ namespace QETXML QVector findInDomElement(const QDomElement &dom_elmt, const QString &tag_name); + + const QString integerS = "int"; + const QString doubleS = "double"; + const QString boolS = "bool"; + const QString stringS = "string"; + const QString uuidS = "uuid"; + const QString colorS = "color"; + + enum PropertyFlags { + Success = 0, + NotFound = 1, + NoValidConversion = 2, + // = 4 + }; + + /*! + * Use this functions to add properties to the xml document + */ + QDomElement createXmlProperty(const QString& name, const QString value); + QDomElement createXmlProperty(const QString& name, const char* value); + QDomElement createXmlProperty(const QString& name, const int value); + QDomElement createXmlProperty(const QString& name, const double value); + QDomElement createXmlProperty(const QString& name, const bool value); + QDomElement createXmlProperty(const QString& name, const QUuid value); + QDomElement createXmlProperty(const QString& name, const QColor value); + + PropertyFlags propertyInteger(const QString& value, int* entry = nullptr); + PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr); + PropertyFlags propertyDouble(const QString& value, double* entry = nullptr); + PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr); + PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr); + PropertyFlags propertyBool(const QString& value, bool* entry = nullptr); + PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr); + PropertyFlags propertyUuid(const QString& value, QUuid* entry = nullptr); + PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr); + PropertyFlags propertyColor(const QString& value, QColor* entry = nullptr); + PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr); + + QDomElement property(const QDomElement& e, const QString& name); + bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); + + /*! + * \brief PropertiesInterface::validXmlProperty + * Check if the Xml element contains the needed fields + * \param e Xml Property + * \return True if name, type, value attribute are available, else false + */ + bool validXmlProperty(const QDomElement& e); } #endif // QETXML_H diff --git a/sources/titleblockproperties.cpp b/sources/titleblockproperties.cpp index 9b75032e0..01bd284df 100644 --- a/sources/titleblockproperties.cpp +++ b/sources/titleblockproperties.cpp @@ -19,6 +19,8 @@ #include "qet.h" #include "qetapp.h" +#include "qetxml.h" + /** Constructeur. Initialise un objet TitleBlockProperties avec tous les champs vides (date vide + useDate a UseDateValue). @@ -71,20 +73,20 @@ bool TitleBlockProperties::operator!=(const TitleBlockProperties &ip) { @param e Element XML auquel seront ajoutes des attributs */ 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")); + e.appendChild(QETXML::createXmlProperty("author", author)); + e.appendChild(QETXML::createXmlProperty("title", title)); + e.appendChild(QETXML::createXmlProperty("filename", filename)); + e.appendChild(QETXML::createXmlProperty("plant", plant)); + e.appendChild(QETXML::createXmlProperty("locmach", locmach)); + e.appendChild(QETXML::createXmlProperty("indexrev", indexrev)); + e.appendChild(QETXML::createXmlProperty("version", version)); + e.appendChild(QETXML::createXmlProperty("folio", folio)); + e.appendChild(QETXML::createXmlProperty("date", exportDate())); + e.appendChild(QETXML::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))); + e.appendChild(QETXML::createXmlProperty("titleblocktemplate", template_name)); + e.appendChild(QETXML::createXmlProperty("titleblocktemplateCollection", QET::qetCollectionToString(collection))); } if (context.keys().count()) { @@ -103,27 +105,27 @@ bool TitleBlockProperties::fromXmlPriv(const QDomElement &e) { // reads the historical fields - propertyString(e, "author", &author); - propertyString(e, "title", &title); - propertyString(e, "filename", &filename); - propertyString(e, "plant", &plant); - propertyString(e, "locmach", &locmach); - propertyString(e, "indexrev", &indexrev); - propertyString(e, "version", &version); - propertyString(e, "folio", &folio); - propertyString(e, "auto_page_num", &auto_page_num); + QETXML::propertyString(e, "author", &author); + QETXML::propertyString(e, "title", &title); + QETXML::propertyString(e, "filename", &filename); + QETXML::propertyString(e, "plant", &plant); + QETXML::propertyString(e, "locmach", &locmach); + QETXML::propertyString(e, "indexrev", &indexrev); + QETXML::propertyString(e, "version", &version); + QETXML::propertyString(e, "folio", &folio); + QETXML::propertyString(e, "auto_page_num", &auto_page_num); QString date; - propertyString(e, "date", &date); + QETXML::propertyString(e, "date", &date); setDateFromString(date); QString display_at_temp; - if (propertyString(e, "displayAt", &display_at_temp) == PropertyFlags::Success) + if (QETXML::propertyString(e, "displayAt", &display_at_temp) == QETXML::PropertyFlags::Success) display_at = (display_at_temp == "bottom" ? Qt::BottomEdge : Qt::RightEdge); // otherwise it gets default in header file // reads the template used to render the title block - if (propertyString(e, "titleblocktemplate", &template_name) == PropertyFlags::Success) { + if (QETXML::propertyString(e, "titleblocktemplate", &template_name) == QETXML::PropertyFlags::Success) { QString tbc; - if (propertyString(e, "titleblocktemplateCollection", &tbc) == PropertyFlags::Success) + if (QETXML::propertyString(e, "titleblocktemplateCollection", &tbc) == QETXML::PropertyFlags::Success) collection = QET::qetCollectionFromString(tbc); }