[4302] | 1 |
|
---|
| 2 | /* -------------------------------------------------------------------------
|
---|
| 3 | * BKG NTRIP Client
|
---|
| 4 | * -------------------------------------------------------------------------
|
---|
| 5 | *
|
---|
| 6 | * Class: t_polarPlot
|
---|
| 7 | *
|
---|
| 8 | * Purpose: Polar Plot
|
---|
| 9 | *
|
---|
| 10 | * Author: L. Mervart
|
---|
| 11 | *
|
---|
| 12 | * Created: 23-Jun-2012
|
---|
| 13 | *
|
---|
| 14 | * Changes:
|
---|
| 15 | *
|
---|
| 16 | * -----------------------------------------------------------------------*/
|
---|
| 17 |
|
---|
| 18 | #include <qpen.h>
|
---|
| 19 | #include <qwt_series_data.h>
|
---|
| 20 | #include <qwt_symbol.h>
|
---|
| 21 | #include <qwt_legend.h>
|
---|
| 22 | #include <qwt_polar_grid.h>
|
---|
| 23 | #include <qwt_polar_curve.h>
|
---|
| 24 | #include <qwt_polar_marker.h>
|
---|
| 25 | #include <qwt_scale_engine.h>
|
---|
| 26 |
|
---|
| 27 | #include "polarplot.h"
|
---|
| 28 |
|
---|
| 29 | const QwtInterval radialInterval( 0.0, 10.0 );
|
---|
| 30 | const QwtInterval azimuthInterval( 0.0, 360.0 );
|
---|
| 31 |
|
---|
| 32 | //
|
---|
| 33 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 34 | class Data: public QwtSeriesData<QwtPointPolar> {
|
---|
| 35 | public:
|
---|
| 36 | Data( const QwtInterval &radialInterval,
|
---|
| 37 | const QwtInterval &azimuthInterval, size_t size ):
|
---|
| 38 | _radialInterval( radialInterval ),
|
---|
| 39 | _azimuthInterval( azimuthInterval ),
|
---|
| 40 | _size( size ) {}
|
---|
| 41 |
|
---|
| 42 | virtual size_t size() const {return _size;}
|
---|
| 43 |
|
---|
| 44 | protected:
|
---|
| 45 | QwtInterval _radialInterval;
|
---|
| 46 | QwtInterval _azimuthInterval;
|
---|
| 47 | size_t _size;
|
---|
| 48 | };
|
---|
| 49 |
|
---|
| 50 | //
|
---|
| 51 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 52 | class SpiralData: public Data {
|
---|
| 53 | public:
|
---|
| 54 | SpiralData( const QwtInterval &radialInterval,
|
---|
| 55 | const QwtInterval &azimuthInterval, size_t size ):
|
---|
| 56 | Data( radialInterval, azimuthInterval, size ) {}
|
---|
| 57 |
|
---|
| 58 | virtual QwtPointPolar sample(size_t i) const {
|
---|
| 59 | const double stepA = 4 * _azimuthInterval.width() / _size;
|
---|
| 60 | const double a = _azimuthInterval.minValue() + i * stepA;
|
---|
| 61 |
|
---|
| 62 | const double stepR = _radialInterval.width() / _size;
|
---|
| 63 | const double r = _radialInterval.minValue() + i * stepR;
|
---|
| 64 |
|
---|
| 65 | return QwtPointPolar( a, r );
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | virtual QRectF boundingRect() const {
|
---|
| 69 | if ( d_boundingRect.width() < 0.0 ) {
|
---|
| 70 | d_boundingRect = qwtBoundingRect( *this );
|
---|
| 71 | }
|
---|
| 72 | return d_boundingRect;
|
---|
| 73 | }
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | // Constructor
|
---|
| 77 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 78 | t_polarPlot::t_polarPlot( QWidget *parent ) :
|
---|
| 79 | QwtPolarPlot(QwtText("Polar Plot"), parent ) {
|
---|
| 80 |
|
---|
[4303] | 81 | /// setAutoReplot(false);
|
---|
[4302] | 82 | setPlotBackground(Qt::darkBlue);
|
---|
| 83 |
|
---|
| 84 | // Scales
|
---|
| 85 | // ------
|
---|
| 86 | setScale(QwtPolar::Azimuth,
|
---|
| 87 | azimuthInterval.minValue(), azimuthInterval.maxValue(),
|
---|
| 88 | azimuthInterval.width() / 12);
|
---|
| 89 |
|
---|
| 90 | setScaleMaxMinor( QwtPolar::Azimuth, 2 );
|
---|
| 91 | setScale( QwtPolar::Radius,
|
---|
| 92 | radialInterval.minValue(), radialInterval.maxValue() );
|
---|
| 93 |
|
---|
| 94 | // Grids, Axes
|
---|
| 95 | // -----------
|
---|
| 96 | _grid = new QwtPolarGrid();
|
---|
| 97 | _grid->setPen( QPen( Qt::white ) );
|
---|
| 98 | for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
|
---|
| 99 | _grid->showGrid( scaleId );
|
---|
| 100 | _grid->showMinorGrid( scaleId );
|
---|
| 101 |
|
---|
| 102 | QPen minorPen( Qt::gray );
|
---|
| 103 | _grid->setMinorGridPen( scaleId, minorPen );
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | _grid->setAxisPen( QwtPolar::AxisAzimuth, QPen( Qt::black ) );
|
---|
| 107 |
|
---|
| 108 | _grid->showAxis( QwtPolar::AxisAzimuth, true );
|
---|
| 109 | _grid->showAxis( QwtPolar::AxisLeft, false );
|
---|
| 110 | _grid->showAxis( QwtPolar::AxisRight, true );
|
---|
| 111 | _grid->showAxis( QwtPolar::AxisTop, true );
|
---|
| 112 | _grid->showAxis( QwtPolar::AxisBottom, false );
|
---|
| 113 | _grid->showGrid( QwtPolar::Azimuth, true );
|
---|
| 114 | _grid->showGrid( QwtPolar::Radius, true );
|
---|
| 115 | _grid->attach( this );
|
---|
| 116 |
|
---|
| 117 | // Curves
|
---|
| 118 | // ------
|
---|
| 119 | QwtPolarCurve* curve = createCurve();
|
---|
| 120 | curve->attach(this);
|
---|
| 121 | _curves << curve;
|
---|
| 122 |
|
---|
| 123 | // Legend
|
---|
| 124 | // ------
|
---|
| 125 | QwtLegend *legend = new QwtLegend;
|
---|
| 126 | insertLegend( legend, QwtPolarPlot::BottomLegend );
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | //
|
---|
| 130 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 131 | QwtPolarCurve* t_polarPlot::createCurve() const {
|
---|
| 132 | const int numPoints = 200;
|
---|
| 133 |
|
---|
| 134 | QwtPolarCurve* curve = new QwtPolarCurve();
|
---|
| 135 | curve->setStyle( QwtPolarCurve::Lines );
|
---|
| 136 | curve->setTitle( "Spiral" );
|
---|
| 137 | curve->setPen( QPen( Qt::yellow, 2 ) );
|
---|
| 138 | curve->setSymbol(new QwtSymbol(QwtSymbol::Rect,
|
---|
| 139 | QBrush(Qt::cyan), QPen(Qt::white), QSize(3, 3)));
|
---|
| 140 | curve->setData(
|
---|
| 141 | new SpiralData( radialInterval, azimuthInterval, numPoints ) );
|
---|
| 142 | return curve;
|
---|
| 143 | }
|
---|