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("Sample %1, %2 V").arg(p.x(), 0, 'f', 0).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);
59 //setAxisScale(QwtPlot::xBottom, -1.0, 1.0);
61 setAxisTitle(QwtPlot::xBottom, "In-phase");
63 setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
64 //setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
66 setAxisTitle(QwtPlot::yLeft, "Quadrature");
68 // Automatically deleted when parent is deleted
69 _plot_curve = new QwtPlotCurve("Constellation Points");
70 _plot_curve->attach(this);
71 _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
72 _plot_curve->setStyle(QwtPlotCurve::Dots);
73 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
75 memset(_realDataPoints, 0x0, _numPoints*sizeof(double));
76 memset(_imagDataPoints, 0x0, _numPoints*sizeof(double));
80 _zoomer = new ConstellationDisplayZoomer(canvas());
81 #if QT_VERSION < 0x040000
82 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
83 Qt::RightButton, Qt::ControlModifier);
85 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
86 Qt::RightButton, Qt::ControlModifier);
88 _zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
91 _panner = new QwtPlotPanner(canvas());
92 _panner->setAxisEnabled(QwtPlot::yRight, false);
93 _panner->setMouseButton(Qt::MidButton);
95 // Avoid jumping when labels with more/less digits
96 // appear/disappear when scrolling vertically
98 const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font());
99 QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
100 sd->setMinimumExtent( fm.width("100.00") );
102 const QColor c(Qt::darkRed);
103 _zoomer->setRubberBandPen(c);
104 _zoomer->setTrackerPen(c);
106 connect(this, SIGNAL( legendChecked(QwtPlotItem *, bool ) ),
107 this, SLOT( LegendEntryChecked(QwtPlotItem *, bool ) ));
110 ConstellationDisplayPlot::~ConstellationDisplayPlot()
112 delete[] _realDataPoints;
113 delete[] _imagDataPoints;
115 // _fft_plot_curves deleted when parent deleted
116 // _zoomer and _panner deleted when parent deleted
120 ConstellationDisplayPlot::set_pen_size(int size)
122 if(size > 0 && size < 30){
124 _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
130 ConstellationDisplayPlot::set_xaxis(double min, double max)
132 setAxisScale(QwtPlot::xBottom, min, max);
136 ConstellationDisplayPlot::set_yaxis(double min, double max)
138 setAxisScale(QwtPlot::yLeft, min, max);
142 ConstellationDisplayPlot::set_axis(double xmin, double xmax,
143 double ymin, double ymax)
145 set_xaxis(xmin, xmax);
146 set_yaxis(ymin, ymax);
149 void ConstellationDisplayPlot::replot()
155 ConstellationDisplayPlot::resizeSlot( QSize *s )
157 resize(s->width(), s->height());
160 void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints,
161 const double* imagDataPoints,
162 const int64_t numDataPoints,
163 const double timeInterval)
165 if((numDataPoints > 0) &&
166 (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) {
168 if(numDataPoints != _numPoints){
169 _numPoints = numDataPoints;
171 delete[] _realDataPoints;
172 delete[] _imagDataPoints;
173 _realDataPoints = new double[_numPoints];
174 _imagDataPoints = new double[_numPoints];
176 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
179 memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double));
180 memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double));
184 _lastReplot = get_highres_clock();
189 ConstellationDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on)
191 plotItem->setVisible(!on);
194 #endif /* CONSTELLATION_DISPLAY_PLOT_C */