Loading...
Searching...
No Matches
qwt_polar_picker.cpp
/******************************************************************************
* QwtPolar Widget Library
* Copyright (C) 2008 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_polar_picker.h"
#include "qwt_polar_plot.h"
#include "qwt_polar_canvas.h"
#include "qwt_scale_map.h"
#include "qwt_picker_machine.h"
#include "qwt_point_polar.h"
class QwtPolarPicker::PrivateData
{
};
QwtPolarPicker::QwtPolarPicker( QwtPolarCanvas* canvas )
: QwtPicker( canvas )
, m_data( NULL )
{
}
QwtPolarPicker::QwtPolarPicker(
RubberBand rubberBand, DisplayMode trackerMode, QwtPolarCanvas* canvas )
: QwtPicker( rubberBand, trackerMode, canvas )
, m_data( NULL )
{
}
QwtPolarPicker::~QwtPolarPicker()
{
}
QwtPolarCanvas* QwtPolarPicker::canvas()
{
return qobject_cast< QwtPolarCanvas* >( parentWidget() );
}
const QwtPolarCanvas* QwtPolarPicker::canvas() const
{
return qobject_cast< const QwtPolarCanvas* >( parentWidget() );
}
QwtPolarPlot* QwtPolarPicker::plot()
{
QwtPolarCanvas* w = canvas();
if ( w )
return w->plot();
return NULL;
}
const QwtPolarPlot* QwtPolarPicker::plot() const
{
const QwtPolarCanvas* w = canvas();
if ( w )
return w->plot();
return NULL;
}
QwtText QwtPolarPicker::trackerText( const QPoint& pos ) const
{
const QwtPointPolar polarPoint = invTransform( pos );
return trackerTextPolar( polarPoint );
}
QwtText QwtPolarPicker::trackerTextPolar( const QwtPointPolar& pos ) const
{
const QString text = QString::number( pos.radius(), 'f', 4 )
+ ", " + QString::number( pos.azimuth(), 'f', 4 );
return QwtText( text );
}
void QwtPolarPicker::append( const QPoint& pos )
{
QwtPicker::append( pos );
Q_EMIT appended( invTransform( pos ) );
}
void QwtPolarPicker::move( const QPoint& pos )
{
QwtPicker::move( pos );
Q_EMIT moved( invTransform( pos ) );
}
bool QwtPolarPicker::end( bool ok )
{
ok = QwtPicker::end( ok );
if ( !ok )
return false;
QwtPolarPlot* plot = QwtPolarPicker::plot();
if ( !plot )
return false;
const QPolygon points = selection();
if ( points.count() == 0 )
return false;
QwtPickerMachine::SelectionType selectionType =
QwtPickerMachine::NoSelection;
if ( stateMachine() )
selectionType = stateMachine()->selectionType();
switch ( selectionType )
{
case QwtPickerMachine::PointSelection:
{
const QwtPointPolar pos = invTransform( points[0] );
Q_EMIT selected( pos );
break;
}
case QwtPickerMachine::RectSelection:
case QwtPickerMachine::PolygonSelection:
{
QVector< QwtPointPolar > polarPoints( points.count() );
for ( int i = 0; i < points.count(); i++ )
polarPoints[i] = invTransform( points[i] );
Q_EMIT selected( polarPoints );
}
default:
break;
}
return true;
}
QwtPointPolar QwtPolarPicker::invTransform( const QPoint& pos ) const
{
QwtPointPolar polarPos;
if ( canvas() == NULL )
return QwtPointPolar();
return canvas()->invTransform( pos );
}
QRect QwtPolarPicker::pickRect() const
{
const QRect cr = canvas()->contentsRect();
const QRect pr = plot()->plotRect( cr ).toRect();
return cr & pr;
}
QPainterPath QwtPolarPicker::pickArea() const
{
const QRect cr = canvas()->contentsRect();
QPainterPath crPath;
crPath.addRect( cr );
QPainterPath prPath;
prPath.addEllipse( plot()->plotRect( cr ) );
return crPath.intersected( prPath );
}
#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