mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-13 11:47:30 +01:00
@@ -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()};
|
||||
|
||||
@@ -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();
|
||||
|
||||
31
plotview.cpp
31
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<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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user