00001 //# TBPlotCanvas.qo.h: Canvas for data plotting using qwt. 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 TBPLOTCANVAS_H_ 00028 #define TBPLOTCANVAS_H_ 00029 00030 #include <casaqt/QtBrowser/TBPlotCanvas.ui.h> 00031 #include <casaqt/QtBrowser/TBConstants.h> 00032 #include <graphics/GenericPlotter/PlotOptions.h> 00033 #include <graphics/GenericPlotter/PlotEventHandler.h> 00034 00035 #include <graphics/GenericPlotter/PlotFactory.h> 00036 00037 #include <casa/BasicSL/String.h> 00038 00039 #include <vector> 00040 00041 namespace casa { 00042 00043 //# Forward Declarations 00044 class TBPlotData; 00045 class TBLocateParams; 00046 00047 // <summary> 00048 // Format for the curves on the plot canvas. 00049 // </summary> 00050 // 00051 // <synopsis> 00052 // A TBPlotFormat specifies how to display a plot curve. The format includes 00053 // a PlotLine and a PlotSymbol. 00054 // </synopsis> 00055 00056 class TBPlotFormat { 00057 public: 00058 // Constructor that takes a factory to build the line and symbol. 00059 TBPlotFormat(PlotFactoryPtr factory); 00060 00061 ~TBPlotFormat(); 00062 00063 00064 // Sets the curve style using the given QString name. 00065 void setCurveStyle(QString str); 00066 00067 // Sets the point style using the given QString name. 00068 void setPointStyle(QString str); 00069 00070 // Line to use with the plot 00071 PlotLinePtr line; 00072 00073 // Symbol to use with the plot 00074 PlotSymbolPtr symbol; 00075 00076 /* 00077 // Returns a QwtSymbol using the format's point style, size, and color. 00078 QwtSymbol getSymbol(); 00079 00080 // Curve style. 00081 QwtPlotCurve::CurveStyle curveStyle; 00082 00083 // Point style. 00084 QwtSymbol::Style pointStyle; 00085 00086 // Point color. 00087 QColor color; 00088 00089 // Point size. 00090 // <group> 00091 int size1; 00092 int size2; 00093 // </group> 00094 */ 00095 }; 00096 00097 00098 // <summary> 00099 // Canvas for data plotting using a given plotting implementation. 00100 // </summary> 00101 // 00102 // <synopsis> 00103 // TBPlotCanvas uses and controls a plotting implementation canvas. If the 00104 // implementation is Qt, it is embedded in the TBPlotCanvas; otherwise it is 00105 // assumed to be in a separate window. 00106 // </synopsis> 00107 00108 class TBPlotCanvas : public QWidget, Ui::PlotCanvas, 00109 public PlotSelectEventHandler { 00110 Q_OBJECT 00111 00112 public: 00113 // Constructor with a factory. 00114 TBPlotCanvas(PlotFactoryPtr factory); 00115 00116 ~TBPlotCanvas(); 00117 00118 00119 // Sets the X-axis title to the given String. 00120 void setXAxisTitle(String title); 00121 00122 // Sets the Y-axis title to the given String. 00123 void setYAxisTitle(String title); 00124 00125 // Sets which grids are shown on the canvas. 00126 void setShownGrids(bool xMaj, bool xMin, bool yMaj, bool yMin); 00127 00128 // Sets the x axis to display values as dates. 00129 void setXAxisDate(bool date = true, bool mjsec = true); 00130 00131 // Sets the y axis to display values as dates. 00132 void setYAxisDate(bool date = true, bool mjsec = true); 00133 00134 // Returns the name of the current table being plotted. 00135 String getCurrentTable(); 00136 00137 // Sets the name of the current table being plotted. 00138 void setTable(String table); 00139 00140 // Returns the current number of plots currently on the canvas. 00141 int getNumPlots(); 00142 00143 00144 // Returns the data corresponding to the current plots. 00145 std::vector<TBPlotData*> allData(); 00146 00147 // Implements PlotSelectEventHandler::handleSelect(). 00148 void handleSelect(const PlotSelectEvent& event); 00149 00150 // Plots the given data. If overplot is true all old plots 00151 // are kept as well, otherwise the old plots are cleared first. 00152 // See PlotCanvas::plot(). 00153 void plot(TBPlotData* data, const TBPlotFormat& format, 00154 bool overplot = false); 00155 00156 // Exports the PlotCanvas to an image in the given format at the given 00157 // location and returns whether the operation succeeded or not. 00158 Result exportToImage(String format, String location); 00159 00160 // If there is a rectangle shape from a user-selected region, clear it 00161 // from the canvas. 00162 void clearSelectedRectangle(); 00163 00164 // If there is a current user-selected region, return it. Otherwise 00165 // behavior is undefined. 00166 PlotRegion currentSelection(); 00167 00168 public slots: 00169 // Clears all current plots and hides the two axes. 00170 void clearAndHideAxes(); 00171 00172 signals: 00173 // Signal that is emitted whenever the user selects a region, or the 00174 // currently selected region is cleared. If selected is true, then the 00175 // user selected a region and a rectangle is now on the canvas. If 00176 // selected is false, then there is no longer a current selected region. 00177 void regionSelected(bool selected); 00178 00179 private: 00180 // Plotter factory 00181 PlotFactoryPtr factory; 00182 00183 // Plotter 00184 PlotterPtr plotter; 00185 00186 // Plot canvas 00187 PlotCanvasPtr canvas; 00188 00189 // Holds the name of the current table being plotted. 00190 String currentTable; 00191 00192 // Currently selected region, or NULL if there is none. 00193 PlotShapeRectanglePtr selectedRegion; 00194 00195 // Current data. 00196 std::vector<TBPlotData*> data; 00197 00198 private slots: 00199 // Slot for clearing all the internal tracking of current plots. 00200 void clearPlots(); 00201 }; 00202 00203 } 00204 00205 #endif /* TBPLOTCANVAS_H_ */