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