00001 //# TBPlotter.qo.h: Widget to collect plot parameters and plot on the canvas. 00002 //# Copyright (C) 2005 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: $ 00027 #ifndef TBPLOTTER_H_ 00028 #define TBPLOTTER_H_ 00029 00030 #include <casaqt/QtBrowser/TBPlotter.ui.h> 00031 #include <casaqt/QtBrowser/TBPlotCanvas.qo.h> 00032 #include <casaqt/QtBrowser/TBConstants.h> 00033 #include <graphics/GenericPlotter/PlotFactory.h> 00034 00035 #include <QtGui> 00036 #include <QtGui/QStandardItemModel> 00037 00038 #include <map> 00039 #include <vector> 00040 00041 #include <casa/BasicSL/String.h> 00042 00043 namespace casa { 00044 00045 //# Forward Declarations 00046 class TBBrowser; 00047 class TBPlotCanvas; 00048 class QProgressPanel; 00049 class TBTableTabs; 00050 00051 // <summary> 00052 // Parameters for a single field for collecting plotting data. 00053 // </summary> 00054 // 00055 // <synopsis> 00056 // A PlotParams accompanies each axis when plot data is being collected. 00057 // A PlotParams indicates which field is being plotted and other important 00058 // parameters. 00059 // </synopsis> 00060 00061 class PlotParams { 00062 public: 00063 // Default Constructor 00064 PlotParams(): rowNumbers(false), complex(false), complexAmp(false), 00065 colIndex(0) { } 00066 00067 00068 // Indicates whether this plot axis is only the row numbers (true) or an 00069 // actual field (false). 00070 bool rowNumbers; 00071 00072 // Indicates whether this field is complex or not. 00073 bool complex; 00074 00075 // If the field is complex, indicates whether the amplitude (true) or the 00076 // phase (false) is used. 00077 bool complexAmp; 00078 00079 // Indicates which field index is to be used. 00080 unsigned int colIndex; 00081 00082 // If the field is an array, indicates the array slice to be used. 00083 std::vector<int> slice; 00084 }; 00085 00086 // <summary> 00087 // Data for plotting. 00088 // </summary> 00089 // 00090 // <synopsis> 00091 // A TBPlotData holds two double arrays and the number of points. 00092 // </synopsis> 00093 00094 class TBPlotData { 00095 public: 00096 // Default Constructor. 00097 TBPlotData() { } 00098 00099 // Constructor which takes the number of points and the two arrays. 00100 TBPlotData(PlotPointDataPtr d) : data(d) { } 00101 00102 ~TBPlotData() { } 00103 00104 // Actual data. 00105 PlotPointDataPtr data; 00106 00107 // Table this data is from. 00108 TBTableTabs* table; 00109 00110 // Row numbers that correspond to the given data. In the future may want 00111 // to replace with a less memory-heavy implementation. 00112 vector<int> rows; 00113 00114 // Title for the plot; usually xAxisName vs. yAxisName 00115 String title; 00116 }; 00117 00118 // <summary> 00119 // Small widget to provide a variable number of spinners to create a slice. 00120 // </summary> 00121 // 00122 // <synopsis> 00123 // A PlotSlicer provides a variable number of QSpinBoxes to allow the user 00124 // to enter an array slice. The number of spinners depends on the 00125 // dimensionality (i.e., a two-dimensional array will have two spinners). The 00126 // range of the spinners depends on the array's shape (i.e., a 4x2 array will 00127 // have a [0, 3] range on the first spinner and a [0, 1] range on the second 00128 // spinner). A PlotSlicer can also display a QComboBox to allow the user to 00129 // choose between phase and amplitude for complex numbers. 00130 // </synopsis> 00131 00132 class PlotSlicer : public QHBoxLayout { 00133 Q_OBJECT 00134 00135 public: 00136 // Default Constructor. 00137 PlotSlicer(); 00138 00139 ~PlotSlicer(); 00140 00141 00142 // Sets the dimensions of the slicer to the given vector. If complex is 00143 // true, a combobox to choose between phase and amplitude is also shown. 00144 // If index is true, a spinbox to select plot axis is also shown. 00145 bool setDimension(std::vector<int>* d, bool complex = false); 00146 bool setDimension(std::vector<int>* d, bool complex, bool index); 00147 00148 // Retrieves the array slice into the given vector. complex is set to true 00149 // if the slice is for complex numbers; if complex is true, amp indicates 00150 // whether the slice is for the amplitude (true) or the phase (false). 00151 void getDimension(std::vector<int>& d, bool& complex, bool& amp); 00152 void getDimension(std::vector<int>& d, bool& complex, bool& amp, int& axis); 00153 00154 private: 00155 // All current spinners. 00156 std::vector<QSpinBox*> spinners; 00157 00158 // Complex chooser. 00159 QComboBox* complexChooser; 00160 00161 // Whether the current slice is for a complex or not. 00162 bool complex; 00163 00164 // Spinbox and Label to choose axis 00165 QSpinBox* plotAxisChooser; 00166 QLabel* axisLabel; 00167 00168 private slots: 00169 void axisChosen(int axis); 00170 }; 00171 00172 // <summary> 00173 // Widget to collect plot parameters and plot on the canvas. 00174 // </summary> 00175 // 00176 // <synopsis> 00177 // A TBPlotter consists of a TBPlotCanvas and other widgets to control plot 00178 // parameters and other options. The TBPlotter has four sections in a vertical 00179 // layout. The first section is the TBPlotCanvas. The second is the data 00180 // parameters: which table and rows to use, which fields to plot, etc. The 00181 // third is the graph format: scatter vs. line, point formatting, etc. The 00182 // fourth are plotting tools such as saving as an image. 00183 // </synopsis> 00184 00185 class TBPlotter : public QMainWindow, public Ui::Plotter { 00186 Q_OBJECT 00187 00188 public: 00189 // Constructor that takes the parent browser. 00190 TBPlotter(TBBrowser* browser, PlotFactoryPtr factory); 00191 00192 ~TBPlotter(); 00193 00194 00195 // Adds a QProgressPanel to the plotter with the given parameters and 00196 // returns it. 00197 QProgressPanel* addProgressPanel(String label, bool hideable, 00198 bool cancelable); 00199 00200 // Removes the given QProgressPanel from the plotter. 00201 void removeProgressPanel(QProgressPanel* panel); 00202 00203 protected: 00204 // Capture when the window closes. If the parameters dock widget is 00205 // floating, close it manually. 00206 void closeEvent(QCloseEvent* event); 00207 00208 private: 00209 // Parent browser. 00210 TBBrowser* browser; 00211 00212 // Plotter factory 00213 PlotFactoryPtr factory; 00214 00215 // For each table the plotter knows about, the dimensions of the fields are 00216 // kept for fast access. So, for example, the dimensions of a field can be 00217 // found with dimensions[tableName][columnIndex]. 00218 std::map<String, std::vector<std::vector<int>*> > dimensions; 00219 00220 // Since only certain field types are plottable, adjustedIndices allows for 00221 // translation between the index of the combobox (which contains only 00222 // plottable fields) and the index in the table (which contains all 00223 // fields). So, for example, adjustedIndices[plottableIndex] = tableIndex. 00224 std::vector<int> adjustedIndices; 00225 00226 // PlotSlicer for the x-axis. 00227 PlotSlicer xSlice; 00228 00229 // PlotSlicer for the y-axis. 00230 PlotSlicer ySlice; 00231 00232 // Types for the displayed plottable fields. 00233 std::vector<String> types; 00234 00235 // Is true if the current selection for the x-axis is valid, false 00236 // otherwise. If the axis is invalid, it cannot be used for plotting. 00237 bool xValid; 00238 00239 // Is true if the current selection for the x-axis is valid, false 00240 // otherwise. If the axis is invalid, it cannot be used for plotting. 00241 bool yValid; 00242 00243 // Flag to indicate whether GUI-generated events are "genuine." 00244 bool update; 00245 00246 // Plot canvas. 00247 TBPlotCanvas* plotCanvas; 00248 00249 00250 // Collects the parameters and plots as indicated. 00251 void doPlot(bool overplot = true); 00252 00253 // Model for xChooser and yChooser to disable [index] selection 00254 QStandardItemModel* xChooserModel; 00255 QStandardItemModel* yChooserModel; 00256 00257 // Flag to indicate whether index based plot is selected or not 00258 bool isIndexPlot; 00259 00260 // Show/Hide row iteration GUI when [index] is deselected/selected. 00261 void enableRowIteration(bool visible); 00262 00263 private slots: 00264 // Slot for when the user chooses a different table from the combobox. 00265 // Updates the displayed options for the table. 00266 void tableChosen(QString name); 00267 00268 // Slot for when the user chooses a field for the x-axis. 00269 void xChosen(int x); 00270 00271 // Slot for when the user chooses a field for the y-axis. 00272 void yChosen(int y); 00273 00274 // Slot for code common to xChosen and yChosen. 00275 void chosen(bool x, int i); 00276 00277 // Slot for when [index] is chosen 00278 void indexChosen(bool x); 00279 00280 // Slot for when [index] is deselected 00281 void indexReleased(bool x, int i); 00282 00283 // Slot for the "Clear and Plot" button. See doPlot(false); 00284 void plot(); 00285 00286 // Slot for the "Overplot" button. See doPlot(true); 00287 void overplot(); 00288 00289 // Opens a new TBPlotter window. 00290 void openNewPlotter(); 00291 00292 // Slot for when a table is opened in the browser. Adds the table name 00293 // to the list of opened tables. 00294 void tableOpened(String table, String fullpath); 00295 00296 // Slot for when a table is closed in the browser. Removes the table 00297 // name from the list of opened tables. 00298 void tableClosed(String table); 00299 00300 // Slot for the "Clear" button. See TBPlotCanvas::clearAndHideAxes(). 00301 void clear(); 00302 00303 // Slot for the "All Rows" button. Sets the row selection to be all the 00304 // rows in the currently selected table. 00305 void allRows(); 00306 00307 // Slot to open a QColorDialog for the given line edit. 00308 void setColor(QLineEdit* lineEdit); 00309 00310 // Convenience slot 00311 void setLineColor() { setColor(lineColorEdit); } 00312 00313 // Convenience slot 00314 void setSymbolColor() { setColor(symbolColorEdit); } 00315 00316 // Slot to export the current plot canvas to the image format specified 00317 // by the QComboBox. 00318 void exportImage(); 00319 00320 // Slot for when the user enters a filter rule for the table at the given 00321 // index. 00322 void filterRuleEntered(int i); 00323 00324 // Slot for when the user enters a filter rule for the table at the given 00325 // index. 00326 void filterRuleCleared(int i); 00327 00328 // Slot for when the user changes the grid options. 00329 void gridChanged(); 00330 00331 void regionSelected(bool selected); 00332 00333 // Slot for when the user clicks "locate". 00334 void selectLocate(); 00335 00336 // Slot for when the user clears the currently selected region. 00337 void clearSelection(); 00338 }; 00339 00340 } 00341 00342 #endif /* TBPLOTTER_H_ */