QElectroTech  0.8-dev
editorcommands.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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:
37  ElementView * = nullptr,
38  QUndoCommand * = nullptr);
39  ElementEditionCommand(const QString &,
40  ElementScene * = nullptr,
41  ElementView * = nullptr,
42  QUndoCommand * = nullptr);
43  ~ElementEditionCommand() override;
44  private:
46 
47  // methods
48  public:
49  ElementScene *elementScene() const;
51  ElementView *elementView() const;
53 
54  // attributes
55  protected:
59 };
60 
66  // constructors, destructor
67  public:
68  DeletePartsCommand(ElementScene *, const QList<QGraphicsItem *>&, QUndoCommand * = nullptr);
69  ~DeletePartsCommand() override;
70  private:
72 
73  // methods
74  public:
75  void undo() override;
76  void redo() override;
77 
78  // attributes
79  private:
81  QList<QGraphicsItem *> deleted_parts;
82 };
83 
88  // constructors, destructor
89  public:
90  CutPartsCommand(ElementScene *, const QList<QGraphicsItem *>&, QUndoCommand * = nullptr);
91  ~CutPartsCommand() override;
92  private:
94 };
95 
100  // constructors, destructor
101  public:
102  MovePartsCommand(const QPointF &, ElementScene *, const QList<QGraphicsItem *>&, QUndoCommand * = nullptr);
103  ~MovePartsCommand() override;
104  private:
106 
107  // methods
108  public:
109  void undo() override;
110  void redo() override;
111 
112  // attributes
113  private:
115  QList<QGraphicsItem *> moved_parts;
117  QPointF movement;
120 };
121 
126  // constructors, destructor
127  public:
128  AddPartCommand(const QString &, ElementScene *, QGraphicsItem *, QUndoCommand * = nullptr);
129  ~AddPartCommand() override;
130  private:
132 
133  // methods
134  public:
135  void undo() override;
136  void redo() override;
137 
138  // attributes
139  private:
141  QGraphicsItem *part;
144 };
145 
150  // constructors, destructor
151  public:
152  ChangeNamesCommand(ElementScene *, const NamesList &, const NamesList &, QUndoCommand * = nullptr);
153  ~ChangeNamesCommand() override;
154  private:
156 
157  // methods
158  public:
159  void undo() override;
160  void redo() override;
161 
162  // attributes
163  private:
168 };
169 
175 {
176  // constructors, destructor
177  public:
178  ChangeZValueCommand(ElementScene *, QET::DepthOption , QUndoCommand * = nullptr);
179  ~ChangeZValueCommand() override;
180  private:
182 
183  // methods
184  public:
185  void undo() override;
186  void redo() override;
187 
188  private:
189  void applyBringForward(const QList<QGraphicsItem *> &);
190  void applyRaise(const QList<QGraphicsItem *> &);
191  void applyLower(const QList<QGraphicsItem *> &);
192  void applySendBackward(const QList<QGraphicsItem *> &);
193 
194  // attributes
195  private:
197  QHash<QGraphicsItem *, qreal> undo_hash;
199  QHash<QGraphicsItem *, qreal> redo_hash;
202 };
203 
208  // constructors, destructor
209  public:
210  ChangeInformationsCommand(ElementScene *, const QString &, const QString &, QUndoCommand * = nullptr);
211  ~ChangeInformationsCommand() override;
212  private:
214 
215  // methods
216  public:
217  void undo() override;
218  void redo() override;
219 
220  // attributes
221  private:
226 };
227 
232  // constructors, destructor
233  public:
234  ScalePartsCommand(ElementScene * = nullptr, QUndoCommand * = nullptr);
235  ~ScalePartsCommand() override;
236  private:
238 
239  // methods
240  public:
241  void undo() override;
242  void redo() override;
243  ElementScene *elementScene() const;
244  void setScaledPrimitives(const QList<CustomElementPart *> &);
245  QList<CustomElementPart *> scaledPrimitives() const;
246  void setTransformation(const QRectF &, const QRectF &);
247  QPair<QRectF, QRectF> transformation();
248 
249  protected:
250  void scale(const QRectF &before, const QRectF &after);
251  void adjustText();
252 
253  // attributes
254  private:
256  QList<CustomElementPart *> scaled_primitives_;
260  QRectF new_rect_;
263 };
264 
266  public:
268  ElementScene *scene,
269  const QString& type,
270  const DiagramContext& info,
271  const DiagramContext& elmt_info,
272  QUndoCommand *parent=nullptr);
273  ~ChangePropertiesCommand () override;
274 
275  void undo() override;
276  void redo() override;
277 
278  private:
279  QList <QString> m_type;
280  QList <DiagramContext> m_kind_info;
281  QList < DiagramContext> m_elmt_info;
282 };
283 
284 #endif
ElementEditionCommand::ElementEditionCommand
ElementEditionCommand(const ElementEditionCommand &)
qgimanager.h
ChangeNamesCommand::ChangeNamesCommand
ChangeNamesCommand(ElementScene *, const NamesList &, const NamesList &, QUndoCommand *=nullptr)
Definition: editorcommands.cpp:252
DeletePartsCommand::DeletePartsCommand
DeletePartsCommand(const DeletePartsCommand &)
ScalePartsCommand::undo
void undo() override
Definition: editorcommands.cpp:458
ElementView
Definition: elementview.h:27
AddPartCommand::part
QGraphicsItem * part
Added primitive.
Definition: editorcommands.h:141
ElementEditionCommand::elementView
ElementView * elementView() const
Definition: editorcommands.cpp:79
AddPartCommand::AddPartCommand
AddPartCommand(const QString &, ElementScene *, QGraphicsItem *, QUndoCommand *=nullptr)
Definition: editorcommands.cpp:204
DeletePartsCommand::deleted_parts
QList< QGraphicsItem * > deleted_parts
Deleted primitives.
Definition: editorcommands.h:81
ChangeZValueCommand::undo_hash
QHash< QGraphicsItem *, qreal > undo_hash
associates impacted primitives with their former zValues
Definition: editorcommands.h:197
AddPartCommand::undo
void undo() override
Annule l'ajout.
Definition: editorcommands.cpp:223
ElementEditionCommand::setElementView
void setElementView(ElementView *)
Definition: editorcommands.cpp:86
ChangePropertiesCommand::m_type
QList< QString > m_type
Definition: editorcommands.h:279
MovePartsCommand::MovePartsCommand
MovePartsCommand(const QPointF &, ElementScene *, const QList< QGraphicsItem * > &, QUndoCommand *=nullptr)
Definition: editorcommands.cpp:164
ChangeNamesCommand::names_before
NamesList names_before
List of former names.
Definition: editorcommands.h:165
QET::Raise
@ Raise
Raise item one layer above their current one; zValues are incremented.
Definition: qet.h:47
ScalePartsCommand::first_redo
bool first_redo
Prevent the first call to redo()
Definition: editorcommands.h:262
DeletePartsCommand::redo
void redo() override
Supprime les parties.
Definition: editorcommands.cpp:127
ScalePartsCommand::scaled_primitives_
QList< CustomElementPart * > scaled_primitives_
List of moved primitives.
Definition: editorcommands.h:256
ChangeInformationsCommand::old_informations_
QString old_informations_
Former information.
Definition: editorcommands.h:223
ChangePropertiesCommand::redo
void redo() override
Definition: editorcommands.cpp:574
ChangePropertiesCommand::undo
void undo() override
Definition: editorcommands.cpp:567
ChangeInformationsCommand::undo
void undo() override
Annule le changement d'autorisation pour les connexions internes.
Definition: editorcommands.cpp:430
CutPartsCommand
Definition: editorcommands.h:87
ElementScene::m_elmt_information
DiagramContext m_elmt_information
Definition: elementscene.h:71
ChangeZValueCommand::m_option
QET::DepthOption m_option
kind of treatment to apply
Definition: editorcommands.h:201
ChangePropertiesCommand::m_elmt_info
QList< DiagramContext > m_elmt_info
Definition: editorcommands.h:281
MovePartsCommand::MovePartsCommand
MovePartsCommand(const MovePartsCommand &)
ChangeInformationsCommand::ChangeInformationsCommand
ChangeInformationsCommand(const ChangeInformationsCommand &)
ScalePartsCommand::adjustText
void adjustText()
Definition: editorcommands.cpp:535
ChangePropertiesCommand::~ChangePropertiesCommand
~ChangePropertiesCommand() override
Definition: editorcommands.cpp:565
ChangeInformationsCommand::ChangeInformationsCommand
ChangeInformationsCommand(ElementScene *, const QString &, const QString &, QUndoCommand *=nullptr)
Definition: editorcommands.cpp:418
ChangeInformationsCommand
Definition: editorcommands.h:207
ElementEditionCommand
The ElementEditionCommand class ElementEditionCommand is the base class for all commands classes invo...
Definition: editorcommands.h:33
ChangeZValueCommand
Definition: editorcommands.h:175
ChangeZValueCommand::~ChangeZValueCommand
~ChangeZValueCommand() override
Destructeur.
Definition: editorcommands.cpp:315
ChangeNamesCommand::redo
void redo() override
Refait le changement.
Definition: editorcommands.cpp:274
ChangeZValueCommand::applyRaise
void applyRaise(const QList< QGraphicsItem * > &)
Definition: editorcommands.cpp:350
QET::SendBackward
@ SendBackward
Send item to the background so they have the lowest zValue.
Definition: qet.h:49
ScalePartsCommand::ScalePartsCommand
ScalePartsCommand(const ScalePartsCommand &)
ScalePartsCommand::elementScene
ElementScene * elementScene() const
Definition: editorcommands.cpp:476
QET::BringForward
@ BringForward
Bring item to the foreground so they have the highest zValue.
Definition: qet.h:46
ChangeZValueCommand::redo_hash
QHash< QGraphicsItem *, qreal > redo_hash
associates impacted primitives with their new zValues
Definition: editorcommands.h:199
AddPartCommand::first_redo
bool first_redo
Prevent the first call to redo()
Definition: editorcommands.h:143
ElementScene::m_elmt_type
QString m_elmt_type
Extra informations.
Definition: elementscene.h:69
ChangePropertiesCommand
Definition: editorcommands.h:265
MovePartsCommand::first_redo
bool first_redo
Prevent the first call to redo()
Definition: editorcommands.h:119
ChangePropertiesCommand::m_kind_info
QList< DiagramContext > m_kind_info
Definition: editorcommands.h:280
ChangeNamesCommand::ChangeNamesCommand
ChangeNamesCommand(const ChangeNamesCommand &)
ElementEditionCommand::m_view
ElementView * m_view
Definition: editorcommands.h:58
ChangeInformationsCommand::redo
void redo() override
Refait le changement d'autorisation pour les connexions internes.
Definition: editorcommands.cpp:435
DeletePartsCommand::~DeletePartsCommand
~DeletePartsCommand() override
Destructeur : detruit egalement les parties supprimees.
Definition: editorcommands.cpp:111
CutPartsCommand::CutPartsCommand
CutPartsCommand(const CutPartsCommand &)
DeletePartsCommand::undo
void undo() override
Restaure les parties supprimees.
Definition: editorcommands.cpp:118
ChangeZValueCommand::ChangeZValueCommand
ChangeZValueCommand(const ChangeZValueCommand &)
MovePartsCommand::moved_parts
QList< QGraphicsItem * > moved_parts
List of moved primitives.
Definition: editorcommands.h:115
elementscene.h
DeletePartsCommand
Definition: editorcommands.h:65
QET::DepthOption
DepthOption
List the various kind of changes for the zValue.
Definition: qet.h:45
ScalePartsCommand::~ScalePartsCommand
~ScalePartsCommand() override
Definition: editorcommands.cpp:452
AddPartCommand::AddPartCommand
AddPartCommand(const AddPartCommand &)
ElementScene::SortByZValue
@ SortByZValue
Definition: elementscene.h:48
ElementScene::SelectedOrNot
@ SelectedOrNot
Definition: elementscene.h:53
AddPartCommand::~AddPartCommand
~AddPartCommand() override
Destructeur.
Definition: editorcommands.cpp:218
MovePartsCommand::~MovePartsCommand
~MovePartsCommand() override
Destructeur.
Definition: editorcommands.cpp:178
ChangeNamesCommand
Definition: editorcommands.h:149
ElementEditionCommand::ElementEditionCommand
ElementEditionCommand(ElementScene *=nullptr, ElementView *=nullptr, QUndoCommand *=nullptr)
ElementEditionCommand::ElementEditionCommand Constructs an ElementEditionCommand, thus embedding the ...
Definition: editorcommands.cpp:28
elementview.h
DeletePartsCommand::DeletePartsCommand
DeletePartsCommand(ElementScene *, const QList< QGraphicsItem * > &, QUndoCommand *=nullptr)
Definition: editorcommands.cpp:97
editorcommands.h
QET::Lower
@ Lower
Send item one layer below their current one; zValues are decremented.
Definition: qet.h:48
ChangeZValueCommand::applyBringForward
void applyBringForward(const QList< QGraphicsItem * > &)
Definition: editorcommands.cpp:332
CutPartsCommand::CutPartsCommand
CutPartsCommand(ElementScene *, const QList< QGraphicsItem * > &, QUndoCommand *=nullptr)
Definition: editorcommands.cpp:142
ChangePropertiesCommand::ChangePropertiesCommand
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.
Definition: editorcommands.cpp:551
MovePartsCommand
Definition: editorcommands.h:99
ScalePartsCommand::transformation
QPair< QRectF, QRectF > transformation()
Definition: editorcommands.cpp:514
ScalePartsCommand::setScaledPrimitives
void setScaledPrimitives(const QList< CustomElementPart * > &)
Definition: editorcommands.cpp:483
ScalePartsCommand::original_rect_
QRectF original_rect_
original rect items fit in
Definition: editorcommands.h:258
ElementEditionCommand::elementScene
ElementScene * elementScene() const
Definition: editorcommands.cpp:65
NamesList
Definition: nameslist.h:30
MovePartsCommand::undo
void undo() override
Annule le deplacement.
Definition: editorcommands.cpp:182
elementcontent.h
ChangeZValueCommand::ChangeZValueCommand
ChangeZValueCommand(ElementScene *, QET::DepthOption, QUndoCommand *=nullptr)
Definition: editorcommands.cpp:284
ScalePartsCommand::scaledPrimitives
QList< CustomElementPart * > scaledPrimitives() const
Definition: editorcommands.cpp:491
ScalePartsCommand::redo
void redo() override
Definition: editorcommands.cpp:465
CutPartsCommand::~CutPartsCommand
~CutPartsCommand() override
Destructeur.
Definition: editorcommands.cpp:153
CustomElementPart
The CustomElementPart class This abstract class represents a primitive of the visual representation o...
Definition: customelementpart.h:40
ScalePartsCommand::scale
void scale(const QRectF &before, const QRectF &after)
Definition: editorcommands.cpp:521
ScalePartsCommand::ScalePartsCommand
ScalePartsCommand(ElementScene *=nullptr, QUndoCommand *=nullptr)
Definition: editorcommands.cpp:444
ElementEditionCommand::m_scene
ElementScene * m_scene
Element editor/view/scene the command should take place on.
Definition: editorcommands.h:57
ChangeNamesCommand::~ChangeNamesCommand
~ChangeNamesCommand() override
Destructeur.
Definition: editorcommands.cpp:265
ChangeInformationsCommand::new_informations_
QString new_informations_
New information.
Definition: editorcommands.h:225
ElementEditionCommand::~ElementEditionCommand
~ElementEditionCommand() override
Definition: editorcommands.cpp:59
AddPartCommand::redo
void redo() override
Refait l'ajout.
Definition: editorcommands.cpp:228
ElementScene
The ElementScene class This class is the canvas allowing the visual edition of an electrial element....
Definition: elementscene.h:40
ChangeNamesCommand::undo
void undo() override
Annule le changement.
Definition: editorcommands.cpp:269
ChangeZValueCommand::applySendBackward
void applySendBackward(const QList< QGraphicsItem * > &)
Definition: editorcommands.cpp:397
ElementScene::m_elmt_kindInfo
DiagramContext m_elmt_kindInfo
element type
Definition: elementscene.h:70
ChangeNamesCommand::names_after
NamesList names_after
List of new names.
Definition: editorcommands.h:167
ScalePartsCommand::new_rect_
QRectF new_rect_
new rect items should fit in
Definition: editorcommands.h:260
ElementEditionCommand::setElementScene
void setElementScene(ElementScene *)
Definition: editorcommands.cpp:72
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
ChangeZValueCommand::undo
void undo() override
Annule les changements de zValue.
Definition: editorcommands.cpp:319
customelementpart.h
ScalePartsCommand::setTransformation
void setTransformation(const QRectF &, const QRectF &)
ScalePartsCommand::setTransformation Define the transformation applied by this command.
Definition: editorcommands.cpp:503
ChangeZValueCommand::applyLower
void applyLower(const QList< QGraphicsItem * > &)
Definition: editorcommands.cpp:373
DiagramContext
Definition: diagramcontext.h:56
MovePartsCommand::movement
QPointF movement
applied movement
Definition: editorcommands.h:117
ChangeZValueCommand::redo
void redo() override
Refait les changements de zValue.
Definition: editorcommands.cpp:324
ElementScene::setElementInfo
void setElementInfo(const DiagramContext &dc)
ElementScene::setElementInfo.
Definition: elementscene.cpp:691
ScalePartsCommand
Definition: editorcommands.h:231
ChangeInformationsCommand::~ChangeInformationsCommand
~ChangeInformationsCommand() override
Destructeur.
Definition: editorcommands.cpp:426
AddPartCommand
Definition: editorcommands.h:125
MovePartsCommand::redo
void redo() override
Refait le deplacement.
Definition: editorcommands.cpp:187