Skip to content

Commit

Permalink
general: Implemented MousePlotMagnifier for all plots
Browse files Browse the repository at this point in the history
- zooms with the scroll wheel in and out centering on the mouse cursor
- pans with shift + wheel on x axis
- if you zoom in using the zoomer and the magnifier then the zoom history is cleared thus zooming out with right click will go back to zoom base

Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed Feb 13, 2024
1 parent 6f21a7c commit fade8c6
Show file tree
Hide file tree
Showing 17 changed files with 568 additions and 82 deletions.
6 changes: 6 additions & 0 deletions src/ConstellationDisplayPlot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ ConstellationDisplayPlot::ConstellationDisplayPlot(int nplots, QWidget* parent)
d_zoomer[0]->setRubberBandPen(c);
d_zoomer[0]->setTrackerPen(c);

d_magnifier.push_back(new scopy::MousePlotMagnifier(canvas()));
connect(d_magnifier[0], &scopy::MousePlotMagnifier::reset, this, [=](){
d_zoomer[0]->zoom(0);
});
d_magnifier[0]->setEnabled(true);

// setAxisScaleEngine(QwtAxis::XBottom, new QwtLinearScaleEngine);
// set_xaxis(-2.0, 2.0);
// setAxisTitle(QwtAxis::XBottom, "In-phase");
Expand Down
42 changes: 34 additions & 8 deletions src/DisplayPlot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include <QIcon>
#include <QGridLayout>
#include <qwt_plot_opengl_canvas.h>
#include "gui/mouseplotmagnifier.hpp"

using namespace adiscope;

Expand Down Expand Up @@ -636,6 +637,17 @@ DisplayPlot::DisplayPlot(int nplots, QWidget* parent, bool isdBgraph,
setupReadouts();
}

scopy::MousePlotMagnifier *DisplayPlot::getMagnifier()
{
if(d_magnifier.size())
return d_magnifier[0];
return nullptr;
}

QVector<scopy::MousePlotMagnifier*> DisplayPlot::getMagnifierList()
{
return d_magnifier;
}

void DisplayPlot::setupDisplayPlotDiv(bool isdBgraph) {
if(!isdBgraph)
Expand Down Expand Up @@ -1295,8 +1307,10 @@ DisplayPlot::setAllYAxis(double min, double max)
}

if (!d_autoscale_state) {
for (int i = 0; i < d_zoomer.size(); ++i)
for (int i = 0; i < d_zoomer.size(); ++i) {
d_zoomer[i]->setZoomBase();
d_magnifier[i]->setBaseRect(d_zoomer[i]->zoomBase());
}
}
}

Expand All @@ -1305,17 +1319,21 @@ DisplayPlot::setYaxis(double min, double max)
{
setAxisScale(QwtAxis::YLeft, min, max);
if(!d_autoscale_state) {
for (unsigned int i = 0; i < d_zoomer.size(); ++i)
d_zoomer[i]->setZoomBase();
for (int i = 0; i < d_zoomer.size(); ++i) {
d_zoomer[i]->setZoomBase();
d_magnifier[i]->setBaseRect(d_zoomer[i]->zoomBase());
}
}
}

void
DisplayPlot::setXaxis(double min, double max)
{
setAxisScale(QwtAxis::XBottom, min, max);
for (unsigned int i = 0; i < d_zoomer.size(); ++i)
for(unsigned int i = 0; i < d_zoomer.size(); ++i) {
d_zoomer[i]->setZoomBase();
d_magnifier[i]->setBaseRect(d_zoomer[i]->zoomBase());
}
}

void
Expand Down Expand Up @@ -1678,8 +1696,10 @@ DisplayPlot::onPickerPointSelected6(const QPointF & p)

void DisplayPlot::zoomBaseUpdate(bool force)
{
for (unsigned int i = 0; i < d_zoomer.size(); ++i)
for(unsigned int i = 0; i < d_zoomer.size(); ++i) {
d_zoomer[i]->setZoomBase(force);
d_magnifier[i]->setBaseRect(d_zoomer[i]->zoomBase());
}
}

void DisplayPlot::AddAxisOffset(int axisPos, int axisIdx, double offset)
Expand Down Expand Up @@ -2027,6 +2047,7 @@ void DisplayPlot::mousePressEvent(QMouseEvent *event)
for (unsigned int i = 0; i < d_zoomer.size(); ++i) {
OscPlotZoomer *zoomer = static_cast<OscPlotZoomer *>(d_zoomer[i]);
zoomer->popZoom();
Q_EMIT d_magnifier[i]->reset();
}
}
}
Expand All @@ -2046,9 +2067,14 @@ void DisplayPlot::setZoomerParams(bool bounded, int maxStackDepth)
return;
}

