diff options
author | Tom Rondeau <trondeau@vt.edu> | 2012-06-28 00:54:13 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2012-06-28 00:54:13 -0400 |
commit | bc77a2f13c4517459f4759bd2d95c7744282264a (patch) | |
tree | 2c122535861a88e3db37b6ca123c043b9fca3e11 | |
parent | be0c66690661eb5147b77892caecf89ed5444b90 (diff) |
qtgui: adding ability to start/stop running time plots.
-rw-r--r-- | gr-qtgui/lib/TimeDomainDisplayPlot.cc | 44 | ||||
-rw-r--r-- | gr-qtgui/lib/TimeDomainDisplayPlot.h | 4 | ||||
-rw-r--r-- | gr-qtgui/lib/timedisplayform.cc | 68 | ||||
-rw-r--r-- | gr-qtgui/lib/timedisplayform.h | 14 |
4 files changed, 91 insertions, 39 deletions
diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 621b677c81..8c3d5dcbbf 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -96,7 +96,7 @@ private: }; TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) - : QwtPlot(parent), _nplots(nplots) + : QwtPlot(parent), _nplots(nplots), _stop(false) { resize(parent->width(), parent->height()); @@ -290,6 +290,12 @@ TimeDomainDisplayPlot::setLineMarker(int which, QwtSymbol::Style marker) _plot_curve[which]->setSymbol(sym); } +void +TimeDomainDisplayPlot::setStop(bool on) +{ + _stop = on; +} + void TimeDomainDisplayPlot::replot() { QwtPlot::replot(); @@ -306,33 +312,35 @@ void TimeDomainDisplayPlot::PlotNewData(const std::vector<double*> dataPoints, const int64_t numDataPoints, const double timeInterval) { - if((numDataPoints > 0)) { - if(numDataPoints != _numPoints){ - _numPoints = numDataPoints; + if(!_stop) { + if((numDataPoints > 0)) { + if(numDataPoints != _numPoints){ + _numPoints = numDataPoints; - delete[] _xAxisPoints; - _xAxisPoints = new double[_numPoints]; + delete[] _xAxisPoints; + _xAxisPoints = new double[_numPoints]; - for(int i = 0; i < _nplots; i++) { - delete[] _dataPoints[i]; - _dataPoints[i] = new double[_numPoints]; + for(int i = 0; i < _nplots; i++) { + delete[] _dataPoints[i]; + _dataPoints[i] = new double[_numPoints]; #if QWT_VERSION < 0x060000 - _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints); + _plot_curve[i]->setRawData(_xAxisPoints, _dataPoints[i], _numPoints); #else - _plot_curve[i]->setRawSamples(_xAxisPoints, _dataPoints[i], _numPoints); + _plot_curve[i]->setRawSamples(_xAxisPoints, _dataPoints[i], _numPoints); #endif + } + + setXaxis(0, numDataPoints); + _resetXAxisPoints(); } - setXaxis(0, numDataPoints); - _resetXAxisPoints(); - } + for(int i = 0; i < _nplots; i++) { + memcpy(_dataPoints[i], dataPoints[i], numDataPoints*sizeof(double)); + } - for(int i = 0; i < _nplots; i++) { - memcpy(_dataPoints[i], dataPoints[i], numDataPoints*sizeof(double)); + replot(); } - - replot(); } } diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.h b/gr-qtgui/lib/TimeDomainDisplayPlot.h index b940aaae78..ef41727b0d 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.h +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.h @@ -64,6 +64,8 @@ public slots: void setLineStyle(int which, Qt::PenStyle style); void setLineMarker(int which, QwtSymbol::Style marker); + void setStop(bool on); + QString title(int which); void resizeSlot( QSize *s ); @@ -102,6 +104,8 @@ private: double _sampleRate; int64_t _numPoints; + + bool _stop; }; #endif /* TIME_DOMAIN_DISPLAY_PLOT_HPP */ diff --git a/gr-qtgui/lib/timedisplayform.cc b/gr-qtgui/lib/timedisplayform.cc index 69d0253984..f87289065d 100644 --- a/gr-qtgui/lib/timedisplayform.cc +++ b/gr-qtgui/lib/timedisplayform.cc @@ -50,18 +50,20 @@ TimeDisplayForm::TimeDisplayForm(int nplots, QWidget* parent) _grid->setPen(QPen(QColor(Qt::gray))); // Create a set of actions for the menu - _grid_on_act = new QAction("Grid On", this); - _grid_on_act->setStatusTip(tr("Toggle Grid on")); - connect(_grid_on_act, SIGNAL(triggered()), this, SLOT(setGridOn())); + _stop_act = new QAction("Stop", this); + _stop_act->setStatusTip(tr("Start/Stop")); + connect(_stop_act, SIGNAL(triggered()), this, SLOT(setStop())); + _stop_state = false; - _grid_off_act = new QAction("Grid Off", this); - _grid_off_act->setStatusTip(tr("Toggle Grid off")); - connect(_grid_off_act, SIGNAL(triggered()), this, SLOT(setGridOff())); + _grid_act = new QAction("Grid On", this); + _grid_act->setStatusTip(tr("Toggle Grid on/off")); + connect(_grid_act, SIGNAL(triggered()), this, SLOT(setGrid())); + _grid_state = false; // Create a pop-up menu for manipulating the figure _menu = new QMenu(this); - _menu->addAction(_grid_on_act); - _menu->addAction(_grid_off_act); + _menu->addAction(_stop_act); + _menu->addAction(_grid_act); for(int i = 0; i < _nplots; i++) { _line_title_act.push_back(new LineTitleAction(i, this)); @@ -173,6 +175,16 @@ TimeDisplayForm::mousePressEvent( QMouseEvent * e) plotrect.setTop(cvs.y()+cvs.width()+plt->spacing()+plt->canvasMargin(0)); if(!plotrect.contains(e->pos())) { + if(_stop_state == false) + _stop_act->setText(tr("Stop")); + else + _stop_act->setText(tr("Start")); + + if(_grid_state == false) + _grid_act->setText(tr("Grid On")); + else + _grid_act->setText(tr("Grid Off")); + // Update the line titles if changed externally for(int i = 0; i < _nplots; i++) { _lines_menu[i]->setTitle(_timeDomainDisplayPlot->title(i)); @@ -282,27 +294,49 @@ TimeDisplayForm::setLineMarker(int which, QwtSymbol::Style marker) } void -TimeDisplayForm::setGrid(bool on) +TimeDisplayForm::setStop(bool on) { - if(on) { + if(!on) { // will auto-detach if already attached. - _grid->attach(_timeDomainDisplayPlot); - + _timeDomainDisplayPlot->setStop(false); + _stop_state = false; } else { - _grid->detach(); + _timeDomainDisplayPlot->setStop(true); + _stop_state = true; } _timeDomainDisplayPlot->replot(); } void -TimeDisplayForm::setGridOn() +TimeDisplayForm::setStop() +{ + if(_stop_state == false) + setStop(true); + else + setStop(false); +} + +void +TimeDisplayForm::setGrid(bool on) { - setGrid(true); + if(on) { + // will auto-detach if already attached. + _grid->attach(_timeDomainDisplayPlot); + _grid_state = true; + } + else { + _grid->detach(); + _grid_state = false; + } + _timeDomainDisplayPlot->replot(); } void -TimeDisplayForm::setGridOff() +TimeDisplayForm::setGrid() { - setGrid(false); + if(_grid_state == false) + setGrid(true); + else + setGrid(false); } diff --git a/gr-qtgui/lib/timedisplayform.h b/gr-qtgui/lib/timedisplayform.h index 37bff59952..07133ea90c 100644 --- a/gr-qtgui/lib/timedisplayform.h +++ b/gr-qtgui/lib/timedisplayform.h @@ -66,9 +66,11 @@ public slots: void setLineStyle(int which, Qt::PenStyle style); void setLineMarker(int which, QwtSymbol::Style style); + void setStop(bool on); + void setStop(); + void setGrid(bool on); - void setGridOn(); - void setGridOff(); + void setGrid(); private slots: void newData( const TimeUpdateEvent* ); @@ -93,8 +95,12 @@ private: QwtPlotGrid *_grid; QMenu *_menu; - QAction *_grid_on_act; - QAction *_grid_off_act; + + QAction *_stop_act; + bool _stop_state; + QAction *_grid_act; + bool _grid_state; + QList<QMenu*> _lines_menu; QList<LineTitleAction*> _line_title_act; |