SciDAVis  1.D4
Table.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : Table.h
3  Project : SciDAVis
4  Description : Table worksheet class
5  --------------------------------------------------------------------
6  Copyright : (C) 2006-2009 Tilman Benkert (thzs*gmx.net)
7  Copyright : (C) 2006-2009 Knut Franke (knut.franke*gmx.de)
8  Copyright : (C) 2006-2007 Ion Vasilief (ion_vasilief*yahoo.fr)
9  (replace * with @ in the email addresses)
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 <QVarLengthArray>
35 #include <QDateTime>
36 #include <QHash>
37 #include <QMap>
38 
39 #include "Graph.h"
40 #include "MyWidget.h"
41 #include "ScriptingEnv.h"
42 #include "Script.h"
44 #include "future/table/TableView.h"
45 #include "globals.h"
46 
49 class Table: public TableView, public scripted
50 {
51  Q_OBJECT
52 
53 public:
55 
56  enum ColType{Numeric = 0, Text = 1, Date = 2, Time = 3, Month = 4, Day = 5, DateTime = 6}; // TODO: remove this in favor of SciDAVis::columnMode
57 
58  Table(ScriptingEnv *env, const QString &fname,const QString &sep, int ignoredLines, bool renameCols,
59  bool stripSpaces, bool simplifySpaces, bool convertToNumeric, QLocale numericFormat, const QString &label,
60  QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
61  Table(ScriptingEnv *env, int r,int c, const QString &label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
62 
64  void setNumericPrecision(int prec);
65 
67  virtual QString name() { return d_future_table->name();}
69  virtual void setName(const QString& s) { d_future_table->setName(s); }
71  virtual QString windowLabel() { return d_future_table->comment(); }
73  virtual void setWindowLabel(const QString& s) { d_future_table->setComment(s); updateCaption(); }
76  {
77  caption_policy = policy; updateCaption();
78  switch (policy)
79  {
80  case Name:
82  break;
83  case Label:
85  break;
86  case Both:
87  d_future_table->setCaptionSpec("%n%C{ - }%c");
88  break;
89  }
90  }
92  virtual void setBirthDate(const QString& s)
93  {
94  birthdate = s;
96  }
97 
98  void closeEvent( QCloseEvent *);
99 public slots:
100  void copy(Table *m);
101  int numRows();
102  int numCols();
103  int rowCount();
104  int columnCount();
105  void setNumRows(int rows);
106  void setNumCols(int cols);
107  void handleChange();
108  void handleRowChange();
109  void handleColumnChange(int,int);
110  void handleColumnChange(int,int,int,int);
111  void handleColumnsAboutToBeRemoved(int,int);
112  void handleColumnsRemoved(int,int);
113 
115  Column* column(int index) const { return d_future_table->column(index); }
117 
122  Column* column(const QString & name) const { return d_future_table->column(name); }
123 
125 
131  double cell(int row, int col);
132  void setCell(int row, int col, double val);
133 
134  QString text(int row, int col);
135  QStringList columnsList();
136  QStringList colNames();
137  QString colName(int col);
138  QString colLabel(int col);
139  int colIndex(const QString& name);
140 
144  QList<int> plotDesignations();
145 
146  void setColName(int col,const QString& text);
147  void setHeader(QStringList header);
148  void importV0x0001XXHeader(QStringList header);
149  void setText(int row,int col,const QString & text);
150 
151  void clearCell(int row, int col);
152 
153  void print();
154  void print(const QString& fileName);
155  void exportPDF(const QString& fileName);
156  void customEvent(QEvent* e);
157 
159 
160  void removeCol();
161  void removeCol(const QStringList& list);
162  void clearCol();
163  void insertCol();
164  void insertCols(int start, int count);
166  void addColumns(int c);
168 
169  int firstXCol();
170  bool noXColumn();
171  bool noYColumn();
172  int colX(int col);
173  int colY(int col);
174 
176  void setCommands(const QStringList& com);
178  void setCommands(const QString& com);
180  void setCommand(int col, const QString& com);
182  bool recalculate(int col, bool only_selected_rows=true);
184  bool recalculate();
185 
187 
188  void deleteSelectedRows();
189  void insertRow();
191 
193 
194  void cutSelection();
195  void copySelection();
196  void clearSelection();
197  void pasteSelection();
198  void selectAllTable();
199  void deselect();
200  void clear();
202 
203  void init();
204  QStringList selectedColumns();
205  QStringList selectedYColumns();
206  QStringList selectedErrColumns();
207  QMap<int, QString> selectedYLabels();
208  QStringList drawableColumnSelection();
209  QStringList YColumns();
210  int selectedColsNumber();
211 
212  int columnWidth(int col);
213  void setColWidths(const QStringList& widths);
214 
215  int numSelectedRows();
216 
217  int columnType(int col);
218 
219  QList<int> columnTypes();
220  void setColumnTypes(QList<int> ctl);
221  void setColumnTypes(const QStringList& ctl);
222  void setColumnType(int col, SciDAVis::ColumnMode mode);
223 
224 
225  QString columnFormat(int col);
226 
227  void importASCII(const QString &fname, const QString &sep, int ignoredLines,
228  bool renameCols, bool stripSpaces, bool simplifySpaces, bool newTable);
229  bool exportASCII(const QString& fname, const QString& separator,
230  bool withLabels = false, bool exportSelection = false);
231 
233 
234  virtual QString saveToString(const QString& geometry);
235  void saveToDevice(QIODevice *device, const QString &geometry);
236  QString saveHeader();
237  QString saveComments();
238  QString saveCommands();
239  QString saveColumnWidths();
240  QString saveColumnTypes();
242 
243  void setBackgroundColor(const QColor& col);
244  void setTextColor(const QColor& col);
245  void setHeaderColor(const QColor& col);
246  void setTextFont(const QFont& fnt);
247  void setHeaderFont(const QFont& fnt);
248 
249  int verticalHeaderWidth();
250 
251  QString colComment(int col);
252  void setColComment(int col, const QString& s);
253  QStringList colComments();
254  void setColComments(const QStringList& lst);
255  bool commentsEnabled();
256 
257  QString saveAsTemplate(const QString& geometryInfo);
258  void restore(const QStringList& lst);
259 
260 signals:
261  void changedColHeader(const QString&, const QString&);
262  void aboutToRemoveCol(const QString&);
263  void removedCol(const QString&);
264  void modifiedData(Table *, const QString&);
265  void resizedTable(QWidget*);
266  void showContextMenu(bool selection);
267 
268 protected slots:
269  void applyFormula();
270  void addFunction();
271  void addReference();
272  void updateFunctionDoc();
275 
276 private:
277  QHash<const AbstractAspect *, QString> d_stored_column_labels;
278 };
279 
280 #endif