plotview: Basic symbol extraction

ref #63
This commit is contained in:
Mike
2016-04-20 20:27:22 +01:00
committed by Mike Walters
parent d3217a3178
commit f74e847950
4 changed files with 38 additions and 0 deletions

View File

@@ -79,6 +79,18 @@ void PlotView::contextMenuEvent(QContextMenuEvent * event)
);
plotsMenu->addAction(action);
}
// Add action to extract symbols from selected plot
auto extract = new QAction("Extract symbols...", &menu);
connect(
extract, &QAction::triggered,
this, [=]() {
extractSymbols(src);
}
);
extract->setEnabled(cursorsEnabled && (src->sampleType() == typeid(float)));
menu.addAction(extract);
if (menu.exec(event->globalPos()))
updateView(false);
}
@@ -151,6 +163,25 @@ bool PlotView::eventFilter(QObject * obj, QEvent *event)
return false;
}
void PlotView::extractSymbols(std::shared_ptr<AbstractSampleSource> src)
{
if (!cursorsEnabled)
return;
auto floatSrc = std::dynamic_pointer_cast<SampleSource<float>>(src);
if (!floatSrc)
return;
auto samples = floatSrc->getSamples(selectedSamples.minimum, selectedSamples.length());
auto step = selectedSamples.length() / cursors.segments();
auto symbols = std::vector<float>();
for (auto i = step / 2; i < selectedSamples.length(); i += step)
{
symbols.push_back(samples[i]);
}
for (auto f : symbols)
std::cout << f << ", ";
std::cout << std::endl << std::flush;
}
void PlotView::invalidateEvent()
{
horizontalScrollBar()->setMinimum(0);