Terminal: pass the voltage across a separation only when it was edited

The three code paths that copied the voltage / protocol to the far
side of a function separated terminal -- the conductor properties
dialog, search/replace and the script API -- compared it against the
far wire's own properties instead of against the edit itself. The two
sides differ on that field just as often as not, so the comparison
held no matter what was edited and every change overwrote the far
side's voltage: setting a colour on a 24 V side dragged the 0 V one
along, where master left it alone. Compare the edit -- what the
dialog was filled with against what the user made of it -- so that a
change of the voltage / protocol is what crosses, which is what the
selection panel multi-edit already did. The values are read before
the undo commands are pushed, since QPropertyUndoCommand applies on
push.

An explicitly selected wire is never the far side of anything:
picking one wire on each side of a separation and editing them edits
them both, in full, however the selection happens to be walked. Nor
is a wire that belongs to a potential on any path, so reaching it
once normally and once across a separation gives it the full edit.
This commit is contained in:
Kellermorph
2026-10-13 20:13:18 +02:00
parent 561ddc29bf
commit 408ef5114d
6 changed files with 170 additions and 18 deletions
+92
View File
@@ -165,6 +165,98 @@ class tst_conductormultiedit : public QObject
QCOMPARE(c.m_properties.m_function, QStringLiteral("fnC"));
}
// The explicitly picked side of a separation: selecting one
// wire on each side and editing them edits them both, in
// full -- however the selection happens to be walked (#review)
void selectedWireIsNeverSeparated()
{
FakeWire a("1", "fnA", "", {}), c("3", "fnC", "", {});
FakeWire::separate({&a}, {&c});
const ConductorProperties original_a = a.properties();
const ConductorProperties original_c = c.properties();
const ConductorProperties after = edited(original_a,
&ConductorProperties::m_function, "PWR");
for (const Wires &selection : {Wires {&a, &c}, Wires {&c, &a}})
{
//Each order starts from the same, unedited state
a.setProperties(original_a);
c.setProperties(original_c);
QSet<FakeWire *> separated;
const Wires t = ConductorMultiEdit::targets(selection, true,
&separated);
//c is picked, so it is not "the far side" of anything
QCOMPARE(separated, (QSet<FakeWire *> {}));
QUndoStack stack;
QUndoCommand *undo = ConductorMultiEdit::undo(t, original_a,
after, separated);
QVERIFY(undo);
stack.push(undo);
QCOMPARE(a.m_properties.m_function, QStringLiteral("PWR"));
QCOMPARE(c.m_properties.m_function, QStringLiteral("PWR"));
}
}
// A wire that belongs to the potential as well -- on any path,
// however far that path runs -- takes the full edit, even when a
// separation also reaches it. The fake's potential is one hop
// deep, unlike the real one, so the shared potential is stated
// in full here.
void wireReachableBothWaysIsNotSeparated()
{
FakeWire a("1", "fnA", "", {}), b("2", "fnB", "", {}),
c("3", "fnC", "", {});
FakeWire::join({&a, &b, &c});
FakeWire::separate({&a}, {&c});
QSet<FakeWire *> separated;
const Wires t = ConductorMultiEdit::targets(Wires {&a}, true,
&separated);
QCOMPARE(QSet<FakeWire *>(t.begin(), t.end()),
(QSet<FakeWire *> {&a, &b, &c}));
QCOMPARE(separated, (QSet<FakeWire *> {}));
const ConductorProperties shown = a.properties();
QUndoStack stack;
stack.push(ConductorMultiEdit::undo(t, shown, edited(shown,
&ConductorProperties::m_function, "PWR"), separated));
QCOMPARE(c.m_properties.m_function, QStringLiteral("PWR"));
}
// The far side only takes the voltage when the edit changed it:
// editing the function of a 24 V wire must leave the 0 V one
// at 0 V, not drag it along (#review)
void separatedWireKeepsVoltageWhenNotEdited()
{
FakeWire a("1", "fnA", "", {}), c("3", "fnC", "", {});
FakeWire::separate({&a}, {&c});
a.m_properties.m_tension_protocol = "24V";
c.m_properties.m_tension_protocol = "0V";
QSet<FakeWire *> separated;
const Wires t = ConductorMultiEdit::targets(Wires {&a}, true,
&separated);
const ConductorProperties shown = a.properties();
QUndoStack stack;
//Only the function changes: the far side changes nothing
stack.push(ConductorMultiEdit::undo(t, shown, edited(shown,
&ConductorProperties::m_function, "PWR"), separated));
QCOMPARE(c.m_properties.m_function, QStringLiteral("fnC"));
QCOMPARE(c.m_properties.m_tension_protocol, QStringLiteral("0V"));
//Now the voltage changes too: it crosses, and only it
const ConductorProperties shown_now = a.properties();
stack.push(ConductorMultiEdit::undo(t, shown_now, edited(shown_now,
&ConductorProperties::m_tension_protocol, "30V"), separated));
QCOMPARE(c.m_properties.m_tension_protocol, QStringLiteral("30V"));
QCOMPARE(c.m_properties.m_function, QStringLiteral("fnC"));
QCOMPARE(a.m_properties.m_tension_protocol, QStringLiteral("30V"));
}
// One edit of three wires: each takes the function, keeps its
// own number and cable; one undo restores all three exactly
void undoRedoThreeWires()