SciDAVis  1.D4
Matrix.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : Matrix.h
3  Project : SciDAVis
4  Description : Matrix worksheet class
5  --------------------------------------------------------------------
6  Copyright : (C) 2006-2009 Tilman Benkert (thzs*gmx.net)
7  Copyright : (C) 2006-2009 Knut Franke (knut.franke*gmx.de)
8  Copyright : (C) 2006-2007 Ion Vasilief (ion_vasilief*yahoo.fr)
9  (replace * with @ in the email addresses)
10 
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  * This program is distributed in the hope that it will be useful, *
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
23  * GNU General Public License for more details. *
24  * *
25  * You should have received a copy of the GNU General Public License *
26  * along with this program; if not, write to the Free Software *
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
28  * Boston, MA 02110-1301 USA *
29  * *
30  ***************************************************************************/
31 #ifndef MATRIX_H
32 #define MATRIX_H
33 
34 #include <QTableWidget>
35 #include <QContextMenuEvent>
36 #include <QEvent>
37 #include <QHeaderView>
38 #include <QDateTime>
39 #include "MyWidget.h"
40 #include "ScriptingEnv.h"
41 #include "Script.h"
42 #include <qwt_double_rect.h>
45 
46 // (maximum) initial matrix size
47 #define _Matrix_initial_rows_ 10
48 #define _Matrix_initial_columns_ 3
49 
51 class Matrix: public MatrixView, public scripted
52 {
53  Q_OBJECT
54 
55 public:
57 
59  virtual QString name() { return d_future_matrix->name();}
61  virtual void setName(const QString& s) { d_future_matrix->setName(s); }
63  virtual QString windowLabel() { return d_future_matrix->comment(); }
65  virtual void setWindowLabel(const QString& s) { d_future_matrix->setComment(s); updateCaption(); }
68  {
69  caption_policy = policy; updateCaption();
70  switch (policy)
71  {
72  case Name:
74  break;
75  case Label:
77  break;
78  case Both:
79  d_future_matrix->setCaptionSpec("%n%C{ - }%c");
80  break;
81  }
82  }
84  virtual void setBirthDate(const QString& s)
85  {
86  birthdate = s;
88  }
89 
102  Matrix(ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
103  ~Matrix();
104 
106  int numRows();
107  void setNumRows(int rows);
108 
110  int numCols();
111  void setNumCols(int cols);
112 
113  //event handlers
115 
118  void customEvent(QEvent *e);
119  void closeEvent( QCloseEvent *);
120 
122 
123  virtual QWidget *view() {return d_future_matrix->view(); }
124 
125 
126 public slots:
127  void exportPDF(const QString& fileName);
129  void print();
131  void print(const QString& fileName);
132  void handleChange();
133 
135 
138  void setColumnsWidth(int width);
139 
141  void setDimensions(int rows, int cols);
143  void transpose();
145  void invert();
147  double determinant();
148 
150  bool recalculate();
151 
153  QString text(int row, int col);
155  void setText(int row, int col, const QString & new_text );
157  double cell(int row, int col);
159  void setCell(int row, int col, double value );
160 
180 
189  void setTextFormat(const QChar &format, int precision);
204  void setNumericFormat(const QChar & f, int prec);
205 
207  QString formula();
209  void setFormula(const QString &s);
210 
212  QString saveAsTemplate(const QString &info);
213 
215  QString saveToString(const QString &info);
217  QString saveText();
218 
219  // selection operations
221  void cutSelection();
223  void copySelection();
225  void clearSelection();
227  void pasteSelection();
228 
230  void insertRow();
232  bool rowsSelected();
234  void deleteSelectedRows();
236  int numSelectedRows();
237 
239  void insertColumn();
241  bool columnsSelected();
243  void deleteSelectedColumns();
245  int numSelectedColumns();
246 
252  void saveCellsToMemory();
258  void forgetSavedCells();
259 
261  double xStart(){return d_future_matrix->xStart();};
263  double xEnd(){return d_future_matrix->xEnd();};
265  double yStart(){return d_future_matrix->yStart();};
267  double yEnd(){return d_future_matrix->yEnd();};
268 
270  QwtDoubleRect boundingRect() {return QwtDoubleRect(xStart(), yStart(), xEnd()-xStart(), yEnd()-yStart()).normalized();};
272  void setCoordinates(double xs, double xe, double ys, double ye);
273 
275  void range(double *min, double *max);
276 
278  static double** allocateMatrixData(int rows, int columns);
280  static void freeMatrixData(double **data, int rows);
281 
282  static Matrix * fromImage(const QImage & image, ScriptingEnv * env);
283  void copy(Matrix *m);
284 
286  virtual QString birthDate(){return d_future_matrix->creationTime().toString(Qt::LocalDate); };
287 
288 signals:
290  void showContextMenu();
291 
292 protected slots:
293  void applyFormula();
294  void addFunction();
295  void addCell();
296  void updateFunctionDoc();
298 
299 private:
301  void init(int rows, int cols);
302 
304  double **dMatrix;
305 
306  Matrix(future::Matrix *future_matrix, ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
307 };
308 
309 #endif