770 lines
21 KiB
C++
Raw Normal View History

/*
2025-01-04 13:37:40 +01:00
Copyright 2006-2025 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/>.
*/
#include "editorcommands.h"
/**
2020-08-20 21:57:35 +02:00
@brief ElementEditionCommand::ElementEditionCommand
Constructs an ElementEditionCommand,
thus embedding the provided \a scene and \a view.
@param scene
@param view
@param parent : Parent command
*/
2020-08-20 21:58:23 +02:00
ElementEditionCommand::ElementEditionCommand(ElementScene *scene,
ElementView *view,
QUndoCommand *parent):
QUndoCommand(parent),
m_scene(scene),
m_view(view)
{
}
/**
2020-08-20 21:57:35 +02:00
@brief ElementEditionCommand::ElementEditionCommand
Constructs an ElementEditionCommand,
thus embedding the provided \a scene and \a view.
@param text : Text describing the effect of the command
@param scene
@param view
@param parent : Parent command
*/
2020-08-20 21:58:23 +02:00
ElementEditionCommand::ElementEditionCommand(const QString &text,
ElementScene *scene,
ElementView *view,
QUndoCommand *parent):
QUndoCommand(text, parent),
m_scene(scene),
m_view(view)
{
}
/**
Destructor
*/
2020-09-07 22:03:40 +02:00
ElementEditionCommand::~ElementEditionCommand()
{
}
/**
@return the element editor/scene the command should take place on
*/
2020-09-07 22:03:40 +02:00
ElementScene *ElementEditionCommand::elementScene() const
{
return(m_scene);
}
/**
Define \a scene as the element editor/scene the command should take place
*/
void ElementEditionCommand::setElementScene(ElementScene *scene) {
m_scene = scene;
}
/**
@return the view the effect of the command should be rendered on
*/
2020-09-07 22:03:40 +02:00
ElementView *ElementEditionCommand::elementView() const
{
return(m_view);
}
/**
Define \a view as the view the effect of the command should be rendered on
*/
void ElementEditionCommand::setElementView(ElementView *view) {
m_view = view;
}
/*** CutPartsCommand ***/
/**
Constructeur
@param scene ElementScene concernee
@param parts Liste des parties coupees
@param parent QUndoCommand parent
*/
CutPartsCommand::CutPartsCommand(
ElementScene *scene,
const QList<QGraphicsItem *>& parts,
QUndoCommand *parent
) :
DeletePartsCommand(scene, parts.toVector(), parent)
{
setText(QString(QObject::tr("couper des parties", "undo caption")));
}
/// Destructeur
2020-09-07 22:03:40 +02:00
CutPartsCommand::~CutPartsCommand()
{
}
/*** MovePartsCommand ***/
/**
Constructeur
@param m Mouvement sous forme de QPointF
@param scene ElementScene concernee
@param parts Liste des parties deplacees
@param parent QUndoCommand parent
*/
MovePartsCommand::MovePartsCommand(
const QPointF &m,
ElementScene *scene,
const QList<QGraphicsItem *>& parts,
QUndoCommand *parent
) :
ElementEditionCommand(QObject::tr("déplacement", "undo caption"), scene, nullptr, parent),
movement(m),
first_redo(true)
{
moved_parts = parts;
}
/// Destructeur
2020-09-07 22:03:40 +02:00
MovePartsCommand::~MovePartsCommand()
{
}
/// Annule le deplacement
2020-09-07 22:03:40 +02:00
void MovePartsCommand::undo()
{
foreach(QGraphicsItem *qgi, moved_parts) qgi -> moveBy(-movement.x(), -movement.y());
}
/// Refait le deplacement
2020-09-07 22:03:40 +02:00
void MovePartsCommand::redo()
{
// le premier appel a redo, lors de la construction de l'objet, ne doit pas se faire
if (first_redo) {
first_redo = false;
return;
}
foreach(QGraphicsItem *qgi, moved_parts) qgi -> moveBy(movement.x(), movement.y());
}
/**
Constructeur
@param element_scene Element edite
@param before Listes des noms avant changement
@param after Listes des noms apres changement
@param parent QUndoCommand parent
*/
ChangeNamesCommand::ChangeNamesCommand(
ElementScene *element_scene,
const NamesList &before,
const NamesList &after,
QUndoCommand *parent
) :
ElementEditionCommand(QObject::tr("modification noms", "undo caption"), element_scene, nullptr, parent),
names_before(before),
names_after(after)
{
}
/// Destructeur
2020-09-07 22:03:40 +02:00
ChangeNamesCommand::~ChangeNamesCommand()
{
}
/// Annule le changement
2020-09-07 22:03:40 +02:00
void ChangeNamesCommand::undo()
{
auto data = m_scene->elementData();
data.m_names_list = names_before;
m_scene->setElementData(data);
}
/// Refait le changement
2020-09-07 22:03:40 +02:00
void ChangeNamesCommand::redo()
{
auto data = m_scene->elementData();
data.m_names_list = names_after;
m_scene->setElementData(data);
}
/**
Constructeur
@param elmt ElementScene concernee
@param o Option decrivant le type de traitement applique aux zValues des parties de l'element
@param parent QUndoCommand parent
*/
ChangeZValueCommand::ChangeZValueCommand(
ElementScene *elmt,
QET::DepthOption o,
QUndoCommand *parent
) :
ElementEditionCommand(elmt, nullptr, parent),
m_option(o)
{
// retrieve all primitives but terminals
QList<QGraphicsItem *> items_list = m_scene -> zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot);
// prend un snapshot des zValues
foreach(QGraphicsItem *qgi, items_list) undo_hash.insert(qgi, qgi -> zValue());
// choisit le nom en fonction du traitement
if (m_option == QET::BringForward) {
setText(QObject::tr("amener au premier plan", "undo caption"));
applyBringForward(items_list);
} else if (m_option == QET::Raise) {
setText(QObject::tr("rapprocher", "undo caption"));
applyRaise(items_list);
} else if (m_option == QET::Lower) {
Merge Qt5 branch sources folder to trunk -Cette ligne, et les suivantes ci-dessous, seront ignorées-- M sources/aboutqet.cpp M sources/bordertitleblock.cpp M sources/conductorproperties.h M sources/configdialog.cpp M sources/configpages.cpp M sources/configpages.h M sources/createdxf.h M sources/diagram.cpp M sources/diagram.h M sources/diagramcommands.cpp M sources/diagramcommands.h M sources/diagramprintdialog.cpp M sources/diagramprintdialog.h M sources/diagramschooser.cpp M sources/diagramschooser.h M sources/diagramview.cpp M sources/diagramview.h M sources/dvevent/dveventaddimage.cpp M sources/dvevent/dveventaddshape.cpp M sources/editor/arceditor.cpp M sources/editor/arceditor.h M sources/editor/editorcommands.cpp M sources/editor/editorcommands.h M sources/editor/elementitemeditor.h M sources/editor/elementprimitivedecorator.cpp M sources/editor/elementscene.cpp M sources/editor/elementscene.h M sources/editor/elementview.cpp M sources/editor/ellipseeditor.cpp M sources/editor/ellipseeditor.h M sources/editor/esevent/eseventaddtext.cpp M sources/editor/esevent/eseventaddtextfield.cpp M sources/editor/esevent/eseventinterface.cpp M sources/editor/graphicspart/customelementpart.h M sources/editor/graphicspart/parttext.cpp M sources/editor/graphicspart/parttext.h M sources/editor/graphicspart/parttextfield.cpp M sources/editor/graphicspart/parttextfield.h M sources/editor/lineeditor.cpp M sources/editor/lineeditor.h M sources/editor/polygoneditor.cpp M sources/editor/qetelementeditor.cpp M sources/editor/qetelementeditor.h M sources/editor/rectangleeditor.cpp M sources/editor/rectangleeditor.h M sources/editor/styleeditor.cpp M sources/editor/styleeditor.h M sources/editor/terminaleditor.cpp M sources/editor/terminaleditor.h M sources/editor/texteditor.cpp M sources/editor/texteditor.h M sources/editor/textfieldeditor.cpp M sources/editor/textfieldeditor.h M sources/editor/ui/elementpropertieseditorwidget.cpp M sources/elementdefinition.cpp M sources/elementdeleter.cpp M sources/elementdeleter.h M sources/elementdialog.cpp M sources/elementscategorieslist.h M sources/elementscategorieswidget.cpp M sources/elementscategorieswidget.h M sources/elementscategory.cpp M sources/elementscategorydeleter.cpp M sources/elementscategorydeleter.h M sources/elementscategoryeditor.cpp M sources/elementscategoryeditor.h M sources/elementscollection.cpp M sources/elementscollectioncache.cpp M sources/elementspanel.cpp M sources/elementspanel.h M sources/elementspanelwidget.cpp M sources/elementspanelwidget.h M sources/elementtextsmover.h M sources/exportdialog.cpp M sources/exportdialog.h M sources/exportproperties.cpp M sources/exportpropertieswidget.cpp M sources/exportpropertieswidget.h M sources/genericpanel.cpp M sources/integrationmoveelementshandler.cpp M sources/integrationmoveelementshandler.h M sources/interactivemoveelementshandler.cpp M sources/nameslistwidget.cpp M sources/nameslistwidget.h M sources/newelementwizard.cpp M sources/newelementwizard.h M sources/nomenclature.cpp M sources/nomenclature.h M sources/projectconfigpages.cpp M sources/projectview.cpp M sources/projectview.h M sources/qet.cpp M sources/qetapp.cpp M sources/qetapp.h M sources/qetdiagrameditor.cpp M sources/qetdiagrameditor.h M sources/qetgraphicsitem/conductor.cpp M sources/qetgraphicsitem/conductortextitem.cpp M sources/qetgraphicsitem/customelement.cpp M sources/qetgraphicsitem/diagramimageitem.cpp M sources/qetgraphicsitem/diagramtextitem.cpp M sources/qetgraphicsitem/diagramtextitem.h M sources/qetgraphicsitem/element.cpp M sources/qetgraphicsitem/ghostelement.cpp M sources/qetgraphicsitem/qetshapeitem.cpp M sources/qetgraphicsitem/terminal.cpp M sources/qetgraphicsitem/terminal.h M sources/qeticons.cpp M sources/qeticons.h M sources/qetmainwindow.cpp M sources/qetmessagebox.cpp M sources/qetmessagebox.h M sources/qetprintpreviewdialog.cpp M sources/qetprintpreviewdialog.h M sources/qetproject.cpp M sources/qetsingleapplication.cpp M sources/qettabbar.h M sources/qfilenameedit.cpp M sources/qtextorientationspinboxwidget.cpp M sources/qtextorientationspinboxwidget.h M sources/qtextorientationwidget.cpp M sources/qtextorientationwidget.h M sources/richtext/richtexteditor.cpp M sources/richtext/richtexteditor_p.h M sources/richtext/ui_addlinkdialog.h M sources/titleblock/dimensionwidget.h M sources/titleblock/gridlayoutanimation.h M sources/titleblock/helpercell.h M sources/titleblock/integrationmovetemplateshandler.cpp M sources/titleblock/integrationmovetemplateshandler.h M sources/titleblock/qettemplateeditor.cpp M sources/titleblock/qettemplateeditor.h M sources/titleblock/templatecellsset.h M sources/titleblock/templatecellwidget.cpp M sources/titleblock/templatecellwidget.h M sources/titleblock/templatecommands.cpp M sources/titleblock/templatedeleter.cpp M sources/titleblock/templatedeleter.h M sources/titleblock/templatelocationchooser.cpp M sources/titleblock/templatelocationchooser.h M sources/titleblock/templatelocationsaver.cpp M sources/titleblock/templatelocationsaver.h M sources/titleblock/templatelogomanager.cpp M sources/titleblock/templatelogomanager.h M sources/titleblock/templateview.cpp M sources/titleblock/templatevisualcell.h M sources/titleblockcell.cpp M sources/titleblocktemplate.cpp M sources/treecoloranimation.h M sources/ui/conductorpropertieswidget.cpp M sources/ui/diagrampropertiesdialog.cpp M sources/ui/diagramselection.cpp M sources/ui/dialogautonum.cpp M sources/ui/dialogwaiting.cpp M sources/ui/elementpropertieswidget.cpp M sources/ui/elementselectorwidget.cpp M sources/ui/linksingleelementwidget.cpp M sources/ui/masterpropertieswidget.cpp M sources/ui/potentialtextsdialog.cpp M sources/ui/projectpropertiesdialog.cpp M sources/ui/selectautonumw.cpp M sources/ui/titleblockpropertieswidget.cpp M sources/ui/xrefpropertieswidget.cpp M sources/undocommand/changeelementinformationcommand.cpp git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3783 bfdf4180-ca20-0410-9c96-a3a8aa849046
2015-03-02 20:14:56 +00:00
setText(QObject::tr("éloigner", "undo caption"));
applyLower(items_list);
} else if (m_option == QET::SendBackward) {
setText(QObject::tr("envoyer au fond", "undo caption"));
applySendBackward(items_list);
}
}
/// Destructeur
2020-09-07 22:03:40 +02:00
ChangeZValueCommand::~ChangeZValueCommand()
{
}
/// Annule les changements de zValue
2020-09-07 22:03:40 +02:00
void ChangeZValueCommand::undo()
{
foreach(QGraphicsItem *qgi, undo_hash.keys()) qgi -> setZValue(undo_hash[qgi]);
}
/// Refait les changements de zValue
2020-09-07 22:03:40 +02:00
void ChangeZValueCommand::redo()
{
foreach(QGraphicsItem *qgi, redo_hash.keys()) qgi -> setZValue(redo_hash[qgi]);
}
/**
Amene les elements selectionnes au premier plan
@param items_list Liste des elements (selectionnes et non selectionnes)
*/
void ChangeZValueCommand::applyBringForward(const QList<QGraphicsItem *> &items_list) {
QList<QGraphicsItem *> non_selected_items = items_list;
QList<QGraphicsItem *> selected_items;
foreach(QGraphicsItem *qgi, non_selected_items) {
if (qgi -> isSelected()) {
selected_items << qgi;
non_selected_items.removeAt(non_selected_items.indexOf(qgi));
}
}
int z = 1;
foreach(QGraphicsItem *qgi, non_selected_items) redo_hash.insert(qgi, z ++);
foreach(QGraphicsItem *qgi, selected_items) redo_hash.insert(qgi, z ++);
}
/**
Remonte les elements selectionnes d'un plan
@param items_list Liste des elements (selectionnes et non selectionnes)
*/
void ChangeZValueCommand::applyRaise(const QList<QGraphicsItem *> &items_list) {
QList<QGraphicsItem *> my_items_list = items_list;
for (int i = my_items_list.count() - 2 ; i >= 0 ; -- i) {
if (my_items_list[i] -> isSelected()) {
if (!my_items_list[i +1] -> isSelected()) {
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) // ### Qt 6: remove
my_items_list.swap(i, i + 1);
#else
#if TODO_LIST
2020-07-19 22:06:42 +02:00
#pragma message("@TODO remove code for QT 5.13 or later")
#endif
my_items_list.swapItemsAt(i, i + 1);
#endif
}
}
}
int z = 1;
foreach(QGraphicsItem *qgi, my_items_list) redo_hash.insert(qgi, z ++);
}
/**
Descend les elements selectionnes d'un plan
@param items_list Liste des elements (selectionnes et non selectionnes)
*/
void ChangeZValueCommand::applyLower(const QList<QGraphicsItem *> &items_list) {
QList<QGraphicsItem *> my_items_list = items_list;
for (int i = 1 ; i < my_items_list.count() ; ++ i) {
if (my_items_list[i] -> isSelected()) {
if (!my_items_list[i - 1] -> isSelected()) {
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) // ### Qt 6: remove
my_items_list.swap(i, i - 1);
#else
#if TODO_LIST
2020-07-19 22:06:42 +02:00
#pragma message("@TODO remove code for QT 5.13 or later")
#endif
my_items_list.swapItemsAt(i, i - 1);
#endif
}
}
}
int z = 1;
foreach(QGraphicsItem *qgi, my_items_list) redo_hash.insert(qgi, z ++);
}
/**
Envoie les elements selectionnes au fond
@param items_list Liste des elements (selectionnes et non selectionnes)
*/
void ChangeZValueCommand::applySendBackward(const QList<QGraphicsItem *> &items_list) {
QList<QGraphicsItem *> non_selected_items = items_list;
QList<QGraphicsItem *> selected_items;
foreach(QGraphicsItem *qgi, non_selected_items) {
if (qgi -> isSelected()) {
selected_items << qgi;
non_selected_items.removeAt(non_selected_items.indexOf(qgi));
}
}
int z = 1;
foreach(QGraphicsItem *qgi, selected_items) redo_hash.insert(qgi, z ++);
foreach(QGraphicsItem *qgi, non_selected_items) redo_hash.insert(qgi, z ++);
}
/**
Constructeur
@param elmt ElementScene concernee
@param old_infos Informations complementaires precedentes
@param new_infos Nouvelles informations complementaires
@param parent QUndoCommand parent
*/
ChangeInformationsCommand::ChangeInformationsCommand(ElementScene *elmt, const QString &old_infos, const QString &new_infos, QUndoCommand *parent) :
ElementEditionCommand(QObject::tr("modification informations complementaires", "undo caption"), elmt, nullptr, parent),
old_informations_(old_infos),
new_informations_(new_infos)
{
}
/// Destructeur
2020-09-07 22:03:40 +02:00
ChangeInformationsCommand::~ChangeInformationsCommand()
{
}
/// Annule le changement d'autorisation pour les connexions internes
2020-09-07 22:03:40 +02:00
void ChangeInformationsCommand::undo()
{
auto data = m_scene->elementData();
data.m_drawing_information = old_informations_;
m_scene->setElementData(data);
}
/// Refait le changement d'autorisation pour les connexions internes
2020-09-07 22:03:40 +02:00
void ChangeInformationsCommand::redo()
{
auto data = m_scene->elementData();
data.m_drawing_information = new_informations_;
m_scene->setElementData(data);
}
/**
Constructor
@param scene Modified ElementScene
@param parent Parent QUndoCommand
*/
ScalePartsCommand::ScalePartsCommand(ElementScene *scene, QUndoCommand * parent) :
ElementEditionCommand(scene, nullptr, parent),
first_redo(true)
{}
/**
Destructor
*/
2020-09-07 22:03:40 +02:00
ScalePartsCommand::~ScalePartsCommand()
{
}
/**
Undo the scaling operation
*/
2020-09-07 22:03:40 +02:00
void ScalePartsCommand::undo()
{
scale(new_rect_, original_rect_);
}
/**
Redo the scaling operation
*/
2020-09-07 22:03:40 +02:00
void ScalePartsCommand::redo()
{
if (first_redo) {
first_redo = false;
return;
}
scale(original_rect_, new_rect_);
}
/**
@return the element editor/scene the command should take place on
*/
2020-09-07 22:03:40 +02:00
ElementScene *ScalePartsCommand::elementScene() const
{
return(m_scene);
}
/**
Set \a primitives as the list of primitives to be scaled by this command
*/
void ScalePartsCommand::setScaledPrimitives(const QList<CustomElementPart *> &primitives) {
scaled_primitives_ = primitives;
adjustText();
}
/**
@return the list of primitives to be scaled by this command
*/
2020-09-07 22:03:40 +02:00
QList<CustomElementPart *> ScalePartsCommand::scaledPrimitives() const
{
return(scaled_primitives_);
}
/**
2020-08-20 17:44:59 +02:00
@brief ScalePartsCommand::setTransformation
Define the transformation applied by this command
2020-08-20 17:45:24 +02:00
@param original_rect :
Bounding rectangle for all scaled primitives before the operation
@param new_rect :
Bounding rectangle for all scaled primitives after the operation
*/
void ScalePartsCommand::setTransformation(const QRectF &original_rect,
const QRectF &new_rect) {
original_rect_ = original_rect;
new_rect_ = new_rect;
}
/**
@return the transformation applied by this command. The returned rectangles
are the bounding rectangles for all scaled primitives respectively before
and after the operation.
*/
2020-09-07 22:03:40 +02:00
QPair<QRectF, QRectF> ScalePartsCommand::transformation()
{
return(QPair<QRectF, QRectF>(original_rect_, new_rect_));
}
/**
Apply the scaling operation from \a before to \a after.
*/
void ScalePartsCommand::scale(const QRectF &before, const QRectF &after) {
if (!scaled_primitives_.count()) return;
if (before == after) return;
if (!before.width() || !before.height()) return; // cowardly flee division by zero FIXME?
foreach (CustomElementPart *part_item, scaled_primitives_) {
part_item -> startUserTransformation(before);
part_item -> handleUserTransformation(before, after);
}
}
/**
Generate the text describing what this command does exactly.
*/
2020-09-07 22:03:40 +02:00
void ScalePartsCommand::adjustText()
{
if (scaled_primitives_.count() == 1) {
setText(QObject::tr("redimensionnement %1", "undo caption -- %1 is the resized primitive type name").arg(scaled_primitives_.first() -> name()));
} else {
setText(QObject::tr("redimensionnement de %1 primitives", "undo caption -- %1 always > 1").arg(scaled_primitives_.count()));
}
}
/**
* @brief changeElementDataCommand::changeElementDataCommand
* Change the properties of the drawn element
* @param scene : scene belonging to the property
* @param old_data : old data
* @param new_data : new data
* @param parent : parent undo command
*/
changeElementDataCommand::changeElementDataCommand(ElementScene *scene,
ElementData old_data,
ElementData new_data,
QUndoCommand *parent) :
ElementEditionCommand(scene, nullptr, parent),
m_old(old_data),
m_new(new_data)
{
setText(QObject::tr("Modifier les propriétées de l'élément"));
}
void changeElementDataCommand::undo() {
m_scene->setElementData(m_old);
QUndoCommand::undo();
}
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() == PartArc::Type) {
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
arc->setRotation(arc->rotation()-90);
}
else if (item->type() == PartEllipse::Type) {
PartEllipse* ellipse = qgraphicsitem_cast<PartEllipse*>(item);
ellipse->setRotation(ellipse->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 if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(text->rotation()-90);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(dyntext->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() == PartArc::Type) {
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
arc->setRotation(arc->rotation()+90);
}
else if (item->type() == PartEllipse::Type) {
PartEllipse* ellipse = qgraphicsitem_cast<PartEllipse*>(item);
ellipse->setRotation(ellipse->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 if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(text->rotation()+90);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(dyntext->rotation()+90);
}
else {
item->setRotation(item->rotation()+90);
}
}
}
RotateFineElementsCommand::RotateFineElementsCommand(ElementScene *scene, QUndoCommand *parent) :
ElementEditionCommand(QObject::tr("Pivoter la selection", "undo caption"), scene, nullptr, parent)
{
m_items = scene->selectedItems();
}
/**
@brief RotateFineElementsCommand::undo
*/
void RotateFineElementsCommand::undo()
{
for (QGraphicsItem *item : m_items)
{
if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(line->rotation()-5);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(poly->rotation()-5);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(text->rotation()-5);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(dyntext->rotation()-5);
}
else {
//item->setRotation(item->rotation()-5);
}
}
}
/**
@brief RotateFineElementsCommand::redo
*/
void RotateFineElementsCommand::redo()
{
for (QGraphicsItem *item : m_items)
{
if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(line->rotation()+5);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(poly->rotation()+5);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(text->rotation()+5);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(dyntext->rotation()+5);
}
else {
//item->setRotation(item->rotation()+5);
}
}
}
MirrorElementsCommand::MirrorElementsCommand(ElementScene *scene, QUndoCommand *parent) :
ElementEditionCommand(QObject::tr("Miroir de sélection", "undo caption"), scene, nullptr, parent)
{
m_items = scene->selectedItems();
}
/**
@brief MirrorElementsCommand::redo
*/
void MirrorElementsCommand::redo()
{
foreach (auto *item, m_items) {
if (item->type() == PartText::Type) {
PartText* staticText = qgraphicsitem_cast<PartText*>(item);
staticText->mirror();
} else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->mirror();
} else if (item->type() == PartArc::Type) {
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
arc->mirror();
} else if (item->type() == PartEllipse::Type) {
PartEllipse* ellipse = qgraphicsitem_cast<PartEllipse*>(item);
ellipse->mirror();
} else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->mirror();
} else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->mirror();
} else if (item->type() == PartRectangle::Type) {
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
rect->mirror();
} else if (item->type() == PartTerminal::Type) {
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
term->mirror();
}
}
}
/**
@brief MirrorElementsCommand::undo
*/
void MirrorElementsCommand::undo()
{
redo();
}
FlipElementsCommand::FlipElementsCommand(ElementScene *scene, QUndoCommand *parent) :
ElementEditionCommand(QObject::tr("Retourner la sélection", "undo caption"), scene, nullptr, parent)
{
m_items = scene->selectedItems();
}
/**
@brief FlipElementsCommand::redo
*/
void FlipElementsCommand::redo()
{
foreach (auto *item, m_items) {
if (item->type() == PartText::Type) {
PartText* staticText = qgraphicsitem_cast<PartText*>(item);
staticText->flip();
} else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->flip();
} else if (item->type() == PartArc::Type) {
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
arc->flip();
} else if (item->type() == PartEllipse::Type) {
PartEllipse* ellipse = qgraphicsitem_cast<PartEllipse*>(item);
ellipse->flip();
} else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->flip();
} else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->flip();
} else if (item->type() == PartRectangle::Type) {
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
rect->flip();
} else if (item->type() == PartTerminal::Type) {
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
term->flip();
}
}
}
/**
@brief FlipElementsCommand::undo
*/
void FlipElementsCommand::undo()
{
redo();
}