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

@@ -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 File

@@ -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 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);

View File

@@ -74,6 +74,7 @@ private:
bool cursorsEnabled;
void addPlot(Plot *plot);
void extractSymbols(std::shared_ptr<AbstractSampleSource> src);
int plotsHeight();
off_t samplesPerLine();
void updateView(bool reCenter = false);