mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-25 15:34:13 +01:00
Mirror a symbol twice and it comes back where it was
Mirroring a symbol on a folio keeps its centre in place and then snapped the new position to the grid. A symbol that was not on the grid was pulled onto it, so a second mirror the same way left it a few pixels away from where it started. In perceuse.qet that is 171 symbols, each way. tst_scriptmirror::mirrorBackAndSave() picks its symbol in an order that changes from run to run, so it failed only some of the time (three runs in eight on macOS, and on the Windows CI). The move is now snapped to the grid instead of the position. A symbol on the grid stays on it, one off the grid keeps its offset, and because qRound() rounds halves away from zero both ways, a second mirror moves it exactly back. The new tst_scriptmirror::mirrorTwiceComesBack mirrors every symbol of perceuse.qet twice, horizontally and vertically, and checks that every terminal is back in place. It fails on master (171 symbols moved). No change to the file format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -83,15 +83,17 @@ MirrorSelectionCommand::MirrorSelectionCommand(const QList<Element *> &elements,
|
||||
|
||||
//The mirror is about the element's hotspot, which is often a
|
||||
//corner of the symbol: move it so that it stays where it was,
|
||||
//centre on centre, and on the grid
|
||||
//centre on centre. The move is snapped to the grid, not the new
|
||||
//position: an element on the grid stays on it, one off the grid
|
||||
//keeps its offset, and a second mirror moves it exactly back.
|
||||
QPointF centre = element->boundingRect().center();
|
||||
centre = QTransform::fromScale(new_horizontal ? -1 : 1, new_vertical ? -1 : 1)
|
||||
.map(centre);
|
||||
centre = QTransform().rotate(element->rotation()).map(centre);
|
||||
|
||||
const QPointF old_pos = element->pos();
|
||||
const QPointF new_pos = Diagram::snapToGrid(
|
||||
element->mapToScene(element->boundingRect().center()) - centre);
|
||||
const QPointF new_pos = old_pos + Diagram::snapToGrid(
|
||||
element->mapToScene(element->boundingRect().center()) - centre - old_pos);
|
||||
if (new_pos != old_pos)
|
||||
new QPropertyUndoCommand(element, "pos", old_pos, new_pos, this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user