diff --git a/cursors.cpp b/cursors.cpp index 8356def..1c22b3e 100644 --- a/cursors.cpp +++ b/cursors.cpp @@ -74,6 +74,11 @@ void Cursors::paintFront(QPainter &painter, QRect &rect, range_t sampleRa painter.restore(); } +int Cursors::segments() +{ + return segmentCount; +} + range_t Cursors::selection() { return {minCursor->pos(), maxCursor->pos()}; diff --git a/cursors.h b/cursors.h index 31390cb..b9e0570 100644 --- a/cursors.h +++ b/cursors.h @@ -32,6 +32,7 @@ class Cursors : public QObject public: Cursors(QObject * parent); + int segments(); bool mouseEvent(QEvent::Type type, QMouseEvent event); void paintFront(QPainter &painter, QRect &rect, range_t sampleRange); range_t selection(); diff --git a/plotview.cpp b/plotview.cpp index 02ce59b..1ae0e5f 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -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 src) +{ + if (!cursorsEnabled) + return; + auto floatSrc = std::dynamic_pointer_cast>(src); + if (!floatSrc) + return; + auto samples = floatSrc->getSamples(selectedSamples.minimum, selectedSamples.length()); + auto step = selectedSamples.length() / cursors.segments(); + auto symbols = std::vector(); + 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); diff --git a/plotview.h b/plotview.h index 9b3bc62..dcec034 100644 --- a/plotview.h +++ b/plotview.h @@ -74,6 +74,7 @@ private: bool cursorsEnabled; void addPlot(Plot *plot); + void extractSymbols(std::shared_ptr src); int plotsHeight(); off_t samplesPerLine(); void updateView(bool reCenter = false);