Matrix.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : Matrix.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006 by Ion Vasilief,
00006                            Tilman Hoener zu Siederdissen
00007                            Knut Franke
00008     Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net,
00009                            knut.franke*gmx.de
00010     Description          : Matrix worksheet class
00011 
00012  ***************************************************************************/
00013 
00014 /***************************************************************************
00015  *                                                                         *
00016  *  This program is free software; you can redistribute it and/or modify   *
00017  *  it under the terms of the GNU General Public License as published by   *
00018  *  the Free Software Foundation; either version 2 of the License, or      *
00019  *  (at your option) any later version.                                    *
00020  *                                                                         *
00021  *  This program is distributed in the hope that it will be useful,        *
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00024  *  GNU General Public License for more details.                           *
00025  *                                                                         *
00026  *   You should have received a copy of the GNU General Public License     *
00027  *   along with this program; if not, write to the Free Software           *
00028  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00029  *   Boston, MA  02110-1301  USA                                           *
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 // (maximum) initial matrix size
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 importImage(const QImage& image);
00103     void exportRasterImage(const QString& fileName, int quality = 100);
00104     void exportSVG(const QString& fileName);
00105     void exportToFile(const QString& fileName);
00106     void exportVector(const QString& fileName, int res = 0, bool color = true);
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     //event handlers
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     void setColorMap(const QwtLinearColorMap& map);
00142     void setColorMap(const QStringList& lst);
00143 
00144     void setGrayScale();
00145     void setRainbowColorMap();
00147     double integrate();
00149     double determinant();
00151     void transpose();
00153     void invert();
00154 
00156     bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1, bool forceMuParser = true);
00158     bool muParserCalculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00159 
00160     bool exportASCII(const QString& fname, const QString& separator, bool exportSelection);
00161     void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool stripSpaces,
00162                     bool simplifySpaces, const QString& commentString, ImportMode importAs = Overwrite,
00163                     const QLocale& l = QLocale(), int endLineChar = 0, int maxRows = -1);
00164 
00165     virtual QString sizeToString();
00166 
00167 public slots:
00168     void exportPDF(const QString& fileName);
00170     void print();
00172     void print(const QString& fileName);
00173 
00175     int columnsWidth(){return d_column_width;};
00177     void setColumnsWidth(int width);
00178 
00180     void setDimensions(int rows, int cols);
00181 
00183     QString text(int row, int col);
00185     void setText(int row, int col, const QString & new_text );
00187     double cell(int row, int col);
00189     void setCell(int row, int col, double value );
00190 
00196     QChar textFormat(){return txt_format;};
00203     int precision(){return num_precision;};
00209     void setNumericPrecision(int prec){num_precision = prec;};
00210 
00219     void setTextFormat(const QChar &format, int precision);
00220     void setNumericFormat(const QChar & f, int prec);
00221 
00223     QString formula(){return formula_str;};
00225     void setFormula(const QString &s){formula_str = s;};
00226 
00228     void restore(const QStringList &l);
00231     void save(const QString &, const QString &, bool saveAsTemplate = false);
00232 
00233     // selection operations
00235     void cutSelection();
00237     void copySelection();
00239     void clearSelection();
00241     void pasteSelection();
00242 
00244     void insertRow();
00246     void deleteSelectedRows();
00248     int numSelectedRows();
00249 
00251     void insertColumn();
00253     void deleteSelectedColumns();
00255     int numSelectedColumns();
00256 
00258     double xStart(){return x_start;};
00260     double xEnd(){return x_end;};
00262     double yStart(){return y_start;};
00264     double yEnd(){return y_end;};
00265 
00267     double dx(){return fabs(x_end - x_start)/(double)(numCols() - 1);};
00269     double dy(){return fabs(y_end - y_start)/(double)(numRows() - 1);};
00270 
00272     QwtDoubleRect boundingRect();
00274     void setCoordinates(double xs, double xe, double ys, double ye);
00275 
00277     void range(double *min, double *max);
00278 
00280     void goToRow(int row);
00282     void goToColumn(int col);
00283 
00285     static double** allocateMatrixData(int rows, int columns);
00287     static void freeMatrixData(double **data, int rows);
00288 
00289     int verticalHeaderWidth(){return d_table_view->verticalHeader()->width();}
00290 
00291     void copy(Matrix *m);
00293     double *initWorkspace(int size);
00294     void freeWorkspace(){free(d_workspace); d_workspace = NULL;};
00295 
00296     bool canCalculate(bool useMuParser = true);
00297 
00298 private:
00300     void initTable(int rows, int cols);
00301     void initImage(const QImage& image);
00302     void initImageView();
00303     void initTableView();
00304     void initGlobals();
00305     bool ignoreUndo();
00306 
00307     QStackedWidget *d_stack;
00308     MatrixModel *d_matrix_model;
00310     QTableView *d_table_view;
00312     QLabel *imageLabel;
00314     QString formula_str;
00316     QChar txt_format;
00318     int num_precision;
00319     double x_start, 
00320     x_end,  
00321     y_start,  
00322     y_end;  
00323 
00325     ViewType d_view_type;
00327     HeaderViewType d_header_view_type;
00329     QwtLinearColorMap d_color_map;
00331     ColorMapType d_color_map_type;
00333     int d_column_width;
00334     QShortcut *d_select_all_shortcut;
00336     QUndoStack *d_undo_stack;
00338     double *d_workspace;
00339 };
00340 
00341 #endif

Generated on Tue Nov 3 10:48:50 2009 for QtiPlot by  doxygen 1.6.1