qwt_polar_picker.cpp
Go to the documentation of this file.
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 
17 {
18 };
19 
26  : QwtPicker( canvas )
27  , m_data( nullptr )
28 {
29 }
30 
44  RubberBand rubberBand, DisplayMode trackerMode, QwtPolarCanvas* canvas )
45  : QwtPicker( rubberBand, trackerMode, canvas )
46  , m_data( nullptr )
47 {
48 }
49 
52 {
53 }
54 
57 {
58  return qobject_cast< QwtPolarCanvas* >( parentWidget() );
59 }
60 
63 {
64  return qobject_cast< const QwtPolarCanvas* >( parentWidget() );
65 }
66 
69 {
70  QwtPolarCanvas* w = canvas();
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 
93 QwtText 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 
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 
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 
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 
222 {
223  const QRect cr = canvas()->contentsRect();
224  const QRect pr = plot()->plotRect( cr ).toRect();
225 
226  return cr & pr;
227 }
228 
229 QPainterPath 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 #if QWT_MOC_INCLUDE
243 #include "moc_qwt_polar_picker.cpp"
244 #endif
QwtPolarPicker::move
virtual void move(const QPoint &) QWT_OVERRIDE
Definition: qwt_polar_picker.cpp:143
QwtPolarPlot
A plotting widget, displaying a polar coordinate system.
Definition: qwt_polar_plot.h:46
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
QwtPolarPicker::end
virtual bool end(bool ok=true) QWT_OVERRIDE
Definition: qwt_polar_picker.cpp:157
QwtPicker::DisplayMode
DisplayMode
Display mode.
Definition: qwt_picker.h:161
QwtPolarPicker::~QwtPolarPicker
virtual ~QwtPolarPicker()
Destructor.
Definition: qwt_polar_picker.cpp:51
QwtPolarCanvas
Canvas of a QwtPolarPlot.
Definition: qwt_polar_canvas.h:27
qwt_polar_picker.h
QwtPolarPicker::QwtPolarPicker
QwtPolarPicker(QwtPolarCanvas *)
Create a polar plot picker.
Definition: qwt_polar_picker.cpp:25
QwtPolarPicker::invTransform
QwtPointPolar invTransform(const QPoint &) const
Definition: qwt_polar_picker.cpp:208
QVector
Definition: qwt_clipper.h:23
QwtPolarPicker::trackerTextPolar
virtual QwtText trackerTextPolar(const QwtPointPolar &) const
Translate a position into a position string.
Definition: qwt_polar_picker.cpp:111
QwtPicker::RubberBand
RubberBand
Definition: qwt_picker.h:127
QwtPolarPicker::pickArea
virtual QPainterPath pickArea() const QWT_OVERRIDE
Definition: qwt_polar_picker.cpp:229
QwtPolarPicker::selected
void selected(const QwtPointPolar &pos)
qwt_polar_canvas.h
QwtPolarCanvas::invTransform
QwtPointPolar invTransform(const QPoint &) const
Definition: qwt_polar_canvas.cpp:267
ok
ROSCPP_DECL bool ok()
QwtPointPolar
A point in polar coordinates.
Definition: qwt_point_polar.h:28
QwtPolarPicker::pickRect
virtual QRect pickRect() const
Definition: qwt_polar_picker.cpp:221
QwtPickerMachine::PointSelection
@ PointSelection
The state machine is for selecting a single point.
Definition: qwt_picker_machine.h:41
QwtPolarPicker::moved
void moved(const QwtPointPolar &pos)
qwt_scale_map.h
QwtText
A class representing a text.
Definition: qwt_text.h:51
QwtPointPolar::azimuth
double azimuth() const
Returns the azimuth.
Definition: qwt_point_polar.h:108
QwtPickerMachine::PolygonSelection
@ PolygonSelection
The state machine is for selecting a polygon (many points).
Definition: qwt_picker_machine.h:47
qwt_point_polar.h
QwtPolarCanvas::plot
QwtPolarPlot * plot()
Definition: qwt_polar_canvas.cpp:97
qwt_picker_machine.h
QwtPickerMachine::SelectionType
SelectionType
Definition: qwt_picker_machine.h:35
QwtPicker::append
virtual void append(const QPoint &)
Definition: qwt_picker.cpp:1339
QwtPolarPicker::append
virtual void append(const QPoint &) QWT_OVERRIDE
Definition: qwt_polar_picker.cpp:128
QwtPicker::move
virtual void move(const QPoint &)
Definition: qwt_picker.cpp:1357
QwtPicker::selection
QPolygon selection() const
Definition: qwt_picker.cpp:792
QwtPolarPicker::plot
QwtPolarPlot * plot()
Definition: qwt_polar_picker.cpp:68
QwtPolarPicker::PrivateData
Definition: qwt_polar_picker.cpp:16
QwtPicker::end
virtual bool end(bool ok=true)
Close a selection setting the state to inactive.
Definition: qwt_picker.cpp:1291
QwtPickerMachine::selectionType
SelectionType selectionType() const
Return the selection type.
Definition: qwt_picker_machine.cpp:28
qwt_polar_plot.h
QwtPicker
QwtPicker provides selections on a widget.
Definition: qwt_picker.h:103
QwtPointPolar::radius
double radius() const
Returns the radius.
Definition: qwt_point_polar.h:102
QwtPolarPlot::plotRect
QRectF plotRect() const
Definition: qwt_polar_plot.cpp:1120
QwtPolarPicker::canvas
QwtPolarCanvas * canvas()
Definition: qwt_polar_picker.cpp:56
QwtPicker::parentWidget
QWidget * parentWidget()
Return the parent widget, where the selection happens.
Definition: qwt_picker.cpp:263
QwtPolarPicker::trackerText
virtual QwtText trackerText(const QPoint &) const QWT_OVERRIDE
Definition: qwt_polar_picker.cpp:93
QwtPolarPicker::appended
void appended(const QwtPointPolar &pos)
nullptr
#define nullptr
Definition: backward.hpp:386
QwtPicker::stateMachine
const QwtPickerMachine * stateMachine() const
Definition: qwt_picker.cpp:248


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46