diff options
author | Thomas Habets <thomas@habets.se> | 2021-03-01 10:37:52 +0000 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-03-01 09:47:14 -0500 |
commit | 031c7d863f38534809a2d8badf74886cbc9fc944 (patch) | |
tree | ce215d27561bd4f4e9def701b2f41ec0330179d7 | |
parent | b69fa4a7b9814ad1bb4ab0dfbe71d5d1c9ab70af (diff) |
qtgui: Remove manual memory management from HistogramDisplayPlot
Signed-off-by: Thomas Habets <thomas@habets.se>
-rw-r--r-- | gr-qtgui/include/gnuradio/qtgui/HistogramDisplayPlot.h | 23 | ||||
-rw-r--r-- | gr-qtgui/lib/HistogramDisplayPlot.cc | 45 |
2 files changed, 29 insertions, 39 deletions
diff --git a/gr-qtgui/include/gnuradio/qtgui/HistogramDisplayPlot.h b/gr-qtgui/include/gnuradio/qtgui/HistogramDisplayPlot.h index 3b120d50c0..3df6c1e86d 100644 --- a/gr-qtgui/include/gnuradio/qtgui/HistogramDisplayPlot.h +++ b/gr-qtgui/include/gnuradio/qtgui/HistogramDisplayPlot.h @@ -28,6 +28,13 @@ public: HistogramDisplayPlot(unsigned int nplots, QWidget*); ~HistogramDisplayPlot() override; + // Disallow copy/move because of the raw QT pointers. + // They are handled by QT. + HistogramDisplayPlot(const HistogramDisplayPlot&) = delete; + HistogramDisplayPlot(HistogramDisplayPlot&&) = delete; + HistogramDisplayPlot& operator=(const HistogramDisplayPlot&) = delete; + HistogramDisplayPlot& operator=(HistogramDisplayPlot&&) = delete; + void plotNewData(const std::vector<double*> dataPoints, const uint64_t numDataPoints, const double timeInterval); @@ -55,17 +62,17 @@ private: void _resetXAxisPoints(double left, double right); void _autoScaleY(double bottom, double top); - double* d_xdata; - std::vector<double*> d_ydata; - - unsigned int d_bins; - bool d_accum; + unsigned int d_bins = 100; + bool d_accum = false; double d_xmin, d_xmax, d_left, d_right; double d_width; - bool d_semilogx; - bool d_semilogy; - bool d_autoscalex_state; + std::vector<double> d_xdata; + std::vector<std::vector<double>> d_ydata; + + bool d_semilogx = false; + bool d_semilogy = false; + bool d_autoscalex_state = true; }; #endif /* HISTOGRAM_DISPLAY_PLOT_H */ diff --git a/gr-qtgui/lib/HistogramDisplayPlot.cc b/gr-qtgui/lib/HistogramDisplayPlot.cc index a918e0a301..b552e95212 100644 --- a/gr-qtgui/lib/HistogramDisplayPlot.cc +++ b/gr-qtgui/lib/HistogramDisplayPlot.cc @@ -88,15 +88,8 @@ private: * Main Time domain plotter widget **********************************************************************/ HistogramDisplayPlot::HistogramDisplayPlot(unsigned int nplots, QWidget* parent) - : DisplayPlot(nplots, parent) + : DisplayPlot(nplots, parent), d_xdata(d_bins) { - d_bins = 100; - d_accum = false; - - // Initialize x-axis data array - d_xdata = new double[d_bins]; - memset(d_xdata, 0x0, d_bins * sizeof(double)); - d_zoomer = new HistogramDisplayZoomer(canvas(), 0); #if QWT_VERSION < 0x060000 @@ -111,10 +104,7 @@ HistogramDisplayPlot::HistogramDisplayPlot(unsigned int nplots, QWidget* parent) d_zoomer->setRubberBandPen(c); d_zoomer->setTrackerPen(c); - d_semilogx = false; - d_semilogy = false; d_autoscale_state = true; - d_autoscalex_state = false; setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine); setXaxis(-1, 1); @@ -133,8 +123,7 @@ HistogramDisplayPlot::HistogramDisplayPlot(unsigned 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_bins]); - memset(d_ydata[i], 0, d_bins * sizeof(double)); + d_ydata.emplace_back(d_bins); d_plot_curve.push_back(new QwtPlotCurve(QString("Data %1").arg(i))); d_plot_curve[i]->attach(this); @@ -150,10 +139,10 @@ HistogramDisplayPlot::HistogramDisplayPlot(unsigned 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_bins); + d_plot_curve[i]->setRawData(d_xdata.data(), d_ydata[i].data(), d_bins); d_plot_curve[i]->setSymbol(*symbol); #else - d_plot_curve[i]->setRawSamples(d_xdata, d_ydata[i], d_bins); + d_plot_curve[i]->setRawSamples(d_xdata.data(), d_ydata[i].data(), d_bins); d_plot_curve[i]->setSymbol(symbol); #endif } @@ -163,10 +152,6 @@ HistogramDisplayPlot::HistogramDisplayPlot(unsigned int nplots, QWidget* parent) HistogramDisplayPlot::~HistogramDisplayPlot() { - for (unsigned int i = 0; i < d_nplots; ++i) - delete[] d_ydata[i]; - delete[] d_xdata; - // d_zoomer and _panner deleted when parent deleted } @@ -213,10 +198,10 @@ void HistogramDisplayPlot::plotNewData(const std::vector<double*> dataPoints, } } - double height = *std::max_element(d_ydata[0], d_ydata[0] + d_bins); - for (unsigned int n = 1; n < d_nplots; ++n) { + auto height = std::numeric_limits<double>::lowest(); + for (const auto& dy : d_ydata) { height = - std::max(height, *std::max_element(d_ydata[n], d_ydata[n] + d_bins)); + std::max(height, *std::max_element(std::begin(dy), std::end(dy))); } if (d_autoscale_state) @@ -409,19 +394,17 @@ void HistogramDisplayPlot::setNumBins(unsigned int bins) { d_bins = bins; - delete[] d_xdata; - d_xdata = new double[d_bins]; + d_xdata.resize(d_bins); _resetXAxisPoints(d_left, d_right); for (unsigned int i = 0; i < d_nplots; ++i) { - delete[] d_ydata[i]; - d_ydata[i] = new double[d_bins]; - memset(d_ydata[i], 0, d_bins * sizeof(double)); + d_ydata[i].clear(); + d_ydata[i].resize(d_bins); #if QWT_VERSION < 0x060000 - d_plot_curve[i]->setRawData(d_xdata, d_ydata[i], d_bins); + d_plot_curve[i]->setRawData(d_xdata.data(), d_ydata[i].data(), d_bins); #else - d_plot_curve[i]->setRawSamples(d_xdata, d_ydata[i], d_bins); + d_plot_curve[i]->setRawSamples(d_xdata.data(), d_ydata[i].data(), d_bins); #endif } } @@ -430,8 +413,8 @@ void HistogramDisplayPlot::setNumBins(unsigned int bins) void HistogramDisplayPlot::clear() { if (!d_stop) { - for (unsigned int n = 0; n < d_nplots; ++n) { - memset(d_ydata[n], 0, d_bins * sizeof(double)); + for (auto& d : d_ydata) { + std::fill(std::begin(d), std::end(d), 0.0); } } } |