Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_zoomer.cpp


Ignore:
Timestamp:
May 10, 2017, 3:20:54 PM (7 years ago)
Author:
stoecker
Message:

update qwt and qwtpolar, many QT5 fixes (unfinished)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_plot_zoomer.cpp

    r4271 r8127  
    1010#include "qwt_plot_zoomer.h"
    1111#include "qwt_plot.h"
    12 #include "qwt_plot_canvas.h"
    1312#include "qwt_scale_div.h"
    1413#include "qwt_picker_machine.h"
    1514#include <qalgorithms.h>
     15
     16static QwtInterval qwtExpandedZoomInterval( double v1, double v2,
     17    double minRange, const QwtTransform* transform )
     18{
     19    double min = v1;
     20    double max = v2;
     21
     22    if ( max - min < minRange )
     23    {
     24        min = 0.5 * ( min + max - minRange );
     25        max = min + minRange;
     26
     27        if ( transform )
     28        {
     29            // f.e the logarithmic scale doesn't allow values
     30            // outside [QwtLogTransform::LogMin/QwtLogTransform::LogMax]
     31
     32            double minBounded = transform->bounded( min );
     33            double maxBounded = transform->bounded( max );
     34
     35            if ( minBounded != min )
     36            {
     37                maxBounded = transform->bounded( minBounded + minRange );
     38            }
     39            else if ( maxBounded != max )
     40            {
     41                minBounded = transform->bounded( maxBounded - minRange );
     42            }
     43
     44            min = minBounded;
     45            max = maxBounded;
     46        }
     47    }
     48
     49    return QwtInterval( min, max );
     50}
     51
     52static QRectF qwtExpandedZoomRect( const QRectF &zoomRect, const QSizeF &minSize,
     53    const QwtTransform* transformX, const QwtTransform* transformY )
     54{
     55    QRectF r = zoomRect;
     56
     57    if ( minSize.width() > r.width() )
     58    {
     59        const QwtInterval intv = qwtExpandedZoomInterval(
     60            r.left(), r.right(), minSize.width(), transformX );
     61
     62        r.setLeft( intv.minValue() );
     63        r.setRight( intv.maxValue() );
     64    }
     65
     66    if ( minSize.height() > r.height() )
     67    {
     68        const QwtInterval intv = qwtExpandedZoomInterval(
     69            zoomRect.top(), zoomRect.bottom(), minSize.height(), transformY );
     70
     71        r.setTop( intv.minValue() );
     72        r.setBottom( intv.maxValue() );
     73    }
     74
     75    return r;
     76}
    1677
    1778class QwtPlotZoomer::PrivateData
     
    3394
    3495  The zoomer is initialized with a QwtPickerDragRectMachine,
    35   the tracker mode is set to QwtPicker::ActiveOnly and the rubberband
     96  the tracker mode is set to QwtPicker::ActiveOnly and the rubber band
    3697  is set to QwtPicker::RectRubberBand
    3798
    3899  \param canvas Plot canvas to observe, also the parent object
    39   \param doReplot Call replot for the attached plot before initializing
     100  \param doReplot Call QwtPlot::replot() for the attached plot before initializing
    40101                  the zoomer with its scales. This might be necessary,
    41102                  when the plot is in a state with pending scale changes.
     
    43104  \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase()
    44105*/
    45 QwtPlotZoomer::QwtPlotZoomer( QwtPlotCanvas *canvas, bool doReplot ):
     106QwtPlotZoomer::QwtPlotZoomer( QWidget *canvas, bool doReplot ):
    46107    QwtPlotPicker( canvas )
    47108{
     
    54115
    55116  The zoomer is initialized with a QwtPickerDragRectMachine,
    56   the tracker mode is set to QwtPicker::ActiveOnly and the rubberband
     117  the tracker mode is set to QwtPicker::ActiveOnly and the rubber band
    57118  is set to QwtPicker;;RectRubberBand
    58119
     
    60121  \param yAxis Y axis of the zoomer
    61122  \param canvas Plot canvas to observe, also the parent object
    62   \param doReplot Call replot for the attached plot before initializing
     123  \param doReplot Call QwtPlot::replot() for the attached plot before initializing
    63124                  the zoomer with its scales. This might be necessary,
    64125                  when the plot is in a state with pending scale changes.
     
    68129
    69130QwtPlotZoomer::QwtPlotZoomer( int xAxis, int yAxis,
    70         QwtPlotCanvas *canvas, bool doReplot ):
     131        QWidget *canvas, bool doReplot ):
    71132    QwtPlotPicker( xAxis, yAxis, canvas )
    72133{
     
    141202
    142203/*!
    143   Return the zoom stack. zoomStack()[0] is the zoom base,
    144   zoomStack()[1] the first zoomed rectangle.
     204  \return The zoom stack. zoomStack()[0] is the zoom base,
     205          zoomStack()[1] the first zoomed rectangle.
    145206
    146207  \sa setZoomStack(), zoomRectIndex()
     
    163224  Reinitialized the zoom stack with scaleRect() as base.
    164225
    165   \param doReplot Call replot for the attached plot before initializing
     226  \param doReplot Call QwtPlot::replot() for the attached plot before initializing
    166227                  the zoomer with its scales. This might be necessary,
    167228                  when the plot is in a state with pending scale changes.
     
    189250
    190251  base is united with the current scaleRect() and the zoom stack is
    191   reinitalized with it as zoom base. plot is zoomed to scaleRect().
     252  reinitialized with it as zoom base. plot is zoomed to scaleRect().
    192253
    193254  \param base Zoom base
     
    218279
    219280/*!
    220   Rectangle at the current position on the zoom stack.
    221 
     281  \return Rectangle at the current position on the zoom stack.
    222282  \sa zoomRectIndex(), scaleRect().
    223283*/
     
    239299
    240300  Clears all rectangles above the current position of the
    241   zoom stack and pushs the normalized rect on it.
     301  zoom stack and pushes the normalized rectangle on it.
    242302
    243303  \note If the maximal stack depth is reached, zoom is ignored.
     
    275335
    276336  Activate a rectangle on the zoom stack with an offset relative
    277   to the current position. Negative values of offest will zoom out,
     337  to the current position. Negative values of offset will zoom out,
    278338  positive zoom in. A value of 0 zooms out to the zoom base.
    279339
     
    344404  Adjust the observed plot to zoomRect()
    345405
    346   \note Initiates QwtPlot::replot
     406  \note Initiates QwtPlot::replot()
    347407*/
    348408
     
    361421        double x1 = rect.left();
    362422        double x2 = rect.right();
    363         if ( plt->axisScaleDiv( xAxis() )->lowerBound() >
    364             plt->axisScaleDiv( xAxis() )->upperBound() )
    365         {
     423        if ( !plt->axisScaleDiv( xAxis() ).isIncreasing() )
    366424            qSwap( x1, x2 );
    367         }
    368425
    369426        plt->setAxisScale( xAxis(), x1, x2 );
     
    371428        double y1 = rect.top();
    372429        double y2 = rect.bottom();
    373         if ( plt->axisScaleDiv( yAxis() )->lowerBound() >
    374             plt->axisScaleDiv( yAxis() )->upperBound() )
    375         {
     430        if ( !plt->axisScaleDiv( yAxis() ).isIncreasing() )
    376431            qSwap( y1, y2 );
    377         }
     432
    378433        plt->setAxisScale( yAxis(), y1, y2 );
    379434
     
    495550  \brief Check and correct a selected rectangle
    496551
    497   Reject rectangles with a hight or width < 2, otherwise
     552  Reject rectangles with a height or width < 2, otherwise
    498553  expand the selected rectangle to a minimum size of 11x11
    499554  and accept it.
    500555
    501   \return true If rect is accepted, or has been changed
    502           to a accepted rectangle.
     556  \return true If the rectangle is accepted, or has been changed
     557          to an accepted one.
    503558*/
    504559
     
    573628  if accepted.
    574629
     630  \param ok If true, complete the selection and emit selected signals
     631            otherwise discard the selection.
     632
    575633  \sa accept(), minZoomSize()
     634  \return True if the selection has been accepted, false otherwise
    576635*/
    577636bool QwtPlotZoomer::end( bool ok )
     
    592651    rect = rect.normalized();
    593652
    594     QRectF zoomRect = invTransform( rect ).normalized();
    595 
    596     const QSizeF minSize = minZoomSize();
    597     if ( minSize.isValid() )
    598     {
    599         const QPointF center = zoomRect.center();
    600         zoomRect.setSize( zoomRect.size().expandedTo( minZoomSize() ) );
    601         zoomRect.moveCenter( center );
    602     }
     653    const QwtScaleMap xMap = plot->canvasMap( xAxis() );
     654    const QwtScaleMap yMap = plot->canvasMap( yAxis() );
     655
     656    QRectF zoomRect = QwtScaleMap::invTransform( xMap, yMap, rect ).normalized();
     657
     658    zoomRect = qwtExpandedZoomRect( zoomRect, minZoomSize(),
     659        xMap.transformation(), yMap.transformation() );
    603660
    604661    zoom( zoomRect );
Note: See TracChangeset for help on using the changeset viewer.