QElectroTech  0.70
rotateselectioncommand.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "rotateselectioncommand.h"
19 #include "element.h"
20 #include "conductortextitem.h"
21 #include "independenttextitem.h"
22 #include "dynamicelementtextitem.h"
23 #include "elementtextitemgroup.h"
24 #include "diagramimageitem.h"
25 #include "diagram.h"
26 #include "conductor.h"
27 #include "qet.h"
29 
30 #include <QGraphicsItem>
31 
32 RotateSelectionCommand::RotateSelectionCommand(Diagram *diagram, qreal angle, QUndoCommand *parent) :
33 QUndoCommand(parent),
34 m_diagram(diagram)
35 {
36  setText(QObject::tr("Pivoter la selection"));
37 
38  if(!m_diagram->isReadOnly())
39  {
40  for (QGraphicsItem *item : m_diagram->selectedItems())
41  {
42  switch (item->type())
43  {
44  case Element::Type:
45  m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
46  break;
48  {
49  m_cond_text << static_cast<ConductorTextItem *>(item);
50  m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
51  }
52  break;
54  m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
55  break;
57  {
58  if(item->parentItem() && !item->parentItem()->isSelected())
59  m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
60  }
61  break;
62  case QGraphicsItemGroup::Type:
63  {
64  if(ElementTextItemGroup *grp = dynamic_cast<ElementTextItemGroup *>(item))
65  if(grp->parentElement() && !grp->parentElement()->isSelected())
66  m_undo << new QPropertyUndoCommand(grp, "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
67  }
68  break;
70  m_undo << new QPropertyUndoCommand(item->toGraphicsObject(), "rotation", QVariant(item->rotation()), QVariant(item->rotation()+angle), this);
71  break;
72  default:
73  break;
74  }
75  }
76 
78  undo->setAnimated(true, false);
79  }
80 }
81 
86 {
87  m_diagram->showMe();
88  QUndoCommand::undo();
89 
90  for(const QPointer<ConductorTextItem>& cti : m_cond_text)
91  {
92  cti->forceRotateByUser(m_rotate_by_user.value(cti.data()));
93  if(!cti->wasRotateByUser())
94  cti->parentConductor()->calculateTextItemPosition();
95  }
96 }
97 
102 {
103  m_diagram->showMe();
104  QUndoCommand::redo();
105 
106  for(const QPointer<ConductorTextItem>& cti : m_cond_text)
107  {
108  m_rotate_by_user.insert(cti, cti->wasRotateByUser());
109  cti->forceRotateByUser(true);
110  }
111 }
112 
118 {
119  if(childCount())
120  return true;
121  else
122  return false;
123 }
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
void redo() override
RotateSelectionCommand::redo.
QList< QPropertyUndoCommand * > m_undo
bool isReadOnly() const
Diagram::isReadOnly.
Definition: diagram.cpp:1764
bool isValid()
RotateSelectionCommand::isValid.
RotateSelectionCommand(Diagram *diagram, qreal angle=90, QUndoCommand *parent=nullptr)
QIcon tr
Definition: qeticons.cpp:204
QList< QPointer< ConductorTextItem > > m_cond_text
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
QHash< ConductorTextItem *, bool > m_rotate_by_user
void showMe()
Definition: diagram.h:150
void undo() override
RotateSelectionCommand::undo.