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     QString saveToString();
00081     QImage renderImage();
00082 
00083     double data(int row, int col) const;
00084     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00085     bool setData(const QModelIndex & index, const QVariant & value, int role);
00086 
00087     double* dataVector(){return d_data;};
00088     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00089 
00090     void setImage(const QImage& image);
00091 
00092     bool importASCII(const QString &fname, const QString &sep, int ignoredLines, bool stripSpaces,
00093                     bool simplifySpaces, const QString& commentString, int importAs,
00094                     const QLocale& locale, int endLineChar = 0, int maxRows = -1);
00095 
00096     void setLocale(const QLocale& locale){d_locale = locale;};
00097     void setNumericFormat(char f, int prec);
00098 
00099     bool initWorkspace();
00100     void invert();
00101     void transpose();
00102     void flipVertically();
00103     void flipHorizontally();
00104     void rotate90(bool clockwise);
00105     void fft(bool inverse);
00106     void clear(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00107     bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00108     bool muParserCalculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00109     double* dataCopy(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00110     void pasteData(double *clipboardBuffer, int topRow, int leftCol, int rows, int cols);
00111 
00112 private:
00113     void init();
00114     int d_rows, d_cols;
00115     double *d_data;
00116     Matrix *d_matrix;
00118     char d_txt_format;
00120     int d_num_precision;
00122     QLocale d_locale;
00123 
00125     gsl_matrix *d_direct_matrix, *d_inv_matrix;
00127     gsl_permutation *d_inv_perm;
00128     QSize d_data_block_size;
00129 };
00130 
00131 #endif

Generated on Sun Jun 15 21:32:16 2008 for QtiPlot by  doxygen 1.5.6