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

Last change on this file since 4314 was 4314, checked in by mervart, 13 years ago
File size: 3.9 KB
RevLine 
[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
[4311]29const QwtInterval zenithInterval(0.0, 90.0);
30const QwtInterval azimuthInterval(0.0, 360.0);
[4302]31
[4311]32// Data Class
[4302]33////////////////////////////////////////////////////////////////////////////
34class Data: public QwtSeriesData<QwtPointPolar> {
35 public:
[4311]36 Data(const QwtInterval &zenithInterval,
37 const QwtInterval &azimuthInterval, size_t size) :
38 _zenithInterval(zenithInterval), _azimuthInterval(azimuthInterval),
39 _size(size) {}
[4302]40
41 virtual size_t size() const {return _size;}
42
43 protected:
[4311]44 QwtInterval _zenithInterval;
[4302]45 QwtInterval _azimuthInterval;
46 size_t _size;
47};
48
[4311]49// Spiral Data Class
[4302]50////////////////////////////////////////////////////////////////////////////
51class SpiralData: public Data {
52 public:
[4311]53 SpiralData(const QwtInterval &zenithInterval,
54 const QwtInterval &azimuthInterval, size_t size) :
55 Data(zenithInterval, azimuthInterval, size) {}
[4302]56
[4311]57 virtual QwtPointPolar sample(size_t ii) const {
[4302]58 const double stepA = 4 * _azimuthInterval.width() / _size;
[4311]59 const double aa = _azimuthInterval.minValue() + ii * stepA;
[4302]60
[4311]61 const double stepR = _zenithInterval.width() / _size;
62 const double rr = _zenithInterval.minValue() + ii * stepR;
[4302]63
[4311]64 return QwtPointPolar(aa, rr);
[4302]65 }
66
67 virtual QRectF boundingRect() const {
[4311]68 if (d_boundingRect.width() < 0.0) {
69 d_boundingRect = qwtBoundingRect(*this);
[4302]70 }
71 return d_boundingRect;
72 }
73};
74
75// Constructor
76////////////////////////////////////////////////////////////////////////////
77t_polarPlot::t_polarPlot( QWidget *parent ) :
[4311]78QwtPolarPlot(QwtText("Polar Plot"), parent) {
[4302]79
[4313]80 setPlotBackground(Qt::white);
[4302]81
82 // Scales
83 // ------
[4311]84 setScale(QwtPolar::Radius,
85 zenithInterval.minValue(), zenithInterval.maxValue());
86
[4302]87 setScale(QwtPolar::Azimuth,
88 azimuthInterval.minValue(), azimuthInterval.maxValue(),
89 azimuthInterval.width() / 12);
90
91 // Grids, Axes
92 // -----------
[4314]93 QwtPolarGrid* grid = new QwtPolarGrid();
94 grid->setPen(QPen(Qt::black));
[4302]95 for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
[4314]96 grid->showGrid(scaleId);
[4302]97 }
98
[4314]99 grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
[4302]100
[4314]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);
[4311]106
[4314]107 grid->showGrid(QwtPolar::Azimuth, true);
108 grid->showGrid(QwtPolar::Radius, true);
[4311]109
[4314]110 grid->attach(this);
[4302]111
112 // Curves
113 // ------
114 QwtPolarCurve* curve = createCurve();
115 curve->attach(this);
116
117 // Legend
118 // ------
119 QwtLegend *legend = new QwtLegend;
[4311]120 insertLegend(legend, QwtPolarPlot::BottomLegend);
[4302]121}
122
[4309]123// Destructor
124////////////////////////////////////////////////////////////////////////////
125t_polarPlot::~t_polarPlot() {
126}
127
[4302]128//
129////////////////////////////////////////////////////////////////////////////
130QwtPolarCurve* t_polarPlot::createCurve() const {
131 const int numPoints = 200;
132 QwtPolarCurve* curve = new QwtPolarCurve();
[4312]133 curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
134 curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
[4313]135 QBrush(Qt::red), QPen(Qt::red),
[4311]136 QSize(3, 3)));
137 curve->setData(new SpiralData(zenithInterval, azimuthInterval, numPoints));
[4302]138 return curve;
139}
Note: See TracBrowser for help on using the repository browser.