mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-13 18:14:13 +02:00
32dd686144
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.
56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef ROTATESELECTIONCOMMAND_H
|
|
#define ROTATESELECTIONCOMMAND_H
|
|
|
|
#include <QUndoCommand>
|
|
#include <QPointer>
|
|
#include <QHash>
|
|
#include <QPointF>
|
|
|
|
class Diagram;
|
|
class ConductorTextItem;
|
|
class QPropertyUndoCommand;
|
|
class QGraphicsItem;
|
|
|
|
/**
|
|
@brief The RotateSelectionCommand class
|
|
Rotate the selected items in the given diagram
|
|
*/
|
|
class RotateSelectionCommand : public QUndoCommand
|
|
{
|
|
public:
|
|
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;
|
|
QHash<ConductorTextItem *, bool> m_rotate_by_user;
|
|
QList<QPropertyUndoCommand*> m_undo;
|
|
|
|
};
|
|
|
|
#endif // ROTATESELECTIONCOMMAND_H
|