QElectroTech  0.70
diagramcommands.h
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 #ifndef DIAGRAM_COMMANDS_H
19 #define DIAGRAM_COMMANDS_H
20 
21 #include "borderproperties.h"
23 #include "diagramcontent.h"
24 #include "qet.h"
26 #include "conductorprofile.h"
27 #include "diagram.h"
29 
30 class DiagramTextItem;
31 class Element;
33 class DiagramImageItem;
34 class QetGraphicsItem;
35 
41 template <typename QGI>
42 class AddItemCommand : public QUndoCommand {
43  public:
44  AddItemCommand(QGI item, Diagram *diagram, const QPointF &pos = QPointF(), QUndoCommand *parent = nullptr) :
45  QUndoCommand (parent),
46  m_item (item),
47  m_diagram (diagram),
48  m_pos(pos)
49  {
50  setText(QObject::tr("Ajouter ") + itemText(item));
51  m_diagram -> qgiManager().manage(m_item);
52  }
53 
54  ~AddItemCommand() override {
55  m_diagram -> qgiManager().release(m_item);
56  }
57 
58  void undo() override {
59  m_diagram -> showMe();
60  m_diagram -> removeItem(m_item);
61  QUndoCommand::undo();
62  }
63 
64  void redo() override {
65  m_diagram -> showMe();
66  m_diagram -> addItem(m_item);
67  m_item -> setPos(m_pos);
68  QUndoCommand::redo();
69  }
70 
71  private:
72  QGI m_item;
74  QPointF m_pos;
75 };
76 
77 //Return a string to describe a QGraphicsItem
78 QString itemText(const QetGraphicsItem *item);
79 QString itemText(const IndependentTextItem *item);
80 QString itemText(const Conductor *item);
81 
85 class PasteDiagramCommand : public QUndoCommand {
86  // constructors, destructor
87  public:
88  PasteDiagramCommand(Diagram *, const DiagramContent &, QUndoCommand * = nullptr);
89  ~PasteDiagramCommand() override;
90  private:
92 
93  // methods
94  public:
95  void undo() override;
96  void redo() override;
97 
98  // attributes
99  private:
105  int filter;
108 };
109 
114  // constructors, destructor
115  public:
116  CutDiagramCommand(Diagram *, const DiagramContent &, QUndoCommand * = nullptr);
117  ~CutDiagramCommand() override;
118  private:
120 };
121 
125 class MoveElementsCommand : public QUndoCommand {
126  // constructors, destructor
127  public:
128  MoveElementsCommand(Diagram *, const DiagramContent &, const QPointF &m, QUndoCommand * = nullptr);
129  ~MoveElementsCommand() override;
130  private:
132 
133  // methods
134  public:
135  void undo() override;
136  void redo() override;
137  virtual void move(const QPointF &);
138 
139  private:
140  void setupAnimation (QObject * target, const QByteArray &propertyName, const QVariant& start, const QVariant& end);
141 
142  // attributes
143  private:
149  QPointF movement;
151  QParallelAnimationGroup *m_anim_group;
154 };
155 
160 class MoveConductorsTextsCommand : public QUndoCommand {
161  // constructors, destructor
162  public:
163  MoveConductorsTextsCommand(Diagram *, QUndoCommand * = nullptr);
164  ~MoveConductorsTextsCommand() override;
165  private:
167 
168  // methods
169  public:
170  void undo() override;
171  void redo() override;
172  virtual void addTextMovement(ConductorTextItem *, const QPointF &, const QPointF &, bool = false);
173 
174  private:
175  void regenerateTextLabel();
176 
177  // attributes
178  private:
182  QHash<ConductorTextItem *, QPair<QPointF, bool> > texts_to_move_;
185 };
186 
190 class ChangeDiagramTextCommand : public QUndoCommand {
191  // constructors, destructor
192  public:
193  ChangeDiagramTextCommand(DiagramTextItem *, const QString &before, const QString &after, QUndoCommand * = nullptr);
194  ~ChangeDiagramTextCommand() override;
195  private:
197 
198  // methods
199  public:
200  void undo() override;
201  void redo() override;
202 
203  // attributes
204  private:
208  QString text_before;
210  QString text_after;
214 };
215 
219 class ChangeConductorCommand : public QUndoCommand {
220  // constructors, destructor
221  public:
222  ChangeConductorCommand(Conductor *, const ConductorProfile &, const ConductorProfile &, Qt::Corner, QUndoCommand * = nullptr);
223  ~ChangeConductorCommand() override;
224  private:
226 
227  // methods
228  public:
229  void undo() override;
230  void redo() override;
231  virtual void setConductorTextItemMove(const QPointF &, const QPointF &);
232 
233  // attributes
234  private:
242  Qt::Corner path_type;
250 };
251 
255 class ResetConductorCommand : public QUndoCommand {
256  // constructors, destructor
257  public:
258  ResetConductorCommand(const QHash<Conductor *, ConductorProfilesGroup> &, QUndoCommand * = nullptr);
259  ~ResetConductorCommand() override;
260  private:
262 
263  // methods
264  public:
265  void undo() override;
266  void redo() override;
267 
268  // attributes
269  private:
271  QHash<Conductor *, ConductorProfilesGroup> conductors_profiles;
273 };
274 
275 
276 
280 class ChangeBorderCommand : public QUndoCommand {
281  // constructors, destructor
282  public:
283  ChangeBorderCommand(Diagram *, const BorderProperties &, const BorderProperties &, QUndoCommand * = nullptr);
284  ~ChangeBorderCommand() override;
285  private:
287 
288  // methods
289  public:
290  void undo() override;
291  void redo() override;
292 
293  // attributes
294  private:
297  public:
302 };
303 
304 #endif
Diagram * diagram
modified diagram
~ResetConductorCommand() override
ResetConductorCommand::~ResetConductorCommand.
int filter
filter stating what kinds of items should be pasted
Diagram * m_diagram
void undo() override
Annule la modification du conducteur.
QPointF movement
applied movement
ChangeDiagramTextCommand(DiagramTextItem *, const QString &before, const QString &after, QUndoCommand *=nullptr)
Conductor * conductor
changed conductor
QParallelAnimationGroup * m_anim_group
animation group
QString text_before
former text
~ChangeBorderCommand() override
Destructeur.
Qt::Corner path_type
Path type of the modified conductor.
Diagram * diagram
diagram the movement takes place on.
virtual void setConductorTextItemMove(const QPointF &, const QPointF &)
The AddItemCommand class This command add an item in a diagram The item to add is template...
MoveConductorsTextsCommand(Diagram *, QUndoCommand *=nullptr)
~CutDiagramCommand() override
Destructeur.
void redo() override
void undo() override
annule la modification de texte
bool first_redo
prevent the first call to redo()
virtual void move(const QPointF &)
MoveElementsCommand::move Move item and conductor to .
ChangeConductorCommand(Conductor *, const ConductorProfile &, const ConductorProfile &, Qt::Corner, QUndoCommand *=nullptr)
bool first_redo
prevent the first call to redo()
void redo() override
MoveElementsCommand::redo.
void undo() override
annule le deplacement
void undo() override
PasteDiagramCommand::undo Undo this command.
virtual void addTextMovement(ConductorTextItem *, const QPointF &, const QPointF &, bool=false)
Diagram * diagram
diagram the movement takes place on.
ResetConductorCommand(const QHash< Conductor *, ConductorProfilesGroup > &, QUndoCommand *=nullptr)
ResetConductorCommand::ResetConductorCommand.
void redo() override
Refait la modification du conducteur.
CutDiagramCommand(Diagram *, const DiagramContent &, QUndoCommand *=nullptr)
ConductorProfile new_profile
profile after the change
~ChangeDiagramTextCommand() override
destructeur
MoveElementsCommand(Diagram *, const DiagramContent &, const QPointF &m, QUndoCommand *=nullptr)
MoveElementsCommand::MoveElementsCommand Constructor.
bool first_redo
prevent the first call to redo()
QIcon tr
Definition: qeticons.cpp:204
void redo() override
ChangeDiagramTextCommand::redo.
~MoveElementsCommand() override
MoveElementsCommand::~MoveElementsCommand Destructor.
ChangeBorderCommand(Diagram *, const BorderProperties &, const BorderProperties &, QUndoCommand *=nullptr)
DiagramTextItem * text_item
modified text item
~ChangeConductorCommand() override
Destructeur.
QString itemText(const QetGraphicsItem *item)
BorderProperties old_properties
properties before the change
void undo() override
Annule les changements apportes au schema.
PasteDiagramCommand(Diagram *, const DiagramContent &, QUndoCommand *=nullptr)
PasteDiagramCommand::PasteDiagramCommand Constructor.
DiagramContent content_to_move
moved content
QHash< ConductorTextItem *, QPair< QPointF, bool > > texts_to_move_
text items to be moved
QString text_after
new text
DiagramContent content
pasted content
void redo() override
Refait les changements apportes au schema.
void redo() override
PasteDiagramCommand::redo Redo this commnand.
void redo() override
ResetConductorCommand::redo.
void undo() override
ResetConductorCommand::undo.
void undo() override
~AddItemCommand() override
QPointF text_pos_before_mov_
position of the text item before the change
void undo() override
MoveElementsCommand::undo.
BorderProperties new_properties
properties after the change
QPointF text_pos_after_mov_
position of the text item after the change
~MoveConductorsTextsCommand() override
Destructeur.
~PasteDiagramCommand() override
PasteDiagramCommand::~PasteDiagramCommand Destructor.
ConductorProfile old_profile
profile before the change
AddItemCommand(QGI item, Diagram *diagram, const QPointF &pos=QPointF(), QUndoCommand *parent=nullptr)
void setupAnimation(QObject *target, const QByteArray &propertyName, const QVariant &start, const QVariant &end)
MoveElementsCommand::setupAnimation Set up the animation for this undo command.
Diagram * diagram
diagram content is pasted onto
bool first_redo
prevent the first call to redo()
QHash< Conductor *, ConductorProfilesGroup > conductors_profiles
impacted conductors along with their former profiles
void redo() override
refait le deplacement
bool first_redo
prevent the first call to redo()