Let Align and Snap to grid move drawn shapes (#1145)

Rectangles, ellipses, lines and polygons were left out of the Align
submenu: with only shapes selected every command was greyed out, and a
shape outside a group was ignored when aligning it with a symbol.

Shapes now take part like pictures. Their edges are the shape as drawn
(the new QetShapeItem::sceneOutlineRect(), without the pen, the 6 px
selection margin or the wider hover outline; the old code used
sceneBoundingRect() for grouped shapes and so aligned them 6 px off).
The point that goes on the grid is the top-left corner of that box: a
rectangle's corner, an ellipse's box. pos() is not used, because a
shape drawn with Ctrl held or rotated has its corners off the grid
while pos() is on it.

The menu's enable rule now counts what the command counts, a group as
one. Before, two symbols in one group enabled the six align commands,
which then did nothing and only said so in the status bar.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-29 23:24:38 +13:00
parent cbbb9fd0ac
commit 795484ff4f
5 changed files with 127 additions and 86 deletions
+4 -1
View File
@@ -22,11 +22,12 @@
#include <QUndoCommand>
class Diagram;
class DiagramContent;
/**
@brief The AlignSelectionCommand class
Moves each selected item by its own amount, as one undo step.
Symbols, pictures and free texts take part; locked items are left
Symbols, pictures, free texts and shapes take part; locked items are left
where they are and counted, so the caller can say so.
*/
class AlignSelectionCommand : public QUndoCommand
@@ -52,6 +53,8 @@ class AlignSelectionCommand : public QUndoCommand
int lockedCount() const;
int itemCount() const;
static int unitCount(const DiagramContent &dc);
private:
QPointer<Diagram> m_diagram;
int m_locked_count = 0;