source: ntrip/trunk/BNC/src/rinex/polarplot.cpp@ 4311

Last change on this file since 4311 was 4311, checked in by mervart, 12 years ago
File size: 4.1 KB
Line 
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
29const QwtInterval zenithInterval(0.0, 90.0);
30const QwtInterval azimuthInterval(0.0, 360.0);
31
32// Data Class
33////////////////////////////////////////////////////////////////////////////
34class Data: public QwtSeriesData<QwtPointPolar> {
35 public:
36 Data(const QwtInterval &zenithInterval,
37 const QwtInterval &azimuthInterval, size_t size) :
38 _zenithInterval(zenithInterval), _azimuthInterval(azimuthInterval),
39 _size(size) {}
40
41 virtual size_t size() const {return _size;}
42
43 protected:
44 QwtInterval _zenithInterval;
45 QwtInterval _azimuthInterval;
46 size_t _size;
47};
48
49// Spiral Data Class
50////////////////////////////////////////////////////////////////////////////
51class SpiralData: public Data {
52 public:
53 SpiralData(const QwtInterval &zenithInterval,
54 const QwtInterval &azimuthInterval, size_t size) :
55 Data(zenithInterval, azimuthInterval, size) {}
56
57 virtual QwtPointPolar sample(size_t ii) const {
58 const double stepA = 4 * _azimuthInterval.width() / _size;
59 const double aa = _azimuthInterval.minValue() + ii * stepA;
60
61 const double stepR = _zenithInterval.width() / _size;
62 const double rr = _zenithInterval.minValue() + ii * stepR;
63
64 return QwtPointPolar(aa, rr);
65 }
66
67 virtual QRectF boundingRect() const {
68 if (d_boundingRect.width() < 0.0) {
69 d_boundingRect = qwtBoundingRect(*this);
70 }
71 return d_boundingRect;
72 }
73};
74
75// Constructor
76////////////////////////////////////////////////////////////////////////////
77t_polarPlot::t_polarPlot( QWidget *parent ) :
78QwtPolarPlot(QwtText("Polar Plot"), parent) {
79
80 setPlotBackground(Qt::darkBlue);
81
82 // Scales
83 // ------
84 setScale(QwtPolar::Radius,
85 zenithInterval.minValue(), zenithInterval.maxValue());
86
87 setScale(QwtPolar::Azimuth,
88 azimuthInterval.minValue(), azimuthInterval.maxValue(),
89 azimuthInterval.width() / 12);
90
91 setScaleMaxMinor(QwtPolar::Azimuth, 2);
92
93 // Grids, Axes
94 // -----------
95 _grid = new QwtPolarGrid();
96 _grid->setPen(QPen(Qt::white));
97 for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
98 _grid->showGrid( scaleId );
99 _grid->showMinorGrid( scaleId );
100 QPen minorPen( Qt::gray );
101 _grid->setMinorGridPen(scaleId, minorPen);
102 }
103
104 _grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
105
106 _grid->showAxis(QwtPolar::AxisAzimuth, true );
107 _grid->showAxis(QwtPolar::AxisLeft, false);
108 _grid->showAxis(QwtPolar::AxisRight, true);
109 _grid->showAxis(QwtPolar::AxisTop, true);
110 _grid->showAxis(QwtPolar::AxisBottom, false);
111
112 _grid->showGrid(QwtPolar::Azimuth, true);
113 _grid->showGrid(QwtPolar::Radius, true);
114
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// Destructor
130////////////////////////////////////////////////////////////////////////////
131t_polarPlot::~t_polarPlot() {
132}
133
134//
135////////////////////////////////////////////////////////////////////////////
136QwtPolarCurve* t_polarPlot::createCurve() const {
137 const int numPoints = 200;
138 QwtPolarCurve* curve = new QwtPolarCurve();
139 curve->setStyle(QwtPolarCurve::Lines);
140 curve->setTitle("Example Curve");
141 curve->setPen(QPen( Qt::yellow, 2));
142 curve->setSymbol(new QwtSymbol(QwtSymbol::Rect,
143 QBrush(Qt::cyan), QPen(Qt::white),
144 QSize(3, 3)));
145 curve->setData(new SpiralData(zenithInterval, azimuthInterval, numPoints));
146 return curve;
147}
Note: See TracBrowser for help on using the repository browser.