From 17e9f53b8195bf060cc1e7199e7fe1ad9bd99b15 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Sun, 4 Oct 2026 00:07:16 +1300 Subject: [PATCH] View > Show: keep the wire text of a potential when its wire is deleted With "one text per potential", deleting the wire that carries the text moves it to another wire of the potential, but only if the text isVisible(). While wire texts were hidden by View > Show none was, so the text was never moved and the potential came back with no text. ShownKinds::wantsVisible() also counts a text hidden only by its kind. Also drop the always-true/false enum range checks clang warned about. Co-Authored-By: Claude Opus 5.5 --- sources/shownkinds.cpp | 14 +++++++++++-- sources/shownkinds.h | 1 + .../deleteqgraphicsitemcommand.cpp | 4 +++- tests/qttest/tst_shownkinds.cpp | 20 +++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/sources/shownkinds.cpp b/sources/shownkinds.cpp index e68584115..b8afae7b3 100644 --- a/sources/shownkinds.cpp +++ b/sources/shownkinds.cpp @@ -30,7 +30,7 @@ namespace */ bool ShownKinds::isShown(Kind kind) { - return kind < 0 || kind >= KindCount || !hidden[kind]; + return kind >= KindCount || !hidden[kind]; } /** @@ -39,7 +39,7 @@ bool ShownKinds::isShown(Kind kind) */ void ShownKinds::setShown(Kind kind, bool shown) { - if (kind >= 0 && kind < KindCount) { + if (kind < KindCount) { hidden[kind] = !shown; } } @@ -106,6 +106,16 @@ bool ShownKinds::isHidden(const QGraphicsItem *item) return false; } +/** + @return true if @a item is visible, or would be but for its kind being + hidden. For code that asks isVisible() to learn what an item's own code + decided (which wire carries the text of a potential). +*/ +bool ShownKinds::wantsVisible(const QGraphicsItem *item) +{ + return item && (item->isVisible() || item->data(hidden_key).toBool()); +} + /** Bring the items of @a kind on @a scene in line with the current state: hide the ones that are visible, or show again the ones hidden for it. diff --git a/sources/shownkinds.h b/sources/shownkinds.h index adb835ab6..39d254c49 100644 --- a/sources/shownkinds.h +++ b/sources/shownkinds.h @@ -70,6 +70,7 @@ namespace ShownKinds void tag(QGraphicsItem *item, Kind kind); void setVisible(QGraphicsItem *item, bool visible); bool isHidden(const QGraphicsItem *item); + bool wantsVisible(const QGraphicsItem *item); void apply(QGraphicsScene *scene, Kind kind); } diff --git a/sources/undocommand/deleteqgraphicsitemcommand.cpp b/sources/undocommand/deleteqgraphicsitemcommand.cpp index a2db0baf8..661e17608 100644 --- a/sources/undocommand/deleteqgraphicsitemcommand.cpp +++ b/sources/undocommand/deleteqgraphicsitemcommand.cpp @@ -26,6 +26,7 @@ #include "../qetgraphicsitem/dynamicelementtextitem.h" #include "../qetgraphicsitem/element.h" #include "../qetgraphicsitem/elementtextitemgroup.h" +#include "../shownkinds.h" #include "../qetgraphicsitem/terminal.h" #include "addelementtextcommand.h" #include "../TerminalStrip/realterminal.h" @@ -324,7 +325,8 @@ void DeleteQGraphicsItemCommand::redo() //current conductor is visible (that mean the conductor have the single displayed text) //We call adjustTextItemPosition to other conductor at the same potential to keep //a visible text on this potential. - if (m_diagram -> defaultConductorProperties.m_one_text_per_folio && c -> textItem() -> isVisible()) + //wantsVisible(): also while wire texts are hidden (View > Show) + if (m_diagram -> defaultConductorProperties.m_one_text_per_folio && ShownKinds::wantsVisible(c -> textItem())) { QList conductor_list; conductor_list << c -> relatedPotentialConductors(false).values(); diff --git a/tests/qttest/tst_shownkinds.cpp b/tests/qttest/tst_shownkinds.cpp index c980ae6c3..048e81a4e 100644 --- a/tests/qttest/tst_shownkinds.cpp +++ b/tests/qttest/tst_shownkinds.cpp @@ -134,6 +134,26 @@ private slots: QVERIFY(!number->isVisible()); } + // wantsVisible() tells the wire carrying a potential's text from the + // others while wire texts are hidden, so deleting it moves the text. + void wantsVisibleWhileKindHidden() + { + auto carrier = add(); + auto other = add(); + ShownKinds::tag(carrier, ShownKinds::WireNumbers); + ShownKinds::tag(other, ShownKinds::WireNumbers); + ShownKinds::setVisible(other, false); + ShownKinds::setShown(ShownKinds::WireNumbers, false); + ShownKinds::apply(scene, ShownKinds::WireNumbers); + QVERIFY(!carrier->isVisible()); + QVERIFY(ShownKinds::wantsVisible(carrier)); + QVERIFY(!ShownKinds::wantsVisible(other)); + ShownKinds::setShown(ShownKinds::WireNumbers, true); + ShownKinds::apply(scene, ShownKinds::WireNumbers); + QVERIFY(ShownKinds::wantsVisible(carrier)); + QVERIFY(!ShownKinds::wantsVisible(other)); + } + // A text under a hidden parent still counts as wanting to be visible. void childOfHiddenParent() {