QtiPlot  0.9.8.2
MatrixModel.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : MatrixModel.h
3  Project : QtiPlot
4 --------------------------------------------------------------------
5  Copyright : (C) 2007 by Ion Vasilief
6  Email (use @ for *) : ion_vasilief*yahoo.fr
7  Description : QtiPlot's matrix model
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 
30 #ifndef MATRIXMODEL_H
31 #define MATRIXMODEL_H
32 
33 #include <QAbstractTableModel>
34 #include <QVector>
35 #include <QLocale>
36 #include <QSize>
37 
38 #include <gsl/gsl_matrix.h>
39 #include <gsl/gsl_permutation.h>
40 
41 class Matrix;
42 
43 class MatrixModel : public QAbstractTableModel
44 {
45  Q_OBJECT
46 
47 public:
48  MatrixModel(int rows = 32, int cols = 32, QObject *parent = 0);
49  MatrixModel(const QImage& image, QObject *parent);
50  ~MatrixModel(){free(d_data);};
51 
52  Matrix *matrix(){return d_matrix;};
53 
54  Qt::ItemFlags flags( const QModelIndex & index ) const;
55 
56  bool canResize(int rows, int cols);
57  void setDimensions(int rows, int cols);
58  void resample(int rows, int cols, int method = 0);
59 
60  int rowCount(const QModelIndex &parent = QModelIndex()) const;
61  void setRowCount(int rows);
62 
63  int columnCount(const QModelIndex &parent = QModelIndex()) const;
64  void setColumnCount(int cols);
65 
66  bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
67  bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex());
68 
69  bool removeColumns(int column, int count, const QModelIndex & parent = QModelIndex());
70  bool insertColumns(int column, int count, const QModelIndex & parent = QModelIndex());
71 
72  double x(int col) const;
73  double y(int row) const;
74 
75  double cell(int row, int col);
76  void setCell(int row, int col, double val);
77 
78  QString text(int row, int col);
79  void setText(int row, int col, const QString&);
80 
81  QImage renderImage();
82 
83  double data(int row, int col) const;
84  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
85  bool setData(const QModelIndex & index, const QVariant & value, int role);
86 
87  double* dataVector(){return d_data;};
88  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
89 
90  void setImage(const QImage& image);
91 
92  bool importASCII(const QString &fname, const QString &sep, int ignoredLines, bool stripSpaces,
93  bool simplifySpaces, const QString& commentString, int importAs,
94  const QLocale& locale, int endLineChar = 0, int maxRows = -1);
95 
96  void setLocale(const QLocale& locale){d_locale = locale;};
97  void setNumericFormat(char f, int prec);
98 
99  bool initWorkspace();
100  void invert();
101  void transpose();
102  void flipVertically();
103  void flipHorizontally();
104  void rotate90(bool clockwise);
105  void fft(bool inverse);
106  void clear(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
107  bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
108  bool muParserCalculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
109  double* dataCopy(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
110  void pasteData(double *clipboardBuffer, int topRow, int leftCol, int rows, int cols);
111 
112 private:
113  void init();
115  double *d_data;
122  QLocale d_locale;
123 
127  gsl_permutation *d_inv_perm;
129 };
130 
131 #endif
void clear(int startRow=0, int endRow=-1, int startCol=0, int endCol=-1)
Definition: MatrixModel.cpp:756
Definition: MatrixModel.h:43
Matrix * matrix()
Definition: MatrixModel.h:52
void flipVertically()
Definition: MatrixModel.cpp:628
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: MatrixModel.cpp:425
void setLocale(const QLocale &locale)
Definition: MatrixModel.h:96
MatrixModel(int rows=32, int cols=32, QObject *parent=0)
Definition: MatrixModel.cpp:51
gsl_matrix * d_direct_matrix
Pointers to GSL matrices used during inversion operations.
Definition: MatrixModel.h:125
void fft(bool inverse)
Definition: MatrixModel.cpp:941
~MatrixModel()
Definition: MatrixModel.h:50
void rotate90(bool clockwise)
Definition: MatrixModel.cpp:670
char d_txt_format
Format code for displaying numbers.
Definition: MatrixModel.h:118
void flipHorizontally()
Definition: MatrixModel.cpp:649
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: MatrixModel.cpp:123
void init()
Definition: MatrixModel.cpp:81
void transpose()
Definition: MatrixModel.cpp:605
void setCell(int row, int col, double val)
Definition: MatrixModel.cpp:183
double cell(int row, int col)
Definition: MatrixModel.cpp:174
bool initWorkspace()
Definition: MatrixModel.cpp:705
double data(int row, int col) const
Definition: MatrixModel.cpp:222
bool importASCII(const QString &fname, const QString &sep, int ignoredLines, bool stripSpaces, bool simplifySpaces, const QString &commentString, int importAs, const QLocale &locale, int endLineChar=0, int maxRows=-1)
Definition: MatrixModel.cpp:486
gsl_permutation * d_inv_perm
Pointer to a GSL permutation used during inversion operations.
Definition: MatrixModel.h:127
int d_cols
Definition: MatrixModel.h:114
bool insertColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Definition: MatrixModel.cpp:399
double * d_data
Definition: MatrixModel.h:115
QLocale d_locale
Locale used to display data.
Definition: MatrixModel.h:122
bool calculate(int startRow=0, int endRow=-1, int startCol=0, int endCol=-1)
Definition: MatrixModel.cpp:880
void pasteData(double *clipboardBuffer, int topRow, int leftCol, int rows, int cols)
Definition: MatrixModel.cpp:1004
bool setData(const QModelIndex &index, const QVariant &value, int role)
Definition: MatrixModel.cpp:316
QSize d_data_block_size
Definition: MatrixModel.h:128
Matrix * d_matrix
Definition: MatrixModel.h:116
int d_num_precision
Number of significant digits.
Definition: MatrixModel.h:120
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: MatrixModel.cpp:110
Matrix worksheet class.
Definition: Matrix.h:57
void setText(int row, int col, const QString &)
Definition: MatrixModel.cpp:206
QString text(int row, int col)
Definition: MatrixModel.cpp:192
double x(int col) const
Definition: MatrixModel.cpp:231
bool canResize(int rows, int cols)
Definition: MatrixModel.cpp:354
QImage renderImage()
Definition: MatrixModel.cpp:464
bool muParserCalculate(int startRow=0, int endRow=-1, int startCol=0, int endCol=-1)
Definition: MatrixModel.cpp:798
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: MatrixModel.cpp:118
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: MatrixModel.cpp:446
void setImage(const QImage &image)
Definition: MatrixModel.cpp:96
gsl_matrix * d_inv_matrix
Definition: MatrixModel.h:125
void setRowCount(int rows)
Definition: MatrixModel.cpp:128
void invert()
Definition: MatrixModel.cpp:724
double * dataCopy(int startRow=0, int endRow=-1, int startCol=0, int endCol=-1)
Definition: MatrixModel.cpp:773
void setNumericFormat(char f, int prec)
Definition: MatrixModel.cpp:596
bool removeColumns(int column, int count, const QModelIndex &parent=QModelIndex())
Definition: MatrixModel.cpp:380
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: MatrixModel.cpp:261
int d_rows
Definition: MatrixModel.h:114
double y(int row) const
Definition: MatrixModel.cpp:246
void setColumnCount(int cols)
Definition: MatrixModel.cpp:143
void setDimensions(int rows, int cols)
Definition: MatrixModel.cpp:158
double * dataVector()
Definition: MatrixModel.h:87
void resample(int rows, int cols, int method=0)
Definition: MatrixModel.cpp:1024