mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-26 08:04:13 +01:00
Align: a group reduced to one shape lines up on its own centre
A group whose only unlocked member is a shape (its other members locked) kept a centre of (0,0), so Centrer horizontalement and Centrer verticalement pulled every item toward the folio origin and the shape itself landed off the line. The rule that turns a group's members into one item now lives in Alignment::combined(), where every member, shapes included, brings its own centre, and tst_alignment covers it. Also comments why unitFor()'s returned reference is safe, as asked in the review of #1087. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
@@ -54,6 +54,24 @@ namespace Alignment
|
||||
QPointF ref;
|
||||
};
|
||||
|
||||
/**
|
||||
@return @a items taken as one piece, the way a group lines up:
|
||||
their edges together, and the middle of that box as its centre.
|
||||
A single item keeps its own centre.
|
||||
*/
|
||||
inline Item combined(const QList<Item> &items)
|
||||
{
|
||||
Item result;
|
||||
for (const Item &item : items)
|
||||
result.edges = result.edges.isNull() ? item.edges
|
||||
: result.edges.united(item.edges);
|
||||
if (items.size() == 1)
|
||||
result.ref = items.first().ref;
|
||||
else
|
||||
result.ref = result.edges.center();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@return true if aligning on @a edge moves items along x
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user