mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
* Added the m_rotate_action to qetelementeditor.ui * Adding QAction to qetelementeditor.cpp and connecting it to new slot RotateElementsCommand defined in editorcommands.cpp
* Some types of elements need to specialize the setRotation method in order to behave correctly : - PartTerminal needs to call setOrientation - PartLine, PartRectangle and PartPolygon need a different rotation center.
This commit is contained in:
committed by
Laurent Trinques
parent
9135099dbf
commit
c640d96bca
@@ -609,3 +609,67 @@ void changeElementDataCommand::redo() {
|
||||
m_scene->setElementData(m_new);
|
||||
QUndoCommand::redo();
|
||||
}
|
||||
|
||||
RotateElementsCommand::RotateElementsCommand(ElementScene *scene, QUndoCommand *parent) :
|
||||
ElementEditionCommand(QObject::tr("Pivoter la selection", "undo caption"), scene, nullptr, parent)
|
||||
{
|
||||
m_items = scene->selectedItems();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief RotateElementsCommand::undo
|
||||
*/
|
||||
void RotateElementsCommand::undo()
|
||||
{
|
||||
for (QGraphicsItem *item : m_items)
|
||||
{
|
||||
if (item->type() == PartTerminal::Type) {
|
||||
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
|
||||
term->setRotation(term->rotation()-90);
|
||||
}
|
||||
else if (item->type() == PartRectangle::Type) {
|
||||
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
|
||||
rect->setRotation(rect->rotation()-90);
|
||||
}
|
||||
else if (item->type() == PartLine::Type) {
|
||||
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
|
||||
line->setRotation(line->rotation()-90);
|
||||
}
|
||||
else if (item->type() == PartPolygon::Type) {
|
||||
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
|
||||
poly->setRotation(poly->rotation()-90);
|
||||
}
|
||||
else {
|
||||
item->setRotation(item->rotation()-90);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
@brief RotateElementsCommand::redo
|
||||
*/
|
||||
void RotateElementsCommand::redo()
|
||||
{
|
||||
for (QGraphicsItem *item : m_items)
|
||||
{
|
||||
if (item->type() == PartTerminal::Type) {
|
||||
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
|
||||
term->setRotation(term->rotation()+90);
|
||||
}
|
||||
else if (item->type() == PartRectangle::Type) {
|
||||
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
|
||||
rect->setRotation(rect->rotation()+90);
|
||||
}
|
||||
else if (item->type() == PartLine::Type) {
|
||||
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
|
||||
line->setRotation(line->rotation()+90);
|
||||
}
|
||||
else if (item->type() == PartPolygon::Type) {
|
||||
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
|
||||
poly->setRotation(poly->rotation()+90);
|
||||
}
|
||||
else {
|
||||
item->setRotation(item->rotation()+90);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user