diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index ffb1535dd..c74a123a1 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -415,6 +415,7 @@ Element *DynamicElementTextItem::elementUseForInfo() const */ void DynamicElementTextItem::refreshLabelConnection() { + refreshLabelShown(); if ((m_text_from == ElementInfo && (m_info_name == QLatin1String("label") || m_info_name == QETInformation::ELMT_TERMINAL_NUMBER)) || @@ -434,6 +435,30 @@ void DynamicElementTextItem::refreshLabelConnection() } } +/** + @brief DynamicElementTextItem::refreshLabelShown + Whether this field is drawn at all: a field bound to the label of + an element whose "Show name" box is unticked (@sa Element::labelShown) + does not stay on the sheet as an empty frame to select -- it is + hidden, and comes back the moment the box is ticked again. Both ways + run through the same signals which refresh the text, so the field + can never get stuck on one side. Every other field is drawn as + always, and a composite text keeps drawing what is not the label. +*/ +void DynamicElementTextItem::refreshLabelShown() +{ + const bool shown = !(m_text_from == ElementInfo + && m_info_name == QETInformation::ELMT_LABEL) + || !m_parent_element + || m_parent_element.data()->labelShown(); + + if (!shown && isSelected()) { + setSelected(false); + } + setVisible(shown); + refreshResizeHandlesVisibility(); +} + /** @brief DynamicElementTextItem::textFrom @return what the final text is created from. @@ -592,7 +617,12 @@ void DynamicElementTextItem::setInfoName(const QString &info_name) || old_info_name == QETInformation::ELMT_TERMINAL_NUMBER)) { parentElement()->refreshLabelFields(); } - + + //A field which becomes, or stops being, the field for the + //label of its element is shown or hidden with the "Show name" + //box (@sa refreshLabelShown) + refreshLabelShown(); + emit infoNameChanged(info_name); } @@ -1001,7 +1031,11 @@ bool DynamicElementTextItem::sceneEventFilter(QGraphicsItem *watched, QEvent *ev */ void DynamicElementTextItem::refreshResizeHandlesVisibility() { - const bool handles_wanted = isSelected() || (m_parent_element && m_parent_element->isSelected()); + //A hidden text has no handles, not even while its element is + //selected: refreshLabelShown() puts them back when the text + //is shown again + const bool handles_wanted = isVisible() + && (isSelected() || (m_parent_element && m_parent_element->isSelected())); if (handles_wanted && !m_left_resize_handle) addResizeHandles(); else if (!handles_wanted && m_left_resize_handle) @@ -1202,6 +1236,11 @@ void DynamicElementTextItem::handlerMouseReleaseEvent(QetGraphicsHandlerItem *ha void DynamicElementTextItem::elementInfoChanged() { + //The "Show name" box of the selection properties was possibly + //ticked or unticked: the field of a hidden name leaves the + //sheet and comes back with the box (@sa refreshLabelShown) + refreshLabelShown(); + //A folio report's label shows where its partner is //(updateReportText()); the label in its information is only where //the partner was when last saved, and changing any other diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.h b/sources/qetgraphicsitem/dynamicelementtextitem.h index 3bc2a0afc..e6fc2134f 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.h +++ b/sources/qetgraphicsitem/dynamicelementtextitem.h @@ -97,6 +97,7 @@ class DynamicElementTextItem : public DiagramTextItem ElementTextItemGroup *parentGroup() const; Element *elementUseForInfo() const; void refreshLabelConnection(); + void refreshLabelShown(); DynamicElementTextItem::TextFrom textFrom() const; void setTextFrom (DynamicElementTextItem::TextFrom text_from); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index c978035a7..da0f98202 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -1690,6 +1690,10 @@ void Element::addDynamicTextItem(DynamicElementTextItem *deti) m_dynamic_text_list.append(deti); + //An element whose name must not be drawn does not keep the + //field of its label on the sheet either (@sa Element::labelShown) + deti->refreshLabelShown(); + //A field of its own for the terminal number is what the label //leaves the number to: the fields which draw the label follow //when such a field lands on the symbol diff --git a/tests/qttest/tst_terminallabeldisplay.cpp b/tests/qttest/tst_terminallabeldisplay.cpp index e52ecc89c..fa07cc4af 100644 --- a/tests/qttest/tst_terminallabeldisplay.cpp +++ b/tests/qttest/tst_terminallabeldisplay.cpp @@ -335,6 +335,36 @@ private slots: QVERIFY(!element->actualLabel().isEmpty()); QCOMPARE(element->labelForDisplay(), element->actualLabel()); } + + //The field of a hidden name does not stay on the sheet as an empty + //frame to select: it leaves the sheet with the box and comes back + //with it, both ways through the same signal + void hiddenNameHidesTheLabelField() + { + QetSettings::setTerminalLabelSplit(false); + + const QString fixture = QFINDTESTDATA("fixtures/every_feature.qet"); + QETProject project(fixture); + QCOMPARE(project.state(), QETProject::Ok); + + Element *element = terminalWithLabel(project, QStringLiteral("X1:1")); + QVERIFY(element); + DynamicElementTextItem *label = fieldBoundTo(element, QETInformation::ELMT_LABEL); + QVERIFY(label); + QVERIFY(label->isVisible()); + + hideName(element); + QVERIFY(!label->isVisible()); + + //The box ticked again: the element drops the information, + //and the field is drawn as it was before + DiagramContext dc = element->elementInformations(); + dc.remove(QStringLiteral("label_shown")); + element->setElementInformations(dc); + + QVERIFY(label->isVisible()); + QCOMPARE(label->toPlainText(), QStringLiteral("X1:1")); + } }; QET_APP_TEST_MAIN(tst_terminallabeldisplay)