QtiPlot 0.9.7.3

MatrixModel.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : MatrixModel.h
00003     Project              : QtiPlot
00004 --------------------------------------------------------------------
00005     Copyright            : (C) 2007 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : QtiPlot's matrix model
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 
00030 #ifndef MATRIXMODEL_H
00031 #define MATRIXMODEL_H
00032 
00033 #include <QAbstractTableModel>
00034 #include <QVector>
00035 #include <QLocale>
00036 #include <QSize>
00037 
00038 #include <gsl/gsl_matrix.h>
00039 #include <gsl/gsl_permutation.h>
00040 
00041 class Matrix;
00042 
00043 class MatrixModel : public QAbstractTableModel
00044 {
00045     Q_OBJECT
00046 
00047 public:
00048     MatrixModel(int rows = 32, int cols = 32, QObject *parent = 0);
00049     MatrixModel(const QImage& image, QObject *parent);
00050     ~MatrixModel(){free(d_data);};
00051 
00052     Matrix *matrix(){return d_matrix;};
00053 
00054     Qt::ItemFlags flags( const QModelIndex & index ) const;
00055 
00056     bool canResize(int rows, int cols);
00057     void setDimensions(int rows, int cols);
00058 
00059     int rowCount(const QModelIndex &parent = QModelIndex()) const;
00060     void setRowCount(int rows);
00061 
00062     int columnCount(const QModelIndex &parent = QModelIndex()) const;
00063     void setColumnCount(int cols);
00064 
00065     bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
00066     bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex());
00067 
00068     bool removeColumns(int column, int count, const QModelIndex & parent = QModelIndex());
00069     bool insertColumns(int column, int count, const QModelIndex & parent = QModelIndex());
00070 
00071     double x(int col) const;
00072     double y(int row) const;
00073 
00074     double cell(int row, int col);
00075     void setCell(int row, int col, double val);
00076 
00077     QString text(int row, int col);
00078     void setText(int row, int col, const QString&);
00079 
00080     QImage renderImage();
00081 
00082     double data(int row, int col) const;
00083     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00084     bool setData(const QModelIndex & index, const QVariant & value, int role);
00085 
00086     double* dataVector(){return d_data;};
00087     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00088 
00089     void setImage(const QImage& image);
00090 
00091     bool importASCII(const QString &fname, const QString &sep, int ignoredLines, bool stripSpaces,
00092                     bool simplifySpaces, const QString& commentString, int importAs,
00093                     const QLocale& locale, int endLineChar = 0, int maxRows = -1);
00094 
00095     void setLocale(const QLocale& locale){d_locale = locale;};
00096     void setNumericFormat(char f, int prec);
00097 
00098     bool initWorkspace();
00099     void invert();
00100     void transpose();
00101     void flipVertically();
00102     void flipHorizontally();
00103     void rotate90(bool clockwise);
00104     void fft(bool inverse);
00105     void clear(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00106     bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00107     bool muParserCalculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00108     double* dataCopy(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00109     void pasteData(double *clipboardBuffer, int topRow, int leftCol, int rows, int cols);
00110 
00111 private:
00112     void init();
00113     int d_rows, d_cols;
00114     double *d_data;
00115     Matrix *d_matrix;
00117     char d_txt_format;
00119     int d_num_precision;
00121     QLocale d_locale;
00122 
00124     gsl_matrix *d_direct_matrix, *d_inv_matrix;
00126     gsl_permutation *d_inv_perm;
00127     QSize d_data_block_size;
00128 };
00129 
00130 #endif