casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QPTool.qo.h
Go to the documentation of this file.
1 //# QPTool.qo.h: Qwt implementations of PlotTools.
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 QPTOOL_QO_H_
28 #define QPTOOL_QO_H_
29 
30 #ifdef AIPS_HAS_QWT
32 
34 
35 #include <qwt_plot_picker.h>
36 #include <qwt_plot_panner.h>
37 
38 namespace casa {
39 
40 //# Forward Declarations
41 class QPTracker;
42 
43 
44 // Subclass of PlotSelectTool specific to Qwt plotter. Currently isn't
45 // specialized.
46 class QPSelectTool : public PlotSelectTool {
47 public:
48  // Constructor which takes the tool's coordinate system.
49  QPSelectTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
50 
51  // Constructor which takes the tool's axes and coordinate system.
52  QPSelectTool(PlotAxis xAxis, PlotAxis yAxis,
53  PlotCoordinate::System sys = PlotCoordinate::WORLD);
54 
55  // Destructor.
56  ~QPSelectTool();
57 };
58 
59 
60 // Subclass of PlotZoomTool specific to Qwt plotter. Currently isn't
61 // specialized.
62 class QPZoomTool : public PlotZoomTool {
63 public:
64  // Constructor which takes the tool's coordinate system.
65  QPZoomTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
66 
67  // Constructor which takes the tool's axes and coordinate system.
68  QPZoomTool(PlotAxis xAxis, PlotAxis yAxis,
69  PlotCoordinate::System sys = PlotCoordinate::WORLD);
70 
71  // Destructor.
72  ~QPZoomTool();
73 };
74 
75 
76 // Subclass of PlotPanTool specific to Qwt plotter. Uses a QwtPlotPanner to
77 // manage some behavior.
78 class QPPanTool : public QObject, public PlotPanTool {
79  Q_OBJECT
80 
81 public:
82  // Constructor which takes the tool's coordinate system.
83  QPPanTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
84 
85  // Constructor which takes the tool's axes and coordinate system.
86  QPPanTool(PlotAxis xAxis, PlotAxis yAxis,
87  PlotCoordinate::System sys = PlotCoordinate::WORLD);
88 
89  // Destructor.
90  ~QPPanTool();
91 
92 
93  // PlotTool Methods //
94 
95  // Overrides PlotTool::setActive().
96  void setActive(bool isActive = true);
97 
98 
99  // PlotMouseTool Methods //
100 
101  // Implements PlotMouseTool::handleMouseEvent() to handle wheel and right
102  // click.
103  void handleMouseEvent(const PlotEvent& event);
104 
105 protected:
106  // PlotTool Methods //
107 
108  // Overrides PlotTool::attach().
109  void attach(PlotCanvas* canvas);
110 
111  // Overrides PlotTool::detach().
112  void detach();
113 
114 private:
115  QwtPlotPanner* m_panner; // Panner
116 
117 private slots:
118  // For when the pan window changes (to update the stack).
119  void panned(int dx, int dy);
120 };
121 
122 
123 // Subclass of PlotTrackerTool specific to Qwt plotter, using a QPTracker.
124 class QPTrackerTool : public PlotTrackerTool {
125 public:
126  // Constructor which takes the tool's coordinate system.
127  QPTrackerTool(PlotCoordinate::System sys = PlotCoordinate::WORLD);
128 
129  // Constructor which takes the tool's axes and coordinate system.
130  QPTrackerTool(PlotAxis xAxis, PlotAxis yAxis,
131  PlotCoordinate::System sys = PlotCoordinate::WORLD);
132 
133  // Destructor.
134  ~QPTrackerTool();
135 
136  // PlotTool Methods //
137 
138  // Overrides PlotTool::setActive().
139  void setActive(bool isActive = true);
140 
141 
142  // PlotMouseTool Methods //
143 
144  // Implements PlotMouseTool::handleMouseEvent() to update PlotTrackerTool's
145  // annotation with that of the QPTracker.
146  void handleMouseEvent(const PlotEvent& event);
147 
148  // PlotTrackerTool Methods //
149 
150  // Overrides PlotTrackerTool::setDrawText().
151  void setDrawText(bool draw = true);
152 
153  // Overrides PlotTrackerTool::formattedString()
154  // to keep tool and tracker in sync.
155  casacore::String formattedString(double x, double y);
156 
157 protected:
158  // PlotTool Methods //
159 
160  // Overrides PlotTool::attach().
161  void attach(PlotCanvas* canvas);
162 
163  // Overrides PlotTool::detach().
164  void detach();
165 
166 private:
167  QPTracker* m_tracker; // Tracker.
168 };
169 
170 
171 // Subclass of QwtPlotPicker to be more compatible with PlotTrackerTool.
172 class QPTracker : public QwtPlotPicker {
173  Q_OBJECT
174 
175 public:
176  // Constructor which takes the tracker and the canvas to be installed on.
177  QPTracker(QPTrackerTool& tracker, QwtPlotCanvas* canvas);
178 
179  // Destructor.
180  ~QPTracker();
181 
182 
183  // Returns the annotation which holds the current position and tracker
184  // text.
185  PlotAnnotationPtr getAnnotation() {
186  return PlotAnnotationPtr(&m_annotation, false); }
187 
188 
189  // QwtPlotPicker Methods //
190 
191  // Overrides QwtPlotPicker::trackerText() to take font and format into
192  // account.
193  // <group>
194  QwtText trackerText(const QPoint& pos) const {
195  return trackerText(invTransform(pos)); }
196  QwtText trackerText(const QwtDoublePoint& pos) const;
197  // </group>
198 
199 private:
200  QPTrackerTool& m_tracker; // Tracker tool
201  QPAnnotation m_annotation; // Current annotation
202 };
203 
204 }
205 
206 #endif
207 
208 #endif /* QPTOOL_QO_H_ */
virtual void attach(PlotCanvas *canvas)
Overrides PlotTool::attach().
virtual PlotAnnotationPtr getAnnotation()
Returns the annotation used to store the coordinates/text.
virtual void setDrawText(bool draw=true)
Sets whether the tracker will draw the text on the canvas or not.
virtual void handleMouseEvent(const PlotEvent &event)
Implements PlotMouseTool::handleMouseEvent().
Definition: PlotTool.h:930
PlotTrackerToolPtr m_tracker
Tracker.
Definition: PlotTool.h:972
INHERITANCE_POINTER(PlotZoomTool, PlotZoomToolPtr, PlotMouseTool, PlotMouseToolPtr, PlotTool, PlotToolPtr) class PlotPanTool PlotPanTool(PlotAxis xAxis, PlotAxis yAxis, PlotCoordinate::System sys=PlotCoordinate::WORLD)
A PlotPanTool is a concrete subclass of PlotMouseTool that provides convenient panning functionality...
virtual void setActive(bool active=true)
Overrides PlotTool::setActive().
static casacore::String formattedString(const casacore::String &format, double x, double y, PlotCanvas *canvas, PlotAxis xAxis, PlotAxis yAxis)
A PlotTrackerTool is a concrete subclass of PlotMouseTool that provides convenient tracker functional...
PlotAxis
Enum for the four plot axes.
Definition: PlotOptions.h:62
INHERITANCE_POINTER(PlotSelectTool, PlotSelectToolPtr, PlotMouseTool, PlotMouseToolPtr, PlotTool, PlotToolPtr) class PlotZoomTool PlotZoomTool(PlotAxis xAxis, PlotAxis yAxis, PlotCoordinate::System sys=PlotCoordinate::WORLD)
A PlotZoomTool is a concrete subclass of PlotMouseTool that provides convenient zooming functionality...
PlotAnnotationPtr m_annotation
Annotation that holds current position (even if not drawn on canvas).
Definition: PlotTool.h:579
PlotTrackerTool(PlotCoordinate::System sys=PlotCoordinate::WORLD)
Non-Static //.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual void detach()
Overrides PlotTool::detach().