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