casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBViewArray.qo.h
Go to the documentation of this file.
1 //# TBViewArray.qo.h: Widget for viewing array data in TBArray format.
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 TBVIEWARRAY_H_
28 #define TBVIEWARRAY_H_
29 
30 #include <casaqt/QtBrowser/TBViewArray.ui.h>
31 #include <casaqt/QtBrowser/TBArrayPanel.ui.h>
33 
34 #include <vector>
35 
36 #include <QtGui>
37 
38 #include <casa/BasicSL/String.h>
39 
40 namespace casa {
41 
42 //# Forward Declarations
43 class TBTableTabs;
44 class TBArray;
45 class TBTable;
46 class TBSlicer;
47 class TBFormat;
48 class QFontColor;
49 class QCloseableWidget;
50 class TBArrayData;
51 class TBData;
52 class TBDataRecord;
53 
54 // <summary>
55 // Widget for viewing array data in TBArray format.
56 // </summary>
57 //
58 // <synopsis>
59 // A TBViewArray displays potentially multi-dimensional array data in a
60 // QTableWidget. If the array has dimensionality greater than two, a
61 // TBSlicer is used to control the array slice.
62 // </synopsis>
63 
64 class TBViewArray : public QWidget, Ui::ViewArray {
65  Q_OBJECT
66 
67 public:
68  // Constructor which takes the table parent, the "indices" where this array
69  // is located, the array to view, the location in the table (if applicable,
70  // and whether this array should be editable or not. The top of the
71  // array view will have a label that says "[table name][first, second] =
72  // [type] array of size [size]." For keyword arrays, row and col are
73  // irrelevant and editable should be false.
75  int row, int col, bool editable);
76 
77  ~TBViewArray();
78 
79 
80  // Returns the array that is being displayed.
82 
83  // Sets whether the arrays being viewed should release their data when
84  // closed or not.
85  void setShouldRelease(bool b);
86 
87 
88  // Returns the data at the given coordinates, or NULL if the coordinates
89  // are invalid.
90  TBData* dataAt(std::vector<int> d);
91 
92  // Sets the data at the given coordinates to the given value WITHOUT
93  // updating the table backend. If format is true, then any current
94  // format is applied to the new value.
95  void setDataAt(std::vector<int> d, TBData& newVal, bool format = true);
96 
97  // Applies the given format to the array cells.
98  void applyFormat(TBFormat* f);
99 
100  // Clears the current format from the array cells and applies the given
101  // QFontColor (which should be the default table cell font and color).
102  void clearFormat(QFontColor* f);
103 
104 protected:
105  // Catches the right-click event to allow for copying.
106  void contextMenuEvent(QContextMenuEvent* event);
107 
108 private:
109  // casacore::Table backend.
110  // <group>
113  // </group>
114 
115  // casacore::Array being displayed.
117 
118  // Flag to indicate whether GUI-generated events are "genuine."
119  bool update;
120 
121  // casacore::Slicer for arrays with dimensionality greater than two.
123 
124  // Current slice for arrays with dimensionality greater than two.
125  std::vector<int> currentSlice;
126 
127  // Indicates whether this array is allowed to be edited. casacore::Data arrays
128  // should be true while keyword arrays should be false.
129  bool editable;
130 
131  // Background for unselected cells.
133 
134  // Background for selected cells.
136 
137  // casacore::List of cells that are on the same row or column as the currently
138  // selected cell.
139  std::vector<QTableWidgetItem*> selectedCells;
140 
141  // Current format.
143 
144  // Indicates whether the underlying array data should be released when
145  // the view is closed or not.
147 
148  // Row of data array.
149  int row;
150 
151  // Column of data array.
152  int col;
153 
154 
155  // Sets up the GUI components with the given parameters for the label.
156  void setup(casacore::String first, casacore::String second);
157 
158  // Returns the array-relevant coordinates corresponding to the given
159  // indices.
160  std::vector<int> currentCell(int row, int col);
161 
162  // Relabels the table headers to be 0- rather than 1-based.
163  void relabelHeaders();
164 
165 private slots:
166  // Slot for when the user changes data in the array. If the edit is
167  // valid, a TBEditArrayDataAction is generated and sent to the browser
168  // for execution.
169  void dataChanged(int row, int col);
170 
171  // Slot for when the slicer changes (for arrays with dimensionality
172  // greater than two).
173  void sliceChanged(std::vector<int> newSlice);
174 
175  // Slot for when an array cell is clicked. Updates cells in the same
176  // row or column with a "selected" background.
177  void cellClicked(int row, int col);
178 
179  // Slot for when an array cell is double-clicked. If the array is
180  // editable and the table is currently in editing mode, the user is then
181  // allowed to edit the cell data.
182  void cellDoubleClicked(int row, int col);
183 
184  // Slot for copying the currently selected text into the system clipboard.
185  void copyData();
186 };
187 
188 // <summary>
189 // Panel that can hold multiple TBViewArray widgets.
190 // </summary>
191 //
192 // <synopsis>
193 // TBArrayPanel is the widget that is actually shown in the side panel and
194 // consists of one or more TBViewArray widgets. When the user double-clicks
195 // on another array, it is added to the TBArrayPanel. When the panel is
196 // closed, it closes all the TBViewArray widgets as well.
197 // </synopsis>
198 
199 class TBArrayPanel : public QWidget, Ui::ArrayPanel {
200  Q_OBJECT
201 
202 public:
203  // Constructor that takes the table backend.
205 
206  ~TBArrayPanel();
207 
208 
209  // Adds the given TBViewArray widget to this panel and returns whether it
210  // succeeded or not. If the given array is already being displayed (see
211  // TBArray::sameLocationAs(), false is returned.
212  bool addArray(TBViewArray* array, int colIndex);
213 
214  // Calls setShouldRelease on all TBViewArrays in this panel.
215  void setShouldRelease(bool b);
216 
217  // Applies the given format to any TBViewArray with the given index.
218  void applyFormat(TBFormat* format, int colIndex);
219 
220 public slots:
221  // Removes any actions in the browser that are associated with any
222  // of the arrays in this panel.
224 
225 signals:
226  // This signal is emitted when the user presses "close" on all the
227  // currently opened arrays in this panel. The caller should then close
228  // the panel itself.
229  void allArraysClosed();
230 
231 private:
232  // casacore::Table backend.
234 
235  // casacore::List of opened arrays.
236  std::vector<TBViewArray*> arrays;
237 
238  // casacore::List of wrapper widgets.
239  std::vector<QCloseableWidget*> widgets;
240 
241  // casacore::Array indices.
242  std::vector<int> indices;
243 
244  // Splitter to hold the opened arrays.
245  QSplitter splitter;
246 
247 
248  // Removes any actions in the browser that are associate with the given
249  // array in this panel.
251 
252 private slots:
253  // Slot for when the user closes an individual array.
254  void closeRequested(QWidget* widget);
255 };
256 
257 
258 // <summary>
259 // Widget for viewing record data.
260 // </summary>
261 //
262 // <synopsis>
263 // A TBViewRecord displays data in a TBDataRecord format, which uses an
264 // underlying casacore::Record object. The record is displayed in a table, and the
265 // values can also be another table (for arrays or sub-records).
266 // </synopsis>
267 
268 class TBViewRecord : public QWidget, Ui::ViewArray {
269  Q_OBJECT
270 
271 public:
272  // Constructor which takes the table parent, the record to display, and the
273  // "indices" to display in the label.
275  casacore::String second = "");
276 
277  ~TBViewRecord();
278 
279 private:
280  // casacore::Table parent.
282 
283  // Displayed record.
285 
286  // Fills the given table with the given parameters.
287  void fill(QTableWidget& table, casacore::Record& r, casacore::String first, casacore::String second);
288 };
289 
290 }
291 
292 #endif /* TBVIEWARRAY_H_ */
std::vector< int > currentSlice
Current slice for arrays with dimensionality greater than two.
bool addArray(TBViewArray *array, int colIndex)
Adds the given TBViewArray widget to this panel and returns whether it succeeded or not...
bool editable
Indicates whether this array is allowed to be edited.
std::vector< QTableWidgetItem * > selectedCells
casacore::List of cells that are on the same row or column as the currently selected cell...
TBArrayData * array
casacore::Array being displayed.
void applyFormat(TBFormat *f)
Applies the given format to the array cells.
QSplitter splitter
Splitter to hold the opened arrays.
void copyData()
Slot for copying the currently selected text into the system clipboard.
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1886
struct Node * first
Definition: malloc.h:330
TBTableTabs * tt
casacore::Table parent.
void relabelHeaders()
Relabels the table headers to be 0- rather than 1-based.
casacore::Data types used for loaded data.
Definition: TBData.h:51
TBTableTabs * tTabs
casacore::Table backend.
std::vector< int > indices
casacore::Array indices.
std::vector< TBViewArray * > arrays
casacore::List of opened arrays.
Widget for viewing record data.
void cellDoubleClicked(int row, int col)
Slot for when an array cell is double-clicked.
void removeActionsAssociatedWithArrays()
Removes any actions in the browser that are associated with any of the arrays in this panel...
void setShouldRelease(bool b)
Sets whether the arrays being viewed should release their data when closed or not.
casacore::Data type that holds an array.
Definition: TBData.h:983
void dataChanged(int row, int col)
Slot for when the user changes data in the array.
bool shouldRelease
Indicates whether the underlying array data should be released when the view is closed or not...
bool update
Flag to indicate whether GUI-generated events are &quot;genuine.&quot;.
QBrush selectedBackground
Background for selected cells.
void cellClicked(int row, int col)
Slot for when an array cell is clicked.
Rules used to format displayed values for fields.
Definition: TBFormat.qo.h:79
void contextMenuEvent(QContextMenuEvent *event)
Catches the right-click event to allow for copying.
TBData * dataAt(std::vector< int > d)
Returns the data at the given coordinates, or NULL if the coordinates are invalid.
Primary interface for the rest of the browser to a table.
Definition: TBTable.h:152
void fill(QTableWidget &table, casacore::Record &r, casacore::String first, casacore::String second)
Fills the given table with the given parameters.
A hierarchical collection of named fields of various types.
Definition: Record.h:180
TBArrayData * getArrayData()
Returns the array that is being displayed.
casacore::Record & record
Displayed record.
TBArrayPanel(TBTableTabs *tt)
Constructor that takes the table backend.
std::vector< QCloseableWidget * > widgets
casacore::List of wrapper widgets.
void setup(casacore::String first, casacore::String second)
Sets up the GUI components with the given parameters for the label.
TBViewRecord(TBTableTabs *tt, TBDataRecord *r, casacore::String first, casacore::String second="")
Constructor which takes the table parent, the record to display, and the &quot;indices&quot; to display in the ...
const Double second
Time interval [T]:
Implementation of TBData for casacore::Record data.
Definition: TBData.h:848
void sliceChanged(std::vector< int > newSlice)
Slot for when the slicer changes (for arrays with dimensionality greater than two).
Widget to display and change the current array slice.
Definition: TBSlicer.qo.h:52
QBrush unselectedBackground
Background for unselected cells.
int col
Column of data array.
Collection of table backend and display tabs.
TBTableTabs * ttabs
casacore::Table backend.
void removeActionsAssociatedWithArray(TBViewArray *array)
Removes any actions in the browser that are associate with the given array in this panel...
void closeRequested(QWidget *widget)
Slot for when the user closes an individual array.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
TBViewArray(TBTableTabs *tt, casacore::String first, casacore::String second, TBArrayData *arr, int row, int col, bool editable)
Constructor which takes the table parent, the &quot;indices&quot; where this array is located, the array to view, the location in the table (if applicable, and whether this array should be editable or not.
Widget for viewing array data in TBArray format.
void setShouldRelease(bool b)
Calls setShouldRelease on all TBViewArrays in this panel.
void setDataAt(std::vector< int > d, TBData &newVal, bool format=true)
Sets the data at the given coordinates to the given value WITHOUT updating the table backend...
void clearFormat(QFontColor *f)
Clears the current format from the array cells and applies the given QFontColor (which should be the ...
void allArraysClosed()
This signal is emitted when the user presses &quot;close&quot; on all the currently opened arrays in this panel...
TBFormat * format
Current format.
void applyFormat(TBFormat *format, int colIndex)
Applies the given format to any TBViewArray with the given index.
TBSlicer * slicer
casacore::Slicer for arrays with dimensionality greater than two.
std::vector< int > currentCell(int row, int col)
Returns the array-relevant coordinates corresponding to the given indices.
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 row
Row of data array.