let conductor textitem export to xml, because the read is also made from it

This commit is contained in:
Martin Marmsoler
2020-10-10 12:25:58 +02:00
parent 497673d83b
commit 0dfe0c1613
3 changed files with 29 additions and 21 deletions

View File

@@ -1032,13 +1032,7 @@ QDomElement Conductor::toXml(QDomDocument & doc) const {
dom_element.appendChild(node);
}
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()));
m_text_item->toXml(doc, dom_element);
return(dom_element);
}

View File

@@ -27,9 +27,7 @@
*/
ConductorTextItem::ConductorTextItem(Conductor *parent_conductor) :
DiagramTextItem(parent_conductor),
parent_conductor_(parent_conductor),
moved_by_user_(false),
rotate_by_user_(false)
parent_conductor_(parent_conductor)
{
setAcceptHoverEvents(true);
}
@@ -61,21 +59,36 @@ Conductor *ConductorTextItem::parentConductor() const {
return(parent_conductor_);
}
void ConductorTextItem::toXml(QDomDocument& doc, QDomElement& e) {
if(moved_by_user_)
{
e.appendChild(PropertiesInterface::createXmlProperty(doc, "userx", pos().x()));
e.appendChild(PropertiesInterface::createXmlProperty(doc, "usery", pos().y()));
}
if(rotate_by_user_)
e.appendChild(PropertiesInterface::createXmlProperty(doc, "rotation", rotation()));
}
/**
* @brief ConductorTextItem::fromXml
* Read the properties stored in the xml element given in parameter
* @param e
*/
void ConductorTextItem::fromXml(const QDomElement &e) {
if (e.hasAttribute("userx")) {
setPos(e.attribute("userx").toDouble(),
e.attribute("usery").toDouble());
moved_by_user_ = true;
}
if (e.hasAttribute("rotation")) {
setRotation(e.attribute("rotation").toDouble());
rotate_by_user_ = true;
}
double userx=0, usery=0;
if (PropertiesInterface::propertyDouble(e, "userx", &userx) == PropertiesInterface::PropertyFlags::Success &&
PropertiesInterface::propertyDouble(e, "usery", &usery) == PropertiesInterface::PropertyFlags::Success) {
setPos(userx, usery);
moved_by_user_ = true;
}
double rotation;
if (PropertiesInterface::propertyDouble(e, "rotation", &rotation) == PropertiesInterface::PropertyFlags::Success) {
setRotation(rotation);
rotate_by_user_ = true;
}
}
/**

View File

@@ -42,6 +42,7 @@ class ConductorTextItem : public DiagramTextItem
enum { Type = UserType + 1006 };
Conductor *parentConductor() const;
void fromXml(const QDomElement &) override;
void toXml(QDomDocument& doc, QDomElement& e);
int type() const override { return Type; }
virtual bool wasMovedByUser() const;
virtual bool wasRotateByUser() const;
@@ -61,8 +62,8 @@ class ConductorTextItem : public DiagramTextItem
// attributes
private:
Conductor *parent_conductor_;
bool moved_by_user_;
bool rotate_by_user_;
bool moved_by_user_{false};
bool rotate_by_user_{false};
QPointF before_mov_pos_;
};
#endif