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