1
/***************************************************************************
4
--------------------------------------------------------------------
5
Copyright : (C) 2006 by Ion Vasilief,
6
Tilman Hoener zu Siederdissen,
8
Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net
9
Description : Table worksheet class
11
***************************************************************************/
13
/***************************************************************************
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. *
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. *
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 *
30
***************************************************************************/
36
#include <Q3ValueList>
37
#include <QVarLengthArray>
41
#include "ScriptingEnv.h"
44
class MyTable : public Q3Table
47
MyTable(QWidget * parent = 0, const char * name = 0);
48
MyTable(int numRows, int numCols, QWidget * parent = 0, const char * name = 0);
50
void activateNextCell();
53
/*!\brief MDI window providing a spreadsheet table with column logic.
55
* \section future Future Plans
56
* Port to the Model/View approach used in Qt4 and get rid of the Qt3Support dependancy.
57
* [ assigned to thzs ]
59
class Table: public MyWidget, public scripted
64
enum PlotDesignation{All = -1, None = 0, X = 1, Y = 2, Z = 3, xErr = 4, yErr = 5};
65
enum ColType{Numeric = 0, Text = 1, Date = 2, Time = 3, Month = 4, Day = 5};
67
Table(ScriptingEnv *env, const QString &fname,const QString &sep, int ignoredLines, bool renameCols,
68
bool stripSpaces, bool simplifySpaces, const QString &label,
69
QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
70
Table(ScriptingEnv *env, int r,int c, const QString &label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
72
Q3TableSelection getSelection();
74
//! Sets the number of significant digits
75
void setNumericPrecision(int prec);
78
MyTable* table(){return d_table;};
82
void setNumRows(int rows);
83
void setNumCols(int cols);
87
//! Return the value of the cell as a double
88
double cell(int row, int col);
89
void setCell(int row, int col, double val);
91
QString text(int row, int col);
92
QStringList columnsList();
93
QStringList colNames(){return col_label;}
94
QString colName(int col);
95
QString colLabel(int col){return col_label[col];};
96
int colIndex(const QString& name);
98
int colPlotDesignation(int col){return col_plot_type[col];};
99
void setColPlotDesignation(int col, PlotDesignation d){col_plot_type[col]=d;};
100
void setPlotDesignation(PlotDesignation pd);
101
Q3ValueList<int> plotDesignations(){return col_plot_type;};
103
void setColName(int col,const QString& text);
104
void setHeader(QStringList header);
105
void loadHeader(QStringList header);
106
void setHeaderColType();
107
void setText(int row,int col,const QString & text);
108
void setRandomValues();
111
void cellEdited(int,int col);
112
void moveCurrentCell();
113
void clearCell(int row, int col);
115
bool isEmptyRow(int row);
116
bool isEmptyColumn(int col);
126
void plotVerticalDropLines();
128
void plotVertSteps();
130
void plotHistogram();
133
void plotBoxDiagram();
138
void plot3DScatter();
139
void plot3DTrajectory();
147
void print(const QString& fileName);
148
void exportPDF(const QString& fileName);
150
//! \name Event Handlers
152
bool eventFilter(QObject *object, QEvent *e);
153
void contextMenuEvent(QContextMenuEvent *e);
154
void customEvent( QEvent* e);
157
//! \name Column Operations
160
void removeCol(const QStringList& list);
163
void insertCols(int start, int count);
164
void addCol(PlotDesignation pd = Y);
165
void addColumns(int c);
170
/*!\brief Sort the current column in ascending order.
171
* \sa sortColDesc(), sortColumn(), Q3Table::currentColumn()
174
/*!\brief Sort the current column in descending order.
175
* \sa sortColAsc(), sortColumn(), Q3Table::currentColumn()
178
/*!\brief Sort the specified column.
179
* \param col the column to be sorted
180
* \param order 0 means ascending, anything else means descending
182
void sortColumn(int col = -1, int order = 0);
183
/*!\brief Display a dialog with some options for sorting all columns.
185
* The sorting itself is done using sort(int,int,const QString&).
187
void sortTableDialog();
188
//! Sort all columns as in sortColumns(const QStringList&,int,int,const QString&).
189
void sort(int type = 0, int order = 0, const QString& leadCol = QString());
190
//! Sort selected columns as in sortColumns(const QStringList&,int,int,const QString&).
191
void sortColumns(int type = 0, int order = 0, const QString& leadCol = QString());
192
/*!\brief Sort the specified columns.
193
* \param cols the columns to be sorted
194
* \param type 0 means sort individually (as in sortColumn()), anything else means together
195
* \param order 0 means ascending, anything else means descending
196
* \param leadCol for sorting together, the column which determines the permutation
198
void sortColumns(const QStringList& cols, int type = 0, int order = 0, const QString& leadCol = QString());
199
/*!\brief Display a dialog with some options for sorting the selected columns.
201
* The sorting itself is done using sortColumns(int,int,const QString&).
203
void sortColumnsDialog();
206
//! \name Normalization
208
void normalizeCol(int col=-1);
209
void normalizeSelection();
213
QVarLengthArray<double> col(int ycol);
220
QStringList getCommands(){return commands;};
221
//! Set all column formulae.
222
void setCommands(const QStringList& com);
223
//! Set all column formulae.
224
void setCommands(const QString& com);
225
//! Set formula for column col.
226
void setCommand(int col, const QString com);
227
//! Compute specified cells from column formula.
228
bool calculate(int col, int startRow, int endRow);
229
//! Compute selected cells from column formulae; use current cell if there's no selection.
232
//! \name Row Operations
234
void deleteSelectedRows();
238
//! Selection Operations
241
void copySelection();
242
void clearSelection();
243
void pasteSelection();
244
void selectAllTable();
249
void init(int rows, int cols);
250
QStringList selectedColumns();
251
QStringList selectedYColumns();
252
QStringList selectedErrColumns();
253
QStringList selectedYLabels();
254
QStringList drawableColumnSelection();
255
QStringList YColumns();
256
int selectedColsNumber();
257
void changeColName(const QString& text);
258
void enumerateRightCols(bool checked);
260
void changeColWidth(int width, bool allCols);
261
void changeColWidth(int width, int col);
262
int columnWidth(int col);
263
QStringList columnWidths();
264
void setColWidths(const QStringList& widths);
266
void setSelectedCol(int col){selectedCol = col;};
267
int selectedColumn(){return selectedCol;};
268
int firstSelectedColumn();
269
int numSelectedRows();
270
bool isRowSelected(int row, bool full=false) { return d_table->isRowSelected(row, full); }
271
bool isColumnSelected(int col, bool full=false) { return d_table->isColumnSelected(col, full); }
272
//! Scroll to row (row starts with 1)
273
void goToRow(int row);
275
void columnNumericFormat(int col, char *f, int *precision);
276
void columnNumericFormat(int col, int *f, int *precision);
277
int columnType(int col){return colTypes[col];};
279
Q3ValueList<int> columnTypes(){return colTypes;};
280
void setColumnTypes(Q3ValueList<int> ctl){colTypes = ctl;};
281
void setColumnTypes(const QStringList& ctl);
282
void setColumnType(int col, ColType val) { colTypes[col] = val; }
287
QString columnFormat(int col){return col_format[col];};
288
QStringList getColumnsFormat(){return col_format;};
289
void setColumnsFormat(const QStringList& lst);
291
void setTextFormat(int col);
292
void setColNumericFormat(int f, int prec, int col);
293
bool setDateFormat(const QString& format, int col);
294
bool setTimeFormat(const QString& format, int col);
295
void setMonthFormat(const QString& format, int col);
296
void setDayFormat(const QString& format, int col);
297
bool setDateTimeFormat(int f, const QString& format, int col);
299
bool exportToASCIIFile(const QString& fname, const QString& separator,
300
bool withLabels,bool exportSelection);
301
void importASCII(const QString &fname, const QString &sep, int ignoredLines,
302
bool renameCols, bool stripSpaces, bool simplifySpaces, bool newTable);
303
void importMultipleASCIIFiles(const QString &fname, const QString &sep, int ignoredLines,
304
bool renameCols, bool stripSpaces, bool simplifySpaces, int importFileAs);
306
//! \name Saving and Restoring
308
virtual QString saveToString(const QString& geometry);
309
QString saveHeader();
310
QString saveComments();
311
QString saveCommands();
312
QString saveColumnWidths();
313
QString saveColumnTypes();
315
void setSpecifications(const QString& s);
316
QString& getSpecifications();
317
void restore(QString& spec);
318
QString& getNewSpecifications();
319
void setNewSpecifications();
322
*used for restoring the table old caption stored in specifications string
324
QString oldCaption();
327
*used for restoring the table caption stored in new specifications string
329
QString newCaption();
332
void setBackgroundColor(const QColor& col);
333
void setTextColor(const QColor& col);
334
void setHeaderColor(const QColor& col);
335
void setTextFont(const QFont& fnt);
336
void setHeaderFont(const QFont& fnt);
338
int verticalHeaderWidth(){return d_table->verticalHeader()->width();};
340
QString colComment(int col){return comments[col];};
341
void setColComment(int col, const QString& s);
342
QStringList colComments(){return comments;};
343
void setColComments(const QStringList& lst){comments = lst;};
344
void showComments(bool on = true);
345
bool commentsEnabled(){return d_show_comments;}
347
QString saveAsTemplate(const QString& geometryInfo);
348
void restore(const QStringList& lst);
350
//! This slot notifies the main application that the table has been modified. Triggers the update of 2D plots.
351
void notifyChanges();
353
//! Notifies the main application that the width of a table column has been modified by the user.
354
void colWidthModified(int, int, int);
357
void plot3DRibbon(Table *,const QString&);
358
void plotXYZ(Table *,const QString&, int);
359
void plotCol(Table *,const QStringList&, int, int, int);
360
void changedColHeader(const QString&, const QString&);
361
void removedCol(const QString&);
362
void modifiedData(Table *, const QString&);
363
void optionsDialog();
364
void colValuesDialog();
365
void resizedTable(QWidget*);
366
void showContextMenu(bool selection);
367
void createTable(const QString&,int,int,const QString&);
373
bool d_show_comments;
374
QString specifications, newSpecifications;
375
QStringList commands, col_format, comments, col_label;
376
QList<int> colTypes, col_plot_type;
378
double **d_saved_cells;
380
//! Internal function to change the column header
381
void setColumnHeader(int index, const QString& label);