From 790497978a967d101f80aee1c415d70a4b2a53fd Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Thu, 22 Oct 2026 18:33:06 +0200 Subject: [PATCH] Split the labelling of terminal symbols only An element of any other type draws its label as a whole, whatever the labelling setting says: the colon in a label like "-K1:13" is part of that label, not a terminal number waiting to be split off. Only an element whose data says it is a terminal is ever drawn split. The test picks a non-terminal whose own label field draws the label it is given -- not a report (its label is where its partner is), not a slave (its label follows its master) and not a numbered symbol (a formula composes its label): those draw texts of their own the split never touches. --- sources/qetgraphicsitem/element.cpp | 15 ++++-- tests/qttest/tst_terminallabeldisplay.cpp | 63 +++++++++++++++++++++++ 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index da0f98202..cf4a84174 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -2769,11 +2769,14 @@ QString Element::actualLabel() of its own for the terminal number; and the two one under the other when it is split without such a field -- so a symbol drawn before the setting existed still shows all of its label, only shorter. + Only an element of the terminal type is ever drawn split: the colon + in any other label is part of the label ("-K1:13"). */ QString Element::labelForDisplay() { const QString label = actualLabel(); - const bool split = QetSettings::terminalLabelSplit(); + const bool split = m_data.m_type == ElementData::Terminal + && QetSettings::terminalLabelSplit(); //The "Show name" box of the selection properties hides the name //of this element on the sheet only: the element keeps all of its @@ -2813,13 +2816,15 @@ QString Element::labelForDisplay() /** @brief Element::terminalNumberForDisplay @return the part of the label behind its last colon ("1" in "X1:1"), - or an empty string while the labelling is shown in one field: the - number is already there with the label, showing it twice would only - be noise. @sa labelForDisplay + or an empty string while the labelling is shown in one field -- and + for every element which is no terminal, whose colon is part of its + label: the number is already there with the label, showing it twice + would only be noise. @sa labelForDisplay */ QString Element::terminalNumberForDisplay() { - if (!QetSettings::terminalLabelSplit()) { + if (m_data.m_type != ElementData::Terminal + || !QetSettings::terminalLabelSplit()) { return QString(); } diff --git a/tests/qttest/tst_terminallabeldisplay.cpp b/tests/qttest/tst_terminallabeldisplay.cpp index fa07cc4af..8d7f4b4ee 100644 --- a/tests/qttest/tst_terminallabeldisplay.cpp +++ b/tests/qttest/tst_terminallabeldisplay.cpp @@ -109,6 +109,45 @@ class tst_terminallabeldisplay : public QObject return nullptr; } + //A non-terminal element of the fixture whose label field draws the + //label it is given, colon and all: a terminal's own kind of drawing + //is what the split changes, so the test needs an element which is + //none of the things drawing a label of their own -- a report (its + //label is where its partner is), a slave (its label follows its + //master) or a numbered symbol (a formula composes its label) + static Element *nonTerminalWithLabel(QETProject &project, const QString &label) + { + for (Diagram *diagram : project.diagrams()) + for (Element *element : diagram->elements()) + { + if (element->elementData().m_type == ElementData::Terminal) { + continue; + } + if (element->linkType() & (Element::Slave | Element::AllReport)) { + continue; + } + DiagramContext dc = element->elementInformations(); + if (!dc.value(QStringLiteral("formula")).toString().isEmpty()) { + continue; + } + dc.addValue(QStringLiteral("label"), label); + element->setElementInformations(dc); + if (element->actualLabel() != label) { + continue; + } + //Only an element whose own label field draws the + //label it stores: everything else draws a text of + //its own, which this test would not understand + DynamicElementTextItem *field = fieldBoundTo(element, + QETInformation::ELMT_LABEL); + if (!field || field->toPlainText() != label) { + continue; + } + return element; + } + return nullptr; + } + private slots: void cleanup() { @@ -336,6 +375,30 @@ private slots: QCOMPARE(element->labelForDisplay(), element->actualLabel()); } + //The labelling is drawn split for an element of the terminal type + //only: the colon in the label of any other element ("-K1:13") is + //part of the label, not a split waiting to happen + void splitLeavesNonTerminalsWithColonAlone() + { + QetSettings::setTerminalLabelSplit(true); + + const QString fixture = QFINDTESTDATA("fixtures/every_feature.qet"); + QETProject project(fixture); + QCOMPARE(project.state(), QETProject::Ok); + + Element *element = nonTerminalWithLabel(project, QStringLiteral("-K1:13")); + QVERIFY2(element, + "the fixture has an element which is no terminal and draws the label it is given"); + + QCOMPARE(element->actualLabel(), QStringLiteral("-K1:13")); + QCOMPARE(element->labelForDisplay(), QStringLiteral("-K1:13")); + QVERIFY(element->terminalNumberForDisplay().isEmpty()); + + DynamicElementTextItem *label = fieldBoundTo(element, QETInformation::ELMT_LABEL); + QVERIFY2(label, "the symbol has a field for its label"); + QCOMPARE(label->toPlainText(), QStringLiteral("-K1:13")); + } + //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