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 using QwtPlotZoomer::trackerText;
28 virtual QwtText trackerText( const QwtDoublePoint& p ) const
30 QwtText t(QString("(%1, %2)").arg(p.x(), 0, 'f', 4).
31 arg(p.y(), 0, 'f', 4));
36 ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent)
39 timespec_reset(&_lastReplot);
41 resize(parent->width(), parent->height());
45 _realDataPoints = new double[_numPoints];
46 _imagDataPoints = new double[_numPoints];
48 // Disable polygon clipping
49 QwtPainter::setDeviceClipping(false);
51 // We don't need the cache here
52 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
53 canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
56 palette.setColor(canvas()->backgroundRole(), QColor("white"));
57 canvas()->setPalette(palette);
59 setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
61 setAxisTitle(QwtPlot::xBottom, "In-phase");
63 setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
65 setAxisTitle(QwtPlot::yLeft, "Quadrature");
67 // Automatically deleted when parent is deleted
68 _plot_curve = new QwtPlotCurve("Constellation Points");
69 _plot_curve->attach(this);
70 _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
71 _plot_curve->setStyle(QwtPlotCurve::Dots);
72 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
74 memset(_realDataPoints, 0x0, _numPoints*sizeof(double));
75 memset(_imagDataPoints, 0x0, _numPoints*sizeof(double));
79 _zoomer = new ConstellationDisplayZoomer(canvas());
80 #if QT_VERSION < 0x040000
81 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
82 Qt::RightButton, Qt::ControlModifier);
84 _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
85 Qt::RightButton, Qt::ControlModifier);
87 _zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
90 _panner = new QwtPlotPanner(canvas());
91 _panner->setAxisEnabled(QwtPlot::yRight, false);
92 _panner->setMouseButton(Qt::MidButton);
94 // Avoid jumping when labels with more/less digits
95 // appear/disappear when scrolling vertically
97 const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font());
98 QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
99 sd->setMinimumExtent( fm.width("100.00") );
101 const QColor c(Qt::darkRed);
102 _zoomer->setRubberBandPen(c);
103 _zoomer->setTrackerPen(c);
105 connect(this, SIGNAL( legendChecked(QwtPlotItem *, bool ) ),
106 this, SLOT( LegendEntryChecked(QwtPlotItem *, bool ) ));
109 ConstellationDisplayPlot::~ConstellationDisplayPlot()
111 delete[] _realDataPoints;
112 delete[] _imagDataPoints;
114 // _fft_plot_curves deleted when parent deleted
115 // _zoomer and _panner deleted when parent deleted
119 ConstellationDisplayPlot::set_pen_size(int size)
121 if(size > 0 && size < 30){
123 _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
129 ConstellationDisplayPlot::set_xaxis(double min, double max)
131 setAxisScale(QwtPlot::xBottom, min, max);
135 ConstellationDisplayPlot::set_yaxis(double min, double max)
137 setAxisScale(QwtPlot::yLeft, min, max);
141 ConstellationDisplayPlot::set_axis(double xmin, double xmax,
142 double ymin, double ymax)
144 set_xaxis(xmin, xmax);
145 set_yaxis(ymin, ymax);
148 void ConstellationDisplayPlot::replot()
154 ConstellationDisplayPlot::resizeSlot( QSize *s )
156 resize(s->width(), s->height());
159 void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints,
160 const double* imagDataPoints,
161 const int64_t numDataPoints,
162 const double timeInterval)
164 if((numDataPoints > 0) &&
165 (diff_timespec(get_highres_clock(), _lastReplot) > timeInterval)) {
167 if(numDataPoints != _numPoints){
168 _numPoints = numDataPoints;
170 delete[] _realDataPoints;
171 delete[] _imagDataPoints;
172 _realDataPoints = new double[_numPoints];
173 _imagDataPoints = new double[_numPoints];
175 _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints);
178 memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double));
179 memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double));
183 _lastReplot = get_highres_clock();
188 ConstellationDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on)
190 plotItem->setVisible(!on);
193 #endif /* CONSTELLATION_DISPLAY_PLOT_C */