casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QPOptions.h
Go to the documentation of this file.
1 //# QPOptions.h: Qwt implementation of generic PlotOption classes.
2 //# Copyright (C) 2008
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef QPOPTIONS_QO_H_
28 #define QPOPTIONS_QO_H_
29 
30 #ifdef AIPS_HAS_QWT
31 
34 
35 #include <QColor>
36 #include <QFont>
37 #include <QMutex>
38 
39 #include <qwt_color_map.h>
40 #include <qwt_plot.h>
41 #include <qwt_symbol.h>
42 
43 namespace casa {
44 
45 // Implementation of PlotColor for Qwt plotter, using QColor.
46 class QPColor : public PlotColor {
47 public:
48  // Defaults to QColor::QColor().
49  QPColor();
50 
51  // Constructor for the given hex value or name.
52  QPColor(const casacore::String& name);
53 
54  // Constructor using a QColor.
55  QPColor(const QColor& color);
56 
57  // Copy constructor for generic PlotColor.
58  // <group>
59  QPColor(const PlotColor& color);
60  QPColor(const PlotColorPtr color);
61  // </group>
62 
63  // Copy constructor.
64  QPColor(const QPColor& color);
65 
66  // Destructor.
67  ~QPColor();
68 
69 
70  // Include overloaded methods.
71  using PlotColor::operator=;
72 
73 
74  // PlotColor Methods //
75 
76  // Implements PlotColor::asHexadecimal().
77  casacore::String asHexadecimal() const;
78 
79  // Implements PlotColor::asName().
80  casacore::String asName() const;
81 
82  // Implements PlotColor::asHexadecimalOrName().
83  void setAsHexadecimalOrName(const casacore::String& str);
84 
85  // Implements PlotColor::alpha().
86  double alpha() const;
87 
88  // Implements PlotColor::setAlpha().
89  void setAlpha(double a);
90 
91 
92  // QPColor Methods //
93 
94  // Provides access to the underlying QColor.
95  // <group>
96  const QColor& asQColor() const;
97  void setAsQColor(const QColor& color);
98  // </group>
99 
100 private:
101  QColor m_color; // Color
102 };
103 
104 
105 // Implementation of PlotFont for Qwt plotter, using QFont and QPColor.
106 class QPFont : public PlotFont {
107 public:
108  // Defaults to QFont::QFont() and QPColor::QPColor().
109  QPFont();
110 
111  // Constructor that takes a QFont and QColor.
112  QPFont(const QFont& font, const QColor& color);
113 
114  // Copy constructor for generic PlotFont.
115  // <group>
116  QPFont(const PlotFont& font);
117  QPFont(const PlotFontPtr font);
118  // </group>
119 
120  // Copy constructor.
121  QPFont(const QPFont& font);
122 
123  // Destructor.
124  ~QPFont();
125 
126 
127  // Include overloaded methods.
128  using PlotFont::operator=;
129  using PlotFont::setColor;
130 
131 
132  // PlotFont Methods //
133 
134  // Implements PlotFont::pointSize().
135  double pointSize() const;
136 
137  // Implements PlotFont::setPointSize().
138  void setPointSize(double size);
139 
140  // Implements PlotFont::pixelSize().
141  int pixelSize() const;
142 
143  // Implements PlotFont::setPixelSize().
144  void setPixelSize(int size);
145 
146  // Implements PlotFont::fontFamily().
147  casacore::String fontFamily() const;
148 
149  // Implements PlotFont::setFontFamily().
150  void setFontFamily(const casacore::String& font);
151 
152  // Implements PlotFont::color().
153  PlotColorPtr color() const;
154 
155  // Implements PlotFont::setColor().
156  void setColor(const PlotColor& color);
157 
158  // Implements PlotFont::italics().
159  bool italics() const;
160 
161  // Implements PlotFont::setItalics().
162  void setItalics(bool i = true);
163 
164  // Implements PlotFont::bold().
165  bool bold() const;
166 
167  // Implements PlotFont::setBold().
168  void setBold(bool b = true);
169 
170  // Implements PlotFont::underline().
171  bool underline() const;
172 
173  // Implements PlotFont::setUnderline().
174  void setUnderline(bool u = true);
175 
176 
177  // QPFont Methods //
178 
179  // Provides access to the underlying QFont.
180  // <group>
181  const QFont& asQFont() const;
182  void setAsQFont(const QFont& font);
183  // </group>
184 
185  // Provides access to the underlying QColor through QPColor.
186  // <group>
187  const QColor& asQColor() const;
188  void setAsQColor(const QColor& color);
189  // </group>
190 
191 private:
192  QFont m_font; // Font
193  QPColor m_color; // Color
194 };
195 
196 
197 // Implementation of PlotLine for Qwt plotter, using QPen.
198 class QPLine : public PlotLine {
199 public:
200  // Defaults to QPen::QPen().
201  QPLine();
202 
203  // Constructor that takes a QPen.
204  QPLine(const QPen& pen);
205 
206  // Copy constructor for generic PlotLine.
207  // <group>
208  QPLine(const PlotLine& copy);
209  QPLine(const PlotLinePtr copy);
210  // </group>
211 
212  // Destructor.
213  ~QPLine();
214 
215 
216  // Include overloaded methods.
217  using PlotLine::operator=;
218  using PlotLine::setColor;
219 
220 
221  // PlotLine Methods //
222 
223  // Implements PlotLine::width().
224  double width() const;
225 
226  // Implements PlotLine::setWidth().
227  void setWidth(double width);
228 
229  // Implements PlotLine::style().
230  Style style() const;
231 
232  // Implements PlotLine::setStyle().
233  void setStyle(Style style);
234 
235  // Implements PlotLine::color().
236  PlotColorPtr color() const;
237 
238  // Implements PlotLine::setColor().
239  void setColor(const PlotColor& color);
240 
241 
242  // QPLine Methods //
243 
244  // Provides access to the underlying QPen.
245  // <group>
246  const QPen& asQPen() const;
247  void setAsQPen(const QPen& pen);
248  // </group>
249 
250 private:
251  QPen m_pen; // Pen
252  QPColor m_color; // Color (for convenience)
253 };
254 
255 
256 // Implementation of PlotAreaFill for Qwt plotter, using QBrush.
257 class QPAreaFill : public PlotAreaFill {
258 public:
259  // Defaults to QBrush::QBrush().
260  QPAreaFill();
261 
262  // Constructor that takes a QBrush.
263  QPAreaFill(const QBrush& brush);
264 
265  // Copy constructor for generic PlotAreaFill.
266  // <group>
267  QPAreaFill(const PlotAreaFill& copy);
268  QPAreaFill(const PlotAreaFillPtr copy);
269  // </group>
270 
271  // Destructor.
272  ~QPAreaFill();
273 
274 
275  // Include overloaded methods.
276  using PlotAreaFill::operator=;
278 
279 
280  // PlotAreaFill Methods //
281 
282  // Implements PlotAreaFill::color().
283  PlotColorPtr color() const;
284 
285  // Implements PlotAreaFill::setColor().
286  void setColor(const PlotColor& color);
287 
288  // Implements PlotAreaFill::pattern().
289  Pattern pattern() const;
290 
291  // Implements PlotAreaFill::setPattern().
292  void setPattern(Pattern pattern);
293 
294 
295  // QPAreaFill Methods //
296 
297  // Provides access to the underlying QBrush.
298  // <group>
299  const QBrush& asQBrush() const;
300  void setAsQBrush(const QBrush& brush);
301  // </group>
302 
303 private:
304  QBrush m_brush; // Brush.
305  QPColor m_color; // color (for convenience).
306 };
307 
308 
309 // Implementation of QPSymbol for Qwt plotter, using QwtSymbol.
310 class QPSymbol : public PlotSymbol, public QwtSymbol {
311 public:
312  // Defaults to QwtSymbol::QwtSymbol().
313  QPSymbol();
314 
315 #if QWT_VERSION >= 0x060000
316  // Implement QwtSymbol constructor
317  QPSymbol(QwtSymbol::Style style, const QBrush & brush,
318  const QPen & pen, const QSize & sz);
319 #else
320  // Copy constructor for QwtSymbol (private in Qwt6)
321  QPSymbol(const QwtSymbol& s);
322 #endif
323 
324  // Copy constructor for generic PlotSymbol.
325  // <group>
326  QPSymbol(const PlotSymbol& copy);
327  QPSymbol(const PlotSymbolPtr copy);
328  // </group>
329 
330  // Destructor.
331  ~QPSymbol();
332 
333 
334  // Include overloaded methods.
335  using PlotSymbol::operator=;
336  using PlotSymbol::setSize;
338  using PlotSymbol::setLine;
339 
340 
341  // PlotSymbol Methods //
342 
343  // Implements PlotSymbol::size().
344  psize_t size() const;
345 
346  // Implements PlotSymbol::setSize(). Note that the underlying QwtSymbol
347  // only supports int sizes.
348  void setSize(double width, double height, bool heightIsPixel = true);
349 
350  // Implements PlotSymbol::heightIsPixel().
351  bool heightIsPixel() const;
352 
353  // Implements PlotSymbol::setHeightIsPixel().
354  void setHeightIsPixel(bool pixel = true);
355 
356  // Implements PlotSymbol::symbol().
357  Symbol symbol() const;
358 
359  // Implements PlotSymbol::symbolChar().
360  char symbolChar() const;
361 
362  // Implements PlotSymbol::symbolUChar().
363  unsigned short symbolUChar() const;
364 
365  // Implements PlotSymbol::setSymbol().
366  // <group>
367  void setSymbol(Symbol symbol);
368  void setSymbol(char c);
369  // </group>
370 
371  // Implements PlotSymbol::setUSymbol().
372  void setUSymbol(unsigned short unicode);
373 
374  // Implements PlotSymbol::line().
375  PlotLinePtr line() const;
376 
377  // Implements PlotSymbol::setLine().
378  void setLine(const PlotLine& line);
379 
380  // Implements PlotSymbol::areaFill().
381  PlotAreaFillPtr areaFill() const;
382 
383  // Implements PlotSymbol::setAreaFill().
384  void setAreaFill(const PlotAreaFill& fill);
385 
386 
387  // QwtSymbol Methods //
388 
389  // Overrides QwtSymbol::draw(). Assumes pen and brush have been set
390  // beforehand.
391  void draw(QPainter* p, const QRect& r) const;
392 
393 #if QWT_VERSION >= 0x060000
394  inline void drawSymbols(QPainter* p, const QPointF* points, int numPoints) const
395  { QwtSymbol::drawSymbols(p, points, numPoints); };
396 #endif
397  // Overrides QwtSymbol::clone().
398  //QwtSymbol* clone() const;
399 
400 
401  // QPSymbol Methods //
402 
403  // Provides access to the underlying QPen and QBrush in a safe way,
404  // since QPainter::drawPoint works differently than the other draw
405  // methods. WARNING: the pixel pen is NOT updated if you call
406  // QwtSymbol::setPen() AFTER a QPSymbol::setSymbol() or a
407  // QPSymbol::setLine() or a QPSymbol::setAreaFill().
408  // <group>
409  const QPen& drawPen() const;
410  const QBrush& drawBrush() const;
411  // </group>
412 
413 private:
414  Symbol m_style; // Style
415  QChar m_char; // Character
416 
417  bool m_heightIsPixel; // Flag for whether height is in pixels or points.
418 
419  QPen m_pixelPen; // Pen used to draw pixels.
420  QBrush m_pixelBrush; // Brush used to draw pixels (empty).
421 
422  // Points to either QwtSymbol::pen() or the pixel pen.
423  const QPen* m_drawPen;
424 
425  // Points to either QwtSymbol::brush() or the pixel brush.
426  const QBrush* m_drawBrush;
427 };
428 
429 
430 // Implementation of PlotMutex for the qwt plotter. Very thin layer on top of
431 // QMutex.
432 class QPMutex : public PlotMutex {
433 public:
434  // Constructor.
435  QPMutex();
436 
437  // Destructor.
438  ~QPMutex();
439 
440 
441  // Implements PlotMutex::lock().
442  void lock();
443 
444  // Implements PlotMutex::unlock().
445  void unlock();
446 
447  // Implements PlotMutex::tryLock().
448  bool tryLock();
449 
450 private:
451  // Mutex.
452  QMutex m_mutex;
453 };
454 
455 
456 // Class containing useful conversions between the generic plotting stuff and
457 // the Qt/Qwt plotting stuff.
458 class QPOptions {
459 public:
460  // Converts between Qwt's axis enum and CASA's.
461  // <group>
462  static QwtPlot::Axis axis(PlotAxis a);
463  static PlotAxis axis(QwtPlot::Axis a);
464  static bool isAxisX( PlotAxis a );
465 
466  // </group>
467 
468  // Converts between Qt's cursors and CASA's.
469  // <group>
470  static Qt::CursorShape cursor(PlotCursor c) {
471  switch(c) {
472  case NORMAL_CURSOR: return Qt::ArrowCursor;
473  case HAND_OPEN: return Qt::OpenHandCursor;
474  case HAND_CLOSED: return Qt::ClosedHandCursor;
475  case CROSSHAIR: return Qt::CrossCursor;
476  case WAIT: return Qt::WaitCursor;
477  case TEXT: return Qt::IBeamCursor;
478 
479  default: return Qt::ArrowCursor;
480  }
481  }
482  static PlotCursor cursor(Qt::CursorShape c) {
483  switch(c) {
484  case Qt::ArrowCursor: return NORMAL_CURSOR;
485  case Qt::OpenHandCursor: return HAND_OPEN;
486  case Qt::ClosedHandCursor: return HAND_CLOSED;
487  case Qt::CrossCursor: return CROSSHAIR;
488  case Qt::WaitCursor: case Qt::BusyCursor: return WAIT;
489  case Qt::IBeamCursor: return TEXT;
490 
491  default: return NORMAL_CURSOR;
492  }
493  }
494  // </group>
495 
496  // Converts between Qt's line style and CASA's.
497  // <group>
498  static Qt::PenStyle linestyle(PlotLine::Style s) {
499  switch(s) {
500  // supported
501  case PlotLine::SOLID: return Qt::SolidLine;
502  case PlotLine::DASHED: return Qt::DashLine;
503  case PlotLine::DOTTED: return Qt::DotLine;
504 
505  // unsupported
506  default: return Qt::NoPen;
507  }
508  }
509  static PlotLine::Style linestyle(Qt::PenStyle s) {
510  switch(s) {
511  // supported
512  case Qt::SolidLine: return PlotLine::SOLID;
513  case Qt::DashLine: return PlotLine::DASHED;
514  case Qt::DotLine: return PlotLine::DOTTED;
515 
516  // unsupported
517  default: return PlotLine::NOLINE;
518  }
519  }
520  // </group>
521 
522  // Converts between Qt's brush style and CASA's.
523  // <group>
524  static Qt::BrushStyle areapattern(PlotAreaFill::Pattern p) {
525  switch(p) {
526  // supported
527  case PlotAreaFill::FILL: return Qt::SolidPattern;
528  case PlotAreaFill::MESH1: return Qt::Dense2Pattern;
529  case PlotAreaFill::MESH2: return Qt::Dense4Pattern;
530  case PlotAreaFill::MESH3: return Qt::Dense6Pattern;
531 
532  // unsupported
533  default: return Qt::NoBrush;
534  }
535  }
536  static PlotAreaFill::Pattern areapattern(Qt::BrushStyle p) {
537  switch(p) {
538  // supported
539  case Qt::SolidPattern: return PlotAreaFill::FILL;
540  case Qt::Dense1Pattern: case Qt::Dense2Pattern:
541  return PlotAreaFill::MESH1;
542  case Qt::Dense3Pattern: case Qt::Dense4Pattern:
543  return PlotAreaFill::MESH2;
544  case Qt::Dense5Pattern: case Qt::Dense6Pattern: case Qt::Dense7Pattern:
545  return PlotAreaFill::MESH3;
546 
547  // unsupported
548  default: return PlotAreaFill::NOFILL;
549  }
550  }
551  // </group>
552 
553  // Converts between Qwt's symbol style and CASA's.
554  // <group>
555  static QwtSymbol::Style symbol(PlotSymbol::Symbol s) {
556  switch(s) {
557  // supported
559  case PlotSymbol::CIRCLE: return QwtSymbol::Ellipse;
560  case PlotSymbol::SQUARE: return QwtSymbol::Rect;
561  case PlotSymbol::DIAMOND: return QwtSymbol::Diamond;
562 
563  // unsupported
564  default: return QwtSymbol::NoSymbol;
565  }
566  }
567  static PlotSymbol::Symbol symbol(QwtSymbol::Style s) {
568  switch(s) {
569  // supported
570  case QwtSymbol::Ellipse: return PlotSymbol::CIRCLE;
571  case QwtSymbol::Rect: return PlotSymbol::SQUARE;
572  case QwtSymbol::Diamond: return PlotSymbol::DIAMOND;
573 
574  // unsupported
575  default: return PlotSymbol::NOSYMBOL;
576  }
577  }
578  // </group>
579 
580  // Returns a string to be used in stylesheet css for the given style.
581  static casacore::String cssLineStyle(PlotLine::Style style) {
582  switch(style) {
583  case PlotLine::SOLID: return "solid";
584  case PlotLine::DASHED: return "dashed";
585  case PlotLine::DOTTED: return "dotted";
586 
587  default: return "";
588  }
589  }
590 
591  // Rounds the given double to the nearest int.
592  static int round(double d) {
593  if(d >= 0) return (int)(d + 0.5);
594  else return (int)(d - 0.5);
595  }
596 
597  // Returns color maps for standard CASA objects.
598  // <group>
599  static QwtLinearColorMap* standardSpectrogramMap();
600  static QwtLinearColorMap* standardRasterMap();
601  static QwtLinearColorMap* rasterMap(const std::vector<double>& values);
602  // </group>
603 };
604 
605 }
606 
607 #endif
608 
609 #endif /*QPOPTIONS_QO_H_*/
casacore::CountedPtr< PlotAreaFill > PlotAreaFillPtr
Definition: PlotOptions.h:364
casacore::CountedPtr< PlotColor > PlotColorPtr
Definition: PlotOptions.h:195
virtual void setColor(const PlotColor &color)=0
Sets the area fill color to the given.
StatsData< AccumType > copy(const StatsData< AccumType > &stats)
casacore::CountedPtr< PlotLine > PlotLinePtr
Definition: PlotOptions.h:446
virtual void setSize(double width, double height, bool heightIsPixel=true)=0
Sets the size of the symbol in pixels.
virtual void setAreaFill(const PlotAreaFill &fill)=0
Sets the area fill of this symbol to the given.
virtual void setLine(const PlotLine &color)=0
Sets the outline of this symbol to the given.
virtual void setSymbol(const PlotSymbolPtr symbol)
Definition: PlotShape.h:356
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
Pattern
Pattern enum, similar in spirit to http://doc.trolltech.com/4.3/qt.html#BrushStyle-enum.
Definition: PlotOptions.h:300
size_t size() const
TableExprNode pattern(const TableExprNode &node)
Definition: ExprNode.h:1444
casacore::CountedPtr< PlotSymbol > PlotSymbolPtr
Definition: PlotOptions.h:604
Style
Static //.
Definition: PlotOptions.h:373
PlotCursor
Enum for cursors.
Definition: PlotOptions.h:94
virtual void setColor(const PlotColor &color)=0
Sets the color of this font to the given.
PlotAxis
Enum for the four plot axes.
Definition: PlotOptions.h:62
casacore::CountedPtr< PlotFont > PlotFontPtr
Definition: PlotOptions.h:291
Symbol
Static //.
Definition: PlotOptions.h:456
std::pair< double, double > psize_t
Typedef for size, which is two doubles (width and height).
Definition: PlotOptions.h:44
const Double c
Fundamental physical constants (SI units):
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual void setColor(const PlotColor &color)=0
Sets this line&#39;s color to the given.
long round(double d)
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the color(i.e.,"000000"for black) and