From 52e33787a8812066fa197cb5757560d072acdf08 Mon Sep 17 00:00:00 2001 From: dfochi Date: Mon, 25 Jul 2016 19:18:26 +0000 Subject: [PATCH] Fix Element Label when opening older QET versions. Fix old user created element label's handling on newer QET versions git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4591 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/qetgraphicsitem/customelement.cpp | 24 +++++++++++------------ sources/qetgraphicsitem/element.cpp | 24 ++++++++++++++++++++++- sources/qetgraphicsitem/element.h | 1 + 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/sources/qetgraphicsitem/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp index 155ac01dd..e14275588 100644 --- a/sources/qetgraphicsitem/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -726,6 +726,18 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp) { eti -> setFollowParentRotations(e.attribute("rotate") == "true"); list_texts_ << eti; + if (e.attribute("tagg")=="label") { + DiagramContext &dc = this->rElementInformations(); + dc.addValue("label", e.attribute("text")); + this->setElementInformations(dc); + this->setTaggedText("label", e.attribute("text")); + } + else if (e.attribute("tagg")=="function") { + DiagramContext &dc = this->rElementInformations(); + dc.addValue("function", e.attribute("text")); + this->setElementInformations(dc); + } + // Se positionne aux coordonnees indiquees dans la description du texte qp.setTransform(QTransform(), false); qp.translate(pos_x, pos_y); @@ -783,18 +795,6 @@ ElementTextItem *CustomElement::parseInput(QDomElement &e) { eti -> setFont(QETApp::diagramTextsFont(size)); eti -> setTagg(e.attribute("tagg", "other")); - if (e.attribute("tagg")=="label") { - DiagramContext &dc = this->rElementInformations(); - dc.addValue("label", e.attribute("text")); - this->setElementInformations(dc); - this->setTaggedText("label", e.attribute("text")); - } - else if (e.attribute("tagg")=="function") { - DiagramContext &dc = this->rElementInformations(); - dc.addValue("function", e.attribute("text")); - this->setElementInformations(dc); - } - // position the text field eti -> setOriginalPos(QPointF(pos_x, pos_y)); eti -> setPos(pos_x, pos_y); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index c0031f039..307045c35 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -307,6 +307,25 @@ void Element::updatePixmap() { paint(&p, 0); } +/** + This class is used to retrieve label and function information from element + and add it to Diagram Context. Used to make older versions work correctly + @param Element Text item to check information +*/ +void Element::etiToElementLabels(ElementTextItem *eti) { + if (eti->tagg() == "label" && eti->toPlainText()!= "_") { + DiagramContext &dc = this->rElementInformations(); + dc.addValue("label", eti->toPlainText()); + this->setElementInformations(dc); + this->setTaggedText("label", eti->toPlainText()); + } + else if(eti->tagg() == "function" && eti->toPlainText() != "_") { + DiagramContext &dc = this->rElementInformations(); + dc.addValue("function", eti->toPlainText()); + this->setElementInformations(dc); + } +} + /** Permet de savoir si un element XML (QDomElement) represente bien un element @param e Le QDomElement a valide @@ -393,7 +412,10 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool QList inputs = QET::findInDomElement(e, "inputs", "input"); foreach(QGraphicsItem *qgi, childItems()) { if (ElementTextItem *eti = qgraphicsitem_cast(qgi)) { - foreach(QDomElement input, inputs) eti -> fromXml(input); + foreach(QDomElement input, inputs) { + eti -> fromXml(input); + etiToElementLabels(eti); + } } } diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index ac24a6410..d772d812e 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -193,6 +193,7 @@ class Element : public QetGraphicsItem { void drawSelection(QPainter *, const QStyleOptionGraphicsItem *); void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *); void updatePixmap(); + void etiToElementLabels(ElementTextItem*); protected: virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent *event );