QtiPlot  0.9.8.2
Table.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : Table.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2006 by Ion Vasilief, Knut Franke
6  Email (use @ for *) : ion_vasilief*yahoo.fr
7  Description : Table worksheet class
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 #ifndef TABLE_H
30 #define TABLE_H
31 
32 #include <q3table.h>
33 #include <q3header.h>
34 #include <QVarLengthArray>
35 #include <QLocale>
36 
37 #include <MdiSubWindow.h>
38 #include <ScriptingEnv.h>
39 #include <Script.h>
40 
41 class MyTable : public Q3Table
42 {
43 public:
44  MyTable(QWidget * parent = 0, const char * name = 0);
45  MyTable(int numRows, int numCols, QWidget * parent = 0, const char * name = 0);
46 
47 private:
48  void activateNextCell();
49 };
50 
57 class Table: public MdiSubWindow, public scripted
58 {
59  Q_OBJECT
60 
61 public:
62  enum PlotDesignation{All = -1, None = 0, X = 1, Y = 2, Z = 3, xErr = 4, yErr = 5, Label = 6};
63  enum ColType{Numeric = 0, Text = 1, Date = 2, Time = 3, Month = 4, Day = 5};
64  enum NumericFormat{Default = 0, Decimal = 1, Scientific = 2};
65  enum ImportMode {
68  Overwrite
69  };
70 
71  Table(ScriptingEnv *env, int r,int c, const QString &label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
72 
73  Q3TableSelection getSelection();
74 
76  void setNumericPrecision(int prec);
78  void updateDecimalSeparators(const QLocale& oldSeparators);
79  void setAutoUpdateValues(bool on = true);
80  virtual QString sizeToString();
81 
82  double avg(int col, int startRow = 0, int endRow = -1);
83  double sum(int col, int startRow = 0, int endRow = -1);
84  double minColumnValue(int col, int startRow = 0, int endRow = -1);
85  double maxColumnValue(int col, int startRow = 0, int endRow = -1);
86  Table* extractData(const QString& name, const QString& condition, int startRow = 0, int endRow = -1);
87  static QDateTime dateTime(double val);
88  static double fromDateTime(const QDateTime& dt);
89  static double fromTime(const QTime& t);
90 
91 public slots:
92  MyTable* table(){return d_table;};
93  void copy(Table *m, bool values = true);
94  int numRows();
95  int numCols();
96  void setNumRows(int rows);
97  void setNumCols(int cols);
98  void resizeRows(int);
99  void resizeCols(int);
100 
102  double cell(int row, int col);
103  void setCell(int row, int col, double val);
104 
105  QString text(int row, int col);
106  QStringList columnsList();
107  QStringList colNames(){return col_label;}
108  QString colName(int col);
109  void setColName(int col, const QString& text, bool enumerateRight = false, bool warn = true);
110  QString colLabel(int col);
111  int colIndex(const QString& name);
112 
113  int colPlotDesignation(int col){return col_plot_type[col];};
114  void setColPlotDesignation(int col, PlotDesignation pd);
115  void setPlotDesignation(PlotDesignation pd, bool rightColumns = false);
116  QList<int> plotDesignations(){return col_plot_type;};
117 
118  void setHeader(QStringList header);
119  void loadHeader(QStringList header);
120  void setHeaderColType();
121  void setText(int row,int col,const QString & text);
122  void setRandomValues();
123  void setRandomValues(int col, int startRow = 0, int endRow = -1);
124  void setNormalRandomValues();
125  void setNormalRandomValues(int col, int startRow = 0, int endRow = -1, double sigma = 1.0);
126  void setAscValues();
127 
128  void cellEdited(int,int col);
129  void moveCurrentCell();
130  void clearCell(int row, int col);
131  bool isEmptyRow(int row);
132  bool isEmptyColumn(int col);
133  int nonEmptyRows();
134 
135  void print();
136  void print(QPrinter *);
137  void print(const QString& fileName);
138  void exportPDF(const QString& fileName);
139 
141 
142  bool eventFilter(QObject *object, QEvent *e);
143  void customEvent( QEvent* e);
145 
147 
148  void removeCol();
149  void removeCol(const QStringList& list);
150  void insertCol();
151  virtual void insertCols(int start, int count);
152  virtual void addCol(PlotDesignation pd = Y);
153  void addColumns(int c);
154  virtual void moveColumn(int, int, int);
155  void swapColumns(int, int);
156  void moveColumnBy(int cols);
157  void hideSelectedColumns();
158  void showAllColumns();
159  void hideColumn(int col, bool = true);
160  bool isColumnHidden(int col){return d_table->isColumnHidden(col);};
162 
164 
165 
168  void sortColAsc();
172  void sortColDesc();
177  void sortColumn(int col = -1, int order = 0);
182  void sortTableDialog();
184  void sort(int type = 0, int order = 0, const QString& leadCol = QString());
186  void sortColumns(int type = 0, int order = 0, const QString& leadCol = QString());
193  void sortColumns(const QStringList& cols, int type = 0, int order = 0, const QString& leadCol = QString());
198  void sortColumnsDialog();
200 
202 
203  void normalizeCol(int col=-1);
204  void normalizeSelection();
205  void normalize();
207 
208  QVarLengthArray<double> col(int ycol);
209  void columnRange(int c, double *min, double *max);
210 
211  int firstXCol();
212  bool noXColumn();
213  bool noYColumn();
214  int colX(int col);
215  int colY(int col, int xCol = -1, const QStringList& lst = QStringList());
216 
217  QStringList getCommands(){return commands;};
219  void clearCommands();
221  void setCommands(const QStringList& com);
223  void setCommands(const QString& com);
225  void setCommand(int col, const QString& com);
227  bool calculate(int col, int startRow, int endRow, bool forceMuParser = false, bool notifyChanges = true);
229  bool muParserCalculate(int col, int startRow, int endRow, bool notifyChanges = true);
231  bool calculate();
233  void updateValues(Table*, const QString& columnName);
234 
236 
237  void deleteSelectedRows();
238  void deleteRows(int startRow, int endRow);
239  void insertRow();
240  void moveRow(bool up = true);
242 
244 
245  void cutSelection();
246  void copySelection();
247  void clearSelection();
248  void pasteSelection();
249  void selectAllTable();
250  void deselect();
251  void clear();
253 
254  void init(int rows, int cols);
255  QStringList writableSelectedColumns();
256  QStringList selectedColumns();
257  QStringList selectedYColumns();
258  QStringList selectedErrColumns();
259  QStringList selectedYLabels();
260  QStringList drawableColumnSelection();
261  QStringList YColumns();
262  int selectedColsNumber();
263 
264  void setColumnWidth(int width, bool allCols);
265  void setColumnWidth(int col, int width);
266  int columnWidth(int col);
267  QStringList columnWidths();
268  void setColWidths(const QStringList& widths);
269  void adjustColumnsWidth(bool selection = true);
270 
271  void setSelectedCol(int col){selectedCol = col;};
272  int selectedColumn(){return selectedCol;};
273  int firstSelectedColumn();
274  int numSelectedRows();
275  bool isRowSelected(int row, bool full=false) { return d_table->isRowSelected(row, full); }
276  bool isColumnSelected(int col, bool full=false) { return d_table->isColumnSelected(col, full); }
278  void goToRow(int row);
280  void goToColumn(int col);
281 
282  void columnNumericFormat(int col, char *f, int *precision);
283  void columnNumericFormat(int col, int *f, int *precision);
284  int columnType(int col){return colTypes[col];};
285 
286  QList<int> columnTypes(){return colTypes;};
287  void setColumnTypes(QList<int> ctl){colTypes = ctl;};
288  void setColumnTypes(const QStringList& ctl);
289  void setColumnType(int col, ColType val) { colTypes[col] = val; }
290 
291  void saveToMemory(double **cells){d_saved_cells = cells;};
292  void saveToMemory();
293  void freeMemory();
294 
295  bool isReadOnlyColumn(int col);
296  void setReadOnlyColumn(int col, bool on = true);
297 
298  QString columnFormat(int col){return col_format[col];};
299  QStringList getColumnsFormat(){return col_format;};
300  void setColumnsFormat(const QStringList& lst);
301 
302  void setTextFormat(int col);
303  void setColNumericFormat(int col);
304  void setColNumericFormat(int f, int prec, int col, bool updateCells = true);
305  bool setDateFormat(const QString& format, int col, bool updateCells = true);
306  bool setTimeFormat(const QString& format, int col, bool updateCells = true);
307  void setMonthFormat(const QString& format, int col, bool updateCells = true);
308  void setDayFormat(const QString& format, int col, bool updateCells = true);
309 
310  bool exportExcel(const QString& fname, bool withLabels, bool exportComments, bool exportSelection);
311  bool exportOdsSpreadsheet(const QString& fname, bool withLabels, bool exportComments, bool exportSelection);
312  bool exportODF(const QString& fname, bool withLabels, bool exportComments, bool exportSelection);
313  bool exportASCII(const QString& fname, const QString& separator, bool withLabels = false,
314  bool exportComments = false, bool exportSelection = false);
315  void importASCII(const QString &fname, const QString &sep = "\t", int ignoredLines = 0, bool renameCols = false,
316  bool stripSpaces = false, bool simplifySpaces = false, bool importComments = false,
317  const QString& commentString = "", bool readOnly = false,
318  ImportMode importAs = Overwrite, const QLocale& importLocale = QLocale(), int endLine = 0, int maxRows = -1,
319  const QList<int>& newColTypes = QList<int>(), const QStringList& colFormats = QStringList());
320 
322 
323  virtual void save(const QString &fn, const QString& geometry, bool = false);
324  void restore(const QStringList& lst);
325 
326  QString saveHeader();
327  QString saveComments();
328  QString saveCommands();
329  QString saveColumnWidths();
330  QString saveColumnTypes();
331  QString saveReadOnlyInfo();
332  QString saveHiddenColumnsInfo();
333 
334  void setBackgroundColor(const QColor& col);
335  void setTextColor(const QColor& col);
336  void setHeaderColor(const QColor& col);
337  void setTextFont(const QFont& fnt);
338  void setHeaderFont(const QFont& fnt);
339 
340  int verticalHeaderWidth(){return d_table->verticalHeader()->width();};
341 
342  QString comment(int col);
343  void setColComment(int col, const QString& s);
344  QStringList colComments(){return comments;};
345  void setColComments(const QStringList& lst){comments = lst;};
346  void showComments(bool on = true);
347  bool commentsEnabled(){return d_show_comments;}
348 
350  void notifyChanges();
351  void notifyChanges(const QString& colName);
352 
354  void colWidthModified(int, int, int);
355 
356 signals:
357  void changedColHeader(const QString&, const QString&);
358  void removedCol(const QString&);
359  void addedCol(const QString&);
360  void removedCol(int);
361  void colIndexChanged(int, int);
362  void modifiedData(Table *, const QString&);
363  void optionsDialog();
364  void colValuesDialog();
365  void resizedTable(QWidget*);
366  void showContextMenu(bool selection);
367 
368 protected:
370 
371 private:
372  void clearCol();
373 
375  QStringList commands, col_format, comments, col_label;
376  QList<int> colTypes, col_plot_type;
379  double **d_saved_cells;
380 
382  void setColumnHeader(int index, const QString& label);
383 };
384 
385 #endif
int selectedCol
Definition: Table.h:377
bool isColumnHidden(int col)
Definition: Table.h:160
QList< int > plotDesignations()
Definition: Table.h:116
void activateNextCell()
Definition: Table.cpp:4003
QStringList getCommands()
Definition: Table.h:217
QList< int > columnTypes()
Definition: Table.h:286
bool isColumnSelected(int col, bool full=false)
Definition: Table.h:276
void setColumnType(int col, ColType val)
Definition: Table.h:289
Definition: Table.h:41
ImportMode
Definition: Table.h:65
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:50
add file as new rows to this table
Definition: Table.h:67
int verticalHeaderWidth()
Definition: Table.h:340
int selectedColumn()
Definition: Table.h:272
QList< int > colTypes
Definition: Table.h:376
int colPlotDesignation(int col)
Definition: Table.h:113
add file as new columns to this table
Definition: Table.h:66
#define min(a, b)
Definition: ShapiroWilkTest.cpp:36
MyTable * d_table
Definition: Table.h:369
QtiPlot&#39;s main window.
Definition: ApplicationWindow.h:133
QStringList colComments()
Definition: Table.h:344
QStringList getColumnsFormat()
Definition: Table.h:299
bool d_show_comments
Definition: Table.h:374
ColType
Definition: Table.h:63
QString columnFormat(int col)
Definition: Table.h:298
void setColComments(const QStringList &lst)
Definition: Table.h:345
void setSelectedCol(int col)
Definition: Table.h:271
double ** d_saved_cells
Definition: Table.h:379
MyTable * table()
Definition: Table.h:92
int columnType(int col)
Definition: Table.h:284
QStringList comments
Definition: Table.h:375
QStringList colNames()
Definition: Table.h:107
void saveToMemory(double **cells)
Definition: Table.h:291
Base class of all MDI client windows.
Definition: MdiSubWindow.h:51
Interface for maintaining a reference to the current ScriptingEnv.
Definition: Script.h:152
MyTable(QWidget *parent=0, const char *name=0)
Definition: Table.cpp:3995
int d_numeric_precision
Definition: Table.h:378
PlotDesignation
Definition: Table.h:62
NumericFormat
Definition: Table.h:64
MDI window providing a spreadsheet table with column logic.
Definition: Table.h:57
void setColumnTypes(QList< int > ctl)
Definition: Table.h:287
bool isRowSelected(int row, bool full=false)
Definition: Table.h:275
bool commentsEnabled()
Definition: Table.h:347