QElectroTech  0.70
editorcommands.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 EDITOR_COMMANDS_H
19 #define EDITOR_COMMANDS_H
20 #include "customelementpart.h"
21 #include "elementview.h"
22 #include "elementscene.h"
23 #include "elementcontent.h"
24 #include "qgimanager.h"
25 
32 class ElementEditionCommand : public QUndoCommand
33 {
34  // constructors, destructor
35  public:
36  ElementEditionCommand(ElementScene * = nullptr, ElementView * = nullptr, QUndoCommand * = nullptr);
37  ElementEditionCommand(const QString &, ElementScene * = nullptr, ElementView * = nullptr, QUndoCommand * = nullptr);
38  ~ElementEditionCommand() override;
39  private:
41 
42  // methods
43  public:
44  ElementScene *elementScene() const;
46  ElementView *elementView() const;
48 
49  // attributes
50  protected:
54 };
55 
61  // constructors, destructor
62  public:
63  DeletePartsCommand(ElementScene *, const QList<QGraphicsItem *>&, QUndoCommand * = nullptr);
64  ~DeletePartsCommand() override;
65  private:
67 
68  // methods
69  public:
70  void undo() override;
71  void redo() override;
72 
73  // attributes
74  private:
76  QList<QGraphicsItem *> deleted_parts;
77 };
78 
83  // constructors, destructor
84  public:
85  PastePartsCommand(ElementView *, const ElementContent &, QUndoCommand * = nullptr);
86  ~PastePartsCommand() override;
87  private:
89 
90  // methods
91  public:
92  void undo() override;
93  void redo() override;
94  virtual void setOffset(int, const QPointF &, int, const QPointF &);
95 
96  // attributes
97  private:
108 };
109 
114  // constructors, destructor
115  public:
116  CutPartsCommand(ElementScene *, const QList<QGraphicsItem *>&, QUndoCommand * = nullptr);
117  ~CutPartsCommand() override;
118  private:
120 };
121 
126  // constructors, destructor
127  public:
128  MovePartsCommand(const QPointF &, ElementScene *, const QList<QGraphicsItem *>&, QUndoCommand * = nullptr);
129  ~MovePartsCommand() override;
130  private:
132 
133  // methods
134  public:
135  void undo() override;
136  void redo() override;
137 
138  // attributes
139  private:
141  QList<QGraphicsItem *> moved_parts;
143  QPointF movement;
146 };
147 
152  // constructors, destructor
153  public:
154  AddPartCommand(const QString &, ElementScene *, QGraphicsItem *, QUndoCommand * = nullptr);
155  ~AddPartCommand() override;
156  private:
158 
159  // methods
160  public:
161  void undo() override;
162  void redo() override;
163 
164  // attributes
165  private:
167  QGraphicsItem *part;
170 };
171 
176  // constructors, destructor
177  public:
178  ChangeNamesCommand(ElementScene *, const NamesList &, const NamesList &, QUndoCommand * = nullptr);
179  ~ChangeNamesCommand() override;
180  private:
182 
183  // methods
184  public:
185  void undo() override;
186  void redo() override;
187 
188  // attributes
189  private:
194 };
195 
201 {
202  // constructors, destructor
203  public:
204  ChangeZValueCommand(ElementScene *, QET::DepthOption , QUndoCommand * = nullptr);
205  ~ChangeZValueCommand() override;
206  private:
208 
209  // methods
210  public:
211  void undo() override;
212  void redo() override;
213 
214  private:
215  void applyBringForward(const QList<QGraphicsItem *> &);
216  void applyRaise(const QList<QGraphicsItem *> &);
217  void applyLower(const QList<QGraphicsItem *> &);
218  void applySendBackward(const QList<QGraphicsItem *> &);
219 
220  // attributes
221  private:
223  QHash<QGraphicsItem *, qreal> undo_hash;
225  QHash<QGraphicsItem *, qreal> redo_hash;
228 };
229 
234  // constructors, destructor
235  public:
236  ChangeInformationsCommand(ElementScene *, const QString &, const QString &, QUndoCommand * = nullptr);
237  ~ChangeInformationsCommand() override;
238  private:
240 
241  // methods
242  public:
243  void undo() override;
244  void redo() override;
245 
246  // attributes
247  private:
252 };
253 
258  // constructors, destructor
259  public:
260  ScalePartsCommand(ElementScene * = nullptr, QUndoCommand * = nullptr);
261  ~ScalePartsCommand() override;
262  private:
264 
265  // methods
266  public:
267  void undo() override;
268  void redo() override;
269  ElementScene *elementScene() const;
270  void setScaledPrimitives(const QList<CustomElementPart *> &);
271  QList<CustomElementPart *> scaledPrimitives() const;
272  void setTransformation(const QRectF &, const QRectF &);
273  QPair<QRectF, QRectF> transformation();
274 
275  protected:
276  void scale(const QRectF &before, const QRectF &after);
277  void adjustText();
278 
279  // attributes
280  private:
282  QList<CustomElementPart *> scaled_primitives_;
286  QRectF new_rect_;
289 };
290 
292  public:
293  ChangePropertiesCommand (ElementScene *scene, const QString& type, const DiagramContext& info, const DiagramContext& elmt_info, QUndoCommand *parent=nullptr);
294  ~ChangePropertiesCommand () override;
295 
296  void undo() override;
297  void redo() override;
298 
299  private:
300  QList <QString> m_type;
301  QList <DiagramContext> m_kind_info;
302  QList < DiagramContext> m_elmt_info;
303 };
304 
305 #endif
void redo() override
QPair< QRectF, QRectF > transformation()
void setElementScene(ElementScene *)
void applyBringForward(const QList< QGraphicsItem *> &)
void redo() override
Refait les changements de zValue.
~ElementEditionCommand() override
void redo() override
Refait le deplacement.
ElementScene * elementScene() const
void undo() override
annule le coller
ElementScene * elementScene() const
~ChangeNamesCommand() override
Destructeur.
~ScalePartsCommand() override
QPointF old_start_top_left_corner_
ElementEditionCommand(ElementScene *=nullptr, ElementView *=nullptr, QUndoCommand *=nullptr)
QPointF new_start_top_left_corner_
QList< QString > m_type
void undo() override
Annule le deplacement.
void setScaledPrimitives(const QList< CustomElementPart *> &)
void redo() override
Refait l&#39;ajout.
ElementView * m_view
QList< QGraphicsItem * > deleted_parts
Deleted primitives.
void undo() override
Annule l&#39;ajout.
QString old_informations_
Former information.
ElementView * elementView() const
ElementScene * m_scene
Element editor/view/scene the command should take place on.
void setElementView(ElementView *)
ChangeInformationsCommand(ElementScene *, const QString &, const QString &, QUndoCommand *=nullptr)
QString new_informations_
New information.
ElementContent content_
Pasted content.
void undo() override
Annule les changements de zValue.
bool first_redo
Prevent the first call to redo()
void redo() override
Refait le changement.
CutPartsCommand(ElementScene *, const QList< QGraphicsItem *> &, QUndoCommand *=nullptr)
~AddPartCommand() override
Destructeur.
QRectF original_rect_
original rect items fit in
The ElementEditionCommand class ElementEditionCommand is the base class for all commands classes invo...
~ChangeZValueCommand() override
Destructeur.
QList< CustomElementPart * > scaledPrimitives() const
~ChangeInformationsCommand() override
Destructeur.
~PastePartsCommand() override
Destructeur.
void undo() override
Annule le changement d&#39;autorisation pour les connexions internes.
QPointF movement
applied movement
bool first_redo
Prevent the first call to redo()
QGraphicsItem * part
Added primitive.
QList< CustomElementPart * > scaled_primitives_
List of moved primitives.
void undo() override
Annule le changement.
QHash< QGraphicsItem *, qreal > redo_hash
associates impacted primitives with their new zValues
DepthOption
List the various kind of changes for the zValue.
Definition: qet.h:43
ChangePropertiesCommand(ElementScene *scene, const QString &type, const DiagramContext &info, const DiagramContext &elmt_info, QUndoCommand *parent=nullptr)
ChangePropertiesCommand::ChangePropertiesCommand Change the properties of the drawed element...
NamesList names_before
List of former names.
void redo() override
Refait le changement d&#39;autorisation pour les connexions internes.
QList< DiagramContext > m_kind_info
~CutPartsCommand() override
Destructeur.
QRectF new_rect_
new rect items should fit in
ChangeNamesCommand(ElementScene *, const NamesList &, const NamesList &, QUndoCommand *=nullptr)
DeletePartsCommand(ElementScene *, const QList< QGraphicsItem *> &, QUndoCommand *=nullptr)
PastePartsCommand(ElementView *, const ElementContent &, QUndoCommand *=nullptr)
void redo() override
Supprime les parties.
AddPartCommand(const QString &, ElementScene *, QGraphicsItem *, QUndoCommand *=nullptr)
QList< QGraphicsItem * > moved_parts
List of moved primitives.
void applyLower(const QList< QGraphicsItem *> &)
void undo() override
ChangeZValueCommand(ElementScene *, QET::DepthOption, QUndoCommand *=nullptr)
void redo() override
refait le coller
virtual void setOffset(int, const QPointF &, int, const QPointF &)
void applySendBackward(const QList< QGraphicsItem *> &)
void setTransformation(const QRectF &, const QRectF &)
ScalePartsCommand(ElementScene *=nullptr, QUndoCommand *=nullptr)
~MovePartsCommand() override
Destructeur.
NamesList names_after
List of new names.
QList< QGraphicsItem * > ElementContent
int old_offset_paste_count_
Data required to undo a copy/paste with offset.
void undo() override
Restaure les parties supprimees.
QET::DepthOption m_option
kind of treatment to apply
void scale(const QRectF &before, const QRectF &after)
QHash< QGraphicsItem *, qreal > undo_hash
associates impacted primitives with their former zValues
MovePartsCommand(const QPointF &, ElementScene *, const QList< QGraphicsItem *> &, QUndoCommand *=nullptr)
bool first_redo
Prevent the first call to redo()
bool first_redo
Prevent the first call to redo()
void applyRaise(const QList< QGraphicsItem *> &)
~DeletePartsCommand() override
Destructeur : detruit egalement les parties supprimees.
QList< DiagramContext > m_elmt_info