diff --git a/src/plot.cpp b/src/plot.cpp --- a/src/plot.cpp +++ b/src/plot.cpp @@ -99,6 +99,7 @@ void Plot::setXAxis(double xMin, double _xMin = xMin; _xMax = xMax; + zoomer.setXLimits(xMin, xMax); zoomer.zoom(0); // unzoom // set axis diff --git a/src/scrollzoomer.cpp b/src/scrollzoomer.cpp --- a/src/scrollzoomer.cpp +++ b/src/scrollzoomer.cpp @@ -42,9 +42,9 @@ ScrollZoomer::ScrollZoomer( QWidget *can d_vScrollData( NULL ), d_inZoom( false ) { - d_limits = QRectF(0, -10, 10000, 20); xMin = 0.; xMax = 10000.; + hViewSize = 10000; for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) d_alignCanvasToScales[ axis ] = false; @@ -64,10 +64,38 @@ ScrollZoomer::~ScrollZoomer() delete d_hScrollData; } +void ScrollZoomer::setXLimits(double min, double max) +{ + xMin = min; + xMax = max; + setZoomBase(); + // TODO: should we update zoom base here? +} + +void ScrollZoomer::setHViewSize(double size) +{ + hViewSize = size; +} + +void ScrollZoomer::setZoomBase(bool doReplot) +{ + QwtPlotZoomer::setZoomBase(doReplot); + auto zb = zoomBase(); + auto zs = zoomStack(); + if ((xMax - xMin) < hViewSize) + { + zb.setWidth(xMax - xMin); + } + else + { + zb.setWidth(hViewSize); + } + zs[0] = zb; + setZoomStack(zs); +} + void ScrollZoomer::rescale() { - qDebug() << "rescale"; - QwtScaleWidget *xScale = plot()->axisWidget( xAxis() ); QwtScaleWidget *yScale = plot()->axisWidget( yAxis() ); @@ -119,9 +147,9 @@ void ScrollZoomer::rescale() } } - // NOTE: Below snipped is copied from QwtPlotZoomer::rescale() just so that + // NOTE: Below snippet is copied from QwtPlotZoomer::rescale() just so that // we can refrain from updating y axis when moving horizontal scrollbar, so - // that auto-scale isn't distrupted. + // that auto-scale isn't disrupted. { QwtPlot *plt = plot(); if ( !plt ) @@ -346,8 +374,6 @@ bool ScrollZoomer::needScrollBar( Qt::Or void ScrollZoomer::updateScrollBars() { - qDebug() << "updateScrollBars()"; - if ( !canvas() ) return; @@ -373,7 +399,6 @@ void ScrollZoomer::updateScrollBars() sb->setInverted( !plot()->axisScaleDiv( xAxis ).isIncreasing() ); sb->setBase( xMin, xMax ); sb->moveSlider( zoomRect().left(), zoomRect().right() ); - qDebug() << "moveSlider" << zoomRect().left() << zoomRect().right(); if ( !sb->isVisibleTo( canvas() ) ) { @@ -440,8 +465,6 @@ void ScrollZoomer::updateScrollBars() void ScrollZoomer::layoutScrollBars( const QRect &rect ) { - qDebug() << "layoutScrollBars" << rect; - int hPos = xAxis(); if ( hScrollBarPosition() == OppositeToScale ) hPos = oppositeAxis( hPos ); diff --git a/src/scrollzoomer.h b/src/scrollzoomer.h --- a/src/scrollzoomer.h +++ b/src/scrollzoomer.h @@ -45,13 +45,14 @@ public: ScrollBarPosition hScrollBarPosition() const; ScrollBarPosition vScrollBarPosition() const; - void setXLimits(double min, double max); - QWidget* cornerWidget() const; virtual void setCornerWidget( QWidget * ); virtual bool eventFilter( QObject *, QEvent * ); + void setXLimits(double min, double max); + void setHViewSize(double size); + virtual void setZoomBase(bool doReplot = true); virtual void rescale(); public Q_SLOTS: @@ -68,6 +69,7 @@ private Q_SLOTS: private: QRectF d_limits; double xMin, xMax; + double hViewSize; bool needScrollBar( Qt::Orientation ) const; int oppositeAxis( int ) const;