~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/future/table/TableView.h

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : TableView.h
 
3
    Project              : SciDAVis
 
4
    Description          : View class for Table
 
5
    --------------------------------------------------------------------
 
6
    Copyright            : (C) 2007 Tilman Benkert (thzs*gmx.net)
 
7
                           (replace * with @ in the email addresses) 
 
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
 
 
30
#ifndef TABLEVIEW_H
 
31
#define TABLEVIEW_H
 
32
 
 
33
#include <QWidget>
 
34
#include <QTableView>
 
35
#include <QMessageBox>
 
36
#include <QHeaderView>
 
37
#include <QSize>
 
38
#include <QTabWidget>
 
39
#include <QPushButton>
 
40
#include <QToolButton>
 
41
#include <QHBoxLayout>
 
42
#include <QVBoxLayout>
 
43
#include <QLabel>
 
44
#include <QLineEdit>
 
45
#include <QTextEdit>
 
46
#include <QPushButton>
 
47
#include <QComboBox>
 
48
#include <QSpinBox> 
 
49
#include <QScrollArea>
 
50
#include "ui_controltabs.h"
 
51
#include <QtDebug>
 
52
#include "globals.h"
 
53
#include "MyWidget.h"
 
54
#include "lib/IntervalAttribute.h"
 
55
 
 
56
class Column;
 
57
namespace future{ class Table; }
 
58
class TableModel;
 
59
class TableItemDelegate;
 
60
class TableDoubleHeaderView;
 
61
class AbstractAspect;
 
62
 
 
63
//! Helper class for TableView
 
64
class TableViewWidget : public QTableView
 
65
{
 
66
    Q_OBJECT
 
67
 
 
68
        public:
 
69
                //! Constructor
 
70
                TableViewWidget(QWidget * parent = 0) : QTableView(parent) {};
 
71
 
 
72
        protected:
 
73
                //! Overloaded function (cf. Qt documentation)
 
74
                virtual void keyPressEvent(QKeyEvent * event);
 
75
 
 
76
        signals:
 
77
                void advanceCell();
 
78
 
 
79
                protected slots:
 
80
                        //! Cause a repaint of the header
 
81
                        void updateHeaderGeometry(Qt::Orientation o, int first, int last);
 
82
                public slots:
 
83
                        void selectAll();
 
84
};
 
85
 
 
86
//! View class for Table
 
87
class TableView : public MyWidget
 
