QPAxis.qo.h

Go to the documentation of this file.
00001 //# QPAxis.qo.h: Qwt implementation of generic PlotCanvas class.
00002 //# Copyright (C) 2008
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 QPAXIS_QO_H_
00028 #define QPAXIS_QO_H_
00029 
00030 #ifdef AIPS_HAS_QWT
00031 
00032 #include <graphics/GenericPlotter/PlotOptions.h>
00033 #include <graphics/GenericPlotter/PlotLogger.h>
00034 #include <graphics/GenericPlotter/Plotter.h>
00035 #include <casaqt/QwtPlotter/QPImageCache.h>
00036 #include <casaqt/QwtPlotter/QPLayeredCanvas.qo.h>
00037 #include <casaqt/QwtPlotter/QPExportCanvas.h>
00038 #include <casaqt/QwtPlotter/QPOptions.h>
00039 #include <casaqt/QwtPlotter/AxisListener.h>
00040 #include <casaqt/QwtPlotter/QPPlotItem.qo.h>
00041 
00042 #include <qwt_plot_picker.h>
00043 
00044 #include <QtGui>
00045 
00046 #include <vector>
00047 
00048 namespace casa {
00049 
00050 //# Forward declarations
00051 class QPPlotter;
00052 class ExternalAxisWidget;
00053 
00054 // Implementation of PlotCanvas for the Qwt plotter.  Mainly consists of
00055 // wrappers and containers around a QwtPlot object.
00056 class QPAxis : public QFrame, public QPExportCanvas, public AxisListener {
00057     Q_OBJECT
00058     
00059     friend class QPAxesCache;
00060     friend class QPDrawThread;
00061     friend class QPLayeredCanvas;
00062     friend class QPPlotItem;
00063     friend class QPPlotter;
00064     
00065 public:
00066     // Static //
00067     
00068     // Keep a z-order variable to increment for subsequent items.
00069     static double zOrder;
00070     
00071     // Convenient access to class name (QPCanvas).
00072     static const String CLASS_NAME;
00073     
00074     // Convenient access to "origin" names for logging.
00075     // <group>
00076     static const String DRAW_NAME;
00077 
00078     // </group>
00079     
00080     
00081 
00082     
00083     // Non-Static //
00084     
00085     // Constructor which takes (optional) parent QPPlotter.
00086     QPAxis(PlotAxis axis, QPPlotter* parent, QwtPlot* associatedPlot,
00087                 bool leftAxisInternal, bool bottomAxisInternal,
00088                 bool rightAxisInternal );
00089 
00090     // Destructor.
00091     virtual ~QPAxis();
00092     
00093 
00094 
00095     // Implements PlotCanvas::legendShown().
00096        bool legendShown() const{return false;};
00097 
00098        // Implements PlotCanvas::showLegend().
00099        void showLegend(bool /*on = true*/, LegendPosition /*position = EXT_BOTTOM*/){}
00100 
00101        // Implements PlotCanvas::legendPosition().
00102        LegendPosition legendPosition() const {
00103            return PlotCanvas::INT_URIGHT;
00104        }
00105 
00106        // Implements PlotCanvas::setLegendPosition().
00107        void setLegendPosition(LegendPosition /*position*/){}
00108 
00109        // Implements PlotCanvas::legendLine().
00110        PlotLinePtr legendLine() const {
00111            return PlotLinePtr();
00112        }
00113 
00114        virtual void setMinimumSizeHint( int width, int height );
00115 
00116        // Implements PlotCanvas::setLegendLine().
00117        void setLegendLine(const PlotLine& /*line*/){}
00118 
00119        // Implements PlotCanvas::legendFill().
00120        PlotAreaFillPtr legendFill() const {
00121            return PlotAreaFillPtr();
00122        }
00123 
00124        // Implements PlotCanvas::setLegendFill().
00125        void setLegendFill(const PlotAreaFill& /*area*/){}
00126 
00127        // Implements PlotCanvas::legendFont().
00128        PlotFontPtr legendFont() const {
00129            return PlotFontPtr();
00130        }
00131 
00132        // Implements PlotCanvas::setLegendFont().
00133        void setLegendFont(const PlotFont& /*font*/){}
00134 
00135     // PlotCanvas Methods //
00136     virtual void setCommonAxes( bool /*commonX*/, bool /*commonY*/ ){}
00137     
00138     // Implements PlotCanvas::size().
00139     std::pair<int, int> size() const;
00140     virtual void setMinimumSize( int width, int height ){
00141         QFrame::setMinimumSize( width, height );
00142     }
00143 
00144     bool isDrawing( );
00145 
00146     virtual void show(){
00147         QFrame::show();
00148     }
00149 
00150     virtual void hide(){
00151         QFrame::show();
00152     }
00153 
00154     // Implements PlotCanvas::title().
00155     String title() const;
00156 
00157     // Implements PlotCanvas::setTitle().
00158     void setTitle(const String& title);
00159     
00160     // Implements PlotCanvas::titleFont().
00161     PlotFontPtr titleFont() const;
00162     
00163     // Implements PlotCanvas::setTitleFont().
00164     void setTitleFont(const PlotFont& font);
00165     
00166     // Implements PlotCanvas::background().
00167     PlotAreaFillPtr background() const;
00168     
00169     // Implements PlotCanvas::setBackground().
00170     void setBackground(const PlotAreaFill& areaFill);
00171 
00172     // Implements PlotCanvas::cursor().
00173     PlotCursor cursor() const;
00174     
00175     // Implements PlotCanvas::setCursor().
00176     void setCursor(PlotCursor cursor);
00177     
00178     // Implements PlotCanvas::refresh().
00179     // <group>
00180     void refresh();
00181     void refresh(int drawLayersFlag);
00182     // </group>
00183     
00184     // Implements PlotCanvas::isQWidget().
00185     bool isQWidget() const { return true; }
00186 
00187     
00188     // Implements PlotCanvas::shownAxes().
00189     // Returns a bit set (really an int) of bits defined by PlotAxis enum or'd together
00190     PlotAxisBitset shownAxes() const;
00191 
00192     // Implements PlotCanvas::showAxes().
00193     // Takes a bit set, as an int, of bits defined by PlotAxis enum or'd together
00194     void showAxes(PlotAxisBitset axes);
00195     
00196     // Implements PlotCanvas::axisScale().
00197     PlotAxisScale axisScale(PlotAxis axis) const;
00198 
00199     // Implements PlotCanvas::setAxisScale().
00200     void setAxisScale(PlotAxis axis, PlotAxisScale scale);
00201 
00202     // Implements PlotCanvas::axisReferenceValueSet().
00203     bool axisReferenceValueSet(PlotAxis axis) const;
00204     
00205     // Implements PlotCanvas::axisReferenceValueValue().
00206     double axisReferenceValue(PlotAxis axis) const;
00207     
00208     // Implements PlotCanvas::setAxisReferenceValue().
00209     void setAxisReferenceValue(PlotAxis axis, bool on, double value = 0);
00210     
00211     // Implements PlotCanvas::cartesianAxisShown().
00212     bool cartesianAxisShown(PlotAxis axis) const;
00213 
00214     // Implements PlotCanvas::showCartesianAxis().
00215     void showCartesianAxis(PlotAxis mirrorAxis, PlotAxis secondaryAxis,
00216             bool show = true, bool hideNormalAxis = true);
00217     
00218     // Implements PlotCanvas::axisLabel().
00219     String axisLabel(PlotAxis axis) const;
00220 
00221     // Implements PlotCanvas::setAxisLabel().
00222     void setAxisLabel(PlotAxis axis, const String& title);
00223 
00224     // Implements PlotCanvas::axisFont().
00225     PlotFontPtr axisFont(PlotAxis axis) const;
00226     
00227     // Implements PlotCanvas::setAxisFont().
00228     void setAxisFont(PlotAxis axis, const PlotFont& font);
00229 
00230     // Implements PlotCanvas::colorBarShown().
00231     bool colorBarShown(PlotAxis axis = Y_RIGHT) const;
00232 
00233     // Implements PlotCanvas::showColorBar().
00234     void showColorBar(bool show = true, PlotAxis axis = Y_RIGHT);
00235 
00236     
00237     // Implements PlotCanvas::axisRange().
00238     prange_t axisRange(PlotAxis axis) const;
00239 
00240     // Implements PlotCanvas::setAxisRange().
00241     void setAxisRange(PlotAxis axis, double from, double to);
00242     
00243     // Overrides PlotCanvas::setAxesRanges().
00244     void setAxesRanges(PlotAxis xAxis, double xFrom, double xTo,
00245                        PlotAxis yAxis, double yFrom, double yTo);
00246     
00247     // Implements PlotCanvas::axesAutoRescale().
00248     bool axesAutoRescale() const;
00249 
00250     // Implements PlotCanvas::setAxesAutoRescale().
00251     void setAxesAutoRescale(bool autoRescale = true);
00252 
00253     // Implements PlotCanvas::rescaleAxes().
00254     void rescaleAxes();
00255 
00256     // Implements PlotCanvas::axesRatioLocked().
00257     bool axesRatioLocked() const;
00258     
00259     // Implements PlotCanvas::setAxesRatioLocked().
00260     void setAxesRatioLocked(bool locked = true);
00261     
00262        
00263     // Implements PlotCanvas::cachedAxesStackSizeLimit().
00264     int cachedAxesStackSizeLimit() const;
00265 
00266     // Implements PlotCanvas::setCachedAxesStackSizeLimit().
00267     void setCachedAxesStackSizeLimit(int sizeInKilobytes);
00268     
00269     // Overrides PlotCanvas::cachedAxesStackImageSize().
00270     std::pair<int, int> cachedAxesStackImageSize() const;
00271     
00272     // Overrides PlotCanvas::setCachedAxesStackImageSize().
00273     void setCachedAxesStackImageSize(int width, int height);
00274 
00275 
00276     // Implements PlotCanvas::plotItem().  If the given items is NOT an
00277     // instance of a QPPlotItem, a copy of the given items is made.  The
00278     // original item is NOT kept by the canvas, so any subsequent changes to
00279     // the original items will not be reflected on the canvas.
00280     bool plotItem(PlotItemPtr item, PlotCanvasLayer layer = MAIN);
00281 
00282     // Implements PlotCanvas::allPlotItems().
00283     std::vector<PlotItemPtr> allPlotItems() const;
00284     
00285     // Implements PlotCanvas::layerPlotItems().
00286     std::vector<PlotItemPtr> layerPlotItems(PlotCanvasLayer layer) const;
00287 
00288     // Overrides PlotCanvas::numPlotItems().
00289     unsigned int numPlotItems() const;
00290 
00291     // Overrides PlotCanvas::numLayerPlotItems().
00292     unsigned int numLayerPlotItems(PlotCanvasLayer layer) const;
00293     
00294     // Implements PlotCanvas::removePlotItems().
00295     void removePlotItems(const std::vector<PlotItemPtr>& items);
00296     
00297     // Overrides PlotCanvas::clearPlotItems().
00298     void clearPlotItems();
00299     
00300     // Overrides PlotCanvas::clearPlots().
00301     void clearPlots();
00302     
00303     virtual void setNotUsed(){}
00304 
00305     // Overrides PlotCanvas::clearLayer().
00306     void clearLayer(PlotCanvasLayer layer);
00307 
00308     
00309     // Implements PlotCanvas::holdDrawing().
00310     void holdDrawing();
00311     
00312     // Implements PlotCanvas::releaseDrawing().
00313     void releaseDrawing();
00314     
00315     // Implements PlotCanvas::drawingIsHeld().
00316     bool drawingIsHeld() const;
00317 
00318         
00319     // Implements PlotCanvas::setSelectLineShown().
00320     void setSelectLineShown(bool shown = true);
00321     
00322     // Implements PlotCanvas::selectLine().
00323     PlotLinePtr selectLine() const;
00324     
00325     // Implements PlotCanvas::setSelectLine().
00326     void setSelectLine(const PlotLine& line);
00327 
00328     
00329     // Implements PlotCanvas::gridShown().
00330     bool gridShown(bool* xMajor = NULL, bool* xMinor = NULL,
00331             bool* yMajor = NULL, bool* yMinor = NULL) const;
00332     
00333     // Implements PlotCanvas::showGrid().
00334     void showGrid(bool xMajor, bool xMinor, bool yMajor,bool yMinor);
00335     
00336     // Implements PlotCanvas::gridMajorLine().
00337     PlotLinePtr gridMajorLine() const;
00338 
00339     // Implements PlotCanvas::setGridMajorLine().
00340     void setGridMajorLine(const PlotLine& line);
00341 
00342     // Implements PlotCanvas::gridMinorLine().
00343     PlotLinePtr gridMinorLine() const;
00344 
00345     // Implements PlotCanvas::setGridMinorLine().
00346     void setGridMinorLine(const PlotLine& line);
00347 
00348 
00349 
00350     // Implements PlotCanvas::autoIncrementColors().
00351     bool autoIncrementColors() const;
00352 
00353     // Implements PlotCanvas::setAutoIncrementColors().
00354     void setAutoIncrementColors(bool autoInc = true);
00355 
00356     // Implements PlotCanvas::exportToFile().
00357     bool exportToFile(const PlotExportFormat& format);
00358 
00359     // Implements PlotCanvas::fileChooserDialog().
00360     String fileChooserDialog(const String& title = "File Chooser",
00361             const String& directory = "");
00362     
00363     // Implements PlotCanvas::dateFormat().
00364     const String& dateFormat() const;
00365     
00366     // Implements PlotCanvas::setDateFormat().
00367     void setDateFormat(const String& dateFormat);
00368     
00369     // Implements PlotCanvas::relativeDateFormat().
00370     const String& relativeDateFormat() const;
00371     
00372     // Implements PlotCanvas::setRelativeDateFormat().
00373     void setRelativeDateFormat(const String& dateFormat);
00374 
00375     // Implements PlotCanvas::convertCoordinate().
00376     PlotCoordinate convertCoordinate(const PlotCoordinate& coord,
00377            PlotCoordinate::System newSystem = PlotCoordinate::WORLD) const;
00378 
00379     // Implements PlotCanvas::textWidthHeightDescent().
00380     std::vector<double> textWidthHeightDescent(const String& text,
00381             PlotFontPtr font) const;
00382     
00383     // Implements PlotCanvas::implementation().
00384     int implementation() const { return Plotter::QWT; }
00385     
00386     // Implements PlotCanvas::implementationFactory().
00387     PlotFactory* implementationFactory() const;
00388     virtual bool print( QPrinter& printer );
00389     virtual QImage grabImageFromCanvas(const PlotExportFormat& format );
00390     virtual bool print(  QPainter* painter, PlotAreaFillPtr paf, double widgetWidth,
00391                 double widgetHeight, int axisWidth, int axisHeight, int rowIndex, int colIndex, 
00392                 QRect imageRect );
00393     virtual bool printRect( QPainter* painter, QRect rect);
00394     virtual const QPalette& palette() const;
00395     virtual QPalette::ColorRole backgroundRole() const;
00396     virtual bool isAxis() const {
00397                 return true;
00398         }
00399     virtual bool isVertical() const {
00400         bool vertical = false;
00401         if ( axisType == QwtPlot::yLeft || axisType == QwtPlot::yRight ){
00402                 vertical = true;
00403         }
00404         return vertical;
00405     }
00406 
00407 protected:
00408     // Sets the parent QPPlotter to the given.  This MUST be done when a canvas
00409     // is added to the plotter so that it can use the plotter's logger if
00410     // needed.
00411     void setQPPlotter(QPPlotter* parent);
00412     
00413     // Returns the parent's logger.
00414     virtual PlotLoggerPtr logger() const;
00415     
00416     // See QPPlotter::logObject().  If called before setQPPlotter() is called,
00417     // creates a queue that is then posted when setQPPlotter() is called.
00418     void logObject(const String& className, void* address, bool creation,
00419             const String& message = String());
00420     
00421     // See QPPlotter::logMethod().  Does NOT queue messages if called before
00422     // setQPPlotter() is called.
00423     void logMethod(const String& className, const String& methodName,
00424             bool entering, const String& message = String());
00425     
00426     // Provides access to the cached axes stack.
00427     // <group>
00428     //QPAxesCache& axesCache();
00429     //const QPAxesCache& axesCache() const;
00430     // </group>
00431     
00432 
00433 
00434 private:
00435     // Parent QPPlotter.
00436     QPPlotter* m_parent;
00437     
00438     QwtPlot::Axis axisType;
00439 
00440     // Queued log messages before parent is set.
00441     std::vector<PlotLogObject> m_queuedLogs;
00442     
00443 
00444     // Whether the axes ratio is locked or not.
00445     bool m_axesRatioLocked;
00446     
00447     // Used for recalculating axes ranges if the ratio is locked.
00448     std::vector<double> m_axesRatios;
00449 
00450     // Date formats.
00451     // <group>
00452     String m_dateFormat;
00453     String m_relativeDateFormat;
00454     // </group>
00455     
00456     //External Axis
00457     ExternalAxisWidget* axisWidget;
00458        
00459     // Converts the given Qt global position to a pixel PlotCoordinate.
00460     // <group>
00461     PlotCoordinate globalPosToPixelCoord(int x, int y);
00462     PlotCoordinate globalPosToPixelCoord(QMouseEvent* event) {
00463         return globalPosToPixelCoord(event->globalX(), event->globalY()); }
00464     PlotCoordinate globalPosToPixelCoord(QWheelEvent* event) {
00465         return globalPosToPixelCoord(event->globalX(), event->globalY()); }
00466     // </group>
00467     
00468 
00469     
00470     // Converts between axes bitset flags (1,2,4,8 in PlotAxis and vector indices (0-3).
00471     // (Does not deal with bitsets for combinations of axes, only single axis)
00472     // <group>
00473     static unsigned int axisIndex(PlotAxis a);   
00474     static PlotAxis axisIndex(unsigned int i);
00475     // </group>
00476     
00477     
00478     virtual int canvasWidth() const{
00479         return width();
00480       }
00481       virtual int canvasHeight() const {
00482         return height();
00483       }
00484 
00485 
00486 };
00487 
00488 }
00489 
00490 #endif
00491 
00492 #endif /*QPCANVAS_QO_H_*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1