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 #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