88
{
 
89
    Q_OBJECT
 
90
 
 
91
        public:
 
92
                //! Constructor
 
93
#ifndef LEGACY_CODE_0_2_x
 
94
                TableView(future::Table * table);
 
95
#else
 
96
                TableView(const QString & label, QWidget * parent=0, const char * name=0, Qt::WFlags f=0);
 
97
                void setTable(future::Table * table);
 
98
#endif
 
99
                //! Destructor
 
100
                virtual ~TableView();
 
101
                bool isControlTabBarVisible() { return d_control_tabs->isVisible(); }
 
102
                //! Show or hide (if on = false) the column comments
 
103
                void showComments(bool on = true);
 
104
                //! Return whether comments are show currently
 
105
                bool areCommentsShown() const;
 
106
 
 
107
                //! \name selection related functions
 
108
                //@{
 
109
                //! Return how many columns are selected
 
110
                /**
 
111
                 * If full is true, this function only returns the number of fully 
 
112
                 * selected columns.
 
113
                 */
 
114
                int selectedColumnCount(bool full = false);
 
115
                //! Return how many columns with the given plot designation are (at least partly) selected
 
116
                int selectedColumnCount(SciDAVis::PlotDesignation pd);
 
117
                //! Returns true if column 'col' is selected; otherwise false
 
118
                /**
 
119
                 * If full is true, this function only returns true if the whole 
 
120
                 * column is selected.
 
121
                 */
 
122
                bool isColumnSelected(int col, bool full = false);
 
123
                //! Return all selected columns
 
124
                /**
 
125
                 * If full is true, this function only returns a column if the whole 
 
126
                 * column is selected.
 
127
                 */
 
128
                QList<Column *> selectedColumns(bool full = false);
 
129
                //! Return how many rows are (at least partly) selected
 
130
                /**
 
131
                 * If full is true, this function only returns the number of fully 
 
132
                 * selected rows.
 
133
                 */
 
134
                int selectedRowCount(bool full = false);
 
135
                //! Returns true if row 'row' is selected; otherwise false
 
136
                /**
 
137
                 * If full is true, this function only returns true if the whole 
 
138
                 * row is selected.
 
139
                 */
 
140
                bool isRowSelected(int row, bool full = false);
 
141
                //! Return the index of the first selected column
 
142
                /**
 
143
                 * If full is true, this function only looks for fully 
 
144
                 * selected columns.
 
145
                 */
 
146
                int firstSelectedColumn(bool full = false);
 
147
                //! Return the index of the last selected column
 
148
                /**
 
149
                 * If full is true, this function only looks for fully 
 
150
                 * selected columns.
 
151
                 */
 
152
                int lastSelectedColumn(bool full = false);
 
153
                //! Return the index of the first selected row
 
154
                /**
 
155
                 * If full is true, this function only looks for fully 
 
156
                 * selected rows.
 
157
                 */
 
158
                int firstSelectedRow(bool full = false);
 
159
                //! Return the index of the last selected row
 
160
                /**
 
161
                 * If full is true, this function only looks for fully 
 
162
                 * selected rows.
 
163
                 */
 
164
                int lastSelectedRow(bool full = false);
 
165
                //! Get the complete set of selected rows.
 
166
                IntervalAttribute<bool> selectedRows(bool full = false);
 
167
                //! Return whether a cell is selected
 
168
                bool isCellSelected(int row, int col);
 
169
                //! Select/Deselect a cell
 
170
                void setCellSelected(int row, int col, bool select = true);
 
171
                //! Select/Deselect a range of cells
 
172
                void setCellsSelected(int first_row, int first_col, int last_row, int last_col, bool select = true);
 
173
                //! Determine the current cell (-1 if no cell is designated as the current)
 
174
                void getCurrentCell(int * row, int * col);
 
175
                //@}
 
176
 
 
177
                void setColumnWidth(int col, int width);
 
178
                int columnWidth(int col) const;
 
179
                bool formulaModeActive() const;
 
180
 
 
181
        public slots:
 
182
                void activateFormulaMode(bool on);
 
183
                void goToCell(int row, int col);
 
184
                void rereadSectionSizes();
 
185
                void selectAll();
 
186
                void deselectAll();
 
187
                void toggleControlTabBar();
 
188
                void toggleComments();
 
189
                void showControlDescriptionTab();
 
190
                void showControlTypeTab();
 
191
                void showControlFormulaTab();
 
192
                void handleHorizontalSectionResized(int logicalIndex, int oldSize, int newSize); 
 
193
                void goToNextColumn();
 
194
                void goToPreviousColumn();
 
195
 
 
196
        protected slots:
 
197
                //! Advance current cell after [Return] or [Enter] was pressed
 
198
                void advanceCell();
 
199
                void handleHorizontalSectionMoved(int index, int from, int to);
 
200
                void handleHorizontalHeaderDoubleClicked(int index);
 
201
                void handleAspectDescriptionChanged(const AbstractAspect * aspect);
 
202
                void handleAspectAdded(const AbstractAspect *aspect);
 
203
                void handleAspectAboutToBeRemoved(const AbstractAspect *aspect, int index);
 
204
                void updateTypeInfo();
 
205
                void updateFormatBox();
 
206
                void handleHeaderDataChanged(Qt::Orientation orientation, int first, int last);
 
207
                void currentColumnChanged(const QModelIndex & current, const QModelIndex & previous);
 
208
                void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
 
209
                void applyDescription();
 
210
                void applyType();
 
211
 
 
212
        protected:
 
213
                //! Pointer to the item delegate
 
214
                TableItemDelegate * d_delegate;
 
215
                //! Pointer to the current underlying model
 
216
                TableModel * d_model;
 
217
 
 
218
                virtual void changeEvent(QEvent * event);
 
219
                void retranslateStrings();
 
220
                void setColumnForControlTabs(int col);
 
221
 
 
222
                bool eventFilter( QObject * watched, QEvent * event);
 
223
 
 
224
                //! UI with options tabs (description, format, formula etc.)
 
225
                Ui::ControlTabs ui;
 
226
                //! The table view (first part of the UI)
 
227
                TableViewWidget * d_view_widget;
 
228
                //! Widget that contains the control tabs UI from #ui
 
229
                QWidget * d_control_tabs;
 
230
                //! Button to toogle the visibility of #d_tool_box
 
231
                QToolButton * d_hide_button;
 
232
                QHBoxLayout * d_main_layout;
 
233
                TableDoubleHeaderView * d_horizontal_header;
 
234
                future::Table * d_table;
 
235
 
 
236
                //! Initialization
 
237
                void init();
 
238
};
 
239
 
 
240
 
 
241
#endif