diff --git a/plotview.cpp b/plotview.cpp index 727f932..bf6a78f 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -110,7 +110,6 @@ void PlotView::contextMenuEvent(QContextMenuEvent * event) exportSamples(src); } ); - save->setEnabled(src->sampleType() == typeid(std::complex)); menu.addAction(save); updateViewRange(false); @@ -215,8 +214,18 @@ void PlotView::extractSymbols(std::shared_ptr src) void PlotView::exportSamples(std::shared_ptr src) { - auto complexSrc = std::dynamic_pointer_cast>>(src); - if (!complexSrc) { + if (src->sampleType() == typeid(std::complex)) { + exportSamples>(src); + } else { + exportSamples(src); + } +} + +template +void PlotView::exportSamples(std::shared_ptr src) +{ + auto sampleSrc = std::dynamic_pointer_cast>(src); + if (!sampleSrc) { return; } @@ -250,7 +259,7 @@ void PlotView::exportSamples(std::shared_ptr src) QGroupBox groupBox2("Decimation"); QSpinBox decimation(&groupBox2); - decimation.setValue(1 / complexSrc->relativeBandwidth()); + decimation.setValue(1 / sampleSrc->relativeBandwidth()); QVBoxLayout vbox2; vbox2.addWidget(&decimation); @@ -270,7 +279,7 @@ void PlotView::exportSamples(std::shared_ptr src) end = start + viewRange.length(); } else { start = 0; - end = complexSrc->count(); + end = sampleSrc->count(); } std::ofstream os (fileNames[0].toStdString(), std::ios::binary); @@ -281,10 +290,10 @@ void PlotView::exportSamples(std::shared_ptr src) for (index = start; index < end; index += step) { off_t length = std::min(step, end - index); - auto samples = complexSrc->getSamples(index, length); + auto samples = sampleSrc->getSamples(index, length); if (samples != nullptr) { for (auto i = 0; i < length; i += decimation.value()) { - os.write((const char*)&samples[i], 8); + os.write((const char*)&samples[i], sizeof(SOURCETYPE)); } } } diff --git a/plotview.h b/plotview.h index 5a76612..4296da0 100644 --- a/plotview.h +++ b/plotview.h @@ -80,6 +80,7 @@ private: void emitTimeSelection(); void extractSymbols(std::shared_ptr src); void exportSamples(std::shared_ptr src); + template void exportSamples(std::shared_ptr src); int plotsHeight(); off_t samplesPerLine(); void updateViewRange(bool reCenter);