casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QPAnnotation.h
Go to the documentation of this file.
1 //# QPAnnotation.h: Qwt implementation of generic PlotAnnotation class.
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 QPANNOTATION_H_
28 #define QPANNOTATION_H_
29 
30 #ifdef AIPS_HAS_QWT
31 
34 
35 #include <qwt_text.h>
36 
37 namespace casa {
38 
39 //# Forward Declarations
40 class QPCanvas;
41 
42 // Implementation of PlotAnnotation for Qwt plotter.
43 class QPAnnotation : public QPPlotItem, public PlotAnnotation {
44 public:
45  // Static //
46 
47  // Convenient access to class name (QPAnnotation).
48  static const casacore::String CLASS_NAME;
49 
50 
51  // Non-Static //
52 
53  // Constructor which takes text and location.
54  QPAnnotation(const casacore::String& text, const PlotCoordinate& coord);
55 
56  // Constructor which takes text, location, font, and (optional) orientation
57  // in counterclockwise degrees.
58  QPAnnotation(const casacore::String& text, const PlotCoordinate& coord,
59  const PlotFont& font, int orientation = 0);
60 
61  // Constructor which copies the given generic PlotAnnotation.
62  QPAnnotation(const PlotAnnotation& copy);
63 
64  // Destructor.
65  ~QPAnnotation();
66 
67 
68  // Include overloaded methods.
72 
73 
74  // PlotItem Methods //
75 
76  // Implements PlotItem::isValid().
77  bool isValid() const { return true; }
78 
79 
80  // QPPlotItem Methods //
81 
82  // Overrides QwtPlotItem::boundingRect().
83  QwtDoubleRect boundingRect() const;
84 
85  // Overrides QwtPlotItem::legendItem().
86  QWidget* legendItem() const;
87 
88 
89  // PlotAnnotation Methods //
90 
91  // Implements PlotAnnotation::text().
92  casacore::String text() const;
93 
94  // Implements PlotAnnotation::setText().
95  void setText(const casacore::String& newText);
96 
97  // Implements PlotAnnotation::font().
98  PlotFontPtr font() const;
99 
100  // Implements PlotAnnotation::setFont().
101  void setFont(const PlotFont& font);
102 
103  // Implements PlotAnnotation::orientation().
104  int orientation() const;
105 
106  // Implements PlotAnnotation::setOrientation().
107  void setOrientation(int orientation);
108 
109  // Implements PlotAnnotation::coordinate().
110  PlotCoordinate coordinate() const;
111 
112  // Implements PlotAnnotation::setCoordinate().
113  void setCoordinate(const PlotCoordinate& coord);
114 
115  // Implements PlotAnnotation::outlineShown().
116  bool outlineShown() const;
117 
118  // Implements PlotAnnotation::setOutlineShown().
119  void setOutlineShown(bool show = true);
120 
121  // Implements PlotAnnotation::outline().
122  PlotLinePtr outline() const;
123 
124  // Implements PlotAnnotation::setOutline().
125  void setOutline(const PlotLine& line);
126 
127  // Implements PlotAnnotation::background().
128  PlotAreaFillPtr background() const;
129 
130  // Implements PlotAnnotation::setBackground().
131  void setBackground(const PlotAreaFill& area);
132 
133 
134  // QPAnnotation Methods //
135 
136  // Provides access to the underlying QwtText object.
137  // <group>
138  QwtText& asQwtText();
139  const QwtText& asQwtText() const;
140  // </group>
141 
142 protected:
143  // Implements QPPlotItem::className().
144  const casacore::String& className() const { return CLASS_NAME; }
145 
146  // Implements QPLayerItem::draw_(). Ignores draw index and count.
147 #if QWT_VERSION >= 0x060000
148  void draw_(QPainter* painter, const QwtScaleMap& xMap,
149  const QwtScaleMap& yMap, const QRectF& canvasRect,
150  unsigned int drawIndex, unsigned int drawCount) const;
151 #else
152  void draw_(QPainter* painter, const QwtScaleMap& xMap,
153  const QwtScaleMap& yMap, const QRect& canvasRect,
154  unsigned int drawIndex, unsigned int drawCount) const;
155 #endif
156 
157 private:
158 
159  QPen getLabelPen() const;
160  void setPen(QwtText text, QPen pen) const;
161 
162  QwtText m_label; // text, font, outline, and background
163  PlotCoordinate m_coord; // location
164  int m_orient; // orientation
165 };
166 
167 }
168 
169 #endif
170 
171 #endif /*QPANNOTATION_H_*/
casacore::CountedPtr< PlotAreaFill > PlotAreaFillPtr
Definition: PlotOptions.h:364
virtual void setFont(const PlotFont &font)=0
Sets the annotation font to the given.
StatsData< AccumType > copy(const StatsData< AccumType > &stats)
virtual void setOutline(const PlotLine &line)=0
Sets the outline to the given line.
casacore::CountedPtr< PlotLine > PlotLinePtr
Definition: PlotOptions.h:446
void show(const variant &v)
virtual void setBackground(const PlotAreaFill &area)=0
Sets the annotation&#39;s background to the given.
casacore::CountedPtr< PlotFont > PlotFontPtr
Definition: PlotOptions.h:291
String: the storage and methods of handling collections of characters.
Definition: String.h:223