00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef MATRIX_H
00033 #define MATRIX_H
00034
00035 #include <QHeaderView>
00036 #include <QTableView>
00037 #include <QPrinter>
00038 #include <QMessageBox>
00039
00040 #include "MatrixModel.h"
00041 #include "../MdiSubWindow.h"
00042 #include "../ScriptingEnv.h"
00043 #include "../Script.h"
00044
00045 #include <qwt_double_rect.h>
00046 #include <qwt_color_map.h>
00047
00048 #include <math.h>
00049
00050
00051 #define _Matrix_initial_rows_ 10
00052 #define _Matrix_initial_columns_ 3
00053
00054 class QLabel;
00055 class QStackedWidget;
00056 class QShortcut;
00057 class QUndoStack;
00058
00060 class Matrix: public MdiSubWindow, public scripted
00061 {
00062 Q_OBJECT
00063
00064 public:
00065
00078 Matrix(ScriptingEnv *env, int r, int c, const QString& label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
00079 Matrix(ScriptingEnv *env, const QImage& image, const QString& label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
00080 ~Matrix();
00081
00082 enum Operation{Transpose, Invert, FlipHorizontally, FlipVertically, RotateClockwise,
00083 RotateCounterClockwise, FFT, Clear, Calculate, MuParserCalculate, SetImage, ImportAscii};
00084 enum HeaderViewType{ColumnRow, XY};
00085 enum ViewType{TableView, ImageView};
00086 enum ColorMapType{GrayScale, Rainbow, Custom};
00087 enum ImportMode {
00088 NewColumns,
00089 NewRows,
00090 Overwrite
00091 };
00092
00093 void setViewType(ViewType, bool renderImage = true);
00094 ViewType viewType(){return d_view_type;};
00095
00096 HeaderViewType headerViewType(){return d_header_view_type;};
00097 void setHeaderViewType(HeaderViewType type);
00098
00099 QImage image();
00100 void displayImage(const QImage& image);
00101 void importImage(const QString& fn);
00102 void exportRasterImage(const QString& fileName, int quality = 100);
00103 void exportSVG(const QString& fileName);
00104 void exportToFile(const QString& fileName);
00105 void exportVector(const QString& fileName, int res = 0, bool color = true, bool keepAspect = true, QPrinter::PageSize pageSize = QPrinter::Custom);
00106
00107 MatrixModel * matrixModel(){return d_matrix_model;};
00108 QUndoStack *undoStack(){return d_undo_stack;};
00109
00110 QItemSelectionModel * selectionModel(){return d_table_view->selectionModel();};
00111
00113 int numRows(){return d_matrix_model->rowCount();};
00114 void setNumRows(int rows){d_matrix_model->setRowCount(rows);};
00115
00117 int numCols(){return d_matrix_model->columnCount();};
00118 void setNumCols(int cols){d_matrix_model->setColumnCount(cols);};
00119
00120
00122
00125 void customEvent(QEvent *e);
00126
00127 void resetView();
00128 void moveCell(const QModelIndex& index);
00129
00130 void flipVertically();
00131 void flipHorizontally();
00132 void rotate90(bool clockwise = true);
00133 void fft(bool inverse = false);
00134
00135 ColorMapType colorMapType(){return d_color_map_type;};
00136 void setColorMapType(ColorMapType mapType);
00137
00138 QwtLinearColorMap colorMap(){return d_color_map;};
00139 void setColorMap(const QwtLinearColorMap& map);
00141 void setColorMap(const QStringList& lst);
00142
00143 void setGrayScale();
00144 void setRainbowColorMap();
00146 double integrate();
00148 double determinant();
00150 void transpose();
00152 void invert();
00153
00155 bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1, bool forceMuParser = true);
00157 bool muParserCalculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00158
00159 bool exportASCII(const QString& fname, const QString& separator, bool exportSelection);
00160 void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool stripSpaces,
00161 bool simplifySpaces, const QString& commentString, ImportMode importAs = Overwrite,
00162 const QLocale& l = QLocale(), int endLineChar = 0, int maxRows = -1);
00163
00164 public slots:
00165 void exportPDF(const QString& fileName);
00167 void print();
00169 void print(const QString& fileName);
00170
00172 int columnsWidth(){return d_column_width;};
00174 void setColumnsWidth(int width);
00175
00177 void setDimensions(int rows, int cols);
00178
00180 QString text(int row, int col);
00182 void setText(int row, int col, const QString & new_text );
00184 double cell(int row, int col);
00186 void setCell(int row, int col, double value );
00187
00193 QChar textFormat(){return txt_format;};
00200 int precision(){return num_precision;};
00206 void setNumericPrecision(int prec){num_precision = prec;};
00207
00216 void setTextFormat(const QChar &format, int precision);
00217 void setNumericFormat(const QChar & f, int prec);
00218
00220 QString formula(){return formula_str;};
00222 void setFormula(const QString &s){formula_str = s;};
00223
00225 void restore(const QStringList &l);
00227 QString saveAsTemplate(const QString &info);
00228
00230 QString saveToString(const QString &info, bool saveAsTemplate = false);
00231
00232
00234 void cutSelection();
00236 void copySelection();
00238 void clearSelection();
00240 void pasteSelection();
00241
00243 void insertRow();
00245 void deleteSelectedRows();
00247 int numSelectedRows();
00248
00250 void insertColumn();
00252 void deleteSelectedColumns();
00254 int numSelectedColumns();
00255
00257 double xStart(){return x_start;};
00259 double xEnd(){return x_end;};
00261 double yStart(){return y_start;};
00263 double yEnd(){return y_end;};
00264
00266 double dx(){return fabs(x_end - x_start)/(double)(numCols() - 1);};
00268 double dy(){return fabs(y_end - y_start)/(double)(numRows() - 1);};
00269
00271 QwtDoubleRect boundingRect();
00273 void setCoordinates(double xs, double xe, double ys, double ye);
00274
00276 void range(double *min, double *max);
00277
00279 void goToRow(int row);
00281 void goToColumn(int col);
00282
00284 static double** allocateMatrixData(int rows, int columns);
00286 static void freeMatrixData(double **data, int rows);
00287
00288 int verticalHeaderWidth(){return d_table_view->verticalHeader()->width();}
00289
00290 void copy(Matrix *m);
00292 double *initWorkspace(int size);
00293 void freeWorkspace(){free(d_workspace); d_workspace = NULL;};
00294
00295 bool canCalculate(bool useMuParser = true);
00296
00297 private:
00299 void initTable(int rows, int cols);
00300 void initImage(const QImage& image);
00301 void initImageView();
00302 void initTableView();
00303 void initGlobals();
00304 bool ignoreUndo();
00305
00306 QStackedWidget *d_stack;
00307 MatrixModel *d_matrix_model;
00309 QTableView *d_table_view;
00311 QLabel *imageLabel;
00313 QString formula_str;
00315 QChar txt_format;
00317 int num_precision;
00318 double x_start,
00319 x_end,
00320 y_start,
00321 y_end;
00322
00324 ViewType d_view_type;
00326 HeaderViewType d_header_view_type;
00328 QwtLinearColorMap d_color_map;
00330 ColorMapType d_color_map_type;
00332 int d_column_width;
00333 QShortcut *d_select_all_shortcut;
00335 QUndoStack *d_undo_stack;
00337 double *d_workspace;
00338 };
00339
00340 #endif