Qwt User's Guide: qwt_polar_picker.cpp Source File

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
25QwtPolarPicker::QwtPolarPicker( QwtPolarCanvas* canvas )
26 : QwtPicker( canvas )
27 , m_data( NULL )
28{
29}
30
43 QwtPolarPicker::QwtPolarPicker(
44 RubberBand rubberBand, DisplayMode trackerMode, QwtPolarCanvas* canvas )
45 : QwtPicker( rubberBand, trackerMode, canvas )
46 , m_data( NULL )
47{
48}
49
51QwtPolarPicker::~QwtPolarPicker()
52{
53}
54
56 QwtPolarCanvas* QwtPolarPicker::canvas()
57{
58 return qobject_cast< QwtPolarCanvas* >( parentWidget() );
59}
60
62 const QwtPolarCanvas* QwtPolarPicker::canvas() const
63{
64 return qobject_cast< const QwtPolarCanvas* >( parentWidget() );
65}
66
68 QwtPolarPlot* QwtPolarPicker::plot()
69{
70 QwtPolarCanvas* w = canvas();
71 if ( w )
72 return w->plot();
73
74 return NULL;
75}
76
78 const QwtPolarPlot* QwtPolarPicker::plot() const
79{
80 const QwtPolarCanvas* w = canvas();
81 if ( w )
82 return w->plot();
83
84 return NULL;
85}
86
93 QwtText QwtPolarPicker::trackerText( const QPoint& pos ) const
94{
95 const QwtPointPolar polarPoint = invTransform( pos );
96 return trackerTextPolar( polarPoint );
97}
98
111 QwtText 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
128 void QwtPolarPicker::append( const QPoint& pos )
129{
130 QwtPicker::append( pos );
131 Q_EMIT appended( invTransform( pos ) );
132}
133
143 void QwtPolarPicker::move( const QPoint& pos )
144{
145 QwtPicker::move( pos );
146 Q_EMIT moved( invTransform( pos ) );
147}
148
157 bool 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
208 QwtPointPolar 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
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"
QVector
Definition qwt_clipper.h:23
QwtPicker
QwtPicker provides selections on a widget.
Definition qwt_picker.h:104
QwtPicker::DisplayMode
DisplayMode
Display mode.
Definition qwt_picker.h:162
QwtPicker::move
virtual void move(const QPoint &)
Definition qwt_picker.cpp:1357
QwtPicker::append
virtual void append(const QPoint &)
Definition qwt_picker.cpp:1339
QwtPicker::RubberBand
RubberBand
Definition qwt_picker.h:128
QwtPicker::end
virtual bool end(bool ok=true)
Close a selection setting the state to inactive.
Definition qwt_picker.cpp:1291
QwtPicker::parentWidget
QWidget * parentWidget()
Return the parent widget, where the selection happens.
Definition qwt_picker.cpp:263
QwtPicker::stateMachine
const QwtPickerMachine * stateMachine() const
Definition qwt_picker.cpp:257
QwtPicker::selection
QPolygon selection() const
Definition qwt_picker.cpp:792
QwtPickerMachine::SelectionType
SelectionType
Definition qwt_picker_machine.h:36
QwtPickerMachine::NoSelection
@ NoSelection
The state machine not usable for any type of selection.
Definition qwt_picker_machine.h:38
QwtPickerMachine::RectSelection
@ RectSelection
The state machine is for selecting a rectangle (2 points).
Definition qwt_picker_machine.h:44
QwtPickerMachine::PolygonSelection
@ PolygonSelection
The state machine is for selecting a polygon (many points).
Definition qwt_picker_machine.h:47
QwtPickerMachine::PointSelection
@ PointSelection
The state machine is for selecting a single point.
Definition qwt_picker_machine.h:41
QwtPickerMachine::selectionType
SelectionType selectionType() const
Return the selection type.
Definition qwt_picker_machine.cpp:28
QwtPointPolar
A point in polar coordinates.
Definition qwt_point_polar.h:29
QwtPointPolar::radius
double radius() const
Returns the radius.
Definition qwt_point_polar.h:102
QwtPointPolar::azimuth
double azimuth() const
Returns the azimuth.
Definition qwt_point_polar.h:108
QwtPolarCanvas
Canvas of a QwtPolarPlot.
Definition qwt_polar_canvas.h:28
QwtPolarCanvas::plot
QwtPolarPlot * plot()
Definition qwt_polar_canvas.cpp:97
QwtPolarCanvas::invTransform
QwtPointPolar invTransform(const QPoint &) const
Definition qwt_polar_canvas.cpp:267
QwtPolarPicker::pickRect
virtual QRect pickRect() const
Definition qwt_polar_picker.cpp:221
QwtPolarPicker::trackerTextPolar
virtual QwtText trackerTextPolar(const QwtPointPolar &) const
Translate a position into a position string.
Definition qwt_polar_picker.cpp:111
QwtPolarPicker::invTransform
QwtPointPolar invTransform(const QPoint &) const
Definition qwt_polar_picker.cpp:208
QwtPolarPicker::selected
void selected(const QwtPointPolar &pos)
QwtPolarPicker::~QwtPolarPicker
virtual ~QwtPolarPicker()
Destructor.
Definition qwt_polar_picker.cpp:51
QwtPolarPicker::moved
void moved(const QwtPointPolar &pos)
QwtPolarPicker::plot
QwtPolarPlot * plot()
Definition qwt_polar_picker.cpp:68
QwtPolarPicker::canvas
QwtPolarCanvas * canvas()
Definition qwt_polar_picker.cpp:56
QwtPolarPicker::move
virtual void move(const QPoint &) override
Definition qwt_polar_picker.cpp:143
QwtPolarPicker::trackerText
virtual QwtText trackerText(const QPoint &) const override
Definition qwt_polar_picker.cpp:93
QwtPolarPicker::pickArea
virtual QPainterPath pickArea() const override
Definition qwt_polar_picker.cpp:229
QwtPolarPicker::appended
void appended(const QwtPointPolar &pos)
QwtPolarPicker::append
virtual void append(const QPoint &) override
Definition qwt_polar_picker.cpp:128
QwtPolarPicker::end
virtual bool end(bool ok=true) override
Definition qwt_polar_picker.cpp:157
QwtPolarPicker::QwtPolarPicker
QwtPolarPicker(QwtPolarCanvas *)
Create a polar plot picker.
Definition qwt_polar_picker.cpp:25
QwtPolarPlot
A plotting widget, displaying a polar coordinate system.
Definition qwt_polar_plot.h:47
QwtPolarPlot::plotRect
QRectF plotRect() const
Definition qwt_polar_plot.cpp:1120
QwtText
A class representing a text.
Definition qwt_text.h:52