scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Matrix.h
Go to the documentation of this file.
1 
13 
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::WindowFlags 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 );
161  void setCells(const QVector<qreal> &);
162 
182 
191  void setTextFormat(const QChar &format, int precision);
206  void setNumericFormat(const QChar & f, int prec);
207 
209  QString formula();
211  void setFormula(const QString &s);
212 
214  QString saveAsTemplate(const QString &info);
215 
217  QString saveToString(const QString &info);
219  QString saveText();
220 
221  // selection operations
223  void cutSelection();
225  void copySelection();
227  void clearSelection();
229  void pasteSelection();
230 
232  void insertRow();
234  bool rowsSelected();
236  void deleteSelectedRows();
238  int numSelectedRows();
239 
241  void insertColumn();
243  bool columnsSelected();
245  void deleteSelectedColumns();
247  int numSelectedColumns();
248 
254  void saveCellsToMemory();
260  void forgetSavedCells();
261 
263  double xStart(){return d_future_matrix->xStart();};
265  double xEnd(){return d_future_matrix->xEnd();};
267  double yStart(){return d_future_matrix->yStart();};
269  double yEnd(){return d_future_matrix->yEnd();};
270 
272  QwtDoubleRect boundingRect() {return QwtDoubleRect(xStart(), yStart(), xEnd()-xStart(), yEnd()-yStart()).normalized();};
274  void setCoordinates(double xs, double xe, double ys, double ye);
275 
277  void range(double *min, double *max);
278 
280  static double** allocateMatrixData(int rows, int columns);
282  static void freeMatrixData(double **data, int rows);
283 
284  static Matrix * fromImage(const QImage & image, ScriptingEnv * env);
285  void copy(Matrix *m);
286 
288  virtual QString birthDate(){return d_future_matrix->creationTime().toString(Qt::LocalDate); };
289 
290 signals:
293 
294 protected slots:
295  void applyFormula();
296  void addFunction();
297  void addCell();
298  void updateFunctionDoc();
300 
301 private:
303  void init(int rows, int cols);
304 
306  double **dMatrix;
307 
308  Matrix(future::Matrix *future_matrix, ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent=0, const char* name=0, Qt::WindowFlags f=0);
309 };
310 
311 #endif
Matrix
Matrix worksheet class.
Definition: Matrix.h:52
future::Matrix::yEnd
double yEnd() const
Definition: future_Matrix.cpp:1090
Matrix::cutSelection
void cutSelection()
Standard cut operation.
Definition: Matrix.cpp:457
Matrix::dMatrix
double ** dMatrix
Stores the matrix data only before the user opens the matrix dialog in order to avoid data loses duri...
Definition: Matrix.h:306
Matrix::yStart
double yStart()
Return the Y value corresponding to row 1.
Definition: Matrix.h:267
MyWidget::Label
@ Label
caption detemined by the window label
Definition: MyWidget.h:70
AbstractAspect::importV0x0001XXCreationTime
void importV0x0001XXCreationTime(const QString &str)
Definition: AbstractAspect.h:255
MatrixView
View class for Matrix.
Definition: MatrixView.h:83
future::Matrix::xStart
double xStart() const
Definition: future_Matrix.cpp:1075
Matrix::formula
QString formula()
Return the matrix formula.
Definition: Matrix.cpp:250
MyWidget::caption_policy
CaptionPolicy caption_policy
The caption policy.
Definition: MyWidget.h:173
ScriptingEnv.h
Matrix::xEnd
double xEnd()
Return the X value corresponding to the last column.
Definition: Matrix.h:265
Matrix::applyFormula
void applyFormula()
Definition: Matrix.cpp:733
Matrix::recalculate
bool recalculate()
Calculate matrix values using the formula for all selected cells.
Definition: Matrix.cpp:396
Matrix::allocateMatrixData
static double ** allocateMatrixData(int rows, int columns)
Allocate memory for a matrix buffer.
Definition: Matrix.cpp:696
Matrix::birthDate
virtual QString birthDate()
Return the creation date.
Definition: Matrix.h:288
Matrix::numSelectedRows
int numSelectedRows()
Return the number of selected rows.
Definition: Matrix.cpp:498
data
Definition: exp_saturation.c:37
Matrix::view
virtual QWidget * view()
Definition: Matrix.h:123
Matrix::fromImage
static Matrix * fromImage(const QImage &image, ScriptingEnv *env)
Definition: Matrix.cpp:726
AbstractAspect::setComment
void setComment(const QString &value)
Definition: AbstractAspect.cpp:265
Matrix::deleteSelectedColumns
void deleteSelectedColumns()
Delte the selected columns.
Definition: Matrix.cpp:493
Matrix::xStart
double xStart()
Return the X value corresponding to column 1.
Definition: Matrix.h:263
Matrix::setTextFormat
void setTextFormat(const QChar &format, int precision)
Set the number format for the cells.
Definition: Matrix.cpp:266
Matrix::columnsSelected
bool columnsSelected()
Return whether any columns are fully selected.
Definition: Matrix.cpp:483
Matrix::setName
virtual void setName(const QString &s)
Set the window name.
Definition: Matrix.h:61
future::Matrix::displayedDigits
int displayedDigits() const
Definition: future_Matrix.cpp:1112
Matrix::setText
void setText(int row, int col, const QString &new_text)
Set the content of the cell as a string.
Definition: Matrix.cpp:157
Matrix::showContextMenu
void showContextMenu()
Show the context menu.
Matrix::setWindowLabel
virtual void setWindowLabel(const QString &s)
Set the window label.
Definition: Matrix.h:65
Matrix::closeEvent
void closeEvent(QCloseEvent *)
Definition: Matrix.cpp:532
Matrix::textFormat
QChar textFormat()
Return the text format code ('e', 'f', ...)
Definition: Matrix.h:168
AbstractAspect::creationTime
QDateTime creationTime() const
Definition: AbstractAspect.cpp:288
MyWidget::birthdate
QString birthdate
The creation date.
Definition: MyWidget.h:166
Matrix::print
void print()
Print the Matrix.
Definition: Matrix.cpp:568
Matrix::saveCellsToMemory
void saveCellsToMemory()
Temporally save the cell values to memory.
Definition: Matrix.cpp:380
Matrix::setFormula
void setFormula(const QString &s)
Set the matrix forumla.
Definition: Matrix.cpp:245
Matrix::setBirthDate
virtual void setBirthDate(const QString &s)
Set the creation date.
Definition: Matrix.h:84
Matrix::setNumericFormat
void setNumericFormat(const QChar &f, int prec)
Set the number format for the cells.
Definition: Matrix.cpp:255
scripted
Interface for maintaining a reference to the current ScriptingEnv.
Definition: Script.h:149
Matrix::setCoordinates
void setCoordinates(double xs, double xe, double ys, double ye)
Set the X and Y coordinate intervals.
Definition: Matrix.cpp:179
Matrix::setCells
void setCells(const QVector< qreal > &)
Set the value of all cells.
Definition: Matrix.cpp:147
Matrix::customEvent
void customEvent(QEvent *e)
Custom event handler.
Definition: Matrix.cpp:526
Matrix::name
virtual QString name()
Return the window name.
Definition: Matrix.h:59
MyWidget::CaptionPolicy
CaptionPolicy
Possible window captions.
Definition: MyWidget.h:68
future_Matrix.h
future::Matrix::xEnd
double xEnd() const
Definition: future_Matrix.cpp:1085
Matrix::~Matrix
~Matrix()
Definition: Matrix.cpp:125
Matrix::setDimensions
void setDimensions(int rows, int cols)
Set the Matrix size.
Definition: Matrix.cpp:278
future::Matrix
Aspect providing a spreadsheet to manage MxN matrix data.
Definition: future_Matrix.h:60
Matrix::saveToString
QString saveToString(const QString &info)
Return a string to save the matrix in a project file (<matrix> section)
Definition: Matrix.cpp:184
Script.h
Matrix::updateFunctionDoc
void updateFunctionDoc()
Definition: Matrix.cpp:755
Matrix::rowsSelected
bool rowsSelected()
Return whether any rows are fully selected.
Definition: Matrix.cpp:463
Matrix::setNumericPrecision
void setNumericPrecision(int prec)
Set the number of significant digits.
Definition: Matrix.h:181
future::Matrix::view
virtual QWidget * view()
Construct a primary view on me.
Definition: future_Matrix.cpp:104
Matrix::numCols
int numCols()
Return the number of columns.
Definition: Matrix.cpp:293
Matrix::invert
void invert()
Invert the matrix.
Definition: Matrix.cpp:334
Matrix::addFunction
void addFunction()
Definition: Matrix.cpp:745
Matrix::insertColumn
void insertColumn()
Insert a column before the current cell.
Definition: Matrix.cpp:478
ScriptingEnv
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:53
Matrix::handleAspectDescriptionChange
void handleAspectDescriptionChange(const AbstractAspect *aspect)
Definition: Matrix.cpp:760
Matrix::d_future_matrix
future::Matrix * d_future_matrix
Definition: Matrix.h:56
AbstractAspect::name
QString name() const
Definition: AbstractAspect.cpp:229
Matrix::saveAsTemplate
QString saveAsTemplate(const QString &info)
Format the matrix format in a string to save it in a template file.
Definition: Matrix.cpp:215
Matrix::setCell
void setCell(int row, int col, double value)
Set the value of the cell.
Definition: Matrix.cpp:142
future::Matrix::yStart
double yStart() const
Definition: future_Matrix.cpp:1080
Matrix::saveText
QString saveText()
Return a string conaining the data of the matrix (<data> section)
Definition: Matrix.cpp:230
MyWidget::Name
@ Name
caption determined by the window name
Definition: MyWidget.h:69
Matrix::insertRow
void insertRow()
Insert a row before the current cell.
Definition: Matrix.cpp:516
Matrix::setCaptionPolicy
void setCaptionPolicy(CaptionPolicy policy)
Set the caption policy.
Definition: Matrix.h:67
Matrix::boundingRect
QwtDoubleRect boundingRect()
Returns the bounding rect of the matrix coordinates.
Definition: Matrix.h:272
Matrix::forgetSavedCells
void forgetSavedCells()
Definition: Matrix.cpp:390
Matrix::setNumCols
void setNumCols(int cols)
Definition: Matrix.cpp:298
Matrix::copy
void copy(Matrix *m)
Definition: Matrix.cpp:718
Matrix::pasteSelection
void pasteSelection()
Standard paste operation.
Definition: Matrix.cpp:521
AbstractAspect::setCaptionSpec
void setCaptionSpec(const QString &value)
Set the specification string used for constructing the caption().
Definition: AbstractAspect.cpp:276
AbstractAspect::setName
void setName(const QString &value)
Definition: AbstractAspect.cpp:234
AbstractAspect::comment
QString comment() const
Definition: AbstractAspect.cpp:260
Matrix::updateDecimalSeparators
void updateDecimalSeparators()
Definition: Matrix.cpp:713
Matrix::handleChange
void handleChange()
Definition: Matrix.cpp:129
MyWidget::Both
@ Both
caption = "name - label"
Definition: MyWidget.h:71
Matrix::range
void range(double *min, double *max)
Min and max values of the matrix.
Definition: Matrix.cpp:674
Matrix::Matrix
Matrix(ScriptingEnv *env, int r, int c, const QString &label, QWidget *parent=0, const char *name=0, Qt::WindowFlags f=0)
Constructor.
Definition: Matrix.cpp:63
MyWidget.h
Matrix::copySelection
void copySelection()
Standard copy operation.
Definition: Matrix.cpp:452
future::Matrix::setDisplayedDigits
void setDisplayedDigits(int digits)
Definition: future_Matrix.cpp:1067
Matrix::setColumnsWidth
void setColumnsWidth(int width)
Set the width of all columns (obsolete, only for OPJ import)
Definition: Matrix.cpp:272
Matrix::text
QString text(int row, int col)
Return the content of the cell as a string.
Definition: Matrix.cpp:152
MatrixView.h
Matrix::determinant
double determinant()
Calculate the determinant of the matrix.
Definition: Matrix.cpp:303
Matrix::clearSelection
void clearSelection()
Clear cells.
Definition: Matrix.cpp:447
Matrix::exportPDF
void exportPDF(const QString &fileName)
Definition: Matrix.cpp:563
Matrix::yEnd
double yEnd()
Return the Y value corresponding to the last row.
Definition: Matrix.h:269
future::Matrix::numericFormat
char numericFormat() const
Definition: future_Matrix.cpp:1107
Matrix::addCell
void addCell()
Definition: Matrix.cpp:750
Matrix::deleteSelectedRows
void deleteSelectedRows()
Delete the selected rows.
Definition: Matrix.cpp:473
Matrix::windowLabel
virtual QString windowLabel()
Return the window label.
Definition: Matrix.h:63
MatrixView::init
void init()
Initialization.
Definition: MatrixView.cpp:84
MyWidget::updateCaption
void updateCaption()
Set caption according to current CaptionPolicy, name and label.
Definition: MyWidget.cpp:52
Matrix::numRows
int numRows()
Return the number of rows.
Definition: Matrix.cpp:283
MyWidget::aspect
QString aspect()
Return the window status as a string.
Definition: MyWidget.cpp:106
Matrix::precision
int precision()
Return the number precision digits.
Definition: Matrix.h:175
Matrix::freeMatrixData
static void freeMatrixData(double **data, int rows)
Free memory used for a matrix buffer.
Definition: Matrix.cpp:705
Matrix::cell
double cell(int row, int col)
Return the value of the cell as a double.
Definition: Matrix.cpp:134
AbstractAspect
Base class of all persistent objects in a Project.
Definition: AbstractAspect.h:86
Matrix::transpose
void transpose()
Transpose the matrix.
Definition: Matrix.cpp:375
Matrix::numSelectedColumns
int numSelectedColumns()
Return the number of selected columns.
Definition: Matrix.cpp:507
Matrix::setNumRows
void setNumRows(int rows)
Definition: Matrix.cpp:288