diff options
author | Thomas Habets <thomas@habets.se> | 2021-04-04 13:24:53 +0100 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2021-04-06 12:04:06 -0700 |
commit | e80b963a4395938677bbc9c46424aa71a8fd0e53 (patch) | |
tree | c283f905b136c6137ca7bee1ab16129331318143 | |
parent | 6b89a4a59bb8e0416046893c34930937b7948755 (diff) |
qtgui: Remove manual memory management from TimeDomainDisplayPlot
Signed-off-by: Thomas Habets <thomas@habets.se>
-rw-r--r-- | gr-qtgui/include/gnuradio/qtgui/TimeDomainDisplayPlot.h | 16 | ||||
-rw-r--r-- | gr-qtgui/lib/TimeDomainDisplayPlot.cc | 37 |
2 files changed, 24 insertions, 29 deletions
diff --git a/gr-qtgui/include/gnuradio/qtgui/TimeDomainDisplayPlot.h b/gr-qtgui/include/gnuradio/qtgui/TimeDomainDisplayPlot.h index 975e79b75f..0072173311 100644 --- a/gr-qtgui/include/gnuradio/qtgui/TimeDomainDisplayPlot.h +++ b/gr-qtgui/include/gnuradio/qtgui/TimeDomainDisplayPlot.h @@ -35,6 +35,12 @@ public: TimeDomainDisplayPlot(int nplots, QWidget*); ~TimeDomainDisplayPlot() override; + // Disable move/delete because of raw QT pointers. + TimeDomainDisplayPlot(const TimeDomainDisplayPlot&) = delete; + TimeDomainDisplayPlot(TimeDomainDisplayPlot&&) = delete; + TimeDomainDisplayPlot& operator=(const TimeDomainDisplayPlot&) = delete; + TimeDomainDisplayPlot& operator=(TimeDomainDisplayPlot&&) = delete; + void plotNewData(const std::vector<double*> dataPoints, const int64_t numDataPoints, const double timeInterval, @@ -77,8 +83,8 @@ private: void _resetXAxisPoints(); void _autoScale(double bottom, double top); - std::vector<double*> d_ydata; - double* d_xdata; + std::vector<std::vector<double>> d_ydata; + std::vector<double> d_xdata; double d_sample_rate; @@ -89,9 +95,9 @@ private: std::vector<std::vector<QwtPlotMarker*>> d_tag_markers; std::vector<bool> d_tag_markers_en; - QColor d_tag_text_color; - QColor d_tag_background_color; - Qt::BrushStyle d_tag_background_style; + QColor d_tag_text_color = Qt::black; + QColor d_tag_background_color = Qt::white; + Qt::BrushStyle d_tag_background_style = Qt::NoBrush; QwtPlotMarker* d_trigger_lines[2]; }; diff --git a/gr-qtgui/lib/TimeDomainDisplayPlot.cc b/gr-qtgui/lib/TimeDomainDisplayPlot.cc index 6bb97dcd43..26f3e3a8df 100644 --- a/gr-qtgui/lib/TimeDomainDisplayPlot.cc +++ b/gr-qtgui/lib/TimeDomainDisplayPlot.cc @@ -90,20 +90,13 @@ private: std::string d_yUnitType; }; - /*********************************************************************** * Main Time domain plotter widget **********************************************************************/ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) - : DisplayPlot(nplots, parent) + : DisplayPlot(nplots, parent), d_xdata(1024) { - d_numPoints = 1024; - d_xdata = new double[d_numPoints]; - memset(d_xdata, 0x0, d_numPoints * sizeof(double)); - - d_tag_text_color = Qt::black; - d_tag_background_color = Qt::white; - d_tag_background_style = Qt::NoBrush; + d_numPoints = d_xdata.size(); d_zoomer = new TimeDomainDisplayZoomer(canvas(), 0); @@ -147,8 +140,7 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) // Setup dataPoints and plot vectors // Automatically deleted when parent is deleted for (unsigned int i = 0; i < d_nplots; ++i) { - d_ydata.push_back(new double[d_numPoints]); - memset(d_ydata[i], 0x0, d_numPoints * sizeof(double)); + d_ydata.emplace_back(d_numPoints); d_plot_curve.push_back(new QwtPlotCurve(QString("Data %1").arg(i))); d_plot_curve[i]->attach(this); @@ -159,10 +151,10 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) QwtSymbol::NoSymbol, QBrush(colors[i]), QPen(colors[i]), QSize(7, 7)); #if QWT_VERSION < 0x060000 - d_plot_curve[i]->setRawData(d_xdata, d_ydata[i], d_numPoints); + d_plot_curve[i]->setRawData(d_xdata.data(), d_ydata[i].data(), d_numPoints); d_plot_curve[i]->setSymbol(*symbol); #else - d_plot_curve[i]->setRawSamples(d_xdata, d_ydata[i], d_numPoints); + d_plot_curve[i]->setRawSamples(d_xdata.data(), d_ydata[i].data(), d_numPoints); d_plot_curve[i]->setSymbol(symbol); #endif } @@ -191,10 +183,6 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(int nplots, QWidget* parent) TimeDomainDisplayPlot::~TimeDomainDisplayPlot() { - for (unsigned int i = 0; i < d_nplots; ++i) - delete[] d_ydata[i]; - delete[] d_xdata; - // d_zoomer and _panner deleted when parent deleted } @@ -210,17 +198,17 @@ void TimeDomainDisplayPlot::plotNewData(const std::vector<double*> dataPoints, if (numDataPoints != d_numPoints) { d_numPoints = numDataPoints; - delete[] d_xdata; - d_xdata = new double[d_numPoints]; + d_xdata.resize(d_numPoints); for (unsigned int i = 0; i < d_nplots; ++i) { - delete[] d_ydata[i]; - d_ydata[i] = new double[d_numPoints]; + d_ydata[i].resize(d_numPoints); #if QWT_VERSION < 0x060000 - d_plot_curve[i]->setRawData(d_xdata, d_ydata[i], d_numPoints); + d_plot_curve[i]->setRawData( + d_xdata.data(), d_ydata[i].data(), d_numPoints); #else - d_plot_curve[i]->setRawSamples(d_xdata, d_ydata[i], d_numPoints); + d_plot_curve[i]->setRawSamples( + d_xdata.data(), d_ydata[i].data(), d_numPoints); #endif } @@ -232,7 +220,8 @@ void TimeDomainDisplayPlot::plotNewData(const std::vector<double*> dataPoints, for (int n = 0; n < numDataPoints; n++) d_ydata[i][n] = fabs(dataPoints[i][n]); } else { - memcpy(d_ydata[i], dataPoints[i], numDataPoints * sizeof(double)); + memcpy( + d_ydata[i].data(), dataPoints[i], numDataPoints * sizeof(double)); } } |