Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detach all curve in AthScan::clear(). #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions UI/athScan/athscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ AthScan::AthScan(QWidget *parent) :
{
ui->setupUi(this);

_fft_curve = NULL;
_fft_data = NULL;
_min_freq = 2400;
_max_freq = 6000;
Expand Down Expand Up @@ -148,7 +147,7 @@ int AthScan::parse_scan_file(QString file_name)
if (!data)
continue;
data->next = NULL;
data->data = new(quint8[len]);
data->data = new quint8[len];
if (!data->data)
continue;

Expand Down Expand Up @@ -286,21 +285,21 @@ int AthScan::compute_bin_pwr(fft_sample_tlv *tlv, QPolygonF &sample)

int AthScan::draw_spectrum(quint32 min_freq, quint32 max_freq)
{
QPolygonF fft_samples;

_fft_curve = new QwtPlotCurve();
_fft_curve->setTitle(_label);
_fft_curve->setPen(Qt::green, 2);
_fft_curve->setStyle(QwtPlotCurve::Dots);
QwtPlotCurve *fft_curve = new QwtPlotCurve();
_fft_curve_vec += fft_curve;
fft_curve->setTitle(_label);
fft_curve->setPen(Qt::green, 2);
fft_curve->setStyle(QwtPlotCurve::Dots);

ui->minFreqSpinBox->setValue(min_freq);
ui->maxFreqSpinBox->setValue(max_freq);

QPolygonF fft_samples;
for (scan_sample *data = _fft_data; data; data = data->next)
compute_bin_pwr((fft_sample_tlv *) data->data, fft_samples);

_fft_curve->setSamples(fft_samples);
_fft_curve->attach(ui->fftPlot);
fft_curve->setSamples(fft_samples);
fft_curve->attach(ui->fftPlot);

_borderV->setValue((min_freq + max_freq) / 2, (ui->minPwrSpinBox->value() + ui->maxPwrSpinBox->value()) / 2);
_borderH->setValue((min_freq + max_freq) / 2, (ui->minPwrSpinBox->value() + ui->maxPwrSpinBox->value()) / 2);
Expand All @@ -326,24 +325,27 @@ int AthScan::open_scan_file()
_label.chop(_label.size() - idx);
draw_spectrum(_min_freq, _max_freq);
}

return 0;
}

int AthScan::clear()
{
_min_freq = 2400;
_max_freq = 6000;

while (_fft_data) {
struct scan_sample *fft_ptr = _fft_data;
_fft_data = _fft_data->next;
free(fft_ptr->data);
free(fft_ptr);
}

if (_fft_curve)
_fft_curve->detach();
for (QwtPlotCurve *curve : _fft_curve_vec) {
if (curve) {
curve->detach();
}
}

_min_freq = 2400;
_max_freq = 6000;
ui->minFreqSpinBox->setValue(_min_freq);
ui->maxFreqSpinBox->setValue(_max_freq);

Expand Down
2 changes: 1 addition & 1 deletion UI/athScan/athscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private slots:
QwtPlotCanvas *_canvas;
QwtPlotGrid *_grid;
QwtPlotMarker *_borderV, *_borderH;
QwtPlotCurve *_fft_curve;
QVector<QwtPlotCurve *> _fft_curve_vec;

Ui::AthScan *ui;
struct scan_sample *_fft_data;
Expand Down