QPOptions.h

Go to the documentation of this file.
00001 //# QPOptions.h: Qwt implementation of generic PlotOption classes.
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 QPOPTIONS_QO_H_
00028 #define QPOPTIONS_QO_H_
00029 
00030 #ifdef AIPS_HAS_QWT
00031 
00032 #include <graphics/GenericPlotter/PlotOperation.h>
00033 #include <graphics/GenericPlotter/PlotOptions.h>
00034 
00035 #include <QColor>
00036 #include <QFont>
00037 #include <QMutex>
00038 
00039 #include <qwt_color_map.h>
00040 #include <qwt_plot.h>
00041 #include <qwt_symbol.h>
00042 
00043 namespace casa {
00044 
00045 // Implementation of PlotColor for Qwt plotter, using QColor.
00046 class QPColor : public PlotColor {
00047 public:
00048     // Defaults to QColor::QColor().
00049     QPColor();
00050 
00051     // Constructor for the given hex value or name.
00052     QPColor(const String& name);
00053     
00054     // Constructor using a QColor.
00055     QPColor(const QColor& color);
00056     
00057     // Copy constructor for generic PlotColor.
00058     // <group>
00059     QPColor(const PlotColor& color);
00060     QPColor(const PlotColorPtr color);
00061     // </group>
00062     
00063     // Copy constructor.
00064     QPColor(const QPColor& color);
00065     
00066     // Destructor.
00067     ~QPColor();
00068     
00069     
00070     // Include overloaded methods.
00071     using PlotColor::operator=;
00072     
00073     
00074     // PlotColor Methods //
00075     
00076     // Implements PlotColor::asHexadecimal().
00077     String asHexadecimal() const;
00078        
00079     // Implements PlotColor::asName().
00080     String asName() const;    
00081 
00082     // Implements PlotColor::asHexadecimalOrName().
00083     void setAsHexadecimalOrName(const String& str);
00084     
00085     // Implements PlotColor::alpha().
00086     double alpha() const;
00087     
00088     // Implements PlotColor::setAlpha().
00089     void setAlpha(double a);
00090     
00091     
00092     // QPColor Methods //
00093     
00094     // Provides access to the underlying QColor.
00095     // <group>
00096     const QColor& asQColor() const;
00097     void setAsQColor(const QColor& color);
00098     // </group>
00099     
00100 private:
00101     QColor m_color; // Color
00102 };
00103 
00104 
00105 // Implementation of PlotFont for Qwt plotter, using QFont and QPColor.
00106 class QPFont : public PlotFont {
00107 public:
00108     // Defaults to QFont::QFont() and QPColor::QPColor().
00109     QPFont();
00110     
00111     // Constructor that takes a QFont and QColor.
00112     QPFont(const QFont& font, const QColor& color);
00113     
00114     // Copy constructor for generic PlotFont.
00115     // <group>
00116     QPFont(const PlotFont& font);
00117     QPFont(const PlotFontPtr font);
00118     // </group>
00119     
00120     // Copy constructor.
00121     QPFont(const QPFont& font);
00122     
00123     // Destructor.
00124     ~QPFont();
00125     
00126     
00127     // Include overloaded methods.
00128     using PlotFont::operator=;
00129     using PlotFont::setColor;
00130     
00131     
00132     // PlotFont Methods //
00133     
00134     // Implements PlotFont::pointSize().
00135     double pointSize() const;
00136 
00137     // Implements PlotFont::setPointSize().
00138     void setPointSize(double size);
00139     
00140     // Implements PlotFont::pixelSize().
00141     int pixelSize() const;
00142     
00143     // Implements PlotFont::setPixelSize().
00144     void setPixelSize(int size);
00145     
00146     // Implements PlotFont::fontFamily().
00147     String fontFamily() const;
00148     
00149     // Implements PlotFont::setFontFamily().
00150     void setFontFamily(const String& font);
00151     
00152     // Implements PlotFont::color().
00153     PlotColorPtr color() const;
00154     
00155     // Implements PlotFont::setColor().
00156     void setColor(const PlotColor& color);
00157     
00158     // Implements PlotFont::italics().
00159     bool italics() const;
00160     
00161     // Implements PlotFont::setItalics().
00162     void setItalics(bool i = true);
00163     
00164     // Implements PlotFont::bold().
00165     bool bold() const;
00166     
00167     // Implements PlotFont::setBold().
00168     void setBold(bool b = true);
00169     
00170     // Implements PlotFont::underline().
00171     bool underline() const;
00172     
00173     // Implements PlotFont::setUnderline().
00174     void setUnderline(bool u = true);
00175     
00176     
00177     // QPFont Methods //
00178     
00179     // Provides access to the underlying QFont.
00180     // <group>
00181     const QFont& asQFont() const;
00182     void setAsQFont(const QFont& font);
00183     // </group>
00184     
00185     // Provides access to the underlying QColor through QPColor.
00186     // <group>
00187     const QColor& asQColor() const;
00188     void setAsQColor(const QColor& color);
00189     // </group>
00190     
00191 private:
00192     QFont m_font;    // Font
00193     QPColor m_color; // Color
00194 };
00195 
00196 
00197 // Implementation of PlotLine for Qwt plotter, using QPen.
00198 class QPLine : public PlotLine {
00199 public:
00200     // Defaults to QPen::QPen().
00201     QPLine();
00202     
00203     // Constructor that takes a QPen.
00204     QPLine(const QPen& pen);
00205     
00206     // Copy constructor for generic PlotLine.
00207     // <group>
00208     QPLine(const PlotLine& copy);
00209     QPLine(const PlotLinePtr copy);
00210     // </group>
00211     
00212     // Destructor.
00213     ~QPLine();
00214     
00215     
00216     // Include overloaded methods.
00217     using PlotLine::operator=;
00218     using PlotLine::setColor;
00219     
00220     
00221     // PlotLine Methods //
00222     
00223     // Implements PlotLine::width().
00224     double width() const;
00225     
00226     // Implements PlotLine::setWidth().
00227     void setWidth(double width);
00228     
00229     // Implements PlotLine::style().
00230     Style style() const;
00231     
00232     // Implements PlotLine::setStyle().
00233     void setStyle(Style style);
00234     
00235     // Implements PlotLine::color().
00236     PlotColorPtr color() const;
00237     
00238     // Implements PlotLine::setColor().
00239     void setColor(const PlotColor& color);
00240     
00241     
00242     // QPLine Methods //
00243     
00244     // Provides access to the underlying QPen.
00245     // <group>
00246     const QPen& asQPen() const;
00247     void setAsQPen(const QPen& pen);
00248     // </group>
00249     
00250 private:
00251     QPen m_pen;      // Pen
00252     QPColor m_color; // Color (for convenience)
00253 };
00254 
00255 
00256 // Implementation of PlotAreaFill for Qwt plotter, using QBrush.
00257 class QPAreaFill : public PlotAreaFill {
00258 public:
00259     // Defaults to QBrush::QBrush().
00260     QPAreaFill();
00261     
00262     // Constructor that takes a QBrush.
00263     QPAreaFill(const QBrush& brush);
00264     
00265     // Copy constructor for generic PlotAreaFill.
00266     // <group>
00267     QPAreaFill(const PlotAreaFill& copy);
00268     QPAreaFill(const PlotAreaFillPtr copy);
00269     // </group>
00270     
00271     // Destructor.
00272     ~QPAreaFill();
00273     
00274     
00275     // Include overloaded methods.
00276     using PlotAreaFill::operator=;
00277     using PlotAreaFill::setColor;
00278     
00279     
00280     // PlotAreaFill Methods //
00281     
00282     // Implements PlotAreaFill::color().
00283     PlotColorPtr color() const;
00284     
00285     // Implements PlotAreaFill::setColor().
00286     void setColor(const PlotColor& color);
00287     
00288     // Implements PlotAreaFill::pattern().
00289     Pattern pattern() const;
00290     
00291     // Implements PlotAreaFill::setPattern().
00292     void setPattern(Pattern pattern);
00293     
00294     
00295     // QPAreaFill Methods //
00296     
00297     // Provides access to the underlying QBrush.
00298     // <group>
00299     const QBrush& asQBrush() const;    
00300     void setAsQBrush(const QBrush& brush);
00301     // </group>
00302     
00303 private:
00304     QBrush m_brush;  // Brush.
00305     QPColor m_color; // color (for convenience).
00306 };
00307 
00308 
00309 // Implementation of QPSymbol for Qwt plotter, using QwtSymbol.
00310 class QPSymbol : public PlotSymbol, public QwtSymbol {
00311 public:
00312     // Defaults to QwtSymbol::QwtSymbol().
00313     QPSymbol();
00314    
00315 #if QWT_VERSION >= 0x060000
00316     // Implement QwtSymbol constructor
00317     QPSymbol(QwtSymbol::Style style, const QBrush & brush, 
00318         const QPen & pen, const QSize & sz);
00319 #else
00320     // Copy constructor for QwtSymbol (private in Qwt6)
00321     QPSymbol(const QwtSymbol& s);
00322 #endif
00323     
00324     // Copy constructor for generic PlotSymbol.
00325     // <group>
00326     QPSymbol(const PlotSymbol& copy);
00327     QPSymbol(const PlotSymbolPtr copy);
00328     // </group>
00329     
00330     // Destructor.
00331     ~QPSymbol();
00332     
00333     
00334     // Include overloaded methods.
00335     using PlotSymbol::operator=;
00336     using PlotSymbol::setSize;
00337     using PlotSymbol::setAreaFill;
00338     using PlotSymbol::setLine;
00339     
00340     
00341     // PlotSymbol Methods //
00342     
00343     // Implements PlotSymbol::size().
00344     psize_t size() const;
00345     
00346     // Implements PlotSymbol::setSize().  Note that the underlying QwtSymbol
00347     // only supports int sizes.
00348     void setSize(double width, double height, bool heightIsPixel = true);
00349     
00350     // Implements PlotSymbol::heightIsPixel().
00351     bool heightIsPixel() const;
00352     
00353     // Implements PlotSymbol::setHeightIsPixel().
00354     void setHeightIsPixel(bool pixel = true);
00355     
00356     // Implements PlotSymbol::symbol().
00357     Symbol symbol() const;
00358     
00359     // Implements PlotSymbol::symbolChar().
00360     char symbolChar() const;
00361     
00362     // Implements PlotSymbol::symbolUChar().
00363     unsigned short symbolUChar() const;
00364     
00365     // Implements PlotSymbol::setSymbol().
00366     // <group>
00367     void setSymbol(Symbol symbol);
00368     void setSymbol(char c);
00369     // </group>
00370     
00371     // Implements PlotSymbol::setUSymbol().
00372     void setUSymbol(unsigned short unicode);
00373     
00374     // Implements PlotSymbol::line().
00375     PlotLinePtr line() const;
00376     
00377     // Implements PlotSymbol::setLine().
00378     void setLine(const PlotLine& line);
00379     
00380     // Implements PlotSymbol::areaFill().
00381     PlotAreaFillPtr areaFill() const;
00382     
00383     // Implements PlotSymbol::setAreaFill().
00384     void setAreaFill(const PlotAreaFill& fill);
00385     
00386     
00387     // QwtSymbol Methods //
00388     
00389     // Overrides QwtSymbol::draw().  Assumes pen and brush have been set
00390     // beforehand.
00391     void draw(QPainter* p, const QRect& r) const;
00392     
00393     // Overrides QwtSymbol::clone().
00394     //QwtSymbol* clone() const;
00395     
00396     
00397     // QPSymbol Methods //
00398     
00399     // Provides access to the underlying QPen and QBrush in a safe way,
00400     // since QPainter::drawPoint works differently than the other draw
00401     // methods.  WARNING: the pixel pen is NOT updated if you call
00402     // QwtSymbol::setPen() AFTER a QPSymbol::setSymbol() or a
00403     // QPSymbol::setLine() or a QPSymbol::setAreaFill().
00404     // <group>
00405     const QPen& drawPen() const;
00406     const QBrush& drawBrush() const;
00407     // </group>
00408     
00409 private:
00410     Symbol m_style; // Style
00411     QChar m_char;   // Character
00412     
00413     bool m_heightIsPixel; // Flag for whether height is in pixels or points.
00414     
00415     QPen m_pixelPen;     // Pen used to draw pixels.
00416     QBrush m_pixelBrush; // Brush used to draw pixels (empty).
00417     
00418     // Points to either QwtSymbol::pen() or the pixel pen.
00419     const QPen* m_drawPen;
00420     
00421     // Points to either QwtSymbol::brush() or the pixel brush.
00422     const QBrush* m_drawBrush;
00423 };
00424 
00425 
00426 // Implementation of PlotMutex for the qwt plotter.  Very thin layer on top of
00427 // QMutex.
00428 class QPMutex : public PlotMutex {
00429 public:
00430     // Constructor.
00431     QPMutex();
00432     
00433     // Destructor.
00434     ~QPMutex();
00435     
00436     
00437     // Implements PlotMutex::lock().
00438     void lock();
00439     
00440     // Implements PlotMutex::unlock().
00441     void unlock();
00442     
00443     // Implements PlotMutex::tryLock().
00444     bool tryLock();
00445     
00446 private:
00447     // Mutex.
00448     QMutex m_mutex;
00449 };
00450 
00451 
00452 // Class containing useful conversions between the generic plotting stuff and
00453 // the Qt/Qwt plotting stuff.
00454 class QPOptions {
00455 public:
00456     // Converts between Qwt's axis enum and CASA's.
00457     // <group>
00458     static QwtPlot::Axis axis(PlotAxis a);
00459     static PlotAxis axis(QwtPlot::Axis a);
00460     static bool isAxisX( PlotAxis a );
00461 
00462     // </group>
00463     
00464     // Converts between Qt's cursors and CASA's.
00465     // <group>
00466     static Qt::CursorShape cursor(PlotCursor c) {
00467         switch(c) {
00468         case NORMAL_CURSOR: return Qt::ArrowCursor;
00469         case HAND_OPEN:     return Qt::OpenHandCursor;
00470         case HAND_CLOSED:   return Qt::ClosedHandCursor;
00471         case CROSSHAIR:     return Qt::CrossCursor;
00472         case WAIT:          return Qt::WaitCursor;
00473         case TEXT:          return Qt::IBeamCursor;
00474         
00475         default: return Qt::ArrowCursor;
00476         }
00477     }    
00478     static PlotCursor cursor(Qt::CursorShape c) {
00479         switch(c) {
00480         case Qt::ArrowCursor:                     return NORMAL_CURSOR;
00481         case Qt::OpenHandCursor:                  return HAND_OPEN;
00482         case Qt::ClosedHandCursor:                return HAND_CLOSED;
00483         case Qt::CrossCursor:                     return CROSSHAIR;
00484         case Qt::WaitCursor: case Qt::BusyCursor: return WAIT;
00485         case Qt::IBeamCursor:                     return TEXT;
00486         
00487         default:                                  return NORMAL_CURSOR;
00488         }
00489     }
00490     // </group>
00491     
00492     // Converts between Qt's line style and CASA's.
00493     // <group>
00494     static Qt::PenStyle linestyle(PlotLine::Style s) {
00495         switch(s) {
00496         // supported
00497         case PlotLine::SOLID: return Qt::SolidLine;
00498         case PlotLine::DASHED: return Qt::DashLine;
00499         case PlotLine::DOTTED: return Qt::DotLine;
00500         
00501         // unsupported
00502         default: return Qt::NoPen;
00503         }
00504     }    
00505     static PlotLine::Style linestyle(Qt::PenStyle s) {
00506         switch(s) {
00507         // supported
00508         case Qt::SolidLine: return PlotLine::SOLID;
00509         case Qt::DashLine: return PlotLine::DASHED;
00510         case Qt::DotLine: return PlotLine::DOTTED;
00511         
00512         // unsupported
00513         default: return PlotLine::NOLINE;
00514         }
00515     }
00516     // </group>
00517     
00518     // Converts between Qt's brush style and CASA's.
00519     // <group>
00520     static Qt::BrushStyle areapattern(PlotAreaFill::Pattern p) {
00521         switch(p) {
00522         // supported
00523         case PlotAreaFill::FILL: return Qt::SolidPattern;
00524         case PlotAreaFill::MESH1: return Qt::Dense2Pattern;
00525         case PlotAreaFill::MESH2: return Qt::Dense4Pattern;
00526         case PlotAreaFill::MESH3: return Qt::Dense6Pattern;
00527         
00528         // unsupported
00529         default: return Qt::NoBrush;
00530         }
00531     }    
00532     static PlotAreaFill::Pattern areapattern(Qt::BrushStyle p) {
00533         switch(p) {
00534         // supported
00535         case Qt::SolidPattern: return PlotAreaFill::FILL;
00536         case Qt::Dense1Pattern: case Qt::Dense2Pattern:
00537             return PlotAreaFill::MESH1;
00538         case Qt::Dense3Pattern: case Qt::Dense4Pattern:
00539             return PlotAreaFill::MESH2;
00540         case Qt::Dense5Pattern: case Qt::Dense6Pattern: case Qt::Dense7Pattern:
00541             return PlotAreaFill::MESH3;
00542         
00543         // unsupported
00544         default: return PlotAreaFill::NOFILL;
00545         }
00546     }
00547     // </group>
00548     
00549     // Converts between Qwt's symbol style and CASA's.
00550     // <group>
00551     static QwtSymbol::Style symbol(PlotSymbol::Symbol s) {
00552         switch(s) {
00553         // supported
00554         case PlotSymbol::AUTOSCALING:
00555         case PlotSymbol::CIRCLE: return QwtSymbol::Ellipse;
00556         case PlotSymbol::SQUARE: return QwtSymbol::Rect;
00557         case PlotSymbol::DIAMOND: return QwtSymbol::Diamond;
00558         
00559         // unsupported
00560         default: return QwtSymbol::NoSymbol;
00561         }
00562     }    
00563     static PlotSymbol::Symbol symbol(QwtSymbol::Style s) {
00564         switch(s) {
00565         // supported
00566         case QwtSymbol::Ellipse: return PlotSymbol::CIRCLE;
00567         case QwtSymbol::Rect: return PlotSymbol::SQUARE;
00568         case QwtSymbol::Diamond: return PlotSymbol::DIAMOND;
00569         
00570         // unsupported
00571         default: return PlotSymbol::NOSYMBOL;
00572         }
00573     }
00574     // </group>
00575     
00576     // Returns a string to be used in stylesheet css for the given style.
00577     static String cssLineStyle(PlotLine::Style style) {
00578         switch(style) {
00579         case PlotLine::SOLID:  return "solid";
00580         case PlotLine::DASHED: return "dashed";
00581         case PlotLine::DOTTED: return "dotted";
00582         
00583         default: return "";
00584         }
00585     }
00586     
00587     // Rounds the given double to the nearest int.
00588     static int round(double d) {
00589         if(d >= 0) return (int)(d + 0.5);
00590         else return (int)(d - 0.5);
00591     }
00592     
00593     // Returns color maps for standard CASA objects.
00594     // <group>
00595     static QwtLinearColorMap* standardSpectrogramMap();    
00596     static QwtLinearColorMap* standardRasterMap();   
00597     static QwtLinearColorMap* rasterMap(const vector<double>& values);
00598     // </group>
00599 };
00600 
00601 }
00602 
00603 #endif
00604 
00605 #endif /*QPOPTIONS_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