From 385d0ffd691a0642aa4dcbcc9d87aa87026baacb Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 13 Aug 2020 23:27:11 +0200 Subject: [PATCH 01/34] initial work to move everything into the propertiesinterface which is related to it --- .../graphicspart/customelementgraphicpart.cpp | 20 +- .../graphicspart/customelementgraphicpart.h | 2 +- .../editor/graphicspart/customelementpart.h | 11 +- sources/editor/graphicspart/partarc.cpp | 43 ++-- sources/editor/graphicspart/partellipse.cpp | 32 +-- sources/editor/graphicspart/partline.cpp | 49 ++-- sources/editor/graphicspart/partpolygon.cpp | 24 +- sources/editor/graphicspart/partrectangle.cpp | 14 +- sources/editor/graphicspart/parttext.cpp | 51 ++-- sources/properties/propertiesinterface.cpp | 218 ++++++++++++++++++ sources/properties/propertiesinterface.h | 45 ++++ sources/properties/terminaldata.cpp | 39 ++-- sources/properties/terminaldata.h | 18 ++ sources/properties/xrefproperties.cpp | 70 +++--- sources/properties/xrefproperties.h | 1 + sources/qet.cpp | 31 --- sources/qetgraphicsitem/terminal.cpp | 103 +++++---- sources/qetgraphicsitem/terminal.h | 10 +- 18 files changed, 555 insertions(+), 226 deletions(-) diff --git a/sources/editor/graphicspart/customelementgraphicpart.cpp b/sources/editor/graphicspart/customelementgraphicpart.cpp index e19280ecc..1ba064e3b 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.cpp +++ b/sources/editor/graphicspart/customelementgraphicpart.cpp @@ -144,7 +144,7 @@ void CustomElementGraphicPart::setAntialiased(const bool b) * Each style separate by ; and name-style/value are separate by : * @param qde : QDOmElement used to write the style. */ -void CustomElementGraphicPart::stylesToXml(QDomElement &qde) const +void CustomElementGraphicPart::stylesToXml(QDomDocument &xml_document, QDomElement &qde) const { QString css_like_styles; @@ -479,9 +479,8 @@ void CustomElementGraphicPart::stylesToXml(QDomElement &qde) const else if (_color == HTMLGrayBlackColor) css_like_styles += "HTMLGrayBlack"; else if (_color == NoneColor) css_like_styles += "none"; - - qde.setAttribute("style", css_like_styles); - qde.setAttribute("antialias", _antialiased ? "true" : "false"); + qde.appendChild(createXmlProperty(xml_document, "style", css_like_styles)); + qde.appendChild(createXmlProperty(xml_document, "antialias", _antialiased ? "true" : "false")); } @@ -493,13 +492,18 @@ void CustomElementGraphicPart::stylesToXml(QDomElement &qde) const void CustomElementGraphicPart::stylesFromXml(const QDomElement &qde) { resetStyles(); + + QString style_string; + propertyString(qde, "style", &style_string); //Get the list of pair style/value #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove - QStringList styles = qde.attribute("style").split(";", QString::SkipEmptyParts); + QStringList styles = style_string.split(";", QString::SkipEmptyParts); #else - QStringList styles = qde.attribute("style").split(";", Qt::SkipEmptyParts); + QStringList styles = style_string.split(";", Qt::SkipEmptyParts); #endif + + //Check each pair of style QRegExp rx("^\\s*([a-z-]+)\\s*:\\s*([a-zA-Z-]+)\\s*$"); @@ -843,7 +847,9 @@ void CustomElementGraphicPart::stylesFromXml(const QDomElement &qde) } } //Get antialiasing - _antialiased = qde.attribute("antialias") == "true"; + QString a; + propertyString(qde, "antialias", &a); + _antialiased = a == "true"; } diff --git a/sources/editor/graphicspart/customelementgraphicpart.h b/sources/editor/graphicspart/customelementgraphicpart.h index 341c245c2..0fdf5979d 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.h +++ b/sources/editor/graphicspart/customelementgraphicpart.h @@ -95,7 +95,7 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar virtual void resetAllHandlerColor() {} protected: - void stylesToXml (QDomElement &) const; + void stylesToXml (QDomDocument &xml_document, QDomElement &) const; void stylesFromXml(const QDomElement &); void resetStyles (); void applyStylesToQPainter(QPainter &) const; diff --git a/sources/editor/graphicspart/customelementpart.h b/sources/editor/graphicspart/customelementpart.h index 3b58a5698..f36658aa0 100644 --- a/sources/editor/graphicspart/customelementpart.h +++ b/sources/editor/graphicspart/customelementpart.h @@ -19,6 +19,7 @@ #define CUSTOM_ELEMENT_PART_H #include "qet.h" +#include "propertiesinterface.h" class CustomElement; class ElementPrimitiveDecorator; @@ -35,7 +36,7 @@ class QGraphicsSceneMouseEvent; is no point for those classes to store their visual representation with anything more complex than a QImage. */ -class CustomElementPart { +class CustomElementPart: public PropertiesInterface { // constructors, destructor public: /** @@ -55,14 +56,6 @@ class CustomElementPart { // methods public: - /** - Load the primitive from an XML element that describes it - */ - virtual void fromXml(const QDomElement &) = 0; - /** - Export the primitive as an XML element - */ - virtual const QDomElement toXml(QDomDocument &) const = 0; /** Set a specific property of the primitive */ diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index a42bff805..c9e526087 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -98,14 +98,18 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, const QDomElement PartArc::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("arc"); QPointF top_left(sceneTopLeft()); - xml_element.setAttribute("x", QString("%1").arg(top_left.x())); - xml_element.setAttribute("y", QString("%1").arg(top_left.y())); - xml_element.setAttribute("width", QString("%1").arg(rect().width())); - xml_element.setAttribute("height", QString("%1").arg(rect().height())); - //to maintain compatibility with the previous version, we write the angle in degrees. - xml_element.setAttribute("start", QString("%1").arg(m_start_angle / 16)); - xml_element.setAttribute("angle", QString("%1").arg(m_span_angle / 16)); - stylesToXml(xml_element); + + xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x())); + xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y())); + xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width())); + xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height())); + + //to maintain compatibility with the previous version, we write the angle in degrees. + xml_element.appendChild(createXmlProperty(xml_document, "start", m_start_angle / 16)); + xml_element.appendChild(createXmlProperty(xml_document, "angle", m_span_angle / 16)); + + + stylesToXml(xml_document, xml_element); return(xml_element); } @@ -115,14 +119,23 @@ const QDomElement PartArc::toXml(QDomDocument &xml_document) const { * @param qde : Xml document to use. */ void PartArc::fromXml(const QDomElement &qde) { - stylesFromXml(qde); - m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(), - qde.attribute("y", "0").toDouble()), - QSizeF(qde.attribute("width", "0").toDouble(), - qde.attribute("height", "0").toDouble()) ); + stylesFromXml(qde); - m_start_angle = qde.attribute("start", "0").toDouble() * 16; - m_span_angle = qde.attribute("angle", "-1440").toDouble() * 16; + double x = 0, y = 0, w = 0, h = 0; // default values + propertyDouble(qde, "x", &x); + propertyDouble(qde, "y", &y); + propertyDouble(qde, "width", &w); + propertyDouble(qde, "height", &h); + + m_rect = QRectF(mapFromScene(x, y), QSizeF(w, h) ); + + m_start_angle = 0; + propertyDouble(qde, "start", &m_start_angle); + m_start_angle *= 16; + + m_span_angle = -1440; + propertyDouble(qde, "angle", &m_span_angle); + m_span_angle *= 16; } /** diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index c6fbdcba4..226719010 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -82,20 +82,20 @@ const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const if (qFuzzyCompare(rect().width(), rect().height())) { xml_element = xml_document.createElement("circle"); - xml_element.setAttribute("diameter", QString("%1").arg(rect().width())); + xml_element.appendChild(createXmlProperty(xml_document, "diameter", rect().width())); } else { xml_element = xml_document.createElement("ellipse"); - xml_element.setAttribute("width", QString("%1").arg(rect().width())); - xml_element.setAttribute("height", QString("%1").arg(rect().height())); + xml_element.appendChild(createXmlProperty(xml_document, "width", rect().width())); + xml_element.appendChild(createXmlProperty(xml_document, "height", rect().height())); } QPointF top_left(sceneTopLeft()); - xml_element.setAttribute("x", QString("%1").arg(top_left.x())); - xml_element.setAttribute("y", QString("%1").arg(top_left.y())); + xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x())); + xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y())); - stylesToXml(xml_element); + stylesToXml(xml_document, xml_element); return(xml_element); } @@ -108,19 +108,23 @@ const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const void PartEllipse::fromXml(const QDomElement &qde) { stylesFromXml(qde); - qreal width, height; + double x = 0, y = 0, width = 0, height = 0; if (qde.tagName() == "ellipse") { - width = qde.attribute("width", "0").toDouble(); - height = qde.attribute("height", "0").toDouble(); + propertyDouble(qde, "width", &width); + propertyDouble(qde, "height", &height); } - else - width = height = qde.attribute("diameter", "0").toDouble(); + else { + propertyDouble(qde, "diameter", &width); + height = width; + } - m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(), - qde.attribute("y", "0").toDouble()), - QSizeF(width, height)); + + propertyDouble(qde, "x", &x); + propertyDouble(qde, "y", &y); + + m_rect = QRectF(mapFromScene(x, y), QSizeF(width, height)); } /** diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index fc6d0746e..57d75900d 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -108,16 +108,18 @@ const QDomElement PartLine::toXml(QDomDocument &xml_document) const QPointF p2(sceneP2()); QDomElement xml_element = xml_document.createElement("line"); - xml_element.setAttribute("x1", QString("%1").arg(p1.x())); - xml_element.setAttribute("y1", QString("%1").arg(p1.y())); - xml_element.setAttribute("x2", QString("%1").arg(p2.x())); - xml_element.setAttribute("y2", QString("%1").arg(p2.y())); - xml_element.setAttribute("end1", Qet::endTypeToString(first_end)); - xml_element.setAttribute("length1", QString("%1").arg(first_length)); - xml_element.setAttribute("end2", Qet::endTypeToString(second_end)); - xml_element.setAttribute("length2", QString("%1").arg(second_length)); + + xml_element.appendChild(createXmlProperty(xml_document, "x1", p1.x())); + xml_element.appendChild(createXmlProperty(xml_document, "y1", p1.y())); + xml_element.appendChild(createXmlProperty(xml_document, "x2", p2.x())); + xml_element.appendChild(createXmlProperty(xml_document, "y2", p2.y())); + + xml_element.appendChild(createXmlProperty(xml_document, "end1", Qet::endTypeToString(first_end))); + xml_element.appendChild(createXmlProperty(xml_document, "length1", first_length)); + xml_element.appendChild(createXmlProperty(xml_document, "end2", Qet::endTypeToString(second_end))); + xml_element.appendChild(createXmlProperty(xml_document, "length2", second_length)); - stylesToXml(xml_element); + stylesToXml(xml_document, xml_element); return(xml_element); } @@ -128,15 +130,28 @@ const QDomElement PartLine::toXml(QDomDocument &xml_document) const */ void PartLine::fromXml(const QDomElement &qde) { stylesFromXml(qde); - m_line = QLineF(mapFromScene(qde.attribute("x1", "0").toDouble(), - qde.attribute("y1", "0").toDouble()), - mapFromScene(qde.attribute("x2", "0").toDouble(), - qde.attribute("y2", "0").toDouble())); - first_end = Qet::endTypeFromString(qde.attribute("end1")); - first_length = qde.attribute("length1", "1.5").toDouble(); - second_end = Qet::endTypeFromString(qde.attribute("end2")); - second_length = qde.attribute("length2", "1.5").toDouble(); + double x1 = 0, y1 = 0, x2 = 0, y2 = 0; + propertyDouble(qde, "x1", &x1); + propertyDouble(qde, "y1", &y1); + propertyDouble(qde, "x2", &x2); + propertyDouble(qde, "y2", &y2); + + m_line = QLineF(mapFromScene(x1, y1), + mapFromScene(x2, y2)); + + QString s; + propertyString(qde, "end1", &s); + first_end = Qet::endTypeFromString(s); + + propertyString(qde, "end2", &s); + first_end = Qet::endTypeFromString(s); + + first_length = 1.5; + second_length = 1.5; + + propertyDouble(qde, "length1", &first_length); + propertyDouble(qde, "length2", &second_length); } /** diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index 4767337ca..2e518bf65 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -89,22 +89,24 @@ void PartPolygon::fromXml(const QDomElement &qde) int i = 1; while(true) { - if (QET::attributeIsAReal(qde, QString("x%1").arg(i)) &&\ - QET::attributeIsAReal(qde, QString("y%1").arg(i))) - ++ i; + if (propertyDouble(qde, QString("x%1").arg(i)) && + propertyDouble(qde, QString("y%1").arg(i))) + i++; else break; } QPolygonF temp_polygon; + double x, y; for (int j = 1 ; j < i ; ++ j) { - temp_polygon << QPointF(qde.attribute(QString("x%1").arg(j)).toDouble(), - qde.attribute(QString("y%1").arg(j)).toDouble()); + propertyDouble(qde, QString("x%1").arg(j), &x); + propertyDouble(qde, QString("y%1").arg(j), &y); + temp_polygon << QPointF(x, y); } m_polygon = temp_polygon; - m_closed = qde.attribute("closed") != "false"; + propertyBool(qde, "closed", &m_closed); } /** @@ -119,12 +121,14 @@ const QDomElement PartPolygon::toXml(QDomDocument &xml_document) const int i = 1; foreach(QPointF point, m_polygon) { point = mapToScene(point); - xml_element.setAttribute(QString("x%1").arg(i), QString("%1").arg(point.x())); - xml_element.setAttribute(QString("y%1").arg(i), QString("%1").arg(point.y())); + xml_element.appendChild(createXmlProperty(xml_document, QString("x%1").arg(i), point.x())); + xml_element.appendChild(createXmlProperty(xml_document, QString("y%1").arg(i), point.y())); ++ i; } - if (!m_closed) xml_element.setAttribute("closed", "false"); - stylesToXml(xml_element); + + xml_element.appendChild(createXmlProperty(xml_document, "closed", m_closed)); + + stylesToXml(xml_document, xml_element); return(xml_element); } diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index 5f17b7252..96ad18a1f 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -81,10 +81,11 @@ const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("rect"); QPointF top_left(sceneTopLeft()); - xml_element.setAttribute("x", QString("%1").arg(top_left.x())); - xml_element.setAttribute("y", QString("%1").arg(top_left.y())); - xml_element.setAttribute("width", QString("%1").arg(m_rect.width())); - xml_element.setAttribute("height", QString("%1").arg(m_rect.height())); + + xml_element.appendChild(createXmlProperty(xml_document, "x", top_left.x())); + xml_element.appendChild(createXmlProperty(xml_document, "y", top_left.y())); + xml_element.appendChild(createXmlProperty(xml_document, "width", m_rect.width())); + xml_element.appendChild(createXmlProperty(xml_document, "height", m_rect.height())); QRectF rect = m_rect.normalized(); qreal x = m_xRadius; @@ -98,8 +99,11 @@ const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const xml_element.setAttribute("rx", QString::number(m_xRadius)); xml_element.setAttribute("ry", QString::number(m_yRadius)); + + xml_element.appendChild(createXmlProperty(xml_document, "rx", m_xRadius)); + xml_element.appendChild(createXmlProperty(xml_document, "ry", m_yRadius)); - stylesToXml(xml_element); + stylesToXml(xml_document, xml_element); return(xml_element); } diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp index 9e1b9b5c6..e3dbf794a 100644 --- a/sources/editor/graphicspart/parttext.cpp +++ b/sources/editor/graphicspart/parttext.cpp @@ -59,28 +59,41 @@ void PartText::fromXml(const QDomElement &xml_element) { bool ok; - if (xml_element.hasAttribute("size")) + int size; + QString font; + + if (propertyInteger(xml_element, "size", &size) != PropertyFlags::NotFound) { - int font_size = xml_element.attribute("size").toInt(&ok); - if (!ok || font_size < 1) { - font_size = 20; + if (size < 1) { + size = 20; } QFont font_ = this->font(); - font_.setPointSize(font_size); + font_.setPointSize(size); setFont(font_); } - else if (xml_element.hasAttribute("font")) + else if (propertyString(xml_element, "font", &font) != PropertyFlags::NotFound) { QFont font_; - font_.fromString(xml_element.attribute("font")); + font_.fromString(font); setFont(font_); - } + } - setDefaultTextColor(QColor(xml_element.attribute("color", "#000000"))); - setPlainText(xml_element.attribute("text")); - setPos(xml_element.attribute("x").toDouble(), - xml_element.attribute("y").toDouble()); - setRotation(xml_element.attribute("rotation", QString::number(0)).toDouble()); + QString color; + QString text; + propertyString(xml_element, "color", &color, "#000000"); + setDefaultTextColor(QColor(color)); + + + propertyString(xml_element, "text", &text); + setPlainText(text); + + double x, y, rot; + propertyDouble(xml_element, "x", &x, 0); + propertyDouble(xml_element, "y", &y, 0); + setPos(x, y); + + propertyDouble(xml_element, "rotation", &rot, 0); + setRotation(rot); } /** @@ -92,12 +105,12 @@ const QDomElement PartText::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement(xmlName()); - xml_element.setAttribute("x", QString::number(pos().x())); - xml_element.setAttribute("y", QString::number(pos().y())); - xml_element.setAttribute("text", toPlainText()); - xml_element.setAttribute("font", font().toString()); - xml_element.setAttribute("rotation", QString::number(rotation())); - xml_element.setAttribute("color", defaultTextColor().name()); + xml_element.appendChild(createXmlProperty(xml_document, "x", pos().x())); + xml_element.appendChild(createXmlProperty(xml_document, "y", pos().y())); + xml_element.appendChild(createXmlProperty(xml_document, "text", toPlainText())); + xml_element.appendChild(createXmlProperty(xml_document, "font", font().toString())); + xml_element.appendChild(createXmlProperty(xml_document, "rotation", rotation())); + xml_element.appendChild(createXmlProperty(xml_document, "color", defaultTextColor().name())); return(xml_element); } diff --git a/sources/properties/propertiesinterface.cpp b/sources/properties/propertiesinterface.cpp index da7b042d4..9ffd197a5 100644 --- a/sources/properties/propertiesinterface.cpp +++ b/sources/properties/propertiesinterface.cpp @@ -17,6 +17,224 @@ */ #include "propertiesinterface.h" +/*! + * Available property types + */ +namespace { + const QString integerS = "int"; + const QString doubleS = "double"; + const QString boolS = "bool"; + const QString stringS = "string"; +} + PropertiesInterface::PropertiesInterface() { } + +QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const QString value) const { + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", stringS); + p.setAttribute("value", value); + return p; +} + +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const int value) const { + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", integerS); + p.setAttribute("value", value); + return p; +} + +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const double value) const { + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", doubleS); + p.setAttribute("value", value); + return p; +} + +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const { + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", boolS); + p.setAttribute("value", value); + 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)) + return QDomElement(); + + if (child.attribute("name") == name) + return child; + } + return QDomElement(); +} + +/*! + * \brief PropertiesInterface::attribute + * Returns the property with the name \p attribute_name + * \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)) + return false; + + *attr = e.attribute(attribute_name); + + } else { + if (p.attribute("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, int defaultValue) { + + QString attr; + + if (!attribute(e, attribute_name, integerS, &attr)) { + *entier = defaultValue; + return PropertyFlags::NotFound; + } + + // verifie la validite de l'attribut + bool ok; + int tmp = attr.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, double defaultValue) { + + QString attr; + + if (!attribute(e, attribute_name, doubleS, &attr)) { + *reel = defaultValue; + return PropertyFlags::NotFound; + } + + // verifie la validite de l'attribut + bool ok; + double tmp = attr.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, bool defaulValue) { + + QString attr; + + if (!attribute(e, attribute_name, integerS, &attr)) { + *boolean = defaulValue; + return PropertyFlags::NotFound; + } + + // verifie la validite de l'attribut + bool ok; + bool tmp = attr.toInt(&ok); + if (!ok) + return PropertyFlags::NoValidConversion; + + if (boolean != nullptr) + *boolean = tmp; + + return PropertyFlags::Success; +} + +PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string, QString defaultValue) { + + QString attr; + if (!attribute(e, attribute_name, stringS, &attr)) { + *string = defaultValue; + 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; +} + +/** + Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w") + en orientation. Si la chaine fait plusieurs caracteres, seul le + premier est pris en compte. En cas d'incoherence, Qet::North est + retourne. + @param s Chaine de caractere cense representer une orientation + @return l'orientation designee par la chaine de caractere +*/ +Qet::Orientation PropertiesInterface::orientationFromString(const QString &s) { + QChar c = s[0]; + if (c == 'e') return(Qet::East); + else if (c == 's') return(Qet::South); + else if (c == 'w') return (Qet::West); + else return(Qet::North); +} + +/** + @param o une orientation + @return une chaine de caractere representant l'orientation +*/ +QString PropertiesInterface::orientationToString(Qet::Orientation o) { + QString ret; + switch(o) { + case Qet::North: ret = "n"; break; + case Qet::East : ret = "e"; break; + case Qet::South: ret = "s"; break; + case Qet::West : ret = "w"; break; + } + return(ret); +} diff --git a/sources/properties/propertiesinterface.h b/sources/properties/propertiesinterface.h index 0799ab69b..0c4bc5793 100644 --- a/sources/properties/propertiesinterface.h +++ b/sources/properties/propertiesinterface.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include "qet.h" /** * @brief The PropertiesInterface class @@ -36,6 +38,49 @@ class PropertiesInterface // Save/load properties to xml element virtual QDomElement toXml (QDomDocument &xml_document) const =0; virtual bool fromXml (const QDomElement &xml_element) =0; + virtual bool valideXml(QDomElement& element) const = 0; + + /*! + * Use this functions to add properties to the xml document + */ + QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QString value) const; + QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value) const; + QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value) const; + QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const; + + static QDomElement property(const QDomElement& e, const QString& name); + static bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); + + typedef enum PropertyFlags { + Success, + NotFound, + NoValidConversion, + }; + + static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, int defaultValue = std::numeric_limits::quiet_NaN()); + static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr, double defaultValue = std::numeric_limits::quiet_NaN()); + static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr, QString defaultValue = QString()); + static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool defaulValue = false); + + static bool validXmlProperty(const QDomElement& e); + + QVariant XmlProperty(const QDomElement& element); + + /** + Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w") + en orientation. Si la chaine fait plusieurs caracteres, seul le + premier est pris en compte. En cas d'incoherence, Qet::North est + retourne. + @param s Chaine de caractere cense representer une orientation + @return l'orientation designee par la chaine de caractere + */ + static Qet::Orientation orientationFromString(const QString &s); + + /** + @param o une orientation + @return une chaine de caractere representant l'orientation + */ + static QString orientationToString(Qet::Orientation o); }; #endif // PROPERTIESINTERFACE_H diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 27bf607f2..2aefb0710 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -43,17 +43,11 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("terminal"); - // ecrit la position de la borne - xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x())); - xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y())); - - - xml_element.setAttribute("uuid", m_uuid.toString()); - xml_element.setAttribute("name", m_name); - - // ecrit l'orientation de la borne - xml_element.setAttribute("orientation", Qet::orientationToString(m_orientation)); - // Write name and number to XML + xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x())); + xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y())); + xml_element.appendChild(createXmlProperty(xml_document, "uuid", m_uuid.toString())); + xml_element.appendChild(createXmlProperty(xml_document, "name", m_name)); + xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation))); return(xml_element); } @@ -61,27 +55,40 @@ bool TerminalData::fromXml (const QDomElement &xml_element) { // lit la position de la borne qreal term_x = 0.0, term_y = 0.0; - if (!QET::attributeIsAReal(xml_element, "x", &term_x)) + + if (!propertyDouble(xml_element, "x", &term_x)) return false; - if (!QET::attributeIsAReal(xml_element, "y", &term_y)) + if (!propertyDouble(xml_element, "y", &term_y)) return false; m_pos = QPointF(term_x, term_y); //emit posFromXML(QPointF(term_x, term_y)); - QString uuid = xml_element.attribute("uuid"); + QString uuid; + if (!propertyString(xml_element, "uuid", &uuid)) + return false; + // 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 if (!uuid.isEmpty()) m_uuid = QUuid(uuid); - m_name = xml_element.attribute("name"); + if (!propertyString(xml_element, "name", &m_name)) + return false; + + QString o; + if (!propertyString(xml_element, "orientation", &o)) + return false; // lit l'orientation de la borne - m_orientation = Qet::orientationFromString(xml_element.attribute("orientation")); + m_orientation = orientationFromString(o); return true; } + +bool TerminalData::valideXml(QDomElement& element) const { + return true; +} diff --git a/sources/properties/terminaldata.h b/sources/properties/terminaldata.h index c31e73929..4d5301cda 100644 --- a/sources/properties/terminaldata.h +++ b/sources/properties/terminaldata.h @@ -35,6 +35,24 @@ public: QDomElement toXml(QDomDocument &xml_element) const override; bool fromXml(const QDomElement &xml_element) override; + bool valideXml(QDomElement &element) const override; + + /** + Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w") + en orientation. Si la chaine fait plusieurs caracteres, seul le + premier est pris en compte. En cas d'incoherence, Qet::North est + retourne. + @param s Chaine de caractere cense representer une orientation + @return l'orientation designee par la chaine de caractere + */ + static Qet::Orientation orientationFromString(const QString &s); + + /** + @param o une orientation + @return une chaine de caractere representant l'orientation + */ + static QString orientationToString(Qet::Orientation o); + // must be public, because this class is a private member of PartTerminal/Terminal and they must // access this data public: diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index 538549761..360ad9b5f 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -96,27 +96,21 @@ void XRefProperties::fromSettings(const QSettings &settings, const QString prefi QDomElement XRefProperties::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("xref"); - xml_element.setAttribute("type", m_key); - xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "false"); - QString display = m_display == Cross? "cross" : "contacts"; - xml_element.setAttribute("displayhas", display); - QString snap = m_snap_to == Bottom? "bottom" : "label"; - xml_element.setAttribute("snapto", snap); + xml_element.appendChild(createXmlProperty(xml_document, "type", m_key)); + xml_element.appendChild(createXmlProperty(xml_document, "showpowerctc", m_show_power_ctc)); + xml_element.appendChild(createXmlProperty(xml_document, "displayhas", m_display == Cross? "cross" : "contacts")); + xml_element.appendChild(createXmlProperty(xml_document, "snapto", m_snap_to == Bottom? "bottom" : "label")); - QString xrefpos; - - QMetaEnum var = QMetaEnum::fromType(); - xml_element.setAttribute("xrefpos", var.valueToKey(m_xref_pos)); - int offset = m_offset; - xml_element.setAttribute("offset", QString::number(offset)); - QString master_label = m_master_label; - xml_element.setAttribute("master_label", master_label); - QString slave_label = m_slave_label; - xml_element.setAttribute("slave_label", slave_label); + QMetaEnum var = QMetaEnum::fromType(); + xml_element.appendChild(createXmlProperty(xml_document, "xrefpos", var.valueToKey(m_xref_pos))); + xml_element.appendChild(createXmlProperty(xml_document, "offset", m_offset)); + xml_element.appendChild(createXmlProperty(xml_document, "master_label", m_master_label)); + xml_element.appendChild(createXmlProperty(xml_document, "slave_label", m_slave_label)); + foreach (QString key, m_prefix.keys()) { - xml_element.setAttribute(key + "prefix", m_prefix.value(key)); + xml_element.appendChild(createXmlProperty(xml_document, key + "prefix", m_prefix.value(key))); } return xml_element; @@ -128,30 +122,42 @@ QDomElement XRefProperties::toXml(QDomDocument &xml_document) const { * @param xml_element: QDomElement to use for load */ bool XRefProperties::fromXml(const QDomElement &xml_element) { - m_show_power_ctc = xml_element.attribute("showpowerctc") == "true"; - QString display = xml_element.attribute("displayhas", "cross"); + + if (!propertyBool(xml_element, "showpowerctc", &m_show_power_ctc)) + return false; + + QString display; + propertyString(xml_element, "displayhas", &display, "cross"); display == "cross"? m_display = Cross : m_display = Contacts; - QString snap = xml_element.attribute("snapto", "label"); + + + QString snap; + propertyString(xml_element, "snapto", &snap, "label"); snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label; - QString xrefpos = xml_element.attribute("xrefpos","Left"); + QString xrefpos; + if (propertyString(xml_element, "xrefpos", &xrefpos, "Left") == PropertyFlags::NotFound) { + QMetaEnum var = QMetaEnum::fromType(); + m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xrefpos.toStdString().data())); + } else + m_xref_pos = Qt::AlignBottom; - QMetaEnum var = QMetaEnum::fromType(); - - if(xml_element.hasAttribute("xrefpos")) - m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xml_element.attribute("xrefpos").toStdString().data())); - else - m_xref_pos = Qt::AlignBottom; - - m_offset = xml_element.attribute("offset", "0").toInt(); - m_master_label = xml_element.attribute("master_label", "%f-%l%c"); - m_slave_label = xml_element.attribute("slave_label","(%f-%l%c)"); + propertyInteger(xml_element, "offset", &m_offset, 0); + propertyString(xml_element, "master_label", &m_master_label, "%f-%l%c"); + propertyString(xml_element, "slave_label", &m_slave_label, "(%f-%l%c)"); + QString value; foreach (QString key, m_prefix_keys) { - m_prefix.insert(key, xml_element.attribute(key + "prefix")); + propertyString(xml_element, key + "prefix", &value); + m_prefix.insert(key, value); } return true; } +bool XRefProperties::valideXml(QDomElement& element) const { + // TODO: implement + return true; +} + /** * @brief XRefProperties::defaultProperties * @return the default properties stored in the setting file diff --git a/sources/properties/xrefproperties.h b/sources/properties/xrefproperties.h index dc03196cf..e10ee872a 100644 --- a/sources/properties/xrefproperties.h +++ b/sources/properties/xrefproperties.h @@ -44,6 +44,7 @@ class XRefProperties : public PropertiesInterface void fromSettings (const QSettings &settings, const QString = QString()) override; QDomElement toXml (QDomDocument &xml_document) const override; bool fromXml(const QDomElement &xml_element) override; + bool valideXml(QDomElement& element) const override; static QHash defaultProperties(); diff --git a/sources/qet.cpp b/sources/qet.cpp index 928ccda86..c2702e7bf 100644 --- a/sources/qet.cpp +++ b/sources/qet.cpp @@ -25,37 +25,6 @@ #include #include -/** - Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w") - en orientation. Si la chaine fait plusieurs caracteres, seul le - premier est pris en compte. En cas d'incoherence, Qet::North est - retourne. - @param s Chaine de caractere cense representer une orientation - @return l'orientation designee par la chaine de caractere -*/ -Qet::Orientation Qet::orientationFromString(const QString &s) { - QChar c = s[0]; - if (c == 'e') return(Qet::East); - else if (c == 's') return(Qet::South); - else if (c == 'w') return (Qet::West); - else return(Qet::North); -} - -/** - @param o une orientation - @return une chaine de caractere representant l'orientation -*/ -QString Qet::orientationToString(Qet::Orientation o) { - QString ret; - switch(o) { - case Qet::North: ret = "n"; break; - case Qet::East : ret = "e"; break; - case Qet::South: ret = "s"; break; - case Qet::West : ret = "w"; break; - } - return(ret); -} - /** Indique si deux orientations de Borne sont sur le meme axe (Vertical / Horizontal). @param a La premiere orientation de Borne diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 1f32441b6..f2f13dfe6 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -719,15 +719,13 @@ QList Terminal::conductors() const { QDomElement Terminal::toXml(QDomDocument &doc) const { QDomElement qdo = doc.createElement("terminal"); - // for backward compatibility - qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x())); - qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y())); - // end for backward compatibility + qdo.appendChild(createXmlProperty(doc, "x", dock_elmt_.x())); + qdo.appendChild(createXmlProperty(doc, "y", dock_elmt_.y())); + qdo.appendChild(createXmlProperty(doc, "orientation", orientationToString(d->m_orientation))); + qdo.appendChild(createXmlProperty(doc, "number", number_terminal_)); + qdo.appendChild(createXmlProperty(doc, "name", name_terminal_)); + qdo.appendChild(createXmlProperty(doc, "nameHidden", name_terminal_hidden)); - qdo.setAttribute("orientation", d->m_orientation); - qdo.setAttribute("number", number_terminal_); - qdo.setAttribute("name", name_terminal_); - qdo.setAttribute("nameHidden", name_terminal_hidden); return(qdo); } @@ -737,38 +735,36 @@ QDomElement Terminal::toXml(QDomDocument &doc) const { @param terminal Le QDomElement a analyser @return true si le QDomElement passe en parametre est une borne, false sinon */ -bool Terminal::valideXml(QDomElement &terminal) { - // verifie le nom du tag +bool Terminal::valideXml(QDomElement &terminal) const { if (terminal.tagName() != "terminal") return(false); + + if (!propertyString(terminal, "number", nullptr)) + return false; + + if (!propertyString(terminal, "name", nullptr)) + return false; + + if (!propertyBool(terminal, "nameHidden", nullptr)) + return false; + + if (!propertyDouble(terminal, "x", nullptr)) + return false; + if (!propertyDouble(terminal, "y", nullptr)) + return false; + + QString o; + if (!propertyString(terminal, "orientation", &o)) + return false; + + Qet::Orientation terminal_or = orientationFromString(o); + if (terminal_or != Qet::North + && terminal_or != Qet::South + && terminal_or != Qet::East + && terminal_or != Qet::West) + return false; - // verifie la presence des attributs minimaux - if (!terminal.hasAttribute("x")) return(false); - if (!terminal.hasAttribute("y")) return(false); - if (!terminal.hasAttribute("orientation")) return(false); - - bool conv_ok; - // parse l'abscisse - terminal.attribute("x").toDouble(&conv_ok); - if (!conv_ok) return(false); - - // parse l'ordonnee - terminal.attribute("y").toDouble(&conv_ok); - if (!conv_ok) return(false); - - // parse l'id - terminal.attribute("id").toInt(&conv_ok); - if (!conv_ok) return(false); - - // parse l'orientation - int terminal_or = terminal.attribute("orientation").toInt(&conv_ok); - if (!conv_ok) return(false); - if (terminal_or != Qet::North - && terminal_or != Qet::South - && terminal_or != Qet::East - && terminal_or != Qet::West) return(false); - - // a ce stade, la borne est syntaxiquement correcte - return(true); + // a ce stade, la borne est syntaxiquement correcte + return true; } /** @@ -779,15 +775,30 @@ bool Terminal::valideXml(QDomElement &terminal) { @return true si la borne "se reconnait" (memes coordonnes, meme orientation), false sinon */ -bool Terminal::fromXml(QDomElement &terminal) { - number_terminal_ = terminal.attribute("number"); - name_terminal_ = terminal.attribute("name"); - name_terminal_hidden = terminal.attribute("nameHidden").toInt(); +bool Terminal::fromXml(const QDomElement &terminal) { + if (!propertyString(terminal, "number", &number_terminal_)) + return false; - return ( - qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) && - qFuzzyCompare(terminal.attribute("y").toDouble(), dock_elmt_.y()) && - (terminal.attribute("orientation").toInt() == d->m_orientation) + if (!propertyString(terminal, "name", &name_terminal_)) + return false; + + if (!propertyBool(terminal, "nameHidden", &name_terminal_hidden)) + return false; + + double x, y; + if (!propertyDouble(terminal, "x", &x)) + return false; + if (!propertyDouble(terminal, "y", &y)) + return false; + + QString o; + if (!propertyString(terminal, "orientation", &o)) + return false; + + return ( + qFuzzyCompare(x, dock_elmt_.x()) && + qFuzzyCompare(y, dock_elmt_.y()) && + (orientationFromString(o) == d->m_orientation) ); } diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index 17e9d7833..b33fdcae9 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -20,6 +20,8 @@ #include #include #include "qet.h" +#include "propertiesinterface.h" + class Conductor; class Diagram; class Element; @@ -31,7 +33,7 @@ class TerminalData; plug point for conductors. This class handles all mouse events for connecting conductors */ -class Terminal : public QGraphicsObject +class Terminal : public QGraphicsObject, public PropertiesInterface { Q_OBJECT @@ -88,9 +90,9 @@ class Terminal : public QGraphicsObject bool canBeLinkedTo(Terminal *); // methods related to XML import/export - static bool valideXml(QDomElement &); - bool fromXml (QDomElement &); - QDomElement toXml (QDomDocument &) const; + bool valideXml(QDomElement &) const override; + bool fromXml (const QDomElement &) override; + QDomElement toXml (QDomDocument &) const override; protected: // methods related to events management From a10709157da3aedf167f24cdb4af5a9bb28ce103 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Mon, 24 Aug 2020 20:34:18 +0200 Subject: [PATCH 02/34] update --- sources/borderproperties.cpp | 49 +++++++++---- sources/borderproperties.h | 13 ++-- sources/conductorproperties.cpp | 4 +- sources/conductorproperties.h | 22 +++--- sources/editor/graphicspart/partarc.cpp | 21 +++--- sources/editor/graphicspart/partarc.h | 4 +- .../graphicspart/partdynamictextfield.cpp | 71 +++++++++++-------- .../graphicspart/partdynamictextfield.h | 4 +- sources/editor/graphicspart/partellipse.cpp | 21 +++--- sources/editor/graphicspart/partellipse.h | 4 +- sources/editor/graphicspart/partline.cpp | 27 ++++--- sources/editor/graphicspart/partline.h | 4 +- sources/editor/graphicspart/partpolygon.cpp | 20 ++++-- sources/editor/graphicspart/partpolygon.h | 4 +- sources/editor/graphicspart/partrectangle.cpp | 31 +++++--- sources/editor/graphicspart/partrectangle.h | 4 +- sources/editor/graphicspart/partterminal.cpp | 10 ++- sources/editor/graphicspart/partterminal.h | 4 +- sources/editor/graphicspart/parttext.cpp | 18 +++-- sources/editor/graphicspart/parttext.h | 4 +- sources/properties/propertiesinterface.cpp | 29 +++++++- sources/properties/propertiesinterface.h | 11 +-- sources/properties/xrefproperties.cpp | 4 +- sources/properties/xrefproperties.h | 4 +- sources/qetproject.cpp | 12 +--- sources/titleblockproperties.cpp | 36 ++++++---- sources/titleblockproperties.h | 8 ++- 27 files changed, 276 insertions(+), 167 deletions(-) diff --git a/sources/borderproperties.cpp b/sources/borderproperties.cpp index 1522d89f9..8c87933b7 100644 --- a/sources/borderproperties.cpp +++ b/sources/borderproperties.cpp @@ -94,13 +94,17 @@ bool BorderProperties::operator!=(const BorderProperties &bp) { - XML element to which attributes will be added - Element XML auquel seront ajoutes des attributs */ -void BorderProperties::toXml(QDomElement &e) const { - e.setAttribute("cols", columns_count); - e.setAttribute("colsize", QString("%1").arg(columns_width)); - e.setAttribute("rows", rows_count); - e.setAttribute("rowsize", QString("%1").arg(rows_height)); - e.setAttribute("displaycols", display_columns ? "true" : "false"); - e.setAttribute("displayrows", display_rows ? "true" : "false"); +QDomElement BorderProperties::toXml(QDomDocument &dom_doc) const { + + QDomElement e = dom_doc.createElement("border"); + + e.appendChild(createXmlProperty(dom_doc, "cols", columns_count)); + e.appendChild(createXmlProperty(dom_doc, "colsize", columns_width)); + e.appendChild(createXmlProperty(dom_doc, "rows", rows_count)); + e.appendChild(createXmlProperty(dom_doc, "rowsize", rows_height)); + e.appendChild(createXmlProperty(dom_doc, "displayrows", display_rows)); + + return e; } /** @@ -111,13 +115,28 @@ void BorderProperties::toXml(QDomElement &e) const { - XML element whose attributes will be read - Element XML dont les attributs seront lus */ -void BorderProperties::fromXml(QDomElement &e) { - if (e.hasAttribute("cols")) columns_count = e.attribute("cols").toInt(); - if (e.hasAttribute("colsize")) columns_width = e.attribute("colsize").toInt(); - if (e.hasAttribute("rows")) rows_count = e.attribute("rows").toInt(); - if (e.hasAttribute("rowsize")) rows_height = e.attribute("rowsize").toInt(); - if (e.hasAttribute("displaycols")) display_columns = e.attribute("displaycols") == "true"; - if (e.hasAttribute("displayrows")) display_rows = e.attribute("displayrows") == "true"; +bool BorderProperties::fromXml(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) + return false; + + return true; +} + +bool BorderProperties::valideXml(QDomElement& e) const { + + 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) + return true; } /** @@ -151,7 +170,7 @@ void BorderProperties::toSettings(QSettings &settings, const QString &prefix) co - prefix to be added before the names of the parameters - prefixe a ajouter devant les noms des parametres */ -void BorderProperties::fromSettings(QSettings &settings, const QString &prefix) { +void BorderProperties::fromSettings(const QSettings &settings, const QString &prefix) { columns_count = settings.value(prefix + "cols", columns_count).toInt(); columns_width = qRound(settings.value(prefix + "colsize", columns_width).toDouble()); display_columns = settings.value(prefix + "displaycols", display_columns).toBool(); diff --git a/sources/borderproperties.h b/sources/borderproperties.h index 74df1e8bb..93d72c78b 100644 --- a/sources/borderproperties.h +++ b/sources/borderproperties.h @@ -20,13 +20,15 @@ #include #include +#include "propertiesinterface.h" + /** @brief The BorderProperties class This class is a container for dimensions and display properties of a diagram. @remark Attributes are public */ -class BorderProperties { +class BorderProperties : public PropertiesInterface { public: // constructor, destructor, operators BorderProperties(); @@ -35,10 +37,11 @@ class BorderProperties { bool operator==(const BorderProperties &); bool operator!=(const BorderProperties &); - void toXml(QDomElement &) const; - void fromXml(QDomElement &); - void toSettings(QSettings &, const QString & = QString()) const; - void fromSettings(QSettings &, const QString & = QString()); + QDomElement toXml(QDomDocument &dom_doc) const override; + bool fromXml(const QDomElement &) override; + bool valideXml(QDomElement& e) const override; + void toSettings(QSettings &, const QString & = QString()) const override; + void fromSettings(const QSettings &, const QString & = QString()) override; static BorderProperties defaultProperties(); diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 1a5b05dab..76f401c20 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -245,8 +245,10 @@ ConductorProperties::~ConductorProperties() { * Export conductor propertie, in the XML element 'e' * @param e the xml element */ -void ConductorProperties::toXml(QDomElement &e) const +void ConductorProperties::toXml(QDomDocument& doc) const { + + QDomElement conductor_elmt = xml_document.createElement("conductors"); e.setAttribute("type", typeToString(type)); if (color != QColor(Qt::black)) diff --git a/sources/conductorproperties.h b/sources/conductorproperties.h index 3356228ea..396933f0b 100644 --- a/sources/conductorproperties.h +++ b/sources/conductorproperties.h @@ -22,12 +22,14 @@ #include #include +#include "propertiesinterface.h" + class QPainter; /** This class represents the properties of a singleline conductor. */ -class SingleLineProperties { +class SingleLineProperties: public PropertiesInterface { public: SingleLineProperties(); virtual ~SingleLineProperties(); @@ -36,10 +38,10 @@ class SingleLineProperties { unsigned short int phasesCount(); bool isPen() const; void draw(QPainter *, QET::ConductorSegmentType, const QRectF &); - void toXml(QDomElement &) const; - void fromXml(QDomElement &); - void toSettings(QSettings &, const QString & = QString()) const; - void fromSettings(QSettings &, const QString & = QString()); + void toXml(QDomElement &) const override; + void fromXml(QDomElement &) override; + void toSettings(QSettings &, const QString & = QString()) const override; + void fromSettings(QSettings &, const QString & = QString()) override; /// Whether the singleline conductor should display the ground symbol bool hasGround; @@ -62,7 +64,7 @@ class SingleLineProperties { This class represents the functional properties of a particular conductor, i.e. properties other than path and terminals. */ -class ConductorProperties +class ConductorProperties: public PropertiesInterface { public: ConductorProperties(); @@ -109,10 +111,10 @@ class ConductorProperties SingleLineProperties singleLineProperties; // methods - void toXml(QDomElement &) const; - void fromXml(QDomElement &); - void toSettings(QSettings &, const QString & = QString()) const; - void fromSettings(QSettings &, const QString & = QString()); + void toXml(QDomDocument &doc) const override; + void fromXml(QDomElement &) override; + void toSettings(QSettings &, const QString & = QString()) const override; + void fromSettings(QSettings &, const QString & = QString()) override; static QString typeToString(ConductorType); void applyForEqualAttributes(QList list); diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index c9e526087..b5ac5cbe7 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -95,7 +95,7 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, * @param xml_document : Xml document to use for create the xml element. * @return : an xml element that describe this arc */ -const QDomElement PartArc::toXml(QDomDocument &xml_document) const { +QDomElement PartArc::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("arc"); QPointF top_left(sceneTopLeft()); @@ -118,23 +118,26 @@ const QDomElement PartArc::toXml(QDomDocument &xml_document) const { * Import the properties of this arc from a xml element. * @param qde : Xml document to use. */ -void PartArc::fromXml(const QDomElement &qde) { +bool PartArc::fromXml(const QDomElement &qde) { stylesFromXml(qde); - double x = 0, y = 0, w = 0, h = 0; // default values - propertyDouble(qde, "x", &x); - propertyDouble(qde, "y", &y); - propertyDouble(qde, "width", &w); - propertyDouble(qde, "height", &h); + double x, y, w, h; + if (propertyDouble(qde, "x", &x, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "y", &y, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "width", &w, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "height", &h, 0) == PropertyFlags::NoValidConversion) + return false; m_rect = QRectF(mapFromScene(x, y), QSizeF(w, h) ); m_start_angle = 0; - propertyDouble(qde, "start", &m_start_angle); + if (propertyDouble(qde, "start", &m_start_angle) == PropertyFlags::NoValidConversion) + return false; m_start_angle *= 16; m_span_angle = -1440; - propertyDouble(qde, "angle", &m_span_angle); + if (propertyDouble(qde, "angle", &m_span_angle) == PropertyFlags::NoValidConversion) + return false; m_span_angle *= 16; } diff --git a/sources/editor/graphicspart/partarc.h b/sources/editor/graphicspart/partarc.h index b0c8a8816..736a8c9de 100644 --- a/sources/editor/graphicspart/partarc.h +++ b/sources/editor/graphicspart/partarc.h @@ -51,8 +51,8 @@ class PartArc : public AbstractPartEllipse //Name and XML QString name() const override { return(QObject::tr("arc", "element part name")); } QString xmlName() const override { return(QString("arc")); } - const QDomElement toXml (QDomDocument &) const override; - void fromXml (const QDomElement &) override; + QDomElement toXml (QDomDocument &) const override; + bool fromXml (const QDomElement &) override; QPainterPath shape() const override; QPainterPath shadowShape() const override; diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp index a9f368ca9..2d09dcb5f 100644 --- a/sources/editor/graphicspart/partdynamictextfield.cpp +++ b/sources/editor/graphicspart/partdynamictextfield.cpp @@ -85,37 +85,38 @@ void PartDynamicTextField::handleUserTransformation(const QRectF &initial_select * @param document * @return */ -const QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const +QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const { QDomElement root_element = dom_doc.createElement(xmlName()); - - root_element.setAttribute("x", QString::number(pos().x())); - root_element.setAttribute("y", QString::number(pos().y())); - root_element.setAttribute("z", QString::number(zValue())); - root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation()))); - root_element.setAttribute("font", font().toString()); - root_element.setAttribute("uuid", m_uuid.toString()); - root_element.setAttribute("frame", m_frame? "true" : "false"); - root_element.setAttribute("text_width", QString::number(m_text_width)); + + root_element.appendChild(createXmlProperty(dom_doc, "x", pos().x())); + root_element.appendChild(createXmlProperty(dom_doc, "y", pos().y())); + root_element.appendChild(createXmlProperty(dom_doc, "z", zValue())); + root_element.appendChild(createXmlProperty(dom_doc, "rotation", QET::correctAngle(rotation()))); + + root_element.appendChild(createXmlProperty(dom_doc, "font", font().toString())); + root_element.appendChild(createXmlProperty(dom_doc, "uuid", m_uuid)); + root_element.appendChild(createXmlProperty(dom_doc, "frame", m_frame)); + root_element.appendChild(createXmlProperty(dom_doc, "text_width", m_text_width)); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); - root_element.setAttribute("text_from", me.valueToKey(m_text_from)); + root_element.appendChild(createXmlProperty(dom_doc, "text_from", me.valueToKey(m_text_from))); me = QMetaEnum::fromType(); if(this->alignment() &Qt::AlignRight) - root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight)); + root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignRight))); else if(this->alignment() &Qt::AlignLeft) - root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft)); + root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignLeft))); else if(this->alignment() &Qt::AlignHCenter) - root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter)); + root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignHCenter))); if(this->alignment() &Qt::AlignBottom) - root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignBottom)); + root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignBottom))); else if(this->alignment() & Qt::AlignTop) - root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop)); + root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignTop))); else if(this->alignment() &Qt::AlignVCenter) - root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter)); + root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignVCenter))); QDomElement dom_text = dom_doc.createElement("text"); dom_text.appendChild(dom_doc.createTextNode(toPlainText())); @@ -152,27 +153,36 @@ const QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const * @brief PartDynamicTextField::fromXml * @param element */ -void PartDynamicTextField::fromXml(const QDomElement &dom_elmt) +bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt) { if (dom_elmt.tagName() != xmlName()) { qDebug() << "PartDynamicTextField::fromXml : Wrong tagg name"; - return; + return false; } - - QGraphicsTextItem::setPos(dom_elmt.attribute("x", QString::number(0)).toDouble(), - dom_elmt.attribute("y", QString::number(0)).toDouble()); - setZValue(dom_elmt.attribute("z", QString::number(zValue())).toDouble()); - QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble()); - if (dom_elmt.hasAttribute("font")) + double x, y, z, rot; + + if (propertyDouble(dom_elmt, "x", &x, 0) == PropertyFlags::NoValidConversion || + propertyDouble(dom_elmt, "y", &y, 0) == PropertyFlags::NoValidConversion || + propertyDouble(dom_elmt, "z", &z, 0) == PropertyFlags::NoValidConversion || + propertyDouble(dom_elmt, "rotation", &rot, 0) == PropertyFlags::NoValidConversion) + return false; + + QGraphicsTextItem::setPos(x, y); + setZValue(z); + QGraphicsTextItem::setRotation(rot); + + QString font; + if (propertyString(dom_elmt, "font", &font) == PropertyFlags::Success) { QFont font_; - font_.fromString(dom_elmt.attribute("font")); + font_.fromString(font); setFont(font_); } else { //Keep compatibility TODO remove in futur setFont(QETApp::dynamicTextsItemFont(9)); } + propertyUuid(dom_elmt, "uuid", &m_uuid, QUuid::createUuid()); m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString())); setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false); setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble()); @@ -181,10 +191,11 @@ void PartDynamicTextField::fromXml(const QDomElement &dom_elmt) m_text_from = DynamicElementTextItem::TextFrom(me.keyToValue(dom_elmt.attribute("text_from").toStdString().data())); me = QMetaEnum::fromType(); - if(dom_elmt.hasAttribute("Halignment")) - setAlignment(Qt::Alignment(me.keyToValue(dom_elmt.attribute("Halignment").toStdString().data()))); - if(dom_elmt.hasAttribute(("Valignment"))) - setAlignment(Qt::Alignment(me.keyToValue(dom_elmt.attribute("Valignment").toStdString().data())) | this->alignment()); + QString alignment; + if(propertyString(dom_elmt, "Halignment", &alignment) != PropertyFlags::NotFound) + setAlignment(Qt::Alignment(me.keyToValue(alignment.toStdString().data()))); + if(propertyString(dom_elmt, "Valignment", &alignment) != PropertyFlags::NotFound) + setAlignment(Qt::Alignment(me.keyToValue(alignment.toStdString().data())) | this->alignment()); //Text QDomElement dom_text = dom_elmt.firstChildElement("text"); diff --git a/sources/editor/graphicspart/partdynamictextfield.h b/sources/editor/graphicspart/partdynamictextfield.h index e190afad8..aadfb5044 100644 --- a/sources/editor/graphicspart/partdynamictextfield.h +++ b/sources/editor/graphicspart/partdynamictextfield.h @@ -74,8 +74,8 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart void startUserTransformation(const QRectF &initial_selection_rect) override; void handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) override; - const QDomElement toXml(QDomDocument &dom_doc) const override; - void fromXml(const QDomElement &dom_elmt) override; + QDomElement toXml(QDomDocument &dom_doc) const override; + bool fromXml(const QDomElement &dom_elmt) override; void fromTextFieldXml(const QDomElement &dom_element); DynamicElementTextItem::TextFrom textFrom() const; diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index 226719010..50079eecb 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -76,7 +76,7 @@ void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio * @param xml_document : Xml document to use for create the xml element. * @return : an xml element that describe this ellipse */ -const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const +QDomElement PartEllipse::toXml(QDomDocument &xml_document) const { QDomElement xml_element; if (qFuzzyCompare(rect().width(), rect().height())) @@ -105,26 +105,31 @@ const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const * Import the properties of this ellipse from a xml element. * @param qde : Xml document to use. */ -void PartEllipse::fromXml(const QDomElement &qde) +bool PartEllipse::fromXml(const QDomElement &qde) { stylesFromXml(qde); - double x = 0, y = 0, width = 0, height = 0; + double x, y, width, height; if (qde.tagName() == "ellipse") { - propertyDouble(qde, "width", &width); - propertyDouble(qde, "height", &height); + if (propertyDouble(qde, "width", &width, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "height", &height, 0) == PropertyFlags::NoValidConversion) + return false; } else { - propertyDouble(qde, "diameter", &width); + if (propertyDouble(qde, "diameter", &width, 0) == PropertyFlags::NoValidConversion) + return false; height = width; } - propertyDouble(qde, "x", &x); - propertyDouble(qde, "y", &y); + if (propertyDouble(qde, "x", &x, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "y", &y, 0) == PropertyFlags::NoValidConversion) + return false; m_rect = QRectF(mapFromScene(x, y), QSizeF(width, height)); + + return true; } /** diff --git a/sources/editor/graphicspart/partellipse.h b/sources/editor/graphicspart/partellipse.h index b7f42dcf7..af2e822be 100644 --- a/sources/editor/graphicspart/partellipse.h +++ b/sources/editor/graphicspart/partellipse.h @@ -52,8 +52,8 @@ class PartEllipse : public AbstractPartEllipse //Name and XML QString name() const override { return(QObject::tr("ellipse", "element part name")); } QString xmlName() const override { return(QString("ellipse")); } - const QDomElement toXml (QDomDocument &) const override; - void fromXml (const QDomElement &) override; + QDomElement toXml (QDomDocument &) const override; + bool fromXml (const QDomElement &) override; QPainterPath shape() const override; QPainterPath shadowShape() const override; void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();} diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index 57d75900d..228b0b2c2 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -102,7 +102,7 @@ void PartLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *options, * @param xml_document : Xml document to use for create the xml element. * @return an xml element that describe this line */ -const QDomElement PartLine::toXml(QDomDocument &xml_document) const +QDomElement PartLine::toXml(QDomDocument &xml_document) const { QPointF p1(sceneP1()); QPointF p2(sceneP2()); @@ -128,30 +128,37 @@ const QDomElement PartLine::toXml(QDomDocument &xml_document) const * Import the properties of this line from a xml element. * @param qde : Xml document to use */ -void PartLine::fromXml(const QDomElement &qde) { +bool PartLine::fromXml(const QDomElement &qde) { stylesFromXml(qde); double x1 = 0, y1 = 0, x2 = 0, y2 = 0; - propertyDouble(qde, "x1", &x1); - propertyDouble(qde, "y1", &y1); - propertyDouble(qde, "x2", &x2); - propertyDouble(qde, "y2", &y2); + 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) + return false; m_line = QLineF(mapFromScene(x1, y1), mapFromScene(x2, y2)); QString s; - propertyString(qde, "end1", &s); + if (propertyString(qde, "end1", &s) != PropertyFlags::Success) + return false; first_end = Qet::endTypeFromString(s); - propertyString(qde, "end2", &s); + if (propertyString(qde, "end2", &s) != PropertyFlags::Success) + return false; + first_end = Qet::endTypeFromString(s); first_length = 1.5; second_length = 1.5; - propertyDouble(qde, "length1", &first_length); - propertyDouble(qde, "length2", &second_length); + if (propertyDouble(qde, "length1", &first_length) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "length2", &second_length) == PropertyFlags::NoValidConversion) + return false; + + return true; } /** diff --git a/sources/editor/graphicspart/partline.h b/sources/editor/graphicspart/partline.h index 9c2d858d7..96f0185fa 100644 --- a/sources/editor/graphicspart/partline.h +++ b/sources/editor/graphicspart/partline.h @@ -70,8 +70,8 @@ class PartLine : public CustomElementGraphicPart void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override; QString name() const override { return(QObject::tr("ligne", "element part name")); } QString xmlName() const override { return(QString("line")); } - const QDomElement toXml(QDomDocument &) const override; - void fromXml(const QDomElement &) override; + QDomElement toXml(QDomDocument &) const override; + bool fromXml(const QDomElement &) override; virtual QPointF sceneP1() const; virtual QPointF sceneP2() const; QPainterPath shape() const override; diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index 2e518bf65..a6558f461 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -82,15 +82,16 @@ void PartPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio * Import the properties of this polygon from a xml element * @param qde : Xml document to use */ -void PartPolygon::fromXml(const QDomElement &qde) +bool PartPolygon::fromXml(const QDomElement &qde) { stylesFromXml(qde); + int error_counter = 0; int i = 1; while(true) { - if (propertyDouble(qde, QString("x%1").arg(i)) && - propertyDouble(qde, QString("y%1").arg(i))) + if (propertyDouble(qde, QString("x%1").arg(i)) == PropertyFlags::Success && + propertyDouble(qde, QString("y%1").arg(i)) == PropertyFlags::Success) i++; else break; @@ -100,13 +101,18 @@ void PartPolygon::fromXml(const QDomElement &qde) double x, y; for (int j = 1 ; j < i ; ++ j) { - propertyDouble(qde, QString("x%1").arg(j), &x); - propertyDouble(qde, QString("y%1").arg(j), &y); + error_counter += propertyDouble(qde, QString("x%1").arg(j), &x); + error_counter += propertyDouble(qde, QString("y%1").arg(j), &y); + if (error_counter) + return false; temp_polygon << QPointF(x, y); } m_polygon = temp_polygon; - propertyBool(qde, "closed", &m_closed); + if (propertyBool(qde, "closed", &m_closed) != PropertyFlags::Success) + return false; + + return true; } /** @@ -115,7 +121,7 @@ void PartPolygon::fromXml(const QDomElement &qde) * @param xml_document : Xml document to use for create the xml element * @return an xml element that describe this polygon */ -const QDomElement PartPolygon::toXml(QDomDocument &xml_document) const +QDomElement PartPolygon::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("polygon"); int i = 1; diff --git a/sources/editor/graphicspart/partpolygon.h b/sources/editor/graphicspart/partpolygon.h index e10eadff1..d0fbb93ff 100644 --- a/sources/editor/graphicspart/partpolygon.h +++ b/sources/editor/graphicspart/partpolygon.h @@ -61,8 +61,8 @@ class PartPolygon : public CustomElementGraphicPart QString name() const override { return(QObject::tr("polygone", "element part name")); } QString xmlName() const override { return(QString("polygon")); } - void fromXml(const QDomElement &) override; - const QDomElement toXml(QDomDocument &) const override; + bool fromXml(const QDomElement &) override; + QDomElement toXml(QDomDocument &) const override; QPainterPath shape () const override; QPainterPath shadowShape() const override; diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index 96ad18a1f..708d52b3f 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -77,7 +77,7 @@ void PartRectangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt * @param xml_document : Xml document to use for create the xml element. * @return an xml element that describe this ellipse */ -const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const +QDomElement PartRectangle::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("rect"); QPointF top_left(sceneTopLeft()); @@ -112,18 +112,33 @@ const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const * Import the properties of this rectangle from a xml element. * @param qde : Xml document to use. */ -void PartRectangle::fromXml(const QDomElement &qde) +bool PartRectangle::fromXml(const QDomElement &qde) { stylesFromXml(qde); - setPos(mapFromScene(qde.attribute("x", "0").toDouble(), - qde.attribute("y", "0").toDouble())); - QRectF rect(QPointF(0,0), QSizeF(qde.attribute("width", "0").toDouble(), - qde.attribute("height", "0").toDouble())); + double x, y, w, h, rx, ry; + if (propertyDouble(qde, "x", &x, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "y", &y, 0) == PropertyFlags::NoValidConversion) + return false; + + setPos(mapFromScene(x, y)); + + if (propertyDouble(qde, "width", &w, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "width", &h, 0) == PropertyFlags::NoValidConversion) + return false; + + QRectF rect(QPointF(0,0), QSizeF(w, h)); setRect(rect.normalized()); - setXRadius(qde.attribute("rx", "0").toDouble()); - setYRadius(qde.attribute("ry", "0").toDouble()); + + if (propertyDouble(qde, "rx", &rx, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "ry", &ry, 0) == PropertyFlags::NoValidConversion) + return false; + + setXRadius(rx); + setYRadius(ry); + + return true; } /** diff --git a/sources/editor/graphicspart/partrectangle.h b/sources/editor/graphicspart/partrectangle.h index d6d7a6608..cc42de702 100644 --- a/sources/editor/graphicspart/partrectangle.h +++ b/sources/editor/graphicspart/partrectangle.h @@ -60,8 +60,8 @@ class PartRectangle : public CustomElementGraphicPart QString name () const override { return(QObject::tr("rectangle", "element part name")); } QString xmlName () const override { return(QString("rect")); } - const QDomElement toXml (QDomDocument &) const override; - void fromXml (const QDomElement &) override; + QDomElement toXml (QDomDocument &) const override; + bool fromXml (const QDomElement &) override; QRectF rect() const; void setRect(const QRectF &rect); diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 38924646e..92ade5134 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -42,10 +42,14 @@ PartTerminal::~PartTerminal() { Importe les proprietes d'une borne depuis un element XML @param xml_elmt Element XML a lire */ -void PartTerminal::fromXml(const QDomElement &xml_elmt) { - d->fromXml(xml_elmt); +bool PartTerminal::fromXml(const QDomElement &xml_elmt) { + if (!d->fromXml(xml_elmt)) + return false; + setPos(d->m_pos); updateSecondPoint(); + + return true; } /** @@ -53,7 +57,7 @@ void PartTerminal::fromXml(const QDomElement &xml_elmt) { @param xml_document Document XML a utiliser pour creer l'element XML @return un element XML decrivant la borne */ -const QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { +QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { return d->toXml(xml_document); } diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index a66aeb2fc..1c44b82eb 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -57,8 +57,8 @@ class PartTerminal : public CustomElementGraphicPart int type() const override { return Type; } QString name() const override { return d->m_name; } QString xmlName() const override { return(QString("terminal")); } - void fromXml(const QDomElement &) override; - const QDomElement toXml(QDomDocument &) const override; + bool fromXml(const QDomElement &) override; + QDomElement toXml(QDomDocument &) const override; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; QPainterPath shape() const override; diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp index e3dbf794a..369355151 100644 --- a/sources/editor/graphicspart/parttext.cpp +++ b/sources/editor/graphicspart/parttext.cpp @@ -55,10 +55,8 @@ PartText::~PartText() { Importe les proprietes d'un texte statique depuis un element XML @param xml_element Element XML a lire */ -void PartText::fromXml(const QDomElement &xml_element) +bool PartText::fromXml(const QDomElement &xml_element) { - bool ok; - int size; QString font; @@ -76,6 +74,8 @@ void PartText::fromXml(const QDomElement &xml_element) QFont font_; font_.fromString(font); setFont(font_); + } else { + return false; } QString color; @@ -88,12 +88,16 @@ void PartText::fromXml(const QDomElement &xml_element) setPlainText(text); double x, y, rot; - propertyDouble(xml_element, "x", &x, 0); - propertyDouble(xml_element, "y", &y, 0); + if (propertyDouble(xml_element, "x", &x, 0) == PropertyFlags::NoValidConversion || + propertyDouble(xml_element, "y", &y, 0) == PropertyFlags::NoValidConversion) + return false; setPos(x, y); - propertyDouble(xml_element, "rotation", &rot, 0); + if (propertyDouble(xml_element, "rotation", &rot, 0) == PropertyFlags::NoValidConversion) + return false; setRotation(rot); + + return true; } /** @@ -101,7 +105,7 @@ void PartText::fromXml(const QDomElement &xml_element) @param xml_document Document XML a utiliser pour creer l'element XML @return un element XML decrivant le texte statique */ -const QDomElement PartText::toXml(QDomDocument &xml_document) const +QDomElement PartText::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement(xmlName()); diff --git a/sources/editor/graphicspart/parttext.h b/sources/editor/graphicspart/parttext.h index 8945f618d..77a670d36 100644 --- a/sources/editor/graphicspart/parttext.h +++ b/sources/editor/graphicspart/parttext.h @@ -59,8 +59,8 @@ class PartText : public QGraphicsTextItem, public CustomElementPart int type() const override { return Type; } QString name() const override { return(QObject::tr("texte", "element part name")); } QString xmlName() const override { return(QString("text")); } - void fromXml(const QDomElement &) override; - const QDomElement toXml(QDomDocument &) const override; + bool fromXml(const QDomElement &) override; + QDomElement toXml(QDomDocument &) const override; void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));} bool isUseless() const override; QRectF sceneGeometricRect() const override; diff --git a/sources/properties/propertiesinterface.cpp b/sources/properties/propertiesinterface.cpp index 9ffd197a5..b4bd2bef8 100644 --- a/sources/properties/propertiesinterface.cpp +++ b/sources/properties/propertiesinterface.cpp @@ -25,6 +25,7 @@ namespace { const QString doubleS = "double"; const QString boolS = "bool"; const QString stringS = "string"; + const QString uuidS = "uuid"; } PropertiesInterface::PropertiesInterface() @@ -63,11 +64,19 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr return p; } +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) const { + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", uuidS); + p.setAttribute("value", value.toString()); + 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)) - return QDomElement(); + continue; // there might also non property childs if (child.attribute("name") == name) return child; @@ -155,12 +164,12 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDo return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean, bool defaulValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean, bool defaultValue) { QString attr; if (!attribute(e, attribute_name, integerS, &attr)) { - *boolean = defaulValue; + *boolean = defaultValue; return PropertyFlags::NotFound; } @@ -176,6 +185,20 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE return PropertyFlags::Success; } +PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid, QUuid defaultValue) { + QString attr; + + if (!attribute(e, attribute_name, uuidS, &attr)) { + *uuid = defaultValue; + return PropertyFlags::NotFound; + } + + if (uuid != nullptr) + *uuid = QUuid(attr); + + return PropertyFlags::Success; +} + PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string, QString defaultValue) { QString attr; diff --git a/sources/properties/propertiesinterface.h b/sources/properties/propertiesinterface.h index 0c4bc5793..ebd60e533 100644 --- a/sources/properties/propertiesinterface.h +++ b/sources/properties/propertiesinterface.h @@ -23,6 +23,7 @@ #include #include #include "qet.h" +#include /** * @brief The PropertiesInterface class @@ -33,8 +34,8 @@ class PropertiesInterface public: PropertiesInterface(); // Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre - virtual void toSettings (QSettings &settings, const QString = QString()) const =0; - virtual void fromSettings (const QSettings &settings, const QString = QString()) =0; + virtual void toSettings (QSettings &settings, const QString& = QString()) const =0; + virtual void fromSettings (const QSettings &settings, const QString& = QString()) =0; // Save/load properties to xml element virtual QDomElement toXml (QDomDocument &xml_document) const =0; virtual bool fromXml (const QDomElement &xml_element) =0; @@ -47,12 +48,13 @@ class PropertiesInterface QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const; + QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) const; static QDomElement property(const QDomElement& e, const QString& name); static bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); typedef enum PropertyFlags { - Success, + Success = 0, NotFound, NoValidConversion, }; @@ -60,7 +62,8 @@ class PropertiesInterface static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, int defaultValue = std::numeric_limits::quiet_NaN()); static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr, double defaultValue = std::numeric_limits::quiet_NaN()); static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr, QString defaultValue = QString()); - static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool defaulValue = false); + static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool defaultValue = false); + static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr, QUuid defaultValue = QUuid()); static bool validXmlProperty(const QDomElement& e); diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index 360ad9b5f..1992d920d 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -41,7 +41,7 @@ XRefProperties::XRefProperties() * @param settings: QSettings to use * @param prefix: prefix before properties name */ -void XRefProperties::toSettings(QSettings &settings, const QString prefix) const { +void XRefProperties::toSettings(QSettings &settings, const QString &prefix) const { settings.setValue(prefix + "showpowerctc", m_show_power_ctc); QString display = m_display == Cross? "cross" : "contacts"; settings.setValue(prefix + "displayhas", display); @@ -69,7 +69,7 @@ void XRefProperties::toSettings(QSettings &settings, const QString prefix) const * @param settings: QSettings to use * @param prefix: prefix before properties name */ -void XRefProperties::fromSettings(const QSettings &settings, const QString prefix) +void XRefProperties::fromSettings(const QSettings &settings, const QString &prefix) { m_show_power_ctc = settings.value(prefix + "showpowerctc", true).toBool(); QString display = settings.value(prefix + "displayhas", "cross").toString(); diff --git a/sources/properties/xrefproperties.h b/sources/properties/xrefproperties.h index e10ee872a..e154827bb 100644 --- a/sources/properties/xrefproperties.h +++ b/sources/properties/xrefproperties.h @@ -40,8 +40,8 @@ class XRefProperties : public PropertiesInterface Label }; - void toSettings (QSettings &settings, const QString = QString()) const override; - void fromSettings (const QSettings &settings, const QString = QString()) override; + void toSettings (QSettings &settings, const QString& = QString()) const override; + void fromSettings (const QSettings &settings, const QString& = QString()) override; QDomElement toXml (QDomDocument &xml_document) const override; bool fromXml(const QDomElement &xml_element) override; bool valideXml(QDomElement& element) const override; diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 1368c63d7..59d4bb5a6 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -1483,19 +1483,13 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) QDomDocument xml_document = xml_element.ownerDocument(); // export size of border - QDomElement border_elmt = xml_document.createElement("border"); - default_border_properties_.toXml(border_elmt); - xml_element.appendChild(border_elmt); + xml_element.appendChild(default_border_properties_.toXml(xml_document)); // export content of titleblock - QDomElement titleblock_elmt = xml_document.createElement("inset"); - default_titleblock_properties_.toXml(titleblock_elmt); - xml_element.appendChild(titleblock_elmt); + xml_element.appendChild(default_titleblock_properties_.toXml(xml_document)); // exporte default conductor - QDomElement conductor_elmt = xml_document.createElement("conductors"); - default_conductor_properties_.toXml(conductor_elmt); - xml_element.appendChild(conductor_elmt); + xml_element.appendChild(default_conductor_properties_.toXml(xml_document)); // export default report properties QDomElement report_elmt = xml_document.createElement("report"); diff --git a/sources/titleblockproperties.cpp b/sources/titleblockproperties.cpp index c645c3779..06a9a1e4a 100644 --- a/sources/titleblockproperties.cpp +++ b/sources/titleblockproperties.cpp @@ -73,22 +73,26 @@ bool TitleBlockProperties::operator!=(const TitleBlockProperties &ip) { Exporte le cartouche sous formes d'attributs XML ajoutes a l'element e. @param e Element XML auquel seront ajoutes des attributs */ -void TitleBlockProperties::toXml(QDomElement &e) const { - e.setAttribute("author", author); - e.setAttribute("title", title); - e.setAttribute("filename", filename); - e.setAttribute("plant", plant); - e.setAttribute("locmach", locmach); - e.setAttribute("indexrev",indexrev); - e.setAttribute("version", version); - e.setAttribute("folio", folio); - e.setAttribute("auto_page_num", auto_page_num); - e.setAttribute("date", exportDate()); - e.setAttribute("displayAt", (display_at == Qt::BottomEdge? "bottom" : "right")); +QDomElement TitleBlockProperties::toXml(QDomDocument &xml_document) const { + + QDomElement e = xml_document.createElement("inset"); + + e.appendChild(createXmlProperty(xml_document, "author", author)); + e.appendChild(createXmlProperty(xml_document, "title", title)); + e.appendChild(createXmlProperty(xml_document, "filename", filename)); + e.appendChild(createXmlProperty(xml_document, "plant", plant)); + e.appendChild(createXmlProperty(xml_document, "locmach", locmach)); + e.appendChild(createXmlProperty(xml_document, "indexrev", indexrev)); + e.appendChild(createXmlProperty(xml_document, "version", version)); + e.appendChild(createXmlProperty(xml_document, "folio", folio)); + e.appendChild(createXmlProperty(xml_document, "auto_page_num", auto_page_num)); + e.appendChild(createXmlProperty(xml_document, "date", exportDate())); + e.appendChild(createXmlProperty(xml_document, "displayAt", display_at == Qt::BottomEdge? "bottom" : "right")); + if (!template_name.isEmpty()) { - e.setAttribute("titleblocktemplate", template_name); - e.setAttribute("titleblocktemplateCollection", QET::qetCollectionToString(collection)); + e.appendChild(createXmlProperty(xml_document, "titleblocktemplate", template_name)); + e.appendChild(createXmlProperty(xml_document, "titleblocktemplateCollection", QET::qetCollectionToString(collection))); } if (context.keys().count()) { @@ -96,13 +100,15 @@ void TitleBlockProperties::toXml(QDomElement &e) const { context.toXml(properties); e.appendChild(properties); } + + return e; } /** Importe le cartouche a partir des attributs XML de l'element e @param e Element XML dont les attributs seront lus */ -void TitleBlockProperties::fromXml(const QDomElement &e) { +bool TitleBlockProperties::fromXml(const QDomElement &e) { // reads the historical fields if (e.hasAttribute("author")) author = e.attribute("author"); if (e.hasAttribute("title")) title = e.attribute("title"); diff --git a/sources/titleblockproperties.h b/sources/titleblockproperties.h index 7f9ebeb0e..480a0265f 100644 --- a/sources/titleblockproperties.h +++ b/sources/titleblockproperties.h @@ -21,12 +21,14 @@ #include "diagramcontext.h" #include "qet.h" +#include "propertiesinterface.h" + /** This class provides a container for the properties of a particular title block, i.e. title, author, date, filename, folio, template, custom properties, ... */ -class TitleBlockProperties { +class TitleBlockProperties: public PropertiesInterface { public: TitleBlockProperties(); virtual ~TitleBlockProperties(); @@ -39,8 +41,8 @@ class TitleBlockProperties { bool operator==(const TitleBlockProperties &); bool operator!=(const TitleBlockProperties &); - void toXml(QDomElement &) const; - void fromXml(const QDomElement &); + QDomElement toXml(QDomDocument &xml_document) const override; + bool fromXml(const QDomElement &) override; void toSettings(QSettings &, const QString & = QString()) const; void fromSettings(QSettings &, const QString & = QString()); From c5f17057458c2cc51bdab5b72bac869a1164b0fc Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Tue, 25 Aug 2020 20:14:38 +0200 Subject: [PATCH 03/34] go on with the work --- sources/borderproperties.cpp | 12 +- sources/borderproperties.h | 2 +- sources/bordertitleblock.cpp | 4 +- sources/bordertitleblock.h | 2 +- sources/conductorproperties.cpp | 193 +++++++++++------ sources/conductorproperties.h | 14 +- sources/diagram.cpp | 11 +- sources/diagram.h | 2 +- sources/diagramcontext.cpp | 10 +- sources/diagramcontext.h | 2 +- sources/editor/graphicspart/partarc.cpp | 12 ++ sources/editor/graphicspart/partarc.h | 1 + .../graphicspart/partdynamictextfield.cpp | 34 ++- .../graphicspart/partdynamictextfield.h | 1 + sources/editor/graphicspart/partellipse.cpp | 20 ++ sources/editor/graphicspart/partellipse.h | 1 + sources/editor/graphicspart/partline.cpp | 14 ++ sources/editor/graphicspart/partline.h | 1 + sources/editor/graphicspart/partpolygon.cpp | 5 + sources/editor/graphicspart/partpolygon.h | 2 + sources/editor/graphicspart/partrectangle.cpp | 12 ++ sources/editor/graphicspart/partrectangle.h | 1 + sources/editor/graphicspart/partterminal.cpp | 4 + sources/editor/graphicspart/partterminal.h | 2 + sources/editor/graphicspart/parttext.cpp | 24 +++ sources/editor/graphicspart/parttext.h | 1 + sources/properties/propertiesinterface.cpp | 42 +++- sources/properties/propertiesinterface.h | 15 +- sources/properties/terminaldata.cpp | 20 +- sources/properties/terminaldata.h | 22 +- sources/properties/xrefproperties.cpp | 5 - sources/properties/xrefproperties.h | 1 - sources/qetgraphicsitem/conductor.cpp | 199 ++++++++++-------- sources/qetgraphicsitem/conductor.h | 8 +- sources/qetgraphicsitem/element.h | 2 +- .../qetgraphicsitem/elementtextitemgroup.h | 2 +- sources/qetgraphicsitem/terminal.cpp | 24 +-- sources/qetgraphicsitem/terminal.h | 2 +- sources/titleblockproperties.cpp | 45 ++-- sources/titleblockproperties.h | 4 +- 40 files changed, 520 insertions(+), 258 deletions(-) diff --git a/sources/borderproperties.cpp b/sources/borderproperties.cpp index 8c87933b7..57e0de57a 100644 --- a/sources/borderproperties.cpp +++ b/sources/borderproperties.cpp @@ -128,13 +128,13 @@ bool BorderProperties::fromXml(const QDomElement &e) { return true; } -bool BorderProperties::valideXml(QDomElement& e) const { +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 && + 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) return true; } diff --git a/sources/borderproperties.h b/sources/borderproperties.h index 93d72c78b..3fdde4d2a 100644 --- a/sources/borderproperties.h +++ b/sources/borderproperties.h @@ -39,7 +39,7 @@ class BorderProperties : public PropertiesInterface { QDomElement toXml(QDomDocument &dom_doc) const override; bool fromXml(const QDomElement &) override; - bool valideXml(QDomElement& e) const override; + static bool valideXml(QDomElement& e); void toSettings(QSettings &, const QString & = QString()) const override; void fromSettings(const QSettings &, const QString & = QString()) override; diff --git a/sources/bordertitleblock.cpp b/sources/bordertitleblock.cpp index ede0f5ccd..9d954c9fd 100644 --- a/sources/bordertitleblock.cpp +++ b/sources/bordertitleblock.cpp @@ -168,8 +168,8 @@ QRectF BorderTitleBlock::insideBorderRect() const Exports the title block current values to XML. @param xml_elmt the XML element attributes will be added to */ -void BorderTitleBlock::titleBlockToXml(QDomElement &xml_elmt) { - exportTitleBlock().toXml(xml_elmt); +void BorderTitleBlock::titleBlockToXml(QDomDocument& doc) { + exportTitleBlock().toXml(doc); } /** diff --git a/sources/bordertitleblock.h b/sources/bordertitleblock.h index 67fe22691..9a892e931 100644 --- a/sources/bordertitleblock.h +++ b/sources/bordertitleblock.h @@ -152,7 +152,7 @@ class BorderTitleBlock : public QObject void setPreviousFolioNum(const QString &previous); void setNextFolioNum(const QString &next); - void titleBlockToXml(QDomElement &); + void titleBlockToXml(QDomDocument &doc); void titleBlockFromXml(const QDomElement &); void borderToXml(QDomElement &); void borderFromXml(const QDomElement &); diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 76f401c20..f70e7b2db 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -196,11 +196,17 @@ void SingleLineProperties::drawPen(QPainter *painter, QET::ConductorSegmentType ajoutes a l'element e. @param e Element XML auquel seront ajoutes des attributs */ -void SingleLineProperties::toXml(QDomElement &e) const { - e.setAttribute("ground", hasGround ? "true" : "false"); - e.setAttribute("neutral", hasNeutral ? "true" : "false"); - e.setAttribute("phase", phases); - if (isPen()) e.setAttribute("pen", "true"); +QDomElement SingleLineProperties::toXml(QDomDocument &doc) const { + + QDomElement e = doc.createElement("SingleLine"); + e.appendChild(createXmlProperty(doc, "ground", hasGround)); + e.appendChild(createXmlProperty(doc, "neutral", hasNeutral)); + e.appendChild(createXmlProperty(doc, "phase", phases)); + + if (isPen()) + e.appendChild(createXmlProperty(doc, "pen", true)); + + return e; } /** @@ -208,11 +214,36 @@ void SingleLineProperties::toXml(QDomElement &e) const { de l'element e @param e Element XML dont les attributs seront lus */ -void SingleLineProperties::fromXml(QDomElement &e) { - hasGround = e.attribute("ground") == "true"; - hasNeutral = e.attribute("neutral") == "true"; - setPhasesCount(e.attribute("phase").toInt()); - is_pen = (hasGround && hasNeutral && e.attribute("pen", "false") == "true"); +bool SingleLineProperties::fromXml(const QDomElement &e) { + if (propertyBool(e, "ground", &hasGround) != PropertyFlags::Success || + propertyBool(e, "neutral", &hasNeutral) != PropertyFlags::Success) + return false; + + int phase; + if (propertyInteger(e, "phase", &phase) != PropertyFlags::Success) + return false; + setPhasesCount(phase); + + bool pen; + if (propertyBool(e, "pen", &pen) != PropertyFlags::Success) + return false; + is_pen = (hasGround && hasNeutral && pen); + + return true; +} + +bool SingleLineProperties::valideXml(QDomElement& e) { + if (propertyBool(e, "ground") != PropertyFlags::Success || + propertyBool(e, "neutral") != PropertyFlags::Success) + return false; + + if (propertyInteger(e, "phase") != PropertyFlags::Success) + return false; + + if (propertyBool(e, "pen") != PropertyFlags::Success) + return false; + + return true; } /** @@ -245,43 +276,46 @@ ConductorProperties::~ConductorProperties() { * Export conductor propertie, in the XML element 'e' * @param e the xml element */ -void ConductorProperties::toXml(QDomDocument& doc) const +QDomElement ConductorProperties::toXml(QDomDocument& doc) const { - QDomElement conductor_elmt = xml_document.createElement("conductors"); - e.setAttribute("type", typeToString(type)); + QDomElement e = doc.createElement("defaultconductor"); + + e.appendChild(createXmlProperty(doc, "type", typeToString(type))); if (color != QColor(Qt::black)) - e.setAttribute("color", color.name()); - - e.setAttribute("bicolor", m_bicolor? "true" : "false"); - e.setAttribute("color2", m_color_2.name()); - e.setAttribute("dash-size", QString::number(m_dash_size)); + e.appendChild(createXmlProperty(doc, "color", color)); + + e.appendChild(createXmlProperty(doc, "bicolor", m_bicolor)); + e.appendChild(createXmlProperty(doc, "color2", m_color_2)); + e.appendChild(createXmlProperty(doc, "dash-size", m_dash_size)); if (type == Single) - singleLineProperties.toXml(e); + e.appendChild(singleLineProperties.toXml(doc)); - e.setAttribute("num", text); - e.setAttribute("text_color", text_color.name()); - e.setAttribute("formula", m_formula); - e.setAttribute("function", m_function); - e.setAttribute("tension_protocol", m_tension_protocol); - e.setAttribute("conductor_color", m_wire_color); - e.setAttribute("conductor_section", m_wire_section); - e.setAttribute("numsize", QString::number(text_size)); - e.setAttribute("condsize", QString::number(cond_size)); - e.setAttribute("displaytext", m_show_text); - e.setAttribute("onetextperfolio", m_one_text_per_folio); - e.setAttribute("vertirotatetext", QString::number(verti_rotate_text)); - e.setAttribute("horizrotatetext", QString::number(horiz_rotate_text)); + e.appendChild(createXmlProperty(doc, "num", text)); + e.appendChild(createXmlProperty(doc, "text_color", text_color.name())); + e.appendChild(createXmlProperty(doc, "formula", m_formula)); + e.appendChild(createXmlProperty(doc, "function", m_function)); + e.appendChild(createXmlProperty(doc, "tension_protocol", m_tension_protocol)); + e.appendChild(createXmlProperty(doc, "conductor_color", m_wire_color)); + e.appendChild(createXmlProperty(doc, "conductor_section", m_wire_section)); + e.appendChild(createXmlProperty(doc, "numsize", text_size)); + e.appendChild(createXmlProperty(doc, "condsize", cond_size)); + e.appendChild(createXmlProperty(doc, "displaytext", m_show_text)); + e.appendChild(createXmlProperty(doc, "onetextperfolio", m_one_text_per_folio)); + e.appendChild(createXmlProperty(doc, "onetextperfolio", verti_rotate_text)); + e.appendChild(createXmlProperty(doc, "horizrotatetext", horiz_rotate_text)); QMetaEnum me = QMetaEnum::fromType(); - e.setAttribute("horizontal-alignment", me.valueToKey(m_horizontal_alignment)); - e.setAttribute("vertical-alignment", me.valueToKey(m_vertical_alignment)); + e.appendChild(createXmlProperty(doc, "horizontal-alignment", me.valueToKey(m_horizontal_alignment))); + e.appendChild(createXmlProperty(doc, "vertical-alignment", me.valueToKey(m_vertical_alignment))); QString conductor_style = writeStyle(); if (!conductor_style.isEmpty()) - e.setAttribute("style", conductor_style); + e.appendChild(createXmlProperty(doc, "style", conductor_style)); + + return e; } @@ -290,24 +324,21 @@ void ConductorProperties::toXml(QDomDocument& doc) const * Import conductor propertie, from the attribute of the xml element 'e' * @param e the xml document */ -void ConductorProperties::fromXml(QDomElement &e) +bool ConductorProperties::fromXml(const QDomElement &e) { // get conductor color - QColor xml_color= QColor(e.attribute("color")); - color = (xml_color.isValid()? xml_color : QColor(Qt::black)); - - QString bicolor_str = e.attribute("bicolor", "false"); - m_bicolor = bicolor_str == "true"? true : false; - - QColor xml_color_2 = QColor(e.attribute("color2")); - m_color_2 = xml_color_2.isValid()? xml_color_2 : QColor(Qt::black); - - m_dash_size = e.attribute("dash-size", QString::number(1)).toInt(); + propertyColor(e, "color", &color); + propertyBool(e, "bicolor", &m_bicolor, false); + propertyColor(e, "color2", &m_color_2); + propertyInteger(e, "dash-size", &m_dash_size, 1); // read style of conductor readStyle(e.attribute("style")); + + QString type_t; + propertyString(e, "type", &type_t); - if (e.attribute("type") == typeToString(Single)) + if (type_t == typeToString(Single)) { // get specific properties for single conductor singleLineProperties.fromXml(e); @@ -316,30 +347,60 @@ void ConductorProperties::fromXml(QDomElement &e) else type = Multi; - text = e.attribute("num"); + propertyString(e, "num", &text); + // get text color - QColor xml_text_color= QColor(e.attribute("text_color")); - text_color = (xml_text_color.isValid()? xml_text_color : QColor(Qt::black)); - m_formula = e.attribute("formula"); - m_function = e.attribute("function"); - m_tension_protocol = e.attribute("tension_protocol"); - m_wire_color = e.attribute("conductor_color"); - m_wire_section = e.attribute("conductor_section"); - text_size = e.attribute("numsize", QString::number(9)).toInt(); - cond_size = e.attribute("condsize", QString::number(1)).toDouble(); - m_show_text = e.attribute("displaytext", QString::number(1)).toInt(); - m_one_text_per_folio = e.attribute("onetextperfolio", QString::number(0)).toInt(); - verti_rotate_text = e.attribute("vertirotatetext").toDouble(); - horiz_rotate_text = e.attribute("horizrotatetext").toDouble(); + 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, 9); + propertyDouble(e, "condsize", &cond_size, 1); + propertyBool(e, "displaytext", &m_show_text, true); + propertyBool(e, "onetextperfolio", &m_one_text_per_folio, 0); + propertyDouble(e, "vertirotatetext", &verti_rotate_text); + propertyDouble(e, "horizrotatetext", &horiz_rotate_text); QMetaEnum me = QMetaEnum::fromType(); - m_horizontal_alignment = Qt::Alignment(me.keyToValue(e.attribute("horizontal-alignment", "AlignBottom").toStdString().data())); - m_vertical_alignment = Qt::Alignment(me.keyToValue(e.attribute("vertical-alignment", "AlignRight").toStdString().data())); + + QString alinment_temp; + propertyString(e, "horizontal-alignment", &alinment_temp, "AlignBottom"); + m_horizontal_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); + propertyString(e, "vertical-alignment", &alinment_temp, "AlignRight"); + m_vertical_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); //Keep retrocompatible with version older than 0,4 //If the propertie @type is simple (removed since QET 0,4), we set text no visible. //@TODO remove this code for qet 0.6 or later - if (e.attribute("type") == "simple") m_show_text = false; + + if (type_t == "simple") m_show_text = false; +} + +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")) + return false; + return true; } /** @@ -379,7 +440,7 @@ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) @param settings Parametres a lire @param prefix prefixe a ajouter devant les noms des parametres */ -void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix) +void ConductorProperties::fromSettings(const QSettings &settings, const QString &prefix) { QColor settings_color = QColor(settings.value(prefix + "color").toString()); color = (settings_color.isValid()? settings_color : QColor(Qt::black)); @@ -823,7 +884,7 @@ void SingleLineProperties::toSettings(QSettings &settings, const QString &prefix @param settings Parametres a lire @param prefix prefix a ajouter devant les noms des parametres */ -void SingleLineProperties::fromSettings(QSettings &settings, const QString &prefix) { +void SingleLineProperties::fromSettings(const QSettings &settings, const QString &prefix) { hasGround = settings.value(prefix + "hasGround", true).toBool(); hasNeutral = settings.value(prefix + "hasNeutral", true).toBool(); phases = settings.value(prefix + "phases", 1).toInt(); diff --git a/sources/conductorproperties.h b/sources/conductorproperties.h index 396933f0b..6435e15d6 100644 --- a/sources/conductorproperties.h +++ b/sources/conductorproperties.h @@ -38,10 +38,11 @@ class SingleLineProperties: public PropertiesInterface { unsigned short int phasesCount(); bool isPen() const; void draw(QPainter *, QET::ConductorSegmentType, const QRectF &); - void toXml(QDomElement &) const override; - void fromXml(QDomElement &) override; + QDomElement toXml(QDomDocument& doc) const override; + bool fromXml(const QDomElement &) override; + static bool valideXml(QDomElement& element); void toSettings(QSettings &, const QString & = QString()) const override; - void fromSettings(QSettings &, const QString & = QString()) override; + void fromSettings(const QSettings &, const QString & = QString()) override; /// Whether the singleline conductor should display the ground symbol bool hasGround; @@ -111,10 +112,11 @@ class ConductorProperties: public PropertiesInterface SingleLineProperties singleLineProperties; // methods - void toXml(QDomDocument &doc) const override; - void fromXml(QDomElement &) override; + QDomElement toXml(QDomDocument &doc) const override; + bool fromXml(const QDomElement &) override; + static bool valideXml(QDomElement& element); void toSettings(QSettings &, const QString & = QString()) const override; - void fromSettings(QSettings &, const QString & = QString()) override; + void fromSettings(const QSettings &, const QString & = QString()) override; static QString typeToString(ConductorType); void applyForEqualAttributes(QList list); diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 5222aa075..952c1a5a7 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -624,13 +624,12 @@ QDomDocument Diagram::toXml(bool whole_content) { // proprietes du schema if (whole_content) { - border_and_titleblock.titleBlockToXml(dom_root); + // TODO: compare with old version + border_and_titleblock.titleBlockToXml(document); border_and_titleblock.borderToXml(dom_root); // Default conductor properties - QDomElement default_conductor = document.createElement("defaultconductor"); - defaultConductorProperties.toXml(default_conductor); - dom_root.appendChild(default_conductor); + dom_root.appendChild(defaultConductorProperties.toXml(document)); // Conductor autonum if (!m_conductors_autonum_name.isEmpty()) { @@ -764,7 +763,8 @@ QDomDocument Diagram::toXml(bool whole_content) { if (!list_conductors.isEmpty()) { auto dom_conductors = document.createElement("conductors"); for (auto cond : list_conductors) { - dom_conductors.appendChild(cond->toXml(document, table_adr_id)); + //dom_conductors.appendChild(cond->toXml(document, table_adr_id)); + dom_conductors.appendChild(cond->toXml(document)); } dom_root.appendChild(dom_conductors); } @@ -948,6 +948,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf defaultConductorProperties.fromXml(default_conductor_elmt); } + // Load the autonum m_conductors_autonum_name = root.attribute("conductorAutonum"); diff --git a/sources/diagram.h b/sources/diagram.h index bbe7325e5..d0bd6d260 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -166,7 +166,7 @@ class Diagram : public QGraphicsScene QList < QSet > potentials(); // methods related to XML import/export - QDomDocument toXml(bool = true); + QDomDocument toXml(bool = true); bool initFromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = nullptr); bool fromXml(QDomDocument &, QPointF = QPointF(), diff --git a/sources/diagramcontext.cpp b/sources/diagramcontext.cpp index 0afc4e14c..5c6ee3a79 100644 --- a/sources/diagramcontext.cpp +++ b/sources/diagramcontext.cpp @@ -197,15 +197,17 @@ void DiagramContext::toSettings(QSettings &settings, const QString &array_name) Read this context properties from \a settings by running through the array named \a array_name. */ -void DiagramContext::fromSettings(QSettings &settings, const QString &array_name) { - int size = settings.beginReadArray(array_name); +void DiagramContext::fromSettings(const QSettings &settings, const QString &array_name) { + // TODO: find better solution than const cast + QSettings& s = const_cast(settings); + int size = s.beginReadArray(array_name); for (int i = 0 ; i < size; ++ i) { - settings.setArrayIndex(i); + s.setArrayIndex(i); QString key = settings.value("name").toString(); if (key.isEmpty()) continue; addValue(key, settings.value("value").toString()); } - settings.endArray(); + s.endArray(); } /** diff --git a/sources/diagramcontext.h b/sources/diagramcontext.h index 6eeaa1508..3ed8bf1b5 100644 --- a/sources/diagramcontext.h +++ b/sources/diagramcontext.h @@ -79,7 +79,7 @@ class DiagramContext void fromXml(const QDomElement &, const QString & = "property"); void fromXml(const pugi::xml_node &dom_element, const QString &tag_name = "property"); void toSettings(QSettings &, const QString &) const; - void fromSettings(QSettings &, const QString &); + void fromSettings(const QSettings &, const QString &); static QString validKeyRegExp(); diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index b5ac5cbe7..ba1716a7f 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -141,6 +141,18 @@ bool PartArc::fromXml(const QDomElement &qde) { m_span_angle *= 16; } +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) + return false; + return true; +} + /** * @brief PartArc::shape * @return the shape of this item diff --git a/sources/editor/graphicspart/partarc.h b/sources/editor/graphicspart/partarc.h index 736a8c9de..792cd7d3b 100644 --- a/sources/editor/graphicspart/partarc.h +++ b/sources/editor/graphicspart/partarc.h @@ -53,6 +53,7 @@ class PartArc : public AbstractPartEllipse QString xmlName() const override { return(QString("arc")); } QDomElement toXml (QDomDocument &) const override; bool fromXml (const QDomElement &) override; + static bool valideXml(QDomElement& element); QPainterPath shape() const override; QPainterPath shadowShape() const override; diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp index 2d09dcb5f..e04b007bc 100644 --- a/sources/editor/graphicspart/partdynamictextfield.cpp +++ b/sources/editor/graphicspart/partdynamictextfield.cpp @@ -183,12 +183,17 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt) } propertyUuid(dom_elmt, "uuid", &m_uuid, QUuid::createUuid()); - m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString())); - setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false); - setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble()); + bool frame; + propertyBool(dom_elmt, "frame", &frame); + + double text_width; + propertyDouble(dom_elmt, "text_width", &text_width, -1); + setTextWidth(text_width); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); - m_text_from = DynamicElementTextItem::TextFrom(me.keyToValue(dom_elmt.attribute("text_from").toStdString().data())); + QString text_from; + propertyString(dom_elmt, "text_from", &text_from); + m_text_from = DynamicElementTextItem::TextFrom(me.keyToValue(text_from.toStdString().data())); me = QMetaEnum::fromType(); QString alignment; @@ -223,6 +228,27 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt) setColor(QColor(dom_color.text())); } +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) + return false; + + if (propertyUuid(dom_elmt, "uuid") == PropertyFlags::NoValidConversion) + return false; + + if (propertyString(dom_elmt, "text_from")) + return false; + + if(propertyString(dom_elmt, "Halignment") == PropertyFlags::NotFound) + return false; + if(propertyString(dom_elmt, "Valignment") == PropertyFlags::NotFound) + return false; + + return true; +} + /** * @brief PartDynamicTextField::fromTextFieldXml * Setup this text from the xml definition of a text field (The xml tagg of a text field is "input"); diff --git a/sources/editor/graphicspart/partdynamictextfield.h b/sources/editor/graphicspart/partdynamictextfield.h index aadfb5044..b6e008b62 100644 --- a/sources/editor/graphicspart/partdynamictextfield.h +++ b/sources/editor/graphicspart/partdynamictextfield.h @@ -77,6 +77,7 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart QDomElement toXml(QDomDocument &dom_doc) const override; bool fromXml(const QDomElement &dom_elmt) override; void fromTextFieldXml(const QDomElement &dom_element); + static bool valideXml(QDomElement& dom_elmt); DynamicElementTextItem::TextFrom textFrom() const; void setTextFrom (DynamicElementTextItem::TextFrom text_from); diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index 50079eecb..ffc75e073 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -132,6 +132,26 @@ bool PartEllipse::fromXml(const QDomElement &qde) return true; } +bool PartEllipse::valideXml(QDomElement& element) { + if (element.tagName() == "ellipse") + { + if (propertyDouble(element, "width") & PropertyFlags::NoValidConversion || + propertyDouble(element, "height") & PropertyFlags::NoValidConversion) + return false; + } + else { + if (propertyDouble(element, "diameter") & PropertyFlags::NoValidConversion) + return false; + } + + + if ((propertyDouble(element, "x") & PropertyFlags::NoValidConversion) || + (propertyDouble(element, "y") & PropertyFlags::NoValidConversion)) + return false; + + return true; +} + /** * @brief PartEllipse::shape * @return the shape of this item diff --git a/sources/editor/graphicspart/partellipse.h b/sources/editor/graphicspart/partellipse.h index af2e822be..0b15136b7 100644 --- a/sources/editor/graphicspart/partellipse.h +++ b/sources/editor/graphicspart/partellipse.h @@ -54,6 +54,7 @@ class PartEllipse : public AbstractPartEllipse QString xmlName() const override { return(QString("ellipse")); } QDomElement toXml (QDomDocument &) const override; bool fromXml (const QDomElement &) override; + static bool valideXml(QDomElement& element); QPainterPath shape() const override; QPainterPath shadowShape() const override; void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();} diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index 228b0b2c2..d9a66b196 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -161,6 +161,20 @@ bool PartLine::fromXml(const QDomElement &qde) { 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") ) + return false; + + return true; +} + /** * @brief PartLine::itemChange * @param change diff --git a/sources/editor/graphicspart/partline.h b/sources/editor/graphicspart/partline.h index 96f0185fa..5e8ccf971 100644 --- a/sources/editor/graphicspart/partline.h +++ b/sources/editor/graphicspart/partline.h @@ -72,6 +72,7 @@ class PartLine : public CustomElementGraphicPart QString xmlName() const override { return(QString("line")); } QDomElement toXml(QDomDocument &) const override; bool fromXml(const QDomElement &) override; + bool valideXml(QDomElement& element) const; virtual QPointF sceneP1() const; virtual QPointF sceneP2() const; QPainterPath shape() const override; diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index a6558f461..8a9aa54bc 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -138,6 +138,11 @@ QDomElement PartPolygon::toXml(QDomDocument &xml_document) const return(xml_element); } +bool PartPolygon::valideXml(QDomElement& element) { + // TODO: implement + return true; +} + /** * @brief PartPolygon::isUseless * @return true if this part is irrelevant and does not deserve to be Retained / registered. diff --git a/sources/editor/graphicspart/partpolygon.h b/sources/editor/graphicspart/partpolygon.h index d0fbb93ff..c59c18a24 100644 --- a/sources/editor/graphicspart/partpolygon.h +++ b/sources/editor/graphicspart/partpolygon.h @@ -63,6 +63,8 @@ class PartPolygon : public CustomElementGraphicPart QString xmlName() const override { return(QString("polygon")); } bool fromXml(const QDomElement &) override; QDomElement toXml(QDomDocument &) const override; + static bool valideXml(QDomElement& element); + QPainterPath shape () const override; QPainterPath shadowShape() const override; diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index 708d52b3f..170068f00 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -141,6 +141,18 @@ bool PartRectangle::fromXml(const QDomElement &qde) return true; } +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, "width") & PropertyFlags::NoValidConversion) | + (propertyDouble(element, "rx") & PropertyFlags::NoValidConversion) | + (propertyDouble(element, "ry") & PropertyFlags::NoValidConversion)) + return false; + return true; +} + /** * @brief PartRectangle::rect * @return : Returns the item's rectangle. diff --git a/sources/editor/graphicspart/partrectangle.h b/sources/editor/graphicspart/partrectangle.h index cc42de702..b6566ce5d 100644 --- a/sources/editor/graphicspart/partrectangle.h +++ b/sources/editor/graphicspart/partrectangle.h @@ -62,6 +62,7 @@ class PartRectangle : public CustomElementGraphicPart QString xmlName () const override { return(QString("rect")); } QDomElement toXml (QDomDocument &) const override; bool fromXml (const QDomElement &) override; + static bool valideXml(QDomElement& element); QRectF rect() const; void setRect(const QRectF &rect); diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 92ade5134..47b9d8cf7 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -61,6 +61,10 @@ QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { return d->toXml(xml_document); } +bool PartTerminal::valideXml(QDomElement& element) { + return TerminalData::valideXml(element); +} + /** Dessine la borne @param p QPainter a utiliser pour rendre le dessin diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index 1c44b82eb..73de2b195 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -59,6 +59,8 @@ class PartTerminal : public CustomElementGraphicPart QString xmlName() const override { return(QString("terminal")); } bool fromXml(const QDomElement &) override; QDomElement toXml(QDomDocument &) const override; + static bool valideXml(QDomElement& element); + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; QPainterPath shape() const override; diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp index 369355151..6ba0eecbb 100644 --- a/sources/editor/graphicspart/parttext.cpp +++ b/sources/editor/graphicspart/parttext.cpp @@ -119,6 +119,30 @@ QDomElement PartText::toXml(QDomDocument &xml_document) const return(xml_element); } +bool PartText::valideXml(QDomElement& element) { + + if (propertyInteger(element, "size") == PropertyFlags::NotFound || + propertyString(element, "font") == PropertyFlags::NotFound) { + return false; + } + + if (propertyString(element, "color") == PropertyFlags::NoValidConversion) + return false; + + + if (propertyString(element, "text")) + return false; + + if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion || + propertyDouble(element, "y") == PropertyFlags::NoValidConversion) + return false; + + if (propertyDouble(element, "rotation", 0) == PropertyFlags::NoValidConversion) + return false; + + return true; +} + /** @return Les coordonnees du point situe en bas a gauche du texte. */ diff --git a/sources/editor/graphicspart/parttext.h b/sources/editor/graphicspart/parttext.h index 77a670d36..e2535ad93 100644 --- a/sources/editor/graphicspart/parttext.h +++ b/sources/editor/graphicspart/parttext.h @@ -60,6 +60,7 @@ class PartText : public QGraphicsTextItem, public CustomElementPart QString name() const override { return(QObject::tr("texte", "element part name")); } QString xmlName() const override { return(QString("text")); } bool fromXml(const QDomElement &) override; + static bool valideXml(QDomElement& element); QDomElement toXml(QDomDocument &) const override; void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));} bool isUseless() const override; diff --git a/sources/properties/propertiesinterface.cpp b/sources/properties/propertiesinterface.cpp index b4bd2bef8..7fd25dc1a 100644 --- a/sources/properties/propertiesinterface.cpp +++ b/sources/properties/propertiesinterface.cpp @@ -26,12 +26,18 @@ namespace { const QString boolS = "bool"; const QString stringS = "string"; const QString uuidS = "uuid"; + const QString colorS = "color"; } PropertiesInterface::PropertiesInterface() { } +bool PropertiesInterface::valideXml(QDomElement& element) { + qDebug(QString("ValideXml() is not implemented. File: %1, Line: %2").arg(__FILE__).arg(__LINE__).toStdString().data()); + return false; +} + QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const QString value) const { QDomElement p = doc.createElement("property"); p.setAttribute("name", name); @@ -44,7 +50,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", integerS); - p.setAttribute("value", value); + p.setAttribute("value", QString::number(value)); return p; } @@ -52,7 +58,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", doubleS); - p.setAttribute("value", value); + p.setAttribute("value", QString::number(value)); return p; } @@ -60,7 +66,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", boolS); - p.setAttribute("value", value); + p.setAttribute("value", QString::number(value)); return p; } @@ -72,6 +78,14 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr return p; } +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) const { + 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(); @@ -86,7 +100,7 @@ QDomElement PropertiesInterface::property(const QDomElement& e, const QString& n /*! * \brief PropertiesInterface::attribute - * Returns the property with the name \p attribute_name + * 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 @@ -185,6 +199,26 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE return PropertyFlags::Success; } +PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color, QColor defaultValue) { + + QString attr; + + if (!attribute(e, attribute_name, colorS, &attr)) { + *color = defaultValue; + return PropertyFlags::NotFound; + } + + // verifie la validite de l'attribut + QColor tmp = QColor(attr); + 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, QUuid defaultValue) { QString attr; diff --git a/sources/properties/propertiesinterface.h b/sources/properties/propertiesinterface.h index ebd60e533..ecb7d18b9 100644 --- a/sources/properties/propertiesinterface.h +++ b/sources/properties/propertiesinterface.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include "qet.h" @@ -34,12 +35,12 @@ class PropertiesInterface public: PropertiesInterface(); // Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre - virtual void toSettings (QSettings &settings, const QString& = QString()) const =0; - virtual void fromSettings (const QSettings &settings, const QString& = QString()) =0; + virtual void toSettings (QSettings &settings, const QString& = QString()) const {Q_UNUSED(settings)}; + virtual void fromSettings (const QSettings &settings, const QString& = QString()) {Q_UNUSED(settings)}; // Save/load properties to xml element virtual QDomElement toXml (QDomDocument &xml_document) const =0; virtual bool fromXml (const QDomElement &xml_element) =0; - virtual bool valideXml(QDomElement& element) const = 0; + static bool valideXml(QDomElement& element); /*! * Use this functions to add properties to the xml document @@ -49,14 +50,16 @@ class PropertiesInterface QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) const; + QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) const; static QDomElement property(const QDomElement& e, const QString& name); static bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); typedef enum PropertyFlags { Success = 0, - NotFound, - NoValidConversion, + NotFound = 1, + NoValidConversion = 2, + // = 4 }; static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, int defaultValue = std::numeric_limits::quiet_NaN()); @@ -64,6 +67,8 @@ class PropertiesInterface static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr, QString defaultValue = QString()); static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool defaultValue = false); static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr, QUuid defaultValue = QUuid()); + static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr, QColor defaultValue = QColor()); + static bool validXmlProperty(const QDomElement& e); diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 2aefb0710..5d3a72779 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -28,13 +28,13 @@ void TerminalData::setParent(QGraphicsObject* parent) q = parent; } -void TerminalData::toSettings(QSettings &settings, const QString) const +void TerminalData::toSettings(QSettings& settings, const QString&) const { Q_UNUSED(settings); } -void TerminalData::fromSettings(const QSettings &settings, const QString) +void TerminalData::fromSettings(const QSettings& settings, const QString&) { Q_UNUSED(settings); } @@ -89,6 +89,20 @@ bool TerminalData::fromXml (const QDomElement &xml_element) return true; } -bool TerminalData::valideXml(QDomElement& element) const { +bool TerminalData::valideXml(QDomElement& xml_element) { + if (propertyDouble(xml_element, "x")) + return false; + + if (propertyDouble(xml_element, "y")) + return false; + + if (propertyString(xml_element, "uuid")) + return false; + + if (propertyString(xml_element, "name")) + return false; + + if (propertyString(xml_element, "orientation")) + return false; return true; } diff --git a/sources/properties/terminaldata.h b/sources/properties/terminaldata.h index 4d5301cda..5c747dfe4 100644 --- a/sources/properties/terminaldata.h +++ b/sources/properties/terminaldata.h @@ -28,30 +28,14 @@ public: void setParent(QGraphicsObject* parent); // Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre - void toSettings(QSettings &settings, const QString = QString()) const override; - void fromSettings(const QSettings &settings, const QString = QString()) override; + void toSettings(QSettings &settings, const QString& = QString()) const override; + void fromSettings(const QSettings &settings, const QString& = QString()) override; // Save/load properties to xml element // This method is only called from the PartTerminal and should never called from the Terminal class QDomElement toXml(QDomDocument &xml_element) const override; bool fromXml(const QDomElement &xml_element) override; - bool valideXml(QDomElement &element) const override; - - /** - Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w") - en orientation. Si la chaine fait plusieurs caracteres, seul le - premier est pris en compte. En cas d'incoherence, Qet::North est - retourne. - @param s Chaine de caractere cense representer une orientation - @return l'orientation designee par la chaine de caractere - */ - static Qet::Orientation orientationFromString(const QString &s); - - /** - @param o une orientation - @return une chaine de caractere representant l'orientation - */ - static QString orientationToString(Qet::Orientation o); + static bool valideXml(QDomElement &xml_element); // must be public, because this class is a private member of PartTerminal/Terminal and they must // access this data diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index 1992d920d..b8f4f6bc6 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -153,11 +153,6 @@ bool XRefProperties::fromXml(const QDomElement &xml_element) { return true; } -bool XRefProperties::valideXml(QDomElement& element) const { - // TODO: implement - return true; -} - /** * @brief XRefProperties::defaultProperties * @return the default properties stored in the setting file diff --git a/sources/properties/xrefproperties.h b/sources/properties/xrefproperties.h index e154827bb..9681657f5 100644 --- a/sources/properties/xrefproperties.h +++ b/sources/properties/xrefproperties.h @@ -44,7 +44,6 @@ class XRefProperties : public PropertiesInterface void fromSettings (const QSettings &settings, const QString& = QString()) override; QDomElement toXml (QDomDocument &xml_document) const override; bool fromXml(const QDomElement &xml_element) override; - bool valideXml(QDomElement& element) const override; static QHash defaultProperties(); diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 804b4aa24..3be915975 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -573,36 +573,16 @@ ConductorTextItem *Conductor::textItem() const { @return true si l'element XML represente bien un Conducteur ; false sinon */ bool Conductor::valideXml(QDomElement &e){ - // verifie le nom du tag - if (e.tagName() != "conductor") return(false); - - // verifie la presence des attributs minimaux - if (!e.hasAttribute("terminal1")) return(false); - if (!e.hasAttribute("terminal2")) return(false); - - bool conv_ok; - // parse l'abscisse - if (e.hasAttribute("element1")) { - if (QUuid(e.attribute("element1")).isNull()) - return false; - if (QUuid(e.attribute("terminal1")).isNull()) - return false; - } else { - e.attribute("terminal1").toInt(&conv_ok); - if (!conv_ok) return(false); - } - - // parse l'ordonnee - if (e.hasAttribute("element2")) { - if (QUuid(e.attribute("element2")).isNull()) - return false; - if (QUuid(e.attribute("terminal2")).isNull()) - return false; - } else { - e.attribute("terminal2").toInt(&conv_ok); - if (!conv_ok) return(false); - } - return(true); + + // TODO: seems to short! (see fromXML) + if (propertyDouble(e, "x") || + propertyDouble(e, "y")) + return false; + + if (propertyBool(e, "freezeLabel")) + return false; + + return true; } /** @@ -973,8 +953,9 @@ void Conductor::pointsToSegments(const QList& points_list) { * @param e * @return true is loading success else return false */ -bool Conductor::fromXml(QDomElement &dom_element) +bool Conductor::fromXml(const QDomElement &dom_element) { + // TODO: seems to short! setPos(dom_element.attribute("x", nullptr).toDouble(), dom_element.attribute("y", nullptr).toDouble()); @@ -997,6 +978,54 @@ bool Conductor::fromXml(QDomElement &dom_element) return return_; } +// does not support legacy method +// dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); +QDomElement Conductor::toXml(QDomDocument & doc) const { + QDomElement dom_element = doc.createElement("conductor"); + + dom_element.appendChild(createXmlProperty(doc, "x", pos().x())); + dom_element.appendChild(createXmlProperty(doc, "y", pos().y())); + + // Terminal is uniquely identified by the uuid of the terminal and the element + dom_element.appendChild(createXmlProperty(doc, "element1", terminal1->parentElement()->uuid())); + dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal1->uuid())); + + dom_element.appendChild(createXmlProperty(doc, "element2", terminal2->parentElement()->uuid())); + dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid())); + + dom_element.appendChild(createXmlProperty(doc, "freezeLabel", m_freeze_label)); + + // on n'exporte les segments du conducteur que si ceux-ci ont + // ete modifies par l'utilisateur + if (modified_path) + { + // parcours et export des segments + QDomElement current_segment; + foreach(ConductorSegment *segment, segmentsList()) + { + current_segment = doc.createElement("segment"); + current_segment.appendChild(createXmlProperty(doc, "orientation", segment->isHorizontal())); + current_segment.appendChild(createXmlProperty(doc, "length", segment -> length())); + dom_element.appendChild(current_segment); + } + } + + QDomElement dom_seq = m_autoNum_seq.toXml(doc); + dom_element.appendChild(dom_seq); + + // Export the properties and text + dom_element.appendChild(m_properties.toXml(doc)); + if(m_text_item->wasMovedByUser()) + { + dom_element.appendChild(createXmlProperty(doc, "userx", m_text_item->pos().x())); + dom_element.appendChild(createXmlProperty(doc, "usery", m_text_item->pos().y())); + } + if(m_text_item->wasRotateByUser()) + dom_element.appendChild(createXmlProperty(doc, "rotation", m_text_item->rotation())); + + return(dom_element); +} + /** Exporte les caracteristiques du conducteur sous forme d'une element XML. @param d Le document XML a utiliser pour creer l'element XML @@ -1004,61 +1033,61 @@ bool Conductor::fromXml(QDomElement &dom_element) bornes dans le document XML et leur adresse en memoire @return Un element XML representant le conducteur */ -QDomElement Conductor::toXml(QDomDocument &dom_document, QHash &table_adr_id) const -{ - QDomElement dom_element = dom_document.createElement("conductor"); +//QDomElement Conductor::toXml(QDomDocument &dom_document, QHash &table_adr_id) const +//{ +// QDomElement dom_element = dom_document.createElement("conductor"); - dom_element.setAttribute("x", QString::number(pos().x())); - dom_element.setAttribute("y", QString::number(pos().y())); +// dom_element.setAttribute("x", QString::number(pos().x())); +// dom_element.setAttribute("y", QString::number(pos().y())); - // Terminal is uniquely identified by the uuid of the terminal and the element - if (terminal1->uuid().isNull()) { - // legacy method to identify the terminal - dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability - } else { - dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString()); - dom_element.setAttribute("terminal1", terminal1->uuid().toString()); - } +// // Terminal is uniquely identified by the uuid of the terminal and the element +// if (terminal1->uuid().isNull()) { +// // legacy method to identify the terminal +// dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability +// } else { +// dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString()); +// dom_element.setAttribute("terminal1", terminal1->uuid().toString()); +// } - if (terminal2->uuid().isNull()) { - // legacy method to identify the terminal - dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability - } else { - dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString()); - dom_element.setAttribute("terminal2", terminal2->uuid().toString()); - } - dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false"); +// if (terminal2->uuid().isNull()) { +// // legacy method to identify the terminal +// dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability +// } else { +// dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString()); +// dom_element.setAttribute("terminal2", terminal2->uuid().toString()); +// } +// dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false"); - // on n'exporte les segments du conducteur que si ceux-ci ont - // ete modifies par l'utilisateur - if (modified_path) - { - // parcours et export des segments - QDomElement current_segment; - foreach(ConductorSegment *segment, segmentsList()) - { - current_segment = dom_document.createElement("segment"); - current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical"); - current_segment.setAttribute("length", QString("%1").arg(segment -> length())); - dom_element.appendChild(current_segment); - } - } +// // on n'exporte les segments du conducteur que si ceux-ci ont +// // ete modifies par l'utilisateur +// if (modified_path) +// { +// // parcours et export des segments +// QDomElement current_segment; +// foreach(ConductorSegment *segment, segmentsList()) +// { +// current_segment = dom_document.createElement("segment"); +// current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical"); +// current_segment.setAttribute("length", QString("%1").arg(segment -> length())); +// dom_element.appendChild(current_segment); +// } +// } - QDomElement dom_seq = m_autoNum_seq.toXml(dom_document); - dom_element.appendChild(dom_seq); +// QDomElement dom_seq = m_autoNum_seq.toXml(dom_document); +// dom_element.appendChild(dom_seq); - // Export the properties and text - m_properties. toXml(dom_element); - if(m_text_item->wasMovedByUser()) - { - dom_element.setAttribute("userx", QString::number(m_text_item->pos().x())); - dom_element.setAttribute("usery", QString::number(m_text_item->pos().y())); - } - if(m_text_item->wasRotateByUser()) - dom_element.setAttribute("rotation", QString::number(m_text_item->rotation())); +// // Export the properties and text +// m_properties.toXml(dom_document); +// if(m_text_item->wasMovedByUser()) +// { +// dom_element.setAttribute("userx", QString::number(m_text_item->pos().x())); +// dom_element.setAttribute("usery", QString::number(m_text_item->pos().y())); +// } +// if(m_text_item->wasRotateByUser()) +// dom_element.setAttribute("rotation", QString::number(m_text_item->rotation())); - return(dom_element); -} +// return(dom_element); +//} /** * @brief Conductor::pathFromXml @@ -1077,14 +1106,14 @@ bool Conductor::pathFromXml(const QDomElement &e) { if (current_segment.isNull() || current_segment.tagName() != "segment") continue; // le segment doit avoir une longueur - if (!current_segment.hasAttribute("length")) continue; + qreal segment_length; + if (propertyDouble(e, "length", & segment_length)) + continue; - // cette longueur doit etre un reel - bool ok; - qreal segment_length = current_segment.attribute("length").toDouble(&ok); - if (!ok) continue; + bool isHorizontal; + propertyBool(e, "orientation", &isHorizontal); - if (current_segment.attribute("orientation") == "horizontal") { + if (isHorizontal) { segments_x << segment_length; segments_y << 0.0; } else { diff --git a/sources/qetgraphicsitem/conductor.h b/sources/qetgraphicsitem/conductor.h index 818ba1444..5abc62620 100644 --- a/sources/qetgraphicsitem/conductor.h +++ b/sources/qetgraphicsitem/conductor.h @@ -19,6 +19,7 @@ #define CONDUCTOR_H #include "conductorproperties.h" +#include "propertiesinterface.h" #include #include "assignvariables.h" @@ -39,7 +40,7 @@ typedef QHash ConductorProfilesGroup; This class represents a conductor, i.e. a wire between two element terminals. */ -class Conductor : public QGraphicsObject +class Conductor : public QGraphicsObject, public PropertiesInterface { Q_OBJECT @@ -95,8 +96,9 @@ class Conductor : public QGraphicsObject public: static bool valideXml (QDomElement &); - bool fromXml (QDomElement &); - QDomElement toXml (QDomDocument &, QHash &) const; + bool fromXml (const QDomElement &) override; + //QDomElement toXml (QDomDocument &, QHash &) const; + QDomElement toXml (QDomDocument &doc) const override; private: bool pathFromXml(const QDomElement &); diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 6c7f4c95f..2c3d55ffb 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -37,7 +37,7 @@ class ElementTextItemGroup; /** This is the base class for electrical elements. */ -class Element : public QetGraphicsItem +class Element : public QetGraphicsItem // TODO: derive from propertiesInterface! { friend class DiagramEventAddElement; diff --git a/sources/qetgraphicsitem/elementtextitemgroup.h b/sources/qetgraphicsitem/elementtextitemgroup.h index 9623abb31..46c8e43f1 100644 --- a/sources/qetgraphicsitem/elementtextitemgroup.h +++ b/sources/qetgraphicsitem/elementtextitemgroup.h @@ -32,7 +32,7 @@ class CrossRefItem; * This class represent a group of element text * Texts in the group can be aligned left / center /right */ -class ElementTextItemGroup : public QObject, public QGraphicsItemGroup +class ElementTextItemGroup : public QObject, public QGraphicsItemGroup // TODO: derive from PropertiesInterface { Q_OBJECT diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index f2f13dfe6..28bd89f52 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -735,21 +735,21 @@ QDomElement Terminal::toXml(QDomDocument &doc) const { @param terminal Le QDomElement a analyser @return true si le QDomElement passe en parametre est une borne, false sinon */ -bool Terminal::valideXml(QDomElement &terminal) const { +bool Terminal::valideXml(QDomElement &terminal) { if (terminal.tagName() != "terminal") return(false); - if (!propertyString(terminal, "number", nullptr)) + if (propertyString(terminal, "number")) return false; - if (!propertyString(terminal, "name", nullptr)) + if (propertyString(terminal, "name")) return false; - if (!propertyBool(terminal, "nameHidden", nullptr)) + if (propertyBool(terminal, "nameHidden")) return false; - if (!propertyDouble(terminal, "x", nullptr)) + if (propertyDouble(terminal, "x")) return false; - if (!propertyDouble(terminal, "y", nullptr)) + if (propertyDouble(terminal, "y")) return false; QString o; @@ -776,23 +776,23 @@ bool Terminal::valideXml(QDomElement &terminal) const { (memes coordonnes, meme orientation), false sinon */ bool Terminal::fromXml(const QDomElement &terminal) { - if (!propertyString(terminal, "number", &number_terminal_)) + if (propertyString(terminal, "number", &number_terminal_)) return false; - if (!propertyString(terminal, "name", &name_terminal_)) + if (propertyString(terminal, "name", &name_terminal_)) return false; - if (!propertyBool(terminal, "nameHidden", &name_terminal_hidden)) + if (propertyBool(terminal, "nameHidden", &name_terminal_hidden)) return false; double x, y; - if (!propertyDouble(terminal, "x", &x)) + if (propertyDouble(terminal, "x", &x)) return false; - if (!propertyDouble(terminal, "y", &y)) + if (propertyDouble(terminal, "y", &y)) return false; QString o; - if (!propertyString(terminal, "orientation", &o)) + if (propertyString(terminal, "orientation", &o)) return false; return ( diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index b33fdcae9..36160cedc 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -90,7 +90,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface bool canBeLinkedTo(Terminal *); // methods related to XML import/export - bool valideXml(QDomElement &) const override; + static bool valideXml(QDomElement &); bool fromXml (const QDomElement &) override; QDomElement toXml (QDomDocument &) const override; diff --git a/sources/titleblockproperties.cpp b/sources/titleblockproperties.cpp index 06a9a1e4a..35e98945c 100644 --- a/sources/titleblockproperties.cpp +++ b/sources/titleblockproperties.cpp @@ -109,24 +109,31 @@ QDomElement TitleBlockProperties::toXml(QDomDocument &xml_document) const { @param e Element XML dont les attributs seront lus */ bool TitleBlockProperties::fromXml(const QDomElement &e) { - // reads the historical fields - if (e.hasAttribute("author")) author = e.attribute("author"); - if (e.hasAttribute("title")) title = e.attribute("title"); - if (e.hasAttribute("filename")) filename = e.attribute("filename"); - if (e.hasAttribute("plant")) plant = e.attribute("plant"); - if (e.hasAttribute("locmach")) locmach = e.attribute("locmach"); - if (e.hasAttribute("indexrev")) indexrev = e.attribute("indexrev"); - if (e.hasAttribute("version")) version = e.attribute("version"); - if (e.hasAttribute("folio")) folio = e.attribute("folio"); - if (e.hasAttribute("auto_page_num")) auto_page_num = e.attribute("auto_page_num"); - if (e.hasAttribute("date")) setDateFromString(e.attribute("date")); - if (e.hasAttribute("displayAt")) display_at = (e.attribute("displayAt") == "bottom" ? Qt::BottomEdge : Qt::RightEdge); - - // reads the template used to render the title block - if (e.hasAttribute("titleblocktemplate")) - { - template_name = e.attribute("titleblocktemplate"); - collection = QET::qetCollectionFromString(e.attribute("titleblocktemplateCollection")); + + + // 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); + QString date; + propertyString(e, "date", &date); + setDateFromString(date); + + QString display_at_temp; + propertyString(e, "displayAt", &display_at_temp); + display_at = (display_at_temp == "bottom" ? Qt::BottomEdge : Qt::RightEdge); + + // reads the template used to render the title block + if (propertyString(e, "titleblocktemplate", &template_name)) { + QString tbc; + propertyString(e, "titleblocktemplateCollection", &tbc); + collection = QET::qetCollectionFromString(tbc); } // reads the additional fields used to fill the title block @@ -164,7 +171,7 @@ void TitleBlockProperties::toSettings(QSettings &settings, const QString &prefix @param settings Parametres a lire @param prefix prefixe a ajouter devant les noms des parametres */ -void TitleBlockProperties::fromSettings(QSettings &settings, const QString &prefix) { +void TitleBlockProperties::fromSettings(const QSettings &settings, const QString &prefix) { title = settings.value(prefix + "title").toString(); author = settings.value(prefix + "author").toString(); filename = settings.value(prefix + "filename").toString(); diff --git a/sources/titleblockproperties.h b/sources/titleblockproperties.h index 480a0265f..df49cc783 100644 --- a/sources/titleblockproperties.h +++ b/sources/titleblockproperties.h @@ -43,8 +43,8 @@ class TitleBlockProperties: public PropertiesInterface { QDomElement toXml(QDomDocument &xml_document) const override; bool fromXml(const QDomElement &) override; - void toSettings(QSettings &, const QString & = QString()) const; - void fromSettings(QSettings &, const QString & = QString()); + void toSettings(QSettings &, const QString & = QString()) const override; + void fromSettings(const QSettings &, const QString & = QString()) override; void setAutoPageNum(QString autonum) {auto_page_num = autonum;} From 6080a7b9c9a03225d1f0c7d058ebd3792062a4af Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Mon, 14 Sep 2020 21:21:32 +0200 Subject: [PATCH 04/34] WIP --- .../qetgraphicshandleritem.h | 2 +- sources/borderproperties.cpp | 14 +-- sources/borderproperties.h | 16 ++-- sources/conductorproperties.cpp | 28 +++--- sources/conductorproperties.h | 27 +++--- sources/diagram.cpp | 4 +- sources/diagram.h | 2 +- sources/diagramprintdialog.cpp | 1 - sources/diagramprintdialog.h | 2 +- sources/editor/graphicspart/partarc.cpp | 2 + .../graphicspart/partdynamictextfield.cpp | 16 ++-- .../graphicspart/partdynamictextfield.h | 2 +- sources/properties/propertiesinterface.cpp | 92 ++++++++++++++----- sources/properties/propertiesinterface.h | 16 ++-- sources/properties/terminaldata.cpp | 34 +++---- sources/properties/terminaldata.h | 10 +- sources/properties/xrefproperties.cpp | 4 +- sources/qetgraphicsitem/conductor.cpp | 31 +++---- sources/qetgraphicsitem/conductor.h | 14 +-- .../qetgraphicsitem/dynamicelementtextitem.h | 2 +- sources/qetgraphicsitem/element.cpp | 34 ++++--- .../qetgraphicsitem/elementtextitemgroup.cpp | 1 + .../qetgraphicsitem/elementtextitemgroup.h | 2 +- .../qetgraphicsitem/independenttextitem.cpp | 1 + sources/qetgraphicsitem/qetgraphicsitem.cpp | 5 +- sources/qetgraphicsitem/qetgraphicsitem.h | 8 +- sources/qetgraphicsitem/qetshapeitem.cpp | 1 + sources/qetgraphicsitem/terminal.cpp | 19 ++-- sources/qetgraphicsitem/terminal.h | 11 ++- sources/titleblock/helpercell.cpp | 7 +- sources/titleblock/helpercell.h | 8 +- sources/titleblock/splittedhelpercell.h | 1 + sources/titleblockproperties.cpp | 12 +-- sources/titleblockproperties.h | 6 +- 34 files changed, 237 insertions(+), 198 deletions(-) diff --git a/sources/QetGraphicsItemModeler/qetgraphicshandleritem.h b/sources/QetGraphicsItemModeler/qetgraphicshandleritem.h index 48f1bfc1d..99fcbc4ef 100644 --- a/sources/QetGraphicsItemModeler/qetgraphicshandleritem.h +++ b/sources/QetGraphicsItemModeler/qetgraphicshandleritem.h @@ -46,7 +46,7 @@ class QetGraphicsHandlerItem : public QGraphicsItem QRectF m_handler_rect, m_br; qreal m_size; - QColor m_color; + QColor m_color{Qt::black}; QPen m_pen; public: diff --git a/sources/borderproperties.cpp b/sources/borderproperties.cpp index 57e0de57a..cdd111027 100644 --- a/sources/borderproperties.cpp +++ b/sources/borderproperties.cpp @@ -32,15 +32,7 @@ - 17 colonnes affichees de 60.0 px de large pour 20.0px de haut - 8 lignes affichees de 80.0 px de haut pour 20.0px de large */ -BorderProperties::BorderProperties() : - columns_count(17), - columns_width(60.0), - columns_header_height(20.0), - display_columns(true), - rows_count(8), - rows_height(80.0), - rows_header_width(20.0), - display_rows(true) +BorderProperties::BorderProperties() { } @@ -103,11 +95,12 @@ QDomElement BorderProperties::toXml(QDomDocument &dom_doc) const { e.appendChild(createXmlProperty(dom_doc, "rows", rows_count)); e.appendChild(createXmlProperty(dom_doc, "rowsize", rows_height)); e.appendChild(createXmlProperty(dom_doc, "displayrows", display_rows)); + e.appendChild(createXmlProperty(dom_doc, "displaycols", display_columns)); return e; } -/** +/**RETURNS True @brief BorderProperties::fromXml - Import dimensions from XML attributes of element e - Importe les dimensions a partir des attributs XML de l'element e @@ -137,6 +130,7 @@ bool BorderProperties::valideXml(QDomElement& e) { propertyBool(e, "displaycols") == PropertyFlags::Success || propertyBool(e, "displayrows") == PropertyFlags::Success) return true; + return false; } /** diff --git a/sources/borderproperties.h b/sources/borderproperties.h index 3fdde4d2a..34e0ead08 100644 --- a/sources/borderproperties.h +++ b/sources/borderproperties.h @@ -46,14 +46,14 @@ class BorderProperties : public PropertiesInterface { static BorderProperties defaultProperties(); // attributes - int columns_count; ///< Columns count - qreal columns_width; ///< Columns width - qreal columns_header_height; ///< Column headers height - bool display_columns; ///< Whether to display column headers + int columns_count{17}; ///< Columns count + qreal columns_width{60.0}; ///< Columns width + qreal columns_header_height{20.0}; ///< Column headers height + bool display_columns{true}; ///< Whether to display column headers - int rows_count; ///< Rows count - qreal rows_height; ///< Rows height - qreal rows_header_width; ///< Row headers width - bool display_rows; ///< Whether to display row headers + int rows_count{8}; ///< Rows count + qreal rows_height{80.0}; ///< Rows height + qreal rows_header_width{20.0}; ///< Row headers width + bool display_rows{true}; ///< Whether to display row headers }; #endif diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index f70e7b2db..a4a593a18 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -22,11 +22,7 @@ /** Constructeur par defaut */ -SingleLineProperties::SingleLineProperties() : - hasGround(true), - hasNeutral(true), - is_pen(false), - phases(1) +SingleLineProperties::SingleLineProperties() { } @@ -282,9 +278,7 @@ QDomElement ConductorProperties::toXml(QDomDocument& doc) const QDomElement e = doc.createElement("defaultconductor"); e.appendChild(createXmlProperty(doc, "type", typeToString(type))); - - if (color != QColor(Qt::black)) - e.appendChild(createXmlProperty(doc, "color", color)); + e.appendChild(createXmlProperty(doc, "color", color)); e.appendChild(createXmlProperty(doc, "bicolor", m_bicolor)); e.appendChild(createXmlProperty(doc, "color2", m_color_2)); @@ -294,7 +288,7 @@ QDomElement ConductorProperties::toXml(QDomDocument& doc) const e.appendChild(singleLineProperties.toXml(doc)); e.appendChild(createXmlProperty(doc, "num", text)); - e.appendChild(createXmlProperty(doc, "text_color", text_color.name())); + e.appendChild(createXmlProperty(doc, "text_color", text_color)); e.appendChild(createXmlProperty(doc, "formula", m_formula)); e.appendChild(createXmlProperty(doc, "function", m_function)); e.appendChild(createXmlProperty(doc, "tension_protocol", m_tension_protocol)); @@ -319,7 +313,7 @@ QDomElement ConductorProperties::toXml(QDomDocument& doc) const } -/** +/** RETURNS True * @brief ConductorProperties::fromXml * Import conductor propertie, from the attribute of the xml element 'e' * @param e the xml document @@ -328,9 +322,9 @@ bool ConductorProperties::fromXml(const QDomElement &e) { // get conductor color propertyColor(e, "color", &color); - propertyBool(e, "bicolor", &m_bicolor, false); + propertyBool(e, "bicolor", &m_bicolor); propertyColor(e, "color2", &m_color_2); - propertyInteger(e, "dash-size", &m_dash_size, 1); + propertyInteger(e, "dash-size", &m_dash_size); // read style of conductor readStyle(e.attribute("style")); @@ -356,10 +350,10 @@ bool ConductorProperties::fromXml(const QDomElement &e) 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, 9); - propertyDouble(e, "condsize", &cond_size, 1); - propertyBool(e, "displaytext", &m_show_text, true); - propertyBool(e, "onetextperfolio", &m_one_text_per_folio, 0); + 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); @@ -376,6 +370,8 @@ bool ConductorProperties::fromXml(const QDomElement &e) //@TODO remove this code for qet 0.6 or later if (type_t == "simple") m_show_text = false; + + return true; } bool ConductorProperties::valideXml(QDomElement& e) { diff --git a/sources/conductorproperties.h b/sources/conductorproperties.h index 6435e15d6..c0ed758cb 100644 --- a/sources/conductorproperties.h +++ b/sources/conductorproperties.h @@ -45,17 +45,17 @@ class SingleLineProperties: public PropertiesInterface { void fromSettings(const QSettings &, const QString & = QString()) override; /// Whether the singleline conductor should display the ground symbol - bool hasGround; + bool hasGround{true}; /// Whether the singleline conductor should display the neutral symbol - bool hasNeutral; + bool hasNeutral{true}; /// Protective Earth Neutral: visually merge neutral and ground - bool is_pen; + bool is_pen{false}; int operator==(const SingleLineProperties &) const; int operator!=(const SingleLineProperties &) const; private: - unsigned short int phases; + unsigned short int phases{1}; void drawGround (QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawNeutral(QPainter *, QET::ConductorSegmentType, QPointF, qreal); void drawPen(QPainter *, QET::ConductorSegmentType, QPointF, qreal); @@ -80,11 +80,12 @@ class ConductorProperties: public PropertiesInterface //Attributes - ConductorType type; + ConductorType type{ConductorType::Single}; - QColor color, - m_color_2, - text_color; + // TODO: set default values! + QColor color{QColor(Qt::black)}, + m_color_2{QColor(Qt::black)}, + text_color{QColor(Qt::black)}; QString text, m_function, @@ -93,21 +94,21 @@ class ConductorProperties: public PropertiesInterface m_wire_section, m_formula; - int text_size, + int text_size{9}, m_dash_size = 1; - double cond_size, + double cond_size{1}, verti_rotate_text, horiz_rotate_text; - bool m_show_text, - m_one_text_per_folio, + bool m_show_text{true}, + m_one_text_per_folio{true}, m_bicolor = false; Qt::Alignment m_horizontal_alignment = Qt::AlignBottom, m_vertical_alignment = Qt::AlignRight; - Qt::PenStyle style; + Qt::PenStyle style{Qt::PenStyle::SolidLine}; SingleLineProperties singleLineProperties; diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 952c1a5a7..ebadb836d 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -924,9 +924,11 @@ Terminal* findTerminal(int conductor_index, QDomElement& f, QHash m_elmt_unitfolio_max; QHash m_elmt_tenfolio_max; diff --git a/sources/diagramprintdialog.cpp b/sources/diagramprintdialog.cpp index 33cd0d3e8..a672dec2f 100644 --- a/sources/diagramprintdialog.cpp +++ b/sources/diagramprintdialog.cpp @@ -41,7 +41,6 @@ DiagramPrintDialog::DiagramPrintDialog(QETProject *project, QWidget *parent) : // orientation paysage par defaut printer_ -> setOrientation(QPrinter::Landscape); - backup_diagram_background_color = Diagram::background_color; Diagram::background_color = Qt::white; } diff --git a/sources/diagramprintdialog.h b/sources/diagramprintdialog.h index aa3b61537..941067953 100644 --- a/sources/diagramprintdialog.h +++ b/sources/diagramprintdialog.h @@ -88,6 +88,6 @@ class DiagramPrintDialog : public QWidget QLineEdit *filepath_field_; QPushButton *browse_button_; QDialogButtonBox *buttons_; - QColor backup_diagram_background_color; + QColor backup_diagram_background_color{Diagram::background_color}; }; #endif diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index ba1716a7f..4e1f26cb9 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -139,6 +139,8 @@ bool PartArc::fromXml(const QDomElement &qde) { if (propertyDouble(qde, "angle", &m_span_angle) == PropertyFlags::NoValidConversion) return false; m_span_angle *= 16; + + return true; } bool PartArc::valideXml(QDomElement& element) { diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp index e04b007bc..b044d2a12 100644 --- a/sources/editor/graphicspart/partdynamictextfield.cpp +++ b/sources/editor/graphicspart/partdynamictextfield.cpp @@ -160,12 +160,12 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt) return false; } - double x, y, z, rot; + double x=0, y=0, z=0, rot=0; - if (propertyDouble(dom_elmt, "x", &x, 0) == PropertyFlags::NoValidConversion || - propertyDouble(dom_elmt, "y", &y, 0) == PropertyFlags::NoValidConversion || - propertyDouble(dom_elmt, "z", &z, 0) == PropertyFlags::NoValidConversion || - propertyDouble(dom_elmt, "rotation", &rot, 0) == PropertyFlags::NoValidConversion) + 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) return false; QGraphicsTextItem::setPos(x, y); @@ -182,12 +182,12 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt) setFont(QETApp::dynamicTextsItemFont(9)); } - propertyUuid(dom_elmt, "uuid", &m_uuid, QUuid::createUuid()); + propertyUuid(dom_elmt, "uuid", &m_uuid); bool frame; propertyBool(dom_elmt, "frame", &frame); double text_width; - propertyDouble(dom_elmt, "text_width", &text_width, -1); + propertyDouble(dom_elmt, "text_width", &text_width, true, -1); setTextWidth(text_width); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); @@ -226,6 +226,8 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt) QDomElement dom_color = dom_elmt.firstChildElement("color"); if(!dom_color.isNull()) setColor(QColor(dom_color.text())); + + return true; } bool PartDynamicTextField::valideXml(QDomElement& dom_elmt) { diff --git a/sources/editor/graphicspart/partdynamictextfield.h b/sources/editor/graphicspart/partdynamictextfield.h index b6e008b62..fd9b5e8cc 100644 --- a/sources/editor/graphicspart/partdynamictextfield.h +++ b/sources/editor/graphicspart/partdynamictextfield.h @@ -117,7 +117,7 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart m_info_name, m_composite_text; DynamicElementTextItem::TextFrom m_text_from = DynamicElementTextItem::UserText; - QUuid m_uuid; + QUuid m_uuid{QUuid::createUuid()}; bool m_frame = false, m_first_add = true, m_block_alignment = false; diff --git a/sources/properties/propertiesinterface.cpp b/sources/properties/propertiesinterface.cpp index 7fd25dc1a..731783731 100644 --- a/sources/properties/propertiesinterface.cpp +++ b/sources/properties/propertiesinterface.cpp @@ -17,6 +17,8 @@ */ #include "propertiesinterface.h" +#include + /*! * Available property types */ @@ -46,6 +48,14 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QStr return p; } +QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const char* value) const { + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", stringS); + p.setAttribute("value", value); + return p; +} + QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const int value) const { QDomElement p = doc.createElement("property"); p.setAttribute("name", name); @@ -112,14 +122,18 @@ bool PropertiesInterface::attribute(const QDomElement& e, const QString& attribu if (p.isNull()) { // check if legacy property is available, // where the property is inside the element as attribute - if (!e.hasAttribute(attribute_name)) + 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) + 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"); @@ -136,20 +150,23 @@ bool PropertiesInterface::attribute(const QDomElement& e, const QString& attribu * \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, int defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QDomElement &e, const QString& attribute_name, int* entier, bool setDefaultValue, int defaultValue) { QString attr; if (!attribute(e, attribute_name, integerS, &attr)) { - *entier = defaultValue; + if (entier && setDefaultValue) + *entier = defaultValue; return PropertyFlags::NotFound; } // verifie la validite de l'attribut bool ok; int tmp = attr.toInt(&ok); - if (!ok) + if (!ok) { + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr; return PropertyFlags::NoValidConversion; + } if (entier != nullptr) *entier = tmp; @@ -157,20 +174,23 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QD return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel, double defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel, bool setDefaultValue, double defaultValue) { QString attr; if (!attribute(e, attribute_name, doubleS, &attr)) { - *reel = defaultValue; + if (reel && setDefaultValue) + *reel = defaultValue; return PropertyFlags::NotFound; } // verifie la validite de l'attribut bool ok; double tmp = attr.toDouble(&ok); - if (!ok) + if (!ok) { + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << doubleS << ". value: " << attr; return PropertyFlags::NoValidConversion; + } if (reel != nullptr) *reel = tmp; @@ -178,20 +198,29 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDo return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean, bool defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean, bool setDefaultValue, bool defaultValue) { QString attr; - if (!attribute(e, attribute_name, integerS, &attr)) { - *boolean = defaultValue; + if (!attribute(e, attribute_name, boolS, &attr)) { + if (boolean && setDefaultValue) + *boolean = defaultValue; return PropertyFlags::NotFound; } // verifie la validite de l'attribut bool ok; bool tmp = attr.toInt(&ok); - if (!ok) - return PropertyFlags::NoValidConversion; + if (!ok) { + if (attr == "true") + tmp = true; + else if (attr == "false") + tmp = false; + else { + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr; + return PropertyFlags::NoValidConversion; + } + } if (boolean != nullptr) *boolean = tmp; @@ -199,19 +228,22 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color, QColor defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color, bool setDefaultValue, QColor defaultValue) { QString attr; if (!attribute(e, attribute_name, colorS, &attr)) { - *color = defaultValue; + if (color && setDefaultValue) + *color = defaultValue; return PropertyFlags::NotFound; } // verifie la validite de l'attribut QColor tmp = QColor(attr); - if (!tmp.isValid()) + if (!tmp.isValid()) { + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << colorS << ". value: " << attr; return PropertyFlags::NoValidConversion; + } if (color != nullptr) *color = tmp; @@ -219,25 +251,33 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDom return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid, QUuid defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid, bool setDefaultValue, QUuid defaultValue) { QString attr; if (!attribute(e, attribute_name, uuidS, &attr)) { - *uuid = defaultValue; + if (uuid && setDefaultValue) + *uuid = defaultValue; return PropertyFlags::NotFound; } + if (QUuid(attr).isNull()){ + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << uuidS << ". value: " << attr; + return PropertyFlags::NoValidConversion; + } + + if (uuid != nullptr) *uuid = QUuid(attr); return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string, QString defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string, bool setDefaultValue, QString defaultValue) { QString attr; if (!attribute(e, attribute_name, stringS, &attr)) { - *string = defaultValue; + if (string && setDefaultValue) + *string = defaultValue; return PropertyFlags::NotFound; } @@ -263,6 +303,8 @@ bool PropertiesInterface::validXmlProperty(const QDomElement& e) { if (!e.hasAttribute("value")) return false; + + return true; } /** @@ -275,10 +317,12 @@ bool PropertiesInterface::validXmlProperty(const QDomElement& e) { */ Qet::Orientation PropertiesInterface::orientationFromString(const QString &s) { QChar c = s[0]; - if (c == 'e') return(Qet::East); - else if (c == 's') return(Qet::South); - else if (c == 'w') return (Qet::West); - else return(Qet::North); + // in some cases/ old projects? (affuteuse_250h.qet) numbers instead of characters are + // used for the orientation + if (c == 'e' || c == '1') return(Qet::East); + else if (c == 's' || c == '2') return(Qet::South); + else if (c == 'w' || c == '3') return (Qet::West); + else return(Qet::North); // c == '0' } /** diff --git a/sources/properties/propertiesinterface.h b/sources/properties/propertiesinterface.h index ecb7d18b9..1419598bf 100644 --- a/sources/properties/propertiesinterface.h +++ b/sources/properties/propertiesinterface.h @@ -46,6 +46,7 @@ class PropertiesInterface * Use this functions to add properties to the xml document */ QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QString value) const; + QDomElement createXmlProperty(QDomDocument &doc, const QString& name, const char* value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value) const; QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const; @@ -62,12 +63,15 @@ class PropertiesInterface // = 4 }; - static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, int defaultValue = std::numeric_limits::quiet_NaN()); - static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr, double defaultValue = std::numeric_limits::quiet_NaN()); - static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr, QString defaultValue = QString()); - static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool defaultValue = false); - static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr, QUuid defaultValue = QUuid()); - static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr, QColor defaultValue = QColor()); + /*! + * Try not using the default Value feature. It is better to initialize the class members in the class definition! + */ + static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, bool setDefaultValue = false, int defaultValue = std::numeric_limits::quiet_NaN()); + static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr, bool setDefaultValue = false, double defaultValue = std::numeric_limits::quiet_NaN()); + static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr, bool setDefaultValue = false, QString defaultValue = QString()); + static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool setDefaultValue = false, bool defaultValue = false); + static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr, bool setDefaultValue = false, QUuid defaultValue = QUuid()); + static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr, bool setDefaultValue = false, QColor defaultValue = QColor()); static bool validXmlProperty(const QDomElement& e); diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 5d3a72779..1adec26ee 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -45,42 +45,41 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x())); xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y())); - xml_element.appendChild(createXmlProperty(xml_document, "uuid", m_uuid.toString())); + xml_element.appendChild(createXmlProperty(xml_document, "uuid", m_uuid)); xml_element.appendChild(createXmlProperty(xml_document, "name", m_name)); xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation))); return(xml_element); } -bool TerminalData::fromXml (const QDomElement &xml_element) +bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True { // lit la position de la borne qreal term_x = 0.0, term_y = 0.0; - if (!propertyDouble(xml_element, "x", &term_x)) + if (propertyDouble(xml_element, "x", &term_x)) return false; - if (!propertyDouble(xml_element, "y", &term_y)) + if (propertyDouble(xml_element, "y", &term_y)) return false; m_pos = QPointF(term_x, term_y); //emit posFromXML(QPointF(term_x, term_y)); - QString uuid; - if (!propertyString(xml_element, "uuid", &uuid)) - return false; - + QUuid uuid; // 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 - if (!uuid.isEmpty()) + if (propertyUuid(xml_element, "uuid", &uuid) == PropertyFlags::Success) m_uuid = QUuid(uuid); - if (!propertyString(xml_element, "name", &m_name)) - return false; + + //if (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" QString o; - if (!propertyString(xml_element, "orientation", &o)) + if (propertyString(xml_element, "orientation", &o)) return false; // lit l'orientation de la borne @@ -89,18 +88,19 @@ bool TerminalData::fromXml (const QDomElement &xml_element) return true; } -bool TerminalData::valideXml(QDomElement& xml_element) { +bool TerminalData::valideXml(const QDomElement& xml_element) { if (propertyDouble(xml_element, "x")) return false; if (propertyDouble(xml_element, "y")) return false; - if (propertyString(xml_element, "uuid")) - return false; + // legacy elements do not have an uuid +// if (propertyUuid(xml_element, "uuid")) +// return false; - if (propertyString(xml_element, "name")) - return false; + //if (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")) return false; diff --git a/sources/properties/terminaldata.h b/sources/properties/terminaldata.h index 5c747dfe4..ead7fa627 100644 --- a/sources/properties/terminaldata.h +++ b/sources/properties/terminaldata.h @@ -35,7 +35,7 @@ public: QDomElement toXml(QDomDocument &xml_element) const override; bool fromXml(const QDomElement &xml_element) override; - static bool valideXml(QDomElement &xml_element); + static bool valideXml(const QDomElement &xml_element); // must be public, because this class is a private member of PartTerminal/Terminal and they must // access this data @@ -44,12 +44,12 @@ public: * \brief m_orientation * Orientation of the terminal */ - Qet::Orientation m_orientation; + Qet::Orientation m_orientation{Qet::Orientation::North}; /*! * \brief second_point * Position of the second point of the terminal in scene coordinates */ - QPointF second_point; + QPointF second_point{0,0}; /*! * \brief m_uuid * Uuid of the terminal. @@ -60,7 +60,7 @@ public: * uuid, the conductor after updating the part is anymore valid. So if in the loaded document a uuid exists, * use this one and don't create a new one. */ - QUuid m_uuid; + QUuid m_uuid; // default is an invalid uuid. /*! * \brief m_name * Name of the element. It can be used to create wiring harness tables @@ -73,7 +73,7 @@ public: * Important: this variable is only updated during read from xml and not during mouse move! * It is used to store the initial position so that PartTerminal and Terminal have access to it. */ - QPointF m_pos; + QPointF m_pos{0,0}; private: QGraphicsObject* q{nullptr}; }; diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index b8f4f6bc6..9c4abc0f3 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -116,14 +116,14 @@ QDomElement XRefProperties::toXml(QDomDocument &xml_document) const { return xml_element; } -/** +/** RETURNS True * @brief XRefProperties::fromXml * Load from xml * @param xml_element: QDomElement to use for load */ bool XRefProperties::fromXml(const QDomElement &xml_element) { - if (!propertyBool(xml_element, "showpowerctc", &m_show_power_ctc)) + if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc)) return false; QString display; diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 3be915975..f99a8a8ab 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -76,14 +76,7 @@ class ConductorXmlRetroCompatibility */ Conductor::Conductor(Terminal *p1, Terminal* p2) : terminal1(p1), - terminal2(p2), - m_mouse_over(false), - m_text_item(nullptr), - segments(nullptr), - m_moving_segment(false), - modified_path(false), - has_to_save_profile(false), - must_highlight_(Conductor::None) + terminal2(p2) { //set Zvalue at 11 to be upper than the DiagramImageItem and element setZValue(11); @@ -574,13 +567,13 @@ ConductorTextItem *Conductor::textItem() const { */ bool Conductor::valideXml(QDomElement &e){ - // TODO: seems to short! (see fromXML) - if (propertyDouble(e, "x") || - propertyDouble(e, "y")) - return false; +// // TODO: seems to short! (see fromXML) +// if (propertyDouble(e, "x") || +// propertyDouble(e, "y")) +// return false; - if (propertyBool(e, "freezeLabel")) - return false; +// if (propertyBool(e, "freezeLabel")) +// return false; return true; } @@ -956,8 +949,11 @@ void Conductor::pointsToSegments(const QList& points_list) { bool Conductor::fromXml(const QDomElement &dom_element) { // TODO: seems to short! - setPos(dom_element.attribute("x", nullptr).toDouble(), - dom_element.attribute("y", nullptr).toDouble()); + double x, y; + propertyDouble(dom_element, "x", &x); + propertyDouble(dom_element, "y", &y); + + setPos(x, y); bool return_ = pathFromXml(dom_element); @@ -971,8 +967,7 @@ bool Conductor::fromXml(const QDomElement &dom_element) else m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers")); - m_freeze_label = dom_element.attribute("freezeLabel") == "true"? true : false; - + propertyBool(dom_element, "freezeLabel", &m_freeze_label, false); setProperties(pr); return return_; diff --git a/sources/qetgraphicsitem/conductor.h b/sources/qetgraphicsitem/conductor.h index 5abc62620..59d484737 100644 --- a/sources/qetgraphicsitem/conductor.h +++ b/sources/qetgraphicsitem/conductor.h @@ -156,28 +156,28 @@ class Conductor : public QGraphicsObject, public PropertiesInterface QVector m_handler_vector; int m_vector_index = -1; - bool m_mouse_over; + bool m_mouse_over{false}; /// Functional properties ConductorProperties m_properties; /// Text input for non simple, non-singleline conductors - ConductorTextItem *m_text_item; + ConductorTextItem *m_text_item{nullptr}; /// Segments composing the conductor - ConductorSegment *segments; + ConductorSegment *segments{nullptr}; /// Attributs related to mouse interaction - bool m_moving_segment; + bool m_moving_segment{false}; int moved_point; qreal m_previous_z_value; ConductorSegment *m_moved_segment; QPointF before_mov_text_pos_; /// Whether the conductor was manually modified by users - bool modified_path; + bool modified_path{false}; /// Whether the current profile should be saved as soon as possible - bool has_to_save_profile; + bool has_to_save_profile{false}; /// conductor profile: "photography" of what the conductor is supposed to look /// like - there is one profile per kind of traject ConductorProfilesGroup conductor_profiles; /// Define whether and how the conductor should be highlighted - Highlight must_highlight_; + Highlight must_highlight_{Conductor::None}; bool m_valid; bool m_freeze_label = false; diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.h b/sources/qetgraphicsitem/dynamicelementtextitem.h index 69e03a94b..53e4d3b14 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.h +++ b/sources/qetgraphicsitem/dynamicelementtextitem.h @@ -150,7 +150,7 @@ class DynamicElementTextItem : public DiagramTextItem QMetaObject::Connection m_report_formula_con; QList m_formula_connection, m_update_slave_Xref_connection; - QColor m_user_color; + QColor m_user_color{QColor()}; bool m_frame = false, m_first_scene_change = true; CrossRefItem *m_Xref_item = nullptr; diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 5bc29dc0e..622fb258f 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -65,6 +65,7 @@ class ElementXmlRetroCompatibility /** * @brief Element::Element + * New element from xml * @param location, location of this element * @param parent, parent graphics item * @param state, state of the instanciation @@ -83,6 +84,7 @@ Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *s } } int elmt_state; + qDebug() << "\tCollection Path: " << location.collectionPath(); buildFromXml(location.xml(), &elmt_state); if (state) { *state = elmt_state; @@ -438,12 +440,16 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state) QDomElement qde = n.toElement(); if (qde.isNull()) continue; + + qDebug() << "\t\tElement.cpp:buildFromXml;parseElement: " << qde.tagName(); if (parseElement(qde)) { + qDebug() << "\t\t\tParsing Element success"; ++ parsed_elements_count; } else { + qDebug() << "\t\t\tParsing Element no success"; if (state) *state = 7; m_state = QET::GIOK; @@ -467,13 +473,11 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state) m_state = QET::GIOK; return(false); } - else - { - if (state) - *state = 0; - m_state = QET::GIOK; - return(true); - } + + if (state) + *state = 0; + m_state = QET::GIOK; + return(true); } /** @@ -570,11 +574,11 @@ DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element Terminal *Element::parseTerminal(const QDomElement &dom_element) { - TerminalData* data = new TerminalData(); - if (!data->fromXml(dom_element)) { - delete data; + if (!TerminalData::valideXml(dom_element)) return nullptr; - } + + TerminalData* data = new TerminalData(); + data->fromXml(dom_element); Terminal *new_terminal = new Terminal(data, this); m_terminals << new_terminal; @@ -643,17 +647,20 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool QHash priv_id_adr; int terminals_non_trouvees = 0; - foreach(QGraphicsItem *qgi, childItems()) { + // The added childs from the collection now must match with the terminals from the diagram. Iterate through + // all Terminals in the collection and in the diagram to link them together + foreach(QGraphicsItem *qgi, childItems()) { // Where the Terminals are added as childs? if (Terminal *p = qgraphicsitem_cast(qgi)) { bool terminal_trouvee = false; foreach(QDomElement qde, liste_terminals) { if (p -> fromXml(qde)) { + qDebug() << "Matching Terminal found."; priv_id_adr.insert(qde.attribute("id").toInt(), p); terminal_trouvee = true; // We used to break here, because we did not expect // several terminals to share the same position. // Of course, it finally happened. - } + } } if (!terminal_trouvee) ++ terminals_non_trouvees; } @@ -661,6 +668,7 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool if (terminals_non_trouvees > 0) { + qDebug() << "element.cpp: Element::fromXML; Elements not found: " << terminals_non_trouvees; m_state = QET::GIOK; return(false); } diff --git a/sources/qetgraphicsitem/elementtextitemgroup.cpp b/sources/qetgraphicsitem/elementtextitemgroup.cpp index cb2207ed4..213138f7c 100644 --- a/sources/qetgraphicsitem/elementtextitemgroup.cpp +++ b/sources/qetgraphicsitem/elementtextitemgroup.cpp @@ -384,6 +384,7 @@ QDomElement ElementTextItemGroup::toXml(QDomDocument &dom_document) const return dom_element; } +// TOOD: inherit from propertiesinterface /** * @brief ElementTextItemGroup::fromXml * Import data of this group from xml diff --git a/sources/qetgraphicsitem/elementtextitemgroup.h b/sources/qetgraphicsitem/elementtextitemgroup.h index 46c8e43f1..aa0a71c38 100644 --- a/sources/qetgraphicsitem/elementtextitemgroup.h +++ b/sources/qetgraphicsitem/elementtextitemgroup.h @@ -108,7 +108,7 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup // TODO: m_hold_to_bottom_of_page = false, m_block_alignment_update = false, m_frame = false; - QPointF m_initial_position; + QPointF m_initial_position{QPointF(0,0)}; int m_vertical_adjustment = 0; CrossRefItem *m_Xref_item = nullptr; Element *m_parent_element = nullptr; diff --git a/sources/qetgraphicsitem/independenttextitem.cpp b/sources/qetgraphicsitem/independenttextitem.cpp index eaed3351e..99b11cb43 100644 --- a/sources/qetgraphicsitem/independenttextitem.cpp +++ b/sources/qetgraphicsitem/independenttextitem.cpp @@ -49,6 +49,7 @@ IndependentTextItem::IndependentTextItem(const QString &text) : IndependentTextItem::~IndependentTextItem() { } +// TODO: inherit from PropertiesInterface /** Permet de lire le texte a mettre dans le champ a partir d'un element XML. Cette methode se base sur la position du champ pour assigner ou non la diff --git a/sources/qetgraphicsitem/qetgraphicsitem.cpp b/sources/qetgraphicsitem/qetgraphicsitem.cpp index 51e6736d8..73111639f 100644 --- a/sources/qetgraphicsitem/qetgraphicsitem.cpp +++ b/sources/qetgraphicsitem/qetgraphicsitem.cpp @@ -25,10 +25,7 @@ * @param parent, Parent Item */ QetGraphicsItem::QetGraphicsItem(QGraphicsItem *parent): - QGraphicsObject(parent), - is_movable_(true), - m_first_move(true), - snap_to_grid_(true) + QGraphicsObject(parent) {} QetGraphicsItem::~QetGraphicsItem() diff --git a/sources/qetgraphicsitem/qetgraphicsitem.h b/sources/qetgraphicsitem/qetgraphicsitem.h index 3f4fb7070..cf30e6098 100644 --- a/sources/qetgraphicsitem/qetgraphicsitem.h +++ b/sources/qetgraphicsitem/qetgraphicsitem.h @@ -53,10 +53,10 @@ class QetGraphicsItem : public QGraphicsObject void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; protected: - bool is_movable_; - bool m_first_move; - bool snap_to_grid_; - QPointF m_mouse_to_origin_movement; + bool is_movable_{true}; + bool m_first_move{true}; + bool snap_to_grid_{true}; + QPointF m_mouse_to_origin_movement{QPointF(0,0)}; QET::GraphicsItemState m_state = QET:: GIOK; }; diff --git a/sources/qetgraphicsitem/qetshapeitem.cpp b/sources/qetgraphicsitem/qetshapeitem.cpp index 20208a32c..a65686296 100644 --- a/sources/qetgraphicsitem/qetshapeitem.cpp +++ b/sources/qetgraphicsitem/qetshapeitem.cpp @@ -830,6 +830,7 @@ void QetShapeItem::handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraph } } +// TODO: inherit from Propertiesinterface! /** * @brief QetShapeItem::fromXml * Build this item from the xml description diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 28bd89f52..d1433edd0 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -41,8 +41,6 @@ const qreal Terminal::Z = 1000; @param name of terminal */ void Terminal::init(QString number, QString name, bool hiddenName) { - - hovered_color_ = Terminal::neutralColor; // calcul de la position du point d'amarrage a l'element dock_elmt_ = d->m_pos; @@ -62,11 +60,9 @@ void Terminal::init(QString number, QString name, bool hiddenName) { // QRectF null br_ = new QRectF(); - previous_terminal_ = nullptr; // divers setAcceptHoverEvents(true); setAcceptedMouseButtons(Qt::LeftButton); - hovered_ = false; setToolTip(QObject::tr("Borne", "tooltip")); setZValue(Z); } @@ -753,7 +749,7 @@ bool Terminal::valideXml(QDomElement &terminal) { return false; QString o; - if (!propertyString(terminal, "orientation", &o)) + if (propertyString(terminal, "orientation", &o)) return false; Qet::Orientation terminal_or = orientationFromString(o); @@ -767,7 +763,7 @@ bool Terminal::valideXml(QDomElement &terminal) { return true; } -/** +/** RETURNS True @brief Terminal::fromXml Permet de savoir si un element XML represente cette borne. Attention, l'element XML n'est pas verifie @@ -795,11 +791,12 @@ bool Terminal::fromXml(const QDomElement &terminal) { if (propertyString(terminal, "orientation", &o)) return false; - return ( - qFuzzyCompare(x, dock_elmt_.x()) && - qFuzzyCompare(y, dock_elmt_.y()) && - (orientationFromString(o) == d->m_orientation) - ); + if (!qFuzzyCompare(x, dock_elmt_.x()) || + !qFuzzyCompare(y, dock_elmt_.y()) || + orientationFromString(o) != d->m_orientation) + return false; + + return true; } /** diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index 36160cedc..1f7f365ab 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -109,9 +109,10 @@ class Terminal : public QGraphicsObject, public PropertiesInterface static const qreal terminalSize; static const qreal Z; - // Various static colors used for hover effects + // Various static colors used for hover effects. + // The assignement is in the cpp file /// default color - static QColor neutralColor; + static QColor neutralColor; /// color for legal actions static QColor allowedColor; /// color for allowed but fuzzy or not recommended actions @@ -140,11 +141,11 @@ class Terminal : public QGraphicsObject, public PropertiesInterface */ QRectF *br_{nullptr}; /// Last terminal seen through an attached conductor - Terminal *previous_terminal_; + Terminal *previous_terminal_{nullptr}; /// Whether the mouse pointer is hovering the terminal - bool hovered_; + bool hovered_{false}; /// Color used for the hover effect - QColor hovered_color_; + QColor hovered_color_{Terminal::hovered_color_}; /// Number of Terminal QString number_terminal_; /// Name of Terminal diff --git a/sources/titleblock/helpercell.cpp b/sources/titleblock/helpercell.cpp index 45b46bca7..64f51cdda 100644 --- a/sources/titleblock/helpercell.cpp +++ b/sources/titleblock/helpercell.cpp @@ -23,12 +23,7 @@ */ HelperCell::HelperCell(QGraphicsItem *parent) : QGraphicsObject(parent), - QGraphicsLayoutItem(), - background_color(Qt::white), - foreground_color(Qt::black), - label(), - orientation(Qt::Horizontal), - index(-1) + QGraphicsLayoutItem() { setGraphicsItem(this); setFlag(QGraphicsItem::ItemIsSelectable, false); diff --git a/sources/titleblock/helpercell.h b/sources/titleblock/helpercell.h index 5763d7390..a93e217cc 100644 --- a/sources/titleblock/helpercell.h +++ b/sources/titleblock/helpercell.h @@ -37,11 +37,11 @@ class HelperCell : public QGraphicsObject, public QGraphicsLayoutItem { // attributes public: - QColor background_color; ///< Background color when rendering this cell - QColor foreground_color; ///< Text color when rendering this cell + QColor background_color{Qt::white}; ///< Background color when rendering this cell + QColor foreground_color{Qt::black}; ///< Text color when rendering this cell QString label; ///< Label displayed in this cell - Qt::Orientation orientation; ///< Orientation of this cell - int index; ///< Index of this cell + Qt::Orientation orientation{Qt::Horizontal}; ///< Orientation of this cell + int index{-1}; ///< Index of this cell // methods public: diff --git a/sources/titleblock/splittedhelpercell.h b/sources/titleblock/splittedhelpercell.h index ca60b45dd..11b887c97 100644 --- a/sources/titleblock/splittedhelpercell.h +++ b/sources/titleblock/splittedhelpercell.h @@ -36,6 +36,7 @@ class SplittedHelperCell : public HelperCell { void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override; // attributes + // colors are set in the constructor QColor split_background_color; ///< Background color on the split side QColor split_foreground_color; ///< Text color on the split side QString split_label; ///< Text displayed on the split side diff --git a/sources/titleblockproperties.cpp b/sources/titleblockproperties.cpp index 35e98945c..876c18589 100644 --- a/sources/titleblockproperties.cpp +++ b/sources/titleblockproperties.cpp @@ -23,11 +23,7 @@ Constructeur. Initialise un objet TitleBlockProperties avec tous les champs vides (date vide + useDate a UseDateValue). */ -TitleBlockProperties::TitleBlockProperties() : - date(), - useDate(UseDateValue), - display_at(Qt::BottomEdge), - collection (QET::QetCollection::Common) +TitleBlockProperties::TitleBlockProperties() { } @@ -87,7 +83,8 @@ QDomElement TitleBlockProperties::toXml(QDomDocument &xml_document) const { e.appendChild(createXmlProperty(xml_document, "folio", folio)); e.appendChild(createXmlProperty(xml_document, "auto_page_num", auto_page_num)); e.appendChild(createXmlProperty(xml_document, "date", exportDate())); - e.appendChild(createXmlProperty(xml_document, "displayAt", display_at == Qt::BottomEdge? "bottom" : "right")); + QString disp_at = display_at == Qt::BottomEdge? "bottom" : "right"; + e.appendChild(createXmlProperty(xml_document, "displayAt", disp_at)); if (!template_name.isEmpty()) { @@ -104,7 +101,7 @@ QDomElement TitleBlockProperties::toXml(QDomDocument &xml_document) const { return e; } -/** +/** RETURNS True Importe le cartouche a partir des attributs XML de l'element e @param e Element XML dont les attributs seront lus */ @@ -141,6 +138,7 @@ bool TitleBlockProperties::fromXml(const QDomElement &e) { foreach (QDomElement e, QET::findInDomElement(e, "properties")) { context.fromXml(e); } + return true; } /** diff --git a/sources/titleblockproperties.h b/sources/titleblockproperties.h index df49cc783..3634df4dc 100644 --- a/sources/titleblockproperties.h +++ b/sources/titleblockproperties.h @@ -63,11 +63,11 @@ class TitleBlockProperties: public PropertiesInterface { QString version; ///< Version (displayed by the default template) QString folio; ///< Folio information (displayed by the default template) QString auto_page_num; - DateManagement useDate; ///< Wheter to use the date attribute + DateManagement useDate{UseDateValue}; ///< Wheter to use the date attribute QString template_name; ///< Name of the template used to render the title block - an empty string means "the default template provided by the application" DiagramContext context; ///< Container for the additional, user-defined fields - Qt::Edge display_at; ///< Edge to display the titleblock - QET::QetCollection collection; /// Date: Mon, 28 Sep 2020 15:42:57 +0200 Subject: [PATCH 05/34] fix wrong position of segments when loading file. This was, because not the segment property is asked, but the parent and this will not work additionally support legacy orientation --- sources/qetgraphicsitem/conductor.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index f99a8a8ab..73047a0c6 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -1102,11 +1102,21 @@ bool Conductor::pathFromXml(const QDomElement &e) { // le segment doit avoir une longueur qreal segment_length; - if (propertyDouble(e, "length", & segment_length)) + if (propertyDouble(current_segment, "length", & segment_length)) continue; - bool isHorizontal; - propertyBool(e, "orientation", &isHorizontal); + bool isHorizontal = false; + if (propertyBool(current_segment, "orientation", &isHorizontal) == PropertyFlags::NoValidConversion) { + // legacy + QString orientation; + if (propertyString(current_segment, "orientation", &orientation) == PropertyFlags::Success) { + if (orientation == "horizontal") + isHorizontal = true; + } else { + qDebug() << "PathFromXML failed"; + return false; + } + } if (isHorizontal) { segments_x << segment_length; From adc28d32b9f81d6d8e718532c6ec91efc1c2bdb5 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Mon, 28 Sep 2020 16:29:09 +0200 Subject: [PATCH 06/34] revert saving title block properties in it's own child, because it makes more sense directly in the diagram --- sources/bordertitleblock.cpp | 2 +- sources/bordertitleblock.h | 2 +- sources/diagram.cpp | 4 +- sources/qetgraphicsitem/conductor.cpp | 2 +- sources/titleblockproperties.cpp | 53 +++++++++++++-------------- sources/titleblockproperties.h | 3 +- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/sources/bordertitleblock.cpp b/sources/bordertitleblock.cpp index 9d954c9fd..6a50c7ea3 100644 --- a/sources/bordertitleblock.cpp +++ b/sources/bordertitleblock.cpp @@ -168,7 +168,7 @@ QRectF BorderTitleBlock::insideBorderRect() const Exports the title block current values to XML. @param xml_elmt the XML element attributes will be added to */ -void BorderTitleBlock::titleBlockToXml(QDomDocument& doc) { +void BorderTitleBlock::titleBlockToXml(QDomElement& doc) { exportTitleBlock().toXml(doc); } diff --git a/sources/bordertitleblock.h b/sources/bordertitleblock.h index 9a892e931..325b67254 100644 --- a/sources/bordertitleblock.h +++ b/sources/bordertitleblock.h @@ -152,7 +152,7 @@ class BorderTitleBlock : public QObject void setPreviousFolioNum(const QString &previous); void setNextFolioNum(const QString &next); - void titleBlockToXml(QDomDocument &doc); + void titleBlockToXml(QDomElement &doc); void titleBlockFromXml(const QDomElement &); void borderToXml(QDomElement &); void borderFromXml(const QDomElement &); diff --git a/sources/diagram.cpp b/sources/diagram.cpp index ebadb836d..42df251c7 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -625,7 +625,7 @@ QDomDocument Diagram::toXml(bool whole_content) { // proprietes du schema if (whole_content) { // TODO: compare with old version - border_and_titleblock.titleBlockToXml(document); + border_and_titleblock.titleBlockToXml(dom_root); border_and_titleblock.borderToXml(dom_root); // Default conductor properties @@ -940,7 +940,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf } // Load border and titleblock - border_and_titleblock.titleBlockFromXml(root); + border_and_titleblock.titleBlockFromXml(root); border_and_titleblock.borderFromXml(root); // Find the element "defaultconductor". diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 73047a0c6..f0f0a5046 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -999,7 +999,7 @@ QDomElement Conductor::toXml(QDomDocument & doc) const { foreach(ConductorSegment *segment, segmentsList()) { current_segment = doc.createElement("segment"); - current_segment.appendChild(createXmlProperty(doc, "orientation", segment->isHorizontal())); + current_segment.appendChild(createXmlProperty(doc, "orientation", segment->isHorizontal() ? "horizontal": "vertical")); current_segment.appendChild(createXmlProperty(doc, "length", segment -> length())); dom_element.appendChild(current_segment); } diff --git a/sources/titleblockproperties.cpp b/sources/titleblockproperties.cpp index 876c18589..c27339e2b 100644 --- a/sources/titleblockproperties.cpp +++ b/sources/titleblockproperties.cpp @@ -69,36 +69,35 @@ bool TitleBlockProperties::operator!=(const TitleBlockProperties &ip) { Exporte le cartouche sous formes d'attributs XML ajoutes a l'element e. @param e Element XML auquel seront ajoutes des attributs */ -QDomElement TitleBlockProperties::toXml(QDomDocument &xml_document) const { +void TitleBlockProperties::toXml(QDomElement &e) const { - QDomElement e = xml_document.createElement("inset"); + e.setAttribute("author", author); + e.setAttribute("title", title); + e.setAttribute("filename", filename); + e.setAttribute("plant", plant); + e.setAttribute("locmach", locmach); + e.setAttribute("indexrev",indexrev); + e.setAttribute("version", version); + e.setAttribute("folio", folio); + e.setAttribute("auto_page_num", auto_page_num); + e.setAttribute("date", exportDate()); + e.setAttribute("displayAt", (display_at == Qt::BottomEdge? "bottom" : "right")); + if (!template_name.isEmpty()) + { + e.setAttribute("titleblocktemplate", template_name); + e.setAttribute("titleblocktemplateCollection", QET::qetCollectionToString(collection)); + } - e.appendChild(createXmlProperty(xml_document, "author", author)); - e.appendChild(createXmlProperty(xml_document, "title", title)); - e.appendChild(createXmlProperty(xml_document, "filename", filename)); - e.appendChild(createXmlProperty(xml_document, "plant", plant)); - e.appendChild(createXmlProperty(xml_document, "locmach", locmach)); - e.appendChild(createXmlProperty(xml_document, "indexrev", indexrev)); - e.appendChild(createXmlProperty(xml_document, "version", version)); - e.appendChild(createXmlProperty(xml_document, "folio", folio)); - e.appendChild(createXmlProperty(xml_document, "auto_page_num", auto_page_num)); - e.appendChild(createXmlProperty(xml_document, "date", exportDate())); - QString disp_at = display_at == Qt::BottomEdge? "bottom" : "right"; - e.appendChild(createXmlProperty(xml_document, "displayAt", disp_at)); + if (context.keys().count()) { + QDomElement properties = e.ownerDocument().createElement("properties"); + context.toXml(properties); + e.appendChild(properties); + } +} - if (!template_name.isEmpty()) - { - e.appendChild(createXmlProperty(xml_document, "titleblocktemplate", template_name)); - e.appendChild(createXmlProperty(xml_document, "titleblocktemplateCollection", QET::qetCollectionToString(collection))); - } - - if (context.keys().count()) { - QDomElement properties = e.ownerDocument().createElement("properties"); - context.toXml(properties); - e.appendChild(properties); - } - - return e; +QDomElement TitleBlockProperties::toXml(QDomDocument &d) const { + qDebug() << "NOT IMPLEMENTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; + return QDomElement(); } /** RETURNS True diff --git a/sources/titleblockproperties.h b/sources/titleblockproperties.h index 3634df4dc..26daba62b 100644 --- a/sources/titleblockproperties.h +++ b/sources/titleblockproperties.h @@ -41,7 +41,8 @@ class TitleBlockProperties: public PropertiesInterface { bool operator==(const TitleBlockProperties &); bool operator!=(const TitleBlockProperties &); - QDomElement toXml(QDomDocument &xml_document) const override; + QDomElement toXml(QDomDocument &e) const override; + void toXml(QDomElement &e) const; bool fromXml(const QDomElement &) override; void toSettings(QSettings &, const QString & = QString()) const override; void fromSettings(const QSettings &, const QString & = QString()) override; From 27a63bbf2be8aacdbbc0abbd3574e7c67c4c8b18 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 1 Oct 2020 14:38:08 +0200 Subject: [PATCH 07/34] WIP --- sources/diagram.cpp | 9 ++- sources/editor/graphicspart/partterminal.cpp | 1 + sources/properties/propertiesinterface.cpp | 4 +- sources/properties/terminaldata.cpp | 4 +- sources/qetgraphicsitem/conductor.cpp | 17 ++-- sources/qetgraphicsitem/element.cpp | 10 +-- sources/qetgraphicsitem/terminal.cpp | 82 ++++++++------------ sources/qetgraphicsitem/terminal.h | 14 +--- 8 files changed, 56 insertions(+), 85 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 42df251c7..6aaa20cf3 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -907,6 +907,7 @@ Terminal* findTerminal(int conductor_index, QDomElement& f, QHash createElement(element_location, nullptr, &state); + Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, nullptr, &state); // read element definition! if (state) { QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(state); @@ -1085,7 +1086,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements); Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements); - if (p1 && p2 && p1 != p2) + if (p1 && p2 && p1 != p2) // why the condition for unequal is required? { Conductor *c = new Conductor(p1, p2); if (c->isValid()) @@ -1096,7 +1097,9 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf } else delete c; - } + } else { + qDebug() << "Diagramm::fromXML(): No matching terminals found."; + } } //Load tables diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 47b9d8cf7..a1ac1c486 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -28,6 +28,7 @@ PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) : CustomElementGraphicPart(editor, parent) { d = new TerminalData(this); + d->m_name = tr("terminal"); d->m_orientation = Qet::North; d->m_uuid = QUuid::createUuid(); // if part is loaded this uuid will be overwritten, but being sure that terminal has a uuid updateSecondPoint(); diff --git a/sources/properties/propertiesinterface.cpp b/sources/properties/propertiesinterface.cpp index 731783731..7d96e8513 100644 --- a/sources/properties/propertiesinterface.cpp +++ b/sources/properties/propertiesinterface.cpp @@ -212,9 +212,9 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE bool ok; bool tmp = attr.toInt(&ok); if (!ok) { - if (attr == "true") + if (attr == "true" || attr == "1") tmp = true; - else if (attr == "false") + else if (attr == "false" || attr == "0") tmp = false; else { qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr; diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 1adec26ee..5594f34c6 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -41,7 +41,7 @@ void TerminalData::fromSettings(const QSettings& settings, const QString&) QDomElement TerminalData::toXml(QDomDocument &xml_document) const { - QDomElement xml_element = xml_document.createElement("terminal"); + QDomElement xml_element = xml_document.createElement("terminaldata"); xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x())); xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y())); @@ -64,7 +64,7 @@ bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True m_pos = QPointF(term_x, term_y); - //emit posFromXML(QPointF(term_x, term_y)); +// emit posFromXML(QPointF(term_x, term_y)); QUuid uuid; // update part and add uuid, which is used in the new version to connect terminals together diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index f0f0a5046..b87138a5a 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -1106,16 +1106,13 @@ bool Conductor::pathFromXml(const QDomElement &e) { continue; bool isHorizontal = false; - if (propertyBool(current_segment, "orientation", &isHorizontal) == PropertyFlags::NoValidConversion) { - // legacy - QString orientation; - if (propertyString(current_segment, "orientation", &orientation) == PropertyFlags::Success) { - if (orientation == "horizontal") - isHorizontal = true; - } else { - qDebug() << "PathFromXML failed"; - return false; - } + QString orientation; + if (propertyString(current_segment, "orientation", &orientation) == PropertyFlags::Success) { + if (orientation == "horizontal") + isHorizontal = true; + } else { + qDebug() << "PathFromXML failed"; + return false; } if (isHorizontal) { diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 622fb258f..7ff42a6d6 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -574,13 +574,11 @@ DynamicElementTextItem *Element::parseDynamicText(const QDomElement &dom_element Terminal *Element::parseTerminal(const QDomElement &dom_element) { - if (!TerminalData::valideXml(dom_element)) + if (!Terminal::valideXml(dom_element)) return nullptr; - - TerminalData* data = new TerminalData(); - data->fromXml(dom_element); - Terminal *new_terminal = new Terminal(data, this); + Terminal *new_terminal = new Terminal(0, 0, Qet::Orientation::North, this); + new_terminal->fromXml(dom_element); m_terminals << new_terminal; //Sort from top to bottom and left to rigth @@ -653,7 +651,7 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool if (Terminal *p = qgraphicsitem_cast(qgi)) { bool terminal_trouvee = false; foreach(QDomElement qde, liste_terminals) { - if (p -> fromXml(qde)) { + if (p -> fromXml(qde)) { // TODO: is there validXML enough? Because the Terminal was already read in the ElementCreation function qDebug() << "Matching Terminal found."; priv_id_adr.insert(qde.attribute("id").toInt(), p); terminal_trouvee = true; diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index d1433edd0..51923ed0e 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -54,7 +54,7 @@ void Terminal::init(QString number, QString name, bool hiddenName) { // Number of terminal number_terminal_ = std::move(number); // Name of terminal - name_terminal_ = std::move(name); + d->m_name = std::move(name); name_terminal_hidden = hiddenName; // par defaut : pas de conducteur @@ -193,10 +193,18 @@ void Terminal::setNumber(QString number) { @param name */ void Terminal::setName(QString name, bool hiddenName) { - name_terminal_ = std::move(name); + d->m_name = std::move(name); name_terminal_hidden = hiddenName; } +/** + @brief Terminal::name + @return the name of terminal. +*/ +inline QString Terminal::name() const { + return(d->m_name); +} + /** @brief Terminal::addConductor Add a conductor to this terminal @@ -715,13 +723,17 @@ QList Terminal::conductors() const { QDomElement Terminal::toXml(QDomDocument &doc) const { QDomElement qdo = doc.createElement("terminal"); - qdo.appendChild(createXmlProperty(doc, "x", dock_elmt_.x())); - qdo.appendChild(createXmlProperty(doc, "y", dock_elmt_.y())); - qdo.appendChild(createXmlProperty(doc, "orientation", orientationToString(d->m_orientation))); qdo.appendChild(createXmlProperty(doc, "number", number_terminal_)); - qdo.appendChild(createXmlProperty(doc, "name", name_terminal_)); qdo.appendChild(createXmlProperty(doc, "nameHidden", name_terminal_hidden)); + // store terminal data too! + + // Do not store terminal data in its own child + QDomElement terminalDataElement = d->toXml(doc); + for (int i=0; i < terminalDataElement.childNodes().length(); i++) { + qdo.appendChild(terminalDataElement.childNodes().at(i)); + } + return(qdo); } @@ -731,32 +743,17 @@ QDomElement Terminal::toXml(QDomDocument &doc) const { @param terminal Le QDomElement a analyser @return true si le QDomElement passe en parametre est une borne, false sinon */ -bool Terminal::valideXml(QDomElement &terminal) { +bool Terminal::valideXml(const QDomElement &terminal) { if (terminal.tagName() != "terminal") return(false); - if (propertyString(terminal, "number")) - return false; +// affuteuse_250h.qet contains in line 8398 terminals which do not have this +// if (propertyString(terminal, "number")) +// return false; +// affuteuse_250h.qet contains in line 8398 terminals which do not have this +// if (propertyBool(terminal, "nameHidden")) +// return false; - if (propertyString(terminal, "name")) - return false; - - if (propertyBool(terminal, "nameHidden")) - return false; - - if (propertyDouble(terminal, "x")) - return false; - if (propertyDouble(terminal, "y")) - return false; - - QString o; - if (propertyString(terminal, "orientation", &o)) - return false; - - Qet::Orientation terminal_or = orientationFromString(o); - if (terminal_or != Qet::North - && terminal_or != Qet::South - && terminal_or != Qet::East - && terminal_or != Qet::West) + if (!TerminalData::valideXml(terminal)) return false; // a ce stade, la borne est syntaxiquement correcte @@ -772,30 +769,15 @@ bool Terminal::valideXml(QDomElement &terminal) { (memes coordonnes, meme orientation), false sinon */ bool Terminal::fromXml(const QDomElement &terminal) { - if (propertyString(terminal, "number", &number_terminal_)) + propertyString(terminal, "number", &number_terminal_); + + propertyBool(terminal, "nameHidden", &name_terminal_hidden); + + if(!d->fromXml(terminal)) return false; - if (propertyString(terminal, "name", &name_terminal_)) - return false; - - if (propertyBool(terminal, "nameHidden", &name_terminal_hidden)) - return false; - - double x, y; - if (propertyDouble(terminal, "x", &x)) - return false; - if (propertyDouble(terminal, "y", &y)) - return false; - - QString o; - if (propertyString(terminal, "orientation", &o)) - return false; - - if (!qFuzzyCompare(x, dock_elmt_.x()) || - !qFuzzyCompare(y, dock_elmt_.y()) || - orientationFromString(o) != d->m_orientation) - return false; + init(number_terminal_, d->m_name, name_terminal_hidden); // initialize dock_elmt_. This must be done after Terminal data is initialized return true; } diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index 1f7f365ab..8a06733f9 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -90,7 +90,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface bool canBeLinkedTo(Terminal *); // methods related to XML import/export - static bool valideXml(QDomElement &); + static bool valideXml(const QDomElement &); bool fromXml (const QDomElement &) override; QDomElement toXml (QDomDocument &) const override; @@ -148,9 +148,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface QColor hovered_color_{Terminal::hovered_color_}; /// Number of Terminal QString number_terminal_; - /// Name of Terminal - QString name_terminal_; - bool name_terminal_hidden; + bool name_terminal_hidden{true}; private: void init(QString number, QString name, bool hiddenName); @@ -174,14 +172,6 @@ inline QString Terminal::number() const { return(number_terminal_); } -/** - @brief Terminal::name - @return the name of terminal. -*/ -inline QString Terminal::name() const { - return(name_terminal_); -} - QList relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram = true); From 10e767c3e0bdd901dcdddd3c210bffc118e83235 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 1 Oct 2020 16:28:48 +0200 Subject: [PATCH 08/34] add comments --- sources/diagram.cpp | 9 +++++---- sources/qetgraphicsitem/element.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 6aaa20cf3..81bd564a8 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -1009,10 +1009,10 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf } } } - //Load all elements from the XML + //Load all elements from the collection in the XML QList added_elements; QHash table_adr_id; - foreach (QDomElement element_xml, QET::findInDomElement(root, "elements", "element")) + foreach (QDomElement element_xml, QET::findInDomElement(root, "elements", "element")) // read all elements from the diagram { if (!Element::valideXml(element_xml)) continue; @@ -1027,7 +1027,8 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf } int state = 0; - Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, nullptr, &state); // read element definition! + // Create element from the collection + Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, nullptr, &state); // read element definition from the collection! if (state) { QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(state); @@ -1038,7 +1039,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf addItem(nvel_elmt); //Loading fail, remove item from the diagram - if (!nvel_elmt->fromXml(element_xml, table_adr_id, handle_inputs_rotation)) + if (!nvel_elmt->fromXml(element_xml, table_adr_id, handle_inputs_rotation)) // load element definition from the diagram { removeItem(nvel_elmt); delete nvel_elmt; diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 7ff42a6d6..2df97d364 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -85,7 +85,7 @@ Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *s } int elmt_state; qDebug() << "\tCollection Path: " << location.collectionPath(); - buildFromXml(location.xml(), &elmt_state); + buildFromXml(location.xml(), &elmt_state); // build from the collection definition if (state) { *state = elmt_state; } @@ -338,7 +338,7 @@ void Element::drawHighlight(QPainter *painter, const QStyleOptionGraphicsItem *o /** * @brief Element::buildFromXml - * Build this element from an xml description + * Build this element from an xml description (from the collection) * @param xml_def_elmt * @param state * Optional pointer which define the status of build @@ -638,7 +638,7 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool les bornes vont maintenant etre recensees pour associer leurs id a leur adresse reelle ce recensement servira lors de la mise en place des fils */ - QList liste_terminals; + QList liste_terminals; // terminals in the element in the diagram foreach(QDomElement qde, QET::findInDomElement(e, "terminals", "terminal")) { if (Terminal::valideXml(qde)) liste_terminals << qde; } @@ -647,7 +647,7 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool int terminals_non_trouvees = 0; // The added childs from the collection now must match with the terminals from the diagram. Iterate through // all Terminals in the collection and in the diagram to link them together - foreach(QGraphicsItem *qgi, childItems()) { // Where the Terminals are added as childs? + for(QGraphicsItem *qgi: childItems()) { // TODO: Where the Terminals are added as childs? if (Terminal *p = qgraphicsitem_cast(qgi)) { bool terminal_trouvee = false; foreach(QDomElement qde, liste_terminals) { From 91a56799a7332a8a7414bd33350d875826626759 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 1 Oct 2020 16:31:15 +0200 Subject: [PATCH 09/34] Solves problem that terminals are not placed at the correct place --- sources/qetgraphicsitem/element.cpp | 10 ++++++++-- sources/qetgraphicsitem/terminal.cpp | 8 ++++++++ sources/qetgraphicsitem/terminal.h | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 2df97d364..fbb04347d 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -650,8 +650,14 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool for(QGraphicsItem *qgi: childItems()) { // TODO: Where the Terminals are added as childs? if (Terminal *p = qgraphicsitem_cast(qgi)) { bool terminal_trouvee = false; - foreach(QDomElement qde, liste_terminals) { - if (p -> fromXml(qde)) { // TODO: is there validXML enough? Because the Terminal was already read in the ElementCreation function + for(QDomElement qde: liste_terminals) { + Terminal diagramTerminal(0,0, Qet::Orientation::East); + diagramTerminal.fromXml(qde); + QPointF dockPos1 = diagramTerminal.originPos(); // position here is directly the dock_elmt_ position (stored in the diagram) + QPointF dockPos2 = p->dockPos(); + if (qFuzzyCompare(dockPos1.x(), dockPos2.x()) && + qFuzzyCompare(dockPos1.y(), dockPos2.y()) && + p->orientation() == diagramTerminal.orientation()) { // check if the part in the collection is the same as in the diagram stored qDebug() << "Matching Terminal found."; priv_id_adr.insert(qde.attribute("id").toInt(), p); terminal_trouvee = true; diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 51923ed0e..8b44f5440 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -811,6 +811,14 @@ QUuid Terminal::uuid() const { return d->m_uuid; } +QPointF Terminal::dockPos() { + return dock_elmt_; +} + +QPointF Terminal::originPos() { + return d->m_pos; +} + /** @brief Conductor::relatedPotentialTerminal Return terminal at the same potential from the same diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index 8a06733f9..6b153e0c7 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -77,6 +77,8 @@ class Terminal : public QGraphicsObject, public PropertiesInterface Diagram *diagram () const; Element *parentElement () const; QUuid uuid () const; + QPointF dockPos(); + QPointF originPos(); QList conductors() const; Qet::Orientation orientation() const; From 9e54137224fef784a4f7070b168a33362a6986b1 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 1 Oct 2020 16:39:12 +0200 Subject: [PATCH 10/34] add explanation --- sources/qetgraphicsitem/element.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index fbb04347d..425bd1271 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -651,6 +651,9 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool if (Terminal *p = qgraphicsitem_cast(qgi)) { bool terminal_trouvee = false; for(QDomElement qde: liste_terminals) { + // The position in the collection element definition is the origin position (originPos). + // The position in the diagram element definition is the position where the conductor is connected (dock position) + // Therefore a simple operator overloading is not possible. Terminal diagramTerminal(0,0, Qet::Orientation::East); diagramTerminal.fromXml(qde); QPointF dockPos1 = diagramTerminal.originPos(); // position here is directly the dock_elmt_ position (stored in the diagram) From a92683f3fa26ec2c4e11cef13f265d6a0a71939f Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 1 Oct 2020 16:51:17 +0200 Subject: [PATCH 11/34] add comment --- sources/qetgraphicsitem/element.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 425bd1271..7982e454f 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -443,7 +443,7 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state) qDebug() << "\t\tElement.cpp:buildFromXml;parseElement: " << qde.tagName(); - if (parseElement(qde)) { + if (parseElement(qde)) { // TODO: why lines are not parsed here? qDebug() << "\t\t\tParsing Element success"; ++ parsed_elements_count; } From 15ca6096ca3d7f6b9155f382dc95bbe8a56dbab7 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Fri, 2 Oct 2020 14:56:15 +0200 Subject: [PATCH 12/34] rename f to conductor for better readability --- sources/diagram.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 81bd564a8..bf37c2bd3 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -872,14 +872,14 @@ bool Diagram::initFromXml(QDomElement &document, QPointF position, bool consider * \param added_elements Elements found in the xml file * \return */ -Terminal* findTerminal(int conductor_index, QDomElement& f, QHash& table_adr_id, QList& added_elements) { +Terminal* findTerminal(int conductor_index, QDomElement& conductor, QHash& table_adr_id, QList& added_elements) { assert(conductor_index == 1 || conductor_index == 2); QString element_index = "element" + QString::number(conductor_index); QString terminal_index = "terminal" + QString::number(conductor_index); - if (f.hasAttribute(element_index)) { - QUuid element_uuid = QUuid(f.attribute(element_index)); + if (conductor.hasAttribute(element_index)) { + QUuid element_uuid = QUuid(conductor.attribute(element_index)); // 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; @@ -887,7 +887,7 @@ Terminal* findTerminal(int conductor_index, QDomElement& f, QHashuuid() != element_uuid) continue; element_found = true; - QUuid terminal_uuid = QUuid(f.attribute(terminal_index)); + QUuid terminal_uuid = QUuid(conductor.attribute(terminal_index)); for (auto terminal: element->terminals()) { if (terminal->uuid() != terminal_uuid) continue; @@ -901,7 +901,7 @@ Terminal* findTerminal(int conductor_index, QDomElement& f, QHash Date: Fri, 2 Oct 2020 14:57:06 +0200 Subject: [PATCH 13/34] write uuid only in partterminal to xml, because in the other case it is not needed --- sources/editor/graphicspart/partterminal.cpp | 21 +++++++++++++++++++- sources/properties/terminaldata.cpp | 9 ++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index a1ac1c486..2b0ca4d8b 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -44,6 +44,14 @@ PartTerminal::~PartTerminal() { @param xml_elmt Element XML a lire */ bool PartTerminal::fromXml(const QDomElement &xml_elmt) { + + QUuid uuid; + // 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 + if (propertyUuid(xml_elmt, "uuid", &uuid) == PropertyFlags::Success) + d->m_uuid = QUuid(uuid); + if (!d->fromXml(xml_elmt)) return false; @@ -59,7 +67,18 @@ bool PartTerminal::fromXml(const QDomElement &xml_elmt) { @return un element XML decrivant la borne */ QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { - return d->toXml(xml_document); + + QDomElement qdo = xml_document.createElement("terminal"); + + qdo.appendChild(createXmlProperty(xml_document, "uuid", d->m_uuid)); + + // Do not store terminal data in its own child + QDomElement terminalDataElement = d->toXml(xml_document); + for (int i=0; i < terminalDataElement.childNodes().length(); i++) { + qdo.appendChild(terminalDataElement.childNodes().at(i)); + } + + return qdo; } bool PartTerminal::valideXml(QDomElement& element) { diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 5594f34c6..59a6f2ae2 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -45,7 +45,6 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x())); xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y())); - xml_element.appendChild(createXmlProperty(xml_document, "uuid", m_uuid)); xml_element.appendChild(createXmlProperty(xml_document, "name", m_name)); xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation))); @@ -66,12 +65,8 @@ bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True // emit posFromXML(QPointF(term_x, term_y)); - QUuid uuid; - // 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 - if (propertyUuid(xml_element, "uuid", &uuid) == PropertyFlags::Success) - m_uuid = QUuid(uuid); + // do not write uuid from this class, because only PartTerminal::fromXml need + // to write it to xml file. Terminal::fromXml does not need. //if (propertyString(xml_element, "name", &m_name)) From c8691b243bc890b68c7e043b528ad16fcc98085a Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Fri, 2 Oct 2020 14:58:33 +0200 Subject: [PATCH 14/34] if no uuid for the terminal is available, use write the id of the terminal to the xml file, otherwise no connection can be done after saving --- sources/qetgraphicsitem/conductor.cpp | 26 ++++++++++++++++++++++---- sources/qetgraphicsitem/element.cpp | 5 +++++ sources/qetgraphicsitem/terminal.cpp | 8 ++++++++ sources/qetgraphicsitem/terminal.h | 5 +++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index b87138a5a..e4567b0ec 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -982,11 +982,29 @@ QDomElement Conductor::toXml(QDomDocument & doc) const { dom_element.appendChild(createXmlProperty(doc, "y", pos().y())); // Terminal is uniquely identified by the uuid of the terminal and the element - dom_element.appendChild(createXmlProperty(doc, "element1", terminal1->parentElement()->uuid())); - dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal1->uuid())); + QUuid terminal = terminal1->uuid(); + QUuid terminalParent = terminal1->parentElement()->uuid(); + if (terminalParent.isNull() || terminal.isNull()) { + // legacy when the terminal does not have a valid uuid + // do not store element1 information, because this is used to determine in the fromXml + // process that legacy file format + dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal1->ID())); + } else { + dom_element.appendChild(createXmlProperty(doc, "element1", terminalParent)); + dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal)); + } - dom_element.appendChild(createXmlProperty(doc, "element2", terminal2->parentElement()->uuid())); - dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid())); + terminal = terminal2->uuid(); + terminalParent = terminal2->parentElement()->uuid(); + if (terminalParent.isNull() || terminal.isNull()) { + // legacy when the terminal does not have a valid uuid + // do not store element1 information, because this is used to determine in the fromXml + // process that legacy file format + dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->ID())); + } else { + dom_element.appendChild(createXmlProperty(doc, "element2", terminal2->parentElement()->uuid())); + dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid())); + } dom_element.appendChild(createXmlProperty(doc, "freezeLabel", m_freeze_label)); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 7982e454f..e2d8169f1 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -662,6 +662,11 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool qFuzzyCompare(dockPos1.y(), dockPos2.y()) && p->orientation() == diagramTerminal.orientation()) { // check if the part in the collection is the same as in the diagram stored qDebug() << "Matching Terminal found."; + // store id for legacy purpose, because when opening a old project in the collection the terminal does not have an uuid. Therefore the id must be used + if (p->uuid().isNull()) { + p->setID(qde.attribute("id").toInt()); + } + priv_id_adr.insert(qde.attribute("id").toInt(), p); terminal_trouvee = true; // We used to break here, because we did not expect diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 8b44f5440..c16e3eee7 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -706,6 +706,10 @@ bool Terminal::canBeLinkedTo(Terminal *other_terminal) return true; } +void Terminal::setID(int id) { + m_id = id; +} + /** @brief Terminal::conductors @return La liste des conducteurs lies a cette borne @@ -811,6 +815,10 @@ QUuid Terminal::uuid() const { return d->m_uuid; } +int Terminal::ID() const { + return m_id; +} + QPointF Terminal::dockPos() { return dock_elmt_; } diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index 6b153e0c7..daf7ac935 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -77,6 +77,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface Diagram *diagram () const; Element *parentElement () const; QUuid uuid () const; + int ID() const; QPointF dockPos(); QPointF originPos(); @@ -90,6 +91,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface void updateConductor(); bool isLinkedTo(Terminal *); bool canBeLinkedTo(Terminal *); + void setID(int id); // methods related to XML import/export static bool valideXml(const QDomElement &); @@ -151,6 +153,9 @@ class Terminal : public QGraphicsObject, public PropertiesInterface /// Number of Terminal QString number_terminal_; bool name_terminal_hidden{true}; + + /// legacy id used by the conductor to find the terminal. From 0.8x on the uuid is used instead. + int m_id{-1}; private: void init(QString number, QString name, bool hiddenName); From 9521a8aa0be4f5c1cd7b01986ef8f00b9dd405d9 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Fri, 2 Oct 2020 15:49:35 +0200 Subject: [PATCH 15/34] WIP --- sources/diagram.cpp | 22 +++++++++++++--------- sources/qetgraphicsitem/terminal.cpp | 1 + 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index bf37c2bd3..0c419722f 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -878,8 +878,8 @@ Terminal* findTerminal(int conductor_index, QDomElement& conductor, QHashuuid() != element_uuid) continue; element_found = true; - QUuid terminal_uuid = QUuid(conductor.attribute(terminal_index)); + QUuid terminal_uuid; + PropertiesInterface::propertyUuid(conductor, terminal_index, &terminal_uuid); for (auto terminal: element->terminals()) { if (terminal->uuid() != terminal_uuid) continue; @@ -901,7 +902,10 @@ Terminal* findTerminal(int conductor_index, QDomElement& conductor, QHash added_conductors; - foreach (QDomElement f, QET::findInDomElement(root, "conductors", "conductor")) + foreach (QDomElement conductorElement, QET::findInDomElement(root, "conductors", "conductor")) { - if (!Conductor::valideXml(f)) continue; + if (!Conductor::valideXml(conductorElement)) continue; //Check if terminal that conductor must be linked is know - Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements); - Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements); + Terminal* p1 = findTerminal(1, conductorElement, table_adr_id, added_elements); + Terminal* p2 = findTerminal(2, conductorElement, table_adr_id, added_elements); if (p1 && p2 && p1 != p2) // why the condition for unequal is required? { @@ -1093,7 +1097,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf if (c->isValid()) { addItem(c); - c -> fromXml(f); + c -> fromXml(conductorElement); added_conductors << c; } else diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index c16e3eee7..127cf2241 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -734,6 +734,7 @@ QDomElement Terminal::toXml(QDomDocument &doc) const { // Do not store terminal data in its own child QDomElement terminalDataElement = d->toXml(doc); + int y = terminalDataElement.().length(); // TODO: seems to be not correct! for (int i=0; i < terminalDataElement.childNodes().length(); i++) { qdo.appendChild(terminalDataElement.childNodes().at(i)); } From f3368f159d646a2a1a87b1002a9d5583beb5f17f Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sat, 3 Oct 2020 20:50:08 +0200 Subject: [PATCH 16/34] Fix problem that not all childs were added to the xml document --- sources/editor/graphicspart/partterminal.cpp | 2 +- sources/qetgraphicsitem/terminal.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 2b0ca4d8b..726c5574e 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -75,7 +75,7 @@ QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { // Do not store terminal data in its own child QDomElement terminalDataElement = d->toXml(xml_document); for (int i=0; i < terminalDataElement.childNodes().length(); i++) { - qdo.appendChild(terminalDataElement.childNodes().at(i)); + qdo.appendChild(terminalDataElement.childNodes().at(i).cloneNode()); // cloneNode() is important, otherwise no deep clone is made } return qdo; diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 127cf2241..01ced29ad 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -734,9 +734,11 @@ QDomElement Terminal::toXml(QDomDocument &doc) const { // Do not store terminal data in its own child QDomElement terminalDataElement = d->toXml(doc); - int y = terminalDataElement.().length(); // TODO: seems to be not correct! - for (int i=0; i < terminalDataElement.childNodes().length(); i++) { - qdo.appendChild(terminalDataElement.childNodes().at(i)); + + int childsCount = terminalDataElement.childNodes().count(); + for (int i=0; i < childsCount; i++) { + QDomNode node = terminalDataElement.childNodes().at(i).cloneNode(); // cloneNode() is important, otherwise no deep clone is made + qdo.appendChild(node); } return(qdo); From 9153588c942c8c484838ea392ad8c1a120b1a54b Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sun, 4 Oct 2020 09:33:16 +0200 Subject: [PATCH 17/34] store position when exporting to xml, because terminalData will create the document from m_pos --- sources/editor/graphicspart/partterminal.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index 726c5574e..a957e6fa7 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -72,6 +72,8 @@ QDomElement PartTerminal::toXml(QDomDocument &xml_document) const { qdo.appendChild(createXmlProperty(xml_document, "uuid", d->m_uuid)); + d->m_pos = pos(); + // Do not store terminal data in its own child QDomElement terminalDataElement = d->toXml(xml_document); for (int i=0; i < terminalDataElement.childNodes().length(); i++) { From 871a2642f475cfa85cb1ddfae4f5f19736cf1a43 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sun, 4 Oct 2020 09:34:25 +0200 Subject: [PATCH 18/34] use m_pos as value to store --- sources/properties/terminaldata.cpp | 9 +++++++-- sources/qetgraphicsitem/terminal.cpp | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sources/properties/terminaldata.cpp b/sources/properties/terminaldata.cpp index 59a6f2ae2..b8f65cdcf 100644 --- a/sources/properties/terminaldata.cpp +++ b/sources/properties/terminaldata.cpp @@ -43,13 +43,18 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const { QDomElement xml_element = xml_document.createElement("terminaldata"); - xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x())); - xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y())); + + // m_pos cannot be stored, because in the partterminal it will not be updated. + // In PartTerminal m_pos is the position of the dock, in Terminal m_pos is the second side of the terminal + // This is hold for legacy compability reason + xml_element.appendChild(createXmlProperty(xml_document, "x", m_pos.x())); + xml_element.appendChild(createXmlProperty(xml_document, "y", m_pos.y())); xml_element.appendChild(createXmlProperty(xml_document, "name", m_name)); xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation))); return(xml_element); } + bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True { // lit la position de la borne diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 01ced29ad..e4ca1d626 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -733,7 +733,11 @@ QDomElement Terminal::toXml(QDomDocument &doc) const { // store terminal data too! // Do not store terminal data in its own child + // Bad hack. The problem is that in the diagrams the terminal is described by the position and in the Collection by the dock. + QPointF tempPos = d->m_pos; + d->m_pos = dock_elmt_; QDomElement terminalDataElement = d->toXml(doc); + d->m_pos = tempPos; int childsCount = terminalDataElement.childNodes().count(); for (int i=0; i < childsCount; i++) { From 8829974852e98dd9e08ee5a7a41df26e9e8bdd31 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sun, 4 Oct 2020 09:34:34 +0200 Subject: [PATCH 19/34] add comment --- sources/qetgraphicsitem/element.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index e2d8169f1..5dc73b442 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -577,7 +577,7 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element) if (!Terminal::valideXml(dom_element)) return nullptr; - Terminal *new_terminal = new Terminal(0, 0, Qet::Orientation::North, this); + Terminal *new_terminal = new Terminal(0, 0, Qet::Orientation::North, this); // does not matter which values are typed in here, because they get overwritten by the fromXML() function new_terminal->fromXml(dom_element); m_terminals << new_terminal; From 8ef8a71680fb1a267785582f23a2ed760f5be24a Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Mon, 5 Oct 2020 21:54:26 +0200 Subject: [PATCH 20/34] add comment --- sources/qetgraphicsitem/terminal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index e4ca1d626..6d753b43b 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -30,7 +30,7 @@ QColor Terminal::neutralColor = QColor(Qt::blue); QColor Terminal::allowedColor = QColor(Qt::darkGreen); QColor Terminal::warningColor = QColor("#ff8000"); QColor Terminal::forbiddenColor = QColor(Qt::red); -const qreal Terminal::terminalSize = 4.0; +const qreal Terminal::terminalSize = 4.0; // TODO: store terminalSize in terminaldata, because in PartTerminal there is the same parameter. So only one is needed const qreal Terminal::Z = 1000; /** From 6d2a88e85ff98337b6fd74b8a7d8c8ae2ab63c18 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Tue, 6 Oct 2020 12:48:39 +0200 Subject: [PATCH 21/34] use default value if the parameter is not available --- sources/titleblockproperties.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/titleblockproperties.cpp b/sources/titleblockproperties.cpp index c27339e2b..4f60b2668 100644 --- a/sources/titleblockproperties.cpp +++ b/sources/titleblockproperties.cpp @@ -122,8 +122,8 @@ bool TitleBlockProperties::fromXml(const QDomElement &e) { setDateFromString(date); QString display_at_temp; - propertyString(e, "displayAt", &display_at_temp); - display_at = (display_at_temp == "bottom" ? Qt::BottomEdge : Qt::RightEdge); + if (propertyString(e, "displayAt", &display_at_temp) == 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)) { From beeeb252b4e6a741ede2c5f83e38755206abe112 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Tue, 6 Oct 2020 17:07:16 +0200 Subject: [PATCH 22/34] fix problem of not showing reference labels --- sources/properties/xrefproperties.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index 9c4abc0f3..d82f09318 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -127,24 +127,24 @@ bool XRefProperties::fromXml(const QDomElement &xml_element) { return false; QString display; - propertyString(xml_element, "displayhas", &display, "cross"); + propertyString(xml_element, "displayhas", &display, true, "cross"); display == "cross"? m_display = Cross : m_display = Contacts; QString snap; - propertyString(xml_element, "snapto", &snap, "label"); + propertyString(xml_element, "snapto", &snap, true, "label"); snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label; QString xrefpos; - if (propertyString(xml_element, "xrefpos", &xrefpos, "Left") == PropertyFlags::NotFound) { + if (propertyString(xml_element, "xrefpos", &xrefpos, true, "Left") == PropertyFlags::NotFound) { QMetaEnum var = QMetaEnum::fromType(); m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xrefpos.toStdString().data())); } else m_xref_pos = Qt::AlignBottom; - - propertyInteger(xml_element, "offset", &m_offset, 0); - propertyString(xml_element, "master_label", &m_master_label, "%f-%l%c"); - propertyString(xml_element, "slave_label", &m_slave_label, "(%f-%l%c)"); + // TODO: why it compiles without this true?? + propertyInteger(xml_element, "offset", &m_offset, true, 0); + propertyString(xml_element, "master_label", &m_master_label, true, "%f-%l%c"); + propertyString(xml_element, "slave_label", &m_slave_label, true, "(%f-%l%c)"); QString value; foreach (QString key, m_prefix_keys) { propertyString(xml_element, key + "prefix", &value); From 2d21391a09971fde0a5f7aca3d440559427d1e42 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Tue, 6 Oct 2020 18:44:14 +0200 Subject: [PATCH 23/34] - AlignBottom shoud be the default - move inital values to header file --- sources/properties/xrefproperties.cpp | 33 +++++++++++---------------- sources/properties/xrefproperties.h | 16 ++++++------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index d82f09318..102f674a9 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -25,14 +25,6 @@ */ XRefProperties::XRefProperties() { - m_show_power_ctc = true; - m_display = Cross; - m_snap_to = Bottom; - m_prefix_keys << "power" << "delay" << "switch"; - m_master_label = "%f-%l%c"; - m_slave_label = "(%f-%l%c)"; - m_offset = 0; - m_xref_pos = Qt::AlignBottom; } /** @@ -127,28 +119,29 @@ bool XRefProperties::fromXml(const QDomElement &xml_element) { return false; QString display; - propertyString(xml_element, "displayhas", &display, true, "cross"); - display == "cross"? m_display = Cross : m_display = Contacts; + if (propertyString(xml_element, "displayhas", &display) != PropertyFlags::NotFound) { + display == "cross"? m_display = Cross : m_display = Contacts; + } QString snap; - propertyString(xml_element, "snapto", &snap, true, "label"); - snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label; + if (propertyString(xml_element, "snapto", &snap) != PropertyFlags::NotFound) { + snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label; + } QString xrefpos; - if (propertyString(xml_element, "xrefpos", &xrefpos, true, "Left") == PropertyFlags::NotFound) { + if (propertyString(xml_element, "xrefpos", &xrefpos) != PropertyFlags::NotFound) { QMetaEnum var = QMetaEnum::fromType(); m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xrefpos.toStdString().data())); - } else - m_xref_pos = Qt::AlignBottom; + } // TODO: why it compiles without this true?? - propertyInteger(xml_element, "offset", &m_offset, true, 0); - propertyString(xml_element, "master_label", &m_master_label, true, "%f-%l%c"); - propertyString(xml_element, "slave_label", &m_slave_label, true, "(%f-%l%c)"); + propertyInteger(xml_element, "offset", &m_offset); + propertyString(xml_element, "master_label", &m_master_label); + propertyString(xml_element, "slave_label", &m_slave_label); QString value; foreach (QString key, m_prefix_keys) { - propertyString(xml_element, key + "prefix", &value); - m_prefix.insert(key, value); + if (!propertyString(xml_element, key + "prefix", &value)); + m_prefix.insert(key, value); } return true; } diff --git a/sources/properties/xrefproperties.h b/sources/properties/xrefproperties.h index 9681657f5..4e2180d43 100644 --- a/sources/properties/xrefproperties.h +++ b/sources/properties/xrefproperties.h @@ -76,15 +76,15 @@ class XRefProperties : public PropertiesInterface void setKey(QString& key) {m_key = key;} private: - bool m_show_power_ctc; - DisplayHas m_display; - SnapTo m_snap_to; - Qt::AlignmentFlag m_xref_pos; + bool m_show_power_ctc{true}; + DisplayHas m_display{Cross}; + SnapTo m_snap_to{Bottom}; + Qt::AlignmentFlag m_xref_pos{Qt::AlignBottom}; QHash m_prefix; - QStringList m_prefix_keys; - QString m_master_label; - QString m_slave_label; - int m_offset; + QStringList m_prefix_keys{"power","delay","switch"}; + QString m_master_label{"%f-%l%c"}; + QString m_slave_label{"(%f-%l%c)"}; + int m_offset{0}; QString m_key; }; From b958848194a26cf0a543fda7890834708b98f630 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Tue, 6 Oct 2020 21:40:48 +0200 Subject: [PATCH 24/34] Update conductorproperties.cpp and conductor.cpp --- sources/conductorproperties.cpp | 1 + sources/qetgraphicsitem/conductor.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index a4a593a18..8d8bb7178 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -360,6 +360,7 @@ bool ConductorProperties::fromXml(const QDomElement &e) QMetaEnum me = QMetaEnum::fromType(); QString alinment_temp; + lksjdflj propertyString(e, "horizontal-alignment", &alinment_temp, "AlignBottom"); m_horizontal_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); propertyString(e, "vertical-alignment", &alinment_temp, "AlignRight"); diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index e4567b0ec..64accc001 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -1027,7 +1027,12 @@ QDomElement Conductor::toXml(QDomDocument & doc) const { dom_element.appendChild(dom_seq); // Export the properties and text - dom_element.appendChild(m_properties.toXml(doc)); + QDomElement conductorProperties = m_properties.toXml(doc); + for (int i=0; i < conductorProperties.childNodes().count(); i++) { + QDomNode node = conductorProperties.childNodes().at(i).cloneNode(); // cloneNode() is important! + dom_element.appendChild(node); + } + if(m_text_item->wasMovedByUser()) { dom_element.appendChild(createXmlProperty(doc, "userx", m_text_item->pos().x())); From a1cf3711a1094d343fea8aae7d4a2d68be98b03d Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Wed, 7 Oct 2020 08:05:01 +0200 Subject: [PATCH 25/34] Fix issues --- sources/conductorproperties.cpp | 46 ++++++++++--------- sources/editor/graphicspart/partarc.cpp | 8 ++-- sources/editor/graphicspart/partellipse.cpp | 10 ++-- sources/editor/graphicspart/partline.cpp | 3 -- sources/editor/graphicspart/partline.h | 4 +- sources/editor/graphicspart/partrectangle.cpp | 14 +++--- sources/editor/graphicspart/partterminal.cpp | 3 +- sources/editor/graphicspart/parttext.cpp | 12 ++--- sources/properties/propertiesinterface.h | 2 +- sources/qetgraphicsitem/conductor.cpp | 3 +- sources/titleblockproperties.cpp | 7 +-- 11 files changed, 55 insertions(+), 57 deletions(-) diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 8d8bb7178..22d047a43 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -327,19 +327,28 @@ bool ConductorProperties::fromXml(const QDomElement &e) propertyInteger(e, "dash-size", &m_dash_size); // read style of conductor - readStyle(e.attribute("style")); + QString style_string; + propertyString(e, "style", &style_string); + readStyle(style_string); QString type_t; - propertyString(e, "type", &type_t); - - if (type_t == typeToString(Single)) - { - // get specific properties for single conductor - singleLineProperties.fromXml(e); - type = Single; - } - else - type = Multi; + if (propertyString(e, "type", &type_t) == PropertyFlags::Success) { + if (type_t == typeToString(Single)) + { + // get specific properties for single conductor + singleLineProperties.fromXml(e); + type = Single; + } + else if (type_t == typeToString(Multi)) + type = Multi; + else { + //Keep retrocompatible with version older than 0,4 + //If the propertie @type is simple (removed since QET 0,4), we set text no visible. + //@TODO remove this code for qet 0.6 or later + + if (type_t == "simple") m_show_text = false; + } + } propertyString(e, "num", &text); @@ -360,17 +369,10 @@ bool ConductorProperties::fromXml(const QDomElement &e) QMetaEnum me = QMetaEnum::fromType(); QString alinment_temp; - lksjdflj - propertyString(e, "horizontal-alignment", &alinment_temp, "AlignBottom"); - m_horizontal_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); - propertyString(e, "vertical-alignment", &alinment_temp, "AlignRight"); - m_vertical_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); - - //Keep retrocompatible with version older than 0,4 - //If the propertie @type is simple (removed since QET 0,4), we set text no visible. - //@TODO remove this code for qet 0.6 or later - - if (type_t == "simple") m_show_text = false; + if (propertyString(e, "horizontal-alignment", &alinment_temp, "AlignBottom") == PropertyFlags::Success) + m_horizontal_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); + if (propertyString(e, "vertical-alignment", &alinment_temp, "AlignRight") == PropertyFlags::Success) + m_vertical_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); return true; } diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index 4e1f26cb9..87a23a411 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -122,10 +122,10 @@ bool PartArc::fromXml(const QDomElement &qde) { stylesFromXml(qde); double x, y, w, h; - if (propertyDouble(qde, "x", &x, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y", &y, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "width", &w, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "height", &h, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "x", &x, true, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "y", &y, true, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "width", &w, true, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "height", &h, true, 0) == PropertyFlags::NoValidConversion) return false; m_rect = QRectF(mapFromScene(x, y), QSizeF(w, h) ); diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index ffc75e073..f29358469 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -112,19 +112,19 @@ bool PartEllipse::fromXml(const QDomElement &qde) if (qde.tagName() == "ellipse") { - if (propertyDouble(qde, "width", &width, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "height", &height, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "width", &width, true, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "height", &height, true, 0) == PropertyFlags::NoValidConversion) return false; } else { - if (propertyDouble(qde, "diameter", &width, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "diameter", &width, true, 0) == PropertyFlags::NoValidConversion) return false; height = width; } - if (propertyDouble(qde, "x", &x, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y", &y, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "x", &x, true, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "y", &y, true, 0) == PropertyFlags::NoValidConversion) return false; m_rect = QRectF(mapFromScene(x, y), QSizeF(width, height)); diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index d9a66b196..df7b41b71 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -151,9 +151,6 @@ bool PartLine::fromXml(const QDomElement &qde) { first_end = Qet::endTypeFromString(s); - first_length = 1.5; - second_length = 1.5; - if (propertyDouble(qde, "length1", &first_length) == PropertyFlags::NoValidConversion || propertyDouble(qde, "length2", &second_length) == PropertyFlags::NoValidConversion) return false; diff --git a/sources/editor/graphicspart/partline.h b/sources/editor/graphicspart/partline.h index 5e8ccf971..8b10de65a 100644 --- a/sources/editor/graphicspart/partline.h +++ b/sources/editor/graphicspart/partline.h @@ -118,10 +118,10 @@ class PartLine : public CustomElementGraphicPart /*****************/ Qet::EndType first_end; - qreal first_length; + qreal first_length{1.5}; Qet::EndType second_end; - qreal second_length; + qreal second_length{1.5}; QList saved_points_; QLineF m_line; int m_vector_index = -1; diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index 170068f00..85c44032e 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -117,22 +117,22 @@ bool PartRectangle::fromXml(const QDomElement &qde) stylesFromXml(qde); double x, y, w, h, rx, ry; - if (propertyDouble(qde, "x", &x, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y", &y, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "x", &x, true, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "y", &y, true, 0) == PropertyFlags::NoValidConversion) return false; setPos(mapFromScene(x, y)); - if (propertyDouble(qde, "width", &w, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "width", &h, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "width", &w, true, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "width", &h, true, 0) == PropertyFlags::NoValidConversion) return false; - QRectF rect(QPointF(0,0), QSizeF(w, h)); + QRectF rect(QPointF(x,y), QSizeF(w, h)); setRect(rect.normalized()); - if (propertyDouble(qde, "rx", &rx, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "ry", &ry, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "rx", &rx, true, 0) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "ry", &ry, true, 0) == PropertyFlags::NoValidConversion) return false; setXRadius(rx); diff --git a/sources/editor/graphicspart/partterminal.cpp b/sources/editor/graphicspart/partterminal.cpp index a957e6fa7..0d13c372f 100644 --- a/sources/editor/graphicspart/partterminal.cpp +++ b/sources/editor/graphicspart/partterminal.cpp @@ -49,8 +49,7 @@ bool PartTerminal::fromXml(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 - if (propertyUuid(xml_elmt, "uuid", &uuid) == PropertyFlags::Success) - d->m_uuid = QUuid(uuid); + propertyUuid(xml_elmt, "uuid", &d->m_uuid); if (!d->fromXml(xml_elmt)) return false; diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp index 6ba0eecbb..b76666b0b 100644 --- a/sources/editor/graphicspart/parttext.cpp +++ b/sources/editor/graphicspart/parttext.cpp @@ -78,22 +78,22 @@ bool PartText::fromXml(const QDomElement &xml_element) return false; } - QString color; + QColor color; QString text; - propertyString(xml_element, "color", &color, "#000000"); - setDefaultTextColor(QColor(color)); + propertyColor(xml_element, "color", &color); + setDefaultTextColor(color); propertyString(xml_element, "text", &text); setPlainText(text); double x, y, rot; - if (propertyDouble(xml_element, "x", &x, 0) == PropertyFlags::NoValidConversion || - propertyDouble(xml_element, "y", &y, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(xml_element, "x", &x, true, 0) == PropertyFlags::NoValidConversion || + propertyDouble(xml_element, "y", &y, true, 0) == PropertyFlags::NoValidConversion) return false; setPos(x, y); - if (propertyDouble(xml_element, "rotation", &rot, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(xml_element, "rotation", &rot, true, 0) == PropertyFlags::NoValidConversion) return false; setRotation(rot); diff --git a/sources/properties/propertiesinterface.h b/sources/properties/propertiesinterface.h index 1419598bf..e75d5f43e 100644 --- a/sources/properties/propertiesinterface.h +++ b/sources/properties/propertiesinterface.h @@ -56,7 +56,7 @@ class PropertiesInterface static QDomElement property(const QDomElement& e, const QString& name); static bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); - typedef enum PropertyFlags { + enum PropertyFlags { Success = 0, NotFound = 1, NoValidConversion = 2, diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 64accc001..74a94ca16 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -949,10 +949,9 @@ void Conductor::pointsToSegments(const QList& points_list) { bool Conductor::fromXml(const QDomElement &dom_element) { // TODO: seems to short! - double x, y; + double x=0, y=0; propertyDouble(dom_element, "x", &x); propertyDouble(dom_element, "y", &y); - setPos(x, y); bool return_ = pathFromXml(dom_element); diff --git a/sources/titleblockproperties.cpp b/sources/titleblockproperties.cpp index 4f60b2668..021029f54 100644 --- a/sources/titleblockproperties.cpp +++ b/sources/titleblockproperties.cpp @@ -96,6 +96,7 @@ void TitleBlockProperties::toXml(QDomElement &e) const { } QDomElement TitleBlockProperties::toXml(QDomDocument &d) const { + Q_UNUSED(d) qDebug() << "NOT IMPLEMENTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; return QDomElement(); } @@ -126,10 +127,10 @@ bool TitleBlockProperties::fromXml(const QDomElement &e) { 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)) { + if (propertyString(e, "titleblocktemplate", &template_name) == PropertyFlags::Success) { QString tbc; - propertyString(e, "titleblocktemplateCollection", &tbc); - collection = QET::qetCollectionFromString(tbc); + if (propertyString(e, "titleblocktemplateCollection", &tbc) == PropertyFlags::Success) + collection = QET::qetCollectionFromString(tbc); } // reads the additional fields used to fill the title block From 52f886e34b06f860e3bbb5c53a06f62499104b56 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 8 Oct 2020 18:39:11 +0200 Subject: [PATCH 26/34] add comment --- sources/qetgraphicsitem/element.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 5dc73b442..59a158174 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -590,7 +590,7 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element) return (a->dockConductor().y() < b->dockConductor().y()); }); - return(new_terminal); + return(new_terminal); // TODO: makes not sense } /** From 0cc6558281b0b18e1e823126d38d8081e7cd5b51 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 8 Oct 2020 19:05:30 +0200 Subject: [PATCH 27/34] Fix issue that conductors where connected wrong. This was, because instead of reusing the id's stored in the Terminal, new id's where created --- sources/diagram.cpp | 4 +--- sources/elementtextpattern.cpp | 3 +-- sources/qetgraphicsitem/element.cpp | 19 +++++-------------- sources/qetgraphicsitem/element.h | 2 +- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 0c419722f..85242dcc8 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -750,12 +750,11 @@ QDomDocument Diagram::toXml(bool whole_content) { } // table de correspondance entre les adresses des bornes et leurs ids - QHash table_adr_id; if (!list_elements.isEmpty()) { auto dom_elements = document.createElement("elements"); for (auto elmt : list_elements) { - dom_elements.appendChild(elmt->toXml(document, table_adr_id)); + dom_elements.appendChild(elmt->toXml(document)); } dom_root.appendChild(dom_elements); } @@ -763,7 +762,6 @@ QDomDocument Diagram::toXml(bool whole_content) { if (!list_conductors.isEmpty()) { auto dom_conductors = document.createElement("conductors"); for (auto cond : list_conductors) { - //dom_conductors.appendChild(cond->toXml(document, table_adr_id)); dom_conductors.appendChild(cond->toXml(document)); } dom_root.appendChild(dom_conductors); diff --git a/sources/elementtextpattern.cpp b/sources/elementtextpattern.cpp index b1253f948..826c5af64 100644 --- a/sources/elementtextpattern.cpp +++ b/sources/elementtextpattern.cpp @@ -108,8 +108,7 @@ QDomDocument ExportElementTextPattern::xmlConf() const root.setAttribute("name", m_name); doc.appendChild(root); - QHash H; - QDomElement elmt = m_element->toXml(doc, H); + QDomElement elmt = m_element->toXml(doc); QDomElement texts = elmt.firstChildElement("dynamic_texts"); QDomElement groups = elmt.firstChildElement("texts_groups"); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 59a158174..ed36696ed 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -1023,7 +1023,7 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool methode @return L'element XML representant cet element electrique */ -QDomElement Element::toXml(QDomDocument &document, QHash &table_adr_id) const +QDomElement Element::toXml(QDomDocument &document) const { QDomElement element = document.createElement("element"); @@ -1050,25 +1050,16 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table element.setAttribute("z", QString::number(this->zValue())); element.setAttribute("orientation", QString::number(orientation())); - /* recupere le premier id a utiliser pour les bornes de cet element */ - int id_terminal = 0; - if (!table_adr_id.isEmpty()) { - // trouve le plus grand id - int max_id_t = -1; - foreach (int id_t, table_adr_id.values()) { - if (id_t > max_id_t) max_id_t = id_t; - } - id_terminal = max_id_t + 1; - } - // enregistrement des bornes de l'appareil QDomElement xml_terminals = document.createElement("terminals"); // pour chaque enfant de l'element foreach(Terminal *t, terminals()) { // alors on enregistre la borne QDomElement terminal = t -> toXml(document); - terminal.setAttribute("id", id_terminal); // for backward compatibility - table_adr_id.insert(t, id_terminal ++); + if (t->ID() > 0) { + // for backward compatibility + terminal.setAttribute("id", t->ID()); // for backward compatibility + } xml_terminals.appendChild(terminal); } element.appendChild(xml_terminals); diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 2c3d55ffb..a5f2c9689 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -113,7 +113,7 @@ class Element : public QetGraphicsItem // TODO: derive from propertiesInterface! void editProperty() override; static bool valideXml(QDomElement &); virtual bool fromXml(QDomElement &, QHash &, bool = false); - virtual QDomElement toXml(QDomDocument &, QHash &) const; + virtual QDomElement toXml(QDomDocument &) const; QUuid uuid() const; int orientation() const; From 9b8c0101be0dc1f5097240634468da89f8fa78a6 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sat, 10 Oct 2020 11:17:15 +0200 Subject: [PATCH 28/34] new method to load properties must be used, otherwise nothing valid will be read --- sources/qetproject.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 59d4bb5a6..1ceeced40 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -1425,7 +1425,11 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project) { XRefProperties xrp; xrp.fromXml(elmt); - m_default_xref_properties.insert(elmt.attribute("type"), xrp); + QString type; + if (PropertiesInterface::propertyString(elmt, "type", &type) == PropertiesInterface::PropertyFlags::Success) + m_default_xref_properties.insert(type, xrp); + else + qDebug() << "xref Property was not added to m_default_xref_properties."; } } if (!conds_autonums.isNull()) From f18e6bd50f71956e0302353b34b12df70dbed719 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sat, 10 Oct 2020 12:02:38 +0200 Subject: [PATCH 29/34] remove default parameter, because it leads only to confusion and errors --- sources/conductorproperties.cpp | 4 ++-- sources/editor/graphicspart/partarc.cpp | 10 ++++---- .../graphicspart/partdynamictextfield.cpp | 4 ++-- sources/editor/graphicspart/partellipse.cpp | 12 +++++----- sources/editor/graphicspart/partrectangle.cpp | 14 +++++------ sources/editor/graphicspart/parttext.cpp | 8 +++---- sources/properties/propertiesinterface.cpp | 24 +++++-------------- sources/properties/propertiesinterface.h | 12 +++++----- sources/qetgraphicsitem/conductor.cpp | 4 ++-- 9 files changed, 40 insertions(+), 52 deletions(-) diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 22d047a43..f33e6d07b 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -369,9 +369,9 @@ bool ConductorProperties::fromXml(const QDomElement &e) QMetaEnum me = QMetaEnum::fromType(); QString alinment_temp; - if (propertyString(e, "horizontal-alignment", &alinment_temp, "AlignBottom") == PropertyFlags::Success) + if (propertyString(e, "horizontal-alignment", &alinment_temp) == PropertyFlags::Success) m_horizontal_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); - if (propertyString(e, "vertical-alignment", &alinment_temp, "AlignRight") == PropertyFlags::Success) + if (propertyString(e, "vertical-alignment", &alinment_temp) == PropertyFlags::Success) m_vertical_alignment = Qt::Alignment(me.keyToValue(alinment_temp.toStdString().data())); return true; diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index 87a23a411..a9b083a3b 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -121,11 +121,11 @@ QDomElement PartArc::toXml(QDomDocument &xml_document) const { bool PartArc::fromXml(const QDomElement &qde) { stylesFromXml(qde); - double x, y, w, h; - if (propertyDouble(qde, "x", &x, true, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y", &y, true, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "width", &w, true, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "height", &h, true, 0) == PropertyFlags::NoValidConversion) + 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) return false; m_rect = QRectF(mapFromScene(x, y), QSizeF(w, h) ); diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp index b044d2a12..025baf5a1 100644 --- a/sources/editor/graphicspart/partdynamictextfield.cpp +++ b/sources/editor/graphicspart/partdynamictextfield.cpp @@ -186,8 +186,8 @@ bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt) bool frame; propertyBool(dom_elmt, "frame", &frame); - double text_width; - propertyDouble(dom_elmt, "text_width", &text_width, true, -1); + double text_width=-1; + propertyDouble(dom_elmt, "text_width", &text_width); setTextWidth(text_width); QMetaEnum me = DynamicElementTextItem::textFromMetaEnum(); diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index f29358469..6163e241f 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -108,23 +108,23 @@ QDomElement PartEllipse::toXml(QDomDocument &xml_document) const bool PartEllipse::fromXml(const QDomElement &qde) { stylesFromXml(qde); - double x, y, width, height; + double x=0, y=0, width=0, height=0; if (qde.tagName() == "ellipse") { - if (propertyDouble(qde, "width", &width, true, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "height", &height, true, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "width", &width) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "height", &height) == PropertyFlags::NoValidConversion) return false; } else { - if (propertyDouble(qde, "diameter", &width, true, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "diameter", &width) == PropertyFlags::NoValidConversion) return false; height = width; } - if (propertyDouble(qde, "x", &x, true, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y", &y, true, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion) return false; m_rect = QRectF(mapFromScene(x, y), QSizeF(width, height)); diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index 85c44032e..ce0ca222b 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -116,23 +116,23 @@ bool PartRectangle::fromXml(const QDomElement &qde) { stylesFromXml(qde); - double x, y, w, h, rx, ry; - if (propertyDouble(qde, "x", &x, true, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "y", &y, true, 0) == PropertyFlags::NoValidConversion) + 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) return false; setPos(mapFromScene(x, y)); - if (propertyDouble(qde, "width", &w, true, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "width", &h, true, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "width", &w) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "width", &h) == PropertyFlags::NoValidConversion) return false; QRectF rect(QPointF(x,y), QSizeF(w, h)); setRect(rect.normalized()); - if (propertyDouble(qde, "rx", &rx, true, 0) == PropertyFlags::NoValidConversion || - propertyDouble(qde, "ry", &ry, true, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(qde, "rx", &rx) == PropertyFlags::NoValidConversion || + propertyDouble(qde, "ry", &ry) == PropertyFlags::NoValidConversion) return false; setXRadius(rx); diff --git a/sources/editor/graphicspart/parttext.cpp b/sources/editor/graphicspart/parttext.cpp index b76666b0b..dbaf3df39 100644 --- a/sources/editor/graphicspart/parttext.cpp +++ b/sources/editor/graphicspart/parttext.cpp @@ -87,13 +87,13 @@ bool PartText::fromXml(const QDomElement &xml_element) propertyString(xml_element, "text", &text); setPlainText(text); - double x, y, rot; - if (propertyDouble(xml_element, "x", &x, true, 0) == PropertyFlags::NoValidConversion || - propertyDouble(xml_element, "y", &y, true, 0) == PropertyFlags::NoValidConversion) + double x=0, y=0, rot=0; + if (propertyDouble(xml_element, "x", &x) == PropertyFlags::NoValidConversion || + propertyDouble(xml_element, "y", &y) == PropertyFlags::NoValidConversion) return false; setPos(x, y); - if (propertyDouble(xml_element, "rotation", &rot, true, 0) == PropertyFlags::NoValidConversion) + if (propertyDouble(xml_element, "rotation", &rot) == PropertyFlags::NoValidConversion) return false; setRotation(rot); diff --git a/sources/properties/propertiesinterface.cpp b/sources/properties/propertiesinterface.cpp index 7d96e8513..af8354a9c 100644 --- a/sources/properties/propertiesinterface.cpp +++ b/sources/properties/propertiesinterface.cpp @@ -150,13 +150,11 @@ bool PropertiesInterface::attribute(const QDomElement& e, const QString& attribu * \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, bool setDefaultValue, int defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QDomElement &e, const QString& attribute_name, int* entier) { QString attr; if (!attribute(e, attribute_name, integerS, &attr)) { - if (entier && setDefaultValue) - *entier = defaultValue; return PropertyFlags::NotFound; } @@ -174,13 +172,11 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QD return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel, bool setDefaultValue, double defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel) { QString attr; if (!attribute(e, attribute_name, doubleS, &attr)) { - if (reel && setDefaultValue) - *reel = defaultValue; return PropertyFlags::NotFound; } @@ -198,13 +194,11 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDo return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean, bool setDefaultValue, bool defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean) { QString attr; if (!attribute(e, attribute_name, boolS, &attr)) { - if (boolean && setDefaultValue) - *boolean = defaultValue; return PropertyFlags::NotFound; } @@ -228,13 +222,11 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color, bool setDefaultValue, QColor defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color) { QString attr; if (!attribute(e, attribute_name, colorS, &attr)) { - if (color && setDefaultValue) - *color = defaultValue; return PropertyFlags::NotFound; } @@ -251,12 +243,10 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDom return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid, bool setDefaultValue, QUuid defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid) { QString attr; if (!attribute(e, attribute_name, uuidS, &attr)) { - if (uuid && setDefaultValue) - *uuid = defaultValue; return PropertyFlags::NotFound; } @@ -272,12 +262,10 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomE return PropertyFlags::Success; } -PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string, bool setDefaultValue, QString defaultValue) { +PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string) { QString attr; if (!attribute(e, attribute_name, stringS, &attr)) { - if (string && setDefaultValue) - *string = defaultValue; return PropertyFlags::NotFound; } diff --git a/sources/properties/propertiesinterface.h b/sources/properties/propertiesinterface.h index e75d5f43e..f02d9e24a 100644 --- a/sources/properties/propertiesinterface.h +++ b/sources/properties/propertiesinterface.h @@ -66,12 +66,12 @@ class PropertiesInterface /*! * Try not using the default Value feature. It is better to initialize the class members in the class definition! */ - static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, bool setDefaultValue = false, int defaultValue = std::numeric_limits::quiet_NaN()); - static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr, bool setDefaultValue = false, double defaultValue = std::numeric_limits::quiet_NaN()); - static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr, bool setDefaultValue = false, QString defaultValue = QString()); - static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool setDefaultValue = false, bool defaultValue = false); - static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr, bool setDefaultValue = false, QUuid defaultValue = QUuid()); - static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr, bool setDefaultValue = false, QColor defaultValue = QColor()); + static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = 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 QDomElement &e, const QString& attribute_name, bool* boolean = nullptr); + static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr); + static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr); static bool validXmlProperty(const QDomElement& e); diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 74a94ca16..d9cf0ba50 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -966,7 +966,7 @@ bool Conductor::fromXml(const QDomElement &dom_element) else m_autoNum_seq.fromXml(dom_element.firstChildElement("sequentialNumbers")); - propertyBool(dom_element, "freezeLabel", &m_freeze_label, false); + propertyBool(dom_element, "freezeLabel", &m_freeze_label); setProperties(pr); return return_; @@ -1022,7 +1022,7 @@ QDomElement Conductor::toXml(QDomDocument & doc) const { } } - QDomElement dom_seq = m_autoNum_seq.toXml(doc); + QDomElement dom_seq = m_autoNum_seq.toXml(doc); // swquentialNumbers tag dom_element.appendChild(dom_seq); // Export the properties and text From 497673d83bef86958610505dc630e8742e9cf89e Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sat, 10 Oct 2020 12:21:37 +0200 Subject: [PATCH 30/34] make createProperty methods static, because they can be used also outside of this class --- sources/properties/propertiesinterface.cpp | 14 +++++++------- sources/properties/propertiesinterface.h | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sources/properties/propertiesinterface.cpp b/sources/properties/propertiesinterface.cpp index af8354a9c..68563b31a 100644 --- a/sources/properties/propertiesinterface.cpp +++ b/sources/properties/propertiesinterface.cpp @@ -40,7 +40,7 @@ bool PropertiesInterface::valideXml(QDomElement& element) { return false; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const QString value) const { +QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const QString value) { QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", stringS); @@ -48,7 +48,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QStr return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const char* value) const { +QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const char* value) { QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", stringS); @@ -56,7 +56,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QStr return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const int value) const { +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const int value) { QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", integerS); @@ -64,7 +64,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const double value) const { +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const double value) { QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", doubleS); @@ -72,7 +72,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const { +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const bool value) { QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", boolS); @@ -80,7 +80,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) const { +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) { QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", uuidS); @@ -88,7 +88,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr return p; } -QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) const { +QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) { QDomElement p = doc.createElement("property"); p.setAttribute("name", name); p.setAttribute("type", colorS); diff --git a/sources/properties/propertiesinterface.h b/sources/properties/propertiesinterface.h index f02d9e24a..a7e27f7c1 100644 --- a/sources/properties/propertiesinterface.h +++ b/sources/properties/propertiesinterface.h @@ -45,13 +45,13 @@ class PropertiesInterface /*! * Use this functions to add properties to the xml document */ - QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QString value) const; - QDomElement createXmlProperty(QDomDocument &doc, const QString& name, const char* value) const; - QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value) const; - QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value) const; - QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const; - QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) const; - QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) const; + static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QString value); + static QDomElement createXmlProperty(QDomDocument &doc, const QString& name, const char* value); + static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value); + static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value); + static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value); + static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value); + static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QColor value); static QDomElement property(const QDomElement& e, const QString& name); static bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); From 0dfe0c16131f7d9857db8246fa2a5222bb3cb3f4 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sat, 10 Oct 2020 12:25:58 +0200 Subject: [PATCH 31/34] let conductor textitem export to xml, because the read is also made from it --- sources/qetgraphicsitem/conductor.cpp | 8 +--- sources/qetgraphicsitem/conductortextitem.cpp | 37 +++++++++++++------ sources/qetgraphicsitem/conductortextitem.h | 5 ++- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index d9cf0ba50..7ea6ac6c3 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -1032,13 +1032,7 @@ QDomElement Conductor::toXml(QDomDocument & doc) const { dom_element.appendChild(node); } - if(m_text_item->wasMovedByUser()) - { - dom_element.appendChild(createXmlProperty(doc, "userx", m_text_item->pos().x())); - dom_element.appendChild(createXmlProperty(doc, "usery", m_text_item->pos().y())); - } - if(m_text_item->wasRotateByUser()) - dom_element.appendChild(createXmlProperty(doc, "rotation", m_text_item->rotation())); + m_text_item->toXml(doc, dom_element); return(dom_element); } diff --git a/sources/qetgraphicsitem/conductortextitem.cpp b/sources/qetgraphicsitem/conductortextitem.cpp index 012d98a43..56b8e8454 100644 --- a/sources/qetgraphicsitem/conductortextitem.cpp +++ b/sources/qetgraphicsitem/conductortextitem.cpp @@ -27,9 +27,7 @@ */ ConductorTextItem::ConductorTextItem(Conductor *parent_conductor) : DiagramTextItem(parent_conductor), - parent_conductor_(parent_conductor), - moved_by_user_(false), - rotate_by_user_(false) + parent_conductor_(parent_conductor) { setAcceptHoverEvents(true); } @@ -61,21 +59,36 @@ Conductor *ConductorTextItem::parentConductor() const { return(parent_conductor_); } +void ConductorTextItem::toXml(QDomDocument& doc, QDomElement& e) { + if(moved_by_user_) + { + e.appendChild(PropertiesInterface::createXmlProperty(doc, "userx", pos().x())); + e.appendChild(PropertiesInterface::createXmlProperty(doc, "usery", pos().y())); + } + if(rotate_by_user_) + e.appendChild(PropertiesInterface::createXmlProperty(doc, "rotation", rotation())); +} + + /** * @brief ConductorTextItem::fromXml * Read the properties stored in the xml element given in parameter * @param e */ void ConductorTextItem::fromXml(const QDomElement &e) { - if (e.hasAttribute("userx")) { - setPos(e.attribute("userx").toDouble(), - e.attribute("usery").toDouble()); - moved_by_user_ = true; - } - if (e.hasAttribute("rotation")) { - setRotation(e.attribute("rotation").toDouble()); - rotate_by_user_ = true; - } + + double userx=0, usery=0; + if (PropertiesInterface::propertyDouble(e, "userx", &userx) == PropertiesInterface::PropertyFlags::Success && + PropertiesInterface::propertyDouble(e, "usery", &usery) == PropertiesInterface::PropertyFlags::Success) { + setPos(userx, usery); + moved_by_user_ = true; + } + + double rotation; + if (PropertiesInterface::propertyDouble(e, "rotation", &rotation) == PropertiesInterface::PropertyFlags::Success) { + setRotation(rotation); + rotate_by_user_ = true; + } } /** diff --git a/sources/qetgraphicsitem/conductortextitem.h b/sources/qetgraphicsitem/conductortextitem.h index 74fe2550f..badd6afdf 100644 --- a/sources/qetgraphicsitem/conductortextitem.h +++ b/sources/qetgraphicsitem/conductortextitem.h @@ -42,6 +42,7 @@ class ConductorTextItem : public DiagramTextItem enum { Type = UserType + 1006 }; Conductor *parentConductor() const; void fromXml(const QDomElement &) override; + void toXml(QDomDocument& doc, QDomElement& e); int type() const override { return Type; } virtual bool wasMovedByUser() const; virtual bool wasRotateByUser() const; @@ -61,8 +62,8 @@ class ConductorTextItem : public DiagramTextItem // attributes private: Conductor *parent_conductor_; - bool moved_by_user_; - bool rotate_by_user_; + bool moved_by_user_{false}; + bool rotate_by_user_{false}; QPointF before_mov_pos_; }; #endif From 3509a1c7a5248a4e2e9a900327d604b92ee15554 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sat, 10 Oct 2020 15:50:04 +0200 Subject: [PATCH 32/34] add comments and move some initializations from the source file to the header file --- sources/qetgraphicsitem/dynamicelementtextitem.cpp | 4 ++-- sources/qetgraphicsitem/element.cpp | 10 +++++----- sources/qetgraphicsitem/slaveelement.cpp | 2 +- sources/qetgraphicsitem/slaveelement.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index ba8ea4fcb..f8b7c798c 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -212,7 +212,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt) setColor(QColor(dom_color.text())); //Force the update of the displayed text - setTextFrom(m_text_from); + setTextFrom(m_text_from); // TODO: does not update because there is a retrun inside if the textfrom argument is the same as m_text_from QGraphicsTextItem::setPos(dom_elmt.attribute("x", QString::number(0)).toDouble(), dom_elmt.attribute("y", QString::number(0)).toDouble()); @@ -325,7 +325,7 @@ void DynamicElementTextItem::setTextFrom(DynamicElementTextItem::TextFrom text_f { if(m_text_from == text_from) return; - + setNoEditable(text_from == UserText? false : true); clearFormulaConnection(); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index ed36696ed..e68875217 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -745,7 +745,7 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool //************************// //***Dynamic texts item***// - //************************// + //************************// read from the diagram section for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTagName())) { DynamicElementTextItem *deti = new DynamicElementTextItem(this); @@ -757,16 +757,16 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool //************************// //***Element texts item***// //************************// - QList inputs = QET::findInDomElement(e, "inputs", "input"); + QList inputs = QET::findInDomElement(e, "inputs", "input"); // inputs in diagram section //First case, we check for the text item converted to dynamic text item const QList conv_deti_list = m_converted_text_from_xml_description.keys(); QList successfully_converted; const QList dom_inputs = inputs; - - for (DynamicElementTextItem *deti : conv_deti_list) + // TODO: legacy??? + for (DynamicElementTextItem *deti : conv_deti_list) // elements read from the element collection definition { - for(const QDomElement& dom_input : dom_inputs) + for(const QDomElement& dom_input : dom_inputs) { //we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored. //The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element diff --git a/sources/qetgraphicsitem/slaveelement.cpp b/sources/qetgraphicsitem/slaveelement.cpp index 2a2f4fb08..3c61830d3 100644 --- a/sources/qetgraphicsitem/slaveelement.cpp +++ b/sources/qetgraphicsitem/slaveelement.cpp @@ -32,7 +32,7 @@ SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) : Element(location, qgi, state, Element::Slave) { - m_xref_item = nullptr; + } /** diff --git a/sources/qetgraphicsitem/slaveelement.h b/sources/qetgraphicsitem/slaveelement.h index 78746a976..fe5067da9 100644 --- a/sources/qetgraphicsitem/slaveelement.h +++ b/sources/qetgraphicsitem/slaveelement.h @@ -32,7 +32,7 @@ class SlaveElement : public Element void unlinkElement(Element *elmt) override; private: - QGraphicsTextItem *m_xref_item; + QGraphicsTextItem *m_xref_item{nullptr}; }; #endif // SLAVEELEMENT_H From f79b1a52bb998e4239f5932fdd23c6b976860f6b Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sun, 11 Oct 2020 11:05:22 +0200 Subject: [PATCH 33/34] WIP --- .../fileelementcollectionitem.cpp | 3 ++- sources/qetgraphicsitem/diagramtextitem.cpp | 24 +++++++++++++++++++ .../dynamicelementtextitem.cpp | 20 ++++++++++++++++ .../qetgraphicsitem/dynamicelementtextitem.h | 2 ++ sources/qetgraphicsitem/element.cpp | 17 +++++++++---- sources/qetgraphicsitem/element.h | 2 +- sources/qetgraphicsitem/slaveelement.cpp | 4 ++-- sources/qetgraphicsitem/slaveelement.h | 2 +- sources/ui/dynamicelementtextmodel.cpp | 6 +++++ 9 files changed, 70 insertions(+), 10 deletions(-) diff --git a/sources/ElementsCollection/fileelementcollectionitem.cpp b/sources/ElementsCollection/fileelementcollectionitem.cpp index ad53e843e..8c6b37bc0 100644 --- a/sources/ElementsCollection/fileelementcollectionitem.cpp +++ b/sources/ElementsCollection/fileelementcollectionitem.cpp @@ -183,13 +183,14 @@ QString FileElementCollectionItem::name() const */ QString FileElementCollectionItem::collectionPath() const { + QStandardItem* parent_ = parent(); if (isCollectionRoot()) { if (m_path == QETApp::commonElementsDirN()) return "common://"; else return "custom://"; } - else if (parent() && parent()->type() == FileElementCollectionItem::Type) { + else if (parent_ && parent()->type() == FileElementCollectionItem::Type) { ElementCollectionItem *eci = static_cast(parent()); if (eci->isCollectionRoot()) return eci->collectionPath() + m_path; diff --git a/sources/qetgraphicsitem/diagramtextitem.cpp b/sources/qetgraphicsitem/diagramtextitem.cpp index b9f8d9024..99aabf7a2 100644 --- a/sources/qetgraphicsitem/diagramtextitem.cpp +++ b/sources/qetgraphicsitem/diagramtextitem.cpp @@ -20,6 +20,8 @@ #include "qetapp.h" #include "richtext/richtexteditor_p.h" #include "diagram.h" +#include "dynamicelementtextitem.h" + /** * @brief DiagramTextItem::DiagramTextItem @@ -211,12 +213,24 @@ QRectF DiagramTextItem::frameRect() const void DiagramTextItem::setHtml(const QString &text) { + DynamicElementTextItem* abc = dynamic_cast(this); + if (abc) { + if (abc->searchedElement) { + int stop = 1; + } + } QGraphicsTextItem::setHtml(text); m_is_html = true; } void DiagramTextItem::setPlainText(const QString &text) { + DynamicElementTextItem* abc = dynamic_cast(this); + if (abc) { + if (abc->searchedElement) { + int stop = 1; + } + } QGraphicsTextItem::setPlainText(text); m_is_html = false; } @@ -235,6 +249,16 @@ bool DiagramTextItem::isHtml() const { */ void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + + DynamicElementTextItem* abc = dynamic_cast(this); + if (abc) { + if (abc->searchedElement) { + int stop = 1; + QString text = toPlainText(); + qDebug() << text; + } + } + painter -> setRenderHint(QPainter::Antialiasing, false); QGraphicsTextItem::paint(painter, option, widget); diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index f8b7c798c..fee849b55 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -323,6 +323,9 @@ DynamicElementTextItem::TextFrom DynamicElementTextItem::textFrom() const { */ void DynamicElementTextItem::setTextFrom(DynamicElementTextItem::TextFrom text_from) { + + if (searchedElement) + int stop = true; if(m_text_from == text_from) return; @@ -386,6 +389,9 @@ QString DynamicElementTextItem::text() const { */ void DynamicElementTextItem::setText(const QString &text) { + if (m_text == "14" && text == "") + int a = 54; + m_text_old = m_text; m_text = text; if(m_text_from == DynamicElementTextItem::UserText) setPlainText(m_text); @@ -402,6 +408,9 @@ void DynamicElementTextItem::setInfoName(const QString &info_name) QString old_info_name = m_info_name; m_info_name = info_name; + if (searchedElement) + int stop = true; + if(old_info_name == "label") { @@ -1321,6 +1330,17 @@ void DynamicElementTextItem::updateXref() void DynamicElementTextItem::setPlainText(const QString &text) { + DynamicElementTextItem* abc = this; + + int abcedwer; + abcedwer += 5; + + if (text == "14") + searchedElement = true; + if (text == "") + int a = 5; + if (m_text_old == "14" && m_text == "") + int a = 5; if (toPlainText() == text) return; diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.h b/sources/qetgraphicsitem/dynamicelementtextitem.h index 53e4d3b14..e7d691d96 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.h +++ b/sources/qetgraphicsitem/dynamicelementtextitem.h @@ -103,6 +103,7 @@ class DynamicElementTextItem : public DiagramTextItem void setPlainText(const QString &text); void setTextWidth(qreal width); void setXref_item(Qt::AlignmentFlag m_exHrefPos); + bool searchedElement{false}; protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) override; @@ -141,6 +142,7 @@ class DynamicElementTextItem : public DiagramTextItem m_other_report; QPointer m_watched_conductor; QString m_text, + m_text_old, m_info_name, m_composite_text, m_report_formula, diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index e68875217..10c2bb959 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -71,7 +71,7 @@ class ElementXmlRetroCompatibility * @param state, state of the instanciation */ Element::Element(const ElementsLocation &location, QGraphicsItem *parent, int *state, kind link_type) : - QetGraphicsItem(parent), + QetGraphicsItem(parent), m_link_type (link_type), m_location (location) { @@ -419,7 +419,8 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state) if (elmts.tagName() == "description") { //Minor workaround to find if there is a "input" tagg as label. - //If not, we set the tagg "label" to the first "input. + //If not, we set the tagg "label" to the first "input. Why one must have a tagg label? + // is label a required field? QList input_field; bool have_label = false; for (QDomElement input_node = node.firstChildElement("input") ; !input_node.isNull() ; input_node = input_node.nextSiblingElement("input")) @@ -715,6 +716,8 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool QString fl = e.attribute("freezeLabel", "false"); m_freeze_label = fl == "false"? false : true; + // TODO: why element information is not read? + //Load Sequential Values if (e.hasAttribute("sequ_1") || e.hasAttribute("sequf_1") || e.hasAttribute("seqt_1") || e.hasAttribute("seqtf_1") || e.hasAttribute("seqh_1") || e.hasAttribute("sequf_1")) ElementXmlRetroCompatibility::loadSequential(e, this); @@ -745,7 +748,9 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool //************************// //***Dynamic texts item***// - //************************// read from the diagram section + //************************// + // read from the diagram section + // this is not done in the older versions, because there only inputs are available. for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTagName())) { DynamicElementTextItem *deti = new DynamicElementTextItem(this); @@ -763,14 +768,16 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool const QList conv_deti_list = m_converted_text_from_xml_description.keys(); QList successfully_converted; const QList dom_inputs = inputs; - // TODO: legacy??? + // TODO: Legacy (0.7 and prior) for (DynamicElementTextItem *deti : conv_deti_list) // elements read from the element collection definition { - for(const QDomElement& dom_input : dom_inputs) + for(const QDomElement& dom_input : dom_inputs) // elements in the diagram section { //we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored. //The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element //that mean this is the good text + // This is only used when in the diagram description the text elements are stored in the "inputs" section. In 0.8 and higher, + // texts are stored in directly in the "dynamic_elmt_text" section if (qFuzzyCompare(qreal(dom_input.attribute("x").toDouble()), m_converted_text_from_xml_description.value(deti).x()) && qFuzzyCompare(qreal(dom_input.attribute("y").toDouble()), m_converted_text_from_xml_description.value(deti).y())) { diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index a5f2c9689..441bbc3d6 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -55,7 +55,7 @@ class Element : public QetGraphicsItem // TODO: derive from propertiesInterface! Slave = 16, Terminale = 32}; - Element(const ElementsLocation &location, QGraphicsItem * = nullptr, int *state = nullptr, Element::kind link_type = Element::Simple); + Element(const ElementsLocation &location, QGraphicsItem * parent= nullptr, int *state = nullptr, Element::kind link_type = Element::Simple); ~Element() override; private: Element(const Element &); diff --git a/sources/qetgraphicsitem/slaveelement.cpp b/sources/qetgraphicsitem/slaveelement.cpp index 3c61830d3..d69b778bd 100644 --- a/sources/qetgraphicsitem/slaveelement.cpp +++ b/sources/qetgraphicsitem/slaveelement.cpp @@ -29,8 +29,8 @@ * @param s parent diagram * @param state int used to know if the creation of element have error */ -SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) : - Element(location, qgi, state, Element::Slave) +SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *parent, int *state) : + Element(location, parent, state, Element::Slave) { } diff --git a/sources/qetgraphicsitem/slaveelement.h b/sources/qetgraphicsitem/slaveelement.h index fe5067da9..3117451da 100644 --- a/sources/qetgraphicsitem/slaveelement.h +++ b/sources/qetgraphicsitem/slaveelement.h @@ -25,7 +25,7 @@ class SlaveElement : public Element { Q_OBJECT public: - explicit SlaveElement (const ElementsLocation &, QGraphicsItem * = nullptr, int * = nullptr); + explicit SlaveElement (const ElementsLocation &, QGraphicsItem * parent= nullptr, int * = nullptr); ~SlaveElement() override; void linkToElement(Element *elmt) override; void unlinkAllElements() override; diff --git a/sources/ui/dynamicelementtextmodel.cpp b/sources/ui/dynamicelementtextmodel.cpp index fc9709d9e..7b9c12e26 100644 --- a/sources/ui/dynamicelementtextmodel.cpp +++ b/sources/ui/dynamicelementtextmodel.cpp @@ -1158,6 +1158,8 @@ void DynamicElementTextModel::enableGroupRotationAndPos(ElementTextItemGroup *gr void DynamicElementTextModel::itemDataChanged(QStandardItem *qsi) { DynamicElementTextItem *deti = textFromItem(qsi); + if (deti->searchedElement) + int stop = 1; ElementTextItemGroup *etig = groupFromItem(qsi); if (!deti && !etig) return; @@ -1297,6 +1299,10 @@ void DynamicElementTextModel::setConnection(ElementTextItemGroup *group, bool se void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, ValueType type) { + + if (deti->searchedElement) + int stop = 1; + QStandardItem *qsi = m_texts_list.value(deti); if (!qsi) return; From c0d9bf95487998f711db6613250198287e5698cc Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Mon, 12 Oct 2020 19:11:01 +0200 Subject: [PATCH 34/34] use more meaningful name --- sources/qetgraphicsitem/element.h | 2 +- sources/qetgraphicsitem/slaveelement.cpp | 4 ++-- sources/qetgraphicsitem/slaveelement.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index a5f2c9689..441bbc3d6 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -55,7 +55,7 @@ class Element : public QetGraphicsItem // TODO: derive from propertiesInterface! Slave = 16, Terminale = 32}; - Element(const ElementsLocation &location, QGraphicsItem * = nullptr, int *state = nullptr, Element::kind link_type = Element::Simple); + Element(const ElementsLocation &location, QGraphicsItem * parent= nullptr, int *state = nullptr, Element::kind link_type = Element::Simple); ~Element() override; private: Element(const Element &); diff --git a/sources/qetgraphicsitem/slaveelement.cpp b/sources/qetgraphicsitem/slaveelement.cpp index 3c61830d3..d69b778bd 100644 --- a/sources/qetgraphicsitem/slaveelement.cpp +++ b/sources/qetgraphicsitem/slaveelement.cpp @@ -29,8 +29,8 @@ * @param s parent diagram * @param state int used to know if the creation of element have error */ -SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) : - Element(location, qgi, state, Element::Slave) +SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *parent, int *state) : + Element(location, parent, state, Element::Slave) { } diff --git a/sources/qetgraphicsitem/slaveelement.h b/sources/qetgraphicsitem/slaveelement.h index fe5067da9..3117451da 100644 --- a/sources/qetgraphicsitem/slaveelement.h +++ b/sources/qetgraphicsitem/slaveelement.h @@ -25,7 +25,7 @@ class SlaveElement : public Element { Q_OBJECT public: - explicit SlaveElement (const ElementsLocation &, QGraphicsItem * = nullptr, int * = nullptr); + explicit SlaveElement (const ElementsLocation &, QGraphicsItem * parent= nullptr, int * = nullptr); ~SlaveElement() override; void linkToElement(Element *elmt) override; void unlinkAllElements() override;