1 /***************************************************************************
2     File                 : matrixcommands.h
3     Project              : SciDAVis
4     Description          : Commands used in Matrix (part of the undo/redo framework)
5     --------------------------------------------------------------------
6     Copyright            : (C) 2008-2009 Tilman Benkert (thzs*gmx.net)
7                            (replace * with @ in the email addresses)
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  *                                                                         *
13  *  This program is free software; you can redistribute it and/or modify   *
14  *  it under the terms of the GNU General Public License as published by   *
15  *  the Free Software Foundation; either version 2 of the License, or      *
16  *  (at your option) any later version.                                    *
17  *                                                                         *
18  *  This program is distributed in the hope that it will be useful,        *
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
21  *  GNU General Public License for more details.                           *
22  *                                                                         *
23  *   You should have received a copy of the GNU General Public License     *
24  *   along with this program; if not, write to the Free Software           *
25  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
26  *   Boston, MA  02110-1301  USA                                           *
27  *                                                                         *
28  ***************************************************************************/
29 
30 #ifndef MATRIX_COMMANDS_H
31 #define MATRIX_COMMANDS_H
32 
33 #include <QUndoCommand>
34 #include "matrix/future_Matrix.h"
35 
36 ///////////////////////////////////////////////////////////////////////////
37 // class MatrixInsertColumnsCmd
38 ///////////////////////////////////////////////////////////////////////////
39 //! Insert columns
40 class MatrixInsertColumnsCmd : public QUndoCommand
41 {
42 public:
43     MatrixInsertColumnsCmd(future::Matrix::Private *private_obj, int before, int count,
44                            QUndoCommand *parent = 0);
45     ~MatrixInsertColumnsCmd();
46 
47     virtual void redo();
48     virtual void undo();
49 
50 private:
51     //! The private object to modify
52     future::Matrix::Private *d_private_obj;
53     //! Column to insert before
54     int d_before;
55     //! The number of new columns
56     int d_count;
57 };
58 
59 ///////////////////////////////////////////////////////////////////////////
60 // end of class MatrixInsertColumnsCmd
61 ///////////////////////////////////////////////////////////////////////////
62 
63 ///////////////////////////////////////////////////////////////////////////
64 // class MatrixInsertRowsCmd
65 ///////////////////////////////////////////////////////////////////////////
66 //! Insert rows
67 class MatrixInsertRowsCmd : public QUndoCommand
68 {
69 public:
70     MatrixInsertRowsCmd(future::Matrix::Private *private_obj, int before, int count,
71                         QUndoCommand *parent = 0);
72     ~MatrixInsertRowsCmd();
73 
74     virtual void redo();
75     virtual void undo();
76 
77 private:
78     //! The private object to modify
79     future::Matrix::Private *d_private_obj;
80     //! Row to insert before
81     int d_before;
82     //! The number of new rows
83     int d_count;
84 };
85 
86 ///////////////////////////////////////////////////////////////////////////
87 // end of class MatrixInsertRowsCmd
88 ///////////////////////////////////////////////////////////////////////////
89 
90 ///////////////////////////////////////////////////////////////////////////
91 // class MatrixRemoveColumnsCmd
92 ///////////////////////////////////////////////////////////////////////////
93 //! Remove columns
94 class MatrixRemoveColumnsCmd : public QUndoCommand
95 {
96 public:
97     MatrixRemoveColumnsCmd(future::Matrix::Private *private_obj, int first, int count,
98                            QUndoCommand *parent = 0);
99     ~MatrixRemoveColumnsCmd();
100 
101     virtual void redo();
102     virtual void undo();
103 
104 private:
105     //! The private object to modify
106     future::Matrix::Private *d_private_obj;
107     //! First column to remove
108     int d_first;
109     //! The number of columns to remove
110     int d_count;
111     //! Backups of the removed columns
112     QVector<QVector<qreal>> d_backups;
113 };
114 
115 ///////////////////////////////////////////////////////////////////////////
116 // end of class MatrixRemoveColumnsCmd
117 ///////////////////////////////////////////////////////////////////////////
118 
119 ///////////////////////////////////////////////////////////////////////////
120 // class MatrixRemoveRowsCmd
121 ///////////////////////////////////////////////////////////////////////////
122 //! Remove rows
123 class MatrixRemoveRowsCmd : public QUndoCommand
124 {
125 public:
126     MatrixRemoveRowsCmd(future::Matrix::Private *private_obj, int first, int count,
127                         QUndoCommand *parent = 0);
128     ~MatrixRemoveRowsCmd();
129 
130     virtual void redo();
131     virtual void undo();
132 
133 private:
134     //! The private object to modify
135     future::Matrix::Private *d_private_obj;
136     //! First row to remove
137     int d_first;
138     //! The number of rows to remove
139     int d_count;
140     //! Backups of the removed rows
141     QVector<QVector<qreal>> d_backups;
142 };
143 
144 ///////////////////////////////////////////////////////////////////////////
145 // end of class MatrixRemoveRowsCmd
146 ///////////////////////////////////////////////////////////////////////////
147 
148 ///////////////////////////////////////////////////////////////////////////
149 // class MatrixClearCmd
150 ///////////////////////////////////////////////////////////////////////////
151 //! Clear matrix
152 class MatrixClearCmd : public QUndoCommand
153 {
154 public:
155     MatrixClearCmd(future::Matrix::Private *private_obj, QUndoCommand *parent = 0);
156     ~MatrixClearCmd();
157 
158     virtual void redo();
159     virtual void undo();
160 
161 private:
162     //! The private object to modify
163     future::Matrix::Private *d_private_obj;
164     //! Backups of the cleared cells
165     QVector<QVector<qreal>> d_backups;
166 };
167 
168 ///////////////////////////////////////////////////////////////////////////
169 // end of class MatrixClearCmd
170 ///////////////////////////////////////////////////////////////////////////
171 
172 ///////////////////////////////////////////////////////////////////////////
173 // class MatrixClearColumnCmd
174 ///////////////////////////////////////////////////////////////////////////
175 //! Clear matrix column
176 class MatrixClearColumnCmd : public QUndoCommand
177 {
178 public:
179     MatrixClearColumnCmd(future::Matrix::Private *private_obj, int col, QUndoCommand *parent = 0);
180     ~MatrixClearColumnCmd();
181 
182     virtual void redo();
183     virtual void undo();
184 
185 private:
186     //! The private object to modify
187     future::Matrix::Private *d_private_obj;
188     //! The index of the column
189     int d_col;
190     //! Backup of the cleared column
191     QVector<qreal> d_backup;
192 };
193 
194 ///////////////////////////////////////////////////////////////////////////
195 // end of class MatrixClearColumnCmd
196 ///////////////////////////////////////////////////////////////////////////
197 
198 ///////////////////////////////////////////////////////////////////////////
199 // class MatrixSetCellValueCmd
200 ///////////////////////////////////////////////////////////////////////////
201 //! Set cell value
202 class MatrixSetCellValueCmd : public QUndoCommand
203 {
204 public:
205     MatrixSetCellValueCmd(future::Matrix::Private *private_obj, int row, int col, double value,
206                           QUndoCommand *parent = 0);
207     ~MatrixSetCellValueCmd();
208 
209     virtual void redo();
210     virtual void undo();
211 
212 private:
213     //! The private object to modify
214     future::Matrix::Private *d_private_obj;
215     //! The index of the row
216     int d_row;
217     //! The index of the column
218     int d_col;
219     //! New cell value
220     double d_value;
221     //! Backup of the changed value
222     double d_old_value;
223 };
224 
225 ///////////////////////////////////////////////////////////////////////////
226 // end of class MatrixSetCellValueCmd
227 ///////////////////////////////////////////////////////////////////////////
228 
229 ///////////////////////////////////////////////////////////////////////////
230 // class MatrixSetCoordinatesCmd
231 ///////////////////////////////////////////////////////////////////////////
232 //! Set matrix coordinates
233 class MatrixSetCoordinatesCmd : public QUndoCommand
234 {
235 public:
236     MatrixSetCoordinatesCmd(future::Matrix::Private *private_obj, double x1, double x2, double y1,
237                             double y2, QUndoCommand *parent = 0);
238     ~MatrixSetCoordinatesCmd();
239 
240     virtual void redo();
241     virtual void undo();
242 
243 private:
244     //! The private object to modify
245     future::Matrix::Private *d_private_obj;
246     double d_new_x1;
247     double d_new_x2;
248     double d_new_y1;
249     double d_new_y2;
250     double d_old_x1;
251     double d_old_x2;
252     double d_old_y1;
253     double d_old_y2;
254 };
255 
256 ///////////////////////////////////////////////////////////////////////////
257 // end of class MatrixSetCoordinatesCmd
258 ///////////////////////////////////////////////////////////////////////////
259 
260 ///////////////////////////////////////////////////////////////////////////
261 // class MatrixSetFormatCmd
262 ///////////////////////////////////////////////////////////////////////////
263 //! Set numeric format
264 class MatrixSetFormatCmd : public QUndoCommand
265 {
266 public:
267     MatrixSetFormatCmd(future::Matrix::Private *private_obj, char new_format);
268 
269     virtual void redo();
270     virtual void undo();
271 
272 private:
273     //! The private object to modify
274     future::Matrix::Private *d_private_obj;
275     char d_other_format;
276 };
277 ///////////////////////////////////////////////////////////////////////////
278 // end of class MatrixSetFormatCmd
279 ///////////////////////////////////////////////////////////////////////////
280 
281 ///////////////////////////////////////////////////////////////////////////
282 // class MatrixSetDigitsCmd
283 ///////////////////////////////////////////////////////////////////////////
284 //! Set displayed digits
285 class MatrixSetDigitsCmd : public QUndoCommand
286 {
287 public:
288     MatrixSetDigitsCmd(future::Matrix::Private *private_obj, int new_digits);
289 
290     virtual void redo();
291     virtual void undo();
292 
293 private:
294     //! The private object to modify
295     future::Matrix::Private *d_private_obj;
296     int d_other_digits;
297 };
298 ///////////////////////////////////////////////////////////////////////////
299 // end of class MatrixSetDigitsCmd
300 ///////////////////////////////////////////////////////////////////////////
301 
302 ///////////////////////////////////////////////////////////////////////////
303 // class MatrixSetFormulaCmd
304 ///////////////////////////////////////////////////////////////////////////
305 //! Set matrix formula
306 class MatrixSetFormulaCmd : public QUndoCommand
307 {
308 public:
309     MatrixSetFormulaCmd(future::Matrix::Private *private_obj, QString formula);
310 
311     virtual void redo();
312     virtual void undo();
313 
314 private:
315     //! The private object to modify
316     future::Matrix::Private *d_private_obj;
317     QString d_other_formula;
318 };
319 ///////////////////////////////////////////////////////////////////////////
320 // end of class MatrixSetFormulaCmd
321 ///////////////////////////////////////////////////////////////////////////
322 
323 ///////////////////////////////////////////////////////////////////////////
324 // class MatrixSetColumnCellsCmd
325 ///////////////////////////////////////////////////////////////////////////
326 //! Set cell values for (a part of) a column at once
327 class MatrixSetColumnCellsCmd : public QUndoCommand
328 {
329 public:
330     MatrixSetColumnCellsCmd(future::Matrix::Private *private_obj, int col, int first_row,
331                             int last_row, const QVector<qreal> &values, QUndoCommand *parent = 0);
332     ~MatrixSetColumnCellsCmd();
333 
334     virtual void redo();
335     virtual void undo();
336 
337 private:
338     //! The private object to modify
339     future::Matrix::Private *d_private_obj;
340     //! The index of the column
341     int d_col;
342     //! The index of the first row
343     int d_first_row;
344     //! The index of the last row
345     int d_last_row;
346     //! New cell values
347     QVector<qreal> d_values;
348     //! Backup of the changed values
349     QVector<qreal> d_old_values;
350 };
351 
352 ///////////////////////////////////////////////////////////////////////////
353 // end of class MatrixSetColumnCellsCmd
354 ///////////////////////////////////////////////////////////////////////////
355 
356 ///////////////////////////////////////////////////////////////////////////
357 // class MatrixSetRowCellsCmd
358 ///////////////////////////////////////////////////////////////////////////
359 //! Set cell values for (a part of) a row at once
360 class MatrixSetRowCellsCmd : public QUndoCommand
361 {
362 public:
363     MatrixSetRowCellsCmd(future::Matrix::Private *private_obj, int row, int first_column,
364                          int last_column, const QVector<qreal> &values, QUndoCommand *parent = 0);
365     ~MatrixSetRowCellsCmd();
366 
367     virtual void redo();
368     virtual void undo();
369 
370 private:
371     //! The private object to modify
372     future::Matrix::Private *d_private_obj;
373     //! The index of the row
374     int d_row;
375     //! The index of the first column
376     int d_first_column;
377     //! The index of the last column
378     int d_last_column;
379     //! New cell values
380     QVector<qreal> d_values;
381     //! Backup of the changed values
382     QVector<qreal> d_old_values;
383 };
384 
385 ///////////////////////////////////////////////////////////////////////////
386 // end of class MatrixSetRowCellsCmd
387 ///////////////////////////////////////////////////////////////////////////
388 
389 ///////////////////////////////////////////////////////////////////////////
390 // class MatrixSetCellsCmd
391 ///////////////////////////////////////////////////////////////////////////
392 //! Set cell values for multiple cells at once
393 class MatrixSetCellsCmd : public QUndoCommand
394 {
395 public:
396     MatrixSetCellsCmd(future::Matrix::Private *private_obj, int first_row, int last_row,
397                       int first_column, int last_column,
398                       const std::vector<std::vector<std::pair<double, bool>>> &values,
399                       QUndoCommand *parent = 0);
400 
401     void redo() override;
402     void undo() override;
403 
404 private:
405     //! The private object to modify
406     future::Matrix::Private * const d_private_obj;
407     //! The index of the first row
408     const int d_first_row;
409     //! The index of the last row
410     const int d_last_row;
411     //! The index of the first column
412     const int d_first_column;
413     //! The index of the last column
414     const int d_last_column;
415     //! New cell values
416     const std::vector<std::vector<std::pair<double, bool>>> d_values;
417     //! Backup of the changed values
418     const std::vector<std::vector<std::pair<double, bool>>> d_old_values;
419 };
420 
421 ///////////////////////////////////////////////////////////////////////////
422 // end of class MatrixSetCellsCmd
423 ///////////////////////////////////////////////////////////////////////////
424 
425 ///////////////////////////////////////////////////////////////////////////
426 // class MatrixTransposeCmd
427 ///////////////////////////////////////////////////////////////////////////
428 //! Transpose the matrix
429 class MatrixTransposeCmd : public QUndoCommand
430 {
431 public:
432     MatrixTransposeCmd(future::Matrix::Private *private_obj, QUndoCommand *parent = 0);
433     ~MatrixTransposeCmd();
434 
435     virtual void redo();
436     virtual void undo();
437 
438 private:
439     //! The private object to modify
440     future::Matrix::Private *d_private_obj;
441 };
442 
443 ///////////////////////////////////////////////////////////////////////////
444 // end of class MatrixTransposeCmd
445 ///////////////////////////////////////////////////////////////////////////
446 
447 ///////////////////////////////////////////////////////////////////////////
448 // class MatrixMirrorHorizontallyCmd
449 ///////////////////////////////////////////////////////////////////////////
450 //! Mirror the matrix horizontally
451 class MatrixMirrorHorizontallyCmd : public QUndoCommand
452 {
453 public:
454     MatrixMirrorHorizontallyCmd(future::Matrix::Private *private_obj, QUndoCommand *parent = 0);
455     ~MatrixMirrorHorizontallyCmd();
456 
457     virtual void redo();
458     virtual void undo();
459 
460 private:
461     //! The private object to modify
462     future::Matrix::Private *d_private_obj;
463 };
464 
465 ///////////////////////////////////////////////////////////////////////////
466 // end of class MatrixMirrorHorizontallyCmd
467 ///////////////////////////////////////////////////////////////////////////
468 
469 ///////////////////////////////////////////////////////////////////////////
470 // class MatrixMirrorVerticallyCmd
471 ///////////////////////////////////////////////////////////////////////////
472 //! Mirror the matrix vertically
473 class MatrixMirrorVerticallyCmd : public QUndoCommand
474 {
475 public:
476     MatrixMirrorVerticallyCmd(future::Matrix::Private *private_obj, QUndoCommand *parent = 0);
477     ~MatrixMirrorVerticallyCmd();
478 
479     virtual void redo();
480     virtual void undo();
481 
482 private:
483     //! The private object to modify
484     future::Matrix::Private *d_private_obj;
485 };
486 
487 ///////////////////////////////////////////////////////////////////////////
488 // end of class MatrixMirrorVerticallyCmd
489 ///////////////////////////////////////////////////////////////////////////
490 
491 #endif // MATRIX_COMMANDS_H
492