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 #ifndef MATRIX_H
00030 #define MATRIX_H
00031
00032 #include <QHeaderView>
00033 #include <QTableView>
00034 #include <QPrinter>
00035 #include <QMessageBox>
00036
00037 #include "MatrixModel.h"
00038 #include <MdiSubWindow.h>
00039 #include <ScriptingEnv.h>
00040 #include <Script.h>
00041
00042 #include <qwt_double_rect.h>
00043 #include <qwt_color_map.h>
00044
00045 #include <math.h>
00046
00047
00048 #define _Matrix_initial_rows_ 10
00049 #define _Matrix_initial_columns_ 3
00050
00051 class QLabel;
00052 class QStackedWidget;
00053 class QShortcut;
00054 class QUndoStack;
00055
00057 class Matrix: public MdiSubWindow, public scripted
00058 {
00059 Q_OBJECT
00060
00061 public:
00062
00075 Matrix(ScriptingEnv *env, int r, int c, const QString& label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
00076 Matrix(ScriptingEnv *env, const QImage& image, const QString& label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
00077 ~Matrix();
00078
00079 enum Operation{Transpose, Invert, FlipHorizontally, FlipVertically, RotateClockwise,
00080 RotateCounterClockwise, FFT, Clear, Calculate, MuParserCalculate, SetImage, ImportAscii};
00081 enum HeaderViewType{ColumnRow, XY};
00082 enum ViewType{TableView, ImageView};
00083 enum ColorMapType{Default, GrayScale, Rainbow, Custom};
00084 enum ImportMode {
00085 NewColumns,
00086 NewRows,
00087 Overwrite
00088 };
00089
00090 void setViewType(ViewType, bool renderImage = true);
00091 ViewType viewType(){return d_view_type;};
00092
00093 HeaderViewType headerViewType(){return d_header_view_type;};
00094 void setHeaderViewType(HeaderViewType type);
00095
00096 QImage image();
00097 void displayImage(const QImage& image);
00098 void importImage(const QString& fn);
00099 void importImage(const QImage& image);
00100 void exportRasterImage(const QString& fileName, int quality = 100, int dpi = 0);
00101 void exportSVG(const QString& fileName);
00102 void exportToFile(const QString& fileName);
00103 void exportVector(const QString& fileName, int res = 0, bool color = true);
00104 #ifdef EMF_OUTPUT
00105 void exportEMF(const QString& fileName);
00106 #endif
00107
00108 MatrixModel * matrixModel(){return d_matrix_model;};
00109 QUndoStack *undoStack(){return d_undo_stack;};
00110
00111 QItemSelectionModel * selectionModel(){return d_table_view->selectionModel();};
00112
00114 int numRows(){return d_matrix_model->rowCount();};
00115 void setNumRows(int rows){d_matrix_model->setRowCount(rows);};
00116
00118 int numCols(){return d_matrix_model->columnCount();};
00119 void setNumCols(int cols){d_matrix_model->setColumnCount(cols);};
00120
00121
00123
00126 void customEvent(QEvent *e);
00127
00128 void resetView();
00129 void moveCell(const QModelIndex& index);
00130
00131 void flipVertically();
00132 void flipHorizontally();
00133 void rotate90(bool clockwise = true);
00134 void fft(bool inverse = false);
00135
00136 ColorMapType colorMapType(){return d_color_map_type;};
00137 void setColorMapType(ColorMapType mapType);
00138
00139 QwtLinearColorMap colorMap(){return d_color_map;};
00140 QwtLinearColorMap *colorMapPointer(){return &d_color_map;};
00141 void setColorMap(const QwtLinearColorMap& map);
00143 void setColorMap(const QStringList& lst);
00145 void setDefaultColorMap();
00146 void setGrayScale();
00147 void setRainbowColorMap();
00149 double integrate();
00151 double determinant();
00153 void transpose();
00155 void invert();
00156
00158 bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1, bool forceMuParser = false);
00160 bool muParserCalculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00161
00162 bool exportODF(const QString& fname, bool exportSelection);
00163 bool exportASCII(const QString& fname, const QString& separator, bool exportSelection);
00164 void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool stripSpaces,
00165 bool simplifySpaces, const QString& commentString, ImportMode importAs = Overwrite,
00166 const QLocale& l = QLocale(), int endLineChar = 0, int maxRows = -1);
00167
00168 virtual QString sizeToString();
00169
00170 public slots:
00171 void exportPDF(const QString& fileName);
00173 void print();
00174 void print(QPrinter *);
00176 void print(const QString& fileName);
00177
00179 int columnsWidth(){return d_column_width;};
00181 void setColumnsWidth(int width);
00182
00184 void setDimensions(int rows, int cols);
00185
00187 QString text(int row, int col);
00189 void setText(int row, int col, const QString & new_text );
00191 double cell(int row, int col);
00193 void setCell(int row, int col, double value );
00194
00200 QChar textFormat(){return txt_format;};
00207 int precision(){return num_precision;};
00213 void setNumericPrecision(int prec);
00214
00223 void setTextFormat(const QChar &format, int precision);
00224 void setNumericFormat(const QChar & f, int prec);
00225
00227 QString formula(){return formula_str;};
00229 void setFormula(const QString &s){formula_str = s;};
00230
00232 void restore(const QStringList &l);
00235 void save(const QString &, const QString &, bool saveAsTemplate = false);
00236
00237
00239 void cutSelection();
00241 void copySelection();
00243 void clearSelection();
00245 void pasteSelection();
00246
00248 void insertRow();
00250 void deleteSelectedRows();
00252 int numSelectedRows();
00253
00255 void insertColumn();
00257 void deleteSelectedColumns();
00259 int numSelectedColumns();
00260
00262 double xStart(){return x_start;};
00264 double xEnd(){return x_end;};
00266 double yStart(){return y_start;};
00268 double yEnd(){return y_end;};
00269
00271 double dx(){return fabs(x_end - x_start)/(double)(numCols() - 1);};
00273 double dy(){return fabs(y_end - y_start)/(double)(numRows() - 1);};
00274
00276 QwtDoubleRect boundingRect();
00278 void setCoordinates(double xs, double xe, double ys, double ye);
00279
00281 void range(double *min, double *max);
00282
00284 void goToRow(int row);
00286 void goToColumn(int col);
00287
00289 static double** allocateMatrixData(int rows, int columns);
00291 static void freeMatrixData(double **data, int rows);
00292
00293 int verticalHeaderWidth(){return d_table_view->verticalHeader()->width();}
00294
00295 void copy(Matrix *m);
00297 double *initWorkspace(int size);
00298 void freeWorkspace(){free(d_workspace); d_workspace = NULL;};
00299
00300 bool canCalculate(bool useMuParser = true);
00301 void notifyModifiedData(){emit modifiedData(this);};
00302
00303 signals:
00304 void modifiedData(Matrix *);
00305
00306 private:
00307 bool eventFilter(QObject *, QEvent *);
00308
00310 void initTable(int rows, int cols);
00311 void initImage(const QImage& image);
00312 void initImageView();
00313 void initTableView();
00314 void initGlobals();
00315 bool ignoreUndo();
00316
00317 QStackedWidget *d_stack;
00318 MatrixModel *d_matrix_model;
00320 QTableView *d_table_view;
00322 QLabel *imageLabel;
00324 QString formula_str;
00326 QChar txt_format;
00328 int num_precision;
00329 double x_start,
00330 x_end,
00331 y_start,
00332 y_end;
00333
00335 ViewType d_view_type;
00337 HeaderViewType d_header_view_type;
00339 QwtLinearColorMap d_color_map;
00341 ColorMapType d_color_map_type;
00343 int d_column_width;
00344 QShortcut *d_select_all_shortcut;
00346 QUndoStack *d_undo_stack;
00348 double *d_workspace;
00349 };
00350
00351 #endif