Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (3 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

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

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_interval.h"
    1414#include "qwt_plot_canvas.h"
     15
    1516#include <qevent.h>
    16 #include <qalgorithms.h>
    1717
    1818class QwtPlotRescaler::AxisData
    1919{
    20 public:
    21     AxisData():
    22         aspectRatio( 1.0 ),
    23         expandingDirection( QwtPlotRescaler::ExpandUp )
     20  public:
     21    AxisData()
     22        : aspectRatio( 1.0 )
     23        , expandingDirection( QwtPlotRescaler::ExpandUp )
    2424    {
    2525    }
    … …  
    3333class QwtPlotRescaler::PrivateData
    3434{
    35 public:
    36     PrivateData():
    37         referenceAxis( QwtPlot::xBottom ),
    38         rescalePolicy( QwtPlotRescaler::Expanding ),
    39         isEnabled( false ),
    40         inReplot( 0 )
    41     {
    42     }
    43 
    44     int referenceAxis;
     35  public:
     36    PrivateData()
     37        : referenceAxis( QwtAxis::XBottom )
     38        , rescalePolicy( QwtPlotRescaler::Expanding )
     39        , isEnabled( false )
     40        , inReplot( 0 )
     41    {
     42    }
     43
     44    QwtPlotRescaler::AxisData* axisData( QwtAxisId axisId )
     45    {
     46        if ( !QwtAxis::isValid( axisId ) )
     47            return NULL;
     48
     49        return &m_axisData[ axisId];
     50    }
     51
     52    QwtAxisId referenceAxis;
    4553    RescalePolicy rescalePolicy;
    46     QwtPlotRescaler::AxisData axisData[QwtPlot::axisCnt];
    4754    bool isEnabled;
    4855
    4956    mutable int inReplot;
     57
     58  private:
     59    QwtPlotRescaler::AxisData m_axisData[QwtAxis::AxisPositions];
    5060};
    5161
    … …  
    5868
    5969   \sa setRescalePolicy(), setReferenceAxis()
    60 */
    61 QwtPlotRescaler::QwtPlotRescaler( QWidget *canvas,
    62         int referenceAxis, RescalePolicy policy ):
    63     QObject( canvas )
    64 {
    65     d_data = new PrivateData;
    66     d_data->referenceAxis = referenceAxis;
    67     d_data->rescalePolicy = policy;
     70 */
     71QwtPlotRescaler::QwtPlotRescaler( QWidget* canvas,
     72        QwtAxisId referenceAxis, RescalePolicy policy )
     73    : QObject( canvas )
     74{
     75    m_data = new PrivateData;
     76    m_data->referenceAxis = referenceAxis;
     77    m_data->rescalePolicy = policy;
    6878
    6979    setEnabled( true );
    … …  
    7383QwtPlotRescaler::~QwtPlotRescaler()
    7484{
    75     delete d_data;
    76 }
    77 
    78 /*!
    79   \brief En/disable the rescaler
    80 
    81   When enabled is true an event filter is installed for
    82   the canvas, otherwise the event filter is removed.
    83 
    84   \param on true or false
    85   \sa isEnabled(), eventFilter()
    86 */
     85    delete m_data;
     86}
     87
     88/*!
     89   \brief En/disable the rescaler
     90
     91   When enabled is true an event filter is installed for
     92   the canvas, otherwise the event filter is removed.
     93
     94   \param on true or false
     95   \sa isEnabled(), eventFilter()
     96 */
    8797void QwtPlotRescaler::setEnabled( bool on )
    8898{
    89     if ( d_data->isEnabled != on )
    90     {
    91         d_data->isEnabled = on;
    92 
    93         QWidget *w = canvas();
     99    if ( m_data->isEnabled != on )
     100    {
     101        m_data->isEnabled = on;
     102
     103        QWidget* w = canvas();
    94104        if ( w )
    95105        {
    96             if ( d_data->isEnabled )
     106            if ( m_data->isEnabled )
    97107                w->installEventFilter( this );
    98108            else
    … …  
    103113
    104114/*!
    105   \return true when enabled, false otherwise
    106   \sa setEnabled, eventFilter()
    107 */
     115   \return true when enabled, false otherwise
     116   \sa setEnabled, eventFilter()
     117 */
    108118bool QwtPlotRescaler::isEnabled() const
    109119{
    110     return d_data->isEnabled;
    111 }
    112 
    113 /*!
    114   Change the rescale policy
    115 
    116   \param policy Rescale policy
    117   \sa rescalePolicy()
    118 */
     120    return m_data->isEnabled;
     121}
     122
     123/*!
     124   Change the rescale policy
     125
     126   \param policy Rescale policy
     127   \sa rescalePolicy()
     128 */
    119129void QwtPlotRescaler::setRescalePolicy( RescalePolicy policy )
    120130{
    121     d_data->rescalePolicy = policy;
    122 }
    123 
    124 /*!
    125   \return Rescale policy
    126   \sa setRescalePolicy()
    127 */
     131    m_data->rescalePolicy = policy;
     132}
     133
     134/*!
     135   \return Rescale policy
     136   \sa setRescalePolicy()
     137 */
    128138QwtPlotRescaler::RescalePolicy QwtPlotRescaler::rescalePolicy() const
    129139{
    130     return d_data->rescalePolicy;
    131 }
    132 
    133 /*!
    134   Set the reference axis ( see RescalePolicy )
    135 
    136   \param axis Axis index ( QwtPlot::Axis )
    137   \sa referenceAxis()
    138 */
    139 void QwtPlotRescaler::setReferenceAxis( int axis )
    140 {
    141     d_data->referenceAxis = axis;
    142 }
    143 
    144 /*!
    145   \return Reference axis ( see RescalePolicy )
    146   \sa setReferenceAxis()
    147 */
    148 int QwtPlotRescaler::referenceAxis() const
    149 {
    150     return d_data->referenceAxis;
    151 }
    152 
    153 /*!
    154   Set the direction in which all axis should be expanded
    155 
    156   \param direction Direction
    157   \sa expandingDirection()
    158 */
     140    return m_data->rescalePolicy;
     141}
     142
     143/*!
     144   Set the reference axis ( see RescalePolicy )
     145
     146   \param axisId Axis
     147   \sa referenceAxis()
     148 */
     149void QwtPlotRescaler::setReferenceAxis( QwtAxisId axisId )
     150{
     151    m_data->referenceAxis = axisId;
     152}
     153
     154/*!
     155   \return Reference axis ( see RescalePolicy )
     156   \sa setReferenceAxis()
     157 */
     158QwtAxisId QwtPlotRescaler::referenceAxis() const
     159{
     160    return m_data->referenceAxis;
     161}
     162
     163/*!
     164   Set the direction in which all axis should be expanded
     165
     166   \param direction Direction
     167   \sa expandingDirection()
     168 */
    159169void QwtPlotRescaler::setExpandingDirection(
    160170    ExpandingDirection direction )
    161171{
    162     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
     172    for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
    163173        setExpandingDirection( axis, direction );
    164174}
    165175
    166176/*!
    167   Set the direction in which an axis should be expanded
    168 
    169   \param axis Axis index ( see QwtPlot::AxisId )
    170   \param direction Direction
    171   \sa expandingDirection()
    172 */
     177   Set the direction in which an axis should be expanded
     178
     179   \param axisId Axis
     180   \param direction Direction
     181   \sa expandingDirection()
     182 */
    173183void QwtPlotRescaler::setExpandingDirection(
    174     int axis, ExpandingDirection direction )
    175 {
    176     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    177         d_data->axisData[axis].expandingDirection = direction;
    178 }
    179 
    180 /*!
    181   \return Direction in which an axis should be expanded
    182 
    183   \param axis Axis index ( see QwtPlot::AxisId )
    184   \sa setExpandingDirection()
    185 */
     184    QwtAxisId axisId, ExpandingDirection direction )
     185{
     186    if ( AxisData* axisData = m_data->axisData( axisId ) )
     187        axisData->expandingDirection = direction;
     188}
     189
     190/*!
     191   \return Direction in which an axis should be expanded
     192
     193   \param axisId Axis
     194   \sa setExpandingDirection()
     195 */
    186196QwtPlotRescaler::ExpandingDirection
    187 QwtPlotRescaler::expandingDirection( int axis ) const
    188 {
    189     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    190         return d_data->axisData[axis].expandingDirection;
     197QwtPlotRescaler::expandingDirection( QwtAxisId axisId ) const
     198{
     199    if ( const AxisData* axisData = m_data->axisData( axisId ) )
     200        return axisData->expandingDirection;
    191201
    192202    return ExpandBoth;
    … …  
    194204
    195205/*!
    196   Set the aspect ratio between the scale of the reference axis
    197   and the other scales. The default ratio is 1.0
    198 
    199   \param ratio Aspect ratio
    200   \sa aspectRatio()
    201 */
     206   Set the aspect ratio between the scale of the reference axis
     207   and the other scales. The default ratio is 1.0
     208
     209   \param ratio Aspect ratio
     210   \sa aspectRatio()
     211 */
    202212void QwtPlotRescaler::setAspectRatio( double ratio )
    203213{
    204     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
     214    for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
    205215        setAspectRatio( axis, ratio );
    206216}
    207217
    208218/*!
    209   Set the aspect ratio between the scale of the reference axis
    210   and another scale. The default ratio is 1.0
    211 
    212   \param axis Axis index ( see QwtPlot::AxisId )
    213   \param ratio Aspect ratio
    214   \sa aspectRatio()
    215 */
    216 void QwtPlotRescaler::setAspectRatio( int axis, double ratio )
    217 {
    218     if ( ratio < 0.0 )
    219         ratio = 0.0;
    220 
    221     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    222         d_data->axisData[axis].aspectRatio = ratio;
    223 }
    224 
    225 /*!
    226   \return Aspect ratio between an axis and the reference axis.
    227 
    228   \param axis Axis index ( see QwtPlot::AxisId )
    229   \sa setAspectRatio()
    230 */
    231 double QwtPlotRescaler::aspectRatio( int axis ) const
    232 {
    233     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    234         return d_data->axisData[axis].aspectRatio;
     219   Set the aspect ratio between the scale of the reference axis
     220   and another scale. The default ratio is 1.0
     221
     222   \param axisId Axis
     223   \param ratio Aspect ratio
     224   \sa aspectRatio()
     225 */
     226void QwtPlotRescaler::setAspectRatio( QwtAxisId axisId, double ratio )
     227{
     228    if ( AxisData* axisData = m_data->axisData( axisId ) )
     229    {
     230        if ( ratio < 0.0 )
     231            ratio = 0.0;
     232
     233        axisData->aspectRatio = ratio;
     234    }
     235}
     236
     237/*!
     238   \return Aspect ratio between an axis and the reference axis.
     239
     240   \param axisId Axis
     241   \sa setAspectRatio()
     242 */
     243double QwtPlotRescaler::aspectRatio( QwtAxisId axisId ) const
     244{
     245    if ( AxisData* axisData = m_data->axisData( axisId ) )
     246        return axisData->aspectRatio;
    235247
    236248    return 0.0;
    … …  
    238250
    239251/*!
    240   Set an interval hint for an axis
    241 
    242   In Fitting mode, the hint is used as minimal interval
    243   that always needs to be displayed.
    244 
    245   \param axis Axis, see QwtPlot::Axis
    246   \param interval Axis
    247   \sa intervalHint(), RescalePolicy
    248 */
    249 void QwtPlotRescaler::setIntervalHint( int axis,
    250     const QwtInterval &interval )
    251 {
    252     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    253         d_data->axisData[axis].intervalHint = interval;
    254 }
    255 
    256 /*!
    257   \param axis Axis, see QwtPlot::Axis
    258   \return Interval hint
    259   \sa setIntervalHint(), RescalePolicy
    260 */
    261 QwtInterval QwtPlotRescaler::intervalHint( int axis ) const
    262 {
    263     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    264         return d_data->axisData[axis].intervalHint;
     252   Set an interval hint for an axis
     253
     254   In Fitting mode, the hint is used as minimal interval
     255   that always needs to be displayed.
     256
     257   \param axisId Axis
     258   \param interval Axis
     259   \sa intervalHint(), RescalePolicy
     260 */
     261void QwtPlotRescaler::setIntervalHint( QwtAxisId axisId,
     262    const QwtInterval& interval )
     263{
     264    if ( AxisData* axisData = m_data->axisData( axisId ) )
     265        axisData->intervalHint = interval;
     266}
     267
     268/*!
     269   \param axisId Axis
     270   \return Interval hint
     271   \sa setIntervalHint(), RescalePolicy
     272 */
     273QwtInterval QwtPlotRescaler::intervalHint( QwtAxisId axisId ) const
     274{
     275    if ( AxisData* axisData = m_data->axisData( axisId ) )
     276        return axisData->intervalHint;
    265277
    266278    return QwtInterval();
    … …  
    268280
    269281//! \return plot canvas
    270 QWidget *QwtPlotRescaler::canvas()
    271 {
    272     return qobject_cast<QWidget *>( parent() );
     282QWidget* QwtPlotRescaler::canvas()
     283{
     284    return qobject_cast< QWidget* >( parent() );
    273285}
    274286
    275287//! \return plot canvas
    276 const QWidget *QwtPlotRescaler::canvas() const
    277 {
    278     return qobject_cast<const QWidget *>( parent() );
     288const QWidget* QwtPlotRescaler::canvas() const
     289{
     290    return qobject_cast< const QWidget* >( parent() );
    279291}
    280292
    281293//! \return plot widget
    282 QwtPlot *QwtPlotRescaler::plot()
    283 {
    284     QWidget *w = canvas();
     294QwtPlot* QwtPlotRescaler::plot()
     295{
     296    QWidget* w = canvas();
    285297    if ( w )
    286298        w = w->parentWidget();
    287299
    288     return qobject_cast<QwtPlot *>( w );
     300    return qobject_cast< QwtPlot* >( w );
    289301}
    290302
    291303//! \return plot widget
    292 const QwtPlot *QwtPlotRescaler::plot() const
    293 {
    294     const QWidget *w = canvas();
     304const QwtPlot* QwtPlotRescaler::plot() const
     305{
     306    const QWidget* w = canvas();
    295307    if ( w )
    296308        w = w->parentWidget();
    297309
    298     return qobject_cast<const QwtPlot *>( w );
     310    return qobject_cast< const QwtPlot* >( w );
    299311}
    300312
    301313//!  Event filter for the plot canvas
    302 bool QwtPlotRescaler::eventFilter( QObject *object, QEvent *event )
     314bool QwtPlotRescaler::eventFilter( QObject* object, QEvent* event )
    303315{
    304316    if ( object && object == canvas() )
    … …  
    308320            case QEvent::Resize:
    309321            {
    310                 canvasResizeEvent( static_cast<QResizeEvent *>( event ) );
     322                canvasResizeEvent( static_cast< QResizeEvent* >( event ) );
    311323                break;
    312324            }
    … …  
    324336
    325337/*!
    326   Event handler for resize events of the plot canvas
    327 
    328   \param event Resize event
    329   \sa rescale()
    330 */
     338   Event handler for resize events of the plot canvas
     339
     340   \param event Resize event
     341   \sa rescale()
     342 */
    331343void QwtPlotRescaler::canvasResizeEvent( QResizeEvent* event )
    332344{
    333     int left, top, right, bottom;
    334     canvas()->getContentsMargins( &left, &top, &right, &bottom );
    335 
    336     const QSize marginSize( left + right, top + bottom );
     345    const QMargins m = canvas()->contentsMargins();
     346    const QSize marginSize( m.left() + m.right(), m.top() + m.bottom() );
    337347
    338348    const QSize newSize = event->size() - marginSize;
    … …  
    354364   \param oldSize Previous size of the canvas
    355365   \param newSize New size of the canvas
    356 */
     366 */
    357367void QwtPlotRescaler::rescale(
    358     const QSize &oldSize, const QSize &newSize ) const
     368    const QSize& oldSize, const QSize& newSize ) const
    359369{
    360370    if ( newSize.isEmpty() )
    361371        return;
    362372
    363     QwtInterval intervals[QwtPlot::axisCnt];
    364     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    365         intervals[axis] = interval( axis );
    366 
    367     const int refAxis = referenceAxis();
     373    QwtInterval intervals[QwtAxis::AxisPositions];
     374    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     375    {
     376        const QwtAxisId axisId( axisPos );
     377        intervals[axisPos] = interval( axisId );
     378    }
     379
     380    const QwtAxisId refAxis = referenceAxis();
    368381    intervals[refAxis] = expandScale( refAxis, oldSize, newSize );
    369382
    370     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    371     {
    372         if ( aspectRatio( axis ) > 0.0 && axis != refAxis )
    373             intervals[axis] = syncScale( axis, intervals[refAxis], newSize );
     383    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     384    {
     385        const QwtAxisId axisId( axisPos );
     386        if ( aspectRatio( axisId ) > 0.0 && axisId != refAxis )
     387        {
     388            intervals[axisPos] = syncScale(
     389                axisId, intervals[refAxis], newSize );
     390        }
    374391    }
    375392
    … …  
    378395
    379396/*!
    380   Calculate the new scale interval of a plot axis
    381 
    382   \param axis Axis index ( see QwtPlot::AxisId )
    383   \param oldSize Previous size of the canvas
    384   \param newSize New size of the canvas
    385 
    386   \return Calculated new interval for the axis
    387 */
    388 QwtInterval QwtPlotRescaler::expandScale( int axis,
    389         const QSize &oldSize, const QSize &newSize ) const
    390 {
    391     const QwtInterval oldInterval = interval( axis );
     397   Calculate the new scale interval of a plot axis
     398
     399   \param axisId Axis
     400   \param oldSize Previous size of the canvas
     401   \param newSize New size of the canvas
     402
     403   \return Calculated new interval for the axis
     404 */
     405QwtInterval QwtPlotRescaler::expandScale( QwtAxisId axisId,
     406    const QSize& oldSize, const QSize& newSize ) const
     407{
     408    const QwtInterval oldInterval = interval( axisId );
    392409
    393410    QwtInterval expanded = oldInterval;
    … …  
    403420            {
    404421                double width = oldInterval.width();
    405                 if ( orientation( axis ) == Qt::Horizontal )
     422                if ( orientation( axisId ) == Qt::Horizontal )
    406423                    width *= double( newSize.width() ) / oldSize.width();
    407424                else
    … …  
    409426
    410427                expanded = expandInterval( oldInterval,
    411                     width, expandingDirection( axis ) );
     428                    width, expandingDirection( axisId ) );
    412429            }
    413430            break;
    … …  
    416433        {
    417434            double dist = 0.0;
    418             for ( int ax = 0; ax < QwtPlot::axisCnt; ax++ )
     435            for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
    419436            {
    420                 const double d = pixelDist( ax, newSize );
     437                const QwtAxisId axisId( axisPos );
     438                const double d = pixelDist( axisId, newSize );
    421439                if ( d > dist )
    422440                    dist = d;
    … …  
    425443            {
    426444                double width;
    427                 if ( orientation( axis ) == Qt::Horizontal )
     445                if ( orientation( axisId ) == Qt::Horizontal )
    428446                    width = newSize.width() * dist;
    429447                else
    430448                    width = newSize.height() * dist;
    431449
    432                 expanded = expandInterval( intervalHint( axis ),
    433                     width, expandingDirection( axis ) );
     450                expanded = expandInterval( intervalHint( axisId ),
     451                    width, expandingDirection( axisId ) );
    434452            }
    435453            break;
    … …  
    441459
    442460/*!
    443   Synchronize an axis scale according to the scale of the reference axis
    444 
    445   \param axis Axis index ( see QwtPlot::AxisId )
    446   \param reference Interval of the reference axis
    447   \param size Size of the canvas
    448 
    449   \return New interval for axis
    450 */
    451 QwtInterval QwtPlotRescaler::syncScale( int axis,
    452     const QwtInterval& reference, const QSize &size ) const
     461   Synchronize an axis scale according to the scale of the reference axis
     462
     463   \param axisId Axis
     464   \param reference Interval of the reference axis
     465   \param size Size of the canvas
     466
     467   \return New interval for axis
     468 */
     469QwtInterval QwtPlotRescaler::syncScale( QwtAxisId axisId,
     470    const QwtInterval& reference, const QSize& size ) const
    453471{
    454472    double dist;
    … …  
    458476        dist = reference.width() / size.height();
    459477
    460     if ( orientation( axis ) == Qt::Horizontal )
     478    if ( orientation( axisId ) == Qt::Horizontal )
    461479        dist *= size.width();
    462480    else
    463481        dist *= size.height();
    464482
    465     dist /= aspectRatio( axis );
     483    dist /= aspectRatio( axisId );
    466484
    467485    QwtInterval intv;
    468486    if ( rescalePolicy() == Fitting )
    469         intv = intervalHint( axis );
     487        intv = intervalHint( axisId );
    470488    else
    471         intv = interval( axis );
    472 
    473     intv = expandInterval( intv, dist, expandingDirection( axis ) );
     489        intv = interval( axisId );
     490
     491    intv = expandInterval( intv, dist, expandingDirection( axisId ) );
    474492
    475493    return intv;
    … …  
    477495
    478496/*!
    479   \return Orientation of an axis
    480   \param axis Axis index ( see QwtPlot::AxisId )
    481 */
    482 Qt::Orientation QwtPlotRescaler::orientation( int axis ) const
    483 {
    484     if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
    485         return Qt::Vertical;
    486 
    487     return Qt::Horizontal;
    488 }
    489 
    490 /*!
    491   \param axis Axis index ( see QwtPlot::AxisId )
    492   \return Normalized interval of an axis
    493 */
    494 QwtInterval QwtPlotRescaler::interval( int axis ) const
    495 {
    496     if ( axis < 0 || axis >= QwtPlot::axisCnt )
     497   \return Orientation of an axis
     498   \param axisId Axis
     499 */
     500Qt::Orientation QwtPlotRescaler::orientation( QwtAxisId axisId ) const
     501{
     502    return QwtAxis::isYAxis( axisId ) ? Qt::Vertical : Qt::Horizontal;
     503}
     504
     505/*!
     506   \param axisId Axis
     507   \return Normalized interval of an axis
     508 */
     509QwtInterval QwtPlotRescaler::interval( QwtAxisId axisId ) const
     510{
     511    if ( !plot()->isAxisValid( axisId ) )
    497512        return QwtInterval();
    498513
    499     return plot()->axisScaleDiv( axis ).interval().normalized();
    500 }
    501 
    502 /*!
    503   Expand the interval
    504 
    505   \param interval Interval to be expanded
    506   \param width Distance to be added to the interval
    507   \param direction Direction of the expand operation
    508 
    509   \return Expanded interval
    510 */
     514    return plot()->axisScaleDiv( axisId ).interval().normalized();
     515}
     516
     517/*!
     518   Expand the interval
     519
     520   \param interval Interval to be expanded
     521   \param width Distance to be added to the interval
     522   \param direction Direction of the expand operation
     523
     524   \return Expanded interval
     525 */
    511526QwtInterval QwtPlotRescaler::expandInterval(
    512     const QwtInterval &interval, double width,
     527    const QwtInterval& interval, double width,
    513528    ExpandingDirection direction ) const
    514529{
    … …  
    536551}
    537552
    538 double QwtPlotRescaler::pixelDist( int axis, const QSize &size ) const
    539 {
    540     const QwtInterval intv = intervalHint( axis );
     553double QwtPlotRescaler::pixelDist( QwtAxisId axisId, const QSize& size ) const
     554{
     555    const QwtInterval intv = intervalHint( axisId );
    541556
    542557    double dist = 0.0;
    543558    if ( !intv.isNull() )
    544559    {
    545         if ( axis == referenceAxis() )
     560        if ( axisId == referenceAxis() )
     561        {
    546562            dist = intv.width();
     563        }
    547564        else
    548565        {
    549             const double r = aspectRatio( axis );
     566            const double r = aspectRatio( axisId );
    550567            if ( r > 0.0 )
    551568                dist = intv.width() * r;
    … …  
    555572    if ( dist > 0.0 )
    556573    {
    557         if ( orientation( axis ) == Qt::Horizontal )
     574        if ( orientation( axisId ) == Qt::Horizontal )
    558575            dist /= size.width();
    559576        else
    … …  
    568585
    569586   \param intervals Scale intervals
    570 */
     587 */
    571588void QwtPlotRescaler::updateScales(
    572     QwtInterval intervals[QwtPlot::axisCnt] ) const
    573 {
    574     if ( d_data->inReplot >= 5 )
     589    QwtInterval intervals[QwtAxis::AxisPositions] ) const
     590{
     591    if ( m_data->inReplot >= 5 )
    575592    {
    576593        return;
    577594    }
    578595
    579     QwtPlot *plt = const_cast<QwtPlot *>( plot() );
     596    QwtPlot* plt = const_cast< QwtPlot* >( plot() );
    580597
    581598    const bool doReplot = plt->autoReplot();
    582599    plt->setAutoReplot( false );
    583600
    584     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    585     {
    586         if ( axis == referenceAxis() || aspectRatio( axis ) > 0.0 )
    587         {
    588             double v1 = intervals[axis].minValue();
    589             double v2 = intervals[axis].maxValue();
    590 
    591             if ( !plt->axisScaleDiv( axis ).isIncreasing() )
    592                 qSwap( v1, v2 );
    593 
    594             if ( d_data->inReplot >= 1 )
    595                 d_data->axisData[axis].scaleDiv = plt->axisScaleDiv( axis );
    596 
    597             if ( d_data->inReplot >= 2 )
     601    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     602    {
     603        {
     604            const QwtAxisId axisId( axisPos );
     605
     606            if ( axisId == referenceAxis() || aspectRatio( axisId ) > 0.0 )
    598607            {
    599                 QList<double> ticks[QwtScaleDiv::NTickTypes];
    600                 for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
    601                     ticks[i] = d_data->axisData[axis].scaleDiv.ticks( i );
    602 
    603                 plt->setAxisScaleDiv( axis, QwtScaleDiv( v1, v2, ticks ) );
     608                double v1 = intervals[axisPos].minValue();
     609                double v2 = intervals[axisPos].maxValue();
     610
     611                if ( !plt->axisScaleDiv( axisId ).isIncreasing() )
     612                    qSwap( v1, v2 );
     613
     614                if ( m_data->inReplot >= 1 )
     615                    m_data->axisData( axisId )->scaleDiv = plt->axisScaleDiv( axisId );
     616
     617                if ( m_data->inReplot >= 2 )
     618                {
     619                    QList< double > ticks[QwtScaleDiv::NTickTypes];
     620                    for ( int t = 0; t < QwtScaleDiv::NTickTypes; t++ )
     621                        ticks[t] = m_data->axisData( axisId )->scaleDiv.ticks( t );
     622
     623                    plt->setAxisScaleDiv( axisId, QwtScaleDiv( v1, v2, ticks ) );
     624                }
     625                else
     626                {
     627                    plt->setAxisScale( axisId, v1, v2 );
     628                }
    604629            }
    605             else
    606             {
    607                 plt->setAxisScale( axis, v1, v2 );
    608             }
    609         }
    610     }
    611 
    612     QwtPlotCanvas *canvas = qobject_cast<QwtPlotCanvas *>( plt->canvas() );
     630        }
     631    }
     632
     633    QwtPlotCanvas* canvas = qobject_cast< QwtPlotCanvas* >( plt->canvas() );
    613634
    614635    bool immediatePaint = false;
    … …  
    621642    plt->setAutoReplot( doReplot );
    622643
    623     d_data->inReplot++;
     644    m_data->inReplot++;
    624645    plt->replot();
    625     d_data->inReplot--;
     646    m_data->inReplot--;
    626647
    627648    if ( canvas && immediatePaint )
    … …  
    630651    }
    631652}
     653
     654#include "moc_qwt_plot_rescaler.cpp"
Note: See TracChangeset for help on using the changeset viewer.