SciDAVis  1.D4
future_Table.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : Table.h
3  Project : SciDAVis
4  Description : Aspect providing a spreadsheet table with column logic
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 FUTURE_TABLE_H
32 #define FUTURE_TABLE_H
33 
34 #include "core/AbstractPart.h"
35 #ifndef LEGACY_CODE_0_2_x
36 #include "AbstractScriptingEngine.h"
37 #endif
38 #include "globals.h"
39 #include <QList>
40 #include <QStringList>
41 
42 class TableView;
43 class QUndoStack;
44 class QMenu;
45 class Column;
46 class QPoint;
47 class QAction;
48 class AbstractColumn;
49 class ActionManager;
50 class TableStatistics;
51 class TeXTableSettings;
52 
53 namespace future
54 {
55 
79 #ifndef LEGACY_CODE_0_2_x
80 class Table : public AbstractPart, public scripted
81 #else
82 class Table : public AbstractPart
83 #endif
84 {
85  Q_OBJECT
86 
87  public:
88  class Private; // This could also be private, but then all commands need to be friend classes
89  friend class Private;
90 
91 #ifndef LEGACY_CODE_0_2_x
92  Table(AbstractScriptingEngine *engine, int rows, int columns, const QString &name);
93 #else
94  Table(void *engine, int rows, int columns, const QString &name);
95  void setView(TableView * view);
96  friend class ::TableStatistics;
97 #endif
98  virtual ~Table();
99 
101  virtual QIcon icon() const;
103 
106  virtual QMenu *createContextMenu() const;
108 
112  virtual QWidget *view();
113 
115 
120  void insertColumns(int before, QList<Column *> new_cols);
122  /*
123  * Convenience function, same as:
124  * <code>
125  * insertColumns(columnCount(), new_cols);
126  * </code>
127  */
128  void appendColumns(QList<Column*> new_cols) { insertColumns(columnCount(), new_cols); }
129  void removeColumns(int first, int count);
130  void removeColumn(Column * col);
131  void removeRows(int first, int count);
132  void insertRows(int before, int count);
133  void appendRows(int count) { insertRows(rowCount(), count); }
135  void setRowCount(int new_size);
137  int columnCount() const;
139  int rowCount() const;
143  Column* column(int index) const;
145 
150  Column* column(const QString & name, bool legacy_kludge=true) const;
151  int columnIndex(const Column * col) const;
153  void setColumnCount(int new_size);
154  QVariant headerData(int section, Qt::Orientation orientation,int role) const;
155 
157 
162  QMenu * createSelectionMenu(QMenu * append_to = 0);
164 
169  QMenu * createColumnMenu(QMenu * append_to = 0);
171 
176  QMenu * createRowMenu(QMenu * append_to = 0);
178 
183  QMenu * createTableMenu(QMenu * append_to = 0);
185 
188  virtual bool fillProjectMenu(QMenu * menu);
190 
193  virtual bool fillProjectToolBar(QToolBar * bar);
194 
196  int colX(int col);
198  int colY(int col);
200 
203  void setPlotMenu(QMenu * menu);
205  void sortDialog(QList<Column*> cols);
207  static void setDefaultCommentVisibility(bool visible) { d_default_comment_visibility = visible; }
211  QString text(int row, int col);
213  void copy(Table * other);
214 
216 
217 
218  virtual void save(QXmlStreamWriter *) const;
220  virtual bool load(XmlStreamReader *);
223 
224  public:
225  static ActionManager * actionManager();
226  static void initActionManager();
227  static int defaultColumnWidth() { return default_column_width; }
228  static void setDefaultColumnWidth(int width) { default_column_width = width; }
229  private:
231  // TODO: the default sizes are to be controlled by the global Table settings
234  Table();
235 
236  public slots:
238  void clear();
239 #ifndef LEGACY_CODE_0_2_x
240 
241  void clearMasks();
242 #endif
243 
245  void addColumn();
247  void addColumns();
249  void addRows();
250  void cutSelection();
251  void copySelection();
252  void pasteIntoSelection();
253  void clearSelectedCells();
254  void goToCell();
255 #ifndef LEGACY_CODE_0_2_x
256  void maskSelection();
257  void unmaskSelection();
258 #endif
259  void setFormulaForSelection();
264  void sortTable();
266  void insertEmptyColumns();
267  void removeSelectedColumns();
268  void clearSelectedColumns();
269  void setSelectedColumnsAsX();
270  void setSelectedColumnsAsY();
271  void setSelectedColumnsAsZ();
275  void normalizeColumns(QList< Column* > cols);
277  void normalizeSelection();
278  void sortSelectedColumns();
282  void insertEmptyRows();
283  void removeSelectedRows();
284  void selectAll();
285  void dimensionsDialog();
288  void moveColumn(int from, int to);
290  /*
291  * If 'leading' is a null pointer, each column is sorted separately.
292  */
293  void sortColumns(Column * leading, QList<Column*> cols, bool ascending);
295 
298  void showTableViewContextMenu(const QPoint& pos);
300 
303  void showTableViewColumnContextMenu(const QPoint& pos);
305 
308  void showTableViewRowContextMenu(const QPoint& pos);
309 
312 
314  /*
315  * \param file name
316  * \param TeX tale settings
317  */
318  bool export_to_TeX( QString fileName, TeXTableSettings& tex_settings );
319 
320 
321 
322  protected:
324 
328  virtual void completeAspectInsertion(AbstractAspect * aspect, int index);
330 
334  virtual void prepareAspectRemoval(AbstractAspect * aspect);
335 
336  public:
338 
341  void setColumnWidth(int col, int width);
342  int columnWidth(int col) const;
343 
344  private:
346  void connectColumn(const Column* col);
348  void disconnectColumn(const Column* col);
349 
350  private slots:
352 
353  void handleDescriptionChange(const AbstractAspect * aspect);
354  void handleModeChange(const AbstractColumn * col);
356  void handleDataChange(const AbstractColumn * col);
357  void handleRowsAboutToBeInserted(const AbstractColumn * col, int before, int count);
358  void handleRowsInserted(const AbstractColumn * col, int before, int count);
359  void handleRowsAboutToBeRemoved(const AbstractColumn * col, int first, int count);
360  void handleRowsRemoved(const AbstractColumn * col, int first, int count);
362  void adjustActionNames();
363 
364  signals:
365  void columnsAboutToBeInserted(int before, QList<Column*> new_cols);
366  void columnsInserted(int first, int count);
367  void columnsAboutToBeReplaced(int first, int count);
368  void columnsReplaced(int first, int count);
369  void columnsAboutToBeRemoved(int first, int count);
370  void columnsRemoved(int first, int count);
371  void rowsAboutToBeInserted(int before, int count);
372  void rowsInserted(int first, int count);
373  void rowsAboutToBeRemoved(int first, int count);
374  void rowsRemoved(int first, int count);
375  void dataChanged(int top, int left, int bottom, int right);
376  void headerDataChanged(Qt::Orientation orientation, int first, int last);
377 #ifdef LEGACY_CODE_0_2_x
378  void recalculate();
379  void requestRowStatistics();
380  void requestColumnStatistics();
381 #endif
382 
383  private:
384  void createActions();
385  void connectActions();
386  void addActionsToView();
387  QMenu * d_plot_menu;
389 
391 
395 #ifndef LEGACY_CODE_0_2_x
398 #endif
406 
407 
410  QAction * action_select_all;
411  QAction * action_add_column;
414 #ifndef LEGACY_CODE_0_2_x
416 #endif
417  QAction * action_sort_table;
418  QAction * action_go_to_cell;
422 
423 
428  QAction * action_set_as_x;
429  QAction * action_set_as_y;
430  QAction * action_set_as_z;
440 
441 
444  QAction * action_clear_rows;
445  QAction * action_add_rows;
448 
451 };
452 
481 {
482  public:
483  Private(Table *owner) : d_owner(owner), d_column_count(0), d_row_count(0) {}
485 
490  void replaceColumns(int first, QList<Column*> new_cols);
492 
498  void insertColumns(int before, QList<Column*> cols);
500 
506  void removeColumns(int first, int count);
508 
511  void appendColumns(QList<Column*> cols);
513  void moveColumn(int from, int to);
515  int columnCount() const { return d_column_count; }
517  int rowCount() const { return d_row_count; }
519  void setRowCount(int count);
521  QString columnHeader(int col);
525  Column* column(int index) const;
527 
530  int columnIndex(const Column * col) const
531  {
532  for(int i=0; i<d_columns.size(); i++)
533  if(d_columns.at(i) == col) return i;
534  return -1;
535  }
536  QString name() const { return d_owner->name(); }
537  QVariant headerData(int section, Qt::Orientation orientation,int role) const;
538 
540 
545  void updateVerticalHeader(int start_row);
547 
554  void updateHorizontalHeader(int start_col, int end_col);
555  void setColumnWidth(int col, int width) { d_column_widths[col] = width; }
556  int columnWidth(int col) const { return d_column_widths.at(col); }
557 
558  private:
570  QList<Column *> d_columns;
572 
575  void composeColumnHeader(int col, const QString& label);
577  QList<int> d_column_widths;
578 };
579 
580 } // namespace
581 
582 #endif
583