Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_polar_picker.cpp
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
26 : QwtPicker( canvas )
27 , m_data( NULL )
28{
29}
30
44 RubberBand rubberBand, DisplayMode trackerMode, QwtPolarCanvas* canvas )
45 : QwtPicker( rubberBand, trackerMode, canvas )
46 , m_data( NULL )
47{
48}
49
54
57{
58 return qobject_cast< QwtPolarCanvas* >( parentWidget() );
59}
60
63{
64 return qobject_cast< const QwtPolarCanvas* >( parentWidget() );
65}
66
69{
71 if ( w )
72 return w->plot();
73
74 return NULL;
75}
76
79{
80 const QwtPolarCanvas* w = canvas();
81 if ( w )
82 return w->plot();
83
84 return NULL;
85}
86
93QwtText QwtPolarPicker::trackerText( const QPoint& pos ) const
94{
95 const QwtPointPolar polarPoint = invTransform( pos );
96 return trackerTextPolar( polarPoint );
97}
98
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
128void QwtPolarPicker::append( const QPoint& pos )
129{
130 QwtPicker::append( pos );
131 Q_EMIT appended( invTransform( pos ) );
132}
133
143void QwtPolarPicker::move( const QPoint& pos )
144{
145 QwtPicker::move( pos );
146 Q_EMIT moved( invTransform( pos ) );
147}
148
157bool QwtPolarPicker::end( bool ok )
158{
159 ok = QwtPicker::end( ok );
160 if ( !ok )
161 return false;
162
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 =
173
174 if ( stateMachine() )
175 selectionType = stateMachine()->selectionType();
176
177 switch ( selectionType )
178 {
180 {
181 const QwtPointPolar pos = invTransform( points[0] );
182 Q_EMIT selected( pos );
183 break;
184 }
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
209{
210 QwtPointPolar polarPos;
211 if ( canvas() == NULL )
212 return QwtPointPolar();
213
214 return canvas()->invTransform( pos );
215}
216
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"
QwtPicker provides selections on a widget.
Definition qwt_picker.h:104
DisplayMode
Display mode.
Definition qwt_picker.h:162
virtual void move(const QPoint &)
virtual void append(const QPoint &)
virtual bool end(bool ok=true)
Close a selection setting the state to inactive.
QWidget * parentWidget()
Return the parent widget, where the selection happens.
const QwtPickerMachine * stateMachine() const
QPolygon selection() const
@ NoSelection
The state machine not usable for any type of selection.
@ RectSelection
The state machine is for selecting a rectangle (2 points).
@ PolygonSelection
The state machine is for selecting a polygon (many points).
@ PointSelection
The state machine is for selecting a single point.
SelectionType selectionType() const
Return the selection type.
A point in polar coordinates.
double radius() const
Returns the radius.
double azimuth() const
Returns the azimuth.
Canvas of a QwtPolarPlot.
QwtPolarPlot * plot()
QwtPointPolar invTransform(const QPoint &) const
virtual QRect pickRect() const
virtual QwtText trackerTextPolar(const QwtPointPolar &) const
Translate a position into a position string.
QwtPointPolar invTransform(const QPoint &) const
void selected(const QwtPointPolar &pos)
virtual ~QwtPolarPicker()
Destructor.
void moved(const QwtPointPolar &pos)
QwtPolarPlot * plot()
QwtPolarCanvas * canvas()
virtual void move(const QPoint &) override
virtual QwtText trackerText(const QPoint &) const override
virtual QPainterPath pickArea() const override
void appended(const QwtPointPolar &pos)
virtual void append(const QPoint &) override
virtual bool end(bool ok=true) override
QwtPolarPicker(QwtPolarCanvas *)
Create a polar plot picker.
A plotting widget, displaying a polar coordinate system.
QRectF plotRect() const
A class representing a text.
Definition qwt_text.h:52