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

Last change on this file since 4313 was 4313, checked in by mervart, 12 years ago
File size: 3.9 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::white);
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 // Grids, Axes
92 // -----------
93 _grid = new QwtPolarGrid();
94 _grid->setPen(QPen(Qt::black));
95 for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
96 _grid->showGrid(scaleId);
97 }
98
99 _grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
100
101 _grid->showAxis(QwtPolar::AxisAzimuth, true);
102 _grid->showAxis(QwtPolar::AxisTop, true);
103 _grid->showAxis(QwtPolar::AxisBottom, false);
104 _grid->showAxis(QwtPolar::AxisLeft, false);
105 _grid->showAxis(QwtPolar::AxisRight, false);
106
107 _grid->showGrid(QwtPolar::Azimuth, true);
108 _grid->showGrid(QwtPolar::Radius, true);
109
110 _grid->attach( this );
111
112 // Curves
113 // ------
114 QwtPolarCurve* curve = createCurve();
115 curve->attach(this);
116 _curves << curve;
117
118 // Legend
119 // ------
120 QwtLegend *legend = new QwtLegend;
121 insertLegend(legend, QwtPolarPlot::BottomLegend);
122}
123
124// Destructor
125////////////////////////////////////////////////////////////////////////////
126t_polarPlot::~t_polarPlot() {
127}
128
129//
130////////////////////////////////////////////////////////////////////////////
131QwtPolarCurve* t_polarPlot::createCurve() const {
132 const int numPoints = 200;
133 QwtPolarCurve* curve = new QwtPolarCurve();
134 curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
135 curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
136 QBrush(Qt::red), QPen(Qt::red),
137 QSize(3, 3)));
138 curve->setData(new SpiralData(zenithInterval, azimuthInterval, numPoints));
139 return curve;
140}
Note: See TracBrowser for help on using the repository browser.