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 "MyWidget.h"
00039 #include "ScriptingEnv.h"
00040 #include "Script.h"
00041 #include <qwt_double_rect.h>
00042 #include <qwt_color_map.h>
00043
00044 #include <math.h>
00045
00046
00047 #define _Matrix_initial_rows_ 10
00048 #define _Matrix_initial_columns_ 3
00049
00050 class MatrixModel;
00051 class QLabel;
00052 class QStackedWidget;
00053 class QShortcut;
00054
00056 class Matrix: public MyWidget, public scripted
00057 {
00058 Q_OBJECT
00059
00060 public:
00061
00074 Matrix(ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent=0, const QString& name = QString(), Qt::WFlags f=0);
00075 Matrix(ScriptingEnv *env, const QImage& image, const QString& label, QWidget* parent=0, const QString& name = QString(), Qt::WFlags f=0);
00076
00077 enum HeaderViewType{ColumnRow, XY};
00078 enum ViewType{TableView, ImageView};
00079 enum ColorMapType{GrayScale, Rainbow, Custom};
00080
00081 void setViewType(ViewType);
00082 ViewType viewType(){return d_view_type;};
00083
00084 HeaderViewType headerViewType(){return d_header_view_type;};
00085 void setHeaderViewType(HeaderViewType type);
00086
00087 QImage image();
00088 void setImage(const QImage& image);
00089 void importImage(const QString& fn);
00090 void exportRasterImage(const QString& fileName, int quality = 100);
00091 void exportSVG(const QString& fileName);
00092 void exportToFile(const QString& fileName);
00093 void exportVector(const QString& fileName, int res = 0, bool color = true, bool keepAspect = true, QPrinter::PageSize pageSize = QPrinter::Custom);
00094
00095 MatrixModel * matrixModel(){return d_matrix_model;};
00096 QItemSelectionModel * selectionModel(){return d_table_view->selectionModel();};
00097
00099 int numRows();
00100 void setNumRows(int rows);
00101
00103 int numCols();
00104 void setNumCols(int cols);
00105
00106
00113 bool eventFilter(QObject *object, QEvent *e);
00115 void contextMenuEvent(QContextMenuEvent *e);
00117
00120 void customEvent(QEvent *e);
00121
00122 void resetView();
00123 void moveCell(const QModelIndex& index);
00124
00125 void flipVertically();
00126 void flipHorizontally();
00127 void rotate90(bool clockwise = true);
00128
00129 #ifdef QTIPLOT_PRO
00130 void fft(bool inverse = false);
00131 #endif
00132
00133 ColorMapType colorMapType(){return d_color_map_type;};
00134 void setColorMapType(ColorMapType mapType);
00135
00136 QwtLinearColorMap colorMap(){return d_color_map;};
00137 void setColorMap(const QwtLinearColorMap& map);
00139 void setColorMap(const QStringList& lst);
00140
00141 void setGrayScale();
00142 void setRainbowColorMap();
00143
00144 public slots:
00145 void exportPDF(const QString& fileName);
00147 void print();
00149 void print(const QString& fileName);
00150
00152 int columnsWidth(){return d_column_width;};
00154 void setColumnsWidth(int width);
00155
00157 void setDimensions(int rows, int cols);
00159 void transpose();
00161 void invert();
00163 double determinant();
00164
00166 bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00167
00169 QString text(int row, int col);
00171 void setText(int row, int col, const QString & new_text );
00173 double cell(int row, int col);
00175 void setCell(int row, int col, double value );
00176
00182 QChar textFormat(){return txt_format;};
00189 int precision(){return num_precision;};
00195 void setNumericPrecision(int prec){num_precision = prec;};
00196
00205 void setTextFormat(const QChar &format, int precision);
00206 void setNumericFormat(const QChar & f, int prec);
00207
00209 QString formula(){return formula_str;};
00211 void setFormula(const QString &s){formula_str = s;};
00212
00214 void restore(const QStringList &l);
00216 QString saveAsTemplate(const QString &info);
00217
00219 QString saveToString(const QString &info, bool saveAsTemplate = false);
00220
00221
00223 void cutSelection();
00225 void copySelection();
00227 void clearSelection();
00229 void pasteSelection();
00230
00232 void insertRow();
00234 void deleteSelectedRows();
00236 int numSelectedRows();
00237
00239 void insertColumn();
00241 void deleteSelectedColumns();
00243 int numSelectedColumns();
00244
00246 double xStart(){return x_start;};
00248 double xEnd(){return x_end;};
00250 double yStart(){return y_start;};
00252 double yEnd(){return y_end;};
00253
00255 double dx(){return fabs(x_end - x_start)/(double)(numCols() - 1);};
00257 double dy(){return fabs(y_end - y_start)/(double)(numRows() - 1);};
00258
00260 QwtDoubleRect boundingRect();
00262 void setCoordinates(double xs, double xe, double ys, double ye);
00263
00265 void range(double *min, double *max);
00266
00268 void goToRow(int row);
00269
00271 static double** allocateMatrixData(int rows, int columns);
00273 static void freeMatrixData(double **data, int rows);
00274
00275 int verticalHeaderWidth(){return d_table_view->verticalHeader()->width();}
00276
00277 void copy(Matrix *m);
00278
00279 signals:
00281 void showContextMenu();
00282
00283 private:
00285 void initTable(int rows, int cols);
00286 void initImage(const QImage& image);
00287 void initImageView();
00288 void initTableView();
00289 void initGlobals();
00290
00291 QStackedWidget *d_stack;
00292 MatrixModel *d_matrix_model;
00294 QTableView *d_table_view;
00296 QLabel *imageLabel;
00298 QString formula_str;
00300 QChar txt_format;
00302 int num_precision;
00303 double x_start,
00304 x_end,
00305 y_start,
00306 y_end;
00307
00309 ViewType d_view_type;
00311 HeaderViewType d_header_view_type;
00312
00313 QwtLinearColorMap d_color_map;
00314 ColorMapType d_color_map_type;
00315
00317 int d_column_width;
00318
00319 QShortcut *d_select_all_shortcut;
00320 };
00321
00322 #endif