auto zoomer = dynamic_cast<LimitedPlotZoomer*>(d_zoomer[0]);
zoomer->setMaxStackDepth(maxStackDepth);
zoomer->setBoundVertical(bounded);
for (auto zoomer: d_zoomer) {
zoomer->setMaxStackDepth(maxStackDepth);
dynamic_cast<LimitedPlotZoomer*>(zoomer)->setBoundVertical(bounded);
}

for (auto magnifier: d_magnifier) {
magnifier->setBounded(bounded);
}
}

void DisplayPlot::horizAxisScaleIncrease()
Expand Down
5 changes: 5 additions & 0 deletions src/DisplayPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Q_DECLARE_METATYPE ( QColorList )
#else /* QWT_VERSION < 0x060100 */
#include <qwt_legend_data.h>
#include <qwt_legend_label.h>

#include <gui/mouseplotmagnifier.hpp>
#endif /* QWT_VERSION < 0x060100 */

namespace adiscope {
Expand Down Expand Up @@ -430,6 +432,8 @@ class DisplayPlot:public PrintablePlot

void adjustHandleAreasSize(bool cursors = false);
void setCursorAxes(QwtAxisId fixed_axis, QwtAxisId mobile_axis);
scopy::MousePlotMagnifier *getMagnifier();
QVector<scopy::MousePlotMagnifier*> getMagnifierList();
public Q_SLOTS:
virtual void disableLegend();
virtual void setYaxis(double min, double max);
Expand Down Expand Up @@ -620,6 +624,7 @@ protected Q_SLOTS:

QwtPlotPanner* d_panner;
QVector<QwtPlotZoomer*> d_zoomer;
QVector<scopy::MousePlotMagnifier *> d_magnifier;
QwtPlotGrid *d_grid;

QwtDblClickPlotPicker *d_picker;
Expand Down
20 changes: 15 additions & 5 deletions src/FftDisplayPlot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ void FftDisplayPlot::setZoomerEnabled()
}
}

void FftDisplayPlot::setMagnifierEnabled(bool enabled)
{
d_magnifier.push_back(new scopy::MousePlotMagnifier(canvas()));
d_magnifier[0]->setEnabled(enabled);
d_magnifier[0]->setYAxisEnabled(false);
connect(d_magnifier[0], &scopy::MousePlotMagnifier::reset, this, [=](){
d_zoomer[0]->zoom(0);
});

d_magnifier[0]->setBaseRect(d_zoomer[0]->zoomBase());
}

void FftDisplayPlot::setNumPoints(uint64_t num_points)
{
d_numPoints = num_points;
Expand Down Expand Up @@ -897,13 +909,11 @@ void FftDisplayPlot::setAmplitude(double top, double bottom)
void FftDisplayPlot::updateZoomerBase()
{
QRectF rect = QRectF(m_sweepStart, m_bottom, m_sweepStop - m_sweepStart, m_top - m_bottom);
getZoomer()->zoom(rect);

getZoomer()->blockSignals(true);
getZoomer()->setZoomBase(rect);
getZoomer()->QwtPlotZoomer::zoom(rect);
getZoomer()->blockSignals(false);
getMagnifier()->setBaseRect(rect);
Q_EMIT getMagnifier()->reset();

getZoomer()->setZoomBase();
}

void FftDisplayPlot::customEvent(QEvent *e)
Expand Down
1 change: 1 addition & 0 deletions src/FftDisplayPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ namespace adiscope {
void recalculateMagnitudes();
void replot();
void setZoomerEnabled();
void setMagnifierEnabled(bool enabled);
double sampleRate();
void setNumPoints(uint64_t num_points);

Expand Down
56 changes: 55 additions & 1 deletion src/TimeDomainDisplayPlot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ TimeDomainDisplayPlot::TimeDomainDisplayPlot(QWidget* parent, bool isdBgraph, un
for (int i = 0; i < 6; i++) {
d_zoomer.push_back(new TimeDomainDisplayZoomer(this->canvas()));
d_zoomer[i]->setEnabled(false);

d_magnifier.push_back(new scopy::MousePlotMagnifier(canvas()));
d_magnifier[i]->setBounded(true);
d_magnifier[i]->setFactor(0.99);
d_magnifier[i]->setYAxisEnabled(false);
connect(d_magnifier[i], &scopy::MousePlotMagnifier::reset, this, [=](){
d_zoomer[i]->zoom(0);
});
}
}

Expand Down Expand Up @@ -624,6 +632,21 @@ TimeDomainDisplayPlot::addZoomer(unsigned int zoomerIdx)
d_zoomer[zoomerIdx]->setAxes(QwtAxisId(QwtAxis::XBottom, 0), QwtAxisId(QwtAxis::YLeft, zoomerIdx));
}


void TimeDomainDisplayPlot::addMagnifier(unsigned int magnifierIdx)
{
d_magnifier[magnifierIdx]->setEnabled(true);
connect(d_magnifier[magnifierIdx], &scopy::MousePlotMagnifier::reset, this, [=](){
d_zoomer[magnifierIdx]->zoom(0);
});

d_magnifier[magnifierIdx]->setBounded(true);
d_magnifier[magnifierIdx]->setFactor(0.99);
d_magnifier[magnifierIdx]->setXAxis(QwtAxisId(QwtAxis::XBottom, 0));
d_magnifier[magnifierIdx]->setYAxis(QwtAxisId(QwtAxis::YLeft, magnifierIdx));
d_magnifier[magnifierIdx]->setBaseRect(d_zoomer[magnifierIdx]->zoomBase());
}

void
TimeDomainDisplayPlot::removeZoomer(unsigned int zoomerIdx)
{
Expand Down Expand Up @@ -652,6 +675,32 @@ TimeDomainDisplayPlot::removeZoomer(unsigned int zoomerIdx)
}
}

