Take the label field off the sheet while the name is hidden

An element whose name must not be drawn left its label field behind
as an empty frame: selected along with the element, ready to click,
drawing nothing. The field now follows the Show name box both ways:

- a field bound to the label is hidden while Element::labelShown()
  says no, and shown again the moment the box is ticked again, both
  through the same signals which refresh the text (elementInfoChange,
  the label connection refresh, binding the field to another
  information), so it can never get stuck on one side;
- a hidden field is deselected and gets no resize handles, and one
  which comes back gets its handles back when its element is still
  selected;
- every other field, composite texts included, is drawn as always,
  and the data of the element never changes - only the drawing.

Adds a test: the field is visible, goes away with the name, and
comes back with it.
This commit is contained in:
Kellermorph
2026-10-22 13:18:55 +02:00
parent edf761c2b6
commit 337502edfc
4 changed files with 76 additions and 2 deletions
@@ -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
@@ -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);
+4
View File
@@ -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
+30
View File
@@ -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)