source: ntrip/trunk/BNC/qwt/qwt_polar_picker.cpp

Last change on this file was 11158, checked in by stuerze, 4 weeks ago

deprecated functions exchanged libs updated

File size: 5.9 KB
Line 
1/******************************************************************************
2 * QwtPolar Widget Library
3 * Copyright (C) 2008 Uwe Rathmann
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the Qwt License, Version 1.0
7 *****************************************************************************/
8
9#include "qwt_polar_picker.h"
10#include "qwt_polar_plot.h"
11#include "qwt_polar_canvas.h"
12#include "qwt_scale_map.h"
13#include "qwt_picker_machine.h"
14#include "qwt_point_polar.h"
15
16class QwtPolarPicker::PrivateData
17{
18};
19
20/*!
21 \brief Create a polar plot picker
22 \param canvas Plot canvas to observe, also the parent object
23 */
24
25QwtPolarPicker::QwtPolarPicker( QwtPolarCanvas* canvas )
26 : QwtPicker( canvas )
27 , m_data( NULL )
28{
29}
30
31/*!
32 Create a plot picker
33
34 \param rubberBand Rubberband style
35 \param trackerMode Tracker mode
36 \param canvas Plot canvas to observe, also the parent object
37
38 \sa QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(),
39 QwtPicker::setTrackerMode
40
41 \sa QwtPolarPlot::autoReplot(), QwtPolarPlot::replot(), scaleRect()
42 */
43QwtPolarPicker::QwtPolarPicker(
44 RubberBand rubberBand, DisplayMode trackerMode, QwtPolarCanvas* canvas )
45 : QwtPicker( rubberBand, trackerMode, canvas )
46 , m_data( NULL )
47{
48}
49
50//! Destructor
51QwtPolarPicker::~QwtPolarPicker()
52{
53}
54
55//! \return Observed plot canvas
56QwtPolarCanvas* QwtPolarPicker::canvas()
57{
58 return qobject_cast< QwtPolarCanvas* >( parentWidget() );
59}
60
61//! \return Observed plot canvas
62const QwtPolarCanvas* QwtPolarPicker::canvas() const
63{
64 return qobject_cast< const QwtPolarCanvas* >( parentWidget() );
65}
66
67//! \return Plot widget, containing the observed plot canvas
68QwtPolarPlot* QwtPolarPicker::plot()
69{
70 QwtPolarCanvas* w = canvas();
71 if ( w )
72 return w->plot();
73
74 return NULL;
75}
76
77//! \return Plot widget, containing the observed plot canvas
78const QwtPolarPlot* QwtPolarPicker::plot() const
79{
80 const QwtPolarCanvas* w = canvas();
81 if ( w )
82 return w->plot();
83
84 return NULL;
85}
86
87/*!
88 Translate a pixel position into a position string
89
90 \param pos Position in pixel coordinates
91 \return Position string
92 */
93QwtText QwtPolarPicker::trackerText( const QPoint& pos ) const
94{
95 const QwtPointPolar polarPoint = invTransform( pos );
96 return trackerTextPolar( polarPoint );
97}
98
99/*!
100 \brief Translate a position into a position string
101
102 In case of HLineRubberBand the label is the value of the
103 y position, in case of VLineRubberBand the value of the x position.
104 Otherwise the label contains x and y position separated by a ',' .
105
106 The format for the double to string conversion is "%.4f".
107
108 \param pos Position
109 \return Position string
110 */
111QwtText QwtPolarPicker::trackerTextPolar( const QwtPointPolar& pos ) const
112{
113 const QString text = QString::number( pos.radius(), 'f', 4 )
114 + ", " + QString::number( pos.azimuth(), 'f', 4 );
115
116 return QwtText( text );
117}
118
119/*!
120 Append a point to the selection and update rubberband and tracker.
121
122 \param pos Additional point
123 \sa isActive, begin(), end(), move(), appended()
124
125 \note The appended(const QPoint &), appended(const QDoublePoint &)
126 signals are emitted.
127 */
128void QwtPolarPicker::append( const QPoint& pos )
129{
130 QwtPicker::append( pos );
131 Q_EMIT appended( invTransform( pos ) );
132}
133
134/*!
135 Move the last point of the selection
136
137 \param pos New position
138 \sa isActive, begin(), end(), append()
139
140 \note The moved(const QPoint &), moved(const QDoublePoint &)
141 signals are emitted.
142 */
143void QwtPolarPicker::move( const QPoint& pos )
144{
145 QwtPicker::move( pos );
146 Q_EMIT moved( invTransform( pos ) );
147}
148
149/*!
150 Close a selection setting the state to inactive.
151
152 \param ok If true, complete the selection and emit selected signals
153 otherwise discard the selection.
154 \return true if the selection is accepted, false otherwise
155 */
156
157bool QwtPolarPicker::end( bool ok )
158{
159 ok = QwtPicker::end( ok );
160 if ( !ok )
161 return false;
162
163 QwtPolarPlot* plot = QwtPolarPicker::plot();
164 if ( !plot )
165 return false;
166
167 const QPolygon points = selection();
168 if ( points.count() == 0 )
169 return false;
170
171 QwtPickerMachine::SelectionType selectionType =
172 QwtPickerMachine::NoSelection;
173
174 if ( stateMachine() )
175 selectionType = stateMachine()->selectionType();
176
177 switch ( selectionType )
178 {
179 case QwtPickerMachine::PointSelection:
180 {
181 const QwtPointPolar pos = invTransform( points[0] );
182 Q_EMIT selected( pos );
183 break;
184 }
185 case QwtPickerMachine::RectSelection:
186 case QwtPickerMachine::PolygonSelection:
187 {
188 QVector< QwtPointPolar > polarPoints( points.count() );
189 for ( int i = 0; i < points.count(); i++ )
190 polarPoints[i] = invTransform( points[i] );
191
192 Q_EMIT selected( polarPoints );
193 }
194 default:
195 break;
196 }
197
198 return true;
199}
200
201/*!
202 Translate a point from widget into plot coordinates
203
204 \param pos Point in widget coordinates of the plot canvas
205 \return Point in plot coordinates
206 \sa transform(), canvas()
207 */
208QwtPointPolar QwtPolarPicker::invTransform( const QPoint& pos ) const
209{
210 QwtPointPolar polarPos;
211 if ( canvas() == NULL )
212 return QwtPointPolar();
213
214 return canvas()->invTransform( pos );
215}
216
217/*!
218 \return Bounding rectangle of the region, where picking is
219 supported.
220 */
221QRect QwtPolarPicker::pickRect() const
222{
223 const QRect cr = canvas()->contentsRect();
224 const QRect pr = plot()->plotRect( cr ).toRect();
225
226 return cr & pr;
227}
228
229QPainterPath QwtPolarPicker::pickArea() const
230{
231 const QRect cr = canvas()->contentsRect();
232
233 QPainterPath crPath;
234 crPath.addRect( cr );
235
236 QPainterPath prPath;
237 prPath.addEllipse( plot()->plotRect( cr ) );
238
239 return crPath.intersected( prPath );
240}
241
242#include "moc_qwt_polar_picker.cpp"
Note: See TracBrowser for help on using the repository browser.