void TimeDomainDisplayPlot::removeMagnifier(unsigned int magnifierIdx)
{
if(magnifierIdx == 0 || magnifierIdx == 1) {
d_magnifier[magnifierIdx]->setEnabled(false);
return;
}

int toDisable = magnifierIdx;
while(d_magnifier[toDisable]->isEnabled() && toDisable < d_magnifier.size() - 1) {
toDisable++;
}

if(toDisable == d_magnifier.size() - 1 && d_magnifier[toDisable]->isEnabled()) {
d_magnifier[toDisable]->setEnabled(false);
} else {
d_magnifier[toDisable - 1]->setEnabled(false);
}

for(int i = 0; i < d_zoomer.size(); ++i) {
if(d_magnifier[i]->isEnabled()) {
d_magnifier[magnifierIdx]->setXAxis(QwtAxisId(QwtAxis::XBottom, 0));
d_magnifier[magnifierIdx]->setYAxis(QwtAxisId(QwtAxis::YLeft, i));
}
}
}

void TimeDomainDisplayPlot::setXAxisNumPoints(unsigned int pts)
{
d_nbPtsXAxis = pts;
Expand Down Expand Up @@ -917,8 +966,10 @@ TimeDomainDisplayPlot::setTagBackgroundStyle(Qt::BrushStyle b)

void TimeDomainDisplayPlot::setZoomerEnabled(bool en)
{
for (unsigned int i = 0; i < d_zoomer.size(); ++i)
for (unsigned int i = 0; i < d_zoomer.size(); ++i) {
d_zoomer[i]->setEnabled(en);
d_magnifier[i]->setEnabled(en);
}
}

bool TimeDomainDisplayPlot::isZoomerEnabled()
Expand Down Expand Up @@ -1419,6 +1470,9 @@ void TimeDomainDisplayPlot::cleanUpJustBeforeChannelRemoval(int)
void TimeDomainDisplayPlot::cancelZoom()
{
for (unsigned int i = 0; i < d_zoomer.size(); ++i) {
if (getMagnifierList()[i]->isZoomed())
Q_EMIT getMagnifierList()[i]->reset();

OscPlotZoomer *zoomer = static_cast<OscPlotZoomer *>(d_zoomer[i]);
zoomer->resetZoom();
}
Expand Down
2 changes: 2 additions & 0 deletions src/TimeDomainDisplayPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ class TimeDomainDisplayPlot: public DisplayPlot
long dataStartingPoint() const;

void addZoomer(unsigned int zoomerIdx);
void addMagnifier(unsigned int magnifierIdx);
void removeZoomer(unsigned int zoomerIdx);
void removeMagnifier(unsigned int magnifierIdx);
void setXAxisNumPoints(unsigned int);

void registerReferenceWaveform(QString name, QVector<double> xData, QVector<double> yData);
Expand Down
22 changes: 11 additions & 11 deletions src/WaterfallDisplayPlot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ WaterfallDisplayPlot::WaterfallDisplayPlot(int nplots, QWidget* parent)
font.setWeight(75);
d_zoomer[0]->setTrackerFont(font);

d_magnifier.push_back(new scopy::MousePlotMagnifier(canvas()));
d_magnifier[0]->setEnabled(true);
d_magnifier[0]->setYAxisEnabled(false);
connect(d_magnifier[0], &scopy::MousePlotMagnifier::reset, this, [=](){
d_zoomer[0]->zoom(0);
});

_updateIntensityRangeDisplay();

// offset between fft plot and waterfall plot raw values
Expand Down Expand Up @@ -416,12 +423,7 @@ void WaterfallDisplayPlot::resetAxis(bool resetData)

setAxisScale(QwtAxis::XBottom, d_start_frequency, d_stop_frequency);

// Load up the new base zoom settings
QwtDoubleRect zbase = d_zoomer[0]->zoomBase();
d_zoomer[0]->zoom(zbase);
d_zoomer[0]->setZoomBase(zbase);
d_zoomer[0]->setZoomBase(true);
d_zoomer[0]->zoom(0);
updateZoomerBase();
}

void WaterfallDisplayPlot::setLeftVertAxisUnit(const QString &unit)
Expand Down Expand Up @@ -981,13 +983,11 @@ void WaterfallDisplayPlot::setUpdateTime(double t)
void WaterfallDisplayPlot::updateZoomerBase()
{
QRectF rect = QRectF(d_start_frequency, 0, d_stop_frequency - d_start_frequency, d_visible_samples);
getZoomer()->zoom(rect);

getZoomer()->blockSignals(true);
getZoomer()->setZoomBase(rect);
getZoomer()->QwtPlotZoomer::zoom(rect);
getZoomer()->blockSignals(false);
getMagnifier()->setBaseRect(rect);
Q_EMIT getMagnifier()->reset();

getZoomer()->setZoomBase();
}

void WaterfallDisplayPlot::customEvent(QEvent *e)
Expand Down
12 changes: 12 additions & 0 deletions src/dbgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ dBgraph::dBgraph(QWidget *parent, bool isdBgraph)
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);

