diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index d8c190b01..f790c1609 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -518,8 +518,9 @@ void Element::initLink(QETProject *prj) { * @param dc */ void Element::setElementInformations(DiagramContext dc) { + DiagramContext old_info = element_informations_; element_informations_ = dc; - emit elementInfoChange(element_informations_); + emit elementInfoChange(old_info, element_informations_); } /** diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 98578a118..0e0070a8a 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -121,7 +121,7 @@ class Element : public QetGraphicsItem { kind link_type_; signals: - void elementInfoChange(DiagramContext); + void elementInfoChange(DiagramContext old_info, DiagramContext new_info); //METHODS related to information public: diff --git a/sources/qetgraphicsitem/masterelement.cpp b/sources/qetgraphicsitem/masterelement.cpp index b22061fa9..e3ba996e9 100644 --- a/sources/qetgraphicsitem/masterelement.cpp +++ b/sources/qetgraphicsitem/masterelement.cpp @@ -17,6 +17,7 @@ */ #include "masterelement.h" #include "crossrefitem.h" +#include "elementtextitem.h" /** * @brief MasterElement::MasterElement @@ -31,7 +32,7 @@ MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qg cri_ (nullptr) { link_type_ = Master; - connect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); + connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext))); } /** @@ -97,13 +98,14 @@ void MasterElement::unlinkElement(Element *elmt) { /** * @brief MasterElement::initLink - * Initialise the links between this element and other element. * @param project + * Call init Link from custom element and after + * call update label for setup it. */ void MasterElement::initLink(QETProject *project) { //Create the link with other element if needed CustomElement::initLink(project); - updateLabel(); + updateLabel(DiagramContext(), elementInformations()); } /** @@ -111,13 +113,18 @@ void MasterElement::initLink(QETProject *project) { * update label of this element * and the comment item if he's displayed. */ -void MasterElement::updateLabel() { - QString label = elementInformations()["label"].toString(); - bool show = elementInformations().keyMustShow("label"); - - // setup the label - if (!label.isEmpty() && show) setTaggedText("label", label, true); +void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info) { + //Label of element + if (old_info["label"].toString() != new_info["label"].toString()) { + if (new_info["label"].toString().isEmpty()) + setTaggedText("label", "_", false); + else + setTaggedText("label", new_info["label"].toString(), true); + } + if (ElementTextItem *eti = taggedText("label")) { + new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label")); + } //Delete or update the xref if (cri_) { diff --git a/sources/qetgraphicsitem/masterelement.h b/sources/qetgraphicsitem/masterelement.h index 53c660c1a..32d83916a 100644 --- a/sources/qetgraphicsitem/masterelement.h +++ b/sources/qetgraphicsitem/masterelement.h @@ -44,7 +44,7 @@ class MasterElement : public CustomElement signals: public slots: - void updateLabel(); + void updateLabel(DiagramContext old_info, DiagramContext new_info); private: bool aboutDeleteXref (); diff --git a/sources/qetgraphicsitem/simpleelement.cpp b/sources/qetgraphicsitem/simpleelement.cpp index 8ba0c597b..a187efdb5 100644 --- a/sources/qetgraphicsitem/simpleelement.cpp +++ b/sources/qetgraphicsitem/simpleelement.cpp @@ -17,6 +17,7 @@ */ #include "simpleelement.h" #include "commentitem.h" +#include "elementtextitem.h" /** * @brief SimpleElement::SimpleElement * @param location @@ -29,37 +30,47 @@ SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qg m_comment_item (nullptr) { link_type_ = Simple; - connect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); + connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext))); } /** * @brief SimpleElement::~SimpleElement */ SimpleElement::~SimpleElement() { - disconnect(this, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); if (m_comment_item) delete m_comment_item; } +/** + * @brief SimpleElement::initLink + * @param project + * Call init Link from custom element and after + * call update label for setup it. + */ void SimpleElement::initLink(QETProject *project) { CustomElement::initLink(project); - updateLabel(); + updateLabel(DiagramContext(), elementInformations()); } /** * @brief SimpleElement::updateLabel * update label of this element */ -void SimpleElement::updateLabel() { +void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info) { //Label of element - QString label = elementInformations()["label"].toString(); - bool show = elementInformations().keyMustShow("label"); + if (old_info["label"].toString() != new_info["label"].toString()) { + if (new_info["label"].toString().isEmpty()) + setTaggedText("label", "_", false); + else + setTaggedText("label", new_info["label"].toString(), true); + } - // setup the label - if (!label.isEmpty() && show) setTaggedText("label", label, true); + if (ElementTextItem *eti = taggedText("label")) { + new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label")); + } //Comment of element - QString comment = elementInformations()["comment"].toString(); - bool must_show = elementInformations().keyMustShow("comment"); + QString comment = new_info["comment"].toString(); + bool must_show = new_info.keyMustShow("comment"); if (!(comment.isEmpty() || !must_show) && !m_comment_item) { m_comment_item = new CommentItem(this); diff --git a/sources/qetgraphicsitem/simpleelement.h b/sources/qetgraphicsitem/simpleelement.h index 9ed9354ae..8b7c09c48 100644 --- a/sources/qetgraphicsitem/simpleelement.h +++ b/sources/qetgraphicsitem/simpleelement.h @@ -40,7 +40,7 @@ class SimpleElement : public CustomElement { signals: public slots: - void updateLabel(); + void updateLabel(DiagramContext old_info, DiagramContext new_info); private: CommentItem *m_comment_item;