This commit is contained in:
Martin Marmsoler
2020-08-24 20:34:18 +02:00
parent 385d0ffd69
commit a10709157d
27 changed files with 276 additions and 167 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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<Qt::Alignment>();
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<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");

View File

@@ -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;

View File

@@ -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;
}
/**

View File

@@ -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();}

View File

@@ -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;
}
/**

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}
/**

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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());

View File

@@ -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;