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 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-04 00:07:16 +13:00
parent 649f06b3b8
commit 17e9f53b81
4 changed files with 36 additions and 3 deletions
+12 -2
View File
@@ -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.
+1
View File
@@ -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);
}
@@ -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 *> conductor_list;
conductor_list << c -> relatedPotentialConductors(false).values();
+20
View File
@@ -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()
{