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
00031
00032 #ifndef MATRIX_H
00033 #define MATRIX_H
00034
00035 #include <QTableWidget>
00036 #include <QContextMenuEvent>
00037 #include <QEvent>
00038 #include <QHeaderView>
00039 #include "MyWidget.h"
00040 #include "ScriptingEnv.h"
00041 #include "Script.h"
00042 #include <qwt_double_rect.h>
00043
00044
00045 #define _Matrix_initial_rows_ 10
00046 #define _Matrix_initial_columns_ 3
00047
00049 class Matrix: public MyWidget, public scripted
00050 {
00051 Q_OBJECT
00052
00053 public:
00054
00067 Matrix(ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
00068 ~Matrix(){};
00069
00071 int numRows();
00073 int numCols();
00074
00076 bool isEmptyRow(int row);
00077
00078
00085 bool eventFilter(QObject *object, QEvent *e);
00087 void contextMenuEvent(QContextMenuEvent *e);
00089
00092 void customEvent(QEvent *e);
00093
00094 public slots:
00095 void exportPDF(const QString& fileName);
00097 void print();
00099 void print(const QString& fileName);
00101 void cellEdited(int,int);
00102
00104 int columnsWidth();
00106 void setColumnsWidth(int width);
00107
00109 void setMatrixDimensions(int rows, int cols);
00111 void transpose();
00113 void invert();
00115 double determinant();
00116
00118 bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
00119
00121 QString text(int row, int col);
00123 void setText(int row, int col, const QString & new_text );
00125 double cell(int row, int col);
00127 void setCell(int row, int col, double value );
00128
00134 QChar textFormat(){return txt_format;};
00141 int precision(){return num_precision;};
00147 void setNumericPrecision(int prec){num_precision = prec;};
00148
00157 void setTextFormat(const QChar &format, int precision);
00172 void setNumericFormat(const QChar & f, int prec);
00173
00175 QString formula();
00177 void setFormula(const QString &s);
00178
00180 void restore(const QStringList &l);
00182 QString saveAsTemplate(const QString &info);
00183
00185 QString saveToString(const QString &info);
00187 QString saveText();
00188
00189
00191 void cutSelection();
00193 void copySelection();
00195 void clearSelection();
00197 void pasteSelection();
00198
00200 void insertRow();
00202 bool rowsSelected();
00204 void deleteSelectedRows();
00206 int numSelectedRows();
00207
00209 void insertColumn();
00211 bool columnsSelected();
00213 void deleteSelectedColumns();
00215 int numSelectedColumns();
00217 bool isColumnSelected(int col, bool full=false);
00219 bool isRowSelected(int row, bool full=false);
00221 int firstSelectedColumn();
00222
00228 void saveCellsToMemory();
00234 void forgetSavedCells();
00235
00237 double xStart(){return x_start;};
00239 double xEnd(){return x_end;};
00241 double yStart(){return y_start;};
00243 double yEnd(){return y_end;};
00244
00246 QwtDoubleRect boundingRect(){return QwtDoubleRect(x_start, y_start, x_end-x_start, y_end-y_start).normalized();};
00248 void setCoordinates(double xs, double xe, double ys, double ye);
00249
00251 void range(double *min, double *max);
00253 QTableWidget* table(){return d_table;};
00254
00256 void goToRow(int row);
00257
00259 static double** allocateMatrixData(int rows, int columns);
00261 static void freeMatrixData(double **data, int rows);
00262
00263 int verticalHeaderWidth(){return table()->verticalHeader()->width();}
00264
00265 signals:
00267 void showContextMenu();
00268
00269 private:
00271 void init(int rows, int cols);
00272
00274 QTableWidget *d_table;
00276 QString formula_str;
00278 QChar txt_format;
00280 int num_precision;
00282 double **dMatrix;
00283 double x_start,
00284 x_end,
00285 y_start,
00286 y_end;
00287
00295 bool allow_modification_signals;
00296 };
00297
00298 #endif