Changeset - 5974901a8564
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 8 years ago 2017-08-13 13:01:56
hy@ozderya.net
set zoombase according to xlimits and hviewsize
3 files changed with 38 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/plot.cpp
Show inline comments
 
@@ -96,12 +96,13 @@ void Plot::setYAxis(bool autoScaled, dou
 

	
 
void Plot::setXAxis(double xMin, double xMax)
 
{
 
    _xMin = xMin;
 
    _xMax = xMax;
 

	
 
    zoomer.setXLimits(xMin, xMax);
 
    zoomer.zoom(0); // unzoom
 

	
 
    // set axis
 
    // setAxisScale(QwtPlot::xBottom, xMin, xMax);
 
    replot(); // Note: if we don't replot here scale at startup isn't set correctly
 

	
src/scrollzoomer.cpp
Show inline comments
 
@@ -39,15 +39,15 @@ ScrollZoomer::ScrollZoomer( QWidget *can
 
    QwtPlotZoomer( canvas ),
 
    d_cornerWidget( NULL ),
 
    d_hScrollData( NULL ),
 
    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;
 

	
 
    if ( !canvas )
 
        return;
 
@@ -61,16 +61,44 @@ ScrollZoomer::~ScrollZoomer()
 
{
 
    delete d_cornerWidget;
 
    delete d_vScrollData;
 
    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() );
 

	
 
    if ( zoomRectIndex() <= 0 )
 
    {
 
        if ( d_inZoom )
 
@@ -116,15 +144,15 @@ void ScrollZoomer::rescale()
 
            layout->setAlignCanvasToScales( false );
 

	
 
            d_inZoom = true;
 
        }
 
    }
 

	
 
    // 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 )
 
            return;
 

	
 
        const QRectF &rect = zoomStack()[zoomRectIndex()];
 
@@ -343,14 +371,12 @@ bool ScrollZoomer::needScrollBar( Qt::Or
 
    }
 
    return needed;
 
}
 

	
 
void ScrollZoomer::updateScrollBars()
 
{
 
    qDebug() << "updateScrollBars()";
 

	
 
    if ( !canvas() )
 
        return;
 

	
 
    const int xAxis = QwtPlotZoomer::xAxis();
 
    const int yAxis = QwtPlotZoomer::yAxis();
 

	
 
@@ -370,13 +396,12 @@ void ScrollZoomer::updateScrollBars()
 
    {
 
        ScrollBar *sb = scrollBar( Qt::Horizontal );
 
        sb->setPalette( plot()->palette() );
 
        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() ) )
 
        {
 
            sb->show();
 
            layout->setCanvasMargin( layout->canvasMargin( xScrollBarAxis )
 
                + sb->extent(), xScrollBarAxis );
 
@@ -437,14 +462,12 @@ void ScrollZoomer::updateScrollBars()
 
    layoutScrollBars( canvas()->contentsRect() );
 
    plot()->updateLayout();
 
}
 

	
 
void ScrollZoomer::layoutScrollBars( const QRect &rect )
 
{
 
    qDebug() << "layoutScrollBars" << rect;
 

	
 
    int hPos = xAxis();
 
    if ( hScrollBarPosition() == OppositeToScale )
 
        hPos = oppositeAxis( hPos );
 

	
 
    int vPos = yAxis();
 
    if ( vScrollBarPosition() == OppositeToScale )
src/scrollzoomer.h
Show inline comments
 
@@ -42,19 +42,20 @@ public:
 
    void setHScrollBarPosition( ScrollBarPosition );
 
    void setVScrollBarPosition( ScrollBarPosition );
 

	
 
    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:
 
    virtual void moveTo( const QPointF & );
 

	
 
protected:
 
@@ -65,12 +66,13 @@ protected:
 
private Q_SLOTS:
 
    void scrollBarMoved( Qt::Orientation o, double min, double max );
 

	
 
private:
 
    QRectF d_limits;
 
    double xMin, xMax;
 
    double hViewSize;
 

	
 
    bool needScrollBar( Qt::Orientation ) const;
 
    int oppositeAxis( int ) const;
 

	
 
    QWidget *d_cornerWidget;
 

	
0 comments (0 inline, 0 general)