QtiPlot  0.9.8.2
MatrixCommand.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : MatrixCommand.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2008 by Ion Vasilief,
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : Matrix undo/redo commands
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef MATRIX_COMMAND_H
00030 #define MATRIX_COMMAND_H
00031 
00032 #include "Matrix.h"
00033 #include "MatrixModel.h"
00034 #include <QUndoCommand>
00035 
00037 class MatrixEditCellCommand: public QUndoCommand
00038 {
00039 public:
00040     MatrixEditCellCommand(MatrixModel *model, const QModelIndex & index, double valBefore,
00041                             double valAfter, const QString & text);
00042     virtual void redo();
00043     virtual void undo();
00044 
00045 private:
00046     MatrixModel *d_model;
00047     QModelIndex d_index;
00048     double d_val_before;
00049     double d_val_after;
00050 };
00051 
00052 class MatrixSetFormulaCommand: public QUndoCommand
00053 {
00054 public:
00055     MatrixSetFormulaCommand(Matrix *m, const QString& oldFormula, const QString& newFormula, const QString & text);
00056     virtual void redo();
00057     virtual void undo();
00058 
00059 private:
00060     Matrix *d_matrix;
00061     QString d_old_formula;
00062     QString d_new_formula;
00063 };
00064 
00065 class MatrixSetViewCommand: public QUndoCommand
00066 {
00067 public:
00068     MatrixSetViewCommand(Matrix *m, Matrix::ViewType oldView, Matrix::ViewType newView, const QString & text);
00069     virtual void redo();
00070     virtual void undo();
00071 
00072 private:
00073     Matrix *d_matrix;
00074     Matrix::ViewType d_old_view;
00075     Matrix::ViewType d_new_view;
00076 };
00077 
00078 class MatrixSetHeaderViewCommand: public QUndoCommand
00079 {
00080 public:
00081     MatrixSetHeaderViewCommand(Matrix *m, Matrix::HeaderViewType oldView,
00082                             Matrix::HeaderViewType newView, const QString & text);
00083     virtual void redo();
00084     virtual void undo();
00085 
00086 private:
00087     Matrix *d_matrix;
00088     Matrix::HeaderViewType d_old_view;
00089     Matrix::HeaderViewType d_new_view;
00090 };
00091 
00092 class MatrixSetColWidthCommand: public QUndoCommand
00093 {
00094 public:
00095     MatrixSetColWidthCommand(Matrix *m, int oldWidth, int newWidth, const QString & text);
00096     virtual void redo();
00097     virtual void undo();
00098 
00099 private:
00100     Matrix *d_matrix;
00101     int d_old_width;
00102     int d_new_width;
00103 };
00104 
00105 class MatrixSetPrecisionCommand: public QUndoCommand
00106 {
00107 public:
00108     MatrixSetPrecisionCommand(Matrix *m, const QChar& oldFormat, const QChar& newFormat,
00109                     int oldPrec, int newPrec, const QString & text);
00110     virtual void redo();
00111     virtual void undo();
00112 
00113 private:
00114     Matrix *d_matrix;
00115     QChar d_old_format;
00116     QChar d_new_format;
00117     int d_old_prec;
00118     int d_new_prec;
00119 };
00120 
00121 class MatrixSetCoordinatesCommand: public QUndoCommand
00122 {
00123 public:
00124     MatrixSetCoordinatesCommand(Matrix *, double, double, double, double,
00125                     double, double, double, double, const QString &);
00126     virtual void redo();
00127     virtual void undo();
00128 
00129 private:
00130     Matrix *d_matrix;
00131     double d_old_xs, d_old_xe, d_old_ys, d_old_ye;
00132     double d_new_xs, d_new_xe, d_new_ys, d_new_ye;
00133 };
00134 
00135 class MatrixSetColorMapCommand: public QUndoCommand
00136 {
00137 public:
00138     MatrixSetColorMapCommand(Matrix *m, Matrix::ColorMapType d_map_type_before,
00139                     const LinearColorMap& d_map_before, Matrix::ColorMapType d_map_type_after,
00140                     const LinearColorMap& d_map_after, const QString& text);
00141     virtual void redo();
00142     virtual void undo();
00143 
00144 private:
00145     Matrix *d_matrix;
00146     Matrix::ColorMapType d_map_type_before, d_map_type_after;
00147     LinearColorMap d_map_before, d_map_after;
00148 };
00149 
00150 class MatrixDeleteRowsCommand: public QUndoCommand
00151 {
00152 public:
00153     MatrixDeleteRowsCommand(MatrixModel *model, int startRow, int count, double* data, const QString& text);
00154     ~MatrixDeleteRowsCommand(){free(d_data);};
00155     virtual void redo();
00156     virtual void undo();
00157 
00158 private:
00159     MatrixModel *d_model;
00160     int d_start_row, d_count;
00161     double* d_data;
00162 };
00163 
00164 class MatrixInsertRowCommand: public QUndoCommand
00165 {
00166 public:
00167     MatrixInsertRowCommand(MatrixModel *model, int startRow, const QString& text);
00168     virtual void redo();
00169     virtual void undo();
00170 
00171 private:
00172     MatrixModel *d_model;
00173     int d_start_row;
00174 };
00175 
00176 class MatrixDeleteColsCommand: public QUndoCommand
00177 {
00178 public:
00179     MatrixDeleteColsCommand(MatrixModel *model, int startCol, int count, double* data, const QString& text);
00180     ~MatrixDeleteColsCommand(){free(d_data);};
00181     virtual void redo();
00182     virtual void undo();
00183 
00184 private:
00185     MatrixModel *d_model;
00186     int d_start_col, d_count;
00187     double* d_data;
00188 };
00189 
00190 class MatrixInsertColCommand: public QUndoCommand
00191 {
00192 public:
00193     MatrixInsertColCommand(MatrixModel *model, int startCol, const QString& text);
00194     virtual void redo();
00195     virtual void undo();
00196 
00197 private:
00198     MatrixModel *d_model;
00199     int d_start_col;
00200 };
00201 
00202 class MatrixSetSizeCommand: public QUndoCommand
00203 {
00204 public:
00205     MatrixSetSizeCommand(MatrixModel *model, const QSize& oldSize, const QSize& newSize, double *data, const QString& text);
00206     ~MatrixSetSizeCommand(){if (d_backup) free(d_backup);};
00207     virtual void redo();
00208     virtual void undo();
00209 
00210 protected:
00211     MatrixModel *d_model;
00212     QSize d_old_size, d_new_size;
00213     double *d_backup;
00214 };
00215 
00216 class MatrixSmoothCommand: public QUndoCommand
00217 {
00218 public:
00219     MatrixSmoothCommand(MatrixModel *model, double *data, const QString& text);
00220     ~MatrixSmoothCommand(){if (d_backup) free(d_backup);};
00221     virtual void redo();
00222     virtual void undo();
00223 
00224 protected:
00225     MatrixModel *d_model;
00226     double *d_backup;
00227 };
00228 
00229 class MatrixResampleCommand: public MatrixSetSizeCommand
00230 {
00231 public:
00232     MatrixResampleCommand(MatrixModel *model, const QSize& oldSize, const QSize& newSize, int method, double *data, const QString& text);
00233     virtual void redo();
00234 
00235 private:
00236     int d_method;
00237 };
00238 
00239 class MatrixUndoCommand: public QUndoCommand
00240 {
00241 public:
00242     MatrixUndoCommand(MatrixModel *model, Matrix::Operation op, int startRow, int endRow, int startCol, int endCol,
00243                         double *data, const QString& text);
00244     ~MatrixUndoCommand(){free(d_data);};
00245     virtual void redo();
00246     virtual void undo();
00247 
00248 protected:
00249     MatrixModel *d_model;
00250     Matrix::Operation d_operation;
00251     int d_start_row, d_end_row, d_start_col, d_end_col;
00252     double* d_data;
00253 };
00254 
00255 class MatrixFftCommand: public MatrixUndoCommand
00256 {
00257 public:
00258     MatrixFftCommand(bool inverse, MatrixModel *model, int startRow, int endRow,
00259                     int startCol, int endCol, double *data, const QString& text);
00260     virtual void redo();
00261 
00262 private:
00263     bool d_inverse;
00264 };
00265 
00266 class MatrixSetImageCommand: public MatrixUndoCommand
00267 {
00268 public:
00269     MatrixSetImageCommand(MatrixModel *model, const QImage& image, Matrix::ViewType oldView,
00270                         int startRow, int endRow, int startCol, int endCol, double *data, const QString& text);
00271     virtual void redo();
00272     virtual void undo();
00273 
00274 private:
00275     QImage d_image;
00276     Matrix::ViewType d_old_view;
00277 };
00278 
00279 class MatrixImportAsciiCommand: public MatrixUndoCommand
00280 {
00281 public:
00282     MatrixImportAsciiCommand(const QString &fname, const QString &sep,
00283                         int ignoredLines, bool stripSpaces, bool simplifySpaces,
00284                         const QString& commentString, Matrix::ImportMode importAs, const QLocale& locale,
00285                         int endLineChar, int maxRows, MatrixModel *model, int startRow, int endRow,
00286                         int startCol, int endCol, double *data, const QString& text);
00287     virtual void redo();
00288 
00289 private:
00290     QString d_path, d_sep, d_comment;
00291     int d_ignore_lines, d_end_line, d_max_rows;
00292     bool d_strip_spaces, d_simplify_spaces;
00293     Matrix::ImportMode d_mode;
00294     QLocale d_locale;
00295 };
00296 
00297 class MatrixSymmetryOperation: public QUndoCommand
00298 {
00299 public:
00300     MatrixSymmetryOperation(MatrixModel *model, Matrix::Operation op, const QString& text);
00301     virtual void redo();
00302     virtual void undo();
00303 
00304 private:
00305     MatrixModel *d_model;
00306     Matrix::Operation d_operation;
00307 };
00308 
00309 class MatrixPasteCommand: public QUndoCommand
00310 {
00311 public:
00312     MatrixPasteCommand(MatrixModel *model, int startRow, int endRow, int startCol, int endCol,
00313                     double *clipboardData, int rows, int cols, double *backupData,
00314                     int oldRows, int oldCols, const QString& text);
00315     ~MatrixPasteCommand(){free(d_clipboard_data); free(d_backup_data);};
00316     virtual void redo();
00317     virtual void undo();
00318 
00319 private:
00320     MatrixModel *d_model;
00321     int d_start_row, d_end_row, d_start_col, d_end_col, d_rows, d_cols, d_old_rows, d_old_cols;
00322     double *d_clipboard_data, *d_backup_data;
00323 };
00324 #endif