casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBDataTab.qo.h
Go to the documentation of this file.
1 //# TBDataTab.qo.h: Widget used to display table data.
2 //# Copyright (C) 2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef TBDATATAB_H_
28 #define TBDATATAB_H_
29 
30 #include <casaqt/QtBrowser/TBDataTab.ui.h>
31 
32 #include <vector>
33 
34 #include <casa/BasicSL/String.h>
35 
36 namespace casa {
37 
38 //# Forward Declarations
39 class TBTable;
40 class QCloseableWidget;
41 class TBFilterRuleSequence;
42 class TBFormat;
43 class QFontColor;
44 class TBTableTabs;
45 class ProgressHelper;
46 class TBArrayPanel;
47 class TBData;
48 
49 // <summary>
50 // Subclass of QTableWidgetItem that allows for custom sorting.
51 // <summary>
52 //
53 // <synopsis>
54 // TBDataItem takes a value and a type. The object saves the value in two
55 // ways using Qt::DisplayRole and Qt::UserRole. The value is stored as a
56 // string using QtDisplayRole, and this is what is actually shown in the
57 // QTableWidget. The data stored with Qt::UserRole, however, may be of a
58 // different type, such as an integer. This storage is used when sorting
59 // so that, for example, numbers can be sorted numerically rather than
60 // lexiographically. casacore::Array types are sorted using the first element for
61 // one-dimensional arrays and the first dimension for other arrays.
62 // </synopsis>
63 
64 class TBDataItem : public QTableWidgetItem {
65 public:
66  // Constructor to take the casacore::String value and the type.
67  //TBDataItem(casacore::String value, casacore::String type);
68 
70 
71  ~TBDataItem();
72 
73 
74  // Override QTableWidgetItem's less-than operator. Returns true if the
75  // value of this TBDataItem is less than that of the given TBDataItem,
76  // false otherwise. If other is not of type TBDataItem, the behavior is
77  // undefined. Also, since this operator is only used for custom sorting,
78  // the other TBDataItem is assumed to have the same type as this one.
79  virtual bool operator<(const QTableWidgetItem& other) const;
80 
81 private:
82  // Holds the data type.
84 
85  // Is true if the value stored for Qt::UserRole is an array dimension,
86  // false otherwise.
88 
90 
91 
92  // Set the Qt::UserRole and, if text is true, the Qt::DisplayRole values.
93  void set(casacore::String value, bool text);
94 };
95 
96 // <summary>
97 // Widget used to display table data.
98 // <summary>
99 //
100 // <synopsis>
101 // TBDataTab is the tab responsible for displaying table data in a
102 // QTableWidget. It also provides functionality for changing page and number
103 // of rows loaded, catching and passing on edit events, and handling
104 // double-click events.
105 // </synopsis>
106 
107 class TBDataTab : public QWidget, Ui::DataTab {
108  Q_OBJECT
109 
110 public:
111  // Constructor that takes the parent TBTableTabs.
112  TBDataTab(TBTableTabs* tt);
113 
114  ~TBDataTab();
115 
116 
117  // Returns the QTableWidget that displays the data.
118  QTableWidget* getTableWidget();
119 
120  // Returns the QBrush that is used to draw the background of any selected
121  // cells in the QTableWidget.
122  QBrush& getSelectedCellBackground();
123 
124  // Retruns the QBrush that is used to draw the background of any unselected
125  // cells in the QTableWidget.
126  QBrush& getUnselectedCellBackground();
127 
128  // Returns the current row filter, or NULL if there is none.
130 
131  // Sets the current filter to the given rules, but does NOT apply it.
132  void setFilter(TBFilterRuleSequence* rule);
133 
134  // Returns the current format for the field at the given index, or NULL if
135  // there is none.
136  TBFormat* formatAt(int index);
137 
138  // Returns the current sort on the displayed data. Each pair in the vector
139  // is the name of the field with a bool indicating whether the sort is
140  // ascending or not.
141  std::vector<std::pair<casacore::String, bool> >* getSortFields();
142 
143 
144  // Updates the QTableWidget with new data that has been loaded into the
145  // table backend. If a ProgressHelper is provided, it will be updated
146  // periodically with progress information.
147  void updateTable(ProgressHelper* pp = NULL);
148 
149  // Sets the given cell in the QTableWidget to the new value, but does NOT
150  // update the backend. If format is true, then any existing format will
151  // be applied to the new value.
152  void setData(int row, int col, TBData* newVal, bool format = true);
153 
154  // Loads the given page into the table backend, which then updates the
155  // display. If the page is valid, the result of TBTableTabs::loadRows()
156  // is returned; otherwise false is returned.
157  bool loadPage(int p);
158 
159  // Refreshes the table backend using TBTable::refresh(), then updates the
160  // displayed data using setData().
161  void refresh(int row, int col, bool format = true);
162 
163  // Sorts the displayed data with the given order. Each pair in the vector
164  // is the name of the field with a bool indicating whether the sort is
165  // ascending or not.
166  void sortBy(std::vector<std::pair<casacore::String, bool> >& s);
167 
168  // Sets the sort indicator on the QTableWidget for the given column with an
169  // ascending arrow if asc is true or a descending arrow otherwise.
170  void setSortIndicator(int index, bool asc);
171 
172  // Clears the sort indicator on the QTableWidget.
173  void clearSortIndicator();
174 
175  // Selects and highlights the given row in the table widget.
176  void highlight(int row);
177 
178  // Returns the visible index for the row with the given logical index.
179  // Rows may have differing visible and logical indices when a sort has
180  // been entered.
181  int visibleIndex(int logicalIndex);
182 
183  // Returns the logical index for the row with the given visible index.
184  // Rows may have differing visible and logical indices when a sort has
185  // been entered.
186  int logicalIndex(int visibleIndex);
187 
188  // Hides (or shows) the column with the given index. Whether the column
189  // is shown or hidden depends on the "hidden" parameter.
190  void hideColumn(int index, bool hidden);
191 
192  // Opens a format dialog for the field with the given index. Applies the
193  // format that the user enters.
194  void formatField(int index);
195 
196  //Remembers whether you pressed the next or previous button. Uses this
197  //when filter rules are applied to avoid displaying blank pages.
198  bool goForward;
199 
200 public slots:
201  // Shows the given widget in the side panel. isArray should be true if
202  // the widget is a TBViewArray, false otherwise.
203  void showWidgetInSplitter(QWidget* widget, bool isArray = false);
204 
205  // Clears whatever widget (if any) is currently being displayed in the side
206  // panel.
207  void clearWidgetInSplitter();
208 
209  // Applies the given format to the field at the given index.
210  void applyFormat(int index, TBFormat* format);
211 
212  // Clears the format on the field at the given index.
213  void clearFormat(int index);
214 
215  // Clears all formats on all fields.
216  void clearAllFormats();
217 
218 signals:
219  // This signal is emitted when the user has edited a cell. The parameter
220  // describe which cell was edited and its new value.
221  void dataChanged(int row, int col, casacore::String newVal);
222 
223  // This signal is emitted when the side panel is closed. The QWidget
224  // points to the widget that was just closed.
225  void rightWidgetClosed(QWidget* which);
226 
227  // This signal is emitted when the user right-clicks on an index and
228  // selects the "Follow subtable index reference" command. The String
229  // indicates which subtable was chosen, and the index indicates the chosen
230  // index which is the value of the cell that was right-clicked on.
231  void followReferenceRequested(casacore::String subtable, int index);
232 
233  // This signal is emitted when a sort is applied to the table.
234  void sortEntered();
235 
236  // This signal is emitted when a sort is cleared from the table.
237  void sortCleared();
238 
239  // This signal is emitted when a column is shown or hidden.
240  void columnHidden(int index, bool hidden);
241 
242 protected:
243  // Catches the right-click event; if the right click is on a table cell and
244  // the displayed data could be an index, show the subtable index reference
245  // menu. Also show action for copying to the clipboard.
246  void contextMenuEvent(QContextMenuEvent* event);
247 
248 private:
249  // Useful pointers to table backend.
250  // <group>
253  // </group>
254 
255  // The currently loaded page.
256  int page;
257 
258  // How many rows per page are loaded at once.
259  int loadRows;
260 
261  // Side panel.
263 
264  // casacore::List of cells that are highlighted (the row and column of the currently
265  // selected cell).
266  std::vector<QTableWidgetItem*> highlightedCells;
267 
268  // Brushes used to draw the backgrounds of unselected and selected cells in
269  // the QTableWidget, respectively.
270  // <group>
273  // </group>
274 
275  // Current row filter, or NULL if there is none.
277 
278  // Current field formats.
279  std::vector<TBFormat*> formats;
280 
281  // "Cleared" format for cell text.
283 
284  // Indicates whether the side panel is currently open with an array or not.
286 
287  // Points to the current array panel, or NULL if there is none.
289 
290  // Keeps track of the un-sorted order of the rows.
291  // Doing rowItems[logicalRow]->row() returns the visualRow.
292  std::vector<QTableWidgetItem*> rowItems;
293 
294  // Keeps track of the un-sorted order of the rows.
295  // Doing rowIndices[visualRow] returns the logicalRow.
296  std::vector<int> rowIndices;
297 
298  // The current sort order.
299  std::vector<std::pair<casacore::String, bool> > currSort;
300 
301  // Used for handling right-clicks on headers. Keeps track of the last
302  // right-clicked header column number.
304 
305 
306  // Update widgets that keep track of what page the browser is on.
307  void updatePageTrackers();
308 
309  // Sorts on the given row. If asc is true, sorts in ascending order,
310  // otherwise sorts in descending order.
311  void sort(int col, bool asc);
312 
313  // Applies the current filter to the displayed rows.
314  void applyFilter();
315 
316 private slots:
317  // Slot for page back button. Goes back a page.
318  void pageBack();
319 
320  // Slot for page forward button. Goes forward a page.
321  void pageForward();
322 
323  // Slot to go to first page.
324  void pageFirst();
325 
326  // Slot to go to last page.
327  void pageLast();
328 
329  // Slot for page go button. Goes to the page specified in the page line
330  // edit.
331  void pageGo();
332 
333  // Slot for QTableWidget::cellChanged(). Catches changes from the
334  // QTableWidget and emits signals as needed.
335  void notifyDataChanged(int row, int col);
336 
337  // Slot for QTableWidget::currentCellChanged(). Updates the display to
338  // highlight the row and column of the selected cell.
339  void cellClicked(int row, int col);
340 
341  // Slot for the menu command chosen from the reference menu shown on a
342  // right click. Catches which subtable the user followed a reference and
343  // emits signals as needed.
344  void referenceMenuClicked(QAction* which);
345 
346  // Slot for QTableWidget::cellDoubleClicked(). Catches a double-click
347  // event on a cell in the QTableWidget. If the value is a table type,
348  // opens the indicated table in a new tab. If the value is an array type,
349  // opens the array in the side panel. Otherwise, if the table is currently
350  // editable, enters into editing mode on that cell.
351  void doubleClicked(int row, int col);
352 
353  // Displays the tooltip for the last clicked header in a dialog.
354  void displayFieldInfo();
355 
356  // Displays statistics (min, max, mean) for the last clicked header in a
357  // dialog.
358  void displayFieldStatistics();
359 
360  // Hides the column that was just right-clicked.
361  void hideColumn();
362 
363  // Formats the field that was just right-clicked.
364  void formatField();
365 
366  // Slot for when a column header is moved. Enables the "restore columns"
367  // button.
368  void headerMoved();
369 
370  // Slot for the restore columns button. Moves all columns back to their
371  // original locations.
372  void restoreColumns();
373 
374  // Slot for the resize headers button. Resizes the row and column headers
375  // to fit displayed contents. See QTableWidget::resizeRowsToContents() and
376  // QTableWidget::resizeColumnsToContents().
377  void resizeHeaders();
378 
379  // Slot for QHeaderView::sectionClicked(). Catches a sorting click event
380  // on a column header and sorts accordingly.
381  void headerClicked(int index);
382 
383  // Slot for the clear sort button. Clears the sort on the table by moving
384  // the rows back to their original order.
385  void clearSort();
386 
387  // Slot for copying the currently selected text into the system clipboard.
388  void copyData();
389 };
390 
391 }
392 
393 #endif /* TBDATATAB_H_ */
void rightWidgetClosed(QWidget *which)
This signal is emitted when the side panel is closed.
void clearFormat(int index)
Clears the format on the field at the given index.
void copyData()
Slot for copying the currently selected text into the system clipboard.
void pageBack()
Slot for page back button.
int loadRows
How many rows per page are loaded at once.
Definition: TBDataTab.qo.h:259
bool arrayOpened
Indicates whether the side panel is currently open with an array or not.
Definition: TBDataTab.qo.h:285
void refresh(int row, int col, bool format=true)
Refreshes the table backend using TBTable::refresh(), then updates the displayed data using setData()...
void formatField()
Formats the field that was just right-clicked.
void setData(int row, int col, TBData *newVal, bool format=true)
Sets the given cell in the QTableWidget to the new value, but does NOT update the backend...
void clearSortIndicator()
Clears the sort indicator on the QTableWidget.
int page
The currently loaded page.
Definition: TBDataTab.qo.h:256
void set(casacore::String value, bool text)
Set the Qt::UserRole and, if text is true, the Qt::DisplayRole values.
void restoreColumns()
Slot for the restore columns button.
QBrush & getUnselectedCellBackground()
Retruns the QBrush that is used to draw the background of any unselected cells in the QTableWidget...
void pageForward()
Slot for page forward button.
void applyFilter()
Applies the current filter to the displayed rows.
TBTableTabs * ttabs
Useful pointers to table backend.
Definition: TBDataTab.qo.h:251
void referenceMenuClicked(QAction *which)
Slot for the menu command chosen from the reference menu shown on a right click.
TBTable * table
Definition: TBDataTab.qo.h:252
void displayFieldInfo()
Displays the tooltip for the last clicked header in a dialog.
casacore::Data types used for loaded data.
Definition: TBData.h:51
QBrush unselectedBackground
Brushes used to draw the backgrounds of unselected and selected cells in the QTableWidget, respectively.
Definition: TBDataTab.qo.h:271
void headerClicked(int index)
Slot for QHeaderView::sectionClicked().
Subclass of QTableWidgetItem that allows for custom sorting.
Definition: TBDataTab.qo.h:64
void clearAllFormats()
Clears all formats on all fields.
int logicalIndex(int visibleIndex)
Returns the logical index for the row with the given visible index.
TBFormat * formatAt(int index)
Returns the current format for the field at the given index, or NULL if there is none.
Widget used to display table data.
Definition: TBDataTab.qo.h:107
void showWidgetInSplitter(QWidget *widget, bool isArray=false)
Shows the given widget in the side panel.
void displayFieldStatistics()
Displays statistics (min, max, mean) for the last clicked header in a dialog.
void hideColumn()
Hides the column that was just right-clicked.
TBFilterRuleSequence * getFilter()
Returns the current row filter, or NULL if there is none.
QCloseableWidget * rightWidget
Side panel.
Definition: TBDataTab.qo.h:262
void contextMenuEvent(QContextMenuEvent *event)
Catches the right-click event; if the right click is on a table cell and the displayed data could be ...
void clearWidgetInSplitter()
Clears whatever widget (if any) is currently being displayed in the side panel.
std::vector< std::pair< casacore::String, bool > > * getSortFields()
Returns the current sort on the displayed data.
void followReferenceRequested(casacore::String subtable, int index)
This signal is emitted when the user right-clicks on an index and selects the &quot;Follow subtable index ...
void sortBy(std::vector< std::pair< casacore::String, bool > > &s)
Sorts the displayed data with the given order.
void pageFirst()
Slot to go to first page.
std::vector< int > rowIndices
Keeps track of the un-sorted order of the rows.
Definition: TBDataTab.qo.h:296
void updatePageTrackers()
Update widgets that keep track of what page the browser is on.
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
bool arrayDimension
Is true if the value stored for Qt::UserRole is an array dimension, false otherwise.
Definition: TBDataTab.qo.h:87
Wrapper around a QProgressPanel or other QLabel/QProgressBar pairing.
virtual bool operator<(const QTableWidgetItem &other) const
Override QTableWidgetItem&#39;s less-than operator.
TBFilterRuleSequence * filter
Current row filter, or NULL if there is none.
Definition: TBDataTab.qo.h:276
void pageGo()
Slot for page go button.
QBrush selectedBackground
Definition: TBDataTab.qo.h:272
void notifyDataChanged(int row, int col)
Slot for QTableWidget::cellChanged().
std::vector< QTableWidgetItem * > rowItems
Keeps track of the un-sorted order of the rows.
Definition: TBDataTab.qo.h:292
Rules used to format displayed values for fields.
Definition: TBFormat.qo.h:79
void dataChanged(int row, int col, casacore::String newVal)
This signal is emitted when the user has edited a cell.
void sortCleared()
This signal is emitted when a sort is cleared from the table.
void updateTable(ProgressHelper *pp=NULL)
Updates the QTableWidget with new data that has been loaded into the table backend.
std::vector< QTableWidgetItem * > highlightedCells
casacore::List of cells that are highlighted (the row and column of the currently selected cell)...
Definition: TBDataTab.qo.h:266
void headerMoved()
Slot for when a column header is moved.
int clickedHeader
Used for handling right-clicks on headers.
Definition: TBDataTab.qo.h:303
Primary interface for the rest of the browser to a table.
Definition: TBTable.h:152
void applyFormat(int index, TBFormat *format)
Applies the given format to the field at the given index.
QTableWidget * getTableWidget()
Returns the QTableWidget that displays the data.
TBDataItem(TBData *data)
Constructor to take the casacore::String value and the type.
void clearSort()
Slot for the clear sort button.
bool goForward
Remembers whether you pressed the next or previous button.
Definition: TBDataTab.qo.h:198
bool loadPage(int p)
Loads the given page into the table backend, which then updates the display.
TBArrayPanel * arrayPanel
Points to the current array panel, or NULL if there is none.
Definition: TBDataTab.qo.h:288
std::vector< TBFormat * > formats
Current field formats.
Definition: TBDataTab.qo.h:279
casacore::String type
Holds the data type.
Definition: TBDataTab.qo.h:83
A sequence of TBFilterRules that can be used to filter rows.
void pageLast()
Slot to go to last page.
Collection of table backend and display tabs.
void resizeHeaders()
Slot for the resize headers button.
void setFilter(TBFilterRuleSequence *rule)
Sets the current filter to the given rules, but does NOT apply it.
TBDataTab(TBTableTabs *tt)
Constructor that takes the parent TBTableTabs.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Wrapper around a QWidget with a &quot;Close&quot; button.
QFontColor * defaultFormat
&quot;Cleared&quot; format for cell text.
Definition: TBDataTab.qo.h:282
void sort(int col, bool asc)
Sorts on the given row.
void sortEntered()
This signal is emitted when a sort is applied to the table.
void columnHidden(int index, bool hidden)
This signal is emitted when a column is shown or hidden.
std::vector< std::pair< casacore::String, bool > > currSort
The current sort order.
Definition: TBDataTab.qo.h:299
void highlight(int row)
Selects and highlights the given row in the table widget.
QBrush & getSelectedCellBackground()
Returns the QBrush that is used to draw the background of any selected cells in the QTableWidget...
void cellClicked(int row, int col)
Slot for QTableWidget::currentCellChanged().
void setSortIndicator(int index, bool asc)
Sets the sort indicator on the QTableWidget for the given column with an ascending arrow if asc is tr...
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
void doubleClicked(int row, int col)
Slot for QTableWidget::cellDoubleClicked().
Panel that can hold multiple TBViewArray widgets.
QFont color is a convenience class containing a QFont and a QColor.
Definition: TBFormat.qo.h:47
int visibleIndex(int logicalIndex)
Returns the visible index for the row with the given logical index.