casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBPlotter.qo.h
Go to the documentation of this file.
1 //# TBPlotter.qo.h: Widget to collect plot parameters and plot on the canvas.
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 TBPLOTTER_H_
28 #define TBPLOTTER_H_
29 
30 #include <casaqt/QtBrowser/TBPlotter.ui.h>
34 
35 #include <QtGui>
36 #include <QStandardItemModel>
37 
38 #include <map>
39 #include <vector>
40 
41 #include <casa/BasicSL/String.h>
42 
43 namespace casa {
44 
45 //# Forward Declarations
46 class TBBrowser;
47 class TBPlotCanvas;
48 class QProgressPanel;
49 class TBTableTabs;
50 
51 // <summary>
52 // Parameters for a single field for collecting plotting data.
53 // </summary>
54 //
55 // <synopsis>
56 // A PlotParams accompanies each axis when plot data is being collected.
57 // A PlotParams indicates which field is being plotted and other important
58 // parameters.
59 // </synopsis>
60 
61 class PlotParams {
62 public:
63  // Default Constructor
64  PlotParams(): rowNumbers(false), complex(false), complexAmp(false),
65  colIndex(0) { }
66 
67 
68  // Indicates whether this plot axis is only the row numbers (true) or an
69  // actual field (false).
70  bool rowNumbers;
71 
72  // Indicates whether this field is complex or not.
73  bool complex;
74 
75  // If the field is complex, indicates whether the amplitude (true) or the
76  // phase (false) is used.
77  bool complexAmp;
78 
79  // Indicates which field index is to be used.
80  unsigned int colIndex;
81 
82  // If the field is an array, indicates the array slice to be used.
83  std::vector<int> slice;
84 };
85 
86 // <summary>
87 // casacore::Data for plotting.
88 // </summary>
89 //
90 // <synopsis>
91 // A TBPlotData holds two double arrays and the number of points.
92 // </synopsis>
93 
94 class TBPlotData {
95 public:
96  // Default Constructor.
97  TBPlotData() { }
98 
99  // Constructor which takes the number of points and the two arrays.
100  TBPlotData(PlotPointDataPtr d) : data(d) { }
101 
103 
104  // Actual data.
105  PlotPointDataPtr data;
106 
107  // casacore::Table this data is from.
109 
110  // Row numbers that correspond to the given data. In the future may want
111  // to replace with a less memory-heavy implementation.
112  std::vector<int> rows;
113 
114  // Title for the plot; usually xAxisName vs. yAxisName
116 };
117 
118 // <summary>
119 // Small widget to provide a variable number of spinners to create a slice.
120 // </summary>
121 //
122 // <synopsis>
123 // A PlotSlicer provides a variable number of QSpinBoxes to allow the user
124 // to enter an array slice. The number of spinners depends on the
125 // dimensionality (i.e., a two-dimensional array will have two spinners). The
126 // range of the spinners depends on the array's shape (i.e., a 4x2 array will
127 // have a [0, 3] range on the first spinner and a [0, 1] range on the second
128 // spinner). A PlotSlicer can also display a QComboBox to allow the user to
129 // choose between phase and amplitude for complex numbers.
130 // </synopsis>
131 
132 class PlotSlicer : public QHBoxLayout {
133  Q_OBJECT
134 
135 public:
136  // Default Constructor.
137  PlotSlicer();
138 
139  ~PlotSlicer();
140 
141 
142  // Sets the dimensions of the slicer to the given vector. If complex is
143  // true, a combobox to choose between phase and amplitude is also shown.
144  // If index is true, a spinbox to select plot axis is also shown.
145  bool setDimension(std::vector<int>* d, bool complex = false);
146  bool setDimension(std::vector<int>* d, bool complex, bool index);
147 
148  // Retrieves the array slice into the given vector. complex is set to true
149  // if the slice is for complex numbers; if complex is true, amp indicates
150  // whether the slice is for the amplitude (true) or the phase (false).
151  void getDimension(std::vector<int>& d, bool& complex, bool& amp);
152  void getDimension(std::vector<int>& d, bool& complex, bool& amp, int& axis);
153 
154 private:
155  // All current spinners.
156  std::vector<QSpinBox*> spinners;
157 
158  // casacore::Complex chooser.
159  QComboBox* complexChooser;
160 
161  // Whether the current slice is for a complex or not.
162  bool complex;
163 
164  // Spinbox and Label to choose axis
165  QSpinBox* plotAxisChooser;
166  QLabel* axisLabel;
167 
168 private slots:
169  void axisChosen(int axis);
170 };
171 
172 // <summary>
173 // Widget to collect plot parameters and plot on the canvas.
174 // </summary>
175 //
176 // <synopsis>
177 // A TBPlotter consists of a TBPlotCanvas and other widgets to control plot
178 // parameters and other options. The TBPlotter has four sections in a vertical
179 // layout. The first section is the TBPlotCanvas. The second is the data
180 // parameters: which table and rows to use, which fields to plot, etc. The
181 // third is the graph format: scatter vs. line, point formatting, etc. The
182 // fourth are plotting tools such as saving as an image.
183 // </synopsis>
184 
185 class TBPlotter : public QMainWindow, public Ui::Plotter {
186  Q_OBJECT
187 
188 public:
189  // Constructor that takes the parent browser.
191 
192  ~TBPlotter();
193 
194 
195  // Adds a QProgressPanel to the plotter with the given parameters and
196  // returns it.
197  QProgressPanel* addProgressPanel(casacore::String label, bool hideable,
198  bool cancelable);
199 
200  // Removes the given QProgressPanel from the plotter.
201  void removeProgressPanel(QProgressPanel* panel);
202 
203 protected:
204  // Capture when the window closes. If the parameters dock widget is
205  // floating, close it manually.
206  void closeEvent(QCloseEvent* event);
207 
208 private:
209  // Parent browser.
211 
212  // Plotter factory
214 
215  // For each table the plotter knows about, the dimensions of the fields are
216  // kept for fast access. So, for example, the dimensions of a field can be
217  // found with dimensions[tableName][columnIndex].
218  std::map<casacore::String, std::vector<std::vector<int>*> > dimensions;
219 
220  // Since only certain field types are plottable, adjustedIndices allows for
221  // translation between the index of the combobox (which contains only
222  // plottable fields) and the index in the table (which contains all
223  // fields). So, for example, adjustedIndices[plottableIndex] = tableIndex.
224  std::vector<int> adjustedIndices;
225 
226  // PlotSlicer for the x-axis.
228 
229  // PlotSlicer for the y-axis.
231 
232  // Types for the displayed plottable fields.
233  std::vector<casacore::String> types;
234 
235  // Is true if the current selection for the x-axis is valid, false
236  // otherwise. If the axis is invalid, it cannot be used for plotting.
237  bool xValid;
238 
239  // Is true if the current selection for the x-axis is valid, false
240  // otherwise. If the axis is invalid, it cannot be used for plotting.
241  bool yValid;
242 
243  // Flag to indicate whether GUI-generated events are "genuine."
244  bool update;
245 
246  // Plot canvas.
248 
249 
250  // Collects the parameters and plots as indicated.
251  void doPlot(bool overplot = true);
252 
253  // Model for xChooser and yChooser to disable [index] selection
254  QStandardItemModel* xChooserModel;
255  QStandardItemModel* yChooserModel;
256 
257  // Flag to indicate whether index based plot is selected or not
259 
260  // Show/Hide row iteration GUI when [index] is deselected/selected.
261  void enableRowIteration(bool visible);
262 
263 private slots:
264  // Slot for when the user chooses a different table from the combobox.
265  // Updates the displayed options for the table.
266  void tableChosen(QString name);
267 
268  // Slot for when the user chooses a field for the x-axis.
269  void xChosen(int x);
270 
271  // Slot for when the user chooses a field for the y-axis.
272  void yChosen(int y);
273 
274  // Slot for code common to xChosen and yChosen.
275  void chosen(bool x, int i);
276 
277  // Slot for when [index] is chosen
278  void indexChosen(bool x);
279 
280  // Slot for when [index] is deselected
281  void indexReleased(bool x, int i);
282 
283  // Slot for the "Clear and Plot" button. See doPlot(false);
284  void plot();
285 
286  // Slot for the "Overplot" button. See doPlot(true);
287  void overplot();
288 
289  // Opens a new TBPlotter window.
290  void openNewPlotter();
291 
292  // Slot for when a table is opened in the browser. Adds the table name
293  // to the list of opened tables.
294  void tableOpened(casacore::String table, casacore::String fullpath);
295 
296  // Slot for when a table is closed in the browser. Removes the table
297  // name from the list of opened tables.
298  void tableClosed(casacore::String table);
299 
300  // Slot for the "Clear" button. See TBPlotCanvas::clearAndHideAxes().
301  void clear();
302 
303  // Slot for the "All Rows" button. Sets the row selection to be all the
304  // rows in the currently selected table.
305  void allRows();
306 
307  // Slot to open a QColorDialog for the given line edit.
308  void setColor(QLineEdit* lineEdit);
309 
310  // Convenience slot
311  void setLineColor() { setColor(lineColorEdit); }
312 
313  // Convenience slot
314  void setSymbolColor() { setColor(symbolColorEdit); }
315 
316  // Slot to export the current plot canvas to the image format specified
317  // by the QComboBox.
318  void exportImage();
319 
320  // Slot for when the user enters a filter rule for the table at the given
321  // index.
322  void filterRuleEntered(int i);
323 
324  // Slot for when the user enters a filter rule for the table at the given
325  // index.
326  void filterRuleCleared(int i);
327 
328  // Slot for when the user changes the grid options.
329  void gridChanged();
330 
331  void regionSelected(bool selected);
332 
333  // Slot for when the user clicks "locate".
334  void selectLocate();
335 
336  // Slot for when the user clears the currently selected region.
337  void clearSelection();
338 };
339 
340 }
341 
342 #endif /* TBPLOTTER_H_ */
void setSymbolColor()
Convenience slot.
Definition: TBPlotter.qo.h:314
void gridChanged()
Slot for when the user changes the grid options.
std::map< casacore::String, std::vector< std::vector< int > * > > dimensions
For each table the plotter knows about, the dimensions of the fields are kept for fast access...
Definition: TBPlotter.qo.h:218
void overplot()
Slot for the &quot;Overplot&quot; button.
void chosen(bool x, int i)
Slot for code common to xChosen and yChosen.
bool update
Flag to indicate whether GUI-generated events are &quot;genuine.&quot;.
Definition: TBPlotter.qo.h:244
void enableRowIteration(bool visible)
Show/Hide row iteration GUI when [index] is deselected/selected.
void regionSelected(bool selected)
Widget to collect plot parameters and plot on the canvas.
Definition: TBPlotter.qo.h:185
void setColor(QLineEdit *lineEdit)
Slot to open a QColorDialog for the given line edit.
casacore::Data for plotting.
Definition: TBPlotter.qo.h:94
void xChosen(int x)
Slot for when the user chooses a field for the x-axis.
Canvas for data plotting using a given plotting implementation.
void filterRuleEntered(int i)
Slot for when the user enters a filter rule for the table at the given index.
bool yValid
Is true if the current selection for the x-axis is valid, false otherwise.
Definition: TBPlotter.qo.h:241
void closeEvent(QCloseEvent *event)
Capture when the window closes.
void clearSelection()
Slot for when the user clears the currently selected region.
Browser widget for managing opened tables.
Definition: TBBrowser.qo.h:63
void tableOpened(casacore::String table, casacore::String fullpath)
Slot for when a table is opened in the browser.
void allRows()
Slot for the &quot;All Rows&quot; button.
std::vector< casacore::String > types
Types for the displayed plottable fields.
Definition: TBPlotter.qo.h:233
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
QStandardItemModel * xChooserModel
Model for xChooser and yChooser to disable [index] selection.
Definition: TBPlotter.qo.h:254
casacore::String title
Title for the plot; usually xAxisName vs.
Definition: TBPlotter.qo.h:115
QProgressPanel * addProgressPanel(casacore::String label, bool hideable, bool cancelable)
Adds a QProgressPanel to the plotter with the given parameters and returns it.
TBPlotData(PlotPointDataPtr d)
Constructor which takes the number of points and the two arrays.
Definition: TBPlotter.qo.h:100
bool complex
Indicates whether this field is complex or not.
Definition: TBPlotter.qo.h:73
void axisChosen(int axis)
Small widget to provide a variable number of spinners to create a slice.
Definition: TBPlotter.qo.h:132
bool complex
Whether the current slice is for a complex or not.
Definition: TBPlotter.qo.h:162
PlotFactoryPtr factory
Plotter factory.
Definition: TBPlotter.qo.h:213
bool xValid
Is true if the current selection for the x-axis is valid, false otherwise.
Definition: TBPlotter.qo.h:237
void filterRuleCleared(int i)
Slot for when the user enters a filter rule for the table at the given index.
TBTableTabs * table
casacore::Table this data is from.
Definition: TBPlotter.qo.h:108
TBBrowser * browser
Parent browser.
Definition: TBPlotter.qo.h:210
TBPlotCanvas * plotCanvas
Plot canvas.
Definition: TBPlotter.qo.h:247
PlotPointDataPtr data
Actual data.
Definition: TBPlotter.qo.h:105
bool complexAmp
If the field is complex, indicates whether the amplitude (true) or the phase (false) is used...
Definition: TBPlotter.qo.h:77
void indexChosen(bool x)
Slot for when [index] is chosen.
LatticeExprNode amp(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds sqrt(left^2+right^2).
void tableClosed(casacore::String table)
Slot for when a table is closed in the browser.
TBPlotter(TBBrowser *browser, PlotFactoryPtr factory)
Constructor that takes the parent browser.
unsigned int colIndex
Indicates which field index is to be used.
Definition: TBPlotter.qo.h:80
void openNewPlotter()
Opens a new TBPlotter window.
std::vector< int > slice
If the field is an array, indicates the array slice to be used.
Definition: TBPlotter.qo.h:83
TBPlotData()
Default Constructor.
Definition: TBPlotter.qo.h:97
void tableChosen(QString name)
Slot for when the user chooses a different table from the combobox.
void yChosen(int y)
Slot for when the user chooses a field for the y-axis.
bool rowNumbers
Indicates whether this plot axis is only the row numbers (true) or an actual field (false)...
Definition: TBPlotter.qo.h:70
void clear()
Slot for the &quot;Clear&quot; button.
QSpinBox * plotAxisChooser
Spinbox and Label to choose axis.
Definition: TBPlotter.qo.h:165
bool setDimension(std::vector< int > *d, bool complex=false)
Sets the dimensions of the slicer to the given vector.
Convenience class with a label and progress meter.
void selectLocate()
Slot for when the user clicks &quot;locate&quot;.
QComboBox * complexChooser
casacore::Complex chooser.
Definition: TBPlotter.qo.h:159
Collection of table backend and display tabs.
void removeProgressPanel(QProgressPanel *panel)
Removes the given QProgressPanel from the plotter.
std::vector< int > rows
Row numbers that correspond to the given data.
Definition: TBPlotter.qo.h:112
std::vector< QSpinBox * > spinners
All current spinners.
Definition: TBPlotter.qo.h:156
std::vector< int > adjustedIndices
Since only certain field types are plottable, adjustedIndices allows for translation between the inde...
Definition: TBPlotter.qo.h:224
void getDimension(std::vector< int > &d, bool &complex, bool &amp)
Retrieves the array slice into the given vector.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void doPlot(bool overplot=true)
Collects the parameters and plots as indicated.
void indexReleased(bool x, int i)
Slot for when [index] is deselected.
PlotSlicer xSlice
PlotSlicer for the x-axis.
Definition: TBPlotter.qo.h:227
Parameters for a single field for collecting plotting data.
Definition: TBPlotter.qo.h:61
QStandardItemModel * yChooserModel
Definition: TBPlotter.qo.h:255
void setLineColor()
Convenience slot.
Definition: TBPlotter.qo.h:311
PlotSlicer ySlice
PlotSlicer for the y-axis.
Definition: TBPlotter.qo.h:230
PlotSlicer()
Default Constructor.
void plot()
Slot for the &quot;Clear and Plot&quot; button.
QLabel * axisLabel
Definition: TBPlotter.qo.h:166
void exportImage()
Slot to export the current plot canvas to the image format specified by the QComboBox.
PlotParams()
Default Constructor.
Definition: TBPlotter.qo.h:64
bool isIndexPlot
Flag to indicate whether index based plot is selected or not.
Definition: TBPlotter.qo.h:258