Minor : improve behavior when rotate terminal part.

iIn the element editor, every rotation is made around the center of the
scene, this is usefull when rotate several part but less when only one
need to be rotated, especially when it is the terminal part and we only
want to change the orientation.
This commit solve it. Now when only a terminal part is selected, the
terminal don't rotate around the center of the scene but change the
orientation.

The rotation, flip and mirror of parts are good features but always
rotate around the center of the scene and if the parts are far from the
center of the scene the behavior look inappropriate from the POV of user
(because parts move far from original position and can out of the view).
A good new features should be to solve it (rotate around the center of
the bounding rect of the selection) and probably extract the function
rotate/flip/mirror from the parts class and create a new class with for
only goal to calculate and apply these modifiaction trough an undo
command.
This commit is contained in:
joshua 2025-07-15 22:47:33 +02:00
parent 07c6ac6c9f
commit 1607c7f5dc
3 changed files with 38 additions and 0 deletions

View File

@ -525,7 +525,11 @@ void RotateElementsCommand::undo()
{
if (item->type() == PartTerminal::Type) {
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
if(m_items.size() == 1) {
term->previousOrientation();
} else {
term->setRotation(term->rotation()-90);
}
}
else if (item->type() == PartRectangle::Type) {
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
@ -570,7 +574,11 @@ void RotateElementsCommand::redo()
{
if (item->type() == PartTerminal::Type) {
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
if (m_items.size() == 1) {
term->nextOrientation();
} else {
term->setRotation(term->rotation()+90);
}
}
else if (item->type() == PartRectangle::Type) {
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);

View File

@ -224,6 +224,34 @@ void PartTerminal::mirror() {
emit xChanged(); // all terminal-signals call "updateForm"
}
void PartTerminal::nextOrientation()
{
switch (d->m_orientation) {
case Qet::North :
setOrientation(Qet::East); break;
case Qet::East :
setOrientation(Qet::South); break;
case Qet::South :
setOrientation(Qet::West); break;
case Qet::West :
setOrientation(Qet::North); break;
}
}
void PartTerminal::previousOrientation()
{
switch (d->m_orientation) {
case Qet::North :
setOrientation(Qet::West); break;
case Qet::East :
setOrientation(Qet::North); break;
case Qet::South :
setOrientation(Qet::East); break;
case Qet::West :
setOrientation(Qet::South); break;
}
}
/**
@brief PartTerminal::setTerminalName

View File

@ -78,6 +78,8 @@ class PartTerminal : public CustomElementGraphicPart
qreal rotation() const;
void flip();
void mirror();
void nextOrientation();
void previousOrientation();
QString terminalName() const { return d -> m_name; }