Add "rotate group" to actually rotate a selection as a whole

RotateSelectionCommand's existing "Pivoter" action (Space) only ever
bumps each selected item's own rotation property -- QGraphicsItem's
setRotation() spins an item around its own local origin and never
touches pos(). Select three elements arranged in a row and rotate:
each spins 90 degrees individually, but the row stays a row. That's
"rotate each item," not "rotate the group."

Add a rotate_as_group parameter to RotateSelectionCommand (default
false, so the existing action and its one call site are unchanged).
When set, it computes a shared pivot once -- the bounding-box center
of the whole selection -- and queues a second, parallel "pos"
QPropertyUndoCommand alongside the existing "rotation" one, rotating
each item's position around that pivot by the same angle.

Scoped the position change to Element/IndependentTextItem/
DiagramImageItem only: these are the only selectable types with
scene-space pos(). ConductorTextItem, DynamicElementTextItem and
ElementTextItemGroup are all parent-relative children (confirmed by
reading their constructors), so when their owning Element is also
selected and gets its own pos() rotated, they're carried along for
free by Qt's normal parent/child transform propagation -- exactly
what the existing "skip rotation if parent is also selected" guard
already assumes for those three cases.

Exposed as a new, separate action ("Pivoter le groupe", Shift+Space)
next to the existing one rather than changing Space's behavior, since
some workflows may rely on the current per-item rotation.
This commit is contained in:
ispyisail
2026-08-04 18:51:22 +12:00
parent 7307a59c10
commit 32dd686144
4 changed files with 75 additions and 5 deletions
+5 -1
View File
@@ -21,10 +21,12 @@
#include <QUndoCommand>
#include <QPointer>
#include <QHash>
#include <QPointF>
class Diagram;
class ConductorTextItem;
class QPropertyUndoCommand;
class QGraphicsItem;
/**
@brief The RotateSelectionCommand class
@@ -33,13 +35,15 @@ class QPropertyUndoCommand;
class RotateSelectionCommand : public QUndoCommand
{
public:
RotateSelectionCommand(Diagram *diagram, qreal angle=90, QUndoCommand *parent=nullptr);
RotateSelectionCommand(Diagram *diagram, qreal angle=90, QUndoCommand *parent=nullptr, bool rotate_as_group=false);
void undo() override;
void redo() override;
bool isValid();
private:
void addGroupPositionUndo(QGraphicsItem *item, const QPointF &pivot, qreal angle);
Diagram *m_diagram =nullptr;
QList<QPointer<ConductorTextItem>> m_cond_text;