~showard314/ubuntu/natty/qtiplot/Python2.7_fix

« back to all changes in this revision

Viewing changes to qtiplot/src/Table.h

  • Committer: Bazaar Package Importer
  • Author(s): Gudjon I. Gudjonsson
  • Date: 2007-03-25 12:06:27 UTC
  • Revision ID: james.westby@ubuntu.com-20070325120627-5pvdufddr7i0r74x
Tags: upstream-0.9~rc2
ImportĀ upstreamĀ versionĀ 0.9~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : Table.h
 
3
    Project              : QtiPlot
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006 by Ion Vasilief,
 
6
                           Tilman Hoener zu Siederdissen,
 
7
                           Knut Franke
 
8
    Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
 
9
    Description          : Table worksheet class
 
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 TABLE_H
 
32
#define TABLE_H
 
33
 
 
34
#include <q3table.h>
 
35
#include <q3header.h>
 
36
#include <Q3ValueList>
 
37
#include <QVarLengthArray>
 
38
 
 
39
#include "Graph.h"
 
40
#include "MyWidget.h"
 
41
#include "ScriptingEnv.h"
 
42
#include "Script.h"
 
43
 
 
44
class MyTable : public Q3Table
 
45
{
 
46
public:
 
47
    MyTable(QWidget * parent = 0, const char * name = 0);
 
48
    MyTable(int numRows, int numCols, QWidget * parent = 0, const char * name = 0);
 
49
 
 
50
    void activateNextCell();
 
51
};
 
52
 
 
53
/*!\brief MDI window providing a spreadsheet table with column logic.
 
54
 *
 
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 ]
 
58
 */
 
59
class Table: public MyWidget, public scripted
 
60
{
 
61
    Q_OBJECT
 
62
 
 
63
public:
 
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};
 
66
 
 
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);
 
71
 
 
72
        Q3TableSelection getSelection();
 
73
 
 
74
        //! Sets the number of significant digits
 
75
        void setNumericPrecision(int prec);
 
76
 
 
77
public slots:
 
78
        MyTable* table(){return d_table;};
 
79
        void copy(Table *m);
 
80
        int numRows();
 
81
        int numCols();
 
82
        void setNumRows(int rows);
 
83
        void setNumCols(int cols);
 
84
        void resizeRows(int);
 
85
        void resizeCols(int);
 
86
 
 
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);
 
90
 
 
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);
 
97
 
 
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;};
 
102
 
 
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();
 
109
        void setAscValues();
 
110
 
 
111
        void cellEdited(int,int col);
 
112
        void moveCurrentCell();
 
113
        void clearCell(int row, int col);
 
114
        QString saveText();
 
115
        bool isEmptyRow(int row);
 
116
        bool isEmptyColumn(int col);
 
117
        int nonEmptyRows();
 
118
 
 
119
        void plotL();
 
120
        void plotLP();
 
121
        void plotP();
 
122
        void plotVB();
 
123
        void plotHB();
 
124
        void plotArea();
 
125
        void plotPie();
 
126
        void plotVerticalDropLines();
 
127
        void plotSpline();
 
128
        void plotVertSteps();
 
129
    void plotHorSteps();
 
130
        void plotHistogram();
 
131
        void plotVectXYXY();
 
132
        void plotVectXYAM();
 
133
        void plotBoxDiagram();
 
134
 
 
135
        //! \name 3D Plots
 
136
        //@{
 
137
        void plot3DRibbon();
 
138
        void plot3DScatter();
 
139
        void plot3DTrajectory();
 
140
        void plot3DBars();
 
141
 
 
142
        bool valid2DPlot();
 
143
        bool valid3DPlot();
 
144
        //@}v
 
145
 
 
146
        void print();
 
147
        void print(const QString& fileName);
 
148
        void exportPDF(const QString& fileName);
 
149
 
 
150
        //! \name Event Handlers
 
151
        //@{
 
152
        bool eventFilter(QObject *object, QEvent *e);
 
153
        void contextMenuEvent(QContextMenuEvent *e);
 
154
        void customEvent( QEvent* e);
 
155
        //@}v
 
156
 
 
157
        //! \name Column Operations
 
158
        //@{
 
159
        void removeCol();
 
160
        void removeCol(const QStringList& list);
 
161
        void clearCol();
 
162
        void insertCol();
 
163
        void insertCols(int start, int count);
 
164
        void addCol(PlotDesignation pd = Y);
 
165
        void addColumns(int c);
 
166
        //@}
 
167
 
 
168
        //! \name Sorting
 
169
        //@{
 
