element-editor: limit decimal places for sizes and positions to two, when saving file

This commit is contained in:
plc-user 2025-02-09 12:33:24 +01:00
parent 706eba6612
commit 1fc33aa1ba
8 changed files with 67 additions and 29 deletions

View File

@ -106,13 +106,21 @@ 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()));
qreal x = qRound(top_left.x() * 100.0) / 100.0;
qreal y = qRound(top_left.y() * 100.0) / 100.0;
qreal w = qRound(rect().width() * 100.0) / 100.0;
qreal h = qRound(rect().height() * 100.0) / 100.0;
qreal s = qRound(m_start_angle * 100.0) / 100.0;
qreal a = qRound(m_span_angle * 100.0) / 100.0;
xml_element.setAttribute("x", QString("%1").arg(x));
xml_element.setAttribute("y", QString("%1").arg(y));
xml_element.setAttribute("width", QString("%1").arg(w));
xml_element.setAttribute("height", QString("%1").arg(h));
//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));
xml_element.setAttribute("start", QString("%1").arg(s / 16));
xml_element.setAttribute("angle", QString("%1").arg(a / 16));
stylesToXml(xml_element);
return(xml_element);
}

View File

@ -97,10 +97,14 @@ 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()));
qreal x = (qRound(pos().x() * 100.0) / 100.0);
qreal y = (qRound(pos().y() * 100.0) / 100.0);
qreal rot = (qRound(rotation() * 10.0) / 10.0);
root_element.setAttribute("x", QString::number(x));
root_element.setAttribute("y", QString::number(y));
root_element.setAttribute("z", QString::number(zValue()));
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
root_element.setAttribute("rotation", QString::number(QET::correctAngle(rot)));
root_element.setAttribute("font", font().toString());
root_element.setAttribute("uuid", m_uuid.toString());
root_element.setAttribute("frame", m_frame? "true" : "false");

View File

@ -89,19 +89,24 @@ const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const
QDomElement xml_element;
if (qFuzzyCompare(rect().width(), rect().height()))
{
double w = qRound(rect().width() * 100.0) / 100.0;
xml_element = xml_document.createElement("circle");
xml_element.setAttribute("diameter", QString("%1").arg(rect().width()));
xml_element.setAttribute("diameter", QString("%1").arg(w));
}
else
{
double w = qRound(rect().width() * 100.0) / 100.0;
double h = qRound(rect().height() * 100.0) / 100.0;
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.setAttribute("width", QString("%1").arg(w));
xml_element.setAttribute("height", QString("%1").arg(h));
}
QPointF top_left(sceneTopLeft());
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
double x = qRound(top_left.x() * 100.0) / 100.0;
double y = qRound(top_left.y() * 100.0) / 100.0;
xml_element.setAttribute("x", QString("%1").arg(x));
xml_element.setAttribute("y", QString("%1").arg(y));
stylesToXml(xml_element);

View File

@ -115,15 +115,22 @@ const QDomElement PartLine::toXml(QDomDocument &xml_document) const
QPointF p1(sceneP1());
QPointF p2(sceneP2());
p1.setX((qRound(p1.x() * 100.0)) / 100.0);
p1.setY((qRound(p1.y() * 100.0)) / 100.0);
p2.setX((qRound(p2.x() * 100.0)) / 100.0);
p2.setY((qRound(p2.y() * 100.0)) / 100.0);
qreal firstLength = ((qRound(first_length * 100.0)) / 100.0);
qreal secondLength = ((qRound(second_length * 100.0)) / 100.0);
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("length1", QString("%1").arg(firstLength));
xml_element.setAttribute("end2", Qet::endTypeToString(second_end));
xml_element.setAttribute("length2", QString("%1").arg(second_length));
xml_element.setAttribute("length2", QString("%1").arg(secondLength));
stylesToXml(xml_element);
return(xml_element);

View File

@ -126,8 +126,10 @@ 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()));
qreal x = ((qRound(point.x() * 100.0)) / 100.0);
qreal y = ((qRound(point.y() * 100.0)) / 100.0);
xml_element.setAttribute(QString("x%1").arg(i), QString("%1").arg(x));
xml_element.setAttribute(QString("y%1").arg(i), QString("%1").arg(y));
++ i;
}
if (!m_closed) xml_element.setAttribute("closed", "false");

View File

@ -91,13 +91,19 @@ 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()));
qreal x = (qRound(top_left.x() * 100.0) / 100.0);
qreal y = (qRound(top_left.y() * 100.0) / 100.0);
qreal w = (qRound(m_rect.width() * 100.0) / 100.0);
qreal h = (qRound(m_rect.height() * 100.0) / 100.0);
qreal rx = (qRound(m_xRadius * 100.0) / 100.0);
qreal ry = (qRound(m_yRadius * 100.0) / 100.0);
xml_element.setAttribute("rx", QString::number(m_xRadius));
xml_element.setAttribute("ry", QString::number(m_yRadius));
xml_element.setAttribute("x", QString::number(x));
xml_element.setAttribute("y", QString::number(y));
xml_element.setAttribute("width", QString::number(w));
xml_element.setAttribute("height", QString::number(h));
xml_element.setAttribute("rx", QString::number(rx));
xml_element.setAttribute("ry", QString::number(ry));
stylesToXml(xml_element);
return(xml_element);

View File

@ -101,11 +101,14 @@ 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()));
qreal x = (qRound(pos().x() * 100.0) / 100.0);
qreal y = (qRound(pos().y() * 100.0) / 100.0);
qreal rot = (qRound(rotation() * 10.0) / 10.0);
xml_element.setAttribute("x", QString::number(x));
xml_element.setAttribute("y", QString::number(y));
xml_element.setAttribute("text", toPlainText());
xml_element.setAttribute("font", font().toString());
xml_element.setAttribute("rotation", QString::number(rotation()));
xml_element.setAttribute("rotation", QString::number(rot));
xml_element.setAttribute("color", defaultTextColor().name());
return(xml_element);

View File

@ -96,8 +96,11 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const
{
QDomElement xml_element = xml_document.createElement("terminal");
xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x()));
xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y()));
qreal x = (qRound(q->scenePos().x() * 100.0) / 100.0);
qreal y = (qRound(q->scenePos().y() * 100.0) / 100.0);
xml_element.setAttribute("x", QString("%1").arg(x));
xml_element.setAttribute("y", QString("%1").arg(y));
xml_element.setAttribute("uuid", m_uuid.toString());
xml_element.setAttribute("name", m_name);