d_magnifier.push_back(new scopy::MousePlotMagnifier(canvas()));
d_magnifier[0]->setXAxis(QwtAxis::XTop);
d_magnifier[0]->setYAxisEnabled(false);
d_magnifier[0]->setEnabled(true);

installEventFilter(this);

static_cast<QFrame *>(canvas())->setLineWidth(0);
Expand Down Expand Up @@ -438,11 +443,13 @@ void dBgraph::setYTitle(const QString& title)
void dBgraph::setXMin(double val)
{
zoomer->resetZoom();
Q_EMIT d_magnifier[0]->reset();
setAxisScale(QwtAxis::XTop, val, xmax);
xmin = val;
draw_x->invalidateCache();

zoomer->setZoomBase();
d_magnifier[0]->setBaseRect(zoomer->zoomBase());
replot();
auto div = axisScaleDiv(QwtAxis::XTop);
setXaxisNumDiv((div.ticks(2)).size() - 1);
Expand All @@ -452,11 +459,13 @@ void dBgraph::setXMin(double val)
void dBgraph::setXMax(double val)
{
zoomer->resetZoom();
Q_EMIT d_magnifier[0]->reset();
setAxisScale(QwtAxis::XTop, xmin, val);
xmax = val;
draw_x->invalidateCache();

zoomer->setZoomBase();
d_magnifier[0]->setBaseRect(zoomer->zoomBase());
replot();
auto div = axisScaleDiv(QwtAxis::XTop);
setXaxisNumDiv((div.ticks(2)).size() - 1);
Expand All @@ -474,6 +483,7 @@ void dBgraph::setYMin(double val)
double width = xmax - xmin;
double height = ymax - ymin;
zoomer->setZoomBase(QRectF(xmin, ymin, width, height));
d_magnifier[0]->setBaseRect(zoomer->zoomBase());
}

void dBgraph::setYMax(double val)
Expand All @@ -485,6 +495,7 @@ void dBgraph::setYMax(double val)
double width = xmax - xmin;
double height = ymax - ymin;
zoomer->setZoomBase(QRectF(xmin, ymin, width, height));
d_magnifier[0]->setBaseRect(zoomer->zoomBase());
}

QString dBgraph::xUnit() const
Expand Down Expand Up @@ -775,6 +786,7 @@ void dBgraph::mousePressEvent(QMouseEvent *event)
void dBgraph::onResetZoom()
{
zoomer->resetZoom();
Q_EMIT d_magnifier[0]->reset();
}

#ifdef __ANDROID__
Expand Down
Loading

0 comments on commit fade8c6

Please sign in to comment.