From 0109a5d188af36ff9581a2402b77cff7a40dedc0 Mon Sep 17 00:00:00 2001 From: blacksun Date: Fri, 21 Mar 2014 14:40:33 +0000 Subject: [PATCH] slave element: when linked to master, label is replaced by the label of master, and show the position of the master git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2946 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/qetgraphicsitem/customelement.cpp | 26 ++++++++++-- sources/qetgraphicsitem/customelement.h | 1 + sources/qetgraphicsitem/element.cpp | 11 ++++++ sources/qetgraphicsitem/element.h | 5 ++- sources/qetgraphicsitem/elementtextitem.h | 3 ++ sources/qetgraphicsitem/slaveelement.cpp | 48 +++++++++++++++++++++++ sources/qetgraphicsitem/slaveelement.h | 6 ++- 7 files changed, 95 insertions(+), 5 deletions(-) diff --git a/sources/qetgraphicsitem/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp index ce8467d78..d22fb86d6 100644 --- a/sources/qetgraphicsitem/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -711,18 +711,19 @@ ElementTextItem *CustomElement::parseInput(QDomElement &e) { ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this); eti -> setFont(QETApp::diagramTextsFont(size)); + eti -> setTagg(e.attribute("tagg", "other")); - // position du champ de texte + // position the text field eti -> setOriginalPos(QPointF(pos_x, pos_y)); eti -> setPos(pos_x, pos_y); - // rotation du champ de texte + // rotation of the text field qreal original_rotation_angle = 0.0; QET::attributeIsAReal(e, "rotation", &original_rotation_angle); eti -> setOriginalRotationAngle(original_rotation_angle); eti -> setRotationAngle(original_rotation_angle); - // comportement du champ lorsque son element parent est pivote + // behavior when the parent element is rotated eti -> setFollowParentRotations(e.attribute("rotate") == "true"); list_texts_ << eti; @@ -900,3 +901,22 @@ void CustomElement::setPainterStyle(QDomElement &e, QPainter &qp) { // mise en place (ou non) de l'antialiasing setQPainterAntiAliasing(qp, e.attribute("antialias") == "true"); } + +/** + * @brief CustomElement::setTaggedText + * Set text @newstr to the text tagged with @tagg. + * If tagg is found return the text item, else return 0. + * @param tagg required tagg + * @param newstr new label + * @param noeditable set editable or not (by default, set editable) + */ +ElementTextItem* CustomElement::setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable) { + foreach (ElementTextItem *eti, list_texts_) { + if (eti -> tagg() == tagg) { + eti -> setPlainText(newstr); + eti -> setNoEditable(noeditable); + return eti; + } + } + return 0; +} diff --git a/sources/qetgraphicsitem/customelement.h b/sources/qetgraphicsitem/customelement.h index 88b2cef26..4d77c9c05 100644 --- a/sources/qetgraphicsitem/customelement.h +++ b/sources/qetgraphicsitem/customelement.h @@ -90,6 +90,7 @@ class CustomElement : public FixedElement { virtual void setQPainterAntiAliasing(QPainter &, bool); virtual bool validOrientationAttribute(const QDomElement &); virtual void setPainterStyle(QDomElement &, QPainter &); + ElementTextItem* setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable=false); }; /** diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index ee2f0f650..0ec193f4e 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -503,6 +503,17 @@ void Element::initLink(QETProject *prj) { tmp_uuids_link.clear(); } +/** + * @brief Element::setElementInformations + * Set new information for this element. + * This method emit @elementInfoChange + * @param dc + */ +void Element::setElementInformations(DiagramContext dc) { + element_informations_ = dc; + emit elementInfoChange(element_informations_); +} + /** * @brief comparPos * Compare position of the two elements. Compare 3 points: diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 813649b15..896b2371d 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -115,10 +115,13 @@ class Element : public QetGraphicsItem { QUuid uuid_; kind link_type_; + signals: + void elementInfoChange(DiagramContext); + //METHODS related to information public: DiagramContext elementInformations()const {return element_informations_;} - void setElementInformations(DiagramContext dc) {element_informations_ = dc;} + void setElementInformations(DiagramContext dc);//{element_informations_ = dc; emit elementInfoChange(dc);} DiagramContext kindInformations() const {return kind_informations_;} //@kind_information_ is used to store more information //about the herited class like contactelement for know // kind of contact (simple tempo) or number of contact show by the element. diff --git a/sources/qetgraphicsitem/elementtextitem.h b/sources/qetgraphicsitem/elementtextitem.h index c2edef619..fe6df2878 100644 --- a/sources/qetgraphicsitem/elementtextitem.h +++ b/sources/qetgraphicsitem/elementtextitem.h @@ -44,6 +44,7 @@ class ElementTextItem : public DiagramTextItem { QPointF original_position; qreal original_rotation_angle_; bool first_move_; + QString tagg_; // methods public: @@ -63,6 +64,8 @@ class ElementTextItem : public DiagramTextItem { void setOriginalRotationAngle(const qreal &); qreal originalRotationAngle() const; virtual void setFont(const QFont &); + void setTagg(const QString &str) {tagg_ = str;} + QString tagg() const {return tagg_;} public slots: void adjustItemPosition(int = 0); diff --git a/sources/qetgraphicsitem/slaveelement.cpp b/sources/qetgraphicsitem/slaveelement.cpp index 186572c26..e6fcd2ec7 100644 --- a/sources/qetgraphicsitem/slaveelement.cpp +++ b/sources/qetgraphicsitem/slaveelement.cpp @@ -16,6 +16,9 @@ along with QElectroTech. If not, see . */ #include "slaveelement.h" +#include "diagramposition.h" +#include "qetapp.h" +#include "elementtextitem.h" /** * @brief SlaveElement::SlaveElement @@ -28,6 +31,7 @@ SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) : CustomElement(location, qgi, s, state) { + Xref_item = NULL; link_type_ = Slave; } @@ -50,6 +54,9 @@ void SlaveElement::linkToElement(Element *elmt) { if (elmt->linkType() == Master && !connected_elements.contains(elmt)) { if(!isFree()) unlinkAllElements(); connected_elements << elmt; + updateLabel(); + connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel())); + connect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); elmt->linkToElement(this); } } @@ -76,6 +83,47 @@ void SlaveElement::unlinkElement(Element *elmt) { //Ensure elmt is linked to this element if (connected_elements.contains(elmt)) { connected_elements.removeOne(elmt); + disconnect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel())); + disconnect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); + delete Xref_item; Xref_item = NULL; + updateLabel(); elmt->unlinkElement(this); } } + +/** + * @brief SlaveElement::updateLabel + * update the label (tagged with label) of this element. + * If this element is connected to a master, + * the label show the string tagged by "label" of the master + * and add a qgraphicstextitem for show the position of the master + */ +void SlaveElement::updateLabel() { + QString label("_"); + QString Xreflabel; + bool no_editable = false; + + //must be linked to set the label of master + if (linkedElements().count()) { + no_editable = true; + Element *elmt = linkedElements().first(); + label = elmt -> elementInformations()["label"].toString(); + + Xreflabel = "("; + Xreflabel += QString::number(elmt->diagram()->folioIndex()+1); + Xreflabel += "-"; + Xreflabel += elmt->diagram() -> convertPosition(elmt -> scenePos()).toString(); + Xreflabel += ")"; + } + + // set the new label + ElementTextItem *eti = setTaggedText("label", label, no_editable); + if (eti && !isFree()) { + if (Xref_item) Xref_item -> setPlainText(Xreflabel); + else { + Xref_item = new QGraphicsTextItem(Xreflabel, eti); + Xref_item -> setFont(QETApp::diagramTextsFont(5)); + Xref_item -> setPos(eti -> boundingRect().bottomLeft()); + } + } +} diff --git a/sources/qetgraphicsitem/slaveelement.h b/sources/qetgraphicsitem/slaveelement.h index 1fa0bddd8..5b82f09d0 100644 --- a/sources/qetgraphicsitem/slaveelement.h +++ b/sources/qetgraphicsitem/slaveelement.h @@ -32,7 +32,11 @@ class SlaveElement : public CustomElement signals: - public slots: + private slots: + void updateLabel(); + + private: + QGraphicsTextItem *Xref_item; };