aboutsummaryrefslogtreecommitdiffstats
path: root/gr-qtgui
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.se>2021-04-03 18:36:23 +0100
committerMartin Braun <martin@gnuradio.org>2021-04-06 12:04:06 -0700
commit7f6ccfb67cc6600af22fb2bd3d4c65ed00e4d5e7 (patch)
treef928e563348eb04bdb51a2241fa94a0735832dc3 /gr-qtgui
parentqtgui: Remove manual memory management from ConstellationDisplayPlot (diff)
downloadgnuradio-7f6ccfb67cc6600af22fb2bd3d4c65ed00e4d5e7.tar.xz
gnuradio-7f6ccfb67cc6600af22fb2bd3d4c65ed00e4d5e7.zip
qtgui: Remove manual memory management from EyeDisplayPlot
Signed-off-by: Thomas Habets <thomas@habets.se>
Diffstat (limited to 'gr-qtgui')
-rw-r--r--gr-qtgui/include/gnuradio/qtgui/EyeDisplayPlot.h15
-rw-r--r--gr-qtgui/lib/EyeDisplayPlot.cc37
2 files changed, 23 insertions, 29 deletions
diff --git a/gr-qtgui/include/gnuradio/qtgui/EyeDisplayPlot.h b/gr-qtgui/include/gnuradio/qtgui/EyeDisplayPlot.h
index 0066b96f2..c66549f8f 100644
--- a/gr-qtgui/include/gnuradio/qtgui/EyeDisplayPlot.h
+++ b/gr-qtgui/include/gnuradio/qtgui/EyeDisplayPlot.h
@@ -34,6 +34,12 @@ public:
EyeDisplayPlot(unsigned int nplots, unsigned int curve_index, QWidget* parent);
~EyeDisplayPlot() override;
+ // Disable copy&move because of raw QT pointers.
+ EyeDisplayPlot(const EyeDisplayPlot&) = delete;
+ EyeDisplayPlot(EyeDisplayPlot&&) = delete;
+ EyeDisplayPlot& operator=(const EyeDisplayPlot&) = delete;
+ EyeDisplayPlot& operator=(EyeDisplayPlot&&) = delete;
+
void plotNewData(const std::vector<double*> dataPoints,
const int64_t numDataPoints,
int d_sps,
@@ -82,16 +88,15 @@ private:
void _resetXAxisPoints();
void _autoScale(double bottom, double top);
- std::vector<double*> d_ydata;
+ std::vector<std::vector<double>> d_ydata;
- double* d_xdata;
+ std::vector<double> d_xdata;
double d_sample_rate;
unsigned int d_curve_index;
- unsigned int nplots;
- int d_sps;
- unsigned int d_numPointsPerPeriod;
+ int d_sps = 4;
+ unsigned int d_numPointsPerPeriod = 2 * d_sps + 1;
unsigned int d_numPeriods;
bool d_autoscale_shot;
diff --git a/gr-qtgui/lib/EyeDisplayPlot.cc b/gr-qtgui/lib/EyeDisplayPlot.cc
index cd54e0660..f336b2370 100644
--- a/gr-qtgui/lib/EyeDisplayPlot.cc
+++ b/gr-qtgui/lib/EyeDisplayPlot.cc
@@ -97,18 +97,12 @@ EyeDisplayPlot::EyeDisplayPlot(unsigned int nplots,
QWidget* parent)
: DisplayPlot(1, parent)
{
-
d_numPoints = 1024;
d_nplots = nplots;
-
- d_sps = 4;
-
- d_numPointsPerPeriod = 2 * d_sps + 1;
d_numPeriods = std::floor((d_numPoints - 1) / 2 / d_sps);
- d_xdata = new double[d_numPointsPerPeriod];
+ d_xdata.resize(d_numPointsPerPeriod);
d_curve_index = curve_index;
- memset(d_xdata, 0x0, d_numPointsPerPeriod * sizeof(double));
d_tag_text_color = Qt::black;
d_tag_background_color = Qt::white;
@@ -159,8 +153,7 @@ EyeDisplayPlot::EyeDisplayPlot(unsigned int nplots,
// Setup dataPoints and plot vectors
// Automatically deleted when parent is deleted
for (unsigned int i = 0; i < d_numPeriods; ++i) {
- d_ydata.push_back(new double[d_numPointsPerPeriod]);
- memset(d_ydata[i], 0x0, d_numPointsPerPeriod * sizeof(double));
+ d_ydata.emplace_back(d_numPointsPerPeriod);
d_plot_curve.push_back(
new QwtPlotCurve(QString("Eye [Data %1]").arg(d_curve_index)));
d_plot_curve[i]->attach(this);
@@ -173,10 +166,12 @@ EyeDisplayPlot::EyeDisplayPlot(unsigned int nplots,
QSize(7, 7));
#if QWT_VERSION < 0x060000
- d_plot_curve[i]->setRawData(d_xdata, d_ydata[i], d_numPointsPerPeriod);
+ d_plot_curve[i]->setRawData(
+ d_xdata.data(), d_ydata[i].data(), d_numPointsPerPeriod);
d_plot_curve[i]->setSymbol(*symbol);
#else
- d_plot_curve[i]->setRawSamples(d_xdata, d_ydata[i], d_numPointsPerPeriod);
+ d_plot_curve[i]->setRawSamples(
+ d_xdata.data(), d_ydata[i].data(), d_numPointsPerPeriod);
d_plot_curve[i]->setSymbol(symbol);
#endif
}
@@ -207,12 +202,6 @@ EyeDisplayPlot::~EyeDisplayPlot()
{
// Delete d_ydata set used by this EyeDisplayPlot
- delete[] d_ydata[d_curve_index];
-
- // Delete d_xdata once (it is used by some EyeDisplayPlot)
- if (d_curve_index == 0)
- delete[] d_xdata;
-
// d_zoomer and _panner deleted when parent deleted
}
@@ -240,15 +229,15 @@ void EyeDisplayPlot::plotNewData(const std::vector<double*> dataPoints,
// clear d_plot_curve, d_xdata, d_ydata
d_plot_curve.clear();
d_ydata.clear();
- delete[] d_xdata;
- d_xdata = new double[(1 + d_numPointsPerPeriod)];
+ d_xdata.resize(1 + d_numPointsPerPeriod);
_resetXAxisPoints();
// New data structure and data
for (unsigned int i = 0; i < d_numPeriods; ++i) {
int64_t time_index = i * (d_numPointsPerPeriod - 1);
- d_ydata.push_back(new double[d_numPointsPerPeriod]);
- memcpy(d_ydata[i],
+ d_ydata.emplace_back(d_numPointsPerPeriod);
+ // TODO: init copy.
+ memcpy(d_ydata[i].data(),
&(dataPoints[d_curve_index][time_index]),
d_numPointsPerPeriod * sizeof(double));
d_plot_curve.push_back(
@@ -264,11 +253,11 @@ void EyeDisplayPlot::plotNewData(const std::vector<double*> dataPoints,
#if QWT_VERSION < 0x060000
d_plot_curve[i]->setRawData(
- d_xdata, d_ydata[i], d_numPointsPerPeriod);
+ d_xdata.data(), d_ydata[i].data(), d_numPointsPerPeriod);
d_plot_curve[i]->setSymbol(*symbol);
#else
d_plot_curve[i]->setRawSamples(
- d_xdata, d_ydata[i], d_numPointsPerPeriod);
+ d_xdata.data(), d_ydata[i].data(), d_numPointsPerPeriod);
d_plot_curve[i]->setSymbol(symbol);
#endif
}
@@ -276,7 +265,7 @@ void EyeDisplayPlot::plotNewData(const std::vector<double*> dataPoints,
// New data
for (unsigned int i = 0; i < d_numPeriods; ++i) {
int64_t time_index = i * (d_numPointsPerPeriod - 1);
- memcpy(d_ydata[i],
+ memcpy(d_ydata[i].data(),
&(dataPoints[d_curve_index][time_index]),
d_numPointsPerPeriod * sizeof(double));
}