mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-24 19:00:00 +01:00
initial work to move everything into the propertiesinterface which is related to it
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user