Permalink
Browse files

plotview: Basic symbol extraction

ref #63
  • Loading branch information...
1 parent d3217a3 commit f74e847950b47fa89289b1be5143c19b38d27aa2 @miek committed with Apr 20, 2016
Showing with 38 additions and 0 deletions.
  1. +5 −0 cursors.cpp
  2. +1 −0 cursors.h
  3. +31 −0 plotview.cpp
  4. +1 −0 plotview.h
View
@@ -74,6 +74,11 @@ void Cursors::paintFront(QPainter &painter, QRect &rect, range_t<off_t> sampleRa
painter.restore();
}
+int Cursors::segments()
+{
+ return segmentCount;
+}
+
range_t<int> Cursors::selection()
{
return {minCursor->pos(), maxCursor->pos()};
View
@@ -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<off_t> sampleRange);
range_t<int> selection();
View
@@ -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);
View
@@ -74,6 +74,7 @@ public slots:
bool cursorsEnabled;
void addPlot(Plot *plot);
+ void extractSymbols(std::shared_ptr<AbstractSampleSource> src);
int plotsHeight();
off_t samplesPerLine();
void updateView(bool reCenter = false);

0 comments on commit f74e847

Please sign in to comment.