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
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 // -----------
93 _grid = new QwtPolarGrid();
[4313]94 _grid->setPen(QPen(Qt::black));
[4302]95 for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
[4313]96 _grid->showGrid(scaleId);
[4302]97 }
98
[4311]99 _grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
[4302]100
[4313]101 _grid->showAxis(QwtPolar::AxisAzimuth, true);
[4311]102 _grid->showAxis(QwtPolar::AxisTop, true);
103 _grid->showAxis(QwtPolar::AxisBottom, false);
[4313]104 _grid->showAxis(QwtPolar::AxisLeft, false);
105 _grid->showAxis(QwtPolar::AxisRight, false);
[4311]106
107 _grid->showGrid(QwtPolar::Azimuth, true);
108 _grid->showGrid(QwtPolar::Radius, true);
109
[4302]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;
[4311]121 insertLegend(legend, QwtPolarPlot::BottomLegend);
[4302]122}
123
[4309]124// Destructor
125////////////////////////////////////////////////////////////////////////////
126t_polarPlot::~t_polarPlot() {
127}
128
[4302]129//
130////////////////////////////////////////////////////////////////////////////
131QwtPolarCurve* t_polarPlot::createCurve() const {
132 const int numPoints = 200;
133 QwtPolarCurve* curve = new QwtPolarCurve();
[4312]134 curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
135 curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
[4313]136 QBrush(Qt::red), QPen(Qt::red),
[4311]137 QSize(3, 3)));
138 curve->setData(new SpiralData(zenithInterval, azimuthInterval, numPoints));
[4302]139 return curve;
140}
Note: See TracBrowser for help on using the repository browser.