1 #ifndef CONSTELLATION_DISPLAY_PLOT_C
2 #define CONSTELLATION_DISPLAY_PLOT_C
4 #include <ConstellationDisplayPlot.h>
6 #include <qwt_scale_draw.h>
7 #include <qwt_legend.h>
10 class ConstellationDisplayZoomer: public QwtPlotZoomer
13 ConstellationDisplayZoomer(QwtPlotCanvas* canvas):QwtPlotZoomer(canvas)
15 setTrackerMode(QwtPicker::AlwaysOn);
18 virtual ~ConstellationDisplayZoomer(){
22 virtual void updateTrackerText(){
27 virtual QwtText trackerText( const QwtDoublePoint& p ) const
29 QwtText t(QString("(%1, %2)").arg(p.x(), 0, 'f', 4).
30 arg(p.y(), 0, 'f', 4));
35 ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent)
38 timespec_reset(&_lastReplot);
40 resize(parent->width(), parent->height());
44 _realDataPoints = new double[_numPoints];
45 _imagDataPoints = new double[_numPoints];
47 // Disable polygon clipping
48 QwtPainter::setDeviceClipping(false);
50 // We don't need the cache here
51 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
52 canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
55 palette.setColor(canvas()->backgroundRole(), QColor("white"));
56 canvas()->setPalette(palette);
58 setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
60 setAxisTitle(QwtPlot::xBottom, "In-phase");
62 setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
64 setAxisTitle(QwtPlot::yLeft, "Quadrature");
66 // Automatically deleted when parent is deleted
67 _plot_curve = new QwtPlotCurve("Constellation Points");
68 _plot_curve->attach(this);
69 _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
70 _plot_curve->setStyle(QwtPlotCurve::Dots);
71 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
73 memset(_realDataPoints, 0x0, _numPoints*sizeof(double));
74 memset(_imagDataPoints, 0x0, _numPoints*sizeof(double));
78 _zoomer = new ConstellationDisplayZoomer(canvas());
79 #if QT_VERSION < 0x040000
80 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
81 Qt::RightButton, Qt::ControlModifier);
83 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
84 Qt::RightButton, Qt::ControlModifier);
86 _zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
89 _panner = new QwtPlotPanner(canvas());
90 _panner->setAxisEnabled(QwtPlot::yRight, false);
91 _panner->setMouseButton(Qt::MidButton);
93 // Avoid jumping when labels with more/less digits
94 // appear/disappear when scrolling vertically
96 const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font());
97 QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
98 sd->setMinimumExtent( fm.width("100.00") );
100 const QColor c(Qt::darkRed);
101 _zoomer->setRubberBandPen(c);
102 _zoomer->setTrackerPen(c);
104 connect(this, SIGNAL( legendChecked(QwtPlotItem *, bool ) ),
105 this, SLOT( LegendEntryChecked(QwtPlotItem *, bool ) ));
108 ConstellationDisplayPlot::~ConstellationDisplayPlot()
110 delete[] _realDataPoints;
111 delete[] _imagDataPoints;
113 // _fft_plot_curves deleted when parent deleted
114 // _zoomer and _panner deleted when parent deleted
118 ConstellationDisplayPlot::set_pen_size(int size)
120 if(size > 0 && size < 30){
122 _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
128 ConstellationDisplayPlot::set_xaxis(double min, double max)
130 setAxisScale(QwtPlot::xBottom, min, max);
134 ConstellationDisplayPlot::set_yaxis(double min, double max)
136 setAxisScale(QwtPlot::yLeft, min, max);
140 ConstellationDisplayPlot::set_axis(double xmin, double xmax,
141 double ymin, double ymax)
143 set_xaxis(xmin, xmax);
144 set_yaxis(ymin, ymax);
147 void ConstellationDisplayPlot::replot()
153 ConstellationDisplayPlot::resizeSlot( QSize *s )
155 resize(s->width(), s->height());
158 void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints,
159 const double* imagDataPoints,
160 const int64_t numDataPoints,
161 const double timeInterval)
163 if((numDataPoints > 0) &&
164 (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) {
166 if(numDataPoints != _numPoints){
167 _numPoints = numDataPoints;
169 delete[] _realDataPoints;
170 delete[] _imagDataPoints;
171 _realDataPoints = new double[_numPoints];
172 _imagDataPoints = new double[_numPoints];
174 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
177 memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double));
178 memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double));
182 _lastReplot = get_highres_clock();
187 ConstellationDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on)
189 plotItem->setVisible(!on);
192 #endif /* CONSTELLATION_DISPLAY_PLOT_C */