QElectroTech  0.70
templatecommands.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 TITLEBLOCK_SLASH_TEMPLATE_COMMANDS_H
19 #define TITLEBLOCK_SLASH_TEMPLATE_COMMANDS_H
20 #define MODIFY_TITLE_BLOCK_CELL_COMMAND_ID 6378
21 #include <QtCore>
22 #include <QUndoCommand>
23 #include "dimension.h"
24 #include "templatecellsset.h"
25 #include "titleblockcell.h"
27 class TitleBlockTemplate;
28 
33 class ModifyTitleBlockCellCommand : public QUndoCommand {
34  // constructor, destructor
35  public:
36  ModifyTitleBlockCellCommand(TitleBlockCell *, QUndoCommand * = nullptr);
38  private:
40 
41  // methods
42  public:
43  int id() const override;
44  bool mergeWith(const QUndoCommand *) override;
45  void undo() override;
46  void redo() override;
47  TitleBlockCell *cell() const;
48  void setCell(TitleBlockCell *);
51  void clear();
52  void addModification(const QString &, const QVariant &, bool = false);
53 
54  // attributes
55  private:
58  QHash<QString, QVariant> old_values_;
59  QHash<QString, QVariant> new_values_;
60 };
61 
66 class TitleBlockTemplateCommand : public QUndoCommand {
67  // Constructors, destructor
68  public:
69  TitleBlockTemplateCommand(TitleBlockTemplate * = nullptr, QUndoCommand * = nullptr);
70  ~TitleBlockTemplateCommand() override;
71  private:
73 
74  // methods
75  public:
80  void refreshView();
81  void refreshLayout();
82 
83  // attributes
84  protected:
87 };
88 
94  // static factory methods
95  public:
100 
101  // Constructors, destructor
102  public:
103  ModifyTemplateGridCommand(TitleBlockTemplate * = nullptr, QUndoCommand * = nullptr);
104  ~ModifyTemplateGridCommand() override;
105  private:
107 
108  // methods
109  public:
110  int index() const;
111  void setIndex(int);
112  QList<TitleBlockCell *> cells() const;
113  void setCells(const QList<TitleBlockCell *> &);
115  void setDimension(const TitleBlockDimension &);
116  int type() const;
117  void setType(bool);
118  bool isInsertion() const;
119  void setInsertion(bool);
120  void undo() override;
121  void redo() override;
122 
123  private:
124  void updateText();
125  void apply(bool = false);
126 
127  // attributes
128  private:
129  int index_;
130  QList<TitleBlockCell *> cells_;
131  bool type_;
133  bool insertion_;
134 };
135 
141  // Constructor, destructor
142  public:
143  ModifyTemplateDimension(TitleBlockTemplate * = nullptr, QUndoCommand * = nullptr);
144  ~ModifyTemplateDimension() override;
145  private:
147 
148  // methods
149  public:
150  int index() const;
151  void setIndex(int);
152  int type() const;
153  void setType(bool);
158  void undo() override;
159  void redo() override;
160 
161  private:
162  void updateText();
163  void apply(const TitleBlockDimension &);
164 
165  // attributes
166  private:
167  int index_;
168  bool type_;
171 };
172 
173 
178  // Constructor, destructor
179  public:
180  MergeCellsCommand(const TitleBlockTemplateCellsSet &, TitleBlockTemplate * = nullptr, QUndoCommand * = nullptr);
181  ~MergeCellsCommand() override;
182 
183  // methods
184  public:
186  bool isValid() const;
187  void undo() override;
188  void redo() override;
189  private:
191 
192  // attributes
193  private:
198  QHash<TitleBlockCell *, TitleBlockCell *> spanner_cells_before_merge_;
206 };
207 
212  // Constructor, destructor
213  public:
214  SplitCellsCommand(const TitleBlockTemplateCellsSet &, TitleBlockTemplate * = nullptr, QUndoCommand * = nullptr);
215  ~SplitCellsCommand() override;
216 
217  // methods
218  public:
219  static bool canSplit(const TitleBlockTemplateCellsSet &splitted_cells, TitleBlockTemplate *tbtemplate);
220  bool isValid() const;
221  void undo() override;
222  void redo() override;
223 
224  // attributes
225  private:
227  QSet<TitleBlockCell *> spanned_cells_;
233 };
234 
239 class ChangeTemplateInformationsCommand : public QUndoCommand {
240  // constructors, destructor
241  public:
242  ChangeTemplateInformationsCommand(TitleBlockTemplate *, const QString &, const QString &, QUndoCommand * = nullptr);
244  private:
246 
247  // methods
248  public:
249  void undo() override;
250  void redo() override;
251 
252  // attributes
253  private:
260 };
261 
266  // constructors, destructor
267  public:
268  CutTemplateCellsCommand(TitleBlockTemplate *, QUndoCommand * = nullptr);
269  ~CutTemplateCellsCommand() override;
270  private:
272 
273  // methods
274  public:
275  void undo() override;
276  void redo() override;
277  virtual void setCutCells(const QList<TitleBlockCell *> &);
278  protected:
279  virtual void updateText();
280 
281  // attributes
282  public:
284  QHash<TitleBlockCell *, TitleBlockCell::TemplateCellType> cut_cells_;
285 };
286 
291  // constructors, destructor
292  public:
293  PasteTemplateCellsCommand(TitleBlockTemplate *, QUndoCommand * = nullptr);
294  ~PasteTemplateCellsCommand() override;
295  private:
297 
298  // methods
299  public:
300  void undo() override;
301  void redo() override;
302  virtual void addPastedCell(TitleBlockCell *, const TitleBlockCell &);
303  virtual void addErasedCell(TitleBlockCell *, const TitleBlockCell &);
304  virtual void addCell(TitleBlockCell *, const TitleBlockCell &, const TitleBlockCell &);
305  protected:
306  virtual void updateText();
307 
308  // attributes
309  public:
311  QHash<TitleBlockCell *, QPair<int, int> > spans_before_;
313  QHash<TitleBlockCell *, TitleBlockCell> pasted_cells_;
315  QHash<TitleBlockCell *, TitleBlockCell> erased_cells_;
316 };
317 #endif
int applied_col_span_before_
the applied_col_span attribute of the spanning cell before the merge
void setDimensionAfter(const TitleBlockDimension &)
QList< TitleBlockCell * > cells_
Cells composing the inserted/deleted row/column.
TitleBlockCell * spanning_cell_
the cell spanning over the other ones
void setDimension(const TitleBlockDimension &)
~SplitCellsCommand() override
TitleBlockTemplateCommand(TitleBlockTemplate *=nullptr, QUndoCommand *=nullptr)
ChangeTemplateInformationsCommand(TitleBlockTemplate *, const QString &, const QString &, QUndoCommand *=nullptr)
TitleBlockTemplate * tbtemplate_
Modified TitleBlock Template.
TitleBlockDimension after_
Size of the row/column after it is changed.
TitleBlockTemplate * titleBlockTemplate() const
QHash< TitleBlockCell *, TitleBlockCell::TemplateCellType > cut_cells_
Cut cells.
QString old_information_
Informations before they are modified.
void undo() override
int col_span_before_
the col_span attribute of the spanning cell before the merge
int row_span_before_
the row_span attribute of the spanning cell before the merge
void setCell(TitleBlockCell *)
QHash< TitleBlockCell *, TitleBlockCell > erased_cells_
Existing cells impacted by the paste operation.
QHash< TitleBlockCell *, TitleBlockCell > pasted_cells_
Pasted cells.
int span_state_before_
the span_state attribute of the spanning cell before splitting
void setView(TitleBlockTemplateView *)
TitleBlockCell * modified_cell_
modified cell
bool mergeWith(const QUndoCommand *) override
QHash< QString, QVariant > new_values_
values after the cell has been modified
int index_
Index of the inserted/deleted row/column.
virtual void addErasedCell(TitleBlockCell *, const TitleBlockCell &)
TitleBlockTemplateView * view() const
ModifyTitleBlockCellCommand(TitleBlockCell *, QUndoCommand *=nullptr)
static bool canMerge(const TitleBlockTemplateCellsSet &, TitleBlockTemplate *)
void setDimensionBefore(const TitleBlockDimension &)
int applied_col_span_before_
the applied_col_span attribute of the spanning cell before splitting
void setView(TitleBlockTemplateView *)
static bool canSplit(const TitleBlockTemplateCellsSet &splitted_cells, TitleBlockTemplate *tbtemplate)
int applied_row_span_before_
the applied_row_span attribute of the spanning cell before the merge
virtual void setCutCells(const QList< TitleBlockCell *> &)
int applied_row_span_before_
the applied_row_span attribute of the spanning cell before splitting
TitleBlockTemplateView * view() const
TitleBlockDimension dimension() const
QHash< TitleBlockCell *, TitleBlockCell * > spanner_cells_before_merge_
CutTemplateCellsCommand(TitleBlockTemplate *, QUndoCommand *=nullptr)
QString new_information_
Informations after they were modified.
bool type_
true for a row, false for a column
TitleBlockDimension dimension_
width/height of the column/row, which interpretation depends on type_
QHash< QString, QVariant > old_values_
values before the cell is modified
void redo() override
int span_state_before_
the span_state attribute of the spanning cell before the merge
int row_span_before_
the row_span attribute of the spanning cell before splitting
PasteTemplateCellsCommand(TitleBlockTemplate *, QUndoCommand *=nullptr)
~MergeCellsCommand() override
static TitleBlockCell * getBottomRightCell(const TitleBlockTemplateCellsSet &)
int row_span_after_
the row_span attribute of the spanning cell after the merge
void setCells(const QList< TitleBlockCell *> &)
static ModifyTemplateGridCommand * deleteRow(TitleBlockTemplate *, int=-1)
static ModifyTemplateGridCommand * addRow(TitleBlockTemplate *, int=-1)
void apply(const TitleBlockDimension &)
int col_span_after_
the col_span attribute of the spanning cell after the merge
MergeCellsCommand(const TitleBlockTemplateCellsSet &, TitleBlockTemplate *=nullptr, QUndoCommand *=nullptr)
void undo() override
static ModifyTemplateGridCommand * deleteColumn(TitleBlockTemplate *, int=-1)
ModifyTemplateGridCommand(TitleBlockTemplate *=nullptr, QUndoCommand *=nullptr)
static ModifyTemplateGridCommand * addColumn(TitleBlockTemplate *, int=-1)
QSet< TitleBlockCell * > spanned_cells_
the spanned cells
bool type_
true for a row, false for a column
void setTitleBlockTemplate(TitleBlockTemplate *)
virtual void addPastedCell(TitleBlockCell *, const TitleBlockCell &)
TitleBlockDimension before_
Size of the row/column before it is changed.
TitleBlockTemplate * tbtemplate_
Changed title block template.
virtual void addCell(TitleBlockCell *, const TitleBlockCell &, const TitleBlockCell &)
SplitCellsCommand(const TitleBlockTemplateCellsSet &, TitleBlockTemplate *=nullptr, QUndoCommand *=nullptr)
TitleBlockTemplateView * view_
This class may trigger a view update.
ModifyTemplateDimension(TitleBlockTemplate *=nullptr, QUndoCommand *=nullptr)
int col_span_before_
the col_span attribute of the spanning cell before splitting
TitleBlockTemplateView * view_
This class may trigger a view update.
TitleBlockDimension dimensionAfter() const
QList< TitleBlockCell * > cells() const
void redo() override
TitleBlockDimension dimensionBefore() const
TitleBlockCell * spanning_cell_
the cell spanning over the other ones
int index_
Index of the resized row/column.
TitleBlockCell * cell() const
void addModification(const QString &, const QVariant &, bool=false)
QHash< TitleBlockCell *, QPair< int, int > > spans_before_
Spans before operation.