QElectroTech  0.8-dev
diagramcommands.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 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,
45  const QPointF &pos = QPointF(),
46  QUndoCommand *parent = nullptr) :
47  QUndoCommand (parent),
48  m_item (item),
49  m_diagram (diagram),
50  m_pos(pos)
51  {
52  setText(QObject::tr("Ajouter ") + itemText(item));
53  m_diagram -> qgiManager().manage(m_item);
54  }
55 
56  ~AddItemCommand() override {
57  m_diagram -> qgiManager().release(m_item);
58  }
59 
60  void undo() override {
61  m_diagram -> showMe();
62  m_diagram -> removeItem(m_item);
63  QUndoCommand::undo();
64  }
65 
66  void redo() override {
67  m_diagram -> showMe();
68  m_diagram -> addItem(m_item);
69  m_item -> setPos(m_pos);
70  QUndoCommand::redo();
71  }
72 
73  private:
74  QGI m_item;
76  QPointF m_pos;
77 };
78 
79 //Return a string to describe a QGraphicsItem
80 QString itemText(const QetGraphicsItem *item);
81 QString itemText(const IndependentTextItem *item);
82 QString itemText(const Conductor *item);
83 
88 class PasteDiagramCommand : public QUndoCommand {
89  // constructors, destructor
90  public:
92  QUndoCommand * = nullptr);
93  ~PasteDiagramCommand() override;
94  private:
96 
97  // methods
98  public:
99  void undo() override;
100  void redo() override;
101 
102  // attributes
103  private:
109  int filter;
112 };
113 
119  // constructors, destructor
120  public:
122  QUndoCommand * = nullptr);
123  ~CutDiagramCommand() override;
124  private:
126 };
127 
132 class MoveElementsCommand : public QUndoCommand {
133  // constructors, destructor
134  public:
136  const QPointF &m, QUndoCommand * = nullptr);
137  ~MoveElementsCommand() override;
138  private:
140 
141  // methods
142  public:
143  void undo() override;
144  void redo() override;
145  virtual void move(const QPointF &);
146 
147  private:
148  void setupAnimation (QObject * target,
149  const QByteArray &propertyName,
150  const QVariant& start,
151  const QVariant& end);
152 
153  // attributes
154  private:
160  QPointF movement;
162  QParallelAnimationGroup *m_anim_group;
165 };
166 
172 class MoveConductorsTextsCommand : public QUndoCommand {
173  // constructors, destructor
174  public:
175  MoveConductorsTextsCommand(Diagram *, QUndoCommand * = nullptr);
176  ~MoveConductorsTextsCommand() override;
177  private:
179 
180  // methods
181  public:
182  void undo() override;
183  void redo() override;
184  virtual void addTextMovement(ConductorTextItem *,
185  const QPointF &,
186  const QPointF &,
187  bool = false);
188 
189  private:
190  void regenerateTextLabel();
191 
192  // attributes
193  private:
197  QHash<ConductorTextItem *, QPair<QPointF, bool> > texts_to_move_;
200 };
201 
206 class ChangeDiagramTextCommand : public QUndoCommand {
207  // constructors, destructor
208  public:
210  const QString &before,
211  const QString &after,
212  QUndoCommand * = nullptr);
213  ~ChangeDiagramTextCommand() override;
214  private:
216 
217  // methods
218  public:
219  void undo() override;
220  void redo() override;
221 
222  // attributes
223  private:
227  QString text_before;
229  QString text_after;
233 };
234 
239 class ChangeConductorCommand : public QUndoCommand {
240  // constructors, destructor
241  public:
243  const ConductorProfile &, Qt::Corner,
244  QUndoCommand * = nullptr);
245  ~ChangeConductorCommand() override;
246  private:
248 
249  // methods
250  public:
251  void undo() override;
252  void redo() override;
253  virtual void setConductorTextItemMove(const QPointF &, const QPointF &);
254 
255  // attributes
256  private:
264  Qt::Corner path_type;
272 };
273 
278 class ResetConductorCommand : public QUndoCommand {
279  // constructors, destructor
280  public:
281  ResetConductorCommand(const QHash<Conductor *,
283  QUndoCommand * = nullptr);
284  ~ResetConductorCommand() override;
285  private:
287 
288  // methods
289  public:
290  void undo() override;
291  void redo() override;
292 
293  // attributes
294  private:
296  QHash<Conductor *, ConductorProfilesGroup> conductors_profiles;
298 };
299 
300 
301 
306 class ChangeBorderCommand : public QUndoCommand {
307  // constructors, destructor
308  public:
310  const BorderProperties &, QUndoCommand * = nullptr);
311  ~ChangeBorderCommand() override;
312  private:
314 
315  // methods
316  public:
317  void undo() override;
318  void redo() override;
319 
320  // attributes
321  private:
324  public:
329 };
330 
331 #endif
MoveElementsCommand::movement
QPointF movement
applied movement
Definition: diagramcommands.h:160
ChangeDiagramTextCommand::redo
void redo() override
ChangeDiagramTextCommand::redo.
Definition: diagramcommands.cpp:455
qgimanager.h
MoveConductorsTextsCommand::addTextMovement
virtual void addTextMovement(ConductorTextItem *, const QPointF &, const QPointF &, bool=false)
MoveConductorsTextsCommand::addTextMovement Ajout un mouvement de champ de texte a cet objet.
Definition: diagramcommands.cpp:381
AddItemCommand::m_diagram
Diagram * m_diagram
Definition: diagramcommands.h:75
MoveElementsCommand::setupAnimation
void setupAnimation(QObject *target, const QByteArray &propertyName, const QVariant &start, const QVariant &end)
MoveElementsCommand::setupAnimation Set up the animation for this undo command.
Definition: diagramcommands.cpp:298
BorderProperties
The BorderProperties class This class is a container for dimensions and display properties of a diagr...
Definition: borderproperties.h:29
MoveConductorsTextsCommand::first_redo
bool first_redo
prevent the first call to redo()
Definition: diagramcommands.h:199
PasteDiagramCommand::undo
void undo() override
PasteDiagramCommand::undo Undo this command.
Definition: diagramcommands.cpp:75
DiagramContent::Images
@ Images
Definition: diagramcontent.h:57
DiagramContent::ConductorsToMove
@ ConductorsToMove
Definition: diagramcontent.h:58
ConductorProfile
Definition: conductorprofile.h:28
PasteDiagramCommand::diagram
Diagram * diagram
diagram content is pasted onto
Definition: diagramcommands.h:107
QetGraphicsItem
Definition: qetgraphicsitem.h:27
ChangeConductorCommand::old_profile
ConductorProfile old_profile
profile before the change
Definition: diagramcommands.h:260
diagramcommands.h
MoveConductorsTextsCommand::regenerateTextLabel
void regenerateTextLabel()
MoveConductorsTextsCommand::regenerateTextLabel Genere la description de l'objet d'annulation.
Definition: diagramcommands.cpp:400
itemText
QString itemText(const QetGraphicsItem *item)
Definition: diagramcommands.cpp:31
ResetConductorCommand::ResetConductorCommand
ResetConductorCommand(const QHash< Conductor *, ConductorProfilesGroup > &, QUndoCommand *=nullptr)
ResetConductorCommand::ResetConductorCommand.
Definition: diagramcommands.cpp:535
MoveElementsCommand::undo
void undo() override
MoveElementsCommand::undo.
Definition: diagramcommands.cpp:220
ChangeConductorCommand::ChangeConductorCommand
ChangeConductorCommand(Conductor *, const ConductorProfile &, const ConductorProfile &, Qt::Corner, QUndoCommand *=nullptr)
ChangeConductorCommand::ChangeConductorCommand Constructeur.
Definition: diagramcommands.cpp:470
ResetConductorCommand::diagram
Diagram * diagram
Definition: diagramcommands.h:297
conductor.h
ChangeBorderCommand::diagram
Diagram * diagram
modified diagram
Definition: diagramcommands.h:323
DiagramContent::m_conductors_to_move
QList< Conductor * > m_conductors_to_move
Definition: diagramcontent.h:74
DiagramContent::TextFields
@ TextFields
Definition: diagramcontent.h:55
conductortextitem.h
DeleteQGraphicsItemCommand
Definition: deleteqgraphicsitemcommand.h:31
MoveConductorsTextsCommand::texts_to_move_
QHash< ConductorTextItem *, QPair< QPointF, bool > > texts_to_move_
text items to be moved
Definition: diagramcommands.h:197
elementtextitemgroup.h
Diagram::addItem
virtual void addItem(QGraphicsItem *item)
Diagram::addItem Réimplemented from QGraphicsScene::addItem(QGraphicsItem *item) Do some specific ope...
Definition: diagram.cpp:1550
ChangeDiagramTextCommand::ChangeDiagramTextCommand
ChangeDiagramTextCommand(DiagramTextItem *, const QString &before, const QString &after, QUndoCommand *=nullptr)
ChangeDiagramTextCommand::ChangeDiagramTextCommand Constructeur.
Definition: diagramcommands.cpp:421
ChangeDiagramTextCommand::diagram
Diagram * diagram
Definition: diagramcommands.h:232
DiagramContent
Definition: diagramcontent.h:46
AddItemCommand::m_item
QGI m_item
Definition: diagramcommands.h:74
MoveElementsCommand::diagram
Diagram * diagram
diagram the movement takes place on.
Definition: diagramcommands.h:156
DiagramContent::m_elements
QList< Element * > m_elements
Definition: diagramcontent.h:69
borderproperties.h
QetGraphicsItem::name
virtual QString name() const
Definition: qetgraphicsitem.h:44
DiagramContent::m_conductors_to_update
QList< Conductor * > m_conductors_to_update
Definition: diagramcontent.h:73
ResetConductorCommand
The ResetConductorCommand class This command resets conductor paths.
Definition: diagramcommands.h:278
ChangeConductorCommand::first_redo
bool first_redo
prevent the first call to redo()
Definition: diagramcommands.h:270
MoveConductorsTextsCommand::redo
void redo() override
MoveConductorsTextsCommand::redo refait le deplacement.
Definition: diagramcommands.cpp:356
DiagramTextItem::setHtml
void setHtml(const QString &text)
Definition: diagramtextitem.cpp:212
PasteDiagramCommand::PasteDiagramCommand
PasteDiagramCommand(const PasteDiagramCommand &)
CutDiagramCommand::CutDiagramCommand
CutDiagramCommand(Diagram *, const DiagramContent &, QUndoCommand *=nullptr)
CutDiagramCommand::CutDiagramCommand Constructeur.
Definition: diagramcommands.cpp:144
ChangeDiagramTextCommand::~ChangeDiagramTextCommand
~ChangeDiagramTextCommand() override
ChangeDiagramTextCommand::~ChangeDiagramTextCommand destructeur.
Definition: diagramcommands.cpp:440
MoveElementsCommand::m_anim_group
QParallelAnimationGroup * m_anim_group
animation group
Definition: diagramcommands.h:162
QET::ElementsAndConductorsSentence
QString ElementsAndConductorsSentence(int elements=0, int conductors=0, int indi_texts=0, int images=0, int shapes=0, int element_text=0, int tables_count=0)
QET::ElementsAndConductorsSentence Permet de composer rapidement la proposition "x elements et y cond...
Definition: qet.cpp:258
DiagramContent::ElementTextFields
@ ElementTextFields
Definition: diagramcontent.h:56
DiagramContent::sentence
QString sentence(int=All) const
DiagramContent::sentence.
Definition: diagramcontent.cpp:438
ChangeConductorCommand::diagram
Diagram * diagram
Definition: diagramcommands.h:271
ChangeConductorCommand::undo
void undo() override
ChangeConductorCommand::undo Annule la modification du conducteur.
Definition: diagramcommands.cpp:498
ChangeBorderCommand::redo
void redo() override
ChangeBorderCommand::redo Refait les changements apportes au schema.
Definition: diagramcommands.cpp:620
ChangeDiagramTextCommand::text_item
DiagramTextItem * text_item
modified text item
Definition: diagramcommands.h:225
ChangeConductorCommand::text_pos_before_mov_
QPointF text_pos_before_mov_
position of the text item before the change
Definition: diagramcommands.h:266
PasteDiagramCommand::~PasteDiagramCommand
~PasteDiagramCommand() override
PasteDiagramCommand::~PasteDiagramCommand Destructor.
Definition: diagramcommands.cpp:67
AddItemCommand::undo
void undo() override
Definition: diagramcommands.h:60
ChangeDiagramTextCommand::text_after
QString text_after
new text
Definition: diagramcommands.h:229
MoveElementsCommand::content_to_move
DiagramContent content_to_move
moved content
Definition: diagramcommands.h:158
DiagramImageItem
Definition: diagramimageitem.h:31
MoveConductorsTextsCommand::diagram
Diagram * diagram
diagram the movement takes place on.
Definition: diagramcommands.h:195
ResetConductorCommand::conductors_profiles
QHash< Conductor *, ConductorProfilesGroup > conductors_profiles
impacted conductors along with their former profiles
Definition: diagramcommands.h:296
AddItemCommand::redo
void redo() override
Definition: diagramcommands.h:66
Diagram
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition: diagram.h:56
ChangeConductorCommand::text_pos_after_mov_
QPointF text_pos_after_mov_
position of the text item after the change
Definition: diagramcommands.h:268
qet.h
ChangeBorderCommand::~ChangeBorderCommand
~ChangeBorderCommand() override
ChangeBorderCommand::~ChangeBorderCommand Destructeur.
Definition: diagramcommands.cpp:604
ChangeConductorCommand
The ChangeConductorCommand class This command changes a particular conductor.
Definition: diagramcommands.h:239
CutDiagramCommand::~CutDiagramCommand
~CutDiagramCommand() override
CutDiagramCommand::~CutDiagramCommand Destructeur.
Definition: diagramcommands.cpp:165
MoveConductorsTextsCommand::undo
void undo() override
MoveConductorsTextsCommand::undo annule le deplacement.
Definition: diagramcommands.cpp:339
ChangeBorderCommand::ChangeBorderCommand
ChangeBorderCommand(const ChangeBorderCommand &)
PasteDiagramCommand::filter
int filter
filter stating what kinds of items should be pasted
Definition: diagramcommands.h:109
ChangeDiagramTextCommand::first_redo
bool first_redo
prevent the first call to redo()
Definition: diagramcommands.h:231
Diagram::removeItem
virtual void removeItem(QGraphicsItem *item)
Diagram::removeItem Reimplemented from QGraphicsScene::removeItem(QGraphicsItem *item) Do some specif...
Definition: diagram.cpp:1581
PasteDiagramCommand::first_redo
bool first_redo
prevent the first call to redo()
Definition: diagramcommands.h:111
DiagramContent::ConductorsToUpdate
@ ConductorsToUpdate
Definition: diagramcontent.h:59
ConductorProfilesGroup
QHash< Qt::Corner, ConductorProfile > ConductorProfilesGroup
Definition: conductor.h:37
conductorprofile.h
MoveElementsCommand::move
virtual void move(const QPointF &)
MoveElementsCommand::move Move item and conductor to actual_movement.
Definition: diagramcommands.cpp:248
MoveConductorsTextsCommand
The MoveConductorsTextsCommand class This command moves text items related to conductors on a particu...
Definition: diagramcommands.h:172
CutDiagramCommand::CutDiagramCommand
CutDiagramCommand(const CutDiagramCommand &)
ChangeBorderCommand::old_properties
BorderProperties old_properties
properties before the change
Definition: diagramcommands.h:326
AddItemCommand
The AddItemCommand class This command add an item in a diagram The item to add is template,...
Definition: diagramcommands.h:42
element.h
ChangeConductorCommand::path_type
Qt::Corner path_type
Path type of the modified conductor.
Definition: diagramcommands.h:264
Conductor::pos
QPointF pos
Definition: conductor.h:46
PasteDiagramCommand::content
DiagramContent content
pasted content
Definition: diagramcommands.h:105
ResetConductorCommand::~ResetConductorCommand
~ResetConductorCommand() override
ResetConductorCommand::~ResetConductorCommand.
Definition: diagramcommands.cpp:554
Element
Definition: element.h:41
MoveElementsCommand::~MoveElementsCommand
~MoveElementsCommand() override
MoveElementsCommand::~MoveElementsCommand Destructor.
Definition: diagramcommands.cpp:213
AddItemCommand::m_pos
QPointF m_pos
Definition: diagramcommands.h:76
ChangeDiagramTextCommand::ChangeDiagramTextCommand
ChangeDiagramTextCommand(const ChangeDiagramTextCommand &)
ResetConductorCommand::redo
void redo() override
ResetConductorCommand::redo.
Definition: diagramcommands.cpp:570
AddItemCommand::AddItemCommand
AddItemCommand(QGI item, Diagram *diagram, const QPointF &pos=QPointF(), QUndoCommand *parent=nullptr)
Definition: diagramcommands.h:44
diagramcontent.h
ResetConductorCommand::undo
void undo() override
ResetConductorCommand::undo.
Definition: diagramcommands.cpp:560
MoveElementsCommand
The MoveElementsCommand class This command moves some content on a particular diagram.
Definition: diagramcommands.h:132
AddItemCommand::~AddItemCommand
~AddItemCommand() override
Definition: diagramcommands.h:56
independenttextitem.h
DiagramTextItem
Definition: diagramtextitem.h:34
DiagramContent::All
@ All
Definition: diagramcontent.h:65
MoveElementsCommand::first_redo
bool first_redo
prevent the first call to redo()
Definition: diagramcommands.h:164
ChangeDiagramTextCommand
The ChangeDiagramTextCommand class This commad modifies a text item.
Definition: diagramcommands.h:206
MoveElementsCommand::MoveElementsCommand
MoveElementsCommand(Diagram *, const DiagramContent &, const QPointF &m, QUndoCommand *=nullptr)
MoveElementsCommand::MoveElementsCommand Constructor.
Definition: diagramcommands.cpp:176
ChangeDiagramTextCommand::undo
void undo() override
ChangeDiagramTextCommand::undo annule la modification de texte.
Definition: diagramcommands.cpp:447
ChangeConductorCommand::setConductorTextItemMove
virtual void setConductorTextItemMove(const QPointF &, const QPointF &)
ChangeConductorCommand::setConductorTextItemMove Integre dans cet objet d'annulation le repositionnem...
Definition: diagramcommands.cpp:525
ElementTextItemGroup
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
Definition: elementtextitemgroup.h:36
PasteDiagramCommand::redo
void redo() override
PasteDiagramCommand::redo Redo this commnand.
Definition: diagramcommands.cpp:87
MoveElementsCommand::redo
void redo() override
MoveElementsCommand::redo.
Definition: diagramcommands.cpp:230
MoveConductorsTextsCommand::MoveConductorsTextsCommand
MoveConductorsTextsCommand(Diagram *, QUndoCommand *=nullptr)
MoveConductorsTextsCommand::MoveConductorsTextsCommand Constructeur.
Definition: diagramcommands.cpp:318
ChangeBorderCommand::ChangeBorderCommand
ChangeBorderCommand(Diagram *, const BorderProperties &, const BorderProperties &, QUndoCommand *=nullptr)
ChangeBorderCommand::ChangeBorderCommand Constructeur.
Definition: diagramcommands.cpp:587
MoveConductorsTextsCommand::~MoveConductorsTextsCommand
~MoveConductorsTextsCommand() override
MoveConductorsTextsCommand::~MoveConductorsTextsCommand Destructeur.
Definition: diagramcommands.cpp:332
ChangeBorderCommand::undo
void undo() override
ChangeBorderCommand::undo Annule les changements apportes au schema.
Definition: diagramcommands.cpp:611
diagramtextitem.h
PasteDiagramCommand::PasteDiagramCommand
PasteDiagramCommand(Diagram *, const DiagramContent &, QUndoCommand *=nullptr)
PasteDiagramCommand::PasteDiagramCommand Constructor.
Definition: diagramcommands.cpp:52
ConductorProperties
The ConductorProperties class This class represents the functional properties of a particular conduct...
Definition: conductorproperties.h:68
IndependentTextItem
Definition: independenttextitem.h:28
CutDiagramCommand
The CutDiagramCommand class This command cuts content from a particular diagram.
Definition: diagramcommands.h:118
DiagramContent::Shapes
@ Shapes
Definition: diagramcontent.h:62
ChangeConductorCommand::redo
void redo() override
ChangeConductorCommand::redo Refait la modification du conducteur.
Definition: diagramcommands.cpp:508
PasteDiagramCommand
The PasteDiagramCommand class This command pastes some content onto a particular diagram.
Definition: diagramcommands.h:88
ChangeConductorCommand::new_profile
ConductorProfile new_profile
profile after the change
Definition: diagramcommands.h:262
DiagramContent::items
QList< QGraphicsItem * > items(int=All) const
DiagramContent::items.
Definition: diagramcontent.cpp:374
MoveElementsCommand::MoveElementsCommand
MoveElementsCommand(const MoveElementsCommand &)
qetshapeitem.h
ChangeConductorCommand::conductor
Conductor * conductor
changed conductor
Definition: diagramcommands.h:258
ChangeBorderCommand::new_properties
BorderProperties new_properties
properties after the change
Definition: diagramcommands.h:328
Conductor
Definition: conductor.h:43
ChangeConductorCommand::~ChangeConductorCommand
~ChangeConductorCommand() override
ChangeConductorCommand::~ChangeConductorCommand Destructeur.
Definition: diagramcommands.cpp:491
ResetConductorCommand::ResetConductorCommand
ResetConductorCommand(const ResetConductorCommand &)
ChangeDiagramTextCommand::text_before
QString text_before
former text
Definition: diagramcommands.h:227
ConductorTextItem
Definition: conductortextitem.h:30
DiagramContent::Elements
@ Elements
Definition: diagramcontent.h:54
ConductorProperties::text
QString text
Definition: conductorproperties.h:89
deleteqgraphicsitemcommand.h
diagramimageitem.h
DiagramContext::addValue
bool addValue(const QString &, const QVariant &, bool show=true)
Definition: diagramcontext.cpp:91
itemText
QString itemText(const QetGraphicsItem *item)
Definition: diagramcommands.cpp:31
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
ChangeConductorCommand::ChangeConductorCommand
ChangeConductorCommand(const ChangeConductorCommand &)
ChangeBorderCommand
The ChangeBorderCommand class This command changes the border properties of a particular diagram.
Definition: diagramcommands.h:306
DiagramContext
Definition: diagramcontext.h:56
diagram.h
MoveConductorsTextsCommand::MoveConductorsTextsCommand
MoveConductorsTextsCommand(const MoveConductorsTextsCommand &)