Skip to content

Commit

Permalink
when increasing the FFT size, the plot should maintain the current ce…
Browse files Browse the repository at this point in the history
…nter frequency

Signed-off-by: Jacob Gilbert <[email protected]>
  • Loading branch information
Jacob Gilbert committed Jul 24, 2021
1 parent 02157c4 commit cb6bba8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/plotview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,17 @@ void PlotView::setCursorSegments(int segments)
selectedSamples.maximum = selectedSamples.minimum + (segments * sampPerSeg + 0.5f);

cursors.setSegments(segments);

updateView();
emitTimeSelection();
}

void PlotView::setFFTAndZoom(int size, int zoom)
{
auto oldSamplesPerColumn = samplesPerColumn();
float oldPlotCenter = (verticalScrollBar()->value() + viewport()->height() / 2.0) / plotsHeight();
if (verticalScrollBar()->maximum() == 0)
oldPlotCenter = 0.5;

// Set new FFT size
fftSize = size;
Expand All @@ -411,6 +415,10 @@ void PlotView::setFFTAndZoom(int size, int zoom)
horizontalScrollBar()->setPageStep(100);

updateView(true, samplesPerColumn() < oldSamplesPerColumn);

// maintain the relative position of the vertical scroll bar
if (verticalScrollBar()->maximum())
verticalScrollBar()->setValue((int )(oldPlotCenter * plotsHeight() - viewport()->height() / 2.0 + 0.5f));
}

void PlotView::setPowerMin(int power)
Expand Down Expand Up @@ -567,6 +575,7 @@ void PlotView::updateView(bool reCenter, bool expanding)
}
horizontalScrollBar()->setMaximum(std::max(0, sampleToColumn(mainSampleSource->count()) - width()));
verticalScrollBar()->setMaximum(std::max(0, plotsHeight() - viewport()->height()));

if (expanding) {
updateViewRange(reCenter);
}
Expand Down

0 comments on commit cb6bba8

Please sign in to comment.