go on with the work

This commit is contained in:
Martin Marmsoler
2020-08-25 20:14:38 +02:00
parent a10709157d
commit c5f1705745
40 changed files with 520 additions and 258 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -166,7 +166,7 @@ class Diagram : public QGraphicsScene
QList < QSet <Conductor *> > 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(),

View File

@@ -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<QSettings&>(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();
}
/**

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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.
*/

View File

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

View File

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

View File

@@ -20,6 +20,7 @@
#include <QString>
#include <QSettings>
#include <QColor>
#include <QDomElement>
#include <limits>
#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<int>::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);

View File

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

View File

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

View File

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

View File

@@ -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<QString, XRefProperties> defaultProperties();

View File

@@ -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<QPointF>& 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<Terminal *, int> &table_adr_id) const
{
QDomElement dom_element = dom_document.createElement("conductor");
//QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int> &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 {

View File

@@ -19,6 +19,7 @@
#define CONDUCTOR_H
#include "conductorproperties.h"
#include "propertiesinterface.h"
#include <QGraphicsPathItem>
#include "assignvariables.h"
@@ -39,7 +40,7 @@ typedef QHash<Qt::Corner, ConductorProfile> 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<Terminal *, int> &) const;
bool fromXml (const QDomElement &) override;
//QDomElement toXml (QDomDocument &, QHash<Terminal *, int> &) const;
QDomElement toXml (QDomDocument &doc) const override;
private:
bool pathFromXml(const QDomElement &);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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