Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_axis.cpp


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_axis.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_plot.h"
    11 #include "qwt_math.h"
    1211#include "qwt_scale_widget.h"
     12#include "qwt_scale_map.h"
    1313#include "qwt_scale_div.h"
    1414#include "qwt_scale_engine.h"
    15 
    16 class QwtPlot::AxisData
    17 {
    18 public:
    19     bool isEnabled;
    20     bool doAutoScale;
    21 
    22     double minValue;
    23     double maxValue;
    24     double stepSize;
    25 
    26     int maxMajor;
    27     int maxMinor;
    28 
    29     bool isValid;
    30 
    31     QwtScaleDiv scaleDiv;
    32     QwtScaleEngine *scaleEngine;
    33     QwtScaleWidget *scaleWidget;
     15#include "qwt_interval.h"
     16
     17namespace
     18{
     19    class AxisData
     20    {
     21      public:
     22        AxisData()
     23            : isVisible( true )
     24            , doAutoScale( true )
     25            , minValue( 0.0 )
     26            , maxValue( 1000.0 )
     27            , stepSize( 0.0 )
     28            , maxMajor( 8 )
     29            , maxMinor( 5 )
     30            , isValid( false )
     31            , scaleEngine( new QwtLinearScaleEngine() )
     32            , scaleWidget( NULL )
     33        {
     34        }
     35
     36        ~AxisData()
     37        {
     38            delete scaleEngine;
     39        }
     40
     41        void initWidget( QwtScaleDraw::Alignment align, const QString& name, QwtPlot* plot )
     42        {
     43            scaleWidget = new QwtScaleWidget( align, plot );
     44            scaleWidget->setObjectName( name );
     45
     46    #if 1
     47            // better find the font sizes from the application font
     48            const QFont fscl( plot->fontInfo().family(), 10 );
     49            const QFont fttl( plot->fontInfo().family(), 12, QFont::Bold );
     50    #endif
     51
     52            scaleWidget->setTransformation( scaleEngine->transformation() );
     53
     54            scaleWidget->setFont( fscl );
     55            scaleWidget->setMargin( 2 );
     56
     57            QwtText text = scaleWidget->title();
     58            text.setFont( fttl );
     59            scaleWidget->setTitle( text );
     60        }
     61
     62        bool isVisible;
     63        bool doAutoScale;
     64
     65        double minValue;
     66        double maxValue;
     67        double stepSize;
     68
     69        int maxMajor;
     70        int maxMinor;
     71
     72        bool isValid;
     73
     74        QwtScaleDiv scaleDiv;
     75        QwtScaleEngine* scaleEngine;
     76        QwtScaleWidget* scaleWidget;
     77    };
     78}
     79
     80class QwtPlot::ScaleData
     81{
     82  public:
     83    ScaleData( QwtPlot* plot )
     84    {
     85        using namespace QwtAxis;
     86
     87        m_axisData[YLeft].initWidget( QwtScaleDraw::LeftScale, "QwtPlotAxisYLeft", plot );
     88        m_axisData[YRight].initWidget( QwtScaleDraw::RightScale, "QwtPlotAxisYRight", plot );
     89        m_axisData[XTop].initWidget( QwtScaleDraw::TopScale, "QwtPlotAxisXTop", plot );
     90        m_axisData[XBottom].initWidget( QwtScaleDraw::BottomScale, "QwtPlotAxisXBottom", plot );
     91    }
     92
     93    inline AxisData& axisData( QwtAxisId axisId )
     94    {
     95        return m_axisData[ axisId ];
     96    }
     97
     98    inline const AxisData& axisData( QwtAxisId axisId ) const
     99    {
     100        return m_axisData[ axisId ];
     101    }
     102
     103  private:
     104    AxisData m_axisData[ QwtAxis::AxisPositions ];
    34105};
    35106
    36 //! Initialize axes
    37107void QwtPlot::initAxesData()
    38108{
    39     int axisId;
    40 
    41     for ( axisId = 0; axisId < axisCnt; axisId++ )
    42         d_axisData[axisId] = new AxisData;
    43 
    44     d_axisData[yLeft]->scaleWidget =
    45         new QwtScaleWidget( QwtScaleDraw::LeftScale, this );
    46     d_axisData[yRight]->scaleWidget =
    47         new QwtScaleWidget( QwtScaleDraw::RightScale, this );
    48     d_axisData[xTop]->scaleWidget =
    49         new QwtScaleWidget( QwtScaleDraw::TopScale, this );
    50     d_axisData[xBottom]->scaleWidget =
    51         new QwtScaleWidget( QwtScaleDraw::BottomScale, this );
    52 
    53     d_axisData[yLeft]->scaleWidget->setObjectName( "QwtPlotAxisYLeft" );
    54     d_axisData[yRight]->scaleWidget->setObjectName( "QwtPlotAxisYRight" );
    55     d_axisData[xTop]->scaleWidget->setObjectName( "QwtPlotAxisXTop" );
    56     d_axisData[xBottom]->scaleWidget->setObjectName( "QwtPlotAxisXBottom" );
    57 
    58 #if 1
    59     // better find the font sizes from the application font
    60     QFont fscl( fontInfo().family(), 10 );
    61     QFont fttl( fontInfo().family(), 12, QFont::Bold );
    62 #endif
    63 
    64     for ( axisId = 0; axisId < axisCnt; axisId++ )
    65     {
    66         AxisData &d = *d_axisData[axisId];
    67 
    68         d.scaleEngine = new QwtLinearScaleEngine;
    69 
    70         d.scaleWidget->setTransformation(
    71             d.scaleEngine->transformation() );
    72 
    73         d.scaleWidget->setFont( fscl );
    74         d.scaleWidget->setMargin( 2 );
    75 
    76         QwtText text = d.scaleWidget->title();
    77         text.setFont( fttl );
    78         d.scaleWidget->setTitle( text );
    79 
    80         d.doAutoScale = true;
    81 
    82         d.minValue = 0.0;
    83         d.maxValue = 1000.0;
    84         d.stepSize = 0.0;
    85 
    86         d.maxMinor = 5;
    87         d.maxMajor = 8;
    88 
    89 
    90         d.isValid = false;
    91     }
    92 
    93     d_axisData[yLeft]->isEnabled = true;
    94     d_axisData[yRight]->isEnabled = false;
    95     d_axisData[xBottom]->isEnabled = true;
    96     d_axisData[xTop]->isEnabled = false;
     109    m_scaleData = new ScaleData( this );
     110
     111    m_scaleData->axisData( QwtAxis::YRight ).isVisible = false;
     112    m_scaleData->axisData( QwtAxis::XTop ).isVisible = false;
    97113}
    98114
    99115void QwtPlot::deleteAxesData()
    100116{
    101     for ( int axisId = 0; axisId < axisCnt; axisId++ )
    102     {
    103         delete d_axisData[axisId]->scaleEngine;
    104         delete d_axisData[axisId];
    105         d_axisData[axisId] = NULL;
    106     }
    107 }
    108 
    109 /*!
    110   \return Scale widget of the specified axis, or NULL if axisId is invalid.
    111   \param axisId Axis index
    112 */
    113 const QwtScaleWidget *QwtPlot::axisWidget( int axisId ) const
    114 {
    115     if ( axisValid( axisId ) )
    116         return d_axisData[axisId]->scaleWidget;
     117    delete m_scaleData;
     118    m_scaleData = NULL;
     119}
     120
     121/*!
     122   Checks if an axis is valid
     123
     124   \param axisId axis
     125   \return \c true if the specified axis exists, otherwise \c false
     126
     127   \note This method is equivalent to QwtAxis::isValid( axisId ) and simply checks
     128         if axisId is one of the values of QwtAxis::Position. It is a placeholder
     129         for future releases, where it will be possible to have a customizable number
     130         of axes ( multiaxes branch ) at each side.
     131 */
     132bool QwtPlot::isAxisValid( QwtAxisId axisId ) const
     133{
     134    return QwtAxis::isValid( axisId );
     135}
     136
     137/*!
     138   \return Scale widget of the specified axis, or NULL if axisId is invalid.
     139   \param axisId Axis
     140 */
     141const QwtScaleWidget* QwtPlot::axisWidget( QwtAxisId axisId ) const
     142{
     143    if ( isAxisValid( axisId ) )
     144        return m_scaleData->axisData( axisId ).scaleWidget;
    117145
    118146    return NULL;
    … …  
    120148
    121149/*!
    122   \return Scale widget of the specified axis, or NULL if axisId is invalid.
    123   \param axisId Axis index
    124 */
    125 QwtScaleWidget *QwtPlot::axisWidget( int axisId )
    126 {
    127     if ( axisValid( axisId ) )
    128         return d_axisData[axisId]->scaleWidget;
     150   \return Scale widget of the specified axis, or NULL if axisId is invalid.
     151   \param axisId Axis
     152 */
     153QwtScaleWidget* QwtPlot::axisWidget( QwtAxisId axisId )
     154{
     155    if ( isAxisValid( axisId ) )
     156        return m_scaleData->axisData( axisId ).scaleWidget;
    129157
    130158    return NULL;
    … …  
    132160
    133161/*!
    134   Change the scale engine for an axis
    135 
    136   \param axisId Axis index
    137   \param scaleEngine Scale engine
    138 
    139   \sa axisScaleEngine()
    140 */
    141 void QwtPlot::setAxisScaleEngine( int axisId, QwtScaleEngine *scaleEngine )
    142 {
    143     if ( axisValid( axisId ) && scaleEngine != NULL )
    144     {
    145         AxisData &d = *d_axisData[axisId];
     162   Change the scale engine for an axis
     163
     164   \param axisId Axis
     165   \param scaleEngine Scale engine
     166
     167   \sa axisScaleEngine()
     168 */
     169void QwtPlot::setAxisScaleEngine( QwtAxisId axisId, QwtScaleEngine* scaleEngine )
     170{
     171    if ( isAxisValid( axisId ) && scaleEngine != NULL )
     172    {
     173        AxisData& d = m_scaleData->axisData( axisId );
    146174
    147175        delete d.scaleEngine;
    148176        d.scaleEngine = scaleEngine;
    149177
    150         d_axisData[axisId]->scaleWidget->setTransformation(
    151             scaleEngine->transformation() );
     178        d.scaleWidget->setTransformation( scaleEngine->transformation() );
    152179
    153180        d.isValid = false;
    … …  
    158185
    159186/*!
    160   \param axisId Axis index
    161   \return Scale engine for a specific axis
    162 */
    163 QwtScaleEngine *QwtPlot::axisScaleEngine( int axisId )
    164 {
    165     if ( axisValid( axisId ) )
    166         return d_axisData[axisId]->scaleEngine;
     187   \param axisId Axis
     188   \return Scale engine for a specific axis
     189 */
     190QwtScaleEngine* QwtPlot::axisScaleEngine( QwtAxisId axisId )
     191{
     192    if ( isAxisValid( axisId ) )
     193        return m_scaleData->axisData( axisId ).scaleEngine;
    167194    else
    168195        return NULL;
    … …  
    170197
    171198/*!
    172   \param axisId Axis index
    173   \return Scale engine for a specific axis
    174 */
    175 const QwtScaleEngine *QwtPlot::axisScaleEngine( int axisId ) const
    176 {
    177     if ( axisValid( axisId ) )
    178         return d_axisData[axisId]->scaleEngine;
     199   \param axisId Axis
     200   \return Scale engine for a specific axis
     201 */
     202const QwtScaleEngine* QwtPlot::axisScaleEngine( QwtAxisId axisId ) const
     203{
     204    if ( isAxisValid( axisId ) )
     205        return m_scaleData->axisData( axisId ).scaleEngine;
    179206    else
    180207        return NULL;
    181208}
    182209/*!
    183   \return \c True, if autoscaling is enabled
    184   \param axisId Axis index
    185 */
    186 bool QwtPlot::axisAutoScale( int axisId ) const
    187 {
    188     if ( axisValid( axisId ) )
    189         return d_axisData[axisId]->doAutoScale;
     210   \return \c True, if autoscaling is enabled
     211   \param axisId Axis
     212 */
     213bool QwtPlot::axisAutoScale( QwtAxisId axisId ) const
     214{
     215    if ( isAxisValid( axisId ) )
     216        return m_scaleData->axisData( axisId ).doAutoScale;
    190217    else
    191218        return false;
    … …  
    193220
    194221/*!
    195   \return \c True, if a specified axis is enabled
    196   \param axisId Axis index
    197 */
    198 bool QwtPlot::axisEnabled( int axisId ) const
    199 {
    200     if ( axisValid( axisId ) )
    201         return d_axisData[axisId]->isEnabled;
     222   \return \c True, if a specified axis is visible
     223   \param axisId Axis
     224 */
     225bool QwtPlot::isAxisVisible( QwtAxisId axisId ) const
     226{
     227    if ( isAxisValid( axisId ) )
     228        return m_scaleData->axisData( axisId ).isVisible;
    202229    else
    203230        return false;
    … …  
    205232
    206233/*!
    207   \return The font of the scale labels for a specified axis
    208   \param axisId Axis index
    209 */
    210 QFont QwtPlot::axisFont( int axisId ) const
    211 {
    212     if ( axisValid( axisId ) )
     234   \return The font of the scale labels for a specified axis
     235   \param axisId Axis
     236 */
     237QFont QwtPlot::axisFont( QwtAxisId axisId ) const
     238{
     239    if ( isAxisValid( axisId ) )
    213240        return axisWidget( axisId )->font();
    214241    else
    … …  
    218245
    219246/*!
    220   \return The maximum number of major ticks for a specified axis
    221   \param axisId Axis index
    222   \sa setAxisMaxMajor(), QwtScaleEngine::divideScale()
    223 */
    224 int QwtPlot::axisMaxMajor( int axisId ) const
    225 {
    226     if ( axisValid( axisId ) )
    227         return d_axisData[axisId]->maxMajor;
     247   \return The maximum number of major ticks for a specified axis
     248   \param axisId Axis
     249   \sa setAxisMaxMajor(), QwtScaleEngine::divideScale()
     250 */
     251int QwtPlot::axisMaxMajor( QwtAxisId axisId ) const
     252{
     253    if ( isAxisValid( axisId ) )
     254        return m_scaleData->axisData( axisId ).maxMajor;
    228255    else
    229256        return 0;
    … …  
    231258
    232259/*!
    233   \return the maximum number of minor ticks for a specified axis
    234   \param axisId Axis index
    235   \sa setAxisMaxMinor(), QwtScaleEngine::divideScale()
    236 */
    237 int QwtPlot::axisMaxMinor( int axisId ) const
    238 {
    239     if ( axisValid( axisId ) )
    240         return d_axisData[axisId]->maxMinor;
     260   \return the maximum number of minor ticks for a specified axis
     261   \param axisId Axis
     262   \sa setAxisMaxMinor(), QwtScaleEngine::divideScale()
     263 */
     264int QwtPlot::axisMaxMinor( QwtAxisId axisId ) const
     265{
     266    if ( isAxisValid( axisId ) )
     267        return m_scaleData->axisData( axisId ).maxMinor;
    241268    else
    242269        return 0;
    … …  
    244271
    245272/*!
    246   \brief Return the scale division of a specified axis
    247 
    248   axisScaleDiv(axisId).lowerBound(), axisScaleDiv(axisId).upperBound()
    249   are the current limits of the axis scale.
    250 
    251   \param axisId Axis index
    252   \return Scale division
    253 
    254   \sa QwtScaleDiv, setAxisScaleDiv(), QwtScaleEngine::divideScale()
    255 */
    256 const QwtScaleDiv &QwtPlot::axisScaleDiv( int axisId ) const
    257 {
    258     return d_axisData[axisId]->scaleDiv;
    259 }
    260 
    261 /*!
    262   \brief Return the scale draw of a specified axis
    263 
    264   \param axisId Axis index
    265   \return Specified scaleDraw for axis, or NULL if axis is invalid.
    266 */
    267 const QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) const
    268 {
    269     if ( !axisValid( axisId ) )
     273   \brief Return the scale division of a specified axis
     274
     275   axisScaleDiv(axisId).lowerBound(), axisScaleDiv(axisId).upperBound()
     276   are the current limits of the axis scale.
     277
     278   \param axisId Axis
     279   \return Scale division
     280
     281   \sa QwtScaleDiv, setAxisScaleDiv(), QwtScaleEngine::divideScale()
     282 */
     283const QwtScaleDiv& QwtPlot::axisScaleDiv( QwtAxisId axisId ) const
     284{
     285    if ( isAxisValid( axisId ) )
     286        return m_scaleData->axisData( axisId ).scaleDiv;
     287
     288    static QwtScaleDiv dummyScaleDiv;
     289    return dummyScaleDiv;
     290}
     291
     292/*!
     293   \brief Return the scale draw of a specified axis
     294
     295   \param axisId Axis
     296   \return Specified scaleDraw for axis, or NULL if axis is invalid.
     297 */
     298const QwtScaleDraw* QwtPlot::axisScaleDraw( QwtAxisId axisId ) const
     299{
     300    if ( !isAxisValid( axisId ) )
    270301        return NULL;
    271302
    … …  
    274305
    275306/*!
    276   \brief Return the scale draw of a specified axis
    277 
    278   \param axisId Axis index
    279   \return Specified scaleDraw for axis, or NULL if axis is invalid.
    280 */
    281 QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId )
    282 {
    283     if ( !axisValid( axisId ) )
     307   \brief Return the scale draw of a specified axis
     308
     309   \param axisId Axis
     310   \return Specified scaleDraw for axis, or NULL if axis is invalid.
     311 */
     312QwtScaleDraw* QwtPlot::axisScaleDraw( QwtAxisId axisId )
     313{
     314    if ( !isAxisValid( axisId ) )
    284315        return NULL;
    285316
    … …  
    288319
    289320/*!
    290   \brief Return the step size parameter that has been set in setAxisScale.
    291 
    292   This doesn't need to be the step size of the current scale.
    293 
    294   \param axisId Axis index
    295   \return step size parameter value
     321   \brief Return the step size parameter that has been set in setAxisScale.
     322
     323   This doesn't need to be the step size of the current scale.
     324
     325   \param axisId Axis
     326   \return step size parameter value
    296327
    297328   \sa setAxisScale(), QwtScaleEngine::divideScale()
    298 */
    299 double QwtPlot::axisStepSize( int axisId ) const
    300 {
    301     if ( !axisValid( axisId ) )
     329 */
     330double QwtPlot::axisStepSize( QwtAxisId axisId ) const
     331{
     332    if ( !isAxisValid( axisId ) )
    302333        return 0;
    303334
    304     return d_axisData[axisId]->stepSize;
    305 }
    306 
    307 /*!
    308   \brief Return the current interval of the specified axis
    309 
    310   This is only a convenience function for axisScaleDiv( axisId )->interval();
    311 
    312   \param axisId Axis index
    313   \return Scale interval
    314 
    315   \sa QwtScaleDiv, axisScaleDiv()
    316 */
    317 QwtInterval QwtPlot::axisInterval( int axisId ) const
    318 {
    319     if ( !axisValid( axisId ) )
     335    return m_scaleData->axisData( axisId ).stepSize;
     336}
     337
     338/*!
     339   \brief Return the current interval of the specified axis
     340
     341   This is only a convenience function for axisScaleDiv( axisId )->interval();
     342
     343   \param axisId Axis
     344   \return Scale interval
     345
     346   \sa QwtScaleDiv, axisScaleDiv()
     347 */
     348QwtInterval QwtPlot::axisInterval( QwtAxisId axisId ) const
     349{
     350    if ( !isAxisValid( axisId ) )
    320351        return QwtInterval();
    321352
    322     return d_axisData[axisId]->scaleDiv.interval();
    323 }
    324 
    325 /*!
    326   \return Title of a specified axis
    327   \param axisId Axis index
    328 */
    329 QwtText QwtPlot::axisTitle( int axisId ) const
    330 {
    331     if ( axisValid( axisId ) )
     353    return m_scaleData->axisData( axisId ).scaleDiv.interval();
     354}
     355
     356/*!
     357   \return Title of a specified axis
     358   \param axisId Axis
     359 */
     360QwtText QwtPlot::axisTitle( QwtAxisId axisId ) const
     361{
     362    if ( isAxisValid( axisId ) )
    332363        return axisWidget( axisId )->title();
    333364    else
    … …  
    336367
    337368/*!
    338   \brief Enable or disable a specified axis
    339 
    340   When an axis is disabled, this only means that it is not
    341   visible on the screen. Curves, markers and can be attached
    342   to disabled axes, and transformation of screen coordinates
    343   into values works as normal.
    344 
    345   Only xBottom and yLeft are enabled by default.
    346 
    347   \param axisId Axis index
    348   \param tf \c true (enabled) or \c false (disabled)
    349 */
    350 void QwtPlot::enableAxis( int axisId, bool tf )
    351 {
    352     if ( axisValid( axisId ) && tf != d_axisData[axisId]->isEnabled )
    353     {
    354         d_axisData[axisId]->isEnabled = tf;
     369   \brief Hide or show a specified axis
     370
     371   Curves, markers and other items can be attached
     372   to hidden axes, and transformation of screen coordinates
     373   into values works as normal.
     374
     375   Only QwtAxis::XBottom and QwtAxis::YLeft are enabled by default.
     376
     377   \param axisId Axis
     378   \param on \c true (visible) or \c false (hidden)
     379 */
     380void QwtPlot::setAxisVisible( QwtAxisId axisId, bool on )
     381{
     382    if ( isAxisValid( axisId ) && on != m_scaleData->axisData( axisId ).isVisible )
     383    {
     384        m_scaleData->axisData( axisId ).isVisible = on;
    355385        updateLayout();
    356386    }
    … …  
    358388
    359389/*!
    360   Transform the x or y coordinate of a position in the
    361   drawing region into a value.
    362 
    363   \param axisId Axis index
    364   \param pos position
    365 
    366   \return Position as axis coordinate
    367 
    368   \warning The position can be an x or a y coordinate,
     390   Transform the x or y coordinate of a position in the
     391   drawing region into a value.
     392
     393   \param axisId Axis
     394   \param pos position
     395
     396   \return Position as axis coordinate
     397
     398   \warning The position can be an x or a y coordinate,
    369399           depending on the specified axis.
    370 */
    371 double QwtPlot::invTransform( int axisId, int pos ) const
    372 {
    373     if ( axisValid( axisId ) )
     400 */
     401double QwtPlot::invTransform( QwtAxisId axisId, double pos ) const
     402{
     403    if ( isAxisValid( axisId ) )
    374404        return( canvasMap( axisId ).invTransform( pos ) );
    375405    else
    … …  
    379409
    380410/*!
    381   \brief Transform a value into a coordinate in the plotting region
    382 
    383   \param axisId Axis index
    384   \param value value
    385   \return X or Y coordinate in the plotting region corresponding
     411   \brief Transform a value into a coordinate in the plotting region
     412
     413   \param axisId Axis
     414   \param value value
     415   \return X or Y coordinate in the plotting region corresponding
    386416          to the value.
    387 */
    388 double QwtPlot::transform( int axisId, double value ) const
    389 {
    390     if ( axisValid( axisId ) )
     417 */
     418double QwtPlot::transform( QwtAxisId axisId, double value ) const
     419{
     420    if ( isAxisValid( axisId ) )
    391421        return( canvasMap( axisId ).transform( value ) );
    392422    else
    … …  
    395425
    396426/*!
    397   \brief Change the font of an axis
    398 
    399   \param axisId Axis index
    400   \param font Font
    401   \warning This function changes the font of the tick labels,
     427   \brief Change the font of an axis
     428
     429   \param axisId Axis
     430   \param font Font
     431   \warning This function changes the font of the tick labels,
    402432           not of the axis title.
    403 */
    404 void QwtPlot::setAxisFont( int axisId, const QFont &font )
    405 {
    406     if ( axisValid( axisId ) )
     433 */
     434void QwtPlot::setAxisFont( QwtAxisId axisId, const QFont& font )
     435{
     436    if ( isAxisValid( axisId ) )
    407437        axisWidget( axisId )->setFont( font );
    408438}
    409439
    410440/*!
    411   \brief Enable autoscaling for a specified axis
    412 
    413   This member function is used to switch back to autoscaling mode
    414   after a fixed scale has been set. Autoscaling is enabled by default.
    415 
    416   \param axisId Axis index
    417   \param on On/Off
    418   \sa setAxisScale(), setAxisScaleDiv(), updateAxes()
    419 
    420   \note The autoscaling flag has no effect until updateAxes() is executed
     441   \brief Enable autoscaling for a specified axis
     442
     443   This member function is used to switch back to autoscaling mode
     444   after a fixed scale has been set. Autoscaling is enabled by default.
     445
     446   \param axisId Axis
     447   \param on On/Off
     448   \sa setAxisScale(), setAxisScaleDiv(), updateAxes()
     449
     450   \note The autoscaling flag has no effect until updateAxes() is executed
    421451        ( called by replot() ).
    422 */
    423 void QwtPlot::setAxisAutoScale( int axisId, bool on )
    424 {
    425     if ( axisValid( axisId ) && ( d_axisData[axisId]->doAutoScale != on ) )
    426     {
    427         d_axisData[axisId]->doAutoScale = on;
     452 */
     453void QwtPlot::setAxisAutoScale( QwtAxisId axisId, bool on )
     454{
     455    if ( isAxisValid( axisId ) && ( m_scaleData->axisData( axisId ).doAutoScale != on ) )
     456    {
     457        m_scaleData->axisData( axisId ).doAutoScale = on;
    428458        autoRefresh();
    429459    }
    … …  
    431461
    432462/*!
    433   \brief Disable autoscaling and specify a fixed scale for a selected axis.
    434 
    435   In updateAxes() the scale engine calculates a scale division from the
    436   specified parameters, that will be assigned to the scale widget. So
    437   updates of the scale widget usually happen delayed with the next replot.
    438 
    439   \param axisId Axis index
    440   \param min Minimum of the scale
    441   \param max Maximum of the scale
    442   \param stepSize Major step size. If <code>step == 0</code>, the step size is
     463   \brief Disable autoscaling and specify a fixed scale for a selected axis.
     464
     465   In updateAxes() the scale engine calculates a scale division from the
     466   specified parameters, that will be assigned to the scale widget. So
     467   updates of the scale widget usually happen delayed with the next replot.
     468
     469   \param axisId Axis
     470   \param min Minimum of the scale
     471   \param max Maximum of the scale
     472   \param stepSize Major step size. If <code>step == 0</code>, the step size is
    443473                  calculated automatically using the maxMajor setting.
    444474
    445   \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize(), QwtScaleEngine::divideScale()
    446 */
    447 void QwtPlot::setAxisScale( int axisId, double min, double max, double stepSize )
    448 {
    449     if ( axisValid( axisId ) )
    450     {
    451         AxisData &d = *d_axisData[axisId];
     475   \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize(), QwtScaleEngine::divideScale()
     476 */
     477void QwtPlot::setAxisScale( QwtAxisId axisId, double min, double max, double stepSize )
     478{
     479    if ( isAxisValid( axisId ) )
     480    {
     481        AxisData& d = m_scaleData->axisData( axisId );
    452482
    453483        d.doAutoScale = false;
    … …  
    463493
    464494/*!
    465   \brief Disable autoscaling and specify a fixed scale for a selected axis.
    466 
    467   The scale division will be stored locally only until the next call
    468   of updateAxes(). So updates of the scale widget usually happen delayed with
    469   the next replot.
    470 
    471   \param axisId Axis index
    472   \param scaleDiv Scale division
    473 
    474   \sa setAxisScale(), setAxisAutoScale()
    475 */
    476 void QwtPlot::setAxisScaleDiv( int axisId, const QwtScaleDiv &scaleDiv )
    477 {
    478     if ( axisValid( axisId ) )
    479     {
    480         AxisData &d = *d_axisData[axisId];
     495   \brief Disable autoscaling and specify a fixed scale for a selected axis.
     496
     497   The scale division will be stored locally only until the next call
     498   of updateAxes(). So updates of the scale widget usually happen delayed with
     499   the next replot.
     500
     501   \param axisId Axis
     502   \param scaleDiv Scale division
     503
     504   \sa setAxisScale(), setAxisAutoScale()
     505 */
     506void QwtPlot::setAxisScaleDiv( QwtAxisId axisId, const QwtScaleDiv& scaleDiv )
     507{
     508    if ( isAxisValid( axisId ) )
     509    {
     510        AxisData& d = m_scaleData->axisData( axisId );
    481511
    482512        d.doAutoScale = false;
    … …  
    489519
    490520/*!
    491   \brief Set a scale draw
    492 
    493   \param axisId Axis index
    494   \param scaleDraw Object responsible for drawing scales.
    495 
    496   By passing scaleDraw it is possible to extend QwtScaleDraw
    497   functionality and let it take place in QwtPlot. Please note
    498   that scaleDraw has to be created with new and will be deleted
    499   by the corresponding QwtScale member ( like a child object ).
    500 
    501   \sa QwtScaleDraw, QwtScaleWidget
    502   \warning The attributes of scaleDraw will be overwritten by those of the
     521   \brief Set a scale draw
     522
     523   \param axisId Axis
     524   \param scaleDraw Object responsible for drawing scales.
     525
     526   By passing scaleDraw it is possible to extend QwtScaleDraw
     527   functionality and let it take place in QwtPlot. Please note
     528   that scaleDraw has to be created with new and will be deleted
     529   by the corresponding QwtScale member ( like a child object ).
     530
     531   \sa QwtScaleDraw, QwtScaleWidget
     532   \warning The attributes of scaleDraw will be overwritten by those of the
    503533           previous QwtScaleDraw.
    504 */
    505 
    506 void QwtPlot::setAxisScaleDraw( int axisId, QwtScaleDraw *scaleDraw )
    507 {
    508     if ( axisValid( axisId ) )
     534 */
     535
     536void QwtPlot::setAxisScaleDraw( QwtAxisId axisId, QwtScaleDraw* scaleDraw )
     537{
     538    if ( isAxisValid( axisId ) )
    509539    {
    510540        axisWidget( axisId )->setScaleDraw( scaleDraw );
    … …  
    514544
    515545/*!
    516   Change the alignment of the tick labels
    517 
    518   \param axisId Axis index
    519   \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h>
    520 
    521   \sa QwtScaleDraw::setLabelAlignment()
    522 */
    523 void QwtPlot::setAxisLabelAlignment( int axisId, Qt::Alignment alignment )
    524 {
    525     if ( axisValid( axisId ) )
     546   Change the alignment of the tick labels
     547
     548   \param axisId Axis
     549   \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h>
     550
     551   \sa QwtScaleDraw::setLabelAlignment()
     552 */
     553void QwtPlot::setAxisLabelAlignment( QwtAxisId axisId, Qt::Alignment alignment )
     554{
     555    if ( isAxisValid( axisId ) )
    526556        axisWidget( axisId )->setLabelAlignment( alignment );
    527557}
    528558
    529559/*!
    530   Rotate all tick labels
    531 
    532   \param axisId Axis index
    533   \param rotation Angle in degrees. When changing the label rotation,
     560   Rotate all tick labels
     561
     562   \param axisId Axis
     563   \param rotation Angle in degrees. When changing the label rotation,
    534564                  the label alignment might be adjusted too.
    535565
    536   \sa QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment()
    537 */
    538 void QwtPlot::setAxisLabelRotation( int axisId, double rotation )
    539 {
    540     if ( axisValid( axisId ) )
     566   \sa QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment()
     567 */
     568void QwtPlot::setAxisLabelRotation( QwtAxisId axisId, double rotation )
     569{
     570    if ( isAxisValid( axisId ) )
    541571        axisWidget( axisId )->setLabelRotation( rotation );
    542572}
    543573
    544574/*!
    545   Set the maximum number of minor scale intervals for a specified axis
    546 
    547   \param axisId Axis index
    548   \param maxMinor Maximum number of minor steps
    549 
    550   \sa axisMaxMinor()
    551 */
    552 void QwtPlot::setAxisMaxMinor( int axisId, int maxMinor )
    553 {
    554     if ( axisValid( axisId ) )
     575   Set the maximum number of minor scale intervals for a specified axis
     576
     577   \param axisId Axis
     578   \param maxMinor Maximum number of minor steps
     579
     580   \sa axisMaxMinor()
     581 */
     582void QwtPlot::setAxisMaxMinor( QwtAxisId axisId, int maxMinor )
     583{
     584    if ( isAxisValid( axisId ) )
    555585    {
    556586        maxMinor = qBound( 0, maxMinor, 100 );
    557587
    558         AxisData &d = *d_axisData[axisId];
     588        AxisData& d = m_scaleData->axisData( axisId );
    559589        if ( maxMinor != d.maxMinor )
    560590        {
    … …  
    567597
    568598/*!
    569   Set the maximum number of major scale intervals for a specified axis
    570 
    571   \param axisId Axis index
    572   \param maxMajor Maximum number of major steps
    573 
    574   \sa axisMaxMajor()
    575 */
    576 void QwtPlot::setAxisMaxMajor( int axisId, int maxMajor )
    577 {
    578     if ( axisValid( axisId ) )
     599   Set the maximum number of major scale intervals for a specified axis
     600
     601   \param axisId Axis
     602   \param maxMajor Maximum number of major steps
     603
     604   \sa axisMaxMajor()
     605 */
     606void QwtPlot::setAxisMaxMajor( QwtAxisId axisId, int maxMajor )
     607{
     608    if ( isAxisValid( axisId ) )
    579609    {
    580610        maxMajor = qBound( 1, maxMajor, 10000 );
    581611
    582         AxisData &d = *d_axisData[axisId];
     612        AxisData& d = m_scaleData->axisData( axisId );
    583613        if ( maxMajor != d.maxMajor )
    584614        {
    … …  
    591621
    592622/*!
    593   \brief Change the title of a specified axis
    594 
    595   \param axisId Axis index
    596   \param title axis title
    597 */
    598 void QwtPlot::setAxisTitle( int axisId, const QString &title )
    599 {
    600     if ( axisValid( axisId ) )
     623   \brief Change the title of a specified axis
     624
     625   \param axisId Axis
     626   \param title axis title
     627 */
     628void QwtPlot::setAxisTitle( QwtAxisId axisId, const QString& title )
     629{
     630    if ( isAxisValid( axisId ) )
    601631        axisWidget( axisId )->setTitle( title );
    602632}
    603633
    604634/*!
    605   \brief Change the title of a specified axis
    606 
    607   \param axisId Axis index
    608   \param title Axis title
    609 */
    610 void QwtPlot::setAxisTitle( int axisId, const QwtText &title )
    611 {
    612     if ( axisValid( axisId ) )
     635   \brief Change the title of a specified axis
     636
     637   \param axisId Axis
     638   \param title Axis title
     639 */
     640void QwtPlot::setAxisTitle( QwtAxisId axisId, const QwtText& title )
     641{
     642    if ( isAxisValid( axisId ) )
    613643        axisWidget( axisId )->setTitle( title );
    614644}
    615645
    616646/*!
    617   \brief Rebuild the axes scales
    618 
    619   In case of autoscaling the boundaries of a scale are calculated
    620   from the bounding rectangles of all plot items, having the
    621   QwtPlotItem::AutoScale flag enabled ( QwtScaleEngine::autoScale() ).
    622   Then a scale division is calculated ( QwtScaleEngine::didvideScale() )
    623   and assigned to scale widget.
    624 
    625   When the scale boundaries have been assigned with setAxisScale() a
    626   scale division is calculated ( QwtScaleEngine::didvideScale() )
    627   for this interval and assigned to the scale widget.
    628 
    629   When the scale has been set explicitly by setAxisScaleDiv() the
    630   locally stored scale division gets assigned to the scale widget.
    631 
    632   The scale widget indicates modifications by emitting a
    633   QwtScaleWidget::scaleDivChanged() signal.
    634 
    635   updateAxes() is usually called by replot().
    636 
    637   \sa setAxisAutoScale(), setAxisScale(), setAxisScaleDiv(), replot()
     647   \brief Rebuild the axes scales
     648
     649   In case of autoscaling the boundaries of a scale are calculated
     650   from the bounding rectangles of all plot items, having the
     651   QwtPlotItem::AutoScale flag enabled ( QwtScaleEngine::autoScale() ).
     652   Then a scale division is calculated ( QwtScaleEngine::didvideScale() )
     653   and assigned to scale widget.
     654
     655   When the scale boundaries have been assigned with setAxisScale() a
     656   scale division is calculated ( QwtScaleEngine::didvideScale() )
     657   for this interval and assigned to the scale widget.
     658
     659   When the scale has been set explicitly by setAxisScaleDiv() the
     660   locally stored scale division gets assigned to the scale widget.
     661
     662   The scale widget indicates modifications by emitting a
     663   QwtScaleWidget::scaleDivChanged() signal.
     664
     665   updateAxes() is usually called by replot().
     666
     667   \sa setAxisAutoScale(), setAxisScale(), setAxisScaleDiv(), replot()
    638668      QwtPlotItem::boundingRect()
    639669 */
    … …  
    643673    // for all axes, where autoscaling is enabled
    644674
    645     QwtInterval intv[axisCnt];
     675    QwtInterval boundingIntervals[QwtAxis::AxisPositions];
    646676
    647677    const QwtPlotItemList& itmList = itemList();
    … …  
    650680    for ( it = itmList.begin(); it != itmList.end(); ++it )
    651681    {
    652         const QwtPlotItem *item = *it;
     682        const QwtPlotItem* item = *it;
    653683
    654684        if ( !item->testItemAttribute( QwtPlotItem::AutoScale ) )
    … …  
    658688            continue;
    659689
    660         if ( axisAutoScale( item->xAxis() ) || axisAutoScale( item->yAxis() ) )
     690        const QwtAxisId xAxis = item->xAxis();
     691        const QwtAxisId yAxis = item->yAxis();
     692
     693        if ( axisAutoScale( xAxis ) || axisAutoScale( yAxis ) )
    661694        {
    662695            const QRectF rect = item->boundingRect();
    663696
    664             if ( rect.width() >= 0.0 )
    665                 intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() );
    666 
    667             if ( rect.height() >= 0.0 )
    668                 intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() );
     697            if ( axisAutoScale( xAxis ) && rect.width() >= 0.0 )
     698                boundingIntervals[xAxis] |= QwtInterval( rect.left(), rect.right() );
     699
     700            if ( axisAutoScale( yAxis ) && rect.height() >= 0.0 )
     701                boundingIntervals[yAxis] |= QwtInterval( rect.top(), rect.bottom() );
    669702        }
    670703    }
    … …  
    672705    // Adjust scales
    673706
    674     for ( int axisId = 0; axisId < axisCnt; axisId++ )
    675     {
    676         AxisData &d = *d_axisData[axisId];
    677 
    678         double minValue = d.minValue;
    679         double maxValue = d.maxValue;
    680         double stepSize = d.stepSize;
    681 
    682         if ( d.doAutoScale && intv[axisId].isValid() )
     707    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     708    {
    683709        {
    684             d.isValid = false;
    685 
    686             minValue = intv[axisId].minValue();
    687             maxValue = intv[axisId].maxValue();
    688 
    689             d.scaleEngine->autoScale( d.maxMajor,
    690                 minValue, maxValue, stepSize );
     710            const QwtAxisId axisId( axisPos );
     711
     712            AxisData& d = m_scaleData->axisData( axisId );
     713
     714            double minValue = d.minValue;
     715            double maxValue = d.maxValue;
     716            double stepSize = d.stepSize;
     717
     718            const QwtInterval& interval = boundingIntervals[axisId];
     719
     720            if ( d.doAutoScale && interval.isValid() )
     721            {
     722                d.isValid = false;
     723
     724                minValue = interval.minValue();
     725                maxValue = interval.maxValue();
     726
     727                d.scaleEngine->autoScale( d.maxMajor,
     728                    minValue, maxValue, stepSize );
     729            }
     730            if ( !d.isValid )
     731            {
     732                d.scaleDiv = d.scaleEngine->divideScale(
     733                    minValue, maxValue, d.maxMajor, d.maxMinor, stepSize );
     734                d.isValid = true;
     735            }
     736
     737            QwtScaleWidget* scaleWidget = axisWidget( axisId );
     738            scaleWidget->setScaleDiv( d.scaleDiv );
     739
     740            int startDist, endDist;
     741            scaleWidget->getBorderDistHint( startDist, endDist );
     742            scaleWidget->setBorderDist( startDist, endDist );
    691743        }
    692         if ( !d.isValid )
    693         {
    694             d.scaleDiv = d.scaleEngine->divideScale(
    695                 minValue, maxValue,
    696                 d.maxMajor, d.maxMinor, stepSize );
    697             d.isValid = true;
    698         }
    699 
    700         QwtScaleWidget *scaleWidget = axisWidget( axisId );
    701         scaleWidget->setScaleDiv( d.scaleDiv );
    702 
    703         int startDist, endDist;
    704         scaleWidget->getBorderDistHint( startDist, endDist );
    705         scaleWidget->setBorderDist( startDist, endDist );
    706744    }
    707745
    708746    for ( it = itmList.begin(); it != itmList.end(); ++it )
    709747    {
    710         QwtPlotItem *item = *it;
     748        QwtPlotItem* item = *it;
    711749        if ( item->testItemInterest( QwtPlotItem::ScaleInterest ) )
    712750        {
    … …  
    716754    }
    717755}
    718 
Note: See TracChangeset for help on using the changeset viewer.