TEST a Merge branch 'XMLProperties'

it gets built let's test it for bugs

 Conflicts:
	sources/ElementsCollection/fileelementcollectionitem.cpp
	sources/QetGraphicsItemModeler/qetgraphicshandleritem.h
	sources/borderproperties.cpp
	sources/conductorproperties.cpp
	sources/conductorproperties.h
	sources/diagram.cpp
	sources/diagram.h
	sources/diagramprintdialog.cpp
	sources/diagramprintdialog.h
	sources/editor/graphicspart/customelementgraphicpart.cpp
	sources/editor/graphicspart/partarc.cpp
	sources/editor/graphicspart/partdynamictextfield.cpp
	sources/editor/graphicspart/partdynamictextfield.h
	sources/editor/graphicspart/partellipse.cpp
	sources/editor/graphicspart/partline.cpp
	sources/editor/graphicspart/partpolygon.cpp
	sources/editor/graphicspart/partrectangle.cpp
	sources/editor/graphicspart/partterminal.cpp
	sources/editor/graphicspart/partterminal.h
	sources/editor/graphicspart/parttext.cpp
	sources/properties/propertiesinterface.cpp
	sources/properties/propertiesinterface.h
	sources/properties/terminaldata.cpp
	sources/properties/terminaldata.h
	sources/properties/xrefproperties.cpp
	sources/properties/xrefproperties.h
	sources/qetgraphicsitem/conductor.cpp
	sources/qetgraphicsitem/conductor.h
	sources/qetgraphicsitem/conductortextitem.h
	sources/qetgraphicsitem/dynamicelementtextitem.h
	sources/qetgraphicsitem/element.cpp
	sources/qetgraphicsitem/element.h
	sources/qetgraphicsitem/elementtextitemgroup.h
	sources/qetgraphicsitem/slaveelement.cpp
	sources/qetgraphicsitem/slaveelement.h
	sources/qetgraphicsitem/terminal.cpp
	sources/qetgraphicsitem/terminal.h
	sources/qetproject.cpp
	sources/titleblockproperties.cpp
This commit is contained in:
Simon De Backer
2020-10-13 21:51:34 +02:00
67 changed files with 2095 additions and 1486 deletions

View File

@@ -161,7 +161,8 @@ 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;
@@ -496,9 +497,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"));
}
@@ -511,16 +511,17 @@ 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
#if TODO_LIST
#pragma message("@TODO remove code for QT 5.14 or later")
#endif
QStringList styles = qde.attribute("style").split(";", Qt::SkipEmptyParts);
#endif
//Check each pair of style
QRegularExpression rx("^\\s*([a-z-]+)\\s*:\\s*([a-zA-Z-]+)\\s*$");
foreach (QString style, styles)
@@ -863,7 +864,9 @@ void CustomElementGraphicPart::stylesFromXml(const QDomElement &qde)
}
}
//Get antialiasing
_antialiased = qde.attribute("antialias") == "true";
QString a;
propertyString(qde, "antialias", &a);
_antialiased = a == "true";
}

View File

@@ -303,7 +303,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;

View File

@@ -19,6 +19,7 @@
#define CUSTOM_ELEMENT_PART_H
#include "qet.h"
#include "propertiesinterface.h"
class CustomElement;
class ElementPrimitiveDecorator;
@@ -37,7 +38,7 @@ class QGraphicsSceneMouseEvent;
there 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:
/**
@@ -61,14 +62,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
*/

View File