170
        /*!\brief Sort the current column in ascending order.
 
171
         * \sa sortColDesc(), sortColumn(), Q3Table::currentColumn()
 
172
         */
 
173
        void sortColAsc();
 
174
        /*!\brief Sort the current column in descending order.
 
175
         * \sa sortColAsc(), sortColumn(), Q3Table::currentColumn()
 
176
         */
 
177
        void sortColDesc();
 
178
        /*!\brief Sort the specified column.
 
179
         * \param col the column to be sorted
 
180
         * \param order 0 means ascending, anything else means descending
 
181
         */
 
182
        void sortColumn(int col = -1, int order = 0);
 
183
        /*!\brief Display a dialog with some options for sorting all columns.
 
184
         *
 
185
         * The sorting itself is done using sort(int,int,const QString&).
 
186
         */
 
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
 
197
         */
 
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.
 
200
         *
 
201
         * The sorting itself is done using sortColumns(int,int,const QString&).
 
202
         */
 
203
        void sortColumnsDialog();
 
204
        //@}
 
205
 
 
206
        //! \name Normalization
 
207
        //@{
 
208
        void normalizeCol(int col=-1);
 
209
        void normalizeSelection();
 
210
        void normalize();
 
211
        //@}
 
212
 
 
213
        QVarLengthArray<double> col(int ycol);
 
214
        int firstXCol();
 
215
        bool noXColumn();
 
216
        bool noYColumn();
 
217
        int colX(int col);
 
218
        int colY(int col);
 
219
 
 
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.
 
230
        bool calculate();
 
231
 
 
232
        //! \name Row Operations
 
233
        //@{
 
234
        void deleteSelectedRows();
 
235
        void insertRow();
 
236
        //@}
 
237
 
 
238
        //! Selection Operations
 
239
        //@{
 
240
        void cutSelection();
 
241
        void copySelection();
 
242
        void clearSelection();
 
243
        void pasteSelection();
 
244
        void selectAllTable();
 
245
        void deselect();
 
246
        void clear();
 
247
        //@}
 
248
 
 
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);
 
259
 
 
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);
 
265
 
 
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);
 
274
 
 
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];};
 
278
 
 
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; }
 
283
 
 
284
        void saveToMemory();
 
285
        void freeMemory();
 
286
 
 
287
        QString columnFormat(int col){return col_format[col];};
 
288
        QStringList getColumnsFormat(){return col_format;};
 
289
        void setColumnsFormat(const QStringList& lst);
 
290
 
 
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);
 
298
 
 
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);
 
305
 
 
306
        //! \name Saving and Restoring
 
307
        //@{
 
308
        virtual QString saveToString(const QString& geometry);
 
309
        QString saveHeader();
 
310
        QString saveComments();
 
311
        QString saveCommands();
 
312
        QString saveColumnWidths();
 
313
        QString saveColumnTypes();
 
314
 
 
315
        void setSpecifications(const QString& s);
 
316
        QString& getSpecifications();
 
317
        void restore(QString& spec);
 
318
        QString& getNewSpecifications();
 
319
        void setNewSpecifications();
 
320
 
 
321
        /*!
 
322
         *used for restoring the table old caption stored in specifications string
 
323
         */
 
324
        QString oldCaption();
 
325
 
 
326
        /*!
 
327
         *used for restoring the table caption stored in new specifications string
 
328
         */
 
329
        QString newCaption();
 
330
        //@}
 
331
 
 
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);
 
337
 
 
338
        int verticalHeaderWidth(){return d_table->verticalHeader()->width();};
 
339
 
 
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;}
 
346
 
 
347
        QString saveAsTemplate(const QString& geometryInfo);
 
348
        void restore(const QStringList& lst);
 
349
 
 
350
        //! This slot notifies the main application that the table has been modified. Triggers the update of 2D plots.
 
351
        void notifyChanges();
 
352
 
 
353
        //! Notifies the main application that the width of a table column has been modified by the user.
 
354
        void colWidthModified(int, int, int);
 
355
 
 
356
signals:
 
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&);
 
368
 
 
369
protected:
 
370
        MyTable *d_table;
 
371
 
 
372
private:
 
373
        bool d_show_comments;
 
374
        QString specifications, newSpecifications;
 
375
        QStringList commands, col_format, comments, col_label;
 
376
        QList<int> colTypes, col_plot_type;
 
377
        int selectedCol;
 
378
        double **d_saved_cells;
 
379
 
 
380
        //! Internal function to change the column header
 
381
        void setColumnHeader(int index, const QString& label);
 
382
};
 
383
 
 
384
#endif