qwt_polar_picker.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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 public:
20  {
21  }
22 };
23 
30  QwtPicker( canvas )
31 {
32  d_data = new PrivateData;
33 }
34 
50  QwtPicker( rubberBand, trackerMode, canvas )
51 {
52  d_data = new PrivateData;
53 }
54 
57 {
58  delete d_data;
59 }
60 
63 {
64  return qobject_cast<QwtPolarCanvas *>( parentWidget() );
65 }
66 
69 {
70  return qobject_cast<const QwtPolarCanvas *>( parentWidget() );
71 }
72 
75 {
76  QwtPolarCanvas *w = canvas();
77  if ( w )
78  return w->plot();
79 
80  return NULL;
81 }
82 
85 {
86  const QwtPolarCanvas *w = canvas();
87  if ( w )
88  return w->plot();
89 
90  return NULL;
91 }
92 
99 QwtText QwtPolarPicker::trackerText( const QPoint &pos ) const
100 {
101  const QwtPointPolar polarPoint = invTransform( pos );
102  return trackerTextPolar( polarPoint );
103 }
104 
118 {
119  const QString text = QString::number( pos.radius(), 'f', 4 )
120  + ", " + QString::number( pos.azimuth(), 'f', 4 );
121 
122  return QwtText( text );
123 }
124 
134 void QwtPolarPicker::append( const QPoint &pos )
135 {
136  QwtPicker::append( pos );
137  Q_EMIT appended( invTransform( pos ) );
138 }
139 
149 void QwtPolarPicker::move( const QPoint &pos )
150 {
151  QwtPicker::move( pos );
152  Q_EMIT moved( invTransform( pos ) );
153 }
154 
163 bool QwtPolarPicker::end( bool ok )
164 {
165  ok = QwtPicker::end( ok );
166  if ( !ok )
167  return false;
168 
170  if ( !plot )
171  return false;
172 
173  const QPolygon points = selection();
174  if ( points.count() == 0 )
175  return false;
176 
177  QwtPickerMachine::SelectionType selectionType =
179 
180  if ( stateMachine() )
181  selectionType = stateMachine()->selectionType();
182 
183  switch ( selectionType )
184  {
186  {
187  const QwtPointPolar pos = invTransform( points[0] );
188  Q_EMIT selected( pos );
189  break;
190  }
193  {
194  QVector<QwtPointPolar> polarPoints( points.count() );
195  for ( int i = 0; i < points.count(); i++ )
196  polarPoints[i] = invTransform( points[i] );
197 
198  Q_EMIT selected( polarPoints );
199  }
200  default:
201  break;
202  }
203 
204  return true;
205 }
206 
214 QwtPointPolar QwtPolarPicker::invTransform( const QPoint &pos ) const
215 {
216  QwtPointPolar polarPos;
217  if ( canvas() == NULL )
218  return QwtPointPolar();
219 
220  return canvas()->invTransform( pos );
221 }
222 
228 {
229  const QRect cr = canvas()->contentsRect();
230  const QRect pr = plot()->plotRect( cr ).toRect();
231 
232  return cr & pr;
233 }
234 
235 QPainterPath QwtPolarPicker::pickArea() const
236 {
237  const QRect cr = canvas()->contentsRect();
238 
239  QPainterPath crPath;
240  crPath.addRect( cr );
241 
242  QPainterPath prPath;
243  prPath.addEllipse( plot()->plotRect( cr ) );
244 
245  return crPath.intersected( prPath );
246 }
247 
248 #if QWT_MOC_INCLUDE
249 #include "moc_qwt_polar_picker.cpp"
250 #endif
virtual bool end(bool ok=true)
Close a selection setting the state to inactive.
DisplayMode
Display mode.
Definition: qwt_picker.h:162
A plotting widget, displaying a polar coordinate system.
DisplayMode trackerMode() const
A point in polar coordinates.
QRectF plotRect() const
The state machine not usable for any type of selection.
virtual QRect pickRect() const
QWidget * parentWidget()
Return the parent widget, where the selection happens.
Definition: qwt_picker.cpp:274
double radius() const
Returns the radius.
QwtPointPolar invTransform(const QPoint &) const
virtual bool end(bool ok=true) QWT_OVERRIDE
QwtPolarPicker(QwtPolarCanvas *)
Create a polar plot picker.
QwtPointPolar invTransform(const QPoint &) const
double azimuth() const
Returns the azimuth.
QPolygon selection() const
Definition: qwt_picker.cpp:805
QwtPolarPlot * plot()
The state machine is for selecting a polygon (many points).
virtual void append(const QPoint &) QWT_OVERRIDE
void moved(const QwtPointPolar &pos)
const QwtPickerMachine * stateMachine() const
Definition: qwt_picker.cpp:268
The state machine is for selecting a single point.
void selected(const QwtPointPolar &pos)
void appended(const QwtPointPolar &pos)
PrivateData * d_data
QwtPolarPlot * plot()
RubberBand rubberBand() const
A class representing a text.
Definition: qwt_text.h:51
virtual void move(const QPoint &)
Canvas of a QwtPolarPlot.
virtual QwtText trackerTextPolar(const QwtPointPolar &) const
Translate a position into a position string.
virtual QPainterPath pickArea() const QWT_OVERRIDE
SelectionType selectionType() const
Return the selection type.
virtual ~QwtPolarPicker()
Destructor.
virtual void move(const QPoint &) QWT_OVERRIDE
virtual QwtText trackerText(const QPoint &) const QWT_OVERRIDE
QwtPicker provides selections on a widget.
Definition: qwt_picker.h:104
The state machine is for selecting a rectangle (2 points).
virtual void append(const QPoint &)
QwtPolarCanvas * canvas()


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10