@@ -97,40 +97,70 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
}
/**
@brief PartArc::toXml
Export this arc in xml
@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
{
* @brief PartArc::toXml
* Export this arc in xml
* @param xml_document : Xml document to use for create the xml element.
* @return : an xml element that describe this arc
*/
QDomElement PartArc::toXml(QDomDocument &xml_document) const
{
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);
}
/**
@brief PartArc::fromXml
Import the properties of this arc from a xml element.
@param qde : Xml document to use.
*/
void PartArc::fromXml(const QDomElement &qde) {
* @brief PartArc::fromXml
* Import the properties of this arc from a xml element.
* @param qde : Xml document to use.
*/
bool 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()) );
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;
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) );
m_start_angle = 0;
if (propertyDouble(qde, "start", &m_start_angle) == PropertyFlags::NoValidConversion)
return false;
m_start_angle *= 16;
m_span_angle = -1440;
if (propertyDouble(qde, "angle", &m_span_angle) == PropertyFlags::NoValidConversion)
return false;
m_span_angle *= 16;
return true;
}
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;
}
/**

View File

@@ -51,8 +51,9 @@ 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;
static bool valideXml(QDomElement& element);
QPainterPath shape() const override;
QPainterPath shadowShape() const override;

View File

@@ -88,45 +88,46 @@ void PartDynamicTextField::handleUserTransformation(
}
/**
@brief PartDynamicTextField::toXml
@param dom_doc
@return
*/
const QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const
* @brief PartDynamicTextField::toXml
* @param document
* @return
*/
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<Qt::Alignment>();
if(this -> alignment() &Qt::AlignRight)
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignRight));
else if(this -> alignment() &Qt::AlignLeft)
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignLeft));
else if(this -> alignment() &Qt::AlignHCenter)
root_element.setAttribute("Halignment", me.valueToKey(Qt::AlignHCenter));
if(this->alignment() &Qt::AlignRight)
root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignRight)));
else if(this->alignment() &Qt::AlignLeft)
root_element.appendChild(createXmlProperty(dom_doc, "Halignment", me.valueToKey(Qt::AlignLeft)));
else if(this->alignment() &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));
else if(this -> alignment() & Qt::AlignTop)
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignTop));
else if(this -> alignment() &Qt::AlignVCenter)
root_element.setAttribute("Valignment", me.valueToKey(Qt::AlignVCenter));
if(this->alignment() &Qt::AlignBottom)
root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignBottom)));
else if(this->alignment() & Qt::AlignTop)
root_element.appendChild(createXmlProperty(dom_doc, "Valignment", me.valueToKey(Qt::AlignTop)));
else if(this->alignment() &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()));
root_element.appendChild(dom_text);
//Info name
if(!m_info_name.isEmpty()) {
QDomElement dom_info_name = dom_doc.createElement("info_name");
@@ -152,25 +153,32 @@ const QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const
}
/**
@brief PartDynamicTextField::fromXml
@param dom_elmt
*/
void PartDynamicTextField::fromXml(const QDomElement &dom_elmt) {
* @brief PartDynamicTextField::fromXml
* @param element
*/
bool PartDynamicTextField::fromXml(const QDomElement &dom_elmt)
{
if (dom_elmt.tagName() != xmlName()) {
qDebug() << "PartDynamicTextField::fromXml : Wrong tagg name";
return;
return false;
}
double x=0, y=0, z=0, rot=0;
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 (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;
if (dom_elmt.hasAttribute("font")) {
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 {
@@ -181,21 +189,25 @@ void PartDynamicTextField::fromXml(const QDomElement &dom_elmt) {
setFont(QETApp::dynamicTextsItemFont(9));
}
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());
propertyUuid(dom_elmt, "uuid", &m_uuid);
bool frame;
propertyBool(dom_elmt, "frame", &frame);
double text_width=-1;
propertyDouble(dom_elmt, "text_width", &text_width);
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<Qt::Alignment>();
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");
@@ -220,6 +232,29 @@ void 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) {
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;
}
/**

View File

@@ -1,17 +1,17 @@
/*
Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -75,10 +75,10 @@ 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);
static bool valideXml(QDomElement& dom_elmt);
DynamicElementTextItem::TextFrom textFrom() const;
void setTextFrom (DynamicElementTextItem::TextFrom text_from);
QString text() const;
@@ -116,7 +116,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;

View File

@@ -78,56 +78,85 @@ void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
}
/**
@brief PartEllipse::toXml
Export this ellipse in xml
@param xml_document : Xml document to use for create the xml element.
@return : an xml element that describe this ellipse
*/
const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const
* @brief PartEllipse::toXml
* Export this ellipse in xml
* @param xml_document : Xml document to use for create the xml element.
* @return : an xml element that describe this ellipse
*/
QDomElement PartEllipse::toXml(QDomDocument &xml_document) const
{
QDomElement xml_element;
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);
}
/**
@brief PartEllipse::fromXml
Import the properties of this ellipse from a xml element.
@param qde : Xml document to use.
*/
void PartEllipse::fromXml(const QDomElement &qde)
* @brief PartEllipse::fromXml
* Import the properties of this ellipse from a xml element.
* @param qde : Xml document to use.
*/
bool 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();
if (propertyDouble(qde, "width", &width) == PropertyFlags::NoValidConversion ||
propertyDouble(qde, "height", &height) == PropertyFlags::NoValidConversion)
return false;
}
else {
if (propertyDouble(qde, "diameter", &width) == PropertyFlags::NoValidConversion)
return false;
height = width;
}
else
width = height = qde.attribute("diameter", "0").toDouble();
m_rect = QRectF(mapFromScene(qde.attribute("x", "0").toDouble(),
qde.attribute("y", "0").toDouble()),
QSizeF(width, height));
if (propertyDouble(qde, "x", &x) == PropertyFlags::NoValidConversion ||
propertyDouble(qde, "y", &y) == PropertyFlags::NoValidConversion)
return false;
m_rect = QRectF(mapFromScene(x, y), QSizeF(width, height));
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;
}
/**

View File

@@ -52,8 +52,9 @@ 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;
static bool valideXml(QDomElement& element);
QPainterPath shape() const override;
QPainterPath shadowShape() const override;
void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjusteHandlerPos();}

View File

@@ -104,46 +104,80 @@ void PartLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
}
/**
@brief PartLine::toXml
Export this line in xml
@param xml_document : Xml document to use for create the xml element.
@return an xml element that describe this line
*/
const QDomElement PartLine::toXml(QDomDocument &xml_document) const
* @brief PartLine::toXml
* Export this line in xml
* @param xml_document : Xml document to use for create the xml element.
* @return an xml element that describe this line
*/
QDomElement PartLine::toXml(QDomDocument &xml_document) const
{
QPointF p1(sceneP1());
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));
stylesToXml(xml_element);
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_document, xml_element);
return(xml_element);
}
/**
@brief PartLine::fromXml
Import the properties of this line from a xml element.
@param qde : Xml document to use
*/
void PartLine::fromXml(const QDomElement &qde) {
* @brief PartLine::fromXml
* Import the properties of this line from a xml element.
* @param qde : Xml document to use
*/
bool 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;
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;
if (propertyString(qde, "end1", &s) != PropertyFlags::Success)
return false;
first_end = Qet::endTypeFromString(s);
if (propertyString(qde, "end2", &s) != PropertyFlags::Success)
return false;
first_end = Qet::endTypeFromString(s);
if (propertyDouble(qde, "length1", &first_length) == PropertyFlags::NoValidConversion ||
propertyDouble(qde, "length2", &second_length) == PropertyFlags::NoValidConversion)
return false;
return true;
}
bool PartLine::valideXml(QDomElement& element) const {
if (propertyDouble(element, "x1") ||
propertyDouble(element, "y1") ||
propertyDouble(element, "x2") ||
propertyDouble(element, "y2") ||
propertyString(element, "end1") ||
propertyString(element, "end2") ||
propertyDouble(element, "length1") ||
propertyDouble(element, "length2") )
return false;
return true;
}
/**

View File

@@ -70,8 +70,9 @@ 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;
bool valideXml(QDomElement& element) const;
virtual QPointF sceneP1() const;
virtual QPointF sceneP2() const;
QPainterPath shape() const override;
@@ -115,10 +116,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<QPointF> saved_points_;
QLineF m_line;
int m_vector_index = -1;

View File

@@ -85,56 +85,71 @@ void PartPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
}
/**
@brief PartPolygon::fromXml
Import the properties of this polygon from a xml element
@param qde : Xml document to use
*/
void PartPolygon::fromXml(const QDomElement &qde)
* @brief PartPolygon::fromXml
* Import the properties of this polygon from a xml element
* @param qde : Xml document to use
*/
bool PartPolygon::fromXml(const QDomElement &qde)
{
stylesFromXml(qde);
int error_counter = 0;
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)) == PropertyFlags::Success &&
propertyDouble(qde, QString("y%1").arg(i)) == PropertyFlags::Success)
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());
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;
m_closed = qde.attribute("closed") != "false";
if (propertyBool(qde, "closed", &m_closed) != PropertyFlags::Success)
return false;
return true;
}
/**
@brief PartPolygon::toXml
Export this polygin in xml
@param xml_document : Xml document to use for create the xml element
@return an xml element that describe this polygon
*/
const QDomElement PartPolygon::toXml(QDomDocument &xml_document) const
* @brief PartPolygon::toXml
* Export this polygin in xml
* @param xml_document : Xml document to use for create the xml element
* @return an xml element that describe this polygon
*/
QDomElement PartPolygon::toXml(QDomDocument &xml_document) const
{
QDomElement xml_element = xml_document.createElement("polygon");
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);
}
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.

