diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index 225aba9dc..9a2b67d25 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -764,6 +764,8 @@ QVariant DynamicElementTextItem::itemChange(QGraphicsItem::GraphicsItemChange ch if(m_parent_element.data()->linkType() == Element::Slave) { connect(m_parent_element.data(), &Element::linkedElementChanged, this, &DynamicElementTextItem::masterChanged); + if(m_parent_element.data()->diagram()) + connect(m_parent_element.data()->diagram()->project(), &QETProject::XRefPropertiesChanged, this, &DynamicElementTextItem::updateXref); //The parent is already linked, wa call master changed for init the connection if(!m_parent_element.data()->linkedElements().isEmpty()) masterChanged(); @@ -1497,6 +1499,18 @@ void DynamicElementTextItem::updateXref() } } } + + //Remove stale "xref" from elementInformations when no longer needed + if(m_parent_element->linkType() == Element::Slave && + m_text_from == ElementInfo && m_info_name == "xref") + { + DiagramContext dc = m_parent_element->elementInformations(); + if(!dc.value("xref").toString().isEmpty()) + { + dc.remove("xref"); + m_parent_element->setElementInformations(dc); + } + } } void DynamicElementTextItem::setPlainText(const QString &text) diff --git a/sources/qetgraphicsitem/elementtextitemgroup.cpp b/sources/qetgraphicsitem/elementtextitemgroup.cpp index b04c91eda..9adade296 100644 --- a/sources/qetgraphicsitem/elementtextitemgroup.cpp +++ b/sources/qetgraphicsitem/elementtextitemgroup.cpp @@ -59,6 +59,11 @@ ElementTextItemGroup::ElementTextItemGroup(const QString &name, &Element::linkedElementChanged, this, &ElementTextItemGroup::updateXref); + if(parent->diagram()) + connect(parent->diagram()->project(), + &QETProject::XRefPropertiesChanged, + this, + &ElementTextItemGroup::updateXref); } ElementTextItemGroup::~ElementTextItemGroup() @@ -898,6 +903,25 @@ void ElementTextItemGroup::updateXref() } } } + + //Remove stale "xref" from elementInformations when no longer needed + if(m_parent_element->linkType() == Element::Slave && + m_parent_element->diagram()) + { + for(DynamicElementTextItem *deti : texts()) + { + if(deti->textFrom() == DynamicElementTextItem::ElementInfo && deti->infoName() == "xref") + { + DiagramContext dc = m_parent_element->elementInformations(); + if(!dc.value("xref").toString().isEmpty()) + { + dc.remove("xref"); + m_parent_element->setElementInformations(dc); + } + break; + } + } + } } void ElementTextItemGroup::adjustSlaveXrefPos(int slave_offset) diff --git a/sources/qetgraphicsitem/masterelement.cpp b/sources/qetgraphicsitem/masterelement.cpp index 01193ed00..24f12eca8 100644 --- a/sources/qetgraphicsitem/masterelement.cpp +++ b/sources/qetgraphicsitem/masterelement.cpp @@ -111,6 +111,7 @@ void MasterElement::unlinkElement(Element *elmt) ctx.remove(QETInformation::ELMT_PLC_COMMENT); ctx.remove(QETInformation::ELMT_PLC_CROSSREF); ctx.remove(QETInformation::ELMT_LABEL); + ctx.remove(QStringLiteral("xref")); elmt->setElementInformations(ctx); setGroupIndexForElement(elmt, -1); diff --git a/sources/undocommand/linkelementcommand.cpp b/sources/undocommand/linkelementcommand.cpp index 51860a944..19d4dcde7 100644 --- a/sources/undocommand/linkelementcommand.cpp +++ b/sources/undocommand/linkelementcommand.cpp @@ -254,6 +254,7 @@ void LinkElementCommand::undo() ctx.remove(QETInformation::ELMT_PLC_COMMENT); ctx.remove(QETInformation::ELMT_PLC_CROSSREF); ctx.remove(QETInformation::ELMT_LABEL); + ctx.remove(QStringLiteral("xref")); m_element->setElementInformations(ctx); foreach(Element *elmt, m_element->linkedElements()) @@ -291,6 +292,7 @@ void LinkElementCommand::undo() ctx.remove(QETInformation::ELMT_PLC_COMMENT); ctx.remove(QETInformation::ELMT_PLC_CROSSREF); ctx.remove(QETInformation::ELMT_LABEL); + ctx.remove(QStringLiteral("xref")); slave->setElementInformations(ctx); } @@ -622,6 +624,7 @@ void LinkElementCommand::makeLink(const QList &element_list) ctx.remove(QETInformation::ELMT_PLC_COMMENT); ctx.remove(QETInformation::ELMT_PLC_CROSSREF); ctx.remove(QETInformation::ELMT_LABEL); + ctx.remove(QStringLiteral("xref")); slave->setElementInformations(ctx); } m_element->unlinkElement(elmt);