View File

@@ -61,8 +61,10 @@ 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;
static bool valideXml(QDomElement& element);
QPainterPath shape () const override;
QPainterPath shadowShape() const override;

View File

@@ -84,15 +84,15 @@ 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());
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;
if (x > rect.width()/2) {
@@ -106,7 +106,10 @@ const QDomElement PartRectangle::toXml(QDomDocument &xml_document) const
xml_element.setAttribute("rx", QString::number(m_xRadius));
xml_element.setAttribute("ry", QString::number(m_yRadius));
stylesToXml(xml_element);
xml_element.appendChild(createXmlProperty(xml_document, "rx", m_xRadius));
xml_element.appendChild(createXmlProperty(xml_document, "ry", m_yRadius));
stylesToXml(xml_document, xml_element);
return(xml_element);
}
@@ -115,18 +118,45 @@ 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=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) == PropertyFlags::NoValidConversion ||
propertyDouble(qde, "width", &h) == PropertyFlags::NoValidConversion)
return false;
QRectF rect(QPointF(x,y), QSizeF(w, h));
setRect(rect.normalized());
setXRadius(qde.attribute("rx", "0").toDouble());
setYRadius(qde.attribute("ry", "0").toDouble());
if (propertyDouble(qde, "rx", &rx) == PropertyFlags::NoValidConversion ||
propertyDouble(qde, "ry", &ry) == PropertyFlags::NoValidConversion)
return false;
setXRadius(rx);
setYRadius(ry);
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;
}
/**

View File

@@ -60,8 +60,9 @@ 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;
static bool valideXml(QDomElement& element);
QRectF rect() const;
void setRect(const QRectF &rect);

View File

@@ -29,8 +29,9 @@ PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
CustomElementGraphicPart(editor, parent)
{
d = new TerminalData(this);
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
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();
setZValue(100000);
}
@@ -44,10 +45,21 @@ 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);
setPos(d -> m_pos);
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
propertyUuid(xml_elmt, "uuid", &d->m_uuid);
if (!d->fromXml(xml_elmt))
return false;
setPos(d->m_pos);
updateSecondPoint();
return true;
}
/**
@@ -55,9 +67,26 @@ 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);
QDomElement qdo = xml_document.createElement("terminal");
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++) {
qdo.appendChild(terminalDataElement.childNodes().at(i).cloneNode()); // cloneNode() is important, otherwise no deep clone is made
}
return qdo;
}
bool PartTerminal::valideXml(QDomElement& element)
{
return TerminalData::valideXml(element);
}
/**

View File

@@ -53,12 +53,11 @@ 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;
void paint(
QPainter *painter,
const QStyleOptionGraphicsItem *,
QWidget *) override;
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;
QPainterPath shadowShape() const override {return shape();}

View File

@@ -1,17 +1,17 @@
/*
Copyright 2006-2020 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -42,8 +42,8 @@ PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent) :
setAcceptHoverEvents(true);
setDefaultTextColor(Qt::black);
setPlainText(QObject::tr(
"T",
"default text when adding a text in the element editor"));
"T",
"default text when adding a text in the element editor"));
adjustItemPosition(1);
// adjust textfield position after line additions/deletions
@@ -66,29 +66,49 @@ 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 ok;
bool PartText::fromXml(const QDomElement &xml_element)
{
int size;
QString font;
if (xml_element.hasAttribute("size")) {
int font_size = xml_element.attribute("size").toInt(&ok);
if (!ok || font_size < 1) {
font_size = 20;
if (propertyInteger(xml_element, "size", &size) != PropertyFlags::NotFound)
{
if (size < 1) {
size = 20;
}
QFont font_ = this -> font();
font_.setPointSize(font_size);
QFont font_ = this->font();
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_);
} else {
return false;
}
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());
QColor color;
QString text;
propertyColor(xml_element, "color", &color);
setDefaultTextColor(color);
propertyString(xml_element, "text", &text);
setPlainText(text);
double x=0, y=0, rot=0;
if (propertyDouble(xml_element, "x", &x) == PropertyFlags::NoValidConversion ||
propertyDouble(xml_element, "y", &y) == PropertyFlags::NoValidConversion)
return false;
setPos(x, y);
if (propertyDouble(xml_element, "rotation", &rot) == PropertyFlags::NoValidConversion)
return false;
setRotation(rot);
return true;
}
/**
@@ -96,20 +116,44 @@ 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());
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);
}
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.
*/

View File

@@ -58,8 +58,9 @@ 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;
static bool valideXml(QDomElement& element);
QDomElement toXml(QDomDocument &) const override;
void setRotation(qreal angle) {(QGraphicsObject::setRotation(QET::correctAngle(angle)));}
bool isUseless() const override;
QRectF sceneGeometricRect() const override;