Changeset 11158 in ntrip for trunk/BNC/qwt


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

deprecated functions exchanged libs updated

Location:
trunk/BNC/qwt
Files:
60 added
2 deleted
193 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414
     15class QSize;
     16
    1517/*!
    16   Some constants for use within Qwt.
    17 */
     18   Some constants for use within Qwt.
     19 */
    1820namespace Qwt
    1921{
    2022}
    2123
     24QWT_EXPORT QSize qwtExpandedToGlobalStrut( const QSize& );
     25
    2226#endif
  • trunk/BNC/qwt/qwt.pro

    r8127 r11158  
    77CONFIG -= debug
    88CONFIG += release
    9 QWT_CONFIG = QwtPlot QwtWidgets QwtSvg
     9QWT_CONFIG = QwtPlot QwtPolar QwtWidgets QwtSvg
    1010
    1111OBJECTS_DIR = .obj
  • trunk/BNC/qwt/qwt_abstract_legend.cpp

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_abstract_legend.h"
     11#include "qwt_legend_data.h"
    1112
    1213/*!
    13   Constructor
     14   Constructor
    1415
    15   \param parent Parent widget
    16 */
    17 QwtAbstractLegend::QwtAbstractLegend( QWidget *parent ):
    18     QFrame( parent )
     16   \param parent Parent widget
     17 */
     18QwtAbstractLegend::QwtAbstractLegend( QWidget* parent )
     19    : QFrame( parent )
    1920{
    2021}
    … …  
    3132   \param orientation Orientation
    3233   \return Extent of the corresponding scroll element
    33 */
     34 */
    3435int QwtAbstractLegend::scrollExtent( Qt::Orientation orientation ) const
    3536{
    … …  
    3738    return 0;
    3839}
     40
     41#include "moc_qwt_abstract_legend.cpp"
  • trunk/BNC/qwt/qwt_abstract_legend.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_legend_data.h"
    1514#include <qframe.h>
    16 #include <qlist.h>
    1715
     16class QwtLegendData;
     17template< typename T > class QList;
    1818class QVariant;
    1919
    2020/*!
    21   \brief Abstract base class for legend widgets
     21   \brief Abstract base class for legend widgets
    2222
    23   Legends, that need to be under control of the QwtPlot layout system
    24   need to be derived from QwtAbstractLegend.
     23   Legends, that need to be under control of the QwtPlot layout system
     24   need to be derived from QwtAbstractLegend.
    2525
    26   \note Other type of legends can be implemented by connecting to
     26   \note Other type of legends can be implemented by connecting to
    2727        the QwtPlot::legendDataChanged() signal. But as these legends
    2828        are unknown to the plot layout system the layout code
    … …  
    3030        in application code.
    3131
    32   \sa QwtLegend
     32   \sa QwtLegend
    3333 */
    3434class QWT_EXPORT QwtAbstractLegend : public QFrame
    … …  
    3636    Q_OBJECT
    3737
    38 public:
    39     explicit QwtAbstractLegend( QWidget *parent = NULL );
     38  public:
     39    explicit QwtAbstractLegend( QWidget* parent = NULL );
    4040    virtual ~QwtAbstractLegend();
    4141
    4242    /*!
    43       Render the legend into a given rectangle.
     43       Render the legend into a given rectangle.
    4444
    45       \param painter Painter
    46       \param rect Bounding rectangle
    47       \param fillBackground When true, fill rect with the widget background
     45       \param painter Painter
     46       \param rect Bounding rectangle
     47       \param fillBackground When true, fill rect with the widget background
    4848
    49       \sa renderLegend() is used by QwtPlotRenderer
    50     */
    51     virtual void renderLegend( QPainter *painter,
    52         const QRectF &rect, bool fillBackground ) const = 0;
     49       \sa renderLegend() is used by QwtPlotRenderer
     50     */
     51    virtual void renderLegend( QPainter* painter,
     52        const QRectF& rect, bool fillBackground ) const = 0;
    5353
    5454    //! \return True, when no plot item is inserted
    … …  
    5757    virtual int scrollExtent( Qt::Orientation ) const;
    5858
    59 public Q_SLOTS:
     59  public Q_SLOTS:
    6060
    6161    /*!
    62       \brief Update the entries for a plot item
     62       \brief Update the entries for a plot item
    6363
    64       \param itemInfo Info about an item
    65       \param data List of legend entry attributes for the  item
     64       \param itemInfo Info about an item
     65       \param data List of legend entry attributes for the  item
    6666     */
    67     virtual void updateLegend( const QVariant &itemInfo,
    68         const QList<QwtLegendData> &data ) = 0;
     67    virtual void updateLegend( const QVariant& itemInfo,
     68        const QList< QwtLegendData >& data ) = 0;
    6969};
    7070
  • trunk/BNC/qwt/qwt_abstract_scale.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1515#include "qwt_interval.h"
    1616
     17#include <qcoreevent.h>
     18
    1719class QwtAbstractScale::PrivateData
    1820{
    19 public:
     21  public:
    2022    PrivateData():
    2123        maxMajor( 5 ),
    … …  
    3335    }
    3436
    35     QwtScaleEngine *scaleEngine;
    36     QwtAbstractScaleDraw *scaleDraw;
     37    QwtScaleEngine* scaleEngine;
     38    QwtAbstractScaleDraw* scaleDraw;
    3739
    3840    int maxMajor;
    … …  
    4244
    4345/*!
    44   Constructor
    45 
    46   \param parent Parent widget
    47 
    48   Creates a default QwtScaleDraw and a QwtLinearScaleEngine.
    49   The initial scale boundaries are set to [ 0.0, 100.0 ]
    50 
    51   The scaleStepSize() is initialized to 0.0, scaleMaxMajor() to 5
    52   and scaleMaxMajor to 3.
    53 */
    54 
    55 QwtAbstractScale::QwtAbstractScale( QWidget *parent ):
    56     QWidget( parent )
    57 {
    58     d_data = new PrivateData;
    59     rescale( 0.0, 100.0, d_data->stepSize );
     46   Constructor
     47
     48   \param parent Parent widget
     49
     50   Creates a default QwtScaleDraw and a QwtLinearScaleEngine.
     51   The initial scale boundaries are set to [ 0.0, 100.0 ]
     52
     53   The scaleStepSize() is initialized to 0.0, scaleMaxMajor() to 5
     54   and scaleMaxMajor to 3.
     55 */
     56
     57QwtAbstractScale::QwtAbstractScale( QWidget* parent )
     58    : QWidget( parent )
     59{
     60    m_data = new PrivateData;
     61    rescale( 0.0, 100.0, m_data->stepSize );
    6062}
    6163
    … …  
    6365QwtAbstractScale::~QwtAbstractScale()
    6466{
    65     delete d_data;
    66 }
    67 
    68 /*!
    69   Set the lower bound of the scale
    70 
    71   \param value Lower bound
    72 
    73   \sa lowerBound(), setScale(), setUpperBound()
    74   \note For inverted scales the lower bound
     67    delete m_data;
     68}
     69
     70/*!
     71   Set the lower bound of the scale
     72
     73   \param value Lower bound
     74
     75   \sa lowerBound(), setScale(), setUpperBound()
     76   \note For inverted scales the lower bound
    7577        is greater than the upper bound
    76 */
     78 */
    7779void QwtAbstractScale::setLowerBound( double value )
    7880{
    … …  
    8183
    8284/*!
    83   \return Lower bound of the scale
    84   \sa setLowerBound(), setScale(), upperBound()
    85 */
     85   \return Lower bound of the scale
     86   \sa setLowerBound(), setScale(), upperBound()
     87 */
    8688double QwtAbstractScale::lowerBound() const
    8789{
    88     return d_data->scaleDraw->scaleDiv().lowerBound();
    89 }
    90 
    91 /*!
    92   Set the upper bound of the scale
    93 
    94   \param value Upper bound
    95 
    96   \sa upperBound(), setScale(), setLowerBound()
    97   \note For inverted scales the lower bound
     90    return m_data->scaleDraw->scaleDiv().lowerBound();
     91}
     92
     93/*!
     94   Set the upper bound of the scale
     95
     96   \param value Upper bound
     97
     98   \sa upperBound(), setScale(), setLowerBound()
     99   \note For inverted scales the lower bound
    98100        is greater than the upper bound
    99 */
     101 */
    100102void QwtAbstractScale::setUpperBound( double value )
    101103{
    … …  
    104106
    105107/*!
    106   \return Upper bound of the scale
    107   \sa setUpperBound(), setScale(), lowerBound()
    108 */
     108   \return Upper bound of the scale
     109   \sa setUpperBound(), setScale(), lowerBound()
     110 */
    109111double QwtAbstractScale::upperBound() const
    110112{
    111     return d_data->scaleDraw->scaleDiv().upperBound();
    112 }
    113 
    114 /*!
    115   \brief Specify a scale.
    116 
    117   Define a scale by an interval
    118 
    119   The ticks are calculated using scaleMaxMinor(),
    120   scaleMaxMajor() and scaleStepSize().
    121 
    122   \param lowerBound lower limit of the scale interval
    123   \param upperBound upper limit of the scale interval
    124 
    125   \note For inverted scales the lower bound
     113    return m_data->scaleDraw->scaleDiv().upperBound();
     114}
     115
     116/*!
     117   \brief Specify a scale.
     118
     119   Define a scale by an interval
     120
     121   The ticks are calculated using scaleMaxMinor(),
     122   scaleMaxMajor() and scaleStepSize().
     123
     124   \param lowerBound lower limit of the scale interval
     125   \param upperBound upper limit of the scale interval
     126
     127   \note For inverted scales the lower bound
    126128        is greater than the upper bound
    127 */
     129 */
    128130void QwtAbstractScale::setScale( double lowerBound, double upperBound )
    129131{
    130     rescale( lowerBound, upperBound, d_data->stepSize );
    131 }
    132 
    133 /*!
    134   \brief Specify a scale.
    135 
    136   Define a scale by an interval
    137 
    138   The ticks are calculated using scaleMaxMinor(),
    139   scaleMaxMajor() and scaleStepSize().
    140 
    141   \param interval Interval
    142 */
    143 void QwtAbstractScale::setScale( const QwtInterval &interval )
     132    rescale( lowerBound, upperBound, m_data->stepSize );
     133}
     134
     135/*!
     136   \brief Specify a scale.
     137
     138   Define a scale by an interval
     139
     140   The ticks are calculated using scaleMaxMinor(),
     141   scaleMaxMajor() and scaleStepSize().
     142
     143   \param interval Interval
     144 */
     145void QwtAbstractScale::setScale( const QwtInterval& interval )
    144146{
    145147    setScale( interval.minValue(), interval.maxValue() );
    … …  
    147149
    148150/*!
    149   \brief Specify a scale.
    150 
    151   scaleMaxMinor(), scaleMaxMajor() and scaleStepSize() and have no effect.
    152 
    153   \param scaleDiv Scale division
    154   \sa setAutoScale()
    155 */
    156 void QwtAbstractScale::setScale( const QwtScaleDiv &scaleDiv )
    157 {
    158     if ( scaleDiv != d_data->scaleDraw->scaleDiv() )
     151   \brief Specify a scale.
     152
     153   scaleMaxMinor(), scaleMaxMajor() and scaleStepSize() and have no effect.
     154
     155   \param scaleDiv Scale division
     156   \sa setAutoScale()
     157 */
     158void QwtAbstractScale::setScale( const QwtScaleDiv& scaleDiv )
     159{
     160    if ( scaleDiv != m_data->scaleDraw->scaleDiv() )
    159161    {
    160162#if 1
    161         if ( d_data->scaleEngine )
     163        if ( m_data->scaleEngine )
    162164        {
    163             d_data->scaleDraw->setTransformation(
    164                 d_data->scaleEngine->transformation() );
     165            m_data->scaleDraw->setTransformation(
     166                m_data->scaleEngine->transformation() );
    165167        }
    166168#endif
    167169
    168         d_data->scaleDraw->setScaleDiv( scaleDiv );
     170        m_data->scaleDraw->setScaleDiv( scaleDiv );
    169171
    170172        scaleChange();
    … …  
    173175
    174176/*!
    175   \brief Set the maximum number of major tick intervals.
    176 
    177   The scale's major ticks are calculated automatically such that
    178   the number of major intervals does not exceed ticks.
    179 
    180   The default value is 5.
    181 
    182   \param ticks Maximal number of major ticks.
    183 
    184   \sa scaleMaxMajor(), setScaleMaxMinor(),
     177   \brief Set the maximum number of major tick intervals.
     178
     179   The scale's major ticks are calculated automatically such that
     180   the number of major intervals does not exceed ticks.
     181
     182   The default value is 5.
     183
     184   \param ticks Maximal number of major ticks.
     185
     186   \sa scaleMaxMajor(), setScaleMaxMinor(),
    185187      setScaleStepSize(), QwtScaleEngine::divideInterval()
    186 */
     188 */
    187189void QwtAbstractScale::setScaleMaxMajor( int ticks )
    188190{
    189     if ( ticks != d_data->maxMajor )
    190     {
    191         d_data->maxMajor = ticks;
     191    if ( ticks != m_data->maxMajor )
     192    {
     193        m_data->maxMajor = ticks;
    192194        updateScaleDraw();
    193195    }
    … …  
    195197
    196198/*!
    197   \return Maximal number of major tick intervals
    198   \sa setScaleMaxMajor(), scaleMaxMinor()
    199 */
     199   \return Maximal number of major tick intervals
     200   \sa setScaleMaxMajor(), scaleMaxMinor()
     201 */
    200202int QwtAbstractScale::scaleMaxMajor() const
    201203{
    202     return d_data->maxMajor;
    203 }
    204 
    205 /*!
    206   \brief Set the maximum number of minor tick intervals
    207 
    208   The scale's minor ticks are calculated automatically such that
    209   the number of minor intervals does not exceed ticks.
    210   The default value is 3.
    211 
    212   \param ticks Maximal number of minor ticks.
    213 
    214   \sa scaleMaxMajor(), setScaleMaxMinor(),
     204    return m_data->maxMajor;
     205}
     206
     207/*!
     208   \brief Set the maximum number of minor tick intervals
     209
     210   The scale's minor ticks are calculated automatically such that
     211   the number of minor intervals does not exceed ticks.
     212   The default value is 3.
     213
     214   \param ticks Maximal number of minor ticks.
     215
     216   \sa scaleMaxMajor(), setScaleMaxMinor(),
    215217      setScaleStepSize(), QwtScaleEngine::divideInterval()
    216 */
     218 */
    217219void QwtAbstractScale::setScaleMaxMinor( int ticks )
    218220{
    219     if ( ticks != d_data->maxMinor )
    220     {
    221         d_data->maxMinor = ticks;
     221    if ( ticks != m_data->maxMinor )
     222    {
     223        m_data->maxMinor = ticks;
    222224        updateScaleDraw();
    223225    }
    … …  
    225227
    226228/*!
    227   \return Maximal number of minor tick intervals
    228   \sa setScaleMaxMinor(), scaleMaxMajor()
    229 */
     229   \return Maximal number of minor tick intervals
     230   \sa setScaleMaxMinor(), scaleMaxMajor()
     231 */
    230232int QwtAbstractScale::scaleMaxMinor() const
    231233{
    232     return d_data->maxMinor;
     234    return m_data->maxMinor;
    233235}
    234236
    … …  
    246248   \note Position and distance between the major ticks also
    247249         depends on scaleMaxMajor().
    248 */
     250 */
    249251void QwtAbstractScale::setScaleStepSize( double stepSize )
    250252{
    251     if ( stepSize != d_data->stepSize )
    252     {
    253         d_data->stepSize = stepSize;
     253    if ( stepSize != m_data->stepSize )
     254    {
     255        m_data->stepSize = stepSize;
    254256        updateScaleDraw();
    255257    }
    … …  
    257259
    258260/*!
    259   \return Hint for the step size of the scale
    260   \sa setScaleStepSize(), QwtScaleEngine::divideScale()
    261 */
     261   \return Hint for the step size of the scale
     262   \sa setScaleStepSize(), QwtScaleEngine::divideScale()
     263 */
    262264double QwtAbstractScale::scaleStepSize() const
    263265{
    264     return d_data->stepSize;
    265 }
    266 
    267 /*!
    268   \brief Set a scale draw
    269 
    270   scaleDraw has to be created with new and will be deleted in
    271   the destructor or the next call of setAbstractScaleDraw().
    272 
    273   \sa abstractScaleDraw()
    274 */
    275 void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw *scaleDraw )
    276 {
    277     if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw )
     266    return m_data->stepSize;
     267}
     268
     269/*!
     270   \brief Set a scale draw
     271
     272   scaleDraw has to be created with new and will be deleted in
     273   the destructor or the next call of setAbstractScaleDraw().
     274
     275   \sa abstractScaleDraw()
     276 */
     277void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw* scaleDraw )
     278{
     279    if ( scaleDraw == NULL || scaleDraw == m_data->scaleDraw )
    278280        return;
    279281
    280     if ( d_data->scaleDraw != NULL )
    281         scaleDraw->setScaleDiv( d_data->scaleDraw->scaleDiv() );
    282 
    283     delete d_data->scaleDraw;
    284     d_data->scaleDraw = scaleDraw;
     282    if ( m_data->scaleDraw != NULL )
     283        scaleDraw->setScaleDiv( m_data->scaleDraw->scaleDiv() );
     284
     285    delete m_data->scaleDraw;
     286    m_data->scaleDraw = scaleDraw;
    285287}
    286288
    … …  
    288290    \return Scale draw
    289291    \sa setAbstractScaleDraw()
    290 */
    291 QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw()
    292 {
    293     return d_data->scaleDraw;
     292 */
     293QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw()
     294{
     295    return m_data->scaleDraw;
    294296}
    295297
    … …  
    297299    \return Scale draw
    298300    \sa setAbstractScaleDraw()
    299 */
    300 const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const
    301 {
    302     return d_data->scaleDraw;
    303 }
    304 
    305 /*!
    306   \brief Set a scale engine
    307 
    308   The scale engine is responsible for calculating the scale division
    309   and provides a transformation between scale and widget coordinates.
    310 
    311   scaleEngine has to be created with new and will be deleted in
    312   the destructor or the next call of setScaleEngine.
    313 */
    314 void QwtAbstractScale::setScaleEngine( QwtScaleEngine *scaleEngine )
    315 {
    316     if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine )
    317     {
    318         delete d_data->scaleEngine;
    319         d_data->scaleEngine = scaleEngine;
    320     }
    321 }
    322 
    323 /*!
    324   \return Scale engine
    325   \sa setScaleEngine()
    326 */
    327 const QwtScaleEngine *QwtAbstractScale::scaleEngine() const
    328 {
    329     return d_data->scaleEngine;
    330 }
    331 
    332 /*!
    333   \return Scale engine
    334   \sa setScaleEngine()
    335 */
    336 QwtScaleEngine *QwtAbstractScale::scaleEngine()
    337 {
    338     return d_data->scaleEngine;
    339 }
    340 
    341 /*!
    342   \return Scale boundaries and positions of the ticks
    343 
    344   The scale division might have been assigned explicitly
    345   or calculated implicitly by rescale().
    346  */
    347 const QwtScaleDiv &QwtAbstractScale::scaleDiv() const
    348 {
    349     return d_data->scaleDraw->scaleDiv();
    350 }
    351 
    352 /*!
    353   \return Map to translate between scale and widget coordinates
    354  */
    355 const QwtScaleMap &QwtAbstractScale::scaleMap() const
    356 {
    357     return d_data->scaleDraw->scaleMap();
    358 }
    359 
    360 /*!
    361   Translate a scale value into a widget coordinate
    362 
    363   \param value Scale value
    364   \return Corresponding widget coordinate for value
    365   \sa scaleMap(), invTransform()
     301 */
     302const QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw() const
     303{
     304    return m_data->scaleDraw;
     305}
     306
     307/*!
     308   \brief Set a scale engine
     309
     310   The scale engine is responsible for calculating the scale division
     311   and provides a transformation between scale and widget coordinates.
     312
     313   scaleEngine has to be created with new and will be deleted in
     314   the destructor or the next call of setScaleEngine.
     315 */
     316void QwtAbstractScale::setScaleEngine( QwtScaleEngine* scaleEngine )
     317{
     318    if ( scaleEngine != NULL && scaleEngine != m_data->scaleEngine )
     319    {
     320        delete m_data->scaleEngine;
     321        m_data->scaleEngine = scaleEngine;
     322    }
     323}
     324
     325/*!
     326   \return Scale engine
     327   \sa setScaleEngine()
     328 */
     329const QwtScaleEngine* QwtAbstractScale::scaleEngine() const
     330{
     331    return m_data->scaleEngine;
     332}
     333
     334/*!
     335   \return Scale engine
     336   \sa setScaleEngine()
     337 */
     338QwtScaleEngine* QwtAbstractScale::scaleEngine()
     339{
     340    return m_data->scaleEngine;
     341}
     342
     343/*!
     344   \return Scale boundaries and positions of the ticks
     345
     346   The scale division might have been assigned explicitly
     347   or calculated implicitly by rescale().
     348 */
     349const QwtScaleDiv& QwtAbstractScale::scaleDiv() const
     350{
     351    return m_data->scaleDraw->scaleDiv();
     352}
     353
     354/*!
     355   \return Map to translate between scale and widget coordinates
     356 */
     357const QwtScaleMap& QwtAbstractScale::scaleMap() const
     358{
     359    return m_data->scaleDraw->scaleMap();
     360}
     361
     362/*!
     363   Translate a scale value into a widget coordinate
     364
     365   \param value Scale value
     366   \return Corresponding widget coordinate for value
     367   \sa scaleMap(), invTransform()
    366368 */
    367369int QwtAbstractScale::transform( double value ) const
    368370{
    369     return qRound( d_data->scaleDraw->scaleMap().transform( value ) );
    370 }
    371 
    372 /*!
    373   Translate a widget coordinate into a scale value
    374 
    375   \param value Widget coordinate
    376   \return Corresponding scale coordinate for value
    377   \sa scaleMap(), transform()
     371    return qRound( m_data->scaleDraw->scaleMap().transform( value ) );
     372}
     373
     374/*!
     375   Translate a widget coordinate into a scale value
     376
     377   \param value Widget coordinate
     378   \return Corresponding scale coordinate for value
     379   \sa scaleMap(), transform()
    378380 */
    379381double QwtAbstractScale::invTransform( int value ) const
    380382{
    381     return d_data->scaleDraw->scaleMap().invTransform( value );
    382 }
    383 
    384 /*!
    385   \return True, when the scale is increasing in opposite direction
     383    return m_data->scaleDraw->scaleMap().invTransform( value );
     384}
     385
     386/*!
     387   \return True, when the scale is increasing in opposite direction
    386388          to the widget coordinates
    387389 */
    388390bool QwtAbstractScale::isInverted() const
    389391{
    390     return d_data->scaleDraw->scaleMap().isInverting();
    391 }
    392 
    393 /*!
    394   \return The boundary with the smaller value
    395   \sa maximum(), lowerBound(), upperBound()
     392    return m_data->scaleDraw->scaleMap().isInverting();
     393}
     394
     395/*!
     396   \return The boundary with the smaller value
     397   \sa maximum(), lowerBound(), upperBound()
    396398 */
    397399double QwtAbstractScale::minimum() const
    398400{
    399     return qMin( d_data->scaleDraw->scaleDiv().lowerBound(),
    400         d_data->scaleDraw->scaleDiv().upperBound() );
    401 }
    402 
    403 /*!
    404   \return The boundary with the larger value
    405   \sa minimum(), lowerBound(), upperBound()
     401    return qMin( m_data->scaleDraw->scaleDiv().lowerBound(),
     402        m_data->scaleDraw->scaleDiv().upperBound() );
     403}
     404
     405/*!
     406   \return The boundary with the larger value
     407   \sa minimum(), lowerBound(), upperBound()
    406408 */
    407409double QwtAbstractScale::maximum() const
    408410{
    409     return qMax( d_data->scaleDraw->scaleDiv().lowerBound(),
    410         d_data->scaleDraw->scaleDiv().upperBound() );
     411    return qMax( m_data->scaleDraw->scaleDiv().lowerBound(),
     412        m_data->scaleDraw->scaleDiv().upperBound() );
    411413}
    412414
    … …  
    417419
    418420/*!
    419   Recalculate the scale division and update the scale.
    420 
    421   \param lowerBound Lower limit of the scale interval
    422   \param upperBound Upper limit of the scale interval
    423   \param stepSize Major step size
    424 
    425   \sa scaleChange()
    426 */
     421   Recalculate the scale division and update the scale.
     422
     423   \param lowerBound Lower limit of the scale interval
     424   \param upperBound Upper limit of the scale interval
     425   \param stepSize Major step size
     426
     427   \sa scaleChange()
     428 */
    427429void QwtAbstractScale::rescale(
    428430    double lowerBound, double upperBound, double stepSize )
    429431{
    430     const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale(
    431         lowerBound, upperBound, d_data->maxMajor, d_data->maxMinor, stepSize );
    432 
    433     if ( scaleDiv != d_data->scaleDraw->scaleDiv() )
     432    const QwtScaleDiv scaleDiv = m_data->scaleEngine->divideScale(
     433        lowerBound, upperBound, m_data->maxMajor, m_data->maxMinor, stepSize );
     434
     435    if ( scaleDiv != m_data->scaleDraw->scaleDiv() )
    434436    {
    435437#if 1
    436         d_data->scaleDraw->setTransformation(
    437             d_data->scaleEngine->transformation() );
     438        m_data->scaleDraw->setTransformation(
     439            m_data->scaleEngine->transformation() );
    438440#endif
    439441
    440         d_data->scaleDraw->setScaleDiv( scaleDiv );
     442        m_data->scaleDraw->setScaleDiv( scaleDiv );
    441443        scaleChange();
    442444    }
    443445}
    444446
     447/*!
     448   Change Event handler
     449   \param event Change event
     450
     451   Invalidates internal caches if necessary
     452 */
     453void QwtAbstractScale::changeEvent( QEvent* event )
     454{
     455    if ( event->type() == QEvent::LocaleChange )
     456    {
     457        m_data->scaleDraw->invalidateCache();
     458    }
     459
     460    QWidget::changeEvent( event );
     461}
     462
     463/*!
     464   Recalculate ticks and scale boundaries.
     465 */
    445466void QwtAbstractScale::updateScaleDraw()
    446467{
    447     rescale( d_data->scaleDraw->scaleDiv().lowerBound(),
    448         d_data->scaleDraw->scaleDiv().upperBound(), d_data->stepSize );
    449 }
     468    rescale( m_data->scaleDraw->scaleDiv().lowerBound(),
     469        m_data->scaleDraw->scaleDiv().upperBound(), m_data->stepSize );
     470}
     471
     472#include "moc_qwt_abstract_scale.cpp"
  • trunk/BNC/qwt/qwt_abstract_scale.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    2121
    2222/*!
    23   \brief An abstract base class for widgets having a scale
     23   \brief An abstract base class for widgets having a scale
    2424
    25   The scale of an QwtAbstractScale is determined by a QwtScaleDiv
    26   definition, that contains the boundaries and the ticks of the scale.
    27   The scale is painted using a QwtScaleDraw object.
     25   The scale of an QwtAbstractScale is determined by a QwtScaleDiv
     26   definition, that contains the boundaries and the ticks of the scale.
     27   The scale is painted using a QwtScaleDraw object.
    2828
    29   The scale division might be assigned explicitly - but usually
    30   it is calculated from the boundaries using a QwtScaleEngine.
     29   The scale division might be assigned explicitly - but usually
     30   it is calculated from the boundaries using a QwtScaleEngine.
    3131
    32   The scale engine also decides the type of transformation of the scale
    33   ( linear, logarithmic ... ).
    34 */
     32   The scale engine also decides the type of transformation of the scale
     33   ( linear, logarithmic ... ).
     34 */
    3535
    36 class QWT_EXPORT QwtAbstractScale: public QWidget
     36class QWT_EXPORT QwtAbstractScale : public QWidget
    3737{
    3838    Q_OBJECT
    … …  
    4646    Q_PROPERTY( double scaleStepSize READ scaleStepSize WRITE setScaleStepSize )
    4747
    48 public:
    49     QwtAbstractScale( QWidget *parent = NULL );
     48  public:
     49    explicit QwtAbstractScale( QWidget* parent = NULL );
    5050    virtual ~QwtAbstractScale();
    5151
    5252    void setScale( double lowerBound, double upperBound );
    53     void setScale( const QwtInterval & );
    54     void setScale( const QwtScaleDiv & );
     53    void setScale( const QwtInterval& );
     54    void setScale( const QwtScaleDiv& );
    5555
    5656    const QwtScaleDiv& scaleDiv() const;
    … …  
    7171    int scaleMaxMajor() const;
    7272
    73     void setScaleEngine( QwtScaleEngine * );
    74     const QwtScaleEngine *scaleEngine() const;
    75     QwtScaleEngine *scaleEngine();
     73    void setScaleEngine( QwtScaleEngine* );
     74    const QwtScaleEngine* scaleEngine() const;
     75    QwtScaleEngine* scaleEngine();
    7676
    7777    int transform( double ) const;
    … …  
    8383    double maximum() const;
    8484
    85     const QwtScaleMap &scaleMap() const;
     85    const QwtScaleMap& scaleMap() const;
    8686
    87 protected:
     87  protected:
     88    virtual void changeEvent( QEvent* ) QWT_OVERRIDE;
     89
    8890    void rescale( double lowerBound,
    8991        double upperBound, double stepSize );
    9092
    91     void setAbstractScaleDraw( QwtAbstractScaleDraw * );
     93    void setAbstractScaleDraw( QwtAbstractScaleDraw* );
    9294
    93     const QwtAbstractScaleDraw *abstractScaleDraw() const;
    94     QwtAbstractScaleDraw *abstractScaleDraw();
     95    const QwtAbstractScaleDraw* abstractScaleDraw() const;
     96    QwtAbstractScaleDraw* abstractScaleDraw();
    9597
     98    void updateScaleDraw();
    9699    virtual void scaleChange();
    97100
    98 private:
    99     void updateScaleDraw();
    100 
     101  private:
    101102    class PrivateData;
    102     PrivateData *d_data;
     103    PrivateData* m_data;
    103104};
    104105
  • trunk/BNC/qwt/qwt_abstract_scale_draw.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_abstract_scale_draw.h"
    11 #include "qwt_math.h"
    1211#include "qwt_text.h"
    1312#include "qwt_painter.h"
    1413#include "qwt_scale_map.h"
     14#include "qwt_math.h"
     15
    1516#include <qpainter.h>
    1617#include <qpalette.h>
    1718#include <qmap.h>
     19#include <qlist.h>
    1820#include <qlocale.h>
    1921
    2022class QwtAbstractScaleDraw::PrivateData
    2123{
    22 public:
     24  public:
    2325    PrivateData():
    2426        spacing( 4.0 ),
    25         penWidth( 0 ),
     27        penWidthF( 0.0 ),
    2628        minExtent( 0.0 )
    2729    {
    … …  
    4244    double spacing;
    4345    double tickLength[QwtScaleDiv::NTickTypes];
    44     int penWidth;
     46    qreal penWidthF;
    4547
    4648    double minExtent;
    4749
    48     QMap<double, QwtText> labelCache;
     50    QMap< double, QwtText > labelCache;
    4951};
    5052
    5153/*!
    52   \brief Constructor
    53 
    54   The range of the scale is initialized to [0, 100],
    55   The spacing (distance between ticks and labels) is
    56   set to 4, the tick lengths are set to 4,6 and 8 pixels
    57 */
     54   \brief Constructor
     55
     56   The range of the scale is initialized to [0, 100],
     57   The spacing (distance between ticks and labels) is
     58   set to 4, the tick lengths are set to 4,6 and 8 pixels
     59 */
    5860QwtAbstractScaleDraw::QwtAbstractScaleDraw()
    5961{
    60     d_data = new QwtAbstractScaleDraw::PrivateData;
     62    m_data = new QwtAbstractScaleDraw::PrivateData;
    6163}
    6264
    … …  
    6466QwtAbstractScaleDraw::~QwtAbstractScaleDraw()
    6567{
    66     delete d_data;
    67 }
    68 
    69 /*!
    70   En/Disable a component of the scale
    71 
    72   \param component Scale component
    73   \param enable On/Off
    74 
    75   \sa hasComponent()
    76 */
     68    delete m_data;
     69}
     70
     71/*!
     72   En/Disable a component of the scale
     73
     74   \param component Scale component
     75   \param enable On/Off
     76
     77   \sa hasComponent()
     78 */
    7779void QwtAbstractScaleDraw::enableComponent(
    7880    ScaleComponent component, bool enable )
    7981{
    8082    if ( enable )
    81         d_data->components |= component;
     83        m_data->components |= component;
    8284    else
    83         d_data->components &= ~component;
    84 }
    85 
    86 /*!
    87   Check if a component is enabled
    88 
    89   \param component Component type
    90   \return true, when component is enabled
    91   \sa enableComponent()
    92 */
     85        m_data->components &= ~component;
     86}
     87
     88/*!
     89   Check if a component is enabled
     90
     91   \param component Component type
     92   \return true, when component is enabled
     93   \sa enableComponent()
     94 */
    9395bool QwtAbstractScaleDraw::hasComponent( ScaleComponent component ) const
    9496{
    95     return ( d_data->components & component );
    96 }
    97 
    98 /*!
    99   Change the scale division
    100   \param scaleDiv New scale division
    101 */
    102 void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv &scaleDiv )
    103 {
    104     d_data->scaleDiv = scaleDiv;
    105     d_data->map.setScaleInterval( scaleDiv.lowerBound(), scaleDiv.upperBound() );
    106     d_data->labelCache.clear();
    107 }
    108 
    109 /*!
    110   Change the transformation of the scale
    111   \param transformation New scale transformation
    112 */
    113 void QwtAbstractScaleDraw::setTransformation(
    114     QwtTransform *transformation )
    115 {
    116     d_data->map.setTransformation( transformation );
     97    return ( m_data->components & component );
     98}
     99
     100/*!
     101   Change the scale division
     102   \param scaleDiv New scale division
     103 */
     104void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv& scaleDiv )
     105{
     106    m_data->scaleDiv = scaleDiv;
     107    m_data->map.setScaleInterval( scaleDiv.lowerBound(), scaleDiv.upperBound() );
     108    m_data->labelCache.clear();
     109}
     110
     111/*!
     112   Change the transformation of the scale
     113   \param transformation New scale transformation
     114 */
     115void QwtAbstractScaleDraw::setTransformation( QwtTransform* transformation )
     116{
     117    m_data->map.setTransformation( transformation );
    117118}
    118119
    119120//! \return Map how to translate between scale and pixel values
    120 const QwtScaleMap &QwtAbstractScaleDraw::scaleMap() const
    121 {
    122     return d_data->map;
     121const QwtScaleMap& QwtAbstractScaleDraw::scaleMap() const
     122{
     123    return m_data->map;
    123124}
    124125
    125126//! \return Map how to translate between scale and pixel values
    126 QwtScaleMap &QwtAbstractScaleDraw::scaleMap()
    127 {
    128     return d_data->map;
     127QwtScaleMap& QwtAbstractScaleDraw::scaleMap()
     128{
     129    return m_data->map;
    129130}
    130131
    … …  
    132133const QwtScaleDiv& QwtAbstractScaleDraw::scaleDiv() const
    133134{
    134     return d_data->scaleDiv;
    135 }
    136 
    137 /*!
    138   \brief Specify the width of the scale pen
    139   \param width Pen width
    140   \sa penWidth()
    141 */
    142 void QwtAbstractScaleDraw::setPenWidth( int width )
    143 {
    144     if ( width < 0 )
    145         width = 0;
    146 
    147     if ( width != d_data->penWidth )
    148         d_data->penWidth = width;
     135    return m_data->scaleDiv;
     136}
     137
     138/*!
     139   \brief Specify the width of the scale pen
     140   \param width Pen width
     141
     142   \sa penWidth()
     143 */
     144void QwtAbstractScaleDraw::setPenWidthF( qreal width )
     145{
     146    if ( width < 0.0 )
     147        width = 0.0;
     148
     149    m_data->penWidthF = width;
    149150}
    150151
    … …  
    152153    \return Scale pen width
    153154    \sa setPenWidth()
    154 */
    155 int QwtAbstractScaleDraw::penWidth() const
    156 {
    157     return d_data->penWidth;
    158 }
    159 
    160 /*!
    161   \brief Draw the scale
    162 
    163   \param painter    The painter
    164 
    165   \param palette    Palette, text color is used for the labels,
     155 */
     156qreal QwtAbstractScaleDraw::penWidthF() const
     157{
     158    return m_data->penWidthF;
     159}
     160
     161/*!
     162   \brief Draw the scale
     163
     164   \param painter    The painter
     165
     166   \param palette    Palette, text color is used for the labels,
    166167                    foreground color for ticks and backbone
    167 */
    168 void QwtAbstractScaleDraw::draw( QPainter *painter,
     168 */
     169void QwtAbstractScaleDraw::draw( QPainter* painter,
    169170    const QPalette& palette ) const
    170171{
    … …  
    172173
    173174    QPen pen = painter->pen();
    174     pen.setWidth( d_data->penWidth );
    175     pen.setCosmetic( false );
     175    pen.setWidthF( m_data->penWidthF );
     176
    176177    painter->setPen( pen );
    177178
    … …  
    181182        painter->setPen( palette.color( QPalette::Text ) ); // ignore pen style
    182183
    183         const QList<double> &majorTicks =
    184             d_data->scaleDiv.ticks( QwtScaleDiv::MajorTick );
     184        const QList< double >& majorTicks =
     185            m_data->scaleDiv.ticks( QwtScaleDiv::MajorTick );
    185186
    186187        for ( int i = 0; i < majorTicks.count(); i++ )
    187188        {
    188189            const double v = majorTicks[i];
    189             if ( d_data->scaleDiv.contains( v ) )
     190            if ( m_data->scaleDiv.contains( v ) )
    190191                drawLabel( painter, v );
    191192        }
    … …  
    207208            tickType < QwtScaleDiv::NTickTypes; tickType++ )
    208209        {
    209             const double tickLen = d_data->tickLength[tickType];
     210            const double tickLen = m_data->tickLength[tickType];
    210211            if ( tickLen <= 0.0 )
    211212                continue;
    212213
    213             const QList<double> &ticks = d_data->scaleDiv.ticks( tickType );
     214            const QList< double >& ticks = m_data->scaleDiv.ticks( tickType );
    214215            for ( int i = 0; i < ticks.count(); i++ )
    215216            {
    216217                const double v = ticks[i];
    217                 if ( d_data->scaleDiv.contains( v ) )
     218                if ( m_data->scaleDiv.contains( v ) )
    218219                    drawTick( painter, v, tickLen );
    219220            }
    … …  
    242243
    243244/*!
    244   \brief Set the spacing between tick and labels
    245 
    246   The spacing is the distance between ticks and labels.
    247   The default spacing is 4 pixels.
    248 
    249   \param spacing Spacing
    250 
    251   \sa spacing()
    252 */
     245   \brief Set the spacing between tick and labels
     246
     247   The spacing is the distance between ticks and labels.
     248   The default spacing is 4 pixels.
     249
     250   \param spacing Spacing
     251
     252   \sa spacing()
     253 */
    253254void QwtAbstractScaleDraw::setSpacing( double spacing )
    254255{
    … …  
    256257        spacing = 0;
    257258
    258     d_data->spacing = spacing;
    259 }
    260 
    261 /*!
    262   \brief Get the spacing
    263 
    264   The spacing is the distance between ticks and labels.
    265   The default spacing is 4 pixels.
    266 
    267   \return Spacing
    268   \sa setSpacing()
    269 */
     259    m_data->spacing = spacing;
     260}
     261
     262/*!
     263   \brief Get the spacing
     264
     265   The spacing is the distance between ticks and labels.
     266   The default spacing is 4 pixels.
     267
     268   \return Spacing
     269   \sa setSpacing()
     270 */
    270271double QwtAbstractScaleDraw::spacing() const
    271272{
    272     return d_data->spacing;
    273 }
    274 
    275 /*!
    276   \brief Set a minimum for the extent
    277 
    278   The extent is calculated from the components of the
    279   scale draw. In situations, where the labels are
    280   changing and the layout depends on the extent (f.e scrolling
    281   a scale), setting an upper limit as minimum extent will
    282   avoid jumps of the layout.
    283 
    284   \param minExtent Minimum extent
    285 
    286   \sa extent(), minimumExtent()
    287 */
     273    return m_data->spacing;
     274}
     275
     276/*!
     277   \brief Set a minimum for the extent
     278
     279   The extent is calculated from the components of the
     280   scale draw. In situations, where the labels are
     281   changing and the layout depends on the extent (f.e scrolling
     282   a scale), setting an upper limit as minimum extent will
     283   avoid jumps of the layout.
     284
     285   \param minExtent Minimum extent
     286
     287   \sa extent(), minimumExtent()
     288 */
    288289void QwtAbstractScaleDraw::setMinimumExtent( double minExtent )
    289290{
    … …  
    291292        minExtent = 0.0;
    292293
    293     d_data->minExtent = minExtent;
    294 }
    295 
    296 /*!
    297   Get the minimum extent
    298   \return Minimum extent
    299   \sa extent(), setMinimumExtent()
    300 */
     294    m_data->minExtent = minExtent;
     295}
     296
     297/*!
     298   Get the minimum extent
     299   \return Minimum extent
     300   \sa extent(), setMinimumExtent()
     301 */
    301302double QwtAbstractScaleDraw::minimumExtent() const
    302303{
    303     return d_data->minExtent;
    304 }
    305 
    306 /*!
    307   Set the length of the ticks
    308 
    309   \param tickType Tick type
    310   \param length New length
    311 
    312   \warning the length is limited to [0..1000]
    313 */
     304    return m_data->minExtent;
     305}
     306
     307/*!
     308   Set the length of the ticks
     309
     310   \param tickType Tick type
     311   \param length New length
     312
     313   \warning the length is limited to [0..1000]
     314 */
    314315void QwtAbstractScaleDraw::setTickLength(
    315316    QwtScaleDiv::TickType tickType, double length )
    … …  
    328329        length = maxTickLen;
    329330
    330     d_data->tickLength[tickType] = length;
     331    m_data->tickLength[tickType] = length;
    331332}
    332333
    … …  
    334335    \return Length of the ticks
    335336    \sa setTickLength(), maxTickLength()
    336 */
     337 */
    337338double QwtAbstractScaleDraw::tickLength( QwtScaleDiv::TickType tickType ) const
    338339{
    … …  
    343344    }
    344345
    345     return d_data->tickLength[tickType];
     346    return m_data->tickLength[tickType];
    346347}
    347348
    … …  
    351352   Useful for layout calculations
    352353   \sa tickLength(), setTickLength()
    353 */
     354 */
    354355double QwtAbstractScaleDraw::maxTickLength() const
    355356{
    356357    double length = 0.0;
    357358    for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
    358         length = qMax( length, d_data->tickLength[i] );
     359        length = qwtMaxF( length, m_data->tickLength[i] );
    359360
    360361    return length;
    … …  
    362363
    363364/*!
    364   \brief Convert a value into its representing label
    365 
    366   The value is converted to a plain text using
    367   QLocale().toString(value).
    368   This method is often overloaded by applications to have individual
    369   labels.
    370 
    371   \param value Value
    372   \return Label string.
    373 */
     365   \brief Convert a value into its representing label
     366
     367   The value is converted to a plain text using
     368   QLocale().toString(value).
     369   This method is often overloaded by applications to have individual
     370   labels.
     371
     372   \param value Value
     373   \return Label string.
     374 */
    374375QwtText QwtAbstractScaleDraw::label( double value ) const
    375376{
    … …  
    389390
    390391   \return Tick label
    391 */
    392 const QwtText &QwtAbstractScaleDraw::tickLabel(
    393     const QFont &font, double value ) const
    394 {
    395     QMap<double, QwtText>::const_iterator it1 = d_data->labelCache.constFind( value );
    396     if ( it1 != d_data->labelCache.constEnd() )
     392 */
     393const QwtText& QwtAbstractScaleDraw::tickLabel(
     394    const QFont& font, double value ) const
     395{
     396    QMap< double, QwtText >::const_iterator it1 = m_data->labelCache.constFind( value );
     397    if ( it1 != m_data->labelCache.constEnd() )
    397398        return *it1;
    398399
    … …  
    403404    ( void )lbl.textSize( font ); // initialize the internal cache
    404405
    405     QMap<double, QwtText>::iterator it2 = d_data->labelCache.insert( value, lbl );
     406    QMap< double, QwtText >::iterator it2 = m_data->labelCache.insert( value, lbl );
    406407    return *it2;
    407408}
    … …  
    413414   the labels need to be changed. while the same QwtScaleDiv is set,
    414415   invalidateCache() needs to be called manually.
    415 */
     416 */
    416417void QwtAbstractScaleDraw::invalidateCache()
    417418{
    418     d_data->labelCache.clear();
    419 }
     419    m_data->labelCache.clear();
     420}
  • trunk/BNC/qwt/qwt_abstract_scale_draw.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_scale_div.h"
    15 #include "qwt_text.h"
    1615
     16class QwtText;
    1717class QPalette;
    1818class QPainter;
    … …  
    2222
    2323/*!
    24   \brief A abstract base class for drawing scales
     24   \brief A abstract base class for drawing scales
    2525
    26   QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.
     26   QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.
    2727
    28   After a scale division has been specified as a QwtScaleDiv object
    29   using setScaleDiv(), the scale can be drawn with the draw() member.
    30 */
     28   After a scale division has been specified as a QwtScaleDiv object
     29   using setScaleDiv(), the scale can be drawn with the draw() member.
     30 */
    3131class QWT_EXPORT QwtAbstractScaleDraw
    3232{
    33 public:
     33  public:
    3434
    3535    /*!
    3636       Components of a scale
    3737       \sa enableComponent(), hasComponent
    38     */
     38     */
    3939    enum ScaleComponent
    4040    {
    … …  
    4949    };
    5050
    51     //! Scale components
    52     typedef QFlags<ScaleComponent> ScaleComponents;
     51    Q_DECLARE_FLAGS( ScaleComponents, ScaleComponent )
    5352
    5453    QwtAbstractScaleDraw();
    5554    virtual ~QwtAbstractScaleDraw();
    5655
    57     void setScaleDiv( const QwtScaleDiv & );
     56    void setScaleDiv( const QwtScaleDiv& );
    5857    const QwtScaleDiv& scaleDiv() const;
    5958
    60     void setTransformation( QwtTransform * );
    61     const QwtScaleMap &scaleMap() const;
    62     QwtScaleMap &scaleMap();
     59    void setTransformation( QwtTransform* );
     60    const QwtScaleMap& scaleMap() const;
     61    QwtScaleMap& scaleMap();
    6362
    6463    void enableComponent( ScaleComponent, bool enable = true );
    … …  
    7271    double spacing() const;
    7372
    74     void setPenWidth( int width );
    75     int penWidth() const;
     73    void setPenWidthF( qreal width );
     74    qreal penWidthF() const;
    7675
    77     virtual void draw( QPainter *, const QPalette & ) const;
     76    virtual void draw( QPainter*, const QPalette& ) const;
    7877
    7978    virtual QwtText label( double ) const;
    8079
    8180    /*!
    82       Calculate the extent
     81       Calculate the extent
    8382
    84       The extent is the distance from the baseline to the outermost
    85       pixel of the scale draw in opposite to its orientation.
    86       It is at least minimumExtent() pixels.
     83       The extent is the distance from the baseline to the outermost
     84       pixel of the scale draw in opposite to its orientation.
     85       It is at least minimumExtent() pixels.
    8786
    88       \param font Font used for drawing the tick labels
    89       \return Number of pixels
     87       \param font Font used for drawing the tick labels
     88       \return Number of pixels
    9089
    91       \sa setMinimumExtent(), minimumExtent()
    92     */
    93     virtual double extent( const QFont &font ) const = 0;
     90       \sa setMinimumExtent(), minimumExtent()
     91     */
     92    virtual double extent( const QFont& font ) const = 0;
    9493
    9594    void setMinimumExtent( double );
    9695    double minimumExtent() const;
    9796
    98 protected:
     97    void invalidateCache();
     98
     99  protected:
    99100    /*!
    100101       Draw a tick
    … …  
    105106
    106107       \sa drawBackbone(), drawLabel()
    107     */
    108     virtual void drawTick( QPainter *painter, double value, double len ) const = 0;
     108     */
     109    virtual void drawTick( QPainter* painter, double value, double len ) const = 0;
    109110
    110111    /*!
    111       Draws the baseline of the scale
    112       \param painter Painter
     112       Draws the baseline of the scale
     113       \param painter Painter
    113114
    114       \sa drawTick(), drawLabel()
    115     */
    116     virtual void drawBackbone( QPainter *painter ) const = 0;
     115       \sa drawTick(), drawLabel()
     116     */
     117    virtual void drawBackbone( QPainter* painter ) const = 0;
    117118
    118119    /*!
    … …  
    123124
    124125        \sa drawTick(), drawBackbone()
    125     */
    126     virtual void drawLabel( QPainter *painter, double value ) const = 0;
     126     */
     127    virtual void drawLabel( QPainter* painter, double value ) const = 0;
    127128
    128     void invalidateCache();
    129     const QwtText &tickLabel( const QFont &, double value ) const;
     129    const QwtText& tickLabel( const QFont&, double value ) const;
    130130
    131 private:
    132     QwtAbstractScaleDraw( const QwtAbstractScaleDraw & );
    133     QwtAbstractScaleDraw &operator=( const QwtAbstractScaleDraw & );
     131  private:
     132    Q_DISABLE_COPY(QwtAbstractScaleDraw)
    134133
    135134    class PrivateData;
    136     PrivateData *d_data;
     135    PrivateData* m_data;
    137136};
    138137
  • trunk/BNC/qwt/qwt_abstract_slider.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_abstract_slider.h"
    11 #include "qwt_abstract_scale_draw.h"
     11#include "qwt_scale_map.h"
     12#include "qwt_scale_div.h"
    1213#include "qwt_math.h"
    13 #include "qwt_scale_map.h"
     14
    1415#include <qevent.h>
    1516
    16 #if QT_VERSION < 0x040601
    17 #define qFabs(x) ::fabs(x)
    18 #endif
    19 
    2017static double qwtAlignToScaleDiv(
    21     const QwtAbstractSlider *slider, double value )
    22 {
    23     const QwtScaleDiv &sd = slider->scaleDiv();
     18    const QwtAbstractSlider* slider, double value )
     19{
     20    const QwtScaleDiv& sd = slider->scaleDiv();
    2421
    2522    const int tValue = slider->transform( value );
    … …  
    3330    for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ )
    3431    {
    35         const QList<double> ticks = sd.ticks( i );
     32        const QList< double > ticks = sd.ticks( i );
    3633        for ( int j = 0; j < ticks.size(); j++ )
    3734        {
    … …  
    4643class QwtAbstractSlider::PrivateData
    4744{
    48 public:
    49     PrivateData():
    50         isScrolling( false ),
    51         isTracking( true ),
    52         pendingValueChanged( false ),
    53         readOnly( false ),
    54         totalSteps( 100 ),
    55         singleSteps( 1 ),
    56         pageSteps( 10 ),
    57         stepAlignment( true ),
    58         isValid( false ),
    59         value( 0.0 ),
    60         wrapping( false ),
    61         invertedControls( false )
     45  public:
     46    PrivateData()
     47        : isScrolling( false )
     48        , isTracking( true )
     49        , pendingValueChanged( false )
     50        , readOnly( false )
     51        , totalSteps( 100 )
     52        , singleSteps( 1 )
     53        , pageSteps( 10 )
     54        , stepAlignment( true )
     55        , isValid( false )
     56        , value( 0.0 )
     57        , wrapping( false )
     58        , invertedControls( false )
    6259    {
    6360    }
    … …  
    8279
    8380/*!
    84   \brief Constructor
    85 
    86   The scale is initialized to [0.0, 100.0], the
    87   number of steps is set to 100 with 1 and 10 and single
    88   an page step sizes. Step alignment is enabled.
    89 
    90   The initial value is invalid.
    91 
    92   \param parent Parent widget
    93 */
    94 QwtAbstractSlider::QwtAbstractSlider( QWidget *parent ):
    95     QwtAbstractScale( parent )
    96 {
    97     d_data = new QwtAbstractSlider::PrivateData;
     81   \brief Constructor
     82
     83   The scale is initialized to [0.0, 100.0], the
     84   number of steps is set to 100 with 1 and 10 and single
     85   an page step sizes. Step alignment is enabled.
     86
     87   The initial value is invalid.
     88
     89   \param parent Parent widget
     90 */
     91QwtAbstractSlider::QwtAbstractSlider( QWidget* parent )
     92    : QwtAbstractScale( parent )
     93{
     94    m_data = new QwtAbstractSlider::PrivateData;
    9895
    9996    setScale( 0.0, 100.0 );
    … …  
    104101QwtAbstractSlider::~QwtAbstractSlider()
    105102{
    106     delete d_data;
    107 }
    108 
    109 /*!
    110   Set the value to be valid/invalid
    111 
    112   \param on When true, the value is invalidated
    113 
    114   \sa setValue()
    115 */
     103    delete m_data;
     104}
     105
     106/*!
     107   Set the value to be valid/invalid
     108
     109   \param on When true, the value is invalidated
     110
     111   \sa setValue()
     112 */
    116113void QwtAbstractSlider::setValid( bool on )
    117114{
    118     if ( on != d_data->isValid )
    119     {
    120         d_data->isValid = on;
     115    if ( on != m_data->isValid )
     116    {
     117        m_data->isValid = on;
    121118        sliderChange();
    122119
    123         Q_EMIT valueChanged( d_data->value );
     120        Q_EMIT valueChanged( m_data->value );
    124121    }
    125122}
    … …  
    128125bool QwtAbstractSlider::isValid() const
    129126{
    130     return d_data->isValid;
    131 }
    132 
    133 /*!
    134   En/Disable read only mode
    135 
    136   In read only mode the slider can't be controlled by mouse
    137   or keyboard.
    138 
    139   \param on Enables in case of true
    140   \sa isReadOnly()
    141 
    142   \warning The focus policy is set to Qt::StrongFocus or Qt::NoFocus
    143 */
     127    return m_data->isValid;
     128}
     129
     130/*!
     131   En/Disable read only mode
     132
     133   In read only mode the slider can't be controlled by mouse
     134   or keyboard.
     135
     136   \param on Enables in case of true
     137   \sa isReadOnly()
     138
     139   \warning The focus policy is set to Qt::StrongFocus or Qt::NoFocus
     140 */
    144141void QwtAbstractSlider::setReadOnly( bool on )
    145142{
    146     if ( d_data->readOnly != on )
    147     {
    148         d_data->readOnly = on;
     143    if ( m_data->readOnly != on )
     144    {
     145        m_data->readOnly = on;
    149146        setFocusPolicy( on ? Qt::StrongFocus : Qt::NoFocus );
    150147
    … …  
    154151
    155152/*!
    156   In read only mode the slider can't be controlled by mouse
    157   or keyboard.
    158 
    159   \return true if read only
    160   \sa setReadOnly()
    161 */
     153   In read only mode the slider can't be controlled by mouse
     154   or keyboard.
     155
     156   \return true if read only
     157   \sa setReadOnly()
     158 */
    162159bool QwtAbstractSlider::isReadOnly() const
    163160{
    164     return d_data->readOnly;
    165 }
    166 
    167 /*!
    168   \brief Enables or disables tracking.
    169 
    170   If tracking is enabled, the slider emits the valueChanged()
    171   signal while the movable part of the slider is being dragged.
    172   If tracking is disabled, the slider emits the valueChanged() signal
    173   only when the user releases the slider.
    174 
    175   Tracking is enabled by default.
    176   \param on \c true (enable) or \c false (disable) tracking.
    177 
    178   \sa isTracking(), sliderMoved()
    179 */
     161    return m_data->readOnly;
     162}
     163
     164/*!
     165   \brief Enables or disables tracking.
     166
     167   If tracking is enabled, the slider emits the valueChanged()
     168   signal while the movable part of the slider is being dragged.
     169   If tracking is disabled, the slider emits the valueChanged() signal
     170   only when the user releases the slider.
     171
     172   Tracking is enabled by default.
     173   \param on \c true (enable) or \c false (disable) tracking.
     174
     175   \sa isTracking(), sliderMoved()
     176 */
    180177void QwtAbstractSlider::setTracking( bool on )
    181178{
    182     d_data->isTracking = on;
    183 }
    184 
    185 /*!
    186   \return True, when tracking has been enabled
    187   \sa setTracking()
    188 */
     179    m_data->isTracking = on;
     180}
     181
     182/*!
     183   \return True, when tracking has been enabled
     184   \sa setTracking()
     185 */
    189186bool QwtAbstractSlider::isTracking() const
    190187{
    191     return d_data->isTracking;
     188    return m_data->isTracking;
    192189}
    193190
    … …  
    195192   Mouse press event handler
    196193   \param event Mouse event
    197 */
    198 void QwtAbstractSlider::mousePressEvent( QMouseEvent *event )
     194 */
     195void QwtAbstractSlider::mousePressEvent( QMouseEvent* event )
    199196{
    200197    if ( isReadOnly() )
    … …  
    204201    }
    205202
    206     if ( !d_data->isValid || lowerBound() == upperBound() )
     203    if ( !m_data->isValid || lowerBound() == upperBound() )
    207204        return;
    208205
    209     d_data->isScrolling = isScrollPosition( event->pos() );
    210 
    211     if ( d_data->isScrolling )
    212     {
    213         d_data->pendingValueChanged = false;
     206    m_data->isScrolling = isScrollPosition( event->pos() );
     207
     208    if ( m_data->isScrolling )
     209    {
     210        m_data->pendingValueChanged = false;
    214211
    215212        Q_EMIT sliderPressed();
    … …  
    220217   Mouse Move Event handler
    221218   \param event Mouse event
    222 */
    223 void QwtAbstractSlider::mouseMoveEvent( QMouseEvent *event )
     219 */
     220void QwtAbstractSlider::mouseMoveEvent( QMouseEvent* event )
    224221{
    225222    if ( isReadOnly() )
    … …  
    229226    }
    230227
    231     if ( d_data->isValid && d_data->isScrolling )
     228    if ( m_data->isValid && m_data->isScrolling )
    232229    {
    233230        double value = scrolledTo( event->pos() );
    234         if ( value != d_data->value )
     231        if ( value != m_data->value )
    235232        {
    236233            value = boundedValue( value );
    237234
    238             if ( d_data->stepAlignment )
     235            if ( m_data->stepAlignment )
    239236            {
    240237                value = alignedValue( value );
    … …  
    245242            }
    246243
    247             if ( value != d_data->value )
     244            if ( value != m_data->value )
    248245            {
    249                 d_data->value = value;
     246                m_data->value = value;
    250247
    251248                sliderChange();
    252249
    253                 Q_EMIT sliderMoved( d_data->value );
    254 
    255                 if ( d_data->isTracking )
    256                     Q_EMIT valueChanged( d_data->value );
     250                Q_EMIT sliderMoved( m_data->value );
     251
     252                if ( m_data->isTracking )
     253                    Q_EMIT valueChanged( m_data->value );
    257254                else
    258                     d_data->pendingValueChanged = true;
     255                    m_data->pendingValueChanged = true;
    259256            }
    260257        }
    … …  
    265262   Mouse Release Event handler
    266263   \param event Mouse event
    267 */
    268 void QwtAbstractSlider::mouseReleaseEvent( QMouseEvent *event )
     264 */
     265void QwtAbstractSlider::mouseReleaseEvent( QMouseEvent* event )
    269266{
    270267    if ( isReadOnly() )
    … …  
    274271    }
    275272
    276     if ( d_data->isScrolling && d_data->isValid )
    277     {
    278         d_data->isScrolling = false;
    279 
    280         if ( d_data->pendingValueChanged )
    281             Q_EMIT valueChanged( d_data->value );
     273    if ( m_data->isScrolling && m_data->isValid )
     274    {
     275        m_data->isScrolling = false;
     276
     277        if ( m_data->pendingValueChanged )
     278            Q_EMIT valueChanged( m_data->value );
    282279
    283280        Q_EMIT sliderReleased();
    … …  
    296293
    297294   \param event Wheel event
    298 */
    299 void QwtAbstractSlider::wheelEvent( QWheelEvent *event )
     295 */
     296void QwtAbstractSlider::wheelEvent( QWheelEvent* event )
    300297{
    301298    if ( isReadOnly() )
    … …  
    305302    }
    306303
    307     if ( !d_data->isValid || d_data->isScrolling )
     304    if ( !m_data->isValid || m_data->isScrolling )
    308305        return;
    309306
     307#if QT_VERSION < 0x050000
     308    const int wheelDelta = event->delta();
     309#else
     310    const QPoint delta = event->angleDelta();
     311    const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
     312        ? delta.x() : delta.y();
     313#endif
     314
    310315    int numSteps = 0;
    311316
    312     if ( ( event->modifiers() & Qt::ControlModifier) ||
     317    if ( ( event->modifiers() & Qt::ControlModifier ) ||
    313318        ( event->modifiers() & Qt::ShiftModifier ) )
    314319    {
    315320        // one page regardless of delta
    316         numSteps = d_data->pageSteps;
    317         if ( event->delta() < 0 )
     321        numSteps = m_data->pageSteps;
     322        if ( wheelDelta < 0 )
    318323            numSteps = -numSteps;
    319324    }
    320325    else
    321326    {
    322         const int numTurns = ( event->delta() / 120 );
    323         numSteps = numTurns * d_data->singleSteps;
    324     }
    325 
    326     if ( d_data->invertedControls )
     327        const int numTurns = ( wheelDelta / 120 );
     328        numSteps = numTurns * m_data->singleSteps;
     329    }
     330
     331    if ( m_data->invertedControls )
    327332        numSteps = -numSteps;
    328333
    329     const double value = incrementedValue( d_data->value, numSteps );
    330     if ( value != d_data->value )
    331     {
    332         d_data->value = value;
     334    const double value = incrementedValue( m_data->value, numSteps );
     335    if ( value != m_data->value )
     336    {
     337        m_data->value = value;
    333338        sliderChange();
    334339
    335         Q_EMIT sliderMoved( d_data->value );
    336         Q_EMIT valueChanged( d_data->value );
    337     }
    338 }
    339 
    340 /*!
    341   Handles key events
    342 
    343   QwtAbstractSlider handles the following keys:
    344 
    345   - Qt::Key_Left\n
     340        Q_EMIT sliderMoved( m_data->value );
     341        Q_EMIT valueChanged( m_data->value );
     342    }
     343}
     344
     345/*!
     346   Handles key events
     347
     348   QwtAbstractSlider handles the following keys:
     349
     350   - Qt::Key_Left\n
    346351    Add/Subtract singleSteps() in direction to lowerBound();
    347   - Qt::Key_Right\n
     352   - Qt::Key_Right\n
    348353    Add/Subtract singleSteps() in direction to upperBound();
    349   - Qt::Key_Down\n
     354   - Qt::Key_Down\n
    350355    Subtract singleSteps(), when invertedControls() is false
    351   - Qt::Key_Up\n
     356   - Qt::Key_Up\n
    352357    Add singleSteps(), when invertedControls() is false
    353   - Qt::Key_PageDown\n
     358   - Qt::Key_PageDown\n
    354359    Subtract pageSteps(), when invertedControls() is false
    355   - Qt::Key_PageUp\n
     360   - Qt::Key_PageUp\n
    356361    Add pageSteps(), when invertedControls() is false
    357   - Qt::Key_Home\n
     362   - Qt::Key_Home\n
    358363    Set the value to the minimum()
    359   - Qt::Key_End\n
     364   - Qt::Key_End\n
    360365    Set the value to the maximum()
    361366
    362   \param event Key event
    363   \sa isReadOnly()
    364 */
    365 void QwtAbstractSlider::keyPressEvent( QKeyEvent *event )
     367   \param event Key event
     368   \sa isReadOnly()
     369 */
     370void QwtAbstractSlider::keyPressEvent( QKeyEvent* event )
    366371{
    367372    if ( isReadOnly() )
    … …  
    371376    }
    372377
    373     if ( !d_data->isValid || d_data->isScrolling )
     378    if ( !m_data->isValid || m_data->isScrolling )
    374379        return;
    375380
    376381    int numSteps = 0;
    377     double value = d_data->value;
     382    double value = m_data->value;
    378383
    379384    switch ( event->key() )
    … …  
    381386        case Qt::Key_Left:
    382387        {
    383             numSteps = -static_cast<int>( d_data->singleSteps );
     388            numSteps = -static_cast< int >( m_data->singleSteps );
    384389            if ( isInverted() )
    385390                numSteps = -numSteps;
    … …  
    389394        case Qt::Key_Right:
    390395        {
    391             numSteps = d_data->singleSteps;
     396            numSteps = m_data->singleSteps;
    392397            if ( isInverted() )
    393398                numSteps = -numSteps;
    … …  
    397402        case Qt::Key_Down:
    398403        {
    399             numSteps = -static_cast<int>( d_data->singleSteps );
    400             if ( d_data->invertedControls )
     404            numSteps = -static_cast< int >( m_data->singleSteps );
     405            if ( m_data->invertedControls )
    401406                numSteps = -numSteps;
    402407            break;
    … …  
    404409        case Qt::Key_Up:
    405410        {
    406             numSteps = d_data->singleSteps;
    407             if ( d_data->invertedControls )
     411            numSteps = m_data->singleSteps;
     412            if ( m_data->invertedControls )
    408413                numSteps = -numSteps;
    409414
    … …  
    412417        case Qt::Key_PageUp:
    413418        {
    414             numSteps = d_data->pageSteps;
    415             if ( d_data->invertedControls )
     419            numSteps = m_data->pageSteps;
     420            if ( m_data->invertedControls )
    416421                numSteps = -numSteps;
    417422            break;
    … …  
    419424        case Qt::Key_PageDown:
    420425        {
    421             numSteps = -static_cast<int>( d_data->pageSteps );
    422             if ( d_data->invertedControls )
     426            numSteps = -static_cast< int >( m_data->pageSteps );
     427            if ( m_data->invertedControls )
    423428                numSteps = -numSteps;
    424429            break;
    … …  
    434439            break;
    435440        }
    436         default:;
     441        default:
    437442        {
    438443            event->ignore();
    … …  
    442447    if ( numSteps != 0 )
    443448    {
    444         value = incrementedValue( d_data->value, numSteps );
    445     }
    446 
    447     if ( value != d_data->value )
    448     {
    449         d_data->value = value;
     449        value = incrementedValue( m_data->value, numSteps );
     450    }
     451
     452    if ( value != m_data->value )
     453    {
     454        m_data->value = value;
    450455        sliderChange();
    451456
    452         Q_EMIT sliderMoved( d_data->value );
    453         Q_EMIT valueChanged( d_data->value );
    454     }
    455 }
    456 
    457 /*!
    458   \brief Set the number of steps
    459 
    460   The range of the slider is divided into a number of steps from
    461   which the value increments according to user inputs depend.
    462 
    463   The default setting is 100.
    464 
    465   \param stepCount Number of steps
    466 
    467   \sa totalSteps(), setSingleSteps(), setPageSteps()
     457        Q_EMIT sliderMoved( m_data->value );
     458        Q_EMIT valueChanged( m_data->value );
     459    }
     460}
     461
     462/*!
     463   \brief Set the number of steps
     464
     465   The range of the slider is divided into a number of steps from
     466   which the value increments according to user inputs depend.
     467
     468   The default setting is 100.
     469
     470   \param stepCount Number of steps
     471
     472   \sa totalSteps(), setSingleSteps(), setPageSteps()
    468473 */
    469474void QwtAbstractSlider::setTotalSteps( uint stepCount )
    470475{
    471     d_data->totalSteps = stepCount;
    472 }
    473 
    474 /*!
    475   \return Number of steps
    476   \sa setTotalSteps(), singleSteps(), pageSteps()
     476    m_data->totalSteps = stepCount;
     477}
     478
     479/*!
     480   \return Number of steps
     481   \sa setTotalSteps(), singleSteps(), pageSteps()
    477482 */
    478483uint QwtAbstractSlider::totalSteps() const
    479484{
    480     return d_data->totalSteps;
    481 }
    482 
    483 /*!
    484   \brief Set the number of steps for a single increment
    485 
    486   The range of the slider is divided into a number of steps from
    487   which the value increments according to user inputs depend.
    488 
    489   \param stepCount Number of steps
    490 
    491   \sa singleSteps(), setTotalSteps(), setPageSteps()
     485    return m_data->totalSteps;
     486}
     487
     488/*!
     489   \brief Set the number of steps for a single increment
     490
     491   The range of the slider is divided into a number of steps from
     492   which the value increments according to user inputs depend.
     493
     494   \param stepCount Number of steps
     495
     496   \sa singleSteps(), setTotalSteps(), setPageSteps()
    492497 */
    493498
    494499void QwtAbstractSlider::setSingleSteps( uint stepCount )
    495500{
    496     d_data->singleSteps = stepCount;
    497 }
    498 
    499 /*!
    500   \return Number of steps
    501   \sa setSingleSteps(), totalSteps(), pageSteps()
     501    m_data->singleSteps = stepCount;
     502}
     503
     504/*!
     505   \return Number of steps
     506   \sa setSingleSteps(), totalSteps(), pageSteps()
    502507 */
    503508uint QwtAbstractSlider::singleSteps() const
    504509{
    505     return d_data->singleSteps;
    506 }
    507 
    508 /*!
    509   \brief Set the number of steps for a page increment
    510 
    511   The range of the slider is divided into a number of steps from
    512   which the value increments according to user inputs depend.
    513 
    514   \param stepCount Number of steps
    515 
    516   \sa pageSteps(), setTotalSteps(), setSingleSteps()
     510    return m_data->singleSteps;
     511}
     512
     513/*!
     514   \brief Set the number of steps for a page increment
     515
     516   The range of the slider is divided into a number of steps from
     517   which the value increments according to user inputs depend.
     518
     519   \param stepCount Number of steps
     520
     521   \sa pageSteps(), setTotalSteps(), setSingleSteps()
    517522 */
    518523
    519524void QwtAbstractSlider::setPageSteps( uint stepCount )
    520525{
    521     d_data->pageSteps = stepCount;
    522 }
    523 
    524 /*!
    525   \return Number of steps
    526   \sa setPageSteps(), totalSteps(), singleSteps()
     526    m_data->pageSteps = stepCount;
     527}
     528
     529/*!
     530   \return Number of steps
     531   \sa setPageSteps(), totalSteps(), singleSteps()
    527532 */
    528533uint QwtAbstractSlider::pageSteps() const
    529534{
    530     return d_data->pageSteps;
    531 }
    532 
    533 /*!
    534   \brief Enable step alignment
    535 
    536   When step alignment is enabled values resulting from slider
    537   movements are aligned to the step size.
    538 
    539   \param on Enable step alignment when true
    540   \sa stepAlignment()
    541 */
     535    return m_data->pageSteps;
     536}
     537
     538/*!
     539   \brief Enable step alignment
     540
     541   When step alignment is enabled values resulting from slider
     542   movements are aligned to the step size.
     543
     544   \param on Enable step alignment when true
     545   \sa stepAlignment()
     546 */
    542547void QwtAbstractSlider::setStepAlignment( bool on )
    543548{
    544     if ( on != d_data->stepAlignment )
    545     {
    546         d_data->stepAlignment = on;
    547     }
    548 }
    549 
    550 /*!
    551   \return True, when step alignment is enabled
    552   \sa setStepAlignment()
     549    if ( on != m_data->stepAlignment )
     550    {
     551        m_data->stepAlignment = on;
     552    }
     553}
     554
     555/*!
     556   \return True, when step alignment is enabled
     557   \sa setStepAlignment()
    553558 */
    554559bool QwtAbstractSlider::stepAlignment() const
    555560{
    556     return d_data->stepAlignment;
    557 }
    558 
    559 /*!
    560   Set the slider to the specified value
    561 
    562   \param value New value
    563   \sa setValid(), sliderChange(), valueChanged()
    564 */
     561    return m_data->stepAlignment;
     562}
     563
     564/*!
     565   Set the slider to the specified value
     566
     567   \param value New value
     568   \sa setValid(), sliderChange(), valueChanged()
     569 */
    565570void QwtAbstractSlider::setValue( double value )
    566571{
    567572    value = qBound( minimum(), value, maximum() );
    568573
    569     const bool changed = ( d_data->value != value ) || !d_data->isValid;
    570 
    571     d_data->value = value;
    572     d_data->isValid = true;
     574    const bool changed = ( m_data->value != value ) || !m_data->isValid;
     575
     576    m_data->value = value;
     577    m_data->isValid = true;
    573578
    574579    if ( changed )
    575580    {
    576581        sliderChange();
    577         Q_EMIT valueChanged( d_data->value );
     582        Q_EMIT valueChanged( m_data->value );
    578583    }
    579584}
    … …  
    582587double QwtAbstractSlider::value() const
    583588{
    584     return d_data->value;
    585 }
    586 
    587 /*!
    588   If wrapping is true stepping up from upperBound() value will
    589   take you to the minimum() value and vice versa.
    590 
    591   \param on En/Disable wrapping
    592   \sa wrapping()
    593 */
     589    return m_data->value;
     590}
     591
     592/*!
     593   If wrapping is true stepping up from upperBound() value will
     594   take you to the minimum() value and vice versa.
     595
     596   \param on En/Disable wrapping
     597   \sa wrapping()
     598 */
    594599void QwtAbstractSlider::setWrapping( bool on )
    595600{
    596     d_data->wrapping = on;
    597 }
    598 
    599 /*!
    600   \return True, when wrapping is set
    601   \sa setWrapping()
     601    m_data->wrapping = on;
     602}
     603
     604/*!
     605   \return True, when wrapping is set
     606   \sa setWrapping()
    602607 */
    603608bool QwtAbstractSlider::wrapping() const
    604609{
    605     return d_data->wrapping;
    606 }
    607 
    608 /*!
    609   Invert wheel and key events
    610 
    611   Usually scrolling the mouse wheel "up" and using keys like page
    612   up will increase the slider's value towards its maximum.
    613   When invertedControls() is enabled the value is scrolled
    614   towards its minimum.
    615 
    616   Inverting the controls might be f.e. useful for a vertical slider
    617   with an inverted scale ( decreasing from top to bottom ).
    618 
    619   \param on Invert controls, when true
    620 
    621   \sa invertedControls(), keyEvent(), wheelEvent()
     610    return m_data->wrapping;
     611}
     612
     613/*!
     614   Invert wheel and key events
     615
     616   Usually scrolling the mouse wheel "up" and using keys like page
     617   up will increase the slider's value towards its maximum.
     618   When invertedControls() is enabled the value is scrolled
     619   towards its minimum.
     620
     621   Inverting the controls might be f.e. useful for a vertical slider
     622   with an inverted scale ( decreasing from top to bottom ).
     623
     624   \param on Invert controls, when true
     625
     626   \sa invertedControls(), keyEvent(), wheelEvent()
    622627 */
    623628void QwtAbstractSlider::setInvertedControls( bool on )
    624629{
    625     d_data->invertedControls = on;
    626 }
    627 
    628 /*!
    629  \return True, when the controls are inverted
    630  \sa setInvertedControls()
     630    m_data->invertedControls = on;
     631}
     632
     633/*!
     634   \return True, when the controls are inverted
     635   \sa setInvertedControls()
    631636 */
    632637bool QwtAbstractSlider::invertedControls() const
    633638{
    634     return d_data->invertedControls;
    635 }
    636 
    637 /*!
    638   Increment the slider
    639 
    640   The step size depends on the number of totalSteps()
    641 
    642   \param stepCount Number of steps
    643   \sa setTotalSteps(), incrementedValue()
     639    return m_data->invertedControls;
     640}
     641
     642/*!
     643   Increment the slider
     644
     645   The step size depends on the number of totalSteps()
     646
     647   \param stepCount Number of steps
     648   \sa setTotalSteps(), incrementedValue()
    644649 */
    645650void QwtAbstractSlider::incrementValue( int stepCount )
    646651{
    647652    const double value = incrementedValue(
    648         d_data->value, stepCount );
    649 
    650     if ( value != d_data->value )
    651     {
    652         d_data->value = value;
     653        m_data->value, stepCount );
     654
     655    if ( value != m_data->value )
     656    {
     657        m_data->value = value;
    653658        sliderChange();
    654659    }
    … …  
    656661
    657662/*!
    658   Increment a value
    659 
    660   \param value Value
    661   \param stepCount Number of steps
    662 
    663   \return Incremented value
     663   Increment a value
     664
     665   \param value Value
     666   \param stepCount Number of steps
     667
     668   \return Incremented value
    664669 */
    665670double QwtAbstractSlider::incrementedValue(
    666671    double value, int stepCount ) const
    667672{
    668     if ( d_data->totalSteps == 0 )
     673    if ( m_data->totalSteps == 0 )
    669674        return value;
    670675
    671     const QwtTransform *transformation =
     676    const QwtTransform* transformation =
    672677        scaleMap().transformation();
    673678
    … …  
    675680    {
    676681        const double range = maximum() - minimum();
    677         value += stepCount * range / d_data->totalSteps;
     682        value += stepCount * range / m_data->totalSteps;
    678683    }
    679684    else
    680685    {
    681686        QwtScaleMap map = scaleMap();
    682         map.setPaintInterval( 0, d_data->totalSteps );
    683 
    684         // we need equidant steps according to
     687        map.setPaintInterval( 0, m_data->totalSteps );
     688
     689        // we need equidistant steps according to
    685690        // paint device coordinates
    686691        const double range = transformation->transform( maximum() )
    687692            - transformation->transform( minimum() );
    688693
    689         const double stepSize = range / d_data->totalSteps;
     694        const double stepSize = range / m_data->totalSteps;
    690695
    691696        double v = transformation->transform( value );
    692697
    693698        v = qRound( v / stepSize ) * stepSize;
    694         v += stepCount * range / d_data->totalSteps;
     699        v += stepCount * range / m_data->totalSteps;
    695700
    696701        value = transformation->invTransform( v );
    … …  
    699704    value = boundedValue( value );
    700705
    701     if ( d_data->stepAlignment )
     706    if ( m_data->stepAlignment )
    702707        value = alignedValue( value );
    703708
    … …  
    710715    const double vmax = maximum();
    711716
    712     if ( d_data->wrapping && vmin != vmax )
    713     {
    714         const int fullCircle = 360 * 16;
    715 
    716         const double pd = scaleMap().pDist();
    717         if ( int( pd / fullCircle ) * fullCircle == pd )
     717    if ( m_data->wrapping && vmin != vmax )
     718    {
     719        if ( qFuzzyCompare( scaleMap().pDist(), 360.0 ) )
    718720        {
    719721            // full circle scales: min and max are the same
    720             const double range = vmax - vmin;
    721 
    722             if ( value < vmin )
     722
     723            if ( qFuzzyCompare( value, vmax ) )
    723724            {
    724                 value += ::ceil( ( vmin - value ) / range ) * range;
     725                value = vmin;
    725726            }
    726             else if ( value > vmax )
     727            else
    727728            {
    728                 value -= ::ceil( ( value - vmax ) / range ) * range;
     729                const double range = vmax - vmin;
     730
     731                if ( value < vmin )
     732                {
     733                    value += std::ceil( ( vmin - value ) / range ) * range;
     734                }
     735                else if ( value > vmax )
     736                {
     737                    value -= std::ceil( ( value - vmax ) / range ) * range;
     738                }
    729739            }
    730740        }
    … …  
    747757double QwtAbstractSlider::alignedValue( double value ) const
    748758{
    749     if ( d_data->totalSteps == 0 )
     759    if ( m_data->totalSteps == 0 )
    750760        return value;
    751761
    … …  
    754764    if ( scaleMap().transformation() == NULL )
    755765    {
    756         stepSize = ( maximum() - minimum() ) / d_data->totalSteps;
     766        stepSize = ( maximum() - minimum() ) / m_data->totalSteps;
    757767        if ( stepSize > 0.0 )
    758768        {
    … …  
    763773    else
    764774    {
    765         stepSize = ( scaleMap().p2() - scaleMap().p1() ) / d_data->totalSteps;
     775        stepSize = ( scaleMap().p2() - scaleMap().p1() ) / m_data->totalSteps;
    766776
    767777        if ( stepSize > 0.0 )
    … …  
    797807
    798808/*!
    799   Update the slider according to modifications of the scale
     809   Update the slider according to modifications of the scale
    800810 */
    801811void QwtAbstractSlider::scaleChange()
    802812{
    803     const double value = qBound( minimum(), d_data->value, maximum() );
    804 
    805     const bool changed = ( value != d_data->value );
     813    const double value = qBound( minimum(), m_data->value, maximum() );
     814
     815    const bool changed = ( value != m_data->value );
    806816    if ( changed )
    807817    {
    808         d_data->value = value;
    809     }
    810 
    811     if ( d_data->isValid || changed )
    812         Q_EMIT valueChanged( d_data->value );
     818        m_data->value = value;
     819    }
     820
     821    if ( m_data->isValid || changed )
     822        Q_EMIT valueChanged( m_data->value );
    813823
    814824    updateGeometry();
    … …  
    821831    update();
    822832}
     833
     834#include "moc_qwt_abstract_slider.cpp"
  • trunk/BNC/qwt/qwt_abstract_slider.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1515
    1616/*!
    17   \brief An abstract base class for slider widgets with a scale
     17   \brief An abstract base class for slider widgets with a scale
    1818
    19   A slider widget displays a value according to a scale.
    20   The class is designed as a common super class for widgets like
    21   QwtKnob, QwtDial and QwtSlider.
     19   A slider widget displays a value according to a scale.
     20   The class is designed as a common super class for widgets like
     21   QwtKnob, QwtDial and QwtSlider.
    2222
    23   When the slider is nor readOnly() its value can be modified
    24   by keyboard, mouse and wheel inputs.
     23   When the slider is nor readOnly() its value can be modified
     24   by keyboard, mouse and wheel inputs.
    2525
    26   The range of the slider is divided into a number of steps from
    27   which the value increments according to user inputs depend.
    28   Only for linear scales the number of steps correspond with
    29   a fixed step size.
    30 */
     26   The range of the slider is divided into a number of steps from
     27   which the value increments according to user inputs depend.
     28   Only for linear scales the number of steps correspond with
     29   a fixed step size.
     30 */
    3131
    32 class QWT_EXPORT QwtAbstractSlider: public QwtAbstractScale
     32class QWT_EXPORT QwtAbstractSlider : public QwtAbstractScale
    3333{
    3434    Q_OBJECT
    3535
    36     Q_PROPERTY( double value READ value WRITE setValue )
     36    Q_PROPERTY( double value READ value WRITE setValue NOTIFY valueChanged USER true )
    3737
    3838    Q_PROPERTY( uint totalSteps READ totalSteps WRITE setTotalSteps )
    … …  
    4747    Q_PROPERTY( bool invertedControls READ invertedControls WRITE setInvertedControls )
    4848
    49 public:
    50     explicit QwtAbstractSlider( QWidget *parent = NULL );
     49  public:
     50    explicit QwtAbstractSlider( QWidget* parent = NULL );
    5151    virtual ~QwtAbstractSlider();
    5252
    … …  
    8080    bool invertedControls() const;
    8181
    82 public Q_SLOTS:
     82  public Q_SLOTS:
    8383    void setValue( double value );
    8484
    85 Q_SIGNALS:
     85  Q_SIGNALS:
    8686
    8787    /*!
    88       \brief Notify a change of value.
     88       \brief Notify a change of value.
    8989
    90       When tracking is enabled (default setting),
    91       this signal will be emitted every time the value changes.
     90       When tracking is enabled (default setting),
     91       this signal will be emitted every time the value changes.
    9292
    93       \param value New value
     93       \param value New value
    9494
    95       \sa setTracking(), sliderMoved()
    96     */
     95       \sa setTracking(), sliderMoved()
     96     */
    9797    void valueChanged( double value );
    9898
    9999    /*!
    100       This signal is emitted when the user presses the
    101       movable part of the slider.
    102     */
     100       This signal is emitted when the user presses the
     101       movable part of the slider.
     102     */
    103103    void sliderPressed();
    104104
    105105    /*!
    106       This signal is emitted when the user releases the
    107       movable part of the slider.
    108     */
     106       This signal is emitted when the user releases the
     107       movable part of the slider.
     108     */
    109109    void sliderReleased();
    110110
    111111    /*!
    112       This signal is emitted when the user moves the
    113       slider with the mouse.
     112       This signal is emitted when the user moves the
     113       slider with the mouse.
    114114
    115       \param value New value
     115       \param value New value
    116116
    117       \sa valueChanged()
    118     */
     117       \sa valueChanged()
     118     */
    119119    void sliderMoved( double value );
    120120
    121 protected:
    122     virtual void mousePressEvent( QMouseEvent * );
    123     virtual void mouseReleaseEvent( QMouseEvent * );
    124     virtual void mouseMoveEvent( QMouseEvent * );
    125     virtual void keyPressEvent( QKeyEvent * );
    126     virtual void wheelEvent( QWheelEvent * );
     121  protected:
     122    virtual void mousePressEvent( QMouseEvent* ) QWT_OVERRIDE;
     123    virtual void mouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE;
     124    virtual void mouseMoveEvent( QMouseEvent* ) QWT_OVERRIDE;
     125    virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE;
     126    virtual void wheelEvent( QWheelEvent* ) QWT_OVERRIDE;
    127127
    128128    /*!
    129       \brief Determine what to do when the user presses a mouse button.
     129       \brief Determine what to do when the user presses a mouse button.
    130130
    131       \param pos Mouse position
     131       \param pos Mouse position
    132132
    133       \retval True, when pos is a valid scroll position
    134       \sa scrolledTo()
    135     */
    136     virtual bool isScrollPosition( const QPoint &pos ) const = 0;
     133       \retval True, when pos is a valid scroll position
     134       \sa scrolledTo()
     135     */
     136    virtual bool isScrollPosition( const QPoint& pos ) const = 0;
    137137
    138138    /*!
    139       \brief Determine the value for a new position of the
     139       \brief Determine the value for a new position of the
    140140             movable part of the slider
    141141
    142       \param pos Mouse position
     142       \param pos Mouse position
    143143
    144       \return Value for the mouse position
    145       \sa isScrollPosition()
    146     */
    147     virtual double scrolledTo( const QPoint &pos ) const = 0;
     144       \return Value for the mouse position
     145       \sa isScrollPosition()
     146     */
     147    virtual double scrolledTo( const QPoint& pos ) const = 0;
    148148
    149149    void incrementValue( int stepCount );
    150150
    151     virtual void scaleChange();
     151    virtual void scaleChange() QWT_OVERRIDE;
    152152
    153 protected:
     153  protected:
    154154    virtual void sliderChange();
    155155
    … …  
    157157        double value, int stepCount ) const;
    158158
    159 private:
     159  private:
    160160    double alignedValue( double ) const;
    161161    double boundedValue( double ) const;
    162162
    163163    class PrivateData;
    164     PrivateData *d_data;
     164    PrivateData* m_data;
    165165};
    166166
  • trunk/BNC/qwt/qwt_analog_clock.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_analog_clock.h"
     11#include "qwt_dial_needle.h"
    1112#include "qwt_round_scale_draw.h"
    12 #include <qmath.h>
     13#include "qwt_text.h"
     14#include "qwt_math.h"
     15
    1316#include <qlocale.h>
    14 
    15 class QwtAnalogClockScaleDraw: public QwtRoundScaleDraw
    16 {
    17 public:
    18     QwtAnalogClockScaleDraw()
    19     {
    20         setSpacing( 8 );
    21 
    22         enableComponent( QwtAbstractScaleDraw::Backbone, false );
    23 
    24         setTickLength( QwtScaleDiv::MinorTick, 2 );
    25         setTickLength( QwtScaleDiv::MediumTick, 4 );
    26         setTickLength( QwtScaleDiv::MajorTick, 8 );
    27 
    28         setPenWidth( 1 );
    29     }
    30 
    31     virtual QwtText label( double value ) const
    32     {
    33         if ( qFuzzyCompare( value + 1.0, 1.0 ) )
    34             value = 60.0 * 60.0 * 12.0;
    35 
    36         return QLocale().toString( qRound( value / ( 60.0 * 60.0 ) ) );
    37     }
    38 };
    39 
    40 /*!
    41   Constructor
    42   \param parent Parent widget
    43 */
    44 QwtAnalogClock::QwtAnalogClock( QWidget *parent ):
    45     QwtDial( parent )
     17#include <qdatetime.h>
     18
     19namespace
     20{
     21    class QwtAnalogClockScaleDraw QWT_FINAL : public QwtRoundScaleDraw
     22    {
     23      public:
     24        QwtAnalogClockScaleDraw()
     25        {
     26            setSpacing( 8 );
     27
     28            enableComponent( QwtAbstractScaleDraw::Backbone, false );
     29
     30            setTickLength( QwtScaleDiv::MinorTick, 2 );
     31            setTickLength( QwtScaleDiv::MediumTick, 4 );
     32            setTickLength( QwtScaleDiv::MajorTick, 8 );
     33
     34            setPenWidthF( 1.0 );
     35        }
     36
     37        virtual QwtText label( double value ) const QWT_OVERRIDE
     38        {
     39            if ( qFuzzyCompare( value + 1.0, 1.0 ) )
     40                value = 60.0 * 60.0 * 12.0;
     41
     42            return QLocale().toString( qRound( value / ( 60.0 * 60.0 ) ) );
     43        }
     44    };
     45}
     46
     47/*!
     48   Constructor
     49   \param parent Parent widget
     50 */
     51QwtAnalogClock::QwtAnalogClock( QWidget* parent )
     52    : QwtDial( parent )
    4653{
    4754    setWrapping( true );
    … …  
    5562    const int secondsPerHour = 60.0 * 60.0;
    5663
    57     QList<double> majorTicks;
    58     QList<double> minorTicks;
     64    QList< double > majorTicks;
     65    QList< double > minorTicks;
    5966
    6067    for ( int i = 0; i < 12; i++ )
    … …  
    9198        }
    9299
    93         QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle(
     100        QwtDialSimpleNeedle* hand = new QwtDialSimpleNeedle(
    94101            QwtDialSimpleNeedle::Arrow, true, handColor, knobColor );
    95102        hand->setWidth( width );
    96103
    97         d_hand[i] = NULL;
    98         setHand( static_cast<Hand>( i ), hand );
     104        m_hand[i] = NULL;
     105        setHand( static_cast< Hand >( i ), hand );
    99106    }
    100107}
    … …  
    104111{
    105112    for ( int i = 0; i < NHands; i++ )
    106         delete d_hand[i];
    107 }
    108 
    109 /*!
    110   Nop method, use setHand() instead
    111   \sa setHand()
    112 */
    113 void QwtAnalogClock::setNeedle( QwtDialNeedle * )
     113        delete m_hand[i];
     114}
     115
     116/*!
     117   Nop method, use setHand() instead
     118   \sa setHand()
     119 */
     120void QwtAnalogClock::setNeedle( QwtDialNeedle* )
    114121{
    115122    // no op
    … …  
    122129   \param needle Hand
    123130   \sa hand()
    124 */
    125 void QwtAnalogClock::setHand( Hand hand, QwtDialNeedle *needle )
     131 */
     132void QwtAnalogClock::setHand( Hand hand, QwtDialNeedle* needle )
    126133{
    127134    if ( hand >= 0 && hand < NHands )
    128135    {
    129         delete d_hand[hand];
    130         d_hand[hand] = needle;
    131     }
    132 }
    133 
    134 /*!
    135   \return Clock hand
    136   \param hd Specifies the type of hand
    137   \sa setHand()
    138 */
    139 QwtDialNeedle *QwtAnalogClock::hand( Hand hd )
     136        delete m_hand[hand];
     137        m_hand[hand] = needle;
     138    }
     139}
     140
     141/*!
     142   \return Clock hand
     143   \param hd Specifies the type of hand
     144   \sa setHand()
     145 */
     146QwtDialNeedle* QwtAnalogClock::hand( Hand hd )
    140147{
    141148    if ( hd < 0 || hd >= NHands )
    142149        return NULL;
    143150
    144     return d_hand[hd];
    145 }
    146 
    147 /*!
    148   \return Clock hand
    149   \param hd Specifies the type of hand
    150   \sa setHand()
    151 */
    152 const QwtDialNeedle *QwtAnalogClock::hand( Hand hd ) const
    153 {
    154     return const_cast<QwtAnalogClock *>( this )->hand( hd );
    155 }
    156 
    157 /*!
    158   \brief Set the current time
    159 */
     151    return m_hand[hd];
     152}
     153
     154/*!
     155   \return Clock hand
     156   \param hd Specifies the type of hand
     157   \sa setHand()
     158 */
     159const QwtDialNeedle* QwtAnalogClock::hand( Hand hd ) const
     160{
     161    return const_cast< QwtAnalogClock* >( this )->hand( hd );
     162}
     163
     164/*!
     165   \brief Set the current time
     166 */
    160167void QwtAnalogClock::setCurrentTime()
    161168{
    … …  
    164171
    165172/*!
    166   Set a time
    167   \param time Time to display
    168 */
    169 void QwtAnalogClock::setTime( const QTime &time )
     173   Set a time
     174   \param time Time to display
     175 */
     176void QwtAnalogClock::setTime( const QTime& time )
    170177{
    171178    if ( time.isValid() )
    … …  
    179186
    180187/*!
    181   \brief Draw the needle
    182 
    183   A clock has no single needle but three hands instead. drawNeedle()
    184   translates value() into directions for the hands and calls
    185   drawHand().
    186 
    187   \param painter Painter
    188   \param center Center of the clock
    189   \param radius Maximum length for the hands
    190   \param dir Dummy, not used.
    191   \param colorGroup ColorGroup
    192 
    193   \sa drawHand()
    194 */
    195 void QwtAnalogClock::drawNeedle( QPainter *painter, const QPointF &center,
    196     double radius, double dir, QPalette::ColorGroup colorGroup ) const
    197 {
    198     Q_UNUSED( dir );
     188   \brief Draw the needle
     189
     190   A clock has no single needle but three hands instead. drawNeedle()
     191   translates value() into directions for the hands and calls
     192   drawHand().
     193
     194   \param painter Painter
     195   \param center Center of the clock
     196   \param radius Maximum length for the hands
     197   \param direction Dummy, not used.
     198   \param colorGroup ColorGroup
     199
     200   \sa drawHand()
     201 */
     202void QwtAnalogClock::drawNeedle( QPainter* painter, const QPointF& center,
     203    double radius, double direction, QPalette::ColorGroup colorGroup ) const
     204{
     205    Q_UNUSED( direction );
    199206
    200207    if ( isValid() )
    … …  
    202209        const double hours = value() / ( 60.0 * 60.0 );
    203210        const double minutes =
    204             ( value() - qFloor(hours) * 60.0 * 60.0 ) / 60.0;
    205         const double seconds = value() - qFloor(hours) * 60.0 * 60.0
    206             - qFloor(minutes) * 60.0;
     211            ( value() - std::floor(hours) * 60.0 * 60.0 ) / 60.0;
     212        const double seconds = value() - std::floor(hours) * 60.0 * 60.0
     213            - std::floor(minutes) * 60.0;
    207214
    208215        double angle[NHands];
    … …  
    214221        {
    215222            const double d = 360.0 - angle[hand] - origin();
    216             drawHand( painter, static_cast<Hand>( hand ),
     223            drawHand( painter, static_cast< Hand >( hand ),
    217224                center, radius, d, colorGroup );
    218225        }
    … …  
    221228
    222229/*!
    223   Draw a clock hand
    224 
    225   \param painter Painter
    226   \param hd Specify the type of hand
    227   \param center Center of the clock
    228   \param radius Maximum length for the hands
    229   \param direction Direction of the hand in degrees, counter clockwise
    230   \param cg ColorGroup
    231 */
    232 void QwtAnalogClock::drawHand( QPainter *painter, Hand hd,
    233     const QPointF &center, double radius, double direction,
     230   Draw a clock hand
     231
     232   \param painter Painter
     233   \param hd Specify the type of hand
     234   \param center Center of the clock
     235   \param radius Maximum length for the hands
     236   \param direction Direction of the hand in degrees, counter clockwise
     237   \param cg ColorGroup
     238 */
     239void QwtAnalogClock::drawHand( QPainter* painter, Hand hd,
     240    const QPointF& center, double radius, double direction,
    234241    QPalette::ColorGroup cg ) const
    235242{
    236     const QwtDialNeedle *needle = hand( hd );
     243    const QwtDialNeedle* needle = hand( hd );
    237244    if ( needle )
    238245    {
    … …  
    243250    }
    244251}
     252
     253#include "moc_qwt_analog_clock.cpp"
  • trunk/BNC/qwt/qwt_analog_clock.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_dial.h"
    15 #include "qwt_dial_needle.h"
    16 #include <qdatetime.h>
     15
     16class QwtDialNeedle;
    1717
    1818/*!
    19   \brief An analog clock
     19   \brief An analog clock
    2020
    21   \image html analogclock.png
     21   \image html analogclock.png
    2222
    23   \par Example
    24   \code
    25   #include <qwt_analog_clock.h>
     23   \par Example
     24   \code
     25 #include <qwt_analog_clock.h>
    2626
    27   QwtAnalogClock *clock = new QwtAnalogClock(...);
    28   clock->scaleDraw()->setPenWidth(3);
    29   clock->setLineWidth(6);
    30   clock->setFrameShadow(QwtDial::Sunken);
    31   clock->setTime();
     27   QwtAnalogClock *clock = new QwtAnalogClock(...);
     28   clock->scaleDraw()->setPenWidth(3);
     29   clock->setLineWidth(6);
     30   clock->setFrameShadow(QwtDial::Sunken);
     31   clock->setTime();
    3232
    33   // update the clock every second
    34   QTimer *timer = new QTimer(clock);
    35   timer->connect(timer, SIGNAL(timeout()), clock, SLOT(setCurrentTime()));
    36   timer->start(1000);
     33   // update the clock every second
     34   QTimer *timer = new QTimer(clock);
     35   timer->connect(timer, SIGNAL(timeout()), clock, SLOT(setCurrentTime()));
     36   timer->start(1000);
    3737
    38   \endcode
     38   \endcode
    3939
    40   \note The examples/dials example shows how to use QwtAnalogClock.
    41 */
     40   \note The examples/dials example shows how to use QwtAnalogClock.
     41 */
    4242
    43 class QWT_EXPORT QwtAnalogClock: public QwtDial
     43class QWT_EXPORT QwtAnalogClock : public QwtDial
    4444{
    4545    Q_OBJECT
    4646
    47 public:
     47  public:
    4848    /*!
    4949        Hand type
    5050        \sa setHand(), hand()
    51     */
     51     */
    5252    enum Hand
    5353    {
    … …  
    6868    virtual ~QwtAnalogClock();
    6969
    70     void setHand( Hand, QwtDialNeedle * );
     70    void setHand( Hand, QwtDialNeedle* );
    7171
    72     const QwtDialNeedle *hand( Hand ) const;
    73     QwtDialNeedle *hand( Hand );
     72    const QwtDialNeedle* hand( Hand ) const;
     73    QwtDialNeedle* hand( Hand );
    7474
    75 public Q_SLOTS:
     75  public Q_SLOTS:
    7676    void setCurrentTime();
    77     void setTime( const QTime & );
     77    void setTime( const QTime& );
    7878
    79 protected:
    80     virtual void drawNeedle( QPainter *, const QPointF &,
     79  protected:
     80    virtual void drawNeedle( QPainter*, const QPointF&, double radius,
     81        double direction, QPalette::ColorGroup ) const QWT_OVERRIDE;
     82
     83    virtual void drawHand( QPainter*, Hand, const QPointF&,
    8184        double radius, double direction, QPalette::ColorGroup ) const;
    8285
    83     virtual void drawHand( QPainter *, Hand, const QPointF &,
    84         double radius, double direction, QPalette::ColorGroup ) const;
     86  private:
     87    // use setHand instead
     88    void setNeedle( QwtDialNeedle* );
    8589
    86 private:
    87     // use setHand instead
    88     void setNeedle( QwtDialNeedle * );
    89 
    90     QwtDialNeedle *d_hand[NHands];
     90    QwtDialNeedle* m_hand[NHands];
    9191};
    9292
  • trunk/BNC/qwt/qwt_arrow_button.cpp

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_arrow_button.h"
    11 #include "qwt_math.h"
     11#include "qwt.h"
     12
    1213#include <qpainter.h>
    1314#include <qstyle.h>
    1415#include <qstyleoption.h>
    1516#include <qevent.h>
    16 #include <qapplication.h>
    1717
    1818static const int MaxNum = 3;
    … …  
    2222class QwtArrowButton::PrivateData
    2323{
    24 public:
     24  public:
    2525    int num;
    2626    Qt::ArrowType arrowType;
    … …  
    3030{
    3131    QStyleOptionButton option;
    32     option.init( btn );
     32    option.initFrom( btn );
    3333    option.features = QStyleOptionButton::None;
    3434    if ( btn->isFlat() )
    … …  
    4949
    5050/*!
    51   \param num Number of arrows
    52   \param arrowType see Qt::ArrowType in the Qt docs.
    53   \param parent Parent widget
    54 */
    55 QwtArrowButton::QwtArrowButton( int num,
    56         Qt::ArrowType arrowType, QWidget *parent ):
    57     QPushButton( parent )
    58 {
    59     d_data = new PrivateData;
    60     d_data->num = qBound( 1, num, MaxNum );
    61     d_data->arrowType = arrowType;
     51   \param num Number of arrows
     52   \param arrowType see Qt::ArrowType in the Qt docs.
     53   \param parent Parent widget
     54 */
     55QwtArrowButton::QwtArrowButton( int num, Qt::ArrowType arrowType, QWidget* parent )
     56    : QPushButton( parent )
     57{
     58    m_data = new PrivateData;
     59    m_data->num = qBound( 1, num, MaxNum );
     60    m_data->arrowType = arrowType;
    6261
    6362    setAutoRepeat( true );
    6463    setAutoDefault( false );
    6564
    66     switch ( d_data->arrowType )
     65    switch ( m_data->arrowType )
    6766    {
    6867        case Qt::LeftArrow:
    … …  
    8079QwtArrowButton::~QwtArrowButton()
    8180{
    82     delete d_data;
    83     d_data = NULL;
    84 }
    85 
    86 /*!
    87   \brief The direction of the arrows
    88 */
     81    delete m_data;
     82    m_data = NULL;
     83}
     84
     85/*!
     86   \brief The direction of the arrows
     87 */
    8988Qt::ArrowType QwtArrowButton::arrowType() const
    9089{
    91     return d_data->arrowType;
    92 }
    93 
    94 /*!
    95   \brief The number of arrows
    96 */
     90    return m_data->arrowType;
     91}
     92
     93/*!
     94   \brief The number of arrows
     95 */
    9796int QwtArrowButton::num() const
    9897{
    99     return d_data->num;
    100 }
    101 
    102 /*!
    103   \return the bounding rectangle for the label
    104 */
     98    return m_data->num;
     99}
     100
     101/*!
     102   \return the bounding rectangle for the label
     103 */
    105104QRect QwtArrowButton::labelRect() const
    106105{
    … …  
    128127   Paint event handler
    129128   \param event Paint event
    130 */
    131 void QwtArrowButton::paintEvent( QPaintEvent *event )
     129 */
     130void QwtArrowButton::paintEvent( QPaintEvent* event )
    132131{
    133132    QPushButton::paintEvent( event );
    … …  
    137136
    138137/*!
    139   \brief Draw the button label
    140 
    141   \param painter Painter
    142   \sa The Qt Manual for QPushButton
    143 */
    144 void QwtArrowButton::drawButtonLabel( QPainter *painter )
    145 {
    146     const bool isVertical = d_data->arrowType == Qt::UpArrow ||
    147         d_data->arrowType == Qt::DownArrow;
     138   \brief Draw the button label
     139
     140   \param painter Painter
     141   \sa The Qt Manual for QPushButton
     142 */
     143void QwtArrowButton::drawButtonLabel( QPainter* painter )
     144{
     145    const bool isVertical = m_data->arrowType == Qt::UpArrow ||
     146        m_data->arrowType == Qt::DownArrow;
    148147
    149148    const QRect r = labelRect();
    … …  
    162161
    163162    QRect contentsSize; // aligned rect where to paint all arrows
    164     if ( d_data->arrowType == Qt::LeftArrow || d_data->arrowType == Qt::RightArrow )
    165     {
    166         contentsSize.setWidth( d_data->num * arrow.width()
    167             + ( d_data->num - 1 ) * Spacing );
     163    if ( m_data->arrowType == Qt::LeftArrow || m_data->arrowType == Qt::RightArrow )
     164    {
     165        contentsSize.setWidth( m_data->num * arrow.width()
     166            + ( m_data->num - 1 ) * Spacing );
    168167        contentsSize.setHeight( arrow.height() );
    169168    }
    … …  
    171170    {
    172171        contentsSize.setWidth( arrow.width() );
    173         contentsSize.setHeight( d_data->num * arrow.height()
    174             + ( d_data->num - 1 ) * Spacing );
     172        contentsSize.setHeight( m_data->num * arrow.height()
     173            + ( m_data->num - 1 ) * Spacing );
    175174    }
    176175
    … …  
    180179
    181180    painter->save();
    182     for ( int i = 0; i < d_data->num; i++ )
    183     {
    184         drawArrow( painter, arrowRect, d_data->arrowType );
     181    for ( int i = 0; i < m_data->num; i++ )
     182    {
     183        drawArrow( painter, arrowRect, m_data->arrowType );
    185184
    186185        int dx = 0;
    … …  
    199198    {
    200199        QStyleOptionFocusRect option;
    201         option.init( this );
     200        option.initFrom( this );
    202201        option.backgroundColor = palette().color( QPalette::Window );
    203202
    … …  
    213212    \param r Rectangle where to paint the arrow
    214213    \param arrowType Arrow type
    215 */
    216 void QwtArrowButton::drawArrow( QPainter *painter,
    217     const QRect &r, Qt::ArrowType arrowType ) const
     214 */
     215void QwtArrowButton::drawArrow( QPainter* painter,
     216    const QRect& r, Qt::ArrowType arrowType ) const
    218217{
    219218    QPolygon pa( 3 );
    … …  
    256255
    257256/*!
    258   \return a size hint
    259 */
     257   \return a size hint
     258 */
    260259QSize QwtArrowButton::sizeHint() const
    261260{
    262261    const QSize hint = minimumSizeHint();
    263     return hint.expandedTo( QApplication::globalStrut() );
    264 }
    265 
    266 /*!
    267   \brief Return a minimum size hint
    268 */
     262    return qwtExpandedToGlobalStrut( hint );
     263}
     264
     265/*!
     266   \brief Return a minimum size hint
     267 */
    269268QSize QwtArrowButton::minimumSizeHint() const
    270269{
    … …  
    274273        2 * Margin + ( MaxNum - 1 ) * Spacing + MaxNum * asz.width(),
    275274        2 * Margin + asz.height()
    276     );
    277 
    278     if ( d_data->arrowType == Qt::UpArrow || d_data->arrowType == Qt::DownArrow )
     275        );
     276
     277    if ( m_data->arrowType == Qt::UpArrow || m_data->arrowType == Qt::DownArrow )
    279278        sz.transpose();
    280279
    281280    QStyleOption styleOption;
    282     styleOption.init( this );
     281    styleOption.initFrom( this );
    283282
    284283    sz = style()->sizeFromContents( QStyle::CT_PushButton,
    … …  
    294293   \param boundingSize Bounding size
    295294   \return Size of the arrow
    296 */
     295 */
    297296QSize QwtArrowButton::arrowSize( Qt::ArrowType arrowType,
    298     const QSize &boundingSize ) const
     297    const QSize& boundingSize ) const
    299298{
    300299    QSize bs = boundingSize;
    … …  
    323322
    324323/*!
    325   \brief autoRepeat for the space keys
    326 */
    327 void QwtArrowButton::keyPressEvent( QKeyEvent *event )
     324   \brief autoRepeat for the space keys
     325 */
     326void QwtArrowButton::keyPressEvent( QKeyEvent* event )
    328327{
    329328    if ( event->isAutoRepeat() && event->key() == Qt::Key_Space )
  • trunk/BNC/qwt/qwt_arrow_button.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1515
    1616/*!
    17   \brief Arrow Button
     17   \brief Arrow Button
    1818
    19   A push button with one or more filled triangles on its front.
    20   An Arrow button can have 1 to 3 arrows in a row, pointing
    21   up, down, left or right.
    22 */
     19   A push button with one or more filled triangles on its front.
     20   An Arrow button can have 1 to 3 arrows in a row, pointing
     21   up, down, left or right.
     22 */
    2323class QWT_EXPORT QwtArrowButton : public QPushButton
    2424{
    25 public:
    26     explicit QwtArrowButton ( int num, Qt::ArrowType, QWidget *parent = NULL );
     25  public:
     26    explicit QwtArrowButton ( int num, Qt::ArrowType, QWidget* parent = NULL );
    2727    virtual ~QwtArrowButton();
    2828
    … …  
    3030    int num() const;
    3131
    32     virtual QSize sizeHint() const;
    33     virtual QSize minimumSizeHint() const;
     32    virtual QSize sizeHint() const QWT_OVERRIDE;
     33    virtual QSize minimumSizeHint() const QWT_OVERRIDE;
    3434
    35 protected:
    36     virtual void paintEvent( QPaintEvent *event );
     35  protected:
     36    virtual void paintEvent( QPaintEvent*) QWT_OVERRIDE;
     37    virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE;
    3738
    38     virtual void drawButtonLabel( QPainter * );
    39     virtual void drawArrow( QPainter *,
    40         const QRect &, Qt::ArrowType ) const;
     39    virtual void drawButtonLabel( QPainter* );
     40    virtual void drawArrow( QPainter*,
     41        const QRect&, Qt::ArrowType ) const;
    4142    virtual QRect labelRect() const;
    4243    virtual QSize arrowSize( Qt::ArrowType,
    43         const QSize &boundingSize ) const;
     44        const QSize& boundingSize ) const;
    4445
    45     virtual void keyPressEvent( QKeyEvent * );
    46 
    47 private:
     46  private:
    4847    class PrivateData;
    49     PrivateData *d_data;
     48    PrivateData* m_data;
    5049};
    5150
  • trunk/BNC/qwt/qwt_clipper.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_clipper.h"
    1111#include "qwt_point_polar.h"
     12#include "qwt_interval.h"
     13#include "qwt_math.h"
     14
     15#include <qpolygon.h>
    1216#include <qrect.h>
    13 #include <string.h>
    14 #include <stdlib.h>
    15 
    16 #if QT_VERSION < 0x040601
    17 #define qAtan(x) ::atan(x)
    18 #endif
     17
     18#include <algorithm>
    1919
    2020namespace QwtClip
    2121{
    2222    // some templates used for inlining
    23     template <class Point, typename T> class LeftEdge;
    24     template <class Point, typename T> class RightEdge;
    25     template <class Point, typename T> class TopEdge;
    26     template <class Point, typename T> class BottomEdge;
    27 
    28     template <class Point> class PointBuffer;
    29 }
    30 
    31 template <class Point, typename Value>
     23    template< class Point, typename T > class LeftEdge;
     24    template< class Point, typename T > class RightEdge;
     25    template< class Point, typename T > class TopEdge;
     26    template< class Point, typename T > class BottomEdge;
     27}
     28
     29template< class Point, typename Value >
    3230class QwtClip::LeftEdge
    3331{
    34 public:
     32  public:
    3533    inline LeftEdge( Value x1, Value, Value, Value ):
    36         d_x1( x1 )
    37     {
    38     }
    39 
    40     inline bool isInside( const Point &p  ) const
    41     {
    42         return p.x() >= d_x1;
    43     }
    44 
    45     inline Point intersection( const Point &p1, const Point &p2 ) const
     34        m_x1( x1 )
     35    {
     36    }
     37
     38    inline bool isInside( const Point& p  ) const
     39    {
     40        return p.x() >= m_x1;
     41    }
     42
     43    inline Point intersection( const Point& p1, const Point& p2 ) const
    4644    {
    4745        double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() );
    48         return Point( d_x1, static_cast< Value >( p2.y() + ( d_x1 - p2.x() ) * dy ) );
    49     }
    50 private:
    51     const Value d_x1;
    52 };
    53 
    54 template <class Point, typename Value>
     46        return Point( m_x1, static_cast< Value >( p2.y() + ( m_x1 - p2.x() ) * dy ) );
     47    }
     48  private:
     49    const Value m_x1;
     50};
     51
     52template< class Point, typename Value >
    5553class QwtClip::RightEdge
    5654{
    57 public:
     55  public:
    5856    inline RightEdge( Value, Value x2, Value, Value ):
    59         d_x2( x2 )
    60     {
    61     }
    62 
    63     inline bool isInside( const Point &p  ) const
    64     {
    65         return p.x() <= d_x2;
    66     }
    67 
    68     inline Point intersection( const Point &p1, const Point &p2 ) const
     57        m_x2( x2 )
     58    {
     59    }
     60
     61    inline bool isInside( const Point& p  ) const
     62    {
     63        return p.x() <= m_x2;
     64    }
     65
     66    inline Point intersection( const Point& p1, const Point& p2 ) const
    6967    {
    7068        double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() );
    71         return Point( d_x2, static_cast<Value>( p2.y() + ( d_x2 - p2.x() ) * dy ) );
    72     }
    73 
    74 private:
    75     const Value d_x2;
    76 };
    77 
    78 template <class Point, typename Value>
     69        return Point( m_x2, static_cast< Value >( p2.y() + ( m_x2 - p2.x() ) * dy ) );
     70    }
     71
     72  private:
     73    const Value m_x2;
     74};
     75
     76template< class Point, typename Value >
    7977class QwtClip::TopEdge
    8078{
    81 public:
     79  public:
    8280    inline TopEdge( Value, Value, Value y1, Value ):
    83         d_y1( y1 )
    84     {
    85     }
    86 
    87     inline bool isInside( const Point &p  ) const
    88     {
    89         return p.y() >= d_y1;
    90     }
    91 
    92     inline Point intersection( const Point &p1, const Point &p2 ) const
     81        m_y1( y1 )
     82    {
     83    }
     84
     85    inline bool isInside( const Point& p  ) const
     86    {
     87        return p.y() >= m_y1;
     88    }
     89
     90    inline Point intersection( const Point& p1, const Point& p2 ) const
    9391    {
    9492        double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() );
    95         return Point( static_cast<Value>( p2.x() + ( d_y1 - p2.y() ) * dx ), d_y1 );
    96     }
    97 
    98 private:
    99     const Value d_y1;
    100 };
    101 
    102 template <class Point, typename Value>
     93        return Point( static_cast< Value >( p2.x() + ( m_y1 - p2.y() ) * dx ), m_y1 );
     94    }
     95
     96  private:
     97    const Value m_y1;
     98};
     99
     100template< class Point, typename Value >
    103101class QwtClip::BottomEdge
    104102{
    105 public:
     103  public:
    106104    inline BottomEdge( Value, Value, Value, Value y2 ):
    107         d_y2( y2 )
    108     {
    109     }
    110 
    111     inline bool isInside( const Point &p ) const
    112     {
    113         return p.y() <= d_y2;
    114     }
    115 
    116     inline Point intersection( const Point &p1, const Point &p2 ) const
     105        m_y2( y2 )
     106    {
     107    }
     108
     109    inline bool isInside( const Point& p ) const
     110    {
     111        return p.y() <= m_y2;
     112    }
     113
     114    inline Point intersection( const Point& p1, const Point& p2 ) const
    117115    {
    118116        double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() );
    119         return Point( static_cast<Value>( p2.x() + ( d_y2 - p2.y() ) * dx ), d_y2 );
    120     }
    121 
    122 private:
    123     const Value d_y2;
    124 };
    125 
    126 template<class Point>
    127 class QwtClip::PointBuffer
    128 {
    129 public:
    130     PointBuffer( int capacity = 0 ):
    131         m_capacity( 0 ),
    132         m_size( 0 ),
    133         m_buffer( NULL )
    134     {
    135         if ( capacity > 0 )
    136             reserve( capacity );
    137     }
    138 
    139     ~PointBuffer()
    140     {
    141         if ( m_buffer )
    142             ::free( m_buffer );
    143     }
    144 
    145     inline void setPoints( int numPoints, const Point *points )
    146     {
    147         reserve( numPoints );
    148 
    149         m_size = numPoints;
    150         ::memcpy( m_buffer, points, m_size * sizeof( Point ) );
    151     }
    152 
    153     inline void reset()
    154     {
    155         m_size = 0;
    156     }
    157 
    158     inline int size() const
    159     {
    160         return m_size;
    161     }
    162 
    163     inline Point *data() const
    164     {
    165         return m_buffer;
    166     }
    167 
    168     inline Point &operator[]( int i )
    169     {
    170         return m_buffer[i];
    171     }
    172 
    173     inline const Point &operator[]( int i ) const
    174     {
    175         return m_buffer[i];
    176     }
    177 
    178     inline void add( const Point &point )
    179     {
    180         if ( m_capacity <= m_size )
    181             reserve( m_size + 1 );
    182 
    183         m_buffer[m_size++] = point;
    184     }
    185 
    186 private:
    187     inline void reserve( int size )
    188     {
    189         if ( m_capacity == 0 )
    190             m_capacity = 1;
    191 
    192         while ( m_capacity < size )
    193             m_capacity *= 2;
    194 
    195         m_buffer = static_cast<Point *>(
    196             ::realloc( m_buffer, m_capacity * sizeof( Point ) ) );
    197     }
    198 
    199     int m_capacity;
    200     int m_size;
    201     Point *m_buffer;
     117        return Point( static_cast< Value >( p2.x() + ( m_y2 - p2.y() ) * dx ), m_y2 );
     118    }
     119
     120  private:
     121    const Value m_y2;
    202122};
    203123
    204124using namespace QwtClip;
    205125
    206 template <class Polygon, class Rect, class Point, typename T>
     126template< class Polygon, class Rect, typename T >
    207127class QwtPolygonClipper
    208128{
    209 public:
    210     QwtPolygonClipper( const Rect &clipRect ):
    211         d_clipRect( clipRect )
    212     {
    213     }
    214 
    215     Polygon clipPolygon( const Polygon &polygon, bool closePolygon ) const
     129    typedef typename Polygon::value_type Point;
     130  public:
     131    explicit QwtPolygonClipper( const Rect& clipRect ):
     132        m_clipRect( clipRect )
     133    {
     134    }
     135
     136    void clipPolygon( Polygon& points1, bool closePolygon ) const
    216137    {
    217138#if 0
    218         if ( d_clipRect.contains( polygon.boundingRect() ) )
     139        if ( m_clipRect.contains( points1.boundingRect() ) )
    219140            return polygon;
    220141#endif
    221142
    222         PointBuffer<Point> points1;
    223         PointBuffer<Point> points2( qMin( 256, polygon.size() ) );
    224 
    225         points1.setPoints( polygon.size(), polygon.data() );
    226 
    227         clipEdge< LeftEdge<Point, T> >( closePolygon, points1, points2 );
    228         clipEdge< RightEdge<Point, T> >( closePolygon, points2, points1 );
    229         clipEdge< TopEdge<Point, T> >( closePolygon, points1, points2 );
    230         clipEdge< BottomEdge<Point, T> >( closePolygon, points2, points1 );
    231 
    232         Polygon p;
    233         p.resize( points1.size() );
    234         ::memcpy( p.data(), points1.data(), points1.size() * sizeof( Point ) );
    235 
    236         return p;
    237     }
    238 
    239 private:
    240     template <class Edge>
     143        Polygon points2;
     144        points2.reserve( qMin( 256, points1.size() ) );
     145
     146        clipEdge< LeftEdge< Point, T > >( closePolygon, points1, points2 );
     147        clipEdge< RightEdge< Point, T > >( closePolygon, points2, points1 );
     148        clipEdge< TopEdge< Point, T > >( closePolygon, points1, points2 );
     149        clipEdge< BottomEdge< Point, T > >( closePolygon, points2, points1 );
     150    }
     151
     152  private:
     153    template< class Edge >
    241154    inline void clipEdge( bool closePolygon,
    242         PointBuffer<Point> &points, PointBuffer<Point> &clippedPoints ) const
    243     {
    244         clippedPoints.reset();
     155        const Polygon& points, Polygon& clippedPoints ) const
     156    {
     157        clippedPoints.clear();
    245158
    246159        if ( points.size() < 2 )
    247160        {
    248161            if ( points.size() == 1 )
    249                 clippedPoints.add( points[0] );
     162                clippedPoints += points[0];
     163
    250164            return;
    251165        }
    252166
    253         const Edge edge( d_clipRect.x(), d_clipRect.x() + d_clipRect.width(),
    254             d_clipRect.y(), d_clipRect.y() + d_clipRect.height() );
    255 
    256         int lastPos, start;
    257         if ( closePolygon )
    258         {
    259             start = 0;
    260             lastPos = points.size() - 1;
     167        const Edge edge( m_clipRect.x(), m_clipRect.x() + m_clipRect.width(),
     168            m_clipRect.y(), m_clipRect.y() + m_clipRect.height() );
     169
     170        if ( !closePolygon )
     171        {
     172            const Point& p1 = points.first();
     173
     174            if ( edge.isInside( p1 ) )
     175                clippedPoints += p1;
    261176        }
    262177        else
    263178        {
    264             start = 1;
    265             lastPos = 0;
    266 
    267             if ( edge.isInside( points[0] ) )
    268                 clippedPoints.add( points[0] );
    269         }
    270 
    271         const uint nPoints = points.size();
    272         for ( uint i = start; i < nPoints; i++ )
    273         {
    274             const Point &p1 = points[i];
    275             const Point &p2 = points[lastPos];
     179            const Point& p1 = points.first();
     180            const Point& p2 = points.last();
    276181
    277182            if ( edge.isInside( p1 ) )
    278183            {
    279                 if ( edge.isInside( p2 ) )
    280                 {
    281                     clippedPoints.add( p1 );
    282                 }
    283                 else
    284                 {
    285                     clippedPoints.add( edge.intersection( p1, p2 ) );
    286                     clippedPoints.add( p1 );
    287                 }
     184                if ( !edge.isInside( p2 ) )
     185                    clippedPoints += edge.intersection( p1, p2 );
     186
     187                clippedPoints += p1;
    288188            }
    289             else
     189            else if ( edge.isInside( p2 ) )
    290190            {
    291                 if ( edge.isInside( p2 ) )
    292                 {
    293                     clippedPoints.add( edge.intersection( p1, p2 ) );
    294                 }
     191                clippedPoints += edge.intersection( p1, p2 );
    295192            }
    296             lastPos = i;
    297         }
    298     }
    299 
    300     const Rect d_clipRect;
     193        }
     194
     195        const uint nPoints = points.size();
     196        const Point* p = points.constData();
     197
     198        for ( uint i = 1; i < nPoints; i++ )
     199        {
     200            const Point& p1 = p[i];
     201            const Point& p2 = p[i - 1];
     202
     203            if ( edge.isInside( p1 ) )
     204            {
     205                if ( !edge.isInside( p2 ) )
     206                    clippedPoints += edge.intersection( p1, p2 );
     207
     208                clippedPoints += p1;
     209            }
     210            else if ( edge.isInside( p2 ) )
     211            {
     212                clippedPoints += edge.intersection( p1, p2 );
     213            }
     214        }
     215    }
     216
     217    const Rect m_clipRect;
    301218};
    302219
    303220class QwtCircleClipper
    304221{
    305 public:
    306     QwtCircleClipper( const QRectF &r );
    307     QVector<QwtInterval> clipCircle( const QPointF &, double radius ) const;
    308 
    309 private:
     222  public:
     223    explicit QwtCircleClipper( const QRectF& r );
     224    QVector< QwtInterval > clipCircle( const QPointF&, double radius ) const;
     225
     226  private:
    310227    enum Edge
    311228    {
    … …  
    318235    };
    319236
    320     QList<QPointF> cuttingPoints(
    321         Edge, const QPointF &pos, double radius ) const;
    322 
    323     double toAngle( const QPointF &, const QPointF & ) const;
    324 
    325     const QRectF d_rect;
    326 };
    327 
    328 
    329 QwtCircleClipper::QwtCircleClipper( const QRectF &r ):
    330     d_rect( r )
    331 {
    332 }
    333 
    334 QVector<QwtInterval> QwtCircleClipper::clipCircle(
    335     const QPointF &pos, double radius ) const
    336 {
    337     QList<QPointF> points;
     237    QVector< QPointF > cuttingPoints(
     238        Edge, const QPointF& pos, double radius ) const;
     239
     240    double toAngle( const QPointF&, const QPointF& ) const;
     241
     242    const QRectF m_rect;
     243};
     244
     245
     246QwtCircleClipper::QwtCircleClipper( const QRectF& r )
     247    : m_rect( r )
     248{
     249}
     250
     251QVector< QwtInterval > QwtCircleClipper::clipCircle(
     252    const QPointF& pos, double radius ) const
     253{
     254    // using QVarLengthArray TODO ...
     255
     256    QVector< QPointF > points;
    338257    for ( int edge = 0; edge < NEdges; edge++ )
    339         points += cuttingPoints( static_cast<Edge>(edge), pos, radius );
    340 
    341     QVector<QwtInterval> intv;
     258        points += cuttingPoints( static_cast< Edge >( edge ), pos, radius );
     259
     260    QVector< QwtInterval > intv;
    342261    if ( points.size() <= 0 )
    343262    {
    344263        QRectF cRect( 0, 0, 2 * radius, 2 * radius );
    345264        cRect.moveCenter( pos );
    346         if ( d_rect.contains( cRect ) )
     265        if ( m_rect.contains( cRect ) )
    347266            intv += QwtInterval( 0.0, 2 * M_PI );
    348267    }
    349268    else
    350269    {
    351         QList<double> angles;
     270        QVector< double > angles;
     271        angles.reserve( points.size() );
     272
    352273        for ( int i = 0; i < points.size(); i++ )
    353274            angles += toAngle( pos, points[i] );
    354         qSort( angles );
    355 
    356         const int in = d_rect.contains( qwtPolar2Pos( pos, radius,
     275
     276        std::sort( angles.begin(), angles.end() );
     277
     278        const int in = m_rect.contains( qwtPolar2Pos( pos, radius,
    357279            angles[0] + ( angles[1] - angles[0] ) / 2 ) );
    358280
     281        intv.reserve( angles.size() / 2 );
    359282        if ( in )
    360283        {
    361284            for ( int i = 0; i < angles.size() - 1; i += 2 )
    362                 intv += QwtInterval( angles[i], angles[i+1] );
     285                intv += QwtInterval( angles[i], angles[i + 1] );
    363286        }
    364287        else
    365288        {
    366289            for ( int i = 1; i < angles.size() - 1; i += 2 )
    367                 intv += QwtInterval( angles[i], angles[i+1] );
     290                intv += QwtInterval( angles[i], angles[i + 1] );
     291
    368292            intv += QwtInterval( angles.last(), angles.first() );
    369293        }
    … …  
    374298
    375299double QwtCircleClipper::toAngle(
    376     const QPointF &from, const QPointF &to ) const
     300    const QPointF& from, const QPointF& to ) const
    377301{
    378302    if ( from.x() == to.x() )
    … …  
    381305    const double m = qAbs( ( to.y() - from.y() ) / ( to.x() - from.x() ) );
    382306
    383     double angle = qAtan( m );
     307    double angle = std::atan( m );
    384308    if ( to.x() > from.x() )
    385309    {
    … …  
    398322}
    399323
    400 QList<QPointF> QwtCircleClipper::cuttingPoints(
    401     Edge edge, const QPointF &pos, double radius ) const
    402 {
    403     QList<QPointF> points;
     324QVector< QPointF > QwtCircleClipper::cuttingPoints(
     325    Edge edge, const QPointF& pos, double radius ) const
     326{
     327    QVector< QPointF > points;
    404328
    405329    if ( edge == Left || edge == Right )
    406330    {
    407         const double x = ( edge == Left ) ? d_rect.left() : d_rect.right();
     331        const double x = ( edge == Left ) ? m_rect.left() : m_rect.right();
    408332        if ( qAbs( pos.x() - x ) < radius )
    409333        {
    410             const double off = qSqrt( qwtSqr( radius ) - qwtSqr( pos.x() - x ) );
     334            const double off = std::sqrt( qwtSqr( radius ) - qwtSqr( pos.x() - x ) );
    411335            const double m_y1 = pos.y() + off;
    412             if ( m_y1 >= d_rect.top() && m_y1 <= d_rect.bottom() )
     336            if ( m_y1 >= m_rect.top() && m_y1 <= m_rect.bottom() )
    413337                points += QPointF( x, m_y1 );
    414338
    415339            const double m_y2 = pos.y() - off;
    416             if ( m_y2 >= d_rect.top() && m_y2 <= d_rect.bottom() )
     340            if ( m_y2 >= m_rect.top() && m_y2 <= m_rect.bottom() )
    417341                points += QPointF( x, m_y2 );
    418342        }
    … …  
    420344    else
    421345    {
    422         const double y = ( edge == Top ) ? d_rect.top() : d_rect.bottom();
     346        const double y = ( edge == Top ) ? m_rect.top() : m_rect.bottom();
    423347        if ( qAbs( pos.y() - y ) < radius )
    424348        {
    425             const double off = qSqrt( qwtSqr( radius ) - qwtSqr( pos.y() - y ) );
     349            const double off = std::sqrt( qwtSqr( radius ) - qwtSqr( pos.y() - y ) );
    426350            const double x1 = pos.x() + off;
    427             if ( x1 >= d_rect.left() && x1 <= d_rect.right() )
     351            if ( x1 >= m_rect.left() && x1 <= m_rect.right() )
    428352                points += QPointF( x1, y );
    429353
    430354            const double m_x2 = pos.x() - off;
    431             if ( m_x2 >= d_rect.left() && m_x2 <= d_rect.right() )
     355            if ( m_x2 >= m_rect.left() && m_x2 <= m_rect.right() )
    432356                points += QPointF( m_x2, y );
    433357        }
    … …  
    440364
    441365   \param clipRect Clip rectangle
    442    \param polygon Polygon
    443    \param closePolygon True, when the polygon is closed
    444 
    445    \return Clipped polygon
    446 */
    447 QPolygon QwtClipper::clipPolygon(
    448     const QRectF &clipRect, const QPolygon &polygon, bool closePolygon )
     366   \param polygon Polygon IN/OUT
     367   \param closePolygon True, when the polygon is closed
     368 */
     369void QwtClipper::clipPolygon(
     370    const QRectF& clipRect, QPolygon& polygon, bool closePolygon )
    449371{
    450372    const int minX = qCeil( clipRect.left() );
    … …  
    455377    const QRect r( minX, minY, maxX - minX, maxY - minY );
    456378
    457     QwtPolygonClipper<QPolygon, QRect, QPoint, int> clipper( r );
    458     return clipper.clipPolygon( polygon, closePolygon );
    459 }
     379    QwtPolygonClipper< QPolygon, QRect, int > clipper( r );
     380    clipper.clipPolygon( polygon, closePolygon );
     381}
     382
     383/*!
     384   Sutherland-Hodgman polygon clipping
     385
     386   \param clipRect Clip rectangle
     387   \param polygon Polygon IN/OUT
     388   \param closePolygon True, when the polygon is closed
     389 */
     390void QwtClipper::clipPolygon(
     391    const QRect& clipRect, QPolygon& polygon, bool closePolygon )
     392{
     393    QwtPolygonClipper< QPolygon, QRect, int > clipper( clipRect );
     394    clipper.clipPolygon( polygon, closePolygon );
     395}
     396
     397/*!
     398   Sutherland-Hodgman polygon clipping
     399
     400   \param clipRect Clip rectangle
     401   \param polygon Polygon IN/OUT
     402   \param closePolygon True, when the polygon is closed
     403 */
     404void QwtClipper::clipPolygonF(
     405    const QRectF& clipRect, QPolygonF& polygon, bool closePolygon )
     406{
     407    QwtPolygonClipper< QPolygonF, QRectF, double > clipper( clipRect );
     408    clipper.clipPolygon( polygon, closePolygon );
     409}
     410
    460411/*!
    461412   Sutherland-Hodgman polygon clipping
    … …  
    466417
    467418   \return Clipped polygon
    468 */
    469 QPolygon QwtClipper::clipPolygon(
    470     const QRect &clipRect, const QPolygon &polygon, bool closePolygon )
    471 {
    472     QwtPolygonClipper<QPolygon, QRect, QPoint, int> clipper( clipRect );
    473     return clipper.clipPolygon( polygon, closePolygon );
    474 }
    475 
     419 */
     420QPolygon QwtClipper::clippedPolygon(
     421    const QRectF& clipRect, const QPolygon& polygon, bool closePolygon )
     422{
     423    QPolygon points( polygon );
     424    clipPolygon( clipRect, points, closePolygon );
     425
     426    return points;
     427}
    476428/*!
    477429   Sutherland-Hodgman polygon clipping
    … …  
    482434
    483435   \return Clipped polygon
    484 */
    485 QPolygonF QwtClipper::clipPolygonF(
    486     const QRectF &clipRect, const QPolygonF &polygon, bool closePolygon )
    487 {
    488     QwtPolygonClipper<QPolygonF, QRectF, QPointF, double> clipper( clipRect );
    489     return clipper.clipPolygon( polygon, closePolygon );
     436 */
     437QPolygon QwtClipper::clippedPolygon(
     438    const QRect& clipRect, const QPolygon& polygon, bool closePolygon )
     439{
     440    QPolygon points( polygon );
     441    clipPolygon( clipRect, points, closePolygon );
     442
     443    return points;
     444}
     445
     446/*!
     447   Sutherland-Hodgman polygon clipping
     448
     449   \param clipRect Clip rectangle
     450   \param polygon Polygon
     451   \param closePolygon True, when the polygon is closed
     452
     453   \return Clipped polygon
     454 */
     455QPolygonF QwtClipper::clippedPolygonF(
     456    const QRectF& clipRect, const QPolygonF& polygon, bool closePolygon )
     457{
     458    QPolygonF points( polygon );
     459    clipPolygonF( clipRect, points, closePolygon );
     460
     461    return points;
    490462}
    491463
    … …  
    502474
    503475   \return Arcs of the circle
    504 */
    505 QVector<QwtInterval> QwtClipper::clipCircle( const QRectF &clipRect,
    506     const QPointF &center, double radius )
     476 */
     477QVector< QwtInterval > QwtClipper::clipCircle( const QRectF& clipRect,
     478    const QPointF& center, double radius )
    507479{
    508480    QwtCircleClipper clipper( clipRect );
  • trunk/BNC/qwt/qwt_clipper.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_interval.h"
    15 #include <qpolygon.h>
    16 #include <qvector.h>
    1714
     15class QwtInterval;
     16class QPointF;
    1817class QRect;
    1918class QRectF;
     19class QPolygon;
     20class QPolygonF;
     21
     22#if QT_VERSION < 0x060000
     23template< typename T > class QVector;
     24#endif
    2025
    2126/*!
    22   \brief Some clipping algorithms
    23 */
     27   \brief Some clipping algorithms
     28 */
    2429
    25 class QWT_EXPORT QwtClipper
     30namespace QwtClipper
    2631{
    27 public:
    28     static QPolygon clipPolygon( const QRect &,
    29         const QPolygon &, bool closePolygon = false );
    30     static QPolygon clipPolygon( const QRectF &,
    31         const QPolygon &, bool closePolygon = false );
     32    QWT_EXPORT void clipPolygon( const QRect&,
     33        QPolygon&, bool closePolygon = false );
    3234
    33     static QPolygonF clipPolygonF( const QRectF &,
    34         const QPolygonF &, bool closePolygon = false );
     35    QWT_EXPORT void clipPolygon( const QRectF&,
     36        QPolygon&, bool closePolygon = false );
    3537
    36     static QVector<QwtInterval> clipCircle(
    37         const QRectF &, const QPointF &, double radius );
     38    QWT_EXPORT void clipPolygonF( const QRectF&,
     39        QPolygonF&, bool closePolygon = false );
     40
     41    QWT_EXPORT QPolygon clippedPolygon( const QRect&,
     42        const QPolygon&, bool closePolygon = false );
     43
     44    QWT_EXPORT QPolygon clippedPolygon( const QRectF&,
     45        const QPolygon&, bool closePolygon = false );
     46
     47    QWT_EXPORT QPolygonF clippedPolygonF( const QRectF&,
     48        const QPolygonF&, bool closePolygon = false );
     49
     50    QWT_EXPORT QVector< QwtInterval > clipCircle(
     51        const QRectF&, const QPointF&, double radius );
    3852};
    3953
  • trunk/BNC/qwt/qwt_color_map.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_color_map.h"
    11 #include "qwt_math.h"
    1211#include "qwt_interval.h"
    13 #include <qnumeric.h>
     12
     13#include <qvector.h>
     14
     15static inline QRgb qwtHsvToRgb( int h, int s, int v, int a )
     16{
     17#if 0
     18    return QColor::fromHsv( h, s, v, a ).rgb();
     19#else
     20
     21    const double vs = v * s / 255.0;
     22    const int p = v - qRound( vs );
     23
     24    switch( h / 60 )
     25    {
     26        case 0:
     27        {
     28            const double r = ( 60 - h ) / 60.0;
     29            return qRgba( v, v - qRound( r * vs ), p, a );
     30        }
     31        case 1:
     32        {
     33            const double r = ( h - 60 ) / 60.0;
     34            return qRgba( v - qRound( r * vs ), v, p, a );
     35        }
     36        case 2:
     37        {
     38            const double r = ( 180 - h ) / 60.0;
     39            return qRgba( p, v, v - qRound( r * vs ), a );
     40        }
     41        case 3:
     42        {
     43            const double r = ( h - 180 ) / 60.0;
     44            return qRgba( p, v - qRound( r * vs ), v, a );
     45        }
     46        case 4:
     47        {
     48            const double r = ( 300 - h ) / 60.0;
     49            return qRgba( v - qRound( r * vs ), p, v, a );
     50        }
     51        case 5:
     52        default:
     53        {
     54            const double r = ( h - 300 ) / 60.0;
     55            return qRgba( v, p, v - qRound( r * vs ), a );
     56        }
     57    }
     58#endif
     59}
    1460
    1561class QwtLinearColorMap::ColorStops
    1662{
    17 public:
     63  public:
    1864    ColorStops():
    19         d_doAlpha( false )
    20     {
    21         d_stops.reserve( 256 );
    22     }
    23 
    24     void insert( double pos, const QColor &color );
     65        m_doAlpha( false )
     66    {
     67        m_stops.reserve( 256 );
     68    }
     69
     70    void insert( double pos, const QColor& color );
    2571    QRgb rgb( QwtLinearColorMap::Mode, double pos ) const;
    2672
    27     QVector<double> stops() const;
    28 
    29 private:
     73    QVector< double > stops() const;
     74
     75  private:
    3076
    3177    class ColorStop
    3278    {
    33     public:
     79      public:
    3480        ColorStop():
    3581            pos( 0.0 ),
    … …  
    3884        };
    3985
    40         ColorStop( double p, const QColor &c ):
     86        ColorStop( double p, const QColor& c ):
    4187            pos( p ),
    4288            rgb( c.rgba() )
    … …  
    4894
    4995            /*
    50                 when mapping a value to rgb we will have to calcualate:
     96                when mapping a value to rgb we will have to calculate:
    5197                   - const int v = int( ( s1.v0 + ratio * s1.vStep ) + 0.5 );
    5298
    … …  
    62108        }
    63109
    64         void updateSteps( const ColorStop &nextStop )
     110        void updateSteps( const ColorStop& nextStop )
    65111        {
    66112            rStep = nextStop.r - r;
    … …  
    82128
    83129    inline int findUpper( double pos ) const;
    84     QVector<ColorStop> d_stops;
    85     bool d_doAlpha;
     130    QVector< ColorStop > m_stops;
     131    bool m_doAlpha;
    86132};
    87133
    88 void QwtLinearColorMap::ColorStops::insert( double pos, const QColor &color )
     134void QwtLinearColorMap::ColorStops::insert( double pos, const QColor& color )
    89135{
    90136    // Lookups need to be very fast, insertions are not so important.
    … …  
    95141
    96142    int index;
    97     if ( d_stops.size() == 0 )
     143    if ( m_stops.size() == 0 )
    98144    {
    99145        index = 0;
    100         d_stops.resize( 1 );
     146        m_stops.resize( 1 );
    101147    }
    102148    else
    103149    {
    104150        index = findUpper( pos );
    105         if ( index == d_stops.size() ||
    106                 qAbs( d_stops[index].pos - pos ) >= 0.001 )
    107         {
    108             d_stops.resize( d_stops.size() + 1 );
    109             for ( int i = d_stops.size() - 1; i > index; i-- )
    110                 d_stops[i] = d_stops[i-1];
    111         }
    112     }
    113 
    114     d_stops[index] = ColorStop( pos, color );
     151        if ( index == m_stops.size() ||
     152            qAbs( m_stops[index].pos - pos ) >= 0.001 )
     153        {
     154            m_stops.resize( m_stops.size() + 1 );
     155            for ( int i = m_stops.size() - 1; i > index; i-- )
     156                m_stops[i] = m_stops[i - 1];
     157        }
     158    }
     159
     160    m_stops[index] = ColorStop( pos, color );
    115161    if ( color.alpha() != 255 )
    116         d_doAlpha = true;
     162        m_doAlpha = true;
    117163
    118164    if ( index > 0 )
    119         d_stops[index-1].updateSteps( d_stops[index] );
    120 
    121     if ( index < d_stops.size() - 1 )
    122         d_stops[index].updateSteps( d_stops[index+1] );
    123 }
    124 
    125 inline QVector<double> QwtLinearColorMap::ColorStops::stops() const
    126 {
    127     QVector<double> positions( d_stops.size() );
    128     for ( int i = 0; i < d_stops.size(); i++ )
    129         positions[i] = d_stops[i].pos;
     165        m_stops[index - 1].updateSteps( m_stops[index] );
     166
     167    if ( index < m_stops.size() - 1 )
     168        m_stops[index].updateSteps( m_stops[index + 1] );
     169}
     170
     171inline QVector< double > QwtLinearColorMap::ColorStops::stops() const
     172{
     173    QVector< double > positions( m_stops.size() );
     174    for ( int i = 0; i < m_stops.size(); i++ )
     175        positions[i] = m_stops[i].pos;
    130176    return positions;
    131177}
    … …  
    134180{
    135181    int index = 0;
    136     int n = d_stops.size();
    137 
    138     const ColorStop *stops = d_stops.data();
     182    int n = m_stops.size();
     183
     184    const ColorStop* stops = m_stops.data();
    139185
    140186    while ( n > 0 )
    … …  
    159205{
    160206    if ( pos <= 0.0 )
    161         return d_stops[0].rgb;
     207        return m_stops[0].rgb;
    162208    if ( pos >= 1.0 )
    163         return d_stops[ d_stops.size() - 1 ].rgb;
     209        return m_stops[ m_stops.size() - 1 ].rgb;
    164210
    165211    const int index = findUpper( pos );
    166212    if ( mode == FixedColors )
    167213    {
    168         return d_stops[index-1].rgb;
     214        return m_stops[index - 1].rgb;
    169215    }
    170216    else
    171217    {
    172         const ColorStop &s1 = d_stops[index-1];
     218        const ColorStop& s1 = m_stops[index - 1];
    173219
    174220        const double ratio = ( pos - s1.pos ) / ( s1.posStep );
    … …  
    178224        const int b = int( s1.b0 + ratio * s1.bStep );
    179225
    180         if ( d_doAlpha )
     226        if ( m_doAlpha )
    181227        {
    182228            if ( s1.aStep )
    … …  
    197243}
    198244
    199 //! Constructor
    200 QwtColorMap::QwtColorMap( Format format ):
    201     d_format( format )
     245/*!
     246   Constructor
     247   \param format Format of the color map
     248 */
     249QwtColorMap::QwtColorMap( Format format )
     250    : m_format( format )
    202251{
    203252}
    … …  
    209258
    210259/*!
     260   Set the format of the color map
     261
     262   \param format Format of the color map
     263 */
     264void QwtColorMap::setFormat( Format format )
     265{
     266    m_format = format;
     267}
     268
     269/*!
     270   \brief Map a value of a given interval into a color index
     271
     272   \param numColors Number of colors
     273   \param interval Range for all values
     274   \param value Value to map into a color index
     275
     276   \return Index, between 0 and numColors - 1, or -1 for an invalid value
     277 */
     278uint QwtColorMap::colorIndex( int numColors,
     279    const QwtInterval& interval, double value ) const
     280{
     281    const double width = interval.width();
     282    if ( width <= 0.0 )
     283        return 0;
     284
     285    if ( value <= interval.minValue() )
     286        return 0;
     287
     288    const int maxIndex = numColors - 1;
     289    if ( value >= interval.maxValue() )
     290        return maxIndex;
     291
     292    const double v = maxIndex * ( ( value - interval.minValue() ) / width );
     293    return static_cast< unsigned int >( v + 0.5 );
     294}
     295
     296/*!
    211297   Build and return a color map of 256 colors
    212298
    … …  
    214300   with using colorIndex().
    215301
    216    \param interval Range for the values
    217302   \return A color table, that can be used for a QImage
    218 */
    219 QVector<QRgb> QwtColorMap::colorTable( const QwtInterval &interval ) const
    220 {
    221     QVector<QRgb> table( 256 );
    222 
    223     if ( interval.isValid() )
    224     {
    225         const double step = interval.width() / ( table.size() - 1 );
    226         for ( int i = 0; i < table.size(); i++ )
    227             table[i] = rgb( interval, interval.minValue() + step * i );
    228     }
     303 */
     304QVector< QRgb > QwtColorMap::colorTable256() const
     305{
     306    QVector< QRgb > table( 256 );
     307
     308    const QwtInterval interval( 0, 256 );
     309
     310    for ( int i = 0; i < 256; i++ )
     311        table[i] = rgb( interval, i );
    229312
    230313    return table;
    231314}
    232315
     316/*!
     317   Build and return a color map of arbitrary number of colors
     318
     319   The color table is needed for rendering indexed images in combination
     320   with using colorIndex().
     321
     322   \param numColors Number of colors
     323   \return A color table
     324 */
     325QVector< QRgb > QwtColorMap::colorTable( int numColors ) const
     326{
     327    QVector< QRgb > table( numColors );
     328
     329    const QwtInterval interval( 0.0, 1.0 );
     330
     331    const double step = 1.0 / ( numColors - 1 );
     332    for ( int i = 0; i < numColors; i++ )
     333        table[i] = rgb( interval, step * i );
     334
     335    return table;
     336}
     337
    233338class QwtLinearColorMap::PrivateData
    234339{
    235 public:
     340  public:
    236341    ColorStops colorStops;
    237342    QwtLinearColorMap::Mode mode;
    … …  
    243348
    244349   \param format Preferred format of the color map
    245 */
     350 */
    246351QwtLinearColorMap::QwtLinearColorMap( QwtColorMap::Format format ):
    247352    QwtColorMap( format )
    248353{
    249     d_data = new PrivateData;
    250     d_data->mode = ScaledColors;
     354    m_data = new PrivateData;
     355    m_data->mode = ScaledColors;
    251356
    252357    setColorInterval( Qt::blue, Qt::yellow );
    … …  
    259364   \param color2 Color used for the maximum value of the value interval
    260365   \param format Preferred format for the color map
    261 */
    262 QwtLinearColorMap::QwtLinearColorMap( const QColor &color1,
    263         const QColor &color2, QwtColorMap::Format format ):
    264     QwtColorMap( format )
    265 {
    266     d_data = new PrivateData;
    267     d_data->mode = ScaledColors;
     366 */
     367QwtLinearColorMap::QwtLinearColorMap( const QColor& color1,
     368        const QColor& color2, QwtColorMap::Format format )
     369    : QwtColorMap( format )
     370{
     371    m_data = new PrivateData;
     372    m_data->mode = ScaledColors;
    268373    setColorInterval( color1, color2 );
    269374}
    … …  
    272377QwtLinearColorMap::~QwtLinearColorMap()
    273378{
    274     delete d_data;
     379    delete m_data;
    275380}
    276381
    … …  
    283388
    284389   \sa mode()
    285 */
     390 */
    286391void QwtLinearColorMap::setMode( Mode mode )
    287392{
    288     d_data->mode = mode;
     393    m_data->mode = mode;
    289394}
    290395
    … …  
    292397   \return Mode of the color map
    293398   \sa setMode()
    294 */
     399 */
    295400QwtLinearColorMap::Mode QwtLinearColorMap::mode() const
    296401{
    297     return d_data->mode;
     402    return m_data->mode;
    298403}
    299404
    … …  
    307412
    308413   \sa color1(), color2()
    309 */
     414 */
    310415void QwtLinearColorMap::setColorInterval(
    311     const QColor &color1, const QColor &color2 )
    312 {
    313     d_data->colorStops = ColorStops();
    314     d_data->colorStops.insert( 0.0, color1 );
    315     d_data->colorStops.insert( 1.0, color2 );
     416    const QColor& color1, const QColor& color2 )
     417{
     418    m_data->colorStops = ColorStops();
     419    m_data->colorStops.insert( 0.0, color1 );
     420    m_data->colorStops.insert( 1.0, color2 );
    316421}
    317422
    … …  
    325430   \param value Value between [0.0, 1.0]
    326431   \param color Color stop
    327 */
     432 */
    328433void QwtLinearColorMap::addColorStop( double value, const QColor& color )
    329434{
    330435    if ( value >= 0.0 && value <= 1.0 )
    331         d_data->colorStops.insert( value, color );
     436        m_data->colorStops.insert( value, color );
    332437}
    333438
    334439/*!
    335440   \return Positions of color stops in increasing order
    336 */
    337 QVector<double> QwtLinearColorMap::colorStops() const
    338 {
    339     return d_data->colorStops.stops();
    340 }
    341 
    342 /*!
    343   \return the first color of the color range
    344   \sa setColorInterval()
    345 */
     441 */
     442QVector< double > QwtLinearColorMap::colorStops() const
     443{
     444    return m_data->colorStops.stops();
     445}
     446
     447/*!
     448   \return the first color of the color range
     449   \sa setColorInterval()
     450 */
    346451QColor QwtLinearColorMap::color1() const
    347452{
    348     return QColor::fromRgba( d_data->colorStops.rgb( d_data->mode, 0.0 ) );
    349 }
    350 
    351 /*!
    352   \return the second color of the color range
    353   \sa setColorInterval()
    354 */
     453    return QColor::fromRgba( m_data->colorStops.rgb( m_data->mode, 0.0 ) );
     454}
     455
     456/*!
     457   \return the second color of the color range
     458   \sa setColorInterval()
     459 */
    355460QColor QwtLinearColorMap::color2() const
    356461{
    357     return QColor::fromRgba( d_data->colorStops.rgb( d_data->mode, 1.0 ) );
    358 }
    359 
    360 /*!
    361   Map a value of a given interval into a RGB value
    362 
    363   \param interval Range for all values
    364   \param value Value to map into a RGB value
    365 
    366   \return RGB value for value
    367 */
     462    return QColor::fromRgba( m_data->colorStops.rgb( m_data->mode, 1.0 ) );
     463}
     464
     465/*!
     466   Map a value of a given interval into a RGB value
     467
     468   \param interval Range for all values
     469   \param value Value to map into a RGB value
     470
     471   \return RGB value for value
     472 */
    368473QRgb QwtLinearColorMap::rgb(
    369     const QwtInterval &interval, double value ) const
    370 {
    371     if ( qIsNaN(value) )
    372         return 0u;
    373 
     474    const QwtInterval& interval, double value ) const
     475{
    374476    const double width = interval.width();
    375477    if ( width <= 0.0 )
    … …  
    377479
    378480    const double ratio = ( value - interval.minValue() ) / width;
    379     return d_data->colorStops.rgb( d_data->mode, ratio );
    380 }
    381 
    382 /*!
    383   \brief Map a value of a given interval into a color index
    384 
    385   \param interval Range for all values
    386   \param value Value to map into a color index
    387 
    388   \return Index, between 0 and 255
    389 */
    390 unsigned char QwtLinearColorMap::colorIndex(
    391     const QwtInterval &interval, double value ) const
     481    return m_data->colorStops.rgb( m_data->mode, ratio );
     482}
     483
     484/*!
     485   \brief Map a value of a given interval into a color index
     486
     487   \param numColors Size of the color table
     488   \param interval Range for all values
     489   \param value Value to map into a color index
     490
     491   \return Index, between 0 and 255
     492   \note NaN values are mapped to 0
     493 */
     494uint QwtLinearColorMap::colorIndex( int numColors,
     495    const QwtInterval& interval, double value ) const
    392496{
    393497    const double width = interval.width();
    394 
    395     if ( qIsNaN(value) || width <= 0.0 || value <= interval.minValue() )
     498    if ( width <= 0.0 )
    396499        return 0;
    397500
     501    if ( value <= interval.minValue() )
     502        return 0;
     503
    398504    if ( value >= interval.maxValue() )
    399         return 255;
    400 
    401     const double ratio = ( value - interval.minValue() ) / width;
    402 
    403     unsigned char index;
    404     if ( d_data->mode == FixedColors )
    405         index = static_cast<unsigned char>( ratio * 255 ); // always floor
    406     else
    407         index = static_cast<unsigned char>( ratio * 255 + 0.5 );
    408 
    409     return index;
     505        return numColors - 1;
     506
     507    const double v = ( numColors - 1 ) * ( value - interval.minValue() ) / width;
     508    return static_cast< unsigned int >( ( m_data->mode == FixedColors ) ? v : v + 0.5 );
    410509}
    411510
    412511class QwtAlphaColorMap::PrivateData
    413512{
    414 public:
     513  public:
     514    PrivateData()
     515        : alpha1(0)
     516        , alpha2(255)
     517    {
     518    }
     519
     520    int alpha1, alpha2;
     521
    415522    QColor color;
    416523    QRgb rgb;
     524
     525    QRgb rgbMin;
    417526    QRgb rgbMax;
    418527};
    … …  
    420529
    421530/*!
    422    Constructor
     531   \brief Constructor
     532
     533   The alpha interval is initialized by 0 to 255.
     534
    423535   \param color Color of the map
    424 */
    425 QwtAlphaColorMap::QwtAlphaColorMap( const QColor &color ):
    426     QwtColorMap( QwtColorMap::RGB )
    427 {
    428     d_data = new PrivateData;
     536
     537   \sa setColor(), setAlphaInterval()
     538 */
     539QwtAlphaColorMap::QwtAlphaColorMap( const QColor& color )
     540    : QwtColorMap( QwtColorMap::RGB )
     541{
     542    m_data = new PrivateData;
    429543    setColor( color );
    430544}
    … …  
    433547QwtAlphaColorMap::~QwtAlphaColorMap()
    434548{
    435     delete d_data;
     549    delete m_data;
    436550}
    437551
    … …  
    441555   \param color Color
    442556   \sa color()
    443 */
    444 void QwtAlphaColorMap::setColor( const QColor &color )
    445 {
    446     d_data->color = color;
    447     d_data->rgb = color.rgb() & qRgba( 255, 255, 255, 0 );
    448     d_data->rgbMax = d_data->rgb | ( 255 << 24 );
    449 }
    450 
    451 /*!
    452   \return the color
    453   \sa setColor()
    454 */
     557 */
     558void QwtAlphaColorMap::setColor( const QColor& color )
     559{
     560    m_data->color = color;
     561    m_data->rgb = color.rgb() & qRgba( 255, 255, 255, 0 );
     562
     563    m_data->rgbMin = m_data->rgb | ( m_data->alpha1 << 24 );
     564    m_data->rgbMax = m_data->rgb | ( m_data->alpha2 << 24 );
     565}
     566
     567/*!
     568   \return the color
     569   \sa setColor()
     570 */
    455571QColor QwtAlphaColorMap::color() const
    456572{
    457     return d_data->color;
    458 }
    459 
    460 /*!
    461   \brief Map a value of a given interval into a alpha value
    462 
    463   alpha := (value - interval.minValue()) / interval.width();
    464 
    465   \param interval Range for all values
    466   \param value Value to map into a RGB value
    467   \return RGB value, with an alpha value
    468 */
    469 QRgb QwtAlphaColorMap::rgb( const QwtInterval &interval, double value ) const
    470 {
    471     if ( qIsNaN(value) )
    472         return 0u;
    473 
     573    return m_data->color;
     574}
     575
     576/*!
     577   Set the interval for the alpha coordinate
     578
     579   alpha1/alpha2 need to be in the range 0 to 255,
     580   where 255 means opaque and 0 means transparent.
     581
     582   \param alpha1 First alpha coordinate
     583   \param alpha2 Second alpha coordinate
     584
     585   \sa alpha1(), alpha2()
     586 */
     587void QwtAlphaColorMap::setAlphaInterval( int alpha1, int alpha2 )
     588{
     589    m_data->alpha1 = qBound( 0, alpha1, 255 );
     590    m_data->alpha2 = qBound( 0, alpha2, 255 );
     591
     592    m_data->rgbMin = m_data->rgb | ( alpha1 << 24 );
     593    m_data->rgbMax = m_data->rgb | ( alpha2 << 24 );
     594}
     595
     596/*!
     597   \return First alpha coordinate
     598   \sa setAlphaInterval()
     599 */
     600int QwtAlphaColorMap::alpha1() const
     601{
     602    return m_data->alpha1;
     603}
     604
     605/*!
     606   \return Second alpha coordinate
     607   \sa setAlphaInterval()
     608 */
     609int QwtAlphaColorMap::alpha2() const
     610{
     611    return m_data->alpha2;
     612}
     613
     614/*!
     615   \brief Map a value of a given interval into a alpha value
     616
     617   \param interval Range for all values
     618   \param value Value to map into a RGB value
     619
     620   \return RGB value, with an alpha value
     621 */
     622QRgb QwtAlphaColorMap::rgb( const QwtInterval& interval, double value ) const
     623{
    474624    const double width = interval.width();
    475625    if ( width <= 0.0 )
    … …  
    477627
    478628    if ( value <= interval.minValue() )
    479         return d_data->rgb;
     629        return m_data->rgb;
    480630
    481631    if ( value >= interval.maxValue() )
    482         return d_data->rgbMax;
     632        return m_data->rgbMax;
    483633
    484634    const double ratio = ( value - interval.minValue() ) / width;
    485     return d_data->rgb | ( qRound( 255 * ratio ) << 24 );
    486 }
    487 
    488 /*!
    489   Dummy function, needed to be implemented as it is pure virtual
    490   in QwtColorMap. Color indices make no sense in combination with
    491   an alpha channel.
    492 
    493   \return Always 0
    494 */
    495 unsigned char QwtAlphaColorMap::colorIndex(
    496     const QwtInterval &, double ) const
    497 {
    498     return 0;
    499 }
     635    const int alpha = m_data->alpha1 + qRound( ratio * ( m_data->alpha2 - m_data->alpha1 ) );
     636
     637    return m_data->rgb | ( alpha << 24 );
     638}
     639
     640class QwtHueColorMap::PrivateData
     641{
     642  public:
     643    PrivateData();
     644
     645    void updateTable();
     646
     647    int hue1, hue2;
     648    int saturation;
     649    int value;
     650    int alpha;
     651
     652    QRgb rgbMin;
     653    QRgb rgbMax;
     654
     655    QRgb rgbTable[360];
     656};
     657
     658QwtHueColorMap::PrivateData::PrivateData()
     659    : hue1(0)
     660    , hue2(359)
     661    , saturation(255)
     662    , value(255)
     663    , alpha(255)
     664{
     665    updateTable();
     666}
     667
     668void QwtHueColorMap::PrivateData::updateTable()
     669{
     670    const int p = qRound( value * ( 255 - saturation ) / 255.0 );
     671    const double vs = value * saturation / 255.0;
     672
     673    for ( int i = 0; i < 60; i++ )
     674    {
     675        const double r = ( 60 - i ) / 60.0;
     676        rgbTable[i] = qRgba( value, qRound( value - r * vs ), p, alpha );
     677    }
     678
     679    for ( int i = 60; i < 120; i++ )
     680    {
     681        const double r = ( i - 60 ) / 60.0;
     682        rgbTable[i] = qRgba( qRound( value - r * vs ), value, p, alpha );
     683    }
     684
     685    for ( int i = 120; i < 180; i++ )
     686    {
     687        const double r = ( 180 - i ) / 60.0;
     688        rgbTable[i] = qRgba( p, value, qRound( value - r * vs ), alpha );
     689    }
     690
     691    for ( int i = 180; i < 240; i++ )
     692    {
     693        const double r = ( i - 180 ) / 60.0;
     694        rgbTable[i] = qRgba( p, qRound( value - r * vs ), value, alpha );
     695    }
     696
     697    for ( int i = 240; i < 300; i++ )
     698    {
     699        const double r = ( 300 - i ) / 60.0;
     700        rgbTable[i] = qRgba( qRound( value - r * vs ), p, value, alpha );
     701    }
     702
     703    for ( int i = 300; i < 360; i++ )
     704    {
     705        const double r = ( i - 300 ) / 60.0;
     706        rgbTable[i] = qRgba( value, p, qRound( value - r * vs ), alpha );
     707    }
     708
     709    rgbMin = rgbTable[ hue1 % 360 ];
     710    rgbMax = rgbTable[ hue2 % 360 ];
     711}
     712
     713/*!
     714   \brief Constructor
     715
     716   The hue interval is initialized by 0 to 359. All other coordinates
     717   are set to 255.
     718
     719   \param format Format of the color map
     720
     721   \sa setHueInterval(), setSaturation(), setValue(), setValue()
     722 */
     723QwtHueColorMap::QwtHueColorMap( QwtColorMap::Format format )
     724    : QwtColorMap( format )
     725{
     726    m_data = new PrivateData;
     727}
     728
     729//! Destructor
     730QwtHueColorMap::~QwtHueColorMap()
     731{
     732    delete m_data;
     733}
     734
     735/*!
     736   Set the interval for the hue coordinate
     737
     738   hue1/hue2 need to be positive number and can be > 360 to define cycles.
     739   F.e. 420 to 240 defines a map yellow/red/magenta/blue.
     740
     741   \param hue1 First hue coordinate
     742   \param hue2 Second hue coordinate
     743
     744   \sa hue1(), hue2()
     745 */
     746void QwtHueColorMap::setHueInterval( int hue1, int hue2 )
     747{
     748    m_data->hue1 = qMax( hue1, 0 );
     749    m_data->hue2 = qMax( hue2, 0 );
     750
     751    m_data->rgbMin = m_data->rgbTable[ hue1 % 360 ];
     752    m_data->rgbMax = m_data->rgbTable[ hue2 % 360 ];
     753}
     754
     755/*!
     756   \brief Set the the saturation coordinate
     757
     758   saturation needs to be in the range 0 to 255,
     759
     760   \param saturation Saturation coordinate
     761
     762   \sa saturation()
     763 */
     764void QwtHueColorMap::setSaturation( int saturation )
     765{
     766    saturation = qBound( 0, saturation, 255 );
     767
     768    if ( saturation != m_data->saturation )
     769    {
     770        m_data->saturation = saturation;
     771        m_data->updateTable();
     772    }
     773}
     774
     775/*!
     776   \brief Set the the value coordinate
     777
     778   value needs to be in the range 0 to 255,
     779
     780   \param value Value coordinate
     781
     782   \sa value()
     783 */
     784void QwtHueColorMap::setValue( int value )
     785{
     786    value = qBound( 0, value, 255 );
     787
     788    if ( value != m_data->value )
     789    {
     790        m_data->value = value;
     791        m_data->updateTable();
     792    }
     793}
     794
     795/*!
     796   \brief Set the the alpha coordinate
     797
     798   alpha needs to be in the range 0 to 255,
     799   where 255 means opaque and 0 means transparent.
     800
     801   \param alpha Alpha coordinate
     802
     803   \sa alpha()
     804 */
     805void QwtHueColorMap::setAlpha( int alpha )
     806{
     807    alpha = qBound( 0, alpha, 255 );
     808
     809    if ( alpha != m_data->alpha )
     810    {
     811        m_data->alpha = alpha;
     812        m_data->updateTable();
     813    }
     814}
     815
     816/*!
     817   \return First hue coordinate
     818   \sa setHueInterval()
     819 */
     820int QwtHueColorMap::hue1() const
     821{
     822    return m_data->hue1;
     823}
     824
     825/*!
     826   \return Second hue coordinate
     827   \sa setHueInterval()
     828 */
     829int QwtHueColorMap::hue2() const
     830{
     831    return m_data->hue2;
     832}
     833
     834/*!
     835   \return Saturation coordinate
     836   \sa setSaturation()
     837 */
     838int QwtHueColorMap::saturation() const
     839{
     840    return m_data->saturation;
     841}
     842
     843/*!
     844   \return Value coordinate
     845   \sa setValue()
     846 */
     847int QwtHueColorMap::value() const
     848{
     849    return m_data->value;
     850}
     851
     852/*!
     853   \return Alpha coordinate
     854   \sa setAlpha()
     855 */
     856int QwtHueColorMap::alpha() const
     857{
     858    return m_data->alpha;
     859}
     860
     861/*!
     862   Map a value of a given interval into a RGB value
     863
     864   \param interval Range for all values
     865   \param value Value to map into a RGB value
     866
     867   \return RGB value for value
     868 */
     869QRgb QwtHueColorMap::rgb( const QwtInterval& interval, double value ) const
     870{
     871    const double width = interval.width();
     872    if ( width <= 0 )
     873        return 0u;
     874
     875    if ( value <= interval.minValue() )
     876        return m_data->rgbMin;
     877
     878    if ( value >= interval.maxValue() )
     879        return m_data->rgbMax;
     880
     881    const double ratio = ( value - interval.minValue() ) / width;
     882
     883    int hue = m_data->hue1 + qRound( ratio * ( m_data->hue2 - m_data->hue1 ) );
     884    if ( hue >= 360 )
     885    {
     886        hue -= 360;
     887
     888        if ( hue >= 360 )
     889            hue = hue % 360;
     890    }
     891
     892    return m_data->rgbTable[hue];
     893}
     894
     895class QwtSaturationValueColorMap::PrivateData
     896{
     897  public:
     898    PrivateData()
     899        : hue(0)
     900        , sat1(255)
     901        , sat2(255)
     902        , value1(0)
     903        , value2(255)
     904        , alpha(255)
     905        , tableType(Invalid)
     906    {
     907        updateTable();
     908    }
     909
     910    void updateTable()
     911    {
     912        tableType = Invalid;
     913
     914        if ( ( value1 == value2 ) && ( sat1 != sat2 ) )
     915        {
     916            rgbTable.resize( 256 );
     917
     918            for ( int i = 0; i < 256; i++ )
     919                rgbTable[i] = qwtHsvToRgb( hue, i, value1, alpha );
     920
     921            tableType = Saturation;
     922        }
     923        else if ( ( value1 != value2 ) && ( sat1 == sat2 ) )
     924        {
     925            rgbTable.resize( 256 );
     926
     927            for ( int i = 0; i < 256; i++ )
     928                rgbTable[i] = qwtHsvToRgb( hue, sat1, i, alpha );
     929
     930            tableType = Value;
     931        }
     932        else
     933        {
     934            rgbTable.resize( 256 * 256 );
     935
     936            for ( int s = 0; s < 256; s++ )
     937            {
     938                const int v0 = s * 256;
     939
     940                for ( int v = 0; v < 256; v++ )
     941                    rgbTable[v0 + v] = qwtHsvToRgb( hue, s, v, alpha );
     942            }
     943        }
     944    }
     945
     946    int hue;
     947    int sat1, sat2;
     948    int value1, value2;
     949    int alpha;
     950
     951    enum
     952    {
     953        Invalid,
     954        Value,
     955        Saturation
     956
     957    } tableType;
     958
     959    QVector< QRgb > rgbTable;
     960};
     961
     962/*!
     963   \brief Constructor
     964
     965   The value interval is initialized by 0 to 255,
     966   saturation by 255 to 255. Hue to 0 and alpha to 255.
     967
     968   So the default setting interpolates the value coordinate only.
     969
     970   \sa setHueInterval(), setSaturation(), setValue(), setValue()
     971 */
     972QwtSaturationValueColorMap::QwtSaturationValueColorMap()
     973{
     974    m_data = new PrivateData;
     975}
     976
     977//! Destructor
     978QwtSaturationValueColorMap::~QwtSaturationValueColorMap()
     979{
     980    delete m_data;
     981}
     982
     983/*!
     984   \brief Set the the hue coordinate
     985
     986   Hue coordinates outside 0 to 359 will be interpreted as hue % 360..
     987
     988   \param hue Hue coordinate
     989
     990   \sa hue()
     991 */
     992void QwtSaturationValueColorMap::setHue( int hue )
     993{
     994    hue = hue % 360;
     995
     996    if ( hue != m_data->hue )
     997    {
     998        m_data->hue = hue;
     999        m_data->updateTable();
     1000    }
     1001}
     1002
     1003/*!
     1004   \brief Set the interval for the saturation coordinate
     1005
     1006   When saturation1 == saturation2 the map interpolates between
     1007   the value coordinates only
     1008
     1009   saturation1/saturation2 need to be in the range 0 to 255.
     1010
     1011   \param saturation1 First saturation
     1012   \param saturation2 Second saturation
     1013
     1014   \sa saturation1(), saturation2(), setValueInterval()
     1015 */
     1016void QwtSaturationValueColorMap::setSaturationInterval(
     1017    int saturation1, int saturation2 )
     1018{
     1019    saturation1 = qBound( 0, saturation1, 255 );
     1020    saturation2 = qBound( 0, saturation2, 255 );
     1021
     1022    if ( ( saturation1 != m_data->sat1 ) || ( saturation2 != m_data->sat2 ) )
     1023    {
     1024        m_data->sat1 = saturation1;
     1025        m_data->sat2 = saturation2;
     1026
     1027        m_data->updateTable();
     1028    }
     1029}
     1030
     1031/*!
     1032   \brief Set the interval for the value coordinate
     1033
     1034   When value1 == value2 the map interpolates between the saturation coordinates only.
     1035
     1036   value1/value2 need to be in the range 0 to 255.
     1037
     1038   \param value1 First value
     1039   \param value2 Second value
     1040
     1041   \sa value1(), value2(), setSaturationInterval()
     1042 */
     1043void QwtSaturationValueColorMap::setValueInterval( int value1, int value2 )
     1044{
     1045    value1 = qBound( 0, value1, 255 );
     1046    value2 = qBound( 0, value2, 255 );
     1047
     1048    if ( ( value1 != m_data->value1 ) || ( value2 != m_data->value2 ) )
     1049    {
     1050        m_data->value1 = value1;
     1051        m_data->value2 = value2;
     1052
     1053        m_data->updateTable();
     1054    }
     1055}
     1056
     1057/*!
     1058   \brief Set the the alpha coordinate
     1059
     1060   alpha needs to be in the range 0 to 255,
     1061   where 255 means opaque and 0 means transparent.
     1062
     1063   \param alpha Alpha coordinate
     1064
     1065   \sa alpha()
     1066 */
     1067void QwtSaturationValueColorMap::setAlpha( int alpha )
     1068{
     1069    alpha = qBound( 0, alpha, 255 );
     1070
     1071    if ( alpha != m_data->alpha )
     1072    {
     1073        m_data->alpha = alpha;
     1074        m_data->updateTable();
     1075    }
     1076}
     1077
     1078/*!
     1079   \return Hue coordinate
     1080   \sa setHue()
     1081 */
     1082int QwtSaturationValueColorMap::hue() const
     1083{
     1084    return m_data->hue;
     1085}
     1086
     1087/*!
     1088   \return First saturation coordinate
     1089   \sa setSaturationInterval()
     1090 */
     1091int QwtSaturationValueColorMap::saturation1() const
     1092{
     1093    return m_data->sat1;
     1094}
     1095
     1096/*!
     1097   \return Second saturation coordinate
     1098   \sa setSaturationInterval()
     1099 */
     1100int QwtSaturationValueColorMap::saturation2() const
     1101{
     1102    return m_data->sat2;
     1103}
     1104
     1105/*!
     1106   \return First value coordinate
     1107   \sa setValueInterval()
     1108 */
     1109int QwtSaturationValueColorMap::value1() const
     1110{
     1111    return m_data->value1;
     1112}
     1113
     1114/*!
     1115   \return Second value coordinate
     1116   \sa setValueInterval()
     1117 */
     1118int QwtSaturationValueColorMap::value2() const
     1119{
     1120    return m_data->value2;
     1121}
     1122
     1123/*!
     1124   \return Alpha coordinate
     1125   \sa setAlpha()
     1126 */
     1127int QwtSaturationValueColorMap::alpha() const
     1128{
     1129    return m_data->alpha;
     1130}
     1131
     1132/*!
     1133   Map a value of a given interval into a RGB value
     1134
     1135   \param interval Range for all values
     1136   \param value Value to map into a RGB value
     1137
     1138   \return RGB value for value
     1139 */
     1140QRgb QwtSaturationValueColorMap::rgb(
     1141    const QwtInterval& interval, double value ) const
     1142{
     1143    const double width = interval.width();
     1144    if ( width <= 0 )
     1145        return 0u;
     1146
     1147    const QRgb* rgbTable = m_data->rgbTable.constData();
     1148
     1149    switch( m_data->tableType )
     1150    {
     1151        case PrivateData::Saturation:
     1152        {
     1153            if ( value <= interval.minValue() )
     1154                return m_data->rgbTable[m_data->sat1];
     1155
     1156            if ( value >= interval.maxValue() )
     1157                return m_data->rgbTable[m_data->sat2];
     1158
     1159            const double ratio = ( value - interval.minValue() ) / width;
     1160            const int sat = m_data->sat1
     1161                + qRound( ratio * ( m_data->sat2 - m_data->sat1 ) );
     1162
     1163            return rgbTable[sat];
     1164        }
     1165        case PrivateData::Value:
     1166        {
     1167            if ( value <= interval.minValue() )
     1168                return m_data->rgbTable[m_data->value1];
     1169
     1170            if ( value >= interval.maxValue() )
     1171                return m_data->rgbTable[m_data->value2];
     1172
     1173            const double ratio = ( value - interval.minValue() ) / width;
     1174            const int v = m_data->value1 +
     1175                qRound( ratio * ( m_data->value2 - m_data->value1 ) );
     1176
     1177            return rgbTable[ v ];
     1178        }
     1179        default:
     1180        {
     1181            int s, v;
     1182            if ( value <= interval.minValue() )
     1183            {
     1184                s = m_data->sat1;
     1185                v = m_data->value1;
     1186            }
     1187            else if ( value >= interval.maxValue() )
     1188            {
     1189                s = m_data->sat2;
     1190                v = m_data->value2;
     1191            }
     1192            else
     1193            {
     1194                const double ratio = ( value - interval.minValue() ) / width;
     1195
     1196                v = m_data->value1 + qRound( ratio * ( m_data->value2 - m_data->value1 ) );
     1197                s = m_data->sat1 + qRound( ratio * ( m_data->sat2 - m_data->sat1 ) );
     1198            }
     1199
     1200            return rgbTable[ 256 * s + v ];
     1201        }
     1202    }
     1203}
  • trunk/BNC/qwt/qwt_color_map.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_interval.h"
    1514#include <qcolor.h>
    16 #include <qvector.h>
    17 
    18 /*!
    19   \brief QwtColorMap is used to map values into colors.
    20 
    21   For displaying 3D data on a 2D plane the 3rd dimension is often
    22   displayed using colors, like f.e in a spectrogram.
    23 
    24   Each color map is optimized to return colors for only one of the
    25   following image formats:
    26 
    27   - QImage::Format_Indexed8\n
    28   - QImage::Format_ARGB32\n
    29 
    30   \sa QwtPlotSpectrogram, QwtScaleWidget
    31 */
     15
     16class QwtInterval;
     17
     18#if QT_VERSION < 0x060000
     19template< typename T > class QVector;
     20#endif
     21
     22/*!
     23   \brief QwtColorMap is used to map values into colors.
     24
     25   For displaying 3D data on a 2D plane the 3rd dimension is often
     26   displayed using colors, like f.e in a spectrogram.
     27
     28   Each color map is optimized to return colors for only one of the
     29   following image formats:
     30
     31   - QImage::Format_Indexed8\n
     32   - QImage::Format_ARGB32\n
     33
     34   \sa QwtPlotSpectrogram, QwtScaleWidget
     35 */
    3236
    3337class QWT_EXPORT QwtColorMap
    3438{
    35 public:
     39  public:
    3640    /*!
    3741        Format for color mapping
    3842        \sa rgb(), colorIndex(), colorTable()
    39     */
     43     */
    4044
    4145    enum Format
    … …  
    4549
    4650        /*!
    47           The map is intended to map into 8 bit values, that
    48           are indices into the color table.
     51           Map values into 8 bit values, that
     52           are used as indexes into the color table.
     53
     54           Indexed color maps are used to generate QImage::Format_Indexed8
     55           images. The calculation of the color index is usually faster
     56           and the resulting image has a lower memory footprint.
     57
     58           \sa colorIndex(), colorTable()
    4959         */
    5060        Indexed
    5161    };
    5262
    53     QwtColorMap( Format = QwtColorMap::RGB );
     63    explicit QwtColorMap( Format = QwtColorMap::RGB );
    5464    virtual ~QwtColorMap();
    5565
     66    void setFormat( Format );
    5667    Format format() const;
    5768
    … …  
    6273       \param value Value
    6374       \return RGB value, corresponding to value
    64     */
    65     virtual QRgb rgb( const QwtInterval &interval,
    66         double value ) const = 0;
    67 
    68     /*!
    69        Map a value of a given interval into a color index
    70 
    71        \param interval Range for the values
    72        \param value Value
    73        \return color index, corresponding to value
    7475     */
    75     virtual unsigned char colorIndex(
    76         const QwtInterval &interval, double value ) const = 0;
    77 
    78     QColor color( const QwtInterval &, double value ) const;
    79     virtual QVector<QRgb> colorTable( const QwtInterval & ) const;
    80 
    81 private:
    82     Format d_format;
    83 };
    84 
    85 /*!
    86   \brief QwtLinearColorMap builds a color map from color stops.
    87 
    88   A color stop is a color at a specific position. The valid
    89   range for the positions is [0.0, 1.0]. When mapping a value
    90   into a color it is translated into this interval according to mode().
    91 */
    92 class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
    93 {
    94 public:
     76    virtual QRgb rgb( const QwtInterval& interval, double value ) const = 0;
     77
     78    virtual uint colorIndex( int numColors,
     79        const QwtInterval& interval, double value ) const;
     80
     81    QColor color( const QwtInterval&, double value ) const;
     82    virtual QVector< QRgb > colorTable( int numColors ) const;
     83    virtual QVector< QRgb > colorTable256() const;
     84
     85  private:
     86    Q_DISABLE_COPY(QwtColorMap)
     87
     88    Format m_format;
     89};
     90
     91/*!
     92   \brief QwtLinearColorMap builds a color map from color stops.
     93
     94   A color stop is a color at a specific position. The valid
     95   range for the positions is [0.0, 1.0]. When mapping a value
     96   into a color it is translated into this interval according to mode().
     97 */
     98class QWT_EXPORT QwtLinearColorMap : public QwtColorMap
     99{
     100  public:
    95101    /*!
    96102       Mode of color map
    97103       \sa setMode(), mode()
    98     */
     104     */
    99105    enum Mode
    100106    {
    … …  
    106112    };
    107113
    108     QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB );
    109     QwtLinearColorMap( const QColor &color1, const QColor &color2,
     114    explicit QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB );
     115
     116    QwtLinearColorMap( const QColor& from, const QColor& to,
    110117        QwtColorMap::Format = QwtColorMap::RGB );
    111118
    … …  
    115122    Mode mode() const;
    116123
    117     void setColorInterval( const QColor &color1, const QColor &color2 );
     124    void setColorInterval( const QColor& color1, const QColor& color2 );
    118125    void addColorStop( double value, const QColor& );
    119     QVector<double> colorStops() const;
     126    QVector< double > colorStops() const;
    120127
    121128    QColor color1() const;
    122129    QColor color2() const;
    123130
    124     virtual QRgb rgb( const QwtInterval &, double value ) const;
    125     virtual unsigned char colorIndex(
    126         const QwtInterval &, double value ) const;
     131    virtual QRgb rgb( const QwtInterval&,
     132        double value ) const QWT_OVERRIDE;
     133
     134    virtual uint colorIndex( int numColors,
     135        const QwtInterval&, double value ) const QWT_OVERRIDE;
    127136
    128137    class ColorStops;
    129138
    130 private:
    131     // Disabled copy constructor and operator=
    132     QwtLinearColorMap( const QwtLinearColorMap & );
    133     QwtLinearColorMap &operator=( const QwtLinearColorMap & );
    134 
    135     class PrivateData;
    136     PrivateData *d_data;
    137 };
    138 
    139 /*!
    140   \brief QwtAlphaColorMap varies the alpha value of a color
    141 */
    142 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
    143 {
    144 public:
    145     QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) );
     139  private:
     140    class PrivateData;
     141    PrivateData* m_data;
     142};
     143
     144/*!
     145   \brief QwtAlphaColorMap varies the alpha value of a color
     146 */
     147class QWT_EXPORT QwtAlphaColorMap : public QwtColorMap
     148{
     149  public:
     150    explicit QwtAlphaColorMap( const QColor& = QColor( Qt::gray ) );
    146151    virtual ~QwtAlphaColorMap();
    147152
    148     void setColor( const QColor & );
     153    void setAlphaInterval( int alpha1, int alpha2 );
     154
     155    int alpha1() const;
     156    int alpha2() const;
     157
     158    void setColor( const QColor& );
    149159    QColor color() const;
    150160
    151     virtual QRgb rgb( const QwtInterval &, double value ) const;
    152 
    153 private:
    154     QwtAlphaColorMap( const QwtAlphaColorMap & );
    155     QwtAlphaColorMap &operator=( const QwtAlphaColorMap & );
    156 
    157     virtual unsigned char colorIndex(
    158         const QwtInterval &, double value ) const;
    159 
    160     class PrivateData;
    161     PrivateData *d_data;
    162 };
    163 
     161    virtual QRgb rgb( const QwtInterval&,
     162        double value ) const QWT_OVERRIDE;
     163
     164  private:
     165    class PrivateData;
     166    PrivateData* m_data;
     167};
     168
     169/*!
     170   \brief QwtHueColorMap varies the hue value of the HSV color model.
     171
     172   QwtHueColorMap can be used to set up a color map easily, that runs cyclic over
     173   all colors. Each cycle has 360 different steps.
     174
     175   The values for value and saturation are in the range of 0 to 255 and doesn't
     176   depend on the data value to be mapped.
     177
     178   \sa QwtSaturationValueColorMap
     179 */
     180class QWT_EXPORT QwtHueColorMap : public QwtColorMap
     181{
     182  public:
     183    explicit QwtHueColorMap( QwtColorMap::Format = QwtColorMap::RGB );
     184    virtual ~QwtHueColorMap();
     185
     186    void setHueInterval( int hue1, int hue2 ); // direction ?
     187    void setSaturation( int saturation );
     188    void setValue( int value );
     189    void setAlpha( int alpha );
     190
     191    int hue1() const;
     192    int hue2() const;
     193    int saturation() const;
     194    int value() const;
     195    int alpha() const;
     196
     197    virtual QRgb rgb( const QwtInterval&,
     198        double value ) const QWT_OVERRIDE;
     199
     200  private:
     201    class PrivateData;
     202    PrivateData* m_data;
     203};
     204
     205/*!
     206   \brief QwtSaturationValueColorMap varies the saturation and/or value for a given
     207         hue in the HSV color model.
     208
     209   Value and saturation are in the range of 0 to 255 while hue is in the range
     210   of 0 to 259.
     211
     212   \sa QwtHueColorMap
     213 */
     214class QWT_EXPORT QwtSaturationValueColorMap : public QwtColorMap
     215{
     216  public:
     217    QwtSaturationValueColorMap();
     218    virtual ~QwtSaturationValueColorMap();
     219
     220    void setHue( int hue );
     221    void setSaturationInterval( int sat1, int sat2 );
     222    void setValueInterval( int value1, int value2 );
     223    void setAlpha( int alpha );
     224
     225    int hue() const;
     226    int saturation1() const;
     227    int saturation2() const;
     228    int value1() const;
     229    int value2() const;
     230    int alpha() const;
     231
     232    virtual QRgb rgb( const QwtInterval&,
     233        double value ) const QWT_OVERRIDE;
     234
     235  private:
     236    class PrivateData;
     237    PrivateData* m_data;
     238};
    164239
    165240/*!
    … …  
    170245
    171246   \return Color corresponding to value
    172 
    173    \warning This method is slow for Indexed color maps. If it is
    174             necessary to map many values, its better to get the
    175             color table once and find the color using colorIndex().
    176 */
    177 inline QColor QwtColorMap::color(
    178     const QwtInterval &interval, double value ) const
    179 {
    180     if ( d_format == RGB )
    181     {
    182         return QColor::fromRgba( rgb( interval, value ) );
    183     }
    184     else
    185     {
    186         const unsigned int index = colorIndex( interval, value );
    187 
    188         const QVector<QRgb> rgbTable = colorTable( interval );
    189         return rgbTable[index]; // slow
    190     }
     247 */
     248inline QColor QwtColorMap::color( const QwtInterval& interval, double value ) const
     249{
     250    return QColor::fromRgba( rgb( interval, value ) );
    191251}
    192252
    … …  
    194254   \return Intended format of the color map
    195255   \sa Format
    196 */
     256 */
    197257inline QwtColorMap::Format QwtColorMap::format() const
    198258{
    199     return d_format;
     259    return m_format;
    200260}
    201261
  • trunk/BNC/qwt/qwt_column_symbol.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_column_symbol.h"
     11#include "qwt_painter.h"
    1112#include "qwt_math.h"
    12 #include "qwt_painter.h"
     13
    1314#include <qpainter.h>
    1415#include <qpalette.h>
    1516
    16 static void qwtDrawBox( QPainter *p, const QRectF &rect,
    17     const QPalette &pal, double lw )
     17static void qwtDrawBox( QPainter* p, const QRectF& rect,
     18    const QPalette& pal, double lw )
    1819{
    1920    if ( lw > 0.0 )
    … …  
    3334        }
    3435
    35         lw = qMin( lw, rect.height() / 2.0 - 1.0 );
    36         lw = qMin( lw, rect.width() / 2.0 - 1.0 );
     36        lw = qwtMinF( lw, rect.height() / 2.0 - 1.0 );
     37        lw = qwtMinF( lw, rect.width() / 2.0 - 1.0 );
    3738
    3839        const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 );
    3940        QPolygonF polygon( outerRect );
    4041
    41         if ( outerRect.width() > 2 * lw &&
    42                 outerRect.height() > 2 * lw )
     42        if ( outerRect.width() > 2 * lw && outerRect.height() > 2 * lw )
    4343        {
    4444            const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw );
    … …  
    5757}
    5858
    59 static void qwtDrawPanel( QPainter *painter, const QRectF &rect,
    60     const QPalette &pal, double lw )
     59static void qwtDrawPanel( QPainter* painter, const QRectF& rect,
     60    const QPalette& pal, double lw )
    6161{
    6262    if ( lw > 0.0 )
    … …  
    7676        }
    7777
    78         lw = qMin( lw, rect.height() / 2.0 - 1.0 );
    79         lw = qMin( lw, rect.width() / 2.0 - 1.0 );
     78        lw = qwtMinF( lw, rect.height() / 2.0 - 1.0 );
     79        lw = qwtMinF( lw, rect.width() / 2.0 - 1.0 );
    8080
    8181        const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 );
    … …  
    111111class QwtColumnSymbol::PrivateData
    112112{
    113 public:
    114     PrivateData():
    115         style( QwtColumnSymbol::Box ),
    116         frameStyle( QwtColumnSymbol::Raised ),
    117         palette( Qt::gray ),
    118         lineWidth( 2 )
     113  public:
     114    PrivateData()
     115        : style( QwtColumnSymbol::Box )
     116        , frameStyle( QwtColumnSymbol::Raised )
     117        , palette( Qt::gray )
     118        , lineWidth( 2 )
    119119    {
    120120    }
    … …  
    128128
    129129/*!
    130   Constructor
    131 
    132   \param style Style of the symbol
    133   \sa setStyle(), style(), Style
    134 */
     130   Constructor
     131
     132   \param style Style of the symbol
     133   \sa setStyle(), style(), Style
     134 */
    135135QwtColumnSymbol::QwtColumnSymbol( Style style )
    136136{
    137     d_data = new PrivateData();
    138     d_data->style = style;
     137    m_data = new PrivateData();
     138    m_data->style = style;
    139139}
    140140
    … …  
    142142QwtColumnSymbol::~QwtColumnSymbol()
    143143{
    144     delete d_data;
    145 }
    146 
    147 /*!
    148   Specify the symbol style
    149 
    150   \param style Style
    151   \sa style(), setPalette()
    152 */
     144    delete m_data;
     145}
     146
     147/*!
     148   Specify the symbol style
     149
     150   \param style Style
     151   \sa style(), setPalette()
     152 */
    153153void QwtColumnSymbol::setStyle( Style style )
    154154{
    155     d_data->style = style;
    156 }
    157 
    158 /*!
    159   \return Current symbol style
    160   \sa setStyle()
    161 */
     155    m_data->style = style;
     156}
     157
     158/*!
     159   \return Current symbol style
     160   \sa setStyle()
     161 */
    162162QwtColumnSymbol::Style QwtColumnSymbol::style() const
    163163{
    164     return d_data->style;
    165 }
    166 
    167 /*!
    168   Assign a palette for the symbol
    169 
    170   \param palette Palette
    171   \sa palette(), setStyle()
    172 */
    173 void QwtColumnSymbol::setPalette( const QPalette &palette )
    174 {
    175     d_data->palette = palette;
    176 }
    177 
    178 /*!
    179   \return Current palette
    180   \sa setPalette()
    181 */
     164    return m_data->style;
     165}
     166
     167/*!
     168   Assign a palette for the symbol
     169
     170   \param palette Palette
     171   \sa palette(), setStyle()
     172 */
     173void QwtColumnSymbol::setPalette( const QPalette& palette )
     174{
     175    m_data->palette = palette;
     176}
     177
     178/*!
     179   \return Current palette
     180   \sa setPalette()
     181 */
    182182const QPalette& QwtColumnSymbol::palette() const
    183183{
    184     return d_data->palette;
     184    return m_data->palette;
    185185}
    186186
    … …  
    190190   \param frameStyle Frame style
    191191   \sa frameStyle(), setLineWidth(), setStyle()
    192 */
     192 */
    193193void QwtColumnSymbol::setFrameStyle( FrameStyle frameStyle )
    194194{
    195     d_data->frameStyle = frameStyle;
    196 }
    197 
    198 /*!
    199   \return Current frame style, that is used for the Box style.
    200   \sa setFrameStyle(), lineWidth(), setStyle()
    201 */
     195    m_data->frameStyle = frameStyle;
     196}
     197
     198/*!
     199   \return Current frame style, that is used for the Box style.
     200   \sa setFrameStyle(), lineWidth(), setStyle()
     201 */
    202202QwtColumnSymbol::FrameStyle QwtColumnSymbol::frameStyle() const
    203203{
    204     return d_data->frameStyle;
     204    return m_data->frameStyle;
    205205}
    206206
    … …  
    210210   \param width Width
    211211   \sa lineWidth(), setFrameStyle()
    212 */
     212 */
    213213void QwtColumnSymbol::setLineWidth( int width )
    214214{
    … …  
    216216        width = 0;
    217217
    218     d_data->lineWidth = width;
    219 }
    220 
    221 /*!
    222   \return Line width of the frame, that is used for the Box style.
    223   \sa setLineWidth(), frameStyle(), setStyle()
    224 */
     218    m_data->lineWidth = width;
     219}
     220
     221/*!
     222   \return Line width of the frame, that is used for the Box style.
     223   \sa setLineWidth(), frameStyle(), setStyle()
     224 */
    225225int QwtColumnSymbol::lineWidth() const
    226226{
    227     return d_data->lineWidth;
    228 }
    229 
    230 /*!
    231   Draw the symbol depending on its style.
    232 
    233   \param painter Painter
    234   \param rect Directed rectangle
    235 
    236   \sa drawBox()
    237 */
    238 void QwtColumnSymbol::draw( QPainter *painter,
    239     const QwtColumnRect &rect ) const
     227    return m_data->lineWidth;
     228}
     229
     230/*!
     231   Draw the symbol depending on its style.
     232
     233   \param painter Painter
     234   \param rect Directed rectangle
     235
     236   \sa drawBox()
     237 */
     238void QwtColumnSymbol::draw( QPainter* painter,
     239    const QwtColumnRect& rect ) const
    240240{
    241241    painter->save();
    242242
    243     switch ( d_data->style )
     243    switch ( m_data->style )
    244244    {
    245245        case QwtColumnSymbol::Box:
    … …  
    255255
    256256/*!
    257   Draw the symbol when it is in Box style.
    258 
    259   \param painter Painter
    260   \param rect Directed rectangle
    261 
    262   \sa draw()
    263 */
    264 void QwtColumnSymbol::drawBox( QPainter *painter,
    265     const QwtColumnRect &rect ) const
     257   Draw the symbol when it is in Box style.
     258
     259   \param painter Painter
     260   \param rect Directed rectangle
     261
     262   \sa draw()
     263 */
     264void QwtColumnSymbol::drawBox( QPainter* painter,
     265    const QwtColumnRect& rect ) const
    266266{
    267267    QRectF r = rect.toRect();
    … …  
    274274    }
    275275
    276     switch ( d_data->frameStyle )
     276    switch ( m_data->frameStyle )
    277277    {
    278278        case QwtColumnSymbol::Raised:
    279279        {
    280             qwtDrawPanel( painter, r, d_data->palette, d_data->lineWidth );
     280            qwtDrawPanel( painter, r, m_data->palette, m_data->lineWidth );
    281281            break;
    282282        }
    283283        case QwtColumnSymbol::Plain:
    284284        {
    285             qwtDrawBox( painter, r, d_data->palette, d_data->lineWidth );
     285            qwtDrawBox( painter, r, m_data->palette, m_data->lineWidth );
    286286            break;
    287287        }
    288288        default:
    289289        {
    290             painter->fillRect( r.adjusted( 0, 0, 1, 1 ), d_data->palette.window() );
    291         }
    292     }
    293 }
     290            painter->fillRect( r.adjusted( 0, 0, 1, 1 ), m_data->palette.window() );
     291        }
     292    }
     293}
     294
     295//! \return A normalized QRect built from the intervals
     296QRectF QwtColumnRect::toRect() const
     297{
     298    QRectF r( hInterval.minValue(), vInterval.minValue(),
     299        hInterval.maxValue() - hInterval.minValue(),
     300        vInterval.maxValue() - vInterval.minValue() );
     301
     302    r = r.normalized();
     303
     304    if ( hInterval.borderFlags() & QwtInterval::ExcludeMinimum )
     305        r.adjust( 1, 0, 0, 0 );
     306
     307    if ( hInterval.borderFlags() & QwtInterval::ExcludeMaximum )
     308        r.adjust( 0, 0, -1, 0 );
     309
     310    if ( vInterval.borderFlags() & QwtInterval::ExcludeMinimum )
     311        r.adjust( 0, 1, 0, 0 );
     312
     313    if ( vInterval.borderFlags() & QwtInterval::ExcludeMaximum )
     314        r.adjust( 0, 0, 0, -1 );
     315
     316    return r;
     317}
     318
  • trunk/BNC/qwt/qwt_column_symbol.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_interval.h"
    15 #include <qpen.h>
    16 #include <qsize.h>
    17 #include <qrect.h>
     15
     16#include <qnamespace.h>
    1817
    1918class QPainter;
    2019class QPalette;
    21 class QRect;
    22 class QwtText;
     20class QRectF;
    2321
    2422/*!
    2523    \brief Directed rectangle representing bounding rectangle and orientation
    2624    of a column.
    27 */
     25 */
    2826class QWT_EXPORT QwtColumnRect
    2927{
    30 public:
     28  public:
    3129    //! Direction of the column
    3230    enum Direction
    … …  
    4644
    4745    //! Build an rectangle with invalid intervals directed BottomToTop.
    48     QwtColumnRect():
    49         direction( BottomToTop )
     46    QwtColumnRect()
     47        : direction( BottomToTop )
    5048    {
    5149    }
    5250
    5351    //! \return A normalized QRect built from the intervals
    54     QRectF toRect() const
    55     {
    56         QRectF r( hInterval.minValue(), vInterval.minValue(),
    57             hInterval.maxValue() - hInterval.minValue(),
    58             vInterval.maxValue() - vInterval.minValue() );
    59         r = r.normalized();
    60 
    61         if ( hInterval.borderFlags() & QwtInterval::ExcludeMinimum )
    62             r.adjust( 1, 0, 0, 0 );
    63         if ( hInterval.borderFlags() & QwtInterval::ExcludeMaximum )
    64             r.adjust( 0, 0, -1, 0 );
    65         if ( vInterval.borderFlags() & QwtInterval::ExcludeMinimum )
    66             r.adjust( 0, 1, 0, 0 );
    67         if ( vInterval.borderFlags() & QwtInterval::ExcludeMaximum )
    68             r.adjust( 0, 0, 0, -1 );
    69 
    70         return r;
    71     }
     52    QRectF toRect() const;
    7253
    7354    //! \return Orientation
    … …  
    9374class QWT_EXPORT QwtColumnSymbol
    9475{
    95 public:
     76  public:
    9677    /*!
    97       Style
    98       \sa setStyle(), style()
    99     */
     78       Style
     79       \sa setStyle(), style()
     80     */
    10081    enum Style
    10182    {
    … …  
    10485
    10586        /*!
    106           The column is painted with a frame depending on the frameStyle()
    107           and lineWidth() using the palette().
     87           The column is painted with a frame depending on the frameStyle()
     88           and lineWidth() using the palette().
    10889         */
    10990        Box,
    11091
    11192        /*!
    112           Styles >= QwtColumnSymbol::UserStyle are reserved for derived
    113           classes of QwtColumnSymbol that overload draw() with
    114           additional application specific symbol types.
     93           Styles >= QwtColumnSymbol::UserStyle are reserved for derived
     94           classes of QwtColumnSymbol that overload draw() with
     95           additional application specific symbol types.
    11596         */
    11697        UserStyle = 1000
    … …  
    11899
    119100    /*!
    120       Frame Style used in Box style().
    121       \sa Style, setFrameStyle(), frameStyle(), setStyle(), setPalette()
     101       Frame Style used in Box style().
     102       \sa Style, setFrameStyle(), frameStyle(), setStyle(), setPalette()
    122103     */
    123104    enum FrameStyle
    … …  
    133114    };
    134115
    135 public:
    136     QwtColumnSymbol( Style = NoStyle );
     116  public:
     117    explicit QwtColumnSymbol( Style = NoStyle );
    137118    virtual ~QwtColumnSymbol();
    138119
    … …  
    143124    int lineWidth() const;
    144125
    145     void setPalette( const QPalette & );
    146     const QPalette &palette() const;
     126    void setPalette( const QPalette& );
     127    const QPalette& palette() const;
    147128
    148129    void setStyle( Style );
    149130    Style style() const;
    150131
    151     virtual void draw( QPainter *, const QwtColumnRect & ) const;
     132    virtual void draw( QPainter*, const QwtColumnRect& ) const;
    152133
    153 protected:
    154     void drawBox( QPainter *, const QwtColumnRect & ) const;
     134  protected:
     135    void drawBox( QPainter*, const QwtColumnRect& ) const;
    155136
    156 private:
     137  private:
     138    Q_DISABLE_COPY(QwtColumnSymbol)
     139
    157140    class PrivateData;
    158     PrivateData* d_data;
     141    PrivateData* m_data;
    159142};
    160143
  • trunk/BNC/qwt/qwt_compass.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_compass.h"
    1111#include "qwt_compass_rose.h"
    12 #include "qwt_math.h"
    13 #include "qwt_scale_draw.h"
    14 #include "qwt_painter.h"
    15 #include "qwt_dial_needle.h"
    16 #include <qpainter.h>
    17 #include <qpixmap.h>
     12#include "qwt_text.h"
     13
    1814#include <qevent.h>
    19 
    20 /*!
    21   \brief Constructor
    22 
    23   Initializes a label map for multiples of 45 degrees
     15#include <qmap.h>
     16
     17class QwtCompassScaleDraw::PrivateData
     18{
     19  public:
     20    QMap< double, QString > labelMap;
     21};
     22
     23/*!
     24   \brief Constructor
     25
     26   Initializes a label map for multiples of 45 degrees
    2427 */
    2528QwtCompassScaleDraw::QwtCompassScaleDraw()
    2629{
     30    m_data = new PrivateData;
     31
    2732    enableComponent( QwtAbstractScaleDraw::Backbone, false );
    2833    enableComponent( QwtAbstractScaleDraw::Ticks, false );
    2934
    30     d_labelMap.insert( 0.0, QString::fromLatin1( "N" ) );
    31     d_labelMap.insert( 45.0, QString::fromLatin1( "NE" ) );
    32     d_labelMap.insert( 90.0, QString::fromLatin1( "E" ) );
    33     d_labelMap.insert( 135.0, QString::fromLatin1( "SE" ) );
    34     d_labelMap.insert( 180.0, QString::fromLatin1( "S" ) );
    35     d_labelMap.insert( 225.0, QString::fromLatin1( "SW" ) );
    36     d_labelMap.insert( 270.0, QString::fromLatin1( "W" ) );
    37     d_labelMap.insert( 315.0, QString::fromLatin1( "NW" ) );
     35    QMap< double, QString >& map = m_data->labelMap;
     36
     37    map.insert( 0.0, QString::fromLatin1( "N" ) );
     38    map.insert( 45.0, QString::fromLatin1( "NE" ) );
     39    map.insert( 90.0, QString::fromLatin1( "E" ) );
     40    map.insert( 135.0, QString::fromLatin1( "SE" ) );
     41    map.insert( 180.0, QString::fromLatin1( "S" ) );
     42    map.insert( 225.0, QString::fromLatin1( "SW" ) );
     43    map.insert( 270.0, QString::fromLatin1( "W" ) );
     44    map.insert( 315.0, QString::fromLatin1( "NW" ) );
    3845
    3946#if 0
    40     d_labelMap.insert( 22.5, QString::fromLatin1( "NNE" ) );
    41     d_labelMap.insert( 67.5, QString::fromLatin1( "NEE" ) );
    42     d_labelMap.insert( 112.5, QString::fromLatin1( "SEE" ) );
    43     d_labelMap.insert( 157.5, QString::fromLatin1( "SSE" ) );
    44     d_labelMap.insert( 202.5, QString::fromLatin1( "SSW" ) );
    45     d_labelMap.insert( 247.5, QString::fromLatin1( "SWW" ) );
    46     d_labelMap.insert( 292.5, QString::fromLatin1( "NWW" ) );
    47     d_labelMap.insert( 337.5, QString::fromLatin1( "NNW" ) );
     47    map.insert( 22.5, QString::fromLatin1( "NNE" ) );
     48    map.insert( 67.5, QString::fromLatin1( "NEE" ) );
     49    map.insert( 112.5, QString::fromLatin1( "SEE" ) );
     50    map.insert( 157.5, QString::fromLatin1( "SSE" ) );
     51    map.insert( 202.5, QString::fromLatin1( "SSW" ) );
     52    map.insert( 247.5, QString::fromLatin1( "SWW" ) );
     53    map.insert( 292.5, QString::fromLatin1( "NWW" ) );
     54    map.insert( 337.5, QString::fromLatin1( "NNW" ) );
    4855#endif
    4956}
    5057
    5158/*!
    52   \brief Constructor
    53 
    54   \param map Value to label map
    55  */
    56 QwtCompassScaleDraw::QwtCompassScaleDraw( const QMap<double, QString> &map ):
    57     d_labelMap( map )
    58 {
     59   \brief Constructor
     60
     61   \param map Value to label map
     62 */
     63QwtCompassScaleDraw::QwtCompassScaleDraw( const QMap< double, QString >& map )
     64{
     65    m_data = new PrivateData;
     66    m_data->labelMap = map;
     67
    5968    enableComponent( QwtAbstractScaleDraw::Backbone, false );
    6069    enableComponent( QwtAbstractScaleDraw::Ticks, false );
    6170}
    6271
    63 /*!
    64   \brief Set a map, mapping values to labels
    65   \param map Value to label map
    66 
    67   The values of the major ticks are found by looking into this
    68   map. The default map consists of the labels N, NE, E, SE, S, SW, W, NW.
    69 
    70   \warning The map will have no effect for values that are no major
     72//!  Destructor
     73QwtCompassScaleDraw::~QwtCompassScaleDraw()
     74{
     75    delete m_data;
     76}
     77
     78/*!
     79   \brief Set a map, mapping values to labels
     80   \param map Value to label map
     81
     82   The values of the major ticks are found by looking into this
     83   map. The default map consists of the labels N, NE, E, SE, S, SW, W, NW.
     84
     85   \warning The map will have no effect for values that are no major
    7186           tick values. Major ticks can be changed by QwtScaleDraw::setScale
    7287
    73   \sa labelMap(), scaleDraw(), setScale()
    74 */
    75 void QwtCompassScaleDraw::setLabelMap( const QMap<double, QString> &map )
    76 {
    77     d_labelMap = map;
    78 }
    79 
    80 
    81 /*!
    82   \return map, mapping values to labels
    83   \sa setLabelMap()
    84 */
    85 QMap<double, QString> QwtCompassScaleDraw::labelMap() const
    86 {
    87     return d_labelMap;
    88 }
    89 
    90 /*!
    91   Map a value to a corresponding label
    92 
    93   \param value Value that will be mapped
    94 
    95   label() looks in the labelMap() for a corresponding label for value
    96   or returns an null text.
    97 
    98   \return Label
    99   \sa labelMap(), setLabelMap()
    100 */
     88   \sa labelMap(), scaleDraw(), setScale()
     89 */
     90void QwtCompassScaleDraw::setLabelMap( const QMap< double, QString >& map )
     91{
     92    m_data->labelMap = map;
     93}
     94
     95/*!
     96   \return map, mapping values to labels
     97   \sa setLabelMap()
     98 */
     99QMap< double, QString > QwtCompassScaleDraw::labelMap() const
     100{
     101    return m_data->labelMap;
     102}
     103
     104/*!
     105   Map a value to a corresponding label
     106
     107   \param value Value that will be mapped
     108
     109   label() looks in the labelMap() for a corresponding label for value
     110   or returns an null text.
     111
     112   \return Label
     113   \sa labelMap(), setLabelMap()
     114 */
    101115
    102116QwtText QwtCompassScaleDraw::label( double value ) const
    … …  
    108122        value += 360.0;
    109123
    110     if ( d_labelMap.contains( value ) )
    111         return d_labelMap[value];
     124    QMap< double, QString >::const_iterator it =
     125        m_data->labelMap.constFind( value );
     126
     127    if ( it != m_data->labelMap.constEnd() )
     128        return *it;
    112129
    113130    return QwtText();
    … …  
    116133class QwtCompass::PrivateData
    117134{
    118 public:
     135  public:
    119136    PrivateData():
    120137        rose( NULL )
    … …  
    127144    }
    128145
    129     QwtCompassRose *rose;
     146    QwtCompassRose* rose;
    130147};
    131148
    132149/*!
    133   \brief Constructor
    134   \param parent Parent widget
    135 
    136   Create a compass widget with a scale, no needle and no rose.
    137   The default origin is 270.0 with no valid value. It accepts
    138   mouse and keyboard inputs and has no step size. The default mode
    139   is QwtDial::RotateNeedle.
    140 */
    141 QwtCompass::QwtCompass( QWidget* parent ):
    142     QwtDial( parent )
    143 {
    144     d_data = new PrivateData;
     150   \brief Constructor
     151   \param parent Parent widget
     152
     153   Create a compass widget with a scale, no needle and no rose.
     154   The default origin is 270.0 with no valid value. It accepts
     155   mouse and keyboard inputs and has no step size. The default mode
     156   is QwtDial::RotateNeedle.
     157 */
     158QwtCompass::QwtCompass( QWidget* parent )
     159    : QwtDial( parent )
     160{
     161    m_data = new PrivateData;
    145162
    146163    setScaleDraw( new QwtCompassScaleDraw() );
    … …  
    159176QwtCompass::~QwtCompass()
    160177{
    161     delete d_data;
     178    delete m_data;
    162179}
    163180
    … …  
    169186   \param center Center of the content circle
    170187   \param radius Radius of the content circle
    171 */
    172 void QwtCompass::drawScaleContents( QPainter *painter,
    173     const QPointF &center, double radius ) const
     188 */
     189void QwtCompass::drawScaleContents( QPainter* painter,
     190    const QPointF& center, double radius ) const
    174191{
    175192    QPalette::ColorGroup cg;
    … …  
    191208
    192209/*!
    193   Draw the compass rose
    194 
    195   \param painter Painter
    196   \param center Center of the compass
    197   \param radius of the circle, where to paint the rose
    198   \param north Direction pointing north, in degrees counter clockwise
    199   \param cg Color group
    200 */
    201 void QwtCompass::drawRose( QPainter *painter, const QPointF &center,
     210   Draw the compass rose
     211
     212   \param painter Painter
     213   \param center Center of the compass
     214   \param radius of the circle, where to paint the rose
     215   \param north Direction pointing north, in degrees counter clockwise
     216   \param cg Color group
     217 */
     218void QwtCompass::drawRose( QPainter* painter, const QPointF& center,
    202219    double radius, double north, QPalette::ColorGroup cg ) const
    203220{
    204     if ( d_data->rose )
    205         d_data->rose->draw( painter, center, radius, north,  cg );
    206 }
    207 
    208 /*!
    209   Set a rose for the compass
    210   \param rose Compass rose
    211   \warning The rose will be deleted, when a different rose is
     221    if ( m_data->rose )
     222        m_data->rose->draw( painter, center, radius, north,  cg );
     223}
     224
     225/*!
     226   Set a rose for the compass
     227   \param rose Compass rose
     228   \warning The rose will be deleted, when a different rose is
    212229    set or in ~QwtCompass
    213   \sa rose()
    214 */
    215 void QwtCompass::setRose( QwtCompassRose *rose )
    216 {
    217     if ( rose != d_data->rose )
    218     {
    219         if ( d_data->rose )
    220             delete d_data->rose;
    221 
    222         d_data->rose = rose;
     230   \sa rose()
     231 */
     232void QwtCompass::setRose( QwtCompassRose* rose )
     233{
     234    if ( rose != m_data->rose )
     235    {
     236        if ( m_data->rose )
     237            delete m_data->rose;
     238
     239        m_data->rose = rose;
    223240        update();
    224241    }
    … …  
    226243
    227244/*!
    228   \return rose
    229   \sa setRose()
    230 */
    231 const QwtCompassRose *QwtCompass::rose() const
    232 {
    233     return d_data->rose;
    234 }
    235 
    236 /*!
    237   \return rose
    238   \sa setRose()
    239 */
    240 QwtCompassRose *QwtCompass::rose()
    241 {
    242     return d_data->rose;
    243 }
    244 
    245 /*!
    246   Handles key events
    247 
    248   Beside the keys described in QwtDial::keyPressEvent numbers
    249   from 1-9 (without 5) set the direction according to their
    250   position on the num pad.
    251 
    252   \sa isReadOnly()
    253 */
    254 void QwtCompass::keyPressEvent( QKeyEvent *kev )
     245   \return rose
     246   \sa setRose()
     247 */
     248const QwtCompassRose* QwtCompass::rose() const
     249{
     250    return m_data->rose;
     251}
     252
     253/*!
     254   \return rose
     255   \sa setRose()
     256 */
     257QwtCompassRose* QwtCompass::rose()
     258{
     259    return m_data->rose;
     260}
     261
     262/*!
     263   Handles key events
     264
     265   Beside the keys described in QwtDial::keyPressEvent numbers
     266   from 1-9 (without 5) set the direction according to their
     267   position on the num pad.
     268
     269   \sa isReadOnly()
     270 */
     271void QwtCompass::keyPressEvent( QKeyEvent* kev )
    255272{
    256273    if ( isReadOnly() )
    … …  
    307324    }
    308325}
     326
     327#include "moc_qwt_compass.cpp"
  • trunk/BNC/qwt/qwt_compass.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_COMPASS_H
    11 #define QWT_COMPASS_H 1
     11#define QWT_COMPASS_H
    1212
    1313#include "qwt_global.h"
    1414#include "qwt_dial.h"
    1515#include "qwt_round_scale_draw.h"
    16 #include <qstring.h>
    17 #include <qmap.h>
    1816
    1917class QwtCompassRose;
     18class QString;
     19template< class Key, class T > class QMap;
     20
    2021
    2122/*!
    22   \brief A special scale draw made for QwtCompass
     23   \brief A special scale draw made for QwtCompass
    2324
    24   QwtCompassScaleDraw maps values to strings using
    25   a special map, that can be modified by the application
     25   QwtCompassScaleDraw maps values to strings using
     26   a special map, that can be modified by the application
    2627
    27   The default map consists of the labels N, NE, E, SE, S, SW, W, NW.
     28   The default map consists of the labels N, NE, E, SE, S, SW, W, NW.
    2829
    29   \sa QwtCompass
    30 */
    31 class QWT_EXPORT QwtCompassScaleDraw: public QwtRoundScaleDraw
     30   \sa QwtCompass
     31 */
     32class QWT_EXPORT QwtCompassScaleDraw : public QwtRoundScaleDraw
    3233{
    33 public:
     34  public:
    3435    explicit QwtCompassScaleDraw();
    35     explicit QwtCompassScaleDraw( const QMap<double, QString> &map );
     36    explicit QwtCompassScaleDraw( const QMap< double, QString >& map );
    3637
    37     void setLabelMap( const QMap<double, QString> &map );
    38     QMap<double, QString> labelMap() const;
     38    virtual ~QwtCompassScaleDraw();
    3939
    40     virtual QwtText label( double value ) const;
     40    void setLabelMap( const QMap< double, QString >& map );
     41    QMap< double, QString > labelMap() const;
    4142
    42 private:
    43     QMap<double, QString> d_labelMap;
     43    virtual QwtText label( double value ) const QWT_OVERRIDE;
     44
     45  private:
     46    class PrivateData;
     47    PrivateData* m_data;
    4448};
    4549
    4650/*!
    47   \brief A Compass Widget
     51   \brief A Compass Widget
    4852
    49   QwtCompass is a widget to display and enter directions. It consists
    50   of a scale, an optional needle and rose.
     53   QwtCompass is a widget to display and enter directions. It consists
     54   of a scale, an optional needle and rose.
    5155
    52   \image html dials1.png
     56   \image html dials1.png
    5357
    54   \note The examples/dials example shows how to use QwtCompass.
    55 */
     58   \note The examples/dials example shows how to use QwtCompass.
     59 */
    5660
    57 class QWT_EXPORT QwtCompass: public QwtDial
     61class QWT_EXPORT QwtCompass : public QwtDial
    5862{
    5963    Q_OBJECT
    6064
    61 public:
     65  public:
    6266    explicit QwtCompass( QWidget* parent = NULL );
    6367    virtual ~QwtCompass();
    6468
    65     void setRose( QwtCompassRose *rose );
    66     const QwtCompassRose *rose() const;
    67     QwtCompassRose *rose();
     69    void setRose( QwtCompassRose* rose );
     70    const QwtCompassRose* rose() const;
     71    QwtCompassRose* rose();
    6872
    69 protected:
    70     virtual void drawRose( QPainter *, const QPointF &center,
     73  protected:
     74    virtual void drawRose( QPainter*, const QPointF& center,
    7175        double radius, double north, QPalette::ColorGroup ) const;
    7276
    73     virtual void drawScaleContents( QPainter *,
    74         const QPointF &center, double radius ) const;
     77    virtual void drawScaleContents( QPainter*,
     78        const QPointF& center, double radius ) const QWT_OVERRIDE;
    7579
    76     virtual void keyPressEvent( QKeyEvent * );
     80    virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE;
    7781
    78 private:
     82  private:
    7983    class PrivateData;
    80     PrivateData *d_data;
     84    PrivateData* m_data;
    8185};
    8286
  • trunk/BNC/qwt/qwt_compass_rose.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_compass_rose.h"
    1111#include "qwt_point_polar.h"
    12 #include "qwt_painter.h"
     12
    1313#include <qpainter.h>
    1414#include <qpainterpath.h>
    … …  
    2121
    2222    QPointF pos;
     23#if QT_VERSION >= 0x050e00
     24    if ( line1.intersects( line2, &pos ) == QLineF::NoIntersection )
     25#else
    2326    if ( line1.intersect( line2, &pos ) == QLineF::NoIntersection )
     27#endif
    2428        return QPointF();
    2529
    … …  
    2731}
    2832
     33//! Constructor
     34QwtCompassRose::QwtCompassRose()
     35{
     36}
     37
     38//! Destructor
     39QwtCompassRose::~QwtCompassRose()
     40{
     41}
     42
     43//! Assign a palette
     44void QwtCompassRose::setPalette( const QPalette& p )
     45{
     46    m_palette = p;
     47}
     48
     49//! \return Current palette
     50const QPalette& QwtCompassRose::palette() const
     51{
     52    return m_palette;
     53}
     54
    2955class QwtSimpleCompassRose::PrivateData
    3056{
    31 public:
    32     PrivateData():
    33         width( 0.2 ),
    34         numThorns( 8 ),
    35         numThornLevels( -1 ),
    36         shrinkFactor( 0.9 )
     57  public:
     58    PrivateData()
     59        : width( 0.2 )
     60        , numThorns( 8 )
     61        , numThornLevels( -1 )
     62        , shrinkFactor( 0.9 )
    3763    {
    3864    }
    … …  
    4975   \param numThorns Number of thorns
    5076   \param numThornLevels Number of thorn levels
    51 */
     77 */
    5278QwtSimpleCompassRose::QwtSimpleCompassRose(
    5379    int numThorns, int numThornLevels )
    5480{
    55     d_data = new PrivateData();
    56     d_data->numThorns = numThorns;
    57     d_data->numThornLevels = numThornLevels;
     81    m_data = new PrivateData();
     82    m_data->numThorns = numThorns;
     83    m_data->numThornLevels = numThornLevels;
    5884
    5985    const QColor dark( 128, 128, 255 );
    … …  
    7096QwtSimpleCompassRose::~QwtSimpleCompassRose()
    7197{
    72     delete d_data;
    73 }
    74 
    75 /*!
    76   Set the Factor how to shrink the thorns with each level
    77   The default value is 0.9.
    78 
    79   \param factor Shrink factor
    80   \sa shrinkFactor()
    81 */
     98    delete m_data;
     99}
     100
     101/*!
     102   Set the Factor how to shrink the thorns with each level
     103   The default value is 0.9.
     104
     105   \param factor Shrink factor
     106   \sa shrinkFactor()
     107 */
    82108void QwtSimpleCompassRose::setShrinkFactor( double factor )
    83109{
    84     d_data->shrinkFactor = factor;
    85 }
    86 
    87 /*!
    88   \return Factor how to shrink the thorns with each level
    89   \sa setShrinkFactor()
    90 */
     110    m_data->shrinkFactor = factor;
     111}
     112
     113/*!
     114   \return Factor how to shrink the thorns with each level
     115   \sa setShrinkFactor()
     116 */
    91117double QwtSimpleCompassRose::shrinkFactor() const
    92118{
    93     return d_data->shrinkFactor;
     119    return m_data->shrinkFactor;
    94120}
    95121
    … …  
    102128   \param north Position
    103129   \param cg Color group
    104 */
    105 void QwtSimpleCompassRose::draw( QPainter *painter, const QPointF &center,
     130 */
     131void QwtSimpleCompassRose::draw( QPainter* painter, const QPointF& center,
    106132    double radius, double north, QPalette::ColorGroup cg ) const
    107133{
    … …  
    109135    pal.setCurrentColorGroup( cg );
    110136
    111     drawRose( painter, pal, center, radius, north, d_data->width,
    112         d_data->numThorns, d_data->numThornLevels, d_data->shrinkFactor );
     137    drawRose( painter, pal, center, radius, north, m_data->width,
     138        m_data->numThorns, m_data->numThornLevels, m_data->shrinkFactor );
    113139}
    114140
    … …  
    125151   \param numThornLevels Number of thorn levels
    126152   \param shrinkFactor Factor to shrink the thorns with each level
    127 */
     153 */
    128154void QwtSimpleCompassRose::drawRose(
    129     QPainter *painter,
    130     const QPalette &palette,
    131     const QPointF &center, double radius, double north, double width,
     155    QPainter* painter,
     156    const QPalette& palette,
     157    const QPointF& center, double radius, double north, double width,
    132158    int numThorns, int numThornLevels, double shrinkFactor )
    133159{
    … …  
    153179    for ( int j = 1; j <= numThornLevels; j++ )
    154180    {
    155         double step =  qPow( 2.0, j ) * M_PI / numThorns;
     181        double step = std::pow( 2.0, j ) * M_PI / numThorns;
    156182        if ( step > M_PI_2 )
    157183            break;
    … …  
    203229
    204230   \param width Width
    205 */
     231 */
    206232void QwtSimpleCompassRose::setWidth( double width )
    207233{
    208     d_data->width = width;
    209     if ( d_data->width < 0.03 )
    210         d_data->width = 0.03;
    211 
    212     if ( d_data->width > 0.4 )
    213         d_data->width = 0.4;
    214 }
    215 
    216 /*!
    217   \return Width of the rose
    218   \sa setWidth()
     234    m_data->width = width;
     235    if ( m_data->width < 0.03 )
     236        m_data->width = 0.03;
     237
     238    if ( m_data->width > 0.4 )
     239        m_data->width = 0.4;
     240}
     241
     242/*!
     243   \return Width of the rose
     244   \sa setWidth()
    219245 */
    220246double QwtSimpleCompassRose::width() const
    221247{
    222     return d_data->width;
    223 }
    224 
    225 /*!
    226   Set the number of thorns on one level
    227   The number is aligned to a multiple of 4, with a minimum of 4
    228 
    229   \param numThorns Number of thorns
    230   \sa numThorns(), setNumThornLevels()
    231 */
     248    return m_data->width;
     249}
     250
     251/*!
     252   Set the number of thorns on one level
     253   The number is aligned to a multiple of 4, with a minimum of 4
     254
     255   \param numThorns Number of thorns
     256   \sa numThorns(), setNumThornLevels()
     257 */
    232258void QwtSimpleCompassRose::setNumThorns( int numThorns )
    233259{
    … …  
    238264        numThorns += 4 - numThorns % 4;
    239265
    240     d_data->numThorns = numThorns;
     266    m_data->numThorns = numThorns;
    241267}
    242268
    … …  
    244270   \return Number of thorns
    245271   \sa setNumThorns(), setNumThornLevels()
    246 */
     272 */
    247273int QwtSimpleCompassRose::numThorns() const
    248274{
    249     return d_data->numThorns;
    250 }
    251 
    252 /*!
    253   Set the of thorns levels
    254 
    255   \param numThornLevels Number of thorns levels
    256   \sa setNumThorns(), numThornLevels()
    257 */
     275    return m_data->numThorns;
     276}
     277
     278/*!
     279   Set the of thorns levels
     280
     281   \param numThornLevels Number of thorns levels
     282   \sa setNumThorns(), numThornLevels()
     283 */
    258284void QwtSimpleCompassRose::setNumThornLevels( int numThornLevels )
    259285{
    260     d_data->numThornLevels = numThornLevels;
     286    m_data->numThornLevels = numThornLevels;
    261287}
    262288
    … …  
    264290   \return Number of thorn levels
    265291   \sa setNumThorns(), setNumThornLevels()
    266 */
     292 */
    267293int QwtSimpleCompassRose::numThornLevels() const
    268294{
    269     return d_data->numThornLevels;
    270 }
     295    return m_data->numThornLevels;
     296}
  • trunk/BNC/qwt/qwt_compass_rose.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_COMPASS_ROSE_H
    11 #define QWT_COMPASS_ROSE_H 1
     11#define QWT_COMPASS_ROSE_H
    1212
    1313#include "qwt_global.h"
    … …  
    1717
    1818/*!
    19   \brief Abstract base class for a compass rose
    20 */
     19   \brief Abstract base class for a compass rose
     20 */
    2121class QWT_EXPORT QwtCompassRose
    2222{
    23 public:
    24     //! Destructor
    25     virtual ~QwtCompassRose() {};
     23  public:
     24    QwtCompassRose();
     25    virtual ~QwtCompassRose();
    2626
    27     //! Assign a palette
    28     virtual void setPalette( const QPalette &p )
    29     {
    30         d_palette = p;
    31     }
    32 
    33     //! \return Current palette
    34     const QPalette &palette() const
    35     {
    36         return d_palette;
    37     }
     27    virtual void setPalette( const QPalette& );
     28    const QPalette& palette() const;
    3829
    3930    /*!
    … …  
    4637        \param colorGroup Color group
    4738     */
    48     virtual void draw( QPainter *painter,
    49         const QPointF &center, double radius, double north,
     39    virtual void draw( QPainter* painter,
     40        const QPointF& center, double radius, double north,
    5041        QPalette::ColorGroup colorGroup = QPalette::Active ) const = 0;
    5142
    52 private:
    53     QPalette d_palette;
     43  private:
     44    Q_DISABLE_COPY(QwtCompassRose)
     45
     46    QPalette m_palette;
    5447};
    5548
    5649/*!
    57   \brief A simple rose for QwtCompass
    58 */
    59 class QWT_EXPORT QwtSimpleCompassRose: public QwtCompassRose
     50   \brief A simple rose for QwtCompass
     51 */
     52class QWT_EXPORT QwtSimpleCompassRose : public QwtCompassRose
    6053{
    61 public:
     54  public:
    6255    QwtSimpleCompassRose( int numThorns = 8, int numThornLevels = -1 );
    6356    virtual ~QwtSimpleCompassRose();
    … …  
    7568    double shrinkFactor() const;
    7669
    77     virtual void draw( QPainter *, const QPointF &center, double radius,
    78         double north, QPalette::ColorGroup = QPalette::Active ) const;
     70    virtual void draw( QPainter*,
     71        const QPointF& center, double radius, double north,
     72        QPalette::ColorGroup = QPalette::Active ) const QWT_OVERRIDE;
    7973
    80     static void drawRose( QPainter *, const QPalette &,
    81         const QPointF &center, double radius, double north, double width,
     74    static void drawRose( QPainter*, const QPalette&,
     75        const QPointF& center, double radius, double north, double width,
    8276        int numThorns, int numThornLevels, double shrinkFactor );
    8377
    84 private:
     78  private:
    8579    class PrivateData;
    86     PrivateData *d_data;
     80    PrivateData* m_data;
    8781};
    8882
  • trunk/BNC/qwt/qwt_counter.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_arrow_button.h"
     11#include "qwt_counter.h"
     12#include "qwt_painter.h"
    1113#include "qwt_math.h"
    12 #include "qwt_counter.h"
     14
    1315#include <qlayout.h>
    1416#include <qlineedit.h>
    … …  
    1921class QwtCounter::PrivateData
    2022{
    21 public:
    22     PrivateData():
    23         minimum( 0.0 ),
    24         maximum( 0.0 ),
    25         singleStep( 1.0 ),
    26         isValid( false ),
    27         value( 0.0 ),
    28         wrapping( false )
     23  public:
     24    PrivateData()
     25        : minimum( 0.0 )
     26        , maximum( 0.0 )
     27        , singleStep( 1.0 )
     28        , isValid( false )
     29        , value( 0.0 )
     30        , wrapping( false )
    2931    {
    3032        increment[Button1] = 1;
    … …  
    3335    }
    3436
    35     QwtArrowButton *buttonDown[ButtonCnt];
    36     QwtArrowButton *buttonUp[ButtonCnt];
    37     QLineEdit *valueEdit;
     37    QwtArrowButton* buttonDown[ButtonCnt];
     38    QwtArrowButton* buttonUp[ButtonCnt];
     39    QLineEdit* valueEdit;
    3840
    3941    int increment[ButtonCnt];
    … …  
    5153
    5254/*!
    53   The counter is initialized with a range is set to [0.0, 1.0] with
    54   0.01 as single step size. The value is invalid.
    55 
    56   The default number of buttons is set to 2. The default increments are:
    57   \li Button 1: 1 step
    58   \li Button 2: 10 steps
    59   \li Button 3: 100 steps
    60 
    61   \param parent
    62  */
    63 QwtCounter::QwtCounter( QWidget *parent ):
    64     QWidget( parent )
     55   The counter is initialized with a range is set to [0.0, 1.0] with
     56   0.01 as single step size. The value is invalid.
     57
     58   The default number of buttons is set to 2. The default increments are:
     59   \li Button 1: 1 step
     60   \li Button 2: 10 steps
     61   \li Button 3: 100 steps
     62
     63   \param parent
     64 */
     65QwtCounter::QwtCounter( QWidget* parent )
     66    : QWidget( parent )
    6567{
    6668    initCounter();
    … …  
    6971void QwtCounter::initCounter()
    7072{
    71     d_data = new PrivateData;
    72 
    73     QHBoxLayout *layout = new QHBoxLayout( this );
     73    m_data = new PrivateData;
     74
     75    QHBoxLayout* layout = new QHBoxLayout( this );
    7476    layout->setSpacing( 0 );
    75     layout->setMargin( 0 );
     77    layout->setContentsMargins( QMargins() );
    7678
    7779    for ( int i = ButtonCnt - 1; i >= 0; i-- )
    7880    {
    79         QwtArrowButton *btn =
     81        QwtArrowButton* btn =
    8082            new QwtArrowButton( i + 1, Qt::DownArrow, this );
    8183        btn->setFocusPolicy( Qt::NoFocus );
    82         btn->installEventFilter( this );
    8384        layout->addWidget( btn );
    8485
    … …  
    8687        connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) );
    8788
    88         d_data->buttonDown[i] = btn;
    89     }
    90 
    91     d_data->valueEdit = new QLineEdit( this );
    92     d_data->valueEdit->setReadOnly( false );
    93     d_data->valueEdit->setValidator( new QDoubleValidator( d_data->valueEdit ) );
    94     layout->addWidget( d_data->valueEdit );
    95 
    96     connect( d_data->valueEdit, SIGNAL(editingFinished()), SLOT(textChanged()) );
    97 
    98     layout->setStretchFactor( d_data->valueEdit, 10 );
     89        m_data->buttonDown[i] = btn;
     90    }
     91
     92    m_data->valueEdit = new QLineEdit( this );
     93    m_data->valueEdit->setReadOnly( false );
     94    m_data->valueEdit->setValidator( new QDoubleValidator( m_data->valueEdit ) );
     95    layout->addWidget( m_data->valueEdit );
     96
     97    connect( m_data->valueEdit, SIGNAL(editingFinished()), SLOT(textChanged()) );
     98
     99    layout->setStretchFactor( m_data->valueEdit, 10 );
    99100
    100101    for ( int i = 0; i < ButtonCnt; i++ )
    101102    {
    102         QwtArrowButton *btn =
     103        QwtArrowButton* btn =
    103104            new QwtArrowButton( i + 1, Qt::UpArrow, this );
    104105        btn->setFocusPolicy( Qt::NoFocus );
    105         btn->installEventFilter( this );
    106106        layout->addWidget( btn );
    107107
    … …  
    109109        connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) );
    110110
    111         d_data->buttonUp[i] = btn;
     111        m_data->buttonUp[i] = btn;
    112112    }
    113113
    … …  
    120120        QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) );
    121121
    122     setFocusProxy( d_data->valueEdit );
     122    setFocusProxy( m_data->valueEdit );
    123123    setFocusPolicy( Qt::StrongFocus );
    124124}
    … …  
    127127QwtCounter::~QwtCounter()
    128128{
    129     delete d_data;
    130 }
    131 
    132 /*!
    133   Set the counter to be in valid/invalid state
    134 
    135   When the counter is set to invalid, no numbers are displayed and
    136   the buttons are disabled.
    137 
    138   \param on If true the counter will be set as valid
    139 
    140   \sa setValue(), isValid()
    141 */
     129    delete m_data;
     130}
     131
     132/*!
     133   Set the counter to be in valid/invalid state
     134
     135   When the counter is set to invalid, no numbers are displayed and
     136   the buttons are disabled.
     137
     138   \param on If true the counter will be set as valid
     139
     140   \sa setValue(), isValid()
     141 */
    142142void QwtCounter::setValid( bool on )
    143143{
    144     if ( on != d_data->isValid )
    145     {
    146         d_data->isValid = on;
     144    if ( on != m_data->isValid )
     145    {
     146        m_data->isValid = on;
    147147
    148148        updateButtons();
    149149
    150         if ( d_data->isValid )
     150        if ( m_data->isValid )
    151151        {
    152152            showNumber( value() );
    … …  
    155155        else
    156156        {
    157             d_data->valueEdit->setText( QString() );
    158         }
    159     }
    160 }
    161 
    162 /*!
    163   \return True, if the value is valid
    164   \sa setValid(), setValue()
     157            m_data->valueEdit->setText( QString() );
     158        }
     159    }
     160}
     161
     162/*!
     163   \return True, if the value is valid
     164   \sa setValid(), setValue()
    165165 */
    166166bool QwtCounter::isValid() const
    167167{
    168     return d_data->isValid;
    169 }
    170 
    171 /*!
    172   \brief Allow/disallow the user to manually edit the value
    173 
    174   \param on True disable editing
    175   \sa isReadOnly()
    176 */
     168    return m_data->isValid;
     169}
     170
     171/*!
     172   \brief Allow/disallow the user to manually edit the value
     173
     174   \param on True disable editing
     175   \sa isReadOnly()
     176 */
    177177void QwtCounter::setReadOnly( bool on )
    178178{
    179     d_data->valueEdit->setReadOnly( on );
     179    m_data->valueEdit->setReadOnly( on );
    180180}
    181181
    182182/*!
    183183   \return True, when the line line edit is read only. (default is no)
    184   \sa setReadOnly()
     184   \sa setReadOnly()
    185185 */
    186186bool QwtCounter::isReadOnly() const
    187187{
    188     return d_data->valueEdit->isReadOnly();
    189 }
    190 
    191 /*!
    192   \brief Set a new value without adjusting to the step raster
    193 
    194   The state of the counter is set to be valid.
    195 
    196   \param value New value
    197 
    198   \sa isValid(), value(), valueChanged()
    199   \warning The value is clipped when it lies outside the range.
    200 */
     188    return m_data->valueEdit->isReadOnly();
     189}
     190
     191/*!
     192   \brief Set a new value without adjusting to the step raster
     193
     194   The state of the counter is set to be valid.
     195
     196   \param value New value
     197
     198   \sa isValid(), value(), valueChanged()
     199   \warning The value is clipped when it lies outside the range.
     200 */
    201201
    202202void QwtCounter::setValue( double value )
    203203{
    204     const double vmin = qMin( d_data->minimum, d_data->maximum );
    205     const double vmax = qMax( d_data->minimum, d_data->maximum );
     204    const double vmin = qwtMinF( m_data->minimum, m_data->maximum );
     205    const double vmax = qwtMaxF( m_data->minimum, m_data->maximum );
    206206
    207207    value = qBound( vmin, value, vmax );
    208208
    209     if ( !d_data->isValid || value != d_data->value )
    210     {
    211         d_data->isValid = true;
    212         d_data->value = value;
     209    if ( !m_data->isValid || value != m_data->value )
     210    {
     211        m_data->isValid = true;
     212        m_data->value = value;
    213213
    214214        showNumber( value );
    … …  
    220220
    221221/*!
    222   \return Current value of the counter
    223   \sa setValue(), valueChanged()
     222   \return Current value of the counter
     223   \sa setValue(), valueChanged()
    224224 */
    225225double QwtCounter::value() const
    226226{
    227     return d_data->value;
    228 }
    229 
    230 /*!
    231   \brief Set the minimum and maximum values
    232 
    233   The maximum is adjusted if necessary to ensure that the range remains valid.
    234   The value might be modified to be inside of the range.
    235 
    236   \param min Minimum value
    237   \param max Maximum value
    238 
    239   \sa minimum(), maximum()
     227    return m_data->value;
     228}
     229
     230/*!
     231   \brief Set the minimum and maximum values
     232
     233   The maximum is adjusted if necessary to ensure that the range remains valid.
     234   The value might be modified to be inside of the range.
     235
     236   \param min Minimum value
     237   \param max Maximum value
     238
     239   \sa minimum(), maximum()
    240240 */
    241241void QwtCounter::setRange( double min, double max )
    242242{
    243     max = qMax( min, max );
    244 
    245     if ( d_data->maximum == max && d_data->minimum == min )
     243    max = qwtMaxF( min, max );
     244
     245    if ( m_data->maximum == max && m_data->minimum == min )
    246246        return;
    247247
    248     d_data->minimum = min;
    249     d_data->maximum = max;
     248    m_data->minimum = min;
     249    m_data->maximum = max;
    250250
    251251    setSingleStep( singleStep() );
    252252
    253     const double value = qBound( min, d_data->value, max );
    254 
    255     if ( value != d_data->value )
    256     {
    257         d_data->value = value;
    258 
    259         if ( d_data->isValid )
     253    const double value = qBound( min, m_data->value, max );
     254
     255    if ( value != m_data->value )
     256    {
     257        m_data->value = value;
     258
     259        if ( m_data->isValid )
    260260        {
    261261            showNumber( value );
    … …  
    268268
    269269/*!
    270   Set the minimum value of the range
    271 
    272   \param value Minimum value
    273   \sa setRange(), setMaximum(), minimum()
    274 
    275   \note The maximum is adjusted if necessary to ensure that the range remains valid.
    276 */
     270   Set the minimum value of the range
     271
     272   \param value Minimum value
     273   \sa setRange(), setMaximum(), minimum()
     274
     275   \note The maximum is adjusted if necessary to ensure that the range remains valid.
     276 */
    277277void QwtCounter::setMinimum( double value )
    278278{
    … …  
    281281
    282282/*!
    283   \return The minimum of the range
    284   \sa setRange(), setMinimum(), maximum()
    285 */
     283   \return The minimum of the range
     284   \sa setRange(), setMinimum(), maximum()
     285 */
    286286double QwtCounter::minimum() const
    287287{
    288     return d_data->minimum;
    289 }
    290 
    291 /*!
    292   Set the maximum value of the range
    293 
    294   \param value Maximum value
    295   \sa setRange(), setMinimum(), maximum()
    296 */
     288    return m_data->minimum;
     289}
     290
     291/*!
     292   Set the maximum value of the range
     293
     294   \param value Maximum value
     295   \sa setRange(), setMinimum(), maximum()
     296 */
    297297void QwtCounter::setMaximum( double value )
    298298{
    … …  
    301301
    302302/*!
    303   \return The maximum of the range
    304   \sa setRange(), setMaximum(), minimum()
    305 */
     303   \return The maximum of the range
     304   \sa setRange(), setMaximum(), minimum()
     305 */
    306306double QwtCounter::maximum() const
    307307{
    308     return d_data->maximum;
    309 }
    310 
    311 /*!
    312   \brief Set the step size of the counter
    313 
    314   A value <= 0.0 disables stepping
    315 
    316   \param stepSize Single step size
    317   \sa singleStep()
    318 */
     308    return m_data->maximum;
     309}
     310
     311/*!
     312   \brief Set the step size of the counter
     313
     314   A value <= 0.0 disables stepping
     315
     316   \param stepSize Single step size
     317   \sa singleStep()
     318 */
    319319void QwtCounter::setSingleStep( double stepSize )
    320320{
    321     d_data->singleStep = qMax( stepSize, 0.0 );
    322 }
    323 
    324 /*!
    325   \return Single step size
    326   \sa setSingleStep()
     321    m_data->singleStep = qwtMaxF( stepSize, 0.0 );
     322}
     323
     324/*!
     325   \return Single step size
     326   \sa setSingleStep()
    327327 */
    328328double QwtCounter::singleStep() const
    329329{
    330     return d_data->singleStep;
    331 }
    332 
    333 /*!
    334   \brief En/Disable wrapping
    335 
    336   If wrapping is true stepping up from maximum() value will take
    337   you to the minimum() value and vice versa.
    338 
    339   \param on En/Disable wrapping
    340   \sa wrapping()
     330    return m_data->singleStep;
     331}
     332
     333/*!
     334   \brief En/Disable wrapping
     335
     336   If wrapping is true stepping up from maximum() value will take
     337   you to the minimum() value and vice versa.
     338
     339   \param on En/Disable wrapping
     340   \sa wrapping()
    341341 */
    342342void QwtCounter::setWrapping( bool on )
    343343{
    344     d_data->wrapping = on;
    345 }
    346 
    347 /*!
    348   \return True, when wrapping is set
    349   \sa setWrapping()
     344    m_data->wrapping = on;
     345}
     346
     347/*!
     348   \return True, when wrapping is set
     349   \sa setWrapping()
    350350 */
    351351bool QwtCounter::wrapping() const
    352352{
    353     return d_data->wrapping;
    354 }
    355 
    356 /*!
    357   Specify the number of buttons on each side of the label
    358 
    359   \param numButtons Number of buttons
    360   \sa numButtons()
    361 */
     353    return m_data->wrapping;
     354}
     355
     356/*!
     357   Specify the number of buttons on each side of the label
     358
     359   \param numButtons Number of buttons
     360   \sa numButtons()
     361 */
    362362void QwtCounter::setNumButtons( int numButtons )
    363363{
    … …  
    369369        if ( i < numButtons )
    370370        {
    371             d_data->buttonDown[i]->show();
    372             d_data->buttonUp[i]->show();
     371            m_data->buttonDown[i]->show();
     372            m_data->buttonUp[i]->show();
    373373        }
    374374        else
    375375        {
    376             d_data->buttonDown[i]->hide();
    377             d_data->buttonUp[i]->hide();
    378         }
    379     }
    380 
    381     d_data->numButtons = numButtons;
    382 }
    383 
    384 /*!
    385   \return The number of buttons on each side of the widget.
    386   \sa setNumButtons()
    387 */
     376            m_data->buttonDown[i]->hide();
     377            m_data->buttonUp[i]->hide();
     378        }
     379    }
     380
     381    m_data->numButtons = numButtons;
     382}
     383
     384/*!
     385   \return The number of buttons on each side of the widget.
     386   \sa setNumButtons()
     387 */
    388388int QwtCounter::numButtons() const
    389389{
    390     return d_data->numButtons;
    391 }
    392 
    393 /*!
    394   Specify the number of steps by which the value
    395   is incremented or decremented when a specified button
    396   is pushed.
    397 
    398   \param button Button index
    399   \param numSteps Number of steps
    400 
    401   \sa incSteps()
    402 */
     390    return m_data->numButtons;
     391}
     392
     393/*!
     394   Specify the number of steps by which the value
     395   is incremented or decremented when a specified button
     396   is pushed.
     397
     398   \param button Button index
     399   \param numSteps Number of steps
     400
     401   \sa incSteps()
     402 */
    403403void QwtCounter::setIncSteps( QwtCounter::Button button, int numSteps )
    404404{
    405405    if ( button >= 0 && button < QwtCounter::ButtonCnt )
    406         d_data->increment[ button ] = numSteps;
    407 }
    408 
    409 /*!
    410   \return The number of steps by which a specified button increments the value
     406        m_data->increment[ button ] = numSteps;
     407}
     408
     409/*!
     410   \return The number of steps by which a specified button increments the value
    411411          or 0 if the button is invalid.
    412   \param button Button index
    413 
    414   \sa setIncSteps()
    415 */
     412   \param button Button index
     413
     414   \sa setIncSteps()
     415 */
    416416int QwtCounter::incSteps( QwtCounter::Button button ) const
    417417{
    418418    if ( button >= 0 && button < QwtCounter::ButtonCnt )
    419         return d_data->increment[ button ];
     419        return m_data->increment[ button ];
    420420
    421421    return 0;
    … …  
    424424
    425425/*!
    426   Set the number of increment steps for button 1
    427   \param nSteps Number of steps
    428 */
     426   Set the number of increment steps for button 1
     427   \param nSteps Number of steps
     428 */
    429429void QwtCounter::setStepButton1( int nSteps )
    430430{
    … …  
    439439
    440440/*!
    441   Set the number of increment steps for button 2
    442   \param nSteps Number of steps
    443 */
     441   Set the number of increment steps for button 2
     442   \param nSteps Number of steps
     443 */
    444444void QwtCounter::setStepButton2( int nSteps )
    445445{
    … …  
    454454
    455455/*!
    456   Set the number of increment steps for button 3
    457   \param nSteps Number of steps
    458 */
     456   Set the number of increment steps for button 3
     457   \param nSteps Number of steps
     458 */
    459459void QwtCounter::setStepButton3( int nSteps )
    460460{
    … …  
    473473    bool converted = false;
    474474
    475     const double value = d_data->valueEdit->text().toDouble( &converted );
     475    const double value = m_data->valueEdit->text().toDouble( &converted );
    476476    if ( converted )
    477477        setValue( value );
    … …  
    482482   \param event Event
    483483   \return see QWidget::event()
    484 */
    485 bool QwtCounter::event( QEvent *event )
     484 */
     485bool QwtCounter::event( QEvent* event )
    486486{
    487487    if ( event->type() == QEvent::PolishRequest )
    488488    {
    489         const int w = d_data->valueEdit->fontMetrics().width( "W" ) + 8;
     489        const QFontMetrics fm = m_data->valueEdit->fontMetrics();
     490
     491        const int w = QwtPainter::horizontalAdvance( fm, "W" ) + 8;
    490492        for ( int i = 0; i < ButtonCnt; i++ )
    491493        {
    492             d_data->buttonDown[i]->setMinimumWidth( w );
    493             d_data->buttonUp[i]->setMinimumWidth( w );
     494            m_data->buttonDown[i]->setMinimumWidth( w );
     495            m_data->buttonUp[i]->setMinimumWidth( w );
    494496        }
    495497    }
    … …  
    499501
    500502/*!
    501   Handle key events
    502 
    503   - Ctrl + Qt::Key_Home\n
     503   Handle key events
     504
     505   - Ctrl + Qt::Key_Home\n
    504506    Step to minimum()
    505   - Ctrl + Qt::Key_End\n
     507   - Ctrl + Qt::Key_End\n
    506508    Step to maximum()
    507   - Qt::Key_Up\n
     509   - Qt::Key_Up\n
    508510    Increment by incSteps(QwtCounter::Button1)
    509   - Qt::Key_Down\n
     511   - Qt::Key_Down\n
    510512    Decrement by incSteps(QwtCounter::Button1)
    511   - Qt::Key_PageUp\n
     513   - Qt::Key_PageUp\n
    512514    Increment by incSteps(QwtCounter::Button2)
    513   - Qt::Key_PageDown\n
     515   - Qt::Key_PageDown\n
    514516    Decrement by incSteps(QwtCounter::Button2)
    515   - Shift + Qt::Key_PageUp\n
     517   - Shift + Qt::Key_PageUp\n
    516518    Increment by incSteps(QwtCounter::Button3)
    517   - Shift + Qt::Key_PageDown\n
     519   - Shift + Qt::Key_PageDown\n
    518520    Decrement by incSteps(QwtCounter::Button3)
    519521
    520   \param event Key event
    521 */
    522 void QwtCounter::keyPressEvent ( QKeyEvent *event )
     522   \param event Key event
     523 */
     524void QwtCounter::keyPressEvent ( QKeyEvent* event )
    523525{
    524526    bool accepted = true;
    … …  
    544546        case Qt::Key_Up:
    545547        {
    546             incrementValue( d_data->increment[0] );
     548            incrementValue( m_data->increment[0] );
    547549            break;
    548550        }
    549551        case Qt::Key_Down:
    550552        {
    551             incrementValue( -d_data->increment[0] );
     553            incrementValue( -m_data->increment[0] );
    552554            break;
    553555        }
    … …  
    555557        case Qt::Key_PageDown:
    556558        {
    557             int increment = d_data->increment[0];
    558             if ( d_data->numButtons >= 2 )
    559                 increment = d_data->increment[1];
    560             if ( d_data->numButtons >= 3 )
     559            int increment = m_data->increment[0];
     560            if ( m_data->numButtons >= 2 )
     561                increment = m_data->increment[1];
     562            if ( m_data->numButtons >= 3 )
    561563            {
    562564                if ( event->modifiers() & Qt::ShiftModifier )
    563                     increment = d_data->increment[2];
     565                    increment = m_data->increment[2];
    564566            }
    565567            if ( event->key() == Qt::Key_PageDown )
    … …  
    584586
    585587/*!
    586   Handle wheel events
    587   \param event Wheel event
    588 */
    589 void QwtCounter::wheelEvent( QWheelEvent *event )
     588   Handle wheel events
     589   \param event Wheel event
     590 */
     591void QwtCounter::wheelEvent( QWheelEvent* event )
    590592{
    591593    event->accept();
    592594
    593     if ( d_data->numButtons <= 0 )
     595    if ( m_data->numButtons <= 0 )
    594596        return;
    595597
    596     int increment = d_data->increment[0];
    597     if ( d_data->numButtons >= 2 )
     598    int increment = m_data->increment[0];
     599    if ( m_data->numButtons >= 2 )
    598600    {
    599601        if ( event->modifiers() & Qt::ControlModifier )
    600             increment = d_data->increment[1];
    601     }
    602     if ( d_data->numButtons >= 3 )
     602            increment = m_data->increment[1];
     603    }
     604    if ( m_data->numButtons >= 3 )
    603605    {
    604606        if ( event->modifiers() & Qt::ShiftModifier )
    605             increment = d_data->increment[2];
    606     }
    607 
    608     for ( int i = 0; i < d_data->numButtons; i++ )
    609     {
    610         if ( d_data->buttonDown[i]->geometry().contains( event->pos() ) ||
    611             d_data->buttonUp[i]->geometry().contains( event->pos() ) )
    612         {
    613             increment = d_data->increment[i];
    614         }
    615     }
    616 
    617     const int wheel_delta = 120;
     607            increment = m_data->increment[2];
     608    }
     609
     610#if QT_VERSION < 0x050e00
     611    const QPoint wheelPos = event->pos();
     612    const int wheelDelta = event->delta();
     613#else
     614    const QPoint wheelPos = event->position().toPoint();
     615
     616    const QPoint delta = event->angleDelta();
     617    const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
     618        ? delta.x() : delta.y();
     619#endif
     620
     621    for ( int i = 0; i < m_data->numButtons; i++ )
     622    {
     623        if ( m_data->buttonDown[i]->geometry().contains( wheelPos ) ||
     624            m_data->buttonUp[i]->geometry().contains( wheelPos ) )
     625        {
     626            increment = m_data->increment[i];
     627        }
     628    }
     629
     630    incrementValue( wheelDelta / 120 * increment );
     631}
     632
     633void QwtCounter::incrementValue( int numSteps )
     634{
     635    const double min = m_data->minimum;
     636    const double max = m_data->maximum;
     637    double stepSize = m_data->singleStep;
     638
     639    if ( !m_data->isValid || min >= max || stepSize <= 0.0 )
     640        return;
     641
    618642
    619643#if 1
    620     int delta = event->delta();
    621     if ( delta >= 2 * wheel_delta )
    622         delta /= 2; // Never saw an abs(delta) < 240
     644    stepSize = qwtMaxF( stepSize, 1.0e-10 * ( max - min ) );
    623645#endif
    624646
    625     incrementValue( delta / wheel_delta * increment );
    626 }
    627 
    628 void QwtCounter::incrementValue( int numSteps )
    629 {
    630     const double min = d_data->minimum;
    631     const double max = d_data->maximum;
    632     double stepSize = d_data->singleStep;
    633 
    634     if ( !d_data->isValid || min >= max || stepSize <= 0.0 )
    635         return;
    636 
    637 
    638 #if 1
    639     stepSize = qMax( stepSize, 1.0e-10 * ( max - min ) );
    640 #endif
    641 
    642     double value = d_data->value + numSteps * stepSize;
    643 
    644     if ( d_data->wrapping )
     647    double value = m_data->value + numSteps * stepSize;
     648
     649    if ( m_data->wrapping )
    645650    {
    646651        const double range = max - min;
    … …  
    648653        if ( value < min )
    649654        {
    650             value += ::ceil( ( min - value ) / range ) * range;
     655            value += std::ceil( ( min - value ) / range ) * range;
    651656        }
    652657        else if ( value > max )
    653658        {
    654             value -= ::ceil( ( value - max ) / range ) * range;
     659            value -= std::ceil( ( value - max ) / range ) * range;
    655660        }
    656661    }
    … …  
    676681    }
    677682
    678     if ( value != d_data->value )
    679     {
    680         d_data->value = value;
    681         showNumber( d_data->value );
     683    if ( value != m_data->value )
     684    {
     685        m_data->value = value;
     686        showNumber( m_data->value );
    682687        updateButtons();
    683688
    684         Q_EMIT valueChanged( d_data->value );
    685     }
    686 }
    687 
    688 
    689 /*!
    690   \brief Update buttons according to the current value
    691 
    692   When the QwtCounter under- or over-flows, the focus is set to the smallest
    693   up- or down-button and counting is disabled.
    694 
    695   Counting is re-enabled on a button release event (mouse or space bar).
    696 */
     689        Q_EMIT valueChanged( m_data->value );
     690    }
     691}
     692
     693
     694/*!
     695   \brief Update buttons according to the current value
     696
     697   When the QwtCounter under- or over-flows, the focus is set to the smallest
     698   up- or down-button and counting is disabled.
     699
     700   Counting is re-enabled on a button release event (mouse or space bar).
     701 */
    697702void QwtCounter::updateButtons()
    698703{
    699     if ( d_data->isValid )
     704    if ( m_data->isValid )
    700705    {
    701706        // 1. save enabled state of the smallest down- and up-button
    … …  
    704709        for ( int i = 0; i < QwtCounter::ButtonCnt; i++ )
    705710        {
    706             d_data->buttonDown[i]->setEnabled( value() > minimum() );
    707             d_data->buttonUp[i]->setEnabled( value() < maximum() );
     711            m_data->buttonDown[i]->setEnabled( value() > minimum() );
     712            m_data->buttonUp[i]->setEnabled( value() < maximum() );
    708713        }
    709714    }
    … …  
    712717        for ( int i = 0; i < QwtCounter::ButtonCnt; i++ )
    713718        {
    714             d_data->buttonDown[i]->setEnabled( false );
    715             d_data->buttonUp[i]->setEnabled( false );
    716         }
    717     }
    718 }
    719 /*!
    720   Display number string
    721 
    722   \param number Number
    723 */
     719            m_data->buttonDown[i]->setEnabled( false );
     720            m_data->buttonUp[i]->setEnabled( false );
     721        }
     722    }
     723}
     724/*!
     725   Display number string
     726
     727   \param number Number
     728 */
    724729void QwtCounter::showNumber( double number )
    725730{
    … …  
    727732    text.setNum( number );
    728733
    729     const int cursorPos = d_data->valueEdit->cursorPosition();
    730     d_data->valueEdit->setText( text );
    731     d_data->valueEdit->setCursorPosition( cursorPos );
     734    const int cursorPos = m_data->valueEdit->cursorPosition();
     735    m_data->valueEdit->setText( text );
     736    m_data->valueEdit->setCursorPosition( cursorPos );
    732737}
    733738
    … …  
    737742    for ( int i = 0; i < ButtonCnt; i++ )
    738743    {
    739         if ( d_data->buttonUp[i] == sender() )
    740             incrementValue( d_data->increment[i] );
    741 
    742         if ( d_data->buttonDown[i] == sender() )
    743             incrementValue( -d_data->increment[i] );
     744        if ( m_data->buttonUp[i] == sender() )
     745            incrementValue( m_data->increment[i] );
     746
     747        if ( m_data->buttonDown[i] == sender() )
     748            incrementValue( -m_data->increment[i] );
    744749    }
    745750}
    … …  
    769774    tmp.fill( '9', w );
    770775
    771     QFontMetrics fm( d_data->valueEdit->font() );
    772     w = fm.width( tmp ) + 2;
    773     if ( d_data->valueEdit->hasFrame() )
     776    w = QwtPainter::horizontalAdvance( m_data->valueEdit->fontMetrics(), tmp ) + 2;
     777
     778    if ( m_data->valueEdit->hasFrame() )
    774779        w += 2 * style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
    775780
    776     // Now we replace default sizeHint contribution of d_data->valueEdit by
     781    // Now we replace default sizeHint contribution of m_data->valueEdit by
    777782    // what we really need.
    778783
    779     w += QWidget::sizeHint().width() - d_data->valueEdit->sizeHint().width();
     784    w += QWidget::sizeHint().width() - m_data->valueEdit->sizeHint().width();
    780785
    781786    const int h = qMin( QWidget::sizeHint().height(),
    782         d_data->valueEdit->minimumSizeHint().height() );
     787        m_data->valueEdit->minimumSizeHint().height() );
     788
    783789    return QSize( w, h );
    784790}
     791
     792#include "moc_qwt_counter.cpp"
  • trunk/BNC/qwt/qwt_counter.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1515
    1616/*!
    17   \brief The Counter Widget
     17   \brief The Counter Widget
    1818
    19   A Counter consists of a label displaying a number and
    20   one ore more (up to three) push buttons on each side
    21   of the label which can be used to increment or decrement
    22   the counter's value.
     19   A Counter consists of a label displaying a number and
     20   one ore more (up to three) push buttons on each side
     21   of the label which can be used to increment or decrement
     22   the counter's value.
    2323
    24   A counter has a range from a minimum value to a maximum value
    25   and a step size. When the wrapping property is set
    26   the counter is circular.
     24   A counter has a range from a minimum value to a maximum value
     25   and a step size. When the wrapping property is set
     26   the counter is circular.
    2727
    28   The number of steps by which a button increments or decrements the value
    29   can be specified using setIncSteps(). The number of buttons can be
    30   changed with setNumButtons().
     28   The number of steps by which a button increments or decrements the value
     29   can be specified using setIncSteps(). The number of buttons can be
     30   changed with setNumButtons().
    3131
    32   Example:
    33 \code
    34 #include <qwt_counter.h>
     32   Example:
     33   \code
     34 #include <qwt_counter.h>
    3535
    36 QwtCounter *counter = new QwtCounter(parent);
     36   QwtCounter *counter = new QwtCounter(parent);
    3737
    38 counter->setRange(0.0, 100.0);                  // From 0.0 to 100
    39 counter->setSingleStep( 1.0 );                  // Step size 1.0
    40 counter->setNumButtons(2);                      // Two buttons each side
    41 counter->setIncSteps(QwtCounter::Button1, 1);   // Button 1 increments 1 step
    42 counter->setIncSteps(QwtCounter::Button2, 20);  // Button 2 increments 20 steps
     38   counter->setRange(0.0, 100.0);                  // From 0.0 to 100
     39   counter->setSingleStep( 1.0 );                  // Step size 1.0
     40   counter->setNumButtons(2);                      // Two buttons each side
     41   counter->setIncSteps(QwtCounter::Button1, 1);   // Button 1 increments 1 step
     42   counter->setIncSteps(QwtCounter::Button2, 20);  // Button 2 increments 20 steps
    4343
    44 connect(counter, SIGNAL(valueChanged(double)), myClass, SLOT(newValue(double)));
    45 \endcode
     44   connect(counter, SIGNAL(valueChanged(double)), myClass, SLOT(newValue(double)));
     45   \endcode
    4646 */
    4747
    … …  
    5050    Q_OBJECT
    5151
    52     Q_PROPERTY( double value READ value WRITE setValue )
     52    Q_PROPERTY( double value READ value WRITE setValue NOTIFY valueChanged USER true )
    5353    Q_PROPERTY( double minimum READ minimum WRITE setMinimum )
    5454    Q_PROPERTY( double maximum READ maximum WRITE setMaximum )
    … …  
    6363    Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping )
    6464
    65 public:
     65  public:
    6666    //! Button index
    6767    enum Button
    … …  
    8080    };
    8181
    82     explicit QwtCounter( QWidget *parent = NULL );
     82    explicit QwtCounter( QWidget* parent = NULL );
    8383    virtual ~QwtCounter();
    8484
    … …  
    9898    int incSteps( QwtCounter::Button ) const;
    9999
    100     virtual QSize sizeHint() const;
     100    virtual QSize sizeHint() const QWT_OVERRIDE;
    101101
    102102    double singleStep() const;
    … …  
    122122    double value() const;
    123123
    124 public Q_SLOTS:
     124  public Q_SLOTS:
    125125    void setValue( double );
    126126
    127127
    128 Q_SIGNALS:
     128  Q_SIGNALS:
    129129    /*!
    130130        This signal is emitted when a button has been released
    131131        \param value The new value
    132     */
     132     */
    133133    void buttonReleased ( double value );
    134134
    … …  
    136136        This signal is emitted when the counter's value has changed
    137137        \param value The new value
    138     */
     138     */
    139139    void valueChanged ( double value );
    140140
    141 protected:
    142     virtual bool event( QEvent * );
    143     virtual void wheelEvent( QWheelEvent * );
    144     virtual void keyPressEvent( QKeyEvent * );
     141  protected:
     142    virtual bool event( QEvent* ) QWT_OVERRIDE;
     143    virtual void wheelEvent( QWheelEvent* ) QWT_OVERRIDE;
     144    virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE;
    145145
    146 private Q_SLOTS:
     146  private Q_SLOTS:
    147147    void btnReleased();
    148148    void btnClicked();
    149149    void textChanged();
    150150
    151 private:
     151  private:
    152152    void incrementValue( int numSteps );
    153153    void initCounter();
    … …  
    156156
    157157    class PrivateData;
    158     PrivateData *d_data;
     158    PrivateData* m_data;
    159159};
    160160
  • trunk/BNC/qwt/qwt_curve_fitter.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_curve_fitter.h"
    11 #include "qwt_math.h"
    12 #include "qwt_spline.h"
    13 #include <qstack.h>
    14 #include <qvector.h>
    1511
    16 #if QT_VERSION < 0x040601
    17 #define qFabs(x) ::fabs(x)
    18 #endif
    19 
    20 //! Constructor
    21 QwtCurveFitter::QwtCurveFitter()
     12/*!
     13   Constructor
     14   \param mode Preferred fitting mode
     15 */
     16QwtCurveFitter::QwtCurveFitter( Mode mode )
     17    : m_mode( mode )
    2218{
    2319}
    … …  
    2824}
    2925
    30 class QwtSplineCurveFitter::PrivateData
     26//! \return Preferred fitting mode
     27QwtCurveFitter::Mode QwtCurveFitter::mode() const
    3128{
    32 public:
    33     PrivateData():
    34         fitMode( QwtSplineCurveFitter::Auto ),
    35         splineSize( 250 )
    36     {
    37     }
    38 
    39     QwtSpline spline;
    40     QwtSplineCurveFitter::FitMode fitMode;
    41     int splineSize;
    42 };
    43 
    44 //! Constructor
    45 QwtSplineCurveFitter::QwtSplineCurveFitter()
    46 {
    47     d_data = new PrivateData;
     29    return m_mode;
    4830}
    49 
    50 //! Destructor
    51 QwtSplineCurveFitter::~QwtSplineCurveFitter()
    52 {
    53     delete d_data;
    54 }
    55 
    56 /*!
    57   Select the algorithm used for building the spline
    58 
    59   \param mode Mode representing a spline algorithm
    60   \sa fitMode()
    61 */
    62 void QwtSplineCurveFitter::setFitMode( FitMode mode )
    63 {
    64     d_data->fitMode = mode;
    65 }
    66 
    67 /*!
    68   \return Mode representing a spline algorithm
    69   \sa setFitMode()
    70 */
    71 QwtSplineCurveFitter::FitMode QwtSplineCurveFitter::fitMode() const
    72 {
    73     return d_data->fitMode;
    74 }
    75 
    76 /*!
    77   Assign a spline
    78 
    79   \param spline Spline
    80   \sa spline()
    81 */
    82 void QwtSplineCurveFitter::setSpline( const QwtSpline &spline )
    83 {
    84     d_data->spline = spline;
    85     d_data->spline.reset();
    86 }
    87 
    88 /*!
    89   \return Spline
    90   \sa setSpline()
    91 */
    92 const QwtSpline &QwtSplineCurveFitter::spline() const
    93 {
    94     return d_data->spline;
    95 }
    96 
    97 /*!
    98   \return Spline
    99   \sa setSpline()
    100 */
    101 QwtSpline &QwtSplineCurveFitter::spline()
    102 {
    103     return d_data->spline;
    104 }
    105 
    106 /*!
    107    Assign a spline size ( has to be at least 10 points )
    108 
    109    \param splineSize Spline size
    110    \sa splineSize()
    111 */
    112 void QwtSplineCurveFitter::setSplineSize( int splineSize )
    113 {
    114     d_data->splineSize = qMax( splineSize, 10 );
    115 }
    116 
    117 /*!
    118   \return Spline size
    119   \sa setSplineSize()
    120 */
    121 int QwtSplineCurveFitter::splineSize() const
    122 {
    123     return d_data->splineSize;
    124 }
    125 
    126 /*!
    127   Find a curve which has the best fit to a series of data points
    128 
    129   \param points Series of data points
    130   \return Curve points
    131 */
    132 QPolygonF QwtSplineCurveFitter::fitCurve( const QPolygonF &points ) const
    133 {
    134     const int size = points.size();
    135     if ( size <= 2 )
    136         return points;
    137 
    138     FitMode fitMode = d_data->fitMode;
    139     if ( fitMode == Auto )
    140     {
    141         fitMode = Spline;
    142 
    143         const QPointF *p = points.data();
    144         for ( int i = 1; i < size; i++ )
    145         {
    146             if ( p[i].x() <= p[i-1].x() )
    147             {
    148                 fitMode = ParametricSpline;
    149                 break;
    150             }
    151         };
    152     }
    153 
    154     if ( fitMode == ParametricSpline )
    155         return fitParametric( points );
    156     else
    157         return fitSpline( points );
    158 }
    159 
    160 QPolygonF QwtSplineCurveFitter::fitSpline( const QPolygonF &points ) const
    161 {
    162     d_data->spline.setPoints( points );
    163     if ( !d_data->spline.isValid() )
    164         return points;
    165 
    166     QPolygonF fittedPoints( d_data->splineSize );
    167 
    168     const double x1 = points[0].x();
    169     const double x2 = points[int( points.size() - 1 )].x();
    170     const double dx = x2 - x1;
    171     const double delta = dx / ( d_data->splineSize - 1 );
    172 
    173     for ( int i = 0; i < d_data->splineSize; i++ )
    174     {
    175         QPointF &p = fittedPoints[i];
    176 
    177         const double v = x1 + i * delta;
    178         const double sv = d_data->spline.value( v );
    179 
    180         p.setX( v );
    181         p.setY( sv );
    182     }
    183     d_data->spline.reset();
    184 
    185     return fittedPoints;
    186 }
    187 
    188 QPolygonF QwtSplineCurveFitter::fitParametric( const QPolygonF &points ) const
    189 {
    190     int i;
    191     const int size = points.size();
    192 
    193     QPolygonF fittedPoints( d_data->splineSize );
    194     QPolygonF splinePointsX( size );
    195     QPolygonF splinePointsY( size );
    196 
    197     const QPointF *p = points.data();
    198     QPointF *spX = splinePointsX.data();
    199     QPointF *spY = splinePointsY.data();
    200 
    201     double param = 0.0;
    202     for ( i = 0; i < size; i++ )
    203     {
    204         const double x = p[i].x();
    205         const double y = p[i].y();
    206         if ( i > 0 )
    207         {
    208             const double delta = qSqrt( qwtSqr( x - spX[i-1].y() )
    209                       + qwtSqr( y - spY[i-1].y() ) );
    210             param += qMax( delta, 1.0 );
    211         }
    212         spX[i].setX( param );
    213         spX[i].setY( x );
    214         spY[i].setX( param );
    215         spY[i].setY( y );
    216     }
    217 
    218     d_data->spline.setPoints( splinePointsX );
    219     if ( !d_data->spline.isValid() )
    220         return points;
    221 
    222     const double deltaX =
    223         splinePointsX[size - 1].x() / ( d_data->splineSize - 1 );
    224     for ( i = 0; i < d_data->splineSize; i++ )
    225     {
    226         const double dtmp = i * deltaX;
    227         fittedPoints[i].setX( d_data->spline.value( dtmp ) );
    228     }
    229 
    230     d_data->spline.setPoints( splinePointsY );
    231     if ( !d_data->spline.isValid() )
    232         return points;
    233 
    234     const double deltaY =
    235         splinePointsY[size - 1].x() / ( d_data->splineSize - 1 );
    236     for ( i = 0; i < d_data->splineSize; i++ )
    237     {
    238         const double dtmp = i * deltaY;
    239         fittedPoints[i].setY( d_data->spline.value( dtmp ) );
    240     }
    241 
    242     return fittedPoints;
    243 }
    244 
    245 class QwtWeedingCurveFitter::PrivateData
    246 {
    247 public:
    248     PrivateData():
    249         tolerance( 1.0 ),
    250         chunkSize( 0 )
    251     {
    252     }
    253 
    254     double tolerance;
    255     uint chunkSize;
    256 };
    257 
    258 class QwtWeedingCurveFitter::Line
    259 {
    260 public:
    261     Line( int i1 = 0, int i2 = 0 ):
    262         from( i1 ),
    263         to( i2 )
    264     {
    265     }
    266 
    267     int from;
    268     int to;
    269 };
    270 
    271 /*!
    272    Constructor
    273 
    274    \param tolerance Tolerance
    275    \sa setTolerance(), tolerance()
    276 */
    277 QwtWeedingCurveFitter::QwtWeedingCurveFitter( double tolerance )
    278 {
    279     d_data = new PrivateData;
    280     setTolerance( tolerance );
    281 }
    282 
    283 //! Destructor
    284 QwtWeedingCurveFitter::~QwtWeedingCurveFitter()
    285 {
    286     delete d_data;
    287 }
    288 
    289 /*!
    290  Assign the tolerance
    291 
    292  The tolerance is the maximum distance, that is acceptable
    293  between the original curve and the smoothed curve.
    294 
    295  Increasing the tolerance will reduce the number of the
    296  resulting points.
    297 
    298  \param tolerance Tolerance
    299 
    300  \sa tolerance()
    301 */
    302 void QwtWeedingCurveFitter::setTolerance( double tolerance )
    303 {
    304     d_data->tolerance = qMax( tolerance, 0.0 );
    305 }
    306 
    307 /*!
    308   \return Tolerance
    309   \sa setTolerance()
    310 */
    311 double QwtWeedingCurveFitter::tolerance() const
    312 {
    313     return d_data->tolerance;
    314 }
    315 
    316 /*!
    317  Limit the number of points passed to a run of the algorithm
    318 
    319  The runtime of the Douglas Peucker algorithm increases non linear
    320  with the number of points. For a chunk size > 0 the polygon
    321  is split into pieces passed to the algorithm one by one.
    322 
    323  \param numPoints Maximum for the number of points passed to the algorithm
    324 
    325  \sa chunkSize()
    326 */
    327 void QwtWeedingCurveFitter::setChunkSize( uint numPoints )
    328 {
    329     if ( numPoints > 0 )
    330         numPoints = qMax( numPoints, 3U );
    331 
    332     d_data->chunkSize = numPoints;
    333 }
    334 
    335 /*!
    336   \return Maximum for the number of points passed to a run
    337           of the algorithm - or 0, when unlimited
    338   \sa setChunkSize()
    339 */
    340 uint QwtWeedingCurveFitter::chunkSize() const
    341 {
    342     return d_data->chunkSize;
    343 }
    344 
    345 /*!
    346   \param points Series of data points
    347   \return Curve points
    348 */
    349 QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const
    350 {
    351     if ( points.isEmpty() )
    352         return points;
    353 
    354     QPolygonF fittedPoints;
    355     if ( d_data->chunkSize == 0 )
    356     {
    357         fittedPoints = simplify( points );
    358     }
    359     else
    360     {
    361         for ( int i = 0; i < points.size(); i += d_data->chunkSize )
    362         {
    363             const QPolygonF p = points.mid( i, d_data->chunkSize );
    364             fittedPoints += simplify( p );
    365         }
    366     }
    367 
    368     return fittedPoints;
    369 }
    370 
    371 QPolygonF QwtWeedingCurveFitter::simplify( const QPolygonF &points ) const
    372 {
    373     const double toleranceSqr = d_data->tolerance * d_data->tolerance;
    374 
    375     QStack<Line> stack;
    376     stack.reserve( 500 );
    377 
    378     const QPointF *p = points.data();
    379     const int nPoints = points.size();
    380 
    381     QVector<bool> usePoint( nPoints, false );
    382 
    383     stack.push( Line( 0, nPoints - 1 ) );
    384 
    385     while ( !stack.isEmpty() )
    386     {
    387         const Line r = stack.pop();
    388 
    389         // initialize line segment
    390         const double vecX = p[r.to].x() - p[r.from].x();
    391         const double vecY = p[r.to].y() - p[r.from].y();
    392 
    393         const double vecLength = qSqrt( vecX * vecX + vecY * vecY );
    394 
    395         const double unitVecX = ( vecLength != 0.0 ) ? vecX / vecLength : 0.0;
    396         const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0;
    397 
    398         double maxDistSqr = 0.0;
    399         int nVertexIndexMaxDistance = r.from + 1;
    400         for ( int i = r.from + 1; i < r.to; i++ )
    401         {
    402             //compare to anchor
    403             const double fromVecX = p[i].x() - p[r.from].x();
    404             const double fromVecY = p[i].y() - p[r.from].y();
    405 
    406             double distToSegmentSqr;
    407             if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )
    408             {
    409                 distToSegmentSqr = fromVecX * fromVecX + fromVecY * fromVecY;
    410             }
    411             else
    412             {
    413                 const double toVecX = p[i].x() - p[r.to].x();
    414                 const double toVecY = p[i].y() - p[r.to].y();
    415                 const double toVecLength = toVecX * toVecX + toVecY * toVecY;
    416 
    417                 const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY );
    418                 if ( s < 0.0 )
    419                 {
    420                     distToSegmentSqr = toVecLength;
    421                 }
    422                 else
    423                 {
    424                     distToSegmentSqr = qFabs( toVecLength - s * s );
    425                 }
    426             }
    427 
    428             if ( maxDistSqr < distToSegmentSqr )
    429             {
    430                 maxDistSqr = distToSegmentSqr;
    431                 nVertexIndexMaxDistance = i;
    432             }
    433         }
    434         if ( maxDistSqr <= toleranceSqr )
    435         {
    436             usePoint[r.from] = true;
    437             usePoint[r.to] = true;
    438         }
    439         else
    440         {
    441             stack.push( Line( r.from, nVertexIndexMaxDistance ) );
    442             stack.push( Line( nVertexIndexMaxDistance, r.to ) );
    443         }
    444     }
    445 
    446     QPolygonF stripped;
    447     for ( int i = 0; i < nPoints; i++ )
    448     {
    449         if ( usePoint[i] )
    450             stripped += p[i];
    451     }
    452 
    453     return stripped;
    454 }
  • trunk/BNC/qwt/qwt_curve_fitter.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include <qpolygon.h>
    15 #include <qrect.h>
    1614
    17 class QwtSpline;
     15class QPainterPath;
     16class QPolygonF;
    1817
    1918/*!
    20   \brief Abstract base class for a curve fitter
    21 */
     19   \brief Abstract base class for a curve fitter
     20 */
    2221class QWT_EXPORT QwtCurveFitter
    2322{
    24 public:
     23  public:
     24    /*!
     25       \brief Preferred mode of the fitting algorithm
     26
     27       Even if a QPainterPath can always be created from a QPolygonF
     28       the overhead of the conversion can be avoided by indicating
     29       the preference of the implementation to the application
     30       code.
     31     */
     32    enum Mode
     33    {
     34        /*!
     35           The fitting algorithm creates a polygon - the implementation
     36           of fitCurvePath() simply wraps the polygon into a path.
     37
     38           \sa QwtWeedingCurveFitter
     39         */
     40        Polygon,
     41
     42        /*!
     43           The fitting algorithm creates a painter path - the implementation
     44           of fitCurve() extracts a polygon from the path.
     45
     46           \sa QwtSplineCurveFitter
     47         */
     48        Path
     49    };
     50
    2551    virtual ~QwtCurveFitter();
     52
     53    Mode mode() const;
    2654
    2755    /*!
    … …  
    3058        \param polygon Series of data points
    3159        \return Curve points
     60
     61        \sa fitCurvePath()
    3262     */
    33     virtual QPolygonF fitCurve( const QPolygonF &polygon ) const = 0;
     63    virtual QPolygonF fitCurve( const QPolygonF& polygon ) const = 0;
    3464
    35 protected:
    36     QwtCurveFitter();
     65    /*!
     66        Find a curve path which has the best fit to a series of data points
    3767
    38 private:
    39     QwtCurveFitter( const QwtCurveFitter & );
    40     QwtCurveFitter &operator=( const QwtCurveFitter & );
    41 };
     68        \param polygon Series of data points
     69        \return Curve path
    4270
    43 /*!
    44   \brief A curve fitter using cubic splines
    45 */
    46 class QWT_EXPORT QwtSplineCurveFitter: public QwtCurveFitter
    47 {
    48 public:
    49     /*!
    50       Spline type
    51       The default setting is Auto
    52       \sa setFitMode(), FitMode()
     71        \sa fitCurve()
    5372     */
    54     enum FitMode
    55     {
    56         /*!
    57           Use the default spline algorithm for polygons with
    58           increasing x values ( p[i-1] < p[i] ), otherwise use
    59           a parametric spline algorithm.
    60          */
    61         Auto,
     73    virtual QPainterPath fitCurvePath( const QPolygonF& polygon ) const = 0;
    6274
    63         //! Use a default spline algorithm
    64         Spline,
     75  protected:
     76    explicit QwtCurveFitter( Mode mode );
    6577
    66         //! Use a parametric spline algorithm
    67         ParametricSpline
    68     };
     78  private:
     79    Q_DISABLE_COPY(QwtCurveFitter)
    6980
    70     QwtSplineCurveFitter();
    71     virtual ~QwtSplineCurveFitter();
    72 
    73     void setFitMode( FitMode );
    74     FitMode fitMode() const;
    75 
    76     void setSpline( const QwtSpline& );
    77     const QwtSpline &spline() const;
    78     QwtSpline &spline();
    79 
    80     void setSplineSize( int );
    81     int splineSize() const;
    82 
    83     virtual QPolygonF fitCurve( const QPolygonF & ) const;
    84 
    85 private:
    86     QPolygonF fitSpline( const QPolygonF & ) const;
    87     QPolygonF fitParametric( const QPolygonF & ) const;
    88 
    89     class PrivateData;
    90     PrivateData *d_data;
    91 };
    92 
    93 /*!
    94   \brief A curve fitter implementing Douglas and Peucker algorithm
    95 
    96   The purpose of the Douglas and Peucker algorithm is that given a 'curve'
    97   composed of line segments to find a curve not too dissimilar but that
    98   has fewer points. The algorithm defines 'too dissimilar' based on the
    99   maximum distance (tolerance) between the original curve and the
    100   smoothed curve.
    101 
    102   The runtime of the algorithm increases non linear ( worst case O( n*n ) )
    103   and might be very slow for huge polygons. To avoid performance issues
    104   it might be useful to split the polygon ( setChunkSize() ) and to run the algorithm
    105   for these smaller parts. The disadvantage of having no interpolation
    106   at the borders is for most use cases irrelevant.
    107 
    108   The smoothed curve consists of a subset of the points that defined the
    109   original curve.
    110 
    111   In opposite to QwtSplineCurveFitter the Douglas and Peucker algorithm reduces
    112   the number of points. By adjusting the tolerance parameter according to the
    113   axis scales QwtSplineCurveFitter can be used to implement different
    114   level of details to speed up painting of curves of many points.
    115 */
    116 class QWT_EXPORT QwtWeedingCurveFitter: public QwtCurveFitter
    117 {
    118 public:
    119     QwtWeedingCurveFitter( double tolerance = 1.0 );
    120     virtual ~QwtWeedingCurveFitter();
    121 
    122     void setTolerance( double );
    123     double tolerance() const;
    124 
    125     void setChunkSize( uint );
    126     uint chunkSize() const;
    127 
    128     virtual QPolygonF fitCurve( const QPolygonF & ) const;
    129 
    130 private:
    131     virtual QPolygonF simplify( const QPolygonF & ) const;
    132 
    133     class Line;
    134 
    135     class PrivateData;
    136     PrivateData *d_data;
     81    const Mode m_mode;
    13782};
    13883
  • trunk/BNC/qwt/qwt_date.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_date.h"
     11#include "qwt_math.h"
     12
    1113#include <qdebug.h>
    1214#include <qlocale.h>
    13 #include <math.h>
     15
    1416#include <limits>
    15 #include <limits.h>
    1617
    1718#if QT_VERSION >= 0x050000
    … …  
    2425
    2526// QDate stores the Julian day as unsigned int, but
    26 // but it is QDate::fromJulianDay( int ). That's why
     27// there is QDate::fromJulianDay( int ). That's why
    2728// we have the range [ 1, INT_MAX ]
     29
    2830typedef int QwtJulianDay;
    2931static const QwtJulianDay minJulianDayD = 1;
    30 static const QwtJulianDay maxJulianDayD = std::numeric_limits<int>::max();
     32static const QwtJulianDay maxJulianDayD = std::numeric_limits< int >::max();
    3133
    3234#endif
    3335
    34 static QString qwtExpandedFormat( const QString & format,
    35     const QDateTime &dateTime, QwtDate::Week0Type week0Type )
     36static QString qwtExpandedFormat( const QString& format,
     37    const QDateTime& dateTime, QwtDate::Week0Type week0Type )
    3638{
    3739    const int week = QwtDate::weekNumber( dateTime.date(), week0Type );
    … …  
    4244    QString weekNoWW;
    4345    if ( weekNo.length() == 1 )
    44         weekNoWW += "0";
     46        weekNoWW += QLatin1Char( '0' );
    4547
    4648    weekNoWW += weekNo;
    4749
    4850    QString fmt = format;
    49     fmt.replace( "ww", weekNoWW );
    50     fmt.replace( "w", weekNo );
     51    fmt.replace( QLatin1String( "ww" ), weekNoWW );
     52    fmt.replace( QLatin1Char( 'w' ), weekNo );
    5153
    5254    if ( week == 1 && dateTime.date().month() != 1 )
    … …  
    5456        // in case of week 1, we might need to increment the year
    5557
    56         static QString s_yyyy = "yyyy";
    57         static QString s_yy = "yy";
     58        QLatin1String s_yyyy( "yyyy" );
     59        QLatin1String s_yy( "yy" );
    5860
    5961        // week 1 might start in the previous year
    … …  
    100102        {
    101103            const QDate dt( dateTime.date().year() + 1, 1, 1 );
     104            const QString dtString = QLocale().toString( dt, s_yyyy );
    102105
    103106            if ( fmt.contains( s_yyyy ) )
    104107            {
    105                 fmt.replace( s_yyyy, dt.toString( s_yyyy ) );
     108                fmt.replace( s_yyyy, dtString );
    106109            }
    107110            else
    108111            {
    109                 fmt.replace( s_yy, dt.toString( s_yyyy ) );
     112                fmt.replace( s_yy, dtString );
    110113            }
    111114        }
    … …  
    117120static inline Qt::DayOfWeek qwtFirstDayOfWeek()
    118121{
    119 #if QT_VERSION >= 0x040800
    120122    return QLocale().firstDayOfWeek();
    121 #else
    122 
    123     switch( QLocale().country() )
    124     {
    125         case QLocale::Maldives:
    126             return Qt::Friday;
    127 
    128         case QLocale::Afghanistan:
    129         case QLocale::Algeria:
    130         case QLocale::Bahrain:
    131         case QLocale::Djibouti:
    132         case QLocale::Egypt:
    133         case QLocale::Eritrea:
    134         case QLocale::Ethiopia:
    135         case QLocale::Iran:
    136         case QLocale::Iraq:
    137         case QLocale::Jordan:
    138         case QLocale::Kenya:
    139         case QLocale::Kuwait:
    140         case QLocale::LibyanArabJamahiriya:
    141         case QLocale::Morocco:
    142         case QLocale::Oman:
    143         case QLocale::Qatar:
    144         case QLocale::SaudiArabia:
    145         case QLocale::Somalia:
    146         case QLocale::Sudan:
    147         case QLocale::Tunisia:
    148         case QLocale::Yemen:
    149             return Qt::Saturday;
    150 
    151         case QLocale::AmericanSamoa:
    152         case QLocale::Argentina:
    153         case QLocale::Azerbaijan:
    154         case QLocale::Botswana:
    155         case QLocale::Canada:
    156         case QLocale::China:
    157         case QLocale::FaroeIslands:
    158         case QLocale::Georgia:
    159         case QLocale::Greenland:
    160         case QLocale::Guam:
    161         case QLocale::HongKong:
    162         case QLocale::Iceland:
    163         case QLocale::India:
    164         case QLocale::Ireland:
    165         case QLocale::Israel:
    166         case QLocale::Jamaica:
    167         case QLocale::Japan:
    168         case QLocale::Kyrgyzstan:
    169         case QLocale::Lao:
    170         case QLocale::Malta:
    171         case QLocale::MarshallIslands:
    172         case QLocale::Macau:
    173         case QLocale::Mongolia:
    174         case QLocale::NewZealand:
    175         case QLocale::NorthernMarianaIslands:
    176         case QLocale::Pakistan:
    177         case QLocale::Philippines:
    178         case QLocale::RepublicOfKorea:
    179         case QLocale::Singapore:
    180         case QLocale::SyrianArabRepublic:
    181         case QLocale::Taiwan:
    182         case QLocale::Thailand:
    183         case QLocale::TrinidadAndTobago:
    184         case QLocale::UnitedStates:
    185         case QLocale::UnitedStatesMinorOutlyingIslands:
    186         case QLocale::USVirginIslands:
    187         case QLocale::Uzbekistan:
    188         case QLocale::Zimbabwe:
    189             return Qt::Sunday;
    190 
    191         default:
    192             return Qt::Monday;
    193     }
    194 #endif
    195123}
    196124
    197125static inline void qwtFloorTime(
    198     QwtDate::IntervalType intervalType, QDateTime &dt )
     126    QwtDate::IntervalType intervalType, QDateTime& dt )
    199127{
    200128    // when dt is inside the special hour where DST is ending
    … …  
    234162
    235163static inline QDateTime qwtToTimeSpec(
    236     const QDateTime &dt, Qt::TimeSpec spec )
     164    const QDateTime& dt, Qt::TimeSpec spec )
    237165{
    238166    if ( dt.timeSpec() == spec )
    … …  
    240168
    241169    const qint64 jd = dt.date().toJulianDay();
    242     if ( jd < 0 || jd >= INT_MAX )
     170    if ( jd < 0 || jd >= std::numeric_limits< int >::max() )
    243171    {
    244172        // the conversion between local time and UTC
    … …  
    264192    const int m1 = ( month - 14 ) / 12;
    265193    const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12;
    266     const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 );
    267 
    268     return ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
    269             - ::floor( ( 3 * y1 ) / 4 ) + day - 32075;
     194    const double y1 = std::floor( ( 4900.0 + year + m1 ) / 100 );
     195
     196    return std::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
     197           - std::floor( ( 3 * y1 ) / 4 ) + day - 32075;
    270198}
    271199
    … …  
    300228        const int m1 = ( month - 14 ) / 12;
    301229        const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12;
    302         const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 );
    303 
    304         const double jd = ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
    305             - ::floor( ( 3 * y1 ) / 4 ) + day - 32075;
     230        const double y1 = std::floor( ( 4900.0 + year + m1 ) / 100 );
     231
     232        const double jd = std::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
     233            - std::floor( ( 3 * y1 ) / 4 ) + day - 32075;
    306234
    307235        if ( jd > maxJulianDayD )
    … …  
    311239        }
    312240
    313         return QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) );
     241        return QDate::fromJulianDay( static_cast< QwtJulianDay >( jd ) );
    314242    }
    315243    else
    … …  
    321249
    322250/*!
    323   Translate from double to QDateTime
    324 
    325   \param value Number of milliseconds since the epoch,
     251   Translate from double to QDateTime
     252
     253   \param value Number of milliseconds since the epoch,
    326254               1970-01-01T00:00:00 UTC
    327   \param timeSpec Time specification
    328   \return Datetime value
    329 
    330   \sa toDouble(), QDateTime::setMSecsSinceEpoch()
    331   \note The return datetime for Qt::OffsetFromUTC will be Qt::UTC
     255   \param timeSpec Time specification
     256   \return Datetime value
     257
     258   \sa toDouble(), QDateTime::setMSecsSinceEpoch()
     259   \note The return datetime for Qt::OffsetFromUTC will be Qt::UTC
    332260 */
    333261QDateTime QwtDate::toDateTime( double value, Qt::TimeSpec timeSpec )
    … …  
    335263    const int msecsPerDay = 86400000;
    336264
    337     const double days = static_cast<qint64>( ::floor( value / msecsPerDay ) );
     265    const double days = static_cast< qint64 >( std::floor( value / msecsPerDay ) );
    338266
    339267    const double jd = QwtDate::JulianDayForEpoch + days;
    … …  
    344272    }
    345273
    346     const QDate d = QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) );
    347 
    348     const int msecs = static_cast<int>( value - days * msecsPerDay );
     274    const QDate d = QDate::fromJulianDay( static_cast< QwtJulianDay >( jd ) );
     275
     276    const int msecs = static_cast< int >( value - days * msecsPerDay );
    349277
    350278    static const QTime timeNull( 0, 0, 0, 0 );
    … …  
    359287
    360288/*!
    361   Translate from QDateTime to double
    362 
    363   \param dateTime Datetime value
    364   \return Number of milliseconds since 1970-01-01T00:00:00 UTC has passed.
    365 
    366   \sa toDateTime(), QDateTime::toMSecsSinceEpoch()
    367   \warning For values very far below or above 1970-01-01 UTC rounding errors
     289   Translate from QDateTime to double
     290
     291   \param dateTime Datetime value
     292   \return Number of milliseconds since 1970-01-01T00:00:00 UTC has passed.
     293
     294   \sa toDateTime(), QDateTime::toMSecsSinceEpoch()
     295   \warning For values very far below or above 1970-01-01 UTC rounding errors
    368296           will happen due to the limited significance of a double.
    369297 */
    370 double QwtDate::toDouble( const QDateTime &dateTime )
     298double QwtDate::toDouble( const QDateTime& dateTime )
    371299{
    372300    const int msecsPerDay = 86400000;
    … …  
    384312
    385313/*!
    386   Ceil a datetime according the interval type
    387 
    388   \param dateTime Datetime value
    389   \param intervalType Interval type, how to ceil.
     314   Ceil a datetime according the interval type
     315
     316   \param dateTime Datetime value
     317   \param intervalType Interval type, how to ceil.
    390318                      F.e. when intervalType = QwtDate::Months, the result
    391319                      will be ceiled to the next beginning of a month
    392   \return Ceiled datetime
    393   \sa floor()
    394  */
    395 QDateTime QwtDate::ceil( const QDateTime &dateTime, IntervalType intervalType )
     320   \return Ceiled datetime
     321   \sa floor()
     322 */
     323QDateTime QwtDate::ceil( const QDateTime& dateTime, IntervalType intervalType )
    396324{
    397325    if ( dateTime.date() >= QwtDate::maxDate() )
    … …  
    485413
    486414/*!
    487   Floor a datetime according the interval type
    488 
    489   \param dateTime Datetime value
    490   \param intervalType Interval type, how to ceil.
     415   Floor a datetime according the interval type
     416
     417   \param dateTime Datetime value
     418   \param intervalType Interval type, how to ceil.
    491419                      F.e. when intervalType = QwtDate::Months,
    492420                      the result will be ceiled to the next
    493421                      beginning of a month
    494   \return Floored datetime
    495   \sa floor()
    496  */
    497 QDateTime QwtDate::floor( const QDateTime &dateTime,
     422   \return Floored datetime
     423   \sa floor()
     424 */
     425QDateTime QwtDate::floor( const QDateTime& dateTime,
    498426    IntervalType intervalType )
    499427{
    … …  
    558486
    559487/*!
    560   Minimum for the supported date range
    561 
    562   The range of valid dates depends on how QDate stores the
    563   Julian day internally.
    564 
    565   - For Qt4 it is "Tue Jan 2 -4713"
    566   - For Qt5 it is "Thu Jan 1 -2147483648"
    567 
    568   \return minimum of the date range
    569   \sa maxDate()
     488   Minimum for the supported date range
     489
     490   The range of valid dates depends on how QDate stores the
     491   Julian day internally.
     492
     493   - For Qt4 it is "Tue Jan 2 -4713"
     494   - For Qt5 it is "Thu Jan 1 -2147483648"
     495
     496   \return minimum of the date range
     497   \sa maxDate()
    570498 */
    571499QDate QwtDate::minDate()
    … …  
    579507
    580508/*!
    581   Maximum for the supported date range
    582 
    583   The range of valid dates depends on how QDate stores the
    584   Julian day internally.
    585 
    586   - For Qt4 it is "Tue Jun 3 5874898"
    587   - For Qt5 it is "Tue Dec 31 2147483647"
    588 
    589   \return maximum of the date range
    590   \sa minDate()
    591   \note The maximum differs between Qt4 and Qt5
     509   Maximum for the supported date range
     510
     511   The range of valid dates depends on how QDate stores the
     512   Julian day internally.
     513
     514   - For Qt4 it is "Tue Jun 3 5874898"
     515   - For Qt5 it is "Tue Dec 31 2147483647"
     516
     517   \return maximum of the date range
     518   \sa minDate()
     519   \note The maximum differs between Qt4 and Qt5
    592520 */
    593521QDate QwtDate::maxDate()
    … …  
    601529
    602530/*!
    603   \brief Date of the first day of the first week for a year
    604 
    605   The first day of a week depends on the current locale
    606   ( QLocale::firstDayOfWeek() ).
    607 
    608   \param year Year
    609   \param type Option how to identify the first week
    610   \return First day of week 0
    611 
    612   \sa QLocale::firstDayOfWeek(), weekNumber()
     531   \brief Date of the first day of the first week for a year
     532
     533   The first day of a week depends on the current locale
     534   ( QLocale::firstDayOfWeek() ).
     535
     536   \param year Year
     537   \param type Option how to identify the first week
     538   \return First day of week 0
     539
     540   \sa QLocale::firstDayOfWeek(), weekNumber()
    613541 */
    614542QDate QwtDate::dateOfWeek0( int year, Week0Type type )
    … …  
    628556    {
    629557        // according to ISO 8601 the first week is defined
    630         // by the first thursday.
     558        // by the first Thursday.
    631559
    632560        int d = Qt::Thursday - firstDayOfWeek;
    … …  
    642570
    643571/*!
    644   Find the week number of a date
    645 
    646   - QwtDate::FirstThursday\n
     572   Find the week number of a date
     573
     574   - QwtDate::FirstThursday\n
    647575    Corresponding to ISO 8601 ( see QDate::weekNumber() ).
    648576
    649   - QwtDate::FirstDay\n
     577   - QwtDate::FirstDay\n
    650578    Number of weeks that have begun since dateOfWeek0().
    651579
    652   \param date Date
    653   \param type Option how to identify the first week
    654 
    655   \return Week number, starting with 1
    656  */
    657 int QwtDate::weekNumber( const QDate &date, Week0Type type )
     580   \param date Date
     581   \param type Option how to identify the first week
     582
     583   \return Week number, starting with 1
     584 */
     585int QwtDate::weekNumber( const QDate& date, Week0Type type )
    658586{
    659587    int weekNo;
    … …  
    695623     0, dateTime has no offset
    696624   - Qt::OffsetFromUTC
    697      returns dateTime.utcOffset()
     625     returns dateTime.offsetFromUtc()
    698626   - Qt::LocalTime:
    699627     number of seconds from the UTC
    … …  
    705633   \return Offset in seconds
    706634 */
    707 int QwtDate::utcOffset( const QDateTime &dateTime )
     635int QwtDate::utcOffset( const QDateTime& dateTime )
    708636{
    709637    int seconds = 0;
    … …  
    717645        case Qt::OffsetFromUTC:
    718646        {
     647#if QT_VERSION >= 0x050200
     648            seconds = dateTime.offsetFromUtc();
     649#else
    719650            seconds = dateTime.utcOffset();
     651#endif
    720652            break;
    721653        }
    … …  
    731663
    732664/*!
    733   Translate a datetime into a string
    734 
    735   Beside the format expressions documented in QDateTime::toString()
    736   the following expressions are supported:
    737 
    738   - w\n
     665   Translate a datetime into a string
     666
     667   Beside the format expressions documented in QDateTime::toString()
     668   the following expressions are supported:
     669
     670   - w\n
    739671    week number: ( 1 - 53 )
    740   - ww\n
     672   - ww\n
    741673    week number with a leading zero ( 01 - 53 )
    742674
    743   As week 1 usually starts in the previous year a special rule
    744   is applied for formats, where the year is expected to match the
    745   week number - even if the date belongs to the previous year.
    746 
    747   \param dateTime Datetime value
    748   \param format Format string
    749   \param week0Type Specification of week 0
    750 
    751   \return Datetime string
    752   \sa QDateTime::toString(), weekNumber(), QwtDateScaleDraw
    753  */
    754 QString QwtDate::toString( const QDateTime &dateTime,
    755     const QString & format, Week0Type week0Type )
     675   As week 1 usually starts in the previous year a special rule
     676   is applied for formats, where the year is expected to match the
     677   week number - even if the date belongs to the previous year.
     678
     679   \param dateTime Datetime value
     680   \param format Format string
     681   \param week0Type Specification of week 0
     682
     683   \return Datetime string
     684   \sa QDateTime::toString(), weekNumber(), QwtDateScaleDraw
     685 */
     686QString QwtDate::toString( const QDateTime& dateTime,
     687    const QString& format, Week0Type week0Type )
    756688{
    757689    QString fmt = format;
    … …  
    761693    }
    762694
    763     return dateTime.toString( fmt );
    764 }
     695    return QLocale().toString( dateTime, fmt );
     696}
  • trunk/BNC/qwt/qwt_date.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    88 *****************************************************************************/
    99
    10 #ifndef _QWT_DATE_H_
    11 #define _QWT_DATE_H_
     10#ifndef QWT_DATE_H
     11#define QWT_DATE_H
    1212
    1313#include "qwt_global.h"
    … …  
    1515
    1616/*!
    17   \brief A collection of methods around date/time values
     17   \brief A collection of methods around date/time values
    1818
    19   Qt offers convenient classes for dealing with date/time values,
    20   but Qwt uses coordinate systems that are based on doubles.
    21   QwtDate offers methods to translate from QDateTime to double and v.v.
     19   Qt offers convenient classes for dealing with date/time values,
     20   but Qwt uses coordinate systems that are based on doubles.
     21   QwtDate offers methods to translate from QDateTime to double and v.v.
    2222
    23   A double is interpreted as the number of milliseconds since
    24   1970-01-01T00:00:00 Universal Coordinated Time - also known
    25   as "The Epoch".
     23   A double is interpreted as the number of milliseconds since
     24   1970-01-01T00:00:00 Universal Coordinated Time - also known
     25   as "The Epoch".
    2626
    27   While the range of the Julian day in Qt4 is limited to [0, MAX_INT],
    28   Qt5 stores it as qint64 offering a huge range of valid dates.
    29   As the significance of a double is below this ( assuming a
    30   fraction of 52 bits ) the translation is not
    31   bijective with rounding errors for dates very far from Epoch.
    32   For a resolution of 1 ms those start to happen for dates above the
    33   year 144683.
     27   While the range of the Julian day in Qt4 is limited to [0, MAX_INT],
     28   Qt5 stores it as qint64 offering a huge range of valid dates.
     29   As the significance of a double is below this ( assuming a
     30   fraction of 52 bits ) the translation is not
     31   bijective with rounding errors for dates very far from Epoch.
     32   For a resolution of 1 ms those start to happen for dates above the
     33   year 144683.
    3434
    35   An axis for a date/time interval is expected to be aligned
    36   and divided in time/date units like seconds, minutes, ...
    37   QwtDate offers several algorithms that are needed to
    38   calculate these axes.
     35   An axis for a date/time interval is expected to be aligned
     36   and divided in time/date units like seconds, minutes, ...
     37   QwtDate offers several algorithms that are needed to
     38   calculate these axes.
    3939
    40   \sa QwtDateScaleEngine, QwtDateScaleDraw, QDate, QTime
    41 */
     40   \sa QwtDateScaleEngine, QwtDateScaleDraw, QDate, QTime
     41 */
    4242class QWT_EXPORT QwtDate
    4343{
    44 public:
     44  public:
    4545    /*!
    4646       How to identify the first week of year differs between
    … …  
    5555           FirstThursday corresponds to the numbering that is
    5656           implemented in QDate::weekNumber().
    57         */
     57         */
    5858        FirstThursday,
    5959
    … …  
    6363            In the U.S. this definition is more common than
    6464            FirstThursday.
    65         */
     65         */
    6666        FirstDay
    6767    };
    6868
    6969    /*!
    70       Classification of an time interval
     70       Classification of an time interval
    7171
    72       Time intervals needs to be classified to decide how to
    73       align and divide it.
     72       Time intervals needs to be classified to decide how to
     73       align and divide it.
    7474     */
    7575    enum IntervalType
    … …  
    112112        Qt::TimeSpec = Qt::UTC );
    113113
    114     static double toDouble( const QDateTime & );
     114    static double toDouble( const QDateTime& );
    115115
    116     static QDateTime ceil( const QDateTime &, IntervalType );
    117     static QDateTime floor( const QDateTime &, IntervalType );
     116    static QDateTime ceil( const QDateTime&, IntervalType );
     117    static QDateTime floor( const QDateTime&, IntervalType );
    118118
    119119    static QDate dateOfWeek0( int year, Week0Type );
    120     static int weekNumber( const QDate &, Week0Type );
     120    static int weekNumber( const QDate&, Week0Type );
    121121
    122     static int utcOffset( const QDateTime & );
     122    static int utcOffset( const QDateTime& );
    123123
    124     static QString toString( const QDateTime &,
    125         const QString & format, Week0Type );
     124    static QString toString( const QDateTime&,
     125        const QString& format, Week0Type );
    126126};
    127127
  • trunk/BNC/qwt/qwt_date_scale_draw.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_date_scale_draw.h"
     11#include "qwt_text.h"
    1112
    1213class QwtDateScaleDraw::PrivateData
    1314{
    14 public:
    15     PrivateData( Qt::TimeSpec spec ):
    16         timeSpec( spec ),
    17         utcOffset( 0 ),
    18         week0Type( QwtDate::FirstThursday )
     15  public:
     16    explicit PrivateData( Qt::TimeSpec spec )
     17        : timeSpec( spec )
     18        , utcOffset( 0 )
     19        , week0Type( QwtDate::FirstThursday )
    1920    {
    2021        dateFormats[ QwtDate::Millisecond ] = "hh:mm:ss:zzz\nddd dd MMM yyyy";
    … …  
    3536
    3637/*!
    37   \brief Constructor
    38 
    39   The default setting is to display tick labels for the
    40   given time specification. The first week of a year is defined like
    41   for QwtDate::FirstThursday.
    42 
    43   \param timeSpec Time specification
    44 
    45   \sa setTimeSpec(), setWeek0Type()
     38   \brief Constructor
     39
     40   The default setting is to display tick labels for the
     41   given time specification. The first week of a year is defined like
     42   for QwtDate::FirstThursday.
     43
     44   \param timeSpec Time specification
     45
     46   \sa setTimeSpec(), setWeek0Type()
    4647 */
    4748QwtDateScaleDraw::QwtDateScaleDraw( Qt::TimeSpec timeSpec )
    4849{
    49     d_data = new PrivateData( timeSpec );
     50    m_data = new PrivateData( timeSpec );
    5051}
    5152
    … …  
    5354QwtDateScaleDraw::~QwtDateScaleDraw()
    5455{
    55     delete d_data;
    56 }
    57 
    58 /*!
    59   Set the time specification used for the tick labels
    60 
    61   \param timeSpec Time specification
    62   \sa timeSpec(), setUtcOffset(), toDateTime()
     56    delete m_data;
     57}
     58
     59/*!
     60   Set the time specification used for the tick labels
     61
     62   \param timeSpec Time specification
     63   \sa timeSpec(), setUtcOffset(), toDateTime()
    6364 */
    6465void QwtDateScaleDraw::setTimeSpec( Qt::TimeSpec timeSpec )
    6566{
    66     d_data->timeSpec = timeSpec;
    67 }
    68 
    69 /*!
    70   \return Time specification used for the tick labels
    71   \sa setTimeSpec(), utcOffset(), toDateTime()
     67    m_data->timeSpec = timeSpec;
     68}
     69
     70/*!
     71   \return Time specification used for the tick labels
     72   \sa setTimeSpec(), utcOffset(), toDateTime()
    7273 */
    7374Qt::TimeSpec QwtDateScaleDraw::timeSpec() const
    7475{
    75     return d_data->timeSpec;
    76 }
    77 
    78 /*!
    79   Set the offset in seconds from Coordinated Universal Time
    80 
    81   \param seconds Offset in seconds
    82 
    83   \note The offset has no effect beside for the time specification
     76    return m_data->timeSpec;
     77}
     78
     79/*!
     80   Set the offset in seconds from Coordinated Universal Time
     81
     82   \param seconds Offset in seconds
     83
     84   \note The offset has no effect beside for the time specification
    8485        Qt::OffsetFromUTC.
    8586
    86   \sa QDate::utcOffset(), setTimeSpec(), toDateTime()
     87   \sa QDate::utcOffset(), setTimeSpec(), toDateTime()
    8788 */
    8889void QwtDateScaleDraw::setUtcOffset( int seconds )
    8990{
    90     d_data->utcOffset = seconds;
    91 }
    92 
    93 /*!
    94   \return Offset in seconds from Coordinated Universal Time
    95   \note The offset has no effect beside for the time specification
     91    m_data->utcOffset = seconds;
     92}
     93
     94/*!
     95   \return Offset in seconds from Coordinated Universal Time
     96   \note The offset has no effect beside for the time specification
    9697        Qt::OffsetFromUTC.
    9798
    98   \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime()
     99   \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime()
    99100 */
    100101int QwtDateScaleDraw::utcOffset() const
    101102{
    102     return d_data->utcOffset;
    103 }
    104 
    105 /*!
    106   Sets how to identify the first week of a year.
    107 
    108   \param week0Type Mode how to identify the first week of a year
    109 
    110   \sa week0Type().
    111   \note week0Type has no effect beside for intervals classified as
     103    return m_data->utcOffset;
     104}
     105
     106/*!
     107   Sets how to identify the first week of a year.
     108
     109   \param week0Type Mode how to identify the first week of a year
     110
     111   \sa week0Type().
     112   \note week0Type has no effect beside for intervals classified as
    112113        QwtDate::Week.
    113114 */
    114115void QwtDateScaleDraw::setWeek0Type( QwtDate::Week0Type week0Type )
    115116{
    116     d_data->week0Type = week0Type;
    117 }
    118 
    119 /*!
    120   \return Setting how to identify the first week of a year.
    121   \sa setWeek0Type()
     117    m_data->week0Type = week0Type;
     118}
     119
     120/*!
     121   \return Setting how to identify the first week of a year.
     122   \sa setWeek0Type()
    122123 */
    123124QwtDate::Week0Type QwtDateScaleDraw::week0Type() const
    124125{
    125     return d_data->week0Type;
    126 }
    127 
    128 /*!
    129   Set the default format string for an datetime interval type
    130 
    131   \param intervalType Interval type
    132   \param format Default format string
    133 
    134   \sa dateFormat(), dateFormatOfDate(), QwtDate::toString()
     126    return m_data->week0Type;
     127}
     128
     129/*!
     130   Set the default format string for an datetime interval type
     131
     132   \param intervalType Interval type
     133   \param format Default format string
     134
     135   \sa dateFormat(), dateFormatOfDate(), QwtDate::toString()
    135136 */
    136137void QwtDateScaleDraw::setDateFormat(
    137     QwtDate::IntervalType intervalType, const QString &format )
     138    QwtDate::IntervalType intervalType, const QString& format )
    138139{
    139140    if ( intervalType >= QwtDate::Millisecond &&
    140141        intervalType <= QwtDate::Year )
    141142    {
    142         d_data->dateFormats[ intervalType ] = format;
    143     }
    144 }
    145 
    146 /*!
    147   \param intervalType Interval type
    148   \return Default format string for an datetime interval type
    149   \sa setDateFormat(), dateFormatOfDate()
     143        m_data->dateFormats[ intervalType ] = format;
     144    }
     145}
     146
     147/*!
     148   \param intervalType Interval type
     149   \return Default format string for an datetime interval type
     150   \sa setDateFormat(), dateFormatOfDate()
    150151 */
    151152QString QwtDateScaleDraw::dateFormat(
    … …  
    155156        intervalType <= QwtDate::Year )
    156157    {
    157         return d_data->dateFormats[ intervalType ];
     158        return m_data->dateFormats[ intervalType ];
    158159    }
    159160
    … …  
    162163
    163164/*!
    164   Format string for the representation of a datetime
    165 
    166   dateFormatOfDate() is intended to be overloaded for
    167   situations, where formats are individual for specific
    168   datetime values.
    169 
    170   The default setting ignores dateTime and return
    171   the default format for the interval type.
    172 
    173   \param dateTime Datetime value
    174   \param intervalType Interval type
    175   \return Format string
    176 
    177   \sa setDateFormat(), QwtDate::toString()
    178  */
    179 QString QwtDateScaleDraw::dateFormatOfDate( const QDateTime &dateTime,
     165   Format string for the representation of a datetime
     166
     167   dateFormatOfDate() is intended to be overloaded for
     168   situations, where formats are individual for specific
     169   datetime values.
     170
     171   The default setting ignores dateTime and return
     172   the default format for the interval type.
     173
     174   \param dateTime Datetime value
     175   \param intervalType Interval type
     176   \return Format string
     177
     178   \sa setDateFormat(), QwtDate::toString()
     179 */
     180QString QwtDateScaleDraw::dateFormatOfDate( const QDateTime& dateTime,
    180181    QwtDate::IntervalType intervalType ) const
    181182{
    … …  
    185186        intervalType <= QwtDate::Year )
    186187    {
    187         return d_data->dateFormats[ intervalType ];
    188     }
    189 
    190     return d_data->dateFormats[ QwtDate::Second ];
    191 }
    192 
    193 /*!
    194   \brief Convert a value into its representing label
    195 
    196   The value is converted to a datetime value using toDateTime()
    197   and converted to a plain text using QwtDate::toString().
    198 
    199   \param value Value
    200   \return Label string.
    201 
    202   \sa dateFormatOfDate()
    203 */
     188        return m_data->dateFormats[ intervalType ];
     189    }
     190
     191    return m_data->dateFormats[ QwtDate::Second ];
     192}
     193
     194/*!
     195   \brief Convert a value into its representing label
     196
     197   The value is converted to a datetime value using toDateTime()
     198   and converted to a plain text using QwtDate::toString().
     199
     200   \param value Value
     201   \return Label string.
     202
     203   \sa dateFormatOfDate()
     204 */
    204205QwtText QwtDateScaleDraw::label( double value ) const
    205206{
    … …  
    208209        dt, intervalType( scaleDiv() ) );
    209210
    210     return QwtDate::toString( dt, fmt, d_data->week0Type );
    211 }
    212 
    213 /*!
    214   Find the less detailed datetime unit, where no rounding
    215   errors happen.
    216 
    217   \param scaleDiv Scale division
    218   \return Interval type
    219 
    220   \sa dateFormatOfDate()
     211    return QwtDate::toString( dt, fmt, m_data->week0Type );
     212}
     213
     214/*!
     215   Find the less detailed datetime unit, where no rounding
     216   errors happen.
     217
     218   \param scaleDiv Scale division
     219   \return Interval type
     220
     221   \sa dateFormatOfDate()
    221222 */
    222223QwtDate::IntervalType QwtDateScaleDraw::intervalType(
    223     const QwtScaleDiv &scaleDiv ) const
     224    const QwtScaleDiv& scaleDiv ) const
    224225{
    225226    int intvType = QwtDate::Year;
    … …  
    227228    bool alignedToWeeks = true;
    228229
    229     const QList<double> ticks = scaleDiv.ticks( QwtScaleDiv::MajorTick );
     230    const QList< double > ticks = scaleDiv.ticks( QwtScaleDiv::MajorTick );
    230231    for ( int i = 0; i < ticks.size(); i++ )
    231232    {
    … …  
    234235        {
    235236            const QDateTime dt0 = QwtDate::floor( dt,
    236                 static_cast<QwtDate::IntervalType>( j ) );
     237                static_cast< QwtDate::IntervalType >( j ) );
    237238
    238239            if ( dt0 != dt )
    … …  
    257258        intvType = QwtDate::Day;
    258259
    259     return static_cast<QwtDate::IntervalType>( intvType );
    260 }
    261 
    262 /*!
    263   Translate a double value into a QDateTime object.
    264 
    265   \return QDateTime object initialized with timeSpec() and utcOffset().
    266   \sa timeSpec(), utcOffset(), QwtDate::toDateTime()
     260    return static_cast< QwtDate::IntervalType >( intvType );
     261}
     262
     263/*!
     264   Translate a double value into a QDateTime object.
     265
     266   \return QDateTime object initialized with timeSpec() and utcOffset().
     267   \sa timeSpec(), utcOffset(), QwtDate::toDateTime()
    267268 */
    268269QDateTime QwtDateScaleDraw::toDateTime( double value ) const
    269270{
    270     QDateTime dt = QwtDate::toDateTime( value, d_data->timeSpec );
    271     if ( d_data->timeSpec == Qt::OffsetFromUTC )
    272     {
    273         dt = dt.addSecs( d_data->utcOffset );
    274         dt.setUtcOffset( d_data->utcOffset );
     271    QDateTime dt = QwtDate::toDateTime( value, m_data->timeSpec );
     272    if ( m_data->timeSpec == Qt::OffsetFromUTC )
     273    {
     274        dt = dt.addSecs( m_data->utcOffset );
     275#if QT_VERSION >= 0x050200
     276        dt.setOffsetFromUtc( m_data->utcOffset );
     277#else
     278        dt.setUtcOffset( m_data->utcOffset );
     279#endif
    275280    }
    276281
  • trunk/BNC/qwt/qwt_date_scale_draw.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    88 *****************************************************************************/
    99
    10 #ifndef _QWT_DATE_SCALE_DRAW_H_
    11 #define _QWT_DATE_SCALE_DRAW_H_ 1
     10#ifndef QWT_DATE_SCALE_DRAW_H
     11#define QWT_DATE_SCALE_DRAW_H
    1212
    1313#include "qwt_global.h"
    … …  
    1616
    1717/*!
    18   \brief A class for drawing datetime scales
     18   \brief A class for drawing datetime scales
    1919
    20   QwtDateScaleDraw displays values as datetime labels.
    21   The format of the labels depends on the alignment of
    22   the major tick labels.
     20   QwtDateScaleDraw displays values as datetime labels.
     21   The format of the labels depends on the alignment of
     22   the major tick labels.
    2323
    24   The default format strings are:
     24   The default format strings are:
    2525
    26   - Millisecond\n
     26   - Millisecond\n
    2727    "hh:mm:ss:zzz\nddd dd MMM yyyy"
    28   - Second\n
     28   - Second\n
    2929    "hh:mm:ss\nddd dd MMM yyyy"
    30   - Minute\n
     30   - Minute\n
    3131    "hh:mm\nddd dd MMM yyyy"
    32   - Hour\n
     32   - Hour\n
    3333    "hh:mm\nddd dd MMM yyyy"
    34   - Day\n
     34   - Day\n
    3535    "ddd dd MMM yyyy"
    36   - Week\n
     36   - Week\n
    3737    "Www yyyy"
    38   - Month\n
     38   - Month\n
    3939    "MMM yyyy"
    40   - Year\n
     40   - Year\n
    4141    "yyyy"
    4242
    43   The format strings can be modified using setDateFormat()
    44   or individually for each tick label by overloading dateFormatOfDate(),
     43   The format strings can be modified using setDateFormat()
     44   or individually for each tick label by overloading dateFormatOfDate(),
    4545
    46   Usually QwtDateScaleDraw is used in combination with
    47   QwtDateScaleEngine, that calculates scales for datetime
    48   intervals.
     46   Usually QwtDateScaleDraw is used in combination with
     47   QwtDateScaleEngine, that calculates scales for datetime
     48   intervals.
    4949
    50   \sa QwtDateScaleEngine, QwtPlot::setAxisScaleDraw()
    51 */
    52 class QWT_EXPORT QwtDateScaleDraw: public QwtScaleDraw
     50   \sa QwtDateScaleEngine, QwtPlot::setAxisScaleDraw()
     51 */
     52class QWT_EXPORT QwtDateScaleDraw : public QwtScaleDraw
    5353{
    54 public:
    55     QwtDateScaleDraw( Qt::TimeSpec = Qt::LocalTime );
     54  public:
     55    explicit QwtDateScaleDraw( Qt::TimeSpec = Qt::LocalTime );
    5656    virtual ~QwtDateScaleDraw();
    5757
    58     void setDateFormat( QwtDate::IntervalType, const QString & );
     58    void setDateFormat( QwtDate::IntervalType, const QString& );
    5959    QString dateFormat( QwtDate::IntervalType ) const;
    6060
    … …  
    6868    QwtDate::Week0Type week0Type() const;
    6969
    70     virtual QwtText label( double ) const;
     70    virtual QwtText label( double ) const QWT_OVERRIDE;
    7171
    7272    QDateTime toDateTime( double ) const;
    7373
    74 protected:
     74  protected:
    7575    virtual QwtDate::IntervalType
    76         intervalType( const QwtScaleDiv & ) const;
     76    intervalType( const QwtScaleDiv& ) const;
    7777
    78     virtual QString dateFormatOfDate( const QDateTime &,
     78    virtual QString dateFormatOfDate( const QDateTime&,
    7979        QwtDate::IntervalType ) const;
    8080
    81 private:
     81  private:
    8282    class PrivateData;
    83     PrivateData *d_data;
     83    PrivateData* m_data;
    8484};
    8585
  • trunk/BNC/qwt/qwt_date_scale_engine.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_date_scale_engine.h"
    1111#include "qwt_math.h"
    12 #include "qwt_transform.h"
     12#include "qwt_interval.h"
     13
    1314#include <qdatetime.h>
    14 #include <limits.h>
     15
     16#include <limits>
    1517
    1618static inline double qwtMsecsForType( int type )
    … …  
    2830    };
    2931
    30     if ( type < 0 || type >= static_cast<int>( sizeof( msecs ) / sizeof( msecs[0] ) ) )
     32    if ( type < 0 || type >= static_cast< int >( sizeof( msecs ) / sizeof( msecs[0] ) ) )
    3133        return 1.0;
    3234
    … …  
    3840{
    3941    double d = value / stepSize;
    40     d = up ? ::ceil( d ) : ::floor( d );
    41 
    42     return static_cast<int>( d * stepSize );
    43 }
    44 
    45 static double qwtIntervalWidth( const QDateTime &minDate,
    46     const QDateTime &maxDate, QwtDate::IntervalType intervalType )
     42    d = up ? std::ceil( d ) : std::floor( d );
     43
     44    return static_cast< int >( d * stepSize );
     45}
     46
     47static double qwtIntervalWidth( const QDateTime& minDate,
     48    const QDateTime& maxDate, QwtDate::IntervalType intervalType )
    4749{
    4850    switch( intervalType )
    … …  
    5052        case QwtDate::Millisecond:
    5153        {
     54            return minDate.msecsTo( maxDate );
     55        }
     56        case QwtDate::Second:
     57        {
     58            return minDate.secsTo( maxDate );
     59        }
     60        case QwtDate::Minute:
     61        {
    5262            const double secsTo = minDate.secsTo( maxDate );
    53             const double msecs = maxDate.time().msec() -
    54                 minDate.time().msec();
    55 
    56             return secsTo * 1000 + msecs;
    57         }
    58         case QwtDate::Second:
    59         {
    60             return minDate.secsTo( maxDate );
    61         }
    62         case QwtDate::Minute:
     63            return std::floor( secsTo / 60 );
     64        }
     65        case QwtDate::Hour:
    6366        {
    6467            const double secsTo = minDate.secsTo( maxDate );
    65             return ::floor( secsTo / 60 );
    66         }
    67         case QwtDate::Hour:
    68         {
    69             const double secsTo = minDate.secsTo( maxDate );
    70             return ::floor( secsTo / 3600 );
     68            return std::floor( secsTo / 3600 );
    7169        }
    7270        case QwtDate::Day:
    … …  
    7674        case QwtDate::Week:
    7775        {
    78             return ::floor( minDate.daysTo( maxDate ) / 7.0 );
     76            return std::floor( minDate.daysTo( maxDate ) / 7.0 );
    7977        }
    8078        case QwtDate::Month:
    … …  
    105103
    106104static double qwtRoundedIntervalWidth(
    107     const QDateTime &minDate, const QDateTime &maxDate,
     105    const QDateTime& minDate, const QDateTime& maxDate,
    108106    QwtDate::IntervalType intervalType )
    109107{
    … …  
    142140            const double stepSize = double( intervalSize ) / numSteps;
    143141
    144             const double p = ::floor( ::log( stepSize ) / ::log( double( base ) ) );
    145             const double fraction = qPow( base, p );
     142            const double p = std::floor( std::log( stepSize ) / std::log( double( base ) ) );
     143            const double fraction = std::pow( base, p );
    146144
    147145            for ( uint n = base; n >= 1; n /= 2 )
    … …  
    165163    const int limits[], size_t numLimits )
    166164{
    167     const int v = qCeil( intervalSize / double( numSteps ) );
     165    const int v = qwtCeil( intervalSize / double( numSteps ) );
    168166
    169167    for ( uint i = 0; i < numLimits - 1; i++ )
    … …  
    215213            const double v = intervalSize / double( numSteps );
    216214            if ( v <= 5.0 )
    217                 stepSize = qCeil( v );
     215                stepSize = std::ceil( v );
    218216            else
    219                 stepSize = qCeil( v / 7 ) * 7;
     217                stepSize = std::ceil( v / 7 ) * 7;
    220218
    221219            break;
    … …  
    285283
    286284            if ( numSteps > 0 )
    287                 minStepSize = double( stepSize ) / numSteps;
     285                minStepSize = stepSize / numSteps;
    288286
    289287            break;
    … …  
    309307
    310308            if ( numSteps > 0 )
    311                 minStepSize = double( stepSize ) / numSteps;
     309                minStepSize = stepSize / numSteps;
    312310
    313311            break;
    … …  
    333331
    334332            if ( numSteps > 0 )
    335                 minStepSize = double( stepSize ) / numSteps;
     333                minStepSize = stepSize / numSteps;
    336334
    337335            break;
    … …  
    370368
    371369            if ( stepSize < maxMinSteps )
    372                 maxMinSteps = static_cast<int>( stepSize );
     370                maxMinSteps = static_cast< int >( stepSize );
    373371
    374372            static int limits[] = { 1, 2, 3, 4, 6, 12 };
    … …  
    378376
    379377            if ( numSteps > 0 )
    380                 minStepSize = double( stepSize ) / numSteps;
     378                minStepSize = stepSize / numSteps;
    381379
    382380            break;
    … …  
    399397
    400398                if ( numSteps > 0 )
    401                     minStepSize = double( stepSize ) / numSteps;
     399                    minStepSize = stepSize / numSteps;
    402400            }
    403401
    … …  
    417415}
    418416
    419 static QList<double> qwtDstTicks( const QDateTime &dateTime,
     417static QList< double > qwtDstTicks( const QDateTime& dateTime,
    420418    int secondsMajor, int secondsMinor )
    421419{
    422420    if ( secondsMinor <= 0 )
    423         QList<double>();
     421        return QList< double >();
    424422
    425423    QDateTime minDate = dateTime.addSecs( -secondsMajor );
    … …  
    438436    }
    439437
    440     QList<double> ticks;
     438    QList< double > ticks;
     439    ticks.reserve( 3600 / secondsMinor);
     440
    441441    for ( int i = 0; i < 3600; i += secondsMinor )
    442442        ticks += dstMin + i * 1000.0;
    … …  
    446446
    447447static QwtScaleDiv qwtDivideToSeconds(
    448     const QDateTime &minDate, const QDateTime &maxDate,
     448    const QDateTime& minDate, const QDateTime& maxDate,
    449449    double stepSize, int maxMinSteps,
    450450    QwtDate::IntervalType intervalType )
    … …  
    470470
    471471    const double s = qwtMsecsForType( intervalType ) / 1000;
    472     const int secondsMajor = static_cast<int>( stepSize * s );
     472    const int secondsMajor = static_cast< int >( stepSize * s );
    473473    const double secondsMinor = minStepSize * s;
    474474
    … …  
    480480    double dstOff = 0;
    481481
    482     QList<double> majorTicks;
    483     QList<double> mediumTicks;
    484     QList<double> minorTicks;
     482    QList< double > majorTicks;
     483    QList< double > mediumTicks;
     484    QList< double > minorTicks;
    485485
    486486    for ( QDateTime dt = minDate; dt <= maxDate;
    … …  
    513513        if ( secondsMinor > 0.0 )
    514514        {
    515             const int numMinorSteps = qFloor( secondsMajor / secondsMinor );
     515            const int numMinorSteps = qwtFloor( secondsMajor / secondsMinor );
    516516
    517517            for ( int i = 1; i < numMinorSteps; i++ )
    … …  
    554554
    555555static QwtScaleDiv qwtDivideToMonths(
    556     QDateTime &minDate, const QDateTime &maxDate,
     556    QDateTime& minDate, const QDateTime& maxDate,
    557557    double stepSize, int maxMinSteps )
    558558{
    … …  
    584584    }
    585585
    586     QList<double> majorTicks;
    587     QList<double> mediumTicks;
    588     QList<double> minorTicks;
     586    QList< double > majorTicks;
     587    QList< double > mediumTicks;
     588    QList< double > minorTicks;
    589589
    590590    for ( QDateTime dt = minDate;
    … …  
    638638
    639639static QwtScaleDiv qwtDivideToYears(
    640     const QDateTime &minDate, const QDateTime &maxDate,
     640    const QDateTime& minDate, const QDateTime& maxDate,
    641641    double stepSize, int maxMinSteps )
    642642{
    643     QList<double> majorTicks;
    644     QList<double> mediumTicks;
    645     QList<double> minorTicks;
     643    QList< double > majorTicks;
     644    QList< double > mediumTicks;
     645    QList< double > minorTicks;
    646646
    647647    double minStepSize = 0.0;
    … …  
    655655    int numMinorSteps = 0;
    656656    if ( minStepSize > 0.0 )
    657         numMinorSteps = qFloor( stepSize / minStepSize );
     657        numMinorSteps = qwtFloor( stepSize / minStepSize );
    658658
    659659    bool dateBC = minDate.date().year() < -1;
    … …  
    679679
    680680            const double years = qRound( i * minStepSize );
    681             if ( years >= INT_MAX / 12 )
     681            if ( years >= std::numeric_limits< int >::max() / 12 )
    682682            {
    683683                tickDate = dt.addYears( years );
    … …  
    717717class QwtDateScaleEngine::PrivateData
    718718{
    719 public:
    720     PrivateData( Qt::TimeSpec spec ):
    721         timeSpec( spec ),
    722         utcOffset( 0 ),
    723         week0Type( QwtDate::FirstThursday ),
    724         maxWeeks( 4 )
     719  public:
     720    explicit PrivateData( Qt::TimeSpec spec )
     721        : timeSpec( spec )
     722        , utcOffset( 0 )
     723        , week0Type( QwtDate::FirstThursday )
     724        , maxWeeks( 4 )
    725725    {
    726726    }
    … …  
    734734
    735735/*!
    736   \brief Constructor
    737 
    738   The engine is initialized to build scales for the
    739   given time specification. It classifies intervals > 4 weeks
    740   as >= Qt::Month. The first week of a year is defined like
    741   for QwtDate::FirstThursday.
    742 
    743   \param timeSpec Time specification
    744 
    745   \sa setTimeSpec(), setMaxWeeks(), setWeek0Type()
     736   \brief Constructor
     737
     738   The engine is initialized to build scales for the
     739   given time specification. It classifies intervals > 4 weeks
     740   as >= Qt::Month. The first week of a year is defined like
     741   for QwtDate::FirstThursday.
     742
     743   \param timeSpec Time specification
     744
     745   \sa setTimeSpec(), setMaxWeeks(), setWeek0Type()
    746746 */
    747 QwtDateScaleEngine::QwtDateScaleEngine( Qt::TimeSpec timeSpec ):
    748     QwtLinearScaleEngine( 10 )
    749 {
    750     d_data = new PrivateData( timeSpec );
     747QwtDateScaleEngine::QwtDateScaleEngine( Qt::TimeSpec timeSpec )
     748    : QwtLinearScaleEngine( 10 )
     749{
     750    m_data = new PrivateData( timeSpec );
    751751}
    752752
    … …  
    754754QwtDateScaleEngine::~QwtDateScaleEngine()
    755755{
    756     delete d_data;
     756    delete m_data;
    757757}
    758758
    759759/*!
    760   Set the time specification used by the engine
    761 
    762   \param timeSpec Time specification
    763   \sa timeSpec(), setUtcOffset(), toDateTime()
     760   Set the time specification used by the engine
     761
     762   \param timeSpec Time specification
     763   \sa timeSpec(), setUtcOffset(), toDateTime()
    764764 */
    765765void QwtDateScaleEngine::setTimeSpec( Qt::TimeSpec timeSpec )
    766766{
    767     d_data->timeSpec = timeSpec;
     767    m_data->timeSpec = timeSpec;
    768768}
    769769
    770770/*!
    771   \return Time specification used by the engine
    772   \sa setTimeSpec(), utcOffset(), toDateTime()
     771   \return Time specification used by the engine
     772   \sa setTimeSpec(), utcOffset(), toDateTime()
    773773 */
    774774Qt::TimeSpec QwtDateScaleEngine::timeSpec() const
    775775{
    776     return d_data->timeSpec;
     776    return m_data->timeSpec;
    777777}
    778778
    779779/*!
    780   Set the offset in seconds from Coordinated Universal Time
    781 
    782   \param seconds Offset in seconds
    783 
    784   \note The offset has no effect beside for the time specification
     780   Set the offset in seconds from Coordinated Universal Time
     781
     782   \param seconds Offset in seconds
     783
     784   \note The offset has no effect beside for the time specification
    785785        Qt::OffsetFromUTC.
    786786
    787   \sa QDate::utcOffset(), setTimeSpec(), toDateTime()
     787   \sa QDate::utcOffset(), setTimeSpec(), toDateTime()
    788788 */
    789789void QwtDateScaleEngine::setUtcOffset( int seconds )
    790790{
    791     d_data->utcOffset = seconds;
     791    m_data->utcOffset = seconds;
    792792}
    793793
    794794/*!
    795   \return Offset in seconds from Coordinated Universal Time
    796   \note The offset has no effect beside for the time specification
     795   \return Offset in seconds from Coordinated Universal Time
     796   \note The offset has no effect beside for the time specification
    797797        Qt::OffsetFromUTC.
    798798
    799   \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime()
     799   \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime()
    800800 */
    801801int QwtDateScaleEngine::utcOffset() const
    802802{
    803     return d_data->utcOffset;
     803    return m_data->utcOffset;
    804804}
    805805
    806806/*!
    807   Sets how to identify the first week of a year.
    808 
    809   \param week0Type Mode how to identify the first week of a year
    810 
    811   \sa week0Type(), setMaxWeeks()
    812   \note week0Type has no effect beside for intervals classified as
     807   Sets how to identify the first week of a year.
     808
     809   \param week0Type Mode how to identify the first week of a year
     810
     811   \sa week0Type(), setMaxWeeks()
     812   \note week0Type has no effect beside for intervals classified as
    813813        QwtDate::Week.
    814814 */
    815815void QwtDateScaleEngine::setWeek0Type( QwtDate::Week0Type week0Type )
    816816{
    817     d_data->week0Type = week0Type;
     817    m_data->week0Type = week0Type;
    818818}
    819819
    820820/*!
    821   \return Setting how to identify the first week of a year.
    822   \sa setWeek0Type(), maxWeeks()
     821   \return Setting how to identify the first week of a year.
     822   \sa setWeek0Type(), maxWeeks()
    823823 */
    824824QwtDate::Week0Type QwtDateScaleEngine::week0Type() const
    825825{
    826     return d_data->week0Type;
     826    return m_data->week0Type;
    827827}
    828828
    829829/*!
    830   Set a upper limit for the number of weeks, when an interval
    831   can be classified as Qt::Week.
    832 
    833   The default setting is 4 weeks.
    834 
    835   \param weeks Upper limit for the number of weeks
    836 
    837   \note In business charts a year is often divided
     830   Set a upper limit for the number of weeks, when an interval
     831   can be classified as Qt::Week.
     832
     833   The default setting is 4 weeks.
     834
     835   \param weeks Upper limit for the number of weeks
     836
     837   \note In business charts a year is often divided
    838838        into weeks [1-52]
    839   \sa maxWeeks(), setWeek0Type()
     839   \sa maxWeeks(), setWeek0Type()
    840840 */
    841841void QwtDateScaleEngine::setMaxWeeks( int weeks )
    842842{
    843     d_data->maxWeeks = qMax( weeks, 0 );
     843    m_data->maxWeeks = qMax( weeks, 0 );
    844844}
    845845
    846846/*!
    847   \return Upper limit for the number of weeks, when an interval
     847   \return Upper limit for the number of weeks, when an interval
    848848          can be classified as Qt::Week.
    849   \sa setMaxWeeks(), week0Type()
     849   \sa setMaxWeeks(), week0Type()
    850850 */
    851851int QwtDateScaleEngine::maxWeeks() const
    852852{
    853     return d_data->maxWeeks;
     853    return m_data->maxWeeks;
    854854}
    855855
    856856/*!
    857   Classification of a date/time interval division
    858 
    859   \param minDate Minimum ( = earlier ) of the interval
    860   \param maxDate Maximum ( = later ) of the interval
    861   \param maxSteps Maximum for the number of steps
    862 
    863   \return Interval classification
     857   Classification of a date/time interval division
     858
     859   \param minDate Minimum ( = earlier ) of the interval
     860   \param maxDate Maximum ( = later ) of the interval
     861   \param maxSteps Maximum for the number of steps
     862
     863   \return Interval classification
    864864 */
    865865QwtDate::IntervalType QwtDateScaleEngine::intervalType(
    866     const QDateTime &minDate, const QDateTime &maxDate,
     866    const QDateTime& minDate, const QDateTime& maxDate,
    867867    int maxSteps ) const
    868868{
    … …  
    880880    const int weeks = qwtRoundedIntervalWidth( minDate, maxDate, QwtDate::Week );
    881881
    882     if ( weeks > d_data->maxWeeks )
     882    if ( weeks > m_data->maxWeeks )
    883883    {
    884884        if ( days > 4 * maxSteps * 7 )
    … …  
    908908
    909909/*!
    910   Align and divide an interval
    911 
    912   The algorithm aligns and divides the interval into steps.
    913 
    914   Datetime interval divisions are usually not equidistant and the
    915   calculated stepSize can only be used as an approximation
    916   for the steps calculated by divideScale().
    917 
    918   \param maxNumSteps Max. number of steps
    919   \param x1 First limit of the interval (In/Out)
    920   \param x2 Second limit of the interval (In/Out)
    921   \param stepSize Step size (Out)
    922 
    923   \sa QwtScaleEngine::setAttribute()
    924 */
     910   Align and divide an interval
     911
     912   The algorithm aligns and divides the interval into steps.
     913
     914   Datetime interval divisions are usually not equidistant and the
     915   calculated stepSize can only be used as an approximation
     916   for the steps calculated by divideScale().
     917
     918   \param maxNumSteps Max. number of steps
     919   \param x1 First limit of the interval (In/Out)
     920   \param x2 Second limit of the interval (In/Out)
     921   \param stepSize Step size (Out)
     922
     923   \sa QwtScaleEngine::setAttribute()
     924 */
    925925void QwtDateScaleEngine::autoScale( int maxNumSteps,
    926     double &x1, double &x2, double &stepSize ) const
     926    double& x1, double& x2, double& stepSize ) const
    927927{
    928928    stepSize = 0.0;
    … …  
    989989                   calculates one.
    990990   \return Calculated scale division
    991 */
     991 */
    992992QwtScaleDiv QwtDateScaleEngine::divideScale( double x1, double x2,
    993993    int maxMajorSteps, int maxMinorSteps, double stepSize ) const
    … …  
    996996        maxMajorSteps = 1;
    997997
    998     const double min = qMin( x1, x2 );
    999     const double max = qMax( x1, x2 );
     998    const double min = qwtMinF( x1, x2 );
     999    const double max = qwtMaxF( x1, x2 );
    10001000
    10011001    const QDateTime from = toDateTime( min );
    … …  
    10121012        // the stepSize is used as a hint only
    10131013
    1014         maxMajorSteps = qCeil( ( max - min ) / stepSize );
     1014        maxMajorSteps = qwtCeil( ( max - min ) / stepSize );
    10151015    }
    10161016
    … …  
    10471047
    10481048QwtScaleDiv QwtDateScaleEngine::buildScaleDiv(
    1049     const QDateTime &minDate, const QDateTime &maxDate,
     1049    const QDateTime& minDate, const QDateTime& maxDate,
    10501050    int maxMajorSteps, int maxMinorSteps,
    10511051    QwtDate::IntervalType intervalType ) const
    … …  
    10911091
    10921092/*!
    1093   Align a date/time value for a step size
    1094 
    1095   For Qt::Day alignments there is no "natural day 0" -
    1096   instead the first day of the year is used to avoid jumping
    1097   major ticks positions when panning a scale. For other alignments
    1098   ( f.e according to the first day of the month ) alignDate()
    1099   has to be overloaded.
    1100 
    1101   \param dateTime Date/time value
    1102   \param stepSize Step size
    1103   \param intervalType Interval type
    1104   \param up When true dateTime is ceiled - otherwise it is floored
    1105 
    1106   \return Aligned date/time value
     1093   Align a date/time value for a step size
     1094
     1095   For Qt::Day alignments there is no "natural day 0" -
     1096   instead the first day of the year is used to avoid jumping
     1097   major ticks positions when panning a scale. For other alignments
     1098   ( f.e according to the first day of the month ) alignDate()
     1099   has to be overloaded.
     1100
     1101   \param dateTime Date/time value
     1102   \param stepSize Step size
     1103   \param intervalType Interval type
     1104   \param up When true dateTime is ceiled - otherwise it is floored
     1105
     1106   \return Aligned date/time value
    11071107 */
    11081108QDateTime QwtDateScaleEngine::alignDate(
    1109     const QDateTime &dateTime, double stepSize,
     1109    const QDateTime& dateTime, double stepSize,
    11101110    QwtDate::IntervalType intervalType, bool up ) const
    11111111{
    … …  
    11161116    if ( dateTime.timeSpec() == Qt::OffsetFromUTC )
    11171117    {
     1118#if QT_VERSION >= 0x050200
     1119        dt.setOffsetFromUtc( 0 );
     1120#else
    11181121        dt.setUtcOffset( 0 );
     1122#endif
    11191123    }
    11201124
    … …  
    11241128        {
    11251129            const int ms = qwtAlignValue(
    1126                 dt.time().msec(), stepSize, up ) ;
     1130                dt.time().msec(), stepSize, up );
    11271131
    11281132            dt = QwtDate::floor( dateTime, QwtDate::Second );
    … …  
    12041208        {
    12051209            const QDate date = QwtDate::dateOfWeek0(
    1206                 dt.date().year(), d_data->week0Type );
     1210                dt.date().year(), m_data->week0Type );
    12071211
    12081212            int numWeeks = date.daysTo( dt.date() ) / 7;
    … …  
    12741278    if ( dateTime.timeSpec() == Qt::OffsetFromUTC )
    12751279    {
     1280#if QT_VERSION >= 0x050200
     1281        dt.setOffsetFromUtc( dateTime.offsetFromUtc() );
     1282#else
    12761283        dt.setUtcOffset( dateTime.utcOffset() );
     1284#endif
    12771285    }
    12781286
    … …  
    12811289
    12821290/*!
    1283   Translate a double value into a QDateTime object.
    1284 
    1285   For QDateTime result is bounded by QwtDate::minDate() and QwtDate::maxDate()
    1286 
    1287   \return QDateTime object initialized with timeSpec() and utcOffset().
    1288   \sa timeSpec(), utcOffset(), QwtDate::toDateTime()
     1291   Translate a double value into a QDateTime object.
     1292
     1293   For QDateTime result is bounded by QwtDate::minDate() and QwtDate::maxDate()
     1294
     1295   \return QDateTime object initialized with timeSpec() and utcOffset().
     1296   \sa timeSpec(), utcOffset(), QwtDate::toDateTime()
    12891297 */
    12901298QDateTime QwtDateScaleEngine::toDateTime( double value ) const
    12911299{
    1292     QDateTime dt = QwtDate::toDateTime( value, d_data->timeSpec );
     1300    QDateTime dt = QwtDate::toDateTime( value, m_data->timeSpec );
    12931301    if ( !dt.isValid() )
    12941302    {
    … …  
    12961304            ? QwtDate::minDate() : QwtDate::maxDate();
    12971305
    1298         dt = QDateTime( date, QTime( 0, 0 ), d_data->timeSpec );
    1299     }
    1300 
    1301     if ( d_data->timeSpec == Qt::OffsetFromUTC )
    1302     {
    1303         dt = dt.addSecs( d_data->utcOffset );
    1304         dt.setUtcOffset( d_data->utcOffset );
     1306        dt = QDateTime( date, QTime( 0, 0 ), m_data->timeSpec );
     1307    }
     1308
     1309    if ( m_data->timeSpec == Qt::OffsetFromUTC )
     1310    {
     1311        dt = dt.addSecs( m_data->utcOffset );
     1312#if QT_VERSION >= 0x050200
     1313        dt.setOffsetFromUtc( m_data->utcOffset );
     1314#else
     1315        dt.setUtcOffset( m_data->utcOffset );
     1316#endif
    13051317    }
    13061318
  • trunk/BNC/qwt/qwt_date_scale_engine.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    88 *****************************************************************************/
    99
    10 #ifndef _QWT_DATE_SCALE_ENGINE_H_
    11 #define _QWT_DATE_SCALE_ENGINE_H_ 1
     10#ifndef QWT_DATE_SCALE_ENGINE_H
     11#define QWT_DATE_SCALE_ENGINE_H
    1212
     13#include "qwt_global.h"
    1314#include "qwt_date.h"
    1415#include "qwt_scale_engine.h"
    1516
    1617/*!
    17   \brief A scale engine for date/time values
     18   \brief A scale engine for date/time values
    1819
    19   QwtDateScaleEngine builds scales from a time intervals.
    20   Together with QwtDateScaleDraw it can be used for
    21   axes according to date/time values.
     20   QwtDateScaleEngine builds scales from a time intervals.
     21   Together with QwtDateScaleDraw it can be used for
     22   axes according to date/time values.
    2223
    23   Years, months, weeks, days, hours and minutes are organized
    24   in steps with non constant intervals. QwtDateScaleEngine
    25   classifies intervals and aligns the boundaries and tick positions
    26   according to this classification.
     24   Years, months, weeks, days, hours and minutes are organized
     25   in steps with non constant intervals. QwtDateScaleEngine
     26   classifies intervals and aligns the boundaries and tick positions
     27   according to this classification.
    2728
    28   QwtDateScaleEngine supports representations depending
    29   on Qt::TimeSpec specifications. The valid range for scales
    30   is limited by the range of QDateTime, that differs
    31   between Qt4 and Qt5.
     29   QwtDateScaleEngine supports representations depending
     30   on Qt::TimeSpec specifications. The valid range for scales
     31   is limited by the range of QDateTime, that differs
     32   between Qt4 and Qt5.
    3233
    33   Datetime values are expected as the number of milliseconds since
    34   1970-01-01T00:00:00 Universal Coordinated Time - also known
    35   as "The Epoch", that can be converted to QDateTime using
    36   QwtDate::toDateTime().
     34   Datetime values are expected as the number of milliseconds since
     35   1970-01-01T00:00:00 Universal Coordinated Time - also known
     36   as "The Epoch", that can be converted to QDateTime using
     37   QwtDate::toDateTime().
    3738
    38   \sa QwtDate, QwtPlot::setAxisScaleEngine(),
     39   \sa QwtDate, QwtPlot::setAxisScaleEngine(),
    3940      QwtAbstractScale::setScaleEngine()
    40 */
    41 class QWT_EXPORT QwtDateScaleEngine: public QwtLinearScaleEngine
     41 */
     42class QWT_EXPORT QwtDateScaleEngine : public QwtLinearScaleEngine
    4243{
    43 public:
    44     QwtDateScaleEngine( Qt::TimeSpec = Qt::LocalTime );
     44  public:
     45    explicit QwtDateScaleEngine( Qt::TimeSpec = Qt::LocalTime );
    4546    virtual ~QwtDateScaleEngine();
    4647
    … …  
    5758    int maxWeeks() const;
    5859
    59     virtual void autoScale( int maxNumSteps,
    60         double &x1, double &x2, double &stepSize ) const;
     60    virtual void autoScale(
     61        int maxNumSteps, double& x1, double& x2,
     62        double& stepSize ) const QWT_OVERRIDE;
    6163
    6264    virtual QwtScaleDiv divideScale(
    6365        double x1, double x2,
    6466        int maxMajorSteps, int maxMinorSteps,
    65         double stepSize = 0.0 ) const;
     67        double stepSize = 0.0 ) const QWT_OVERRIDE;
    6668
    6769    virtual QwtDate::IntervalType intervalType(
    68         const QDateTime &, const QDateTime &, int maxSteps ) const;
     70        const QDateTime&, const QDateTime&, int maxSteps ) const;
    6971
    7072    QDateTime toDateTime( double ) const;
    7173
    72 protected:
    73     virtual QDateTime alignDate( const QDateTime &, double stepSize,
     74  protected:
     75    virtual QDateTime alignDate( const QDateTime&, double stepSize,
    7476        QwtDate::IntervalType, bool up ) const;
    7577
    76 private:
    77     QwtScaleDiv buildScaleDiv( const QDateTime &, const QDateTime &,
     78  private:
     79    QwtScaleDiv buildScaleDiv( const QDateTime&, const QDateTime&,
    7880        int maxMajorSteps, int maxMinorSteps,
    7981        QwtDate::IntervalType ) const;
    8082
    81 private:
     83  private:
    8284    class PrivateData;
    83     PrivateData *d_data;
     85    PrivateData* m_data;
    8486};
    8587
  • trunk/BNC/qwt/qwt_dial.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_dial_needle.h"
    1212#include "qwt_math.h"
    13 #include "qwt_scale_engine.h"
    1413#include "qwt_scale_map.h"
    1514#include "qwt_round_scale_draw.h"
    1615#include "qwt_painter.h"
     16#include "qwt.h"
     17
    1718#include <qpainter.h>
    1819#include <qpalette.h>
    1920#include <qpixmap.h>
    2021#include <qevent.h>
    21 #include <qalgorithms.h>
    22 #include <qmath.h>
    2322#include <qstyle.h>
    2423#include <qstyleoption.h>
    25 #include <qapplication.h>
    2624
    2725static inline double qwtAngleDist( double a1, double a2 )
    … …  
    7775class QwtDial::PrivateData
    7876{
    79 public:
    80     PrivateData():
    81         frameShadow( Sunken ),
    82         lineWidth( 0 ),
    83         mode( RotateNeedle ),
    84         origin( 90.0 ),
    85         minScaleArc( 0.0 ),
    86         maxScaleArc( 0.0 ),
    87         needle( NULL ),
    88         arcOffset( 0.0 ),
    89         mouseOffset( 0.0 )
     77  public:
     78    PrivateData()
     79        : frameShadow( Sunken )
     80        , lineWidth( 0 )
     81        , mode( RotateNeedle )
     82        , origin( 90.0 )
     83        , minScaleArc( 0.0 )
     84        , maxScaleArc( 0.0 )
     85        , needle( NULL )
     86        , arcOffset( 0.0 )
     87        , mouseOffset( 0.0 )
    9088    {
    9189    }
    … …  
    104102    double maxScaleArc;
    105103
    106     QwtDialNeedle *needle;
     104    QwtDialNeedle* needle;
    107105
    108106    double arcOffset;
    … …  
    113111
    114112/*!
    115   \brief Constructor
    116   \param parent Parent widget
    117 
    118   Create a dial widget with no needle. The scale is initialized
    119   to [ 0.0, 360.0 ] and 360 steps ( QwtAbstractSlider::setTotalSteps() ).
    120   The origin of the scale is at 90°,
    121 
    122   The value is set to 0.0.
    123 
    124   The default mode is QwtDial::RotateNeedle.
    125 */
    126 QwtDial::QwtDial( QWidget* parent ):
    127     QwtAbstractSlider( parent )
    128 {
    129     d_data = new PrivateData;
     113   \brief Constructor
     114   \param parent Parent widget
     115
     116   Create a dial widget with no needle. The scale is initialized
     117   to [ 0.0, 360.0 ] and 360 steps ( QwtAbstractSlider::setTotalSteps() ).
     118   The origin of the scale is at 90°,
     119
     120   The value is set to 0.0.
     121
     122   The default mode is QwtDial::RotateNeedle.
     123 */
     124QwtDial::QwtDial( QWidget* parent )
     125    : QwtAbstractSlider( parent )
     126{
     127    m_data = new PrivateData;
    130128
    131129    setFocusPolicy( Qt::TabFocus );
    … …  
    135133    {
    136134        const QPalette::ColorGroup colorGroup =
    137             static_cast<QPalette::ColorGroup>( i );
     135            static_cast< QPalette::ColorGroup >( i );
    138136
    139137        // Base: background color of the circle inside the frame.
    … …  
    161159QwtDial::~QwtDial()
    162160{
    163     delete d_data;
    164 }
    165 
    166 /*!
    167   Sets the frame shadow value from the frame style.
    168 
    169   \param shadow Frame shadow
    170   \sa setLineWidth(), QFrame::setFrameShadow()
    171 */
     161    delete m_data;
     162}
     163
     164/*!
     165   Sets the frame shadow value from the frame style.
     166
     167   \param shadow Frame shadow
     168   \sa setLineWidth(), QFrame::setFrameShadow()
     169 */
    172170void QwtDial::setFrameShadow( Shadow shadow )
    173171{
    174     if ( shadow != d_data->frameShadow )
     172    if ( shadow != m_data->frameShadow )
    175173    {
    176174        invalidateCache();
    177175
    178         d_data->frameShadow = shadow;
     176        m_data->frameShadow = shadow;
    179177        if ( lineWidth() > 0 )
    180178            update();
    … …  
    183181
    184182/*!
    185   \return Frame shadow
    186   /sa setFrameShadow(), lineWidth(), QFrame::frameShadow()
    187 */
     183   \return Frame shadow
     184   /sa setFrameShadow(), lineWidth(), QFrame::frameShadow()
     185 */
    188186QwtDial::Shadow QwtDial::frameShadow() const
    189187{
    190     return d_data->frameShadow;
    191 }
    192 
    193 /*!
    194   Sets the line width of the frame
    195 
    196   \param lineWidth Line width
    197   \sa setFrameShadow()
    198 */
     188    return m_data->frameShadow;
     189}
     190
     191/*!
     192   Sets the line width of the frame
     193
     194   \param lineWidth Line width
     195   \sa setFrameShadow()
     196 */
    199197void QwtDial::setLineWidth( int lineWidth )
    200198{
    … …  
    202200        lineWidth = 0;
    203201
    204     if ( d_data->lineWidth != lineWidth )
     202    if ( m_data->lineWidth != lineWidth )
    205203    {
    206204        invalidateCache();
    207205
    208         d_data->lineWidth = lineWidth;
     206        m_data->lineWidth = lineWidth;
    209207        update();
    210208    }
    … …  
    212210
    213211/*!
    214   \return Line width of the frame
    215   \sa setLineWidth(), frameShadow(), lineWidth()
    216 */
     212   \return Line width of the frame
     213   \sa setLineWidth(), frameShadow(), lineWidth()
     214 */
    217215int QwtDial::lineWidth() const
    218216{
    219     return d_data->lineWidth;
    220 }
    221 
    222 /*!
    223   \return bounding rectangle of the circle inside the frame
    224   \sa setLineWidth(), scaleInnerRect(), boundingRect()
    225 */
     217    return m_data->lineWidth;
     218}
     219
     220/*!
     221   \return bounding rectangle of the circle inside the frame
     222   \sa setLineWidth(), scaleInnerRect(), boundingRect()
     223 */
    226224QRect QwtDial::innerRect() const
    227225{
    … …  
    231229
    232230/*!
    233   \return bounding rectangle of the dial including the frame
    234   \sa setLineWidth(), scaleInnerRect(), innerRect()
    235 */
     231   \return bounding rectangle of the dial including the frame
     232   \sa setLineWidth(), scaleInnerRect(), innerRect()
     233 */
    236234QRect QwtDial::boundingRect() const
    237235{
    … …  
    247245
    248246/*!
    249   \return rectangle inside the scale
    250   \sa setLineWidth(), boundingRect(), innerRect()
    251 */
     247   \return rectangle inside the scale
     248   \sa setLineWidth(), boundingRect(), innerRect()
     249 */
    252250QRect QwtDial::scaleInnerRect() const
    253251{
    254252    QRect rect = innerRect();
    255253
    256     const QwtAbstractScaleDraw *sd = scaleDraw();
     254    const QwtAbstractScaleDraw* sd = scaleDraw();
    257255    if ( sd )
    258256    {
    259         int scaleDist = qCeil( sd->extent( font() ) );
     257        int scaleDist = qwtCeil( sd->extent( font() ) );
    260258        scaleDist++; // margin
    261259
    … …  
    267265
    268266/*!
    269   \brief Change the mode of the dial.
    270   \param mode New mode
    271 
    272   In case of QwtDial::RotateNeedle the needle is rotating, in case of
    273   QwtDial::RotateScale, the needle points to origin()
    274   and the scale is rotating.
    275 
    276   The default mode is QwtDial::RotateNeedle.
    277 
    278   \sa mode(), setValue(), setOrigin()
    279 */
     267   \brief Change the mode of the dial.
     268   \param mode New mode
     269
     270   In case of QwtDial::RotateNeedle the needle is rotating, in case of
     271   QwtDial::RotateScale, the needle points to origin()
     272   and the scale is rotating.
     273
     274   The default mode is QwtDial::RotateNeedle.
     275
     276   \sa mode(), setValue(), setOrigin()
     277 */
    280278void QwtDial::setMode( Mode mode )
    281279{
    282     if ( mode != d_data->mode )
     280    if ( mode != m_data->mode )
    283281    {
    284282        invalidateCache();
    285283
    286         d_data->mode = mode;
     284        m_data->mode = mode;
    287285        sliderChange();
    288286    }
    … …  
    290288
    291289/*!
    292   \return Mode of the dial.
    293   \sa setMode(), origin(), setScaleArc(), value()
    294 */
     290   \return Mode of the dial.
     291   \sa setMode(), origin(), setScaleArc(), value()
     292 */
    295293QwtDial::Mode QwtDial::mode() const
    296294{
    297     return d_data->mode;
    298 }
    299 
    300 /*!
    301   Invalidate the internal caches used to speed up repainting
     295    return m_data->mode;
     296}
     297
     298/*!
     299   Invalidate the internal caches used to speed up repainting
    302300 */
    303301void QwtDial::invalidateCache()
    304302{
    305     d_data->pixmapCache = QPixmap();
     303    m_data->pixmapCache = QPixmap();
    306304}
    307305
    … …  
    309307   Paint the dial
    310308   \param event Paint event
    311 */
    312 void QwtDial::paintEvent( QPaintEvent *event )
     309 */
     310void QwtDial::paintEvent( QPaintEvent* event )
    313311{
    314312    QPainter painter( this );
    … …  
    316314
    317315    QStyleOption opt;
    318     opt.init(this);
     316    opt.initFrom(this);
    319317    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
    320318
    321     if ( d_data->mode == QwtDial::RotateScale )
     319    if ( m_data->mode == QwtDial::RotateScale )
    322320    {
    323321        painter.save();
    … …  
    330328
    331329    const QRect r = contentsRect();
    332     if ( r.size() != d_data->pixmapCache.size() )
    333     {
    334         d_data->pixmapCache = QwtPainter::backingStore( this, r.size() );
    335         d_data->pixmapCache.fill( Qt::transparent );
    336 
    337         QPainter p( &d_data->pixmapCache );
     330    if ( r.size() != m_data->pixmapCache.size() )
     331    {
     332        m_data->pixmapCache = QwtPainter::backingStore( this, r.size() );
     333        m_data->pixmapCache.fill( Qt::transparent );
     334
     335        QPainter p( &m_data->pixmapCache );
    338336        p.setRenderHint( QPainter::Antialiasing, true );
    339337        p.translate( -r.topLeft() );
    340338
    341         if ( d_data->mode != QwtDial::RotateScale )
     339        if ( m_data->mode != QwtDial::RotateScale )
    342340            drawContents( &p );
    343341
    … …  
    345343            drawFrame( &p );
    346344
    347         if ( d_data->mode != QwtDial::RotateNeedle )
     345        if ( m_data->mode != QwtDial::RotateNeedle )
    348346            drawNeedle( &p );
    349347    }
    350348
    351     painter.drawPixmap( r.topLeft(), d_data->pixmapCache );
    352 
    353     if ( d_data->mode == QwtDial::RotateNeedle )
     349    painter.drawPixmap( r.topLeft(), m_data->pixmapCache );
     350
     351    if ( m_data->mode == QwtDial::RotateNeedle )
    354352        drawNeedle( &painter );
    355353
    … …  
    359357
    360358/*!
    361   Draw the focus indicator
    362   \param painter Painter
    363 */
    364 void QwtDial::drawFocusIndicator( QPainter *painter ) const
     359   Draw the focus indicator
     360   \param painter Painter
     361 */
     362void QwtDial::drawFocusIndicator( QPainter* painter ) const
    365363{
    366364    QwtPainter::drawFocusRect( painter, this, boundingRect() );
    … …  
    368366
    369367/*!
    370   Draw the frame around the dial
    371 
    372   \param painter Painter
    373   \sa lineWidth(), frameShadow()
    374 */
    375 void QwtDial::drawFrame( QPainter *painter )
     368   Draw the frame around the dial
     369
     370   \param painter Painter
     371   \sa lineWidth(), frameShadow()
     372 */
     373void QwtDial::drawFrame( QPainter* painter )
    376374{
    377375    QwtPainter::drawRoundFrame( painter, boundingRect(),
    378         palette(), lineWidth(), d_data->frameShadow );
    379 }
    380 
    381 /*!
    382   \brief Draw the contents inside the frame
    383 
    384   QPalette::Window is the background color outside of the frame.
    385   QPalette::Base is the background color inside the frame.
    386   QPalette::WindowText is the background color inside the scale.
    387 
    388   \param painter Painter
    389 
    390   \sa boundingRect(), innerRect(),
     376        palette(), lineWidth(), m_data->frameShadow );
     377}
     378
     379/*!
     380   \brief Draw the contents inside the frame
     381
     382   QPalette::Window is the background color outside of the frame.
     383   QPalette::Base is the background color inside the frame.
     384   QPalette::WindowText is the background color inside the scale.
     385
     386   \param painter Painter
     387
     388   \sa boundingRect(), innerRect(),
    391389    scaleInnerRect(), QWidget::setPalette()
    392 */
    393 void QwtDial::drawContents( QPainter *painter ) const
     390 */
     391void QwtDial::drawContents( QPainter* painter ) const
    394392{
    395393    if ( testAttribute( Qt::WA_NoSystemBackground ) ||
    396394        palette().brush( QPalette::Base ) !=
    397             palette().brush( QPalette::Window ) )
     395        palette().brush( QPalette::Window ) )
    398396    {
    399397        const QRectF br = boundingRect();
    … …  
    408406    const QRectF insideScaleRect = scaleInnerRect();
    409407    if ( palette().brush( QPalette::WindowText ) !=
    410             palette().brush( QPalette::Base ) )
     408        palette().brush( QPalette::Base ) )
    411409    {
    412410        painter->save();
    … …  
    430428
    431429/*!
    432   Draw the needle
    433 
    434   \param painter Painter
    435   \param center Center of the dial
    436   \param radius Length for the needle
    437   \param direction Direction of the needle in degrees, counter clockwise
    438   \param colorGroup ColorGroup
    439 */
    440 void QwtDial::drawNeedle( QPainter *painter, const QPointF &center,
     430   Draw the needle
     431
     432   \param painter Painter
     433   \param center Center of the dial
     434   \param radius Length for the needle
     435   \param direction Direction of the needle in degrees, counter clockwise
     436   \param colorGroup ColorGroup
     437 */
     438void QwtDial::drawNeedle( QPainter* painter, const QPointF& center,
    441439    double radius, double direction, QPalette::ColorGroup colorGroup ) const
    442440{
    443     if ( d_data->needle )
     441    if ( m_data->needle )
    444442    {
    445443        direction = 360.0 - direction; // counter clockwise
    446         d_data->needle->draw( painter, center, radius, direction, colorGroup );
    447     }
    448 }
    449 
    450 void QwtDial::drawNeedle( QPainter *painter ) const
     444        m_data->needle->draw( painter, center, radius, direction, colorGroup );
     445    }
     446}
     447
     448void QwtDial::drawNeedle( QPainter* painter ) const
    451449{
    452450    if ( !isValid() )
    … …  
    469467
    470468/*!
    471   Draw the scale
    472 
    473   \param painter Painter
    474   \param center Center of the dial
    475   \param radius Radius of the scale
    476 */
    477 void QwtDial::drawScale( QPainter *painter,
    478     const QPointF &center, double radius ) const
    479 {
    480     QwtRoundScaleDraw *sd = const_cast<QwtRoundScaleDraw *>( scaleDraw() );
     469   Draw the scale
     470
     471   \param painter Painter
     472   \param center Center of the dial
     473   \param radius Radius of the scale
     474 */
     475void QwtDial::drawScale( QPainter* painter,
     476    const QPointF& center, double radius ) const
     477{
     478    QwtRoundScaleDraw* sd = const_cast< QwtRoundScaleDraw* >( scaleDraw() );
    481479    if ( sd == NULL )
    482480        return;
    … …  
    491489
    492490    painter->setFont( font() );
    493     painter->setPen( QPen( textColor, sd->penWidth() ) );
     491    painter->setPen( QPen( textColor, sd->penWidthF() ) );
    494492
    495493    painter->setBrush( Qt::red );
    … …  
    498496
    499497/*!
    500   Draw the contents inside the scale
    501 
    502   Paints nothing.
    503 
    504   \param painter Painter
    505   \param center Center of the contents circle
    506   \param radius Radius of the contents circle
    507 */
    508 void QwtDial::drawScaleContents( QPainter *painter,
    509     const QPointF &center, double radius ) const
     498   Draw the contents inside the scale
     499
     500   Paints nothing.
     501
     502   \param painter Painter
     503   \param center Center of the contents circle
     504   \param radius Radius of the contents circle
     505 */
     506void QwtDial::drawScaleContents( QPainter* painter,
     507    const QPointF& center, double radius ) const
    510508{
    511509    Q_UNUSED(painter);
    … …  
    515513
    516514/*!
    517   Set a needle for the dial
    518 
    519   \param needle Needle
    520 
    521   \warning The needle will be deleted, when a different needle is
     515   Set a needle for the dial
     516
     517   \param needle Needle
     518
     519   \warning The needle will be deleted, when a different needle is
    522520           set or in ~QwtDial()
    523 */
    524 void QwtDial::setNeedle( QwtDialNeedle *needle )
    525 {
    526     if ( needle != d_data->needle )
    527     {
    528         if ( d_data->needle )
    529             delete d_data->needle;
    530 
    531         d_data->needle = needle;
     521 */
     522void QwtDial::setNeedle( QwtDialNeedle* needle )
     523{
     524    if ( needle != m_data->needle )
     525    {
     526        if ( m_data->needle )
     527            delete m_data->needle;
     528
     529        m_data->needle = needle;
    532530        update();
    533531    }
    … …  
    535533
    536534/*!
    537   \return needle
    538   \sa setNeedle()
    539 */
    540 const QwtDialNeedle *QwtDial::needle() const
    541 {
    542     return d_data->needle;
    543 }
    544 
    545 /*!
    546   \return needle
    547   \sa setNeedle()
    548 */
    549 QwtDialNeedle *QwtDial::needle()
    550 {
    551     return d_data->needle;
     535   \return needle
     536   \sa setNeedle()
     537 */
     538const QwtDialNeedle* QwtDial::needle() const
     539{
     540    return m_data->needle;
     541}
     542
     543/*!
     544   \return needle
     545   \sa setNeedle()
     546 */
     547QwtDialNeedle* QwtDial::needle()
     548{
     549    return m_data->needle;
    552550}
    553551
    554552//! \return the scale draw
    555 QwtRoundScaleDraw *QwtDial::scaleDraw()
    556 {
    557     return static_cast<QwtRoundScaleDraw *>( abstractScaleDraw() );
     553QwtRoundScaleDraw* QwtDial::scaleDraw()
     554{
     555    return static_cast< QwtRoundScaleDraw* >( abstractScaleDraw() );
    558556}
    559557
    560558//! \return the scale draw
    561 const QwtRoundScaleDraw *QwtDial::scaleDraw() const
    562 {
    563     return static_cast<const QwtRoundScaleDraw *>( abstractScaleDraw() );
    564 }
    565 
    566 /*!
    567   Set an individual scale draw
    568 
    569   The motivation for setting a scale draw is often
    570   to overload QwtRoundScaleDraw::label() to return
    571   individual tick labels.
    572 
    573   \param scaleDraw Scale draw
    574   \warning The previous scale draw is deleted
    575 */
    576 void QwtDial::setScaleDraw( QwtRoundScaleDraw *scaleDraw )
     559const QwtRoundScaleDraw* QwtDial::scaleDraw() const
     560{
     561    return static_cast< const QwtRoundScaleDraw* >( abstractScaleDraw() );
     562}
     563
     564/*!
     565   Set an individual scale draw
     566
     567   The motivation for setting a scale draw is often
     568   to overload QwtRoundScaleDraw::label() to return
     569   individual tick labels.
     570
     571   \param scaleDraw Scale draw
     572   \warning The previous scale draw is deleted
     573 */
     574void QwtDial::setScaleDraw( QwtRoundScaleDraw* scaleDraw )
    577575{
    578576    setAbstractScaleDraw( scaleDraw );
    … …  
    581579
    582580/*!
    583   Change the arc of the scale
    584 
    585   \param minArc Lower limit
    586   \param maxArc Upper limit
    587 
    588   \sa minScaleArc(), maxScaleArc()
    589 */
     581   Change the arc of the scale
     582
     583   \param minArc Lower limit
     584   \param maxArc Upper limit
     585
     586   \sa minScaleArc(), maxScaleArc()
     587 */
    590588void QwtDial::setScaleArc( double minArc, double maxArc )
    591589{
    592590    if ( minArc != 360.0 && minArc != -360.0 )
    593         minArc = ::fmod( minArc, 360.0 );
     591        minArc = std::fmod( minArc, 360.0 );
    594592    if ( maxArc != 360.0 && maxArc != -360.0 )
    595         maxArc = ::fmod( maxArc, 360.0 );
    596 
    597     double minScaleArc = qMin( minArc, maxArc );
    598     double maxScaleArc = qMax( minArc, maxArc );
     593        maxArc = std::fmod( maxArc, 360.0 );
     594
     595    double minScaleArc = qwtMinF( minArc, maxArc );
     596    double maxScaleArc = qwtMaxF( minArc, maxArc );
    599597
    600598    if ( maxScaleArc - minScaleArc > 360.0 )
    601599        maxScaleArc = minScaleArc + 360.0;
    602600
    603     if ( ( minScaleArc != d_data->minScaleArc ) ||
    604         ( maxScaleArc != d_data->maxScaleArc ) )
    605     {
    606         d_data->minScaleArc = minScaleArc;
    607         d_data->maxScaleArc = maxScaleArc;
     601    if ( ( minScaleArc != m_data->minScaleArc ) ||
     602        ( maxScaleArc != m_data->maxScaleArc ) )
     603    {
     604        m_data->minScaleArc = minScaleArc;
     605        m_data->maxScaleArc = maxScaleArc;
    608606
    609607        invalidateCache();
    … …  
    613611
    614612/*!
    615   Set the lower limit for the scale arc
    616 
    617   \param min Lower limit of the scale arc
    618   \sa setScaleArc(), setMaxScaleArc()
     613   Set the lower limit for the scale arc
     614
     615   \param min Lower limit of the scale arc
     616   \sa setScaleArc(), setMaxScaleArc()
    619617 */
    620618void QwtDial::setMinScaleArc( double min )
    621619{
    622     setScaleArc( min, d_data->maxScaleArc );
    623 }
    624 
    625 /*!
    626   \return Lower limit of the scale arc
    627   \sa setScaleArc()
    628 */
     620    setScaleArc( min, m_data->maxScaleArc );
     621}
     622
     623/*!
     624   \return Lower limit of the scale arc
     625   \sa setScaleArc()
     626 */
    629627double QwtDial::minScaleArc() const
    630628{
    631     return d_data->minScaleArc;
    632 }
    633 
    634 /*!
    635   Set the upper limit for the scale arc
    636 
    637   \param max Upper limit of the scale arc
    638   \sa setScaleArc(), setMinScaleArc()
     629    return m_data->minScaleArc;
     630}
     631
     632/*!
     633   Set the upper limit for the scale arc
     634
     635   \param max Upper limit of the scale arc
     636   \sa setScaleArc(), setMinScaleArc()
    639637 */
    640638void QwtDial::setMaxScaleArc( double max )
    641639{
    642     setScaleArc( d_data->minScaleArc, max );
    643 }
    644 
    645 /*!
    646   \return Upper limit of the scale arc
    647   \sa setScaleArc()
    648 */
     640    setScaleArc( m_data->minScaleArc, max );
     641}
     642
     643/*!
     644   \return Upper limit of the scale arc
     645   \sa setScaleArc()
     646 */
    649647double QwtDial::maxScaleArc() const
    650648{
    651     return d_data->maxScaleArc;
    652 }
    653 
    654 /*!
    655   \brief Change the origin
    656 
    657   The origin is the angle where scale and needle is relative to.
    658 
    659   \param origin New origin
    660   \sa origin()
    661 */
     649    return m_data->maxScaleArc;
     650}
     651
     652/*!
     653   \brief Change the origin
     654
     655   The origin is the angle where scale and needle is relative to.
     656
     657   \param origin New origin
     658   \sa origin()
     659 */
    662660void QwtDial::setOrigin( double origin )
    663661{
    664662    invalidateCache();
    665663
    666     d_data->origin = origin;
     664    m_data->origin = origin;
    667665    sliderChange();
    668666}
    669667
    670668/*!
    671   The origin is the angle where scale and needle is relative to.
    672 
    673   \return Origin of the dial
    674   \sa setOrigin()
    675 */
     669   The origin is the angle where scale and needle is relative to.
     670
     671   \return Origin of the dial
     672   \sa setOrigin()
     673 */
    676674double QwtDial::origin() const
    677675{
    678     return d_data->origin;
    679 }
    680 
    681 /*!
    682   \return Size hint
    683   \sa minimumSizeHint()
    684 */
     676    return m_data->origin;
     677}
     678
     679/*!
     680   \return Size hint
     681   \sa minimumSizeHint()
     682 */
    685683QSize QwtDial::sizeHint() const
    686684{
    687685    int sh = 0;
    688686    if ( scaleDraw() )
    689         sh = qCeil( scaleDraw()->extent( font() ) );
     687        sh = qwtCeil( scaleDraw()->extent( font() ) );
    690688
    691689    const int d = 6 * sh + 2 * lineWidth();
    … …  
    693691    QSize hint( d, d );
    694692    if ( !isReadOnly() )
    695         hint = hint.expandedTo( QApplication::globalStrut() );
     693        hint = qwtExpandedToGlobalStrut( hint );
    696694
    697695    return hint;
    … …  
    699697
    700698/*!
    701   \return Minimum size hint
    702   \sa sizeHint()
    703 */
     699   \return Minimum size hint
     700   \sa sizeHint()
     701 */
    704702QSize QwtDial::minimumSizeHint() const
    705703{
    706704    int sh = 0;
    707705    if ( scaleDraw() )
    708         sh = qCeil( scaleDraw()->extent( font() ) );
     706        sh = qwtCeil( scaleDraw()->extent( font() ) );
    709707
    710708    const int d = 3 * sh + 2 * lineWidth();
    … …  
    714712
    715713/*!
    716   \brief Determine what to do when the user presses a mouse button.
    717 
    718   \param pos Mouse position
    719 
    720   \retval True, when the inner circle contains pos
    721   \sa scrolledTo()
    722 */
    723 bool QwtDial::isScrollPosition( const QPoint &pos ) const
     714   \brief Determine what to do when the user presses a mouse button.
     715
     716   \param pos Mouse position
     717
     718   \retval True, when the inner circle contains pos
     719   \sa scrolledTo()
     720 */
     721bool QwtDial::isScrollPosition( const QPoint& pos ) const
    724722{
    725723    const QRegion region( innerRect(), QRegion::Ellipse );
    … …  
    727725    {
    728726        double angle = QLineF( rect().center(), pos ).angle();
    729         if ( d_data->mode == QwtDial::RotateScale )
     727        if ( m_data->mode == QwtDial::RotateScale )
    730728            angle = 360.0 - angle;
    731729
    … …  
    733731            qwtNormalizeDegrees( 90.0 - scaleMap().transform( value() ) );
    734732
    735         d_data->mouseOffset = qwtNormalizeDegrees( angle - valueAngle );
    736         d_data->arcOffset = scaleMap().p1();
     733        m_data->mouseOffset = qwtNormalizeDegrees( angle - valueAngle );
     734        m_data->arcOffset = scaleMap().p1();
    737735
    738736        return true;
    … …  
    743741
    744742/*!
    745   \brief Determine the value for a new position of the
     743   \brief Determine the value for a new position of the
    746744         slider handle.
    747745
    748   \param pos Mouse position
    749 
    750   \return Value for the mouse position
    751   \sa isScrollPosition()
    752 */
    753 double QwtDial::scrolledTo( const QPoint &pos ) const
     746   \param pos Mouse position
     747
     748   \return Value for the mouse position
     749   \sa isScrollPosition()
     750 */
     751double QwtDial::scrolledTo( const QPoint& pos ) const
    754752{
    755753    double angle = QLineF( rect().center(), pos ).angle();
    756     if ( d_data->mode == QwtDial::RotateScale )
    757     {
    758         angle += scaleMap().p1() - d_data->arcOffset;
     754    if ( m_data->mode == QwtDial::RotateScale )
     755    {
     756        angle += scaleMap().p1() - m_data->arcOffset;
    759757        angle = 360.0 - angle;
    760758    }
    761759
    762     angle = qwtNormalizeDegrees( angle - d_data->mouseOffset );
     760    angle = qwtNormalizeDegrees( angle - m_data->mouseOffset );
    763761    angle = qwtNormalizeDegrees( 90.0 - angle );
    764762
    … …  
    779777            }
    780778
    781             d_data->mouseOffset += ( boundedAngle - angle );
     779            m_data->mouseOffset += ( boundedAngle - angle );
    782780
    783781            angle = boundedAngle;
    … …  
    790788
    791789        if ( !wrapping() )
    792             d_data->mouseOffset += ( boundedAngle - angle );
     790            m_data->mouseOffset += ( boundedAngle - angle );
    793791
    794792        angle = boundedAngle;
    … …  
    799797
    800798/*!
    801   Change Event handler
    802   \param event Change event
    803 
    804   Invalidates internal paint caches if necessary
    805 */
    806 void QwtDial::changeEvent( QEvent *event )
     799   Change Event handler
     800   \param event Change event
     801
     802   Invalidates internal paint caches if necessary
     803 */
     804void QwtDial::changeEvent( QEvent* event )
    807805{
    808806    switch( event->type() )
    … …  
    826824
    827825/*!
    828   Wheel Event handler
    829   \param event Wheel event
    830 */
    831 void QwtDial::wheelEvent( QWheelEvent *event )
    832 {
     826   Wheel Event handler
     827   \param event Wheel event
     828 */
     829void QwtDial::wheelEvent( QWheelEvent* event )
     830{
     831#if QT_VERSION < 0x050e00
     832    const QPoint wheelPos = event->pos();
     833#else
     834    const QPoint wheelPos = event->position().toPoint();
     835#endif
     836
    833837    const QRegion region( innerRect(), QRegion::Ellipse );
    834     if ( region.contains( event->pos() ) )
     838    if ( region.contains( wheelPos ) )
    835839        QwtAbstractSlider::wheelEvent( event );
    836840}
    … …  
    838842void QwtDial::setAngleRange( double angle, double span )
    839843{
    840     QwtRoundScaleDraw *sd = const_cast<QwtRoundScaleDraw *>( scaleDraw() );
    841     if ( sd  )
     844    if ( QwtRoundScaleDraw* sd = scaleDraw() )
    842845    {
    843846        angle = qwtNormalizeDegrees( angle - 270.0 );
    … …  
    847850
    848851/*!
    849   Invalidate the internal caches and call
    850   QwtAbstractSlider::scaleChange()
     852   Invalidate the internal caches and call
     853   QwtAbstractSlider::scaleChange()
    851854 */
    852855void QwtDial::scaleChange()
    … …  
    858861void QwtDial::sliderChange()
    859862{
    860     setAngleRange( d_data->origin + d_data->minScaleArc,
    861         d_data->maxScaleArc - d_data->minScaleArc );
     863    setAngleRange( m_data->origin + m_data->minScaleArc,
     864        m_data->maxScaleArc - m_data->minScaleArc );
    862865
    863866    if ( mode() == RotateScale )
    864867    {
    865868        const double arc = scaleMap().transform( value() ) - scaleMap().p1();
    866         setAngleRange( d_data->origin - arc,
    867             d_data->maxScaleArc - d_data->minScaleArc );
     869        setAngleRange( m_data->origin - arc,
     870            m_data->maxScaleArc - m_data->minScaleArc );
    868871    }
    869872
    870873    QwtAbstractSlider::sliderChange();
    871874}
     875
     876#include "moc_qwt_dial.cpp"
  • trunk/BNC/qwt/qwt_dial.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_DIAL_H
    11 #define QWT_DIAL_H 1
     11#define QWT_DIAL_H
    1212
    1313#include "qwt_global.h"
    1414#include "qwt_abstract_slider.h"
    15 #include "qwt_abstract_scale_draw.h"
     15
    1616#include <qframe.h>
    1717#include <qpalette.h>
    … …  
    1919class QwtDialNeedle;
    2020class QwtRoundScaleDraw;
     21class QwtAbstractScaleDraw;
    2122
    2223/*!
    23   \brief QwtDial class provides a rounded range control.
     24   \brief QwtDial class provides a rounded range control.
    2425
    25   QwtDial is intended as base class for dial widgets like
    26   speedometers, compass widgets, clocks ...
     26   QwtDial is intended as base class for dial widgets like
     27   speedometers, compass widgets, clocks ...
    2728
    28   \image html dials2.png
     29   \image html dials2.png
    2930
    30   A dial contains a scale and a needle indicating the current value
    31   of the dial. Depending on Mode one of them is fixed and the
    32   other is rotating. If not isReadOnly() the
    33   dial can be rotated by dragging the mouse or using keyboard inputs
    34   (see QwtAbstractSlider::keyPressEvent()). A dial might be wrapping, what means
    35   a rotation below/above one limit continues on the other limit (f.e compass).
    36   The scale might cover any arc of the dial, its values are related to
    37   the origin() of the dial.
     31   A dial contains a scale and a needle indicating the current value
     32   of the dial. Depending on Mode one of them is fixed and the
     33   other is rotating. If not isReadOnly() the
     34   dial can be rotated by dragging the mouse or using keyboard inputs
     35   (see QwtAbstractSlider::keyPressEvent()). A dial might be wrapping, what means
     36   a rotation below/above one limit continues on the other limit (f.e compass).
     37   The scale might cover any arc of the dial, its values are related to
     38   the origin() of the dial.
    3839
    39   Often dials have to be updated very often according to values from external
    40   devices. For these high refresh rates QwtDial caches as much as possible.
    41   For derived classes it might be necessary to clear these caches manually
    42   according to attribute changes using invalidateCache().
     40   Often dials have to be updated very often according to values from external
     41   devices. For these high refresh rates QwtDial caches as much as possible.
     42   For derived classes it might be necessary to clear these caches manually
     43   according to attribute changes using invalidateCache().
    4344
    44   \sa QwtCompass, QwtAnalogClock, QwtDialNeedle
    45   \note The controls and dials examples shows different types of dials.
    46   \note QDial is more similar to QwtKnob than to QwtDial
    47 */
     45   \sa QwtCompass, QwtAnalogClock, QwtDialNeedle
     46   \note The controls and dials examples shows different types of dials.
     47   \note QDial is more similar to QwtKnob than to QwtDial
     48 */
    4849
    49 class QWT_EXPORT QwtDial: public QwtAbstractSlider
     50class QWT_EXPORT QwtDial : public QwtAbstractSlider
    5051{
    5152    Q_OBJECT
    … …  
    6061    Q_PROPERTY( double maxScaleArc READ maxScaleArc WRITE setMaxScaleArc )
    6162
    62 public:
     63  public:
    6364
    6465    /*!
    … …  
    9293    };
    9394
    94     explicit QwtDial( QWidget *parent = NULL );
     95    explicit QwtDial( QWidget* parent = NULL );
    9596    virtual ~QwtDial();
    9697
    … …  
    115116    double origin() const;
    116117
    117     void setNeedle( QwtDialNeedle * );
    118     const QwtDialNeedle *needle() const;
    119     QwtDialNeedle *needle();
     118    void setNeedle( QwtDialNeedle* );
     119    const QwtDialNeedle* needle() const;
     120    QwtDialNeedle* needle();
    120121
    121122    QRect boundingRect() const;
    … …  
    124125    virtual QRect scaleInnerRect() const;
    125126
    126     virtual QSize sizeHint() const;
    127     virtual QSize minimumSizeHint() const;
     127    virtual QSize sizeHint() const QWT_OVERRIDE;
     128    virtual QSize minimumSizeHint() const QWT_OVERRIDE;
    128129
    129     void setScaleDraw( QwtRoundScaleDraw * );
     130    void setScaleDraw( QwtRoundScaleDraw* );
    130131
    131     QwtRoundScaleDraw *scaleDraw();
    132     const QwtRoundScaleDraw *scaleDraw() const;
     132    QwtRoundScaleDraw* scaleDraw();
     133    const QwtRoundScaleDraw* scaleDraw() const;
    133134
    134 protected:
    135     virtual void wheelEvent( QWheelEvent * );
    136     virtual void paintEvent( QPaintEvent * );
    137     virtual void changeEvent( QEvent * );
     135  protected:
     136    virtual void wheelEvent( QWheelEvent* ) QWT_OVERRIDE;
     137    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
     138    virtual void changeEvent( QEvent* ) QWT_OVERRIDE;
    138139
    139     virtual void drawFrame( QPainter * );
    140     virtual void drawContents( QPainter * ) const;
    141     virtual void drawFocusIndicator( QPainter * ) const;
     140    virtual void drawFrame( QPainter* );
     141    virtual void drawContents( QPainter* ) const;
     142    virtual void drawFocusIndicator( QPainter* ) const;
    142143
    143144    void invalidateCache();
    144145
    145     virtual void drawScale( QPainter *,
    146         const QPointF &center, double radius ) const;
     146    virtual void drawScale( QPainter*,
     147        const QPointF& center, double radius ) const;
    147148
    148     virtual void drawScaleContents( QPainter *painter,
    149         const QPointF &center, double radius ) const;
     149    virtual void drawScaleContents( QPainter* painter,
     150        const QPointF& center, double radius ) const;
    150151
    151     virtual void drawNeedle( QPainter *, const QPointF &,
     152    virtual void drawNeedle( QPainter*, const QPointF&,
    152153        double radius, double direction, QPalette::ColorGroup ) const;
    153154
    154     virtual double scrolledTo( const QPoint & ) const;
    155     virtual bool isScrollPosition( const QPoint & ) const;
     155    virtual double scrolledTo( const QPoint& ) const QWT_OVERRIDE;
     156    virtual bool isScrollPosition( const QPoint& ) const QWT_OVERRIDE;
    156157
    157     virtual void sliderChange();
    158     virtual void scaleChange();
     158    virtual void sliderChange() QWT_OVERRIDE;
     159    virtual void scaleChange() QWT_OVERRIDE;
    159160
    160 private:
     161  private:
    161162    void setAngleRange( double angle, double span );
    162     void drawNeedle( QPainter * ) const;
     163    void drawNeedle( QPainter* ) const;
    163164
    164165    class PrivateData;
    165     PrivateData *d_data;
     166    PrivateData* m_data;
    166167};
    167168
  • trunk/BNC/qwt/qwt_dial_needle.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_dial_needle.h"
    11 #include "qwt_global.h"
    1211#include "qwt_math.h"
    13 #include "qwt_painter.h"
     12
    1413#include <qapplication.h>
    1514#include <qpainter.h>
    1615#include <qpainterpath.h>
    17 
    18 #if QT_VERSION < 0x040601
    19 #define qFastSin(x) qSin(x)
    20 #define qFastCos(x) qCos(x)
    21 #endif
    22 
    23 static void qwtDrawStyle1Needle( QPainter *painter,
    24     const QPalette &palette, QPalette::ColorGroup colorGroup,
    25     double length )
    26 {
    27     const double r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 };
    28     const double a[] = { -45, -20, -15, 0, 15, 20, 45 };
     16#include <qmath.h>
     17
     18static void qwtDrawStyle1Needle( QPainter* painter,
     19    const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length )
     20{
     21    const qreal r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 };
     22    const qreal a[] = { -45, -20, -15, 0, 15, 20, 45 };
    2923
    3024    QPainterPath path;
    3125    for ( int i = 0; i < 7; i++ )
    3226    {
    33         const double angle = a[i] / 180.0 * M_PI;
    34         const double radius = r[i] * length;
    35 
    36         const double x = radius * qFastCos( angle );
    37         const double y = radius * qFastSin( angle );
     27        const qreal angle = a[i] / 180.0 * M_PI;
     28        const qreal radius = r[i] * length;
     29
     30        const qreal x = radius * qFastCos( angle );
     31        const qreal y = radius * qFastSin( angle );
    3832
    3933        path.lineTo( x, -y );
    … …  
    4539}
    4640
    47 static void qwtDrawStyle2Needle( QPainter *painter,
    48     const QPalette &palette, QPalette::ColorGroup colorGroup, double length )
    49 {
    50     const double ratioX = 0.7;
    51     const double ratioY = 0.3;
     41static void qwtDrawStyle2Needle( QPainter* painter,
     42    const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length )
     43{
     44    const qreal ratioX = 0.7;
     45    const qreal ratioY = 0.3;
    5246
    5347    QPainterPath path1;
    … …  
    6862}
    6963
    70 static void qwtDrawShadedPointer( QPainter *painter,
    71     const QColor &lightColor, const QColor &darkColor,
    72     double length, double width )
    73 {
    74     const double peak = qMax( length / 10.0, 5.0 );
    75 
    76     const double knobWidth = width + 8;
     64static void qwtDrawShadedPointer( QPainter* painter,
     65    const QColor& lightColor, const QColor& darkColor,
     66    qreal length, qreal width )
     67{
     68    const qreal peak = qwtMaxF( length / 10.0, 5.0 );
     69
     70    const qreal knobWidth = width + 8;
    7771    QRectF knobRect( 0, 0, knobWidth, knobWidth );
    7872    knobRect.moveCenter( QPointF(0, 0) );
    … …  
    109103}
    110104
    111 static void qwtDrawArrowNeedle( QPainter *painter,
    112     const QPalette &palette, QPalette::ColorGroup colorGroup,
    113     double length, double width )
     105static void qwtDrawArrowNeedle( QPainter* painter,
     106    const QPalette& palette, QPalette::ColorGroup colorGroup,
     107    qreal length, qreal width )
    114108{
    115109    if ( width <= 0 )
    116         width = qMax( length * 0.06, 9.0 );
    117 
    118     const double peak = qMax( 2.0, 0.4 * width );
     110        width = qwtMaxF( length * 0.06, 9.0 );
     111
     112    const qreal peak = qwtMaxF( 2.0, 0.4 * width );
    119113
    120114    QPainterPath path;
    … …  
    146140}
    147141
    148 static void qwtDrawTriangleNeedle( QPainter *painter,
    149     const QPalette &palette, QPalette::ColorGroup colorGroup,
    150     double length )
    151 {
    152     const double width = qRound( length / 3.0 );
     142static void qwtDrawTriangleNeedle( QPainter* painter,
     143    const QPalette& palette, QPalette::ColorGroup colorGroup, qreal length )
     144{
     145    const qreal width = qRound( length / 3.0 );
    153146
    154147    QPainterPath path[4];
    … …  
    167160
    168161
    169     const int colorOffset =  10;
     162    const int colorOffset = 10;
    170163    const QColor darkColor = palette.color( colorGroup, QPalette::Dark );
    171164    const QColor lightColor = palette.color( colorGroup, QPalette::Light );
    … …  
    187180
    188181//! Constructor
    189 QwtDialNeedle::QwtDialNeedle():
    190     d_palette( QApplication::palette() )
     182QwtDialNeedle::QwtDialNeedle()
     183    : m_palette( QApplication::palette() )
    191184{
    192185}
    … …  
    201194
    202195    \param palette New Palette
    203 */
    204 void QwtDialNeedle::setPalette( const QPalette &palette )
    205 {
    206     d_palette = palette;
    207 }
    208 
    209 /*!
    210   \return the palette of the needle.
    211 */
    212 const QPalette &QwtDialNeedle::palette() const
    213 {
    214     return d_palette;
    215 }
    216 
    217 /*!
    218   Draw the needle
    219 
    220   \param painter Painter
    221   \param center Center of the dial, start position for the needle
    222   \param length Length of the needle
    223   \param direction Direction of the needle, in degrees counter clockwise
    224   \param colorGroup Color group, used for painting
    225 */
    226 void QwtDialNeedle::draw( QPainter *painter,
    227     const QPointF &center, double length, double direction,
     196 */
     197void QwtDialNeedle::setPalette( const QPalette& palette )
     198{
     199    m_palette = palette;
     200}
     201
     202/*!
     203   \return the palette of the needle.
     204 */
     205const QPalette& QwtDialNeedle::palette() const
     206{
     207    return m_palette;
     208}
     209
     210/*!
     211   Draw the needle
     212
     213   \param painter Painter
     214   \param center Center of the dial, start position for the needle
     215   \param length Length of the needle
     216   \param direction Direction of the needle, in degrees counter clockwise
     217   \param colorGroup Color group, used for painting
     218 */
     219void QwtDialNeedle::draw( QPainter* painter,
     220    const QPointF& center, double length, double direction,
    228221    QPalette::ColorGroup colorGroup ) const
    229222{
    … …  
    239232
    240233//!  Draw the knob
    241 void QwtDialNeedle::drawKnob( QPainter *painter,
    242     double width, const QBrush &brush, bool sunken ) const
     234void QwtDialNeedle::drawKnob( QPainter* painter,
     235    double width, const QBrush& brush, bool sunken ) const
    243236{
    244237    QPalette palette( brush.color() );
    … …  
    251244
    252245    QRectF rect( 0.0, 0.0, width, width );
    253     rect.moveCenter( painter->combinedTransform().map( QPointF() ) );
     246    rect.moveCenter( painter->transform().map( QPointF() ) );
    254247
    255248    QLinearGradient gradient( rect.topLeft(), rect.bottomRight() );
    … …  
    271264
    272265/*!
    273   Constructor
    274 
    275   \param style Style
    276   \param hasKnob With/Without knob
    277   \param mid Middle color
    278   \param base Base color
    279 */
     266   Constructor
     267
     268   \param style Style
     269   \param hasKnob With/Without knob
     270   \param mid Middle color
     271   \param base Base color
     272 */
    280273QwtDialSimpleNeedle::QwtDialSimpleNeedle( Style style, bool hasKnob,
    281         const QColor &mid, const QColor &base ):
    282     d_style( style ),
    283     d_hasKnob( hasKnob ),
    284     d_width( -1 )
     274    const QColor& mid, const QColor& base ):
     275    m_style( style ),
     276    m_hasKnob( hasKnob ),
     277    m_width( -1 )
    285278{
    286279    QPalette palette;
    … …  
    292285
    293286/*!
    294   Set the width of the needle
    295   \param width Width
    296   \sa width()
    297 */
     287   Set the width of the needle
     288   \param width Width
     289   \sa width()
     290 */
    298291void QwtDialSimpleNeedle::setWidth( double width )
    299292{
    300     d_width = width;
    301 }
    302 
    303 /*!
    304   \return the width of the needle
    305   \sa setWidth()
    306 */
     293    m_width = width;
     294}
     295
     296/*!
     297   \return the width of the needle
     298   \sa setWidth()
     299 */
    307300double QwtDialSimpleNeedle::width() const
    308301{
    309     return d_width;
    310 }
    311 
    312 /*!
    313  Draw the needle
    314 
    315  \param painter Painter
    316  \param length Length of the needle
    317  \param colorGroup Color group, used for painting
    318 */
    319 void QwtDialSimpleNeedle::drawNeedle( QPainter *painter,
     302    return m_width;
     303}
     304
     305/*!
     306   Draw the needle
     307
     308   \param painter Painter
     309   \param length Length of the needle
     310   \param colorGroup Color group, used for painting
     311 */
     312void QwtDialSimpleNeedle::drawNeedle( QPainter* painter,
    320313    double length, QPalette::ColorGroup colorGroup ) const
    321314{
    322     double knobWidth = 0.0;
    323     double width = d_width;
    324 
    325     if ( d_style == Arrow )
     315    qreal knobWidth = 0.0;
     316    qreal width = m_width;
     317
     318    if ( m_style == Arrow )
    326319    {
    327320        if ( width <= 0.0 )
    328             width = qMax(length * 0.06, 6.0);
     321            width = qwtMaxF( length * 0.06, 6.0 );
    329322
    330323        qwtDrawArrowNeedle( painter,
    331324            palette(), colorGroup, length, width );
    332325
    333         knobWidth = qMin( width * 2.0, 0.2 * length );
     326        knobWidth = qwtMinF( width * 2.0, 0.2 * length );
    334327    }
    335328    else
    … …  
    344337        painter->drawLine( QPointF( 0.0, 0.0 ), QPointF( length, 0.0 ) );
    345338
    346         knobWidth = qMax( width * 3.0, 5.0 );
    347     }
    348 
    349     if ( d_hasKnob && knobWidth > 0.0 )
     339        knobWidth = qwtMaxF( width * 3.0, 5.0 );
     340    }
     341
     342    if ( m_hasKnob && knobWidth > 0.0 )
    350343    {
    351344        drawKnob( painter, knobWidth,
    … …  
    356349//! Constructor
    357350QwtCompassMagnetNeedle::QwtCompassMagnetNeedle( Style style,
    358         const QColor &light, const QColor &dark ):
    359     d_style( style )
     351    const QColor& light, const QColor& dark ):
     352    m_style( style )
    360353{
    361354    QPalette palette;
    … …  
    373366    \param length Length of the needle
    374367    \param colorGroup Color group, used for painting
    375 */
    376 void QwtCompassMagnetNeedle::drawNeedle( QPainter *painter,
     368 */
     369void QwtCompassMagnetNeedle::drawNeedle( QPainter* painter,
    377370    double length, QPalette::ColorGroup colorGroup ) const
    378371{
    379     if ( d_style == ThinStyle )
    380     {
    381         const double width = qMax( length / 6.0, 3.0 );
     372    if ( m_style == ThinStyle )
     373    {
     374        const qreal width = qwtMaxF( length / 6.0, 3.0 );
    382375
    383376        const int colorOffset = 10;
    … …  
    413406   \param light Light color
    414407   \param dark Dark color
    415 */
     408 */
    416409QwtCompassWindArrow::QwtCompassWindArrow( Style style,
    417         const QColor &light, const QColor &dark ):
    418     d_style( style )
     410    const QColor& light, const QColor& dark ):
     411    m_style( style )
    419412{
    420413    QPalette palette;
    … …  
    426419
    427420/*!
    428  Draw the needle
    429 
    430  \param painter Painter
    431  \param length Length of the needle
    432  \param colorGroup Color group, used for painting
    433 */
    434 void QwtCompassWindArrow::drawNeedle( QPainter *painter,
     421   Draw the needle
     422
     423   \param painter Painter
     424   \param length Length of the needle
     425   \param colorGroup Color group, used for painting
     426 */
     427void QwtCompassWindArrow::drawNeedle( QPainter* painter,
    435428    double length, QPalette::ColorGroup colorGroup ) const
    436429{
    437     if ( d_style == Style1 )
     430    if ( m_style == Style1 )
    438431        qwtDrawStyle1Needle( painter, palette(), colorGroup, length );
    439432    else
  • trunk/BNC/qwt/qwt_dial_needle.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_DIAL_NEEDLE_H
    11 #define QWT_DIAL_NEEDLE_H 1
     11#define QWT_DIAL_NEEDLE_H
    1212
    1313#include "qwt_global.h"
    … …  
    1515
    1616class QPainter;
    17 class QPoint;
    1817
    1918/*!
    20   \brief Base class for needles that can be used in a QwtDial.
     19   \brief Base class for needles that can be used in a QwtDial.
    2120
    22   QwtDialNeedle is a pointer that indicates a value by pointing
    23   to a specific direction.
     21   QwtDialNeedle is a pointer that indicates a value by pointing
     22   to a specific direction.
    2423
    25   \sa QwtDial, QwtCompass
    26 */
     24   \sa QwtDial, QwtCompass
     25 */
    2726
    2827class QWT_EXPORT QwtDialNeedle
    2928{
    30 public:
     29  public:
    3130    QwtDialNeedle();
    3231    virtual ~QwtDialNeedle();
    3332
    34     virtual void setPalette( const QPalette & );
    35     const QPalette &palette() const;
     33    virtual void setPalette( const QPalette& );
     34    const QPalette& palette() const;
    3635
    37     virtual void draw( QPainter *painter, const QPointF &center,
     36    virtual void draw( QPainter*, const QPointF& center,
    3837        double length, double direction,
    3938        QPalette::ColorGroup = QPalette::Active ) const;
    4039
    41 protected:
     40  protected:
    4241    /*!
    43       \brief Draw the needle
     42       \brief Draw the needle
    4443
    45       The origin of the needle is at position (0.0, 0.0 )
    46       pointing in direction 0.0 ( = east ).
     44       The origin of the needle is at position (0.0, 0.0 )
     45       pointing in direction 0.0 ( = east ).
    4746
    48       The painter is already initialized with translation and
    49       rotation.
     47       The painter is already initialized with translation and
     48       rotation.
    5049
    51       \param painter Painter
    52       \param length Length of the needle
    53       \param colorGroup Color group, used for painting
     50       \param painter Painter
     51       \param length Length of the needle
     52       \param colorGroup Color group, used for painting
    5453
    55       \sa setPalette(), palette()
    56     */
    57     virtual void drawNeedle( QPainter *painter,
     54       \sa setPalette(), palette()
     55     */
     56    virtual void drawNeedle( QPainter* painter,
    5857        double length, QPalette::ColorGroup colorGroup ) const = 0;
    5958
    60     virtual void drawKnob( QPainter *, double width,
    61         const QBrush &, bool sunken ) const;
     59    virtual void drawKnob( QPainter*, double width,
     60        const QBrush&, bool sunken ) const;
    6261
    63 private:
    64     QPalette d_palette;
     62  private:
     63    Q_DISABLE_COPY(QwtDialNeedle)
     64
     65    QPalette m_palette;
    6566};
    6667
    6768/*!
    68   \brief A needle for dial widgets
     69   \brief A needle for dial widgets
    6970
    70   The following colors are used:
     71   The following colors are used:
    7172
    72   - QPalette::Mid\n
     73   - QPalette::Mid\n
    7374    Pointer
    74   - QPalette::Base\n
     75   - QPalette::Base\n
    7576    Knob
    7677
    77   \sa QwtDial, QwtCompass
    78 */
     78   \sa QwtDial, QwtCompass
     79 */
    7980
    80 class QWT_EXPORT QwtDialSimpleNeedle: public QwtDialNeedle
     81class QWT_EXPORT QwtDialSimpleNeedle : public QwtDialNeedle
    8182{
    82 public:
     83  public:
    8384    //! Style of the needle
    8485    enum Style
    … …  
    9293
    9394    QwtDialSimpleNeedle( Style, bool hasKnob = true,
    94         const QColor &mid = Qt::gray, const QColor &base = Qt::darkGray );
     95        const QColor& mid = Qt::gray, const QColor& base = Qt::darkGray );
    9596
    9697    void setWidth( double width );
    9798    double width() const;
    9899
    99 protected:
    100     virtual void drawNeedle( QPainter *, double length,
    101         QPalette::ColorGroup ) const;
     100  protected:
     101    virtual void drawNeedle( QPainter*, double length,
     102        QPalette::ColorGroup ) const QWT_OVERRIDE;
    102103
    103 private:
    104     Style d_style;
    105     bool d_hasKnob;
    106     double d_width;
     104  private:
     105    Style m_style;
     106    bool m_hasKnob;
     107    double m_width;
    107108};
    108109
    109110/*!
    110   \brief A magnet needle for compass widgets
     111   \brief A magnet needle for compass widgets
    111112
    112   A magnet needle points to two opposite directions indicating
    113   north and south.
     113   A magnet needle points to two opposite directions indicating
     114   north and south.
    114115
    115   The following colors are used:
    116   - QPalette::Light\n
     116   The following colors are used:
     117   - QPalette::Light\n
    117118    Used for pointing south
    118   - QPalette::Dark\n
     119   - QPalette::Dark\n
    119120    Used for pointing north
    120   - QPalette::Base\n
     121   - QPalette::Base\n
    121122    Knob (ThinStyle only)
    122123
    123   \sa QwtDial, QwtCompass
    124 */
     124   \sa QwtDial, QwtCompass
     125 */
    125126
    126 class QWT_EXPORT QwtCompassMagnetNeedle: public QwtDialNeedle
     127class QWT_EXPORT QwtCompassMagnetNeedle : public QwtDialNeedle
    127128{
    128 public:
     129  public:
    129130    //! Style of the needle
    130131    enum Style
    … …  
    138139
    139140    QwtCompassMagnetNeedle( Style = TriangleStyle,
    140         const QColor &light = Qt::white, const QColor &dark = Qt::red );
     141        const QColor& light = Qt::white, const QColor& dark = Qt::red );
    141142
    142 protected:
    143     virtual void drawNeedle( QPainter *,
    144         double length, QPalette::ColorGroup ) const;
     143  protected:
     144    virtual void drawNeedle( QPainter*,
     145        double length, QPalette::ColorGroup ) const QWT_OVERRIDE;
    145146
    146 private:
    147     Style d_style;
     147  private:
     148    Style m_style;
    148149};
    149150
    150151/*!
    151   \brief An indicator for the wind direction
     152   \brief An indicator for the wind direction
    152153
    153   QwtCompassWindArrow shows the direction where the wind comes from.
     154   QwtCompassWindArrow shows the direction where the wind comes from.
    154155
    155   - QPalette::Light\n
     156   - QPalette::Light\n
    156157    Used for Style1, or the light half of Style2
    157   - QPalette::Dark\n
     158   - QPalette::Dark\n
    158159    Used for the dark half of Style2
    159160
    160   \sa QwtDial, QwtCompass
    161 */
     161   \sa QwtDial, QwtCompass
     162 */
    162163
    163 class QWT_EXPORT QwtCompassWindArrow: public QwtDialNeedle
     164class QWT_EXPORT QwtCompassWindArrow : public QwtDialNeedle
    164165{
    165 public:
     166  public:
    166167    //! Style of the arrow
    167168    enum Style
    … …  
    174175    };
    175176
    176     QwtCompassWindArrow( Style, const QColor &light = Qt::white,
    177         const QColor &dark = Qt::gray );
     177    QwtCompassWindArrow( Style, const QColor& light = Qt::white,
     178        const QColor& dark = Qt::gray );
    178179
    179 protected:
    180     virtual void drawNeedle( QPainter *,
    181         double length, QPalette::ColorGroup ) const;
     180  protected:
     181    virtual void drawNeedle( QPainter*,
     182        double length, QPalette::ColorGroup ) const QWT_OVERRIDE;
    182183
    183 private:
    184     Style d_style;
     184  private:
     185    Style m_style;
    185186};
    186187
  • trunk/BNC/qwt/qwt_dyngrid_layout.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_dyngrid_layout.h"
    11 #include "qwt_math.h"
     11
    1212#include <qvector.h>
    1313#include <qlist.h>
    … …  
    1515class QwtDynGridLayout::PrivateData
    1616{
    17 public:
    18     PrivateData():
    19         isDirty( true )
     17  public:
     18    PrivateData()
     19        : isDirty( true )
    2020    {
    2121    }
    … …  
    2323    void updateLayoutCache();
    2424
    25     mutable QList<QLayoutItem*> itemList;
     25    mutable QList< QLayoutItem* > itemList;
    2626
    2727    uint maxColumns;
    … …  
    3232
    3333    bool isDirty;
    34     QVector<QSize> itemSizeHints;
     34    QVector< QSize > itemSizeHints;
    3535};
    3636
    … …  
    4141    int index = 0;
    4242
    43     for ( QList<QLayoutItem*>::iterator it = itemList.begin();
    44         it != itemList.end(); ++it, index++ )
     43    for ( QList< QLayoutItem* >::const_iterator it = itemList.constBegin();
     44        it != itemList.constEnd(); ++it, index++ )
    4545    {
    4646        itemSizeHints[ index ] = ( *it )->sizeHint();
    … …  
    5151
    5252/*!
    53   \param parent Parent widget
    54   \param margin Margin
    55   \param spacing Spacing
    56 */
    57 
    58 QwtDynGridLayout::QwtDynGridLayout( QWidget *parent,
    59         int margin, int spacing ):
    60     QLayout( parent )
     53   \param parent Parent widget
     54   \param margin Margin
     55   \param spacing Spacing
     56 */
     57
     58QwtDynGridLayout::QwtDynGridLayout( QWidget* parent, int margin, int spacing )
     59    : QLayout( parent )
    6160{
    6261    init();
    6362
    6463    setSpacing( spacing );
    65     setMargin( margin );
    66 }
    67 
    68 /*!
    69   \param spacing Spacing
    70 */
     64    setContentsMargins( margin, margin, margin, margin );
     65}
     66
     67/*!
     68   \param spacing Spacing
     69 */
    7170
    7271QwtDynGridLayout::QwtDynGridLayout( int spacing )
    … …  
    7776
    7877/*!
    79   Initialize the layout with default values.
    80 */
     78   Initialize the layout with default values.
     79 */
    8180void QwtDynGridLayout::init()
    8281{
    83     d_data = new QwtDynGridLayout::PrivateData;
    84     d_data->maxColumns = d_data->numRows = d_data->numColumns = 0;
    85     d_data->expanding = 0;
     82    m_data = new QwtDynGridLayout::PrivateData;
     83    m_data->maxColumns = m_data->numRows = m_data->numColumns = 0;
    8684}
    8785
    … …  
    9088QwtDynGridLayout::~QwtDynGridLayout()
    9189{
    92     for ( int i = 0; i < d_data->itemList.size(); i++ )
    93         delete d_data->itemList[i];
    94 
    95     delete d_data;
     90    qDeleteAll( m_data->itemList );
     91    delete m_data;
    9692}
    9793
    … …  
    9995void QwtDynGridLayout::invalidate()
    10096{
    101     d_data->isDirty = true;
     97    m_data->isDirty = true;
    10298    QLayout::invalidate();
    10399}
    104100
    105101/*!
    106   Limit the number of columns.
    107   \param maxColumns upper limit, 0 means unlimited
    108   \sa maxColumns()
    109 */
     102   Limit the number of columns.
     103   \param maxColumns upper limit, 0 means unlimited
     104   \sa maxColumns()
     105 */
    110106void QwtDynGridLayout::setMaxColumns( uint maxColumns )
    111107{
    112     d_data->maxColumns = maxColumns;
    113 }
    114 
    115 /*!
    116   \brief Return the upper limit for the number of columns.
    117 
    118   0 means unlimited, what is the default.
    119 
    120   \return Upper limit for the number of columns
    121   \sa setMaxColumns()
    122 */
     108    m_data->maxColumns = maxColumns;
     109}
     110
     111/*!
     112   \brief Return the upper limit for the number of columns.
     113
     114   0 means unlimited, what is the default.
     115
     116   \return Upper limit for the number of columns
     117   \sa setMaxColumns()
     118 */
    123119uint QwtDynGridLayout::maxColumns() const
    124120{
    125     return d_data->maxColumns;
    126 }
    127 
    128 /*!
    129   \brief Add an item to the next free position.
    130   \param item Layout item
    131  */
    132 void QwtDynGridLayout::addItem( QLayoutItem *item )
    133 {
    134     d_data->itemList.append( item );
     121    return m_data->maxColumns;
     122}
     123
     124/*!
     125   \brief Add an item to the next free position.
     126   \param item Layout item
     127 */
     128void QwtDynGridLayout::addItem( QLayoutItem* item )
     129{
     130    m_data->itemList.append( item );
    135131    invalidate();
    136132}
    137133
    138134/*!
    139   \return true if this layout is empty.
    140 */
     135   \return true if this layout is empty.
     136 */
    141137bool QwtDynGridLayout::isEmpty() const
    142138{
    143     return d_data->itemList.isEmpty();
    144 }
    145 
    146 /*!
    147   \return number of layout items
    148 */
     139    return m_data->itemList.isEmpty();
     140}
     141
     142/*!
     143   \return number of layout items
     144 */
    149145uint QwtDynGridLayout::itemCount() const
    150146{
    151     return d_data->itemList.count();
    152 }
    153 
    154 /*!
    155   Find the item at a specific index
    156 
    157   \param index Index
    158   \return Item at a specific index
    159   \sa takeAt()
    160 */
    161 QLayoutItem *QwtDynGridLayout::itemAt( int index ) const
    162 {
    163     if ( index < 0 || index >= d_data->itemList.count() )
     147    return m_data->itemList.count();
     148}
     149
     150/*!
     151   Find the item at a specific index
     152
     153   \param index Index
     154   \return Item at a specific index
     155   \sa takeAt()
     156 */
     157QLayoutItem* QwtDynGridLayout::itemAt( int index ) const
     158{
     159    if ( index < 0 || index >= m_data->itemList.count() )
    164160        return NULL;
    165161
    166     return d_data->itemList.at( index );
    167 }
    168 
    169 /*!
    170   Find the item at a specific index and remove it from the layout
    171 
    172   \param index Index
    173   \return Layout item, removed from the layout
    174   \sa itemAt()
    175 */
    176 QLayoutItem *QwtDynGridLayout::takeAt( int index )
    177 {
    178     if ( index < 0 || index >= d_data->itemList.count() )
     162    return m_data->itemList.at( index );
     163}
     164
     165/*!
     166   Find the item at a specific index and remove it from the layout
     167
     168   \param index Index
     169   \return Layout item, removed from the layout
     170   \sa itemAt()
     171 */
     172QLayoutItem* QwtDynGridLayout::takeAt( int index )
     173{
     174    if ( index < 0 || index >= m_data->itemList.count() )
    179175        return NULL;
    180176
    181     d_data->isDirty = true;
    182     return d_data->itemList.takeAt( index );
     177    m_data->isDirty = true;
     178    return m_data->itemList.takeAt( index );
    183179}
    184180
    … …  
    186182int QwtDynGridLayout::count() const
    187183{
    188     return d_data->itemList.count();
    189 }
    190 
    191 /*!
    192   Set whether this layout can make use of more space than sizeHint().
    193   A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only
    194   one dimension, while Qt::Vertical | Qt::Horizontal means that it wants
    195   to grow in both dimensions. The default value is 0.
    196 
    197   \param expanding Or'd orientations
    198   \sa expandingDirections()
    199 */
     184    return m_data->itemList.count();
     185}
     186
     187/*!
     188   Set whether this layout can make use of more space than sizeHint().
     189   A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only
     190   one dimension, while Qt::Vertical | Qt::Horizontal means that it wants
     191   to grow in both dimensions. The default value is 0.
     192
     193   \param expanding Or'd orientations
     194   \sa expandingDirections()
     195 */
    200196void QwtDynGridLayout::setExpandingDirections( Qt::Orientations expanding )
    201197{
    202     d_data->expanding = expanding;
    203 }
    204 
    205 /*!
    206   \brief Returns whether this layout can make use of more space than sizeHint().
    207 
    208   A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only
    209   one dimension, while Qt::Vertical | Qt::Horizontal means that it wants
    210   to grow in both dimensions.
    211 
    212   \return Orientations, where the layout expands
    213   \sa setExpandingDirections()
    214 */
     198    m_data->expanding = expanding;
     199}
     200
     201/*!
     202   \brief Returns whether this layout can make use of more space than sizeHint().
     203
     204   A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only
     205   one dimension, while Qt::Vertical | Qt::Horizontal means that it wants
     206   to grow in both dimensions.
     207
     208   \return Orientations, where the layout expands
     209   \sa setExpandingDirections()
     210 */
    215211Qt::Orientations QwtDynGridLayout::expandingDirections() const
    216212{
    217     return d_data->expanding;
    218 }
    219 
    220 /*!
    221   Reorganizes columns and rows and resizes managed items within
    222   a rectangle.
    223 
    224   \param rect Layout geometry
    225 */
    226 void QwtDynGridLayout::setGeometry( const QRect &rect )
     213    return m_data->expanding;
     214}
     215
     216/*!
     217   Reorganizes columns and rows and resizes managed items within
     218   a rectangle.
     219
     220   \param rect Layout geometry
     221 */
     222void QwtDynGridLayout::setGeometry( const QRect& rect )
    227223{
    228224    QLayout::setGeometry( rect );
    … …  
    231227        return;
    232228
    233     d_data->numColumns = columnsForWidth( rect.width() );
    234     d_data->numRows = itemCount() / d_data->numColumns;
    235     if ( itemCount() % d_data->numColumns )
    236         d_data->numRows++;
    237 
    238     QList<QRect> itemGeometries = layoutItems( rect, d_data->numColumns );
     229    m_data->numColumns = columnsForWidth( rect.width() );
     230    m_data->numRows = itemCount() / m_data->numColumns;
     231    if ( itemCount() % m_data->numColumns )
     232        m_data->numRows++;
     233
     234    const QList< QRect > itemGeometries = layoutItems( rect, m_data->numColumns );
    239235
    240236    int index = 0;
    241     for ( QList<QLayoutItem*>::iterator it = d_data->itemList.begin();
    242         it != d_data->itemList.end(); ++it )
     237    for ( QList< QLayoutItem* >::const_iterator it = m_data->itemList.constBegin();
     238        it != m_data->itemList.constEnd(); ++it )
    243239    {
    244240        ( *it )->setGeometry( itemGeometries[index] );
    … …  
    248244
    249245/*!
    250   \brief Calculate the number of columns for a given width.
    251 
    252   The calculation tries to use as many columns as possible
    253   ( limited by maxColumns() )
    254 
    255   \param width Available width for all columns
    256   \return Number of columns for a given width
    257 
    258   \sa maxColumns(), setMaxColumns()
    259 */
     246   \brief Calculate the number of columns for a given width.
     247
     248   The calculation tries to use as many columns as possible
     249   ( limited by maxColumns() )
     250
     251   \param width Available width for all columns
     252   \return Number of columns for a given width
     253
     254   \sa maxColumns(), setMaxColumns()
     255 */
    260256uint QwtDynGridLayout::columnsForWidth( int width ) const
    261257{
    … …  
    264260
    265261    uint maxColumns = itemCount();
    266     if ( d_data->maxColumns > 0 )
    267         maxColumns = qMin( d_data->maxColumns, maxColumns );
     262    if ( m_data->maxColumns > 0 )
     263        maxColumns = qMin( m_data->maxColumns, maxColumns );
    268264
    269265    if ( maxRowWidth( maxColumns ) <= width )
    … …  
    281277
    282278/*!
    283   Calculate the width of a layout for a given number of
    284   columns.
    285 
    286   \param numColumns Given number of columns
    287   \param itemWidth Array of the width hints for all items
    288 */
     279   Calculate the width of a layout for a given number of
     280   columns.
     281
     282   \param numColumns Given number of columns
     283   \param itemWidth Array of the width hints for all items
     284 */
    289285int QwtDynGridLayout::maxRowWidth( int numColumns ) const
    290286{
    291287    int col;
    292288
    293     QVector<int> colWidth( numColumns );
     289    QVector< int > colWidth( numColumns );
    294290    for ( col = 0; col < numColumns; col++ )
    295291        colWidth[col] = 0;
    296292
    297     if ( d_data->isDirty )
    298         d_data->updateLayoutCache();
     293    if ( m_data->isDirty )
     294        m_data->updateLayoutCache();
    299295
    300296    for ( int index = 0;
    301         index < d_data->itemSizeHints.count(); index++ )
     297        index < m_data->itemSizeHints.count(); index++ )
    302298    {
    303299        col = index % numColumns;
    304300        colWidth[col] = qMax( colWidth[col],
    305             d_data->itemSizeHints[int( index )].width() );
    306     }
    307 
    308     int rowWidth = 2 * margin() + ( numColumns - 1 ) * spacing();
     301            m_data->itemSizeHints[index].width() );
     302    }
     303
     304    const QMargins m = contentsMargins();
     305
     306    int rowWidth = m.left() + m.right() + ( numColumns - 1 ) * spacing();
    309307    for ( col = 0; col < numColumns; col++ )
    310308        rowWidth += colWidth[col];
    … …  
    314312
    315313/*!
    316   \return the maximum width of all layout items
    317 */
     314   \return the maximum width of all layout items
     315 */
    318316int QwtDynGridLayout::maxItemWidth() const
    319317{
    … …  
    321319        return 0;
    322320
    323     if ( d_data->isDirty )
    324         d_data->updateLayoutCache();
     321    if ( m_data->isDirty )
     322        m_data->updateLayoutCache();
    325323
    326324    int w = 0;
    327     for ( int i = 0; i < d_data->itemSizeHints.count(); i++ )
    328     {
    329         const int itemW = d_data->itemSizeHints[i].width();
     325    for ( int i = 0; i < m_data->itemSizeHints.count(); i++ )
     326    {
     327        const int itemW = m_data->itemSizeHints[i].width();
    330328        if ( itemW > w )
    331329            w = itemW;
    … …  
    336334
    337335/*!
    338   Calculate the geometries of the layout items for a layout
    339   with numColumns columns and a given rectangle.
    340 
    341   \param rect Rect where to place the items
    342   \param numColumns Number of columns
    343   \return item geometries
    344 */
    345 
    346 QList<QRect> QwtDynGridLayout::layoutItems( const QRect &rect,
     336   Calculate the geometries of the layout items for a layout
     337   with numColumns columns and a given rectangle.
     338
     339   \param rect Rect where to place the items
     340   \param numColumns Number of columns
     341   \return item geometries
     342 */
     343
     344QList< QRect > QwtDynGridLayout::layoutItems( const QRect& rect,
    347345    uint numColumns ) const
    348346{
    349     QList<QRect> itemGeometries;
     347    QList< QRect > itemGeometries;
    350348    if ( numColumns == 0 || isEmpty() )
    351349        return itemGeometries;
    … …  
    358356        return itemGeometries;
    359357
    360     QVector<int> rowHeight( numRows );
    361     QVector<int> colWidth( numColumns );
     358    QVector< int > rowHeight( numRows );
     359    QVector< int > colWidth( numColumns );
    362360
    363361    layoutGrid( numColumns, rowHeight, colWidth );
    … …  
    370368        stretchGrid( rect, numColumns, rowHeight, colWidth );
    371369
    372     const int maxColumns = d_data->maxColumns;
    373     d_data->maxColumns = numColumns;
     370    const int maxColumns = m_data->maxColumns;
     371    m_data->maxColumns = numColumns;
    374372    const QRect alignedRect = alignmentRect( rect );
    375     d_data->maxColumns = maxColumns;
     373    m_data->maxColumns = maxColumns;
    376374
    377375    const int xOffset = expandH ? 0 : alignedRect.x();
    378376    const int yOffset = expandV ? 0 : alignedRect.y();
    379377
    380     QVector<int> colX( numColumns );
    381     QVector<int> rowY( numRows );
     378    QVector< int > colX( numColumns );
     379    QVector< int > rowY( numRows );
    382380
    383381    const int xySpace = spacing();
    384382
    385     rowY[0] = yOffset + margin();
     383    const QMargins m = contentsMargins();
     384
     385    rowY[0] = yOffset + m.top();
    386386    for ( uint r = 1; r < numRows; r++ )
    387         rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace;
    388 
    389     colX[0] = xOffset + margin();
     387        rowY[r] = rowY[r - 1] + rowHeight[r - 1] + xySpace;
     388
     389    colX[0] = xOffset + m.left();
    390390    for ( uint c = 1; c < numColumns; c++ )
    391         colX[c] = colX[c-1] + colWidth[c-1] + xySpace;
    392 
    393     const int itemCount = d_data->itemList.size();
     391        colX[c] = colX[c - 1] + colWidth[c - 1] + xySpace;
     392
     393    const int itemCount = m_data->itemList.size();
     394    itemGeometries.reserve( itemCount );
     395
    394396    for ( int i = 0; i < itemCount; i++ )
    395397    {
    … …  
    397399        const int col = i % numColumns;
    398400
    399         QRect itemGeometry( colX[col], rowY[row],
     401        const QRect itemGeometry( colX[col], rowY[row],
    400402            colWidth[col], rowHeight[row] );
    401403        itemGeometries.append( itemGeometry );
    … …  
    407409
    408410/*!
    409   Calculate the dimensions for the columns and rows for a grid
    410   of numColumns columns.
    411 
    412   \param numColumns Number of columns.
    413   \param rowHeight Array where to fill in the calculated row heights.
    414   \param colWidth Array where to fill in the calculated column widths.
    415 */
     411   Calculate the dimensions for the columns and rows for a grid
     412   of numColumns columns.
     413
     414   \param numColumns Number of columns.
     415   \param rowHeight Array where to fill in the calculated row heights.
     416   \param colWidth Array where to fill in the calculated column widths.
     417 */
    416418
    417419void QwtDynGridLayout::layoutGrid( uint numColumns,
    418     QVector<int>& rowHeight, QVector<int>& colWidth ) const
     420    QVector< int >& rowHeight, QVector< int >& colWidth ) const
    419421{
    420422    if ( numColumns <= 0 )
    421423        return;
    422424
    423     if ( d_data->isDirty )
    424         d_data->updateLayoutCache();
    425 
    426     for ( int index = 0; index < d_data->itemSizeHints.count(); index++ )
     425    if ( m_data->isDirty )
     426        m_data->updateLayoutCache();
     427
     428    for ( int index = 0; index < m_data->itemSizeHints.count(); index++ )
    427429    {
    428430        const int row = index / numColumns;
    429431        const int col = index % numColumns;
    430432
    431         const QSize &size = d_data->itemSizeHints[int( index )];
     433        const QSize& size = m_data->itemSizeHints[index];
    432434
    433435        rowHeight[row] = ( col == 0 )
    … …  
    439441
    440442/*!
    441   \return true: QwtDynGridLayout implements heightForWidth().
    442   \sa heightForWidth()
    443 */
     443   \return true: QwtDynGridLayout implements heightForWidth().
     444   \sa heightForWidth()
     445 */
    444446bool QwtDynGridLayout::hasHeightForWidth() const
    445447{
    … …  
    448450
    449451/*!
    450   \return The preferred height for this layout, given a width.
    451   \sa hasHeightForWidth()
    452 */
     452   \return The preferred height for this layout, given a width.
     453   \sa hasHeightForWidth()
     454 */
    453455int QwtDynGridLayout::heightForWidth( int width ) const
    454456{
    … …  
    461463        numRows++;
    462464
    463     QVector<int> rowHeight( numRows );
    464     QVector<int> colWidth( numColumns );
     465    QVector< int > rowHeight( numRows );
     466    QVector< int > colWidth( numColumns );
    465467
    466468    layoutGrid( numColumns, rowHeight, colWidth );
    467469
    468     int h = 2 * margin() + ( numRows - 1 ) * spacing();
     470    const QMargins m = contentsMargins();
     471
     472    int h = m.top() + m.bottom() + ( numRows - 1 ) * spacing();
    469473    for ( uint row = 0; row < numRows; row++ )
    470474        h += rowHeight[row];
    … …  
    474478
    475479/*!
    476   Stretch columns in case of expanding() & QSizePolicy::Horizontal and
    477   rows in case of expanding() & QSizePolicy::Vertical to fill the entire
    478   rect. Rows and columns are stretched with the same factor.
    479 
    480   \param rect Bounding rectangle
    481   \param numColumns Number of columns
    482   \param rowHeight Array to be filled with the calculated row heights
    483   \param colWidth Array to be filled with the calculated column widths
    484 
    485   \sa setExpanding(), expanding()
    486 */
    487 void QwtDynGridLayout::stretchGrid( const QRect &rect,
    488     uint numColumns, QVector<int>& rowHeight, QVector<int>& colWidth ) const
     480   Stretch columns in case of expanding() & QSizePolicy::Horizontal and
     481   rows in case of expanding() & QSizePolicy::Vertical to fill the entire
     482   rect. Rows and columns are stretched with the same factor.
     483
     484   \param rect Bounding rectangle
     485   \param numColumns Number of columns
     486   \param rowHeight Array to be filled with the calculated row heights
     487   \param colWidth Array to be filled with the calculated column widths
     488
     489   \sa setExpanding(), expanding()
     490 */
     491void QwtDynGridLayout::stretchGrid( const QRect& rect,
     492    uint numColumns, QVector< int >& rowHeight, QVector< int >& colWidth ) const
    489493{
    490494    if ( numColumns == 0 || isEmpty() )
    … …  
    495499    expandV = expandingDirections() & Qt::Vertical;
    496500
     501    const QMargins m = contentsMargins();
     502
    497503    if ( expandH )
    498504    {
    499         int xDelta = rect.width() - 2 * margin() - ( numColumns - 1 ) * spacing();
     505        int xDelta = rect.width() - m.left() - m.right() - ( numColumns - 1 ) * spacing();
    500506        for ( uint col = 0; col < numColumns; col++ )
    501507            xDelta -= colWidth[col];
    … …  
    518524            numRows++;
    519525
    520         int yDelta = rect.height() - 2 * margin() - ( numRows - 1 ) * spacing();
     526        int yDelta = rect.height() - m.top() - m.bottom() - ( numRows - 1 ) * spacing();
    521527        for ( uint row = 0; row < numRows; row++ )
    522528            yDelta -= rowHeight[row];
    … …  
    541547   \return Size hint
    542548   \sa maxColumns(), setMaxColumns()
    543 */
     549 */
    544550QSize QwtDynGridLayout::sizeHint() const
    545551{
    … …  
    548554
    549555    uint numColumns = itemCount();
    550     if ( d_data->maxColumns > 0 )
    551         numColumns = qMin( d_data->maxColumns, numColumns );
     556    if ( m_data->maxColumns > 0 )
     557        numColumns = qMin( m_data->maxColumns, numColumns );
    552558
    553559    uint numRows = itemCount() / numColumns;
    … …  
    555561        numRows++;
    556562
    557     QVector<int> rowHeight( numRows );
    558     QVector<int> colWidth( numColumns );
     563    QVector< int > rowHeight( numRows );
     564    QVector< int > colWidth( numColumns );
    559565
    560566    layoutGrid( numColumns, rowHeight, colWidth );
    561567
    562     int h = 2 * margin() + ( numRows - 1 ) * spacing();
     568    const QMargins m = contentsMargins();
     569
     570    int h = m.top() + m.bottom() + ( numRows - 1 ) * spacing();
    563571    for ( uint row = 0; row < numRows; row++ )
    564572        h += rowHeight[row];
    565573
    566     int w = 2 * margin() + ( numColumns - 1 ) * spacing();
     574    int w = m.left() + m.right() + ( numColumns - 1 ) * spacing();
    567575    for ( uint col = 0; col < numColumns; col++ )
    568576        w += colWidth[col];
    … …  
    572580
    573581/*!
    574   \return Number of rows of the current layout.
    575   \sa numColumns()
    576   \warning The number of rows might change whenever the geometry changes
    577 */
     582   \return Number of rows of the current layout.
     583   \sa numColumns()
     584   \warning The number of rows might change whenever the geometry changes
     585 */
    578586uint QwtDynGridLayout::numRows() const
    579587{
    580     return d_data->numRows;
    581 }
    582 
    583 /*!
    584   \return Number of columns of the current layout.
    585   \sa numRows()
    586   \warning The number of columns might change whenever the geometry changes
    587 */
     588    return m_data->numRows;
     589}
     590
     591/*!
     592   \return Number of columns of the current layout.
     593   \sa numRows()
     594   \warning The number of columns might change whenever the geometry changes
     595 */
    588596uint QwtDynGridLayout::numColumns() const
    589597{
    590     return d_data->numColumns;
    591 }
     598    return m_data->numColumns;
     599}
     600
     601#include "moc_qwt_dyngrid_layout.cpp"
  • trunk/BNC/qwt/qwt_dyngrid_layout.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include <qlayout.h>
    15 #include <qsize.h>
    16 #include <qlist.h>
     15
     16template< typename T > class QList;
    1717
    1818/*!
    19   \brief The QwtDynGridLayout class lays out widgets in a grid,
     19   \brief The QwtDynGridLayout class lays out widgets in a grid,
    2020         adjusting the number of columns and rows to the current size.
    2121
    22   QwtDynGridLayout takes the space it gets, divides it up into rows and
    23   columns, and puts each of the widgets it manages into the correct cell(s).
    24   It lays out as many number of columns as possible (limited by maxColumns()).
    25 */
     22   QwtDynGridLayout takes the space it gets, divides it up into rows and
     23   columns, and puts each of the widgets it manages into the correct cell(s).
     24   It lays out as many number of columns as possible (limited by maxColumns()).
     25 */
    2626
    2727class QWT_EXPORT QwtDynGridLayout : public QLayout
    2828{
    2929    Q_OBJECT
    30 public:
    31     explicit QwtDynGridLayout( QWidget *, int margin = 0, int spacing = -1 );
     30  public:
     31    explicit QwtDynGridLayout( QWidget*, int margin = 0, int spacing = -1 );
    3232    explicit QwtDynGridLayout( int spacing = -1 );
    3333
    3434    virtual ~QwtDynGridLayout();
    3535
    36     virtual void invalidate();
     36    virtual void invalidate() QWT_OVERRIDE;
    3737
    3838    void setMaxColumns( uint maxColumns );
    … …  
    4242    uint numColumns () const;
    4343
    44     virtual void addItem( QLayoutItem * );
     44    virtual void addItem( QLayoutItem* ) QWT_OVERRIDE;
    4545
    46     virtual QLayoutItem *itemAt( int index ) const;
    47     virtual QLayoutItem *takeAt( int index );
    48     virtual int count() const;
     46    virtual QLayoutItem* itemAt( int index ) const QWT_OVERRIDE;
     47    virtual QLayoutItem* takeAt( int index ) QWT_OVERRIDE;
     48    virtual int count() const QWT_OVERRIDE;
    4949
    5050    void setExpandingDirections( Qt::Orientations );
    51     virtual Qt::Orientations expandingDirections() const;
    52     QList<QRect> layoutItems( const QRect &, uint numColumns ) const;
     51    virtual Qt::Orientations expandingDirections() const QWT_OVERRIDE;
     52    QList< QRect > layoutItems( const QRect&, uint numColumns ) const;
    5353
    5454    virtual int maxItemWidth() const;
    5555
    56     virtual void setGeometry( const QRect &rect );
     56    virtual void setGeometry( const QRect& ) QWT_OVERRIDE;
    5757
    58     virtual bool hasHeightForWidth() const;
    59     virtual int heightForWidth( int ) const;
     58    virtual bool hasHeightForWidth() const QWT_OVERRIDE;
     59    virtual int heightForWidth( int ) const QWT_OVERRIDE;
    6060
    61     virtual QSize sizeHint() const;
     61    virtual QSize sizeHint() const QWT_OVERRIDE;
    6262
    63     virtual bool isEmpty() const;
     63    virtual bool isEmpty() const QWT_OVERRIDE;
    6464    uint itemCount() const;
    6565
    6666    virtual uint columnsForWidth( int width ) const;
    6767
    68 protected:
     68  protected:
    6969
    7070    void layoutGrid( uint numColumns,
    71         QVector<int>& rowHeight, QVector<int>& colWidth ) const;
    72     void stretchGrid( const QRect &rect, uint numColumns,
    73         QVector<int>& rowHeight, QVector<int>& colWidth ) const;
     71        QVector< int >& rowHeight, QVector< int >& colWidth ) const;
    7472
    75 private:
     73    void stretchGrid( const QRect& rect, uint numColumns,
     74        QVector< int >& rowHeight, QVector< int >& colWidth ) const;
     75
     76  private:
    7677    void init();
    7778    int maxRowWidth( int numColumns ) const;
    7879
    7980    class PrivateData;
    80     PrivateData *d_data;
     81    PrivateData* m_data;
    8182};
    8283
  • trunk/BNC/qwt/qwt_event_pattern.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313/*!
    14   Constructor
    15 
    16   \sa MousePatternCode, KeyPatternCode
    17 */
    18 
    19 QwtEventPattern::QwtEventPattern():
    20     d_mousePattern( MousePatternCount ),
    21     d_keyPattern( KeyPatternCount )
     14   Constructor
     15
     16   \sa MousePatternCode, KeyPatternCode
     17 */
     18
     19QwtEventPattern::QwtEventPattern()
     20    : m_mousePattern( MousePatternCount )
     21    , m_keyPattern( KeyPatternCount )
    2222{
    2323    initKeyPattern();
    … …  
    3131
    3232/*!
    33   Set default mouse patterns, depending on the number of mouse buttons
    34 
    35   \param numButtons Number of mouse buttons ( <= 3 )
    36   \sa MousePatternCode
    37 */
     33   Set default mouse patterns, depending on the number of mouse buttons
     34
     35   \param numButtons Number of mouse buttons ( <= 3 )
     36   \sa MousePatternCode
     37 */
    3838void QwtEventPattern::initMousePattern( int numButtons )
    3939{
    40     d_mousePattern.resize( MousePatternCount );
     40    m_mousePattern.resize( MousePatternCount );
    4141
    4242    switch ( numButtons )
    … …  
    6060            setMousePattern( MouseSelect1, Qt::LeftButton );
    6161            setMousePattern( MouseSelect2, Qt::RightButton );
    62             setMousePattern( MouseSelect3, Qt::MidButton );
     62            setMousePattern( MouseSelect3, Qt::MiddleButton );
    6363        }
    6464    }
    6565
    66     setMousePattern( MouseSelect4, d_mousePattern[MouseSelect1].button,
    67         d_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier );
    68 
    69     setMousePattern( MouseSelect5, d_mousePattern[MouseSelect2].button,
    70         d_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier );
    71 
    72     setMousePattern( MouseSelect6, d_mousePattern[MouseSelect3].button,
    73         d_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier );
    74 }
    75 
    76 /*!
    77   Set default mouse patterns.
    78 
    79   \sa KeyPatternCode
    80 */
     66    setMousePattern( MouseSelect4, m_mousePattern[MouseSelect1].button,
     67        m_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier );
     68
     69    setMousePattern( MouseSelect5, m_mousePattern[MouseSelect2].button,
     70        m_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier );
     71
     72    setMousePattern( MouseSelect6, m_mousePattern[MouseSelect3].button,
     73        m_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier );
     74}
     75
     76/*!
     77   Set default mouse patterns.
     78
     79   \sa KeyPatternCode
     80 */
    8181void QwtEventPattern::initKeyPattern()
    8282{
    83     d_keyPattern.resize( KeyPatternCount );
     83    m_keyPattern.resize( KeyPatternCount );
    8484
    8585    setKeyPattern( KeySelect1, Qt::Key_Return );
    … …  
    9898
    9999/*!
    100   Change one mouse pattern
    101 
    102   \param pattern Index of the pattern
    103   \param button Button
    104   \param modifiers Keyboard modifiers
    105 
    106   \sa QMouseEvent
    107 */
     100   Change one mouse pattern
     101
     102   \param pattern Index of the pattern
     103   \param button Button
     104   \param modifiers Keyboard modifiers
     105
     106   \sa QMouseEvent
     107 */
    108108void QwtEventPattern::setMousePattern( MousePatternCode pattern,
    109109    Qt::MouseButton button, Qt::KeyboardModifiers modifiers )
    … …  
    111111    if ( pattern >= 0 && pattern < MousePatternCount )
    112112    {
    113         d_mousePattern[ pattern ].button = button;
    114         d_mousePattern[ pattern ].modifiers = modifiers;
     113        m_mousePattern[ pattern ].button = button;
     114        m_mousePattern[ pattern ].modifiers = modifiers;
    115115    }
    116116}
    117117
    118118/*!
    119   Change one key pattern
    120 
    121   \param pattern Index of the pattern
    122   \param key Key
    123   \param modifiers Keyboard modifiers
    124 
    125   \sa QKeyEvent
    126 */
     119   Change one key pattern
     120
     121   \param pattern Index of the pattern
     122   \param key Key
     123   \param modifiers Keyboard modifiers
     124
     125   \sa QKeyEvent
     126 */
    127127void QwtEventPattern::setKeyPattern( KeyPatternCode pattern,
    128128    int key, Qt::KeyboardModifiers modifiers )
    … …  
    130130    if ( pattern >= 0 && pattern < KeyPatternCount )
    131131    {
    132         d_keyPattern[ pattern ].key = key;
    133         d_keyPattern[ pattern ].modifiers = modifiers;
     132        m_keyPattern[ pattern ].key = key;
     133        m_keyPattern[ pattern ].modifiers = modifiers;
    134134    }
    135135}
    136136
    137137//! Change the mouse event patterns
    138 void QwtEventPattern::setMousePattern( const QVector<MousePattern> &pattern )
    139 {
    140     d_mousePattern = pattern;
     138void QwtEventPattern::setMousePattern( const QVector< MousePattern >& pattern )
     139{
     140    m_mousePattern = pattern;
    141141}
    142142
    143143//! Change the key event patterns
    144 void QwtEventPattern::setKeyPattern( const QVector<KeyPattern> &pattern )
    145 {
    146     d_keyPattern = pattern;
     144void QwtEventPattern::setKeyPattern( const QVector< KeyPattern >& pattern )
     145{
     146    m_keyPattern = pattern;
    147147}
    148148
    149149//! \return Mouse pattern
    150 const QVector<QwtEventPattern::MousePattern> &
     150const QVector< QwtEventPattern::MousePattern >&
    151151QwtEventPattern::mousePattern() const
    152152{
    153     return d_mousePattern;
     153    return m_mousePattern;
    154154}
    155155
    156156//! \return Key pattern
    157 const QVector<QwtEventPattern::KeyPattern> &
     157const QVector< QwtEventPattern::KeyPattern >&
    158158QwtEventPattern::keyPattern() const
    159159{
    160     return d_keyPattern;
     160    return m_keyPattern;
    161161}
    162162
    163163//! \return Mouse pattern
    164 QVector<QwtEventPattern::MousePattern> &QwtEventPattern::mousePattern()
    165 {
    166     return d_mousePattern;
     164QVector< QwtEventPattern::MousePattern >& QwtEventPattern::mousePattern()
     165{
     166    return m_mousePattern;
    167167}
    168168
    169169//! \return Key pattern
    170 QVector<QwtEventPattern::KeyPattern> &QwtEventPattern::keyPattern()
    171 {
    172     return d_keyPattern;
    173 }
    174 
    175 /*!
    176   \brief Compare a mouse event with an event pattern.
    177 
    178   A mouse event matches the pattern when both have the same button
    179   value and in the state value the same key flags(Qt::KeyButtonMask)
    180   are set.
    181 
    182   \param code Index of the event pattern
    183   \param event Mouse event
    184   \return true if matches
    185 
    186   \sa keyMatch()
    187 */
     170QVector< QwtEventPattern::KeyPattern >& QwtEventPattern::keyPattern()
     171{
     172    return m_keyPattern;
     173}
     174
     175/*!
     176   \brief Compare a mouse event with an event pattern.
     177
     178   A mouse event matches the pattern when both have the same button
     179   value and in the state value the same key flags(Qt::KeyButtonMask)
     180   are set.
     181
     182   \param code Index of the event pattern
     183   \param event Mouse event
     184   \return true if matches
     185
     186   \sa keyMatch()
     187 */
    188188bool QwtEventPattern::mouseMatch( MousePatternCode code,
    189     const QMouseEvent *event ) const
     189    const QMouseEvent* event ) const
    190190{
    191191    if ( code >= 0 && code < MousePatternCount )
    192         return mouseMatch( d_mousePattern[ code ], event );
     192        return mouseMatch( m_mousePattern[ code ], event );
    193193
    194194    return false;
    … …  
    196196
    197197/*!
    198   \brief Compare a mouse event with an event pattern.
    199 
    200   A mouse event matches the pattern when both have the same button
    201   value and in the state value the same key flags(Qt::KeyButtonMask)
    202   are set.
    203 
    204   \param pattern Mouse event pattern
    205   \param event Mouse event
    206   \return true if matches
    207 
    208   \sa keyMatch()
    209 */
    210 
    211 bool QwtEventPattern::mouseMatch( const MousePattern &pattern,
    212     const QMouseEvent *event ) const
     198   \brief Compare a mouse event with an event pattern.
     199
     200   A mouse event matches the pattern when both have the same button
     201   value and in the state value the same key flags(Qt::KeyButtonMask)
     202   are set.
     203
     204   \param pattern Mouse event pattern
     205   \param event Mouse event
     206   \return true if matches
     207
     208   \sa keyMatch()
     209 */
     210
     211bool QwtEventPattern::mouseMatch( const MousePattern& pattern,
     212    const QMouseEvent* event ) const
    213213{
    214214    if ( event == NULL )
    … …  
    220220
    221221/*!
    222   \brief Compare a key event with an event pattern.
    223 
    224   A key event matches the pattern when both have the same key
    225   value and in the state value the same key flags (Qt::KeyButtonMask)
    226   are set.
    227 
    228   \param code Index of the event pattern
    229   \param event Key event
    230   \return true if matches
    231 
    232   \sa mouseMatch()
    233 */
     222   \brief Compare a key event with an event pattern.
     223
     224   A key event matches the pattern when both have the same key
     225   value and in the state value the same key flags (Qt::KeyButtonMask)
     226   are set.
     227
     228   \param code Index of the event pattern
     229   \param event Key event
     230   \return true if matches
     231
     232   \sa mouseMatch()
     233 */
    234234bool QwtEventPattern::keyMatch( KeyPatternCode code,
    235     const QKeyEvent *event ) const
     235    const QKeyEvent* event ) const
    236236{
    237237    if ( code >= 0 && code < KeyPatternCount )
    238         return keyMatch( d_keyPattern[ code ], event );
     238        return keyMatch( m_keyPattern[ code ], event );
    239239
    240240    return false;
    … …  
    242242
    243243/*!
    244   \brief Compare a key event with an event pattern.
    245 
    246   A key event matches the pattern when both have the same key
    247   value and in the state value the same key flags (Qt::KeyButtonMask)
    248   are set.
    249 
    250   \param pattern Key event pattern
    251   \param event Key event
    252   \return true if matches
    253 
    254   \sa mouseMatch()
    255 */
     244   \brief Compare a key event with an event pattern.
     245
     246   A key event matches the pattern when both have the same key
     247   value and in the state value the same key flags (Qt::KeyButtonMask)
     248   are set.
     249
     250   \param pattern Key event pattern
     251   \param event Key event
     252   \return true if matches
     253
     254   \sa mouseMatch()
     255 */
    256256
    257257bool QwtEventPattern::keyMatch(
    258     const KeyPattern &pattern, const QKeyEvent *event ) const
     258    const KeyPattern& pattern, const QKeyEvent* event ) const
    259259{
    260260    if ( event == NULL )
  • trunk/BNC/qwt/qwt_event_pattern.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_EVENT_PATTERN
    11 #define QWT_EVENT_PATTERN 1
     11#define QWT_EVENT_PATTERN
    1212
    1313#include "qwt_global.h"
     14
    1415#include <qnamespace.h>
    1516#include <qvector.h>
    … …  
    1920
    2021/*!
    21   \brief A collection of event patterns
    22 
    23   QwtEventPattern introduces an level of indirection for mouse and
    24   keyboard inputs. Those are represented by symbolic names, so
    25   the application code can be configured by individual mappings.
    26 
    27   \sa QwtPicker, QwtPickerMachine, QwtPlotZoomer
    28 */
     22   \brief A collection of event patterns
     23
     24   QwtEventPattern introduces an level of indirection for mouse and
     25   keyboard inputs. Those are represented by symbolic names, so
     26   the application code can be configured by individual mappings.
     27
     28   \sa QwtPicker, QwtPickerMachine, QwtPlotZoomer
     29 */
    2930class QWT_EXPORT QwtEventPattern
    3031{
    31 public:
     32  public:
    3233    /*!
    33       \brief Symbolic mouse input codes
    34 
    35       QwtEventPattern implements 3 different settings for
    36       mice with 1, 2, or 3 buttons that can be activated
    37       using initMousePattern(). The default setting is for
    38       3 button mice.
    39 
    40       Individual settings can be configured using setMousePattern().
    41 
    42       \sa initMousePattern(), setMousePattern(), setKeyPattern()
    43     */
     34       \brief Symbolic mouse input codes
     35
     36       QwtEventPattern implements 3 different settings for
     37       mice with 1, 2, or 3 buttons that can be activated
     38       using initMousePattern(). The default setting is for
     39       3 button mice.
     40
     41       Individual settings can be configured using setMousePattern().
     42
     43       \sa initMousePattern(), setMousePattern(), setKeyPattern()
     44     */
    4445    enum MousePatternCode
    4546    {
    4647        /*!
    47           The default setting for 1, 2 and 3 button mice is:
    48 
    49           - Qt::LeftButton
    50           - Qt::LeftButton
    51           - Qt::LeftButton
     48           The default setting for 1, 2 and 3 button mice is:
     49
     50           - Qt::LeftButton
     51           - Qt::LeftButton
     52           - Qt::LeftButton
    5253         */
    5354        MouseSelect1,
    5455
    5556        /*!
    56           The default setting for 1, 2 and 3 button mice is:
    57 
    58           - Qt::LeftButton + Qt::ControlModifier
    59           - Qt::RightButton
    60           - Qt::RightButton
     57           The default setting for 1, 2 and 3 button mice is:
     58
     59           - Qt::LeftButton + Qt::ControlModifier
     60           - Qt::RightButton
     61           - Qt::RightButton
    6162         */
    6263        MouseSelect2,
    6364
    6465        /*!
    65           The default setting for 1, 2 and 3 button mice is:
    66 
    67           - Qt::LeftButton + Qt::AltModifier
    68           - Qt::LeftButton + Qt::AltModifier
    69           - Qt::MidButton
     66           The default setting for 1, 2 and 3 button mice is:
     67
     68           - Qt::LeftButton + Qt::AltModifier
     69           - Qt::LeftButton + Qt::AltModifier
     70           - Qt::MidButton
    7071         */
    7172        MouseSelect3,
    7273
    7374        /*!
    74           The default setting for 1, 2 and 3 button mice is:
    75 
    76           - Qt::LeftButton + Qt::ShiftModifier
    77           - Qt::LeftButton + Qt::ShiftModifier
    78           - Qt::LeftButton + Qt::ShiftModifier
     75           The default setting for 1, 2 and 3 button mice is:
     76
     77           - Qt::LeftButton + Qt::ShiftModifier
     78           - Qt::LeftButton + Qt::ShiftModifier
     79           - Qt::LeftButton + Qt::ShiftModifier
    7980         */
    8081        MouseSelect4,
    8182
    8283        /*!
    83           The default setting for 1, 2 and 3 button mice is:
    84 
    85           - Qt::LeftButton + Qt::ControlButton | Qt::ShiftModifier
    86           - Qt::RightButton + Qt::ShiftModifier
    87           - Qt::RightButton + Qt::ShiftModifier
     84           The default setting for 1, 2 and 3 button mice is:
     85
     86           - Qt::LeftButton + Qt::ControlButton | Qt::ShiftModifier
     87           - Qt::RightButton + Qt::ShiftModifier
     88           - Qt::RightButton + Qt::ShiftModifier
    8889         */
    8990        MouseSelect5,
    9091
    9192        /*!
    92           The default setting for 1, 2 and 3 button mice is:
    93 
    94           - Qt::LeftButton + Qt::AltModifier + Qt::ShiftModifier
    95           - Qt::LeftButton + Qt::AltModifier | Qt::ShiftModifier
    96           - Qt::MidButton + Qt::ShiftModifier
     93           The default setting for 1, 2 and 3 button mice is:
     94
     95           - Qt::LeftButton + Qt::AltModifier + Qt::ShiftModifier
     96           - Qt::LeftButton + Qt::AltModifier | Qt::ShiftModifier
     97           - Qt::MidButton + Qt::ShiftModifier
    9798         */
    9899        MouseSelect6,
    … …  
    103104
    104105    /*!
    105       \brief Symbolic keyboard input codes
    106 
    107       Individual settings can be configured using setKeyPattern()
    108 
    109       \sa setKeyPattern(), setMousePattern()
    110     */
     106       \brief Symbolic keyboard input codes
     107
     108       Individual settings can be configured using setKeyPattern()
     109
     110       \sa setKeyPattern(), setMousePattern()
     111     */
    111112    enum KeyPatternCode
    112113    {
    … …  
    148149    class MousePattern
    149150    {
    150     public:
     151      public:
    151152        //! Constructor
    152153        MousePattern( Qt::MouseButton btn = Qt::NoButton,
    153                 Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
     154            Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
    154155            button( btn ),
    155156            modifiers( modifierCodes )
    … …  
    167168    class KeyPattern
    168169    {
    169     public:
     170      public:
    170171        //! Constructor
    171172        KeyPattern( int keyCode = Qt::Key_unknown,
    172                 Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
     173            Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
    173174            key( keyCode ),
    174175            modifiers( modifierCodes )
    … …  
    195196        Qt::KeyboardModifiers modifiers = Qt::NoModifier );
    196197
    197     void setMousePattern( const QVector<MousePattern> & );
    198     void setKeyPattern( const QVector<KeyPattern> & );
    199 
    200     const QVector<MousePattern> &mousePattern() const;
    201     const QVector<KeyPattern> &keyPattern() const;
    202 
    203     QVector<MousePattern> &mousePattern();
    204     QVector<KeyPattern> &keyPattern();
    205 
    206     bool mouseMatch( MousePatternCode, const QMouseEvent * ) const;
    207     bool keyMatch( KeyPatternCode, const QKeyEvent * ) const;
    208 
    209 protected:
    210     virtual bool mouseMatch( const MousePattern &, const QMouseEvent * ) const;
    211     virtual bool keyMatch( const KeyPattern &, const QKeyEvent * ) const;
    212 
    213 private:
    214 
    215 #if defined(_MSC_VER)
     198    void setMousePattern( const QVector< MousePattern >& );
     199    void setKeyPattern( const QVector< KeyPattern >& );
     200
     201    const QVector< MousePattern >& mousePattern() const;
     202    const QVector< KeyPattern >& keyPattern() const;
     203
     204    QVector< MousePattern >& mousePattern();
     205    QVector< KeyPattern >& keyPattern();
     206
     207    bool mouseMatch( MousePatternCode, const QMouseEvent* ) const;
     208    bool keyMatch( KeyPatternCode, const QKeyEvent* ) const;
     209
     210  protected:
     211    virtual bool mouseMatch( const MousePattern&, const QMouseEvent* ) const;
     212    virtual bool keyMatch( const KeyPattern&, const QKeyEvent* ) const;
     213
     214  private:
     215
     216#if defined( _MSC_VER )
    216217#pragma warning(push)
    217218#pragma warning(disable: 4251)
    218219#endif
    219     QVector<MousePattern> d_mousePattern;
    220     QVector<KeyPattern> d_keyPattern;
    221 #if defined(_MSC_VER)
     220    QVector< MousePattern > m_mousePattern;
     221    QVector< KeyPattern > m_keyPattern;
     222#if defined( _MSC_VER )
    222223#pragma warning(pop)
    223224#endif
    … …  
    226227//! Compare operator
    227228inline bool operator==( QwtEventPattern::MousePattern b1,
    228     QwtEventPattern::MousePattern  b2 )
     229    QwtEventPattern::MousePattern b2 )
    229230{
    230231    return b1.button == b2.button && b1.modifiers == b2.modifiers;
    … …  
    233234//! Compare operator
    234235inline bool operator==( QwtEventPattern::KeyPattern b1,
    235    QwtEventPattern::KeyPattern  b2 )
     236    QwtEventPattern::KeyPattern b2 )
    236237{
    237238    return b1.key == b2.key && b1.modifiers == b2.modifiers;
  • trunk/BNC/qwt/qwt_global.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1515// QWT_VERSION is (major << 16) + (minor << 8) + patch.
    1616
    17 #define QWT_VERSION       0x060106
    18 #define QWT_VERSION_STR   "6.1.6"
     17#define QWT_VERSION       0x060300
     18#define QWT_VERSION_STR   "6.3.0"
    1919
    20 #if defined(_MSC_VER) /* MSVC Compiler */
     20#if defined( _MSC_VER ) /* MSVC Compiler */
    2121/* template-class specialization 'identifier' is already instantiated */
    2222#pragma warning(disable: 4660)
    … …  
    2727#ifdef QWT_DLL
    2828
    29 #if defined(QWT_MAKEDLL)     // create a Qwt DLL library
     29#if defined( QWT_MAKEDLL )     // create a Qwt DLL library
    3030#define QWT_EXPORT Q_DECL_EXPORT
    3131#else                        // use a Qwt DLL library
    … …  
    3939#endif
    4040
     41#define QWT_CONSTEXPR Q_DECL_CONSTEXPR
     42
     43#if QT_VERSION >= 0x050000
     44#define QWT_OVERRIDE Q_DECL_OVERRIDE
     45#define QWT_FINAL Q_DECL_FINAL
    4146#endif
     47
     48#ifndef QWT_CONSTEXPR
     49#define QWT_CONSTEXPR
     50#endif
     51
     52#ifndef QWT_OVERRIDE
     53#define QWT_OVERRIDE
     54#endif
     55
     56#ifndef QWT_FINAL
     57#define QWT_FINAL
     58#endif
     59
     60#endif
  • trunk/BNC/qwt/qwt_graphic.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_graphic.h"
    1111#include "qwt_painter_command.h"
     12#include "qwt_math.h"
     13
    1214#include <qvector.h>
    1315#include <qpainter.h>
    … …  
    1618#include <qpixmap.h>
    1719#include <qpainterpath.h>
    18 #include <qmath.h>
    19 
    20 static bool qwtHasScalablePen( const QPainter *painter )
     20
     21#if QT_VERSION >= 0x050000
     22
     23#include <qguiapplication.h>
     24
     25static inline qreal qwtDevicePixelRatio()
     26{
     27    return qGuiApp ? qGuiApp->devicePixelRatio() : 1.0;
     28}
     29
     30#endif
     31
     32static bool qwtHasScalablePen( const QPainter* painter )
    2133{
    2234    const QPen pen = painter->pen();
    … …  
    2739    {
    2840        scalablePen = !pen.isCosmetic();
     41#if QT_VERSION < 0x050000
    2942        if ( !scalablePen && pen.widthF() == 0.0 )
    3043        {
    … …  
    3346                scalablePen = true;
    3447        }
     48#endif
    3549    }
    3650
    … …  
    3953
    4054static QRectF qwtStrokedPathRect(
    41     const QPainter *painter, const QPainterPath &path )
     55    const QPainter* painter, const QPainterPath& path )
    4256{
    4357    QPainterPathStroker stroker;
    … …  
    5064    if ( qwtHasScalablePen( painter ) )
    5165    {
    52         QPainterPath stroke = stroker.createStroke(path);
    53         rect = painter->transform().map(stroke).boundingRect();
     66        QPainterPath stroke = stroker.createStroke( path );
     67        rect = painter->transform().map( stroke ).boundingRect();
    5468    }
    5569    else
    5670    {
    57         QPainterPath mappedPath = painter->transform().map(path);
     71        QPainterPath mappedPath = painter->transform().map( path );
    5872        mappedPath = stroker.createStroke( mappedPath );
    5973
    … …  
    6579
    6680static inline void qwtExecCommand(
    67     QPainter *painter, const QwtPainterCommand &cmd,
     81    QPainter* painter, const QwtPainterCommand& cmd,
    6882    QwtGraphic::RenderHints renderHints,
    69     const QTransform &transform,
    70     const QTransform *initialTransform )
     83    const QTransform& transform,
     84    const QTransform* initialTransform )
    7185{
    7286    switch( cmd.type() )
    … …  
    7690            bool doMap = false;
    7791
    78             if ( renderHints.testFlag( QwtGraphic::RenderPensUnscaled )
    79                 && painter->transform().isScaling() )
     92            if ( painter->transform().isScaling() )
    8093            {
    8194                bool isCosmetic = painter->pen().isCosmetic();
     95#if QT_VERSION < 0x050000
    8296                if ( isCosmetic && painter->pen().widthF() == 0.0 )
    8397                {
    … …  
    86100                        isCosmetic = false;
    87101                }
    88 
    89                 doMap = !isCosmetic;
     102#endif
     103
     104                if ( isCosmetic )
     105                {
     106                    // OpenGL2 seems to be buggy for cosmetic pens.
     107                    // It interpolates curves in too rough steps then
     108
     109                    doMap = painter->paintEngine()->type() == QPaintEngine::OpenGL2;
     110                }
     111                else
     112                {
     113                    doMap = renderHints.testFlag( QwtGraphic::RenderPensUnscaled );
     114                }
    90115            }
    91116
    … …  
    115140        case QwtPainterCommand::Pixmap:
    116141        {
    117             const QwtPainterCommand::PixmapData *data = cmd.pixmapData();
     142            const QwtPainterCommand::PixmapData* data = cmd.pixmapData();
    118143            painter->drawPixmap( data->rect, data->pixmap, data->subRect );
    119144            break;
    … …  
    121146        case QwtPainterCommand::Image:
    122147        {
    123             const QwtPainterCommand::ImageData *data = cmd.imageData();
     148            const QwtPainterCommand::ImageData* data = cmd.imageData();
    124149            painter->drawImage( data->rect, data->image,
    125150                data->subRect, data->flags );
    … …  
    128153        case QwtPainterCommand::State:
    129154        {
    130             const QwtPainterCommand::StateData *data = cmd.stateData();
     155            const QwtPainterCommand::StateData* data = cmd.stateData();
    131156
    132157            if ( data->flags & QPaintEngine::DirtyPen )
    … …  
    156181                painter->setClipping( data->isClipEnabled );
    157182
    158             if ( data->flags & QPaintEngine::DirtyClipRegion)
     183            if ( data->flags & QPaintEngine::DirtyClipRegion )
    159184            {
    160185                painter->setClipRegion( data->clipRegion,
    … …  
    167192            }
    168193
    169             if ( data->flags & QPaintEngine::DirtyHints)
     194            if ( data->flags & QPaintEngine::DirtyHints )
    170195            {
    171                 const QPainter::RenderHints hints = data->renderHints;
    172 
    173                 painter->setRenderHint( QPainter::Antialiasing,
    174                     hints.testFlag( QPainter::Antialiasing ) );
    175 
    176                 painter->setRenderHint( QPainter::TextAntialiasing,
    177                     hints.testFlag( QPainter::TextAntialiasing ) );
    178 
    179                 painter->setRenderHint( QPainter::SmoothPixmapTransform,
    180                     hints.testFlag( QPainter::SmoothPixmapTransform ) );
    181 
    182                 painter->setRenderHint( QPainter::HighQualityAntialiasing,
    183                     hints.testFlag( QPainter::HighQualityAntialiasing ) );
    184 
    185                 painter->setRenderHint( QPainter::NonCosmeticDefaultPen,
    186                     hints.testFlag( QPainter::NonCosmeticDefaultPen ) );
     196                for ( int i = 0; i < 8; i++ )
     197                {
     198                    const QPainter::RenderHint hint = static_cast< QPainter::RenderHint >( 1 << i );
     199                    painter->setRenderHint( hint, data->renderHints.testFlag( hint ) );
     200                }
    187201            }
    188202
    189             if ( data->flags & QPaintEngine::DirtyCompositionMode)
     203            if ( data->flags & QPaintEngine::DirtyCompositionMode )
    190204                painter->setCompositionMode( data->compositionMode );
    191205
    192             if ( data->flags & QPaintEngine::DirtyOpacity)
     206            if ( data->flags & QPaintEngine::DirtyOpacity )
    193207                painter->setOpacity( data->opacity );
    194208
    … …  
    198212            break;
    199213    }
    200 
    201214}
    202215
    203216class QwtGraphic::PathInfo
    204217{
    205 public:
    206     PathInfo():
    207         d_scalablePen( false )
     218  public:
     219    PathInfo()
     220        : m_scalablePen( false )
    208221    {
    209222        // QVector needs a default constructor
    210223    }
    211224
    212     PathInfo( const QRectF &pointRect,
    213             const QRectF &boundingRect, bool scalablePen ):
    214         d_pointRect( pointRect ),
    215         d_boundingRect( boundingRect ),
    216         d_scalablePen( scalablePen )
    217     {
    218     }
    219 
    220     inline QRectF scaledBoundingRect( double sx, double sy,
    221         bool scalePens ) const
     225    PathInfo( const QRectF& pointRect,
     226            const QRectF& boundingRect, bool scalablePen )
     227        : m_pointRect( pointRect )
     228        , m_boundingRect( boundingRect )
     229        , m_scalablePen( scalablePen )
     230    {
     231    }
     232
     233    inline QRectF scaledBoundingRect( qreal sx, qreal sy, bool scalePens ) const
    222234    {
    223235        if ( sx == 1.0 && sy == 1.0 )
    224             return d_boundingRect;
     236            return m_boundingRect;
    225237
    226238        QTransform transform;
    … …  
    228240
    229241        QRectF rect;
    230         if ( scalePens && d_scalablePen )
    231         {
    232             rect = transform.mapRect( d_boundingRect );
     242        if ( scalePens && m_scalablePen )
     243        {
     244            rect = transform.mapRect( m_boundingRect );
    233245        }
    234246        else
    235247        {
    236             rect = transform.mapRect( d_pointRect );
    237 
    238             const double l = qAbs( d_pointRect.left() - d_boundingRect.left() );
    239             const double r = qAbs( d_pointRect.right() - d_boundingRect.right() );
    240             const double t = qAbs( d_pointRect.top() - d_boundingRect.top() );
    241             const double b = qAbs( d_pointRect.bottom() - d_boundingRect.bottom() );
     248            rect = transform.mapRect( m_pointRect );
     249
     250            const qreal l = qAbs( m_pointRect.left() - m_boundingRect.left() );
     251            const qreal r = qAbs( m_pointRect.right() - m_boundingRect.right() );
     252            const qreal t = qAbs( m_pointRect.top() - m_boundingRect.top() );
     253            const qreal b = qAbs( m_pointRect.bottom() - m_boundingRect.bottom() );
    242254
    243255            rect.adjust( -l, -t, r, b );
    … …  
    248260
    249261    inline double scaleFactorX( const QRectF& pathRect,
    250         const QRectF &targetRect, bool scalePens ) const
     262        const QRectF& targetRect, bool scalePens ) const
    251263    {
    252264        if ( pathRect.width() <= 0.0 )
    253265            return 0.0;
    254266
    255         const QPointF p0 = d_pointRect.center();
    256 
    257         const double l = qAbs( pathRect.left() - p0.x() );
    258         const double r = qAbs( pathRect.right() - p0.x() );
    259 
    260         const double w = 2.0 * qMin( l, r )
     267        const QPointF p0 = m_pointRect.center();
     268
     269        const qreal l = qAbs( pathRect.left() - p0.x() );
     270        const qreal r = qAbs( pathRect.right() - p0.x() );
     271
     272        const double w = 2.0 * qwtMinF( l, r )
    261273            * targetRect.width() / pathRect.width();
    262274
    263275        double sx;
    264         if ( scalePens && d_scalablePen )
    265         {
    266             sx = w / d_boundingRect.width();
     276        if ( scalePens && m_scalablePen )
     277        {
     278            sx = w / m_boundingRect.width();
    267279        }
    268280        else
    269281        {
    270             const double pw = qMax(
    271                 qAbs( d_boundingRect.left() - d_pointRect.left() ),
    272                 qAbs( d_boundingRect.right() - d_pointRect.right() ) );
    273 
    274             sx = ( w - 2 * pw ) / d_pointRect.width();
     282            const qreal pw = qwtMaxF(
     283                qAbs( m_boundingRect.left() - m_pointRect.left() ),
     284                qAbs( m_boundingRect.right() - m_pointRect.right() ) );
     285
     286            sx = ( w - 2 * pw ) / m_pointRect.width();
    275287        }
    276288
    … …  
    279291
    280292    inline double scaleFactorY( const QRectF& pathRect,
    281         const QRectF &targetRect, bool scalePens ) const
     293        const QRectF& targetRect, bool scalePens ) const
    282294    {
    283295        if ( pathRect.height() <= 0.0 )
    284296            return 0.0;
    285297
    286         const QPointF p0 = d_pointRect.center();
    287 
    288         const double t = qAbs( pathRect.top() - p0.y() );
    289         const double b = qAbs( pathRect.bottom() - p0.y() );
    290 
    291         const double h = 2.0 * qMin( t, b )
     298        const QPointF p0 = m_pointRect.center();
     299
     300        const qreal t = qAbs( pathRect.top() - p0.y() );
     301        const qreal b = qAbs( pathRect.bottom() - p0.y() );
     302
     303        const qreal h = 2.0 * qwtMinF( t, b )
    292304            * targetRect.height() / pathRect.height();
    293305
    294306        double sy;
    295         if ( scalePens && d_scalablePen )
    296         {
    297             sy = h / d_boundingRect.height();
     307        if ( scalePens && m_scalablePen )
     308        {
     309            sy = h / m_boundingRect.height();
    298310        }
    299311        else
    300312        {
    301             const double pw =
    302                 qMax( qAbs( d_boundingRect.top() - d_pointRect.top() ),
    303                 qAbs( d_boundingRect.bottom() - d_pointRect.bottom() ) );
    304 
    305             sy = ( h - 2 * pw ) / d_pointRect.height();
     313            const qreal pw = qwtMaxF(
     314                qAbs( m_boundingRect.top() - m_pointRect.top() ),
     315                qAbs( m_boundingRect.bottom() - m_pointRect.bottom() ) );
     316
     317            sy = ( h - 2 * pw ) / m_pointRect.height();
    306318        }
    307319
    … …  
    309321    }
    310322
    311 private:
    312     QRectF d_pointRect;
    313     QRectF d_boundingRect;
    314     bool d_scalablePen;
     323  private:
     324    QRectF m_pointRect;
     325    QRectF m_boundingRect;
     326    bool m_scalablePen;
    315327};
    316328
    317329class QwtGraphic::PrivateData
    318330{
    319 public:
    320     PrivateData():
    321         boundingRect( 0.0, 0.0, -1.0, -1.0 ),
    322         pointRect( 0.0, 0.0, -1.0, -1.0 ),
    323         initialTransform( NULL )
     331  public:
     332    PrivateData()
     333        : boundingRect( 0.0, 0.0, -1.0, -1.0 )
     334        , pointRect( 0.0, 0.0, -1.0, -1.0 )
    324335    {
    325336    }
    326337
    327338    QSizeF defaultSize;
    328     QVector<QwtPainterCommand> commands;
    329     QVector<QwtGraphic::PathInfo> pathInfos;
     339    QVector< QwtPainterCommand > commands;
     340    QVector< QwtGraphic::PathInfo > pathInfos;
    330341
    331342    QRectF boundingRect;
    332343    QRectF pointRect;
    333344
     345    QwtGraphic::CommandTypes commandTypes;
    334346    QwtGraphic::RenderHints renderHints;
    335     QTransform *initialTransform;
    336347};
    337348
    338349/*!
    339   \brief Constructor
    340 
    341   Initializes a null graphic
    342   \sa isNull()
    343  */
    344 QwtGraphic::QwtGraphic():
    345     QwtNullPaintDevice()
     350   \brief Constructor
     351
     352   Initializes a null graphic
     353   \sa isNull()
     354 */
     355QwtGraphic::QwtGraphic()
    346356{
    347357    setMode( QwtNullPaintDevice::PathMode );
    348     d_data = new PrivateData;
    349 }
    350 
    351 /*!
    352   \brief Copy constructor
    353 
    354   \param other Source
    355   \sa operator=()
    356  */
    357 QwtGraphic::QwtGraphic( const QwtGraphic &other ):
    358     QwtNullPaintDevice()
     358    m_data = new PrivateData;
     359}
     360
     361/*!
     362   \brief Copy constructor
     363
     364   \param other Source
     365   \sa operator=()
     366 */
     367QwtGraphic::QwtGraphic( const QwtGraphic& other )
    359368{
    360369    setMode( other.mode() );
    361     d_data = new PrivateData( *other.d_data );
     370    m_data = new PrivateData( *other.m_data );
    362371}
    363372
    … …  
    365374QwtGraphic::~QwtGraphic()
    366375{
    367     delete d_data;
    368 }
    369 
    370 /*!
    371   \brief Assignment operator
    372 
    373   \param other Source
    374   \return A reference of this object
    375  */
    376 QwtGraphic& QwtGraphic::operator=(const QwtGraphic &other)
     376    delete m_data;
     377}
     378
     379/*!
     380   \brief Assignment operator
     381
     382   \param other Source
     383   \return A reference of this object
     384 */
     385QwtGraphic& QwtGraphic::operator=( const QwtGraphic& other )
    377386{
    378387    setMode( other.mode() );
    379     *d_data = *other.d_data;
     388    *m_data = *other.m_data;
    380389
    381390    return *this;
    … …  
    383392
    384393/*!
    385   \brief Clear all stored commands
    386   \sa isNull()
     394   \brief Clear all stored commands
     395   \sa isNull()
    387396 */
    388397void QwtGraphic::reset()
    389398{
    390     d_data->commands.clear();
    391     d_data->pathInfos.clear();
    392 
    393     d_data->boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
    394     d_data->pointRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
    395     d_data->defaultSize = QSizeF();
    396 
    397 }
    398 
    399 /*!
    400   \return True, when no painter commands have been stored
    401   \sa isEmpty(), commands()
    402 */
     399    m_data->commands.clear();
     400    m_data->pathInfos.clear();
     401
     402    m_data->commandTypes = CommandTypes();
     403
     404    m_data->boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
     405    m_data->pointRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
     406    m_data->defaultSize = QSizeF();
     407}
     408
     409/*!
     410   \return True, when no painter commands have been stored
     411   \sa isEmpty(), commands()
     412 */
    403413bool QwtGraphic::isNull() const
    404414{
    405     return d_data->commands.isEmpty();
    406 }
    407 
    408 /*!
    409   \return True, when the bounding rectangle is empty
    410   \sa boundingRect(), isNull()
    411 */
     415    return m_data->commands.isEmpty();
     416}
     417
     418/*!
     419   \return True, when the bounding rectangle is empty
     420   \sa boundingRect(), isNull()
     421 */
    412422bool QwtGraphic::isEmpty() const
    413423{
    414     return d_data->boundingRect.isEmpty();
    415 }
    416 
    417 /*!
    418   Toggle an render hint
    419 
    420   \param hint Render hint
    421   \param on true/false
    422 
    423   \sa testRenderHint(), RenderHint
    424 */
     424    return m_data->boundingRect.isEmpty();
     425}
     426
     427/*!
     428   \return Types of painter commands being used
     429 */
     430QwtGraphic::CommandTypes QwtGraphic::commandTypes() const
     431{
     432    return m_data->commandTypes;
     433}
     434
     435/*!
     436   Toggle an render hint
     437
     438   \param hint Render hint
     439   \param on true/false
     440
     441   \sa testRenderHint(), RenderHint
     442 */
    425443void QwtGraphic::setRenderHint( RenderHint hint, bool on )
    426444{
    427445    if ( on )
    428         d_data->renderHints |= hint;
     446        m_data->renderHints |= hint;
    429447    else
    430         d_data->renderHints &= ~hint;
    431 }
    432 
    433 /*!
    434   Test a render hint
    435 
    436   \param hint Render hint
    437   \return true/false
    438   \sa setRenderHint(), RenderHint
    439 */
     448        m_data->renderHints &= ~hint;
     449}
     450
     451/*!
     452   Test a render hint
     453
     454   \param hint Render hint
     455   \return true/false
     456   \sa setRenderHint(), RenderHint
     457 */
    440458bool QwtGraphic::testRenderHint( RenderHint hint ) const
    441459{
    442     return d_data->renderHints.testFlag( hint );
    443 }
    444 
    445 /*!
    446   The bounding rectangle is the controlPointRect()
    447   extended by the areas needed for rendering the outlines
    448   with unscaled pens.
    449 
    450   \return Bounding rectangle of the graphic
    451   \sa controlPointRect(), scaledBoundingRect()
     460    return m_data->renderHints.testFlag( hint );
     461}
     462
     463//! \return Render hints
     464QwtGraphic::RenderHints QwtGraphic::renderHints() const
     465{
     466    return m_data->renderHints;
     467}
     468
     469/*!
     470   The bounding rectangle is the controlPointRect()
     471   extended by the areas needed for rendering the outlines
     472   with unscaled pens.
     473
     474   \return Bounding rectangle of the graphic
     475   \sa controlPointRect(), scaledBoundingRect()
    452476 */
    453477QRectF QwtGraphic::boundingRect() const
    454478{
    455     if ( d_data->boundingRect.width() < 0 )
     479    if ( m_data->boundingRect.width() < 0 )
    456480        return QRectF();
    457481
    458     return d_data->boundingRect;
    459 }
    460 
    461 /*!
    462   The control point rectangle is the bounding rectangle
    463   of all control points of the paths and the target
    464   rectangles of the images/pixmaps.
    465 
    466   \return Control point rectangle
    467   \sa boundingRect(), scaledBoundingRect()
     482    return m_data->boundingRect;
     483}
     484
     485/*!
     486   The control point rectangle is the bounding rectangle
     487   of all control points of the paths and the target
     488   rectangles of the images/pixmaps.
     489
     490   \return Control point rectangle
     491   \sa boundingRect(), scaledBoundingRect()
    468492 */
    469493QRectF QwtGraphic::controlPointRect() const
    470494{
    471     if ( d_data->pointRect.width() < 0 )
     495    if ( m_data->pointRect.width() < 0 )
    472496        return QRectF();
    473497
    474     return d_data->pointRect;
    475 }
    476 
    477 /*!
    478   \brief Calculate the target rectangle for scaling the graphic
    479 
    480   \param sx Horizontal scaling factor
    481   \param sy Vertical scaling factor
    482 
    483   \note In case of paths that are painted with a cosmetic pen
     498    return m_data->pointRect;
     499}
     500
     501/*!
     502   \brief Calculate the target rectangle for scaling the graphic
     503
     504   \param sx Horizontal scaling factor
     505   \param sy Vertical scaling factor
     506
     507   \note In case of paths that are painted with a cosmetic pen
    484508        ( see QPen::isCosmetic() ) the target rectangle is different to
    485509        multiplying the bounding rectangle.
    486510
    487   \return Scaled bounding rectangle
    488   \sa boundingRect(), controlPointRect()
    489  */
    490 QRectF QwtGraphic::scaledBoundingRect( double sx, double sy ) const
     511   \return Scaled bounding rectangle
     512   \sa boundingRect(), controlPointRect()
     513 */
     514QRectF QwtGraphic::scaledBoundingRect( qreal sx, qreal sy ) const
    491515{
    492516    if ( sx == 1.0 && sy == 1.0 )
    493         return d_data->boundingRect;
     517        return m_data->boundingRect;
     518
     519    const bool scalePens = !( m_data->renderHints & RenderPensUnscaled );
    494520
    495521    QTransform transform;
    496522    transform.scale( sx, sy );
    497523
    498     QRectF rect = transform.mapRect( d_data->pointRect );
    499 
    500     for ( int i = 0; i < d_data->pathInfos.size(); i++ )
    501     {
    502         rect |= d_data->pathInfos[i].scaledBoundingRect( sx, sy,
    503             !d_data->renderHints.testFlag( RenderPensUnscaled ) );
    504     }
     524    QRectF rect = transform.mapRect( m_data->pointRect );
     525
     526    for ( int i = 0; i < m_data->pathInfos.size(); i++ )
     527        rect |= m_data->pathInfos[i].scaledBoundingRect( sx, sy, scalePens );
    505528
    506529    return rect;
    … …  
    511534{
    512535    const QSizeF sz = defaultSize();
    513     return QSize( qCeil( sz.width() ), qCeil( sz.height() ) );
    514 }
    515 
    516 /*!
    517   \brief Set a default size
    518 
    519   The default size is used in all methods rendering the graphic,
    520   where no size is explicitly specified. Assigning an empty size
    521   means, that the default size will be calculated from the bounding
    522   rectangle.
    523 
    524   The default setting is an empty size.
    525 
    526   \param size Default size
    527 
    528   \sa defaultSize(), boundingRect()
    529  */
    530 void QwtGraphic::setDefaultSize( const QSizeF &size )
    531 {
    532     const double w = qMax( qreal( 0.0 ), size.width() );
    533     const double h = qMax( qreal( 0.0 ), size.height() );
    534 
    535     d_data->defaultSize = QSizeF( w, h );
    536 }
    537 
    538 /*!
    539   \brief Default size
    540 
    541   When a non empty size has been assigned by setDefaultSize() this
    542   size will be returned. Otherwise the default size is the size
    543   of the bounding rectangle.
    544 
    545   The default size is used in all methods rendering the graphic,
    546   where no size is explicitly specified.
    547 
    548   \return Default size
    549   \sa setDefaultSize(), boundingRect()
     536    return QSize( qwtCeil( sz.width() ), qwtCeil( sz.height() ) );
     537}
     538
     539/*!
     540   \brief Set a default size
     541
     542   The default size is used in all methods rendering the graphic,
     543   where no size is explicitly specified. Assigning an empty size
     544   means, that the default size will be calculated from the bounding
     545   rectangle.
     546
     547   The default setting is an empty size.
     548
     549   \param size Default size
     550
     551   \sa defaultSize(), boundingRect()
     552 */
     553void QwtGraphic::setDefaultSize( const QSizeF& size )
     554{
     555    const double w = qwtMaxF( 0.0, size.width() );
     556    const double h = qwtMaxF( 0.0, size.height() );
     557
     558    m_data->defaultSize = QSizeF( w, h );
     559}
     560
     561/*!
     562   \brief Default size
     563
     564   When a non empty size has been assigned by setDefaultSize() this
     565   size will be returned. Otherwise the default size is the size
     566   of the bounding rectangle.
     567
     568   The default size is used in all methods rendering the graphic,
     569   where no size is explicitly specified.
     570
     571   \return Default size
     572   \sa setDefaultSize(), boundingRect()
    550573 */
    551574QSizeF QwtGraphic::defaultSize() const
    552575{
    553     if ( !d_data->defaultSize.isEmpty() )
    554         return d_data->defaultSize;
     576    if ( !m_data->defaultSize.isEmpty() )
     577        return m_data->defaultSize;
    555578
    556579    return boundingRect().size();
    … …  
    558581
    559582/*!
    560   \brief Replay all recorded painter commands
    561   \param painter Qt painter
    562  */
    563 void QwtGraphic::render( QPainter *painter ) const
     583   Find the height for a given width
     584
     585   The height is calculated using the aspect ratio of defaultSize().
     586
     587   \param width Width
     588
     589   \return Calculated height
     590   \sa defaultSize()
     591 */
     592qreal QwtGraphic::heightForWidth( qreal width ) const
     593{
     594    const QSizeF sz = defaultSize();
     595    if ( sz.isEmpty() )
     596        return 0.0;
     597
     598    return sz.height() * width / sz.width();
     599}
     600
     601/*!
     602   Find the width for a given height
     603
     604   The width is calculated using the aspect ratio of defaultSize().
     605
     606   \param height Height
     607
     608   \return Calculated width
     609   \sa defaultSize()
     610 */
     611qreal QwtGraphic::widthForHeight( qreal height ) const
     612{
     613    const QSizeF sz = defaultSize();
     614    if ( sz.isEmpty() )
     615        return 0.0;
     616
     617    return sz.width() * height / sz.height();
     618}
     619
     620/*!
     621   \brief Replay all recorded painter commands
     622   \param painter Qt painter
     623 */
     624void QwtGraphic::render( QPainter* painter ) const
     625{
     626    renderGraphic( painter, NULL );
     627}
     628
     629void QwtGraphic::renderGraphic( QPainter* painter, QTransform* initialTransform ) const
    564630{
    565631    if ( isNull() )
    566632        return;
    567633
    568     const int numCommands = d_data->commands.size();
    569     const QwtPainterCommand *commands = d_data->commands.constData();
     634    const int numCommands = m_data->commands.size();
     635    const QwtPainterCommand* commands = m_data->commands.constData();
    570636
    571637    const QTransform transform = painter->transform();
    … …  
    576642    {
    577643        qwtExecCommand( painter, commands[i],
    578             d_data->renderHints, transform, d_data->initialTransform );
     644            m_data->renderHints, transform, initialTransform );
    579645    }
    580646
    … …  
    583649
    584650/*!
    585   \brief Replay all recorded painter commands
    586 
    587   The graphic is scaled to fit into the rectangle
    588   of the given size starting at ( 0, 0 ).
    589 
    590   \param painter Qt painter
    591   \param size Size for the scaled graphic
    592   \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode
    593  */
    594 void QwtGraphic::render( QPainter *painter, const QSizeF &size,
     651   \brief Replay all recorded painter commands
     652
     653   The graphic is scaled to fit into the rectangle
     654   of the given size starting at ( 0, 0 ).
     655
     656   \param painter Qt painter
     657   \param size Size for the scaled graphic
     658   \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode
     659 */
     660void QwtGraphic::render( QPainter* painter, const QSizeF& size,
    595661    Qt::AspectRatioMode aspectRatioMode ) const
    596662{
    … …  
    600666
    601667/*!
    602   \brief Replay all recorded painter commands
    603 
    604   The graphic is scaled to fit into the given rectangle
    605 
    606   \param painter Qt painter
    607   \param rect Rectangle for the scaled graphic
    608   \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode
    609  */
    610 void QwtGraphic::render( QPainter *painter, const QRectF &rect,
     668   \brief Replay all recorded painter commands
     669
     670   The graphic is scaled to fit into the given rectangle
     671
     672   \param painter Qt painter
     673   \param rect Rectangle for the scaled graphic
     674   \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode
     675 */
     676void QwtGraphic::render( QPainter* painter, const QRectF& rect,
    611677    Qt::AspectRatioMode aspectRatioMode ) const
    612678{
    … …  
    617683    double sy = 1.0;
    618684
    619     if ( d_data->pointRect.width() > 0.0 )
    620         sx = rect.width() / d_data->pointRect.width();
    621 
    622     if ( d_data->pointRect.height() > 0.0 )
    623         sy = rect.height() / d_data->pointRect.height();
    624 
    625     const bool scalePens =
    626         !d_data->renderHints.testFlag( RenderPensUnscaled );
    627 
    628     for ( int i = 0; i < d_data->pathInfos.size(); i++ )
    629     {
    630         const PathInfo info = d_data->pathInfos[i];
     685    if ( m_data->pointRect.width() > 0.0 )
     686        sx = rect.width() / m_data->pointRect.width();
     687
     688    if ( m_data->pointRect.height() > 0.0 )
     689        sy = rect.height() / m_data->pointRect.height();
     690
     691    const bool scalePens = !m_data->renderHints.testFlag( RenderPensUnscaled );
     692
     693    for ( int i = 0; i < m_data->pathInfos.size(); i++ )
     694    {
     695        const PathInfo& info = m_data->pathInfos[i];
    631696
    632697        const double ssx = info.scaleFactorX(
    633             d_data->pointRect, rect, scalePens );
     698            m_data->pointRect, rect, scalePens );
    634699
    635700        if ( ssx > 0.0 )
    636             sx = qMin( sx, ssx );
     701            sx = qwtMinF( sx, ssx );
    637702
    638703        const double ssy = info.scaleFactorY(
    639             d_data->pointRect, rect, scalePens );
     704            m_data->pointRect, rect, scalePens );
    640705
    641706        if ( ssy > 0.0 )
    642             sy = qMin( sy, ssy );
     707            sy = qwtMinF( sy, ssy );
    643708    }
    644709
    645710    if ( aspectRatioMode == Qt::KeepAspectRatio )
    646711    {
    647         const double s = qMin( sx, sy );
     712        const qreal s = qwtMinF( sx, sy );
    648713        sx = s;
    649714        sy = s;
    … …  
    651716    else if ( aspectRatioMode == Qt::KeepAspectRatioByExpanding )
    652717    {
    653         const double s = qMax( sx, sy );
     718        const qreal s = qwtMaxF( sx, sy );
    654719        sx = s;
    655720        sy = s;
    … …  
    657722
    658723    QTransform tr;
    659     tr.translate( rect.center().x() - 0.5 * sx * d_data->pointRect.width(),
    660         rect.center().y() - 0.5 * sy * d_data->pointRect.height() );
     724    tr.translate( rect.center().x() - 0.5 * sx * m_data->pointRect.width(),
     725        rect.center().y() - 0.5 * sy * m_data->pointRect.height() );
    661726    tr.scale( sx, sy );
    662     tr.translate( -d_data->pointRect.x(), -d_data->pointRect.y() );
     727    tr.translate( -m_data->pointRect.x(), -m_data->pointRect.y() );
    663728
    664729    const QTransform transform = painter->transform();
     730
     731    painter->setTransform( tr, true );
     732
    665733    if ( !scalePens && transform.isScaling() )
    666734    {
    … …  
    669737        // painter transformation later
    670738
    671         d_data->initialTransform = new QTransform();
    672         d_data->initialTransform->scale( transform.m11(), transform.m22() );
    673     }
    674 
    675     painter->setTransform( tr, true );
    676     render( painter );
     739        QTransform initialTransform;
     740        initialTransform.scale( transform.m11(), transform.m22() );
     741
     742        renderGraphic( painter, &initialTransform );
     743    }
     744    else
     745    {
     746        renderGraphic( painter, NULL );
     747    }
    677748
    678749    painter->setTransform( transform );
    679 
    680     delete d_data->initialTransform;
    681     d_data->initialTransform = NULL;
    682 }
    683 
    684 /*!
    685   \brief Replay all recorded painter commands
    686 
    687   The graphic is scaled to the defaultSize() and aligned
    688   to a position.
    689 
    690   \param painter Qt painter
    691   \param pos Reference point, where to render
    692   \param alignment Flags how to align the target rectangle
    693                    to pos.
    694  */
    695 void QwtGraphic::render( QPainter *painter,
    696     const QPointF &pos, Qt::Alignment alignment ) const
     750}
     751
     752/*!
     753   \brief Replay all recorded painter commands
     754
     755   The graphic is scaled to the defaultSize() and aligned
     756   to a position.
     757
     758   \param painter Qt painter
     759   \param pos Reference point, where to render
     760   \param alignment Flags how to align the target rectangle to pos.
     761 */
     762void QwtGraphic::render( QPainter* painter,
     763    const QPointF& pos, Qt::Alignment alignment ) const
    697764{
    698765    QRectF r( pos, defaultSize() );
    … …  
    728795
    729796/*!
    730   \brief Convert the graphic to a QPixmap
    731 
    732   All pixels of the pixmap get initialized by Qt::transparent
    733   before the graphic is scaled and rendered on it.
    734 
    735   The size of the pixmap is the default size ( ceiled to integers )
    736   of the graphic.
    737 
    738   \return The graphic as pixmap in default size
    739   \sa defaultSize(), toImage(), render()
    740  */
    741 QPixmap QwtGraphic::toPixmap() const
     797   \brief Convert the graphic to a QPixmap
     798
     799   All pixels of the pixmap get initialized by Qt::transparent
     800   before the graphic is scaled and rendered on it.
     801
     802   The size of the pixmap is the default size ( ceiled to integers )
     803   of the graphic.
     804
     805   \param devicePixelRatio Device pixel ratio for the pixmap.
     806                          If devicePixelRatio <= 0.0 the pixmap
     807                          is initialized with the system default.
     808
     809   \return The graphic as pixmap in default size
     810   \sa defaultSize(), toImage(), render()
     811 */
     812QPixmap QwtGraphic::toPixmap( qreal devicePixelRatio ) const
    742813{
    743814    if ( isNull() )
    … …  
    746817    const QSizeF sz = defaultSize();
    747818
    748     const int w = qCeil( sz.width() );
    749     const int h = qCeil( sz.height() );
     819#if QT_VERSION >= 0x050000
     820    if ( devicePixelRatio <= 0.0 )
     821        devicePixelRatio = qwtDevicePixelRatio();
     822
     823    const int w = qwtCeil( sz.width() * devicePixelRatio );
     824    const int h = qwtCeil( sz.height() * devicePixelRatio );
    750825
    751826    QPixmap pixmap( w, h );
     827    pixmap.setDevicePixelRatio( devicePixelRatio );
     828#else
     829    Q_UNUSED( devicePixelRatio )
     830
     831    const int w = qwtCeil( sz.width() );
     832    const int h = qwtCeil( sz.height() );
     833
     834    QPixmap pixmap( w, h );
     835#endif
     836
    752837    pixmap.fill( Qt::transparent );
    753838
    … …  
    762847
    763848/*!
    764   \brief Convert the graphic to a QPixmap
    765 
    766   All pixels of the pixmap get initialized by Qt::transparent
    767   before the graphic is scaled and rendered on it.
    768 
    769   \param size Size of the image
    770   \param aspectRatioMode Aspect ratio how to scale the graphic
    771 
    772   \return The graphic as pixmap
    773   \sa toImage(), render()
    774  */
    775 QPixmap QwtGraphic::toPixmap( const QSize &size,
    776     Qt::AspectRatioMode aspectRatioMode ) const
    777 {
     849   \brief Convert the graphic to a QPixmap
     850
     851   All pixels of the pixmap get initialized by Qt::transparent
     852   before the graphic is scaled and rendered on it.
     853
     854   \param size Size of the image
     855   \param aspectRatioMode Aspect ratio how to scale the graphic
     856   \param devicePixelRatio Device pixel ratio for the pixmap.
     857                          If devicePixelRatio <= 0.0 the pixmap
     858                          is initialized with the system default.
     859
     860   \return The graphic as pixmap
     861   \sa toImage(), render()
     862 */
     863QPixmap QwtGraphic::toPixmap( const QSize& size,
     864    Qt::AspectRatioMode aspectRatioMode, qreal devicePixelRatio ) const
     865{
     866#if QT_VERSION >= 0x050000
     867    if ( devicePixelRatio <= 0.0 )
     868        devicePixelRatio = qwtDevicePixelRatio();
     869
     870    const int w = qwtCeil( size.width() * devicePixelRatio );
     871    const int h = qwtCeil( size.height() * devicePixelRatio );
     872
     873    QPixmap pixmap( w, h );
     874    pixmap.setDevicePixelRatio( devicePixelRatio );
     875#else
     876    Q_UNUSED( devicePixelRatio )
    778877    QPixmap pixmap( size );
     878#endif
    779879    pixmap.fill( Qt::transparent );
    780880
    … …  
    789889
    790890/*!
    791   \brief Convert the graphic to a QImage
    792 
    793   All pixels of the image get initialized by 0 ( transparent )
    794   before the graphic is scaled and rendered on it.
    795 
    796   The format of the image is QImage::Format_ARGB32_Premultiplied.
    797 
    798   \param size Size of the image
    799   \param aspectRatioMode Aspect ratio how to scale the graphic
    800 
    801   \return The graphic as image
    802   \sa toPixmap(), render()
    803  */
    804 QImage QwtGraphic::toImage( const QSize &size,
    805     Qt::AspectRatioMode aspectRatioMode  ) const
    806 {
     891   \brief Convert the graphic to a QImage
     892
     893   All pixels of the image get initialized by 0 ( transparent )
     894   before the graphic is scaled and rendered on it.
     895
     896   The format of the image is QImage::Format_ARGB32_Premultiplied.
     897
     898   \param size Size of the image ( will be multiplied by the devicePixelRatio )
     899   \param aspectRatioMode Aspect ratio how to scale the graphic
     900   \param devicePixelRatio Device pixel ratio for the image.
     901                          If devicePixelRatio <= 0.0 the pixmap
     902                          is initialized with the system default.
     903
     904   \return The graphic as image
     905   \sa toPixmap(), render()
     906 */
     907QImage QwtGraphic::toImage( const QSize& size,
     908    Qt::AspectRatioMode aspectRatioMode, qreal devicePixelRatio  ) const
     909{
     910#if QT_VERSION >= 0x050000
     911    if ( devicePixelRatio <= 0.0 )
     912        devicePixelRatio = qwtDevicePixelRatio();
     913
     914    const int w = qwtCeil( size.width() * devicePixelRatio );
     915    const int h = qwtCeil( size.height() * devicePixelRatio );
     916
     917    QImage image( w, h, QImage::Format_ARGB32_Premultiplied );
     918    image.setDevicePixelRatio( devicePixelRatio );
     919#else
     920    Q_UNUSED( devicePixelRatio )
    807921    QImage image( size, QImage::Format_ARGB32_Premultiplied );
     922#endif
     923
    808924    image.fill( 0 );
    809925
    … …  
    818934
    819935/*!
    820   \brief Convert the graphic to a QImage
    821 
    822   All pixels of the image get initialized by 0 ( transparent )
    823   before the graphic is scaled and rendered on it.
    824 
    825   The format of the image is QImage::Format_ARGB32_Premultiplied.
    826 
    827   The size of the image is the default size ( ceiled to integers )
    828   of the graphic.
    829 
    830   \return The graphic as image in default size
    831   \sa defaultSize(), toPixmap(), render()
    832  */
    833 QImage QwtGraphic::toImage() const
     936   \brief Convert the graphic to a QImage
     937
     938   All pixels of the image get initialized by 0 ( transparent )
     939   before the graphic is scaled and rendered on it.
     940
     941   The format of the image is QImage::Format_ARGB32_Premultiplied.
     942
     943   The size of the image is the default size ( ceiled to integers )
     944   of the graphic multiplied by the devicePixelRatio.
     945
     946   \param devicePixelRatio Device pixel ratio for the image.
     947                          If devicePixelRatio <= 0.0 the pixmap
     948                          is initialized with the system default.
     949
     950   \return The graphic as image in default size
     951   \sa defaultSize(), toPixmap(), render()
     952 */
     953QImage QwtGraphic::toImage( qreal devicePixelRatio ) const
    834954{
    835955    if ( isNull() )
    … …  
    838958    const QSizeF sz = defaultSize();
    839959
    840     const int w = qCeil( sz.width() );
    841     const int h = qCeil( sz.height() );
     960#if QT_VERSION >= 0x050000
     961    if ( devicePixelRatio <= 0.0 )
     962        devicePixelRatio = qwtDevicePixelRatio();
     963
     964    const int w = qwtCeil( sz.width() * devicePixelRatio );
     965    const int h = qwtCeil( sz.height() * devicePixelRatio );
    842966
    843967    QImage image( w, h, QImage::Format_ARGB32 );
     968    image.setDevicePixelRatio( devicePixelRatio );
     969#else
     970    Q_UNUSED( devicePixelRatio )
     971
     972    const int w = qwtCeil( sz.width() );
     973    const int h = qwtCeil( sz.height() );
     974
     975    QImage image( w, h, QImage::Format_ARGB32 );
     976#endif
     977
    844978    image.fill( 0 );
    845979
    … …  
    854988
    855989/*!
    856   Store a path command in the command list
    857 
    858   \param path Painter path
    859   \sa QPaintEngine::drawPath()
    860 */
    861 void QwtGraphic::drawPath( const QPainterPath &path )
    862 {
    863     const QPainter *painter = paintEngine()->painter();
     990   Store a path command in the command list
     991
     992   \param path Painter path
     993   \sa QPaintEngine::drawPath()
     994 */
     995void QwtGraphic::drawPath( const QPainterPath& path )
     996{
     997    const QPainter* painter = paintEngine()->painter();
    864998    if ( painter == NULL )
    865999        return;
    8661000
    867     d_data->commands += QwtPainterCommand( path );
     1001    m_data->commands += QwtPainterCommand( path );
     1002    m_data->commandTypes |= QwtGraphic::VectorData;
    8681003
    8691004    if ( !path.isEmpty() )
    … …  
    8831018        updateBoundingRect( boundingRect );
    8841019
    885         d_data->pathInfos += PathInfo( pointRect,
     1020        m_data->pathInfos += PathInfo( pointRect,
    8861021            boundingRect, qwtHasScalablePen( painter ) );
    8871022    }
    … …  
    8891024
    8901025/*!
    891   \brief Store a pixmap command in the command list
    892 
    893   \param rect target rectangle
    894   \param pixmap Pixmap to be painted
    895   \param subRect Reactangle of the pixmap to be painted
    896 
    897   \sa QPaintEngine::drawPixmap()
    898 */
    899 void QwtGraphic::drawPixmap( const QRectF &rect,
    900     const QPixmap &pixmap, const QRectF &subRect )
    901 {
    902     const QPainter *painter = paintEngine()->painter();
     1026   \brief Store a pixmap command in the command list
     1027
     1028   \param rect target rectangle
     1029   \param pixmap Pixmap to be painted
     1030   \param subRect Reactangle of the pixmap to be painted
     1031
     1032   \sa QPaintEngine::drawPixmap()
     1033 */
     1034void QwtGraphic::drawPixmap( const QRectF& rect,
     1035    const QPixmap& pixmap, const QRectF& subRect )
     1036{
     1037    const QPainter* painter = paintEngine()->painter();
    9031038    if ( painter == NULL )
    9041039        return;
    9051040
    906     d_data->commands += QwtPainterCommand( rect, pixmap, subRect );
     1041    m_data->commands += QwtPainterCommand( rect, pixmap, subRect );
     1042    m_data->commandTypes |= QwtGraphic::RasterData;
    9071043
    9081044    const QRectF r = painter->transform().mapRect( rect );
    … …  
    9121048
    9131049/*!
    914   \brief Store a image command in the command list
    915 
    916   \param rect traget rectangle
    917   \param image Image to be painted
    918   \param subRect Reactangle of the pixmap to be painted
    919   \param flags Image conversion flags
    920 
    921   \sa QPaintEngine::drawImage()
    922  */
    923 void QwtGraphic::drawImage( const QRectF &rect, const QImage &image,
    924     const QRectF &subRect, Qt::ImageConversionFlags flags)
    925 {
    926     const QPainter *painter = paintEngine()->painter();
     1050   \brief Store a image command in the command list
     1051
     1052   \param rect target rectangle
     1053   \param image Image to be painted
     1054   \param subRect Reactangle of the pixmap to be painted
     1055   \param flags Image conversion flags
     1056
     1057   \sa QPaintEngine::drawImage()
     1058 */
     1059void QwtGraphic::drawImage( const QRectF& rect, const QImage& image,
     1060    const QRectF& subRect, Qt::ImageConversionFlags flags )
     1061{
     1062    const QPainter* painter = paintEngine()->painter();
    9271063    if ( painter == NULL )
    9281064        return;
    9291065
    930     d_data->commands += QwtPainterCommand( rect, image, subRect, flags );
     1066    m_data->commands += QwtPainterCommand( rect, image, subRect, flags );
     1067    m_data->commandTypes |= QwtGraphic::RasterData;
    9311068
    9321069    const QRectF r = painter->transform().mapRect( rect );
    … …  
    9371074
    9381075/*!
    939   \brief Store a state command in the command list
    940 
    941   \param state State to be stored
    942   \sa QPaintEngine::updateState()
    943  */
    944 void QwtGraphic::updateState( const QPaintEngineState &state)
    945 {
    946     d_data->commands += QwtPainterCommand( state );
    947 }
    948 
    949 void QwtGraphic::updateBoundingRect( const QRectF &rect )
     1076   \brief Store a state command in the command list
     1077
     1078   \param state State to be stored
     1079   \sa QPaintEngine::updateState()
     1080 */
     1081void QwtGraphic::updateState( const QPaintEngineState& state )
     1082{
     1083    m_data->commands += QwtPainterCommand( state );
     1084
     1085    if ( state.state() & QPaintEngine::DirtyTransform )
     1086    {
     1087        if ( !( m_data->commandTypes & QwtGraphic::Transformation ) )
     1088        {
     1089            /*
     1090                QTransform::isScaling() returns true for all type
     1091                of transformations beside simple translations
     1092                even if it is f.e a rotation
     1093             */
     1094            if ( state.transform().isScaling() )
     1095                m_data->commandTypes |= QwtGraphic::Transformation;
     1096        }
     1097    }
     1098}
     1099
     1100void QwtGraphic::updateBoundingRect( const QRectF& rect )
    9501101{
    9511102    QRectF br = rect;
    9521103
    953     const QPainter *painter = paintEngine()->painter();
     1104    const QPainter* painter = paintEngine()->painter();
    9541105    if ( painter && painter->hasClipping() )
    9551106    {
    … …  
    9601111    }
    9611112
    962     if ( d_data->boundingRect.width() < 0 )
    963         d_data->boundingRect = br;
     1113    if ( m_data->boundingRect.width() < 0 )
     1114        m_data->boundingRect = br;
    9641115    else
    965         d_data->boundingRect |= br;
    966 }
    967 
    968 void QwtGraphic::updateControlPointRect( const QRectF &rect )
    969 {
    970     if ( d_data->pointRect.width() < 0.0 )
    971         d_data->pointRect = rect;
     1116        m_data->boundingRect |= br;
     1117}
     1118
     1119void QwtGraphic::updateControlPointRect( const QRectF& rect )
     1120{
     1121    if ( m_data->pointRect.width() < 0.0 )
     1122        m_data->pointRect = rect;
    9721123    else
    973         d_data->pointRect |= rect;
    974 }
    975 
    976 /*!
    977   \return List of recorded paint commands
    978   \sa setCommands()
    979  */
    980 const QVector< QwtPainterCommand > &QwtGraphic::commands() const
    981 {
    982     return d_data->commands;
    983 }
    984 
    985 /*!
    986   \brief Append paint commands
    987 
    988   \param commands Paint commands
    989   \sa commands()
    990  */
    991 void QwtGraphic::setCommands( QVector< QwtPainterCommand > &commands )
     1124        m_data->pointRect |= rect;
     1125}
     1126
     1127/*!
     1128   \return List of recorded paint commands
     1129   \sa setCommands()
     1130 */
     1131const QVector< QwtPainterCommand >& QwtGraphic::commands() const
     1132{
     1133    return m_data->commands;
     1134}
     1135
     1136/*!
     1137   \brief Append paint commands
     1138
     1139   \param commands Paint commands
     1140   \sa commands()
     1141 */
     1142void QwtGraphic::setCommands( const QVector< QwtPainterCommand >& commands )
    9921143{
    9931144    reset();
    … …  
    10001151    // the commands.
    10011152
    1002     const QwtPainterCommand *cmds = commands.constData();
     1153    const QwtPainterCommand* cmds = commands.constData();
     1154
     1155    const QTransform noTransform;
     1156    const RenderHints noRenderHints;
    10031157
    10041158    QPainter painter( this );
    10051159    for ( int i = 0; i < numCommands; i++ )
    1006         qwtExecCommand( &painter, cmds[i], RenderHints(), QTransform(), NULL );
     1160        qwtExecCommand( &painter, cmds[i], noRenderHints, noTransform, NULL );
    10071161
    10081162    painter.end();
  • trunk/BNC/qwt/qwt_graphic.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_null_paintdevice.h"
     15
    1516#include <qmetatype.h>
    16 #include <qimage.h>
    17 #include <qpixmap.h>
    1817
    1918class QwtPainterCommand;
     19class QPixmap;
     20class QImage;
    2021
    2122/*!
    … …  
    7273    \sa QwtPainterCommand
    7374 */
    74 class QWT_EXPORT QwtGraphic: public QwtNullPaintDevice
     75class QWT_EXPORT QwtGraphic : public QwtNullPaintDevice
    7576{
    76 public:
     77  public:
    7778    /*!
    7879        Hint how to render a graphic
    … …  
    9697    };
    9798
     99    Q_DECLARE_FLAGS( RenderHints, RenderHint )
     100
    98101    /*!
    99         \brief Render hints
    100 
    101         The default setting is to disable all hints
     102       Indicator if the graphic contains a specific type of painter command
     103       \sa CommandTypes, commandTypes();
    102104     */
    103     typedef QFlags<RenderHint> RenderHints;
     105    enum CommandType
     106    {
     107        //! The graphic contains scalable vector data
     108        VectorData     = 1 << 0,
     109
     110        //! The graphic contains raster data ( QPixmap or QImage )
     111        RasterData     = 1 << 1,
     112
     113        //! The graphic contains transformations beyond simple translations
     114        Transformation = 1 << 2
     115    };
     116
     117    Q_DECLARE_FLAGS( CommandTypes, CommandType )
    104118
    105119    QwtGraphic();
    106     QwtGraphic( const QwtGraphic & );
     120    QwtGraphic( const QwtGraphic& );
    107121
    108122    virtual ~QwtGraphic();
    109123
    110     QwtGraphic& operator=( const QwtGraphic & );
     124    QwtGraphic& operator=( const QwtGraphic& );
    111125
    112126    void reset();
    … …  
    115129    bool isEmpty() const;
    116130
    117     void render( QPainter * ) const;
    118 
    119     void render( QPainter *, const QSizeF &,
    120             Qt::AspectRatioMode = Qt::IgnoreAspectRatio  ) const;
    121 
    122     void render( QPainter *, const QRectF &,
    123             Qt::AspectRatioMode = Qt::IgnoreAspectRatio  ) const;
    124 
    125     void render( QPainter *, const QPointF &,
     131    CommandTypes commandTypes() const;
     132
     133    void render( QPainter* ) const;
     134
     135    void render( QPainter*, const QSizeF&,
     136        Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
     137
     138    void render( QPainter*, const QPointF&,
    126139        Qt::Alignment = Qt::AlignTop | Qt::AlignLeft ) const;
    127140
    128     QPixmap toPixmap() const;
    129     QPixmap toPixmap( const QSize &,
    130         Qt::AspectRatioMode = Qt::IgnoreAspectRatio  ) const;
    131 
    132     QImage toImage() const;
    133     QImage toImage( const QSize &,
    134         Qt::AspectRatioMode = Qt::IgnoreAspectRatio  ) const;
    135 
    136     QRectF scaledBoundingRect( double sx, double sy ) const;
     141    void render( QPainter*, const QRectF&,
     142        Qt::AspectRatioMode = Qt::IgnoreAspectRatio ) const;
     143
     144    QPixmap toPixmap( qreal devicePixelRatio = 0.0 ) const;
     145
     146    QPixmap toPixmap( const QSize&,
     147        Qt::AspectRatioMode = Qt::IgnoreAspectRatio,
     148        qreal devicePixelRatio = 0.0 ) const;
     149
     150    QImage toImage( qreal devicePixelRatio = 0.0 ) const;
     151
     152    QImage toImage( const QSize&,
     153        Qt::AspectRatioMode = Qt::IgnoreAspectRatio,
     154        qreal devicePixelRatio = 0.0 ) const;
     155
     156    QRectF scaledBoundingRect( qreal sx, qreal sy ) const;
    137157
    138158    QRectF boundingRect() const;
    139159    QRectF controlPointRect() const;
    140160
    141     const QVector< QwtPainterCommand > &commands() const;
    142     void setCommands( QVector< QwtPainterCommand > & );
    143 
    144     void setDefaultSize( const QSizeF & );
     161    const QVector< QwtPainterCommand >& commands() const;
     162    void setCommands( const QVector< QwtPainterCommand >& );
     163
     164    void setDefaultSize( const QSizeF& );
    145165    QSizeF defaultSize() const;
     166
     167    qreal heightForWidth( qreal width ) const;
     168    qreal widthForHeight( qreal height ) const;
    146169
    147170    void setRenderHint( RenderHint, bool on = true );
    148171    bool testRenderHint( RenderHint ) const;
    149172
    150 protected:
    151     virtual QSize sizeMetrics() const;
    152 
    153     virtual void drawPath( const QPainterPath & );
    154 
    155     virtual void drawPixmap( const QRectF &,
    156         const QPixmap &, const QRectF & );
    157 
    158     virtual void drawImage( const QRectF &,
    159         const QImage &, const QRectF &, Qt::ImageConversionFlags );
    160 
    161     virtual void updateState( const QPaintEngineState &state );
    162 
    163 private:
    164     void updateBoundingRect( const QRectF & );
    165     void updateControlPointRect( const QRectF & );
     173    RenderHints renderHints() const;
     174
     175  protected:
     176    virtual QSize sizeMetrics() const QWT_OVERRIDE;
     177
     178    virtual void drawPath( const QPainterPath& ) QWT_OVERRIDE;
     179
     180    virtual void drawPixmap( const QRectF&,
     181        const QPixmap&, const QRectF& ) QWT_OVERRIDE;
     182
     183    virtual void drawImage( const QRectF&, const QImage&,
     184        const QRectF&, Qt::ImageConversionFlags ) QWT_OVERRIDE;
     185
     186    virtual void updateState( const QPaintEngineState& ) QWT_OVERRIDE;
     187
     188  private:
     189    void renderGraphic( QPainter*, QTransform* ) const;
     190
     191    void updateBoundingRect( const QRectF& );
     192    void updateControlPointRect( const QRectF& );
    166193
    167194    class PathInfo;
    168195
    169196    class PrivateData;
    170     PrivateData *d_data;
     197    PrivateData* m_data;
    171198};
    172199
    173200Q_DECLARE_OPERATORS_FOR_FLAGS( QwtGraphic::RenderHints )
     201Q_DECLARE_OPERATORS_FOR_FLAGS( QwtGraphic::CommandTypes )
    174202Q_DECLARE_METATYPE( QwtGraphic )
    175203
  • trunk/BNC/qwt/qwt_interval.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_interval.h"
    11 #include "qwt_math.h"
    12 #include <qalgorithms.h>
    13 
    14 /*!
    15   \brief Normalize the limits of the interval
    16 
    17   If maxValue() < minValue() the limits will be inverted.
    18   \return Normalized interval
    19 
    20   \sa isValid(), inverted()
    21 */
     11
     12namespace
     13{
     14    static const struct RegisterQwtInterval
     15    {
     16        inline RegisterQwtInterval() { qRegisterMetaType< QwtInterval >(); }
     17
     18    } qwtRegisterQwtInterval;
     19}
     20
     21/*!
     22   \brief Normalize the limits of the interval
     23
     24   If maxValue() < minValue() the limits will be inverted.
     25   \return Normalized interval
     26
     27   \sa isValid(), inverted()
     28 */
    2229QwtInterval QwtInterval::normalized() const
    2330{
    24     if ( d_minValue > d_maxValue )
     31    if ( m_minValue > m_maxValue )
    2532    {
    2633        return inverted();
    2734    }
    28     if ( d_minValue == d_maxValue && d_borderFlags == ExcludeMinimum )
     35    if ( m_minValue == m_maxValue && m_borderFlags == ExcludeMinimum )
    2936    {
    3037        return inverted();
    … …  
    3542
    3643/*!
    37   Invert the limits of the interval
    38   \return Inverted interval
    39   \sa normalized()
    40 */
     44   Invert the limits of the interval
     45   \return Inverted interval
     46   \sa normalized()
     47 */
    4148QwtInterval QwtInterval::inverted() const
    4249{
    4350    BorderFlags borderFlags = IncludeBorders;
    44     if ( d_borderFlags & ExcludeMinimum )
     51
     52    if ( m_borderFlags & ExcludeMinimum )
    4553        borderFlags |= ExcludeMaximum;
    46     if ( d_borderFlags & ExcludeMaximum )
     54
     55    if ( m_borderFlags & ExcludeMaximum )
    4756        borderFlags |= ExcludeMinimum;
    4857
    49     return QwtInterval( d_maxValue, d_minValue, borderFlags );
    50 }
    51 
    52 /*!
    53   Test if a value is inside an interval
    54 
    55   \param value Value
    56   \return true, if value >= minValue() && value <= maxValue()
    57 */
     58    return QwtInterval( m_maxValue, m_minValue, borderFlags );
     59}
     60
     61/*!
     62   Test if a value is inside an interval
     63
     64   \param value Value
     65   \return true, if value lies inside the boundaries
     66 */
    5867bool QwtInterval::contains( double value ) const
    5968{
    … …  
    6170        return false;
    6271
    63     if ( value < d_minValue || value > d_maxValue )
    64         return false;
    65 
    66     if ( value == d_minValue && d_borderFlags & ExcludeMinimum )
    67         return false;
    68 
    69     if ( value == d_maxValue && d_borderFlags & ExcludeMaximum )
     72    if ( ( value < m_minValue ) || ( value > m_maxValue ) )
     73        return false;
     74
     75    if ( ( value == m_minValue ) && ( m_borderFlags & ExcludeMinimum ) )
     76        return false;
     77
     78    if ( ( value == m_maxValue ) && ( m_borderFlags & ExcludeMaximum ) )
    7079        return false;
    7180
    … …  
    7382}
    7483
     84/*!
     85   Test if an interval is inside an interval
     86
     87   \param interval Interval
     88   \return true, if interval lies inside the boundaries
     89 */
     90bool QwtInterval::contains( const QwtInterval& interval ) const
     91{
     92    if ( !isValid() || !interval.isValid() )
     93        return false;
     94
     95    if ( ( interval.m_minValue < m_minValue ) || ( interval.m_maxValue > m_maxValue ) )
     96        return false;
     97
     98    if ( m_borderFlags )
     99    {
     100        if ( interval.m_minValue == m_minValue )
     101        {
     102            if ( ( m_borderFlags & ExcludeMinimum )
     103                && !( interval.m_borderFlags & ExcludeMinimum ) )
     104            {
     105                return false;
     106            }
     107        }
     108
     109        if ( interval.m_maxValue == m_maxValue )
     110        {
     111            if ( ( m_borderFlags & ExcludeMaximum )
     112                && !( interval.m_borderFlags & ExcludeMaximum ) )
     113            {
     114                return false;
     115            }
     116        }
     117    }
     118
     119    return true;
     120}
     121
    75122//! Unite 2 intervals
    76 QwtInterval QwtInterval::unite( const QwtInterval &other ) const
     123QwtInterval QwtInterval::unite( const QwtInterval& other ) const
    77124{
    78125    /*
    79      If one of the intervals is invalid return the other one.
    80      If both are invalid return an invalid default interval
     126       If one of the intervals is invalid return the other one.
     127       If both are invalid return an invalid default interval
    81128     */
    82129    if ( !isValid() )
    … …  
    94141
    95142    // minimum
    96     if ( d_minValue < other.minValue() )
    97     {
    98         united.setMinValue( d_minValue );
    99         flags &= d_borderFlags & ExcludeMinimum;
    100     }
    101     else if ( other.minValue() < d_minValue )
     143    if ( m_minValue < other.minValue() )
     144    {
     145        united.setMinValue( m_minValue );
     146        flags &= m_borderFlags & ExcludeMinimum;
     147    }
     148    else if ( other.minValue() < m_minValue )
    102149    {
    103150        united.setMinValue( other.minValue() );
    104151        flags &= other.borderFlags() & ExcludeMinimum;
    105152    }
    106     else // d_minValue == other.minValue()
    107     {
    108         united.setMinValue( d_minValue );
    109         flags &= ( d_borderFlags & other.borderFlags() ) & ExcludeMinimum;
     153    else // m_minValue == other.minValue()
     154    {
     155        united.setMinValue( m_minValue );
     156        flags &= ( m_borderFlags & other.borderFlags() ) & ExcludeMinimum;
    110157    }
    111158
    112159    // maximum
    113     if ( d_maxValue > other.maxValue() )
    114     {
    115         united.setMaxValue( d_maxValue );
    116         flags &= d_borderFlags & ExcludeMaximum;
    117     }
    118     else if ( other.maxValue() > d_maxValue )
     160    if ( m_maxValue > other.maxValue() )
     161    {
     162        united.setMaxValue( m_maxValue );
     163        flags &= m_borderFlags & ExcludeMaximum;
     164    }
     165    else if ( other.maxValue() > m_maxValue )
    119166    {
    120167        united.setMaxValue( other.maxValue() );
    121168        flags &= other.borderFlags() & ExcludeMaximum;
    122169    }
    123     else // d_maxValue == other.maxValue() )
    124     {
    125         united.setMaxValue( d_maxValue );
    126         flags &= d_borderFlags & other.borderFlags() & ExcludeMaximum;
     170    else // m_maxValue == other.maxValue() )
     171    {
     172        united.setMaxValue( m_maxValue );
     173        flags &= m_borderFlags & other.borderFlags() & ExcludeMaximum;
    127174    }
    128175
    … …  
    132179
    133180/*!
    134   \brief Intersect 2 intervals
    135 
    136   \param other Interval to be intersect with
    137   \return Intersection
    138  */
    139 QwtInterval QwtInterval::intersect( const QwtInterval &other ) const
     181   \brief Intersect 2 intervals
     182
     183   \param other Interval to be intersect with
     184   \return Intersection
     185 */
     186QwtInterval QwtInterval::intersect( const QwtInterval& other ) const
    140187{
    141188    if ( !other.isValid() || !isValid() )
    … …  
    199246
    200247/*!
    201   \brief Unite this interval with the given interval.
    202 
    203   \param other Interval to be united with
    204   \return This interval
    205  */
    206 QwtInterval& QwtInterval::operator|=( const QwtInterval &other )
     248   \brief Unite this interval with the given interval.
     249
     250   \param other Interval to be united with
     251   \return This interval
     252 */
     253QwtInterval& QwtInterval::operator|=( const QwtInterval& other )
    207254{
    208255    *this = *this | other;
    … …  
    211258
    212259/*!
    213   \brief Intersect this interval with the given interval.
    214 
    215   \param other Interval to be intersected with
    216   \return This interval
    217  */
    218 QwtInterval& QwtInterval::operator&=( const QwtInterval &other )
     260   \brief Intersect this interval with the given interval.
     261
     262   \param other Interval to be intersected with
     263   \return This interval
     264 */
     265QwtInterval& QwtInterval::operator&=( const QwtInterval& other )
    219266{
    220267    *this = *this & other;
    … …  
    223270
    224271/*!
    225   \brief Test if two intervals overlap
    226 
    227   \param other Interval
    228   \return True, when the intervals are intersecting
    229 */
    230 bool QwtInterval::intersects( const QwtInterval &other ) const
     272   \brief Test if two intervals overlap
     273
     274   \param other Interval
     275   \return True, when the intervals are intersecting
     276 */
     277bool QwtInterval::intersects( const QwtInterval& other ) const
    231278{
    232279    if ( !isValid() || !other.isValid() )
    … …  
    244291    }
    245292    else if ( i1.minValue() == i2.minValue() &&
    246               i1.borderFlags() & ExcludeMinimum )
     293        i1.borderFlags() & ExcludeMinimum )
    247294    {
    248295        qSwap( i1, i2 );
    … …  
    256303    {
    257304        return !( ( i1.borderFlags() & ExcludeMaximum ) ||
    258             ( i2.borderFlags() & ExcludeMinimum ) );
     305               ( i2.borderFlags() & ExcludeMinimum ) );
    259306    }
    260307    return false;
    … …  
    262309
    263310/*!
    264   Adjust the limit that is closer to value, so that value becomes
    265   the center of the interval.
    266 
    267   \param value Center
    268   \return Interval with value as center
    269 */
     311   Adjust the limit that is closer to value, so that value becomes
     312   the center of the interval.
     313
     314   \param value Center
     315   \return Interval with value as center
     316 */
    270317QwtInterval QwtInterval::symmetrize( double value ) const
    271318{
    … …  
    274321
    275322    const double delta =
    276         qMax( qAbs( value - d_maxValue ), qAbs( value - d_minValue ) );
     323        qMax( qAbs( value - m_maxValue ), qAbs( value - m_minValue ) );
    277324
    278325    return QwtInterval( value - delta, value + delta );
    … …  
    280327
    281328/*!
    282   Limit the interval, keeping the border modes
    283 
    284   \param lowerBound Lower limit
    285   \param upperBound Upper limit
    286 
    287   \return Limited interval
    288 */
     329   Limit the interval, keeping the border modes
     330
     331   \param lowerBound Lower limit
     332   \param upperBound Upper limit
     333
     334   \return Limited interval
     335 */
    289336QwtInterval QwtInterval::limited( double lowerBound, double upperBound ) const
    290337{
    … …  
    292339        return QwtInterval();
    293340
    294     double minValue = qMax( d_minValue, lowerBound );
     341    double minValue = qMax( m_minValue, lowerBound );
    295342    minValue = qMin( minValue, upperBound );
    296343
    297     double maxValue = qMax( d_maxValue, lowerBound );
     344    double maxValue = qMax( m_maxValue, lowerBound );
    298345    maxValue = qMin( maxValue, upperBound );
    299346
    300     return QwtInterval( minValue, maxValue, d_borderFlags );
    301 }
    302 
    303 /*!
    304   \brief Extend the interval
    305 
    306   If value is below minValue(), value becomes the lower limit.
    307   If value is above maxValue(), value becomes the upper limit.
    308 
    309   extend() has no effect for invalid intervals
    310 
    311   \param value Value
    312   \return extended interval
    313 
    314   \sa isValid()
    315 */
     347    return QwtInterval( minValue, maxValue, m_borderFlags );
     348}
     349
     350/*!
     351   \brief Extend the interval
     352
     353   If value is below minValue(), value becomes the lower limit.
     354   If value is above maxValue(), value becomes the upper limit.
     355
     356   extend() has no effect for invalid intervals
     357
     358   \param value Value
     359   \return extended interval
     360
     361   \sa isValid()
     362 */
    316363QwtInterval QwtInterval::extend( double value ) const
    317364{
    … …  
    319366        return *this;
    320367
    321     return QwtInterval( qMin( value, d_minValue ),
    322         qMax( value, d_maxValue ), d_borderFlags );
    323 }
    324 
    325 /*!
    326   Extend an interval
    327 
    328   \param value Value
    329   \return Reference of the extended interval
    330 
    331   \sa extend()
    332 */
     368    return QwtInterval( qMin( value, m_minValue ),
     369        qMax( value, m_maxValue ), m_borderFlags );
     370}
     371
     372/*!
     373   Extend an interval
     374
     375   \param value Value
     376   \return Reference of the extended interval
     377
     378   \sa extend()
     379 */
    333380QwtInterval& QwtInterval::operator|=( double value )
    334381{
    … …  
    339386#ifndef QT_NO_DEBUG_STREAM
    340387
    341 QDebug operator<<( QDebug debug, const QwtInterval &interval )
     388#include <qdebug.h>
     389
     390QDebug operator<<( QDebug debug, const QwtInterval& interval )
    342391{
    343392    const int flags = interval.borderFlags();
    344393
    345394    debug.nospace() << "QwtInterval("
    346         << ( ( flags & QwtInterval::ExcludeMinimum ) ? "]" : "[" )
    347         << interval.minValue() << "," << interval.maxValue()
    348         << ( ( flags & QwtInterval::ExcludeMaximum ) ? "[" : "]" )
    349         << ")";
     395                    << ( ( flags& QwtInterval::ExcludeMinimum ) ? "]" : "[" )
     396                    << interval.minValue() << "," << interval.maxValue()
     397                    << ( ( flags& QwtInterval::ExcludeMaximum ) ? "[" : "]" )
     398                    << ")";
    350399
    351400    return debug.space();
  • trunk/BNC/qwt/qwt_interval.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1414#include <qmetatype.h>
    1515
    16 #ifndef QT_NO_DEBUG_STREAM
    17 #include <qdebug.h>
    18 #endif
    19 
    20 /*!
    21   \brief A class representing an interval
    22 
    23   The interval is represented by 2 doubles, the lower and the upper limit.
    24 */
     16/*!
     17   \brief A class representing an interval
     18
     19   The interval is represented by 2 doubles, the lower and the upper limit.
     20 */
    2521
    2622class QWT_EXPORT QwtInterval
    2723{
    28 public:
     24  public:
    2925    /*!
    30       Flag indicating if a border is included or excluded
    31       \sa setBorderFlags(), borderFlags()
    32     */
     26       Flag indicating if a border is included or excluded
     27       \sa setBorderFlags(), borderFlags()
     28     */
    3329    enum BorderFlag
    3430    {
    … …  
    4743
    4844    //! Border flags
    49     typedef QFlags<BorderFlag> BorderFlags;
     45    Q_DECLARE_FLAGS( BorderFlags, BorderFlag )
    5046
    5147    QwtInterval();
    … …  
    6056    QwtInterval limited( double lowerBound, double upperBound ) const;
    6157
    62     bool operator==( const QwtInterval & ) const;
    63     bool operator!=( const QwtInterval & ) const;
     58    bool operator==( const QwtInterval& ) const;
     59    bool operator!=( const QwtInterval& ) const;
    6460
    6561    void setBorderFlags( BorderFlags );
    … …  
    7066
    7167    double width() const;
     68    long double widthL() const;
    7269
    7370    void setMinValue( double );
    … …  
    7572
    7673    bool contains( double value ) const;
    77 
    78     bool intersects( const QwtInterval & ) const;
    79     QwtInterval intersect( const QwtInterval & ) const;
    80     QwtInterval unite( const QwtInterval & ) const;
    81 
    82     QwtInterval operator|( const QwtInterval & ) const;
    83     QwtInterval operator&( const QwtInterval & ) const;
    84 
    85     QwtInterval &operator|=( const QwtInterval & );
    86     QwtInterval &operator&=( const QwtInterval & );
     74    bool contains( const QwtInterval& ) const;
     75
     76    bool intersects( const QwtInterval& ) const;
     77    QwtInterval intersect( const QwtInterval& ) const;
     78    QwtInterval unite( const QwtInterval& ) const;
     79
     80    QwtInterval operator|( const QwtInterval& ) const;
     81    QwtInterval operator&( const QwtInterval& ) const;
     82
     83    QwtInterval& operator|=( const QwtInterval& );
     84    QwtInterval& operator&=( const QwtInterval& );
    8785
    8886    QwtInterval extend( double value ) const;
    8987    QwtInterval operator|( double ) const;
    90     QwtInterval &operator|=( double );
     88    QwtInterval& operator|=( double );
    9189
    9290    bool isValid() const;
    … …  
    9694    QwtInterval symmetrize( double value ) const;
    9795
    98 private:
    99     double d_minValue;
    100     double d_maxValue;
    101     BorderFlags d_borderFlags;
     96  private:
     97    double m_minValue;
     98    double m_maxValue;
     99    BorderFlags m_borderFlags;
    102100};
    103101
    104 Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
    105 
    106 /*!
    107   \brief Default Constructor
    108 
    109   Creates an invalid interval [0.0, -1.0]
    110   \sa setInterval(), isValid()
    111 */
    112 inline QwtInterval::QwtInterval():
    113     d_minValue( 0.0 ),
    114     d_maxValue( -1.0 ),
    115     d_borderFlags( IncludeBorders )
     102Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
     103Q_DECLARE_METATYPE( QwtInterval )
     104Q_DECLARE_TYPEINFO( QwtInterval, Q_MOVABLE_TYPE );
     105
     106/*!
     107   \brief Default Constructor
     108
     109   Creates an invalid interval [0.0, -1.0]
     110   \sa setInterval(), isValid()
     111 */
     112inline QwtInterval::QwtInterval()
     113    : m_minValue( 0.0 )
     114    , m_maxValue( -1.0 )
     115    , m_borderFlags( IncludeBorders )
    116116{
    117117}
    … …  
    125125   \param maxValue Maximum value
    126126   \param borderFlags Include/Exclude borders
    127 */
     127 */
    128128inline QwtInterval::QwtInterval(
    129         double minValue, double maxValue, BorderFlags borderFlags ):
    130     d_minValue( minValue ),
    131     d_maxValue( maxValue ),
    132     d_borderFlags( borderFlags )
     129        double minValue, double maxValue, BorderFlags borderFlags )
     130    : m_minValue( minValue )
     131    , m_maxValue( maxValue )
     132    , m_borderFlags( borderFlags )
    133133{
    134134}
    … …  
    140140   \param maxValue Maximum value
    141141   \param borderFlags Include/Exclude borders
    142 */
     142 */
    143143inline void QwtInterval::setInterval(
    144144    double minValue, double maxValue, BorderFlags borderFlags )
    145145{
    146     d_minValue = minValue;
    147     d_maxValue = maxValue;
    148     d_borderFlags = borderFlags;
     146    m_minValue = minValue;
     147    m_maxValue = maxValue;
     148    m_borderFlags = borderFlags;
    149149}
    150150
    … …  
    154154   \param borderFlags Or'd BorderMode flags
    155155   \sa borderFlags()
    156 */
     156 */
    157157inline void QwtInterval::setBorderFlags( BorderFlags borderFlags )
    158158{
    159     d_borderFlags = borderFlags;
     159    m_borderFlags = borderFlags;
    160160}
    161161
    … …  
    163163   \return Border flags
    164164   \sa setBorderFlags()
    165 */
     165 */
    166166inline QwtInterval::BorderFlags QwtInterval::borderFlags() const
    167167{
    168     return d_borderFlags;
     168    return m_borderFlags;
    169169}
    170170
    … …  
    173173
    174174   \param minValue Minimum value
    175 */
     175 */
    176176inline void QwtInterval::setMinValue( double minValue )
    177177{
    178     d_minValue = minValue;
     178    m_minValue = minValue;
    179179}
    180180
    … …  
    183183
    184184   \param maxValue Maximum value
    185 */
     185 */
    186186inline void QwtInterval::setMaxValue( double maxValue )
    187187{
    188     d_maxValue = maxValue;
     188    m_maxValue = maxValue;
    189189}
    190190
    … …  
    192192inline double QwtInterval::minValue() const
    193193{
    194     return d_minValue;
     194    return m_minValue;
    195195}
    196196
    … …  
    198198inline double QwtInterval::maxValue() const
    199199{
    200     return d_maxValue;
     200    return m_maxValue;
    201201}
    202202
    … …  
    207207
    208208   \return True, when the interval is valid
    209 */
     209 */
    210210inline bool QwtInterval::isValid() const
    211211{
    212     if ( ( d_borderFlags & ExcludeBorders ) == 0 )
    213         return d_minValue <= d_maxValue;
     212    if ( ( m_borderFlags & ExcludeBorders ) == 0 )
     213        return m_minValue <= m_maxValue;
    214214    else
    215         return d_minValue < d_maxValue;
     215        return m_minValue < m_maxValue;
    216216}
    217217
    … …  
    224224   \return Interval width
    225225   \sa isValid()
    226 */
     226 */
    227227inline double QwtInterval::width() const
    228228{
    229     return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
     229    return isValid() ? ( m_maxValue - m_minValue ) : 0.0;
     230}
     231
     232/*!
     233   \brief Return the width of an interval as long double
     234
     235   The width of invalid intervals is 0.0, otherwise the result is
     236   maxValue() - minValue().
     237
     238   \return Interval width
     239   \sa isValid()
     240 */
     241inline long double QwtInterval::widthL() const
     242{
     243    if ( !isValid() )
     244        return 0.0;
     245
     246    return static_cast< long double >( m_maxValue )
     247           - static_cast< long double >( m_minValue );
    230248}
    231249
    … …  
    237255
    238256   \sa intersect()
    239 */
     257 */
    240258inline QwtInterval QwtInterval::operator&(
    241     const QwtInterval &other ) const
     259    const QwtInterval& other ) const
    242260{
    243261    return intersect( other );
    … …  
    251269
    252270   \sa unite()
    253 */
     271 */
    254272inline QwtInterval QwtInterval::operator|(
    255     const QwtInterval &other ) const
     273    const QwtInterval& other ) const
    256274{
    257275    return unite( other );
    … …  
    263281   \param other Interval to compare with
    264282   \return True, when this and other are equal
    265 */
    266 inline bool QwtInterval::operator==( const QwtInterval &other ) const
    267 {
    268     return ( d_minValue == other.d_minValue ) &&
    269            ( d_maxValue == other.d_maxValue ) &&
    270            ( d_borderFlags == other.d_borderFlags );
     283 */
     284inline bool QwtInterval::operator==( const QwtInterval& other ) const
     285{
     286    return ( m_minValue == other.m_minValue ) &&
     287           ( m_maxValue == other.m_maxValue ) &&
     288           ( m_borderFlags == other.m_borderFlags );
    271289}
    272290/*!
    … …  
    275293   \param other Interval to compare with
    276294   \return True, when this and other are not equal
    277 */
    278 inline bool QwtInterval::operator!=( const QwtInterval &other ) const
     295 */
     296inline bool QwtInterval::operator!=( const QwtInterval& other ) const
    279297{
    280298    return ( !( *this == other ) );
    … …  
    287305   \return Extended interval
    288306   \sa extend()
    289 */
     307 */
    290308inline QwtInterval QwtInterval::operator|( double value ) const
    291309{
    … …  
    296314inline bool QwtInterval::isNull() const
    297315{
    298     return isValid() && d_minValue >= d_maxValue;
    299 }
    300 
    301 /*!
    302   Invalidate the interval
    303 
    304   The limits are set to interval [0.0, -1.0]
    305   \sa isValid()
    306 */
     316    return isValid() && m_minValue >= m_maxValue;
     317}
     318
     319/*!
     320   Invalidate the interval
     321
     322   The limits are set to interval [0.0, -1.0]
     323   \sa isValid()
     324 */
    307325inline void QwtInterval::invalidate()
    308326{
    309     d_minValue = 0.0;
    310     d_maxValue = -1.0;
    311 }
    312 
    313 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
    314 Q_DECLARE_METATYPE( QwtInterval )
     327    m_minValue = 0.0;
     328    m_maxValue = -1.0;
     329}
    315330
    316331#ifndef QT_NO_DEBUG_STREAM
    317 QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );
     332QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval& );
    318333#endif
    319334
  • trunk/BNC/qwt/qwt_interval_symbol.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_painter.h"
    1212#include "qwt_math.h"
     13
    1314#include <qpainter.h>
    14 
    15 #if QT_VERSION < 0x040601
    16 #define qAtan2(y, x) ::atan2(y, x)
    17 #define qFastSin(x) qSin(x)
    18 #define qFastCos(x) qCos(x)
    19 #endif
     15#include <qmath.h>
    2016
    2117class QwtIntervalSymbol::PrivateData
    2218{
    23 public:
    24     PrivateData():
    25         style( QwtIntervalSymbol::NoSymbol ),
    26         width( 6 )
     19  public:
     20    PrivateData()
     21        : style( QwtIntervalSymbol::NoSymbol )
     22        , width( 6 )
    2723    {
    2824    }
    2925
    30     bool operator==( const PrivateData &other ) const
     26    bool operator==( const PrivateData& other ) const
    3127    {
    3228        return ( style == other.style )
    33             && ( width == other.width )
    34             && ( brush == other.brush )
    35             && ( pen == other.pen );
     29               && ( width == other.width )
     30               && ( brush == other.brush )
     31               && ( pen == other.pen );
    3632    }
    3733
    … …  
    4440
    4541/*!
    46   Constructor
    47 
    48   \param style Style of the symbol
    49   \sa setStyle(), style(), Style
    50 */
     42   Constructor
     43
     44   \param style Style of the symbol
     45   \sa setStyle(), style(), Style
     46 */
    5147QwtIntervalSymbol::QwtIntervalSymbol( Style style )
    5248{
    53     d_data = new PrivateData();
    54     d_data->style = style;
     49    m_data = new PrivateData();
     50    m_data->style = style;
    5551}
    5652
    5753//! Copy constructor
    58 QwtIntervalSymbol::QwtIntervalSymbol( const QwtIntervalSymbol &other )
    59 {
    60     d_data = new PrivateData();
    61     *d_data = *other.d_data;
     54QwtIntervalSymbol::QwtIntervalSymbol( const QwtIntervalSymbol& other )
     55{
     56    m_data = new PrivateData();
     57    *m_data = *other.m_data;
    6258}
    6359
    … …  
    6561QwtIntervalSymbol::~QwtIntervalSymbol()
    6662{
    67     delete d_data;
     63    delete m_data;
    6864}
    6965
    7066//! \brief Assignment operator
    71 QwtIntervalSymbol &QwtIntervalSymbol::operator=(
    72     const QwtIntervalSymbol &other )
    73 {
    74     *d_data = *other.d_data;
     67QwtIntervalSymbol& QwtIntervalSymbol::operator=(
     68    const QwtIntervalSymbol& other )
     69{
     70    *m_data = *other.m_data;
    7571    return *this;
    7672}
    … …  
    7874//! \brief Compare two symbols
    7975bool QwtIntervalSymbol::operator==(
    80     const QwtIntervalSymbol &other ) const
    81 {
    82     return *d_data == *other.d_data;
     76    const QwtIntervalSymbol& other ) const
     77{
     78    return *m_data == *other.m_data;
    8379}
    8480
    8581//! \brief Compare two symbols
    8682bool QwtIntervalSymbol::operator!=(
    87     const QwtIntervalSymbol &other ) const
    88 {
    89     return !( *d_data == *other.d_data );
    90 }
    91 
    92 /*!
    93   Specify the symbol style
    94 
    95   \param style Style
    96   \sa style(), Style
    97 */
     83    const QwtIntervalSymbol& other ) const
     84{
     85    return !( *m_data == *other.m_data );
     86}
     87
     88/*!
     89   Specify the symbol style
     90
     91   \param style Style
     92   \sa style(), Style
     93 */
    9894void QwtIntervalSymbol::setStyle( Style style )
    9995{
    100     d_data->style = style;
    101 }
    102 
    103 /*!
    104   \return Current symbol style
    105   \sa setStyle()
    106 */
     96    m_data->style = style;
     97}
     98
     99/*!
     100   \return Current symbol style
     101   \sa setStyle()
     102 */
    107103QwtIntervalSymbol::Style QwtIntervalSymbol::style() const
    108104{
    109     return d_data->style;
    110 }
    111 
    112 /*!
    113   Specify the width of the symbol
    114   It is used depending on the style.
    115 
    116   \param width Width
    117   \sa width(), setStyle()
    118 */
     105    return m_data->style;
     106}
     107
     108/*!
     109   Specify the width of the symbol
     110   It is used depending on the style.
     111
     112   \param width Width
     113   \sa width(), setStyle()
     114 */
    119115void QwtIntervalSymbol::setWidth( int width )
    120116{
    121     d_data->width = width;
    122 }
    123 
    124 /*!
    125   \return Width of the symbol.
    126   \sa setWidth(), setStyle()
    127 */
     117    m_data->width = width;
     118}
     119
     120/*!
     121   \return Width of the symbol.
     122   \sa setWidth(), setStyle()
     123 */
    128124int QwtIntervalSymbol::width() const
    129125{
    130     return d_data->width;
    131 }
    132 
    133 /*!
    134   \brief Assign a brush
    135 
    136   The brush is used for the Box style.
    137 
    138   \param brush Brush
    139   \sa brush()
    140 */
    141 void QwtIntervalSymbol::setBrush( const QBrush &brush )
    142 {
    143     d_data->brush = brush;
    144 }
    145 
    146 /*!
    147   \return Brush
    148   \sa setBrush()
    149 */
     126    return m_data->width;
     127}
     128
     129/*!
     130   \brief Assign a brush
     131
     132   The brush is used for the Box style.
     133
     134   \param brush Brush
     135   \sa brush()
     136 */
     137void QwtIntervalSymbol::setBrush( const QBrush& brush )
     138{
     139    m_data->brush = brush;
     140}
     141
     142/*!
     143   \return Brush
     144   \sa setBrush()
     145 */
    150146const QBrush& QwtIntervalSymbol::brush() const
    151147{
    152     return d_data->brush;
    153 }
    154 
    155 /*!
    156   Build and assign a pen
    157 
    158   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    159   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    160   to hide this incompatibility.
    161 
    162   \param color Pen color
    163   \param width Pen width
    164   \param style Pen style
    165 
    166   \sa pen(), brush()
    167  */
    168 void QwtIntervalSymbol::setPen( const QColor &color,
     148    return m_data->brush;
     149}
     150
     151/*!
     152   Build and assign a pen
     153
     154   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     155   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     156   to hide this incompatibility.
     157
     158   \param color Pen color
     159   \param width Pen width
     160   \param style Pen style
     161
     162   \sa pen(), brush()
     163 */
     164void QwtIntervalSymbol::setPen( const QColor& color,
    169165    qreal width, Qt::PenStyle style )
    170166{
    … …  
    173169
    174170/*!
    175   Assign a pen
    176 
    177   \param pen Pen
    178   \sa pen(), setBrush()
    179 */
    180 void QwtIntervalSymbol::setPen( const QPen &pen )
    181 {
    182     d_data->pen = pen;
    183 }
    184 
    185 /*!
    186   \return Pen
    187   \sa setPen(), brush()
    188 */
     171   Assign a pen
     172
     173   \param pen Pen
     174   \sa pen(), setBrush()
     175 */
     176void QwtIntervalSymbol::setPen( const QPen& pen )
     177{
     178    m_data->pen = pen;
     179}
     180
     181/*!
     182   \return Pen
     183   \sa setPen(), brush()
     184 */
    189185const QPen& QwtIntervalSymbol::pen() const
    190186{
    191     return d_data->pen;
    192 }
    193 
    194 /*!
    195   Draw a symbol depending on its style
    196 
    197   \param painter Painter
    198   \param orientation Orientation
    199   \param from Start point of the interval in target device coordinates
    200   \param to End point of the interval in target device coordinates
    201 
    202   \sa setStyle()
    203 */
    204 void QwtIntervalSymbol::draw( QPainter *painter, Qt::Orientation orientation,
    205     const QPointF &from, const QPointF &to ) const
    206 {
    207     const qreal pw = qMax( painter->pen().widthF(), qreal( 1.0 ) );
     187    return m_data->pen;
     188}
     189
     190/*!
     191   Draw a symbol depending on its style
     192
     193   \param painter Painter
     194   \param orientation Orientation
     195   \param from Start point of the interval in target device coordinates
     196   \param to End point of the interval in target device coordinates
     197
     198   \sa setStyle()
     199 */
     200void QwtIntervalSymbol::draw( QPainter* painter, Qt::Orientation orientation,
     201    const QPointF& from, const QPointF& to ) const
     202{
     203    const qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
    208204
    209205    QPointF p1 = from;
    … …  
    215211    }
    216212
    217     switch ( d_data->style )
     213    switch ( m_data->style )
    218214    {
    219215        case QwtIntervalSymbol::Bar:
    220216        {
    221217            QwtPainter::drawLine( painter, p1, p2 );
    222             if ( d_data->width > pw )
     218            if ( m_data->width > pw )
    223219            {
    224220                if ( ( orientation == Qt::Horizontal )
    225221                    && ( p1.y() == p2.y() ) )
    226222                {
    227                     const double sw = d_data->width;
     223                    const double sw = m_data->width;
    228224
    229225                    const double y = p1.y() - sw / 2;
    … …  
    236232                    && ( p1.x() == p2.x() ) )
    237233                {
    238                     const double sw = d_data->width;
     234                    const double sw = m_data->width;
    239235
    240236                    const double x = p1.x() - sw / 2;
    … …  
    246242                else
    247243                {
    248                     const double sw = d_data->width;
     244                    const double sw = m_data->width;
    249245
    250246                    const double dx = p2.x() - p1.x();
    251247                    const double dy = p2.y() - p1.y();
    252                     const double angle = qAtan2( dy, dx ) + M_PI_2;
     248                    const double angle = std::atan2( dy, dx ) + M_PI_2;
    253249                    double dw2 = sw / 2.0;
    254250
    … …  
    268264        case QwtIntervalSymbol::Box:
    269265        {
    270             if ( d_data->width <= pw )
     266            if ( m_data->width <= pw )
    271267            {
    272268                QwtPainter::drawLine( painter, p1, p2 );
    … …  
    277273                    && ( p1.y() == p2.y() ) )
    278274                {
    279                     const double sw = d_data->width;
    280 
    281                     const double y = p1.y() - d_data->width / 2;
     275                    const double sw = m_data->width;
     276
     277                    const double y = p1.y() - m_data->width / 2;
    282278                    QwtPainter::drawRect( painter,
    283279                        p1.x(), y, p2.x() - p1.x(),  sw );
    … …  
    286282                    && ( p1.x() == p2.x() ) )
    287283                {
    288                     const double sw = d_data->width;
    289 
    290                     const double x = p1.x() - d_data->width / 2;
     284                    const double sw = m_data->width;
     285
     286                    const double x = p1.x() - m_data->width / 2;
    291287                    QwtPainter::drawRect( painter,
    292288                        x, p1.y(), sw, p2.y() - p1.y() );
    … …  
    294290                else
    295291                {
    296                     const double sw = d_data->width;
     292                    const double sw = m_data->width;
    297293
    298294                    const double dx = p2.x() - p1.x();
    299295                    const double dy = p2.y() - p1.y();
    300                     const double angle = qAtan2( dy, dx ) + M_PI_2;
     296                    const double angle = std::atan2( dy, dx ) + M_PI_2;
    301297                    double dw2 = sw / 2.0;
    302298
  • trunk/BNC/qwt/qwt_interval_symbol.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include <qpen.h>
    15 #include <qsize.h>
     14#include <qnamespace.h>
    1615
    1716class QPainter;
    18 class QRect;
     17class QPen;
     18class QBrush;
    1919class QPointF;
     20class QColor;
    2021
    2122/*!
    22   \brief A drawing primitive for displaying an interval like an error bar
     23   \brief A drawing primitive for displaying an interval like an error bar
    2324
    24   \sa QwtPlotIntervalCurve
    25 */
     25   \sa QwtPlotIntervalCurve
     26 */
    2627class QWT_EXPORT QwtIntervalSymbol
    2728{
    28 public:
     29  public:
    2930    //! Symbol style
    3031    enum Style
    … …  
    3435
    3536        /*!
    36           The symbol displays a line with caps at the beginning/end.
    37           The size of the caps depends on the symbol width().
     37           The symbol displays a line with caps at the beginning/end.
     38           The size of the caps depends on the symbol width().
    3839         */
    3940        Bar,
    4041
    4142        /*!
    42           The symbol displays a plain rectangle using pen() and brush().
    43           The size of the rectangle depends on the translated interval and
    44           the width(),
     43           The symbol displays a plain rectangle using pen() and brush().
     44           The size of the rectangle depends on the translated interval and
     45           the width(),
    4546         */
    4647        Box,
    4748
    4849        /*!
    49           Styles >= UserSymbol are reserved for derived
    50           classes of QwtIntervalSymbol that overload draw() with
    51           additional application specific symbol types.
     50           Styles >= UserSymbol are reserved for derived
     51           classes of QwtIntervalSymbol that overload draw() with
     52           additional application specific symbol types.
    5253         */
    5354        UserSymbol = 1000
    5455    };
    5556
    56 public:
    57     QwtIntervalSymbol( Style = NoSymbol );
    58     QwtIntervalSymbol( const QwtIntervalSymbol & );
     57  public:
     58    explicit QwtIntervalSymbol( Style = NoSymbol );
     59    QwtIntervalSymbol( const QwtIntervalSymbol& );
     60
    5961    virtual ~QwtIntervalSymbol();
    6062
    61     QwtIntervalSymbol &operator=( const QwtIntervalSymbol & );
    62     bool operator==( const QwtIntervalSymbol & ) const;
    63     bool operator!=( const QwtIntervalSymbol & ) const;
     63    QwtIntervalSymbol& operator=( const QwtIntervalSymbol& );
     64    bool operator==( const QwtIntervalSymbol& ) const;
     65    bool operator!=( const QwtIntervalSymbol& ) const;
    6466
    6567    void setWidth( int );
    6668    int width() const;
    6769
    68     void setBrush( const QBrush & );
     70    void setBrush( const QBrush& );
    6971    const QBrush& brush() const;
    7072
    71     void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    72     void setPen( const QPen & );
     73    void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
     74    void setPen( const QPen& );
    7375    const QPen& pen() const;
    7476
    … …  
    7678    Style style() const;
    7779
    78     virtual void draw( QPainter *, Qt::Orientation,
     80    virtual void draw( QPainter*, Qt::Orientation,
    7981        const QPointF& from, const QPointF& to ) const;
    8082
    81 private:
     83  private:
    8284    class PrivateData;
    83     PrivateData* d_data;
     85    PrivateData* m_data;
    8486};
    8587
  • trunk/BNC/qwt/qwt_knob.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_knob.h"
    1111#include "qwt_round_scale_draw.h"
    12 #include "qwt_math.h"
    1312#include "qwt_painter.h"
    1413#include "qwt_scale_map.h"
     14#include "qwt_math.h"
     15#include "qwt.h"
     16
    1517#include <qpainter.h>
    1618#include <qpalette.h>
    … …  
    1820#include <qstyleoption.h>
    1921#include <qevent.h>
     22#include <qmargins.h>
    2023#include <qmath.h>
    21 #include <qapplication.h>
    22 
    23 #if QT_VERSION < 0x040601
    24 #define qAtan2(y, x) ::atan2(y, x)
    25 #define qFabs(x) ::fabs(x)
    26 #define qFastCos(x) qCos(x)
    27 #define qFastSin(x) qSin(x)
    28 #endif
    29 
    30 static QSize qwtKnobSizeHint( const QwtKnob *knob, int min )
     24
     25static QSize qwtKnobSizeHint( const QwtKnob* knob, int min )
    3126{
    3227    int knobWidth = knob->knobWidth();
    … …  
    3530
    3631    // Add the scale radial thickness to the knobWidth
    37     const int extent = qCeil( knob->scaleDraw()->extent( knob->font() ) );
     32    const int extent = qwtCeil( knob->scaleDraw()->extent( knob->font() ) );
    3833    const int d = 2 * ( extent + 4 ) + knobWidth;
    3934
    40     int left, right, top, bottom;
    41     knob->getContentsMargins( &left, &top, &right, &bottom );
    42 
    43     return QSize( d + left + right, d + top + bottom );
     35    const QMargins m = knob->contentsMargins();
     36    return QSize( d + m.left() + m.right(), d + m.top() + m.bottom() );
    4437}
    4538
    … …  
    6558class QwtKnob::PrivateData
    6659{
    67 public:
    68     PrivateData():
    69         knobStyle( QwtKnob::Raised ),
    70         markerStyle( QwtKnob::Notch ),
    71         borderWidth( 2 ),
    72         borderDist( 4 ),
    73         scaleDist( 4 ),
    74         maxScaleTicks( 11 ),
    75         knobWidth( 0 ),
    76         alignment( Qt::AlignCenter ),
    77         markerSize( 8 ),
    78         totalAngle( 270.0 ),
    79         mouseOffset( 0.0 )
     60  public:
     61    PrivateData()
     62        : knobStyle( QwtKnob::Raised )
     63        , markerStyle( QwtKnob::Notch )
     64        , borderWidth( 2 )
     65        , borderDist( 4 )
     66        , scaleDist( 4 )
     67        , maxScaleTicks( 11 )
     68        , knobWidth( 0 )
     69        , alignment( Qt::AlignCenter )
     70        , markerSize( 8 )
     71        , totalAngle( 270.0 )
     72        , mouseOffset( 0.0 )
    8073    {
    8174    }
    … …  
    9891
    9992/*!
    100   \brief Constructor
    101 
    102   Construct a knob with an angle of 270°. The style is
    103   QwtKnob::Raised and the marker style is QwtKnob::Notch.
    104   The width of the knob is set to 50 pixels.
    105 
    106   \param parent Parent widget
    107 
    108   \sa setTotalAngle()
    109 */
    110 QwtKnob::QwtKnob( QWidget* parent ):
    111     QwtAbstractSlider( parent )
    112 {
    113     d_data = new PrivateData;
     93   \brief Constructor
     94
     95   Construct a knob with an angle of 270°. The style is
     96   QwtKnob::Raised and the marker style is QwtKnob::Notch.
     97   The width of the knob is set to 50 pixels.
     98
     99   \param parent Parent widget
     100
     101   \sa setTotalAngle()
     102 */
     103QwtKnob::QwtKnob( QWidget* parent )
     104    : QwtAbstractSlider( parent )
     105{
     106    m_data = new PrivateData;
    114107
    115108    setScaleDraw( new QwtRoundScaleDraw() );
    … …  
    127120QwtKnob::~QwtKnob()
    128121{
    129     delete d_data;
    130 }
    131 
    132 /*!
    133   \brief Set the knob type
    134 
    135   \param knobStyle Knob type
    136   \sa knobStyle(), setBorderWidth()
    137 */
     122    delete m_data;
     123}
     124
     125/*!
     126   \brief Set the knob type
     127
     128   \param knobStyle Knob type
     129   \sa knobStyle(), setBorderWidth()
     130 */
    138131void QwtKnob::setKnobStyle( KnobStyle knobStyle )
    139132{
    140     if ( d_data->knobStyle != knobStyle )
    141     {
    142         d_data->knobStyle = knobStyle;
     133    if ( m_data->knobStyle != knobStyle )
     134    {
     135        m_data->knobStyle = knobStyle;
    143136        update();
    144137    }
    … …  
    148141    \return Marker type of the knob
    149142    \sa setKnobStyle(), setBorderWidth()
    150 */
     143 */
    151144QwtKnob::KnobStyle QwtKnob::knobStyle() const
    152145{
    153     return d_data->knobStyle;
    154 }
    155 
    156 /*!
    157   \brief Set the marker type of the knob
    158 
    159   \param markerStyle Marker type
    160   \sa markerStyle(), setMarkerSize()
    161 */
     146    return m_data->knobStyle;
     147}
     148
     149/*!
     150   \brief Set the marker type of the knob
     151
     152   \param markerStyle Marker type
     153   \sa markerStyle(), setMarkerSize()
     154 */
    162155void QwtKnob::setMarkerStyle( MarkerStyle markerStyle )
    163156{
    164     if ( d_data->markerStyle != markerStyle )
    165     {
    166         d_data->markerStyle = markerStyle;
     157    if ( m_data->markerStyle != markerStyle )
     158    {
     159        m_data->markerStyle = markerStyle;
    167160        update();
    168161    }
    … …  
    170163
    171164/*!
    172   \return Marker type of the knob
    173   \sa setMarkerStyle(), setMarkerSize()
    174 */
     165   \return Marker type of the knob
     166   \sa setMarkerStyle(), setMarkerSize()
     167 */
    175168QwtKnob::MarkerStyle QwtKnob::markerStyle() const
    176169{
    177     return d_data->markerStyle;
    178 }
    179 
    180 /*!
    181   \brief Set the total angle by which the knob can be turned
    182   \param angle Angle in degrees.
    183 
    184   The angle has to be between [10, 360] degrees. Angles above
    185   360 ( so that the knob can be turned several times around its axis )
    186   have to be set using setNumTurns().
    187 
    188   The default angle is 270 degrees.
    189 
    190   \sa totalAngle(), setNumTurns()
    191 */
     170    return m_data->markerStyle;
     171}
     172
     173/*!
     174   \brief Set the total angle by which the knob can be turned
     175   \param angle Angle in degrees.
     176
     177   The angle has to be between [10, 360] degrees. Angles above
     178   360 ( so that the knob can be turned several times around its axis )
     179   have to be set using setNumTurns().
     180
     181   The default angle is 270 degrees.
     182
     183   \sa totalAngle(), setNumTurns()
     184 */
    192185void QwtKnob::setTotalAngle ( double angle )
    193186{
    194187    angle = qBound( 10.0, angle, 360.0 );
    195188
    196     if ( angle != d_data->totalAngle )
    197     {
    198         d_data->totalAngle = angle;
    199 
    200         scaleDraw()->setAngleRange( -0.5 * d_data->totalAngle,
    201             0.5 * d_data->totalAngle );
     189    if ( angle != m_data->totalAngle )
     190    {
     191        m_data->totalAngle = angle;
     192
     193        scaleDraw()->setAngleRange( -0.5 * m_data->totalAngle,
     194            0.5 * m_data->totalAngle );
    202195
    203196        updateGeometry();
    … …  
    207200
    208201/*!
    209   \return the total angle
    210   \sa setTotalAngle(), setNumTurns(), numTurns()
     202   \return the total angle
     203   \sa setTotalAngle(), setNumTurns(), numTurns()
    211204 */
    212205double QwtKnob::totalAngle() const
    213206{
    214     return d_data->totalAngle;
    215 }
    216 
    217 /*!
    218   \brief Set the number of turns
    219 
    220   When numTurns > 1 the knob can be turned several times around its axis
    221   - otherwise the total angle is floored to 360°.
    222 
    223   \sa numTurns(), totalAngle(), setTotalAngle()
    224 */
     207    return m_data->totalAngle;
     208}
     209
     210/*!
     211   \brief Set the number of turns
     212
     213   When numTurns > 1 the knob can be turned several times around its axis
     214   - otherwise the total angle is floored to 360°.
     215
     216   \sa numTurns(), totalAngle(), setTotalAngle()
     217 */
    225218
    226219void QwtKnob::setNumTurns( int numTurns )
    … …  
    228221    numTurns = qMax( numTurns, 1 );
    229222
    230     if ( numTurns == 1 && d_data->totalAngle <= 360.0 )
     223    if ( numTurns == 1 && m_data->totalAngle <= 360.0 )
    231224        return;
    232225
    233226    const double angle = numTurns * 360.0;
    234     if ( angle != d_data->totalAngle )
    235     {
    236         d_data->totalAngle = angle;
    237 
    238         scaleDraw()->setAngleRange( -0.5 * d_data->totalAngle,
    239             0.5 * d_data->totalAngle );
     227    if ( angle != m_data->totalAngle )
     228    {
     229        m_data->totalAngle = angle;
     230
     231        scaleDraw()->setAngleRange( -0.5 * m_data->totalAngle,
     232            0.5 * m_data->totalAngle );
    240233
    241234        updateGeometry();
    … …  
    245238
    246239/*!
    247   \return Number of turns.
    248 
    249   When the total angle is below 360° numTurns() is ceiled to 1.
    250   \sa setNumTurns(), setTotalAngle(), totalAngle()
     240   \return Number of turns.
     241
     242   When the total angle is below 360° numTurns() is ceiled to 1.
     243   \sa setNumTurns(), setTotalAngle(), totalAngle()
    251244 */
    252245int QwtKnob::numTurns() const
    253246{
    254     return qCeil( d_data->totalAngle / 360.0 );
     247    return qwtCeil( m_data->totalAngle / 360.0 );
    255248}
    256249
    … …  
    263256
    264257   \sa scaleDraw()
    265 */
    266 void QwtKnob::setScaleDraw( QwtRoundScaleDraw *scaleDraw )
     258 */
     259void QwtKnob::setScaleDraw( QwtRoundScaleDraw* scaleDraw )
    267260{
    268261    setAbstractScaleDraw( scaleDraw );
    269     setTotalAngle( d_data->totalAngle );
     262    setTotalAngle( m_data->totalAngle );
    270263
    271264    updateGeometry();
    … …  
    276269   \return the scale draw of the knob
    277270   \sa setScaleDraw()
    278 */
    279 const QwtRoundScaleDraw *QwtKnob::scaleDraw() const
    280 {
    281     return static_cast<const QwtRoundScaleDraw *>( abstractScaleDraw() );
     271 */
     272const QwtRoundScaleDraw* QwtKnob::scaleDraw() const
     273{
     274    return static_cast< const QwtRoundScaleDraw* >( abstractScaleDraw() );
    282275}
    283276
    … …  
    285278   \return the scale draw of the knob
    286279   \sa setScaleDraw()
    287 */
    288 QwtRoundScaleDraw *QwtKnob::scaleDraw()
    289 {
    290     return static_cast<QwtRoundScaleDraw *>( abstractScaleDraw() );
    291 }
    292 
    293 /*!
    294   Calculate the bounding rectangle of the knob without the scale
    295 
    296   \return Bounding rectangle of the knob
    297   \sa knobWidth(), alignment(), QWidget::contentsRect()
     280 */
     281QwtRoundScaleDraw* QwtKnob::scaleDraw()
     282{
     283    return static_cast< QwtRoundScaleDraw* >( abstractScaleDraw() );
     284}
     285
     286/*!
     287   Calculate the bounding rectangle of the knob without the scale
     288
     289   \return Bounding rectangle of the knob
     290   \sa knobWidth(), alignment(), QWidget::contentsRect()
    298291 */
    299292QRect QwtKnob::knobRect() const
    … …  
    301294    const QRect cr = contentsRect();
    302295
    303     const int extent = qCeil( scaleDraw()->extent( font() ) );
    304     const int d = extent + d_data->scaleDist;
    305 
    306     int w = d_data->knobWidth;
     296    const int extent = qwtCeil( scaleDraw()->extent( font() ) );
     297    const int d = extent + m_data->scaleDist;
     298
     299    int w = m_data->knobWidth;
    307300    if ( w <= 0 )
    308301    {
    … …  
    315308    QRect r( 0, 0, w, w );
    316309
    317     if ( d_data->alignment & Qt::AlignLeft )
     310    if ( m_data->alignment & Qt::AlignLeft )
    318311    {
    319312        r.moveLeft( cr.left() + d );
    320313    }
    321     else if ( d_data->alignment & Qt::AlignRight )
     314    else if ( m_data->alignment & Qt::AlignRight )
    322315    {
    323316        r.moveRight( cr.right() - d );
    … …  
    328321    }
    329322
    330     if ( d_data->alignment & Qt::AlignTop )
     323    if ( m_data->alignment & Qt::AlignTop )
    331324    {
    332325        r.moveTop( cr.top() + d );
    333326    }
    334     else if ( d_data->alignment & Qt::AlignBottom )
     327    else if ( m_data->alignment & Qt::AlignBottom )
    335328    {
    336329        r.moveBottom( cr.bottom() - d );
    … …  
    345338
    346339/*!
    347   \brief Determine what to do when the user presses a mouse button.
    348 
    349   \param pos Mouse position
    350 
    351   \retval True, when pos is inside the circle of the knob.
    352   \sa scrolledTo()
    353 */
    354 bool QwtKnob::isScrollPosition( const QPoint &pos ) const
     340   \brief Determine what to do when the user presses a mouse button.
     341
     342   \param pos Mouse position
     343
     344   \retval True, when pos is inside the circle of the knob.
     345   \sa scrolledTo()
     346 */
     347bool QwtKnob::isScrollPosition( const QPoint& pos ) const
    355348{
    356349    const QRect kr = knobRect();
    … …  
    362355        const double valueAngle = qwtToDegrees( scaleMap().transform( value() ) );
    363356
    364         d_data->mouseOffset = qwtNormalizeDegrees( angle - valueAngle );
     357        m_data->mouseOffset = qwtNormalizeDegrees( angle - valueAngle );
    365358
    366359        return true;
    … …  
    371364
    372365/*!
    373   \brief Determine the value for a new position of the mouse
    374 
    375   \param pos Mouse position
    376 
    377   \return Value for the mouse position
    378   \sa isScrollPosition()
    379 */
    380 double QwtKnob::scrolledTo( const QPoint &pos ) const
     366   \brief Determine the value for a new position of the mouse
     367
     368   \param pos Mouse position
     369
     370   \return Value for the mouse position
     371   \sa isScrollPosition()
     372 */
     373double QwtKnob::scrolledTo( const QPoint& pos ) const
    381374{
    382375    double angle = QLineF( rect().center(), pos ).angle();
    383     angle = qwtNormalizeDegrees( angle - d_data->mouseOffset );
     376    angle = qwtNormalizeDegrees( angle - m_data->mouseOffset );
    384377
    385378    if ( scaleMap().pDist() > 360.0 )
    … …  
    389382        const double v = scaleMap().transform( value() );
    390383
    391         int numTurns = qFloor( ( v - scaleMap().p1() ) / 360.0 );
     384        int numTurns = qwtFloor( ( v - scaleMap().p1() ) / 360.0 );
    392385
    393386        double valueAngle = qwtNormalizeDegrees( v );
    … …  
    404397                qBound( scaleMap().p1(), angle, scaleMap().p2() );
    405398
    406             d_data->mouseOffset += ( boundedAngle - angle );
     399            m_data->mouseOffset += ( boundedAngle - angle );
    407400            angle = boundedAngle;
    408401        }
    … …  
    423416                boundedAngle = scaleMap().p1();
    424417
    425             d_data->mouseOffset += ( boundedAngle - angle );
     418            m_data->mouseOffset += ( boundedAngle - angle );
    426419        }
    427420
    … …  
    433426
    434427/*!
    435   Handle QEvent::StyleChange and QEvent::FontChange;
    436   \param event Change event
    437 */
    438 void QwtKnob::changeEvent( QEvent *event )
     428   Handle QEvent::StyleChange and QEvent::FontChange;
     429   \param event Change event
     430 */
     431void QwtKnob::changeEvent( QEvent* event )
    439432{
    440433    switch( event->type() )
    … …  
    453446
    454447/*!
    455   Repaint the knob
    456   \param event Paint event
    457 */
    458 void QwtKnob::paintEvent( QPaintEvent *event )
     448   Repaint the knob
     449   \param event Paint event
     450 */
     451void QwtKnob::paintEvent( QPaintEvent* event )
    459452{
    460453    const QRectF knobRect = this->knobRect();
    … …  
    464457
    465458    QStyleOption opt;
    466     opt.init(this);
     459    opt.initFrom(this);
    467460    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
    468461
    … …  
    471464    if ( !knobRect.contains( event->region().boundingRect() ) )
    472465    {
    473         scaleDraw()->setRadius( 0.5 * knobRect.width() + d_data->scaleDist );
     466        scaleDraw()->setRadius( 0.5 * knobRect.width() + m_data->scaleDist );
    474467        scaleDraw()->moveCenter( knobRect.center() );
    475468
    … …  
    489482
    490483/*!
    491   \brief Draw the knob
    492 
    493   \param painter painter
    494   \param knobRect Bounding rectangle of the knob (without scale)
    495 */
    496 void QwtKnob::drawKnob( QPainter *painter, const QRectF &knobRect ) const
     484   \brief Draw the knob
     485
     486   \param painter painter
     487   \param knobRect Bounding rectangle of the knob (without scale)
     488 */
     489void QwtKnob::drawKnob( QPainter* painter, const QRectF& knobRect ) const
    497490{
    498491    double dim = qMin( knobRect.width(), knobRect.height() );
    499     dim -= d_data->borderWidth * 0.5;
     492    dim -= m_data->borderWidth * 0.5;
    500493
    501494    QRectF aRect( 0, 0, dim, dim );
    … …  
    503496
    504497    QPen pen( Qt::NoPen );
    505     if ( d_data->borderWidth > 0 )
     498    if ( m_data->borderWidth > 0 )
    506499    {
    507500        QColor c1 = palette().color( QPalette::Light );
    … …  
    514507        gradient.setColorAt( 1.0, c2 );
    515508
    516         pen = QPen( gradient, d_data->borderWidth );
     509        pen = QPen( gradient, m_data->borderWidth );
    517510    }
    518511
    519512    QBrush brush;
    520     switch( d_data->knobStyle )
     513    switch( m_data->knobStyle )
    521514    {
    522515        case QwtKnob::Raised:
    … …  
    542535
    543536            const QColor c = palette().color( QPalette::Button );
    544             gradient.setColorAt(0, c.lighter(110));
    545             gradient.setColorAt(qreal(0.5), c);
    546             gradient.setColorAt(qreal(0.501), c.darker(102));
    547             gradient.setColorAt(1, c.darker(115));
     537            gradient.setColorAt(0, c.lighter(110) );
     538            gradient.setColorAt( 0.5, c);
     539            gradient.setColorAt( 0.501, c.darker(102) );
     540            gradient.setColorAt(1, c.darker(115) );
    548541
    549542            brush = QBrush( gradient );
    … …  
    574567
    575568/*!
    576   \brief Draw the marker at the knob's front
    577 
    578   \param painter Painter
    579   \param rect Bounding rectangle of the knob without scale
    580   \param angle Angle of the marker in degrees
     569   \brief Draw the marker at the knob's front
     570
     571   \param painter Painter
     572   \param rect Bounding rectangle of the knob without scale
     573   \param angle Angle of the marker in degrees
    581574               ( clockwise, 0 at the 12 o'clock position )
    582 */
    583 void QwtKnob::drawMarker( QPainter *painter,
    584     const QRectF &rect, double angle ) const
    585 {
    586     if ( d_data->markerStyle == NoMarker || !isValid() )
     575 */
     576void QwtKnob::drawMarker( QPainter* painter,
     577    const QRectF& rect, double angle ) const
     578{
     579    if ( m_data->markerStyle == NoMarker || !isValid() )
    587580        return;
    588581
    … …  
    595588    const double margin = 4.0;
    596589
    597     double radius = 0.5 * ( rect.width() - d_data->borderWidth ) - margin;
     590    double radius = 0.5 * ( rect.width() - m_data->borderWidth ) - margin;
    598591    if ( radius < 1.0 )
    599592        radius = 1.0;
    600593
    601     int markerSize = d_data->markerSize;
     594    double markerSize = m_data->markerSize;
    602595    if ( markerSize <= 0 )
    603596        markerSize = qRound( 0.4 * radius );
    604597
    605     switch ( d_data->markerStyle )
     598    switch ( m_data->markerStyle )
    606599    {
    607600        case Notch:
    608601        case Nub:
    609602        {
    610             const double dotWidth =
    611                 qMin( double( markerSize ), radius);
     603            const double dotWidth = qwtMinF( markerSize, radius );
    612604
    613605            const double dotCenterDist = radius - 0.5 * dotWidth;
    … …  
    623615                QColor c2 = palette().color( QPalette::Mid );
    624616
    625                 if ( d_data->markerStyle == Notch )
     617                if ( m_data->markerStyle == Notch )
    626618                    qSwap( c1, c2 );
    627619
    … …  
    640632        case Dot:
    641633        {
    642             const double dotWidth =
    643                 qMin( double( markerSize ), radius);
     634            const double dotWidth = qwtMinF( markerSize, radius);
    644635
    645636            const double dotCenterDist = radius - 0.5 * dotWidth;
    … …  
    661652        case Tick:
    662653        {
    663             const double rb = qMax( radius - markerSize, 1.0 );
     654            const double rb = qwtMaxF( radius - markerSize, 1.0 );
    664655            const double re = radius;
    665656
    … …  
    676667        case Triangle:
    677668        {
    678             const double rb = qMax( radius - markerSize, 1.0 );
     669            const double rb = qwtMaxF( radius - markerSize, 1.0 );
    679670            const double re = radius;
    680671
    … …  
    701692
    702693/*!
    703   Draw the focus indicator
    704   \param painter Painter
    705 */
    706 void QwtKnob::drawFocusIndicator( QPainter *painter ) const
     694   Draw the focus indicator
     695   \param painter Painter
     696 */
     697void QwtKnob::drawFocusIndicator( QPainter* painter ) const
    707698{
    708699    const QRect cr = contentsRect();
    709700
    710     int w = d_data->knobWidth;
     701    int w = m_data->knobWidth;
    711702    if ( w <= 0 )
    712703    {
    … …  
    716707    {
    717708        const int extent = qCeil( scaleDraw()->extent( font() ) );
    718         w += 2 * ( extent + d_data->scaleDist );
     709        w += 2 * ( extent + m_data->scaleDist );
    719710    }
    720711
    … …  
    726717
    727718/*!
    728   \brief Set the alignment of the knob
    729 
    730   Similar to a QLabel::alignment() the flags decide how
    731   to align the knob inside of contentsRect().
    732 
    733   The default setting is Qt::AlignCenter
    734 
    735   \param alignment Or'd alignment flags
    736 
    737   \sa alignment(), setKnobWidth(), knobRect()
     719   \brief Set the alignment of the knob
     720
     721   Similar to a QLabel::alignment() the flags decide how
     722   to align the knob inside of contentsRect().
     723
     724   The default setting is Qt::AlignCenter
     725
     726   \param alignment Or'd alignment flags
     727
     728   \sa alignment(), setKnobWidth(), knobRect()
    738729 */
    739730void QwtKnob::setAlignment( Qt::Alignment alignment )
    740731{
    741     if ( d_data->alignment != alignment )
    742     {
    743         d_data->alignment = alignment;
     732    if ( m_data->alignment != alignment )
     733    {
     734        m_data->alignment = alignment;
    744735        update();
    745736    }
    … …  
    747738
    748739/*!
    749   \return Alignment of the knob inside of contentsRect()
    750   \sa setAlignment(), knobWidth(), knobRect()
     740   \return Alignment of the knob inside of contentsRect()
     741   \sa setAlignment(), knobWidth(), knobRect()
    751742 */
    752743Qt::Alignment QwtKnob::alignment() const
    753744{
    754     return d_data->alignment;
    755 }
    756 
    757 /*!
    758   \brief Change the knob's width.
    759 
    760   Setting a fixed value for the diameter of the knob
    761   is helpful for aligning several knobs in a row.
    762 
    763   \param width New width
    764 
    765   \sa knobWidth(), setAlignment()
    766   \note Modifies the sizePolicy()
    767 */
     745    return m_data->alignment;
     746}
     747
     748/*!
     749   \brief Change the knob's width.
     750
     751   Setting a fixed value for the diameter of the knob
     752   is helpful for aligning several knobs in a row.
     753
     754   \param width New width
     755
     756   \sa knobWidth(), setAlignment()
     757   \note Modifies the sizePolicy()
     758 */
    768759void QwtKnob::setKnobWidth( int width )
    769760{
    770761    width = qMax( width, 0 );
    771762
    772     if ( width != d_data->knobWidth )
     763    if ( width != m_data->knobWidth )
    773764    {
    774765        QSizePolicy::Policy policy;
    … …  
    780771        setSizePolicy( policy, policy );
    781772
    782         d_data->knobWidth = width;
     773        m_data->knobWidth = width;
    783774
    784775        updateGeometry();
    … …  
    790781int QwtKnob::knobWidth() const
    791782{
    792     return d_data->knobWidth;
    793 }
    794 
    795 /*!
    796   \brief Set the knob's border width
    797   \param borderWidth new border width
    798 */
     783    return m_data->knobWidth;
     784}
     785
     786/*!
     787   \brief Set the knob's border width
     788   \param borderWidth new border width
     789 */
    799790void QwtKnob::setBorderWidth( int borderWidth )
    800791{
    801     d_data->borderWidth = qMax( borderWidth, 0 );
     792    m_data->borderWidth = qMax( borderWidth, 0 );
    802793
    803794    updateGeometry();
    … …  
    808799int QwtKnob::borderWidth() const
    809800{
    810     return d_data->borderWidth;
    811 }
    812 
    813 /*!
    814   \brief Set the size of the marker
    815 
    816   When setting a size <= 0 the marker will
    817   automatically scaled to 40% of the radius of the knob.
    818 
    819   \sa markerSize(), markerStyle()
    820 */
     801    return m_data->borderWidth;
     802}
     803
     804/*!
     805   \brief Set the size of the marker
     806
     807   When setting a size <= 0 the marker will
     808   automatically scaled to 40% of the radius of the knob.
     809
     810   \sa markerSize(), markerStyle()
     811 */
    821812void QwtKnob::setMarkerSize( int size )
    822813{
    823     if ( d_data->markerSize != size )
    824     {
    825         d_data->markerSize = size;
     814    if ( m_data->markerSize != size )
     815    {
     816        m_data->markerSize = size;
    826817        update();
    827818    }
    … …  
    829820
    830821/*!
    831   \return Marker size
    832   \sa setMarkerSize()
     822   \return Marker size
     823   \sa setMarkerSize()
    833824 */
    834825int QwtKnob::markerSize() const
    835826{
    836     return d_data->markerSize;
    837 }
    838 
    839 /*!
    840   \return sizeHint()
    841 */
     827    return m_data->markerSize;
     828}
     829
     830/*!
     831   \return sizeHint()
     832 */
    842833QSize QwtKnob::sizeHint() const
    843834{
    844835    const QSize hint = qwtKnobSizeHint( this, 50 );
    845     return hint.expandedTo( QApplication::globalStrut() );
    846 }
    847 
    848 /*!
    849   \return Minimum size hint
    850   \sa sizeHint()
    851 */
     836    return qwtExpandedToGlobalStrut( hint );
     837}
     838
     839/*!
     840   \return Minimum size hint
     841   \sa sizeHint()
     842 */
    852843QSize QwtKnob::minimumSizeHint() const
    853844{
    854845    return qwtKnobSizeHint( this, 20 );
    855846}
     847
     848#include "moc_qwt_knob.cpp"
  • trunk/BNC/qwt/qwt_knob.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1717
    1818/*!
    19   \brief The Knob Widget
     19   \brief The Knob Widget
    2020
    21   The QwtKnob widget imitates look and behavior of a volume knob on a radio.
    22   It looks similar to QDial - not to QwtDial.
     21   The QwtKnob widget imitates look and behavior of a volume knob on a radio.
     22   It looks similar to QDial - not to QwtDial.
    2323
    24   The value range of a knob might be divided into several turns.
     24   The value range of a knob might be divided into several turns.
    2525
    26   The layout of the knob depends on the knobWidth().
     26   The layout of the knob depends on the knobWidth().
    2727
    28   - width > 0
     28   - width > 0
    2929    The diameter of the knob is fixed and the knob is aligned
    3030    according to the alignment() flags inside of the contentsRect().
    3131
    32   - width <= 0
     32   - width <= 0
    3333    The knob is extended to the minimum of width/height of the contentsRect()
    3434    and aligned in the other direction according to alignment().
    3535
    36   Setting a fixed knobWidth() is helpful to align several knobs with different
    37   scale labels.
     36   Setting a fixed knobWidth() is helpful to align several knobs with different
     37   scale labels.
    3838
    39   \image html knob.png
    40 */
     39   \image html knob.png
     40 */
    4141
    42 class QWT_EXPORT QwtKnob: public QwtAbstractSlider
     42class QWT_EXPORT QwtKnob : public QwtAbstractSlider
    4343{
    4444    Q_OBJECT
    … …  
    5555    Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
    5656
    57 public:
     57  public:
    5858    /*!
    5959       \brief Style of the knob surface
    … …  
    7373
    7474        /*!
    75           Build a gradient from QPalette::Midlight, QPalette::Button
    76           and QPalette::Midlight
     75           Build a gradient from QPalette::Midlight, QPalette::Button
     76           and QPalette::Midlight
    7777         */
    7878        Sunken,
    7979
    8080        /*!
    81           Build a radial gradient from QPalette::Button
    82           like it is used for QDial in various Qt styles.
     81           Build a radial gradient from QPalette::Button
     82           like it is used for QDial in various Qt styles.
    8383         */
    8484        Styled
    … …  
    9292
    9393        \sa setMarkerStyle(), setMarkerSize()
    94     */
     94     */
    9595    enum MarkerStyle
    9696    {
    … …  
    108108
    109109        /*!
    110           Draw a raised ellipse with a gradient build from
    111           QPalette::Light and QPalette::Mid
     110           Draw a raised ellipse with a gradient build from
     111           QPalette::Light and QPalette::Mid
    112112         */
    113113        Nub,
    114114
    115115        /*!
    116           Draw a sunken ellipse with a gradient build from
    117           QPalette::Light and QPalette::Mid
     116           Draw a sunken ellipse with a gradient build from
     117           QPalette::Light and QPalette::Mid
    118118         */
    119119        Notch
    … …  
    147147    int markerSize() const;
    148148
    149     virtual QSize sizeHint() const;
    150     virtual QSize minimumSizeHint() const;
     149    virtual QSize sizeHint() const QWT_OVERRIDE;
     150    virtual QSize minimumSizeHint() const QWT_OVERRIDE;
    151151
    152     void setScaleDraw( QwtRoundScaleDraw * );
     152    void setScaleDraw( QwtRoundScaleDraw* );
    153153
    154     const QwtRoundScaleDraw *scaleDraw() const;
    155     QwtRoundScaleDraw *scaleDraw();
     154    const QwtRoundScaleDraw* scaleDraw() const;
     155    QwtRoundScaleDraw* scaleDraw();
    156156
    157157    QRect knobRect() const;
    158158
    159 protected:
    160     virtual void paintEvent( QPaintEvent * );
    161     virtual void changeEvent( QEvent * );
     159  protected:
     160    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
     161    virtual void changeEvent( QEvent* ) QWT_OVERRIDE;
    162162
    163     virtual void drawKnob( QPainter *, const QRectF & ) const;
     163    virtual void drawKnob( QPainter*, const QRectF& ) const;
    164164
    165     virtual void drawFocusIndicator( QPainter * ) const;
     165    virtual void drawFocusIndicator( QPainter* ) const;
    166166
    167     virtual void drawMarker( QPainter *,
    168         const QRectF &, double angle ) const;
     167    virtual void drawMarker( QPainter*,
     168        const QRectF&, double angle ) const;
    169169
    170     virtual double scrolledTo( const QPoint & ) const;
    171     virtual bool isScrollPosition( const QPoint & ) const;
     170    virtual double scrolledTo( const QPoint& ) const QWT_OVERRIDE;
     171    virtual bool isScrollPosition( const QPoint& ) const QWT_OVERRIDE;
    172172
    173 private:
     173  private:
    174174    class PrivateData;
    175     PrivateData *d_data;
     175    PrivateData* m_data;
    176176};
    177177
  • trunk/BNC/qwt/qwt_legend.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212#include "qwt_dyngrid_layout.h"
    1313#include "qwt_math.h"
    14 #include "qwt_plot_item.h"
    1514#include "qwt_painter.h"
     15#include "qwt_graphic.h"
     16
    1617#include <qapplication.h>
    1718#include <qscrollbar.h>
    1819#include <qscrollarea.h>
    1920#include <qpainter.h>
    20 #include <qstyle.h>
    21 #include <qstyleoption.h>
    22 
    23 class QwtLegendMap
    24 {
    25 public:
    26     inline bool isEmpty() const { return d_entries.isEmpty(); }
    27 
    28     void insert( const QVariant &, const QList<QWidget *> & );
    29     void remove( const QVariant & );
    30 
    31     void removeWidget( const QWidget * );
    32 
    33     QList<QWidget *> legendWidgets( const QVariant & ) const;
    34     QVariant itemInfo( const QWidget * ) const;
    35 
    36 private:
    37     // we don't know anything about itemInfo and therefore don't have
    38     // any key that can be used for a map or hashtab.
    39     // But a simple linear list is o.k. here, as we will never have
    40     // more than a few entries.
    41 
    42     class Entry
    43     {
    44     public:
    45         QVariant itemInfo;
    46         QList<QWidget *> widgets;
     21#include <qmargins.h>
     22
     23namespace
     24{
     25    class LegendMap
     26    {
     27      public:
     28        inline bool isEmpty() const { return m_entries.isEmpty(); }
     29
     30        void insert( const QVariant&, const QList< QWidget* >& );
     31        void remove( const QVariant& );
     32
     33        void removeWidget( const QWidget* );
     34
     35        QList< QWidget* > legendWidgets( const QVariant& ) const;
     36        QVariant itemInfo( const QWidget* ) const;
     37
     38      private:
     39        // we don't know anything about itemInfo and therefore don't have
     40        // any key that can be used for a map or hashtab.
     41        // But a simple linear list is o.k. here, as we will never have
     42        // more than a few entries.
     43
     44        class Entry
     45        {
     46          public:
     47            QVariant itemInfo;
     48            QList< QWidget* > widgets;
     49        };
     50
     51        QList< Entry > m_entries;
    4752    };
    4853
    49     QList< Entry > d_entries;
     54    void LegendMap::insert( const QVariant& itemInfo,
     55        const QList< QWidget* >& widgets )
     56    {
     57        for ( int i = 0; i < m_entries.size(); i++ )
     58        {
     59            Entry& entry = m_entries[i];
     60            if ( entry.itemInfo == itemInfo )
     61            {
     62                entry.widgets = widgets;
     63                return;
     64            }
     65        }
     66
     67        Entry newEntry;
     68        newEntry.itemInfo = itemInfo;
     69        newEntry.widgets = widgets;
     70
     71        m_entries += newEntry;
     72    }
     73
     74    void LegendMap::remove( const QVariant& itemInfo )
     75    {
     76        for ( int i = 0; i < m_entries.size(); i++ )
     77        {
     78            Entry& entry = m_entries[i];
     79            if ( entry.itemInfo == itemInfo )
     80            {
     81                m_entries.removeAt( i );
     82                return;
     83            }
     84        }
     85    }
     86
     87    void LegendMap::removeWidget( const QWidget* widget )
     88    {
     89        QWidget* w = const_cast< QWidget* >( widget );
     90
     91        for ( int i = 0; i < m_entries.size(); i++ )
     92            m_entries[ i ].widgets.removeAll( w );
     93    }
     94
     95    QVariant LegendMap::itemInfo( const QWidget* widget ) const
     96    {
     97        if ( widget != NULL )
     98        {
     99            QWidget* w = const_cast< QWidget* >( widget );
     100
     101            for ( int i = 0; i < m_entries.size(); i++ )
     102            {
     103                const Entry& entry = m_entries[i];
     104                if ( entry.widgets.indexOf( w ) >= 0 )
     105                    return entry.itemInfo;
     106            }
     107        }
     108
     109        return QVariant();
     110    }
     111
     112    QList< QWidget* > LegendMap::legendWidgets( const QVariant& itemInfo ) const
     113    {
     114        if ( itemInfo.isValid() )
     115        {
     116            for ( int i = 0; i < m_entries.size(); i++ )
     117            {
     118                const Entry& entry = m_entries[i];
     119                if ( entry.itemInfo == itemInfo )
     120                    return entry.widgets;
     121            }
     122        }
     123
     124        return QList< QWidget* >();
     125    }
     126}
     127
     128class QwtLegend::PrivateData
     129{
     130  public:
     131    PrivateData()
     132        : itemMode( QwtLegendData::ReadOnly )
     133        , view( NULL )
     134    {
     135    }
     136
     137    QwtLegendData::Mode itemMode;
     138    LegendMap itemMap;
     139
     140    class LegendView;
     141    LegendView* view;
    50142};
    51143
    52 void QwtLegendMap::insert( const QVariant &itemInfo,
    53     const QList<QWidget *> &widgets )
    54 {
    55     for ( int i = 0; i < d_entries.size(); i++ )
    56     {
    57         Entry &entry = d_entries[i];
    58         if ( entry.itemInfo == itemInfo )
    59         {
    60             entry.widgets = widgets;
    61             return;
    62         }
    63     }
    64 
    65     Entry newEntry;
    66     newEntry.itemInfo = itemInfo;
    67     newEntry.widgets = widgets;
    68 
    69     d_entries += newEntry;
    70 }
    71 
    72 void QwtLegendMap::remove( const QVariant &itemInfo )
    73 {
    74     for ( int i = 0; i < d_entries.size(); i++ )
    75     {
    76         Entry &entry = d_entries[i];
    77         if ( entry.itemInfo == itemInfo )
    78         {
    79             d_entries.removeAt( i );
    80             return;
    81         }
    82     }
    83 }
    84 
    85 void QwtLegendMap::removeWidget( const QWidget *widget )
    86 {
    87     QWidget *w = const_cast<QWidget *>( widget );
    88 
    89     for ( int i = 0; i < d_entries.size(); i++ )
    90         d_entries[ i ].widgets.removeAll( w );
    91 }
    92 
    93 QVariant QwtLegendMap::itemInfo( const QWidget *widget ) const
    94 {
    95     if ( widget != NULL )
    96     {
    97         QWidget *w = const_cast<QWidget *>( widget );
    98 
    99         for ( int i = 0; i < d_entries.size(); i++ )
    100         {
    101             const Entry &entry = d_entries[i];
    102             if ( entry.widgets.indexOf( w ) >= 0 )
    103                 return entry.itemInfo;
    104         }
    105     }
    106 
    107     return QVariant();
    108 }
    109 
    110 QList<QWidget *> QwtLegendMap::legendWidgets( const QVariant &itemInfo ) const
    111 {
    112     if ( itemInfo.isValid() )
    113     {
    114         for ( int i = 0; i < d_entries.size(); i++ )
    115         {
    116             const Entry &entry = d_entries[i];
    117             if ( entry.itemInfo == itemInfo )
    118                 return entry.widgets;
    119         }
    120     }
    121 
    122     return QList<QWidget *>();
    123 }
    124 
    125 class QwtLegend::PrivateData
    126 {
    127 public:
    128     PrivateData():
    129         itemMode( QwtLegendData::ReadOnly ),
    130         view( NULL )
    131     {
    132     }
    133 
    134     QwtLegendData::Mode itemMode;
    135     QwtLegendMap itemMap;
    136 
    137     class LegendView;
    138     LegendView *view;
    139 };
    140 
    141 class QwtLegend::PrivateData::LegendView: public QScrollArea
    142 {
    143 public:
    144     explicit LegendView( QWidget *parent ):
     144class QwtLegend::PrivateData::LegendView QWT_FINAL : public QScrollArea
     145{
     146  public:
     147    explicit LegendView( QWidget * parent ) :
    145148        QScrollArea( parent )
    146149    {
    … …  
    159162    }
    160163
    161     virtual bool event( QEvent *event )
     164    virtual bool event( QEvent* event ) QWT_OVERRIDE
    162165    {
    163166        if ( event->type() == QEvent::PolishRequest )
    … …  
    187190    }
    188191
    189     virtual bool viewportEvent( QEvent *event )
     192    virtual bool viewportEvent( QEvent* event ) QWT_OVERRIDE
    190193    {
    191194        bool ok = QScrollArea::viewportEvent( event );
    … …  
    223226    void layoutContents()
    224227    {
    225         const QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>(
     228        const QwtDynGridLayout* tl = qobject_cast< QwtDynGridLayout* >(
    226229            contentsWidget->layout() );
    227230        if ( tl == NULL )
    … …  
    230233        const QSize visibleSize = viewport()->contentsRect().size();
    231234
    232         const int minW = int( tl->maxItemWidth() ) + 2 * tl->margin();
     235        const QMargins m = tl->contentsMargins();
     236        const int minW = tl->maxItemWidth() + m.left() + m.right();
    233237
    234238        int w = qMax( visibleSize.width(), minW );
    … …  
    245249    }
    246250
    247     QWidget *contentsWidget;
     251    QWidget* contentsWidget;
    248252};
    249253
    250254/*!
    251   Constructor
    252   \param parent Parent widget
    253 */
    254 QwtLegend::QwtLegend( QWidget *parent ):
    255     QwtAbstractLegend( parent )
     255   Constructor
     256   \param parent Parent widget
     257 */
     258QwtLegend::QwtLegend( QWidget* parent )
     259    : QwtAbstractLegend( parent )
    256260{
    257261    setFrameStyle( NoFrame );
    258262
    259     d_data = new QwtLegend::PrivateData;
    260 
    261     d_data->view = new QwtLegend::PrivateData::LegendView( this );
    262     d_data->view->setObjectName( "QwtLegendView" );
    263     d_data->view->setFrameStyle( NoFrame );
    264 
    265     QwtDynGridLayout *gridLayout = new QwtDynGridLayout(
    266         d_data->view->contentsWidget );
     263    m_data = new QwtLegend::PrivateData;
     264
     265    m_data->view = new QwtLegend::PrivateData::LegendView( this );
     266    m_data->view->setObjectName( "QwtLegendView" );
     267    m_data->view->setFrameStyle( NoFrame );
     268
     269    QwtDynGridLayout* gridLayout = new QwtDynGridLayout(
     270        m_data->view->contentsWidget );
    267271    gridLayout->setAlignment( Qt::AlignHCenter | Qt::AlignTop );
    268272
    269     d_data->view->contentsWidget->installEventFilter( this );
    270 
    271     QVBoxLayout *layout = new QVBoxLayout( this );
     273    m_data->view->contentsWidget->installEventFilter( this );
     274
     275    QVBoxLayout* layout = new QVBoxLayout( this );
    272276    layout->setContentsMargins( 0, 0, 0, 0 );
    273     layout->addWidget( d_data->view );
     277    layout->addWidget( m_data->view );
    274278}
    275279
    … …  
    277281QwtLegend::~QwtLegend()
    278282{
    279     delete d_data;
    280 }
    281 
    282 /*!
    283   \brief Set the maximum number of entries in a row
    284 
    285   F.e when the maximum is set to 1 all items are aligned
    286   vertically. 0 means unlimited
    287 
    288   \param numColums Maximum number of entries in a row
    289 
    290   \sa maxColumns(), QwtDynGridLayout::setMaxColumns()
     283    delete m_data;
     284}
     285
     286/*!
     287   \brief Set the maximum number of entries in a row
     288
     289   F.e when the maximum is set to 1 all items are aligned
     290   vertically. 0 means unlimited
     291
     292   \param numColums Maximum number of entries in a row
     293
     294   \sa maxColumns(), QwtDynGridLayout::setMaxColumns()
    291295 */
    292296void QwtLegend::setMaxColumns( uint numColums )
    293297{
    294     QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>(
    295         d_data->view->contentsWidget->layout() );
     298    QwtDynGridLayout* tl = qobject_cast< QwtDynGridLayout* >(
     299        m_data->view->contentsWidget->layout() );
    296300    if ( tl )
    297301        tl->setMaxColumns( numColums );
    … …  
    301305
    302306/*!
    303   \return Maximum number of entries in a row
    304   \sa setMaxColumns(), QwtDynGridLayout::maxColumns()
     307   \return Maximum number of entries in a row
     308   \sa setMaxColumns(), QwtDynGridLayout::maxColumns()
    305309 */
    306310uint QwtLegend::maxColumns() const
    … …  
    308312    uint maxCols = 0;
    309313
    310     const QwtDynGridLayout *tl = qobject_cast<const QwtDynGridLayout *>(
    311         d_data->view->contentsWidget->layout() );
     314    const QwtDynGridLayout* tl = qobject_cast< const QwtDynGridLayout* >(
     315        m_data->view->contentsWidget->layout() );
    312316    if ( tl )
    313317        maxCols = tl->maxColumns();
    … …  
    317321
    318322/*!
    319   \brief Set the default mode for legend labels
    320 
    321   Legend labels will be constructed according to the
    322   attributes in a QwtLegendData object. When it doesn't
    323   contain a value for the QwtLegendData::ModeRole the
    324   label will be initialized with the default mode of the legend.
    325 
    326   \param mode Default item mode
    327 
    328   \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData()
    329   \note Changing the mode doesn't have any effect on existing labels.
     323   \brief Set the default mode for legend labels
     324
     325   Legend labels will be constructed according to the
     326   attributes in a QwtLegendData object. When it doesn't
     327   contain a value for the QwtLegendData::ModeRole the
     328   label will be initialized with the default mode of the legend.
     329
     330   \param mode Default item mode
     331
     332   \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData()
     333   \note Changing the mode doesn't have any effect on existing labels.
    330334 */
    331335void QwtLegend::setDefaultItemMode( QwtLegendData::Mode mode )
    332336{
    333     d_data->itemMode = mode;
    334 }
    335 
    336 /*!
    337   \return Default item mode
    338   \sa setDefaultItemMode()
    339 */
     337    m_data->itemMode = mode;
     338}
     339
     340/*!
     341   \return Default item mode
     342   \sa setDefaultItemMode()
     343 */
    340344QwtLegendData::Mode QwtLegend::defaultItemMode() const
    341345{
    342     return d_data->itemMode;
    343 }
    344 
    345 /*!
    346   The contents widget is the only child of the viewport of
    347   the internal QScrollArea and the parent widget of all legend items.
    348 
    349   \return Container widget of the legend items
    350 */
    351 QWidget *QwtLegend::contentsWidget()
    352 {
    353     return d_data->view->contentsWidget;
    354 }
    355 
    356 /*!
    357   \return Horizontal scrollbar
    358   \sa verticalScrollBar()
    359 */
    360 QScrollBar *QwtLegend::horizontalScrollBar() const
    361 {
    362     return d_data->view->horizontalScrollBar();
    363 }
    364 
    365 /*!
    366   \return Vertical scrollbar
    367   \sa horizontalScrollBar()
    368 */
    369 QScrollBar *QwtLegend::verticalScrollBar() const
    370 {
    371     return d_data->view->verticalScrollBar();
    372 }
    373 
    374 /*!
    375   The contents widget is the only child of the viewport of
    376   the internal QScrollArea and the parent widget of all legend items.
    377 
    378   \return Container widget of the legend items
    379 
    380 */
    381 const QWidget *QwtLegend::contentsWidget() const
    382 {
    383     return d_data->view->contentsWidget;
    384 }
    385 
    386 /*!
    387   \brief Update the entries for an item
    388 
    389   \param itemInfo Info for an item
    390   \param legendData List of legend entry attributes for the item
    391  */
    392 void QwtLegend::updateLegend( const QVariant &itemInfo,
    393     const QList<QwtLegendData> &legendData )
    394 {
    395     QList<QWidget *> widgetList = legendWidgets( itemInfo );
     346    return m_data->itemMode;
     347}
     348
     349/*!
     350   The contents widget is the only child of the viewport of
     351   the internal QScrollArea and the parent widget of all legend items.
     352
     353   \return Container widget of the legend items
     354 */
     355QWidget* QwtLegend::contentsWidget()
     356{
     357    return m_data->view->contentsWidget;
     358}
     359
     360/*!
     361   \return Horizontal scrollbar
     362   \sa verticalScrollBar()
     363 */
     364QScrollBar* QwtLegend::horizontalScrollBar() const
     365{
     366    return m_data->view->horizontalScrollBar();
     367}
     368
     369/*!
     370   \return Vertical scrollbar
     371   \sa horizontalScrollBar()
     372 */
     373QScrollBar* QwtLegend::verticalScrollBar() const
     374{
     375    return m_data->view->verticalScrollBar();
     376}
     377
     378/*!
     379   The contents widget is the only child of the viewport of
     380   the internal QScrollArea and the parent widget of all legend items.
     381
     382   \return Container widget of the legend items
     383
     384 */
     385const QWidget* QwtLegend::contentsWidget() const
     386{
     387    return m_data->view->contentsWidget;
     388}
     389
     390/*!
     391   \brief Update the entries for an item
     392
     393   \param itemInfo Info for an item
     394   \param legendData List of legend entry attributes for the item
     395 */
     396void QwtLegend::updateLegend( const QVariant& itemInfo,
     397    const QList< QwtLegendData >& legendData )
     398{
     399    QList< QWidget* > widgetList = legendWidgets( itemInfo );
    396400
    397401    if ( widgetList.size() != legendData.size() )
    398402    {
    399         QLayout *contentsLayout = d_data->view->contentsWidget->layout();
     403        QLayout* contentsLayout = m_data->view->contentsWidget->layout();
    400404
    401405        while ( widgetList.size() > legendData.size() )
    402406        {
    403             QWidget *w = widgetList.takeLast();
     407            QWidget* w = widgetList.takeLast();
    404408
    405409            contentsLayout->removeWidget( w );
    … …  
    412416        }
    413417
    414 #if QT_VERSION >= 0x040700
    415418        widgetList.reserve( legendData.size() );
    416 #endif
    417419
    418420        for ( int i = widgetList.size(); i < legendData.size(); i++ )
    419421        {
    420             QWidget *widget = createWidget( legendData[i] );
     422            QWidget* widget = createWidget( legendData[i] );
    421423
    422424            if ( contentsLayout )
    … …  
    438440        if ( widgetList.isEmpty() )
    439441        {
    440             d_data->itemMap.remove( itemInfo );
     442            m_data->itemMap.remove( itemInfo );
    441443        }
    442444        else
    443445        {
    444             d_data->itemMap.insert( itemInfo, widgetList );
     446            m_data->itemMap.insert( itemInfo, widgetList );
    445447        }
    446448
    … …  
    453455
    454456/*!
    455   \brief Create a widget to be inserted into the legend
    456 
    457   The default implementation returns a QwtLegendLabel.
    458 
    459   \param legendData Attributes of the legend entry
    460   \return Widget representing data on the legend
    461 
    462   \note updateWidget() will called soon after createWidget()
     457   \brief Create a widget to be inserted into the legend
     458
     459   The default implementation returns a QwtLegendLabel.
     460
     461   \param legendData Attributes of the legend entry
     462   \return Widget representing data on the legend
     463
     464   \note updateWidget() will called soon after createWidget()
    463465        with the same attributes.
    464466 */
    465 QWidget *QwtLegend::createWidget( const QwtLegendData &legendData ) const
     467QWidget* QwtLegend::createWidget( const QwtLegendData& legendData ) const
    466468{
    467469    Q_UNUSED( legendData );
    468470
    469     QwtLegendLabel *label = new QwtLegendLabel();
     471    QwtLegendLabel* label = new QwtLegendLabel();
    470472    label->setItemMode( defaultItemMode() );
    471473
    … …  
    477479
    478480/*!
    479   \brief Update the widget
    480 
    481   \param widget Usually a QwtLegendLabel
    482   \param legendData Attributes to be displayed
    483 
    484   \sa createWidget()
    485   \note When widget is no QwtLegendLabel updateWidget() does nothing.
    486  */
    487 void QwtLegend::updateWidget( QWidget *widget, const QwtLegendData &legendData )
    488 {
    489     QwtLegendLabel *label = qobject_cast<QwtLegendLabel *>( widget );
     481   \brief Update the widget
     482
     483   \param widget Usually a QwtLegendLabel
     484   \param legendData Attributes to be displayed
     485
     486   \sa createWidget()
     487   \note When widget is no QwtLegendLabel updateWidget() does nothing.
     488 */
     489void QwtLegend::updateWidget( QWidget* widget, const QwtLegendData& legendData )
     490{
     491    QwtLegendLabel* label = qobject_cast< QwtLegendLabel* >( widget );
    490492    if ( label )
    491493    {
    … …  
    503505void QwtLegend::updateTabOrder()
    504506{
    505     QLayout *contentsLayout = d_data->view->contentsWidget->layout();
     507    QLayout* contentsLayout = m_data->view->contentsWidget->layout();
    506508    if ( contentsLayout )
    507509    {
    508510        // set tab focus chain
    509511
    510         QWidget *w = NULL;
     512        QWidget* w = NULL;
    511513
    512514        for ( int i = 0; i < contentsLayout->count(); i++ )
    513515        {
    514             QLayoutItem *item = contentsLayout->itemAt( i );
     516            QLayoutItem* item = contentsLayout->itemAt( i );
    515517            if ( w && item->widget() )
    516518                QWidget::setTabOrder( w, item->widget() );
    … …  
    524526QSize QwtLegend::sizeHint() const
    525527{
    526     QSize hint = d_data->view->contentsWidget->sizeHint();
     528    QSize hint = m_data->view->contentsWidget->sizeHint();
    527529    hint += QSize( 2 * frameWidth(), 2 * frameWidth() );
    528530
    … …  
    531533
    532534/*!
    533   \return The preferred height, for a width.
    534   \param width Width
    535 */
     535   \return The preferred height, for a width.
     536   \param width Width
     537 */
    536538int QwtLegend::heightForWidth( int width ) const
    537539{
    538540    width -= 2 * frameWidth();
    539541
    540     int h = d_data->view->contentsWidget->heightForWidth( width );
     542    int h = m_data->view->contentsWidget->heightForWidth( width );
    541543    if ( h >= 0 )
    542544        h += 2 * frameWidth();
    … …  
    547549
    548550/*!
    549   Handle QEvent::ChildRemoved andQEvent::LayoutRequest events
    550   for the contentsWidget().
    551 
    552   \param object Object to be filtered
    553   \param event Event
    554 
    555   \return Forwarded to QwtAbstractLegend::eventFilter()
    556 */
    557 bool QwtLegend::eventFilter( QObject *object, QEvent *event )
    558 {
    559     if ( object == d_data->view->contentsWidget )
     551   Handle QEvent::ChildRemoved and QEvent::LayoutRequest events
     552   for the contentsWidget().
     553
     554   \param object Object to be filtered
     555   \param event Event
     556
     557   \return Forwarded to QwtAbstractLegend::eventFilter()
     558 */
     559bool QwtLegend::eventFilter( QObject* object, QEvent* event )
     560{
     561    if ( object == m_data->view->contentsWidget )
    560562    {
    561563        switch ( event->type() )
    … …  
    563565            case QEvent::ChildRemoved:
    564566            {
    565                 const QChildEvent *ce =
    566                     static_cast<const QChildEvent *>(event);
     567                const QChildEvent* ce =
     568                    static_cast< const QChildEvent* >( event );
    567569
    568570                if ( ce->child()->isWidgetType() )
    … …  
    573575                        to remove it from the map.
    574576                     */
    575                     QWidget *w = reinterpret_cast< QWidget * >( ce->child() );
    576                     d_data->itemMap.removeWidget( w );
     577                    QWidget* w = reinterpret_cast< QWidget* >( ce->child() );
     578                    m_data->itemMap.removeWidget( w );
    577579                }
    578580                break;
    … …  
    580582            case QEvent::LayoutRequest:
    581583            {
    582                 d_data->view->layoutContents();
     584                m_data->view->layoutContents();
    583585
    584586                if ( parentWidget() && parentWidget()->layout() == NULL )
    … …  
    609611
    610612/*!
    611   Called internally when the legend has been clicked on.
    612   Emits a clicked() signal.
    613 */
     613   Called internally when the legend has been clicked on.
     614   Emits a clicked() signal.
     615 */
    614616void QwtLegend::itemClicked()
    615617{
    616     QWidget *w = qobject_cast<QWidget *>( sender() );
     618    QWidget* w = qobject_cast< QWidget* >( sender() );
    617619    if ( w )
    618620    {
    619         const QVariant itemInfo = d_data->itemMap.itemInfo( w );
     621        const QVariant itemInfo = m_data->itemMap.itemInfo( w );
    620622        if ( itemInfo.isValid() )
    621623        {
    622             const QList<QWidget *> widgetList =
    623                 d_data->itemMap.legendWidgets( itemInfo );
     624            const QList< QWidget* > widgetList =
     625                m_data->itemMap.legendWidgets( itemInfo );
    624626
    625627            const int index = widgetList.indexOf( w );
    … …  
    631633
    632634/*!
    633   Called internally when the legend has been checked
    634   Emits a checked() signal.
    635 */
     635   Called internally when the legend has been checked
     636   Emits a checked() signal.
     637 */
    636638void QwtLegend::itemChecked( bool on )
    637639{
    638     QWidget *w = qobject_cast<QWidget *>( sender() );
     640    QWidget* w = qobject_cast< QWidget* >( sender() );
    639641    if ( w )
    640642    {
    641         const QVariant itemInfo = d_data->itemMap.itemInfo( w );
     643        const QVariant itemInfo = m_data->itemMap.itemInfo( w );
    642644        if ( itemInfo.isValid() )
    643645        {
    644             const QList<QWidget *> widgetList =
    645                 d_data->itemMap.legendWidgets( itemInfo );
     646            const QList< QWidget* > widgetList =
     647                m_data->itemMap.legendWidgets( itemInfo );
    646648
    647649            const int index = widgetList.indexOf( w );
    … …  
    653655
    654656/*!
    655   Render the legend into a given rectangle.
    656 
    657   \param painter Painter
    658   \param rect Bounding rectangle
    659   \param fillBackground When true, fill rect with the widget background
    660 
    661   \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself
    662 */
    663 void QwtLegend::renderLegend( QPainter *painter,
    664     const QRectF &rect, bool fillBackground ) const
    665 {
    666     if ( d_data->itemMap.isEmpty() )
     657   Render the legend into a given rectangle.
     658
     659   \param painter Painter
     660   \param rect Bounding rectangle
     661   \param fillBackground When true, fill rect with the widget background
     662
     663   \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself
     664 */
     665void QwtLegend::renderLegend( QPainter* painter,
     666    const QRectF& rect, bool fillBackground ) const
     667{
     668    if ( m_data->itemMap.isEmpty() )
    667669        return;
    668670
    … …  
    676678    }
    677679
    678     const QwtDynGridLayout *legendLayout =
    679         qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );
     680    const QwtDynGridLayout* legendLayout =
     681        qobject_cast< QwtDynGridLayout* >( contentsWidget()->layout() );
    680682    if ( legendLayout == NULL )
    681683        return;
    682684
    683     int left, right, top, bottom;
    684     getContentsMargins( &left, &top, &right, &bottom );
     685    const QMargins m = contentsMargins();
    685686
    686687    QRect layoutRect;
    687     layoutRect.setLeft( qCeil( rect.left() ) + left );
    688     layoutRect.setTop( qCeil( rect.top() ) + top );
    689     layoutRect.setRight( qFloor( rect.right() ) - right );
    690     layoutRect.setBottom( qFloor( rect.bottom() ) - bottom );
     688    layoutRect.setLeft( qwtCeil( rect.left() ) + m.left() );
     689    layoutRect.setTop( qwtCeil( rect.top() ) + m.top() );
     690    layoutRect.setRight( qwtFloor( rect.right() ) - m.right() );
     691    layoutRect.setBottom( qwtFloor( rect.bottom() ) - m.bottom() );
    691692
    692693    uint numCols = legendLayout->columnsForWidth( layoutRect.width() );
    693     const QList<QRect> itemRects =
     694    const QList< QRect > itemRects =
    694695        legendLayout->layoutItems( layoutRect, numCols );
    695696
    … …  
    698699    for ( int i = 0; i < legendLayout->count(); i++ )
    699700    {
    700         QLayoutItem *item = legendLayout->itemAt( i );
    701         QWidget *w = item->widget();
     701        QLayoutItem* item = legendLayout->itemAt( i );
     702        QWidget* w = item->widget();
    702703        if ( w )
    703704        {
    … …  
    714715
    715716/*!
    716   Render a legend entry into a given rectangle.
    717 
    718   \param painter Painter
    719   \param widget Widget representing a legend entry
    720   \param rect Bounding rectangle
    721   \param fillBackground When true, fill rect with the widget background
    722 
    723   \note When widget is not derived from QwtLegendLabel renderItem
     717   Render a legend entry into a given rectangle.
     718
     719   \param painter Painter
     720   \param widget Widget representing a legend entry
     721   \param rect Bounding rectangle
     722   \param fillBackground When true, fill rect with the widget background
     723
     724   \note When widget is not derived from QwtLegendLabel renderItem
    724725        does nothing beside the background
    725 */
    726 void QwtLegend::renderItem( QPainter *painter,
    727     const QWidget *widget, const QRectF &rect, bool fillBackground ) const
     726 */
     727void QwtLegend::renderItem( QPainter* painter,
     728    const QWidget* widget, const QRectF& rect, bool fillBackground ) const
    728729{
    729730    if ( fillBackground )
    … …  
    736737    }
    737738
    738     const QwtLegendLabel *label = qobject_cast<const QwtLegendLabel *>( widget );
     739    const QwtLegendLabel* label = qobject_cast< const QwtLegendLabel* >( widget );
    739740    if ( label )
    740741    {
    741742        // icon
    742743
    743         const QwtGraphic &icon = label->data().icon();
     744        const QwtGraphic& icon = label->data().icon();
    744745        const QSizeF sz = icon.defaultSize();
    745746
    … …  
    756757
    757758        QFont labelFont = label->font();
     759#if QT_VERSION >= 0x060000
     760        labelFont.setResolveMask( QFont::AllPropertiesResolved );
     761#else
    758762        labelFont.resolve( QFont::AllPropertiesResolved );
     763#endif
    759764
    760765        painter->setFont( labelFont );
    761766        painter->setPen( label->palette().color( QPalette::Text ) );
    762767
    763         const_cast< QwtLegendLabel *>( label )->drawText( painter, titleRect );
    764     }
    765 }
    766 
    767 /*!
    768   \return List of widgets associated to a item
    769   \param itemInfo Info about an item
    770   \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo()
    771  */
    772 QList<QWidget *> QwtLegend::legendWidgets( const QVariant &itemInfo ) const
    773 {
    774     return d_data->itemMap.legendWidgets( itemInfo );
    775 }
    776 
    777 /*!
    778   \return First widget in the list of widgets associated to an item
    779   \param itemInfo Info about an item
    780   \sa itemInfo(), QwtPlot::itemToInfo()
    781   \note Almost all types of items have only one widget
    782 */
    783 QWidget *QwtLegend::legendWidget( const QVariant &itemInfo ) const
    784 {
    785     const QList<QWidget *> list = d_data->itemMap.legendWidgets( itemInfo );
     768        const_cast< QwtLegendLabel* >( label )->drawText( painter, titleRect );
     769    }
     770}
     771
     772/*!
     773   \return List of widgets associated to a item
     774   \param itemInfo Info about an item
     775   \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo()
     776 */
     777QList< QWidget* > QwtLegend::legendWidgets( const QVariant& itemInfo ) const
     778{
     779    return m_data->itemMap.legendWidgets( itemInfo );
     780}
     781
     782/*!
     783   \return First widget in the list of widgets associated to an item
     784   \param itemInfo Info about an item
     785   \sa itemInfo(), QwtPlot::itemToInfo()
     786   \note Almost all types of items have only one widget
     787 */
     788QWidget* QwtLegend::legendWidget( const QVariant& itemInfo ) const
     789{
     790    const QList< QWidget* > list = m_data->itemMap.legendWidgets( itemInfo );
    786791    if ( list.isEmpty() )
    787792        return NULL;
    … …  
    791796
    792797/*!
    793   Find the item that is associated to a widget
    794 
    795   \param widget Widget on the legend
    796   \return Associated item info
    797   \sa legendWidget()
    798  */
    799 QVariant QwtLegend::itemInfo( const QWidget *widget ) const
    800 {
    801     return d_data->itemMap.itemInfo( widget );
     798   Find the item that is associated to a widget
     799
     800   \param widget Widget on the legend
     801   \return Associated item info
     802   \sa legendWidget()
     803 */
     804QVariant QwtLegend::itemInfo( const QWidget* widget ) const
     805{
     806    return m_data->itemMap.itemInfo( widget );
    802807}
    803808
    … …  
    805810bool QwtLegend::isEmpty() const
    806811{
    807     return d_data->itemMap.isEmpty();
     812    return m_data->itemMap.isEmpty();
    808813}
    809814
    … …  
    826831}
    827832
     833#include "moc_qwt_legend.cpp"
  • trunk/BNC/qwt/qwt_legend.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_abstract_legend.h"
     15#include "qwt_legend_data.h"
     16
    1517#include <qvariant.h>
    1618
    … …  
    1820
    1921/*!
    20   \brief The legend widget
     22   \brief The legend widget
    2123
    22   The QwtLegend widget is a tabular arrangement of legend items. Legend
    23   items might be any type of widget, but in general they will be
    24   a QwtLegendLabel.
     24   The QwtLegend widget is a tabular arrangement of legend items. Legend
     25   items might be any type of widget, but in general they will be
     26   a QwtLegendLabel.
    2527
    26   \sa QwtLegendLabel, QwtPlotItem, QwtPlot
    27 */
     28   \sa QwtLegendLabel, QwtPlotItem, QwtPlot
     29 */
    2830
    2931class QWT_EXPORT QwtLegend : public QwtAbstractLegend
    … …  
    3133    Q_OBJECT
    3234
    33 public:
    34     explicit QwtLegend( QWidget *parent = NULL );
     35  public:
     36    explicit QwtLegend( QWidget* parent = NULL );
    3537    virtual ~QwtLegend();
    3638
    … …  
    4143    QwtLegendData::Mode defaultItemMode() const;
    4244
    43     QWidget *contentsWidget();
    44     const QWidget *contentsWidget() const;
     45    QWidget* contentsWidget();
     46    const QWidget* contentsWidget() const;
    4547
    46     QWidget *legendWidget( const QVariant &  ) const;
    47     QList<QWidget *> legendWidgets( const QVariant & ) const;
     48    QWidget* legendWidget( const QVariant&  ) const;
     49    QList< QWidget* > legendWidgets( const QVariant& ) const;
    4850
    49     QVariant itemInfo( const QWidget * ) const;
     51    QVariant itemInfo( const QWidget* ) const;
    5052
    51     virtual bool eventFilter( QObject *, QEvent * );
     53    virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE;
    5254
    53     virtual QSize sizeHint() const;
    54     virtual int heightForWidth( int width ) const;
     55    virtual QSize sizeHint() const QWT_OVERRIDE;
     56    virtual int heightForWidth( int w ) const QWT_OVERRIDE;
    5557
    56     QScrollBar *horizontalScrollBar() const;
    57     QScrollBar *verticalScrollBar() const;
     58    QScrollBar* horizontalScrollBar() const;
     59    QScrollBar* verticalScrollBar() const;
    5860
    59     virtual void renderLegend( QPainter *,
    60         const QRectF &, bool fillBackground ) const;
     61    virtual void renderLegend( QPainter*,
     62        const QRectF&, bool fillBackground ) const QWT_OVERRIDE;
    6163
    62     virtual void renderItem( QPainter *,
    63         const QWidget *, const QRectF &, bool fillBackground ) const;
     64    virtual void renderItem( QPainter*,
     65        const QWidget*, const QRectF&, bool fillBackground ) const;
    6466
    65     virtual bool isEmpty() const;
    66     virtual int scrollExtent( Qt::Orientation ) const;
     67    virtual bool isEmpty() const QWT_OVERRIDE;
     68    virtual int scrollExtent( Qt::Orientation ) const QWT_OVERRIDE;
    6769
    68 Q_SIGNALS:
     70  Q_SIGNALS:
    6971    /*!
    70       A signal which is emitted when the user has clicked on
    71       a legend label, which is in QwtLegendData::Clickable mode.
     72       A signal which is emitted when the user has clicked on
     73       a legend label, which is in QwtLegendData::Clickable mode.
    7274
    73       \param itemInfo Info for the item item of the
     75       \param itemInfo Info for the item item of the
    7476                      selected legend item
    75       \param index Index of the legend label in the list of widgets
     77       \param index Index of the legend label in the list of widgets
    7678                   that are associated with the plot item
    7779
    78       \note clicks are disabled as default
    79       \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo()
     80       \note clicks are disabled as default
     81       \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo()
    8082     */
    81     void clicked( const QVariant &itemInfo, int index );
     83    void clicked( const QVariant& itemInfo, int index );
    8284
    8385    /*!
    84       A signal which is emitted when the user has clicked on
    85       a legend label, which is in QwtLegendData::Checkable mode
     86       A signal which is emitted when the user has clicked on
     87       a legend label, which is in QwtLegendData::Checkable mode
    8688
    87       \param itemInfo Info for the item of the
     89       \param itemInfo Info for the item of the
    8890                      selected legend label
    89       \param index Index of the legend label in the list of widgets
     91       \param index Index of the legend label in the list of widgets
    9092                   that are associated with the plot item
    91       \param on True when the legend label is checked
     93       \param on True when the legend label is checked
    9294
    93       \note clicks are disabled as default
    94       \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo()
     95       \note clicks are disabled as default
     96       \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo()
    9597     */
    96     void checked( const QVariant &itemInfo, bool on, int index );
     98    void checked( const QVariant& itemInfo, bool on, int index );
    9799
    98 public Q_SLOTS:
    99     virtual void updateLegend( const QVariant &,
    100         const QList<QwtLegendData> & );
     100  public Q_SLOTS:
     101    virtual void updateLegend( const QVariant&,
     102        const QList< QwtLegendData >& ) QWT_OVERRIDE;
    101103
    102 protected Q_SLOTS:
     104  protected Q_SLOTS:
    103105    void itemClicked();
    104106    void itemChecked( bool );
    105107
    106 protected:
    107     virtual QWidget *createWidget( const QwtLegendData & ) const;
    108     virtual void updateWidget( QWidget *widget, const QwtLegendData & );
     108  protected:
     109    virtual QWidget* createWidget( const QwtLegendData& ) const;
     110    virtual void updateWidget( QWidget*, const QwtLegendData& );
    109111
    110 private:
     112  private:
    111113    void updateTabOrder();
    112114
    113115    class PrivateData;
    114     PrivateData *d_data;
     116    PrivateData* m_data;
    115117};
    116118
  • trunk/BNC/qwt/qwt_legend_data.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_legend_data.h"
     11#include "qwt_text.h"
     12#include "qwt_graphic.h"
    1113
    1214//! Constructor
    … …  
    2123
    2224/*!
    23   Set the legend attributes
     25   Set the legend attributes
    2426
    25   QwtLegendData actually is a QMap<int, QVariant> with some
    26   convenience interfaces
     27   QwtLegendData actually is a QMap<int, QVariant> with some
     28   convenience interfaces
    2729
    28   \param map Values
    29   \sa values()
     30   \param map Values
     31   \sa values()
    3032 */
    31 void QwtLegendData::setValues( const QMap<int, QVariant> &map )
     33void QwtLegendData::setValues( const QMap< int, QVariant >& map )
    3234{
    33     d_map = map;
     35    m_map = map;
    3436}
    3537
    3638/*!
    37   \return Legend attributes
    38   \sa setValues()
     39   \return Legend attributes
     40   \sa setValues()
    3941 */
    40 const QMap<int, QVariant> &QwtLegendData::values() const
     42const QMap< int, QVariant >& QwtLegendData::values() const
    4143{
    42     return d_map;
     44    return m_map;
    4345}
    4446
    4547/*!
    46   \param role Attribute role
    47   \return True, when the internal map has an entry for role
     48   \param role Attribute role
     49   \return True, when the internal map has an entry for role
    4850 */
    4951bool QwtLegendData::hasRole( int role ) const
    5052{
    51     return d_map.contains( role );
     53    return m_map.contains( role );
    5254}
    5355
    5456/*!
    55   Set an attribute value
     57   Set an attribute value
    5658
    57   \param role Attribute role
    58   \param data Attribute value
     59   \param role Attribute role
     60   \param data Attribute value
    5961
    60   \sa value()
     62   \sa value()
    6163 */
    62 void QwtLegendData::setValue( int role, const QVariant &data )
     64void QwtLegendData::setValue( int role, const QVariant& data )
    6365{
    64     d_map[role] = data;
     66    m_map[role] = data;
    6567}
    6668
    6769/*!
    68   \param role Attribute role
    69   \return Attribute value for a specific role
     70   \param role Attribute role
     71   \return Attribute value for a specific role
    7072 */
    7173QVariant QwtLegendData::value( int role ) const
    7274{
    73     if ( !d_map.contains( role ) )
     75    if ( !m_map.contains( role ) )
    7476        return QVariant();
    7577
    76     return d_map[role];
     78    return m_map[role];
    7779}
    7880
    … …  
    8082bool QwtLegendData::isValid() const
    8183{
    82     return !d_map.isEmpty();
     84    return !m_map.isEmpty();
    8385}
    8486
    … …  
    8991
    9092    const QVariant titleValue = value( QwtLegendData::TitleRole );
    91     if ( titleValue.canConvert<QwtText>() )
     93    if ( titleValue.canConvert< QwtText >() )
    9294    {
    93         text = qvariant_cast<QwtText>( titleValue );
     95        text = qvariant_cast< QwtText >( titleValue );
    9496    }
    95     else if ( titleValue.canConvert<QString>() )
     97    else if ( titleValue.canConvert< QString >() )
    9698    {
    97         text.setText( qvariant_cast<QString>( titleValue ) );
     99        text.setText( qvariant_cast< QString >( titleValue ) );
    98100    }
    99101
    … …  
    107109
    108110    QwtGraphic graphic;
    109     if ( iconValue.canConvert<QwtGraphic>() )
     111    if ( iconValue.canConvert< QwtGraphic >() )
    110112    {
    111         graphic = qvariant_cast<QwtGraphic>( iconValue );
     113        graphic = qvariant_cast< QwtGraphic >( iconValue );
    112114    }
    113115
    … …  
    119121{
    120122    const QVariant modeValue = value( QwtLegendData::ModeRole );
    121     if ( modeValue.canConvert<int>() )
     123    if ( modeValue.canConvert< int >() )
    122124    {
    123         const int mode = qvariant_cast<int>( modeValue );
    124         return static_cast<QwtLegendData::Mode>( mode );
     125        const int mode = qvariant_cast< int >( modeValue );
     126        return static_cast< QwtLegendData::Mode >( mode );
    125127    }
    126128
  • trunk/BNC/qwt/qwt_legend_data.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_text.h"
    15 #include "qwt_graphic.h"
     14
    1615#include <qvariant.h>
    17 #include <qpixmap.h>
    1816#include <qmap.h>
    1917
     18class QwtText;
     19class QwtGraphic;
     20
    2021/*!
    21   \brief Attributes of an entry on a legend
     22   \brief Attributes of an entry on a legend
    2223
    23   QwtLegendData is an abstract container ( like QAbstractModel )
    24   to exchange attributes, that are only known between to
    25   the plot item and the legend.
     24   QwtLegendData is an abstract container ( like QAbstractModel )
     25   to exchange attributes, that are only known between to
     26   the plot item and the legend.
    2627
    27   By overloading QwtPlotItem::legendData() any other set of attributes
    28   could be used, that can be handled by a modified ( or completely
    29   different ) implementation of a legend.
     28   By overloading QwtPlotItem::legendData() any other set of attributes
     29   could be used, that can be handled by a modified ( or completely
     30   different ) implementation of a legend.
    3031
    31   \sa QwtLegend, QwtPlotLegendItem
    32   \note The stockchart example implements a legend as a tree
     32   \sa QwtLegend, QwtPlotLegendItem
     33   \note The stockchart example implements a legend as a tree
    3334        with checkable items
    3435 */
    3536class QWT_EXPORT QwtLegendData
    3637{
    37 public:
     38  public:
    3839    //! Mode defining how a legend entry interacts
    3940    enum Mode
    … …  
    4950    };
    5051
    51     //! Identifier how to interprete a QVariant
     52    //! Identifier how to interpret a QVariant
    5253    enum Role
    5354    {
    … …  
    6869    ~QwtLegendData();
    6970
    70     void setValues( const QMap<int, QVariant> & );
    71     const QMap<int, QVariant> &values() const;
     71    void setValues( const QMap< int, QVariant >& );
     72    const QMap< int, QVariant >& values() const;
    7273
    73     void setValue( int role, const QVariant & );
     74    void setValue( int role, const QVariant& );
    7475    QVariant value( int role ) const;
    7576
    … …  
    8182    Mode mode() const;
    8283
    83 private:
    84     QMap<int, QVariant> d_map;
     84  private:
     85    QMap< int, QVariant > m_map;
    8586};
    8687
  • trunk/BNC/qwt/qwt_legend_label.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_legend_label.h"
    1111#include "qwt_legend_data.h"
    12 #include "qwt_math.h"
     12#include "qwt_graphic.h"
    1313#include "qwt_painter.h"
    14 #include "qwt_symbol.h"
    15 #include "qwt_graphic.h"
     14#include "qwt.h"
     15
    1616#include <qpainter.h>
    1717#include <qdrawutil.h>
    1818#include <qstyle.h>
    19 #include <qpen.h>
    2019#include <qevent.h>
    2120#include <qstyleoption.h>
    22 #include <qapplication.h>
    2321
    2422static const int ButtonFrame = 2;
    2523static const int Margin = 2;
    2624
    27 static QSize buttonShift( const QwtLegendLabel *w )
     25static QSize buttonShift( const QwtLegendLabel* w )
    2826{
    2927    QStyleOption option;
    30     option.init( w );
     28    option.initFrom( w );
    3129
    3230    const int ph = w->style()->pixelMetric(
    … …  
    3937class QwtLegendLabel::PrivateData
    4038{
    41 public:
    42     PrivateData():
    43         itemMode( QwtLegendData::ReadOnly ),
    44         isDown( false ),
    45         spacing( Margin )
     39  public:
     40    PrivateData()
     41        : itemMode( QwtLegendData::ReadOnly )
     42        , isDown( false )
     43        , spacing( Margin )
    4644    {
    4745    }
    … …  
    5755
    5856/*!
    59   Set the attributes of the legend label
    60 
    61   \param legendData Attributes of the label
    62   \sa data()
    63  */
    64 void QwtLegendLabel::setData( const QwtLegendData &legendData )
    65 {
    66     d_data->legendData = legendData;
     57   Set the attributes of the legend label
     58
     59   \param legendData Attributes of the label
     60   \sa data()
     61 */
     62void QwtLegendLabel::setData( const QwtLegendData& legendData )
     63{
     64    m_data->legendData = legendData;
    6765
    6866    const bool doUpdate = updatesEnabled();
    69     setUpdatesEnabled( false );
     67    if ( doUpdate )
     68        setUpdatesEnabled( false );
    7069
    7170    setText( legendData.title() );
    … …  
    7675
    7776    if ( doUpdate )
    78     {
    7977        setUpdatesEnabled( true );
    80         update();
    81     }
    82 }
    83 
    84 /*!
    85   \return Attributes of the label
    86   \sa setData(), QwtPlotItem::legendData()
    87  */
    88 const QwtLegendData &QwtLegendLabel::data() const
    89 {
    90     return d_data->legendData;
    91 }
    92 
    93 /*!
    94   \param parent Parent widget
    95 */
    96 QwtLegendLabel::QwtLegendLabel( QWidget *parent ):
    97     QwtTextLabel( parent )
    98 {
    99     d_data = new PrivateData;
     78}
     79
     80/*!
     81   \return Attributes of the label
     82   \sa setData(), QwtPlotItem::legendData()
     83 */
     84const QwtLegendData& QwtLegendLabel::data() const
     85{
     86    return m_data->legendData;
     87}
     88
     89/*!
     90   \param parent Parent widget
     91 */
     92QwtLegendLabel::QwtLegendLabel( QWidget* parent )
     93    : QwtTextLabel( parent )
     94{
     95    m_data = new PrivateData;
    10096    setMargin( Margin );
    10197    setIndent( Margin );
    … …  
    105101QwtLegendLabel::~QwtLegendLabel()
    106102{
    107     delete d_data;
    108     d_data = NULL;
     103    delete m_data;
     104    m_data = NULL;
    109105}
    110106
    … …  
    114110   \param text Text label
    115111    \sa QwtTextLabel::text()
    116 */
    117 void QwtLegendLabel::setText( const QwtText &text )
     112 */
     113void QwtLegendLabel::setText( const QwtText& text )
    118114{
    119115    const int flags = Qt::AlignLeft | Qt::AlignVCenter
    … …  
    132128   \param mode Item mode
    133129   \sa itemMode()
    134 */
     130 */
    135131void QwtLegendLabel::setItemMode( QwtLegendData::Mode mode )
    136132{
    137     if ( mode != d_data->itemMode )
    138     {
    139         d_data->itemMode = mode;
    140         d_data->isDown = false;
     133    if ( mode != m_data->itemMode )
     134    {
     135        m_data->itemMode = mode;
     136        m_data->isDown = false;
    141137
    142138        setFocusPolicy( ( mode != QwtLegendData::ReadOnly )
    … …  
    151147   \return Item mode
    152148   \sa setItemMode()
    153 */
     149 */
    154150QwtLegendData::Mode QwtLegendLabel::itemMode() const
    155151{
    156     return d_data->itemMode;
    157 }
    158 
    159 /*!
    160   Assign the icon
    161 
    162   \param icon Pixmap representing a plot item
    163 
    164   \sa icon(), QwtPlotItem::legendIcon()
    165 */
    166 void QwtLegendLabel::setIcon( const QPixmap &icon )
    167 {
    168     d_data->icon = icon;
    169 
    170     int indent = margin() + d_data->spacing;
     152    return m_data->itemMode;
     153}
     154
     155/*!
     156   Assign the icon
     157
     158   \param icon Pixmap representing a plot item
     159
     160   \sa icon(), QwtPlotItem::legendIcon()
     161 */
     162void QwtLegendLabel::setIcon( const QPixmap& icon )
     163{
     164    m_data->icon = icon;
     165
     166    int indent = margin() + m_data->spacing;
    171167    if ( icon.width() > 0 )
    172         indent += icon.width() + d_data->spacing;
     168    {
     169        const qreal devicePixelRatio = QwtPainter::devicePixelRatio( &icon );
     170        indent += icon.width() / devicePixelRatio + m_data->spacing;
     171    }
    173172
    174173    setIndent( indent );
    … …  
    176175
    177176/*!
    178   \return Pixmap representing a plot item
    179   \sa setIcon()
    180 */
     177   \return Pixmap representing a plot item
     178   \sa setIcon()
     179 */
    181180QPixmap QwtLegendLabel::icon() const
    182181{
    183     return d_data->icon;
     182    return m_data->icon;
    184183}
    185184
    … …  
    189188   \param spacing Spacing
    190189   \sa spacing(), QwtTextLabel::margin()
    191 */
     190 */
    192191void QwtLegendLabel::setSpacing( int spacing )
    193192{
    194193    spacing = qMax( spacing, 0 );
    195     if ( spacing != d_data->spacing )
    196     {
    197         d_data->spacing = spacing;
    198 
    199         int indent = margin() + d_data->spacing;
    200         if ( d_data->icon.width() > 0 )
    201             indent += d_data->icon.width() + d_data->spacing;
     194    if ( spacing != m_data->spacing )
     195    {
     196        m_data->spacing = spacing;
     197
     198        int indent = margin() + m_data->spacing;
     199        if ( m_data->icon.width() > 0 )
     200            indent += m_data->icon.width() + m_data->spacing;
    202201
    203202        setIndent( indent );
    … …  
    208207   \return Spacing between icon and text
    209208   \sa setSpacing(), QwtTextLabel::margin()
    210 */
     209 */
    211210int QwtLegendLabel::spacing() const
    212211{
    213     return d_data->spacing;
     212    return m_data->spacing;
    214213}
    215214
    … …  
    219218    \param on check/uncheck
    220219    \sa setItemMode()
    221 */
     220 */
    222221void QwtLegendLabel::setChecked( bool on )
    223222{
    224     if ( d_data->itemMode == QwtLegendData::Checkable )
     223    if ( m_data->itemMode == QwtLegendData::Checkable )
    225224    {
    226225        const bool isBlocked = signalsBlocked();
    … …  
    236235bool QwtLegendLabel::isChecked() const
    237236{
    238     return d_data->itemMode == QwtLegendData::Checkable && isDown();
     237    return m_data->itemMode == QwtLegendData::Checkable && isDown();
    239238}
    240239
    … …  
    242241void QwtLegendLabel::setDown( bool down )
    243242{
    244     if ( down == d_data->isDown )
     243    if ( down == m_data->isDown )
    245244        return;
    246245
    247     d_data->isDown = down;
     246    m_data->isDown = down;
    248247    update();
    249248
    250     if ( d_data->itemMode == QwtLegendData::Clickable )
    251     {
    252         if ( d_data->isDown )
     249    if ( m_data->itemMode == QwtLegendData::Clickable )
     250    {
     251        if ( m_data->isDown )
    253252            Q_EMIT pressed();
    254253        else
    … …  
    259258    }
    260259
    261     if ( d_data->itemMode == QwtLegendData::Checkable )
    262         Q_EMIT checked( d_data->isDown );
     260    if ( m_data->itemMode == QwtLegendData::Checkable )
     261        Q_EMIT checked( m_data->isDown );
    263262}
    264263
    … …  
    266265bool QwtLegendLabel::isDown() const
    267266{
    268     return d_data->isDown;
     267    return m_data->isDown;
    269268}
    270269
    … …  
    273272{
    274273    QSize sz = QwtTextLabel::sizeHint();
    275     sz.setHeight( qMax( sz.height(), d_data->icon.height() + 4 ) );
    276 
    277     if ( d_data->itemMode != QwtLegendData::ReadOnly )
     274    sz.setHeight( qMax( sz.height(), m_data->icon.height() + 4 ) );
     275
     276    if ( m_data->itemMode != QwtLegendData::ReadOnly )
    278277    {
    279278        sz += buttonShift( this );
    280         sz = sz.expandedTo( QApplication::globalStrut() );
     279        sz = qwtExpandedToGlobalStrut( sz );
    281280    }
    282281
    … …  
    285284
    286285//! Paint event
    287 void QwtLegendLabel::paintEvent( QPaintEvent *e )
     286void QwtLegendLabel::paintEvent( QPaintEvent* e )
    288287{
    289288    const QRect cr = contentsRect();
    … …  
    292291    painter.setClipRegion( e->region() );
    293292
    294     if ( d_data->isDown )
     293    if ( m_data->isDown )
    295294    {
    296295        qDrawWinButton( &painter, 0, 0, width(), height(),
    … …  
    300299    painter.save();
    301300
    302     if ( d_data->isDown )
     301    if ( m_data->isDown )
    303302    {
    304303        const QSize shiftSize = buttonShift( this );
    … …  
    310309    drawContents( &painter );
    311310
    312     if ( !d_data->icon.isNull() )
     311    if ( !m_data->icon.isNull() )
    313312    {
    314313        QRect iconRect = cr;
    315314        iconRect.setX( iconRect.x() + margin() );
    316         if ( d_data->itemMode != QwtLegendData::ReadOnly )
     315        if ( m_data->itemMode != QwtLegendData::ReadOnly )
    317316            iconRect.setX( iconRect.x() + ButtonFrame );
    318317
    319         iconRect.setSize( d_data->icon.size() );
     318        const qreal devicePixelRatio = QwtPainter::devicePixelRatio( &m_data->icon );
     319        iconRect.setSize( m_data->icon.size() / devicePixelRatio );
    320320        iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) );
    321321
    322         painter.drawPixmap( iconRect, d_data->icon );
     322        painter.drawPixmap( iconRect, m_data->icon );
    323323    }
    324324
    … …  
    327327
    328328//! Handle mouse press events
    329 void QwtLegendLabel::mousePressEvent( QMouseEvent *e )
     329void QwtLegendLabel::mousePressEvent( QMouseEvent* e )
    330330{
    331331    if ( e->button() == Qt::LeftButton )
    332332    {
    333         switch ( d_data->itemMode )
     333        switch ( m_data->itemMode )
    334334        {
    335335            case QwtLegendData::Clickable:
    … …  
    350350
    351351//! Handle mouse release events
    352 void QwtLegendLabel::mouseReleaseEvent( QMouseEvent *e )
     352void QwtLegendLabel::mouseReleaseEvent( QMouseEvent* e )
    353353{
    354354    if ( e->button() == Qt::LeftButton )
    355355    {
    356         switch ( d_data->itemMode )
     356        switch ( m_data->itemMode )
    357357        {
    358358            case QwtLegendData::Clickable:
    … …  
    372372
    373373//! Handle key press events
    374 void QwtLegendLabel::keyPressEvent( QKeyEvent *e )
     374void QwtLegendLabel::keyPressEvent( QKeyEvent* e )
    375375{
    376376    if ( e->key() == Qt::Key_Space )
    377377    {
    378         switch ( d_data->itemMode )
     378        switch ( m_data->itemMode )
    379379        {
    380380            case QwtLegendData::Clickable:
    … …  
    398398
    399399//! Handle key release events
    400 void QwtLegendLabel::keyReleaseEvent( QKeyEvent *e )
     400void QwtLegendLabel::keyReleaseEvent( QKeyEvent* e )
    401401{
    402402    if ( e->key() == Qt::Key_Space )
    403403    {
    404         switch ( d_data->itemMode )
     404        switch ( m_data->itemMode )
    405405        {
    406406            case QwtLegendData::Clickable:
    … …  
    420420    QwtTextLabel::keyReleaseEvent( e );
    421421}
     422
     423#include "moc_qwt_legend_label.cpp"
  • trunk/BNC/qwt/qwt_legend_label.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
     14#include "qwt_text_label.h"
    1415#include "qwt_legend_data.h"
    15 #include "qwt_text.h"
    16 #include "qwt_text_label.h"
    17 #include <qpixmap.h>
    1816
    19 class QwtLegendData;
     17class QwtText;
    2018
    2119/*!
    22   \brief A widget representing something on a QwtLegend.
    23 */
    24 class QWT_EXPORT QwtLegendLabel: public QwtTextLabel
     20   \brief A widget representing something on a QwtLegend.
     21 */
     22class QWT_EXPORT QwtLegendLabel : public QwtTextLabel
    2523{
    2624    Q_OBJECT
    27 public:
    28     explicit QwtLegendLabel( QWidget *parent = 0 );
     25  public:
     26    explicit QwtLegendLabel( QWidget* parent = 0 );
    2927    virtual ~QwtLegendLabel();
    3028
    31     void setData( const QwtLegendData & );
    32     const QwtLegendData &data() const;
     29    void setData( const QwtLegendData& );
     30    const QwtLegendData& data() const;
    3331
    3432    void setItemMode( QwtLegendData::Mode );
    … …  
    3836    int spacing() const;
    3937
    40     virtual void setText( const QwtText & );
     38    virtual void setText( const QwtText& ) QWT_OVERRIDE;
    4139
    42     void setIcon( const QPixmap & );
     40    void setIcon( const QPixmap& );
    4341    QPixmap icon() const;
    4442
    45     virtual QSize sizeHint() const;
     43    virtual QSize sizeHint() const QWT_OVERRIDE;
    4644
    4745    bool isChecked() const;
    4846
    49 public Q_SLOTS:
     47  public Q_SLOTS:
    5048    void setChecked( bool on );
    5149
    52 Q_SIGNALS:
     50  Q_SIGNALS:
    5351    //! Signal, when the legend item has been clicked
    5452    void clicked();
    … …  
    6361    void checked( bool );
    6462
    65 protected:
     63  protected:
    6664    void setDown( bool );
    6765    bool isDown() const;
    6866
    69     virtual void paintEvent( QPaintEvent * );
    70     virtual void mousePressEvent( QMouseEvent * );
    71     virtual void mouseReleaseEvent( QMouseEvent * );
    72     virtual void keyPressEvent( QKeyEvent * );
    73     virtual void keyReleaseEvent( QKeyEvent * );
     67    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
     68    virtual void mousePressEvent( QMouseEvent* ) QWT_OVERRIDE;
     69    virtual void mouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE;
     70    virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE;
     71    virtual void keyReleaseEvent( QKeyEvent* ) QWT_OVERRIDE;
    7472
    75 private:
     73  private:
    7674    class PrivateData;
    77     PrivateData *d_data;
     75    PrivateData* m_data;
    7876};
    7977
  • trunk/BNC/qwt/qwt_magnifier.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_magnifier.h"
    1111#include "qwt_math.h"
     12
    1213#include <qevent.h>
    1314#include <qwidget.h>
    … …  
    1516class QwtMagnifier::PrivateData
    1617{
    17 public:
    18     PrivateData():
    19         isEnabled( false ),
    20         wheelFactor( 0.9 ),
    21         wheelModifiers( Qt::NoModifier ),
    22         mouseFactor( 0.95 ),
    23         mouseButton( Qt::RightButton ),
    24         mouseButtonModifiers( Qt::NoModifier ),
    25         keyFactor( 0.9 ),
    26         zoomInKey( Qt::Key_Plus ),
    27         zoomInKeyModifiers( Qt::NoModifier ),
    28         zoomOutKey( Qt::Key_Minus ),
    29         zoomOutKeyModifiers( Qt::NoModifier ),
    30         mousePressed( false )
     18  public:
     19    PrivateData()
     20        : isEnabled( false )
     21        , wheelFactor( 0.9 )
     22        , wheelModifiers( Qt::NoModifier )
     23        , mouseFactor( 0.95 )
     24        , mouseButton( Qt::RightButton )
     25        , mouseButtonModifiers( Qt::NoModifier )
     26        , keyFactor( 0.9 )
     27        , zoomInKey( Qt::Key_Plus )
     28        , zoomInKeyModifiers( Qt::NoModifier )
     29        , zoomOutKey( Qt::Key_Minus )
     30        , zoomOutKeyModifiers( Qt::NoModifier )
     31        , mousePressed( false )
     32        , hasMouseTracking( false )
    3133    {
    3234    }
    … …  
    4850
    4951    int zoomOutKey;
    50     Qt::KeyboardModifiers  zoomOutKeyModifiers;
     52    Qt::KeyboardModifiers zoomOutKeyModifiers;
    5153
    5254    bool mousePressed;
    … …  
    5860   Constructor
    5961   \param parent Widget to be magnified
    60 */
    61 QwtMagnifier::QwtMagnifier( QWidget *parent ):
    62     QObject( parent )
    63 {
    64     d_data = new PrivateData();
     62 */
     63QwtMagnifier::QwtMagnifier( QWidget* parent )
     64    : QObject( parent )
     65{
     66    m_data = new PrivateData();
     67
     68    if ( parent )
     69    {
     70        if ( parent->focusPolicy() == Qt::NoFocus )
     71            parent->setFocusPolicy( Qt::WheelFocus );
     72    }
     73
    6574    setEnabled( true );
    6675}
    … …  
    6978QwtMagnifier::~QwtMagnifier()
    7079{
    71     delete d_data;
    72 }
    73 
    74 /*!
    75   \brief En/disable the magnifier
    76 
    77   When enabled is true an event filter is installed for
    78   the observed widget, otherwise the event filter is removed.
    79 
    80   \param on true or false
    81   \sa isEnabled(), eventFilter()
    82 */
     80    delete m_data;
     81}
     82
     83/*!
     84   \brief En/disable the magnifier
     85
     86   When enabled is true an event filter is installed for
     87   the observed widget, otherwise the event filter is removed.
     88
     89   \param on true or false
     90   \sa isEnabled(), eventFilter()
     91 */
    8392void QwtMagnifier::setEnabled( bool on )
    8493{
    85     if ( d_data->isEnabled != on )
    86     {
    87         d_data->isEnabled = on;
    88 
    89         QObject *o = parent();
     94    if ( m_data->isEnabled != on )
     95    {
     96        m_data->isEnabled = on;
     97
     98        QObject* o = parent();
    9099        if ( o )
    91100        {
    92             if ( d_data->isEnabled )
     101            if ( m_data->isEnabled )
    93102                o->installEventFilter( this );
    94103            else
    … …  
    99108
    100109/*!
    101   \return true when enabled, false otherwise
    102   \sa setEnabled(), eventFilter()
    103 */
     110   \return true when enabled, false otherwise
     111   \sa setEnabled(), eventFilter()
     112 */
    104113bool QwtMagnifier::isEnabled() const
    105114{
    106     return d_data->isEnabled;
     115    return m_data->isEnabled;
    107116}
    108117
    … …  
    122131   \sa wheelFactor(), setWheelButtonState(),
    123132       setMouseFactor(), setKeyFactor()
    124 */
     133 */
    125134void QwtMagnifier::setWheelFactor( double factor )
    126135{
    127     d_data->wheelFactor = factor;
     136    m_data->wheelFactor = factor;
    128137}
    129138
    … …  
    131140   \return Wheel factor
    132141   \sa setWheelFactor()
    133 */
     142 */
    134143double QwtMagnifier::wheelFactor() const
    135144{
    136     return d_data->wheelFactor;
     145    return m_data->wheelFactor;
    137146}
    138147
    … …  
    143152   \param modifiers Keyboard modifiers
    144153   \sa wheelModifiers()
    145 */
     154 */
    146155void QwtMagnifier::setWheelModifiers( Qt::KeyboardModifiers modifiers )
    147156{
    148     d_data->wheelModifiers = modifiers;
     157    m_data->wheelModifiers = modifiers;
    149158}
    150159
    … …  
    152161   \return Wheel modifiers
    153162   \sa setWheelModifiers()
    154 */
     163 */
    155164Qt::KeyboardModifiers QwtMagnifier::wheelModifiers() const
    156165{
    157     return d_data->wheelModifiers;
     166    return m_data->wheelModifiers;
    158167}
    159168
    … …  
    167176   \param factor Wheel factor
    168177   \sa mouseFactor(), setMouseButton(), setWheelFactor(), setKeyFactor()
    169 */
     178 */
    170179void QwtMagnifier::setMouseFactor( double factor )
    171180{
    172     d_data->mouseFactor = factor;
     181    m_data->mouseFactor = factor;
    173182}
    174183
    … …  
    176185   \return Mouse factor
    177186   \sa setMouseFactor()
    178 */
     187 */
    179188double QwtMagnifier::mouseFactor() const
    180189{
    181     return d_data->mouseFactor;
     190    return m_data->mouseFactor;
    182191}
    183192
    … …  
    190199
    191200   \sa getMouseButton()
    192 */
     201 */
    193202void QwtMagnifier::setMouseButton(
    194203    Qt::MouseButton button, Qt::KeyboardModifiers modifiers )
    195204{
    196     d_data->mouseButton = button;
    197     d_data->mouseButtonModifiers = modifiers;
     205    m_data->mouseButton = button;
     206    m_data->mouseButtonModifiers = modifiers;
    198207}
    199208
    200209//! \sa setMouseButton()
    201210void QwtMagnifier::getMouseButton(
    202     Qt::MouseButton &button, Qt::KeyboardModifiers &modifiers ) const
    203 {
    204     button = d_data->mouseButton;
    205     modifiers = d_data->mouseButtonModifiers;
     211    Qt::MouseButton& button, Qt::KeyboardModifiers& modifiers ) const
     212{
     213    button = m_data->mouseButton;
     214    modifiers = m_data->mouseButtonModifiers;
    206215}
    207216
    … …  
    216225   \sa keyFactor(), setZoomInKey(), setZoomOutKey(),
    217226       setWheelFactor, setMouseFactor()
    218 */
     227 */
    219228void QwtMagnifier::setKeyFactor( double factor )
    220229{
    221     d_data->keyFactor = factor;
     230    m_data->keyFactor = factor;
    222231}
    223232
    … …  
    225234   \return Key factor
    226235   \sa setKeyFactor()
    227 */
     236 */
    228237double QwtMagnifier::keyFactor() const
    229238{
    230     return d_data->keyFactor;
     239    return m_data->keyFactor;
    231240}
    232241
    … …  
    238247   \param modifiers
    239248   \sa getZoomInKey(), setZoomOutKey()
    240 */
     249 */
    241250void QwtMagnifier::setZoomInKey( int key,
    242251    Qt::KeyboardModifiers modifiers )
    243252{
    244     d_data->zoomInKey = key;
    245     d_data->zoomInKeyModifiers = modifiers;
     253    m_data->zoomInKey = key;
     254    m_data->zoomInKeyModifiers = modifiers;
    246255}
    247256
    … …  
    253262
    254263   \sa setZoomInKey()
    255 */
    256 void QwtMagnifier::getZoomInKey( int &key,
    257     Qt::KeyboardModifiers &modifiers ) const
    258 {
    259     key = d_data->zoomInKey;
    260     modifiers = d_data->zoomInKeyModifiers;
     264 */
     265void QwtMagnifier::getZoomInKey( int& key,
     266    Qt::KeyboardModifiers& modifiers ) const
     267{
     268    key = m_data->zoomInKey;
     269    modifiers = m_data->zoomInKeyModifiers;
    261270}
    262271
    … …  
    268277   \param modifiers
    269278   \sa getZoomOutKey(), setZoomOutKey()
    270 */
     279 */
    271280void QwtMagnifier::setZoomOutKey( int key,
    272281    Qt::KeyboardModifiers modifiers )
    273282{
    274     d_data->zoomOutKey = key;
    275     d_data->zoomOutKeyModifiers = modifiers;
     283    m_data->zoomOutKey = key;
     284    m_data->zoomOutKeyModifiers = modifiers;
    276285}
    277286
    … …  
    283292
    284293   \sa setZoomOutKey()
    285 */
    286 void QwtMagnifier::getZoomOutKey( int &key,
    287     Qt::KeyboardModifiers &modifiers ) const
    288 {
    289     key = d_data->zoomOutKey;
    290     modifiers = d_data->zoomOutKeyModifiers;
    291 }
    292 
    293 /*!
    294   \brief Event filter
    295 
    296   When isEnabled() is true, the mouse events of the
    297   observed widget are filtered.
    298 
    299   \param object Object to be filtered
    300   \param event Event
    301 
    302   \return Forwarded to QObject::eventFilter()
    303 
    304   \sa widgetMousePressEvent(), widgetMouseReleaseEvent(),
     294 */
     295void QwtMagnifier::getZoomOutKey( int& key,
     296    Qt::KeyboardModifiers& modifiers ) const
     297{
     298    key = m_data->zoomOutKey;
     299    modifiers = m_data->zoomOutKeyModifiers;
     300}
     301
     302/*!
     303   \brief Event filter
     304
     305   When isEnabled() is true, the mouse events of the
     306   observed widget are filtered.
     307
     308   \param object Object to be filtered
     309   \param event Event
     310
     311   \return Forwarded to QObject::eventFilter()
     312
     313   \sa widgetMousePressEvent(), widgetMouseReleaseEvent(),
    305314      widgetMouseMoveEvent(), widgetWheelEvent(), widgetKeyPressEvent()
    306315      widgetKeyReleaseEvent()
    307 */
    308 bool QwtMagnifier::eventFilter( QObject *object, QEvent *event )
     316 */
     317bool QwtMagnifier::eventFilter( QObject* object, QEvent* event )
    309318{
    310319    if ( object && object == parent() )
    … …  
    314323            case QEvent::MouseButtonPress:
    315324            {
    316                 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );
     325                widgetMousePressEvent( static_cast< QMouseEvent* >( event ) );
    317326                break;
    318327            }
    319328            case QEvent::MouseMove:
    320329            {
    321                 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );
     330                widgetMouseMoveEvent( static_cast< QMouseEvent* >( event ) );
    322331                break;
    323332            }
    324333            case QEvent::MouseButtonRelease:
    325334            {
    326                 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );
     335                widgetMouseReleaseEvent( static_cast< QMouseEvent* >( event ) );
    327336                break;
    328337            }
    329338            case QEvent::Wheel:
    330339            {
    331                 widgetWheelEvent( static_cast<QWheelEvent *>( event ) );
     340                widgetWheelEvent( static_cast< QWheelEvent* >( event ) );
    332341                break;
    333342            }
    334343            case QEvent::KeyPress:
    335344            {
    336                 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );
     345                widgetKeyPressEvent( static_cast< QKeyEvent* >( event ) );
    337346                break;
    338347            }
    339348            case QEvent::KeyRelease:
    340349            {
    341                 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );
     350                widgetKeyReleaseEvent( static_cast< QKeyEvent* >( event ) );
    342351                break;
    343352            }
    … …  
    349358
    350359/*!
    351   Handle a mouse press event for the observed widget.
    352 
    353   \param mouseEvent Mouse event
    354   \sa eventFilter(), widgetMouseReleaseEvent(), widgetMouseMoveEvent()
    355 */
    356 void QwtMagnifier::widgetMousePressEvent( QMouseEvent *mouseEvent )
     360   Handle a mouse press event for the observed widget.
     361
     362   \param mouseEvent Mouse event
     363   \sa eventFilter(), widgetMouseReleaseEvent(), widgetMouseMoveEvent()
     364 */
     365void QwtMagnifier::widgetMousePressEvent( QMouseEvent* mouseEvent )
    357366{
    358367    if ( parentWidget() == NULL )
    359368        return;
    360369
    361     if ( ( mouseEvent->button() != d_data->mouseButton ) ||
    362         ( mouseEvent->modifiers() != d_data->mouseButtonModifiers ) )
     370    if ( ( mouseEvent->button() != m_data->mouseButton ) ||
     371        ( mouseEvent->modifiers() != m_data->mouseButtonModifiers ) )
    363372    {
    364373        return;
    365374    }
    366375
    367     d_data->hasMouseTracking = parentWidget()->hasMouseTracking();
     376    m_data->hasMouseTracking = parentWidget()->hasMouseTracking();
    368377
    369378    parentWidget()->setMouseTracking( true );
    370     d_data->mousePos = mouseEvent->pos();
    371     d_data->mousePressed = true;
    372 }
    373 
    374 /*!
    375   Handle a mouse release event for the observed widget.
    376 
    377   \param mouseEvent Mouse event
    378 
    379   \sa eventFilter(), widgetMousePressEvent(), widgetMouseMoveEvent(),
    380 */
    381 void QwtMagnifier::widgetMouseReleaseEvent( QMouseEvent *mouseEvent )
     379    m_data->mousePos = mouseEvent->pos();
     380    m_data->mousePressed = true;
     381}
     382
     383/*!
     384   Handle a mouse release event for the observed widget.
     385
     386   \param mouseEvent Mouse event
     387
     388   \sa eventFilter(), widgetMousePressEvent(), widgetMouseMoveEvent(),
     389 */
     390void QwtMagnifier::widgetMouseReleaseEvent( QMouseEvent* mouseEvent )
    382391{
    383392    Q_UNUSED( mouseEvent );
    384393
    385     if ( d_data->mousePressed && parentWidget() )
    386     {
    387         d_data->mousePressed = false;
    388         parentWidget()->setMouseTracking( d_data->hasMouseTracking );
    389     }
    390 }
    391 
    392 /*!
    393   Handle a mouse move event for the observed widget.
    394 
    395   \param mouseEvent Mouse event
    396   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
    397 */
    398 void QwtMagnifier::widgetMouseMoveEvent( QMouseEvent *mouseEvent )
    399 {
    400     if ( !d_data->mousePressed )
     394    if ( m_data->mousePressed && parentWidget() )
     395    {
     396        m_data->mousePressed = false;
     397        parentWidget()->setMouseTracking( m_data->hasMouseTracking );
     398    }
     399}
     400
     401/*!
     402   Handle a mouse move event for the observed widget.
     403
     404   \param mouseEvent Mouse event
     405   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
     406 */
     407void QwtMagnifier::widgetMouseMoveEvent( QMouseEvent* mouseEvent )
     408{
     409    if ( !m_data->mousePressed )
    401410        return;
    402411
    403     const int dy = mouseEvent->pos().y() - d_data->mousePos.y();
     412    const int dy = mouseEvent->pos().y() - m_data->mousePos.y();
    404413    if ( dy != 0 )
    405414    {
    406         double f = d_data->mouseFactor;
     415        double f = m_data->mouseFactor;
    407416        if ( dy < 0 )
    408417            f = 1 / f;
    … …  
    411420    }
    412421
    413     d_data->mousePos = mouseEvent->pos();
    414 }
    415 
    416 /*!
    417   Handle a wheel event for the observed widget.
    418 
    419   \param wheelEvent Wheel event
    420   \sa eventFilter()
    421 */
    422 void QwtMagnifier::widgetWheelEvent( QWheelEvent *wheelEvent )
    423 {
    424     if ( wheelEvent->modifiers() != d_data->wheelModifiers )
     422    m_data->mousePos = mouseEvent->pos();
     423}
     424
     425/*!
     426   Handle a wheel event for the observed widget.
     427
     428   \param wheelEvent Wheel event
     429   \sa eventFilter()
     430 */
     431void QwtMagnifier::widgetWheelEvent( QWheelEvent* wheelEvent )
     432{
     433    if ( wheelEvent->modifiers() != m_data->wheelModifiers )
    425434    {
    426435        return;
    427436    }
    428437
    429     if ( d_data->wheelFactor != 0.0 )
    430     {
     438    if ( m_data->wheelFactor != 0.0 )
     439    {
     440#if QT_VERSION < 0x050000
     441        const int wheelDelta = wheelEvent->delta();
     442#else
     443        const QPoint delta = wheelEvent->angleDelta();
     444        const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
     445            ? delta.x() : delta.y();
     446#endif
     447
    431448        /*
    432449            A positive delta indicates that the wheel was
    … …  
    438455            of 120 (== 15 * 8).
    439456         */
    440         double f = qPow( d_data->wheelFactor,
    441             qAbs( wheelEvent->delta() / 120.0 ) );
    442 
    443         if ( wheelEvent->delta() > 0 )
     457        double f = std::pow( m_data->wheelFactor,
     458            qAbs( wheelDelta / 120.0 ) );
     459
     460        if ( wheelDelta > 0 )
    444461            f = 1 / f;
    445462
    … …  
    449466
    450467/*!
    451   Handle a key press event for the observed widget.
    452 
    453   \param keyEvent Key event
    454   \sa eventFilter(), widgetKeyReleaseEvent()
    455 */
    456 void QwtMagnifier::widgetKeyPressEvent( QKeyEvent *keyEvent )
    457 {
    458     if ( keyEvent->key() == d_data->zoomInKey &&
    459         keyEvent->modifiers() == d_data->zoomInKeyModifiers )
    460     {
    461         rescale( d_data->keyFactor );
    462     }
    463     else if ( keyEvent->key() == d_data->zoomOutKey &&
    464         keyEvent->modifiers() == d_data->zoomOutKeyModifiers )
    465     {
    466         rescale( 1.0 / d_data->keyFactor );
    467     }
    468 }
    469 
    470 /*!
    471   Handle a key release event for the observed widget.
    472 
    473   \param keyEvent Key event
    474   \sa eventFilter(), widgetKeyReleaseEvent()
    475 */
    476 void QwtMagnifier::widgetKeyReleaseEvent( QKeyEvent *keyEvent )
     468   Handle a key press event for the observed widget.
     469
     470   \param keyEvent Key event
     471   \sa eventFilter(), widgetKeyReleaseEvent()
     472 */
     473void QwtMagnifier::widgetKeyPressEvent( QKeyEvent* keyEvent )
     474{
     475    if ( keyEvent->key() == m_data->zoomInKey &&
     476        keyEvent->modifiers() == m_data->zoomInKeyModifiers )
     477    {
     478        rescale( m_data->keyFactor );
     479    }
     480    else if ( keyEvent->key() == m_data->zoomOutKey &&
     481        keyEvent->modifiers() == m_data->zoomOutKeyModifiers )
     482    {
     483        rescale( 1.0 / m_data->keyFactor );
     484    }
     485}
     486
     487/*!
     488   Handle a key release event for the observed widget.
     489
     490   \param keyEvent Key event
     491   \sa eventFilter(), widgetKeyReleaseEvent()
     492 */
     493void QwtMagnifier::widgetKeyReleaseEvent( QKeyEvent* keyEvent )
    477494{
    478495    Q_UNUSED( keyEvent );
    … …  
    480497
    481498//! \return Parent widget, where the rescaling happens
    482 QWidget *QwtMagnifier::parentWidget()
    483 {
    484     return qobject_cast<QWidget *>( parent() );
     499QWidget* QwtMagnifier::parentWidget()
     500{
     501    return qobject_cast< QWidget* >( parent() );
    485502}
    486503
    487504//! \return Parent widget, where the rescaling happens
    488 const QWidget *QwtMagnifier::parentWidget() const
    489 {
    490     return qobject_cast<const QWidget *>( parent() );
    491 }
    492 
     505const QWidget* QwtMagnifier::parentWidget() const
     506{
     507    return qobject_cast< const QWidget* >( parent() );
     508}
     509
     510#include "moc_qwt_magnifier.cpp"
  • trunk/BNC/qwt/qwt_magnifier.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_MAGNIFIER_H
    11 #define QWT_MAGNIFIER_H 1
     11#define QWT_MAGNIFIER_H
    1212
    1313#include "qwt_global.h"
    … …  
    2020
    2121/*!
    22   \brief QwtMagnifier provides zooming, by magnifying in steps.
     22   \brief QwtMagnifier provides zooming, by magnifying in steps.
    2323
    24   Using QwtMagnifier a plot can be zoomed in/out in steps using
    25   keys, the mouse wheel or moving a mouse button in vertical direction.
    26 */
    27 class QWT_EXPORT QwtMagnifier: public QObject
     24   Using QwtMagnifier a plot can be zoomed in/out in steps using
     25   keys, the mouse wheel or moving a mouse button in vertical direction.
     26 */
     27class QWT_EXPORT QwtMagnifier : public QObject
    2828{
    2929    Q_OBJECT
    3030
    31 public:
    32     explicit QwtMagnifier( QWidget * );
     31  public:
     32    explicit QwtMagnifier( QWidget* );
    3333    virtual ~QwtMagnifier();
    3434
    35     QWidget *parentWidget();
    36     const QWidget *parentWidget() const;
     35    QWidget* parentWidget();
     36    const QWidget* parentWidget() const;
    3737
    3838    void setEnabled( bool );
    … …  
    4444
    4545    void setMouseButton( Qt::MouseButton, Qt::KeyboardModifiers = Qt::NoModifier );
    46     void getMouseButton( Qt::MouseButton &, Qt::KeyboardModifiers & ) const;
     46    void getMouseButton( Qt::MouseButton&, Qt::KeyboardModifiers& ) const;
    4747
    4848    // mouse wheel
    … …  
    5858
    5959    void setZoomInKey( int key, Qt::KeyboardModifiers = Qt::NoModifier );
    60     void getZoomInKey( int &key, Qt::KeyboardModifiers & ) const;
     60    void getZoomInKey( int& key, Qt::KeyboardModifiers& ) const;
    6161
    6262    void setZoomOutKey( int key, Qt::KeyboardModifiers = Qt::NoModifier );
    63     void getZoomOutKey( int &key, Qt::KeyboardModifiers & ) const;
     63    void getZoomOutKey( int& key, Qt::KeyboardModifiers& ) const;
    6464
    65     virtual bool eventFilter( QObject *, QEvent * );
     65    virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE;
    6666
    67 protected:
     67  protected:
    6868    /*!
    6969       Rescale the parent widget
    … …  
    7272    virtual void rescale( double factor ) = 0;
    7373
    74     virtual void widgetMousePressEvent( QMouseEvent * );
    75     virtual void widgetMouseReleaseEvent( QMouseEvent * );
    76     virtual void widgetMouseMoveEvent( QMouseEvent * );
    77     virtual void widgetWheelEvent( QWheelEvent * );
    78     virtual void widgetKeyPressEvent( QKeyEvent * );
    79     virtual void widgetKeyReleaseEvent( QKeyEvent * );
     74    virtual void widgetMousePressEvent( QMouseEvent* );
     75    virtual void widgetMouseReleaseEvent( QMouseEvent* );
     76    virtual void widgetMouseMoveEvent( QMouseEvent* );
     77    virtual void widgetWheelEvent( QWheelEvent* );
     78    virtual void widgetKeyPressEvent( QKeyEvent* );
     79    virtual void widgetKeyReleaseEvent( QKeyEvent* );
    8080
    81 private:
     81  private:
    8282    class PrivateData;
    83     PrivateData *d_data;
     83    PrivateData* m_data;
    8484};
    8585
  • trunk/BNC/qwt/qwt_math.cpp

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_math.h"
     11#if QT_VERSION >= 0x050a00
     12#include <qrandom.h>
     13#endif
    1114
    1215/*!
    13   \brief Find the smallest value in an array
    14   \param array Pointer to an array
    15   \param size Array size
    16 */
    17 double qwtGetMin( const double *array, int size )
    18 {
    19     if ( size <= 0 )
    20         return 0.0;
    21 
    22     double rv = array[0];
    23     for ( int i = 1; i < size; i++ )
    24         rv = qMin( rv, array[i] );
    25 
    26     return rv;
    27 }
    28 
    29 
    30 /*!
    31   \brief Find the largest value in an array
    32   \param array Pointer to an array
    33   \param size Array size
    34 */
    35 double qwtGetMax( const double *array, int size )
    36 {
    37     if ( size <= 0 )
    38         return 0.0;
    39 
    40     double rv = array[0];
    41     for ( int i = 1; i < size; i++ )
    42         rv = qMax( rv, array[i] );
    43 
    44     return rv;
    45 }
    46 
    47 /*!
    48   \brief Normalize an angle to be int the range [0.0, 2 * PI[
    49   \param radians Angle in radians
    50   \return Normalized angle in radians
    51 */
     16   \brief Normalize an angle to be int the range [0.0, 2 * PI[
     17   \param radians Angle in radians
     18   \return Normalized angle in radians
     19 */
    5220double qwtNormalizeRadians( double radians )
    5321{
    54     double a = ::fmod( radians, 2.0 * M_PI );
     22    double a = std::fmod( radians, 2.0 * M_PI );
    5523    if ( a < 0.0 )
    5624        a += 2.0 * M_PI;
    … …  
    6129
    6230/*!
    63   \brief Normalize an angle to be int the range [0.0, 360.0[
    64   \param radians Angle in degrees
    65   \return Normalized angle in degrees
    66 */
     31   \brief Normalize an angle to be int the range [0.0, 360.0[
     32   \param radians Angle in degrees
     33   \return Normalized angle in degrees
     34 */
    6735double qwtNormalizeDegrees( double degrees )
    6836{
    69     double a = ::fmod( degrees, 360.0 );
     37    double a = std::fmod( degrees, 360.0 );
    7038    if ( a < 0.0 )
    7139        a += 360.0;
    … …  
    7341    return a;
    7442}
     43
     44/*!
     45   \brief Uses QRandomGenerator for Qt >= 5.10 and qRand() otherwise
     46   \return A 32-bit random quantity
     47 */
     48quint32 qwtRand()
     49{
     50#if QT_VERSION >= 0x050a00
     51    return QRandomGenerator::global()->generate();
     52#else
     53    return static_cast< quint32 >( qrand() ); // [0, RAND_MAX ]
     54#endif
     55}
  • trunk/BNC/qwt/qwt_math.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414
    15 #if defined(_MSC_VER)
    1615/*
    17   Microsoft says:
    18 
    19   Define _USE_MATH_DEFINES before including math.h to expose these macro
    20   definitions for common math constants.  These are placed under an #ifdef
    21   since these commonly-defined names are not part of the C/C++ standards.
    22 */
    23 #define _USE_MATH_DEFINES 1
    24 #endif
    25 
    26 #include <qmath.h>
    27 #include "qwt_global.h"
     16   Microsoft says:
     17
     18   Define _USE_MATH_DEFINES before including math.h to expose these macro
     19   definitions for common math constants.  These are placed under an #ifdef
     20   since these commonly-defined names are not part of the C/C++ standards.
     21 */
     22
     23#ifndef _USE_MATH_DEFINES
     24#define _USE_MATH_DEFINES
     25#define undef_USE_MATH_DEFINES
     26#endif
     27
     28#include <cmath>
     29
     30#ifdef undef_USE_MATH_DEFINES
     31#undef _USE_MATH_DEFINES
     32#undef undef_USE_MATH_DEFINES
     33#endif
     34
     35#ifndef M_E
     36#define M_E ( 2.7182818284590452354 )
     37#endif
     38
     39#ifndef M_LOG2E
     40#define M_LOG2E ( 1.4426950408889634074 )
     41#endif
     42
     43#ifndef M_LOG10E
     44#define M_LOG10E ( 0.43429448190325182765 )
     45#endif
     46
     47#ifndef M_LN2
     48#define M_LN2 ( 0.69314718055994530942 )
     49#endif
     50
     51#ifndef M_LN10
     52#define M_LN10 ( 2.30258509299404568402 )
     53#endif
     54
     55#ifndef M_PI
     56#define M_PI ( 3.14159265358979323846 )
     57#endif
    2858
    2959#ifndef M_PI_2
    30 // For Qt <= 4.8.4 M_PI_2 is not known by MinGW-w64
    31 // when compiling with -std=c++11
    32 #define M_PI_2 (1.57079632679489661923)
    33 #endif
    34 
    35 #ifndef LOG_MIN
    36 //! Minimum value for logarithmic scales
    37 #define LOG_MIN 1.0e-100
    38 #endif
    39 
    40 #ifndef LOG_MAX
    41 //! Maximum value for logarithmic scales
    42 #define LOG_MAX 1.0e100
    43 #endif
    44 
    45 QWT_EXPORT double qwtGetMin( const double *array, int size );
    46 QWT_EXPORT double qwtGetMax( const double *array, int size );
     60#define M_PI_2 ( 1.57079632679489661923 )
     61#endif
     62
     63#ifndef M_PI_4
     64#define M_PI_4 ( 0.78539816339744830962 )
     65#endif
     66
     67#ifndef M_1_PI
     68#define M_1_PI ( 0.31830988618379067154 )
     69#endif
     70
     71#ifndef M_2_PI
     72#define M_2_PI ( 0.63661977236758134308 )
     73#endif
     74
     75#ifndef M_2_SQRTPI
     76#define M_2_SQRTPI ( 1.12837916709551257390 )
     77#endif
     78
     79#ifndef M_SQRT2
     80#define M_SQRT2 ( 1.41421356237309504880 )
     81#endif
     82
     83#ifndef M_SQRT1_2
     84#define M_SQRT1_2 ( 0.70710678118654752440 )
     85#endif
     86
     87#if defined( QT_WARNING_PUSH )
     88    /*
     89        early Qt versions not having QT_WARNING_PUSH is full of warnings
     90        so that we do not care of suppressing those from below
     91     */
     92    QT_WARNING_PUSH
     93    QT_WARNING_DISABLE_CLANG("-Wdouble-promotion")
     94    QT_WARNING_DISABLE_GCC("-Wdouble-promotion")
     95#endif
     96
     97/*
     98    On systems, where qreal is a float you often run into
     99    compiler issues with qMin/qMax.
     100 */
     101
     102//! \return Minimum of a and b.
     103QWT_CONSTEXPR inline float qwtMinF( float a, float b )
     104{
     105    return ( a < b ) ? a : b;
     106}
     107
     108//! \return Minimum of a and b.
     109QWT_CONSTEXPR inline double qwtMinF( double a, double b )
     110{
     111    return ( a < b ) ? a : b;
     112}
     113
     114//! \return Minimum of a and b.
     115QWT_CONSTEXPR inline qreal qwtMinF( float a, double b )
     116{
     117    return ( a < b ) ? a : b;
     118}
     119
     120//! \return Minimum of a and b.
     121QWT_CONSTEXPR inline qreal qwtMinF( double a, float b )
     122{
     123    return ( a < b ) ? a : b;
     124}
     125
     126//! \return Maximum of a and b.
     127QWT_CONSTEXPR inline float qwtMaxF( float a, float b )
     128{
     129    return ( a < b ) ? b : a;
     130}
     131
     132//! \return Maximum of a and b.
     133QWT_CONSTEXPR inline double qwtMaxF( double a, double b )
     134{
     135    return ( a < b ) ? b : a;
     136}
     137
     138//! \return Maximum of a and b.
     139QWT_CONSTEXPR inline qreal qwtMaxF( float a, double b )
     140{
     141    return ( a < b ) ? b : a;
     142}
     143
     144//! \return Maximum of a and b.
     145QWT_CONSTEXPR inline qreal qwtMaxF( double a, float b )
     146{
     147    return ( a < b ) ? b : a;
     148}
     149
     150#if defined( QT_WARNING_POP )
     151    QT_WARNING_POP
     152#endif
    47153
    48154QWT_EXPORT double qwtNormalizeRadians( double radians );
    49155QWT_EXPORT double qwtNormalizeDegrees( double degrees );
     156QWT_EXPORT quint32 qwtRand();
    50157
    51158/*!
    52   \brief Compare 2 values, relative to an interval
    53 
    54   Values are "equal", when :
    55   \f$\cdot value2 - value1 <= abs(intervalSize * 10e^{-6})\f$
    56 
    57   \param value1 First value to compare
    58   \param value2 Second value to compare
    59   \param intervalSize interval size
    60 
    61   \return 0: if equal, -1: if value2 > value1, 1: if value1 > value2
    62 */
     159   \brief Compare 2 values, relative to an interval
     160
     161   Values are "equal", when :
     162   \f$\cdot value2 - value1 <= abs(intervalSize * 10e^{-6})\f$
     163
     164   \param value1 First value to compare
     165   \param value2 Second value to compare
     166   \param intervalSize interval size
     167
     168   \return 0: if equal, -1: if value2 > value1, 1: if value1 > value2
     169 */
    63170inline int qwtFuzzyCompare( double value1, double value2, double intervalSize )
    64171{
    … …  
    72179
    73180    return 0;
    74 }
    75 
    76 
    77 inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 )
    78 {
    79     return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );
    80 }
    81 
    82 inline bool qwtFuzzyLessOrEqual( double d1, double d2 )
    83 {
    84     return ( d1 <= d2 ) || qFuzzyCompare( d1, d2 );
    85181}
    86182
    … …  
    135231}
    136232
     233/* !
     234   \brief Calculate a value of a cubic polynomial
     235
     236   \param x Value
     237   \param a Cubic coefficient
     238   \param b Quadratic coefficient
     239   \param c Linear coefficient
     240   \param d Constant offset
     241
     242   \return Value of the polyonom for x
     243 */
     244inline double qwtCubicPolynomial( double x,
     245    double a, double b, double c, double d )
     246{
     247    return ( ( ( a * x ) + b ) * x + c ) * x + d;
     248}
     249
    137250//! Translate degrees into radians
    138251inline double qwtRadians( double degrees )
    … …  
    147260}
    148261
    149 #endif
     262/*!
     263    The same as qCeil, but avoids including qmath.h
     264    \return Ceiling of value.
     265 */
     266inline int qwtCeil( qreal value )
     267{
     268    using std::ceil;
     269    return int( ceil( value ) );
     270}
     271/*!
     272    The same as qFloor, but avoids including qmath.h
     273    \return Floor of value.
     274 */
     275inline int qwtFloor( qreal value )
     276{
     277    using std::floor;
     278    return int( floor( value ) );
     279}
     280
     281#endif
  • trunk/BNC/qwt/qwt_matrix_raster_data.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_matrix_raster_data.h"
     11#include "qwt_interval.h"
     12
     13#include <qvector.h>
    1114#include <qnumeric.h>
    12 #include <qmath.h>
     15#include <qrect.h>
     16
     17static inline double qwtHermiteInterpolate(
     18    double A, double B, double C, double D, double t )
     19{
     20    const double t2 = t * t;
     21    const double t3 = t2 * t;
     22
     23    const double a = -A / 2.0 + ( 3.0 * B ) / 2.0 - ( 3.0 * C ) / 2.0 + D / 2.0;
     24    const double b = A - ( 5.0 * B ) / 2.0 + 2.0 * C - D / 2.0;
     25    const double c = -A / 2.0 + C / 2.0;
     26    const double d = B;
     27
     28    return a * t3 + b * t2 + c * t + d;
     29}
     30
     31static inline double qwtBicubicInterpolate(
     32    double v00, double v10, double v20, double v30,
     33    double v01, double v11, double v21, double v31,
     34    double v02, double v12, double v22, double v32,
     35    double v03, double v13, double v23, double v33,
     36    double dx, double dy )
     37{
     38    const double v0 = qwtHermiteInterpolate( v00, v10, v20, v30, dx );
     39    const double v1 = qwtHermiteInterpolate( v01, v11, v21, v31, dx );
     40    const double v2 = qwtHermiteInterpolate( v02, v12, v22, v32, dx );
     41    const double v3 = qwtHermiteInterpolate( v03, v13, v23, v33, dx );
     42
     43    return qwtHermiteInterpolate( v0, v1, v2, v3, dy );
     44}
    1345
    1446class QwtMatrixRasterData::PrivateData
    1547{
    16 public:
    17     PrivateData():
    18         resampleMode(QwtMatrixRasterData::NearestNeighbour),
    19         numColumns(0)
     48  public:
     49    PrivateData()
     50        : resampleMode( QwtMatrixRasterData::NearestNeighbour )
     51        , numColumns(0)
    2052    {
    2153    }
    … …  
    2658    }
    2759
     60    QwtInterval intervals[3];
    2861    QwtMatrixRasterData::ResampleMode resampleMode;
    2962
    30     QVector<double> values;
     63    QVector< double > values;
    3164    int numColumns;
    3265    int numRows;
    … …  
    3972QwtMatrixRasterData::QwtMatrixRasterData()
    4073{
    41     d_data = new PrivateData();
     74    m_data = new PrivateData();
    4275    update();
    4376}
    … …  
    4679QwtMatrixRasterData::~QwtMatrixRasterData()
    4780{
    48     delete d_data;
     81    delete m_data;
    4982}
    5083
    … …  
    5487   \param mode Resampling mode
    5588   \sa resampleMode(), value()
    56 */
     89 */
    5790void QwtMatrixRasterData::setResampleMode( ResampleMode mode )
    5891{
    59     d_data->resampleMode = mode;
     92    m_data->resampleMode = mode;
    6093}
    6194
    … …  
    6396   \return resampling algorithm
    6497   \sa setResampleMode(), value()
    65 */
     98 */
    6699QwtMatrixRasterData::ResampleMode QwtMatrixRasterData::resampleMode() const
    67100{
    68     return d_data->resampleMode;
     101    return m_data->resampleMode;
    69102}
    70103
    … …  
    84117
    85118   \sa QwtRasterData::interval(), setValueMatrix()
    86 */
     119 */
    87120void QwtMatrixRasterData::setInterval(
    88     Qt::Axis axis, const QwtInterval &interval )
    89 {
    90     QwtRasterData::setInterval( axis, interval );
    91     update();
     121    Qt::Axis axis, const QwtInterval& interval )
     122{
     123    if ( axis >= 0 && axis <= 2 )
     124    {
     125        m_data->intervals[axis] = interval;
     126        update();
     127    }
     128}
     129
     130/*!
     131   \return Bounding interval for an axis
     132   \sa setInterval
     133 */
     134QwtInterval QwtMatrixRasterData::interval( Qt::Axis axis ) const
     135{
     136    if ( axis >= 0 && axis <= 2 )
     137        return m_data->intervals[ axis ];
     138
     139    return QwtInterval();
    92140}
    93141
    … …  
    104152
    105153   \sa valueMatrix(), numColumns(), numRows(), setInterval()()
    106 */
     154 */
    107155void QwtMatrixRasterData::setValueMatrix(
    108     const QVector<double> &values, int numColumns )
    109 {
    110     d_data->values = values;
    111     d_data->numColumns = qMax( numColumns, 0 );
     156    const QVector< double >& values, int numColumns )
     157{
     158    m_data->values = values;
     159    m_data->numColumns = qMax( numColumns, 0 );
    112160    update();
    113161}
    … …  
    116164   \return Value matrix
    117165   \sa setValueMatrix(), numColumns(), numRows(), setInterval()
    118 */
    119 const QVector<double> QwtMatrixRasterData::valueMatrix() const
    120 {
    121     return d_data->values;
    122 }
    123 
    124 /*!
    125   \brief Change a single value in the matrix
    126 
    127   \param row Row index
    128   \param col Column index
    129   \param value New value
    130 
    131   \sa value(), setValueMatrix()
    132 */
     166 */
     167const QVector< double > QwtMatrixRasterData::valueMatrix() const
     168{
     169    return m_data->values;
     170}
     171
     172/*!
     173   \brief Change a single value in the matrix
     174
     175   \param row Row index
     176   \param col Column index
     177   \param value New value
     178
     179   \sa value(), setValueMatrix()
     180 */
    133181void QwtMatrixRasterData::setValue( int row, int col, double value )
    134182{
    135     if ( row >= 0 && row < d_data->numRows &&
    136         col >= 0 && col < d_data->numColumns )
    137     {
    138         const int index = row * d_data->numColumns + col;
    139         d_data->values.data()[ index ] = value;
     183    if ( row >= 0 && row < m_data->numRows &&
     184        col >= 0 && col < m_data->numColumns )
     185    {
     186        const int index = row * m_data->numColumns + col;
     187        m_data->values.data()[ index ] = value;
    140188    }
    141189}
    … …  
    144192   \return Number of columns of the value matrix
    145193   \sa valueMatrix(), numRows(), setValueMatrix()
    146 */
     194 */
    147195int QwtMatrixRasterData::numColumns() const
    148196{
    149     return d_data->numColumns;
     197    return m_data->numColumns;
    150198}
    151199
    … …  
    153201   \return Number of rows of the value matrix
    154202   \sa valueMatrix(), numColumns(), setValueMatrix()
    155 */
     203 */
    156204int QwtMatrixRasterData::numRows() const
    157205{
    158     return d_data->numRows;
     206    return m_data->numRows;
    159207}
    160208
    … …  
    178226
    179227   \sa ResampleMode, setMatrix(), setInterval()
    180 */
    181 QRectF QwtMatrixRasterData::pixelHint( const QRectF &area ) const
     228 */
     229QRectF QwtMatrixRasterData::pixelHint( const QRectF& area ) const
    182230{
    183231    Q_UNUSED( area )
    184232
    185233    QRectF rect;
    186     if ( d_data->resampleMode == NearestNeighbour )
     234    if ( m_data->resampleMode == NearestNeighbour )
    187235    {
    188236        const QwtInterval intervalX = interval( Qt::XAxis );
    … …  
    191239        {
    192240            rect = QRectF( intervalX.minValue(), intervalY.minValue(),
    193                 d_data->dx, d_data->dy );
     241                m_data->dx, m_data->dy );
    194242        }
    195243    }
    … …  
    205253
    206254   \sa ResampleMode
    207 */
     255 */
    208256double QwtMatrixRasterData::value( double x, double y ) const
    209257{
    … …  
    216264    double value;
    217265
    218     switch( d_data->resampleMode )
    219     {
     266    switch( m_data->resampleMode )
     267    {
     268        case BicubicInterpolation:
     269        {
     270            const double colF = ( x - xInterval.minValue() ) / m_data->dx;
     271            const double rowF = ( y - yInterval.minValue() ) / m_data->dy;
     272
     273            const int col = qRound( colF );
     274            const int row = qRound( rowF );
     275
     276            int col0 = col - 2;
     277            int col1 = col - 1;
     278            int col2 = col;
     279            int col3 = col + 1;
     280
     281            if ( col1 < 0 )
     282                col1 = col2;
     283
     284            if ( col0 < 0 )
     285                col0 = col1;
     286
     287            if ( col2 >= m_data->numColumns )
     288                col2 = col1;
     289
     290            if ( col3 >= m_data->numColumns )
     291                col3 = col2;
     292
     293            int row0 = row - 2;
     294            int row1 = row - 1;
     295            int row2 = row;
     296            int row3 = row + 1;
     297
     298            if ( row1 < 0 )
     299                row1 = row2;
     300
     301            if ( row0 < 0 )
     302                row0 = row1;
     303
     304            if ( row2 >= m_data->numRows )
     305                row2 = row1;
     306
     307            if ( row3 >= m_data->numRows )
     308                row3 = row2;
     309
     310            // First row
     311            const double v00 = m_data->value( row0, col0 );
     312            const double v10 = m_data->value( row0, col1 );
     313            const double v20 = m_data->value( row0, col2 );
     314            const double v30 = m_data->value( row0, col3 );
     315
     316            // Second row
     317            const double v01 = m_data->value( row1, col0 );
     318            const double v11 = m_data->value( row1, col1 );
     319            const double v21 = m_data->value( row1, col2 );
     320            const double v31 = m_data->value( row1, col3 );
     321
     322            // Third row
     323            const double v02 = m_data->value( row2, col0 );
     324            const double v12 = m_data->value( row2, col1 );
     325            const double v22 = m_data->value( row2, col2 );
     326            const double v32 = m_data->value( row2, col3 );
     327
     328            // Fourth row
     329            const double v03 = m_data->value( row3, col0 );
     330            const double v13 = m_data->value( row3, col1 );
     331            const double v23 = m_data->value( row3, col2 );
     332            const double v33 = m_data->value( row3, col3 );
     333
     334            value = qwtBicubicInterpolate(
     335                v00, v10, v20, v30, v01, v11, v21, v31,
     336                v02, v12, v22, v32, v03, v13, v23, v33,
     337                colF - col + 0.5, rowF - row + 0.5 );
     338
     339            break;
     340        }
    220341        case BilinearInterpolation:
    221342        {
    222             int col1 = qRound( (x - xInterval.minValue() ) / d_data->dx ) - 1;
    223             int row1 = qRound( (y - yInterval.minValue() ) / d_data->dy ) - 1;
     343            int col1 = qRound( ( x - xInterval.minValue() ) / m_data->dx ) - 1;
     344            int row1 = qRound( ( y - yInterval.minValue() ) / m_data->dy ) - 1;
    224345            int col2 = col1 + 1;
    225346            int row2 = row1 + 1;
    … …  
    227348            if ( col1 < 0 )
    228349                col1 = col2;
    229             else if ( col2 >= static_cast<int>( d_data->numColumns ) )
     350            else if ( col2 >= m_data->numColumns )
    230351                col2 = col1;
    231352
    232353            if ( row1 < 0 )
    233354                row1 = row2;
    234             else if ( row2 >= static_cast<int>( d_data->numRows ) )
     355            else if ( row2 >= m_data->numRows )
    235356                row2 = row1;
    236357
    237             const double v11 = d_data->value( row1, col1 );
    238             const double v21 = d_data->value( row1, col2 );
    239             const double v12 = d_data->value( row2, col1 );
    240             const double v22 = d_data->value( row2, col2 );
    241 
    242             const double x2 = xInterval.minValue() +
    243                 ( col2 + 0.5 ) * d_data->dx;
    244             const double y2 = yInterval.minValue() +
    245                 ( row2 + 0.5 ) * d_data->dy;
    246 
    247             const double rx = ( x2 - x ) / d_data->dx;
    248             const double ry = ( y2 - y ) / d_data->dy;
     358            const double v11 = m_data->value( row1, col1 );
     359            const double v21 = m_data->value( row1, col2 );
     360            const double v12 = m_data->value( row2, col1 );
     361            const double v22 = m_data->value( row2, col2 );
     362
     363            const double x2 = xInterval.minValue() + ( col2 + 0.5 ) * m_data->dx;
     364            const double y2 = yInterval.minValue() + ( row2 + 0.5 ) * m_data->dy;
     365
     366            const double rx = ( x2 - x ) / m_data->dx;
     367            const double ry = ( y2 - y ) / m_data->dy;
    249368
    250369            const double vr1 = rx * v11 + ( 1.0 - rx ) * v21;
    … …  
    258377        default:
    259378        {
    260             int row = int( (y - yInterval.minValue() ) / d_data->dy );
    261             int col = int( (x - xInterval.minValue() ) / d_data->dx );
     379            int row = int( ( y - yInterval.minValue() ) / m_data->dy );
     380            int col = int( ( x - xInterval.minValue() ) / m_data->dx );
    262381
    263382            // In case of intervals, where the maximum is included
    … …  
    266385            // from the last row/col
    267386
    268             if ( row >= d_data->numRows )
    269                 row = d_data->numRows - 1;
    270 
    271             if ( col >= d_data->numColumns )
    272                 col = d_data->numColumns - 1;
    273 
    274             value = d_data->value( row, col );
     387            if ( row >= m_data->numRows )
     388                row = m_data->numRows - 1;
     389
     390            if ( col >= m_data->numColumns )
     391                col = m_data->numColumns - 1;
     392
     393            value = m_data->value( row, col );
    275394        }
    276395    }
    … …  
    281400void QwtMatrixRasterData::update()
    282401{
    283     d_data->numRows = 0;
    284     d_data->dx = 0.0;
    285     d_data->dy = 0.0;
    286 
    287     if ( d_data->numColumns > 0 )
    288     {
    289         d_data->numRows = d_data->values.size() / d_data->numColumns;
     402    m_data->numRows = 0;
     403    m_data->dx = 0.0;
     404    m_data->dy = 0.0;
     405
     406    if ( m_data->numColumns > 0 )
     407    {
     408        m_data->numRows = m_data->values.size() / m_data->numColumns;
    290409
    291410        const QwtInterval xInterval = interval( Qt::XAxis );
    292411        const QwtInterval yInterval = interval( Qt::YAxis );
    293412        if ( xInterval.isValid() )
    294             d_data->dx = xInterval.width() / d_data->numColumns;
     413            m_data->dx = xInterval.width() / m_data->numColumns;
    295414        if ( yInterval.isValid() )
    296             d_data->dy = yInterval.width() / d_data->numRows;
    297     }
    298 }
     415            m_data->dy = yInterval.width() / m_data->numRows;
     416    }
     417}
  • trunk/BNC/qwt/qwt_matrix_raster_data.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_MATRIX_RASTER_DATA_H
    11 #define QWT_MATRIX_RASTER_DATA_H 1
     11#define QWT_MATRIX_RASTER_DATA_H
    1212
    1313#include "qwt_global.h"
    1414#include "qwt_raster_data.h"
    15 #include <qvector.h>
     15
     16#if QT_VERSION < 0x060000
     17template< typename T > class QVector;
     18#endif
    1619
    1720/*!
    18   \brief A class representing a matrix of values as raster data
     21   \brief A class representing a matrix of values as raster data
    1922
    20   QwtMatrixRasterData implements an interface for a matrix of
    21   equidistant values, that can be used by a QwtPlotRasterItem.
    22   It implements a couple of resampling algorithms, to provide
    23   values for positions, that or not on the value matrix.
    24 */
    25 class QWT_EXPORT QwtMatrixRasterData: public QwtRasterData
     23   QwtMatrixRasterData implements an interface for a matrix of
     24   equidistant values, that can be used by a QwtPlotRasterItem.
     25   It implements a couple of resampling algorithms, to provide
     26   values for positions, that or not on the value matrix.
     27 */
     28class QWT_EXPORT QwtMatrixRasterData : public QwtRasterData
    2629{
    27 public:
     30  public:
    2831    /*!
    29       \brief Resampling algorithm
    30       The default setting is NearestNeighbour;
    31     */
     32       \brief Resampling algorithm
     33       The default setting is NearestNeighbour;
     34     */
    3235    enum ResampleMode
    3336    {
    3437        /*!
    35           Return the value from the matrix, that is nearest to the
    36           the requested position.
     38           Return the value from the matrix, that is nearest to the
     39           the requested position.
    3740         */
    3841        NearestNeighbour,
    3942
    4043        /*!
    41           Interpolate the value from the distances and values of the
    42           4 surrounding values in the matrix,
     44           Interpolate the value from the distances and values of the
     45           4 surrounding values in the matrix,
    4346         */
    44         BilinearInterpolation
     47        BilinearInterpolation,
     48
     49        /*!
     50           Interpolate the value from the 16 surrounding values in the
     51           matrix using hermite bicubic interpolation
     52         */
     53        BicubicInterpolation
    4554    };
    4655
    … …  
    5160    ResampleMode resampleMode() const;
    5261
    53     virtual void setInterval( Qt::Axis, const QwtInterval & );
     62    void setInterval( Qt::Axis, const QwtInterval& );
     63    virtual QwtInterval interval( Qt::Axis axis) const QWT_OVERRIDE QWT_FINAL;
    5464
    55     void setValueMatrix( const QVector<double> &values, int numColumns );
    56     const QVector<double> valueMatrix() const;
     65    void setValueMatrix( const QVector< double >& values, int numColumns );
     66    const QVector< double > valueMatrix() const;
    5767
    5868    void setValue( int row, int col, double value );
    … …  
    6171    int numRows() const;
    6272
    63     virtual QRectF pixelHint( const QRectF & ) const;
     73    virtual QRectF pixelHint( const QRectF& ) const QWT_OVERRIDE;
    6474
    65     virtual double value( double x, double y ) const;
     75    virtual double value( double x, double y ) const QWT_OVERRIDE;
    6676
    67 private:
     77  private:
    6878    void update();
    6979
    7080    class PrivateData;
    71     PrivateData *d_data;
     81    PrivateData* m_data;
    7282};
    7383
  • trunk/BNC/qwt/qwt_null_paintdevice.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include <qpaintengine.h>
    1212#include <qpainterpath.h>
    13 #include <qpixmap.h>
    1413
    1514class QwtNullPaintDevice::PrivateData
    1615{
    17 public:
     16  public:
    1817    PrivateData():
    1918        mode( QwtNullPaintDevice::NormalMode )
    … …  
    2423};
    2524
    26 class QwtNullPaintDevice::PaintEngine: public QPaintEngine
    27 {
    28 public:
     25class QwtNullPaintDevice::PaintEngine QWT_FINAL : public QPaintEngine
     26{
     27  public:
    2928    PaintEngine();
    3029
    31     virtual bool begin( QPaintDevice * );
    32     virtual bool end();
    33 
    34     virtual Type type () const;
    35     virtual void updateState(const QPaintEngineState &);
    36 
    37     virtual void drawRects(const QRect *, int );
    38     virtual void drawRects(const QRectF *, int );
    39 
    40     virtual void drawLines(const QLine *, int );
    41     virtual void drawLines(const QLineF *, int );
    42 
    43     virtual void drawEllipse(const QRectF &);
    44     virtual void drawEllipse(const QRect &);
    45 
    46     virtual void drawPath(const QPainterPath &);
    47 
    48     virtual void drawPoints(const QPointF *, int );
    49     virtual void drawPoints(const QPoint *, int );
    50 
    51     virtual void drawPolygon(const QPointF *, int , PolygonDrawMode );
    52     virtual void drawPolygon(const QPoint *, int , PolygonDrawMode );
    53 
    54     virtual void drawPixmap(const QRectF &,
    55         const QPixmap &, const QRectF &);
    56 
    57     virtual void drawTextItem(const QPointF &, const QTextItem &);
    58 
    59     virtual void drawTiledPixmap(const QRectF &,
    60         const QPixmap &, const QPointF &s);
    61 
    62     virtual void drawImage(const QRectF &,
    63         const QImage &, const QRectF &, Qt::ImageConversionFlags );
    64 
    65 private:
    66     QwtNullPaintDevice *nullDevice();
     30    virtual bool begin( QPaintDevice* ) QWT_OVERRIDE;
     31    virtual bool end() QWT_OVERRIDE;
     32
     33    virtual Type type () const QWT_OVERRIDE;
     34    virtual void updateState(const QPaintEngineState&) QWT_OVERRIDE;
     35
     36    virtual void drawRects(const QRect*, int ) QWT_OVERRIDE;
     37    virtual void drawRects(const QRectF*, int ) QWT_OVERRIDE;
     38
     39    virtual void drawLines(const QLine*, int ) QWT_OVERRIDE;
     40    virtual void drawLines(const QLineF*, int ) QWT_OVERRIDE;
     41
     42    virtual void drawEllipse(const QRectF&) QWT_OVERRIDE;
     43    virtual void drawEllipse(const QRect&) QWT_OVERRIDE;
     44
     45    virtual void drawPath(const QPainterPath&) QWT_OVERRIDE;
     46
     47    virtual void drawPoints(const QPointF*, int ) QWT_OVERRIDE;
     48    virtual void drawPoints(const QPoint*, int ) QWT_OVERRIDE;
     49
     50    virtual void drawPolygon(
     51        const QPointF*, int, PolygonDrawMode ) QWT_OVERRIDE;
     52
     53    virtual void drawPolygon(
     54        const QPoint*, int, PolygonDrawMode ) QWT_OVERRIDE;
     55
     56    virtual void drawPixmap(const QRectF&,
     57        const QPixmap&, const QRectF&) QWT_OVERRIDE;
     58
     59    virtual void drawTextItem(
     60        const QPointF&, const QTextItem&) QWT_OVERRIDE;
     61
     62    virtual void drawTiledPixmap(const QRectF&,
     63        const QPixmap&, const QPointF& s) QWT_OVERRIDE;
     64
     65    virtual void drawImage(const QRectF&, const QImage&,
     66        const QRectF&, Qt::ImageConversionFlags ) QWT_OVERRIDE;
     67
     68  private:
     69    QwtNullPaintDevice* nullDevice();
    6770};
    6871
    69 QwtNullPaintDevice::PaintEngine::PaintEngine():
    70     QPaintEngine( QPaintEngine::AllFeatures )
    71 {
    72 }
    73 
    74 bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice * )
     72QwtNullPaintDevice::PaintEngine::PaintEngine()
     73    : QPaintEngine( QPaintEngine::AllFeatures )
     74{
     75}
     76
     77bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice* )
    7578{
    7679    setActive( true );
    … …  
    8689QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const
    8790{
    88     return QPaintEngine::User;
     91    /*
     92        How to avoid conflicts with other 3rd party pain engines ?
     93        At least we don't use QPaintEngine::User what is known to
     94        be the value of some print engines
     95     */
     96    return static_cast< QPaintEngine::Type >( QPaintEngine::MaxUser - 2 );
    8997}
    9098
    9199void QwtNullPaintDevice::PaintEngine::drawRects(
    92     const QRect *rects, int rectCount)
    93 {
    94     QwtNullPaintDevice *device = nullDevice();
     100    const QRect* rects, int rectCount)
     101{
     102    QwtNullPaintDevice* device = nullDevice();
    95103    if ( device == NULL )
    96104        return;
    … …  
    106114
    107115void QwtNullPaintDevice::PaintEngine::drawRects(
    108     const QRectF *rects, int rectCount)
    109 {
    110     QwtNullPaintDevice *device = nullDevice();
     116    const QRectF* rects, int rectCount)
     117{
     118    QwtNullPaintDevice* device = nullDevice();
    111119    if ( device == NULL )
    112120        return;
    … …  
    122130
    123131void QwtNullPaintDevice::PaintEngine::drawLines(
    124     const QLine *lines, int lineCount)
    125 {
    126     QwtNullPaintDevice *device = nullDevice();
     132    const QLine* lines, int lineCount)
     133{
     134    QwtNullPaintDevice* device = nullDevice();
    127135    if ( device == NULL )
    128136        return;
    … …  
    138146
    139147void QwtNullPaintDevice::PaintEngine::drawLines(
    140     const QLineF *lines, int lineCount)
    141 {
    142     QwtNullPaintDevice *device = nullDevice();
     148    const QLineF* lines, int lineCount)
     149{
     150    QwtNullPaintDevice* device = nullDevice();
    143151    if ( device == NULL )
    144152        return;
    … …  
    154162
    155163void QwtNullPaintDevice::PaintEngine::drawEllipse(
    156     const QRectF &rect)
    157 {
    158     QwtNullPaintDevice *device = nullDevice();
     164    const QRectF& rect)
     165{
     166    QwtNullPaintDevice* device = nullDevice();
    159167    if ( device == NULL )
    160168        return;
    … …  
    170178
    171179void QwtNullPaintDevice::PaintEngine::drawEllipse(
    172     const QRect &rect)
    173 {
    174     QwtNullPaintDevice *device = nullDevice();
     180    const QRect& rect)
     181{
     182    QwtNullPaintDevice* device = nullDevice();
    175183    if ( device == NULL )
    176184        return;
    … …  
    187195
    188196void QwtNullPaintDevice::PaintEngine::drawPath(
    189     const QPainterPath &path)
    190 {
    191     QwtNullPaintDevice *device = nullDevice();
     197    const QPainterPath& path)
     198{
     199    QwtNullPaintDevice* device = nullDevice();
    192200    if ( device == NULL )
    193201        return;
    … …  
    197205
    198206void QwtNullPaintDevice::PaintEngine::drawPoints(
    199     const QPointF *points, int pointCount)
    200 {
    201     QwtNullPaintDevice *device = nullDevice();
     207    const QPointF* points, int pointCount)
     208{
     209    QwtNullPaintDevice* device = nullDevice();
    202210    if ( device == NULL )
    203211        return;
    … …  
    213221
    214222void QwtNullPaintDevice::PaintEngine::drawPoints(
    215     const QPoint *points, int pointCount)
    216 {
    217     QwtNullPaintDevice *device = nullDevice();
     223    const QPoint* points, int pointCount)
     224{
     225    QwtNullPaintDevice* device = nullDevice();
    218226    if ( device == NULL )
    219227        return;
    … …  
    229237
    230238void QwtNullPaintDevice::PaintEngine::drawPolygon(
    231     const QPointF *points, int pointCount, PolygonDrawMode mode)
    232 {
    233     QwtNullPaintDevice *device = nullDevice();
     239    const QPointF* points, int pointCount, PolygonDrawMode mode)
     240{
     241    QwtNullPaintDevice* device = nullDevice();
    234242    if ( device == NULL )
    235243        return;
    … …  
    257265
    258266void QwtNullPaintDevice::PaintEngine::drawPolygon(
    259     const QPoint *points, int pointCount, PolygonDrawMode mode)
    260 {
    261     QwtNullPaintDevice *device = nullDevice();
     267    const QPoint* points, int pointCount, PolygonDrawMode mode)
     268{
     269    QwtNullPaintDevice* device = nullDevice();
    262270    if ( device == NULL )
    263271        return;
    … …  
    285293
    286294void QwtNullPaintDevice::PaintEngine::drawPixmap(
    287     const QRectF &rect, const QPixmap &pm, const QRectF &subRect )
    288 {
    289     QwtNullPaintDevice *device = nullDevice();
     295    const QRectF& rect, const QPixmap& pm, const QRectF& subRect )
     296{
     297    QwtNullPaintDevice* device = nullDevice();
    290298    if ( device == NULL )
    291299        return;
    … …  
    295303
    296304void QwtNullPaintDevice::PaintEngine::drawTextItem(
    297     const QPointF &pos, const QTextItem &textItem)
    298 {
    299     QwtNullPaintDevice *device = nullDevice();
     305    const QPointF& pos, const QTextItem& textItem)
     306{
     307    QwtNullPaintDevice* device = nullDevice();
    300308    if ( device == NULL )
    301309        return;
    … …  
    311319
    312320void QwtNullPaintDevice::PaintEngine::drawTiledPixmap(
    313     const QRectF &rect, const QPixmap &pixmap,
    314     const QPointF &subRect)
    315 {
    316     QwtNullPaintDevice *device = nullDevice();
     321    const QRectF& rect, const QPixmap& pixmap,
     322    const QPointF& subRect)
     323{
     324    QwtNullPaintDevice* device = nullDevice();
    317325    if ( device == NULL )
    318326        return;
    … …  
    328336
    329337void QwtNullPaintDevice::PaintEngine::drawImage(
    330     const QRectF &rect, const QImage &image,
    331     const QRectF &subRect, Qt::ImageConversionFlags flags)
    332 {
    333     QwtNullPaintDevice *device = nullDevice();
     338    const QRectF& rect, const QImage& image,
     339    const QRectF& subRect, Qt::ImageConversionFlags flags)
     340{
     341    QwtNullPaintDevice* device = nullDevice();
    334342    if ( device == NULL )
    335343        return;
    … …  
    339347
    340348void QwtNullPaintDevice::PaintEngine::updateState(
    341     const QPaintEngineState &engineState)
    342 {
    343     QwtNullPaintDevice *device = nullDevice();
     349    const QPaintEngineState& engineState)
     350{
     351    QwtNullPaintDevice* device = nullDevice();
    344352    if ( device == NULL )
    345353        return;
    … …  
    348356}
    349357
    350 inline QwtNullPaintDevice *QwtNullPaintDevice::PaintEngine::nullDevice()
     358inline QwtNullPaintDevice* QwtNullPaintDevice::PaintEngine::nullDevice()
    351359{
    352360    if ( !isActive() )
    353361        return NULL;
    354362
    355     return static_cast<QwtNullPaintDevice *>( paintDevice() );
     363    return static_cast< QwtNullPaintDevice* >( paintDevice() );
    356364}
    357365
    358366//! Constructor
    359367QwtNullPaintDevice::QwtNullPaintDevice():
    360     d_engine( NULL )
    361 {
    362     d_data = new PrivateData;
     368    m_engine( NULL )
     369{
     370    m_data = new PrivateData;
    363371}
    364372
    … …  
    366374QwtNullPaintDevice::~QwtNullPaintDevice()
    367375{
    368     delete d_engine;
    369     delete d_data;
     376    delete m_engine;
     377    delete m_data;
    370378}
    371379
    … …  
    378386void QwtNullPaintDevice::setMode( Mode mode )
    379387{
    380     d_data->mode = mode;
     388    m_data->mode = mode;
    381389}
    382390
    … …  
    384392    \return Render mode
    385393    \sa setMode()
    386 */
     394 */
    387395QwtNullPaintDevice::Mode QwtNullPaintDevice::mode() const
    388396{
    389     return d_data->mode;
     397    return m_data->mode;
    390398}
    391399
    392400//! See QPaintDevice::paintEngine()
    393 QPaintEngine *QwtNullPaintDevice::paintEngine() const
    394 {
    395     if ( d_engine == NULL )
    396     {
    397         QwtNullPaintDevice *that =
    398             const_cast< QwtNullPaintDevice * >( this );
    399 
    400         that->d_engine = new PaintEngine();
    401     }
    402 
    403     return d_engine;
     401QPaintEngine* QwtNullPaintDevice::paintEngine() const
     402{
     403    if ( m_engine == NULL )
     404    {
     405        QwtNullPaintDevice* that =
     406            const_cast< QwtNullPaintDevice* >( this );
     407
     408        that->m_engine = new PaintEngine();
     409    }
     410
     411    return m_engine;
    404412}
    405413
    … …  
    411419
    412420    \sa sizeMetrics()
    413 */
     421 */
    414422int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const
    415423{
    … …  
    456464            break;
    457465        }
     466#if QT_VERSION >= 0x050100
     467        case PdmDevicePixelRatio:
     468        {
     469            value = 1.0;
     470            break;
     471        }
     472#endif
    458473        default:
    459             value = 0;
    460     }
     474        {
     475            value = QPaintDevice::metric( deviceMetric );
     476        }
     477    }
     478
    461479    return value;
    462 
    463480}
    464481
    465482//! See QPaintEngine::drawRects()
    466483void QwtNullPaintDevice::drawRects(
    467     const QRect *rects, int rectCount)
     484    const QRect* rects, int rectCount)
    468485{
    469486    Q_UNUSED(rects);
    … …  
    473490//! See QPaintEngine::drawRects()
    474491void QwtNullPaintDevice::drawRects(
    475     const QRectF *rects, int rectCount)
     492    const QRectF* rects, int rectCount)
    476493{
    477494    Q_UNUSED(rects);
    … …  
    481498//! See QPaintEngine::drawLines()
    482499void QwtNullPaintDevice::drawLines(
    483     const QLine *lines, int lineCount)
     500    const QLine* lines, int lineCount)
    484501{
    485502    Q_UNUSED(lines);
    … …  
    489506//! See QPaintEngine::drawLines()
    490507void QwtNullPaintDevice::drawLines(
    491     const QLineF *lines, int lineCount)
     508    const QLineF* lines, int lineCount)
    492509{
    493510    Q_UNUSED(lines);
    … …  
    496513
    497514//! See QPaintEngine::drawEllipse()
    498 void QwtNullPaintDevice::drawEllipse( const QRectF &rect )
     515void QwtNullPaintDevice::drawEllipse( const QRectF& rect )
    499516{
    500517    Q_UNUSED(rect);
    … …  
    502519
    503520//! See QPaintEngine::drawEllipse()
    504 void QwtNullPaintDevice::drawEllipse( const QRect &rect )
     521void QwtNullPaintDevice::drawEllipse( const QRect& rect )
    505522{
    506523    Q_UNUSED(rect);
    … …  
    508525
    509526//! See QPaintEngine::drawPath()
    510 void QwtNullPaintDevice::drawPath( const QPainterPath &path )
     527void QwtNullPaintDevice::drawPath( const QPainterPath& path )
    511528{
    512529    Q_UNUSED(path);
    … …  
    515532//! See QPaintEngine::drawPoints()
    516533void QwtNullPaintDevice::drawPoints(
    517     const QPointF *points, int pointCount)
     534    const QPointF* points, int pointCount)
    518535{
    519536    Q_UNUSED(points);
    … …  
    523540//! See QPaintEngine::drawPoints()
    524541void QwtNullPaintDevice::drawPoints(
    525     const QPoint *points, int pointCount)
     542    const QPoint* points, int pointCount)
    526543{
    527544    Q_UNUSED(points);
    … …  
    531548//! See QPaintEngine::drawPolygon()
    532549void QwtNullPaintDevice::drawPolygon(
    533     const QPointF *points, int pointCount,
     550    const QPointF* points, int pointCount,
    534551    QPaintEngine::PolygonDrawMode mode)
    535552{
    … …  
    541558//! See QPaintEngine::drawPolygon()
    542559void QwtNullPaintDevice::drawPolygon(
    543     const QPoint *points, int pointCount,
     560    const QPoint* points, int pointCount,
    544561    QPaintEngine::PolygonDrawMode mode)
    545562{
    … …  
    550567
    551568//! See QPaintEngine::drawPixmap()
    552 void QwtNullPaintDevice::drawPixmap( const QRectF &rect,
    553     const QPixmap &pm, const QRectF &subRect )
     569void QwtNullPaintDevice::drawPixmap( const QRectF& rect,
     570    const QPixmap& pm, const QRectF& subRect )
    554571{
    555572    Q_UNUSED(rect);
    … …  
    560577//! See QPaintEngine::drawTextItem()
    561578void QwtNullPaintDevice::drawTextItem(
    562     const QPointF &pos, const QTextItem &textItem)
     579    const QPointF& pos, const QTextItem& textItem)
    563580{
    564581    Q_UNUSED(pos);
    … …  
    568585//! See QPaintEngine::drawTiledPixmap()
    569586void QwtNullPaintDevice::drawTiledPixmap(
    570     const QRectF &rect, const QPixmap &pixmap,
    571     const QPointF &subRect)
     587    const QRectF& rect, const QPixmap& pixmap,
     588    const QPointF& subRect)
    572589{
    573590    Q_UNUSED(rect);
    … …  
    578595//! See QPaintEngine::drawImage()
    579596void QwtNullPaintDevice::drawImage(
    580     const QRectF &rect, const QImage &image,
    581     const QRectF &subRect, Qt::ImageConversionFlags flags)
     597    const QRectF& rect, const QImage& image,
     598    const QRectF& subRect, Qt::ImageConversionFlags flags)
    582599{
    583600    Q_UNUSED(rect);
    … …  
    589606//! See QPaintEngine::updateState()
    590607void QwtNullPaintDevice::updateState(
    591     const QPaintEngineState &state )
     608    const QPaintEngineState& state )
    592609{
    593610    Q_UNUSED(state);
  • trunk/BNC/qwt/qwt_null_paintdevice.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_NULL_PAINT_DEVICE_H
    11 #define QWT_NULL_PAINT_DEVICE_H 1
     11#define QWT_NULL_PAINT_DEVICE_H
    1212
    1313#include "qwt_global.h"
     14
    1415#include <qpaintdevice.h>
    1516#include <qpaintengine.h>
    1617
    1718/*!
    18   \brief A null paint device doing nothing
     19   \brief A null paint device doing nothing
    1920
    20   Sometimes important layout/rendering geometries are not
    21   available or changeable from the public Qt class interface.
    22   ( f.e hidden in the style implementation ).
     21   Sometimes important layout/rendering geometries are not
     22   available or changeable from the public Qt class interface.
     23   ( f.e hidden in the style implementation ).
    2324
    24   QwtNullPaintDevice can be used to manipulate or filter out
    25   this information by analyzing the stream of paint primitives.
     25   QwtNullPaintDevice can be used to manipulate or filter out
     26   this information by analyzing the stream of paint primitives.
    2627
    27   F.e. QwtNullPaintDevice is used by QwtPlotCanvas to identify
    28   styled backgrounds with rounded corners.
    29 */
     28   F.e. QwtNullPaintDevice is used by QwtPlotCanvas to identify
     29   styled backgrounds with rounded corners.
     30 */
    3031
    31 class QWT_EXPORT QwtNullPaintDevice: public QPaintDevice
     32class QWT_EXPORT QwtNullPaintDevice : public QPaintDevice
    3233{
    33 public:
     34  public:
    3435    /*!
    35       \brief Render mode
     36       \brief Render mode
    3637
    37       \sa setMode(), mode()
     38       \sa setMode(), mode()
    3839     */
    3940    enum Mode
    … …  
    7576    Mode mode() const;
    7677
    77     virtual QPaintEngine *paintEngine() const;
     78    virtual QPaintEngine* paintEngine() const QWT_OVERRIDE;
    7879
    79     virtual int metric( PaintDeviceMetric ) const;
     80    virtual int metric( PaintDeviceMetric ) const QWT_OVERRIDE;
    8081
    81     virtual void drawRects(const QRect *, int );
    82     virtual void drawRects(const QRectF *, int );
     82    virtual void drawRects(const QRect*, int );
     83    virtual void drawRects(const QRectF*, int );
    8384
    84     virtual void drawLines(const QLine *, int );
    85     virtual void drawLines(const QLineF *, int );
     85    virtual void drawLines(const QLine*, int );
     86    virtual void drawLines(const QLineF*, int );
    8687
    87     virtual void drawEllipse(const QRectF &);
    88     virtual void drawEllipse(const QRect &);
     88    virtual void drawEllipse(const QRectF&);
     89    virtual void drawEllipse(const QRect&);
    8990
    90     virtual void drawPath(const QPainterPath &);
     91    virtual void drawPath(const QPainterPath&);
    9192
    92     virtual void drawPoints(const QPointF *, int );
    93     virtual void drawPoints(const QPoint *, int );
     93    virtual void drawPoints(const QPointF*, int );
     94    virtual void drawPoints(const QPoint*, int );
    9495
    95     virtual void drawPolygon(
    96         const QPointF *, int , QPaintEngine::PolygonDrawMode );
     96    virtual void drawPolygon( const QPointF*, int,
     97        QPaintEngine::PolygonDrawMode );
    9798
    98     virtual void drawPolygon(
    99         const QPoint *, int , QPaintEngine::PolygonDrawMode );
     99    virtual void drawPolygon( const QPoint*, int,
     100        QPaintEngine::PolygonDrawMode );
    100101
    101     virtual void drawPixmap(const QRectF &,
    102         const QPixmap &, const QRectF &);
     102    virtual void drawPixmap(const QRectF&,
     103        const QPixmap&, const QRectF&);
    103104
    104     virtual void drawTextItem(const QPointF &, const QTextItem &);
     105    virtual void drawTextItem(const QPointF&, const QTextItem&);
    105106
    106     virtual void drawTiledPixmap(const QRectF &,
    107         const QPixmap &, const QPointF & );
     107    virtual void drawTiledPixmap(const QRectF&,
     108        const QPixmap&, const QPointF& );
    108109
    109     virtual void drawImage(const QRectF &,
    110         const QImage &, const QRectF &, Qt::ImageConversionFlags );
     110    virtual void drawImage(const QRectF&, const QImage&,
     111        const QRectF&, Qt::ImageConversionFlags );
    111112
    112     virtual void updateState( const QPaintEngineState & );
     113    virtual void updateState( const QPaintEngineState& );
    113114
    114 protected:
     115  protected:
    115116    //! \return Size needed to implement metric()
    116117    virtual QSize sizeMetrics() const = 0;
    117118
    118 private:
     119  private:
    119120    class PaintEngine;
    120     PaintEngine *d_engine;
     121    PaintEngine* m_engine;
    121122
    122123    class PrivateData;
    123     PrivateData *d_data;
     124    PrivateData* m_data;
    124125};
    125126
  • trunk/BNC/qwt/qwt_painter.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_color_map.h"
    1414#include "qwt_scale_map.h"
    15 #include <qwindowdefs.h>
     15
    1616#include <qwidget.h>
    1717#include <qframe.h>
    … …  
    2828#include <qpaintengine.h>
    2929#include <qapplication.h>
     30
     31#if QT_VERSION >= 0x060000
     32#include <qscreen.h>
     33#else
    3034#include <qdesktopwidget.h>
    31 
    32 #if QT_VERSION >= 0x050000
    33 #include <qwindow.h>
    3435#endif
    3536
    … …  
    4243#endif
    4344
    44 bool QwtPainter::d_polylineSplitting = true;
    45 bool QwtPainter::d_roundingAlignment = true;
     45#include <cstring>
     46
     47bool QwtPainter::m_polylineSplitting = true;
     48bool QwtPainter::m_roundingAlignment = true;
     49
     50static inline bool qwtIsRasterPaintEngineBuggy()
     51{
     52#if 0
     53    static int isBuggy = -1;
     54    if ( isBuggy < 0 )
     55    {
     56        // auto detect bug of the raster paint engine,
     57        // fixed with: https://codereview.qt-project.org/#/c/99456/
     58
     59        QImage image( 2, 3, QImage::Format_ARGB32 );
     60        image.fill( 0u );
     61
     62        QPolygonF p;
     63        p += QPointF(0, 1);
     64        p += QPointF(0, 0);
     65        p += QPointF(1, 0 );
     66        p += QPointF(1, 2 );
     67
     68        QPainter painter( &image );
     69        painter.drawPolyline( p );
     70        painter.end();
     71
     72        isBuggy = ( image.pixel( 1, 1 ) == 0 ) ? 1 : 0;
     73    }
     74
     75    return isBuggy == 1;
     76#endif
     77
     78#if QT_VERSION < 0x050000
     79    return true;
     80#elif QT_VERSION < 0x050100
     81    return false;
     82#elif QT_VERSION < 0x050400
     83    return true;
     84#else
     85    return false;
     86#endif
     87}
    4688
    4789static inline bool qwtIsClippingNeeded(
    48     const QPainter *painter, QRectF &clipRect )
     90    const QPainter* painter, QRectF& clipRect )
    4991{
    5092    bool doClipping = false;
    51     const QPaintEngine *pe = painter->paintEngine();
     93    const QPaintEngine* pe = painter->paintEngine();
    5294    if ( pe && pe->type() == QPaintEngine::SVG )
    5395    {
    … …  
    64106}
    65107
    66 template <class T>
    67 static inline void qwtDrawPolyline( QPainter *painter,
    68     const T *points, int pointCount, bool polylineSplitting )
     108template< class T >
     109static inline void qwtDrawPolyline( QPainter* painter,
     110    const T* points, int pointCount, bool polylineSplitting )
    69111{
    70112    bool doSplit = false;
    71113    if ( polylineSplitting )
    72114    {
    73         const QPaintEngine *pe = painter->paintEngine();
     115        const QPaintEngine* pe = painter->paintEngine();
    74116        if ( pe && pe->type() == QPaintEngine::Raster )
    75117        {
    76118            /*
    77                 The raster paint engine seems to use some algo with O(n*n).
    78                 ( Qt 4.3 is better than Qt 4.2, but remains unacceptable)
    79                 To work around this problem, we have to split the polygon into
    80                 smaller pieces.
     119               Raster paint engine is much faster when splitting
     120               the polygon, but of course we might see some issues where
     121               the pieces are joining
    81122             */
    82123            doSplit = true;
    … …  
    86127    if ( doSplit )
    87128    {
     129        QPen pen = painter->pen();
     130
    88131        const int splitSize = 6;
    89132
    90         for ( int i = 0; i < pointCount; i += splitSize )
    91         {
    92             const int n = qMin( splitSize + 1, pointCount - i );
    93             painter->drawPolyline( points + i, n );
     133        if ( pen.width() <= 1 && pen.isSolid() && qwtIsRasterPaintEngineBuggy()
     134            && !( painter->renderHints() & QPainter::Antialiasing ) )
     135        {
     136            int k = 0;
     137
     138            for ( int i = k + 1; i < pointCount; i++ )
     139            {
     140                const QPointF& p1 = points[i - 1];
     141                const QPointF& p2 = points[i];
     142
     143                const bool isBad = ( qAbs( p2.y() - p1.y() ) <= 1 )
     144                    && qAbs( p2.x() - p1.x() ) <= 1;
     145
     146                if ( isBad || ( i - k >= splitSize ) )
     147                {
     148                    painter->drawPolyline( points + k, i - k + 1 );
     149                    k = i;
     150                }
     151            }
     152
     153            painter->drawPolyline( points + k, pointCount - k );
     154        }
     155        else
     156        {
     157            for ( int i = 0; i < pointCount; i += splitSize )
     158            {
     159                const int n = qMin( splitSize + 1, pointCount - i );
     160                painter->drawPolyline( points + i, n );
     161            }
    94162        }
    95163    }
    … …  
    105173    if ( !screenResolution.isValid() )
    106174    {
    107         QDesktopWidget *desktop = QApplication::desktop();
     175        /*
     176            We might have screens with different resolutions. TODO ...
     177         */
     178#if QT_VERSION >= 0x060000
     179        QScreen* screen = QGuiApplication::primaryScreen();
     180        if ( screen )
     181        {
     182            screenResolution.setWidth( screen->logicalDotsPerInchX() );
     183            screenResolution.setHeight( screen->logicalDotsPerInchY() );
     184        }
     185#else
     186        QDesktopWidget* desktop = QApplication::desktop();
    108187        if ( desktop )
    109188        {
    … …  
    111190            screenResolution.setHeight( desktop->logicalDpiY() );
    112191        }
     192#endif
    113193    }
    114194
    … …  
    116196}
    117197
    118 static inline void qwtUnscaleFont( QPainter *painter )
     198static inline void qwtUnscaleFont( QPainter* painter )
    119199{
    120200    if ( painter->font().pixelSize() >= 0 )
    … …  
    123203    const QSize screenResolution = qwtScreenResolution();
    124204
    125     const QPaintDevice *pd = painter->device();
     205    const QPaintDevice* pd = painter->device();
    126206    if ( pd->logicalDpiX() != screenResolution.width() ||
    127207        pd->logicalDpiY() != screenResolution.height() )
    128208    {
    129         QFont pixelFont( painter->font(), QApplication::desktop() );
     209        QFont pixelFont = QwtPainter::scaledFont( painter->font() );
    130210        pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() );
    131211
    … …  
    135215
    136216/*!
    137   Check is the application is running with the X11 graphics system
    138   that has some special capabilities that can be used for incremental
    139   painting to a widget.
    140 
    141   \return True, when the graphics system is X11
    142 */
     217   Check is the application is running with the X11 graphics system
     218   that has some special capabilities that can be used for incremental
     219   painting to a widget.
     220
     221   \return True, when the graphics system is X11
     222 */
    143223bool QwtPainter::isX11GraphicsSystem()
    144224{
    … …  
    162242
    163243/*!
    164   Check if the painter is using a paint engine, that aligns
    165   coordinates to integers. Today these are all paint engines
    166   beside QPaintEngine::Pdf and QPaintEngine::SVG.
    167 
    168   If we have an integer based paint engine it is also
    169   checked if the painter has a transformation matrix,
    170   that rotates or scales.
    171 
    172   \param  painter Painter
    173   \return true, when the painter is aligning
    174 
    175   \sa setRoundingAlignment()
    176 */
    177 bool QwtPainter::isAligning( QPainter *painter )
     244   Check if the painter is using a paint engine, that aligns
     245   coordinates to integers. Today these are all paint engines
     246   beside QPaintEngine::Pdf and QPaintEngine::SVG.
     247
     248   If we have an integer based paint engine it is also
     249   checked if the painter has a transformation matrix,
     250   that rotates or scales.
     251
     252   \param  painter Painter
     253   \return true, when the painter is aligning
     254
     255   \sa setRoundingAlignment()
     256 */
     257bool QwtPainter::isAligning( const QPainter* painter )
    178258{
    179259    if ( painter && painter->isActive() )
    180260    {
    181         switch ( painter->paintEngine()->type() )
     261        const QPaintEngine::Type type =
     262            painter->paintEngine()->type();
     263
     264        if ( type >= QPaintEngine::User )
     265        {
     266            // we have no idea - better don't align
     267            return false;
     268        }
     269
     270        switch ( type )
    182271        {
    183272            case QPaintEngine::Pdf:
    184273            case QPaintEngine::SVG:
     274#if 0
     275            case QPaintEngine::MacPrinter:
     276#endif
    185277                return false;
    186278
    187             default:;
    188         }
    189 
    190         const QTransform &tr = painter->transform();
     279            default:
     280                break;
     281        }
     282
     283        const QTransform& tr = painter->transform();
    191284        if ( tr.isRotating() || tr.isScaling() )
    192285        {
    … …  
    200293
    201294/*!
    202   Enable whether coordinates should be rounded, before they are painted
    203   to a paint engine that floors to integer values. For other paint engines
    204   ( PDF, SVG ) this flag has no effect.
    205   QwtPainter stores this flag only, the rounding itself is done in
    206   the painting code ( f.e the plot items ).
    207 
    208   The default setting is true.
    209 
    210   \sa roundingAlignment(), isAligning()
    211 */
     295   Enable whether coordinates should be rounded, before they are painted
     296   to a paint engine that floors to integer values. For other paint engines
     297   ( PDF, SVG ) this flag has no effect.
     298   QwtPainter stores this flag only, the rounding itself is done in
     299   the painting code ( f.e the plot items ).
     300
     301   The default setting is true.
     302
     303   \sa roundingAlignment(), isAligning()
     304 */
    212305void QwtPainter::setRoundingAlignment( bool enable )
    213306{
    214     d_roundingAlignment = enable;
    215 }
    216 
    217 /*!
    218   \brief En/Disable line splitting for the raster paint engine
    219 
    220   In some Qt versions the raster paint engine paints polylines of many points
    221   much faster when they are split in smaller chunks: f.e all supported Qt versions
    222   >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.
    223 
    224   Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... )
    225   for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked
    226   around in this mode.
    227 
    228   The default setting is true.
    229 
    230   \sa polylineSplitting()
    231 */
     307    m_roundingAlignment = enable;
     308}
     309
     310/*!
     311   \brief En/Disable line splitting for the raster paint engine
     312
     313   In some Qt versions the raster paint engine paints polylines of many points
     314   much faster when they are split in smaller chunks: f.e all supported Qt versions
     315   >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.
     316
     317   Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... )
     318   for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked
     319   around in this mode.
     320
     321   The default setting is true.
     322
     323   \sa polylineSplitting()
     324 */
    232325void QwtPainter::setPolylineSplitting( bool enable )
    233326{
    234     d_polylineSplitting = enable;
     327    m_polylineSplitting = enable;
    235328}
    236329
    237330//! Wrapper for QPainter::drawPath()
    238 void QwtPainter::drawPath( QPainter *painter, const QPainterPath &path )
     331void QwtPainter::drawPath( QPainter* painter, const QPainterPath& path )
    239332{
    240333    painter->drawPath( path );
    … …  
    242335
    243336//! Wrapper for QPainter::drawRect()
    244 void QwtPainter::drawRect( QPainter *painter, double x, double y, double w, double h )
     337void QwtPainter::drawRect( QPainter* painter, qreal x, qreal y, qreal w, qreal h )
    245338{
    246339    drawRect( painter, QRectF( x, y, w, h ) );
    … …  
    248341
    249342//! Wrapper for QPainter::drawRect()
    250 void QwtPainter::drawRect( QPainter *painter, const QRectF &rect )
     343void QwtPainter::drawRect( QPainter* painter, const QRectF& rect )
    251344{
    252345    const QRectF r = rect;
    … …  
    277370
    278371//! Wrapper for QPainter::fillRect()
    279 void QwtPainter::fillRect( QPainter *painter,
    280     const QRectF &rect, const QBrush &brush )
     372void QwtPainter::fillRect( QPainter* painter,
     373    const QRectF& rect, const QBrush& brush )
    281374{
    282375    if ( !rect.isValid() )
    … …  
    287380
    288381    /*
    289       Performance of Qt4 is horrible for a non trivial brush. Without
    290       clipping expect minutes or hours for repainting large rectangles
    291       (might result from zooming)
    292     */
     382       Performance of Qt4 is horrible for a non trivial brush. Without
     383       clipping expect minutes or hours for repainting large rectangles
     384       (might result from zooming)
     385     */
    293386
    294387    if ( deviceClipping )
    … …  
    309402
    310403//! Wrapper for QPainter::drawPie()
    311 void QwtPainter::drawPie( QPainter *painter, const QRectF &rect,
     404void QwtPainter::drawPie( QPainter* painter, const QRectF& rect,
    312405    int a, int alen )
    313406{
    … …  
    321414
    322415//! Wrapper for QPainter::drawEllipse()
    323 void QwtPainter::drawEllipse( QPainter *painter, const QRectF &rect )
     416void QwtPainter::drawEllipse( QPainter* painter, const QRectF& rect )
    324417{
    325418    QRectF clipRect;
    … …  
    333426
    334427//! Wrapper for QPainter::drawText()
    335 void QwtPainter::drawText( QPainter *painter, double x, double y,
    336         const QString &text )
     428void QwtPainter::drawText( QPainter* painter,
     429    qreal x, qreal y, const QString& text )
    337430{
    338431    drawText( painter, QPointF( x, y ), text );
    … …  
    340433
    341434//! Wrapper for QPainter::drawText()
    342 void QwtPainter::drawText( QPainter *painter, const QPointF &pos,
    343         const QString &text )
     435void QwtPainter::drawText( QPainter* painter, const QPointF& pos,
     436    const QString& text )
    344437{
    345438    QRectF clipRect;
    … …  
    357450
    358451//! Wrapper for QPainter::drawText()
    359 void QwtPainter::drawText( QPainter *painter,
    360     double x, double y, double w, double h,
    361     int flags, const QString &text )
     452void QwtPainter::drawText( QPainter* painter,
     453    qreal x, qreal y, qreal w, qreal h,
     454    int flags, const QString& text )
    362455{
    363456    drawText( painter, QRectF( x, y, w, h ), flags, text );
    … …  
    365458
    366459//! Wrapper for QPainter::drawText()
    367 void QwtPainter::drawText( QPainter *painter, const QRectF &rect,
    368         int flags, const QString &text )
     460void QwtPainter::drawText( QPainter* painter, const QRectF& rect,
     461    int flags, const QString& text )
    369462{
    370463    painter->save();
    … …  
    377470
    378471/*!
    379   Draw a text document into a rectangle
    380 
    381   \param painter Painter
    382   \param rect Traget rectangle
    383   \param flags Alignments/Text flags, see QPainter::drawText()
    384   \param text Text document
    385 */
    386 void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
    387     int flags, const QTextDocument &text )
    388 {
    389     QTextDocument *txt = text.clone();
     472   Draw a text document into a rectangle
     473
     474   \param painter Painter
     475   \param rect Target rectangle
     476   \param flags Alignments/Text flags, see QPainter::drawText()
     477   \param text Text document
     478 */
     479void QwtPainter::drawSimpleRichText( QPainter* painter, const QRectF& rect,
     480    int flags, const QTextDocument& text )
     481{
     482    QTextDocument* txt = text.clone();
    390483
    391484    painter->save();
    … …  
    397490        const QSize res = qwtScreenResolution();
    398491
    399         const QPaintDevice *pd = painter->device();
     492        const QPaintDevice* pd = painter->device();
    400493        if ( pd->logicalDpiX() != res.width() ||
    401494            pd->logicalDpiY() != res.height() )
    402495        {
    403496            QTransform transform;
    404             transform.scale( res.width() / double( pd->logicalDpiX() ),
    405                 res.height() / double( pd->logicalDpiY() ));
     497            transform.scale( res.width() / qreal( pd->logicalDpiX() ),
     498                res.height() / qreal( pd->logicalDpiY() ) );
    406499
    407500            painter->setWorldTransform( transform, true );
    … …  
    415508    QAbstractTextDocumentLayout* layout = txt->documentLayout();
    416509
    417     const double height = layout->documentSize().height();
    418     double y = unscaledRect.y();
     510    const qreal height = layout->documentSize().height();
     511    qreal y = unscaledRect.y();
    419512    if ( flags & Qt::AlignBottom )
    420513        y += ( unscaledRect.height() - height );
    … …  
    436529
    437530//! Wrapper for QPainter::drawLine()
    438 void QwtPainter::drawLine( QPainter *painter,
    439     const QPointF &p1, const QPointF &p2 )
     531void QwtPainter::drawLine( QPainter* painter,
     532    const QPointF& p1, const QPointF& p2 )
    440533{
    441534    QRectF clipRect;
    … …  
    456549
    457550//! Wrapper for QPainter::drawPolygon()
    458 void QwtPainter::drawPolygon( QPainter *painter, const QPolygonF &polygon )
     551void QwtPainter::drawPolygon( QPainter* painter, const QPolygonF& polygon )
    459552{
    460553    QRectF clipRect;
    461554    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    462555
    463     QPolygonF cpa = polygon;
    464556    if ( deviceClipping )
    465         cpa = QwtClipper::clipPolygonF( clipRect, polygon, true );
    466 
    467     painter->drawPolygon( cpa );
     557    {
     558        painter->drawPolygon(
     559            QwtClipper::clippedPolygonF( clipRect, polygon, true ) );
     560    }
     561    else
     562    {
     563        painter->drawPolygon( polygon );
     564    }
    468565}
    469566
    470567//! Wrapper for QPainter::drawPolyline()
    471 void QwtPainter::drawPolyline( QPainter *painter, const QPolygonF &polygon )
     568void QwtPainter::drawPolyline( QPainter* painter, const QPolygonF& polygon )
    472569{
    473570    QRectF clipRect;
    474571    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    475572
    476     QPolygonF cpa = polygon;
    477573    if ( deviceClipping )
    478         cpa = QwtClipper::clipPolygonF( clipRect, cpa );
    479 
    480     qwtDrawPolyline<QPointF>( painter,
    481         cpa.constData(), cpa.size(), d_polylineSplitting );
     574    {
     575        const QPolygonF cpa = QwtClipper::clippedPolygonF( clipRect, polygon );
     576
     577        qwtDrawPolyline< QPointF >( painter,
     578            cpa.constData(), cpa.size(), m_polylineSplitting );
     579    }
     580    else
     581    {
     582        qwtDrawPolyline< QPointF >( painter,
     583            polygon.constData(), polygon.size(), m_polylineSplitting );
     584    }
    482585}
    483586
    484587//! Wrapper for QPainter::drawPolyline()
    485 void QwtPainter::drawPolyline( QPainter *painter,
    486     const QPointF *points, int pointCount )
     588void QwtPainter::drawPolyline( QPainter* painter,
     589    const QPointF* points, int pointCount )
    487590{
    488591    QRectF clipRect;
    … …  
    492595    {
    493596        QPolygonF polygon( pointCount );
    494         ::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
    495 
    496         polygon = QwtClipper::clipPolygonF( clipRect, polygon );
    497         qwtDrawPolyline<QPointF>( painter,
    498             polygon.constData(), polygon.size(), d_polylineSplitting );
     597        std::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
     598
     599        QwtClipper::clipPolygonF( clipRect, polygon );
     600        qwtDrawPolyline< QPointF >( painter,
     601            polygon.constData(), polygon.size(), m_polylineSplitting );
    499602    }
    500603    else
    501604    {
    502         qwtDrawPolyline<QPointF>( painter, points, pointCount, d_polylineSplitting );
     605        qwtDrawPolyline< QPointF >( painter, points, pointCount, m_polylineSplitting );
    503606    }
    504607}
    505608
    506609//! Wrapper for QPainter::drawPolygon()
    507 void QwtPainter::drawPolygon( QPainter *painter, const QPolygon &polygon )
     610void QwtPainter::drawPolygon( QPainter* painter, const QPolygon& polygon )
    508611{
    509612    QRectF clipRect;
    510613    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    511614
    512     QPolygon cpa = polygon;
    513615    if ( deviceClipping )
    514         cpa = QwtClipper::clipPolygon( clipRect, polygon, true );
    515 
    516     painter->drawPolygon( cpa );
     616    {
     617        painter->drawPolygon(
     618            QwtClipper::clippedPolygon( clipRect, polygon, true ) );
     619    }
     620    else
     621    {
     622        painter->drawPolygon( polygon );
     623    }
    517624}
    518625
    519626//! Wrapper for QPainter::drawPolyline()
    520 void QwtPainter::drawPolyline( QPainter *painter, const QPolygon &polygon )
     627void QwtPainter::drawPolyline( QPainter* painter, const QPolygon& polygon )
    521628{
    522629    QRectF clipRect;
    523630    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    524631
    525     QPolygon cpa = polygon;
    526632    if ( deviceClipping )
    527         cpa = QwtClipper::clipPolygon( clipRect, cpa );
    528 
    529     qwtDrawPolyline<QPoint>( painter,
    530         cpa.constData(), cpa.size(), d_polylineSplitting );
     633    {
     634        const QPolygon cpa = QwtClipper::clippedPolygon( clipRect, polygon );
     635
     636        qwtDrawPolyline< QPoint >( painter,
     637            cpa.constData(), cpa.size(), m_polylineSplitting );
     638    }
     639    else
     640    {
     641        qwtDrawPolyline< QPoint >( painter,
     642            polygon.constData(), polygon.size(), m_polylineSplitting );
     643    }
    531644}
    532645
    533646//! Wrapper for QPainter::drawPolyline()
    534 void QwtPainter::drawPolyline( QPainter *painter,
    535     const QPoint *points, int pointCount )
     647void QwtPainter::drawPolyline( QPainter* painter,
     648    const QPoint* points, int pointCount )
    536649{
    537650    QRectF clipRect;
    … …  
    541654    {
    542655        QPolygon polygon( pointCount );
    543         ::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
    544 
    545         polygon = QwtClipper::clipPolygon( clipRect, polygon );
    546         qwtDrawPolyline<QPoint>( painter,
    547             polygon.constData(), polygon.size(), d_polylineSplitting );
     656        std::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
     657
     658        QwtClipper::clipPolygon( clipRect, polygon );
     659        qwtDrawPolyline< QPoint >( painter,
     660            polygon.constData(), polygon.size(), m_polylineSplitting );
    548661    }
    549662    else
    550663    {
    551         qwtDrawPolyline<QPoint>( painter, points, pointCount, d_polylineSplitting );
     664        qwtDrawPolyline< QPoint >( painter, points, pointCount, m_polylineSplitting );
    552665    }
    553666}
    554667
    555668//! Wrapper for QPainter::drawPoint()
    556 void QwtPainter::drawPoint( QPainter *painter, const QPointF &pos )
     669void QwtPainter::drawPoint( QPainter* painter, const QPointF& pos )
    557670{
    558671    QRectF clipRect;
    … …  
    566679
    567680//! Wrapper for QPainter::drawPoint()
    568 void QwtPainter::drawPoint( QPainter *painter, const QPoint &pos )
     681void QwtPainter::drawPoint( QPainter* painter, const QPoint& pos )
    569682{
    570683    QRectF clipRect;
    … …  
    573686    if ( deviceClipping )
    574687    {
    575         const int minX = qCeil( clipRect.left() );
    576         const int maxX = qFloor( clipRect.right() );
    577         const int minY = qCeil( clipRect.top() );
    578         const int maxY = qFloor( clipRect.bottom() );
     688        const int minX = qwtCeil( clipRect.left() );
     689        const int maxX = qwtFloor( clipRect.right() );
     690        const int minY = qwtCeil( clipRect.top() );
     691        const int maxY = qwtFloor( clipRect.bottom() );
    579692
    580693        if ( pos.x() < minX || pos.x() > maxX
    … …  
    589702
    590703//! Wrapper for QPainter::drawPoints()
    591 void QwtPainter::drawPoints( QPainter *painter,
    592     const QPoint *points, int pointCount )
     704void QwtPainter::drawPoints( QPainter* painter,
     705    const QPoint* points, int pointCount )
    593706{
    594707    QRectF clipRect;
    … …  
    597710    if ( deviceClipping )
    598711    {
    599         const int minX = qCeil( clipRect.left() );
    600         const int maxX = qFloor( clipRect.right() );
    601         const int minY = qCeil( clipRect.top() );
    602         const int maxY = qFloor( clipRect.bottom() );
     712        const int minX = qwtCeil( clipRect.left() );
     713        const int maxX = qwtFloor( clipRect.right() );
     714        const int minY = qwtCeil( clipRect.top() );
     715        const int maxY = qwtFloor( clipRect.bottom() );
    603716
    604717        const QRect r( minX, minY, maxX - minX, maxY - minY );
    605718
    606719        QPolygon clippedPolygon( pointCount );
    607         QPoint *clippedData = clippedPolygon.data();
     720        QPoint* clippedData = clippedPolygon.data();
    608721
    609722        int numClippedPoints = 0;
    … …  
    622735
    623736//! Wrapper for QPainter::drawPoints()
    624 void QwtPainter::drawPoints( QPainter *painter,
    625     const QPointF *points, int pointCount )
     737void QwtPainter::drawPoints( QPainter* painter,
     738    const QPointF* points, int pointCount )
    626739{
    627740    QRectF clipRect;
    … …  
    631744    {
    632745        QPolygonF clippedPolygon( pointCount );
    633         QPointF *clippedData = clippedPolygon.data();
     746        QPointF* clippedData = clippedPolygon.data();
    634747
    635748        int numClippedPoints = 0;
    … …  
    648761
    649762//! Wrapper for QPainter::drawImage()
    650 void QwtPainter::drawImage( QPainter *painter,
    651     const QRectF &rect, const QImage &image )
     763void QwtPainter::drawImage( QPainter* painter,
     764    const QRectF& rect, const QImage& image )
    652765{
    653766    const QRect alignedRect = rect.toAlignedRect();
    … …  
    669782
    670783//! Wrapper for QPainter::drawPixmap()
    671 void QwtPainter::drawPixmap( QPainter *painter,
    672     const QRectF &rect, const QPixmap &pixmap )
     784void QwtPainter::drawPixmap( QPainter* painter,
     785    const QRectF& rect, const QPixmap& pixmap )
    673786{
    674787    const QRect alignedRect = rect.toAlignedRect();
    … …  
    690803
    691804//! Draw a focus rectangle on a widget using its style.
    692 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget )
     805void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget )
    693806{
    694807    drawFocusRect( painter, widget, widget->rect() );
    … …  
    696809
    697810//! Draw a focus rectangle on a widget using its style.
    698 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget,
    699     const QRect &rect )
     811void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget,
     812    const QRect& rect )
    700813{
    701814    QStyleOptionFocusRect opt;
    702     opt.init( widget );
     815    opt.initFrom( widget );
    703816    opt.rect = rect;
    704817    opt.state |= QStyle::State_HasFocus;
    … …  
    710823
    711824/*!
    712   Draw a round frame
    713 
    714   \param painter Painter
    715   \param rect Frame rectangle
    716   \param palette QPalette::WindowText is used for plain borders
     825   Draw a round frame
     826
     827   \param painter Painter
     828   \param rect Frame rectangle
     829   \param palette QPalette::WindowText is used for plain borders
    717830                 QPalette::Dark and QPalette::Light for raised
    718831                 or sunken borders
    719   \param lineWidth Line width
    720   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
    721 */
    722 void QwtPainter::drawRoundFrame( QPainter *painter,
    723     const QRectF &rect, const QPalette &palette,
     832   \param lineWidth Line width
     833   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
     834 */
     835void QwtPainter::drawRoundFrame( QPainter* painter,
     836    const QRectF& rect, const QPalette& palette,
    724837    int lineWidth, int frameStyle )
    725838{
    … …  
    732845
    733846    Style style = Plain;
    734     if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
     847    if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
    735848        style = Sunken;
    736     else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
     849    else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
    737850        style = Raised;
    738851
    739     const double lw2 = 0.5 * lineWidth;
     852    const qreal lw2 = 0.5 * lineWidth;
    740853    QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
    741854
    … …  
    776889
    777890/*!
    778   Draw a rectangular frame
    779 
    780   \param painter Painter
    781   \param rect Frame rectangle
    782   \param palette Palette
    783   \param foregroundRole Foreground role used for QFrame::Plain
    784   \param frameWidth Frame width
    785   \param midLineWidth Used for QFrame::Box
    786   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
    787 */
    788 void QwtPainter::drawFrame( QPainter *painter, const QRectF &rect,
    789     const QPalette &palette, QPalette::ColorRole foregroundRole,
     891   Draw a rectangular frame
     892
     893   \param painter Painter
     894   \param rect Frame rectangle
     895   \param palette Palette
     896   \param foregroundRole Foreground role used for QFrame::Plain
     897   \param frameWidth Frame width
     898   \param midLineWidth Used for QFrame::Box
     899   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
     900 */
     901void QwtPainter::drawFrame( QPainter* painter, const QRectF& rect,
     902    const QPalette& palette, QPalette::ColorRole foregroundRole,
    790903    int frameWidth, int midLineWidth, int frameStyle )
    791904{
    … …  
    882995            painter->drawPath( path5 );
    883996        }
    884 #if 0
    885         // qDrawWinPanel doesn't result in something nice
    886         // on a scalable document like PDF. Better draw a
    887         // Panel.
    888 
    889         else if ( shape == QFrame::WinPanel )
    890         {
    891             painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true );
    892             qDrawWinPanel ( painter, rect.toRect(), palette,
    893                 frameStyle & QFrame::Sunken );
    894         }
    895         else if ( shape == QFrame::StyledPanel )
    896         {
    897         }
    898 #endif
    899997        else
    900998        {
    … …  
    9421040
    9431041/*!
    944   Draw a rectangular frame with rounded borders
    945 
    946   \param painter Painter
    947   \param rect Frame rectangle
    948   \param xRadius x-radius of the ellipses defining the corners
    949   \param yRadius y-radius of the ellipses defining the corners
    950   \param palette QPalette::WindowText is used for plain borders
     1042   Draw a rectangular frame with rounded borders
     1043
     1044   \param painter Painter
     1045   \param rect Frame rectangle
     1046   \param xRadius x-radius of the ellipses defining the corners
     1047   \param yRadius y-radius of the ellipses defining the corners
     1048   \param palette QPalette::WindowText is used for plain borders
    9511049                 QPalette::Dark and QPalette::Light for raised
    9521050                 or sunken borders
    953   \param lineWidth Line width
    954   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
    955 */
    956 
    957 void QwtPainter::drawRoundedFrame( QPainter *painter,
    958     const QRectF &rect, double xRadius, double yRadius,
    959     const QPalette &palette, int lineWidth, int frameStyle )
     1051   \param lineWidth Line width
     1052   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
     1053 */
     1054
     1055void QwtPainter::drawRoundedFrame( QPainter* painter,
     1056    const QRectF& rect, qreal xRadius, qreal yRadius,
     1057    const QPalette& palette, int lineWidth, int frameStyle )
    9601058{
    9611059    painter->save();
    … …  
    9631061    painter->setBrush( Qt::NoBrush );
    9641062
    965     double lw2 = lineWidth * 0.5;
     1063    qreal lw2 = lineWidth * 0.5;
    9661064    QRectF innerRect = rect.adjusted( lw2, lw2, -lw2, -lw2 );
    9671065
    … …  
    9771075
    9781076    Style style = Plain;
    979     if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
     1077    if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
    9801078        style = Sunken;
    981     else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
     1079    else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
    9821080        style = Raised;
    9831081
    … …  
    9931091            pathList[ 2 * i ].moveTo(
    9941092                path.elementAt(j - 1).x, path.elementAt( j - 1 ).y
    995             );
     1093                );
    9961094
    9971095            pathList[ 2 * i ].cubicTo(
    … …  
    10021100            pathList[ 2 * i + 1 ].moveTo(
    10031101                path.elementAt(j + 2).x, path.elementAt(j + 2).y
    1004             );
     1102                );
    10051103            pathList[ 2 * i + 1 ].lineTo(
    10061104                path.elementAt(j + 3).x, path.elementAt(j + 3).y
    1007             );
     1105                );
    10081106        }
    10091107
    … …  
    10861184
    10871185/*!
    1088   Draw a color bar into a rectangle
    1089 
    1090   \param painter Painter
    1091   \param colorMap Color map
    1092   \param interval Value range
    1093   \param scaleMap Scale map
    1094   \param orientation Orientation
    1095   \param rect Traget rectangle
    1096 */
    1097 void QwtPainter::drawColorBar( QPainter *painter,
    1098         const QwtColorMap &colorMap, const QwtInterval &interval,
    1099         const QwtScaleMap &scaleMap, Qt::Orientation orientation,
    1100         const QRectF &rect )
    1101 {
    1102     QVector<QRgb> colorTable;
     1186   Draw a color bar into a rectangle
     1187
     1188   \param painter Painter
     1189   \param colorMap Color map
     1190   \param interval Value range
     1191   \param scaleMap Scale map
     1192   \param orientation Orientation
     1193   \param rect Target rectangle
     1194 */
     1195void QwtPainter::drawColorBar( QPainter* painter,
     1196    const QwtColorMap& colorMap, const QwtInterval& interval,
     1197    const QwtScaleMap& scaleMap, Qt::Orientation orientation,
     1198    const QRectF& rect )
     1199{
     1200    QVector< QRgb > colorTable;
    11031201    if ( colorMap.format() == QwtColorMap::Indexed )
    1104         colorTable = colorMap.colorTable( interval );
     1202        colorTable = colorMap.colorTable256();
    11051203
    11061204    QColor c;
    … …  
    11091207
    11101208    /*
    1111       We paint to a pixmap first to have something scalable for printing
    1112       ( f.e. in a Pdf document )
     1209       We paint to a pixmap first to have something scalable for printing
     1210       ( f.e. in a Pdf document )
    11131211     */
    11141212
    … …  
    11311229                c.setRgba( colorMap.rgb( interval, value ) );
    11321230            else
    1133                 c = colorTable[colorMap.colorIndex( interval, value )];
     1231                c = colorTable[colorMap.colorIndex( 256, interval, value )];
    11341232
    11351233            pmPainter.setPen( c );
    … …  
    11491247                c.setRgba( colorMap.rgb( interval, value ) );
    11501248            else
    1151                 c = colorTable[colorMap.colorIndex( interval, value )];
     1249                c = colorTable[colorMap.colorIndex( 256, interval, value )];
    11521250
    11531251            pmPainter.setPen( c );
    … …  
    11601258}
    11611259
    1162 static inline void qwtFillRect( const QWidget *widget, QPainter *painter,
    1163     const QRect &rect, const QBrush &brush)
     1260static inline void qwtFillRect( const QWidget* widget, QPainter* painter,
     1261    const QRect& rect, const QBrush& brush)
    11641262{
    11651263    if ( brush.style() == Qt::TexturePattern )
    … …  
    11681266
    11691267        painter->setClipRect( rect );
    1170         painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
     1268        painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft() );
    11711269
    11721270        painter->restore();
    … …  
    11891287
    11901288/*!
    1191   Fill a pixmap with the content of a widget
    1192 
    1193   In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy
    1194   for backgrounds with gradients. Thus fillPixmap() offers
    1195   an alternative implementation.
    1196 
    1197   \param widget Widget
    1198   \param pixmap Pixmap to be filled
    1199   \param offset Offset
    1200 
    1201   \sa QPixmap::fill()
    1202  */
    1203 void QwtPainter::fillPixmap( const QWidget *widget,
    1204     QPixmap &pixmap, const QPoint &offset )
     1289   Fill a pixmap with the content of a widget
     1290
     1291   In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy
     1292   for backgrounds with gradients. Thus fillPixmap() offers
     1293   an alternative implementation.
     1294
     1295   \param widget Widget
     1296   \param pixmap Pixmap to be filled
     1297   \param offset Offset
     1298
     1299   \sa QPixmap::fill()
     1300 */
     1301void QwtPainter::fillPixmap( const QWidget* widget,
     1302    QPixmap& pixmap, const QPoint& offset )
    12051303{
    12061304    const QRect rect( offset, pixmap.size() );
    … …  
    12331331
    12341332/*!
    1235   Fill rect with the background of a widget
    1236 
    1237   \param painter Painter
    1238   \param rect Rectangle to be filled
    1239   \param widget Widget
    1240 
    1241   \sa QStyle::PE_Widget, QWidget::backgroundRole()
    1242  */
    1243 void QwtPainter::drawBackgound( QPainter *painter,
    1244     const QRectF &rect, const QWidget *widget )
     1333   Fill rect with the background of a widget
     1334
     1335   \param painter Painter
     1336   \param rect Rectangle to be filled
     1337   \param widget Widget
     1338
     1339   \sa QStyle::PE_Widget, QWidget::backgroundRole()
     1340 */
     1341void QwtPainter::drawBackgound( QPainter* painter,
     1342    const QRectF& rect, const QWidget* widget )
    12451343{
    12461344    if ( widget->testAttribute( Qt::WA_StyledBackground ) )
    … …  
    12631361
    12641362/*!
    1265   \return A pixmap that can be used as backing store
    1266 
    1267   \param widget Widget, for which the backingstore is intended
    1268   \param size Size of the pixmap
    1269  */
    1270 QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size )
     1363   Distance appropriate for drawing a subsequent character after text.
     1364
     1365   \param fontMetrics Font metrics
     1366   \param text Text
     1367   \return horizontal advance in pixels
     1368 */
     1369int QwtPainter::horizontalAdvance(
     1370    const QFontMetrics& fontMetrics, const QString& text )
     1371{
     1372#if QT_VERSION >= 0x050b00
     1373    return fontMetrics.horizontalAdvance( text );
     1374#else
     1375    return fontMetrics.width( text );
     1376#endif
     1377
     1378}
     1379
     1380/*!
     1381   Distance appropriate for drawing a subsequent character after text.
     1382
     1383   \param fontMetrics Font metrics
     1384   \param text Text
     1385   \return horizontal advance in pixels
     1386 */
     1387qreal QwtPainter::horizontalAdvance(
     1388    const QFontMetricsF& fontMetrics, const QString& text )
     1389{
     1390#if QT_VERSION >= 0x050b00
     1391    return fontMetrics.horizontalAdvance( text );
     1392#else
     1393    return fontMetrics.width( text );
     1394#endif
     1395}
     1396
     1397/*!
     1398   Distance appropriate for drawing a subsequent character after ch.
     1399
     1400   \param fontMetrics Font metrics
     1401   \param ch Character
     1402   \return horizontal advance in pixels
     1403 */
     1404int QwtPainter::horizontalAdvance(
     1405    const QFontMetrics& fontMetrics, QChar ch )
     1406{
     1407#if QT_VERSION >= 0x050b00
     1408    return fontMetrics.horizontalAdvance( ch );
     1409#else
     1410    return fontMetrics.width( ch );
     1411#endif
     1412}
     1413
     1414/*!
     1415   Distance appropriate for drawing a subsequent character after ch.
     1416
     1417   \param fontMetrics Font metrics
     1418   \param ch Character
     1419   \return horizontal advance in pixels
     1420 */
     1421qreal QwtPainter::horizontalAdvance(
     1422    const QFontMetricsF& fontMetrics, QChar ch )
     1423{
     1424#if QT_VERSION >= 0x050b00
     1425    return fontMetrics.horizontalAdvance( ch );
     1426#else
     1427    return fontMetrics.width( ch );
     1428#endif
     1429}
     1430
     1431/*!
     1432   Adjust the DPI value of font according to the DPI value of the paint device
     1433
     1434   \param font Unscaled font
     1435   \param paintDevice Paint device providing a DPI value. If paintDevice == null
     1436                     the DPI value of the primary screen will be used
     1437
     1438   \return Font being adjusted to the DPI value of the paint device
     1439 */
     1440QFont QwtPainter::scaledFont( const QFont& font, const QPaintDevice* paintDevice )
     1441{
     1442    if ( paintDevice == NULL )
     1443    {
     1444#if QT_VERSION < 0x060000
     1445        paintDevice = QApplication::desktop();
     1446#else
     1447        class PaintDevice : public QPaintDevice
     1448        {
     1449            virtual QPaintEngine* paintEngine() const QWT_OVERRIDE
     1450            {
     1451                return NULL;
     1452            }
     1453
     1454            virtual int metric( PaintDeviceMetric metric ) const QWT_OVERRIDE
     1455            {
     1456                if ( metric == PdmDpiY )
     1457                {
     1458                    QScreen* screen = QGuiApplication::primaryScreen();
     1459                    if ( screen )
     1460                    {
     1461                        return screen->logicalDotsPerInchY();
     1462                    }
     1463                }
     1464
     1465                return QPaintDevice::metric( metric );
     1466            }
     1467        };
     1468
     1469        static PaintDevice dummyPaintDevice;
     1470        paintDevice = &dummyPaintDevice;
     1471#endif
     1472    }
     1473
     1474    return QFont( font, const_cast< QPaintDevice* >( paintDevice ) );
     1475}
     1476
     1477/*!
     1478   \return Pixel ratio for a paint device
     1479   \param paintDevice Paint device
     1480 */
     1481qreal QwtPainter::devicePixelRatio( const QPaintDevice* paintDevice )
     1482{
     1483    qreal pixelRatio = 0.0;
     1484
     1485#if QT_VERSION >= 0x050100
     1486    if ( paintDevice )
     1487    {
     1488#if QT_VERSION >= 0x050600
     1489        pixelRatio = paintDevice->devicePixelRatioF();
     1490#else
     1491        pixelRatio = paintDevice->devicePixelRatio();
     1492#endif
     1493    }
     1494#else
     1495    Q_UNUSED( paintDevice )
     1496#endif
     1497
     1498#if QT_VERSION >= 0x050000
     1499    if ( pixelRatio == 0.0 && qApp )
     1500        pixelRatio = qApp->devicePixelRatio();
     1501#endif
     1502
     1503    if ( pixelRatio == 0.0 )
     1504        pixelRatio = 1.0;
     1505
     1506    return pixelRatio;
     1507}
     1508
     1509/*!
     1510   \return A pixmap that can be used as backing store
     1511
     1512   \param widget Widget, for which the backingstore is intended
     1513   \param size Size of the pixmap
     1514 */
     1515QPixmap QwtPainter::backingStore( QWidget* widget, const QSize& size )
    12711516{
    12721517    QPixmap pm;
    12731518
    1274 #define QWT_HIGH_DPI 1
    1275 
    1276 #if QT_VERSION >= 0x050000 && QWT_HIGH_DPI
    1277     qreal pixelRatio = 1.0;
    1278 
    1279     if ( widget && widget->windowHandle() )
    1280     {
    1281 #if QT_VERSION < 0x050100
    1282         pixelRatio = widget->windowHandle()->devicePixelRatio();
    1283 #else
    1284         pixelRatio = widget->devicePixelRatio();
    1285 #endif
    1286     }
    1287     else
    1288     {
    1289         if ( qApp )
    1290             pixelRatio = qApp->devicePixelRatio();
    1291     }
     1519#if QT_VERSION >= 0x050000
     1520    const qreal pixelRatio = QwtPainter::devicePixelRatio( widget );
    12921521
    12931522    pm = QPixmap( size * pixelRatio );
    12941523    pm.setDevicePixelRatio( pixelRatio );
    12951524#else
    1296     Q_UNUSED( widget )
    12971525    pm = QPixmap( size );
    12981526#endif
    12991527
    1300 #if QT_VERSION < 0x050000
    13011528#ifdef Q_WS_X11
    13021529    if ( widget && isX11GraphicsSystem() )
    … …  
    13051532            pm.x11SetScreen( widget->x11Info().screen() );
    13061533    }
    1307 #endif
     1534#else
     1535    Q_UNUSED( widget )
    13081536#endif
    13091537
    13101538    return pm;
    13111539}
    1312 
  • trunk/BNC/qwt/qwt_painter.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414
    15 #include <qpoint.h>
    16 #include <qrect.h>
     15#include <qpalette.h>
     16#include <qpolygon.h>
    1717#include <qpen.h>
    18 #include <qline.h>
    19 #include <qpalette.h>
    20 
    21 class QPainter;
    22 class QBrush;
    23 class QColor;
    24 class QWidget;
    25 class QPolygonF;
    26 class QRectF;
    27 class QImage;
    28 class QPixmap;
     18
    2919class QwtScaleMap;
    3020class QwtColorMap;
    3121class QwtInterval;
    3222
     23class QPainter;
     24class QBrush;
     25class QWidget;
     26class QImage;
     27class QPixmap;
     28class QFontMetrics;
     29class QFontMetricsF;
    3330class QTextDocument;
    3431class QPainterPath;
    3532
    3633/*!
    37   \brief A collection of QPainter workarounds
    38 */
     34   \brief A collection of QPainter workarounds
     35 */
    3936class QWT_EXPORT QwtPainter
    4037{
    41 public:
     38  public:
    4239    static void setPolylineSplitting( bool );
    4340    static bool polylineSplitting();
    … …  
    4542    static void setRoundingAlignment( bool );
    4643    static bool roundingAlignment();
    47     static bool roundingAlignment(QPainter *);
    48 
    49     static void drawText( QPainter *, double x, double y, const QString & );
    50     static void drawText( QPainter *, const QPointF &, const QString & );
    51     static void drawText( QPainter *, double x, double y, double w, double h,
    52         int flags, const QString & );
    53     static void drawText( QPainter *, const QRectF &,
    54         int flags, const QString & );
     44    static bool roundingAlignment( const QPainter* );
     45
     46    static void drawText( QPainter*, qreal x, qreal y, const QString& );
     47    static void drawText( QPainter*, const QPointF&, const QString& );
     48    static void drawText( QPainter*, qreal x, qreal y, qreal w, qreal h,
     49        int flags, const QString& );
     50    static void drawText( QPainter*, const QRectF&,
     51        int flags, const QString& );
    5552
    5653#ifndef QT_NO_RICHTEXT
    57     static void drawSimpleRichText( QPainter *, const QRectF &,
    58         int flags, const QTextDocument & );
     54    static void drawSimpleRichText( QPainter*, const QRectF&,
     55        int flags, const QTextDocument& );
    5956#endif
    6057
    61     static void drawRect( QPainter *, double x, double y, double w, double h );
    62     static void drawRect( QPainter *, const QRectF &rect );
    63     static void fillRect( QPainter *, const QRectF &, const QBrush & );
    64 
    65     static void drawEllipse( QPainter *, const QRectF & );
    66     static void drawPie( QPainter *, const QRectF &, int a, int alen );
    67 
    68     static void drawLine( QPainter *, double x1, double y1, double x2, double y2 );
    69     static void drawLine( QPainter *, const QPointF &p1, const QPointF &p2 );
    70     static void drawLine( QPainter *, const QLineF & );
    71 
    72     static void drawPolygon( QPainter *, const QPolygonF & );
    73     static void drawPolyline( QPainter *, const QPolygonF & );
    74     static void drawPolyline( QPainter *, const QPointF *, int pointCount );
    75 
    76     static void drawPolygon( QPainter *, const QPolygon & );
    77     static void drawPolyline( QPainter *, const QPolygon & );
    78     static void drawPolyline( QPainter *, const QPoint *, int pointCount );
    79 
    80     static void drawPoint( QPainter *, const QPoint & );
    81     static void drawPoints( QPainter *, const QPolygon & );
    82     static void drawPoints( QPainter *, const QPoint *, int pointCount );
    83 
    84     static void drawPoint( QPainter *, double x, double y );
    85     static void drawPoint( QPainter *, const QPointF & );
    86     static void drawPoints( QPainter *, const QPolygonF & );
    87     static void drawPoints( QPainter *, const QPointF *, int pointCount );
    88 
    89     static void drawPath( QPainter *, const QPainterPath & );
    90     static void drawImage( QPainter *, const QRectF &, const QImage & );
    91     static void drawPixmap( QPainter *, const QRectF &, const QPixmap & );
    92 
    93     static void drawRoundFrame( QPainter *,
    94         const QRectF &, const QPalette &, int lineWidth, int frameStyle );
    95 
    96     static void drawRoundedFrame( QPainter *,
    97         const QRectF &, double xRadius, double yRadius,
    98         const QPalette &, int lineWidth, int frameStyle );
    99 
    100     static void drawFrame( QPainter *, const QRectF &rect,
    101         const QPalette &palette, QPalette::ColorRole foregroundRole,
    102         int frameWidth, int midLineWidth, int frameStyle );
    103 
    104     static void drawFocusRect( QPainter *, const QWidget * );
    105     static void drawFocusRect( QPainter *, const QWidget *, const QRect & );
    106 
    107     static void drawColorBar( QPainter *painter,
    108         const QwtColorMap &, const QwtInterval &,
    109         const QwtScaleMap &, Qt::Orientation, const QRectF & );
    110 
    111     static bool isAligning( QPainter *painter );
     58    static void drawRect( QPainter*, qreal x, qreal y, qreal w, qreal h );
     59    static void drawRect( QPainter*, const QRectF& rect );
     60    static void fillRect( QPainter*, const QRectF&, const QBrush& );
     61
     62    static void drawEllipse( QPainter*, const QRectF& );
     63    static void drawPie( QPainter*, const QRectF& r, int a, int alen );
     64
     65    static void drawLine( QPainter*, qreal x1, qreal y1, qreal x2, qreal y2 );
     66    static void drawLine( QPainter*, const QPointF& p1, const QPointF& p2 );
     67    static void drawLine( QPainter*, const QLineF& );
     68
     69    static void drawPolygon( QPainter*, const QPolygonF& );
     70    static void drawPolyline( QPainter*, const QPolygonF& );
     71    static void drawPolyline( QPainter*, const QPointF*, int pointCount );
     72
     73    static void drawPolygon( QPainter*, const QPolygon& );
     74    static void drawPolyline( QPainter*, const QPolygon& );
     75    static void drawPolyline( QPainter*, const QPoint*, int pointCount );
     76
     77    static void drawPoint( QPainter*, const QPoint& );
     78    static void drawPoints( QPainter*, const QPolygon& );
     79    static void drawPoints( QPainter*, const QPoint*, int pointCount );
     80
     81    static void drawPoint( QPainter*, qreal x, qreal y );
     82    static void drawPoint( QPainter*, const QPointF& );
     83    static void drawPoints( QPainter*, const QPolygonF& );
     84    static void drawPoints( QPainter*, const QPointF*, int pointCount );
     85
     86    static void drawPath( QPainter*, const QPainterPath& );
     87    static void drawImage( QPainter*, const QRectF&, const QImage& );
     88    static void drawPixmap( QPainter*, const QRectF&, const QPixmap& );
     89
     90    static void drawRoundFrame( QPainter*,
     91        const QRectF&, const QPalette&, int lineWidth, int frameStyle );
     92
     93    static void drawRoundedFrame( QPainter*,
     94        const QRectF&, qreal xRadius, qreal yRadius,
     95        const QPalette&, int lineWidth, int frameStyle );
     96
     97    static void drawFrame( QPainter*, const QRectF& rect,
     98        const QPalette& palette, QPalette::ColorRole foregroundRole,
     99        int lineWidth, int midLineWidth, int frameStyle );
     100
     101    static void drawFocusRect( QPainter*, const QWidget* );
     102    static void drawFocusRect( QPainter*, const QWidget*, const QRect& );
     103
     104    static void drawColorBar( QPainter*,
     105        const QwtColorMap&, const QwtInterval&,
     106        const QwtScaleMap&, Qt::Orientation, const QRectF& );
     107
     108    static bool isAligning( const QPainter*);
    112109    static bool isX11GraphicsSystem();
    113110
    114     static void fillPixmap( const QWidget *,
    115         QPixmap &, const QPoint &offset = QPoint() );
    116 
    117     static void drawBackgound( QPainter *painter,
    118         const QRectF &rect, const QWidget *widget );
    119 
    120     static QPixmap backingStore( QWidget *, const QSize & );
    121 
    122 private:
    123     static bool d_polylineSplitting;
    124     static bool d_roundingAlignment;
     111    static void fillPixmap( const QWidget*,
     112        QPixmap&, const QPoint& offset = QPoint() );
     113
     114    static void drawBackgound( QPainter*,
     115        const QRectF&, const QWidget* );
     116
     117    static QPixmap backingStore( QWidget*, const QSize& );
     118    static qreal devicePixelRatio( const QPaintDevice* );
     119
     120    static qreal effectivePenWidth( const QPen& );
     121
     122    static int horizontalAdvance( const QFontMetrics&, const QString& );
     123    static qreal horizontalAdvance( const QFontMetricsF&, const QString& );
     124
     125    static int horizontalAdvance( const QFontMetrics&, QChar );
     126    static qreal horizontalAdvance( const QFontMetricsF&, QChar );
     127
     128    static QFont scaledFont( const QFont&, const QPaintDevice* = NULL );
     129
     130  private:
     131    static bool m_polylineSplitting;
     132    static bool m_roundingAlignment;
    125133};
    126134
    127135//!  Wrapper for QPainter::drawPoint()
    128 inline void QwtPainter::drawPoint( QPainter *painter, double x, double y )
     136inline void QwtPainter::drawPoint( QPainter* painter, qreal x, qreal y )
    129137{
    130138    QwtPainter::drawPoint( painter, QPointF( x, y ) );
    … …  
    132140
    133141//! Wrapper for QPainter::drawPoints()
    134 inline void QwtPainter::drawPoints( QPainter *painter, const QPolygon &polygon )
     142inline void QwtPainter::drawPoints( QPainter* painter, const QPolygon& polygon )
    135143{
    136144    drawPoints( painter, polygon.data(), polygon.size() );
    … …  
    138146
    139147//! Wrapper for QPainter::drawPoints()
    140 inline void QwtPainter::drawPoints( QPainter *painter, const QPolygonF &polygon )
     148inline void QwtPainter::drawPoints( QPainter* painter, const QPolygonF& polygon )
    141149{
    142150    drawPoints( painter, polygon.data(), polygon.size() );
    … …  
    144152
    145153//!  Wrapper for QPainter::drawLine()
    146 inline void QwtPainter::drawLine( QPainter *painter,
    147     double x1, double y1, double x2, double y2 )
     154inline void QwtPainter::drawLine( QPainter* painter,
     155    qreal x1, qreal y1, qreal x2, qreal y2 )
    148156{
    149157    QwtPainter::drawLine( painter, QPointF( x1, y1 ), QPointF( x2, y2 ) );
    … …  
    151159
    152160//!  Wrapper for QPainter::drawLine()
    153 inline void QwtPainter::drawLine( QPainter *painter, const QLineF &line )
     161inline void QwtPainter::drawLine( QPainter* painter, const QLineF& line )
    154162{
    155163    QwtPainter::drawLine( painter, line.p1(), line.p2() );
    … …  
    157165
    158166/*!
    159   \return True, when line splitting for the raster paint engine is enabled.
    160   \sa setPolylineSplitting()
    161 */
     167   \return True, when line splitting for the raster paint engine is enabled.
     168   \sa setPolylineSplitting()
     169 */
    162170inline bool QwtPainter::polylineSplitting()
    163171{
    164     return d_polylineSplitting;
    165 }
    166 
    167 /*!
    168   Check whether coordinates should be rounded, before they are painted
    169   to a paint engine that rounds to integer values. For other paint engines
    170   ( PDF, SVG ), this flag has no effect.
    171 
    172   \return True, when rounding is enabled
    173   \sa setRoundingAlignment(), isAligning()
    174 */
     172    return m_polylineSplitting;
     173}
     174
     175/*!
     176   Check whether coordinates should be rounded, before they are painted
     177   to a paint engine that rounds to integer values. For other paint engines
     178   ( PDF, SVG ), this flag has no effect.
     179
     180   \return True, when rounding is enabled
     181   \sa setRoundingAlignment(), isAligning()
     182 */
    175183inline bool QwtPainter::roundingAlignment()
    176184{
    177     return d_roundingAlignment;
    178 }
    179 
    180 /*!
    181   \return roundingAlignment() && isAligning(painter);
    182   \param painter Painter
    183 */
    184 inline bool QwtPainter::roundingAlignment(QPainter *painter)
    185 {
    186     return d_roundingAlignment && isAligning(painter);
    187 }
     185    return m_roundingAlignment;
     186}
     187
     188/*!
     189   \return roundingAlignment() && isAligning(painter);
     190   \param painter Painter
     191 */
     192inline bool QwtPainter::roundingAlignment( const QPainter* painter )
     193{
     194    return m_roundingAlignment && isAligning(painter);
     195}
     196
     197/*!
     198   \return pen.widthF() expanded to at least 1.0
     199   \param pen Pen
     200 */
     201inline qreal QwtPainter::effectivePenWidth( const QPen& pen )
     202{
     203    const qreal width = pen.widthF();
     204    return ( width < 1.0 ) ? 1.0 : width;
     205}
     206
    188207#endif
  • trunk/BNC/qwt/qwt_painter_command.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111
    1212//! Construct an invalid command
    13 QwtPainterCommand::QwtPainterCommand():
    14     d_type( Invalid )
     13QwtPainterCommand::QwtPainterCommand()
     14    : m_type( Invalid )
    1515{
    1616}
    1717
    1818//! Copy constructor
    19 QwtPainterCommand::QwtPainterCommand( const QPainterPath &path ):
    20     d_type( Path )
    21 {
    22     d_path = new QPainterPath( path );
    23 }
    24 
    25 /*!
    26   Constructor for Pixmap paint operation
    27 
    28   \param rect Target rectangle
    29   \param pixmap Pixmap
    30   \param subRect Rectangle inside the pixmap
    31 
    32   \sa QPainter::drawPixmap()
    33  */
    34 QwtPainterCommand::QwtPainterCommand( const QRectF &rect,
    35         const QPixmap &pixmap, const QRectF& subRect ):
    36     d_type( Pixmap )
    37 {
    38     d_pixmapData = new PixmapData();
    39     d_pixmapData->rect = rect;
    40     d_pixmapData->pixmap = pixmap;
    41     d_pixmapData->subRect = subRect;
    42 }
    43 
    44 /*!
    45   Constructor for Image paint operation
    46 
    47   \param rect Target rectangle
    48   \param image Image
    49   \param subRect Rectangle inside the image
    50   \param flags Conversion flags
    51 
    52   \sa QPainter::drawImage()
    53  */
    54 QwtPainterCommand::QwtPainterCommand( const QRectF &rect,
    55         const QImage &image, const QRectF& subRect,
    56         Qt::ImageConversionFlags flags ):
    57     d_type( Image )
    58 {
    59     d_imageData = new ImageData();
    60     d_imageData->rect = rect;
    61     d_imageData->image = image;
    62     d_imageData->subRect = subRect;
    63     d_imageData->flags = flags;
    64 }
    65 
    66 /*!
    67   Constructor for State paint operation
    68   \param state Paint engine state
    69  */
    70 QwtPainterCommand::QwtPainterCommand( const QPaintEngineState &state ):
    71     d_type( State )
    72 {
    73     d_stateData = new StateData();
    74 
    75     d_stateData->flags = state.state();
    76 
    77     if ( d_stateData->flags & QPaintEngine::DirtyPen )
    78         d_stateData->pen = state.pen();
    79 
    80     if ( d_stateData->flags & QPaintEngine::DirtyBrush )
    81         d_stateData->brush = state.brush();
    82 
    83     if ( d_stateData->flags & QPaintEngine::DirtyBrushOrigin )
    84         d_stateData->brushOrigin = state.brushOrigin();
    85 
    86     if ( d_stateData->flags & QPaintEngine::DirtyFont )
    87         d_stateData->font = state.font();
    88 
    89     if ( d_stateData->flags & QPaintEngine::DirtyBackground )
    90     {
    91         d_stateData->backgroundMode = state.backgroundMode();
    92         d_stateData->backgroundBrush = state.backgroundBrush();
    93     }
    94 
    95     if ( d_stateData->flags & QPaintEngine::DirtyTransform )
    96         d_stateData->transform = state.transform();
    97 
    98     if ( d_stateData->flags & QPaintEngine::DirtyClipEnabled )
    99         d_stateData->isClipEnabled = state.isClipEnabled();
    100 
    101     if ( d_stateData->flags & QPaintEngine::DirtyClipRegion )
    102     {
    103         d_stateData->clipRegion = state.clipRegion();
    104         d_stateData->clipOperation = state.clipOperation();
    105     }
    106 
    107     if ( d_stateData->flags & QPaintEngine::DirtyClipPath )
    108     {
    109         d_stateData->clipPath = state.clipPath();
    110         d_stateData->clipOperation = state.clipOperation();
    111     }
    112 
    113     if ( d_stateData->flags & QPaintEngine::DirtyHints )
    114         d_stateData->renderHints = state.renderHints();
    115 
    116     if ( d_stateData->flags & QPaintEngine::DirtyCompositionMode )
    117         d_stateData->compositionMode = state.compositionMode();
    118 
    119     if ( d_stateData->flags & QPaintEngine::DirtyOpacity )
    120         d_stateData->opacity = state.opacity();
    121 }
    122 
    123 /*!
    124   Copy constructor
    125   \param other Command to be copied
    126 
    127  */
    128 QwtPainterCommand::QwtPainterCommand(const QwtPainterCommand &other)
     19QwtPainterCommand::QwtPainterCommand( const QPainterPath& path )
     20    : m_type( Path )
     21{
     22    m_path = new QPainterPath( path );
     23}
     24
     25/*!
     26   Constructor for Pixmap paint operation
     27
     28   \param rect Target rectangle
     29   \param pixmap Pixmap
     30   \param subRect Rectangle inside the pixmap
     31
     32   \sa QPainter::drawPixmap()
     33 */
     34QwtPainterCommand::QwtPainterCommand( const QRectF& rect,
     35        const QPixmap& pixmap, const QRectF& subRect )
     36    : m_type( Pixmap )
     37{
     38    m_pixmapData = new PixmapData();
     39    m_pixmapData->rect = rect;
     40    m_pixmapData->pixmap = pixmap;
     41    m_pixmapData->subRect = subRect;
     42}
     43
     44/*!
     45   Constructor for Image paint operation
     46
     47   \param rect Target rectangle
     48   \param image Image
     49   \param subRect Rectangle inside the image
     50   \param flags Conversion flags
     51
     52   \sa QPainter::drawImage()
     53 */
     54QwtPainterCommand::QwtPainterCommand( const QRectF& rect,
     55        const QImage& image, const QRectF& subRect,
     56        Qt::ImageConversionFlags flags )
     57    : m_type( Image )
     58{
     59    m_imageData = new ImageData();
     60    m_imageData->rect = rect;
     61    m_imageData->image = image;
     62    m_imageData->subRect = subRect;
     63    m_imageData->flags = flags;
     64}
     65
     66/*!
     67   Constructor for State paint operation
     68   \param state Paint engine state
     69 */
     70QwtPainterCommand::QwtPainterCommand( const QPaintEngineState& state )
     71    : m_type( State )
     72{
     73    m_stateData = new StateData();
     74
     75    m_stateData->flags = state.state();
     76
     77    if ( m_stateData->flags & QPaintEngine::DirtyPen )
     78        m_stateData->pen = state.pen();
     79
     80    if ( m_stateData->flags & QPaintEngine::DirtyBrush )
     81        m_stateData->brush = state.brush();
     82
     83    if ( m_stateData->flags & QPaintEngine::DirtyBrushOrigin )
     84        m_stateData->brushOrigin = state.brushOrigin();
     85
     86    if ( m_stateData->flags & QPaintEngine::DirtyFont )
     87        m_stateData->font = state.font();
     88
     89    if ( m_stateData->flags & QPaintEngine::DirtyBackground )
     90    {
     91        m_stateData->backgroundMode = state.backgroundMode();
     92        m_stateData->backgroundBrush = state.backgroundBrush();
     93    }
     94
     95    if ( m_stateData->flags & QPaintEngine::DirtyTransform )
     96        m_stateData->transform = state.transform();
     97
     98    if ( m_stateData->flags & QPaintEngine::DirtyClipEnabled )
     99        m_stateData->isClipEnabled = state.isClipEnabled();
     100
     101    if ( m_stateData->flags & QPaintEngine::DirtyClipRegion )
     102    {
     103        m_stateData->clipRegion = state.clipRegion();
     104        m_stateData->clipOperation = state.clipOperation();
     105    }
     106
     107    if ( m_stateData->flags & QPaintEngine::DirtyClipPath )
     108    {
     109        m_stateData->clipPath = state.clipPath();
     110        m_stateData->clipOperation = state.clipOperation();
     111    }
     112
     113    if ( m_stateData->flags & QPaintEngine::DirtyHints )
     114        m_stateData->renderHints = state.renderHints();
     115
     116    if ( m_stateData->flags & QPaintEngine::DirtyCompositionMode )
     117        m_stateData->compositionMode = state.compositionMode();
     118
     119    if ( m_stateData->flags & QPaintEngine::DirtyOpacity )
     120        m_stateData->opacity = state.opacity();
     121}
     122
     123/*!
     124   Copy constructor
     125   \param other Command to be copied
     126
     127 */
     128QwtPainterCommand::QwtPainterCommand( const QwtPainterCommand& other )
    129129{
    130130    copy( other );
    … …  
    138138
    139139/*!
    140   Assignment operator
    141 
    142   \param other Command to be copied
    143   \return Modified command
    144  */
    145 QwtPainterCommand &QwtPainterCommand::operator=(const QwtPainterCommand &other)
     140   Assignment operator
     141
     142   \param other Command to be copied
     143   \return Modified command
     144 */
     145QwtPainterCommand& QwtPainterCommand::operator=( const QwtPainterCommand& other )
    146146{
    147147    reset();
    … …  
    151151}
    152152
    153 void QwtPainterCommand::copy( const QwtPainterCommand &other )
    154 {
    155     d_type = other.d_type;
    156 
    157     switch( other.d_type )
     153void QwtPainterCommand::copy( const QwtPainterCommand& other )
     154{
     155    m_type = other.m_type;
     156
     157    switch( other.m_type )
    158158    {
    159159        case Path:
    160160        {
    161             d_path = new QPainterPath( *other.d_path );
     161            m_path = new QPainterPath( *other.m_path );
    162162            break;
    163163        }
    164164        case Pixmap:
    165165        {
    166             d_pixmapData = new PixmapData( *other.d_pixmapData );
     166            m_pixmapData = new PixmapData( *other.m_pixmapData );
    167167            break;
    168168        }
    169169        case Image:
    170170        {
    171             d_imageData = new ImageData( *other.d_imageData );
     171            m_imageData = new ImageData( *other.m_imageData );
    172172            break;
    173173        }
    174174        case State:
    175175        {
    176             d_stateData = new StateData( *other.d_stateData );
     176            m_stateData = new StateData( *other.m_stateData );
    177177            break;
    178178        }
    … …  
    184184void QwtPainterCommand::reset()
    185185{
    186     switch( d_type )
     186    switch( m_type )
    187187    {
    188188        case Path:
    189189        {
    190             delete d_path;
     190            delete m_path;
    191191            break;
    192192        }
    193193        case Pixmap:
    194194        {
    195             delete d_pixmapData;
     195            delete m_pixmapData;
    196196            break;
    197197        }
    198198        case Image:
    199199        {
    200             delete d_imageData;
     200            delete m_imageData;
    201201            break;
    202202        }
    203203        case State:
    204204        {
    205             delete d_stateData;
     205            delete m_stateData;
    206206            break;
    207207        }
    … …  
    210210    }
    211211
    212     d_type = Invalid;
     212    m_type = Invalid;
    213213}
    214214
    215215//! \return Painter path to be painted
    216 QPainterPath *QwtPainterCommand::path()
    217 {
    218     return d_path;
     216QPainterPath* QwtPainterCommand::path()
     217{
     218    return m_path;
    219219}
    220220
    … …  
    222222QwtPainterCommand::PixmapData* QwtPainterCommand::pixmapData()
    223223{
    224     return d_pixmapData;
     224    return m_pixmapData;
    225225}
    226226
    … …  
    228228QwtPainterCommand::ImageData* QwtPainterCommand::imageData()
    229229{
    230     return d_imageData;
     230    return m_imageData;
    231231}
    232232
    … …  
    234234QwtPainterCommand::StateData* QwtPainterCommand::stateData()
    235235{
    236     return d_stateData;
    237 }
     236    return m_stateData;
     237}
  • trunk/BNC/qwt/qwt_painter_command.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
     14
    1415#include <qpaintengine.h>
    1516#include <qpixmap.h>
    … …  
    2122
    2223/*!
    23   QwtPainterCommand represents the attributes of a paint operation
    24   how it is used between QPainter and QPaintDevice
     24   QwtPainterCommand represents the attributes of a paint operation
     25   how it is used between QPainter and QPaintDevice
    2526
    26   It is used by QwtGraphic to record and replay paint operations
     27   It is used by QwtGraphic to record and replay paint operations
    2728
    28   \sa QwtGraphic::commands()
     29   \sa QwtGraphic::commands()
    2930 */
    3031
    3132class QWT_EXPORT QwtPainterCommand
    3233{
    33 public:
     34  public:
    3435    //! Type of the paint command
    3536    enum Type
    … …  
    7980        Qt::BGMode backgroundMode;
    8081        QFont font;
    81         QMatrix matrix;
    8282        QTransform transform;
    8383
    … …  
    9393
    9494    QwtPainterCommand();
    95     QwtPainterCommand(const QwtPainterCommand &);
     95    QwtPainterCommand(const QwtPainterCommand&);
    9696
    97     QwtPainterCommand( const QPainterPath & );
     97    explicit QwtPainterCommand( const QPainterPath& );
    9898
    99     QwtPainterCommand( const QRectF &rect,
    100             const QPixmap &, const QRectF& subRect );
     99    QwtPainterCommand( const QRectF& rect,
     100        const QPixmap&, const QRectF& subRect );
    101101
    102     QwtPainterCommand( const QRectF &rect,
    103             const QImage &, const QRectF& subRect,
    104             Qt::ImageConversionFlags );
     102    QwtPainterCommand( const QRectF& rect,
     103        const QImage&, const QRectF& subRect,
     104        Qt::ImageConversionFlags );
    105105
    106     QwtPainterCommand( const QPaintEngineState & );
     106    explicit QwtPainterCommand( const QPaintEngineState& );
    107107
    108108    ~QwtPainterCommand();
    109109
    110     QwtPainterCommand &operator=(const QwtPainterCommand & );
     110    QwtPainterCommand& operator=(const QwtPainterCommand& );
    111111
    112112    Type type() const;
    113113
    114     QPainterPath *path();
    115     const QPainterPath *path() const;
     114    QPainterPath* path();
     115    const QPainterPath* path() const;
    116116
    117117    PixmapData* pixmapData();
    … …  
    124124    const StateData* stateData() const;
    125125
    126 private:
    127     void copy( const QwtPainterCommand & );
     126  private:
     127    void copy( const QwtPainterCommand& );
    128128    void reset();
    129129
    130     Type d_type;
     130    Type m_type;
    131131
    132132    union
    133133    {
    134         QPainterPath *d_path;
    135         PixmapData *d_pixmapData;
    136         ImageData *d_imageData;
    137         StateData *d_stateData;
     134        QPainterPath* m_path;
     135        PixmapData* m_pixmapData;
     136        ImageData* m_imageData;
     137        StateData* m_stateData;
    138138    };
    139139};
    … …  
    142142inline QwtPainterCommand::Type QwtPainterCommand::type() const
    143143{
    144     return d_type;
     144    return m_type;
    145145}
    146146
    147147//! \return Painter path to be painted
    148 inline const QPainterPath *QwtPainterCommand::path() const
     148inline const QPainterPath* QwtPainterCommand::path() const
    149149{
    150     return d_path;
     150    return m_path;
    151151}
    152152
    153153//! \return Attributes how to paint a QPixmap
    154 inline const QwtPainterCommand::PixmapData *
     154inline const QwtPainterCommand::PixmapData*
    155155QwtPainterCommand::pixmapData() const
    156156{
    157     return d_pixmapData;
     157    return m_pixmapData;
    158158}
    159159
    160160//! \return Attributes how to paint a QImage
    161 inline const QwtPainterCommand::ImageData *
     161inline const QwtPainterCommand::ImageData*
    162162QwtPainterCommand::imageData() const
    163163{
    164     return d_imageData;
     164    return m_imageData;
    165165}
    166166
    167167//! \return Attributes of a state change
    168 inline const QwtPainterCommand::StateData *
     168inline const QwtPainterCommand::StateData*
    169169QwtPainterCommand::stateData() const
    170170{
    171     return d_stateData;
     171    return m_stateData;
    172172}
    173173
  • trunk/BNC/qwt/qwt_panner.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_picker.h"
    1212#include "qwt_painter.h"
     13
    1314#include <qpainter.h>
    1415#include <qpixmap.h>
    … …  
    1718#include <qbitmap.h>
    1819
    19 static QVector<QwtPicker *> qwtActivePickers( QWidget *w )
    20 {
    21     QVector<QwtPicker *> pickers;
     20static QVector< QwtPicker* > qwtActivePickers( QWidget* w )
     21{
     22    QVector< QwtPicker* > pickers;
    2223
    2324    QObjectList children = w->children();
    2425    for ( int i = 0; i < children.size(); i++ )
    2526    {
    26         QwtPicker *picker = qobject_cast<QwtPicker *>( children[i] );
     27        QwtPicker* picker = qobject_cast< QwtPicker* >( children[i] );
    2728        if ( picker && picker->isEnabled() )
    2829            pickers += picker;
    … …  
    3435class QwtPanner::PrivateData
    3536{
    36 public:
    37     PrivateData():
    38         button( Qt::LeftButton ),
    39         buttonModifiers( Qt::NoModifier ),
    40         abortKey( Qt::Key_Escape ),
    41         abortKeyModifiers( Qt::NoModifier ),
    42 #ifndef QT_NO_CURSOR
    43         cursor( NULL ),
    44         restoreCursor( NULL ),
    45         hasCursor( false ),
    46 #endif
    47         isEnabled( false )
    48     {
    49         orientations = Qt::Vertical | Qt::Horizontal;
     37  public:
     38    PrivateData()
     39        : button( Qt::LeftButton )
     40        , buttonModifiers( Qt::NoModifier )
     41        , abortKey( Qt::Key_Escape )
     42        , abortKeyModifiers( Qt::NoModifier )
     43#ifndef QT_NO_CURSOR
     44        , cursor( NULL )
     45        , restoreCursor( NULL )
     46        , hasCursor( false )
     47#endif
     48        , isEnabled( false )
     49        , orientations( Qt::Vertical | Qt::Horizontal )
     50    {
    5051    }
    5152
    … …  
    5960
    6061    Qt::MouseButton button;
    61     Qt::KeyboardModifiers  buttonModifiers;
     62    Qt::KeyboardModifiers buttonModifiers;
    6263
    6364    int abortKey;
    … …  
    7172
    7273#ifndef QT_NO_CURSOR
    73     QCursor *cursor;
    74     QCursor *restoreCursor;
     74    QCursor* cursor;
     75    QCursor* restoreCursor;
    7576    bool hasCursor;
    7677#endif
    … …  
    8081
    8182/*!
    82   Creates an panner that is enabled for the left mouse button.
    83 
    84   \param parent Parent widget to be panned
    85 */
    86 QwtPanner::QwtPanner( QWidget *parent ):
    87     QWidget( parent )
    88 {
    89     d_data = new PrivateData();
     83   Creates an panner that is enabled for the left mouse button.
     84
     85   \param parent Parent widget to be panned
     86 */
     87QwtPanner::QwtPanner( QWidget* parent )
     88    : QWidget( parent )
     89{
     90    m_data = new PrivateData();
    9091
    9192    setAttribute( Qt::WA_TransparentForMouseEvents );
    … …  
    100101QwtPanner::~QwtPanner()
    101102{
    102     delete d_data;
     103    delete m_data;
    103104}
    104105
    … …  
    106107   Change the mouse button and modifiers used for panning
    107108   The defaults are Qt::LeftButton and Qt::NoModifier
    108 */
     109 */
    109110void QwtPanner::setMouseButton( Qt::MouseButton button,
    110111    Qt::KeyboardModifiers modifiers )
    111112{
    112     d_data->button = button;
    113     d_data->buttonModifiers = modifiers;
     113    m_data->button = button;
     114    m_data->buttonModifiers = modifiers;
    114115}
    115116
    116117//! Get mouse button and modifiers used for panning
    117 void QwtPanner::getMouseButton( Qt::MouseButton &button,
    118     Qt::KeyboardModifiers &modifiers ) const
    119 {
    120     button = d_data->button;
    121     modifiers = d_data->buttonModifiers;
     118void QwtPanner::getMouseButton( Qt::MouseButton& button,
     119    Qt::KeyboardModifiers& modifiers ) const
     120{
     121    button = m_data->button;
     122    modifiers = m_data->buttonModifiers;
    122123}
    123124
    … …  
    128129   \param key Key ( See Qt::Keycode )
    129130   \param modifiers Keyboard modifiers
    130 */
     131 */
    131132void QwtPanner::setAbortKey( int key,
    132133    Qt::KeyboardModifiers modifiers )
    133134{
    134     d_data->abortKey = key;
    135     d_data->abortKeyModifiers = modifiers;
     135    m_data->abortKey = key;
     136    m_data->abortKeyModifiers = modifiers;
    136137}
    137138
    138139//! Get the abort key and modifiers
    139 void QwtPanner::getAbortKey( int &key,
    140     Qt::KeyboardModifiers &modifiers ) const
    141 {
    142     key = d_data->abortKey;
    143     modifiers = d_data->abortKeyModifiers;
     140void QwtPanner::getAbortKey( int& key,
     141    Qt::KeyboardModifiers& modifiers ) const
     142{
     143    key = m_data->abortKey;
     144    modifiers = m_data->abortKeyModifiers;
    144145}
    145146
    … …  
    151152
    152153   \sa setCursor()
    153 */
    154 #ifndef QT_NO_CURSOR
    155 void QwtPanner::setCursor( const QCursor &cursor )
    156 {
    157     d_data->cursor = new QCursor( cursor );
     154 */
     155#ifndef QT_NO_CURSOR
     156void QwtPanner::setCursor( const QCursor& cursor )
     157{
     158    m_data->cursor = new QCursor( cursor );
    158159}
    159160#endif
    … …  
    162163   \return Cursor that is active while panning
    163164   \sa setCursor()
    164 */
     165 */
    165166#ifndef QT_NO_CURSOR
    166167const QCursor QwtPanner::cursor() const
    167168{
    168     if ( d_data->cursor )
    169         return *d_data->cursor;
     169    if ( m_data->cursor )
     170        return *m_data->cursor;
    170171
    171172    if ( parentWidget() )
    … …  
    177178
    178179/*!
    179   \brief En/disable the panner
    180 
    181   When enabled is true an event filter is installed for
    182   the observed widget, otherwise the event filter is removed.
    183 
    184   \param on true or false
    185   \sa isEnabled(), eventFilter()
    186 */
     180   \brief En/disable the panner
     181
     182   When enabled is true an event filter is installed for
     183   the observed widget, otherwise the event filter is removed.
     184
     185   \param on true or false
     186   \sa isEnabled(), eventFilter()
     187 */
    187188void QwtPanner::setEnabled( bool on )
    188189{
    189     if ( d_data->isEnabled != on )
    190     {
    191         d_data->isEnabled = on;
    192 
    193         QWidget *w = parentWidget();
     190    if ( m_data->isEnabled != on )
     191    {
     192        m_data->isEnabled = on;
     193
     194        QWidget* w = parentWidget();
    194195        if ( w )
    195196        {
    196             if ( d_data->isEnabled )
     197            if ( m_data->isEnabled )
    197198            {
    198199                w->installEventFilter( this );
    … …  
    212213
    213214   /param o Orientation
    214 */
     215 */
    215216void QwtPanner::setOrientations( Qt::Orientations o )
    216217{
    217     d_data->orientations = o;
    218 }
    219 
    220 //! Return the orientation, where paning is enabled
     218    m_data->orientations = o;
     219}
     220
     221//! Return the orientation, where panning is enabled
    221222Qt::Orientations QwtPanner::orientations() const
    222223{
    223     return d_data->orientations;
     224    return m_data->orientations;
    224225}
    225226
    … …  
    227228   \return True if an orientation is enabled
    228229   \sa orientations(), setOrientations()
    229 */
     230 */
    230231bool QwtPanner::isOrientationEnabled( Qt::Orientation o ) const
    231232{
    232     return d_data->orientations & o;
    233 }
    234 
    235 /*!
    236   \return true when enabled, false otherwise
    237   \sa setEnabled, eventFilter()
    238 */
     233    return m_data->orientations & o;
     234}
     235
     236/*!
     237   \return true when enabled, false otherwise
     238   \sa setEnabled, eventFilter()
     239 */
    239240bool QwtPanner::isEnabled() const
    240241{
    241     return d_data->isEnabled;
     242    return m_data->isEnabled;
    242243}
    243244
    … …  
    249250
    250251   \param event Paint event
    251 */
    252 void QwtPanner::paintEvent( QPaintEvent *event )
    253 {
    254     int dx = d_data->pos.x() - d_data->initialPos.x();
    255     int dy = d_data->pos.y() - d_data->initialPos.y();
     252 */
     253void QwtPanner::paintEvent( QPaintEvent* event )
     254{
     255    int dx = m_data->pos.x() - m_data->initialPos.x();
     256    int dy = m_data->pos.y() - m_data->initialPos.y();
    256257
    257258    QRectF r;
    258     r.setSize( d_data->pixmap.size() );
    259 #if QT_VERSION >= 0x050000
    260     r.setSize( r.size() / d_data->pixmap.devicePixelRatio() );
    261 #endif
     259    r.setSize( m_data->pixmap.size() / QwtPainter::devicePixelRatio( &m_data->pixmap ) );
    262260    r.moveCenter( QPointF( r.center().x() + dx, r.center().y() + dy ) );
    263261
    … …  
    267265    QPainter painter( &pm );
    268266
    269     if ( !d_data->contentsMask.isNull() )
    270     {
    271         QPixmap masked = d_data->pixmap;
    272         masked.setMask( d_data->contentsMask );
     267    if ( !m_data->contentsMask.isNull() )
     268    {
     269        QPixmap masked = m_data->pixmap;
     270        masked.setMask( m_data->contentsMask );
    273271        painter.drawPixmap( r.toRect(), masked );
    274272    }
    275273    else
    276274    {
    277         painter.drawPixmap( r.toRect(), d_data->pixmap );
     275        painter.drawPixmap( r.toRect(), m_data->pixmap );
    278276    }
    279277
    280278    painter.end();
    281279
    282     if ( !d_data->contentsMask.isNull() )
    283         pm.setMask( d_data->contentsMask );
     280    if ( !m_data->contentsMask.isNull() )
     281        pm.setMask( m_data->contentsMask );
    284282
    285283    painter.begin( this );
    … …  
    289287
    290288/*!
    291   \brief Calculate a mask for the contents of the panned widget
    292 
    293   Sometimes only parts of the contents of a widget should be
    294   panned. F.e. for a widget with a styled background with rounded borders
    295   only the area inside of the border should be panned.
    296 
    297   \return An empty bitmap, indicating no mask
    298 */
     289   \brief Calculate a mask for the contents of the panned widget
     290
     291   Sometimes only parts of the contents of a widget should be
     292   panned. F.e. for a widget with a styled background with rounded borders
     293   only the area inside of the border should be panned.
     294
     295   \return An empty bitmap, indicating no mask
     296 */
    299297QBitmap QwtPanner::contentsMask() const
    300298{
    … …  
    303301
    304302/*!
    305   Grab the widget into a pixmap.
    306   \return Grabbed pixmap
    307 */
     303   Grab the widget into a pixmap.
     304   \return Grabbed pixmap
     305 */
    308306QPixmap QwtPanner::grab() const
    309307{
    … …  
    316314
    317315/*!
    318   \brief Event filter
    319 
    320   When isEnabled() is true mouse events of the
    321   observed widget are filtered.
    322 
    323   \param object Object to be filtered
    324   \param event Event
    325 
    326   \return Always false, beside for paint events for the
     316   \brief Event filter
     317
     318   When isEnabled() is true mouse events of the
     319   observed widget are filtered.
     320
     321   \param object Object to be filtered
     322   \param event Event
     323
     324   \return Always false, beside for paint events for the
    327325          parent widget.
    328326
    329   \sa widgetMousePressEvent(), widgetMouseReleaseEvent(),
     327   \sa widgetMousePressEvent(), widgetMouseReleaseEvent(),
    330328      widgetMouseMoveEvent()
    331 */
    332 bool QwtPanner::eventFilter( QObject *object, QEvent *event )
     329 */
     330bool QwtPanner::eventFilter( QObject* object, QEvent* event )
    333331{
    334332    if ( object == NULL || object != parentWidget() )
    … …  
    339337        case QEvent::MouseButtonPress:
    340338        {
    341             widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );
     339            widgetMousePressEvent( static_cast< QMouseEvent* >( event ) );
    342340            break;
    343341        }
    344342        case QEvent::MouseMove:
    345343        {
    346             widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );
     344            widgetMouseMoveEvent( static_cast< QMouseEvent* >( event ) );
    347345            break;
    348346        }
    349347        case QEvent::MouseButtonRelease:
    350348        {
    351             widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );
     349            widgetMouseReleaseEvent( static_cast< QMouseEvent* >( event ) );
    352350            break;
    353351        }
    354352        case QEvent::KeyPress:
    355353        {
    356             widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );
     354            widgetKeyPressEvent( static_cast< QKeyEvent* >( event ) );
    357355            break;
    358356        }
    359357        case QEvent::KeyRelease:
    360358        {
    361             widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );
     359            widgetKeyReleaseEvent( static_cast< QKeyEvent* >( event ) );
    362360            break;
    363361        }
    … …  
    375373
    376374/*!
    377   Handle a mouse press event for the observed widget.
    378 
    379   \param mouseEvent Mouse event
    380   \sa eventFilter(), widgetMouseReleaseEvent(),
     375   Handle a mouse press event for the observed widget.
     376
     377   \param mouseEvent Mouse event
     378   \sa eventFilter(), widgetMouseReleaseEvent(),
    381379      widgetMouseMoveEvent(),
    382 */
    383 void QwtPanner::widgetMousePressEvent( QMouseEvent *mouseEvent )
    384 {
    385     if ( ( mouseEvent->button() != d_data->button )
    386         || ( mouseEvent->modifiers() != d_data->buttonModifiers ) )
     380 */
     381void QwtPanner::widgetMousePressEvent( QMouseEvent* mouseEvent )
     382{
     383    if ( ( mouseEvent->button() != m_data->button )
     384        || ( mouseEvent->modifiers() != m_data->buttonModifiers ) )
    387385    {
    388386        return;
    389387    }
    390388
    391     QWidget *w = parentWidget();
     389    QWidget* w = parentWidget();
    392390    if ( w == NULL )
    393391        return;
    … …  
    397395#endif
    398396
    399     d_data->initialPos = d_data->pos = mouseEvent->pos();
     397    m_data->initialPos = m_data->pos = mouseEvent->pos();
    400398
    401399    setGeometry( parentWidget()->rect() );
    402400
    403401    // We don't want to grab the picker !
    404     QVector<QwtPicker *> pickers = qwtActivePickers( parentWidget() );
     402    QVector< QwtPicker* > pickers = qwtActivePickers( parentWidget() );
    405403    for ( int i = 0; i < pickers.size(); i++ )
    406404        pickers[i]->setEnabled( false );
    407405
    408     d_data->pixmap = grab();
    409     d_data->contentsMask = contentsMask();
     406    m_data->pixmap = grab();
     407    m_data->contentsMask = contentsMask();
    410408
    411409    for ( int i = 0; i < pickers.size(); i++ )
    … …  
    416414
    417415/*!
    418   Handle a mouse move event for the observed widget.
    419 
    420   \param mouseEvent Mouse event
    421   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent()
    422 */
    423 void QwtPanner::widgetMouseMoveEvent( QMouseEvent *mouseEvent )
     416   Handle a mouse move event for the observed widget.
     417
     418   \param mouseEvent Mouse event
     419   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent()
     420 */
     421void QwtPanner::widgetMouseMoveEvent( QMouseEvent* mouseEvent )
    424422{
    425423    if ( !isVisible() )
    … …  
    428426    QPoint pos = mouseEvent->pos();
    429427    if ( !isOrientationEnabled( Qt::Horizontal ) )
    430         pos.setX( d_data->initialPos.x() );
     428        pos.setX( m_data->initialPos.x() );
    431429    if ( !isOrientationEnabled( Qt::Vertical ) )
    432         pos.setY( d_data->initialPos.y() );
    433 
    434     if ( pos != d_data->pos && rect().contains( pos ) )
    435     {
    436         d_data->pos = pos;
     430        pos.setY( m_data->initialPos.y() );
     431
     432    if ( pos != m_data->pos && rect().contains( pos ) )
     433    {
     434        m_data->pos = pos;
    437435        update();
    438436
    439         Q_EMIT moved( d_data->pos.x() - d_data->initialPos.x(),
    440             d_data->pos.y() - d_data->initialPos.y() );
    441     }
    442 }
    443 
    444 /*!
    445   Handle a mouse release event for the observed widget.
    446 
    447   \param mouseEvent Mouse event
    448   \sa eventFilter(), widgetMousePressEvent(),
     437        Q_EMIT moved( m_data->pos.x() - m_data->initialPos.x(),
     438            m_data->pos.y() - m_data->initialPos.y() );
     439    }
     440}
     441
     442/*!
     443   Handle a mouse release event for the observed widget.
     444
     445   \param mouseEvent Mouse event
     446   \sa eventFilter(), widgetMousePressEvent(),
    449447      widgetMouseMoveEvent(),
    450 */
    451 void QwtPanner::widgetMouseReleaseEvent( QMouseEvent *mouseEvent )
     448 */
     449void QwtPanner::widgetMouseReleaseEvent( QMouseEvent* mouseEvent )
    452450{
    453451    if ( isVisible() )
    … …  
    460458        QPoint pos = mouseEvent->pos();
    461459        if ( !isOrientationEnabled( Qt::Horizontal ) )
    462             pos.setX( d_data->initialPos.x() );
     460            pos.setX( m_data->initialPos.x() );
    463461        if ( !isOrientationEnabled( Qt::Vertical ) )
    464             pos.setY( d_data->initialPos.y() );
    465 
    466         d_data->pixmap = QPixmap();
    467         d_data->contentsMask = QBitmap();
    468         d_data->pos = pos;
    469 
    470         if ( d_data->pos != d_data->initialPos )
    471         {
    472             Q_EMIT panned( d_data->pos.x() - d_data->initialPos.x(),
    473                 d_data->pos.y() - d_data->initialPos.y() );
    474         }
    475     }
    476 }
    477 
    478 /*!
    479   Handle a key press event for the observed widget.
    480 
    481   \param keyEvent Key event
    482   \sa eventFilter(), widgetKeyReleaseEvent()
    483 */
    484 void QwtPanner::widgetKeyPressEvent( QKeyEvent *keyEvent )
    485 {
    486     if ( ( keyEvent->key() == d_data->abortKey )
    487         && ( keyEvent->modifiers() == d_data->abortKeyModifiers ) )
     462            pos.setY( m_data->initialPos.y() );
     463
     464        m_data->pixmap = QPixmap();
     465        m_data->contentsMask = QBitmap();
     466        m_data->pos = pos;
     467
     468        if ( m_data->pos != m_data->initialPos )
     469        {
     470            Q_EMIT panned( m_data->pos.x() - m_data->initialPos.x(),
     471                m_data->pos.y() - m_data->initialPos.y() );
     472        }
     473    }
     474}
     475
     476/*!
     477   Handle a key press event for the observed widget.
     478
     479   \param keyEvent Key event
     480   \sa eventFilter(), widgetKeyReleaseEvent()
     481 */
     482void QwtPanner::widgetKeyPressEvent( QKeyEvent* keyEvent )
     483{
     484    if ( ( keyEvent->key() == m_data->abortKey )
     485        && ( keyEvent->modifiers() == m_data->abortKeyModifiers ) )
    488486    {
    489487        hide();
    … …  
    492490        showCursor( false );
    493491#endif
    494         d_data->pixmap = QPixmap();
    495     }
    496 }
    497 
    498 /*!
    499   Handle a key release event for the observed widget.
    500 
    501   \param keyEvent Key event
    502   \sa eventFilter(), widgetKeyReleaseEvent()
    503 */
    504 void QwtPanner::widgetKeyReleaseEvent( QKeyEvent *keyEvent )
     492        m_data->pixmap = QPixmap();
     493    }
     494}
     495
     496/*!
     497   Handle a key release event for the observed widget.
     498
     499   \param keyEvent Key event
     500   \sa eventFilter(), widgetKeyReleaseEvent()
     501 */
     502void QwtPanner::widgetKeyReleaseEvent( QKeyEvent* keyEvent )
    505503{
    506504    Q_UNUSED( keyEvent );
    … …  
    510508void QwtPanner::showCursor( bool on )
    511509{
    512     if ( on == d_data->hasCursor )
     510    if ( on == m_data->hasCursor )
    513511        return;
    514512
    515     QWidget *w = parentWidget();
    516     if ( w == NULL || d_data->cursor == NULL )
     513    QWidget* w = parentWidget();
     514    if ( w == NULL || m_data->cursor == NULL )
    517515        return;
    518516
    519     d_data->hasCursor = on;
     517    m_data->hasCursor = on;
    520518
    521519    if ( on )
    … …  
    523521        if ( w->testAttribute( Qt::WA_SetCursor ) )
    524522        {
    525             delete d_data->restoreCursor;
    526             d_data->restoreCursor = new QCursor( w->cursor() );
    527         }
    528         w->setCursor( *d_data->cursor );
     523            delete m_data->restoreCursor;
     524            m_data->restoreCursor = new QCursor( w->cursor() );
     525        }
     526        w->setCursor( *m_data->cursor );
    529527    }
    530528    else
    531529    {
    532         if ( d_data->restoreCursor )
    533         {
    534             w->setCursor( *d_data->restoreCursor );
    535             delete d_data->restoreCursor;
    536             d_data->restoreCursor = NULL;
     530        if ( m_data->restoreCursor )
     531        {
     532            w->setCursor( *m_data->restoreCursor );
     533            delete m_data->restoreCursor;
     534            m_data->restoreCursor = NULL;
    537535        }
    538536        else
    … …  
    541539}
    542540#endif
     541
     542#include "moc_qwt_panner.cpp"
  • trunk/BNC/qwt/qwt_panner.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_PANNER_H
    11 #define QWT_PANNER_H 1
     11#define QWT_PANNER_H
    1212
    1313#include "qwt_global.h"
    1414#include <qwidget.h>
    15 #include <qpixmap.h>
    1615
    1716class QCursor;
     17class QPixmap;
    1818
    1919/*!
    20   \brief QwtPanner provides panning of a widget
     20   \brief QwtPanner provides panning of a widget
    2121
    22   QwtPanner grabs the contents of a widget, that can be dragged
    23   in all directions. The offset between the start and the end position
    24   is emitted by the panned signal.
     22   QwtPanner grabs the contents of a widget, that can be dragged
     23   in all directions. The offset between the start and the end position
     24   is emitted by the panned signal.
    2525
    26   QwtPanner grabs the content of the widget into a pixmap and moves
    27   the pixmap around, without initiating any repaint events for the widget.
    28   Areas, that are not part of content are not painted  while panning.
    29   This makes panning fast enough for widgets, where
    30   repaints are too slow for mouse movements.
     26   QwtPanner grabs the content of the widget into a pixmap and moves
     27   the pixmap around, without initiating any repaint events for the widget.
     28   Areas, that are not part of content are not painted  while panning.
     29   This makes panning fast enough for widgets, where
     30   repaints are too slow for mouse movements.
    3131
    32   For widgets, where repaints are very fast it might be better to
    33   implement panning manually by mapping mouse events into paint events.
    34 */
    35 class QWT_EXPORT QwtPanner: public QWidget
     32   For widgets, where repaints are very fast it might be better to
     33   implement panning manually by mapping mouse events into paint events.
     34 */
     35class QWT_EXPORT QwtPanner : public QWidget
    3636{
    3737    Q_OBJECT
    3838
    39 public:
    40     QwtPanner( QWidget* parent );
     39  public:
     40    explicit QwtPanner( QWidget* parent );
    4141    virtual ~QwtPanner();
    4242
    … …  
    4646    void setMouseButton( Qt::MouseButton,
    4747        Qt::KeyboardModifiers = Qt::NoModifier );
    48     void getMouseButton( Qt::MouseButton &button,
    49         Qt::KeyboardModifiers & ) const;
     48    void getMouseButton( Qt::MouseButton& button,
     49        Qt::KeyboardModifiers& ) const;
    5050
    5151    void setAbortKey( int key, Qt::KeyboardModifiers = Qt::NoModifier );
    52     void getAbortKey( int &key, Qt::KeyboardModifiers & ) const;
     52    void getAbortKey( int& key, Qt::KeyboardModifiers& ) const;
    5353
    54     void setCursor( const QCursor & );
     54    void setCursor( const QCursor& );
    5555    const QCursor cursor() const;
    5656
    … …  
    6060    bool isOrientationEnabled( Qt::Orientation ) const;
    6161
    62     virtual bool eventFilter( QObject *, QEvent * );
     62    virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE;
    6363
    64 Q_SIGNALS:
     64  Q_SIGNALS:
    6565    /*!
    66       Signal emitted, when panning is done
     66       Signal emitted, when panning is done
    6767
    68       \param dx Offset in horizontal direction
    69       \param dy Offset in vertical direction
    70     */
     68       \param dx Offset in horizontal direction
     69       \param dy Offset in vertical direction
     70     */
    7171    void panned( int dx, int dy );
    7272
    7373    /*!
    74       Signal emitted, while the widget moved, but panning
    75       is not finished.
     74       Signal emitted, while the widget moved, but panning
     75       is not finished.
    7676
    77       \param dx Offset in horizontal direction
    78       \param dy Offset in vertical direction
    79     */
     77       \param dx Offset in horizontal direction
     78       \param dy Offset in vertical direction
     79     */
    8080    void moved( int dx, int dy );
    8181
    82 protected:
    83     virtual void widgetMousePressEvent( QMouseEvent * );
    84     virtual void widgetMouseReleaseEvent( QMouseEvent * );
    85     virtual void widgetMouseMoveEvent( QMouseEvent * );
    86     virtual void widgetKeyPressEvent( QKeyEvent * );
    87     virtual void widgetKeyReleaseEvent( QKeyEvent * );
     82  protected:
     83    virtual void widgetMousePressEvent( QMouseEvent* );
     84    virtual void widgetMouseReleaseEvent( QMouseEvent* );
     85    virtual void widgetMouseMoveEvent( QMouseEvent* );
     86    virtual void widgetKeyPressEvent( QKeyEvent* );
     87    virtual void widgetKeyReleaseEvent( QKeyEvent* );
    8888
    89     virtual void paintEvent( QPaintEvent * );
     89    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
    9090
    9191    virtual QBitmap contentsMask() const;
    9292    virtual QPixmap grab() const;
    9393
    94 private:
     94  private:
    9595#ifndef QT_NO_CURSOR
    9696    void showCursor( bool );
    … …  
    9898
    9999    class PrivateData;
    100     PrivateData *d_data;
     100    PrivateData* m_data;
    101101};
    102102
  • trunk/BNC/qwt/qwt_picker.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_math.h"
    1414#include "qwt_widget_overlay.h"
    15 #include <qapplication.h>
     15#include "qwt_text.h"
     16
    1617#include <qevent.h>
    1718#include <qpainter.h>
    18 #include <qframe.h>
     19#include <qpainterpath.h>
    1920#include <qcursor.h>
    20 #include <qbitmap.h>
    2121#include <qpointer.h>
    22 #include <qpaintengine.h>
    2322#include <qmath.h>
    2423
    25 static inline QRegion qwtMaskRegion( const QRect &r, int penWidth )
     24static inline QRegion qwtMaskRegion( const QRect& r, int penWidth )
    2625{
    2726    const int pw = qMax( penWidth, 1 );
    … …  
    4443}
    4544
    46 static inline QRegion qwtMaskRegion( const QLine &l, int penWidth )
     45static inline QRegion qwtMaskRegion( const QLine& l, int penWidth )
    4746{
    4847    const int pw = qMax( penWidth, 1 );
    … …  
    6564}
    6665
    67 class QwtPickerRubberband: public QwtWidgetOverlay
    68 {
    69 public:
    70     QwtPickerRubberband( QwtPicker *, QWidget * );
    71 
    72 protected:
    73     virtual void drawOverlay( QPainter * ) const;
    74     virtual QRegion maskHint() const;
    75 
    76     QwtPicker *d_picker;
    77 };
    78 
    79 class QwtPickerTracker: public QwtWidgetOverlay
    80 {
    81 public:
    82     QwtPickerTracker( QwtPicker *, QWidget * );
    83 
    84 protected:
    85     virtual void drawOverlay( QPainter * ) const;
    86     virtual QRegion maskHint() const;
    87 
    88     QwtPicker *d_picker;
    89 };
    90 
     66namespace
     67{
     68    class Rubberband QWT_FINAL : public QwtWidgetOverlay
     69    {
     70      public:
     71        Rubberband( QwtPicker* picker, QWidget* parent )
     72            : QwtWidgetOverlay( parent )
     73            , m_picker( picker )
     74        {
     75            setMaskMode( QwtWidgetOverlay::MaskHint );
     76        }
     77
     78      protected:
     79        virtual void drawOverlay( QPainter* painter ) const QWT_OVERRIDE
     80        {
     81            painter->setPen( m_picker->rubberBandPen() );
     82            m_picker->drawRubberBand( painter );
     83        }
     84
     85        virtual QRegion maskHint() const QWT_OVERRIDE
     86        {
     87            return m_picker->rubberBandMask();
     88        }
     89
     90        QwtPicker* m_picker;
     91    };
     92
     93    class Tracker QWT_FINAL : public QwtWidgetOverlay
     94    {
     95      public:
     96        Tracker( QwtPicker* picker, QWidget* parent )
     97            : QwtWidgetOverlay( parent )
     98            , m_picker( picker )
     99        {
     100            setMaskMode( QwtWidgetOverlay::MaskHint );
     101        }
     102
     103      protected:
     104        virtual void drawOverlay( QPainter* painter ) const QWT_OVERRIDE
     105        {
     106            painter->setPen( m_picker->trackerPen() );
     107            m_picker->drawTracker( painter );
     108        }
     109
     110        virtual QRegion maskHint() const QWT_OVERRIDE
     111        {
     112            return m_picker->trackerMask();
     113        }
     114
     115        QwtPicker* m_picker;
     116    };
     117}
    91118
    92119class QwtPicker::PrivateData
    93120{
    94 public:
     121  public:
    95122    PrivateData():
    96123        enabled( false ),
    … …  
    108135    bool enabled;
    109136
    110     QwtPickerMachine *stateMachine;
     137    QwtPickerMachine* stateMachine;
    111138
    112139    QwtPicker::ResizeMode resizeMode;
    … …  
    125152    bool mouseTracking; // used to save previous value
    126153
    127     QPointer< QwtPickerRubberband > rubberBandOverlay;
    128     QPointer< QwtPickerTracker> trackerOverlay;
     154    QPointer< Rubberband > rubberBandOverlay;
     155    QPointer< Tracker > trackerOverlay;
    129156
    130157    bool openGL;
    131158};
    132159
    133 QwtPickerRubberband::QwtPickerRubberband(
    134         QwtPicker *picker, QWidget *parent ):
    135     QwtWidgetOverlay( parent ),
    136     d_picker( picker )
    137 {
    138     setMaskMode( QwtWidgetOverlay::MaskHint );
    139 }
    140 
    141 QRegion QwtPickerRubberband::maskHint() const
    142 {
    143     return d_picker->rubberBandMask();
    144 }
    145 
    146 void QwtPickerRubberband::drawOverlay( QPainter *painter ) const
    147 {
    148     painter->setPen( d_picker->rubberBandPen() );
    149     d_picker->drawRubberBand( painter );
    150 }
    151 
    152 QwtPickerTracker::QwtPickerTracker(
    153         QwtPicker *picker, QWidget *parent ):
    154     QwtWidgetOverlay( parent ),
    155     d_picker( picker )
    156 {
    157     setMaskMode( QwtWidgetOverlay::MaskHint );
    158 }
    159 
    160 QRegion QwtPickerTracker::maskHint() const
    161 {
    162     return d_picker->trackerRect( font() );
    163 }
    164 
    165 void QwtPickerTracker::drawOverlay( QPainter *painter ) const
    166 {
    167     painter->setPen( d_picker->trackerPen() );
    168     d_picker->drawTracker( painter );
    169 }
    170 
    171 /*!
    172   Constructor
    173 
    174   Creates an picker that is enabled, but without a state machine.
    175   rubber band and tracker are disabled.
    176 
    177   \param parent Parent widget, that will be observed
    178  */
    179 
    180 QwtPicker::QwtPicker( QWidget *parent ):
     160/*!
     161   Constructor
     162
     163   Creates an picker that is enabled, but without a state machine.
     164   rubber band and tracker are disabled.
     165
     166   \param parent Parent widget, that will be observed
     167 */
     168
     169QwtPicker::QwtPicker( QWidget* parent ):
    181170    QObject( parent )
    182171{
    … …  
    185174
    186175/*!
    187   Constructor
    188 
    189   \param rubberBand Rubber band style
    190   \param trackerMode Tracker mode
    191   \param parent Parent widget, that will be observed
     176   Constructor
     177
     178   \param rubberBand Rubber band style
     179   \param trackerMode Tracker mode
     180   \param parent Parent widget, that will be observed
    192181 */
    193182QwtPicker::QwtPicker( RubberBand rubberBand,
    194         DisplayMode trackerMode, QWidget *parent ):
     183    DisplayMode trackerMode, QWidget* parent ):
    195184    QObject( parent )
    196185{
    … …  
    203192    setMouseTracking( false );
    204193
    205     delete d_data->stateMachine;
    206     delete d_data->rubberBandOverlay;
    207     delete d_data->trackerOverlay;
    208 
    209     delete d_data;
     194    delete m_data->stateMachine;
     195    delete m_data->rubberBandOverlay;
     196    delete m_data->trackerOverlay;
     197
     198    delete m_data;
    210199}
    211200
    212201//! Initialize the picker - used by the constructors
    213 void QwtPicker::init( QWidget *parent,
     202void QwtPicker::init( QWidget* parent,
    214203    RubberBand rubberBand, DisplayMode trackerMode )
    215204{
    216     d_data = new PrivateData;
    217 
    218     d_data->rubberBand = rubberBand;
     205    m_data = new PrivateData;
     206
     207    m_data->rubberBand = rubberBand;
    219208
    220209    if ( parent )
    … …  
    223212            parent->setFocusPolicy( Qt::WheelFocus );
    224213
    225         d_data->openGL = parent->inherits( "QGLWidget" );
    226         d_data->trackerFont = parent->font();
    227         d_data->mouseTracking = parent->hasMouseTracking();
     214        m_data->openGL = parent->inherits( "QGLWidget" );
     215        m_data->trackerFont = parent->font();
     216        m_data->mouseTracking = parent->hasMouseTracking();
    228217
    229218        setEnabled( true );
    … …  
    234223
    235224/*!
    236   Set a state machine and delete the previous one
    237 
    238   \param stateMachine State machine
    239   \sa stateMachine()
    240 */
    241 void QwtPicker::setStateMachine( QwtPickerMachine *stateMachine )
    242 {
    243     if ( d_data->stateMachine != stateMachine )
     225   Set a state machine and delete the previous one
     226
     227   \param stateMachine State machine
     228   \sa stateMachine()
     229 */
     230void QwtPicker::setStateMachine( QwtPickerMachine* stateMachine )
     231{
     232    if ( m_data->stateMachine != stateMachine )
    244233    {
    245234        reset();
    246235
    247         delete d_data->stateMachine;
    248         d_data->stateMachine = stateMachine;
    249 
    250         if ( d_data->stateMachine )
    251             d_data->stateMachine->reset();
    252     }
    253 }
    254 
    255 /*!
    256   \return Assigned state machine
    257   \sa setStateMachine()
    258 */
    259 QwtPickerMachine *QwtPicker::stateMachine()
    260 {
    261     return d_data->stateMachine;
    262 }
    263 
    264 /*!
    265   \return Assigned state machine
    266   \sa setStateMachine()
    267 */
    268 const QwtPickerMachine *QwtPicker::stateMachine() const
    269 {
    270     return d_data->stateMachine;
     236        delete m_data->stateMachine;
     237        m_data->stateMachine = stateMachine;
     238
     239        if ( m_data->stateMachine )
     240            m_data->stateMachine->reset();
     241    }
     242}
     243
     244/*!
     245   \return Assigned state machine
     246   \sa setStateMachine()
     247 */
     248QwtPickerMachine* QwtPicker::stateMachine()
     249{
     250    return m_data->stateMachine;
     251}
     252
     253/*!
     254   \return Assigned state machine
     255   \sa setStateMachine()
     256 */
     257const QwtPickerMachine* QwtPicker::stateMachine() const
     258{
     259    return m_data->stateMachine;
    271260}
    272261
    273262//! Return the parent widget, where the selection happens
    274 QWidget *QwtPicker::parentWidget()
    275 {
    276     QObject *obj = parent();
     263QWidget* QwtPicker::parentWidget()
     264{
     265    QObject* obj = parent();
    277266    if ( obj && obj->isWidgetType() )
    278         return static_cast<QWidget *>( obj );
     267        return static_cast< QWidget* >( obj );
    279268
    280269    return NULL;
    … …  
    282271
    283272//! Return the parent widget, where the selection happens
    284 const QWidget *QwtPicker::parentWidget() const
    285 {
    286     QObject *obj = parent();
     273const QWidget* QwtPicker::parentWidget() const
     274{
     275    QObject* obj = parent();
    287276    if ( obj && obj->isWidgetType() )
    288         return static_cast< const QWidget *>( obj );
     277        return static_cast< const QWidget* >( obj );
    289278
    290279    return NULL;
    … …  
    292281
    293282/*!
    294   Set the rubber band style
    295 
    296   \param rubberBand Rubber band style
     283   Set the rubber band style
     284
     285   \param rubberBand Rubber band style
    297286         The default value is NoRubberBand.
    298287
    299   \sa rubberBand(), RubberBand, setRubberBandPen()
    300 */
     288   \sa rubberBand(), RubberBand, setRubberBandPen()
     289 */
    301290void QwtPicker::setRubberBand( RubberBand rubberBand )
    302291{
    303     d_data->rubberBand = rubberBand;
    304 }
    305 
    306 /*!
    307   \return Rubber band style
    308   \sa setRubberBand(), RubberBand, rubberBandPen()
    309 */
     292    m_data->rubberBand = rubberBand;
     293}
     294
     295/*!
     296   \return Rubber band style
     297   \sa setRubberBand(), RubberBand, rubberBandPen()
     298 */
    310299QwtPicker::RubberBand QwtPicker::rubberBand() const
    311300{
    312     return d_data->rubberBand;
    313 }
    314 
    315 /*!
    316   \brief Set the display mode of the tracker.
    317 
    318   A tracker displays information about current position of
    319   the cursor as a string. The display mode controls
    320   if the tracker has to be displayed whenever the observed
    321   widget has focus and cursor (AlwaysOn), never (AlwaysOff), or
    322   only when the selection is active (ActiveOnly).
    323 
    324   \param mode Tracker display mode
    325 
    326   \warning In case of AlwaysOn, mouseTracking will be enabled
     301    return m_data->rubberBand;
     302}
     303
     304/*!
     305   \brief Set the display mode of the tracker.
     306
     307   A tracker displays information about current position of
     308   the cursor as a string. The display mode controls
     309   if the tracker has to be displayed whenever the observed
     310   widget has focus and cursor (AlwaysOn), never (AlwaysOff), or
     311   only when the selection is active (ActiveOnly).
     312
     313   \param mode Tracker display mode
     314
     315   \warning In case of AlwaysOn, mouseTracking will be enabled
    327316           for the observed widget.
    328   \sa trackerMode(), DisplayMode
    329 */
     317   \sa trackerMode(), DisplayMode
     318 */
    330319
    331320void QwtPicker::setTrackerMode( DisplayMode mode )
    332321{
    333     if ( d_data->trackerMode != mode )
    334     {
    335         d_data->trackerMode = mode;
    336         setMouseTracking( d_data->trackerMode == AlwaysOn );
    337     }
    338 }
    339 
    340 /*!
    341   \return Tracker display mode
    342   \sa setTrackerMode(), DisplayMode
    343 */
     322    if ( m_data->trackerMode != mode )
     323    {
     324        m_data->trackerMode = mode;
     325        setMouseTracking( m_data->trackerMode == AlwaysOn );
     326    }
     327}
     328
     329/*!
     330   \return Tracker display mode
     331   \sa setTrackerMode(), DisplayMode
     332 */
    344333QwtPicker::DisplayMode QwtPicker::trackerMode() const
    345334{
    346     return d_data->trackerMode;
    347 }
    348 
    349 /*!
    350   \brief Set the resize mode.
    351 
    352   The resize mode controls what to do with the selected points of an active
    353   selection when the observed widget is resized.
    354 
    355   Stretch means the points are scaled according to the new
    356   size, KeepSize means the points remain unchanged.
    357 
    358   The default mode is Stretch.
    359 
    360   \param mode Resize mode
    361   \sa resizeMode(), ResizeMode
    362 */
     335    return m_data->trackerMode;
     336}
     337
     338/*!
     339   \brief Set the resize mode.
     340
     341   The resize mode controls what to do with the selected points of an active
     342   selection when the observed widget is resized.
     343
     344   Stretch means the points are scaled according to the new
     345   size, KeepSize means the points remain unchanged.
     346
     347   The default mode is Stretch.
     348
     349   \param mode Resize mode
     350   \sa resizeMode(), ResizeMode
     351 */
    363352void QwtPicker::setResizeMode( ResizeMode mode )
    364353{
    365     d_data->resizeMode = mode;
    366 }
    367 
    368 /*!
    369   \return Resize mode
    370   \sa setResizeMode(), ResizeMode
    371 */
     354    m_data->resizeMode = mode;
     355}
     356
     357/*!
     358   \return Resize mode
     359   \sa setResizeMode(), ResizeMode
     360 */
    372361
    373362QwtPicker::ResizeMode QwtPicker::resizeMode() const
    374363{
    375     return d_data->resizeMode;
    376 }
    377 
    378 /*!
    379   \brief En/disable the picker
    380 
    381   When enabled is true an event filter is installed for
    382   the observed widget, otherwise the event filter is removed.
    383 
    384   \param enabled true or false
    385   \sa isEnabled(), eventFilter()
    386 */
     364    return m_data->resizeMode;
     365}
     366
     367/*!
     368   \brief En/disable the picker
     369
     370   When enabled is true an event filter is installed for
     371   the observed widget, otherwise the event filter is removed.
     372
     373   \param enabled true or false
     374   \sa isEnabled(), eventFilter()
     375 */
    387376void QwtPicker::setEnabled( bool enabled )
    388377{
    389     if ( d_data->enabled != enabled )
    390     {
    391         d_data->enabled = enabled;
    392 
    393         QWidget *w = parentWidget();
     378    if ( m_data->enabled != enabled )
     379    {
     380        m_data->enabled = enabled;
     381
     382        QWidget* w = parentWidget();
    394383        if ( w )
    395384        {
    … …  
    405394
    406395/*!
    407   \return true when enabled, false otherwise
    408   \sa setEnabled(), eventFilter()
    409 */
     396   \return true when enabled, false otherwise
     397   \sa setEnabled(), eventFilter()
     398 */
    410399
    411400bool QwtPicker::isEnabled() const
    412401{
    413     return d_data->enabled;
    414 }
    415 
    416 /*!
    417   Set the font for the tracker
    418 
    419   \param font Tracker font
    420   \sa trackerFont(), setTrackerMode(), setTrackerPen()
    421 */
    422 void QwtPicker::setTrackerFont( const QFont &font )
    423 {
    424     if ( font != d_data->trackerFont )
    425     {
    426         d_data->trackerFont = font;
     402    return m_data->enabled;
     403}
     404
     405/*!
     406   Set the font for the tracker
     407
     408   \param font Tracker font
     409   \sa trackerFont(), setTrackerMode(), setTrackerPen()
     410 */
     411void QwtPicker::setTrackerFont( const QFont& font )
     412{
     413    if ( font != m_data->trackerFont )
     414    {
     415        m_data->trackerFont = font;
    427416        updateDisplay();
    428417    }
    … …  
    430419
    431420/*!
    432   \return Tracker font
    433   \sa setTrackerFont(), trackerMode(), trackerPen()
    434 */
     421   \return Tracker font
     422   \sa setTrackerFont(), trackerMode(), trackerPen()
     423 */
    435424
    436425QFont QwtPicker::trackerFont() const
    437426{
    438     return d_data->trackerFont;
    439 }
    440 
    441 /*!
    442   Set the pen for the tracker
    443 
    444   \param pen Tracker pen
    445   \sa trackerPen(), setTrackerMode(), setTrackerFont()
    446 */
    447 void QwtPicker::setTrackerPen( const QPen &pen )
    448 {
    449     if ( pen != d_data->trackerPen )
    450     {
    451         d_data->trackerPen = pen;
     427    return m_data->trackerFont;
     428}
     429
     430/*!
     431   Set the pen for the tracker
     432
     433   \param pen Tracker pen
     434   \sa trackerPen(), setTrackerMode(), setTrackerFont()
     435 */
     436void QwtPicker::setTrackerPen( const QPen& pen )
     437{
     438    if ( pen != m_data->trackerPen )
     439    {
     440        m_data->trackerPen = pen;
    452441        updateDisplay();
    453442    }
    … …  
    455444
    456445/*!
    457   \return Tracker pen
    458   \sa setTrackerPen(), trackerMode(), trackerFont()
    459 */
     446   \return Tracker pen
     447   \sa setTrackerPen(), trackerMode(), trackerFont()
     448 */
    460449QPen QwtPicker::trackerPen() const
    461450{
    462     return d_data->trackerPen;
    463 }
    464 
    465 /*!
    466   Set the pen for the rubberband
    467 
    468   \param pen Rubber band pen
    469   \sa rubberBandPen(), setRubberBand()
    470 */
    471 void QwtPicker::setRubberBandPen( const QPen &pen )
    472 {
    473     if ( pen != d_data->rubberBandPen )
    474     {
    475         d_data->rubberBandPen = pen;
     451    return m_data->trackerPen;
     452}
     453
     454/*!
     455   Set the pen for the rubberband
     456
     457   \param pen Rubber band pen
     458   \sa rubberBandPen(), setRubberBand()
     459 */
     460void QwtPicker::setRubberBandPen( const QPen& pen )
     461{
     462    if ( pen != m_data->rubberBandPen )
     463    {
     464        m_data->rubberBandPen = pen;
    476465        updateDisplay();
    477466    }
    … …  
    479468
    480469/*!
    481   \return Rubber band pen
    482   \sa setRubberBandPen(), rubberBand()
    483 */
     470   \return Rubber band pen
     471   \sa setRubberBandPen(), rubberBand()
     472 */
    484473QPen QwtPicker::rubberBandPen() const
    485474{
    486     return d_data->rubberBandPen;
     475    return m_data->rubberBandPen;
    487476}
    488477
    … …  
    498487   \param pos Position
    499488   \return Converted position as string
    500 */
    501 
    502 QwtText QwtPicker::trackerText( const QPoint &pos ) const
     489 */
     490
     491QwtText QwtPicker::trackerText( const QPoint& pos ) const
    503492{
    504493    QString label;
    … …  
    507496    {
    508497        case HLineRubberBand:
    509             label.sprintf( "%d", pos.y() );
     498            label = QString::number( pos.y() );
    510499            break;
    511500        case VLineRubberBand:
    512             label.sprintf( "%d", pos.x() );
     501            label = QString::number( pos.x() );
    513502            break;
    514503        default:
    515             label.sprintf( "%d, %d", pos.x(), pos.y() );
     504            label = QString::number( pos.x() ) + ", " + QString::number( pos.y() );
    516505    }
    517506    return label;
    … …  
    519508
    520509/*!
    521   Calculate the mask for the rubber band overlay
    522 
    523   \return Region for the mask
    524   \sa QWidget::setMask()
     510   Calculate the mask for the tracker overlay
     511
     512   \return Region with one rectangle: trackerRect( trackerFont() );
     513   \sa QWidget::setMask(), trackerRect()
     514 */
     515QRegion QwtPicker::trackerMask() const
     516{
     517    return trackerRect( m_data->trackerFont );
     518}
     519
     520/*!
     521   Calculate the mask for the rubber band overlay
     522
     523   \return Region for the mask
     524   \sa QWidget::setMask()
    525525 */
    526526QRegion QwtPicker::rubberBandMask() const
    … …  
    534534    }
    535535
    536     const QPolygon pa = adjustedPoints( d_data->pickedPoints );
     536    const QPolygon pa = adjustedPoints( m_data->pickedPoints );
    537537
    538538    QwtPickerMachine::SelectionType selectionType =
    539539        QwtPickerMachine::NoSelection;
    540540
    541     if ( d_data->stateMachine )
    542         selectionType = d_data->stateMachine->selectionType();
     541    if ( m_data->stateMachine )
     542        selectionType = m_data->stateMachine->selectionType();
     543
     544    const int pw = qCeil( rubberBandPen().widthF()
     545        * QwtPainter::devicePixelRatio( parentWidget() ) );
    543546
    544547    switch ( selectionType )
    … …  
    551554
    552555            const QPoint pos = pa[0];
    553             const int pw = rubberBandPen().width();
    554556
    555557            const QRect pRect = pickArea().boundingRect().toRect();
    … …  
    586588                return mask;
    587589
    588             const int pw = rubberBandPen().width();
    589 
    590590            switch ( rubberBand() )
    591591            {
    … …  
    609609        case QwtPickerMachine::PolygonSelection:
    610610        {
    611             const int pw = rubberBandPen().width();
    612611            if ( pw <= 1 )
    613612            {
    … …  
    634633
    635634   \sa rubberBand(), RubberBand
    636 */
    637 
    638 void QwtPicker::drawRubberBand( QPainter *painter ) const
     635 */
     636
     637void QwtPicker::drawRubberBand( QPainter* painter ) const
    639638{
    640639    if ( !isActive() || rubberBand() == NoRubberBand ||
    … …  
    644643    }
    645644
    646     const QPolygon pa = adjustedPoints( d_data->pickedPoints );
     645    const QPolygon pa = adjustedPoints( m_data->pickedPoints );
    647646
    648647    QwtPickerMachine::SelectionType selectionType =
    649648        QwtPickerMachine::NoSelection;
    650649
    651     if ( d_data->stateMachine )
    652         selectionType = d_data->stateMachine->selectionType();
     650    if ( m_data->stateMachine )
     651        selectionType = m_data->stateMachine->selectionType();
    653652
    654653    switch ( selectionType )
    … …  
    729728   \param painter Painter
    730729   \sa trackerRect(), trackerText()
    731 */
    732 
    733 void QwtPicker::drawTracker( QPainter *painter ) const
     730 */
     731
     732void QwtPicker::drawTracker( QPainter* painter ) const
    734733{
    735734    const QRect textRect = trackerRect( painter->font() );
    736735    if ( !textRect.isEmpty() )
    737736    {
    738         const QwtText label = trackerText( d_data->trackerPosition );
     737        const QwtText label = trackerText( m_data->trackerPosition );
    739738        if ( !label.isEmpty() )
    740739            label.draw( painter, textRect );
    … …  
    759758   point is the center of the selected rectangle.
    760759
    761   \par Example
    762   \code
     760   \par Example
     761   \code
    763762    QPolygon MyPicker::adjustedPoints( const QPolygon &points ) const
    764763    {
    … …  
    777776        return adjusted;
    778777    }
    779   \endcode
    780   \endpar
    781 
    782   \param points Selected points
    783   \return Selected points unmodified
    784 */
    785 QPolygon QwtPicker::adjustedPoints( const QPolygon &points ) const
     778   \endcode
     779
     780   \param points Selected points
     781   \return Selected points unmodified
     782 */
     783QPolygon QwtPicker::adjustedPoints( const QPolygon& points ) const
    786784{
    787785    return points;
    … …  
    789787
    790788/*!
    791   \return Selected points
    792   \sa pickedPoints(), adjustedPoints()
    793 */
     789   \return Selected points
     790   \sa pickedPoints(), adjustedPoints()
     791 */
    794792QPolygon QwtPicker::selection() const
    795793{
    796     return adjustedPoints( d_data->pickedPoints );
     794    return adjustedPoints( m_data->pickedPoints );
    797795}
    798796
    … …  
    800798QPoint QwtPicker::trackerPosition() const
    801799{
    802     return d_data->trackerPosition;
     800    return m_data->trackerPosition;
    803801}
    804802
    … …  
    811809
    812810   \sa trackerPosition()
    813 */
    814 QRect QwtPicker::trackerRect( const QFont &font ) const
     811 */
     812QRect QwtPicker::trackerRect( const QFont& font ) const
    815813{
    816814    if ( trackerMode() == AlwaysOff ||
    … …  
    820818    }
    821819
    822     if ( d_data->trackerPosition.x() < 0 || d_data->trackerPosition.y() < 0 )
     820    if ( m_data->trackerPosition.x() < 0 || m_data->trackerPosition.y() < 0 )
    823821        return QRect();
    824822
    825     QwtText text = trackerText( d_data->trackerPosition );
     823    QwtText text = trackerText( m_data->trackerPosition );
    826824    if ( text.isEmpty() )
    827825        return QRect();
    828826
    829827    const QSizeF textSize = text.textSize( font );
    830     QRect textRect( 0, 0, qCeil( textSize.width() ), qCeil( textSize.height() ) );
    831 
    832     const QPoint &pos = d_data->trackerPosition;
     828
     829    const int w = qwtCeil( textSize.width() );
     830    const int h = qwtCeil( textSize.height() );
     831
     832    return trackerRect( QSize( w, h ) );
     833}
     834
     835/*!
     836   Calculate the geometry of the tracker that is needed to display
     837   information of a specific size at the tracker position
     838   
     839   \param size Size
     840   \return Bounding rectangle of the tracker
     841   
     842   \sa trackerPosition()
     843 */
     844QRect QwtPicker::trackerRect( const QSize& size ) const
     845{
     846    const QPoint& pos = m_data->trackerPosition;
     847    QRect infoRect( 0, 0, size.width(), size.height() );
    833848
    834849    int alignment = 0;
    835     if ( isActive() && d_data->pickedPoints.count() > 1
     850    if ( isActive() && m_data->pickedPoints.count() > 1
    836851        && rubberBand() != NoRubberBand )
    837852    {
    838853        const QPoint last =
    839             d_data->pickedPoints[ d_data->pickedPoints.count() - 2 ];
     854            m_data->pickedPoints[ m_data->pickedPoints.count() - 2 ];
    840855
    841856        alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft;
    … …  
    843858    }
    844859    else
     860    {
    845861        alignment = Qt::AlignTop | Qt::AlignRight;
     862    }
    846863
    847864    const int margin = 5;
    … …  
    849866    int x = pos.x();
    850867    if ( alignment & Qt::AlignLeft )
    851         x -= textRect.width() + margin;
     868        x -= infoRect.width() + margin;
    852869    else if ( alignment & Qt::AlignRight )
    853870        x += margin;
    … …  
    857874        y += margin;
    858875    else if ( alignment & Qt::AlignTop )
    859         y -= textRect.height() + margin;
    860 
    861     textRect.moveTopLeft( QPoint( x, y ) );
     876        y -= infoRect.height() + margin;
     877
     878    infoRect.moveTopLeft( QPoint( x, y ) );
    862879
    863880    const QRect pickRect = pickArea().boundingRect().toRect();
    864881
    865     int right = qMin( textRect.right(), pickRect.right() - margin );
    866     int bottom = qMin( textRect.bottom(), pickRect.bottom() - margin );
    867     textRect.moveBottomRight( QPoint( right, bottom ) );
    868 
    869     int left = qMax( textRect.left(), pickRect.left() + margin );
    870     int top = qMax( textRect.top(), pickRect.top() + margin );
    871     textRect.moveTopLeft( QPoint( left, top ) );
    872 
    873     return textRect;
    874 }
    875 
    876 /*!
    877   \brief Event filter
    878 
    879   When isEnabled() is true all events of the observed widget are filtered.
    880   Mouse and keyboard events are translated into widgetMouse- and widgetKey-
    881   and widgetWheel-events. Paint and Resize events are handled to keep
    882   rubber band and tracker up to date.
    883 
    884   \param object Object to be filtered
    885   \param event Event
    886 
    887   \return Always false.
    888 
    889   \sa widgetEnterEvent(), widgetLeaveEvent(),
     882    int right = qMin( infoRect.right(), pickRect.right() - margin );
     883    int bottom = qMin( infoRect.bottom(), pickRect.bottom() - margin );
     884    infoRect.moveBottomRight( QPoint( right, bottom ) );
     885
     886    int left = qMax( infoRect.left(), pickRect.left() + margin );
     887    int top = qMax( infoRect.top(), pickRect.top() + margin );
     888    infoRect.moveTopLeft( QPoint( left, top ) );
     889
     890    return infoRect;
     891}
     892
     893/*!
     894   \brief Event filter
     895
     896   When isEnabled() is true all events of the observed widget are filtered.
     897   Mouse and keyboard events are translated into widgetMouse- and widgetKey-
     898   and widgetWheel-events. Paint and Resize events are handled to keep
     899   rubber band and tracker up to date.
     900
     901   \param object Object to be filtered
     902   \param event Event
     903
     904   \return Always false.
     905
     906   \sa widgetEnterEvent(), widgetLeaveEvent(),
    890907      widgetMousePressEvent(), widgetMouseReleaseEvent(),
    891908      widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(),
    892909      widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent(),
    893910      QObject::installEventFilter(), QObject::event()
    894 */
    895 bool QwtPicker::eventFilter( QObject *object, QEvent *event )
     911 */
     912bool QwtPicker::eventFilter( QObject* object, QEvent* event )
    896913{
    897914    if ( object && object == parentWidget() )
    … …  
    901918            case QEvent::Resize:
    902919            {
    903                 const QResizeEvent *re = static_cast<QResizeEvent *>( event );
     920                const QResizeEvent* re = static_cast< QResizeEvent* >( event );
    904921
    905922                /*
    906923                   Adding/deleting additional event filters inside of an event filter
    907                    is not safe dues to the implementation in Qt ( changing alist while iterating ).
     924                   is not safe dues to the implementation in Qt ( changing a list while iterating ).
    908925                   So we create the overlays in a way, that they don't install en event filter
    909926                   ( parent set to NULL ) and do the resizing here.
    910927                 */
    911                 if ( d_data->trackerOverlay )
    912                     d_data->trackerOverlay->resize( re->size() );
    913 
    914                 if ( d_data->rubberBandOverlay )
    915                     d_data->rubberBandOverlay->resize( re->size() );
    916 
    917                 if ( d_data->resizeMode == Stretch )
     928                if ( m_data->trackerOverlay )
     929                    m_data->trackerOverlay->resize( re->size() );
     930
     931                if ( m_data->rubberBandOverlay )
     932                    m_data->rubberBandOverlay->resize( re->size() );
     933
     934                if ( m_data->resizeMode == Stretch )
    918935                    stretchSelection( re->oldSize(), re->size() );
    919936
    … …  
    933950            case QEvent::MouseButtonPress:
    934951            {
    935                 widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );
     952                widgetMousePressEvent( static_cast< QMouseEvent* >( event ) );
    936953                break;
    937954            }
    938955            case QEvent::MouseButtonRelease:
    939956            {
    940                 widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );
     957                widgetMouseReleaseEvent( static_cast< QMouseEvent* >( event ) );
    941958                break;
    942959            }
    943960            case QEvent::MouseButtonDblClick:
    944961            {
    945                 widgetMouseDoubleClickEvent( static_cast<QMouseEvent *>( event ) );
     962                widgetMouseDoubleClickEvent( static_cast< QMouseEvent* >( event ) );
    946963                break;
    947964            }
    948965            case QEvent::MouseMove:
    949966            {
    950                 widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );
     967                widgetMouseMoveEvent( static_cast< QMouseEvent* >( event ) );
    951968                break;
    952969            }
    953970            case QEvent::KeyPress:
    954971            {
    955                 widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );
     972                widgetKeyPressEvent( static_cast< QKeyEvent* >( event ) );
    956973                break;
    957974            }
    958975            case QEvent::KeyRelease:
    959976            {
    960                 widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );
     977                widgetKeyReleaseEvent( static_cast< QKeyEvent* >( event ) );
    961978                break;
    962979            }
    963980            case QEvent::Wheel:
    964981            {
    965                 widgetWheelEvent( static_cast<QWheelEvent *>( event ) );
     982                widgetWheelEvent( static_cast< QWheelEvent* >( event ) );
    966983                break;
    967984            }
    … …  
    974991
    975992/*!
    976   Handle a mouse press event for the observed widget.
    977 
    978   \param mouseEvent Mouse event
    979 
    980   \sa eventFilter(), widgetMouseReleaseEvent(),
     993   Handle a mouse press event for the observed widget.
     994
     995   \param mouseEvent Mouse event
     996
     997   \sa eventFilter(), widgetMouseReleaseEvent(),
    981998      widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(),
    982999      widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent()
    983 */
    984 void QwtPicker::widgetMousePressEvent( QMouseEvent *mouseEvent )
     1000 */
     1001void QwtPicker::widgetMousePressEvent( QMouseEvent* mouseEvent )
    9851002{
    9861003    transition( mouseEvent );
    … …  
    9881005
    9891006/*!
    990   Handle a mouse move event for the observed widget.
    991 
    992   \param mouseEvent Mouse event
    993 
    994   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
     1007   Handle a mouse move event for the observed widget.
     1008
     1009   \param mouseEvent Mouse event
     1010
     1011   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
    9951012      widgetMouseDoubleClickEvent(),
    9961013      widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent()
    997 */
    998 void QwtPicker::widgetMouseMoveEvent( QMouseEvent *mouseEvent )
     1014 */
     1015void QwtPicker::widgetMouseMoveEvent( QMouseEvent* mouseEvent )
    9991016{
    10001017    if ( pickArea().contains( mouseEvent->pos() ) )
    1001         d_data->trackerPosition = mouseEvent->pos();
     1018        m_data->trackerPosition = mouseEvent->pos();
    10021019    else
    1003         d_data->trackerPosition = QPoint( -1, -1 );
     1020        m_data->trackerPosition = QPoint( -1, -1 );
    10041021
    10051022    if ( !isActive() )
    … …  
    10101027
    10111028/*!
    1012   Handle a enter event for the observed widget.
    1013 
    1014   \param event Qt event
    1015 
    1016   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
     1029   Handle a enter event for the observed widget.
     1030
     1031   \param event Qt event
     1032
     1033   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
    10171034      widgetMouseDoubleClickEvent(),
    10181035      widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent()
    1019 */
    1020 void QwtPicker::widgetEnterEvent( QEvent *event )
     1036 */
     1037void QwtPicker::widgetEnterEvent( QEvent* event )
    10211038{
    10221039    transition( event );
    … …  
    10241041
    10251042/*!
    1026   Handle a leave event for the observed widget.
    1027 
    1028   \param event Qt event
    1029 
    1030   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
     1043   Handle a leave event for the observed widget.
     1044
     1045   \param event Qt event
     1046
     1047   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
    10311048      widgetMouseDoubleClickEvent(),
    10321049      widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent()
    1033 */
    1034 void QwtPicker::widgetLeaveEvent( QEvent *event )
     1050 */
     1051void QwtPicker::widgetLeaveEvent( QEvent* event )
    10351052{
    10361053    transition( event );
    10371054
    1038     d_data->trackerPosition = QPoint( -1, -1 );
     1055    m_data->trackerPosition = QPoint( -1, -1 );
    10391056    if ( !isActive() )
    10401057        updateDisplay();
    … …  
    10421059
    10431060/*!
    1044   Handle a mouse release event for the observed widget.
    1045 
    1046   \param mouseEvent Mouse event
    1047 
    1048   \sa eventFilter(), widgetMousePressEvent(),
     1061   Handle a mouse release event for the observed widget.
     1062
     1063   \param mouseEvent Mouse event
     1064
     1065   \sa eventFilter(), widgetMousePressEvent(),
    10491066      widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(),
    10501067      widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent()
    1051 */
    1052 void QwtPicker::widgetMouseReleaseEvent( QMouseEvent *mouseEvent )
     1068 */
     1069void QwtPicker::widgetMouseReleaseEvent( QMouseEvent* mouseEvent )
    10531070{
    10541071    transition( mouseEvent );
    … …  
    10561073
    10571074/*!
    1058   Handle mouse double click event for the observed widget.
    1059 
    1060   \param mouseEvent Mouse event
    1061 
    1062   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
     1075   Handle mouse double click event for the observed widget.
     1076
     1077   \param mouseEvent Mouse event
     1078
     1079   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
    10631080      widgetMouseMoveEvent(),
    10641081      widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent()
    1065 */
    1066 void QwtPicker::widgetMouseDoubleClickEvent( QMouseEvent *mouseEvent )
     1082 */
     1083void QwtPicker::widgetMouseDoubleClickEvent( QMouseEvent* mouseEvent )
    10671084{
    10681085    transition( mouseEvent );
    … …  
    10711088
    10721089/*!
    1073   Handle a wheel event for the observed widget.
    1074 
    1075   Move the last point of the selection in case of isActive() == true
    1076 
    1077   \param wheelEvent Wheel event
    1078 
    1079   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
     1090   Handle a wheel event for the observed widget.
     1091
     1092   Move the last point of the selection in case of isActive() == true
     1093
     1094   \param wheelEvent Wheel event
     1095
     1096   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
    10801097      widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(),
    10811098      widgetKeyPressEvent(), widgetKeyReleaseEvent()
    1082 */
    1083 void QwtPicker::widgetWheelEvent( QWheelEvent *wheelEvent )
    1084 {
    1085     if ( pickArea().contains( wheelEvent->pos() ) )
    1086         d_data->trackerPosition = wheelEvent->pos();
     1099 */
     1100void QwtPicker::widgetWheelEvent( QWheelEvent* wheelEvent )
     1101{
     1102#if QT_VERSION < 0x050e00
     1103    const QPoint wheelPos = wheelEvent->pos();
     1104#else
     1105    const QPoint wheelPos = wheelEvent->position().toPoint();
     1106#endif
     1107    if ( pickArea().contains( wheelPos ) )
     1108        m_data->trackerPosition = wheelPos;
    10871109    else
    1088         d_data->trackerPosition = QPoint( -1, -1 );
     1110        m_data->trackerPosition = QPoint( -1, -1 );
    10891111
    10901112    updateDisplay();
    … …  
    10941116
    10951117/*!
    1096   Handle a key press event for the observed widget.
    1097 
    1098   Selections can be completely done by the keyboard. The arrow keys
    1099   move the cursor, the abort key aborts a selection. All other keys
    1100   are handled by the current state machine.
    1101 
    1102   \param keyEvent Key event
    1103 
    1104   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
     1118   Handle a key press event for the observed widget.
     1119
     1120   Selections can be completely done by the keyboard. The arrow keys
     1121   move the cursor, the abort key aborts a selection. All other keys
     1122   are handled by the current state machine.
     1123
     1124   \param keyEvent Key event
     1125
     1126   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
    11051127      widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(),
    11061128      widgetWheelEvent(), widgetKeyReleaseEvent(), stateMachine(),
    11071129      QwtEventPattern::KeyPatternCode
    1108 */
    1109 void QwtPicker::widgetKeyPressEvent( QKeyEvent *keyEvent )
     1130 */
     1131void QwtPicker::widgetKeyPressEvent( QKeyEvent* keyEvent )
    11101132{
    11111133    int dx = 0;
    … …  
    11491171
    11501172/*!
    1151   Handle a key release event for the observed widget.
    1152 
    1153   Passes the event to the state machine.
    1154 
    1155   \param keyEvent Key event
    1156 
    1157   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
     1173   Handle a key release event for the observed widget.
     1174
     1175   Passes the event to the state machine.
     1176
     1177   \param keyEvent Key event
     1178
     1179   \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(),
    11581180      widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(),
    11591181      widgetWheelEvent(), widgetKeyPressEvent(), stateMachine()
    1160 */
    1161 void QwtPicker::widgetKeyReleaseEvent( QKeyEvent *keyEvent )
     1182 */
     1183void QwtPicker::widgetKeyReleaseEvent( QKeyEvent* keyEvent )
    11621184{
    11631185    transition( keyEvent );
    … …  
    11651187
    11661188/*!
    1167   Passes an event to the state machine and executes the resulting
    1168   commands. Append and Move commands use the current position
    1169   of the cursor ( QCursor::pos() ).
    1170 
    1171   \param event Event
    1172 */
    1173 void QwtPicker::transition( const QEvent *event )
    1174 {
    1175     if ( !d_data->stateMachine )
     1189   Passes an event to the state machine and executes the resulting
     1190   commands. Append and Move commands use the current position
     1191   of the cursor ( QCursor::pos() ).
     1192
     1193   \param event Event
     1194 */
     1195void QwtPicker::transition( const QEvent* event )
     1196{
     1197    if ( !m_data->stateMachine )
    11761198        return;
    11771199
    1178     const QList<QwtPickerMachine::Command> commandList =
    1179         d_data->stateMachine->transition( *this, event );
     1200    const QList< QwtPickerMachine::Command > commandList =
     1201        m_data->stateMachine->transition( *this, event );
    11801202
    11811203    QPoint pos;
    … …  
    11871209        case QEvent::MouseMove:
    11881210        {
    1189             const QMouseEvent *me =
    1190                 static_cast< const QMouseEvent * >( event );
     1211            const QMouseEvent* me =
     1212                static_cast< const QMouseEvent* >( event );
    11911213            pos = me->pos();
    11921214            break;
    … …  
    12301252
    12311253/*!
    1232   Open a selection setting the state to active
    1233 
    1234   \sa isActive(), end(), append(), move()
    1235 */
     1254   Open a selection setting the state to active
     1255
     1256   \sa isActive(), end(), append(), move()
     1257 */
    12361258void QwtPicker::begin()
    12371259{
    1238     if ( d_data->isActive )
     1260    if ( m_data->isActive )
    12391261        return;
    12401262
    1241     d_data->pickedPoints.clear();
    1242     d_data->isActive = true;
     1263    m_data->pickedPoints.clear();
     1264    m_data->isActive = true;
    12431265    Q_EMIT activated( true );
    12441266
    12451267    if ( trackerMode() != AlwaysOff )
    12461268    {
    1247         if ( d_data->trackerPosition.x() < 0 || d_data->trackerPosition.y() < 0 )
    1248         {
    1249             QWidget *w = parentWidget();
     1269        if ( m_data->trackerPosition.x() < 0 || m_data->trackerPosition.y() < 0 )
     1270        {
     1271            QWidget* w = parentWidget();
    12501272            if ( w )
    1251                 d_data->trackerPosition = w->mapFromGlobal( QCursor::pos() );
     1273                m_data->trackerPosition = w->mapFromGlobal( QCursor::pos() );
    12521274        }
    12531275    }
    … …  
    12581280
    12591281/*!
    1260   \brief Close a selection setting the state to inactive.
    1261 
    1262   The selection is validated and maybe fixed by accept().
    1263 
    1264   \param ok If true, complete the selection and emit a selected signal
     1282   \brief Close a selection setting the state to inactive.
     1283
     1284   The selection is validated and maybe fixed by accept().
     1285
     1286   \param ok If true, complete the selection and emit a selected signal
    12651287            otherwise discard the selection.
    1266   \return true if the selection is accepted, false otherwise
    1267   \sa isActive(), begin(), append(), move(), selected(), accept()
    1268 */
     1288   \return true if the selection is accepted, false otherwise
     1289   \sa isActive(), begin(), append(), move(), selected(), accept()
     1290 */
    12691291bool QwtPicker::end( bool ok )
    12701292{
    1271     if ( d_data->isActive )
     1293    if ( m_data->isActive )
    12721294    {
    12731295        setMouseTracking( false );
    12741296
    1275         d_data->isActive = false;
     1297        m_data->isActive = false;
    12761298        Q_EMIT activated( false );
    12771299
    12781300        if ( trackerMode() == ActiveOnly )
    1279             d_data->trackerPosition = QPoint( -1, -1 );
     1301            m_data->trackerPosition = QPoint( -1, -1 );
    12801302
    12811303        if ( ok )
    1282             ok = accept( d_data->pickedPoints );
     1304            ok = accept( m_data->pickedPoints );
    12831305
    12841306        if ( ok )
    1285             Q_EMIT selected( d_data->pickedPoints );
     1307            Q_EMIT selected( m_data->pickedPoints );
    12861308        else
    1287             d_data->pickedPoints.clear();
     1309            m_data->pickedPoints.clear();
    12881310
    12891311        updateDisplay();
    … …  
    12971319/*!
    12981320   Reset the state machine and terminate ( end(false) ) the selection
    1299 */
     1321 */
    13001322void QwtPicker::reset()
    13011323{
    1302     if ( d_data->stateMachine )
    1303         d_data->stateMachine->reset();
     1324    if ( m_data->stateMachine )
     1325        m_data->stateMachine->reset();
    13041326
    13051327    if ( isActive() )
    … …  
    13081330
    13091331/*!
    1310   Append a point to the selection and update rubber band and tracker.
    1311   The appended() signal is emitted.
    1312 
    1313   \param pos Additional point
    1314 
    1315   \sa isActive(), begin(), end(), move(), appended()
    1316 */
    1317 void QwtPicker::append( const QPoint &pos )
    1318 {
    1319     if ( d_data->isActive )
    1320     {
    1321         d_data->pickedPoints += pos;
     1332   Append a point to the selection and update rubber band and tracker.
     1333   The appended() signal is emitted.
     1334
     1335   \param pos Additional point
     1336
     1337   \sa isActive(), begin(), end(), move(), appended()
     1338 */
     1339void QwtPicker::append( const QPoint& pos )
     1340{
     1341    if ( m_data->isActive )
     1342    {
     1343        m_data->pickedPoints += pos;
    13221344
    13231345        updateDisplay();
    … …  
    13271349
    13281350/*!
    1329   Move the last point of the selection
    1330   The moved() signal is emitted.
    1331 
    1332   \param pos New position
    1333   \sa isActive(), begin(), end(), append()
    1334 */
    1335 void QwtPicker::move( const QPoint &pos )
    1336 {
    1337     if ( d_data->isActive && !d_data->pickedPoints.isEmpty() )
    1338     {
    1339         QPoint &point = d_data->pickedPoints.last();
     1351   Move the last point of the selection
     1352   The moved() signal is emitted.
     1353
     1354   \param pos New position
     1355   \sa isActive(), begin(), end(), append()
     1356 */
     1357void QwtPicker::move( const QPoint& pos )
     1358{
     1359    if ( m_data->isActive && !m_data->pickedPoints.isEmpty() )
     1360    {
     1361        QPoint& point = m_data->pickedPoints.last();
    13401362        if ( point != pos )
    13411363        {
    … …  
    13491371
    13501372/*!
    1351   Remove the last point of the selection
    1352   The removed() signal is emitted.
    1353 
    1354   \sa isActive(), begin(), end(), append(), move()
    1355 */
     1373   Remove the last point of the selection
     1374   The removed() signal is emitted.
     1375
     1376   \sa isActive(), begin(), end(), append(), move()
     1377 */
    13561378void QwtPicker::remove()
    13571379{
    1358     if ( d_data->isActive && !d_data->pickedPoints.isEmpty() )
     1380    if ( m_data->isActive && !m_data->pickedPoints.isEmpty() )
    13591381    {
    13601382#if QT_VERSION >= 0x050100
    1361         const QPoint pos = d_data->pickedPoints.takeLast();
     1383        const QPoint pos = m_data->pickedPoints.takeLast();
    13621384#else
    1363         const QPoint pos = d_data->pickedPoints.last();
    1364         d_data->pickedPoints.resize( d_data->pickedPoints.count() - 1 );
     1385        const QPoint pos = m_data->pickedPoints.last();
     1386        m_data->pickedPoints.resize( m_data->pickedPoints.count() - 1 );
    13651387#endif
    13661388
    … …  
    13711393
    13721394/*!
    1373   \brief Validate and fix up the selection
    1374 
    1375   Accepts all selections unmodified
    1376 
    1377   \param selection Selection to validate and fix up
    1378   \return true, when accepted, false otherwise
    1379 */
    1380 bool QwtPicker::accept( QPolygon &selection ) const
     1395   \brief Validate and fix up the selection
     1396
     1397   Accepts all selections unmodified
     1398
     1399   \param selection Selection to validate and fix up
     1400   \return true, when accepted, false otherwise
     1401 */
     1402bool QwtPicker::accept( QPolygon& selection ) const
    13811403{
    13821404    Q_UNUSED( selection );
    … …  
    13851407
    13861408/*!
    1387   A picker is active between begin() and end().
    1388   \return true if the selection is active.
    1389 */
     1409   A picker is active between begin() and end().
     1410   \return true if the selection is active.
     1411 */
    13901412bool QwtPicker::isActive() const
    13911413{
    1392     return d_data->isActive;
    1393 }
    1394 
    1395 /*!
    1396   Return the points, that have been collected so far. The selection()
    1397   is calculated from the pickedPoints() in adjustedPoints().
    1398   \return Picked points
    1399 */
    1400 const QPolygon &QwtPicker::pickedPoints() const
    1401 {
    1402     return d_data->pickedPoints;
    1403 }
    1404 
    1405 /*!
    1406   Scale the selection by the ratios of oldSize and newSize
    1407   The changed() signal is emitted.
    1408 
    1409   \param oldSize Previous size
    1410   \param newSize Current size
    1411 
    1412   \sa ResizeMode, setResizeMode(), resizeMode()
    1413 */
    1414 void QwtPicker::stretchSelection( const QSize &oldSize, const QSize &newSize )
     1414    return m_data->isActive;
     1415}
     1416
     1417/*!
     1418   Return the points, that have been collected so far. The selection()
     1419   is calculated from the pickedPoints() in adjustedPoints().
     1420   \return Picked points
     1421 */
     1422const QPolygon& QwtPicker::pickedPoints() const
     1423{
     1424    return m_data->pickedPoints;
     1425}
     1426
     1427/*!
     1428   Scale the selection by the ratios of oldSize and newSize
     1429   The changed() signal is emitted.
     1430
     1431   \param oldSize Previous size
     1432   \param newSize Current size
     1433
     1434   \sa ResizeMode, setResizeMode(), resizeMode()
     1435 */
     1436void QwtPicker::stretchSelection( const QSize& oldSize, const QSize& newSize )
    14151437{
    14161438    if ( oldSize.isEmpty() )
    … …  
    14241446    const double yRatio = double( newSize.height() ) / double( oldSize.height() );
    14251447
    1426     for ( int i = 0; i < d_data->pickedPoints.count(); i++ )
    1427     {
    1428         QPoint &p = d_data->pickedPoints[i];
     1448    for ( int i = 0; i < m_data->pickedPoints.count(); i++ )
     1449    {
     1450        QPoint& p = m_data->pickedPoints[i];
    14291451        p.setX( qRound( p.x() * xRatio ) );
    14301452        p.setY( qRound( p.y() * yRatio ) );
    14311453
    1432         Q_EMIT changed( d_data->pickedPoints );
    1433     }
    1434 }
    1435 
    1436 /*!
    1437   Set mouse tracking for the observed widget.
    1438 
    1439   In case of enable is true, the previous value
    1440   is saved, that is restored when enable is false.
    1441 
    1442   \warning Even when enable is false, mouse tracking might be restored
     1454        Q_EMIT changed( m_data->pickedPoints );
     1455    }
     1456}
     1457
     1458/*!
     1459   Set mouse tracking for the observed widget.
     1460
     1461   In case of enable is true, the previous value
     1462   is saved, that is restored when enable is false.
     1463
     1464   \warning Even when enable is false, mouse tracking might be restored
    14431465           to true. When mouseTracking for the observed widget
    14441466           has been changed directly by QWidget::setMouseTracking
    14451467           while mouse tracking has been set to true, this value can't
    14461468           be restored.
    1447 */
     1469 */
    14481470
    14491471void QwtPicker::setMouseTracking( bool enable )
    14501472{
    1451     QWidget *widget = parentWidget();
     1473    QWidget* widget = parentWidget();
    14521474    if ( !widget )
    14531475        return;
    … …  
    14551477    if ( enable )
    14561478    {
    1457         d_data->mouseTracking = widget->hasMouseTracking();
     1479        m_data->mouseTracking = widget->hasMouseTracking();
    14581480        widget->setMouseTracking( true );
    14591481    }
    14601482    else
    14611483    {
    1462         widget->setMouseTracking( d_data->mouseTracking );
    1463     }
    1464 }
    1465 
    1466 /*!
    1467   Find the area of the observed widget, where selection might happen.
    1468 
    1469   \return parentWidget()->contentsRect()
    1470 */
     1484        widget->setMouseTracking( m_data->mouseTracking );
     1485    }
     1486}
     1487
     1488/*!
     1489   Find the area of the observed widget, where selection might happen.
     1490
     1491   \return parentWidget()->contentsRect()
     1492 */
    14711493QPainterPath QwtPicker::pickArea() const
    14721494{
    14731495    QPainterPath path;
    14741496
    1475     const QWidget *widget = parentWidget();
     1497    const QWidget* widget = parentWidget();
    14761498    if ( widget )
    14771499        path.addRect( widget->contentsRect() );
    … …  
    14831505void QwtPicker::updateDisplay()
    14841506{
    1485     QWidget *w = parentWidget();
     1507    QWidget* w = parentWidget();
    14861508
    14871509    bool showRubberband = false;
    14881510    bool showTracker = false;
    14891511
    1490     if ( w && w->isVisible() && d_data->enabled )
     1512    if ( w && w->isVisible() && m_data->enabled )
    14911513    {
    14921514        if ( rubberBand() != NoRubberBand && isActive() &&
    … …  
    15071529    }
    15081530
    1509     QPointer< QwtPickerRubberband > &rw = d_data->rubberBandOverlay;
     1531    QPointer< Rubberband >& rw = m_data->rubberBandOverlay;
    15101532    if ( showRubberband )
    15111533    {
    15121534        if ( rw.isNull() )
    15131535        {
    1514             rw = new QwtPickerRubberband( this, NULL ); // NULL -> no extra event filter
     1536            rw = new Rubberband( this, NULL ); // NULL -> no extra event filter
    15151537            rw->setObjectName( "PickerRubberBand" );
    15161538            rw->setParent( w );
    … …  
    15181540        }
    15191541
    1520         if ( d_data->rubberBand <= RectRubberBand )
     1542        if ( m_data->rubberBand <= RectRubberBand )
    15211543            rw->setMaskMode( QwtWidgetOverlay::MaskHint );
    15221544        else
    … …  
    15271549    else
    15281550    {
    1529         if ( d_data->openGL )
     1551        if ( m_data->openGL )
    15301552        {
    15311553            // Qt 4.8 crashes for a delete
    … …  
    15431565    }
    15441566
    1545     QPointer< QwtPickerTracker > &tw = d_data->trackerOverlay;
     1567    QPointer< Tracker >& tw = m_data->trackerOverlay;
    15461568    if ( showTracker )
    15471569    {
    15481570        if ( tw.isNull() )
    15491571        {
    1550             tw = new QwtPickerTracker( this, NULL ); // NULL -> no extra event filter
     1572            tw = new Tracker( this, NULL ); // NULL -> no extra event filter
    15511573            tw->setObjectName( "PickerTracker" );
    15521574            tw->setParent( w );
    15531575            tw->resize( w->size() );
    15541576        }
    1555         tw->setFont( d_data->trackerFont );
     1577        tw->setFont( m_data->trackerFont );
    15561578        tw->updateOverlay();
    15571579    }
    15581580    else
    15591581    {
    1560         if ( d_data->openGL )
     1582        if ( m_data->openGL )
    15611583        {
    15621584            // Qt 4.8 crashes for a delete
    … …  
    15761598
    15771599//! \return Overlay displaying the rubber band
    1578 const QwtWidgetOverlay *QwtPicker::rubberBandOverlay() const
    1579 {
    1580     return d_data->rubberBandOverlay;
     1600const QwtWidgetOverlay* QwtPicker::rubberBandOverlay() const
     1601{
     1602    return m_data->rubberBandOverlay;
    15811603}
    15821604
    15831605//! \return Overlay displaying the tracker text
    1584 const QwtWidgetOverlay *QwtPicker::trackerOverlay() const
    1585 {
    1586     return d_data->trackerOverlay;
    1587 }
    1588 
     1606const QwtWidgetOverlay* QwtPicker::trackerOverlay() const
     1607{
     1608    return m_data->trackerOverlay;
     1609}
     1610
     1611#include "moc_qwt_picker.cpp"
  • trunk/BNC/qwt/qwt_picker.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_PICKER
    11 #define QWT_PICKER 1
     11#define QWT_PICKER
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_text.h"
    1514#include "qwt_event_pattern.h"
     15
    1616#include <qobject.h>
    17 #include <qpen.h>
    18 #include <qfont.h>
    19 #include <qrect.h>
    20 #include <qpainterpath.h>
    21 
     17
     18class QwtPickerMachine;
     19class QwtWidgetOverlay;
     20class QwtText;
    2221class QWidget;
    2322class QMouseEvent;
    2423class QWheelEvent;
    2524class QKeyEvent;
    26 class QwtPickerMachine;
    27 class QwtWidgetOverlay;
     25class QPainter;
     26class QPen;
     27class QFont;
     28class QRegion;
     29class QPainterPath;
     30class QPoint;
     31class QRect;
     32class QSize;
     33class QPolygon;
    2834
    2935/*!
    30   \brief QwtPicker provides selections on a widget
    31 
    32   QwtPicker filters all enter, leave, mouse and keyboard events of a widget
    33   and translates them into an array of selected points.
    34 
    35   The way how the points are collected depends on type of state machine
    36   that is connected to the picker. Qwt offers a couple of predefined
    37   state machines for selecting:
    38 
    39   - Nothing\n
     36   \brief QwtPicker provides selections on a widget
     37
     38   QwtPicker filters all enter, leave, mouse and keyboard events of a widget
     39   and translates them into an array of selected points.
     40
     41   The way how the points are collected depends on type of state machine
     42   that is connected to the picker. Qwt offers a couple of predefined
     43   state machines for selecting:
     44
     45   - Nothing\n
    4046    QwtPickerTrackerMachine
    41   - Single points\n
     47   - Single points\n
    4248    QwtPickerClickPointMachine, QwtPickerDragPointMachine
    43   - Rectangles\n
     49   - Rectangles\n
    4450    QwtPickerClickRectMachine, QwtPickerDragRectMachine
    45   - Polygons\n
     51   - Polygons\n
    4652    QwtPickerPolygonMachine
    4753
    48   While these state machines cover the most common ways to collect points
    49   it is also possible to implement individual machines as well.
    50 
    51   QwtPicker translates the picked points into a selection using the
    52   adjustedPoints() method. adjustedPoints() is intended to be reimplemented
    53   to fix up the selection according to application specific requirements.
    54   (F.e. when an application accepts rectangles of a fixed aspect ratio only.)
    55 
    56   Optionally QwtPicker support the process of collecting points by a
    57   rubber band and tracker displaying a text for the current mouse
    58   position.
    59 
    60   \par Example
    61   \code
    62     #include <qwt_picker.h>
    63     #include <qwt_picker_machine.h>
     54   While these state machines cover the most common ways to collect points
     55   it is also possible to implement individual machines as well.
     56
     57   QwtPicker translates the picked points into a selection using the
     58   adjustedPoints() method. adjustedPoints() is intended to be reimplemented
     59   to fix up the selection according to application specific requirements.
     60   (F.e. when an application accepts rectangles of a fixed aspect ratio only.)
     61
     62   Optionally QwtPicker support the process of collecting points by a
     63   rubber band and tracker displaying a text for the current mouse
     64   position.
     65
     66   \par Example
     67   \code
     68 #include <qwt_picker.h>
     69 #include <qwt_picker_machine.h>
    6470
    6571    QwtPicker *picker = new QwtPicker(widget);
    … …  
    6773    picker->setTrackerMode(QwtPicker::ActiveOnly);
    6874    picker->setRubberBand(QwtPicker::RectRubberBand);
    69   \endcode
    70   \endpar
    71 
    72   The state machine triggers the following commands:
    73 
    74   - begin()\n
     75   \endcode
     76
     77   The state machine triggers the following commands:
     78
     79   - begin()\n
    7580    Activate/Initialize the selection.
    76   - append()\n
     81   - append()\n
    7782    Add a new point
    78   - move() \n
     83   - move() \n
    7984    Change the position of the last point.
    80   - remove()\n
     85   - remove()\n
    8186    Remove the last point.
    82   - end()\n
     87   - end()\n
    8388    Terminate the selection and call accept to validate the picked points.
    8489
    85   The picker is active (isActive()), between begin() and end().
    86   In active state the rubber band is displayed, and the tracker is visible
    87   in case of trackerMode is ActiveOnly or AlwaysOn.
    88 
    89   The cursor can be moved using the arrow keys. All selections can be aborted
    90   using the abort key. (QwtEventPattern::KeyPatternCode)
    91 
    92   \warning In case of QWidget::NoFocus the focus policy of the observed
     90   The picker is active (isActive()), between begin() and end().
     91   In active state the rubber band is displayed, and the tracker is visible
     92   in case of trackerMode is ActiveOnly or AlwaysOn.
     93
     94   The cursor can be moved using the arrow keys. All selections can be aborted
     95   using the abort key. (QwtEventPattern::KeyPatternCode)
     96
     97   \warning In case of QWidget::NoFocus the focus policy of the observed
    9398           widget is set to QWidget::WheelFocus and mouse tracking
    9499           will be manipulated while the picker is active,
    95100           or if trackerMode() is AlwayOn.
    96 */
    97 
    98 class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern
     101 */
     102
     103class QWT_EXPORT QwtPicker : public QObject, public QwtEventPattern
    99104{
    100105    Q_OBJECT
    … …  
    112117    Q_PROPERTY( QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen )
    113118
    114 public:
    115     /*!
    116       Rubber band style
    117 
    118       The default value is QwtPicker::NoRubberBand.
    119       \sa setRubberBand(), rubberBand()
    120     */
     119  public:
     120    /*!
     121       Rubber band style
     122
     123       The default value is QwtPicker::NoRubberBand.
     124       \sa setRubberBand(), rubberBand()
     125     */
    121126
    122127    enum RubberBand
    … …  
    144149
    145150        /*!
    146           Values >= UserRubberBand can be used to define additional
    147           rubber bands.
     151           Values >= UserRubberBand can be used to define additional
     152           rubber bands.
    148153         */
    149154        UserRubberBand = 100
    … …  
    151156
    152157    /*!
    153       \brief Display mode
    154       \sa setTrackerMode(), trackerMode(), isActive()
    155     */
     158       \brief Display mode
     159       \sa setTrackerMode(), trackerMode(), isActive()
     160     */
    156161    enum DisplayMode
    157162    {
    … …  
    167172
    168173    /*!
    169       Controls what to do with the selected points of an active
     174       Controls what to do with the selected points of an active
    170175         selection when the observed widget is resized.
    171176
    172       The default value is QwtPicker::Stretch.
    173       \sa setResizeMode()
    174     */
     177       The default value is QwtPicker::Stretch.
     178       \sa setResizeMode()
     179     */
    175180
    176181    enum ResizeMode
    … …  
    183188    };
    184189
    185     explicit QwtPicker( QWidget *parent );
     190    explicit QwtPicker( QWidget* parent );
    186191    explicit QwtPicker( RubberBand rubberBand,
    187                         DisplayMode trackerMode, QWidget * );
     192        DisplayMode trackerMode, QWidget* );
    188193
    189194    virtual ~QwtPicker();
    190195
    191     void setStateMachine( QwtPickerMachine * );
    192     const QwtPickerMachine *stateMachine() const;
    193     QwtPickerMachine *stateMachine();
     196    void setStateMachine( QwtPickerMachine* );
     197    const QwtPickerMachine* stateMachine() const;
     198    QwtPickerMachine* stateMachine();
    194199
    195200    void setRubberBand( RubberBand );
    … …  
    202207    ResizeMode resizeMode() const;
    203208
    204     void setRubberBandPen( const QPen & );
     209    void setRubberBandPen( const QPen& );
    205210    QPen rubberBandPen() const;
    206211
    207     void setTrackerPen( const QPen & );
     212    void setTrackerPen( const QPen& );
    208213    QPen trackerPen() const;
    209214
    210     void setTrackerFont( const QFont & );
     215    void setTrackerFont( const QFont& );
    211216    QFont trackerFont() const;
    212217
    … …  
    214219    bool isActive() const;
    215220
    216     virtual bool eventFilter( QObject *, QEvent * );
    217 
    218     QWidget *parentWidget();
    219     const QWidget *parentWidget() const;
     221    virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE;
     222
     223    QWidget* parentWidget();
     224    const QWidget* parentWidget() const;
    220225
    221226    virtual QPainterPath pickArea() const;
    222227
    223     virtual void drawRubberBand( QPainter * ) const;
    224     virtual void drawTracker( QPainter * ) const;
    225 
     228    virtual void drawRubberBand( QPainter* ) const;
     229    virtual void drawTracker( QPainter* ) const;
     230
     231    virtual QRegion trackerMask() const;
    226232    virtual QRegion rubberBandMask() const;
    227233
    228     virtual QwtText trackerText( const QPoint &pos ) const;
     234    virtual QwtText trackerText( const QPoint& pos ) const;
    229235    QPoint trackerPosition() const;
    230     virtual QRect trackerRect( const QFont & ) const;
     236    virtual QRect trackerRect( const QFont& ) const;
    231237
    232238    QPolygon selection() const;
    233239
    234 public Q_SLOTS:
     240  public Q_SLOTS:
    235241    void setEnabled( bool );
    236242
    237 Q_SIGNALS:
    238     /*!
    239       A signal indicating, when the picker has been activated.
    240       Together with setEnabled() it can be used to implement
    241       selections with more than one picker.
    242 
    243       \param on True, when the picker has been activated
    244     */
     243  Q_SIGNALS:
     244    /*!
     245       A signal indicating, when the picker has been activated.
     246       Together with setEnabled() it can be used to implement
     247       selections with more than one picker.
     248
     249       \param on True, when the picker has been activated
     250     */
    245251    void activated( bool on );
    246252
    247253    /*!
    248       A signal emitting the selected points,
    249       at the end of a selection.
    250 
    251       \param polygon Selected points
    252     */
    253     void selected( const QPolygon &polygon );
    254 
    255     /*!
    256       A signal emitted when a point has been appended to the selection
    257 
    258       \param pos Position of the appended point.
    259       \sa append(). moved()
    260     */
    261     void appended( const QPoint &pos );
    262 
    263     /*!
    264       A signal emitted whenever the last appended point of the
    265       selection has been moved.
    266 
    267       \param pos Position of the moved last point of the selection.
    268       \sa move(), appended()
    269     */
    270     void moved( const QPoint &pos );
    271 
    272     /*!
    273       A signal emitted whenever the last appended point of the
    274       selection has been removed.
    275 
    276       \param pos Position of the point, that has been removed
    277       \sa remove(), appended()
    278     */
    279     void removed( const QPoint &pos );
    280     /*!
    281       A signal emitted when the active selection has been changed.
    282       This might happen when the observed widget is resized.
    283 
    284       \param selection Changed selection
    285       \sa stretchSelection()
    286     */
    287     void changed( const QPolygon &selection );
    288 
    289 protected:
    290     virtual QPolygon adjustedPoints( const QPolygon & ) const;
    291 
    292     virtual void transition( const QEvent * );
     254       A signal emitting the selected points,
     255       at the end of a selection.
     256
     257       \param polygon Selected points
     258     */
     259    void selected( const QPolygon& polygon );
     260
     261    /*!
     262       A signal emitted when a point has been appended to the selection
     263
     264       \param pos Position of the appended point.
     265       \sa append(). moved()
     266     */
     267    void appended( const QPoint& pos );
     268
     269    /*!
     270       A signal emitted whenever the last appended point of the
     271       selection has been moved.
     272
     273       \param pos Position of the moved last point of the selection.
     274       \sa move(), appended()
     275     */
     276    void moved( const QPoint& pos );
     277
     278    /*!
     279       A signal emitted whenever the last appended point of the
     280       selection has been removed.
     281
     282       \param pos Position of the point, that has been removed
     283       \sa remove(), appended()
     284     */
     285    void removed( const QPoint& pos );
     286    /*!
     287       A signal emitted when the active selection has been changed.
     288       This might happen when the observed widget is resized.
     289
     290       \param selection Changed selection
     291       \sa stretchSelection()
     292     */
     293    void changed( const QPolygon& selection );
     294
     295  protected:
     296    virtual QPolygon adjustedPoints( const QPolygon& ) const;
     297
     298    virtual void transition( const QEvent* );
    293299
    294300    virtual void begin();
    295     virtual void append( const QPoint & );
    296     virtual void move( const QPoint & );
     301    virtual void append( const QPoint& );
     302    virtual void move( const QPoint& );
    297303    virtual void remove();
    298304    virtual bool end( bool ok = true );
    299305
    300     virtual bool accept( QPolygon & ) const;
     306    virtual bool accept( QPolygon& ) const;
    301307    virtual void reset();
    302308
    303     virtual void widgetMousePressEvent( QMouseEvent * );
    304     virtual void widgetMouseReleaseEvent( QMouseEvent * );
    305     virtual void widgetMouseDoubleClickEvent( QMouseEvent * );
    306     virtual void widgetMouseMoveEvent( QMouseEvent * );
    307     virtual void widgetWheelEvent( QWheelEvent * );
    308     virtual void widgetKeyPressEvent( QKeyEvent * );
    309     virtual void widgetKeyReleaseEvent( QKeyEvent * );
    310     virtual void widgetEnterEvent( QEvent * );
    311     virtual void widgetLeaveEvent( QEvent * );
     309    virtual void widgetMousePressEvent( QMouseEvent* );
     310    virtual void widgetMouseReleaseEvent( QMouseEvent* );
     311    virtual void widgetMouseDoubleClickEvent( QMouseEvent* );
     312    virtual void widgetMouseMoveEvent( QMouseEvent* );
     313    virtual void widgetWheelEvent( QWheelEvent* );
     314    virtual void widgetKeyPressEvent( QKeyEvent* );
     315    virtual void widgetKeyReleaseEvent( QKeyEvent* );
     316    virtual void widgetEnterEvent( QEvent* );
     317    virtual void widgetLeaveEvent( QEvent* );
    312318
    313319    virtual void stretchSelection(
    314         const QSize &oldSize, const QSize &newSize );
     320        const QSize& oldSize, const QSize& newSize );
    315321
    316322    virtual void updateDisplay();
    317323
    318     const QwtWidgetOverlay *rubberBandOverlay() const;
    319     const QwtWidgetOverlay *trackerOverlay() const;
    320 
    321     const QPolygon &pickedPoints() const;
    322 
    323 private:
    324     void init( QWidget *, RubberBand rubberBand, DisplayMode trackerMode );
     324    const QwtWidgetOverlay* rubberBandOverlay() const;
     325    const QwtWidgetOverlay* trackerOverlay() const;
     326
     327    const QPolygon& pickedPoints() const;
     328    QRect trackerRect( const QSize& ) const;
     329
     330  private:
     331    void init( QWidget*, RubberBand rubberBand, DisplayMode trackerMode );
    325332
    326333    void setMouseTracking( bool );
    327334
    328335    class PrivateData;
    329     PrivateData *d_data;
     336    PrivateData* m_data;
    330337};
    331338
  • trunk/BNC/qwt/qwt_picker_machine.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_picker_machine.h"
    1111#include "qwt_event_pattern.h"
     12
    1213#include <qevent.h>
    1314
    1415//! Constructor
    15 QwtPickerMachine::QwtPickerMachine( SelectionType type ):
    16     d_selectionType( type ),
    17     d_state( 0 )
     16QwtPickerMachine::QwtPickerMachine( SelectionType type )
     17    : m_selectionType( type )
     18    , m_state( 0 )
    1819{
    1920}
    … …  
    2728QwtPickerMachine::SelectionType QwtPickerMachine::selectionType() const
    2829{
    29     return d_selectionType;
     30    return m_selectionType;
    3031}
    3132
    … …  
    3334int QwtPickerMachine::state() const
    3435{
    35     return d_state;
     36    return m_state;
    3637}
    3738
    … …  
    3940void QwtPickerMachine::setState( int state )
    4041{
    41     d_state = state;
     42    m_state = state;
    4243}
    4344
    … …  
    5556
    5657//! Transition
    57 QList<QwtPickerMachine::Command> QwtPickerTrackerMachine::transition(
    58     const QwtEventPattern &, const QEvent *e )
    59 {
    60     QList<QwtPickerMachine::Command> cmdList;
     58QList< QwtPickerMachine::Command > QwtPickerTrackerMachine::transition(
     59    const QwtEventPattern&, const QEvent* e )
     60{
     61    QList< QwtPickerMachine::Command > cmdList;
    6162
    6263    switch ( e->type() )
    … …  
    9798
    9899//! Transition
    99 QList<QwtPickerMachine::Command> QwtPickerClickPointMachine::transition(
    100     const QwtEventPattern &eventPattern, const QEvent *event )
    101 {
    102     QList<QwtPickerMachine::Command> cmdList;
     100QList< QwtPickerMachine::Command > QwtPickerClickPointMachine::transition(
     101    const QwtEventPattern& eventPattern, const QEvent* event )
     102{
     103    QList< QwtPickerMachine::Command > cmdList;
    103104
    104105    switch ( event->type() )
    … …  
    107108        {
    108109            if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
    109                 static_cast<const QMouseEvent *>( event ) ) )
     110                static_cast< const QMouseEvent* >( event ) ) )
    110111            {
    111112                cmdList += Begin;
    … …  
    117118        case QEvent::KeyPress:
    118119        {
    119             const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
     120            const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event );
    120121            if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
    121122            {
    … …  
    143144
    144145//! Transition
    145 QList<QwtPickerMachine::Command> QwtPickerDragPointMachine::transition(
    146     const QwtEventPattern &eventPattern, const QEvent *event )
    147 {
    148     QList<QwtPickerMachine::Command> cmdList;
     146QList< QwtPickerMachine::Command > QwtPickerDragPointMachine::transition(
     147    const QwtEventPattern& eventPattern, const QEvent* event )
     148{
     149    QList< QwtPickerMachine::Command > cmdList;
    149150
    150151    switch ( event->type() )
    … …  
    153154        {
    154155            if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
    155                 static_cast<const QMouseEvent *>( event ) ) )
     156                static_cast< const QMouseEvent* >( event ) ) )
    156157            {
    157158                if ( state() == 0 )
    … …  
    182183        case QEvent::KeyPress:
    183184        {
    184             const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
     185            const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event );
    185186            if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
    186187            {
    … …  
    216217
    217218//! Transition
    218 QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition(
    219     const QwtEventPattern &eventPattern, const QEvent *event )
    220 {
    221     QList<QwtPickerMachine::Command> cmdList;
     219QList< QwtPickerMachine::Command > QwtPickerClickRectMachine::transition(
     220    const QwtEventPattern& eventPattern, const QEvent* event )
     221{
     222    QList< QwtPickerMachine::Command > cmdList;
    222223
    223224    switch ( event->type() )
    … …  
    226227        {
    227228            if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
    228                 static_cast<const QMouseEvent *>( event ) ) )
     229                static_cast< const QMouseEvent* >( event ) ) )
    229230            {
    230231                switch ( state() )
    … …  
    261262        {
    262263            if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
    263                 static_cast<const QMouseEvent *>( event ) ) )
     264                static_cast< const QMouseEvent* >( event ) ) )
    264265            {
    265266                if ( state() == 1 )
    … …  
    273274        case QEvent::KeyPress:
    274275        {
    275             const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
     276            const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event );
    276277            if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
    277278            {
    … …  
    315316
    316317//! Transition
    317 QList<QwtPickerMachine::Command> QwtPickerDragRectMachine::transition(
    318     const QwtEventPattern &eventPattern, const QEvent *event )
    319 {
    320     QList<QwtPickerMachine::Command> cmdList;
     318QList< QwtPickerMachine::Command > QwtPickerDragRectMachine::transition(
     319    const QwtEventPattern& eventPattern, const QEvent* event )
     320{
     321    QList< QwtPickerMachine::Command > cmdList;
    321322
    322323    switch ( event->type() )
    … …  
    325326        {
    326327            if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
    327                 static_cast<const QMouseEvent *>( event ) ) )
     328                static_cast< const QMouseEvent* >( event ) ) )
    328329            {
    329330                if ( state() == 0 )
    … …  
    356357        {
    357358            if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
    358                 static_cast<const QKeyEvent *> ( event ) ) )
     359                static_cast< const QKeyEvent* > ( event ) ) )
    359360            {
    360361                if ( state() == 0 )
    … …  
    387388
    388389//! Transition
    389 QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition(
    390     const QwtEventPattern &eventPattern, const QEvent *event )
    391 {
    392     QList<QwtPickerMachine::Command> cmdList;
     390QList< QwtPickerMachine::Command > QwtPickerPolygonMachine::transition(
     391    const QwtEventPattern& eventPattern, const QEvent* event )
     392{
     393    QList< QwtPickerMachine::Command > cmdList;
    393394
    394395    switch ( event->type() )
    … …  
    397398        {
    398399            if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
    399                 static_cast<const QMouseEvent *>( event ) ) )
     400                static_cast< const QMouseEvent* >( event ) ) )
    400401            {
    401402                if ( state() == 0 )
    … …  
    412413            }
    413414            if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect2,
    414                 static_cast<const QMouseEvent *>( event ) ) )
     415                static_cast< const QMouseEvent* >( event ) ) )
    415416            {
    416417                if ( state() == 1 )
    … …  
    431432        case QEvent::KeyPress:
    432433        {
    433             const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
     434            const QKeyEvent* keyEvent = static_cast< const QKeyEvent* > ( event );
    434435            if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
    435436            {
    … …  
    476477
    477478//! Transition
    478 QList<QwtPickerMachine::Command> QwtPickerDragLineMachine::transition(
    479     const QwtEventPattern &eventPattern, const QEvent *event )
    480 {
    481     QList<QwtPickerMachine::Command> cmdList;
     479QList< QwtPickerMachine::Command > QwtPickerDragLineMachine::transition(
     480    const QwtEventPattern& eventPattern, const QEvent* event )
     481{
     482    QList< QwtPickerMachine::Command > cmdList;
    482483
    483484    switch( event->type() )
    … …  
    486487        {
    487488            if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
    488                 static_cast<const QMouseEvent *>( event ) ) )
     489                static_cast< const QMouseEvent* >( event ) ) )
    489490            {
    490491                if ( state() == 0 )
    … …  
    501502        {
    502503            if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
    503                 static_cast<const QKeyEvent *> ( event ) ) )
     504                static_cast< const QKeyEvent* > ( event ) ) )
    504505            {
    505506                if ( state() == 0 )
  • trunk/BNC/qwt/qwt_picker_machine.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_PICKER_MACHINE
    11 #define QWT_PICKER_MACHINE 1
     11#define QWT_PICKER_MACHINE
    1212
    1313#include "qwt_global.h"
    14 #include <qlist.h>
    15 
     14
     15class QwtEventPattern;
    1616class QEvent;
    17 class QwtEventPattern;
    18 
    19 /*!
    20   \brief A state machine for QwtPicker selections
    21 
    22   QwtPickerMachine accepts key and mouse events and translates them
    23   into selection commands.
    24 
    25   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
    26 */
     17template< typename T > class QList;
     18
     19/*!
     20   \brief A state machine for QwtPicker selections
     21
     22   QwtPickerMachine accepts key and mouse events and translates them
     23   into selection commands.
     24
     25   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
     26 */
    2727
    2828class QWT_EXPORT QwtPickerMachine
    2929{
    30 public:
     30  public:
    3131    /*!
    32       Type of a selection.
    33       \sa selectionType()
    34     */
     32       Type of a selection.
     33       \sa selectionType()
     34     */
    3535    enum SelectionType
    3636    {
    … …  
    5858    };
    5959
    60     QwtPickerMachine( SelectionType );
     60    explicit QwtPickerMachine( SelectionType );
    6161    virtual ~QwtPickerMachine();
    6262
    6363    //! Transition
    64     virtual QList<Command> transition(
    65         const QwtEventPattern &, const QEvent * ) = 0;
     64    virtual QList< Command > transition(
     65        const QwtEventPattern&, const QEvent* ) = 0;
    6666    void reset();
    6767
    … …  
    7171    SelectionType selectionType() const;
    7272
    73 private:
    74     const SelectionType d_selectionType;
    75     int d_state;
    76 };
    77 
    78 /*!
    79   \brief A state machine for indicating mouse movements
    80 
    81   QwtPickerTrackerMachine supports displaying information
    82   corresponding to mouse movements, but is not intended for
    83   selecting anything. Begin/End are related to Enter/Leave events.
    84 */
    85 class QWT_EXPORT QwtPickerTrackerMachine: public QwtPickerMachine
    86 {
    87 public:
     73  private:
     74    const SelectionType m_selectionType;
     75    int m_state;
     76};
     77
     78/*!
     79   \brief A state machine for indicating mouse movements
     80
     81   QwtPickerTrackerMachine supports displaying information
     82   corresponding to mouse movements, but is not intended for
     83   selecting anything. Begin/End are related to Enter/Leave events.
     84 */
     85class QWT_EXPORT QwtPickerTrackerMachine : public QwtPickerMachine
     86{
     87  public:
    8888    QwtPickerTrackerMachine();
    8989
    90     virtual QList<Command> transition(
    91         const QwtEventPattern &, const QEvent * );
    92 };
    93 
    94 /*!
    95   \brief A state machine for point selections
    96 
    97   Pressing QwtEventPattern::MouseSelect1 or
    98   QwtEventPattern::KeySelect1 selects a point.
    99 
    100   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
    101 */
    102 class QWT_EXPORT QwtPickerClickPointMachine: public QwtPickerMachine
    103 {
    104 public:
     90    virtual QList< Command > transition(
     91        const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE;
     92};
     93
     94/*!
     95   \brief A state machine for point selections
     96
     97   Pressing QwtEventPattern::MouseSelect1 or
     98   QwtEventPattern::KeySelect1 selects a point.
     99
     100   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
     101 */
     102class QWT_EXPORT QwtPickerClickPointMachine : public QwtPickerMachine
     103{
     104  public:
    105105    QwtPickerClickPointMachine();
    106106
    107     virtual QList<Command> transition(
    108         const QwtEventPattern &, const QEvent * );
    109 };
    110 
    111 /*!
    112   \brief A state machine for point selections
    113 
    114   Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1
    115   starts the selection, releasing QwtEventPattern::MouseSelect1 or
    116   a second press of QwtEventPattern::KeySelect1 terminates it.
    117 */
    118 class QWT_EXPORT QwtPickerDragPointMachine: public QwtPickerMachine
    119 {
    120 public:
     107    virtual QList< Command > transition(
     108        const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE;
     109};
     110
     111/*!
     112   \brief A state machine for point selections
     113
     114   Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1
     115   starts the selection, releasing QwtEventPattern::MouseSelect1 or
     116   a second press of QwtEventPattern::KeySelect1 terminates it.
     117 */
     118class QWT_EXPORT QwtPickerDragPointMachine : public QwtPickerMachine
     119{
     120  public:
    121121    QwtPickerDragPointMachine();
    122122
    123     virtual QList<Command> transition(
    124         const QwtEventPattern &, const QEvent * );
    125 };
    126 
    127 /*!
    128   \brief A state machine for rectangle selections
    129 
    130   Pressing QwtEventPattern::MouseSelect1 starts
    131   the selection, releasing it selects the first point. Pressing it
    132   again selects the second point and terminates the selection.
    133   Pressing QwtEventPattern::KeySelect1 also starts the
    134   selection, a second press selects the first point. A third one selects
    135   the second point and terminates the selection.
    136 
    137   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
    138 */
    139 
    140 class QWT_EXPORT QwtPickerClickRectMachine: public QwtPickerMachine
    141 {
    142 public:
     123    virtual QList< Command > transition(
     124        const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE;
     125};
     126
     127/*!
     128   \brief A state machine for rectangle selections
     129
     130   Pressing QwtEventPattern::MouseSelect1 starts
     131   the selection, releasing it selects the first point. Pressing it
     132   again selects the second point and terminates the selection.
     133   Pressing QwtEventPattern::KeySelect1 also starts the
     134   selection, a second press selects the first point. A third one selects
     135   the second point and terminates the selection.
     136
     137   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
     138 */
     139
     140class QWT_EXPORT QwtPickerClickRectMachine : public QwtPickerMachine
     141{
     142  public:
    143143    QwtPickerClickRectMachine();
    144144
    145     virtual QList<Command> transition(
    146         const QwtEventPattern &, const QEvent * );
    147 };
    148 
    149 /*!
    150   \brief A state machine for rectangle selections
    151 
    152   Pressing QwtEventPattern::MouseSelect1 selects
    153   the first point, releasing it the second point.
    154   Pressing QwtEventPattern::KeySelect1 also selects the
    155   first point, a second press selects the second point and terminates
    156   the selection.
    157 
    158   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
    159 */
    160 
    161 class QWT_EXPORT QwtPickerDragRectMachine: public QwtPickerMachine
    162 {
    163 public:
     145    virtual QList< Command > transition(
     146        const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE;
     147};
     148
     149/*!
     150   \brief A state machine for rectangle selections
     151
     152   Pressing QwtEventPattern::MouseSelect1 selects
     153   the first point, releasing it the second point.
     154   Pressing QwtEventPattern::KeySelect1 also selects the
     155   first point, a second press selects the second point and terminates
     156   the selection.
     157
     158   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
     159 */
     160
     161class QWT_EXPORT QwtPickerDragRectMachine : public QwtPickerMachine
     162{
     163  public:
    164164    QwtPickerDragRectMachine();
    165165
    166     virtual QList<Command> transition(
    167         const QwtEventPattern &, const QEvent * );
    168 };
    169 
    170 /*!
    171   \brief A state machine for line selections
    172 
    173   Pressing QwtEventPattern::MouseSelect1 selects
    174   the first point, releasing it the second point.
    175   Pressing QwtEventPattern::KeySelect1 also selects the
    176   first point, a second press selects the second point and terminates
    177   the selection.
    178 
    179   A common use case of QwtPickerDragLineMachine are pickers for
    180   distance measurements.
    181 
    182   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
    183 */
    184 
    185 class QWT_EXPORT QwtPickerDragLineMachine: public QwtPickerMachine
    186 {
    187 public:
     166    virtual QList< Command > transition(
     167        const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE;
     168};
     169
     170/*!
     171   \brief A state machine for line selections
     172
     173   Pressing QwtEventPattern::MouseSelect1 selects
     174   the first point, releasing it the second point.
     175   Pressing QwtEventPattern::KeySelect1 also selects the
     176   first point, a second press selects the second point and terminates
     177   the selection.
     178
     179   A common use case of QwtPickerDragLineMachine are pickers for
     180   distance measurements.
     181
     182   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
     183 */
     184
     185class QWT_EXPORT QwtPickerDragLineMachine : public QwtPickerMachine
     186{
     187  public:
    188188    QwtPickerDragLineMachine();
    189189
    190     virtual QList<Command> transition(
    191         const QwtEventPattern &, const QEvent * );
    192 };
    193 
    194 /*!
    195   \brief A state machine for polygon selections
    196 
    197   Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1
    198   starts the selection and selects the first point, or appends a point.
    199   Pressing QwtEventPattern::MouseSelect2 or QwtEventPattern::KeySelect2
    200   appends the last point and terminates the selection.
    201 
    202   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
    203 */
    204 
    205 class QWT_EXPORT QwtPickerPolygonMachine: public QwtPickerMachine
    206 {
    207 public:
     190    virtual QList< Command > transition(
     191        const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE;
     192};
     193
     194/*!
     195   \brief A state machine for polygon selections
     196
     197   Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1
     198   starts the selection and selects the first point, or appends a point.
     199   Pressing QwtEventPattern::MouseSelect2 or QwtEventPattern::KeySelect2
     200   appends the last point and terminates the selection.
     201
     202   \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode
     203 */
     204
     205class QWT_EXPORT QwtPickerPolygonMachine : public QwtPickerMachine
     206{
     207  public:
    208208    QwtPickerPolygonMachine();
    209209
    210     virtual QList<Command> transition(
    211         const QwtEventPattern &, const QEvent * );
     210    virtual QList< Command > transition(
     211        const QwtEventPattern&, const QEvent* ) QWT_OVERRIDE;
    212212};
    213213
  • trunk/BNC/qwt/qwt_pixel_matrix.cpp

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111
    1212/*!
    13   \brief Constructor
     13   \brief Constructor
    1414
    15   \param rect Bounding rectangle for the matrix
    16 */
    17 QwtPixelMatrix::QwtPixelMatrix( const QRect& rect ):
    18     QBitArray( qMax( rect.width() * rect.height(), 0 ) ),
    19     d_rect( rect )
     15   \param rect Bounding rectangle for the matrix
     16 */
     17QwtPixelMatrix::QwtPixelMatrix( const QRect& rect )
     18    : QBitArray( qMax( rect.width() * rect.height(), 0 ) )
     19    , m_rect( rect )
    2020{
    2121}
    … …  
    3535void QwtPixelMatrix::setRect( const QRect& rect )
    3636{
    37     if ( rect != d_rect )
     37    if ( rect != m_rect )
    3838    {
    39         d_rect = rect;
     39        m_rect = rect;
    4040        const int sz = qMax( rect.width() * rect.height(), 0 );
    4141        resize( sz );
    … …  
    4848QRect QwtPixelMatrix::rect() const
    4949{
    50     return d_rect;
     50    return m_rect;
    5151}
  • trunk/BNC/qwt/qwt_pixel_matrix.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
     14
    1415#include <qbitarray.h>
    1516#include <qrect.h>
    1617
    1718/*!
    18   \brief A bit field corresponding to the pixels of a rectangle
     19   \brief A bit field corresponding to the pixels of a rectangle
    1920
    20   QwtPixelMatrix is intended to filter out duplicates in an
    21   unsorted array of points.
    22 */
    23 class QWT_EXPORT QwtPixelMatrix: public QBitArray
     21   QwtPixelMatrix is intended to filter out duplicates in an
     22   unsorted array of points.
     23 */
     24class QWT_EXPORT QwtPixelMatrix : public QBitArray
    2425{
    25 public:
    26     QwtPixelMatrix( const QRect& rect );
     26  public:
     27    explicit QwtPixelMatrix( const QRect& rect );
    2728    ~QwtPixelMatrix();
    2829
    … …  
    3536    int index( int x, int y ) const;
    3637
    37 private:
    38     QRect d_rect;
     38  private:
     39    QRect m_rect;
    3940};
    4041
    4142/*!
    42   \brief Test if a pixel has been set
     43   \brief Test if a pixel has been set
    4344
    44   \param x X-coordinate
    45   \param y Y-coordinate
     45   \param x X-coordinate
     46   \param y Y-coordinate
    4647
    47   \return true, when pos is outside of rect(), or when the pixel
     48   \return true, when pos is outside of rect(), or when the pixel
    4849          has already been set.
    4950 */
    … …  
    5556
    5657/*!
    57   \brief Set a pixel and test if a pixel has been set before
     58   \brief Set a pixel and test if a pixel has been set before
    5859
    59   \param x X-coordinate
    60   \param y Y-coordinate
    61   \param on Set/Clear the pixel
     60   \param x X-coordinate
     61   \param y Y-coordinate
     62   \param on Set/Clear the pixel
    6263
    63   \return true, when pos is outside of rect(), or when the pixel
     64   \return true, when pos is outside of rect(), or when the pixel
    6465          was set before.
    6566 */
    … …  
    7778
    7879/*!
    79   \brief Calculate the index in the bit field corresponding to a position
     80   \brief Calculate the index in the bit field corresponding to a position
    8081
    81   \param x X-coordinate
    82   \param y Y-coordinate
    83   \return Index, when rect() contains pos - otherwise -1.
     82   \param x X-coordinate
     83   \param y Y-coordinate
     84   \return Index, when rect() contains pos - otherwise -1.
    8485 */
    8586inline int QwtPixelMatrix::index( int x, int y ) const
    8687{
    87     const int dx = x - d_rect.x();
    88     if ( dx < 0 || dx >= d_rect.width() )
     88    const int dx = x - m_rect.x();
     89    if ( dx < 0 || dx >= m_rect.width() )
    8990        return -1;
    9091
    91     const int dy = y - d_rect.y();
    92     if ( dy < 0 || dy >= d_rect.height() )
     92    const int dy = y - m_rect.y();
     93    if ( dy < 0 || dy >= m_rect.height() )
    9394        return -1;
    9495
    95     return dy * d_rect.width() + dx;
     96    return dy * m_rect.width() + dx;
    9697}
    9798
  • trunk/BNC/qwt/qwt_plot.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_scale_widget.h"
    1414#include "qwt_scale_engine.h"
     15#include "qwt_scale_map.h"
    1516#include "qwt_text_label.h"
    1617#include "qwt_legend.h"
    1718#include "qwt_legend_data.h"
    1819#include "qwt_plot_canvas.h"
    19 #include <qmath.h>
     20#include "qwt_math.h"
     21
    2022#include <qpainter.h>
    2123#include <qpointer.h>
    22 #include <qpaintengine.h>
    2324#include <qapplication.h>
    24 #include <qevent.h>
    25 
    26 static inline void qwtEnableLegendItems( QwtPlot *plot, bool on )
    27 {
     25#include <qcoreevent.h>
     26
     27static inline void qwtEnableLegendItems( QwtPlot* plot, bool on )
     28{
     29    // gcc seems to have problems with const char sig[] in combination with certain options
     30    const char* sig = SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>));
     31    const char* slot = SLOT(updateLegendItems(QVariant,QList<QwtLegendData>));
     32
    2833    if ( on )
    29     {
    30         QObject::connect(
    31             plot, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)),
    32             plot, SLOT(updateLegendItems(QVariant,QList<QwtLegendData>))
    33         );
    34     }
     34        QObject::connect( plot, sig, plot, slot );
    3535    else
    36     {
    37         QObject::disconnect(
    38             plot, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>) ),
    39             plot, SLOT( updateLegendItems(QVariant,QList<QwtLegendData>))
    40         );
    41     }
     36        QObject::disconnect( plot, sig, plot, slot );
    4237}
    4338
    4439static void qwtSetTabOrder(
    45     QWidget *first, QWidget *second, bool withChildren )
    46 {
    47     QList<QWidget *> tabChain;
     40    QWidget* first, QWidget* second, bool withChildren )
     41{
     42    QList< QWidget* > tabChain;
    4843    tabChain += first;
    4944    tabChain += second;
    … …  
    5146    if ( withChildren )
    5247    {
    53         QList<QWidget *> children = second->findChildren<QWidget *>();
    54 
    55         QWidget *w = second->nextInFocusChain();
     48        QList< QWidget* > children = second->findChildren< QWidget* >();
     49
     50        QWidget* w = second->nextInFocusChain();
    5651        while ( children.contains( w ) )
    5752        {
    … …  
    6560    for ( int i = 0; i < tabChain.size() - 1; i++ )
    6661    {
    67         QWidget *from = tabChain[i];
    68         QWidget *to = tabChain[i+1];
     62        QWidget* from = tabChain[i];
     63        QWidget* to = tabChain[i + 1];
    6964
    7065        const Qt::FocusPolicy policy1 = from->focusPolicy();
    7166        const Qt::FocusPolicy policy2 = to->focusPolicy();
    7267
    73         QWidget *proxy1 = from->focusProxy();
    74         QWidget *proxy2 = to->focusProxy();
     68        QWidget* proxy1 = from->focusProxy();
     69        QWidget* proxy2 = to->focusProxy();
    7570
    7671        from->setFocusPolicy( Qt::TabFocus );
    … …  
    9287class QwtPlot::PrivateData
    9388{
    94 public:
    95     QPointer<QwtTextLabel> titleLabel;
    96     QPointer<QwtTextLabel> footerLabel;
    97     QPointer<QWidget> canvas;
    98     QPointer<QwtAbstractLegend> legend;
    99     QwtPlotLayout *layout;
     89  public:
     90    QPointer< QwtTextLabel > titleLabel;
     91    QPointer< QwtTextLabel > footerLabel;
     92    QPointer< QWidget > canvas;
     93    QPointer< QwtAbstractLegend > legend;
     94    QwtPlotLayout* layout;
    10095
    10196    bool autoReplot;
    … …  
    10398
    10499/*!
    105   \brief Constructor
    106   \param parent Parent widget
    107  */
    108 QwtPlot::QwtPlot( QWidget *parent ):
    109     QFrame( parent )
     100   \brief Constructor
     101   \param parent Parent widget
     102 */
     103QwtPlot::QwtPlot( QWidget* parent )
     104    : QFrame( parent )
    110105{
    111106    initPlot( QwtText() );
    … …  
    113108
    114109/*!
    115   \brief Constructor
    116   \param title Title text
    117   \param parent Parent widget
    118  */
    119 QwtPlot::QwtPlot( const QwtText &title, QWidget *parent ):
    120     QFrame( parent )
     110   \brief Constructor
     111   \param title Title text
     112   \param parent Parent widget
     113 */
     114QwtPlot::QwtPlot( const QwtText& title, QWidget* parent )
     115    : QFrame( parent )
    121116{
    122117    initPlot( title );
    … …  
    129124    detachItems( QwtPlotItem::Rtti_PlotItem, autoDelete() );
    130125
    131     delete d_data->layout;
     126    delete m_data->layout;
    132127    deleteAxesData();
    133     delete d_data;
    134 }
    135 
    136 /*!
    137   \brief Initializes a QwtPlot instance
    138   \param title Title text
    139  */
    140 void QwtPlot::initPlot( const QwtText &title )
    141 {
    142     d_data = new PrivateData;
    143 
    144     d_data->layout = new QwtPlotLayout;
    145     d_data->autoReplot = false;
     128    delete m_data;
     129}
     130
     131/*!
     132   \brief Initializes a QwtPlot instance
     133   \param title Title text
     134 */
     135void QwtPlot::initPlot( const QwtText& title )
     136{
     137    m_data = new PrivateData;
     138
     139    m_data->layout = new QwtPlotLayout;
     140    m_data->autoReplot = false;
    146141
    147142    // title
    148     d_data->titleLabel = new QwtTextLabel( this );
    149     d_data->titleLabel->setObjectName( "QwtPlotTitle" );
    150     d_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) );
     143    m_data->titleLabel = new QwtTextLabel( this );
     144    m_data->titleLabel->setObjectName( "QwtPlotTitle" );
     145    m_data->titleLabel->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) );
    151146
    152147    QwtText text( title );
    153148    text.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap );
    154     d_data->titleLabel->setText( text );
     149    m_data->titleLabel->setText( text );
    155150
    156151    // footer
    157     d_data->footerLabel = new QwtTextLabel( this );
    158     d_data->footerLabel->setObjectName( "QwtPlotFooter" );
     152    m_data->footerLabel = new QwtTextLabel( this );
     153    m_data->footerLabel->setObjectName( "QwtPlotFooter" );
    159154
    160155    QwtText footer;
    161156    footer.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap );
    162     d_data->footerLabel->setText( footer );
     157    m_data->footerLabel->setText( footer );
    163158
    164159    // legend
    165     d_data->legend = NULL;
    166 
    167     // axis
     160    m_data->legend = NULL;
     161
     162    // axes
    168163    initAxesData();
    169164
    170165    // canvas
    171     d_data->canvas = new QwtPlotCanvas( this );
    172     d_data->canvas->setObjectName( "QwtPlotCanvas" );
    173     d_data->canvas->installEventFilter( this );
     166    m_data->canvas = new QwtPlotCanvas( this );
     167    m_data->canvas->setObjectName( "QwtPlotCanvas" );
     168    m_data->canvas->installEventFilter( this );
    174169
    175170    setSizePolicy( QSizePolicy::MinimumExpanding,
    … …  
    178173    resize( 200, 200 );
    179174
    180     QList<QWidget *> focusChain;
    181     focusChain << this << d_data->titleLabel << axisWidget( xTop )
    182         << axisWidget( yLeft ) << d_data->canvas << axisWidget( yRight )
    183         << axisWidget( xBottom ) << d_data->footerLabel;
     175    using namespace QwtAxis;
     176
     177    QList< QWidget* > focusChain;
     178    focusChain << this << m_data->titleLabel << axisWidget( XTop )
     179               << axisWidget( YLeft ) << m_data->canvas
     180               << axisWidget( YRight ) << axisWidget( XBottom )
     181               << m_data->footerLabel;
    184182
    185183    for ( int i = 0; i < focusChain.size() - 1; i++ )
    186         qwtSetTabOrder( focusChain[i], focusChain[i+1], false );
     184        qwtSetTabOrder( focusChain[i], focusChain[i + 1], false );
    187185
    188186    qwtEnableLegendItems( this, true );
    … …  
    190188
    191189/*!
    192   \brief Set the drawing canvas of the plot widget
    193 
    194   QwtPlot invokes methods of the canvas as meta methods ( see QMetaObject ).
    195   In opposite to using conventional C++ techniques like virtual methods
    196   they allow to use canvas implementations that are derived from
    197   QWidget or QGLWidget.
    198 
    199   The following meta methods could be implemented:
    200 
    201   - replot()
     190   \brief Set the drawing canvas of the plot widget
     191
     192   QwtPlot invokes methods of the canvas as meta methods ( see QMetaObject ).
     193   In opposite to using conventional C++ techniques like virtual methods
     194   they allow to use canvas implementations that are derived from
     195   QWidget or QGLWidget.
     196
     197   The following meta methods could be implemented:
     198
     199   - replot()
    202200    When the canvas doesn't offer a replot method, QwtPlot calls
    203201    update() instead.
    204202
    205   - borderPath()
     203   - borderPath()
    206204    The border path is necessary to clip the content of the canvas
    207205    When the canvas doesn't have any special border ( f.e rounded corners )
    208206    it is o.k. not to implement this method.
    209207
    210   The default canvas is a QwtPlotCanvas
    211 
    212   \param canvas Canvas Widget
    213   \sa canvas()
    214  */
    215 void QwtPlot::setCanvas( QWidget *canvas )
    216 {
    217     if ( canvas == d_data->canvas )
     208   The default canvas is a QwtPlotCanvas
     209
     210   \param canvas Canvas Widget
     211   \sa canvas()
     212 */
     213void QwtPlot::setCanvas( QWidget* canvas )
     214{
     215    if ( canvas == m_data->canvas )
    218216        return;
    219217
    220     delete d_data->canvas;
    221     d_data->canvas = canvas;
     218    delete m_data->canvas;
     219    m_data->canvas = canvas;
    222220
    223221    if ( canvas )
    … …  
    232230
    233231/*!
    234   \brief Adds handling of layout requests
    235   \param event Event
    236 
    237   \return See QFrame::event()
    238 */
    239 bool QwtPlot::event( QEvent *event )
     232   \brief Adds handling of layout requests
     233   \param event Event
     234
     235   \return See QFrame::event()
     236 */
     237bool QwtPlot::event( QEvent* event )
    240238{
    241239    bool ok = QFrame::event( event );
    … …  
    254252
    255253/*!
    256   \brief Event filter
    257 
    258   The plot handles the following events for the canvas:
    259 
    260   - QEvent::Resize
     254   \brief Event filter
     255
     256   The plot handles the following events for the canvas:
     257
     258   - QEvent::Resize
    261259    The canvas margins might depend on its size
    262260
    263   - QEvent::ContentsRectChange
     261   - QEvent::ContentsRectChange
    264262    The layout needs to be recalculated
    265263
    266   \param object Object to be filtered
    267   \param event Event
    268 
    269   \return See QFrame::eventFilter()
    270 
    271   \sa updateCanvasMargins(), updateLayout()
    272 */
    273 bool QwtPlot::eventFilter( QObject *object, QEvent *event )
    274 {
    275     if ( object == d_data->canvas )
     264   \param object Object to be filtered
     265   \param event Event
     266
     267   \return See QFrame::eventFilter()
     268
     269   \sa updateCanvasMargins(), updateLayout()
     270 */
     271bool QwtPlot::eventFilter( QObject* object, QEvent* event )
     272{
     273    if ( object == m_data->canvas )
    276274    {
    277275        if ( event->type() == QEvent::Resize )
    … …  
    291289void QwtPlot::autoRefresh()
    292290{
    293     if ( d_data->autoReplot )
     291    if ( m_data->autoReplot )
    294292        replot();
    295293}
    296294
    297295/*!
    298   \brief Set or reset the autoReplot option
    299 
    300   If the autoReplot option is set, the plot will be
    301   updated implicitly by manipulating member functions.
    302   Since this may be time-consuming, it is recommended
    303   to leave this option switched off and call replot()
    304   explicitly if necessary.
    305 
    306   The autoReplot option is set to false by default, which
    307   means that the user has to call replot() in order to make
    308   changes visible.
    309   \param tf \c true or \c false. Defaults to \c true.
    310   \sa replot()
    311 */
     296   \brief Set or reset the autoReplot option
     297
     298   If the autoReplot option is set, the plot will be
     299   updated implicitly by manipulating member functions.
     300   Since this may be time-consuming, it is recommended
     301   to leave this option switched off and call replot()
     302   explicitly if necessary.
     303
     304   The autoReplot option is set to false by default, which
     305   means that the user has to call replot() in order to make
     306   changes visible.
     307   \param tf \c true or \c false. Defaults to \c true.
     308   \sa replot()
     309 */
    312310void QwtPlot::setAutoReplot( bool tf )
    313311{
    314     d_data->autoReplot = tf;
    315 }
    316 
    317 /*!
    318   \return true if the autoReplot option is set.
    319   \sa setAutoReplot()
    320 */
     312    m_data->autoReplot = tf;
     313}
     314
     315/*!
     316   \return true if the autoReplot option is set.
     317   \sa setAutoReplot()
     318 */
    321319bool QwtPlot::autoReplot() const
    322320{
    323     return d_data->autoReplot;
    324 }
    325 
    326 /*!
    327   Change the plot's title
    328   \param title New title
    329 */
    330 void QwtPlot::setTitle( const QString &title )
    331 {
    332     if ( title != d_data->titleLabel->text().text() )
    333     {
    334         d_data->titleLabel->setText( title );
     321    return m_data->autoReplot;
     322}
     323
     324/*!
     325   Change the plot's title
     326   \param title New title
     327 */
     328void QwtPlot::setTitle( const QString& title )
     329{
     330    if ( title != m_data->titleLabel->text().text() )
     331    {
     332        m_data->titleLabel->setText( title );
    335333        updateLayout();
    336334    }
    … …  
    338336
    339337/*!
    340   Change the plot's title
    341   \param title New title
    342 */
    343 void QwtPlot::setTitle( const QwtText &title )
    344 {
    345     if ( title != d_data->titleLabel->text() )
    346     {
    347         d_data->titleLabel->setText( title );
     338   Change the plot's title
     339   \param title New title
     340 */
     341void QwtPlot::setTitle( const QwtText& title )
     342{
     343    if ( title != m_data->titleLabel->text() )
     344    {
     345        m_data->titleLabel->setText( title );
    348346        updateLayout();
    349347    }
    … …  
    353351QwtText QwtPlot::title() const
    354352{
    355     return d_data->titleLabel->text();
     353    return m_data->titleLabel->text();
    356354}
    357355
    358356//! \return Title label widget.
    359 QwtTextLabel *QwtPlot::titleLabel()
    360 {
    361     return d_data->titleLabel;
     357QwtTextLabel* QwtPlot::titleLabel()
     358{
     359    return m_data->titleLabel;
    362360}
    363361
    364362//! \return Title label widget.
    365 const QwtTextLabel *QwtPlot::titleLabel() const
    366 {
    367     return d_data->titleLabel;
    368 }
    369 
    370 /*!
    371   Change the text the footer
    372   \param text New text of the footer
    373 */
    374 void QwtPlot::setFooter( const QString &text )
    375 {
    376     if ( text != d_data->footerLabel->text().text() )
    377     {
    378         d_data->footerLabel->setText( text );
     363const QwtTextLabel* QwtPlot::titleLabel() const
     364{
     365    return m_data->titleLabel;
     366}
     367
     368/*!
     369   Change the text the footer
     370   \param text New text of the footer
     371 */
     372void QwtPlot::setFooter( const QString& text )
     373{
     374    if ( text != m_data->footerLabel->text().text() )
     375    {
     376        m_data->footerLabel->setText( text );
    379377        updateLayout();
    380378    }
    … …  
    382380
    383381/*!
    384   Change the text the footer
    385   \param text New text of the footer
    386 */
    387 void QwtPlot::setFooter( const QwtText &text )
    388 {
    389     if ( text != d_data->footerLabel->text() )
    390     {
    391         d_data->footerLabel->setText( text );
     382   Change the text the footer
     383   \param text New text of the footer
     384 */
     385void QwtPlot::setFooter( const QwtText& text )
     386{
     387    if ( text != m_data->footerLabel->text() )
     388    {
     389        m_data->footerLabel->setText( text );
    392390        updateLayout();
    393391    }
    … …  
    397395QwtText QwtPlot::footer() const
    398396{
    399     return d_data->footerLabel->text();
     397    return m_data->footerLabel->text();
    400398}
    401399
    402400//! \return Footer label widget.
    403 QwtTextLabel *QwtPlot::footerLabel()
    404 {
    405     return d_data->footerLabel;
     401QwtTextLabel* QwtPlot::footerLabel()
     402{
     403    return m_data->footerLabel;
    406404}
    407405
    408406//! \return Footer label widget.
    409 const QwtTextLabel *QwtPlot::footerLabel() const
    410 {
    411     return d_data->footerLabel;
     407const QwtTextLabel* QwtPlot::footerLabel() const
     408{
     409    return m_data->footerLabel;
    412410}
    413411
    … …  
    418416   \sa plotLayout()
    419417 */
    420 void QwtPlot::setPlotLayout( QwtPlotLayout *layout )
    421 {
    422     if ( layout != d_data->layout )
    423     {
    424         delete d_data->layout;
    425         d_data->layout = layout;
     418void QwtPlot::setPlotLayout( QwtPlotLayout* layout )
     419{
     420    if ( layout != m_data->layout )
     421    {
     422        delete m_data->layout;
     423        m_data->layout = layout;
    426424
    427425        updateLayout();
    … …  
    430428
    431429//! \return the plot's layout
    432 QwtPlotLayout *QwtPlot::plotLayout()
    433 {
    434     return d_data->layout;
     430QwtPlotLayout* QwtPlot::plotLayout()
     431{
     432    return m_data->layout;
    435433}
    436434
    437435//! \return the plot's layout
    438 const QwtPlotLayout *QwtPlot::plotLayout() const
    439 {
    440     return d_data->layout;
    441 }
    442 
    443 /*!
    444   \return the plot's legend
    445   \sa insertLegend()
    446 */
    447 QwtAbstractLegend *QwtPlot::legend()
    448 {
    449     return d_data->legend;
    450 }
    451 
    452 /*!
    453   \return the plot's legend
    454   \sa insertLegend()
    455 */
    456 const QwtAbstractLegend *QwtPlot::legend() const
    457 {
    458     return d_data->legend;
    459 }
    460 
    461 
    462 /*!
    463   \return the plot's canvas
    464 */
    465 QWidget *QwtPlot::canvas()
    466 {
    467     return d_data->canvas;
    468 }
    469 
    470 /*!
    471   \return the plot's canvas
    472 */
    473 const QWidget *QwtPlot::canvas() const
    474 {
    475     return d_data->canvas;
    476 }
    477 
    478 /*!
    479   \return Size hint for the plot widget
    480   \sa minimumSizeHint()
    481 */
     436const QwtPlotLayout* QwtPlot::plotLayout() const
     437{
     438    return m_data->layout;
     439}
     440
     441/*!
     442   \return the plot's legend
     443   \sa insertLegend()
     444 */
     445QwtAbstractLegend* QwtPlot::legend()
     446{
     447    return m_data->legend;
     448}
     449
     450/*!
     451   \return the plot's legend
     452   \sa insertLegend()
     453 */
     454const QwtAbstractLegend* QwtPlot::legend() const
     455{
     456    return m_data->legend;
     457}
     458
     459
     460/*!
     461   \return the plot's canvas
     462 */
     463QWidget* QwtPlot::canvas()
     464{
     465    return m_data->canvas;
     466}
     467
     468/*!
     469   \return the plot's canvas
     470 */
     471const QWidget* QwtPlot::canvas() const
     472{
     473    return m_data->canvas;
     474}
     475
     476/*!
     477   \return Size hint for the plot widget
     478   \sa minimumSizeHint()
     479 */
    482480QSize QwtPlot::sizeHint() const
    483481{
    484482    int dw = 0;
    485483    int dh = 0;
    486     for ( int axisId = 0; axisId < axisCnt; axisId++ )
    487     {
    488         if ( axisEnabled( axisId ) )
    489         {
    490             const int niceDist = 40;
    491             const QwtScaleWidget *scaleWidget = axisWidget( axisId );
    492             const QwtScaleDiv &scaleDiv = scaleWidget->scaleDraw()->scaleDiv();
    493             const int majCnt = scaleDiv.ticks( QwtScaleDiv::MajorTick ).count();
    494 
    495             if ( axisId == yLeft || axisId == yRight )
     484
     485    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     486    {
     487        {
     488            const QwtAxisId axisId( axisPos );
     489
     490            if ( isAxisVisible( axisId ) )
    496491            {
    497                 int hDiff = ( majCnt - 1 ) * niceDist
    498                     - scaleWidget->minimumSizeHint().height();
    499                 if ( hDiff > dh )
    500                     dh = hDiff;
     492                const int niceDist = 40;
     493                const QwtScaleWidget* scaleWidget = axisWidget( axisId );
     494                const QwtScaleDiv& scaleDiv = scaleWidget->scaleDraw()->scaleDiv();
     495                const int majCnt = scaleDiv.ticks( QwtScaleDiv::MajorTick ).count();
     496
     497                const QSize hint = scaleWidget->minimumSizeHint();
     498
     499                if ( QwtAxis::isYAxis( axisPos ) )
     500                {
     501                    const int hDiff = ( majCnt - 1 ) * niceDist - hint.height();
     502                    dh = qMax( dh, hDiff );
     503                }
     504                else
     505                {
     506                    const int wDiff = ( majCnt - 1 ) * niceDist - hint.width();
     507                    dw = qMax( dw, wDiff );
     508                }
     509            }
     510        }
     511    }
     512    return minimumSizeHint() + QSize( dw, dh );
     513}
     514
     515/*!
     516   \brief Return a minimum size hint
     517 */
     518QSize QwtPlot::minimumSizeHint() const
     519{
     520    QSize hint = m_data->layout->minimumSizeHint( this );
     521    hint += QSize( 2 * frameWidth(), 2 * frameWidth() );
     522
     523    return hint;
     524}
     525
     526/*!
     527   Resize and update internal layout
     528   \param e Resize event
     529 */
     530void QwtPlot::resizeEvent( QResizeEvent* e )
     531{
     532    QFrame::resizeEvent( e );
     533    updateLayout();
     534}
     535
     536/*!
     537   \brief Redraw the plot
     538
     539   If the autoReplot option is not set (which is the default)
     540   or if any curves are attached to raw data, the plot has to
     541   be refreshed explicitly in order to make changes visible.
     542
     543   \sa updateAxes(), setAutoReplot()
     544 */
     545void QwtPlot::replot()
     546{
     547    bool doAutoReplot = autoReplot();
     548    setAutoReplot( false );
     549
     550    updateAxes();
     551
     552    /*
     553       Maybe the layout needs to be updated, because of changed
     554       axes labels. We need to process them here before painting
     555       to avoid that scales and canvas get out of sync.
     556     */
     557    QApplication::sendPostedEvents( this, QEvent::LayoutRequest );
     558
     559    if ( m_data->canvas )
     560    {
     561        const bool ok = QMetaObject::invokeMethod(
     562            m_data->canvas, "replot", Qt::DirectConnection );
     563        if ( !ok )
     564        {
     565            // fallback, when canvas has no a replot method
     566            m_data->canvas->update( m_data->canvas->contentsRect() );
     567        }
     568    }
     569
     570    setAutoReplot( doAutoReplot );
     571}
     572
     573/*!
     574   \brief Adjust plot content to its current size.
     575   \sa resizeEvent()
     576 */
     577void QwtPlot::updateLayout()
     578{
     579    QwtPlotLayout* layout = m_data->layout;
     580    layout->activate( this, contentsRect() );
     581
     582    const QRect titleRect = layout->titleRect().toRect();
     583    const QRect footerRect = layout->footerRect().toRect();
     584    const QRect legendRect = layout->legendRect().toRect();
     585    const QRect canvasRect = layout->canvasRect().toRect();
     586
     587    // resize and show the visible widgets
     588
     589    if ( !m_data->titleLabel->text().isEmpty() )
     590    {
     591        m_data->titleLabel->setGeometry( titleRect );
     592        if ( !m_data->titleLabel->isVisibleTo( this ) )
     593            m_data->titleLabel->show();
     594    }
     595    else
     596        m_data->titleLabel->hide();
     597
     598    if ( !m_data->footerLabel->text().isEmpty() )
     599    {
     600        m_data->footerLabel->setGeometry( footerRect );
     601        if ( !m_data->footerLabel->isVisibleTo( this ) )
     602            m_data->footerLabel->show();
     603    }
     604    else
     605    {
     606        m_data->footerLabel->hide();
     607    }
     608
     609    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     610    {
     611        {
     612            const QwtAxisId axisId( axisPos );
     613
     614            QwtScaleWidget* scaleWidget = axisWidget( axisId );
     615
     616            if ( isAxisVisible( axisId ) )
     617            {
     618                const QRect scaleRect = layout->scaleRect( axisId ).toRect();
     619
     620                if ( scaleRect != scaleWidget->geometry() )
     621                {
     622                    scaleWidget->setGeometry( scaleRect );
     623
     624                    int startDist, endDist;
     625                    scaleWidget->getBorderDistHint( startDist, endDist );
     626                    scaleWidget->setBorderDist( startDist, endDist );
     627                }
     628
     629                if ( !scaleWidget->isVisibleTo( this ) )
     630                    scaleWidget->show();
    501631            }
    502632            else
    503633            {
    504                 int wDiff = ( majCnt - 1 ) * niceDist
    505                     - scaleWidget->minimumSizeHint().width();
    506                 if ( wDiff > dw )
    507                     dw = wDiff;
     634                scaleWidget->hide();
    508635            }
    509636        }
    510637    }
    511     return minimumSizeHint() + QSize( dw, dh );
    512 }
    513 
    514 /*!
    515   \brief Return a minimum size hint
    516 */
    517 QSize QwtPlot::minimumSizeHint() const
    518 {
    519     QSize hint = d_data->layout->minimumSizeHint( this );
    520     hint += QSize( 2 * frameWidth(), 2 * frameWidth() );
    521 
    522     return hint;
    523 }
    524 
    525 /*!
    526   Resize and update internal layout
    527   \param e Resize event
    528 */
    529 void QwtPlot::resizeEvent( QResizeEvent *e )
    530 {
    531     QFrame::resizeEvent( e );
    532     updateLayout();
    533 }
    534 
    535 /*!
    536   \brief Redraw the plot
    537 
    538   If the autoReplot option is not set (which is the default)
    539   or if any curves are attached to raw data, the plot has to
    540   be refreshed explicitly in order to make changes visible.
    541 
    542   \sa updateAxes(), setAutoReplot()
    543 */
    544 void QwtPlot::replot()
    545 {
    546     bool doAutoReplot = autoReplot();
    547     setAutoReplot( false );
    548 
    549     updateAxes();
    550 
    551     /*
    552       Maybe the layout needs to be updated, because of changed
    553       axes labels. We need to process them here before painting
    554       to avoid that scales and canvas get out of sync.
    555      */
    556     QApplication::sendPostedEvents( this, QEvent::LayoutRequest );
    557 
    558     if ( d_data->canvas )
    559     {
    560         const bool ok = QMetaObject::invokeMethod(
    561             d_data->canvas, "replot", Qt::DirectConnection );
    562         if ( !ok )
    563         {
    564             // fallback, when canvas has no a replot method
    565             d_data->canvas->update( d_data->canvas->contentsRect() );
    566         }
    567     }
    568 
    569     setAutoReplot( doAutoReplot );
    570 }
    571 
    572 /*!
    573   \brief Adjust plot content to its current size.
    574   \sa resizeEvent()
    575 */
    576 void QwtPlot::updateLayout()
    577 {
    578     d_data->layout->activate( this, contentsRect() );
    579 
    580     QRect titleRect = d_data->layout->titleRect().toRect();
    581     QRect footerRect = d_data->layout->footerRect().toRect();
    582     QRect scaleRect[QwtPlot::axisCnt];
    583     for ( int axisId = 0; axisId < axisCnt; axisId++ )
    584         scaleRect[axisId] = d_data->layout->scaleRect( axisId ).toRect();
    585     QRect legendRect = d_data->layout->legendRect().toRect();
    586     QRect canvasRect = d_data->layout->canvasRect().toRect();
    587 
    588     // resize and show the visible widgets
    589 
    590     if ( !d_data->titleLabel->text().isEmpty() )
    591     {
    592         d_data->titleLabel->setGeometry( titleRect );
    593         if ( !d_data->titleLabel->isVisibleTo( this ) )
    594             d_data->titleLabel->show();
    595     }
    596     else
    597         d_data->titleLabel->hide();
    598 
    599     if ( !d_data->footerLabel->text().isEmpty() )
    600     {
    601         d_data->footerLabel->setGeometry( footerRect );
    602         if ( !d_data->footerLabel->isVisibleTo( this ) )
    603             d_data->footerLabel->show();
    604     }
    605     else
    606     {
    607         d_data->footerLabel->hide();
    608     }
    609 
    610     for ( int axisId = 0; axisId < axisCnt; axisId++ )
    611     {
    612         QwtScaleWidget* scaleWidget = axisWidget( axisId );
    613 
    614         if ( axisEnabled( axisId ) )
    615         {
    616             if ( scaleRect[axisId] != scaleWidget->geometry() )
    617             {
    618                 scaleWidget->setGeometry( scaleRect[axisId] );
    619 
    620                 int startDist, endDist;
    621                 scaleWidget->getBorderDistHint( startDist, endDist );
    622                 scaleWidget->setBorderDist( startDist, endDist );
    623             }
    624 
    625 #if 1
    626             if ( axisId == xBottom || axisId == xTop )
    627             {
    628                 // do we need this code any longer ???
    629 
    630                 QRegion r( scaleRect[axisId] );
    631                 if ( axisEnabled( yLeft ) )
    632                     r = r.subtracted( QRegion( scaleRect[yLeft] ) );
    633                 if ( axisEnabled( yRight ) )
    634                     r = r.subtracted( QRegion( scaleRect[yRight] ) );
    635                 r.translate( -scaleRect[ axisId ].x(),
    636                     -scaleRect[axisId].y() );
    637 
    638                 scaleWidget->setMask( r );
    639             }
    640 #endif
    641             if ( !scaleWidget->isVisibleTo( this ) )
    642                 scaleWidget->show();
     638
     639    if ( m_data->legend )
     640    {
     641        if ( m_data->legend->isEmpty() )
     642        {
     643            m_data->legend->hide();
    643644        }
    644645        else
    645646        {
    646             scaleWidget->hide();
    647         }
    648     }
    649 
    650     if ( d_data->legend )
    651     {
    652         if ( d_data->legend->isEmpty() )
    653         {
    654             d_data->legend->hide();
    655         }
    656         else
    657         {
    658             d_data->legend->setGeometry( legendRect );
    659             d_data->legend->show();
    660         }
    661     }
    662 
    663     d_data->canvas->setGeometry( canvasRect );
    664 }
    665 
    666 /*!
    667   \brief Calculate the canvas margins
    668 
    669   \param maps QwtPlot::axisCnt maps, mapping between plot and paint device coordinates
    670   \param canvasRect Bounding rectangle where to paint
    671   \param left Return parameter for the left margin
    672   \param top Return parameter for the top margin
    673   \param right Return parameter for the right margin
    674   \param bottom Return parameter for the bottom margin
    675 
    676   Plot items might indicate, that they need some extra space
    677   at the borders of the canvas by the QwtPlotItem::Margins flag.
    678 
    679   updateCanvasMargins(), QwtPlotItem::getCanvasMarginHint()
     647            m_data->legend->setGeometry( legendRect );
     648            m_data->legend->show();
     649        }
     650    }
     651
     652    m_data->canvas->setGeometry( canvasRect );
     653}
     654
     655/*!
     656   \brief Calculate the canvas margins
     657
     658   \param maps QwtAxis::AxisCount maps, mapping between plot and paint device coordinates
     659   \param canvasRect Bounding rectangle where to paint
     660   \param left Return parameter for the left margin
     661   \param top Return parameter for the top margin
     662   \param right Return parameter for the right margin
     663   \param bottom Return parameter for the bottom margin
     664
     665   Plot items might indicate, that they need some extra space
     666   at the borders of the canvas by the QwtPlotItem::Margins flag.
     667
     668   updateCanvasMargins(), QwtPlotItem::getCanvasMarginHint()
    680669 */
    681670void QwtPlot::getCanvasMarginsHint(
    682     const QwtScaleMap maps[], const QRectF &canvasRect,
    683     double &left, double &top, double &right, double &bottom) const
     671    const QwtScaleMap maps[], const QRectF& canvasRect,
     672    double& left, double& top, double& right, double& bottom) const
    684673{
    685674    left = top = right = bottom = -1.0;
    … …  
    689678        it != itmList.end(); ++it )
    690679    {
    691         const QwtPlotItem *item = *it;
     680        const QwtPlotItem* item = *it;
    692681        if ( item->testItemAttribute( QwtPlotItem::Margins ) )
    693682        {
    694             double m[ QwtPlot::axisCnt ];
     683            using namespace QwtAxis;
     684
     685            double m[ AxisPositions ];
    695686            item->getCanvasMarginHint(
    696687                maps[ item->xAxis() ], maps[ item->yAxis() ],
    697                 canvasRect, m[yLeft], m[xTop], m[yRight], m[xBottom] );
    698 
    699             left = qMax( left, m[yLeft] );
    700             top = qMax( top, m[xTop] );
    701             right = qMax( right, m[yRight] );
    702             bottom = qMax( bottom, m[xBottom] );
    703         }
    704     }
    705 }
    706 
    707 /*!
    708   \brief Update the canvas margins
    709 
    710   Plot items might indicate, that they need some extra space
    711   at the borders of the canvas by the QwtPlotItem::Margins flag.
    712 
    713   getCanvasMarginsHint(), QwtPlotItem::getCanvasMarginHint()
     688                canvasRect, m[YLeft], m[XTop], m[YRight], m[XBottom] );
     689
     690            left = qwtMaxF( left, m[YLeft] );
     691            top = qwtMaxF( top, m[XTop] );
     692            right = qwtMaxF( right, m[YRight] );
     693            bottom = qwtMaxF( bottom, m[XBottom] );
     694        }
     695    }
     696}
     697
     698/*!
     699   \brief Update the canvas margins
     700
     701   Plot items might indicate, that they need some extra space
     702   at the borders of the canvas by the QwtPlotItem::Margins flag.
     703
     704   getCanvasMarginsHint(), QwtPlotItem::getCanvasMarginHint()
    714705 */
    715706void QwtPlot::updateCanvasMargins()
    716707{
    717     QwtScaleMap maps[axisCnt];
    718     for ( int axisId = 0; axisId < axisCnt; axisId++ )
     708    using namespace QwtAxis;
     709
     710    QwtScaleMap maps[ AxisPositions ];
     711    for ( int axisId = 0; axisId < AxisPositions; axisId++ )
    719712        maps[axisId] = canvasMap( axisId );
    720713
    721     double margins[axisCnt];
     714    double margins[AxisPositions];
    722715    getCanvasMarginsHint( maps, canvas()->contentsRect(),
    723         margins[yLeft], margins[xTop], margins[yRight], margins[xBottom] );
     716        margins[YLeft], margins[XTop], margins[YRight], margins[XBottom] );
    724717
    725718    bool doUpdate = false;
    726     for ( int axisId = 0; axisId < axisCnt; axisId++ )
    727     {
    728         if ( margins[axisId] >= 0.0 )
    729         {
    730             const int m = qCeil( margins[axisId] );
    731             plotLayout()->setCanvasMargin( m, axisId);
     719    for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ )
     720    {
     721        if ( margins[axisPos] >= 0.0 )
     722        {
     723            const int m = qwtCeil( margins[axisPos] );
     724            plotLayout()->setCanvasMargin( m, axisPos);
    732725            doUpdate = true;
    733726        }
    … …  
    739732
    740733/*!
    741   Redraw the canvas.
    742   \param painter Painter used for drawing
    743 
    744   \warning drawCanvas calls drawItems what is also used
     734   Redraw the canvas.
     735   \param painter Painter used for drawing
     736
     737   \warning drawCanvas calls drawItems what is also used
    745738           for printing. Applications that like to add individual
    746739           plot items better overload drawItems()
    747   \sa drawItems()
    748 */
    749 void QwtPlot::drawCanvas( QPainter *painter )
    750 {
    751     QwtScaleMap maps[axisCnt];
    752     for ( int axisId = 0; axisId < axisCnt; axisId++ )
    753         maps[axisId] = canvasMap( axisId );
    754 
    755     drawItems( painter, d_data->canvas->contentsRect(), maps );
    756 }
    757 
    758 /*!
    759   Redraw the canvas items.
    760 
    761   \param painter Painter used for drawing
    762   \param canvasRect Bounding rectangle where to paint
    763   \param maps QwtPlot::axisCnt maps, mapping between plot and paint device coordinates
    764 
    765   \note Usually canvasRect is contentsRect() of the plot canvas.
     740   \sa drawItems()
     741 */
     742void QwtPlot::drawCanvas( QPainter* painter )
     743{
     744    QwtScaleMap maps[ QwtAxis::AxisPositions ];
     745    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     746        maps[axisPos] = canvasMap( axisPos );
     747
     748    drawItems( painter, m_data->canvas->contentsRect(), maps );
     749}
     750
     751/*!
     752   Redraw the canvas items.
     753
     754   \param painter Painter used for drawing
     755   \param canvasRect Bounding rectangle where to paint
     756   \param maps QwtAxis::AxisCount maps, mapping between plot and paint device coordinates
     757
     758   \note Usually canvasRect is contentsRect() of the plot canvas.
    766759        Due to a bug in Qt this rectangle might be wrong for certain
    767760        frame styles ( f.e QFrame::Box ) and it might be necessary to
    768761        fix the margins manually using QWidget::setContentsMargins()
    769 */
    770 
    771 void QwtPlot::drawItems( QPainter *painter, const QRectF &canvasRect,
    772         const QwtScaleMap maps[axisCnt] ) const
     762 */
     763
     764void QwtPlot::drawItems( QPainter* painter, const QRectF& canvasRect,
     765    const QwtScaleMap maps[ QwtAxis::AxisPositions ] ) const
    773766{
    774767    const QwtPlotItemList& itmList = itemList();
    … …  
    776769        it != itmList.end(); ++it )
    777770    {
    778         QwtPlotItem *item = *it;
     771        QwtPlotItem* item = *it;
    779772        if ( item && item->isVisible() )
    780773        {
     774            const QwtAxisId xAxis = item->xAxis();
     775            const QwtAxisId yAxis = item->yAxis();
     776
    781777            painter->save();
    782778
    783779            painter->setRenderHint( QPainter::Antialiasing,
    784780                item->testRenderHint( QwtPlotItem::RenderAntialiased ) );
     781
     782#if QT_VERSION < 0x050100
    785783            painter->setRenderHint( QPainter::HighQualityAntialiasing,
    786784                item->testRenderHint( QwtPlotItem::RenderAntialiased ) );
    787 
    788             item->draw( painter,
    789                 maps[item->xAxis()], maps[item->yAxis()],
    790                 canvasRect );
     785#endif
     786
     787            item->draw( painter, maps[xAxis], maps[yAxis], canvasRect );
    791788
    792789            painter->restore();
    … …  
    796793
    797794/*!
    798   \param axisId Axis
    799   \return Map for the axis on the canvas. With this map pixel coordinates can
     795   \param axisId Axis
     796   \return Map for the axis on the canvas. With this map pixel coordinates can
    800797          translated to plot coordinates and vice versa.
    801   \sa QwtScaleMap, transform(), invTransform()
    802 
    803 */
    804 QwtScaleMap QwtPlot::canvasMap( int axisId ) const
     798   \sa QwtScaleMap, transform(), invTransform()
     799 */
     800QwtScaleMap QwtPlot::canvasMap( QwtAxisId axisId ) const
    805801{
    806802    QwtScaleMap map;
    807     if ( !d_data->canvas )
     803    if ( !m_data->canvas )
    808804        return map;
    809805
    810806    map.setTransformation( axisScaleEngine( axisId )->transformation() );
    811807
    812     const QwtScaleDiv &sd = axisScaleDiv( axisId );
     808    const QwtScaleDiv& sd = axisScaleDiv( axisId );
    813809    map.setScaleInterval( sd.lowerBound(), sd.upperBound() );
    814810
    815     if ( axisEnabled( axisId ) )
    816     {
    817         const QwtScaleWidget *s = axisWidget( axisId );
    818         if ( axisId == yLeft || axisId == yRight )
    819         {
    820             double y = s->y() + s->startBorderDist() - d_data->canvas->y();
     811    if ( isAxisVisible( axisId ) )
     812    {
     813        const QwtScaleWidget* s = axisWidget( axisId );
     814        if ( QwtAxis::isYAxis( axisId ) )
     815        {
     816            double y = s->y() + s->startBorderDist() - m_data->canvas->y();
    821817            double h = s->height() - s->startBorderDist() - s->endBorderDist();
    822818            map.setPaintInterval( y + h, y );
    … …  
    824820        else
    825821        {
    826             double x = s->x() + s->startBorderDist() - d_data->canvas->x();
     822            double x = s->x() + s->startBorderDist() - m_data->canvas->x();
    827823            double w = s->width() - s->startBorderDist() - s->endBorderDist();
    828824            map.setPaintInterval( x, x + w );
    … …  
    831827    else
    832828    {
    833         const QRect &canvasRect = d_data->canvas->contentsRect();
    834         if ( axisId == yLeft || axisId == yRight )
     829        using namespace QwtAxis;
     830
     831        const QRect& canvasRect = m_data->canvas->contentsRect();
     832        if ( isYAxis( axisId ) )
    835833        {
    836834            int top = 0;
    837             if ( !plotLayout()->alignCanvasToScale( xTop ) )
    838                 top = plotLayout()->canvasMargin( xTop );
     835            if ( !plotLayout()->alignCanvasToScale( XTop ) )
     836                top = plotLayout()->canvasMargin( XTop );
    839837
    840838            int bottom = 0;
    841             if ( !plotLayout()->alignCanvasToScale( xBottom ) )
    842                 bottom = plotLayout()->canvasMargin( xBottom );
     839            if ( !plotLayout()->alignCanvasToScale( XBottom ) )
     840                bottom = plotLayout()->canvasMargin( XBottom );
    843841
    844842            map.setPaintInterval( canvasRect.bottom() - bottom,
    … …  
    848846        {
    849847            int left = 0;
    850             if ( !plotLayout()->alignCanvasToScale( yLeft ) )
    851                 left = plotLayout()->canvasMargin( yLeft );
     848            if ( !plotLayout()->alignCanvasToScale( YLeft ) )
     849                left = plotLayout()->canvasMargin( YLeft );
    852850
    853851            int right = 0;
    854             if ( !plotLayout()->alignCanvasToScale( yRight ) )
    855                 right = plotLayout()->canvasMargin( yRight );
     852            if ( !plotLayout()->alignCanvasToScale( YRight ) )
     853                right = plotLayout()->canvasMargin( YRight );
    856854
    857855            map.setPaintInterval( canvasRect.left() + left,
    … …  
    864862
    865863/*!
    866   \brief Change the background of the plotting area
    867 
    868   Sets brush to QPalette::Window of all color groups of
    869   the palette of the canvas. Using canvas()->setPalette()
    870   is a more powerful way to set these colors.
    871 
    872   \param brush New background brush
    873   \sa canvasBackground()
    874 */
    875 void QwtPlot::setCanvasBackground( const QBrush &brush )
    876 {
    877     QPalette pal = d_data->canvas->palette();
     864   \brief Change the background of the plotting area
     865
     866   Sets brush to QPalette::Window of all color groups of
     867   the palette of the canvas. Using canvas()->setPalette()
     868   is a more powerful way to set these colors.
     869
     870   \param brush New background brush
     871   \sa canvasBackground()
     872 */
     873void QwtPlot::setCanvasBackground( const QBrush& brush )
     874{
     875    QPalette pal = m_data->canvas->palette();
    878876    pal.setBrush( QPalette::Window, brush );
    879877
    … …  
    882880
    883881/*!
    884   Nothing else than: canvas()->palette().brush(
     882   Nothing else than: canvas()->palette().brush(
    885883        QPalette::Normal, QPalette::Window);
    886884
    887   \return Background brush of the plotting area.
    888   \sa setCanvasBackground()
    889 */
     885   \return Background brush of the plotting area.
     886   \sa setCanvasBackground()
     887 */
    890888QBrush QwtPlot::canvasBackground() const
    891889{
    … …  
    895893
    896894/*!
    897   \return \c true if the specified axis exists, otherwise \c false
    898   \param axisId axis index
    899  */
    900 bool QwtPlot::axisValid( int axisId )
    901 {
    902     return ( ( axisId >= QwtPlot::yLeft ) && ( axisId < QwtPlot::axisCnt ) );
    903 }
    904 
    905 /*!
    906   \brief Insert a legend
    907 
    908   If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend
    909   the legend will be organized in one column from top to down.
    910   Otherwise the legend items will be placed in a table
    911   with a best fit number of columns from left to right.
    912 
    913   insertLegend() will set the plot widget as parent for the legend.
    914   The legend will be deleted in the destructor of the plot or when
    915   another legend is inserted.
    916 
    917   Legends, that are not inserted into the layout of the plot widget
    918   need to connect to the legendDataChanged() signal. Calling updateLegend()
    919   initiates this signal for an initial update. When the application code
    920   wants to implement its own layout this also needs to be done for
    921   rendering plots to a document ( see QwtPlotRenderer ).
    922 
    923   \param legend Legend
    924   \param pos The legend's position. For top/left position the number
     895   \brief Insert a legend
     896
     897   If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend
     898   the legend will be organized in one column from top to down.
     899   Otherwise the legend items will be placed in a table
     900   with a best fit number of columns from left to right.
     901
     902   insertLegend() will set the plot widget as parent for the legend.
     903   The legend will be deleted in the destructor of the plot or when
     904   another legend is inserted.
     905
     906   Legends, that are not inserted into the layout of the plot widget
     907   need to connect to the legendDataChanged() signal. Calling updateLegend()
     908   initiates this signal for an initial update. When the application code
     909   wants to implement its own layout this also needs to be done for
     910   rendering plots to a document ( see QwtPlotRenderer ).
     911
     912   \param legend Legend
     913   \param pos The legend's position. For top/left position the number
    925914             of columns will be limited to 1, otherwise it will be set to
    926915             unlimited.
    927916
    928   \param ratio Ratio between legend and the bounding rectangle
     917   \param ratio Ratio between legend and the bounding rectangle
    929918               of title, canvas and axes. The legend will be shrunk
    930919               if it would need more space than the given ratio.
    … …  
    933922               The default vertical/horizontal ratio is 0.33/0.5.
    934923
    935   \sa legend(), QwtPlotLayout::legendPosition(),
     924   \sa legend(), QwtPlotLayout::legendPosition(),
    936925      QwtPlotLayout::setLegendPosition()
    937 */
    938 void QwtPlot::insertLegend( QwtAbstractLegend *legend,
     926 */
     927void QwtPlot::insertLegend( QwtAbstractLegend* legend,
    939928    QwtPlot::LegendPosition pos, double ratio )
    940929{
    941     d_data->layout->setLegendPosition( pos, ratio );
    942 
    943     if ( legend != d_data->legend )
    944     {
    945         if ( d_data->legend && d_data->legend->parent() == this )
    946             delete d_data->legend;
    947 
    948         d_data->legend = legend;
    949 
    950         if ( d_data->legend )
     930    m_data->layout->setLegendPosition( pos, ratio );
     931
     932    if ( legend != m_data->legend )
     933    {
     934        if ( m_data->legend && m_data->legend->parent() == this )
     935            delete m_data->legend;
     936
     937        m_data->legend = legend;
     938
     939        if ( m_data->legend )
    951940        {
    952941            connect(
    953942                this, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)),
    954                 d_data->legend, SLOT(updateLegend(QVariant,QList<QwtLegendData>) )
    955             );
    956 
    957             if ( d_data->legend->parent() != this )
    958                 d_data->legend->setParent( this );
     943                m_data->legend, SLOT(updateLegend(QVariant,QList<QwtLegendData>))
     944                );
     945
     946            if ( m_data->legend->parent() != this )
     947                m_data->legend->setParent( this );
    959948
    960949            qwtEnableLegendItems( this, false );
    … …  
    962951            qwtEnableLegendItems( this, true );
    963952
    964             QwtLegend *lgd = qobject_cast<QwtLegend *>( legend );
     953            QwtLegend* lgd = qobject_cast< QwtLegend* >( legend );
    965954            if ( lgd )
    966955            {
    967                 switch ( d_data->layout->legendPosition() )
     956                switch ( m_data->layout->legendPosition() )
    968957                {
    969958                    case LeftLegend:
    … …  
    985974            }
    986975
    987             QWidget *previousInChain = NULL;
    988             switch ( d_data->layout->legendPosition() )
     976            QWidget* previousInChain = NULL;
     977            switch ( m_data->layout->legendPosition() )
    989978            {
    990979                case LeftLegend:
    991980                {
    992                     previousInChain = axisWidget( QwtPlot::xTop );
     981                    const QwtAxisId axisId( QwtAxis::XTop );
     982                    previousInChain = axisWidget( axisId );
    993983                    break;
    994984                }
    … …  
    1000990                case RightLegend:
    1001991                {
    1002                     previousInChain = axisWidget( QwtPlot::yRight );
     992                    const QwtAxisId axisId( QwtAxis::YRight );
     993                    previousInChain = axisWidget( axisId );
    1003994                    break;
    1004995                }
    … …  
    10191010
    10201011/*!
    1021   Emit legendDataChanged() for all plot item
    1022 
    1023   \sa QwtPlotItem::legendData(), legendDataChanged()
     1012   Emit legendDataChanged() for all plot item
     1013
     1014   \sa QwtPlotItem::legendData(), legendDataChanged()
    10241015 */
    10251016void QwtPlot::updateLegend()
    … …  
    10341025
    10351026/*!
    1036   Emit legendDataChanged() for a plot item
    1037 
    1038   \param plotItem Plot item
    1039   \sa QwtPlotItem::legendData(), legendDataChanged()
    1040  */
    1041 void QwtPlot::updateLegend( const QwtPlotItem *plotItem )
     1027   Emit legendDataChanged() for a plot item
     1028
     1029   \param plotItem Plot item
     1030   \sa QwtPlotItem::legendData(), legendDataChanged()
     1031 */
     1032void QwtPlot::updateLegend( const QwtPlotItem* plotItem )
    10421033{
    10431034    if ( plotItem == NULL )
    10441035        return;
    10451036
    1046     QList<QwtLegendData> legendData;
     1037    QList< QwtLegendData > legendData;
    10471038
    10481039    if ( plotItem->testItemAttribute( QwtPlotItem::Legend ) )
    10491040        legendData = plotItem->legendData();
    10501041
    1051     const QVariant itemInfo = itemToInfo( const_cast< QwtPlotItem *>( plotItem) );
     1042    const QVariant itemInfo = itemToInfo( const_cast< QwtPlotItem* >( plotItem ) );
    10521043    Q_EMIT legendDataChanged( itemInfo, legendData );
    10531044}
    10541045
    10551046/*!
    1056   \brief Update all plot items interested in legend attributes
    1057 
    1058   Call QwtPlotItem::updateLegend(), when the QwtPlotItem::LegendInterest
    1059   flag is set.
    1060 
    1061   \param itemInfo Info about the plot item
    1062   \param legendData Entries to be displayed for the plot item ( usually 1 )
    1063 
    1064   \sa QwtPlotItem::LegendInterest,
     1047   \brief Update all plot items interested in legend attributes
     1048
     1049   Call QwtPlotItem::updateLegend(), when the QwtPlotItem::LegendInterest
     1050   flag is set.
     1051
     1052   \param itemInfo Info about the plot item
     1053   \param legendData Entries to be displayed for the plot item ( usually 1 )
     1054
     1055   \sa QwtPlotItem::LegendInterest,
    10651056      QwtPlotLegendItem, QwtPlotItem::updateLegend()
    10661057 */
    1067 void QwtPlot::updateLegendItems( const QVariant &itemInfo,
    1068     const QList<QwtLegendData> &legendData )
    1069 {
    1070     QwtPlotItem *plotItem = infoToItem( itemInfo );
     1058void QwtPlot::updateLegendItems( const QVariant& itemInfo,
     1059    const QList< QwtLegendData >& legendData )
     1060{
     1061    QwtPlotItem* plotItem = infoToItem( itemInfo );
    10711062    if ( plotItem )
    10721063    {
    … …  
    10751066            it != itmList.end(); ++it )
    10761067        {
    1077             QwtPlotItem *item = *it;
     1068            QwtPlotItem* item = *it;
    10781069            if ( item->testItemInterest( QwtPlotItem::LegendInterest ) )
    10791070                item->updateLegend( plotItem, legendData );
    … …  
    10831074
    10841075/*!
    1085   \brief Attach/Detach a plot item
    1086 
    1087   \param plotItem Plot item
    1088   \param on When true attach the item, otherwise detach it
    1089  */
    1090 void QwtPlot::attachItem( QwtPlotItem *plotItem, bool on )
     1076   \brief Attach/Detach a plot item
     1077
     1078   \param plotItem Plot item
     1079   \param on When true attach the item, otherwise detach it
     1080 */
     1081void QwtPlot::attachItem( QwtPlotItem* plotItem, bool on )
    10911082{
    10921083    if ( plotItem->testItemInterest( QwtPlotItem::LegendInterest ) )
    … …  
    10981089            it != itmList.end(); ++it )
    10991090        {
    1100             QwtPlotItem *item = *it;
    1101 
    1102             QList<QwtLegendData> legendData;
     1091            QwtPlotItem* item = *it;
     1092
     1093            QList< QwtLegendData > legendData;
    11031094            if ( on && item->testItemAttribute( QwtPlotItem::Legend ) )
    11041095            {
    … …  
    11271118        {
    11281119            const QVariant itemInfo = itemToInfo( plotItem );
    1129             Q_EMIT legendDataChanged( itemInfo, QList<QwtLegendData>() );
     1120            Q_EMIT legendDataChanged( itemInfo, QList< QwtLegendData >() );
    11301121        }
    11311122    }
    … …  
    11351126
    11361127/*!
    1137   \brief Build an information, that can be used to identify
     1128   \brief Build an information, that can be used to identify
    11381129         a plot item on the legend.
    11391130
    1140   The default implementation simply wraps the plot item
    1141   into a QVariant object. When overloading itemToInfo()
    1142   usually infoToItem() needs to reimplemeted too.
    1143 
    1144 \code
    1145     QVariant itemInfo;
    1146     qVariantSetValue( itemInfo, plotItem );
    1147 \endcode
    1148 
    1149   \param plotItem Plot item
    1150   \return Plot item embedded in a QVariant
    1151   \sa infoToItem()
    1152  */
    1153 QVariant QwtPlot::itemToInfo( QwtPlotItem *plotItem ) const
    1154 {
    1155     QVariant itemInfo;
    1156     qVariantSetValue( itemInfo, plotItem );
    1157 
    1158     return itemInfo;
    1159 }
    1160 
    1161 /*!
    1162   \brief Identify the plot item according to an item info object,
     1131   The default implementation simply wraps the plot item
     1132   into a QVariant object. When overloading itemToInfo()
     1133   usually infoToItem() needs to reimplemeted too.
     1134
     1135   \param plotItem Plot item
     1136   \return Plot item embedded in a QVariant
     1137   \sa infoToItem()
     1138 */
     1139QVariant QwtPlot::itemToInfo( QwtPlotItem* plotItem ) const
     1140{
     1141    return QVariant::fromValue( plotItem );
     1142}
     1143
     1144/*!
     1145   \brief Identify the plot item according to an item info object,
    11631146         that has bee generated from itemToInfo().
    11641147
    1165   The default implementation simply tries to unwrap a QwtPlotItem
    1166   pointer:
    1167 
    1168 \code
     1148   The default implementation simply tries to unwrap a QwtPlotItem
     1149   pointer:
     1150
     1151   \code
    11691152    if ( itemInfo.canConvert<QwtPlotItem *>() )
    11701153        return qvariant_cast<QwtPlotItem *>( itemInfo );
    1171 \endcode
    1172   \param itemInfo Plot item
    1173   \return A plot item, when successful, otherwise a NULL pointer.
    1174   \sa itemToInfo()
    1175 */
    1176 QwtPlotItem *QwtPlot::infoToItem( const QVariant &itemInfo ) const
    1177 {
    1178     if ( itemInfo.canConvert<QwtPlotItem *>() )
    1179         return qvariant_cast<QwtPlotItem *>( itemInfo );
     1154   \endcode
     1155   \param itemInfo Plot item
     1156   \return A plot item, when successful, otherwise a NULL pointer.
     1157   \sa itemToInfo()
     1158 */
     1159QwtPlotItem* QwtPlot::infoToItem( const QVariant& itemInfo ) const
     1160{
     1161    if ( itemInfo.canConvert< QwtPlotItem* >() )
     1162        return qvariant_cast< QwtPlotItem* >( itemInfo );
    11801163
    11811164    return NULL;
    11821165}
    11831166
    1184 
     1167#include "moc_qwt_plot.cpp"
  • trunk/BNC/qwt/qwt_plot.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_text.h"
     14#include "qwt_axis_id.h"
    1515#include "qwt_plot_dict.h"
    16 #include "qwt_scale_map.h"
    17 #include "qwt_interval.h"
     16
    1817#include <qframe.h>
    19 #include <qlist.h>
    20 #include <qvariant.h>
    2118
    2219class QwtPlotLayout;
    … …  
    2522class QwtScaleEngine;
    2623class QwtScaleDiv;
     24class QwtScaleMap;
    2725class QwtScaleDraw;
    2826class QwtTextLabel;
     27class QwtInterval;
     28class QwtText;
     29template< typename T > class QList;
     30
     31// 6.1 compatibility definitions
     32#define QWT_AXIS_COMPAT 1
    2933
    3034/*!
    31   \brief A 2-D plotting widget
    32 
    33   QwtPlot is a widget for plotting two-dimensional graphs.
    34   An unlimited number of plot items can be displayed on
    35   its canvas. Plot items might be curves (QwtPlotCurve), markers
    36   (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived
    37   from QwtPlotItem.
    38   A plot can have up to four axes, with each plot item attached to an x- and
    39   a y axis. The scales at the axes can be explicitly set (QwtScaleDiv), or
    40   are calculated from the plot items, using algorithms (QwtScaleEngine) which
    41   can be configured separately for each axis.
    42 
    43   The simpleplot example is a good starting point to see how to set up a
    44   plot widget.
    45 
    46   \image html plot.png
    47 
    48   \par Example
     35   \brief A 2-D plotting widget
     36
     37   QwtPlot is a widget for plotting two-dimensional graphs.
     38   An unlimited number of plot items can be displayed on
     39   its canvas. Plot items might be curves (QwtPlotCurve), markers
     40   (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived
     41   from QwtPlotItem.
     42   A plot can have up to four axes, with each plot item attached to an x- and
     43   a y axis. The scales at the axes can be explicitly set (QwtScaleDiv), or
     44   are calculated from the plot items, using algorithms (QwtScaleEngine) which
     45   can be configured separately for each axis.
     46
     47   The simpleplot example is a good starting point to see how to set up a
     48   plot widget.
     49
     50   \image html plot.png
     51
     52   \par Example
    4953    The following example shows (schematically) the most simple
    5054    way to use QwtPlot. By default, only the left and bottom axes are
    5155    visible and their scales are computed automatically.
    5256    \code
    53       #include <qwt_plot.h>
    54       #include <qwt_plot_curve.h>
     57 #include <qwt_plot.h>
     58 #include <qwt_plot_curve.h>
    5559
    5660      QwtPlot *myPlot = new QwtPlot( "Two Curves", parent );
    … …  
    7074      myPlot->replot();
    7175    \endcode
    72   \endpar
    73 */
    74 
    75 class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict
     76 */
     77
     78class QWT_EXPORT QwtPlot : public QFrame, public QwtPlotDict
    7679{
    7780    Q_OBJECT
    … …  
    7982    Q_PROPERTY( QBrush canvasBackground
    8083        READ canvasBackground WRITE setCanvasBackground )
     84
    8185    Q_PROPERTY( bool autoReplot READ autoReplot WRITE setAutoReplot )
    8286
    83 #if 0
    84     // This property is intended to configure the plot
    85     // widget from a special dialog in the deigner plugin.
    86     // Disabled until such a dialog has been implemented.
    87 
    88     Q_PROPERTY( QString propertiesDocument
    89         READ grabProperties WRITE applyProperties )
    90 #endif
    91 
    92 public:
    93     //! \brief Axis index
    94     enum Axis
    95     {
    96         //! Y axis left of the canvas
    97         yLeft,
    98 
    99         //! Y axis right of the canvas
    100         yRight,
    101 
    102         //! X axis below the canvas
    103         xBottom,
    104 
    105         //! X axis above the canvas
    106         xTop,
    107 
    108         //! Number of axes
    109         axisCnt
    110     };
    111 
     87  public:
    11288    /*!
    11389        Position of the legend, relative to the canvas.
    … …  
    11793    enum LegendPosition
    11894    {
    119         //! The legend will be left from the QwtPlot::yLeft axis.
     95        //! The legend will be left from the QwtAxis::YLeft axis.
    12096        LeftLegend,
    12197
    122         //! The legend will be right from the QwtPlot::yRight axis.
     98        //! The legend will be right from the QwtAxis::YRight axis.
    12399        RightLegend,
    124100
    … …  
    130106    };
    131107
    132     explicit QwtPlot( QWidget * = NULL );
    133     explicit QwtPlot( const QwtText &title, QWidget * = NULL );
     108    explicit QwtPlot( QWidget* = NULL );
     109    explicit QwtPlot( const QwtText& title, QWidget* = NULL );
    134110
    135111    virtual ~QwtPlot();
    136 
    137     void applyProperties( const QString & );
    138     QString grabProperties() const;
    139112
    140113    void setAutoReplot( bool = true );
    … …  
    143116    // Layout
    144117
    145     void setPlotLayout( QwtPlotLayout * );
    146 
    147     QwtPlotLayout *plotLayout();
    148     const QwtPlotLayout *plotLayout() const;
     118    void setPlotLayout( QwtPlotLayout* );
     119
     120    QwtPlotLayout* plotLayout();
     121    const QwtPlotLayout* plotLayout() const;
    149122
    150123    // Title
    151124
    152     void setTitle( const QString & );
    153     void setTitle( const QwtText & );
     125    void setTitle( const QString& );
     126    void setTitle( const QwtText& );
    154127    QwtText title() const;
    155128
    156     QwtTextLabel *titleLabel();
    157     const QwtTextLabel *titleLabel() const;
     129    QwtTextLabel* titleLabel();
     130    const QwtTextLabel* titleLabel() const;
    158131
    159132    // Footer
    160133
    161     void setFooter( const QString & );
    162     void setFooter( const QwtText & );
     134    void setFooter( const QString& );
     135    void setFooter( const QwtText& );
    163136    QwtText footer() const;
    164137
    165     QwtTextLabel *footerLabel();
    166     const QwtTextLabel *footerLabel() const;
     138    QwtTextLabel* footerLabel();
     139    const QwtTextLabel* footerLabel() const;
    167140
    168141    // Canvas
    169142
    170     void setCanvas( QWidget * );
    171 
    172     QWidget *canvas();
    173     const QWidget *canvas() const;
    174 
    175     void setCanvasBackground( const QBrush & );
     143    void setCanvas( QWidget* );
     144
     145    QWidget* canvas();
     146    const QWidget* canvas() const;
     147
     148    void setCanvasBackground( const QBrush& );
    176149    QBrush canvasBackground() const;
    177150
    178     virtual QwtScaleMap canvasMap( int axisId ) const;
    179 
    180     double invTransform( int axisId, int pos ) const;
    181     double transform( int axisId, double value ) const;
     151    virtual QwtScaleMap canvasMap( QwtAxisId ) const;
     152
     153    double invTransform( QwtAxisId, double pos ) const;
     154    double transform( QwtAxisId, double value ) const;
    182155
    183156    // Axes
    184157
    185     QwtScaleEngine *axisScaleEngine( int axisId );
    186     const QwtScaleEngine *axisScaleEngine( int axisId ) const;
    187     void setAxisScaleEngine( int axisId, QwtScaleEngine * );
    188 
    189     void setAxisAutoScale( int axisId, bool on = true );
    190     bool axisAutoScale( int axisId ) const;
    191 
    192     void enableAxis( int axisId, bool tf = true );
    193     bool axisEnabled( int axisId ) const;
    194 
    195     void setAxisFont( int axisId, const QFont & );
    196     QFont axisFont( int axisId ) const;
    197 
    198     void setAxisScale( int axisId, double min, double max, double stepSize = 0 );
    199     void setAxisScaleDiv( int axisId, const QwtScaleDiv & );
    200     void setAxisScaleDraw( int axisId, QwtScaleDraw * );
    201 
    202     double axisStepSize( int axisId ) const;
    203     QwtInterval axisInterval( int axisId ) const;
    204 
    205     const QwtScaleDiv &axisScaleDiv( int axisId ) const;
    206 
    207     const QwtScaleDraw *axisScaleDraw( int axisId ) const;
    208     QwtScaleDraw *axisScaleDraw( int axisId );
    209 
    210     const QwtScaleWidget *axisWidget( int axisId ) const;
    211     QwtScaleWidget *axisWidget( int axisId );
    212 
    213     void setAxisLabelAlignment( int axisId, Qt::Alignment );
    214     void setAxisLabelRotation( int axisId, double rotation );
    215 
    216     void setAxisTitle( int axisId, const QString & );
    217     void setAxisTitle( int axisId, const QwtText & );
    218     QwtText axisTitle( int axisId ) const;
    219 
    220     void setAxisMaxMinor( int axisId, int maxMinor );
    221     int axisMaxMinor( int axisId ) const;
    222 
    223     void setAxisMaxMajor( int axisId, int maxMajor );
    224     int axisMaxMajor( int axisId ) const;
     158    bool isAxisValid( QwtAxisId ) const;
     159
     160    void setAxisVisible( QwtAxisId, bool on = true );
     161    bool isAxisVisible( QwtAxisId ) const;
     162
     163    // Axes data
     164
     165    QwtScaleEngine* axisScaleEngine( QwtAxisId );
     166    const QwtScaleEngine* axisScaleEngine( QwtAxisId ) const;
     167    void setAxisScaleEngine( QwtAxisId, QwtScaleEngine* );
     168
     169    void setAxisAutoScale( QwtAxisId, bool on = true );
     170    bool axisAutoScale( QwtAxisId ) const;
     171
     172    void setAxisFont( QwtAxisId, const QFont& );
     173    QFont axisFont( QwtAxisId ) const;
     174
     175    void setAxisScale( QwtAxisId, double min, double max, double stepSize = 0 );
     176    void setAxisScaleDiv( QwtAxisId, const QwtScaleDiv& );
     177    void setAxisScaleDraw( QwtAxisId, QwtScaleDraw* );
     178
     179    double axisStepSize( QwtAxisId ) const;
     180    QwtInterval axisInterval( QwtAxisId ) const;
     181    const QwtScaleDiv& axisScaleDiv( QwtAxisId ) const;
     182
     183    const QwtScaleDraw* axisScaleDraw( QwtAxisId ) const;
     184    QwtScaleDraw* axisScaleDraw( QwtAxisId );
     185
     186    const QwtScaleWidget* axisWidget( QwtAxisId ) const;
     187    QwtScaleWidget* axisWidget( QwtAxisId );
     188
     189    void setAxisLabelAlignment( QwtAxisId, Qt::Alignment );
     190    void setAxisLabelRotation( QwtAxisId, double rotation );
     191
     192    void setAxisTitle( QwtAxisId, const QString& );
     193    void setAxisTitle( QwtAxisId, const QwtText& );
     194    QwtText axisTitle( QwtAxisId ) const;
     195
     196    void setAxisMaxMinor( QwtAxisId, int maxMinor );
     197    int axisMaxMinor( QwtAxisId ) const;
     198
     199    void setAxisMaxMajor( QwtAxisId, int maxMajor );
     200    int axisMaxMajor( QwtAxisId ) const;
    225201
    226202    // Legend
    227203
    228     void insertLegend( QwtAbstractLegend *,
     204    void insertLegend( QwtAbstractLegend*,
    229205        LegendPosition = QwtPlot::RightLegend, double ratio = -1.0 );
    230206
    231     QwtAbstractLegend *legend();
    232     const QwtAbstractLegend *legend() const;
     207    QwtAbstractLegend* legend();
     208    const QwtAbstractLegend* legend() const;
    233209
    234210    void updateLegend();
    235     void updateLegend( const QwtPlotItem * );
     211    void updateLegend( const QwtPlotItem* );
    236212
    237213    // Misc
    238214
    239     virtual QSize sizeHint() const;
    240     virtual QSize minimumSizeHint() const;
     215    virtual QSize sizeHint() const QWT_OVERRIDE;
     216    virtual QSize minimumSizeHint() const QWT_OVERRIDE;
    241217
    242218    virtual void updateLayout();
    243     virtual void drawCanvas( QPainter * );
     219    virtual void drawCanvas( QPainter* );
    244220
    245221    void updateAxes();
    … …  
    247223
    248224    virtual void getCanvasMarginsHint(
    249         const QwtScaleMap maps[], const QRectF &canvasRect,
    250         double &left, double &top, double &right, double &bottom) const;
    251 
    252     virtual bool event( QEvent * );
    253     virtual bool eventFilter( QObject *, QEvent * );
    254 
    255     virtual void drawItems( QPainter *, const QRectF &,
    256         const QwtScaleMap maps[axisCnt] ) const;
    257 
    258     virtual QVariant itemToInfo( QwtPlotItem * ) const;
    259     virtual QwtPlotItem *infoToItem( const QVariant & ) const;
    260 
    261 Q_SIGNALS:
     225        const QwtScaleMap maps[], const QRectF& canvasRect,
     226        double& left, double& top, double& right, double& bottom) const;
     227
     228    virtual bool event( QEvent* ) QWT_OVERRIDE;
     229    virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE;
     230
     231    virtual void drawItems( QPainter*, const QRectF&,
     232        const QwtScaleMap maps[ QwtAxis::AxisPositions ] ) const;
     233
     234    virtual QVariant itemToInfo( QwtPlotItem* ) const;
     235    virtual QwtPlotItem* infoToItem( const QVariant& ) const;
     236
     237#if QWT_AXIS_COMPAT
     238    enum Axis
     239    {
     240        yLeft   = QwtAxis::YLeft,
     241        yRight  = QwtAxis::YRight,
     242        xBottom = QwtAxis::XBottom,
     243        xTop    = QwtAxis::XTop,
     244
     245        axisCnt = QwtAxis::AxisPositions
     246    };
     247
     248    void enableAxis( int axisId, bool on = true )
     249    {
     250        setAxisVisible( axisId, on );
     251    }
     252
     253    bool axisEnabled( int axisId ) const
     254    {
     255        return isAxisVisible( axisId );
     256    }
     257#endif
     258
     259  Q_SIGNALS:
    262260    /*!
    263       A signal indicating, that an item has been attached/detached
    264 
    265       \param plotItem Plot item
    266       \param on Attached/Detached
     261       A signal indicating, that an item has been attached/detached
     262
     263       \param plotItem Plot item
     264       \param on Attached/Detached
    267265     */
    268     void itemAttached( QwtPlotItem *plotItem, bool on );
     266    void itemAttached( QwtPlotItem* plotItem, bool on );
    269267
    270268    /*!
    271       A signal with the attributes how to update
    272       the legend entries for a plot item.
    273 
    274       \param itemInfo Info about a plot item, build from itemToInfo()
    275       \param data Attributes of the entries ( usually <= 1 ) for
     269       A signal with the attributes how to update
     270       the legend entries for a plot item.
     271
     272       \param itemInfo Info about a plot item, build from itemToInfo()
     273       \param data Attributes of the entries ( usually <= 1 ) for
    276274                  the plot item.
    277275
    278       \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend()
     276       \sa itemToInfo(), infoToItem(), QwtAbstractLegend::updateLegend()
    279277     */
    280     void legendDataChanged( const QVariant &itemInfo,
    281         const QList<QwtLegendData> &data );
    282 
    283 public Q_SLOTS:
     278    void legendDataChanged( const QVariant& itemInfo,
     279        const QList< QwtLegendData >& data );
     280
     281  public Q_SLOTS:
    284282    virtual void replot();
    285283    void autoRefresh();
    286284
    287 protected:
    288     static bool axisValid( int axisId );
    289 
    290     virtual void resizeEvent( QResizeEvent *e );
    291 
    292 private Q_SLOTS:
    293     void updateLegendItems( const QVariant &itemInfo,
    294         const QList<QwtLegendData> &legendData );
    295 
    296 private:
     285  protected:
     286
     287    virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE;
     288
     289  private Q_SLOTS:
     290    void updateLegendItems( const QVariant& itemInfo,
     291        const QList< QwtLegendData >& legendData );
     292
     293  private:
    297294    friend class QwtPlotItem;
    298     void attachItem( QwtPlotItem *, bool );
     295    void attachItem( QwtPlotItem*, bool );
    299296
    300297    void initAxesData();
    … …  
    302299    void updateScaleDiv();
    303300
    304     void initPlot( const QwtText &title );
    305 
    306     class AxisData;
    307     AxisData *d_axisData[axisCnt];
     301    void initPlot( const QwtText& title );
     302
     303    class ScaleData;
     304    ScaleData* m_scaleData;
    308305
    309306    class PrivateData;
    310     PrivateData *d_data;
     307    PrivateData* m_data;
    311308};
    312309
  • trunk/BNC/qwt/qwt_plot_abstract_barchart.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_plot_abstract_barchart.h"
    1111#include "qwt_scale_map.h"
     12#include "qwt_math.h"
    1213
    1314static inline double qwtTransformWidth(
    14     const QwtScaleMap &map, double value, double width )
     15    const QwtScaleMap& map, double value, double width )
    1516{
    1617    const double w2 = 0.5 * width;
    … …  
    2425class QwtPlotAbstractBarChart::PrivateData
    2526{
    26 public:
    27     PrivateData():
    28         layoutPolicy( QwtPlotAbstractBarChart::AutoAdjustSamples ),
    29         layoutHint( 0.5 ),
    30         spacing( 10 ),
    31         margin( 5 ),
    32         baseline( 0.0 )
     27  public:
     28    PrivateData()
     29        : layoutPolicy( QwtPlotAbstractBarChart::AutoAdjustSamples )
     30        , layoutHint( 0.5 )
     31        , spacing( 10 )
     32        , margin( 5 )
     33        , baseline( 0.0 )
    3334    {
    3435    }
    … …  
    4243
    4344/*!
    44   Constructor
    45   \param title Title of the chart
    46 */
    47 QwtPlotAbstractBarChart::QwtPlotAbstractBarChart( const QwtText &title ):
    48     QwtPlotSeriesItem( title )
    49 {
    50     d_data = new PrivateData;
     45   Constructor
     46   \param title Title of the chart
     47 */
     48QwtPlotAbstractBarChart::QwtPlotAbstractBarChart( const QwtText& title )
     49    : QwtPlotSeriesItem( title )
     50{
     51    m_data = new PrivateData;
    5152
    5253    setItemAttribute( QwtPlotItem::Legend, true );
    … …  
    5960QwtPlotAbstractBarChart::~QwtPlotAbstractBarChart()
    6061{
    61     delete d_data;
    62 }
    63 
    64 /*!
    65   The combination of layoutPolicy() and layoutHint() define how the width
    66   of the bars is calculated
    67 
    68   \param policy Layout policy
    69 
    70   \sa layoutPolicy(), layoutHint()
     62    delete m_data;
     63}
     64
     65/*!
     66   The combination of layoutPolicy() and layoutHint() define how the width
     67   of the bars is calculated
     68
     69   \param policy Layout policy
     70
     71   \sa layoutPolicy(), layoutHint()
    7172 */
    7273void QwtPlotAbstractBarChart::setLayoutPolicy( LayoutPolicy policy )
    7374{
    74     if ( policy != d_data->layoutPolicy )
    75     {
    76         d_data->layoutPolicy = policy;
    77         itemChanged();
    78     }
    79 }
    80 
    81 /*!
    82   The combination of layoutPolicy() and layoutHint() define how the width
    83   of the bars is calculated
    84 
    85   \return Layout policy of the chart item
    86   \sa setLayoutPolicy(), layoutHint()
     75    if ( policy != m_data->layoutPolicy )
     76    {
     77        m_data->layoutPolicy = policy;
     78        itemChanged();
     79    }
     80}
     81
     82/*!
     83   The combination of layoutPolicy() and layoutHint() define how the width
     84   of the bars is calculated
     85
     86   \return Layout policy of the chart item
     87   \sa setLayoutPolicy(), layoutHint()
    8788 */
    8889QwtPlotAbstractBarChart::LayoutPolicy QwtPlotAbstractBarChart::layoutPolicy() const
    8990{
    90     return d_data->layoutPolicy;
    91 }
    92 
    93 /*!
    94   The combination of layoutPolicy() and layoutHint() define how the width
    95   of the bars is calculated
    96 
    97   \param hint Layout hint
    98 
    99   \sa LayoutPolicy, layoutPolicy(), layoutHint()
     91    return m_data->layoutPolicy;
     92}
     93
     94/*!
     95   The combination of layoutPolicy() and layoutHint() define how the width
     96   of the bars is calculated
     97
     98   \param hint Layout hint
     99
     100   \sa LayoutPolicy, layoutPolicy(), layoutHint()
    100101 */
    101102void QwtPlotAbstractBarChart::setLayoutHint( double hint )
    102103{
    103     hint = qMax( 0.0, hint );
    104     if ( hint != d_data->layoutHint )
    105     {
    106         d_data->layoutHint = hint;
    107         itemChanged();
    108     }
    109 }
    110 
    111 /*!
    112   The combination of layoutPolicy() and layoutHint() define how the width
    113   of the bars is calculated
    114 
    115   \return Layout policy of the chart item
    116   \sa LayoutPolicy, setLayoutHint(), layoutPolicy()
    117 */
     104    hint = qwtMaxF( 0.0, hint );
     105    if ( hint != m_data->layoutHint )
     106    {
     107        m_data->layoutHint = hint;
     108        itemChanged();
     109    }
     110}
     111
     112/*!
     113   The combination of layoutPolicy() and layoutHint() define how the width
     114   of the bars is calculated
     115
     116   \return Layout policy of the chart item
     117   \sa LayoutPolicy, setLayoutHint(), layoutPolicy()
     118 */
    118119double QwtPlotAbstractBarChart::layoutHint() const
    119120{
    120     return d_data->layoutHint;
    121 }
    122 
    123 /*!
    124   \brief Set the spacing
    125 
    126   The spacing is the distance between 2 samples ( bars for QwtPlotBarChart or
    127   a group of bars for QwtPlotMultiBarChart ) in paint device coordinates.
    128 
    129   \sa spacing()
     121    return m_data->layoutHint;
     122}
     123
     124/*!
     125   \brief Set the spacing
     126
     127   The spacing is the distance between 2 samples ( bars for QwtPlotBarChart or
     128   a group of bars for QwtPlotMultiBarChart ) in paint device coordinates.
     129
     130   \sa spacing()
    130131 */
    131132void QwtPlotAbstractBarChart::setSpacing( int spacing )
    132133{
    133134    spacing = qMax( spacing, 0 );
    134     if ( spacing != d_data->spacing )
    135     {
    136         d_data->spacing = spacing;
    137         itemChanged();
    138     }
    139 }
    140 
    141 /*!
    142   \return Spacing between 2 samples ( bars or groups of bars )
    143   \sa setSpacing(), margin()
     135    if ( spacing != m_data->spacing )
     136    {
     137        m_data->spacing = spacing;
     138        itemChanged();
     139    }
     140}
     141
     142/*!
     143   \return Spacing between 2 samples ( bars or groups of bars )
     144   \sa setSpacing(), margin()
    144145 */
    145146int QwtPlotAbstractBarChart::spacing() const
    146147{
    147     return d_data->spacing;
    148 }
    149 /*!
    150   \brief Set the margin
    151 
    152   The margin is the distance between the outmost bars and the contentsRect()
    153   of the canvas. The default setting is 5 pixels.
    154 
    155   \param margin Margin
    156 
    157   \sa spacing(), margin()
     148    return m_data->spacing;
     149}
     150/*!
     151   \brief Set the margin
     152
     153   The margin is the distance between the outmost bars and the contentsRect()
     154   of the canvas. The default setting is 5 pixels.
     155
     156   \param margin Margin
     157
     158   \sa spacing(), margin()
    158159 */
    159160void QwtPlotAbstractBarChart::setMargin( int margin )
    160161{
    161162    margin = qMax( margin, 0 );
    162     if ( margin != d_data->margin )
    163     {
    164         d_data->margin = margin;
    165         itemChanged();
    166     }
    167 }
    168 
    169 /*!
    170   \return Margin between the outmost bars and the contentsRect()
    171   of the canvas.
    172 
    173   \sa setMargin(), spacing()
     163    if ( margin != m_data->margin )
     164    {
     165        m_data->margin = margin;
     166        itemChanged();
     167    }
     168}
     169
     170/*!
     171   \return Margin between the outmost bars and the contentsRect()
     172   of the canvas.
     173
     174   \sa setMargin(), spacing()
    174175 */
    175176int QwtPlotAbstractBarChart::margin() const
    176177{
    177     return d_data->margin;
     178    return m_data->margin;
    178179}
    179180
    … …  
    191192
    192193   \sa baseline(), QwtPlotSeriesItem::orientation()
    193 */
     194 */
    194195void QwtPlotAbstractBarChart::setBaseline( double value )
    195196{
    196     if ( value != d_data->baseline )
    197     {
    198         d_data->baseline = value;
     197    if ( value != m_data->baseline )
     198    {
     199        m_data->baseline = value;
    199200        itemChanged();
    200201    }
    … …  
    207208double QwtPlotAbstractBarChart::baseline() const
    208209{
    209     return d_data->baseline;
     210    return m_data->baseline;
    210211}
    211212
    … …  
    221222   \return Sample width
    222223   \sa layoutPolicy(), layoutHint()
    223 */
    224 double QwtPlotAbstractBarChart::sampleWidth( const QwtScaleMap &map,
     224 */
     225double QwtPlotAbstractBarChart::sampleWidth( const QwtScaleMap& map,
    225226    double canvasSize, double boundingSize, double value ) const
    226227{
    227228    double width;
    228229
    229     switch( d_data->layoutPolicy )
     230    switch( m_data->layoutPolicy )
    230231    {
    231232        case ScaleSamplesToAxes:
    232233        {
    233             width = qwtTransformWidth( map, value, d_data->layoutHint );
     234            width = qwtTransformWidth( map, value, m_data->layoutHint );
    234235            break;
    235236        }
    236237        case ScaleSampleToCanvas:
    237238        {
    238             width = canvasSize * d_data->layoutHint;
     239            width = canvasSize * m_data->layoutHint;
    239240            break;
    240241        }
    241242        case FixedSampleSize:
    242243        {
    243             width = d_data->layoutHint;
     244            width = m_data->layoutHint;
    244245            break;
    245246        }
    … …  
    256257
    257258            width = qwtTransformWidth( map, value, w );
    258             width -= d_data->spacing;
    259             width = qMax( width, d_data->layoutHint );
     259            width -= m_data->spacing;
     260            width = qwtMaxF( width, m_data->layoutHint );
    260261        }
    261262    }
    … …  
    281282   \param bottom Returns the bottom margin
    282283
    283    \return Margin
    284 
    285284   \sa layoutPolicy(), layoutHint(), QwtPlotItem::Margins
    286285       QwtPlot::getCanvasMarginsHint(), QwtPlot::updateCanvasMargins()
    287286 */
    288 void QwtPlotAbstractBarChart::getCanvasMarginHint( const QwtScaleMap &xMap,
    289     const QwtScaleMap &yMap, const QRectF &canvasRect,
    290     double &left, double &top, double &right, double &bottom ) const
     287void QwtPlotAbstractBarChart::getCanvasMarginHint( const QwtScaleMap& xMap,
     288    const QwtScaleMap& yMap, const QRectF& canvasRect,
     289    double& left, double& top, double& right, double& bottom ) const
    291290{
    292291    double hint = -1.0;
    … …  
    297296        {
    298297            if ( orientation() == Qt::Vertical )
    299                 hint = 0.5 * canvasRect.width() * d_data->layoutHint;
     298                hint = 0.5 * canvasRect.width() * m_data->layoutHint;
    300299            else
    301                 hint = 0.5 * canvasRect.height() * d_data->layoutHint;
     300                hint = 0.5 * canvasRect.height() * m_data->layoutHint;
    302301
    303302            break;
    … …  
    305304        case FixedSampleSize:
    306305        {
    307             hint = 0.5 * d_data->layoutHint;
     306            hint = 0.5 * m_data->layoutHint;
    308307            break;
    309308        }
    … …  
    324323            if ( layoutPolicy() == ScaleSamplesToAxes )
    325324            {
    326                 sampleWidthS = qMax( d_data->layoutHint, 0.0 );
     325                sampleWidthS = qwtMaxF( m_data->layoutHint, 0.0 );
    327326            }
    328327            else
    329328            {
    330                 spacing = d_data->spacing;
     329                spacing = m_data->spacing;
    331330
    332331                if ( numSamples > 1 )
    … …  
    352351
    353352            hint = 0.5 * sampleWidthP;
    354             hint += qMax( d_data->margin, 0 );
     353            hint += qMax( m_data->margin, 0 );
    355354        }
    356355    }
  • trunk/BNC/qwt/qwt_plot_abstract_barchart.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_seriesitem.h"
    15 #include "qwt_series_data.h"
    1615
    1716/*!
    18   \brief Abstract base class for bar chart items
     17   \brief Abstract base class for bar chart items
    1918
    20   In opposite to almost all other plot items bar charts can't be
    21   displayed inside of their bounding rectangle and need a special
    22   API  how to calculate the width of the bars and how they affect
    23   the layout of the attached plot.
     19   In opposite to almost all other plot items bar charts can't be
     20   displayed inside of their bounding rectangle and need a special
     21   API  how to calculate the width of the bars and how they affect
     22   the layout of the attached plot.
    2423 */
    25 class QWT_EXPORT QwtPlotAbstractBarChart: public QwtPlotSeriesItem
     24class QWT_EXPORT QwtPlotAbstractBarChart : public QwtPlotSeriesItem
    2625{
    27 public:
     26  public:
    2827    /*!
    2928        \brief Mode how to calculate the bar width
    … …  
    3433    {
    3534        /*!
    36           The sample width is calculated by dividing the bounding rectangle
    37           by the number of samples. The layoutHint() is used as a minimum width
    38           in paint device coordinates.
     35           The sample width is calculated by dividing the bounding rectangle
     36           by the number of samples. The layoutHint() is used as a minimum width
     37           in paint device coordinates.
    3938
    40           \sa boundingRectangle()
     39           \sa boundingRectangle()
    4140         */
    4241        AutoAdjustSamples,
    4342
    4443        /*!
    45           layoutHint() defines an interval in axis coordinates
     44           layoutHint() defines an interval in axis coordinates
    4645         */
    4746        ScaleSamplesToAxes,
    4847
    4948        /*!
    50           The bar width is calculated by multiplying layoutHint()
    51           with the height or width of the canvas.
     49           The bar width is calculated by multiplying layoutHint()
     50           with the height or width of the canvas.
    5251
    53           \sa boundingRectangle()
     52           \sa boundingRectangle()
    5453         */
    5554        ScaleSampleToCanvas,
    5655
    5756        /*!
    58           layoutHint() defines a fixed width in paint device coordinates.
     57           layoutHint() defines a fixed width in paint device coordinates.
    5958         */
    6059        FixedSampleSize
    6160    };
    6261
    63     explicit QwtPlotAbstractBarChart( const QwtText &title );
     62    explicit QwtPlotAbstractBarChart( const QwtText& title );
    6463    virtual ~QwtPlotAbstractBarChart();
    6564
    … …  
    8079
    8180    virtual void getCanvasMarginHint(
    82         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    83         const QRectF &canvasRect,
    84         double &left, double &top, double &right, double &bottom) const;
     81        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     82        const QRectF& canvasRect, double& left, double& top,
     83        double& right, double& bottom) const QWT_OVERRIDE;
    8584
    8685
    87 protected:
    88     double sampleWidth( const QwtScaleMap &map,
     86  protected:
     87    double sampleWidth( const QwtScaleMap& map,
    8988        double canvasSize, double boundingSize,
    9089        double value ) const;
    9190
    92 private:
     91  private:
    9392    class PrivateData;
    94     PrivateData *d_data;
     93    PrivateData* m_data;
    9594};
    9695
  • 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 
  • trunk/BNC/qwt/qwt_plot_barchart.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_scale_map.h"
    1212#include "qwt_column_symbol.h"
    13 #include "qwt_painter.h"
     13#include "qwt_text.h"
     14#include "qwt_graphic.h"
     15#include "qwt_legend_data.h"
     16
    1417#include <qpainter.h>
    1518
    1619class QwtPlotBarChart::PrivateData
    1720{
    18 public:
    19     PrivateData():
    20         symbol( NULL ),
    21         legendMode( QwtPlotBarChart::LegendChartTitle )
     21  public:
     22    PrivateData()
     23        : symbol( NULL )
     24        , legendMode( QwtPlotBarChart::LegendChartTitle )
    2225    {
    2326    }
    … …  
    2831    }
    2932
    30     QwtColumnSymbol *symbol;
     33    QwtColumnSymbol* symbol;
    3134    QwtPlotBarChart::LegendMode legendMode;
    3235};
    3336
    3437/*!
    35   Constructor
    36   \param title Title of the curve
    37 */
    38 QwtPlotBarChart::QwtPlotBarChart( const QwtText &title ):
    39     QwtPlotAbstractBarChart( title )
     38   Constructor
     39   \param title Title of the curve
     40 */
     41QwtPlotBarChart::QwtPlotBarChart( const QwtText& title )
     42    : QwtPlotAbstractBarChart( title )
    4043{
    4144    init();
    … …  
    4346
    4447/*!
    45   Constructor
    46   \param title Title of the curve
    47 */
    48 QwtPlotBarChart::QwtPlotBarChart( const QString &title ):
    49     QwtPlotAbstractBarChart( QwtText( title ) )
     48   Constructor
     49   \param title Title of the curve
     50 */
     51QwtPlotBarChart::QwtPlotBarChart( const QString& title )
     52    : QwtPlotAbstractBarChart( QwtText( title ) )
    5053{
    5154    init();
    … …  
    5558QwtPlotBarChart::~QwtPlotBarChart()
    5659{
    57     delete d_data;
     60    delete m_data;
    5861}
    5962
    6063void QwtPlotBarChart::init()
    6164{
    62     d_data = new PrivateData;
     65    m_data = new PrivateData;
    6366    setData( new QwtPointSeriesData() );
    6467}
    … …  
    7174
    7275/*!
    73   Initialize data with an array of points
    74 
    75   \param samples Vector of points
    76   \note QVector is implicitly shared
    77   \note QPolygonF is derived from QVector<QPointF>
    78 */
     76   Initialize data with an array of points
     77
     78   \param samples Vector of points
     79   \note QVector is implicitly shared
     80   \note QPolygonF is derived from QVector<QPointF>
     81 */
    7982void QwtPlotBarChart::setSamples(
    80     const QVector<QPointF> &samples )
     83    const QVector< QPointF >& samples )
    8184{
    8285    setData( new QwtPointSeriesData( samples ) );
    … …  
    8487
    8588/*!
    86   Initialize data with an array of doubles
    87 
    88   The indices in the array are taken as x coordinate,
    89   while the doubles are interpreted as y values.
    90 
    91   \param samples Vector of y coordinates
    92   \note QVector is implicitly shared
    93 */
     89   Initialize data with an array of doubles
     90
     91   The indices in the array are taken as x coordinate,
     92   while the doubles are interpreted as y values.
     93
     94   \param samples Vector of y coordinates
     95   \note QVector is implicitly shared
     96 */
    9497void QwtPlotBarChart::setSamples(
    95     const QVector<double> &samples )
    96 {
    97     QVector<QPointF> points;
     98    const QVector< double >& samples )
     99{
     100    QVector< QPointF > points;
     101    points.reserve( samples.size() );
     102
    98103    for ( int i = 0; i < samples.size(); i++ )
    99104        points += QPointF( i, samples[ i ] );
    … …  
    103108
    104109/*!
    105   Assign a series of samples
    106 
    107   setSamples() is just a wrapper for setData() without any additional
    108   value - beside that it is easier to find for the developer.
    109 
    110   \param data Data
    111   \warning The item takes ownership of the data object, deleting
     110   Assign a series of samples
     111
     112   setSamples() is just a wrapper for setData() without any additional
     113   value - beside that it is easier to find for the developer.
     114
     115   \param data Data
     116   \warning The item takes ownership of the data object, deleting
    112117           it when its not used anymore.
    113 */
    114 void QwtPlotBarChart::setSamples( QwtSeriesData<QPointF> *data )
     118 */
     119void QwtPlotBarChart::setSamples( QwtSeriesData< QPointF >* data )
    115120{
    116121    setData( data );
    … …  
    118123
    119124/*!
    120   \brief Assign a symbol
    121 
    122   The bar chart will take the ownership of the symbol, hence the previously
    123   set symbol will be delete by setting a new one. If \p symbol is
    124   \c NULL no symbol will be drawn.
    125 
    126   \param symbol Symbol
    127   \sa symbol()
    128 */
    129 void QwtPlotBarChart::setSymbol( QwtColumnSymbol *symbol )
    130 {
    131     if ( symbol != d_data->symbol )
    132     {
    133         delete d_data->symbol;
    134         d_data->symbol = symbol;
     125   \brief Assign a symbol
     126
     127   The bar chart will take the ownership of the symbol, hence the previously
     128   set symbol will be delete by setting a new one. If \p symbol is
     129   \c NULL no symbol will be drawn.
     130
     131   \param symbol Symbol
     132   \sa symbol()
     133 */
     134void QwtPlotBarChart::setSymbol( QwtColumnSymbol* symbol )
     135{
     136    if ( symbol != m_data->symbol )
     137    {
     138        delete m_data->symbol;
     139        m_data->symbol = symbol;
    135140
    136141        legendChanged();
    … …  
    140145
    141146/*!
    142   \return Current symbol or NULL, when no symbol has been assigned
    143   \sa setSymbol()
    144 */
    145 const QwtColumnSymbol *QwtPlotBarChart::symbol() const
    146 {
    147     return d_data->symbol;
    148 }
    149 
    150 /*!
    151   Set the mode that decides what to display on the legend
    152 
    153   In case of LegendBarTitles barTitle() needs to be overloaded
    154   to return individual titles for each bar.
    155 
    156   \param mode New mode
    157   \sa legendMode(), legendData(), barTitle(), QwtPlotItem::ItemAttribute
     147   \return Current symbol or NULL, when no symbol has been assigned
     148   \sa setSymbol()
     149 */
     150const QwtColumnSymbol* QwtPlotBarChart::symbol() const
     151{
     152    return m_data->symbol;
     153}
     154
     155/*!
     156   Set the mode that decides what to display on the legend
     157
     158   In case of LegendBarTitles barTitle() needs to be overloaded
     159   to return individual titles for each bar.
     160
     161   \param mode New mode
     162   \sa legendMode(), legendData(), barTitle(), QwtPlotItem::ItemAttribute
    158163 */
    159164void QwtPlotBarChart::setLegendMode( LegendMode mode )
    160165{
    161     if ( mode != d_data->legendMode )
    162     {
    163         d_data->legendMode = mode;
     166    if ( mode != m_data->legendMode )
     167    {
     168        m_data->legendMode = mode;
    164169        legendChanged();
    165170    }
    … …  
    167172
    168173/*!
    169   \return Legend mode
    170   \sa setLegendMode()
     174   \return Legend mode
     175   \sa setLegendMode()
    171176 */
    172177QwtPlotBarChart::LegendMode QwtPlotBarChart::legendMode() const
    173178{
    174     return d_data->legendMode;
    175 }
    176 
    177 /*!
    178   \return Bounding rectangle of all samples.
    179   For an empty series the rectangle is invalid.
    180 */
     179    return m_data->legendMode;
     180}
     181
     182/*!
     183   \return Bounding rectangle of all samples.
     184   For an empty series the rectangle is invalid.
     185 */
    181186QRectF QwtPlotBarChart::boundingRect() const
    182187{
    … …  
    204209
    205210/*!
    206   Draw an interval of the bar chart
    207 
    208   \param painter Painter
    209   \param xMap Maps x-values into pixel coordinates.
    210   \param yMap Maps y-values into pixel coordinates.
    211   \param canvasRect Contents rect of the canvas
    212   \param from Index of the first point to be painted
    213   \param to Index of the last point to be painted. If to < 0 the
     211   Draw an interval of the bar chart
     212
     213   \param painter Painter
     214   \param xMap Maps x-values into pixel coordinates.
     215   \param yMap Maps y-values into pixel coordinates.
     216   \param canvasRect Contents rect of the canvas
     217   \param from Index of the first point to be painted
     218   \param to Index of the last point to be painted. If to < 0 the
    214219         curve will be painted to its last point.
    215220
    216   \sa drawSymbols()
    217 */
    218 void QwtPlotBarChart::drawSeries( QPainter *painter,
    219     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    220     const QRectF &canvasRect, int from, int to ) const
     221   \sa drawSymbols()
     222 */
     223void QwtPlotBarChart::drawSeries( QPainter* painter,
     224    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     225    const QRectF& canvasRect, int from, int to ) const
    221226{
    222227    if ( to < 0 )
    … …  
    238243    {
    239244        drawSample( painter, xMap, yMap,
    240                     canvasRect, interval, i, sample( i ) );
     245            canvasRect, interval, i, sample( i ) );
    241246    }
    242247
    … …  
    245250
    246251/*!
    247   Draw a sample
    248 
    249   \param painter Painter
    250   \param xMap x map
    251   \param yMap y map
    252   \param canvasRect Contents rect of the canvas
    253   \param boundingInterval Bounding interval of sample values
    254   \param index Index of the sample
    255   \param sample Value of the sample
    256 
    257   \sa drawSeries()
    258 */
    259 void QwtPlotBarChart::drawSample( QPainter *painter,
    260     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    261     const QRectF &canvasRect, const QwtInterval &boundingInterval,
    262     int index, const QPointF &sample ) const
     252   Calculate the geometry of a bar in widget coordinates
     253
     254   \param xMap x map
     255   \param yMap y map
     256   \param canvasRect Contents rect of the canvas
     257   \param boundingInterval Bounding interval of sample values
     258   \param sample Value of the sample
     259
     260   \return Geometry of the column
     261 */
     262QwtColumnRect QwtPlotBarChart::columnRect(
     263    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     264    const QRectF& canvasRect, const QwtInterval& boundingInterval,
     265    const QPointF& sample ) const
    263266{
    264267    QwtColumnRect barRect;
    … …  
    301304    }
    302305
     306    return barRect;
     307}
     308
     309/*!
     310   Draw a sample
     311
     312   \param painter Painter
     313   \param xMap x map
     314   \param yMap y map
     315   \param canvasRect Contents rect of the canvas
     316   \param boundingInterval Bounding interval of sample values
     317   \param index Index of the sample
     318   \param sample Value of the sample
     319
     320   \sa drawSeries()
     321 */
     322void QwtPlotBarChart::drawSample( QPainter* painter,
     323    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     324    const QRectF& canvasRect, const QwtInterval& boundingInterval,
     325    int index, const QPointF& sample ) const
     326{
     327    const QwtColumnRect barRect = columnRect( xMap, yMap,
     328        canvasRect, boundingInterval, sample );
     329
    303330    drawBar( painter, index, sample, barRect );
    304331}
    305332
    306333/*!
    307   Draw a bar
    308 
    309   \param painter Painter
    310   \param sampleIndex Index of the sample represented by the bar
    311   \param sample Value of the sample
    312   \param rect Bounding rectangle of the bar
    313  */
    314 void QwtPlotBarChart::drawBar( QPainter *painter,
    315     int sampleIndex, const QPointF &sample,
    316     const QwtColumnRect &rect ) const
    317 {
    318     const QwtColumnSymbol *specialSym =
     334   Draw a bar
     335
     336   \param painter Painter
     337   \param sampleIndex Index of the sample represented by the bar
     338   \param sample Value of the sample
     339   \param rect Bounding rectangle of the bar
     340 */
     341void QwtPlotBarChart::drawBar( QPainter* painter,
     342    int sampleIndex, const QPointF& sample,
     343    const QwtColumnRect& rect ) const
     344{
     345    const QwtColumnSymbol* specialSym =
    319346        specialSymbol( sampleIndex, sample );
    320347
    321     const QwtColumnSymbol *sym = specialSym;
     348    const QwtColumnSymbol* sym = specialSym;
    322349    if ( sym == NULL )
    323         sym = d_data->symbol;
     350        sym = m_data->symbol;
    324351
    325352    if ( sym )
    … …  
    340367
    341368/*!
    342   Needs to be overloaded to return a
    343   non default symbol for a specific sample
    344 
    345   \param sampleIndex Index of the sample represented by the bar
    346   \param sample Value of the sample
    347 
    348   \return NULL, indicating to use the default symbol
    349  */
    350 QwtColumnSymbol *QwtPlotBarChart::specialSymbol(
    351     int sampleIndex, const QPointF &sample ) const
     369   Needs to be overloaded to return a
     370   non default symbol for a specific sample
     371
     372   \param sampleIndex Index of the sample represented by the bar
     373   \param sample Value of the sample
     374
     375   \return NULL, indicating to use the default symbol
     376 */
     377QwtColumnSymbol* QwtPlotBarChart::specialSymbol(
     378    int sampleIndex, const QPointF& sample ) const
    352379{
    353380    Q_UNUSED( sampleIndex );
    … …  
    358385
    359386/*!
    360   \brief Return the title of a bar
    361 
    362   In LegendBarTitles mode the title is displayed on
    363   the legend entry corresponding to a bar.
    364 
    365   The default implementation is a dummy, that is intended
    366   to be overloaded.
    367 
    368   \param sampleIndex Index of the bar
    369   \return An empty text
    370   \sa LegendBarTitles
     387   \brief Return the title of a bar
     388
     389   In LegendBarTitles mode the title is displayed on
     390   the legend entry corresponding to a bar.
     391
     392   The default implementation is a dummy, that is intended
     393   to be overloaded.
     394
     395   \param sampleIndex Index of the bar
     396   \return An empty text
     397   \sa LegendBarTitles
    371398 */
    372399QwtText QwtPlotBarChart::barTitle( int sampleIndex ) const
    … …  
    387414   \sa title(), setLegendMode(), barTitle(), QwtLegend, QwtPlotLegendItem
    388415 */
    389 QList<QwtLegendData> QwtPlotBarChart::legendData() const
    390 {
    391     QList<QwtLegendData> list;
    392 
    393     if ( d_data->legendMode == LegendBarTitles )
     416QList< QwtLegendData > QwtPlotBarChart::legendData() const
     417{
     418    QList< QwtLegendData > list;
     419
     420    if ( m_data->legendMode == LegendBarTitles )
    394421    {
    395422        const size_t numSamples = dataSize();
     423        list.reserve( numSamples );
     424
    396425        for ( size_t i = 0; i < numSamples; i++ )
    397426        {
    398427            QwtLegendData data;
    399428
    400             QVariant titleValue;
    401             qVariantSetValue( titleValue, barTitle( i ) );
    402             data.setValue( QwtLegendData::TitleRole, titleValue );
     429            data.setValue( QwtLegendData::TitleRole,
     430                QVariant::fromValue( barTitle( i ) ) );
    403431
    404432            if ( !legendIconSize().isEmpty() )
    405433            {
    406                 QVariant iconValue;
    407                 qVariantSetValue( iconValue,
    408                     legendIcon( i, legendIconSize() ) );
    409 
    410                 data.setValue( QwtLegendData::IconRole, iconValue );
     434                data.setValue( QwtLegendData::IconRole,
     435                    QVariant::fromValue( legendIcon( i, legendIconSize() ) ) );
    411436            }
    412437
    … …  
    436461 */
    437462QwtGraphic QwtPlotBarChart::legendIcon(
    438     int index, const QSizeF &size ) const
     463    int index, const QSizeF& size ) const
    439464{
    440465    QwtColumnRect column;
    … …  
    451476
    452477    int barIndex = -1;
    453     if ( d_data->legendMode == QwtPlotBarChart::LegendBarTitles )
     478    if ( m_data->legendMode == QwtPlotBarChart::LegendBarTitles )
    454479        barIndex = index;
    455480
  • trunk/BNC/qwt/qwt_plot_barchart.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_abstract_barchart.h"
    15 #include "qwt_series_data.h"
    1615
    1716class QwtColumnRect;
    1817class QwtColumnSymbol;
     18template< typename T > class QwtSeriesData;
    1919
    2020/*!
    21   \brief QwtPlotBarChart displays a series of a values as bars.
     21   \brief QwtPlotBarChart displays a series of a values as bars.
    2222
    23   Each bar might be customized individually by implementing
    24   a specialSymbol(). Otherwise it is rendered using a default symbol.
     23   Each bar might be customized individually by implementing
     24   a specialSymbol(). Otherwise it is rendered using a default symbol.
    2525
    26   Depending on its orientation() the bars are displayed horizontally
    27   or vertically. The bars cover the interval between the baseline()
    28   and the value.
     26   Depending on its orientation() the bars are displayed horizontally
     27   or vertically. The bars cover the interval between the baseline()
     28   and the value.
    2929
    30   By activating the LegendBarTitles mode each sample will have
    31   its own entry on the legend.
     30   By activating the LegendBarTitles mode each sample will have
     31   its own entry on the legend.
    3232
    33   The most common use case of a bar chart is to display a
    34   list of y coordinates, where the x coordinate is simply the index
    35   in the list. But for other situations ( f.e. when values are related
    36   to dates ) it is also possible to set x coordinates explicitly.
     33   The most common use case of a bar chart is to display a
     34   list of y coordinates, where the x coordinate is simply the index
     35   in the list. But for other situations ( f.e. when values are related
     36   to dates ) it is also possible to set x coordinates explicitly.
    3737
    38   \sa QwtPlotMultiBarChart, QwtPlotHistogram, QwtPlotCurve::Sticks,
     38   \sa QwtPlotMultiBarChart, QwtPlotHistogram, QwtPlotCurve::Sticks,
    3939      QwtPlotSeriesItem::orientation(), QwtPlotAbstractBarChart::baseline()
    4040 */
    41 class QWT_EXPORT QwtPlotBarChart:
    42     public QwtPlotAbstractBarChart, public QwtSeriesStore<QPointF>
     41class QWT_EXPORT QwtPlotBarChart
     42    : public QwtPlotAbstractBarChart
     43    , public QwtSeriesStore< QPointF >
    4344{
    44 public:
     45  public:
    4546    /*!
    46       \brief Legend modes.
     47       \brief Legend modes.
    4748
    48       The default setting is QwtPlotBarChart::LegendChartTitle.
    49       \sa setLegendMode(), legendMode()
    50     */
     49       The default setting is QwtPlotBarChart::LegendChartTitle.
     50       \sa setLegendMode(), legendMode()
     51     */
    5152    enum LegendMode
    5253    {
    5354        /*!
    54           One entry on the legend showing the default symbol
    55           and the title() of the chart
     55           One entry on the legend showing the default symbol
     56           and the title() of the chart
    5657
    57           \sa QwtPlotItem::title()
     58           \sa QwtPlotItem::title()
    5859         */
    5960        LegendChartTitle,
    6061
    6162        /*!
    62           One entry for each value showing the individual symbol
    63           of the corresponding bar and the bar title.
     63           One entry for each value showing the individual symbol
     64           of the corresponding bar and the bar title.
    6465
    65           \sa specialSymbol(), barTitle()
     66           \sa specialSymbol(), barTitle()
    6667         */
    6768        LegendBarTitles
    6869    };
    6970
    70     explicit QwtPlotBarChart( const QString &title = QString() );
    71     explicit QwtPlotBarChart( const QwtText &title );
     71    explicit QwtPlotBarChart( const QString& title = QString() );
     72    explicit QwtPlotBarChart( const QwtText& title );
    7273
    7374    virtual ~QwtPlotBarChart();
    7475
    75     virtual int rtti() const;
     76    virtual int rtti() const QWT_OVERRIDE;
    7677
    77     void setSamples( const QVector<QPointF> & );
    78     void setSamples( const QVector<double> & );
    79     void setSamples( QwtSeriesData<QPointF> * );
     78    void setSamples( const QVector< QPointF >& );
     79    void setSamples( const QVector< double >& );
     80    void setSamples( QwtSeriesData< QPointF >* );
    8081
    81     void setSymbol( QwtColumnSymbol * );
    82     const QwtColumnSymbol *symbol() const;
     82    void setSymbol( QwtColumnSymbol* );
     83    const QwtColumnSymbol* symbol() const;
    8384
    8485    void setLegendMode( LegendMode );
    8586    LegendMode legendMode() const;
    8687
    87     virtual void drawSeries( QPainter *painter,
    88         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    89         const QRectF &canvasRect, int from, int to ) const;
     88    virtual void drawSeries( QPainter*,
     89        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     90        const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE;
    9091
    91     virtual QRectF boundingRect() const;
     92    virtual QRectF boundingRect() const QWT_OVERRIDE;
    9293
    93     virtual QwtColumnSymbol *specialSymbol(
     94    virtual QwtColumnSymbol* specialSymbol(
    9495        int sampleIndex, const QPointF& ) const;
    9596
    9697    virtual QwtText barTitle( int sampleIndex ) const;
    9798
    98 protected:
    99     virtual void drawSample( QPainter *painter,
    100         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    101         const QRectF &canvasRect, const QwtInterval &boundingInterval,
     99  protected:
     100    virtual void drawSample( QPainter* painter,
     101        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     102        const QRectF& canvasRect, const QwtInterval& boundingInterval,
    102103        int index, const QPointF& sample ) const;
    103104
    104     virtual void drawBar( QPainter *,
     105    virtual void drawBar( QPainter*,
    105106        int sampleIndex, const QPointF& sample,
    106         const QwtColumnRect & ) const;
     107        const QwtColumnRect& ) const;
    107108
    108     QList<QwtLegendData> legendData() const;
    109     QwtGraphic legendIcon( int index, const QSizeF & ) const;
     109    QwtColumnRect columnRect(
     110        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     111        const QRectF& canvasRect, const QwtInterval& boundingInterval,
     112        const QPointF& sample ) const;
    110113
    111 private:
     114    QList< QwtLegendData > legendData() const QWT_OVERRIDE;
     115    QwtGraphic legendIcon( int index, const QSizeF& ) const QWT_OVERRIDE;
     116
     117  private:
    112118    void init();
    113119
    114120    class PrivateData;
    115     PrivateData *d_data;
     121    PrivateData* m_data;
    116122};
    117123
  • trunk/BNC/qwt/qwt_plot_canvas.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_plot_canvas.h"
    1111#include "qwt_painter.h"
    12 #include "qwt_null_paintdevice.h"
    13 #include "qwt_math.h"
    1412#include "qwt_plot.h"
     13
    1514#include <qpainter.h>
    16 #include <qstyle.h>
    17 #include <qstyleoption.h>
    18 #include <qpaintengine.h>
     15#include <qpainterpath.h>
    1916#include <qevent.h>
    2017
    21 class QwtStyleSheetRecorder: public QwtNullPaintDevice
    22 {
    23 public:
    24     QwtStyleSheetRecorder( const QSize &size ):
    25         d_size( size )
    26     {
    27     }
    28 
    29     virtual void updateState( const QPaintEngineState &state )
    30     {
    31         if ( state.state() & QPaintEngine::DirtyPen )
    32         {
    33             d_pen = state.pen();
    34         }
    35         if ( state.state() & QPaintEngine::DirtyBrush )
    36         {
    37             d_brush = state.brush();
    38         }
    39         if ( state.state() & QPaintEngine::DirtyBrushOrigin )
    40         {
    41             d_origin = state.brushOrigin();
    42         }
    43     }
    44 
    45     virtual void drawRects(const QRectF *rects, int count )
    46     {
    47         for ( int i = 0; i < count; i++ )
    48             border.rectList += rects[i];
    49     }
    50 
    51     virtual void drawRects(const QRect *rects, int count )
    52     {
    53         // to silence -Woverloaded-virtual
    54         QwtNullPaintDevice::drawRects( rects, count );
    55     }
    56 
    57     virtual void drawPath( const QPainterPath &path )
    58     {
    59         const QRectF rect( QPointF( 0.0, 0.0 ), d_size );
    60         if ( path.controlPointRect().contains( rect.center() ) )
    61         {
    62             setCornerRects( path );
    63             alignCornerRects( rect );
    64 
    65             background.path = path;
    66             background.brush = d_brush;
    67             background.origin = d_origin;
    68         }
    69         else
    70         {
    71             border.pathList += path;
    72         }
    73     }
    74 
    75     void setCornerRects( const QPainterPath &path )
    76     {
    77         QPointF pos( 0.0, 0.0 );
    78 
    79         for ( int i = 0; i < path.elementCount(); i++ )
    80         {
    81             QPainterPath::Element el = path.elementAt(i);
    82             switch( el.type )
    83             {
    84                 case QPainterPath::MoveToElement:
    85                 case QPainterPath::LineToElement:
    86                 {
    87                     pos.setX( el.x );
    88                     pos.setY( el.y );
    89                     break;
    90                 }
    91                 case QPainterPath::CurveToElement:
    92                 {
    93                     QRectF r( pos, QPointF( el.x, el.y ) );
    94                     clipRects += r.normalized();
    95 
    96                     pos.setX( el.x );
    97                     pos.setY( el.y );
    98 
    99                     break;
    100                 }
    101                 case QPainterPath::CurveToDataElement:
    102                 {
    103                     if ( clipRects.size() > 0 )
    104                     {
    105                         QRectF r = clipRects.last();
    106                         r.setCoords(
    107                             qMin( r.left(), el.x ),
    108                             qMin( r.top(), el.y ),
    109                             qMax( r.right(), el.x ),
    110                             qMax( r.bottom(), el.y )
    111                         );
    112                         clipRects.last() = r.normalized();
    113                     }
    114                     break;
    115                 }
    116             }
    117         }
    118     }
    119 
    120 protected:
    121     virtual QSize sizeMetrics() const
    122     {
    123         return d_size;
    124     }
    125 
    126 private:
    127     void alignCornerRects( const QRectF &rect )
    128     {
    129         for ( int i = 0; i < clipRects.size(); i++ )
    130         {
    131             QRectF &r = clipRects[i];
    132             if ( r.center().x() < rect.center().x() )
    133                 r.setLeft( rect.left() );
    134             else
    135                 r.setRight( rect.right() );
    136 
    137             if ( r.center().y() < rect.center().y() )
    138                 r.setTop( rect.top() );
    139             else
    140                 r.setBottom( rect.bottom() );
    141         }
    142     }
    143 
    144 
    145 public:
    146     QVector<QRectF> clipRects;
    147 
    148     struct Border
    149     {
    150         QList<QPainterPath> pathList;
    151         QList<QRectF> rectList;
    152         QRegion clipRegion;
    153     } border;
    154 
    155     struct Background
    156     {
    157         QPainterPath path;
    158         QBrush brush;
    159         QPointF origin;
    160     } background;
    161 
    162 private:
    163     const QSize d_size;
    164 
    165     QPen d_pen;
    166     QBrush d_brush;
    167     QPointF d_origin;
     18class QwtPlotCanvas::PrivateData
     19{
     20  public:
     21    PrivateData()
     22        : backingStore( NULL )
     23    {
     24    }
     25
     26    ~PrivateData()
     27    {
     28        delete backingStore;
     29    }
     30
     31    QwtPlotCanvas::PaintAttributes paintAttributes;
     32    QPixmap* backingStore;
    16833};
    16934
    170 static void qwtDrawBackground( QPainter *painter, QwtPlotCanvas *canvas )
    171 {
    172     painter->save();
    173 
    174     const QPainterPath borderClip = canvas->borderPath( canvas->rect() );
    175     if ( !borderClip.isEmpty() )
    176         painter->setClipPath( borderClip, Qt::IntersectClip );
    177 
    178     const QBrush &brush =
    179         canvas->palette().brush( canvas->backgroundRole() );
    180 
    181     if ( brush.style() == Qt::TexturePattern )
    182     {
    183         QPixmap pm( canvas->size() );
    184         QwtPainter::fillPixmap( canvas, pm );
    185         painter->drawPixmap( 0, 0, pm );
    186     }
    187     else if ( brush.gradient() )
    188     {
    189         QVector<QRect> rects;
    190 
    191         if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode )
    192         {
    193             rects += canvas->rect();
    194         }
    195         else
    196         {
    197             rects = painter->clipRegion().rects();
    198         }
    199 
    200 #if 1
    201         bool useRaster = false;
    202 
    203         if ( painter->paintEngine()->type() == QPaintEngine::X11 )
    204         {
    205             // Qt 4.7.1: gradients on X11 are broken ( subrects +
    206             // QGradient::StretchToDeviceMode ) and horrible slow.
    207             // As workaround we have to use the raster paintengine.
    208             // Even if the QImage -> QPixmap translation is slow
    209             // it is three times faster, than using X11 directly
    210 
    211             useRaster = true;
    212         }
    213 #endif
    214         if ( useRaster )
    215         {
    216             QImage::Format format = QImage::Format_RGB32;
    217 
    218             const QGradientStops stops = brush.gradient()->stops();
    219             for ( int i = 0; i < stops.size(); i++ )
    220             {
    221                 if ( stops[i].second.alpha() != 255 )
    222                 {
    223                     // don't use Format_ARGB32_Premultiplied. It's
    224                     // recommended by the Qt docs, but QPainter::drawImage()
    225                     // is horrible slow on X11.
    226 
    227                     format = QImage::Format_ARGB32;
    228                     break;
    229                 }
    230             }
    231 
    232             QImage image( canvas->size(), format );
    233 
    234             QPainter p( &image );
    235             p.setPen( Qt::NoPen );
    236             p.setBrush( brush );
    237 
    238             p.drawRects( rects );
    239 
    240             p.end();
    241 
    242             painter->drawImage( 0, 0, image );
    243         }
    244         else
    245         {
    246             painter->setPen( Qt::NoPen );
    247             painter->setBrush( brush );
    248 
    249             painter->drawRects( rects );
    250         }
    251     }
    252     else
    253     {
    254         painter->setPen( Qt::NoPen );
    255         painter->setBrush( brush );
    256 
    257         painter->drawRects( painter->clipRegion().rects() );
    258 
    259     }
    260 
    261     painter->restore();
    262 }
    263 
    264 static inline void qwtRevertPath( QPainterPath &path )
    265 {
    266     if ( path.elementCount() == 4 )
    267     {
    268         QPainterPath::Element el0 = path.elementAt(0);
    269         QPainterPath::Element el3 = path.elementAt(3);
    270 
    271         path.setElementPositionAt( 0, el3.x, el3.y );
    272         path.setElementPositionAt( 3, el0.x, el0.y );
    273     }
    274 }
    275 
    276 static QPainterPath qwtCombinePathList( const QRectF &rect,
    277     const QList<QPainterPath> &pathList )
    278 {
    279     if ( pathList.isEmpty() )
    280         return QPainterPath();
    281 
    282     QPainterPath ordered[8]; // starting top left
    283 
    284     for ( int i = 0; i < pathList.size(); i++ )
    285     {
    286         int index = -1;
    287         QPainterPath subPath = pathList[i];
    288 
    289         const QRectF br = pathList[i].controlPointRect();
    290         if ( br.center().x() < rect.center().x() )
    291         {
    292             if ( br.center().y() < rect.center().y() )
    293             {
    294                 if ( qAbs( br.top() - rect.top() ) <
    295                     qAbs( br.left() - rect.left() ) )
    296                 {
    297                     index = 1;
    298                 }
    299                 else
    300                 {
    301                     index = 0;
    302                 }
    303             }
    304             else
    305             {
    306                 if ( qAbs( br.bottom() - rect.bottom() ) <
    307                     qAbs( br.left() - rect.left() ) )
    308                 {
    309                     index = 6;
    310                 }
    311                 else
    312                 {
    313                     index = 7;
    314                 }
    315             }
    316 
    317             if ( subPath.currentPosition().y() > br.center().y() )
    318                 qwtRevertPath( subPath );
    319         }
    320         else
    321         {
    322             if ( br.center().y() < rect.center().y() )
    323             {
    324                 if ( qAbs( br.top() - rect.top() ) <
    325                     qAbs( br.right() - rect.right() ) )
    326                 {
    327                     index = 2;
    328                 }
    329                 else
    330                 {
    331                     index = 3;
    332                 }
    333             }
    334             else
    335             {
    336                 if ( qAbs( br.bottom() - rect.bottom() ) <
    337                     qAbs( br.right() - rect.right() ) )
    338                 {
    339                     index = 5;
    340                 }
    341                 else
    342                 {
    343                     index = 4;
    344                 }
    345             }
    346             if ( subPath.currentPosition().y() < br.center().y() )
    347                 qwtRevertPath( subPath );
    348         }
    349         ordered[index] = subPath;
    350     }
    351 
    352     for ( int i = 0; i < 4; i++ )
    353     {
    354         if ( ordered[ 2 * i].isEmpty() != ordered[2 * i + 1].isEmpty() )
    355         {
    356             // we don't accept incomplete rounded borders
    357             return QPainterPath();
    358         }
    359     }
    360 
    361 
    362     const QPolygonF corners( rect );
    363 
    364     QPainterPath path;
    365     //path.moveTo( rect.topLeft() );
    366 
    367     for ( int i = 0; i < 4; i++ )
    368     {
    369         if ( ordered[2 * i].isEmpty() )
    370         {
    371             path.lineTo( corners[i] );
    372         }
    373         else
    374         {
    375             path.connectPath( ordered[2 * i] );
    376             path.connectPath( ordered[2 * i + 1] );
    377         }
    378     }
    379 
    380     path.closeSubpath();
    381 
    382 #if 0
    383     return path.simplified();
    384 #else
    385     return path;
    386 #endif
    387 }
    388 
    389 static inline void qwtDrawStyledBackground(
    390     QWidget *w, QPainter *painter )
    391 {
    392     QStyleOption opt;
    393     opt.initFrom(w);
    394     w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w);
    395 }
    396 
    397 static QWidget *qwtBackgroundWidget( QWidget *w )
    398 {
    399     if ( w->parentWidget() == NULL )
    400         return w;
    401 
    402     if ( w->autoFillBackground() )
    403     {
    404         const QBrush brush = w->palette().brush( w->backgroundRole() );
    405         if ( brush.color().alpha() > 0 )
    406             return w;
    407     }
    408 
    409     if ( w->testAttribute( Qt::WA_StyledBackground ) )
    410     {
    411         QImage image( 1, 1, QImage::Format_ARGB32 );
    412         image.fill( Qt::transparent );
    413 
    414         QPainter painter( &image );
    415         painter.translate( -w->rect().center() );
    416         qwtDrawStyledBackground( w, &painter );
    417         painter.end();
    418 
    419         if ( qAlpha( image.pixel( 0, 0 ) ) != 0 )
    420             return w;
    421     }
    422 
    423     return qwtBackgroundWidget( w->parentWidget() );
    424 }
    425 
    426 static void qwtFillBackground( QPainter *painter,
    427     QWidget *widget, const QVector<QRectF> &fillRects )
    428 {
    429     if ( fillRects.isEmpty() )
    430         return;
    431 
    432     QRegion clipRegion;
    433     if ( painter->hasClipping() )
    434         clipRegion = painter->transform().map( painter->clipRegion() );
    435     else
    436         clipRegion = widget->contentsRect();
    437 
    438     // Try to find out which widget fills
    439     // the unfilled areas of the styled background
    440 
    441     QWidget *bgWidget = qwtBackgroundWidget( widget->parentWidget() );
    442 
    443     for ( int i = 0; i < fillRects.size(); i++ )
    444     {
    445         const QRect rect = fillRects[i].toAlignedRect();
    446         if ( clipRegion.intersects( rect ) )
    447         {
    448             QPixmap pm( rect.size() );
    449             QwtPainter::fillPixmap( bgWidget, pm, widget->mapTo( bgWidget, rect.topLeft() ) );
    450             painter->drawPixmap( rect, pm );
    451         }
    452     }
    453 }
    454 
    455 static void qwtFillBackground( QPainter *painter, QwtPlotCanvas *canvas )
    456 {
    457     QVector<QRectF> rects;
    458 
    459     if ( canvas->testAttribute( Qt::WA_StyledBackground ) )
    460     {
    461         QwtStyleSheetRecorder recorder( canvas->size() );
    462 
    463         QPainter p( &recorder );
    464         qwtDrawStyledBackground( canvas, &p );
    465         p.end();
    466 
    467         if ( recorder.background.brush.isOpaque() )
    468             rects = recorder.clipRects;
    469         else
    470             rects += canvas->rect();
    471     }
    472     else
    473     {
    474         const QRectF r = canvas->rect();
    475         const double radius = canvas->borderRadius();
    476         if ( radius > 0.0 )
    477         {
    478             QSizeF sz( radius, radius );
    479 
    480             rects += QRectF( r.topLeft(), sz );
    481             rects += QRectF( r.topRight() - QPointF( radius, 0 ), sz );
    482             rects += QRectF( r.bottomRight() - QPointF( radius, radius ), sz );
    483             rects += QRectF( r.bottomLeft() - QPointF( 0, radius ), sz );
    484         }
    485     }
    486 
    487     qwtFillBackground( painter, canvas, rects);
    488 }
    489 
    490 
    491 class QwtPlotCanvas::PrivateData
    492 {
    493 public:
    494     PrivateData():
    495         focusIndicator( NoFocusIndicator ),
    496         borderRadius( 0 ),
    497         paintAttributes( 0 ),
    498         backingStore( NULL )
    499     {
    500         styleSheet.hasBorder = false;
    501     }
    502 
    503     ~PrivateData()
    504     {
    505         delete backingStore;
    506     }
    507 
    508     FocusIndicator focusIndicator;
    509     double borderRadius;
    510     QwtPlotCanvas::PaintAttributes paintAttributes;
    511     QPixmap *backingStore;
    512 
    513     struct StyleSheet
    514     {
    515         bool hasBorder;
    516         QPainterPath borderPath;
    517         QVector<QRectF> cornerRects;
    518 
    519         struct StyleSheetBackground
    520         {
    521             QBrush brush;
    522             QPointF origin;
    523         } background;
    524 
    525     } styleSheet;
    526 
    527 };
    528 
    529 /*!
    530   \brief Constructor
    531 
    532   \param plot Parent plot widget
    533   \sa QwtPlot::setCanvas()
    534 */
    535 QwtPlotCanvas::QwtPlotCanvas( QwtPlot *plot ):
    536     QFrame( plot )
    537 {
    538     setFrameStyle( QFrame::Panel | QFrame::Sunken );
    539     setLineWidth( 2 );
    540 
    541     d_data = new PrivateData;
    542 
    543 #ifndef QT_NO_CURSOR
    544     setCursor( Qt::CrossCursor );
    545 #endif
    546 
    547     setAutoFillBackground( true );
     35/*!
     36   \brief Constructor
     37
     38   \param plot Parent plot widget
     39   \sa QwtPlot::setCanvas()
     40 */
     41QwtPlotCanvas::QwtPlotCanvas( QwtPlot* plot )
     42    : QFrame( plot )
     43    , QwtPlotAbstractCanvas( this )
     44{
     45    m_data = new PrivateData;
     46
    54847    setPaintAttribute( QwtPlotCanvas::BackingStore, true );
    54948    setPaintAttribute( QwtPlotCanvas::Opaque, true );
    55049    setPaintAttribute( QwtPlotCanvas::HackStyledBackground, true );
     50
     51    setLineWidth( 2 );
     52    setFrameShadow( QFrame::Sunken );
     53    setFrameShape( QFrame::Panel );
    55154}
    55255
    … …  
    55457QwtPlotCanvas::~QwtPlotCanvas()
    55558{
    556     delete d_data;
    557 }
    558 
    559 //! Return parent plot widget
    560 QwtPlot *QwtPlotCanvas::plot()
    561 {
    562     return qobject_cast<QwtPlot *>( parent() );
    563 }
    564 
    565 //! Return parent plot widget
    566 const QwtPlot *QwtPlotCanvas::plot() const
    567 {
    568     return qobject_cast<const QwtPlot *>( parent() );
    569 }
    570 
    571 /*!
    572   \brief Changing the paint attributes
    573 
    574   \param attribute Paint attribute
    575   \param on On/Off
    576 
    577   \sa testPaintAttribute(), backingStore()
    578 */
     59    delete m_data;
     60}
     61
     62/*!
     63   \brief Changing the paint attributes
     64
     65   \param attribute Paint attribute
     66   \param on On/Off
     67
     68   \sa testPaintAttribute(), backingStore()
     69 */
    57970void QwtPlotCanvas::setPaintAttribute( PaintAttribute attribute, bool on )
    58071{
    581     if ( bool( d_data->paintAttributes & attribute ) == on )
     72    if ( bool( m_data->paintAttributes & attribute ) == on )
    58273        return;
    58374
    58475    if ( on )
    585         d_data->paintAttributes |= attribute;
     76        m_data->paintAttributes |= attribute;
    58677    else
    587         d_data->paintAttributes &= ~attribute;
     78        m_data->paintAttributes &= ~attribute;
    58879
    58980    switch ( attribute )
    … …  
    59384            if ( on )
    59485            {
    595                 if ( d_data->backingStore == NULL )
    596                     d_data->backingStore = new QPixmap();
     86                if ( m_data->backingStore == NULL )
     87                    m_data->backingStore = new QPixmap();
    59788
    59889                if ( isVisible() )
    59990                {
    60091#if QT_VERSION >= 0x050000
    601                     *d_data->backingStore = grab( rect() );
     92                    *m_data->backingStore = grab( rect() );
    60293#else
    603                     *d_data->backingStore =
     94                    *m_data->backingStore =
    60495                        QPixmap::grabWidget( this, rect() );
    60596#endif
    … …  
    60899            else
    609100            {
    610                 delete d_data->backingStore;
    611                 d_data->backingStore = NULL;
     101                delete m_data->backingStore;
     102                m_data->backingStore = NULL;
    612103            }
    613104            break;
    … …  
    620111            break;
    621112        }
    622         case HackStyledBackground:
    623         case ImmediatePaint:
     113        default:
    624114        {
    625115            break;
    … …  
    629119
    630120/*!
    631   Test whether a paint attribute is enabled
    632 
    633   \param attribute Paint attribute
    634   \return true, when attribute is enabled
    635   \sa setPaintAttribute()
    636 */
     121   Test whether a paint attribute is enabled
     122
     123   \param attribute Paint attribute
     124   \return true, when attribute is enabled
     125   \sa setPaintAttribute()
     126 */
    637127bool QwtPlotCanvas::testPaintAttribute( PaintAttribute attribute ) const
    638128{
    639     return d_data->paintAttributes & attribute;
     129    return m_data->paintAttributes & attribute;
    640130}
    641131
    642132//! \return Backing store, might be null
    643 const QPixmap *QwtPlotCanvas::backingStore() const
    644 {
    645     return d_data->backingStore;
     133const QPixmap* QwtPlotCanvas::backingStore() const
     134{
     135    return m_data->backingStore;
    646136}
    647137
    … …  
    649139void QwtPlotCanvas::invalidateBackingStore()
    650140{
    651     if ( d_data->backingStore )
    652         *d_data->backingStore = QPixmap();
    653 }
    654 
    655 /*!
    656   Set the focus indicator
    657 
    658   \sa FocusIndicator, focusIndicator()
    659 */
    660 void QwtPlotCanvas::setFocusIndicator( FocusIndicator focusIndicator )
    661 {
    662     d_data->focusIndicator = focusIndicator;
    663 }
    664 
    665 /*!
    666   \return Focus indicator
    667 
    668   \sa FocusIndicator, setFocusIndicator()
    669 */
    670 QwtPlotCanvas::FocusIndicator QwtPlotCanvas::focusIndicator() const
    671 {
    672     return d_data->focusIndicator;
    673 }
    674 
    675 /*!
    676   Set the radius for the corners of the border frame
    677 
    678   \param radius Radius of a rounded corner
    679   \sa borderRadius()
    680 */
    681 void QwtPlotCanvas::setBorderRadius( double radius )
    682 {
    683     d_data->borderRadius = qMax( 0.0, radius );
    684 }
    685 
    686 /*!
    687   \return Radius for the corners of the border frame
    688   \sa setBorderRadius()
    689 */
    690 double QwtPlotCanvas::borderRadius() const
    691 {
    692     return d_data->borderRadius;
    693 }
    694 
    695 /*!
    696   Qt event handler for QEvent::PolishRequest and QEvent::StyleChange
    697 
    698   \param event Qt Event
    699   \return See QFrame::event()
    700 */
    701 bool QwtPlotCanvas::event( QEvent *event )
     141    if ( m_data->backingStore )
     142        *m_data->backingStore = QPixmap();
     143}
     144
     145/*!
     146   Qt event handler for QEvent::PolishRequest and QEvent::StyleChange
     147
     148   \param event Qt Event
     149   \return See QFrame::event()
     150 */
     151bool QwtPlotCanvas::event( QEvent* event )
    702152{
    703153    if ( event->type() == QEvent::PolishRequest )
    … …  
    723173
    724174/*!
    725   Paint event
    726   \param event Paint event
    727 */
    728 void QwtPlotCanvas::paintEvent( QPaintEvent *event )
     175   Paint event
     176   \param event Paint event
     177 */
     178void QwtPlotCanvas::paintEvent( QPaintEvent* event )
    729179{
    730180    QPainter painter( this );
    … …  
    732182
    733183    if ( testPaintAttribute( QwtPlotCanvas::BackingStore ) &&
    734         d_data->backingStore != NULL )
    735     {
    736         QPixmap &bs = *d_data->backingStore;
    737 
    738         qreal pixelRatio = 1.0;
    739 
    740 #if QT_VERSION >= 0x050000
    741         pixelRatio = bs.devicePixelRatio();
    742 #endif
    743 
    744         if ( bs.size() != size() * pixelRatio )
     184        m_data->backingStore != NULL )
     185    {
     186        QPixmap& bs = *m_data->backingStore;
     187        if ( bs.size() != size() * QwtPainter::devicePixelRatio( &bs ) )
    745188        {
    746189            bs = QwtPainter::backingStore( this, size() );
    … …  
    749192            {
    750193                QPainter p( &bs );
    751                 qwtFillBackground( &p, this );
    752                 drawCanvas( &p, true );
     194                drawStyled( &p, testPaintAttribute( HackStyledBackground ) );
    753195            }
    754196            else
    755197            {
    756198                QPainter p;
    757                 if ( d_data->borderRadius <= 0.0 )
     199                if ( borderRadius() <= 0.0 )
    758200                {
    759201                    QwtPainter::fillPixmap( this, bs );
    760202                    p.begin( &bs );
    761                     drawCanvas( &p, false );
     203                    drawCanvas( &p );
    762204                }
    763205                else
    764206                {
    765207                    p.begin( &bs );
    766                     qwtFillBackground( &p, this );
    767                     drawCanvas( &p, true );
     208                    drawUnstyled( &p );
    768209                }
    769210
    … …  
    773214        }
    774215
    775         painter.drawPixmap( 0, 0, *d_data->backingStore );
     216        painter.drawPixmap( 0, 0, *m_data->backingStore );
    776217    }
    777218    else
    … …  
    781222            if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
    782223            {
    783                 qwtFillBackground( &painter, this );
    784                 drawCanvas( &painter, true );
     224                drawStyled( &painter, testPaintAttribute( HackStyledBackground ) );
    785225            }
    786226            else
    787227            {
    788                 drawCanvas( &painter, false );
     228                drawCanvas( &painter );
    789229            }
    790230        }
    … …  
    795235                if ( autoFillBackground() )
    796236                {
    797                     qwtFillBackground( &painter, this );
    798                     qwtDrawBackground( &painter, this );
     237                    fillBackground( &painter );
     238                    drawBackground( &painter );
    799239                }
    800240            }
    … …  
    810250
    811251                    painter.setClipPath( clipPath, Qt::IntersectClip );
    812                     qwtFillBackground( &painter, this );
    813                     qwtDrawBackground( &painter, this );
     252                    fillBackground( &painter );
     253                    drawBackground( &painter );
    814254
    815255                    painter.restore();
    … …  
    817257            }
    818258
    819             drawCanvas( &painter, false );
     259            drawCanvas( &painter );
    820260
    821261            if ( frameWidth() > 0 )
    … …  
    828268}
    829269
    830 void QwtPlotCanvas::drawCanvas( QPainter *painter, bool withBackground )
    831 {
    832     bool hackStyledBackground = false;
    833 
    834     if ( withBackground && testAttribute( Qt::WA_StyledBackground )
    835         && testPaintAttribute( HackStyledBackground ) )
    836     {
    837         // Antialiasing rounded borders is done by
    838         // inserting pixels with colors between the
    839         // border color and the color on the canvas,
    840         // When the border is painted before the plot items
    841         // these colors are interpolated for the canvas
    842         // and the plot items need to be clipped excluding
    843         // the anialiased pixels. In situations, where
    844         // the plot items fill the area at the rounded
    845         // borders this is noticeable.
    846         // The only way to avoid these annoying "artefacts"
    847         // is to paint the border on top of the plot items.
    848 
    849         if ( d_data->styleSheet.hasBorder &&
    850             !d_data->styleSheet.borderPath.isEmpty() )
    851         {
    852             // We have a border with at least one rounded corner
    853             hackStyledBackground = true;
    854         }
    855     }
    856 
    857     if ( withBackground )
    858     {
    859         painter->save();
    860 
    861         if ( testAttribute( Qt::WA_StyledBackground ) )
    862         {
    863             if ( hackStyledBackground )
    864             {
    865                 // paint background without border
    866 
    867                 painter->setPen( Qt::NoPen );
    868                 painter->setBrush( d_data->styleSheet.background.brush );
    869                 painter->setBrushOrigin( d_data->styleSheet.background.origin );
    870                 painter->setClipPath( d_data->styleSheet.borderPath );
    871                 painter->drawRect( contentsRect() );
    872             }
    873             else
    874             {
    875                 qwtDrawStyledBackground( this, painter );
    876             }
    877         }
    878         else if ( autoFillBackground() )
    879         {
    880             painter->setPen( Qt::NoPen );
    881             painter->setBrush( palette().brush( backgroundRole() ) );
    882 
    883             if ( d_data->borderRadius > 0.0 && ( rect() == frameRect() ) )
    884             {
    885                 if ( frameWidth() > 0 )
    886                 {
    887                     painter->setClipPath( borderPath( rect() ) );
    888                     painter->drawRect( rect() );
    889                 }
    890                 else
    891                 {
    892                     painter->setRenderHint( QPainter::Antialiasing, true );
    893                     painter->drawPath( borderPath( rect() ) );
    894                 }
    895             }
    896             else
    897             {
    898                 painter->drawRect( rect() );
    899             }
    900         }
    901 
    902         painter->restore();
    903     }
    904 
    905     painter->save();
    906 
    907     if ( !d_data->styleSheet.borderPath.isEmpty() )
    908     {
    909         painter->setClipPath(
    910             d_data->styleSheet.borderPath, Qt::IntersectClip );
    911     }
    912     else
    913     {
    914         if ( d_data->borderRadius > 0.0 )
    915             painter->setClipPath( borderPath( frameRect() ), Qt::IntersectClip );
    916         else
    917             painter->setClipRect( contentsRect(), Qt::IntersectClip );
    918     }
    919 
    920     plot()->drawCanvas( painter );
    921 
    922     painter->restore();
    923 
    924     if ( withBackground && hackStyledBackground )
    925     {
    926         // Now paint the border on top
    927         QStyleOptionFrame opt;
    928         opt.initFrom(this);
    929         style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, this);
    930     }
    931 }
    932 
    933 /*!
    934   Draw the border of the plot canvas
    935 
    936   \param painter Painter
    937   \sa setBorderRadius()
    938 */
    939 void QwtPlotCanvas::drawBorder( QPainter *painter )
    940 {
    941     if ( d_data->borderRadius > 0 )
    942     {
    943         if ( frameWidth() > 0 )
    944         {
    945             QwtPainter::drawRoundedFrame( painter, QRectF( frameRect() ),
    946                 d_data->borderRadius, d_data->borderRadius,
    947                 palette(), frameWidth(), frameStyle() );
    948         }
    949     }
    950     else
    951     {
    952 #if QT_VERSION >= 0x040500
    953 #if QT_VERSION < 0x050000
    954         QStyleOptionFrameV3 opt;
    955 #else
    956         QStyleOptionFrame opt;
    957 #endif
    958         opt.init(this);
    959 
    960         int frameShape  = frameStyle() & QFrame::Shape_Mask;
    961         int frameShadow = frameStyle() & QFrame::Shadow_Mask;
    962 
    963         opt.frameShape = QFrame::Shape( int( opt.frameShape ) | frameShape );
    964 #if 0
    965         opt.rect = frameRect();
    966 #endif
    967 
    968         switch (frameShape)
    969         {
    970             case QFrame::Box:
    971             case QFrame::HLine:
    972             case QFrame::VLine:
    973             case QFrame::StyledPanel:
    974             case QFrame::Panel:
    975             {
    976                 opt.lineWidth = lineWidth();
    977                 opt.midLineWidth = midLineWidth();
    978                 break;
    979             }
    980             default:
    981             {
    982                 opt.lineWidth = frameWidth();
    983                 break;
    984             }
    985         }
    986 
    987         if ( frameShadow == Sunken )
    988             opt.state |= QStyle::State_Sunken;
    989         else if ( frameShadow == Raised )
    990             opt.state |= QStyle::State_Raised;
    991 
    992         style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter, this);
    993 #else
     270/*!
     271   Draw the border of the plot canvas
     272
     273   \param painter Painter
     274   \sa setBorderRadius()
     275 */
     276void QwtPlotCanvas::drawBorder( QPainter* painter )
     277{
     278    if ( borderRadius() <= 0 )
     279    {
    994280        drawFrame( painter );
    995 #endif
    996     }
    997 }
    998 
    999 /*!
    1000   Resize event
    1001   \param event Resize event
    1002 */
    1003 void QwtPlotCanvas::resizeEvent( QResizeEvent *event )
     281        return;
     282    }
     283
     284    QwtPlotAbstractCanvas::drawBorder( painter );
     285}
     286
     287/*!
     288   Resize event
     289   \param event Resize event
     290 */
     291void QwtPlotCanvas::resizeEvent( QResizeEvent* event )
    1004292{
    1005293    QFrame::resizeEvent( event );
    … …  
    1008296
    1009297/*!
    1010   Draw the focus indication
    1011   \param painter Painter
    1012 */
    1013 void QwtPlotCanvas::drawFocusIndicator( QPainter *painter )
    1014 {
    1015     const int margin = 1;
    1016 
    1017     QRect focusRect = contentsRect();
    1018     focusRect.setRect( focusRect.x() + margin, focusRect.y() + margin,
    1019         focusRect.width() - 2 * margin, focusRect.height() - 2 * margin );
    1020 
    1021     QwtPainter::drawFocusRect( painter, this, focusRect );
    1022 }
    1023 
    1024 /*!
    1025298   Invalidate the paint cache and repaint the canvas
    1026299   \sa invalidatePaintCache()
    1027 */
     300 */
    1028301void QwtPlotCanvas::replot()
    1029302{
    … …  
    1036309}
    1037310
    1038 //! Update the cached information about the current style sheet
    1039 void QwtPlotCanvas::updateStyleSheetInfo()
    1040 {
    1041     if ( !testAttribute(Qt::WA_StyledBackground ) )
    1042         return;
    1043 
    1044     QwtStyleSheetRecorder recorder( size() );
    1045 
    1046     QPainter painter( &recorder );
    1047 
    1048     QStyleOption opt;
    1049     opt.initFrom(this);
    1050     style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, this);
    1051 
    1052     painter.end();
    1053 
    1054     d_data->styleSheet.hasBorder = !recorder.border.rectList.isEmpty();
    1055     d_data->styleSheet.cornerRects = recorder.clipRects;
    1056 
    1057     if ( recorder.background.path.isEmpty() )
    1058     {
    1059         if ( !recorder.border.rectList.isEmpty() )
    1060         {
    1061             d_data->styleSheet.borderPath =
    1062                 qwtCombinePathList( rect(), recorder.border.pathList );
    1063         }
    1064     }
    1065     else
    1066     {
    1067         d_data->styleSheet.borderPath = recorder.background.path;
    1068         d_data->styleSheet.background.brush = recorder.background.brush;
    1069         d_data->styleSheet.background.origin = recorder.background.origin;
    1070     }
    1071 }
    1072 
    1073311/*!
    1074312   Calculate the painter path for a styled or rounded border
    … …  
    1079317   \param rect Bounding rectangle of the canvas
    1080318   \return Painter path, that can be used for clipping
    1081 */
    1082 QPainterPath QwtPlotCanvas::borderPath( const QRect &rect ) const
    1083 {
    1084     if ( testAttribute(Qt::WA_StyledBackground ) )
    1085     {
    1086         QwtStyleSheetRecorder recorder( rect.size() );
    1087 
    1088         QPainter painter( &recorder );
    1089 
    1090         QStyleOption opt;
    1091         opt.initFrom(this);
    1092         opt.rect = rect;
    1093         style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, this);
    1094 
    1095         painter.end();
    1096 
    1097         if ( !recorder.background.path.isEmpty() )
    1098             return recorder.background.path;
    1099 
    1100         if ( !recorder.border.rectList.isEmpty() )
    1101             return qwtCombinePathList( rect, recorder.border.pathList );
    1102     }
    1103     else if ( d_data->borderRadius > 0.0 )
    1104     {
    1105         double fw2 = frameWidth() * 0.5;
    1106         QRectF r = QRectF(rect).adjusted( fw2, fw2, -fw2, -fw2 );
    1107 
    1108         QPainterPath path;
    1109         path.addRoundedRect( r, d_data->borderRadius, d_data->borderRadius );
    1110         return path;
    1111     }
    1112 
    1113     return QPainterPath();
    1114 }
     319 */
     320QPainterPath QwtPlotCanvas::borderPath( const QRect& rect ) const
     321{
     322    return canvasBorderPath( rect );
     323}
     324
     325#include "moc_qwt_plot_canvas.cpp"
  • trunk/BNC/qwt/qwt_plot_canvas.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
     14#include "qwt_plot_abstract_canvas.h"
     15
    1416#include <qframe.h>
    15 #include <qpainterpath.h>
    1617
    1718class QwtPlot;
    1819class QPixmap;
     20class QPainterPath;
    1921
    2022/*!
    21   \brief Canvas of a QwtPlot.
     23   \brief Canvas of a QwtPlot.
    2224
    2325   Canvas is the widget where all plot items are displayed
    2426
    25   \sa QwtPlot::setCanvas(), QwtPlotGLCanvas
    26 */
    27 class QWT_EXPORT QwtPlotCanvas : public QFrame
     27   \sa QwtPlot::setCanvas(), QwtPlotGLCanvas, QwtPlotOpenGLCanvas
     28 */
     29class QWT_EXPORT QwtPlotCanvas : public QFrame, public QwtPlotAbstractCanvas
    2830{
    2931    Q_OBJECT
    … …  
    3133    Q_PROPERTY( double borderRadius READ borderRadius WRITE setBorderRadius )
    3234
    33 public:
     35  public:
    3436
    3537    /*!
    36       \brief Paint attributes
     38       \brief Paint attributes
    3739
    38       The default setting enables BackingStore and Opaque.
     40       The default setting enables BackingStore and Opaque.
    3941
    40       \sa setPaintAttribute(), testPaintAttribute()
     42       \sa setPaintAttribute(), testPaintAttribute()
    4143     */
    4244    enum PaintAttribute
    4345    {
    4446        /*!
    45           \brief Paint double buffered reusing the content
     47           \brief Paint double buffered reusing the content
    4648                 of the pixmap buffer when possible.
    4749
    48           Using a backing store might improve the performance
    49           significantly, when working with widget overlays ( like rubber bands ).
    50           Disabling the cache might improve the performance for
    51           incremental paints (using QwtPlotDirectPainter ).
     50           Using a backing store might improve the performance
     51           significantly, when working with widget overlays ( like rubber bands ).
     52           Disabling the cache might improve the performance for
     53           incremental paints (using QwtPlotDirectPainter ).
    5254
    53           \sa backingStore(), invalidateBackingStore()
     55           \sa backingStore(), invalidateBackingStore()
    5456         */
    5557        BackingStore = 1,
    5658
    5759        /*!
    58           \brief Try to fill the complete contents rectangle
     60           \brief Try to fill the complete contents rectangle
    5961                 of the plot canvas
    6062
    61           When using styled backgrounds Qt assumes, that the
    62           canvas doesn't fill its area completely
    63           ( f.e because of rounded borders ) and fills the area
    64           below the canvas. When this is done with gradients it might
    65           result in a serious performance bottleneck - depending on the size.
     63           When using styled backgrounds Qt assumes, that the
     64           canvas doesn't fill its area completely
     65           ( f.e because of rounded borders ) and fills the area
     66           below the canvas. When this is done with gradients it might
     67           result in a serious performance bottleneck - depending on the size.
    6668
    67           When the Opaque attribute is enabled the canvas tries to
    68           identify the gaps with some heuristics and to fill those only.
     69           When the Opaque attribute is enabled the canvas tries to
     70           identify the gaps with some heuristics and to fill those only.
    6971
    70           \warning Will not work for semitransparent backgrounds
     72           \warning Will not work for semitransparent backgrounds
    7173         */
    7274        Opaque       = 2,
    7375
    7476        /*!
    75           \brief Try to improve painting of styled backgrounds
     77           \brief Try to improve painting of styled backgrounds
    7678
    77           QwtPlotCanvas supports the box model attributes for
    78           customizing the layout with style sheets. Unfortunately
    79           the design of Qt style sheets has no concept how to
    80           handle backgrounds with rounded corners - beside of padding.
     79           QwtPlotCanvas supports the box model attributes for
     80           customizing the layout with style sheets. Unfortunately
     81           the design of Qt style sheets has no concept how to
     82           handle backgrounds with rounded corners - beside of padding.
    8183
    82           When HackStyledBackground is enabled the plot canvas tries
    83           to separate the background from the background border
    84           by reverse engineering to paint the background before and
    85           the border after the plot items. In this order the border
    86           gets perfectly antialiased and you can avoid some pixel
    87           artifacts in the corners.
     84           When HackStyledBackground is enabled the plot canvas tries
     85           to separate the background from the background border
     86           by reverse engineering to paint the background before and
     87           the border after the plot items. In this order the border
     88           gets perfectly antialiased and you can avoid some pixel
     89           artifacts in the corners.
    8890         */
    8991        HackStyledBackground = 4,
    9092
    9193        /*!
    92           When ImmediatePaint is set replot() calls repaint()
    93           instead of update().
     94           When ImmediatePaint is set replot() calls repaint()
     95           instead of update().
    9496
    95           \sa replot(), QWidget::repaint(), QWidget::update()
     97           \sa replot(), QWidget::repaint(), QWidget::update()
    9698         */
    9799        ImmediatePaint = 8
    98100    };
    99101
    100     //! Paint attributes
    101     typedef QFlags<PaintAttribute> PaintAttributes;
     102    Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute )
    102103
    103     /*!
    104       \brief Focus indicator
    105       The default setting is NoFocusIndicator
    106       \sa setFocusIndicator(), focusIndicator(), drawFocusIndicator()
    107     */
    108 
    109     enum FocusIndicator
    110     {
    111         //! Don't paint a focus indicator
    112         NoFocusIndicator,
    113 
    114         /*!
    115           The focus is related to the complete canvas.
    116           Paint the focus indicator using drawFocusIndicator()
    117          */
    118         CanvasFocusIndicator,
    119 
    120         /*!
    121           The focus is related to an item (curve, point, ...) on
    122           the canvas. It is up to the application to display a
    123           focus indication using f.e. highlighting.
    124          */
    125         ItemFocusIndicator
    126     };
    127 
    128     explicit QwtPlotCanvas( QwtPlot * = NULL );
     104    explicit QwtPlotCanvas( QwtPlot* = NULL );
    129105    virtual ~QwtPlotCanvas();
    130 
    131     QwtPlot *plot();
    132     const QwtPlot *plot() const;
    133 
    134     void setFocusIndicator( FocusIndicator );
    135     FocusIndicator focusIndicator() const;
    136 
    137     void setBorderRadius( double );
    138     double borderRadius() const;
    139106
    140107    void setPaintAttribute( PaintAttribute, bool on = true );
    141108    bool testPaintAttribute( PaintAttribute ) const;
    142109
    143     const QPixmap *backingStore() const;
    144     void invalidateBackingStore();
     110    const QPixmap* backingStore() const;
     111    Q_INVOKABLE void invalidateBackingStore();
    145112
    146     virtual bool event( QEvent * );
     113    virtual bool event( QEvent* ) QWT_OVERRIDE;
    147114
    148     Q_INVOKABLE QPainterPath borderPath( const QRect & ) const;
     115    Q_INVOKABLE QPainterPath borderPath( const QRect& ) const;
    149116
    150 public Q_SLOTS:
     117  public Q_SLOTS:
    151118    void replot();
    152119
    153 protected:
    154     virtual void paintEvent( QPaintEvent * );
    155     virtual void resizeEvent( QResizeEvent * );
     120  protected:
     121    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
     122    virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE;
    156123
    157     virtual void drawFocusIndicator( QPainter * );
    158     virtual void drawBorder( QPainter * );
     124    virtual void drawBorder( QPainter* ) QWT_OVERRIDE;
    159125
    160     void updateStyleSheetInfo();
    161 
    162 private:
    163     void drawCanvas( QPainter *, bool withBackground );
    164 
     126  private:
    165127    class PrivateData;
    166     PrivateData *d_data;
     128    PrivateData* m_data;
    167129};
    168130
  • trunk/BNC/qwt/qwt_plot_curve.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1515#include "qwt_scale_map.h"
    1616#include "qwt_plot.h"
    17 #include "qwt_curve_fitter.h"
     17#include "qwt_spline_curve_fitter.h"
    1818#include "qwt_symbol.h"
    1919#include "qwt_point_mapper.h"
     20#include "qwt_text.h"
     21#include "qwt_graphic.h"
     22
    2023#include <qpainter.h>
    21 #include <qpixmap.h>
    22 #include <qalgorithms.h>
    23 #include <qmath.h>
    24 
    25 static void qwtUpdateLegendIconSize( QwtPlotCurve *curve )
     24#include <qpainterpath.h>
     25#include <qnumeric.h>
     26
     27#include <climits>
     28
     29static inline QRectF qwtIntersectedClipRect( const QRectF& rect, QPainter* painter )
     30{
     31    QRectF clipRect = rect;
     32    if ( painter->hasClipping() )
     33        clipRect &= painter->clipBoundingRect();
     34
     35    return clipRect;
     36}
     37
     38static void qwtUpdateLegendIconSize( QwtPlotCurve* curve )
    2639{
    2740    if ( curve->symbol() &&
    … …  
    3548            // Avoid, that the line is completely covered by the symbol
    3649
    37             int w = qCeil( 1.5 * sz.width() );
     50            int w = qwtCeil( 1.5 * sz.width() );
    3851            if ( w % 2 )
    3952                w++;
    … …  
    4659}
    4760
    48 static int qwtVerifyRange( int size, int &i1, int &i2 )
     61static int qwtVerifyRange( int size, int& i1, int& i2 )
    4962{
    5063    if ( size < 1 )
    … …  
    6275class QwtPlotCurve::PrivateData
    6376{
    64 public:
    65     PrivateData():
    66         style( QwtPlotCurve::Lines ),
    67         baseline( 0.0 ),
    68         symbol( NULL ),
    69         attributes( 0 ),
    70         paintAttributes(
    71             QwtPlotCurve::ClipPolygons | QwtPlotCurve::FilterPoints ),
    72         legendAttributes( 0 )
    73     {
    74         pen = QPen( Qt::black );
     77  public:
     78    PrivateData()
     79        : style( QwtPlotCurve::Lines )
     80        , baseline( 0.0 )
     81        , symbol( NULL )
     82        , pen( Qt::black )
     83        , paintAttributes( QwtPlotCurve::ClipPolygons | QwtPlotCurve::FilterPoints )
     84    {
    7585        curveFitter = new QwtSplineCurveFitter;
    7686    }
    … …  
    8595    double baseline;
    8696
    87     const QwtSymbol *symbol;
    88     QwtCurveFitter *curveFitter;
     97    const QwtSymbol* symbol;
     98    QwtCurveFitter* curveFitter;
    8999
    90100    QPen pen;
    … …  
    98108
    99109/*!
    100   Constructor
    101   \param title Title of the curve
    102 */
    103 QwtPlotCurve::QwtPlotCurve( const QwtText &title ):
    104     QwtPlotSeriesItem( title )
     110   Constructor
     111   \param title Title of the curve
     112 */
     113QwtPlotCurve::QwtPlotCurve( const QwtText& title )
     114    : QwtPlotSeriesItem( title )
    105115{
    106116    init();
    … …  
    108118
    109119/*!
    110   Constructor
    111   \param title Title of the curve
    112 */
    113 QwtPlotCurve::QwtPlotCurve( const QString &title ):
    114     QwtPlotSeriesItem( QwtText( title ) )
     120   Constructor
     121   \param title Title of the curve
     122 */
     123QwtPlotCurve::QwtPlotCurve( const QString& title )
     124    : QwtPlotSeriesItem( QwtText( title ) )
    115125{
    116126    init();
    … …  
    120130QwtPlotCurve::~QwtPlotCurve()
    121131{
    122     delete d_data;
     132    delete m_data;
    123133}
    124134
    … …  
    129139    setItemAttribute( QwtPlotItem::AutoScale );
    130140
    131     d_data = new PrivateData;
     141    m_data = new PrivateData;
    132142    setData( new QwtPointSeriesData() );
    133143
    … …  
    142152
    143153/*!
    144   Specify an attribute how to draw the curve
    145 
    146   \param attribute Paint attribute
    147   \param on On/Off
    148   \sa testPaintAttribute()
    149 */
     154   Specify an attribute how to draw the curve
     155
     156   \param attribute Paint attribute
     157   \param on On/Off
     158   \sa testPaintAttribute()
     159 */
    150160void QwtPlotCurve::setPaintAttribute( PaintAttribute attribute, bool on )
    151161{
    152162    if ( on )
    153         d_data->paintAttributes |= attribute;
     163        m_data->paintAttributes |= attribute;
    154164    else
    155         d_data->paintAttributes &= ~attribute;
     165        m_data->paintAttributes &= ~attribute;
    156166}
    157167
    … …  
    159169    \return True, when attribute is enabled
    160170    \sa setPaintAttribute()
    161 */
     171 */
    162172bool QwtPlotCurve::testPaintAttribute( PaintAttribute attribute ) const
    163173{
    164     return ( d_data->paintAttributes & attribute );
    165 }
    166 
    167 /*!
    168   Specify an attribute how to draw the legend icon
    169 
    170   \param attribute Attribute
    171   \param on On/Off
    172   /sa testLegendAttribute(). legendIcon()
    173 */
     174    return ( m_data->paintAttributes & attribute );
     175}
     176
     177/*!
     178   Specify an attribute how to draw the legend icon
     179
     180   \param attribute Attribute
     181   \param on On/Off
     182   /sa testLegendAttribute(). legendIcon()
     183 */
    174184void QwtPlotCurve::setLegendAttribute( LegendAttribute attribute, bool on )
    175185{
    … …  
    177187    {
    178188        if ( on )
    179             d_data->legendAttributes |= attribute;
     189            m_data->legendAttributes |= attribute;
    180190        else
    181             d_data->legendAttributes &= ~attribute;
     191            m_data->legendAttributes &= ~attribute;
    182192
    183193        qwtUpdateLegendIconSize( this );
    … …  
    187197
    188198/*!
    189   \return True, when attribute is enabled
    190   \sa setLegendAttribute()
    191 */
     199   \return True, when attribute is enabled
     200   \sa setLegendAttribute()
     201 */
    192202bool QwtPlotCurve::testLegendAttribute( LegendAttribute attribute ) const
    193203{
    194     return ( d_data->legendAttributes & attribute );
    195 }
    196 
    197 /*!
    198   Set the curve's drawing style
    199 
    200   \param style Curve style
    201   \sa style()
    202 */
     204    return ( m_data->legendAttributes & attribute );
     205}
     206
     207/*!
     208   Specify the attributes how to draw the legend icon
     209
     210   \param attributes Attributes
     211   /sa setLegendAttribute(). legendIcon()
     212 */
     213void QwtPlotCurve::setLegendAttributes( LegendAttributes attributes )
     214{
     215    if ( attributes != m_data->legendAttributes )
     216    {
     217        m_data->legendAttributes = attributes;
     218
     219        qwtUpdateLegendIconSize( this );
     220        legendChanged();
     221    }
     222}
     223
     224/*!
     225   \return Attributes how to draw the legend icon
     226   \sa setLegendAttributes(), testLegendAttribute()
     227 */
     228QwtPlotCurve::LegendAttributes QwtPlotCurve::legendAttributes() const
     229{
     230    return m_data->legendAttributes;
     231}
     232
     233/*!
     234   Set the curve's drawing style
     235
     236   \param style Curve style
     237   \sa style()
     238 */
    203239void QwtPlotCurve::setStyle( CurveStyle style )
    204240{
    205     if ( style != d_data->style )
    206     {
    207         d_data->style = style;
     241    if ( style != m_data->style )
     242    {
     243        m_data->style = style;
    208244
    209245        legendChanged();
    … …  
    213249
    214250/*!
    215   \return Style of the curve
    216   \sa setStyle()
    217 */
     251   \return Style of the curve
     252   \sa setStyle()
     253 */
    218254QwtPlotCurve::CurveStyle QwtPlotCurve::style() const
    219255{
    220     return d_data->style;
    221 }
    222 
    223 /*!
    224   \brief Assign a symbol
    225 
    226   The curve will take the ownership of the symbol, hence the previously
    227   set symbol will be delete by setting a new one. If \p symbol is
    228   \c NULL no symbol will be drawn.
    229 
    230   \param symbol Symbol
    231   \sa symbol()
    232 */
    233 void QwtPlotCurve::setSymbol( QwtSymbol *symbol )
    234 {
    235     if ( symbol != d_data->symbol )
    236     {
    237         delete d_data->symbol;
    238         d_data->symbol = symbol;
     256    return m_data->style;
     257}
     258
     259/*!
     260   \brief Assign a symbol
     261
     262   The curve will take the ownership of the symbol, hence the previously
     263   set symbol will be delete by setting a new one. If \p symbol is
     264   \c NULL no symbol will be drawn.
     265
     266   \param symbol Symbol
     267   \sa symbol()
     268 */
     269void QwtPlotCurve::setSymbol( QwtSymbol* symbol )
     270{
     271    if ( symbol != m_data->symbol )
     272    {
     273        delete m_data->symbol;
     274        m_data->symbol = symbol;
    239275
    240276        qwtUpdateLegendIconSize( this );
    … …  
    246282
    247283/*!
    248   \return Current symbol or NULL, when no symbol has been assigned
    249   \sa setSymbol()
    250 */
    251 const QwtSymbol *QwtPlotCurve::symbol() const
    252 {
    253     return d_data->symbol;
    254 }
    255 
    256 /*!
    257   Build and assign a pen
    258 
    259   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    260   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    261   to hide this incompatibility.
    262 
    263   \param color Pen color
    264   \param width Pen width
    265   \param style Pen style
    266 
    267   \sa pen(), brush()
    268  */
    269 void QwtPlotCurve::setPen( const QColor &color, qreal width, Qt::PenStyle style )
     284   \return Current symbol or NULL, when no symbol has been assigned
     285   \sa setSymbol()
     286 */
     287const QwtSymbol* QwtPlotCurve::symbol() const
     288{
     289    return m_data->symbol;
     290}
     291
     292/*!
     293   Build and assign a pen
     294
     295   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     296   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     297   to hide this incompatibility.
     298
     299   \param color Pen color
     300   \param width Pen width
     301   \param style Pen style
     302
     303   \sa pen(), brush()
     304 */
     305void QwtPlotCurve::setPen( const QColor& color, qreal width, Qt::PenStyle style )
    270306{
    271307    setPen( QPen( color, width, style ) );
    … …  
    273309
    274310/*!
    275   Assign a pen
    276 
    277   \param pen New pen
    278   \sa pen(), brush()
    279 */
    280 void QwtPlotCurve::setPen( const QPen &pen )
    281 {
    282     if ( pen != d_data->pen )
    283     {
    284         d_data->pen = pen;
     311   Assign a pen
     312
     313   \param pen New pen
     314   \sa pen(), brush()
     315 */
     316void QwtPlotCurve::setPen( const QPen& pen )
     317{
     318    if ( pen != m_data->pen )
     319    {
     320        m_data->pen = pen;
    285321
    286322        legendChanged();
    … …  
    290326
    291327/*!
    292   \return Pen used to draw the lines
    293   \sa setPen(), brush()
    294 */
     328   \return Pen used to draw the lines
     329   \sa setPen(), brush()
     330 */
    295331const QPen& QwtPlotCurve::pen() const
    296332{
    297     return d_data->pen;
    298 }
    299 
    300 /*!
    301   \brief Assign a brush.
     333    return m_data->pen;
     334}
     335
     336/*!
     337   \brief Assign a brush.
    302338
    303339   In case of brush.style() != QBrush::NoBrush
    … …  
    310346   (ascending or descending).
    311347
    312   \param brush New brush
    313   \sa brush(), setBaseline(), baseline()
    314 */
    315 void QwtPlotCurve::setBrush( const QBrush &brush )
    316 {
    317     if ( brush != d_data->brush )
    318     {
    319         d_data->brush = brush;
     348   \param brush New brush
     349   \sa brush(), setBaseline(), baseline()
     350 */
     351void QwtPlotCurve::setBrush( const QBrush& brush )
     352{
     353    if ( brush != m_data->brush )
     354    {
     355        m_data->brush = brush;
    320356
    321357        legendChanged();
    … …  
    325361
    326362/*!
    327   \return Brush used to fill the area between lines and the baseline
    328   \sa setBrush(), setBaseline(), baseline()
    329 */
     363   \return Brush used to fill the area between lines and the baseline
     364   \sa setBrush(), setBaseline(), baseline()
     365 */
    330366const QBrush& QwtPlotCurve::brush() const
    331367{
    332     return d_data->brush;
    333 }
    334 
    335 /*!
    336   Draw an interval of the curve
    337 
    338   \param painter Painter
    339   \param xMap Maps x-values into pixel coordinates.
    340   \param yMap Maps y-values into pixel coordinates.
    341   \param canvasRect Contents rectangle of the canvas
    342   \param from Index of the first point to be painted
    343   \param to Index of the last point to be painted. If to < 0 the
     368    return m_data->brush;
     369}
     370
     371/*!
     372   Draw an interval of the curve
     373
     374   \param painter Painter
     375   \param xMap Maps x-values into pixel coordinates.
     376   \param yMap Maps y-values into pixel coordinates.
     377   \param canvasRect Contents rectangle of the canvas
     378   \param from Index of the first point to be painted
     379   \param to Index of the last point to be painted. If to < 0 the
    344380         curve will be painted to its last point.
    345381
    346   \sa drawCurve(), drawSymbols(),
    347 */
    348 void QwtPlotCurve::drawSeries( QPainter *painter,
    349     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    350     const QRectF &canvasRect, int from, int to ) const
     382   \sa drawCurve(), drawSymbols(),
     383 */
     384void QwtPlotCurve::drawSeries( QPainter* painter,
     385    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     386    const QRectF& canvasRect, int from, int to ) const
    351387{
    352388    const size_t numSamples = dataSize();
    … …  
    361397    {
    362398        painter->save();
    363         painter->setPen( d_data->pen );
     399        painter->setPen( m_data->pen );
    364400
    365401        /*
    366           Qt 4.0.0 is slow when drawing lines, but it's even
    367           slower when the painter has a brush. So we don't
    368           set the brush before we really need it.
     402           Qt 4.0.0 is slow when drawing lines, but it's even
     403           slower when the painter has a brush. So we don't
     404           set the brush before we really need it.
    369405         */
    370406
    371         drawCurve( painter, d_data->style, xMap, yMap, canvasRect, from, to );
     407        drawCurve( painter, m_data->style, xMap, yMap, canvasRect, from, to );
    372408        painter->restore();
    373409
    374         if ( d_data->symbol &&
    375             ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
     410        if ( m_data->symbol &&
     411            ( m_data->symbol->style() != QwtSymbol::NoSymbol ) )
    376412        {
    377413            painter->save();
    378             drawSymbols( painter, *d_data->symbol,
     414            drawSymbols( painter, *m_data->symbol,
    379415                xMap, yMap, canvasRect, from, to );
    380416            painter->restore();
    … …  
    384420
    385421/*!
    386   \brief Draw the line part (without symbols) of a curve interval.
    387   \param painter Painter
    388   \param style curve style, see QwtPlotCurve::CurveStyle
    389   \param xMap x map
    390   \param yMap y map
    391   \param canvasRect Contents rectangle of the canvas
    392   \param from index of the first point to be painted
    393   \param to index of the last point to be painted
    394   \sa draw(), drawDots(), drawLines(), drawSteps(), drawSticks()
    395 */
    396 void QwtPlotCurve::drawCurve( QPainter *painter, int style,
    397     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    398     const QRectF &canvasRect, int from, int to ) const
     422   \brief Draw the line part (without symbols) of a curve interval.
     423   \param painter Painter
     424   \param style curve style, see QwtPlotCurve::CurveStyle
     425   \param xMap x map
     426   \param yMap y map
     427   \param canvasRect Contents rectangle of the canvas
     428   \param from index of the first point to be painted
     429   \param to index of the last point to be painted
     430   \sa draw(), drawDots(), drawLines(), drawSteps(), drawSticks()
     431 */
     432void QwtPlotCurve::drawCurve( QPainter* painter, int style,
     433    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     434    const QRectF& canvasRect, int from, int to ) const
    399435{
    400436    switch ( style )
    … …  
    426462
    427463/*!
    428   \brief Draw lines
    429 
    430   If the CurveAttribute Fitted is enabled a QwtCurveFitter tries
    431   to interpolate/smooth the curve, before it is painted.
    432 
    433   \param painter Painter
    434   \param xMap x map
    435   \param yMap y map
    436   \param canvasRect Contents rectangle of the canvas
    437   \param from index of the first point to be painted
    438   \param to index of the last point to be painted
    439 
    440   \sa setCurveAttribute(), setCurveFitter(), draw(),
     464   \brief Draw lines
     465
     466   If the CurveAttribute Fitted is enabled a QwtCurveFitter tries
     467   to interpolate/smooth the curve, before it is painted.
     468
     469   \param painter Painter
     470   \param xMap x map
     471   \param yMap y map
     472   \param canvasRect Contents rectangle of the canvas
     473   \param from index of the first point to be painted
     474   \param to index of the last point to be painted
     475
     476   \sa setCurveAttribute(), setCurveFitter(), draw(),
    441477      drawLines(), drawDots(), drawSteps(), drawSticks()
    442 */
    443 void QwtPlotCurve::drawLines( QPainter *painter,
    444     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    445     const QRectF &canvasRect, int from, int to ) const
     478 */
     479void QwtPlotCurve::drawLines( QPainter* painter,
     480    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     481    const QRectF& canvasRect, int from, int to ) const
    446482{
    447483    if ( from > to )
    448484        return;
    449485
    450     const bool doAlign = QwtPainter::roundingAlignment( painter );
    451     const bool doFit = ( d_data->attributes & Fitted ) && d_data->curveFitter;
    452     const bool doFill = ( d_data->brush.style() != Qt::NoBrush )
    453             && ( d_data->brush.color().alpha() > 0 );
     486    const bool doFit = ( m_data->attributes & Fitted ) && m_data->curveFitter;
     487    const bool doAlign = !doFit && QwtPainter::roundingAlignment( painter );
     488    const bool doFill = ( m_data->brush.style() != Qt::NoBrush )
     489        && ( m_data->brush.color().alpha() > 0 );
    454490
    455491    QRectF clipRect;
    456     if ( d_data->paintAttributes & ClipPolygons )
    457     {
    458         qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
    459         clipRect = canvasRect.adjusted(-pw, -pw, pw, pw);
    460     }
    461 
    462     bool doIntegers = false;
    463 
    464 #if QT_VERSION < 0x040800
    465 
    466     // For Qt <= 4.7 the raster paint engine is significantly faster
    467     // for rendering QPolygon than for QPolygonF. So let's
    468     // see if we can use it.
    469 
    470     if ( painter->paintEngine()->type() == QPaintEngine::Raster )
    471     {
    472         // In case of filling or fitting performance doesn't count
    473         // because both operations are much more expensive
    474         // then drawing the polyline itself
    475 
    476         if ( !doFit && !doFill )
    477             doIntegers = true;
    478     }
    479 #endif
    480 
    481     const bool noDuplicates = d_data->paintAttributes & FilterPoints;
     492    if ( m_data->paintAttributes & ClipPolygons )
     493    {
     494        clipRect = qwtIntersectedClipRect( canvasRect, painter );
     495
     496        const qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
     497        clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
     498    }
    482499
    483500    QwtPointMapper mapper;
    484     mapper.setFlag( QwtPointMapper::RoundPoints, doAlign );
    485     mapper.setFlag( QwtPointMapper::WeedOutPoints, noDuplicates );
     501
     502    if ( doAlign )
     503    {
     504        mapper.setFlag( QwtPointMapper::RoundPoints, true );
     505        mapper.setFlag( QwtPointMapper::WeedOutIntermediatePoints,
     506            testPaintAttribute( FilterPointsAggressive ) );
     507    }
     508
     509    mapper.setFlag( QwtPointMapper::WeedOutPoints,
     510        testPaintAttribute( FilterPoints ) ||
     511        testPaintAttribute( FilterPointsAggressive ) );
     512
    486513    mapper.setBoundingRect( canvasRect );
    487514
    488     if ( doIntegers )
    489     {
    490         QPolygon polyline = mapper.toPolygon(
    491             xMap, yMap, data(), from, to );
    492 
    493         if ( d_data->paintAttributes & ClipPolygons )
    494         {
    495             polyline = QwtClipper::clipPolygon(
    496                 clipRect.toAlignedRect(), polyline, false );
    497         }
    498 
    499         QwtPainter::drawPolyline( painter, polyline );
     515    QPolygonF polyline = mapper.toPolygonF( xMap, yMap, data(), from, to );
     516
     517    if ( doFill )
     518    {
     519        if ( doFit )
     520        {
     521            // it might be better to extend and draw the curvePath, but for
     522            // the moment we keep an implementation, where we translate the
     523            // path back to a polyline.
     524
     525            polyline = m_data->curveFitter->fitCurve( polyline );
     526        }
     527
     528        if ( painter->pen().style() != Qt::NoPen )
     529        {
     530            // here we are wasting memory for the filled copy,
     531            // do polygon clipping twice etc .. TODO
     532
     533            QPolygonF filled = polyline;
     534            fillCurve( painter, xMap, yMap, canvasRect, filled );
     535            filled.clear();
     536
     537            if ( m_data->paintAttributes & ClipPolygons )
     538                QwtClipper::clipPolygonF( clipRect, polyline, false );
     539
     540            QwtPainter::drawPolyline( painter, polyline );
     541        }
     542        else
     543        {
     544            fillCurve( painter, xMap, yMap, canvasRect, polyline );
     545        }
    500546    }
    501547    else
    502548    {
    503         QPolygonF polyline = mapper.toPolygonF( xMap, yMap, data(), from, to );
     549        if ( testPaintAttribute( ClipPolygons ) )
     550        {
     551            QwtClipper::clipPolygonF( clipRect, polyline, false );
     552        }
    504553
    505554        if ( doFit )
    506             polyline = d_data->curveFitter->fitCurve( polyline );
    507 
    508         if ( doFill )
    509         {
    510             if ( painter->pen().style() != Qt::NoPen )
     555        {
     556            if ( m_data->curveFitter->mode() == QwtCurveFitter::Path )
    511557            {
    512                 // here we are wasting memory for the filled copy,
    513                 // do polygon clipping twice etc .. TODO
    514 
    515                 QPolygonF filled = polyline;
    516                 fillCurve( painter, xMap, yMap, canvasRect, filled );
    517                 filled.clear();
    518 
    519                 if ( d_data->paintAttributes & ClipPolygons )
    520                 {
    521                     polyline = QwtClipper::clipPolygonF(
    522                         clipRect, polyline, false );
    523                 }
    524 
    525                 QwtPainter::drawPolyline( painter, polyline );
     558                const QPainterPath curvePath =
     559                    m_data->curveFitter->fitCurvePath( polyline );
     560
     561                painter->drawPath( curvePath );
    526562            }
    527563            else
    528564            {
    529                 fillCurve( painter, xMap, yMap, canvasRect, polyline );
     565                polyline = m_data->curveFitter->fitCurve( polyline );
     566                QwtPainter::drawPolyline( painter, polyline );
    530567            }
    531568        }
    532569        else
    533570        {
    534             if ( d_data->paintAttributes & ClipPolygons )
    535             {
    536                 polyline = QwtClipper::clipPolygonF(
    537                     clipRect, polyline, false );
    538             }
    539 
    540571            QwtPainter::drawPolyline( painter, polyline );
    541572        }
    … …  
    544575
    545576/*!
    546   Draw sticks
    547 
    548   \param painter Painter
    549   \param xMap x map
    550   \param yMap y map
    551   \param canvasRect Contents rectangle of the canvas
    552   \param from index of the first point to be painted
    553   \param to index of the last point to be painted
    554 
    555   \sa draw(), drawCurve(), drawDots(), drawLines(), drawSteps()
    556 */
    557 void QwtPlotCurve::drawSticks( QPainter *painter,
    558     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    559     const QRectF &canvasRect, int from, int to ) const
     577   Draw sticks
     578
     579   \param painter Painter
     580   \param xMap x map
     581   \param yMap y map
     582   \param canvasRect Contents rectangle of the canvas
     583   \param from index of the first point to be painted
     584   \param to index of the last point to be painted
     585
     586   \sa draw(), drawCurve(), drawDots(), drawLines(), drawSteps()
     587 */
     588void QwtPlotCurve::drawSticks( QPainter* painter,
     589    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     590    const QRectF& canvasRect, int from, int to ) const
    560591{
    561592    Q_UNUSED( canvasRect )
    … …  
    566597    const bool doAlign = QwtPainter::roundingAlignment( painter );
    567598
    568     double x0 = xMap.transform( d_data->baseline );
    569     double y0 = yMap.transform( d_data->baseline );
     599    double x0 = xMap.transform( m_data->baseline );
     600    double y0 = yMap.transform( m_data->baseline );
    570601    if ( doAlign )
    571602    {
    … …  
    576607    const Qt::Orientation o = orientation();
    577608
    578     const QwtSeriesData<QPointF> *series = data();
     609    const QwtSeriesData< QPointF >* series = data();
    579610
    580611    for ( int i = from; i <= to; i++ )
    … …  
    599630
    600631/*!
    601   Draw dots
    602 
    603   \param painter Painter
    604   \param xMap x map
    605   \param yMap y map
    606   \param canvasRect Contents rectangle of the canvas
    607   \param from index of the first point to be painted
    608   \param to index of the last point to be painted
    609 
    610   \sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()
    611 */
    612 void QwtPlotCurve::drawDots( QPainter *painter,
    613     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    614     const QRectF &canvasRect, int from, int to ) const
     632   Draw dots
     633
     634   \param painter Painter
     635   \param xMap x map
     636   \param yMap y map
     637   \param canvasRect Contents rectangle of the canvas
     638   \param from index of the first point to be painted
     639   \param to index of the last point to be painted
     640
     641   \sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()
     642 */
     643void QwtPlotCurve::drawDots( QPainter* painter,
     644    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     645    const QRectF& canvasRect, int from, int to ) const
    615646{
    616647    const QColor color = painter->pen().color();
    … …  
    621652    }
    622653
    623     const bool doFill = ( d_data->brush.style() != Qt::NoBrush )
    624             && ( d_data->brush.color().alpha() > 0 );
     654    const bool doFill = ( m_data->brush.style() != Qt::NoBrush )
     655        && ( m_data->brush.color().alpha() > 0 );
    625656    const bool doAlign = QwtPainter::roundingAlignment( painter );
    626657
    … …  
    629660    mapper.setFlag( QwtPointMapper::RoundPoints, doAlign );
    630661
    631     if ( d_data->paintAttributes & FilterPoints )
     662    if ( m_data->paintAttributes & FilterPoints )
    632663    {
    633664        if ( ( color.alpha() == 255 )
    … …  
    642673        mapper.setFlag( QwtPointMapper::WeedOutPoints, false );
    643674
    644         QPolygonF points = mapper.toPointsF(
     675        QPolygonF points = mapper.toPolygonF(
    645676            xMap, yMap, data(), from, to );
    646677
    … …  
    648679        fillCurve( painter, xMap, yMap, canvasRect, points );
    649680    }
    650     else if ( d_data->paintAttributes & ImageBuffer )
     681    else if ( m_data->paintAttributes & ImageBuffer )
    651682    {
    652683        const QImage image = mapper.toImage( xMap, yMap,
    653             data(), from, to, d_data->pen,
     684            data(), from, to, m_data->pen,
    654685            painter->testRenderHint( QPainter::Antialiasing ),
    655686            renderThreadCount() );
    … …  
    657688        painter->drawImage( canvasRect.toAlignedRect(), image );
    658689    }
    659     else if ( d_data->paintAttributes & MinimizeMemory )
    660     {
    661         const QwtSeriesData<QPointF> *series = data();
     690    else if ( m_data->paintAttributes & MinimizeMemory )
     691    {
     692        const QwtSeriesData< QPointF >* series = data();
    662693
    663694        for ( int i = from; i <= to; i++ )
    … …  
    697728
    698729/*!
    699   Draw step function
    700 
    701   The direction of the steps depends on Inverted attribute.
    702 
    703   \param painter Painter
    704   \param xMap x map
    705   \param yMap y map
    706   \param canvasRect Contents rectangle of the canvas
    707   \param from index of the first point to be painted
    708   \param to index of the last point to be painted
    709 
    710   \sa CurveAttribute, setCurveAttribute(),
     730   Draw step function
     731
     732   The direction of the steps depends on Inverted attribute.
     733
     734   \param painter Painter
     735   \param xMap x map
     736   \param yMap y map
     737   \param canvasRect Contents rectangle of the canvas
     738   \param from index of the first point to be painted
     739   \param to index of the last point to be painted
     740
     741   \sa CurveAttribute, setCurveAttribute(),
    711742      draw(), drawCurve(), drawDots(), drawLines(), drawSticks()
    712 */
    713 void QwtPlotCurve::drawSteps( QPainter *painter,
    714     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    715     const QRectF &canvasRect, int from, int to ) const
     743 */
     744void QwtPlotCurve::drawSteps( QPainter* painter,
     745    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     746    const QRectF& canvasRect, int from, int to ) const
    716747{
    717748    const bool doAlign = QwtPainter::roundingAlignment( painter );
    718749
    719750    QPolygonF polygon( 2 * ( to - from ) + 1 );
    720     QPointF *points = polygon.data();
     751    QPointF* points = polygon.data();
    721752
    722753    bool inverted = orientation() == Qt::Vertical;
    723     if ( d_data->attributes & Inverted )
     754    if ( m_data->attributes & Inverted )
    724755        inverted = !inverted;
    725756
    726     const QwtSeriesData<QPointF> *series = data();
     757    const QwtSeriesData< QPointF >* series = data();
    727758
    728759    int i, ip;
    … …  
    740771        if ( ip > 0 )
    741772        {
    742             const QPointF &p0 = points[ip - 2];
    743             QPointF &p = points[ip - 1];
     773            const QPointF& p0 = points[ip - 2];
     774            QPointF& p = points[ip - 1];
    744775
    745776            if ( inverted )
    … …  
    759790    }
    760791
    761     if ( d_data->paintAttributes & ClipPolygons )
    762     {
    763         qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
    764         const QRectF clipRect = canvasRect.adjusted(-pw, -pw, pw, pw);
    765 
    766         const QPolygonF clipped = QwtClipper::clipPolygonF(
     792    if ( m_data->paintAttributes & ClipPolygons )
     793    {
     794        QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter );
     795
     796        const qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
     797        clipRect = clipRect.adjusted(-pw, -pw, pw, pw);
     798
     799        const QPolygonF clipped = QwtClipper::clippedPolygonF(
    767800            clipRect, polygon, false );
    768801
    … …  
    774807    }
    775808
    776     if ( d_data->brush.style() != Qt::NoBrush )
     809    if ( m_data->brush.style() != Qt::NoBrush )
    777810        fillCurve( painter, xMap, yMap, canvasRect, polygon );
    778811}
    … …  
    780813
    781814/*!
    782   Specify an attribute for drawing the curve
    783 
    784   \param attribute Curve attribute
    785   \param on On/Off
    786 
    787   /sa testCurveAttribute(), setCurveFitter()
    788 */
     815   Specify an attribute for drawing the curve
     816
     817   \param attribute Curve attribute
     818   \param on On/Off
     819
     820   /sa testCurveAttribute(), setCurveFitter()
     821 */
    789822void QwtPlotCurve::setCurveAttribute( CurveAttribute attribute, bool on )
    790823{
    791     if ( bool( d_data->attributes & attribute ) == on )
     824    if ( bool( m_data->attributes & attribute ) == on )
    792825        return;
    793826
    794827    if ( on )
    795         d_data->attributes |= attribute;
     828        m_data->attributes |= attribute;
    796829    else
    797         d_data->attributes &= ~attribute;
     830        m_data->attributes &= ~attribute;
    798831
    799832    itemChanged();
    … …  
    803836    \return true, if attribute is enabled
    804837    \sa setCurveAttribute()
    805 */
     838 */
    806839bool QwtPlotCurve::testCurveAttribute( CurveAttribute attribute ) const
    807840{
    808     return d_data->attributes & attribute;
    809 }
    810 
    811 /*!
    812   Assign a curve fitter
    813 
    814   The curve fitter "smooths" the curve points, when the Fitted
    815   CurveAttribute is set. setCurveFitter(NULL) also disables curve fitting.
    816 
    817   The curve fitter operates on the translated points ( = widget coordinates)
    818   to be functional for logarithmic scales. Obviously this is less performant
    819   for fitting algorithms, that reduce the number of points.
    820 
    821   For situations, where curve fitting is used to improve the performance
    822   of painting huge series of points it might be better to execute the fitter
    823   on the curve points once and to cache the result in the QwtSeriesData object.
    824 
    825   \param curveFitter() Curve fitter
    826   \sa Fitted
    827 */
    828 void QwtPlotCurve::setCurveFitter( QwtCurveFitter *curveFitter )
    829 {
    830     delete d_data->curveFitter;
    831     d_data->curveFitter = curveFitter;
     841    return m_data->attributes & attribute;
     842}
     843
     844/*!
     845   Assign a curve fitter
     846
     847   The curve fitter "smooths" the curve points, when the Fitted
     848   CurveAttribute is set. setCurveFitter(NULL) also disables curve fitting.
     849
     850   The curve fitter operates on the translated points ( = widget coordinates)
     851   to be functional for logarithmic scales. Obviously this is less performant
     852   for fitting algorithms, that reduce the number of points.
     853
     854   For situations, where curve fitting is used to improve the performance
     855   of painting huge series of points it might be better to execute the fitter
     856   on the curve points once and to cache the result in the QwtSeriesData object.
     857
     858   \param curveFitter() Curve fitter
     859   \sa Fitted
     860 */
     861void QwtPlotCurve::setCurveFitter( QwtCurveFitter* curveFitter )
     862{
     863    delete m_data->curveFitter;
     864    m_data->curveFitter = curveFitter;
    832865
    833866    itemChanged();
    … …  
    835868
    836869/*!
    837   Get the curve fitter. If curve fitting is disabled NULL is returned.
    838 
    839   \return Curve fitter
    840   \sa setCurveFitter(), Fitted
    841 */
    842 QwtCurveFitter *QwtPlotCurve::curveFitter() const
    843 {
    844     return d_data->curveFitter;
    845 }
    846 
    847 /*!
    848   Fill the area between the curve and the baseline with
    849   the curve brush
    850 
    851   \param painter Painter
    852   \param xMap x map
    853   \param yMap y map
    854   \param canvasRect Contents rectangle of the canvas
    855   \param polygon Polygon - will be modified !
    856 
    857   \sa setBrush(), setBaseline(), setStyle()
    858 */
    859 void QwtPlotCurve::fillCurve( QPainter *painter,
    860     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    861     const QRectF &canvasRect, QPolygonF &polygon ) const
    862 {
    863     if ( d_data->brush.style() == Qt::NoBrush )
     870   Get the curve fitter. If curve fitting is disabled NULL is returned.
     871
     872   \return Curve fitter
     873   \sa setCurveFitter(), Fitted
     874 */
     875QwtCurveFitter* QwtPlotCurve::curveFitter() const
     876{
     877    return m_data->curveFitter;
     878}
     879
     880/*!
     881   Fill the area between the curve and the baseline with
     882   the curve brush
     883
     884   \param painter Painter
     885   \param xMap x map
     886   \param yMap y map
     887   \param canvasRect Contents rectangle of the canvas
     888   \param polygon Polygon - will be modified !
     889
     890   \sa setBrush(), setBaseline(), setStyle()
     891 */
     892void QwtPlotCurve::fillCurve( QPainter* painter,
     893    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     894    const QRectF& canvasRect, QPolygonF& polygon ) const
     895{
     896    if ( m_data->brush.style() == Qt::NoBrush )
    864897        return;
    865898
    … …  
    868901        return;
    869902
    870     QBrush brush = d_data->brush;
     903    QBrush brush = m_data->brush;
    871904    if ( !brush.color().isValid() )
    872         brush.setColor( d_data->pen.color() );
    873 
    874     if ( d_data->paintAttributes & ClipPolygons )
    875         polygon = QwtClipper::clipPolygonF( canvasRect, polygon, true );
     905        brush.setColor( m_data->pen.color() );
     906
     907    if ( m_data->paintAttributes & ClipPolygons )
     908    {
     909        const QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter );
     910        QwtClipper::clipPolygonF( clipRect, polygon, true );
     911    }
    876912
    877913    painter->save();
    … …  
    886922
    887923/*!
    888   \brief Complete a polygon to be a closed polygon including the
     924   \brief Complete a polygon to be a closed polygon including the
    889925         area between the original polygon and the baseline.
    890926
    891   \param painter Painter
    892   \param xMap X map
    893   \param yMap Y map
    894   \param polygon Polygon to be completed
    895 */
    896 void QwtPlotCurve::closePolyline( QPainter *painter,
    897     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    898     QPolygonF &polygon ) const
     927   \param painter Painter
     928   \param xMap X map
     929   \param yMap Y map
     930   \param polygon Polygon to be completed
     931 */
     932void QwtPlotCurve::closePolyline( QPainter* painter,
     933    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     934    QPolygonF& polygon ) const
    899935{
    900936    if ( polygon.size() < 2 )
    … …  
    903939    const bool doAlign = QwtPainter::roundingAlignment( painter );
    904940
    905     double baseline = d_data->baseline;
     941    double baseline = m_data->baseline;
    906942
    907943    if ( orientation() == Qt::Vertical )
    … …  
    911947
    912948        double refY = yMap.transform( baseline );
    913         if ( doAlign )
     949        if ( doAlign && qAbs( refY ) < std::numeric_limits< int >::max() )
    914950            refY = qRound( refY );
    915951
    … …  
    923959
    924960        double refX = xMap.transform( baseline );
    925         if ( doAlign )
     961        if ( doAlign && qAbs( refX ) < std::numeric_limits< int >::max() )
    926962            refX = qRound( refX );
    927963
    … …  
    932968
    933969/*!
    934   Draw symbols
    935 
    936   \param painter Painter
    937   \param symbol Curve symbol
    938   \param xMap x map
    939   \param yMap y map
    940   \param canvasRect Contents rectangle of the canvas
    941   \param from Index of the first point to be painted
    942   \param to Index of the last point to be painted
    943 
    944   \sa setSymbol(), drawSeries(), drawCurve()
    945 */
    946 void QwtPlotCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
    947     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    948     const QRectF &canvasRect, int from, int to ) const
     970   Draw symbols
     971
     972   \param painter Painter
     973   \param symbol Curve symbol
     974   \param xMap x map
     975   \param yMap y map
     976   \param canvasRect Contents rectangle of the canvas
     977   \param from Index of the first point to be painted
     978   \param to Index of the last point to be painted
     979
     980   \sa setSymbol(), drawSeries(), drawCurve()
     981 */
     982void QwtPlotCurve::drawSymbols( QPainter* painter, const QwtSymbol& symbol,
     983    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     984    const QRectF& canvasRect, int from, int to ) const
    949985{
    950986    QwtPointMapper mapper;
    … …  
    953989    mapper.setFlag( QwtPointMapper::WeedOutPoints,
    954990        testPaintAttribute( QwtPlotCurve::FilterPoints ) );
    955     mapper.setBoundingRect( canvasRect );
     991
     992    const QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter );
     993    mapper.setBoundingRect( clipRect );
    956994
    957995    const int chunkSize = 500;
    … …  
    9701008
    9711009/*!
    972   \brief Set the value of the baseline
    973 
    974   The baseline is needed for filling the curve with a brush or
    975   the Sticks drawing style.
    976 
    977   The interpretation of the baseline depends on the orientation().
    978   With Qt::Vertical, the baseline is interpreted as a horizontal line
    979   at y = baseline(), with Qt::Horizontal, it is interpreted as a vertical
    980   line at x = baseline().
    981 
    982   The default value is 0.0.
    983 
    984   \param value Value of the baseline
    985   \sa baseline(), setBrush(), setStyle(), QwtPlotAbstractSeriesItem::orientation()
    986 */
     1010   \brief Set the value of the baseline
     1011
     1012   The baseline is needed for filling the curve with a brush or
     1013   the Sticks drawing style.
     1014
     1015   The interpretation of the baseline depends on the orientation().
     1016   With Qt::Vertical, the baseline is interpreted as a horizontal line
     1017   at y = baseline(), with Qt::Horizontal, it is interpreted as a vertical
     1018   line at x = baseline().
     1019
     1020   The default value is 0.0.
     1021
     1022   \param value Value of the baseline
     1023   \sa baseline(), setBrush(), setStyle(), QwtPlotAbstractSeriesItem::orientation()
     1024 */
    9871025void QwtPlotCurve::setBaseline( double value )
    9881026{
    989     if ( d_data->baseline != value )
    990     {
    991         d_data->baseline = value;
     1027    if ( m_data->baseline != value )
     1028    {
     1029        m_data->baseline = value;
    9921030        itemChanged();
    9931031    }
    … …  
    9951033
    9961034/*!
    997   \return Value of the baseline
    998   \sa setBaseline()
    999 */
     1035   \return Value of the baseline
     1036   \sa setBaseline()
     1037 */
    10001038double QwtPlotCurve::baseline() const
    10011039{
    1002     return d_data->baseline;
    1003 }
    1004 
    1005 /*!
    1006   Find the closest curve point for a specific position
    1007 
    1008   \param pos Position, where to look for the closest curve point
    1009   \param dist If dist != NULL, closestPoint() returns the distance between
    1010               the position and the closest curve point
    1011   \return Index of the closest curve point, or -1 if none can be found
     1040    return m_data->baseline;
     1041}
     1042
     1043/*!
     1044   Find the closest curve point for a specific position
     1045
     1046   \param pos Position, where to look for the closest curve point
     1047   \param dist If dist != NULL, closestPoint() returns the distance between
     1048              the position and the closest curve point in paint device coordinates
     1049   \return Index of the closest curve point, or -1 if none can be found
    10121050          ( f.e when the curve has no points )
    1013   \note closestPoint() implements a dumb algorithm, that iterates
     1051   \note closestPoint() implements a dumb algorithm, that iterates
    10141052        over all points
    1015 */
    1016 int QwtPlotCurve::closestPoint( const QPoint &pos, double *dist ) const
    1017 {
     1053 */
     1054int QwtPlotCurve::closestPoint( const QPointF& pos, double* dist ) const
     1055{
     1056    const QwtPlot* plot = this->plot();
     1057
     1058    if ( ( plot == NULL ) || !plot->isAxisValid( xAxis() ) || !plot->isAxisValid( yAxis() ) )
     1059        return -1;
     1060
    10181061    const size_t numSamples = dataSize();
    1019 
    1020     if ( plot() == NULL || numSamples <= 0 )
     1062    if ( numSamples <= 0 )
    10211063        return -1;
    10221064
    1023     const QwtSeriesData<QPointF> *series = data();
    1024 
    1025     const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
    1026     const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
     1065    const QwtSeriesData< QPointF >* series = data();
     1066
     1067    const QwtScaleMap xMap = plot->canvasMap( xAxis() );
     1068    const QwtScaleMap yMap = plot->canvasMap( yAxis() );
    10271069
    10281070    int index = -1;
    … …  
    10441086    }
    10451087    if ( dist )
    1046         *dist = qSqrt( dmin );
     1088        *dist = std::sqrt( dmin );
    10471089
    10481090    return index;
     1091}
     1092
     1093/*!
     1094   Find the curve point with the smallest coordinate larger than a specific value
     1095   The coordinates have to be monotonic in direction of the orientation.
     1096   
     1097   \param orientation Qt::Horizontal corresponds to x, Qt::Vertical to y coordinates
     1098   \param value x or y coordinate, depending on the orientation
     1099
     1100   \return Index of the curve point with the smalles coordinate above value
     1101           or -1 if there is none.
     1102
     1103   \note The implementation uses a binary search algorithm and requires the
     1104         points being ordered in direction of the orientation.
     1105
     1106   \sa qwtUpperSampleIndex()
     1107 */
     1108int QwtPlotCurve::adjacentPoint( Qt::Orientation orientation, qreal value ) const
     1109{
     1110    const QwtSeriesData< QPointF >* data = this->data();
     1111    if ( data == NULL )
     1112        return -1;
     1113
     1114    if ( orientation == Qt::Horizontal )
     1115    {
     1116        struct compareX
     1117        {
     1118            inline bool operator()( const double x, const QPointF& pos ) const
     1119            {
     1120                return ( x < pos.x() );
     1121            }
     1122        };
     1123
     1124        return qwtUpperSampleIndex< QPointF >( *data, value, compareX() );
     1125    }
     1126    else
     1127    {
     1128        struct compareY
     1129        {
     1130            inline bool operator()( const double y, const QPointF& pos ) const
     1131            {
     1132                return ( y < pos.y() );
     1133            }
     1134        };
     1135
     1136        return qwtUpperSampleIndex< QPointF >( *data, value, compareY() );
     1137    }
     1138
     1139    return -1;
     1140}
     1141
     1142/*!
     1143   Calculate a fictive curve point by interpolating between the adjacent
     1144   points. The curve points have to be monotonic in direction of the orientation.
     1145   
     1146   \param orientation For Qt::Horizontal value is a x coordinate and a y coordinate
     1147                      is returned. For Qt::Vertical value is a x coordinate
     1148   \param value x or y coordinate, depending on the orientation
     1149
     1150   \return Interpolated coordinate or qQNaN() if value is outside the bounding
     1151           rectangle of the curve
     1152
     1153   \note The implementation uses a binary search algorithm and requires the
     1154         points being ordered in direction of the orientation.
     1155
     1156   \sa adjacentPoint()
     1157 */
     1158qreal QwtPlotCurve::interpolatedValueAt( Qt::Orientation orientation, double value ) const
     1159{
     1160    const QRectF br = boundingRect();
     1161    if ( br.width() <= 0.0 )
     1162        return qQNaN();
     1163
     1164    double v;
     1165
     1166    if ( orientation == Qt::Horizontal )
     1167    {
     1168        if ( value < br.left() || value > br.right() )
     1169            return qQNaN();
     1170
     1171        const int index = adjacentPoint( orientation, value );
     1172
     1173        if ( index == -1 )
     1174        {
     1175            const QPointF last = sample( dataSize() - 1 );
     1176
     1177            if ( value != last.x() )
     1178                return qQNaN();
     1179
     1180            v = last.y();
     1181        }
     1182        else
     1183        {
     1184            const QLineF line( sample( index - 1 ), sample( index ) );
     1185            v = line.pointAt( ( value - line.p1().x() ) / line.dx() ).y();
     1186        }
     1187    }
     1188    else
     1189    {
     1190        if ( value < br.top() || value > br.bottom() )
     1191            return qQNaN();
     1192
     1193        const int index = adjacentPoint( orientation, value );
     1194
     1195        if ( index == -1 )
     1196        {
     1197            const QPointF last = sample( dataSize() - 1 );
     1198
     1199            if ( value != last.y() )
     1200                return qQNaN();
     1201
     1202            v = last.x();
     1203        }
     1204        else
     1205        {
     1206            const QLineF line( sample( index - 1 ), sample( index ) );
     1207            v = line.pointAt( ( value - line.p1().y() ) / line.dy() ).x();
     1208        }
     1209    }
     1210
     1211    return v;
    10491212}
    10501213
    … …  
    10581221   \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
    10591222 */
    1060 QwtGraphic QwtPlotCurve::legendIcon( int index,
    1061     const QSizeF &size ) const
     1223QwtGraphic QwtPlotCurve::legendIcon( int index, const QSizeF& size ) const
    10621224{
    10631225    Q_UNUSED( index );
    … …  
    10741236        testRenderHint( QwtPlotItem::RenderAntialiased ) );
    10751237
    1076     if ( d_data->legendAttributes == 0 ||
    1077         d_data->legendAttributes & QwtPlotCurve::LegendShowBrush )
    1078     {
    1079         QBrush brush = d_data->brush;
     1238    if ( m_data->legendAttributes == 0 ||
     1239        m_data->legendAttributes & QwtPlotCurve::LegendShowBrush )
     1240    {
     1241        QBrush brush = m_data->brush;
    10801242
    10811243        if ( brush.style() == Qt::NoBrush &&
    1082             d_data->legendAttributes == 0 )
     1244            m_data->legendAttributes == 0 )
    10831245        {
    10841246            if ( style() != QwtPlotCurve::NoCurve )
    … …  
    10861248                brush = QBrush( pen().color() );
    10871249            }
    1088             else if ( d_data->symbol &&
    1089                 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
     1250            else if ( m_data->symbol &&
     1251                ( m_data->symbol->style() != QwtSymbol::NoSymbol ) )
    10901252            {
    1091                 brush = QBrush( d_data->symbol->pen().color() );
     1253                brush = QBrush( m_data->symbol->pen().color() );
    10921254            }
    10931255        }
    … …  
    11001262    }
    11011263
    1102     if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine )
     1264    if ( m_data->legendAttributes & QwtPlotCurve::LegendShowLine )
    11031265    {
    11041266        if ( pen() != Qt::NoPen )
    … …  
    11141276    }
    11151277
    1116     if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
    1117     {
    1118         if ( d_data->symbol )
     1278    if ( m_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
     1279    {
     1280        if ( m_data->symbol )
    11191281        {
    11201282            QRectF r( 0, 0, size.width(), size.height() );
    1121             d_data->symbol->drawSymbol( &painter, r );
     1283            m_data->symbol->drawSymbol( &painter, r );
    11221284        }
    11231285    }
    … …  
    11271289
    11281290/*!
    1129   Initialize data with an array of points.
    1130 
    1131   \param samples Vector of points
    1132   \note QVector is implicitly shared
    1133   \note QPolygonF is derived from QVector<QPointF>
    1134 */
    1135 void QwtPlotCurve::setSamples( const QVector<QPointF> &samples )
     1291   Assign a series of points
     1292
     1293   setSamples() is just a wrapper for setData() without any additional
     1294   value - beside that it is easier to find for the developer.
     1295
     1296   \param data Data
     1297   \warning The item takes ownership of the data object, deleting
     1298           it when its not used anymore.
     1299 */
     1300void QwtPlotCurve::setSamples( QwtSeriesData< QPointF >* data )
     1301{
     1302    setData( data );
     1303}
     1304
     1305/*!
     1306   Initialize data with an array of points.
     1307
     1308   \param samples Vector of points
     1309   \note QVector is implicitly shared
     1310   \note QPolygonF is derived from QVector<QPointF>
     1311 */
     1312void QwtPlotCurve::setSamples( const QVector< QPointF >& samples )
    11361313{
    11371314    setData( new QwtPointSeriesData( samples ) );
    … …  
    11391316
    11401317/*!
    1141   Assign a series of points
    1142 
    1143   setSamples() is just a wrapper for setData() without any additional
    1144   value - beside that it is easier to find for the developer.
    1145 
    1146   \param data Data
    1147   \warning The item takes ownership of the data object, deleting
    1148            it when its not used anymore.
    1149 */
    1150 void QwtPlotCurve::setSamples( QwtSeriesData<QPointF> *data )
    1151 {
    1152     setData( data );
    1153 }
    1154 
    1155 #ifndef QWT_NO_COMPAT
    1156 
    1157 /*!
    1158   \brief Initialize the data by pointing to memory blocks which
     1318   \brief Initialize the data by pointing to memory blocks which
    11591319         are not managed by QwtPlotCurve.
    11601320
    1161   setRawSamples is provided for efficiency.
    1162   It is important to keep the pointers
    1163   during the lifetime of the underlying QwtCPointerData class.
    1164 
    1165   \param xData pointer to x data
    1166   \param yData pointer to y data
    1167   \param size size of x and y
    1168 
    1169   \sa QwtCPointerData
    1170 */
     1321   setRawSamples is provided for efficiency.
     1322   It is important to keep the pointers
     1323   during the lifetime of the underlying QwtCPointerData class.
     1324
     1325   \param xData pointer to x data
     1326   \param yData pointer to y data
     1327   \param size size of x and y
     1328
     1329   \sa QwtCPointerData
     1330 */
    11711331void QwtPlotCurve::setRawSamples(
    1172     const double *xData, const double *yData, int size )
    1173 {
    1174     setData( new QwtCPointerData( xData, yData, size ) );
    1175 }
    1176 
    1177 /*!
    1178   Set data by copying x- and y-values from specified memory blocks.
    1179   Contrary to setRawSamples(), this function makes a 'deep copy' of
    1180   the data.
    1181 
    1182   \param xData pointer to x values
    1183   \param yData pointer to y values
    1184   \param size size of xData and yData
    1185 
    1186   \sa QwtPointArrayData
    1187 */
     1332    const double* xData, const double* yData, int size )
     1333{
     1334    setData( new QwtCPointerData< double >( xData, yData, size ) );
     1335}
     1336
     1337/*!
     1338   \brief Initialize the data by pointing to memory blocks which
     1339         are not managed by QwtPlotCurve.
     1340
     1341   setRawSamples is provided for efficiency.
     1342   It is important to keep the pointers
     1343   during the lifetime of the underlying QwtCPointerData class.
     1344
     1345   \param xData pointer to x data
     1346   \param yData pointer to y data
     1347   \param size size of x and y
     1348
     1349   \sa QwtCPointerData
     1350 */
     1351void QwtPlotCurve::setRawSamples(
     1352    const float* xData, const float* yData, int size )
     1353{
     1354    setData( new QwtCPointerData< float >( xData, yData, size ) );
     1355}
     1356
     1357/*!
     1358   \brief Initialize the data by pointing to a memory block which
     1359         is not managed by QwtPlotCurve.
     1360
     1361   The memory contains the y coordinates, while the index is
     1362   interpreted as x coordinate.
     1363
     1364   setRawSamples() is provided for efficiency. It is important to
     1365   keep the pointers during the lifetime of the underlying
     1366   QwtCPointerValueData class.
     1367
     1368   \param yData pointer to y data
     1369   \param size size of x and y
     1370
     1371   \sa QwtCPointerData
     1372 */
     1373void QwtPlotCurve::setRawSamples( const double* yData, int size )
     1374{
     1375    setData( new QwtCPointerValueData< double >( yData, size ) );
     1376}
     1377
     1378/*!
     1379   \brief Initialize the data by pointing to memory blocks which
     1380         are not managed by QwtPlotCurve.
     1381
     1382   The memory contains the y coordinates, while the index is
     1383   interpreted as x coordinate.
     1384
     1385   setRawSamples() is provided for efficiency. It is important to
     1386   keep the pointers during the lifetime of the underlying
     1387   QwtCPointerValueData class.
     1388
     1389   \param yData pointer to y data
     1390   \param size size of x and y
     1391
     1392   \sa QwtCPointerData
     1393 */
     1394void QwtPlotCurve::setRawSamples( const float* yData, int size )
     1395{
     1396    setData( new QwtCPointerValueData< float >( yData, size ) );
     1397}
     1398
     1399/*!
     1400   Set data by copying x- and y-values from specified memory blocks.
     1401   Contrary to setRawSamples(), this function makes a 'deep copy' of
     1402   the data.
     1403
     1404   \param xData pointer to x values
     1405   \param yData pointer to y values
     1406   \param size size of xData and yData
     1407
     1408   \sa QwtPointArrayData
     1409 */
    11881410void QwtPlotCurve::setSamples(
    1189     const double *xData, const double *yData, int size )
    1190 {
    1191     setData( new QwtPointArrayData( xData, yData, size ) );
    1192 }
    1193 
    1194 /*!
    1195   \brief Initialize data with x- and y-arrays (explicitly shared)
    1196 
    1197   \param xData x data
    1198   \param yData y data
    1199 
    1200   \sa QwtPointArrayData
    1201 */
    1202 void QwtPlotCurve::setSamples( const QVector<double> &xData,
    1203     const QVector<double> &yData )
    1204 {
    1205     setData( new QwtPointArrayData( xData, yData ) );
    1206 }
    1207 
    1208 #endif // !QWT_NO_COMPAT
    1209 
     1411    const double* xData, const double* yData, int size )
     1412{
     1413    setData( new QwtPointArrayData< double >( xData, yData, size ) );
     1414}
     1415
     1416/*!
     1417   Set data by copying x- and y-values from specified memory blocks.
     1418   Contrary to setRawSamples(), this function makes a 'deep copy' of
     1419   the data.
     1420
     1421   \param xData pointer to x values
     1422   \param yData pointer to y values
     1423   \param size size of xData and yData
     1424
     1425   \sa QwtPointArrayData
     1426 */
     1427void QwtPlotCurve::setSamples(
     1428    const float* xData, const float* yData, int size )
     1429{
     1430    setData( new QwtPointArrayData< float >( xData, yData, size ) );
     1431}
     1432
     1433/*!
     1434   \brief Initialize data with x- and y-arrays (explicitly shared)
     1435
     1436   \param xData x data
     1437   \param yData y data
     1438
     1439   \sa QwtPointArrayData
     1440 */
     1441void QwtPlotCurve::setSamples( const QVector< double >& xData,
     1442    const QVector< double >& yData )
     1443{
     1444    setData( new QwtPointArrayData< double >( xData, yData ) );
     1445}
     1446
     1447/*!
     1448   \brief Initialize data with x- and y-arrays (explicitly shared)
     1449
     1450   \param xData x data
     1451   \param yData y data
     1452
     1453   \sa QwtPointArrayData
     1454 */
     1455void QwtPlotCurve::setSamples( const QVector< float >& xData,
     1456    const QVector< float >& yData )
     1457{
     1458    setData( new QwtPointArrayData< float >( xData, yData ) );
     1459}
     1460
     1461/*!
     1462   Set data by copying y-values from a specified memory block.
     1463
     1464   The memory contains the y coordinates, while the index is
     1465   interpreted as x coordinate.
     1466
     1467   \param yData y data
     1468   \param size size of yData
     1469
     1470   \sa QwtValuePointData
     1471 */
     1472void QwtPlotCurve::setSamples( const double* yData, int size )
     1473{
     1474    setData( new QwtValuePointData< double >( yData, size ) );
     1475}
     1476
     1477/*!
     1478   Set data by copying y-values from a specified memory block.
     1479
     1480   The vector contains the y coordinates, while the index is
     1481   interpreted as x coordinate.
     1482
     1483   \param yData y data
     1484   \param size size of yData
     1485
     1486   \sa QwtValuePointData
     1487 */
     1488void QwtPlotCurve::setSamples( const float* yData, int size )
     1489{
     1490    setData( new QwtValuePointData< float >( yData, size ) );
     1491}
     1492
     1493/*!
     1494   Initialize data with an array of y values (explicitly shared)
     1495
     1496   The vector contains the y coordinates, while the index is
     1497   the x coordinate.
     1498
     1499   \param yData y data
     1500
     1501   \sa QwtValuePointData
     1502 */
     1503void QwtPlotCurve::setSamples( const QVector< double >& yData )
     1504{
     1505    setData( new QwtValuePointData< double >( yData ) );
     1506}
     1507
     1508/*!
     1509   Initialize data with an array of y values (explicitly shared)
     1510
     1511   The vector contains the y coordinates, while the index is
     1512   the x coordinate.
     1513
     1514   \param yData y data
     1515
     1516   \sa QwtValuePointData
     1517 */
     1518void QwtPlotCurve::setSamples( const QVector< float >& yData )
     1519{
     1520    setData( new QwtValuePointData< float >( yData ) );
     1521}
  • trunk/BNC/qwt/qwt_plot_curve.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_seriesitem.h"
    15 #include "qwt_series_data.h"
    16 #include "qwt_text.h"
    17 #include <qpen.h>
     15
    1816#include <qstring.h>
    1917
    20 class QPainter;
    21 class QPolygonF;
    2218class QwtScaleMap;
    2319class QwtSymbol;
    2420class QwtCurveFitter;
     21template< typename T > class QwtSeriesData;
     22class QwtText;
     23class QPainter;
     24class QPolygonF;
     25class QPen;
    2526
    2627/*!
    27   \brief A plot item, that represents a series of points
    28 
    29   A curve is the representation of a series of points in the x-y plane.
    30   It supports different display styles, interpolation ( f.e. spline )
    31   and symbols.
    32 
    33   \par Usage
    34   <dl><dt>a) Assign curve properties</dt>
    35   <dd>When a curve is created, it is configured to draw black solid lines
    36   with in QwtPlotCurve::Lines style and no symbols.
    37   You can change this by calling
    38   setPen(), setStyle() and setSymbol().</dd>
    39   <dt>b) Connect/Assign data.</dt>
    40   <dd>QwtPlotCurve gets its points using a QwtSeriesData object offering
    41   a bridge to the real storage of the points ( like QAbstractItemModel ).
    42   There are several convenience classes derived from QwtSeriesData, that also store
    43   the points inside ( like QStandardItemModel ). QwtPlotCurve also offers
    44   a couple of variations of setSamples(), that build QwtSeriesData objects from
    45   arrays internally.</dd>
    46   <dt>c) Attach the curve to a plot</dt>
    47   <dd>See QwtPlotItem::attach()
    48   </dd></dl>
    49 
    50   \par Example:
    51   see examples/bode
    52 
    53   \sa QwtPointSeriesData, QwtSymbol, QwtScaleMap
    54 */
    55 class QWT_EXPORT QwtPlotCurve:
    56     public QwtPlotSeriesItem, public QwtSeriesStore<QPointF>
    57 {
    58 public:
     28   \brief A plot item, that represents a series of points
     29
     30   A curve is the representation of a series of points in the x-y plane.
     31   It supports different display styles, interpolation ( f.e. spline )
     32   and symbols.
     33
     34   \par Usage
     35   <dl><dt>a) Assign curve properties</dt>
     36   <dd>When a curve is created, it is configured to draw black solid lines
     37   with in QwtPlotCurve::Lines style and no symbols.
     38   You can change this by calling
     39   setPen(), setStyle() and setSymbol().</dd>
     40   <dt>b) Connect/Assign data.</dt>
     41   <dd>QwtPlotCurve gets its points using a QwtSeriesData object offering
     42   a bridge to the real storage of the points ( like QAbstractItemModel ).
     43   There are several convenience classes derived from QwtSeriesData, that also store
     44   the points inside ( like QStandardItemModel ). QwtPlotCurve also offers
     45   a couple of variations of setSamples(), that build QwtSeriesData objects from
     46   arrays internally.</dd>
     47   <dt>c) Attach the curve to a plot</dt>
     48   <dd>See QwtPlotItem::attach()
     49   </dd></dl>
     50
     51   \par Example:
     52   see examples/bode
     53
     54   \sa QwtPointSeriesData, QwtSymbol, QwtScaleMap
     55 */
     56class QWT_EXPORT QwtPlotCurve
     57    : public QwtPlotSeriesItem
     58    , public QwtSeriesStore< QPointF >
     59{
     60  public:
    5961    /*!
    6062        Curve styles.
    6163        \sa setStyle(), style()
    62     */
     64     */
    6365    enum CurveStyle
    6466    {
    6567        /*!
    6668           Don't draw a curve. Note: This doesn't affect the symbols.
    67         */
     69         */
    6870        NoCurve = -1,
    6971
    … …  
    7274           be interpolated depending on the 'Fitted' attribute. Curve
    7375           fitting can be configured using setCurveFitter().
    74         */
     76         */
    7577        Lines,
    7678
    … …  
    7880           Draw vertical or horizontal sticks ( depending on the
    7981           orientation() ) from a baseline which is defined by setBaseline().
    80         */
     82         */
    8183        Sticks,
    8284
    … …  
    8587           is drawn from the left to the right or vice versa,
    8688           depending on the QwtPlotCurve::Inverted attribute.
    87         */
     89         */
    8890        Steps,
    8991
    … …  
    9395           as a curve in QwtPlotCurve::NoStyle style and a symbol
    9496           painting a point.
    95         */
     97         */
    9698        Dots,
    9799
    … …  
    100102           classes of QwtPlotCurve that overload drawCurve() with
    101103           additional application specific curve types.
    102         */
     104         */
    103105        UserCurve = 100
    104106    };
    105107
    106108    /*!
    107       Attribute for drawing the curve
    108       \sa setCurveAttribute(), testCurveAttribute(), curveFitter()
    109     */
     109       Attribute for drawing the curve
     110       \sa setCurveAttribute(), testCurveAttribute(), curveFitter()
     111     */
    110112    enum CurveAttribute
    111113    {
    … …  
    117119
    118120        /*!
    119           Only in combination with QwtPlotCurve::Lines
    120           A QwtCurveFitter tries to
    121           interpolate/smooth the curve, before it is painted.
    122 
    123           \note Curve fitting requires temporary memory
    124           for calculating coefficients and additional points.
    125           If painting in QwtPlotCurve::Fitted mode is slow it might be better
    126           to fit the points, before they are passed to QwtPlotCurve.
     121           Only in combination with QwtPlotCurve::Lines
     122           A QwtCurveFitter tries to
     123           interpolate/smooth the curve, before it is painted.
     124
     125           \note Curve fitting requires temporary memory
     126           for calculating coefficients and additional points.
     127           If painting in QwtPlotCurve::Fitted mode is slow it might be better
     128           to fit the points, before they are passed to QwtPlotCurve.
    127129         */
    128130        Fitted = 0x02
    129131    };
    130132
    131     //! Curve attributes
    132     typedef QFlags<CurveAttribute> CurveAttributes;
     133    Q_DECLARE_FLAGS( CurveAttributes, CurveAttribute )
    133134
    134135    /*!
    … …  
    142143    {
    143144        /*!
    144           QwtPlotCurve tries to find a color representing the curve
    145           and paints a rectangle with it.
     145           QwtPlotCurve tries to find a color representing the curve
     146           and paints a rectangle with it.
    146147         */
    147148        LegendNoAttribute = 0x00,
    148149
    149150        /*!
    150           If the style() is not QwtPlotCurve::NoCurve a line
    151           is painted with the curve pen().
     151           If the style() is not QwtPlotCurve::NoCurve a line
     152           is painted with the curve pen().
    152153         */
    153154        LegendShowLine = 0x01,
    154155
    155156        /*!
    156           If the curve has a valid symbol it is painted.
     157           If the curve has a valid symbol it is painted.
    157158         */
    158159        LegendShowSymbol = 0x02,
    159160
    160161        /*!
    161           If the curve has a brush a rectangle filled with the
    162           curve brush() is painted.
     162           If the curve has a brush a rectangle filled with the
     163           curve brush() is painted.
    163164         */
    164165        LegendShowBrush = 0x04
    165166    };
    166167
    167     //! Legend attributes
    168     typedef QFlags<LegendAttribute> LegendAttributes;
     168    Q_DECLARE_FLAGS( LegendAttributes, LegendAttribute )
    169169
    170170    /*!
    … …  
    173173
    174174        \sa setPaintAttribute(), testPaintAttribute()
    175     */
     175     */
    176176    enum PaintAttribute
    177177    {
    178178        /*!
    179           Clip polygons before painting them. In situations, where points
    180           are far outside the visible area (f.e when zooming deep) this
    181           might be a substantial improvement for the painting performance
     179           Clip polygons before painting them. In situations, where points
     180           are far outside the visible area (f.e when zooming deep) this
     181           might be a substantial improvement for the painting performance
    182182         */
    183183        ClipPolygons = 0x01,
    184184
    185185        /*!
    186           Tries to reduce the data that has to be painted, by sorting out
    187           duplicates, or paintings outside the visible area. Might have a
    188           notable impact on curves with many close points.
    189           Only a couple of very basic filtering algorithms are implemented.
     186           Tries to reduce the data that has to be painted, by sorting out
     187           duplicates, or paintings outside the visible area. Might have a
     188           notable impact on curves with many close points.
     189           Only a couple of very basic filtering algorithms are implemented.
    190190         */
    191191        FilterPoints = 0x02,
    192192
    193193        /*!
    194           Minimize memory usage that is temporarily needed for the
    195           translated points, before they get painted.
    196           This might slow down the performance of painting
     194           Minimize memory usage that is temporarily needed for the
     195           translated points, before they get painted.
     196           This might slow down the performance of painting
    197197         */
    198198        MinimizeMemory = 0x04,
    199199
    200200        /*!
    201           Render the points to a temporary image and paint the image.
    202           This is a very special optimization for Dots style, when
    203           having a huge amount of points.
    204           With a reasonable number of points QPainter::drawPoints()
    205           will be faster.
    206          */
    207         ImageBuffer = 0x08
     201           Render the points to a temporary image and paint the image.
     202           This is a very special optimization for Dots style, when
     203           having a huge amount of points.
     204           With a reasonable number of points QPainter::drawPoints()
     205           will be faster.
     206         */
     207        ImageBuffer = 0x08,
     208
     209        /*!
     210           More aggressive point filtering trying to filter out
     211           intermediate points, accepting minor visual differences.
     212
     213           Has only an effect, when drawing the curve to a paint device
     214           in integer coordinates ( f.e. all widgets on screen ) using the fact,
     215           that consecutive points are often mapped to the same x or y coordinate.
     216           Each chunk of samples mapped to the same coordinate can be reduced to
     217           4 points ( first, min, max last ).
     218
     219           In the worst case the polygon to be rendered will be 4 times the width
     220           of the plot canvas.
     221
     222           The algorithm is very fast and effective for huge datasets, and can be used
     223           inside a replot cycle.
     224
     225           \note Implemented for QwtPlotCurve::Lines only
     226           \note As this algo replaces many small lines by a long one
     227                a nasty bug of the raster paint engine ( Qt 4.8, Qt 5.1 - 5.3 )
     228                becomes more dominant. For these versions the bug can be
     229                worked around by enabling the QwtPainter::polylineSplitting() mode.
     230         */
     231        FilterPointsAggressive = 0x10,
    208232    };
    209233
    210     //! Paint attributes
    211     typedef QFlags<PaintAttribute> PaintAttributes;
    212 
    213     explicit QwtPlotCurve( const QString &title = QString() );
    214     explicit QwtPlotCurve( const QwtText &title );
     234    Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute )
     235
     236    explicit QwtPlotCurve( const QString& title = QString() );
     237    explicit QwtPlotCurve( const QwtText& title );
    215238
    216239    virtual ~QwtPlotCurve();
    217240
    218     virtual int rtti() const;
     241    virtual int rtti() const QWT_OVERRIDE;
    219242
    220243    void setPaintAttribute( PaintAttribute, bool on = true );
    … …  
    224247    bool testLegendAttribute( LegendAttribute ) const;
    225248
    226 #ifndef QWT_NO_COMPAT
    227     void setRawSamples( const double *xData, const double *yData, int size );
    228     void setSamples( const double *xData, const double *yData, int size );
    229     void setSamples( const QVector<double> &xData, const QVector<double> &yData );
    230 #endif
    231     void setSamples( const QVector<QPointF> & );
    232     void setSamples( QwtSeriesData<QPointF> * );
    233 
    234     int closestPoint( const QPoint &pos, double *dist = NULL ) const;
     249    void setLegendAttributes( LegendAttributes );
     250    LegendAttributes legendAttributes() const;
     251
     252    void setRawSamples( const double* xData, const double* yData, int size );
     253    void setRawSamples( const float* xData, const float* yData, int size );
     254
     255    void setRawSamples( const double* yData, int size );
     256    void setRawSamples( const float* yData, int size );
     257
     258    void setSamples( const double* xData, const double* yData, int size );
     259    void setSamples( const float* xData, const float* yData, int size );
     260
     261    void setSamples( const double* yData, int size );
     262    void setSamples( const float* yData, int size );
     263
     264    void setSamples( const QVector< double >& yData );
     265    void setSamples( const QVector< float >& yData );
     266
     267    void setSamples( const QVector< double >& xData, const QVector< double >& yData );
     268    void setSamples( const QVector< float >& xData, const QVector< float >& yData );
     269
     270    void setSamples( const QVector< QPointF >& );
     271    void setSamples( QwtSeriesData< QPointF >* );
     272
     273    virtual int closestPoint( const QPointF& pos, double* dist = NULL ) const;
     274    virtual int adjacentPoint( Qt::Orientation orientation, qreal value ) const;
     275
     276    qreal interpolatedValueAt( Qt::Orientation, double ) const;
    235277
    236278    double minXValue() const;
    … …  
    242284    bool testCurveAttribute( CurveAttribute ) const;
    243285
    244     void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    245     void setPen( const QPen & );
    246     const QPen &pen() const;
    247 
    248     void setBrush( const QBrush & );
    249     const QBrush &brush() const;
     286    void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
     287    void setPen( const QPen& );
     288    const QPen& pen() const;
     289
     290    void setBrush( const QBrush& );
     291    const QBrush& brush() const;
    250292
    251293    void setBaseline( double );
    … …  
    255297    CurveStyle style() const;
    256298
    257     void setSymbol( QwtSymbol * );
    258     const QwtSymbol *symbol() const;
    259 
    260     void setCurveFitter( QwtCurveFitter * );
    261     QwtCurveFitter *curveFitter() const;
    262 
    263     virtual void drawSeries( QPainter *,
    264         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    265         const QRectF &canvasRect, int from, int to ) const;
    266 
    267     virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
    268 
    269 protected:
     299    void setSymbol( QwtSymbol* );
     300    const QwtSymbol* symbol() const;
     301
     302    void setCurveFitter( QwtCurveFitter* );
     303    QwtCurveFitter* curveFitter() const;
     304
     305    virtual void drawSeries( QPainter*,
     306        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     307        const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE;
     308
     309    virtual QwtGraphic legendIcon( int index, const QSizeF& ) const QWT_OVERRIDE;
     310
     311  protected:
    270312
    271313    void init();
    272314
    273     virtual void drawCurve( QPainter *, int style,
    274         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    275         const QRectF &canvasRect, int from, int to ) const;
    276 
    277     virtual void drawSymbols( QPainter *, const QwtSymbol &,
    278         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    279         const QRectF &canvasRect, int from, int to ) const;
    280 
    281     virtual void drawLines( QPainter *,
    282         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    283         const QRectF &canvasRect, int from, int to ) const;
    284 
    285     virtual void drawSticks( QPainter *,
    286         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    287         const QRectF &canvasRect, int from, int to ) const;
    288 
    289     virtual void drawDots( QPainter *,
    290         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    291         const QRectF &canvasRect, int from, int to ) const;
    292 
    293     virtual void drawSteps( QPainter *,
    294         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    295         const QRectF &canvasRect, int from, int to ) const;
    296 
    297     virtual void fillCurve( QPainter *,
    298         const QwtScaleMap &, const QwtScaleMap &,
    299         const QRectF &canvasRect, QPolygonF & ) const;
    300 
    301     void closePolyline( QPainter *,
    302         const QwtScaleMap &, const QwtScaleMap &, QPolygonF & ) const;
    303 
    304 private:
     315    virtual void drawCurve( QPainter*, int style,
     316        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     317        const QRectF& canvasRect, int from, int to ) const;
     318
     319    virtual void drawSymbols( QPainter*, const QwtSymbol&,
     320        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     321        const QRectF& canvasRect, int from, int to ) const;
     322
     323    virtual void drawLines( QPainter*,
     324        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     325        const QRectF& canvasRect, int from, int to ) const;
     326
     327    virtual void drawSticks( QPainter*,
     328        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     329        const QRectF& canvasRect, int from, int to ) const;
     330
     331    virtual void drawDots( QPainter*,
     332        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     333        const QRectF& canvasRect, int from, int to ) const;
     334
     335    virtual void drawSteps( QPainter*,
     336        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     337        const QRectF& canvasRect, int from, int to ) const;
     338
     339    virtual void fillCurve( QPainter*,
     340        const QwtScaleMap&, const QwtScaleMap&,
     341        const QRectF& canvasRect, QPolygonF& ) const;
     342
     343    void closePolyline( QPainter*,
     344        const QwtScaleMap&, const QwtScaleMap&, QPolygonF& ) const;
     345
     346  private:
    305347    class PrivateData;
    306     PrivateData *d_data;
     348    PrivateData* m_data;
    307349};
    308350
  • trunk/BNC/qwt/qwt_plot_dict.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_dict.h"
     11#include <algorithm>
    1112
    1213class QwtPlotDict::PrivateData
    1314{
    14 public:
     15  public:
    1516
    16     class ItemList: public QList<QwtPlotItem *>
     17    class ItemList : public QList< QwtPlotItem* >
    1718    {
    18     public:
    19         void insertItem( QwtPlotItem *item )
     19      public:
     20        void insertItem( QwtPlotItem* item )
    2021        {
    2122            if ( item == NULL )
    2223                return;
    2324
    24             QList<QwtPlotItem *>::iterator it =
    25                 qUpperBound( begin(), end(), item, LessZThan() );
     25            QList< QwtPlotItem* >::iterator it =
     26                std::upper_bound( begin(), end(), item, LessZThan() );
    2627            insert( it, item );
    2728        }
    2829
    29         void removeItem( QwtPlotItem *item )
     30        void removeItem( QwtPlotItem* item )
    3031        {
    3132            if ( item == NULL )
    3233                return;
    3334
    34             QList<QwtPlotItem *>::iterator it =
    35                 qLowerBound( begin(), end(), item, LessZThan() );
     35            QList< QwtPlotItem* >::iterator it =
     36                std::lower_bound( begin(), end(), item, LessZThan() );
    3637
    3738            for ( ; it != end(); ++it )
    … …  
    4445            }
    4546        }
    46     private:
     47      private:
    4748        class LessZThan
    4849        {
    49         public:
    50             inline bool operator()( const QwtPlotItem *item1,
    51                 const QwtPlotItem *item2 ) const
     50          public:
     51            inline bool operator()( const QwtPlotItem* item1,
     52                const QwtPlotItem* item2 ) const
    5253            {
    5354                return item1->z() < item2->z();
    … …  
    6566   Auto deletion is enabled.
    6667   \sa setAutoDelete(), QwtPlotItem::attach()
    67 */
     68 */
    6869QwtPlotDict::QwtPlotDict()
    6970{
    70     d_data = new QwtPlotDict::PrivateData;
    71     d_data->autoDelete = true;
     71    m_data = new QwtPlotDict::PrivateData;
     72    m_data->autoDelete = true;
    7273}
    7374
    … …  
    7778   If autoDelete() is on, all attached items will be deleted
    7879   \sa setAutoDelete(), autoDelete(), QwtPlotItem::attach()
    79 */
     80 */
    8081QwtPlotDict::~QwtPlotDict()
    8182{
    82     detachItems( QwtPlotItem::Rtti_PlotItem, d_data->autoDelete );
    83     delete d_data;
     83    detachItems( QwtPlotItem::Rtti_PlotItem, m_data->autoDelete );
     84    delete m_data;
    8485}
    8586
    … …  
    9192
    9293   \sa autoDelete(), insertItem()
    93 */
     94 */
    9495void QwtPlotDict::setAutoDelete( bool autoDelete )
    9596{
    96     d_data->autoDelete = autoDelete;
     97    m_data->autoDelete = autoDelete;
    9798}
    9899
    … …  
    100101   \return true if auto deletion is enabled
    101102   \sa setAutoDelete(), insertItem()
    102 */
     103 */
    103104bool QwtPlotDict::autoDelete() const
    104105{
    105     return d_data->autoDelete;
     106    return m_data->autoDelete;
    106107}
    107108
    108109/*!
    109   Insert a plot item
     110   Insert a plot item
    110111
    111   \param item PlotItem
    112   \sa removeItem()
     112   \param item PlotItem
     113   \sa removeItem()
    113114 */
    114 void QwtPlotDict::insertItem( QwtPlotItem *item )
     115void QwtPlotDict::insertItem( QwtPlotItem* item )
    115116{
    116     d_data->itemList.insertItem( item );
     117    m_data->itemList.insertItem( item );
    117118}
    118119
    119120/*!
    120   Remove a plot item
     121   Remove a plot item
    121122
    122   \param item PlotItem
    123   \sa insertItem()
     123   \param item PlotItem
     124   \sa insertItem()
    124125 */
    125 void QwtPlotDict::removeItem( QwtPlotItem *item )
     126void QwtPlotDict::removeItem( QwtPlotItem* item )
    126127{
    127     d_data->itemList.removeItem( item );
     128    m_data->itemList.removeItem( item );
    128129}
    129130
    … …  
    134135               otherwise only those items of the type rtti.
    135136   \param autoDelete If true, delete all detached items
    136 */
     137 */
    137138void QwtPlotDict::detachItems( int rtti, bool autoDelete )
    138139{
    139     PrivateData::ItemList list = d_data->itemList;
     140    PrivateData::ItemList list = m_data->itemList;
    140141    QwtPlotItemIterator it = list.constBegin();
    141142    while ( it != list.constEnd() )
    142143    {
    143         QwtPlotItem *item = *it;
     144        QwtPlotItem* item = *it;
    144145
    145146        ++it; // increment before removing item from the list
    … …  
    155156
    156157/*!
    157   \brief A QwtPlotItemList of all attached plot items.
     158   \brief A QwtPlotItemList of all attached plot items.
    158159
    159   Use caution when iterating these lists, as removing/detaching an item will
    160   invalidate the iterator. Instead you can place pointers to objects to be
    161   removed in a removal list, and traverse that list later.
     160   Use caution when iterating these lists, as removing/detaching an item will
     161   invalidate the iterator. Instead you can place pointers to objects to be
     162   removed in a removal list, and traverse that list later.
    162163
    163   \return List of all attached plot items.
    164 */
    165 const QwtPlotItemList &QwtPlotDict::itemList() const
     164   \return List of all attached plot items.
     165 */
     166const QwtPlotItemList& QwtPlotDict::itemList() const
    166167{
    167     return d_data->itemList;
     168    return m_data->itemList;
    168169}
    169170
    170171/*!
    171   \return List of all attached plot items of a specific type.
    172   \param rtti See QwtPlotItem::RttiValues
    173   \sa QwtPlotItem::rtti()
    174 */
     172   \return List of all attached plot items of a specific type.
     173   \param rtti See QwtPlotItem::RttiValues
     174   \sa QwtPlotItem::rtti()
     175 */
    175176QwtPlotItemList QwtPlotDict::itemList( int rtti ) const
    176177{
    177178    if ( rtti == QwtPlotItem::Rtti_PlotItem )
    178         return d_data->itemList;
     179        return m_data->itemList;
    179180
    180181    QwtPlotItemList items;
    181182
    182     PrivateData::ItemList list = d_data->itemList;
     183    PrivateData::ItemList list = m_data->itemList;
    183184    for ( QwtPlotItemIterator it = list.constBegin(); it != list.constEnd(); ++it )
    184185    {
    185         QwtPlotItem *item = *it;
     186        QwtPlotItem* item = *it;
    186187        if ( item->rtti() == rtti )
    187188            items += item;
  • trunk/BNC/qwt/qwt_plot_dict.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    88 *****************************************************************************/
    99
    10 /*! \file !*/
    1110#ifndef QWT_PLOT_DICT
    1211#define QWT_PLOT_DICT
    … …  
    1413#include "qwt_global.h"
    1514#include "qwt_plot_item.h"
     15
    1616#include <qlist.h>
    1717
    18 /// \var typedef QList< QwtPlotItem *> QwtPlotItemList
    19 /// \brief See QT 4.x assistant documentation for QList
    20 typedef QList<QwtPlotItem *> QwtPlotItemList;
    21 typedef QList<QwtPlotItem *>::ConstIterator QwtPlotItemIterator;
     18typedef QList< QwtPlotItem* > QwtPlotItemList;
     19typedef QList< QwtPlotItem* >::ConstIterator QwtPlotItemIterator;
    2220
    2321/*!
    24   \brief A dictionary for plot items
     22   \brief A dictionary for plot items
    2523
    26   QwtPlotDict organizes plot items in increasing z-order.
    27   If autoDelete() is enabled, all attached items will be deleted
    28   in the destructor of the dictionary.
    29   QwtPlotDict can be used to get access to all QwtPlotItem items - or all
    30   items of a specific type -  that are currently on the plot.
     24   QwtPlotDict organizes plot items in increasing z-order.
     25   If autoDelete() is enabled, all attached items will be deleted
     26   in the destructor of the dictionary.
     27   QwtPlotDict can be used to get access to all QwtPlotItem items - or all
     28   items of a specific type -  that are currently on the plot.
    3129
    32   \sa QwtPlotItem::attach(), QwtPlotItem::detach(), QwtPlotItem::z()
    33 */
     30   \sa QwtPlotItem::attach(), QwtPlotItem::detach(), QwtPlotItem::z()
     31 */
    3432class QWT_EXPORT QwtPlotDict
    3533{
    36 public:
     34  public:
    3735    explicit QwtPlotDict();
    3836    virtual ~QwtPlotDict();
    … …  
    4745        bool autoDelete = true );
    4846
    49 protected:
    50     void insertItem( QwtPlotItem * );
    51     void removeItem( QwtPlotItem * );
     47  protected:
     48    void insertItem( QwtPlotItem* );
     49    void removeItem( QwtPlotItem* );
    5250
    53 private:
     51  private:
    5452    class PrivateData;
    55     PrivateData *d_data;
     53    PrivateData* m_data;
    5654};
    5755
  • trunk/BNC/qwt/qwt_plot_directpainter.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_plot_canvas.h"
    1414#include "qwt_plot_seriesitem.h"
     15
    1516#include <qpainter.h>
    1617#include <qevent.h>
    17 #include <qapplication.h>
    1818#include <qpixmap.h>
    1919
    2020static inline void qwtRenderItem(
    21     QPainter *painter, const QRect &canvasRect,
    22     QwtPlotSeriesItem *seriesItem, int from, int to )
     21    QPainter* painter, const QRect& canvasRect,
     22    QwtPlotSeriesItem* seriesItem, int from, int to )
    2323{
    2424    // A minor performance improvement is possible
    2525    // with caching the maps. TODO ...
    2626
    27     QwtPlot *plot = seriesItem->plot();
     27    QwtPlot* plot = seriesItem->plot();
    2828    const QwtScaleMap xMap = plot->canvasMap( seriesItem->xAxis() );
    2929    const QwtScaleMap yMap = plot->canvasMap( seriesItem->yAxis() );
    … …  
    3434}
    3535
    36 static inline bool qwtHasBackingStore( const QwtPlotCanvas *canvas )
     36static inline bool qwtHasBackingStore( const QwtPlotCanvas* canvas )
    3737{
    3838    return canvas->testPaintAttribute( QwtPlotCanvas::BackingStore )
    39         && canvas->backingStore() && !canvas->backingStore()->isNull();
     39           && canvas->backingStore() && !canvas->backingStore()->isNull();
    4040}
    4141
    4242class QwtPlotDirectPainter::PrivateData
    4343{
    44 public:
    45     PrivateData():
    46         attributes( 0 ),
    47         hasClipping(false),
    48         seriesItem( NULL ),
    49         from( 0 ),
    50         to( 0 )
     44  public:
     45    PrivateData()
     46        : hasClipping( false )
     47        , seriesItem( NULL )
     48        , from( 0 )
     49        , to( 0 )
    5150    {
    5251    }
    … …  
    5958    QPainter painter;
    6059
    61     QwtPlotSeriesItem *seriesItem;
     60    QwtPlotSeriesItem* seriesItem;
    6261    int from;
    6362    int to;
    … …  
    6564
    6665//! Constructor
    67 QwtPlotDirectPainter::QwtPlotDirectPainter( QObject *parent ):
    68     QObject( parent )
    69 {
    70     d_data = new PrivateData;
     66QwtPlotDirectPainter::QwtPlotDirectPainter( QObject* parent )
     67    : QObject( parent )
     68{
     69    m_data = new PrivateData;
    7170}
    7271
    … …  
    7473QwtPlotDirectPainter::~QwtPlotDirectPainter()
    7574{
    76     delete d_data;
    77 }
    78 
    79 /*!
    80   Change an attribute
    81 
    82   \param attribute Attribute to change
    83   \param on On/Off
    84 
    85   \sa Attribute, testAttribute()
    86 */
     75    delete m_data;
     76}
     77
     78/*!
     79   Change an attribute
     80
     81   \param attribute Attribute to change
     82   \param on On/Off
     83
     84   \sa Attribute, testAttribute()
     85 */
    8786void QwtPlotDirectPainter::setAttribute( Attribute attribute, bool on )
    8887{
    89     if ( bool( d_data->attributes & attribute ) != on )
     88    if ( bool( m_data->attributes & attribute ) != on )
    9089    {
    9190        if ( on )
    92             d_data->attributes |= attribute;
     91            m_data->attributes |= attribute;
    9392        else
    94             d_data->attributes &= ~attribute;
     93            m_data->attributes &= ~attribute;
    9594
    9695        if ( ( attribute == AtomicPainter ) && on )
    … …  
    10099
    101100/*!
    102   \return True, when attribute is enabled
    103   \param attribute Attribute to be tested
    104   \sa Attribute, setAttribute()
    105 */
     101   \return True, when attribute is enabled
     102   \param attribute Attribute to be tested
     103   \sa Attribute, setAttribute()
     104 */
    106105bool QwtPlotDirectPainter::testAttribute( Attribute attribute ) const
    107106{
    108     return d_data->attributes & attribute;
    109 }
    110 
    111 /*!
    112   En/Disables clipping
    113 
    114   \param enable Enables clipping is true, disable it otherwise
    115   \sa hasClipping(), clipRegion(), setClipRegion()
    116 */
     107    return m_data->attributes & attribute;
     108}
     109
     110/*!
     111   En/Disables clipping
     112
     113   \param enable Enables clipping is true, disable it otherwise
     114   \sa hasClipping(), clipRegion(), setClipRegion()
     115 */
    117116void QwtPlotDirectPainter::setClipping( bool enable )
    118117{
    119     d_data->hasClipping = enable;
    120 }
    121 
    122 /*!
    123   \return true, when clipping is enabled
    124   \sa setClipping(), clipRegion(), setClipRegion()
    125 */
     118    m_data->hasClipping = enable;
     119}
     120
     121/*!
     122   \return true, when clipping is enabled
     123   \sa setClipping(), clipRegion(), setClipRegion()
     124 */
    126125bool QwtPlotDirectPainter::hasClipping() const
    127126{
    128     return d_data->hasClipping;
     127    return m_data->hasClipping;
    129128}
    130129
    … …  
    139138   \param region Clip region
    140139   \sa clipRegion(), hasClipping(), setClipping()
    141 */
    142 void QwtPlotDirectPainter::setClipRegion( const QRegion &region )
    143 {
    144     d_data->clipRegion = region;
    145     d_data->hasClipping = true;
     140 */
     141void QwtPlotDirectPainter::setClipRegion( const QRegion& region )
     142{
     143    m_data->clipRegion = region;
     144    m_data->hasClipping = true;
    146145}
    147146
    … …  
    149148   \return Currently set clip region.
    150149   \sa setClipRegion(), setClipping(), hasClipping()
    151 */
     150 */
    152151QRegion QwtPlotDirectPainter::clipRegion() const
    153152{
    154     return d_data->clipRegion;
    155 }
    156 
    157 /*!
    158   \brief Draw a set of points of a seriesItem.
    159 
    160   When observing an measurement while it is running, new points have to be
    161   added to an existing seriesItem. drawSeries() can be used to display them avoiding
    162   a complete redraw of the canvas.
    163 
    164   Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    165   will result in faster painting, if the paint engine of the canvas widget
    166   supports this feature.
    167 
    168   \param seriesItem Item to be painted
    169   \param from Index of the first point to be painted
    170   \param to Index of the last point to be painted. If to < 0 the
     153    return m_data->clipRegion;
     154}
     155
     156/*!
     157   \brief Draw a set of points of a seriesItem.
     158
     159   When observing an measurement while it is running, new points have to be
     160   added to an existing seriesItem. drawSeries() can be used to display them avoiding
     161   a complete redraw of the canvas.
     162
     163   Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
     164   will result in faster painting, if the paint engine of the canvas widget
     165   supports this feature.
     166
     167   \param seriesItem Item to be painted
     168   \param from Index of the first point to be painted
     169   \param to Index of the last point to be painted. If to < 0 the
    171170         series will be painted to its last point.
    172 */
     171 */
    173172void QwtPlotDirectPainter::drawSeries(
    174     QwtPlotSeriesItem *seriesItem, int from, int to )
     173    QwtPlotSeriesItem* seriesItem, int from, int to )
    175174{
    176175    if ( seriesItem == NULL || seriesItem->plot() == NULL )
    177176        return;
    178177
    179     QWidget *canvas = seriesItem->plot()->canvas();
     178    QWidget* canvas = seriesItem->plot()->canvas();
    180179    const QRect canvasRect = canvas->contentsRect();
    181180
    182     QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>( canvas );
     181    QwtPlotCanvas* plotCanvas = qobject_cast< QwtPlotCanvas* >( canvas );
    183182
    184183    if ( plotCanvas && qwtHasBackingStore( plotCanvas ) )
    185184    {
    186         QPainter painter( const_cast<QPixmap *>( plotCanvas->backingStore() ) );
    187 
    188         if ( d_data->hasClipping )
    189             painter.setClipRegion( d_data->clipRegion );
     185        QPainter painter( const_cast< QPixmap* >( plotCanvas->backingStore() ) );
     186
     187        if ( m_data->hasClipping )
     188            painter.setClipRegion( m_data->clipRegion );
    190189
    191190        qwtRenderItem( &painter, canvasRect, seriesItem, from, to );
    … …  
    206205        if ( !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) )
    207206#endif
    208             immediatePaint = false;
     207        immediatePaint = false;
    209208    }
    210209
    211210    if ( immediatePaint )
    212211    {
    213         if ( !d_data->painter.isActive() )
     212        if ( !m_data->painter.isActive() )
    214213        {
    215214            reset();
    216215
    217             d_data->painter.begin( canvas );
     216            m_data->painter.begin( canvas );
    218217            canvas->installEventFilter( this );
    219218        }
    220219
    221         if ( d_data->hasClipping )
    222         {
    223             d_data->painter.setClipRegion(
    224                 QRegion( canvasRect ) & d_data->clipRegion );
     220        if ( m_data->hasClipping )
     221        {
     222            m_data->painter.setClipRegion(
     223                QRegion( canvasRect ) & m_data->clipRegion );
    225224        }
    226225        else
    227226        {
    228             if ( !d_data->painter.hasClipping() )
    229                 d_data->painter.setClipRect( canvasRect );
    230         }
    231 
    232         qwtRenderItem( &d_data->painter, canvasRect, seriesItem, from, to );
    233 
    234         if ( d_data->attributes & QwtPlotDirectPainter::AtomicPainter )
     227            if ( !m_data->painter.hasClipping() )
     228                m_data->painter.setClipRect( canvasRect );
     229        }
     230
     231        qwtRenderItem( &m_data->painter, canvasRect, seriesItem, from, to );
     232
     233        if ( m_data->attributes & QwtPlotDirectPainter::AtomicPainter )
    235234        {
    236235            reset();
    … …  
    238237        else
    239238        {
    240             if ( d_data->hasClipping )
    241                 d_data->painter.setClipping( false );
     239            if ( m_data->hasClipping )
     240                m_data->painter.setClipping( false );
    242241        }
    243242    }
    … …  
    246245        reset();
    247246
    248         d_data->seriesItem = seriesItem;
    249         d_data->from = from;
    250         d_data->to = to;
     247        m_data->seriesItem = seriesItem;
     248        m_data->from = from;
     249        m_data->to = to;
    251250
    252251        QRegion clipRegion = canvasRect;
    253         if ( d_data->hasClipping )
    254             clipRegion &= d_data->clipRegion;
     252        if ( m_data->hasClipping )
     253            clipRegion &= m_data->clipRegion;
    255254
    256255        canvas->installEventFilter( this );
    … …  
    258257        canvas->removeEventFilter( this );
    259258
    260         d_data->seriesItem = NULL;
     259        m_data->seriesItem = NULL;
    261260    }
    262261}
    … …  
    265264void QwtPlotDirectPainter::reset()
    266265{
    267     if ( d_data->painter.isActive() )
    268     {
    269         QWidget *w = static_cast<QWidget *>( d_data->painter.device() );
     266    if ( m_data->painter.isActive() )
     267    {
     268        QWidget* w = static_cast< QWidget* >( m_data->painter.device() );
    270269        if ( w )
    271270            w->removeEventFilter( this );
    272271
    273         d_data->painter.end();
     272        m_data->painter.end();
    274273    }
    275274}
    276275
    277276//! Event filter
    278 bool QwtPlotDirectPainter::eventFilter( QObject *, QEvent *event )
     277bool QwtPlotDirectPainter::eventFilter( QObject*, QEvent* event )
    279278{
    280279    if ( event->type() == QEvent::Paint )
    … …  
    282281        reset();
    283282
    284         if ( d_data->seriesItem )
    285         {
    286             const QPaintEvent *pe = static_cast< QPaintEvent *>( event );
    287 
    288             QWidget *canvas = d_data->seriesItem->plot()->canvas();
     283        if ( m_data->seriesItem )
     284        {
     285            const QPaintEvent* pe = static_cast< QPaintEvent* >( event );
     286
     287            QWidget* canvas = m_data->seriesItem->plot()->canvas();
    289288
    290289            QPainter painter( canvas );
    … …  
    295294            if ( doCopyCache )
    296295            {
    297                 QwtPlotCanvas *plotCanvas =
    298                     qobject_cast<QwtPlotCanvas *>( canvas );
     296                QwtPlotCanvas* plotCanvas =
     297                    qobject_cast< QwtPlotCanvas* >( canvas );
    299298                if ( plotCanvas )
    300299                {
    … …  
    311310            {
    312311                qwtRenderItem( &painter, canvas->contentsRect(),
    313                     d_data->seriesItem, d_data->from, d_data->to );
     312                    m_data->seriesItem, m_data->from, m_data->to );
    314313            }
    315314
  • trunk/BNC/qwt/qwt_plot_directpainter.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    3636             by another operation ( like changing scales ) and nothing needs
    3737             to be erased.
    38 */
    39 class QWT_EXPORT QwtPlotDirectPainter: public QObject
     38 */
     39class QWT_EXPORT QwtPlotDirectPainter : public QObject
    4040{
    41 public:
     41  public:
    4242    /*!
    43       \brief Paint attributes
    44       \sa setAttribute(), testAttribute(), drawSeries()
    45     */
     43       \brief Paint attributes
     44       \sa setAttribute(), testAttribute(), drawSeries()
     45     */
    4646    enum Attribute
    4747    {
    4848        /*!
    49           Initializing a QPainter is an expensive operation.
    50           When AtomicPainter is set each call of drawSeries() opens/closes
    51           a temporary QPainter. Otherwise QwtPlotDirectPainter tries to
    52           use the same QPainter as long as possible.
     49           Initializing a QPainter is an expensive operation.
     50           When AtomicPainter is set each call of drawSeries() opens/closes
     51           a temporary QPainter. Otherwise QwtPlotDirectPainter tries to
     52           use the same QPainter as long as possible.
    5353         */
    5454        AtomicPainter = 0x01,
    5555
    5656        /*!
    57           When FullRepaint is set the plot canvas is explicitly repainted
    58           after the samples have been rendered.
     57           When FullRepaint is set the plot canvas is explicitly repainted
     58           after the samples have been rendered.
    5959         */
    6060        FullRepaint = 0x02,
    6161
    6262        /*!
    63           When QwtPlotCanvas::BackingStore is enabled the painter
    64           has to paint to the backing store and the widget. In certain
    65           situations/environments it might be faster to paint to
    66           the backing store only and then copy the backing store to the canvas.
    67           This flag can also be useful for settings, where Qt fills the
    68           the clip region with the widget background.
     63           When QwtPlotCanvas::BackingStore is enabled the painter
     64           has to paint to the backing store and the widget. In certain
     65           situations/environments it might be faster to paint to
     66           the backing store only and then copy the backing store to the canvas.
     67           This flag can also be useful for settings, where Qt fills the
     68           the clip region with the widget background.
    6969         */
    7070        CopyBackingStore = 0x04
    7171    };
    7272
    73     //! Paint attributes
    74     typedef QFlags<Attribute> Attributes;
     73    Q_DECLARE_FLAGS( Attributes, Attribute )
    7574
    76     QwtPlotDirectPainter( QObject *parent = NULL );
     75    explicit QwtPlotDirectPainter( QObject* parent = NULL );
    7776    virtual ~QwtPlotDirectPainter();
    7877
    … …  
    8382    bool hasClipping() const;
    8483
    85     void setClipRegion( const QRegion & );
     84    void setClipRegion( const QRegion& );
    8685    QRegion clipRegion() const;
    8786
    88     void drawSeries( QwtPlotSeriesItem *, int from, int to );
     87    void drawSeries( QwtPlotSeriesItem*, int from, int to );
    8988    void reset();
    9089
    91     virtual bool eventFilter( QObject *, QEvent * );
     90    virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE;
    9291
    93 private:
     92  private:
    9493    class PrivateData;
    95     PrivateData *d_data;
     94    PrivateData* m_data;
    9695};
    9796
  • trunk/BNC/qwt/qwt_plot_glcanvas.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_plot.h"
    1212#include "qwt_painter.h"
    13 #include <qevent.h>
     13
     14#include <qcoreevent.h>
    1415#include <qpainter.h>
    15 #include <qdrawutil.h>
    16 #include <qstyle.h>
    17 #include <qstyleoption.h>
    18 
    19 #define FIX_GL_TRANSLATION 0
    20 
    21 static QWidget *qwtBGWidget( QWidget *widget )
    22 {
    23     QWidget *w = widget;
    24 
    25     for ( ; w->parentWidget() != NULL; w = w->parentWidget() )
    26     {
    27         if ( w->autoFillBackground() ||
    28             w->testAttribute( Qt::WA_StyledBackground ) )
    29         {
    30             return w;
    31         }
    32     }
    33 
    34     return w;
    35 }
    36 
    37 static void qwtUpdateContentsRect( QwtPlotGLCanvas *canvas )
    38 {
    39     const int fw = canvas->frameWidth();
    40     canvas->setContentsMargins( fw, fw, fw, fw );
     16#include <qpainterpath.h>
     17#include <qglframebufferobject.h>
     18
     19namespace
     20{
     21    class QwtPlotGLCanvasFormat : public QGLFormat
     22    {
     23      public:
     24        QwtPlotGLCanvasFormat()
     25            : QGLFormat( QGLFormat::defaultFormat() )
     26        {
     27            setSampleBuffers( true );
     28        }
     29    };
    4130}
    4231
    4332class QwtPlotGLCanvas::PrivateData
    4433{
    45 public:
    46     PrivateData():
    47         frameStyle( QFrame::Panel | QFrame::Sunken),
    48         lineWidth( 2 ),
    49         midLineWidth( 0 )
    50     {
    51     }
    52 
    53     int frameStyle;
    54     int lineWidth;
    55     int midLineWidth;
     34  public:
     35    PrivateData()
     36        : fboDirty( true )
     37        , fbo( NULL )
     38    {
     39    }
     40
     41    ~PrivateData()
     42    {
     43        delete fbo;
     44    }
     45
     46    bool fboDirty;
     47    QGLFramebufferObject* fbo;
    5648};
    5749
    58 class QwtPlotGLCanvasFormat: public QGLFormat
    59 {
    60 public:
    61     QwtPlotGLCanvasFormat():
    62         QGLFormat( QGLFormat::defaultFormat() )
    63     {
    64         setSampleBuffers( true );
    65     }
    66 };
    67 
    68 /*!
    69   \brief Constructor
    70 
    71   \param plot Parent plot widget
    72   \sa QwtPlot::setCanvas()
    73 */
    74 QwtPlotGLCanvas::QwtPlotGLCanvas( QwtPlot *plot ):
    75     QGLWidget( QwtPlotGLCanvasFormat(), plot )
    76 {
    77     d_data = new PrivateData;
    78 
    79 #ifndef QT_NO_CURSOR
    80     setCursor( Qt::CrossCursor );
    81 #endif
    82 
    83     setAutoFillBackground( true );
    84     qwtUpdateContentsRect( this );
     50/*!
     51   \brief Constructor
     52
     53   \param plot Parent plot widget
     54   \sa QwtPlot::setCanvas()
     55 */
     56QwtPlotGLCanvas::QwtPlotGLCanvas( QwtPlot* plot )
     57    : QGLWidget( QwtPlotGLCanvasFormat(), plot )
     58    , QwtPlotAbstractGLCanvas( this )
     59{
     60    init();
     61}
     62/*!
     63   \brief Constructor
     64
     65   \param format OpenGL rendering options
     66   \param plot Parent plot widget
     67   \sa QwtPlot::setCanvas()
     68 */
     69QwtPlotGLCanvas::QwtPlotGLCanvas( const QGLFormat& format, QwtPlot* plot )
     70    : QGLWidget( format, plot )
     71    , QwtPlotAbstractGLCanvas( this )
     72{
     73    init();
    8574}
    8675
    … …  
    8877QwtPlotGLCanvas::~QwtPlotGLCanvas()
    8978{
    90     delete d_data;
    91 }
    92 
    93 /*!
    94   Set the frame style
    95 
    96   \param style The bitwise OR between a shape and a shadow.
    97 
    98   \sa frameStyle(), QFrame::setFrameStyle(),
    99       setFrameShadow(), setFrameShape()
    100  */
    101 void QwtPlotGLCanvas::setFrameStyle( int style )
    102 {
    103     if ( style != d_data->frameStyle )
    104     {
    105         d_data->frameStyle = style;
    106         qwtUpdateContentsRect( this );
    107 
    108         update();
    109     }
    110 }
    111 
    112 /*!
    113   \return The bitwise OR between a frameShape() and a frameShadow()
    114   \sa setFrameStyle(), QFrame::frameStyle()
    115  */
    116 int QwtPlotGLCanvas::frameStyle() const
    117 {
    118     return d_data->frameStyle;
    119 }
    120 
    121 /*!
    122   Set the frame shadow
    123 
    124   \param shadow Frame shadow
    125   \sa frameShadow(), setFrameShape(), QFrame::setFrameShadow()
    126  */
    127 void QwtPlotGLCanvas::setFrameShadow( Shadow shadow )
    128 {
    129     setFrameStyle(( d_data->frameStyle & QFrame::Shape_Mask ) | shadow );
    130 }
    131 
    132 /*!
    133   \return Frame shadow
    134   \sa setFrameShadow(), QFrame::setFrameShadow()
    135  */
    136 QwtPlotGLCanvas::Shadow QwtPlotGLCanvas::frameShadow() const
    137 {
    138     return (Shadow) ( d_data->frameStyle & QFrame::Shadow_Mask );
    139 }
    140 
    141 /*!
    142   Set the frame shape
    143 
    144   \param shape Frame shape
    145   \sa frameShape(), setFrameShadow(), QFrame::frameShape()
    146  */
    147 void QwtPlotGLCanvas::setFrameShape( Shape shape )
    148 {
    149     setFrameStyle( ( d_data->frameStyle & QFrame::Shadow_Mask ) | shape );
    150 }
    151 
    152 /*!
    153   \return Frame shape
    154   \sa setFrameShape(), QFrame::frameShape()
    155  */
    156 QwtPlotGLCanvas::Shape QwtPlotGLCanvas::frameShape() const
    157 {
    158     return (Shape) ( d_data->frameStyle & QFrame::Shape_Mask );
    159 }
    160 
    161 /*!
    162    Set the frame line width
    163 
    164    The default line width is 2 pixels.
    165 
    166    \param width Line width of the frame
    167    \sa lineWidth(), setMidLineWidth()
    168 */
    169 void QwtPlotGLCanvas::setLineWidth( int width )
    170 {
    171     width = qMax( width, 0 );
    172     if ( width != d_data->lineWidth )
    173     {
    174         d_data->lineWidth = qMax( width, 0 );
    175         qwtUpdateContentsRect( this );
    176         update();
    177     }
    178 }
    179 
    180 /*!
    181   \return Line width of the frame
    182   \sa setLineWidth(), midLineWidth()
    183  */
    184 int QwtPlotGLCanvas::lineWidth() const
    185 {
    186     return d_data->lineWidth;
    187 }
    188 
    189 /*!
    190    Set the frame mid line width
    191 
    192    The default midline width is 0 pixels.
    193 
    194    \param width Midline width of the frame
    195    \sa midLineWidth(), setLineWidth()
    196 */
    197 void QwtPlotGLCanvas::setMidLineWidth( int width )
    198 {
    199     width = qMax( width, 0 );
    200     if ( width != d_data->midLineWidth )
    201     {
    202         d_data->midLineWidth = width;
    203         qwtUpdateContentsRect( this );
    204         update();
    205     }
    206 }
    207 
    208 /*!
    209   \return Midline width of the frame
    210   \sa setMidLineWidth(), lineWidth()
    211  */
    212 int QwtPlotGLCanvas::midLineWidth() const
    213 {
    214     return d_data->midLineWidth;
    215 }
    216 
    217 /*!
    218   \return Frame width depending on the style, line width and midline width.
    219  */
    220 int QwtPlotGLCanvas::frameWidth() const
    221 {
    222     return ( frameStyle() != NoFrame ) ? d_data->lineWidth : 0;
    223 }
    224 
    225 /*!
    226   Paint event
    227 
    228   \param event Paint event
    229   \sa QwtPlot::drawCanvas()
    230 */
    231 void QwtPlotGLCanvas::paintEvent( QPaintEvent *event )
    232 {
    233     Q_UNUSED( event );
    234 
    235     QPainter painter( this );
    236 
    237 #if FIX_GL_TRANSLATION
    238     if ( painter.paintEngine()->type() == QPaintEngine::OpenGL2 )
    239     {
    240         // work around a translation bug of QPaintEngine::OpenGL2
    241         painter.translate( 1, 1 );
    242     }
     79    delete m_data;
     80}
     81
     82void QwtPlotGLCanvas::init()
     83{
     84    m_data = new PrivateData;
     85
     86#if 1
     87    setAttribute( Qt::WA_OpaquePaintEvent, true );
    24388#endif
    244 
    245     drawBackground( &painter );
    246     drawItems( &painter );
    247 
    248     if ( !testAttribute( Qt::WA_StyledBackground ) )
    249     {
    250         if ( frameWidth() > 0 )
    251             drawBorder( &painter );
    252     }
    253 }
    254 /*!
    255   Qt event handler for QEvent::PolishRequest and QEvent::StyleChange
    256   \param event Qt Event
    257   \return See QGLWidget::event()
    258 */
    259 bool QwtPlotGLCanvas::event( QEvent *event )
     89    setLineWidth( 2 );
     90    setFrameShadow( QFrame::Sunken );
     91    setFrameShape( QFrame::Panel );
     92}
     93
     94/*!
     95   Paint event
     96
     97   \param event Paint event
     98   \sa QwtPlot::drawCanvas()
     99 */
     100void QwtPlotGLCanvas::paintEvent( QPaintEvent* event )
     101{
     102    QGLWidget::paintEvent( event );
     103}
     104
     105/*!
     106   Qt event handler for QEvent::PolishRequest and QEvent::StyleChange
     107   \param event Qt Event
     108   \return See QGLWidget::event()
     109 */
     110bool QwtPlotGLCanvas::event( QEvent* event )
    260111{
    261112    const bool ok = QGLWidget::event( event );
    … …  
    275126
    276127/*!
    277   Draw the plot items
    278   \param painter Painter
    279 
    280   \sa QwtPlot::drawCanvas()
    281 */
    282 void QwtPlotGLCanvas::drawItems( QPainter *painter )
    283 {
    284     painter->save();
    285 
    286     painter->setClipRect( contentsRect(), Qt::IntersectClip );
    287 
    288     QwtPlot *plot = qobject_cast< QwtPlot *>( parent() );
    289     if ( plot )
    290         plot->drawCanvas( painter );
    291 
    292     painter->restore();
    293 }
    294 
    295 /*!
    296   Draw the background of the canvas
    297   \param painter Painter
    298 */
    299 void QwtPlotGLCanvas::drawBackground( QPainter *painter )
    300 {
    301     painter->save();
    302 
    303     QWidget *w = qwtBGWidget( this );
    304 
    305     const QPoint off = mapTo( w, QPoint() );
    306     painter->translate( -off );
    307 
    308     const QRect fillRect = rect().translated( off );
    309 
    310     if ( w->testAttribute( Qt::WA_StyledBackground ) )
    311     {
    312         painter->setClipRect( fillRect );
    313 
    314         QStyleOption opt;
    315         opt.initFrom( w );
    316         w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w);
     128   Invalidate the paint cache and repaint the canvas
     129   \sa invalidatePaintCache()
     130 */
     131void QwtPlotGLCanvas::replot()
     132{
     133    QwtPlotAbstractGLCanvas::replot();
     134}
     135
     136//! Invalidate the internal backing store
     137void QwtPlotGLCanvas::invalidateBackingStore()
     138{
     139    m_data->fboDirty = true;
     140}
     141
     142void QwtPlotGLCanvas::clearBackingStore()
     143{
     144    delete m_data->fbo;
     145    m_data->fbo = NULL;
     146}
     147
     148/*!
     149   Calculate the painter path for a styled or rounded border
     150
     151   When the canvas has no styled background or rounded borders
     152   the painter path is empty.
     153
     154   \param rect Bounding rectangle of the canvas
     155   \return Painter path, that can be used for clipping
     156 */
     157QPainterPath QwtPlotGLCanvas::borderPath( const QRect& rect ) const
     158{
     159    return canvasBorderPath( rect );
     160}
     161
     162//! No operation - reserved for some potential use in the future
     163void QwtPlotGLCanvas::initializeGL()
     164{
     165}
     166
     167//! Paint the plot
     168void QwtPlotGLCanvas::paintGL()
     169{
     170    const bool hasFocusIndicator =
     171        hasFocus() && focusIndicator() == CanvasFocusIndicator;
     172
     173    QPainter painter;
     174
     175    if ( testPaintAttribute( QwtPlotGLCanvas::BackingStore ) )
     176    {
     177        const qreal pixelRatio = QwtPainter::devicePixelRatio( this );
     178        const QRect rect( 0, 0, width() * pixelRatio, height() * pixelRatio );
     179
     180        if ( hasFocusIndicator )
     181            painter.begin( this );
     182
     183        if ( m_data->fbo )
     184        {
     185            if ( m_data->fbo->size() != rect.size() )
     186            {
     187                delete m_data->fbo;
     188                m_data->fbo = NULL;
     189            }
     190        }
     191
     192        if ( m_data->fbo == NULL )
     193        {
     194            QGLFramebufferObjectFormat format;
     195            format.setSamples( 4 );
     196            format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
     197
     198            m_data->fbo = new QGLFramebufferObject( rect.size(), format );
     199            m_data->fboDirty = true;
     200        }
     201
     202        if ( m_data->fboDirty )
     203        {
     204            QPainter fboPainter( m_data->fbo );
     205            fboPainter.scale( pixelRatio, pixelRatio );
     206            draw( &fboPainter );
     207            fboPainter.end();
     208
     209            m_data->fboDirty = false;
     210        }
     211
     212        /*
     213            Why do we have this strange translation - but, anyway
     214            QwtPlotGLCanvas in combination with scaling factor
     215            is not very likely to happen as using QwtPlotOpenGLCanvas
     216            usually makes more sense then.
     217         */
     218
     219        QGLFramebufferObject::blitFramebuffer( NULL,
     220            rect.translated( 0, height() - rect.height() ), m_data->fbo, rect );
    317221    }
    318222    else
    319223    {
    320         painter->fillRect( fillRect,
    321             w->palette().brush( w->backgroundRole() ) );
    322     }
    323 
    324     painter->restore();
    325 }
    326 
    327 /*!
    328   Draw the border of the canvas
    329   \param painter Painter
    330 */
    331 void QwtPlotGLCanvas::drawBorder( QPainter *painter )
    332 {
    333     const int fw = frameWidth();
    334     if ( fw <= 0 )
    335         return;
    336 
    337     if ( frameShadow() == QwtPlotGLCanvas::Plain )
    338     {
    339         qDrawPlainRect( painter, frameRect(),
    340             palette().shadow().color(), lineWidth() );
    341     }
    342     else
    343     {
    344         if ( frameShape() == QwtPlotGLCanvas::Box )
    345         {
    346             qDrawShadeRect( painter, frameRect(), palette(),
    347                 frameShadow() == Sunken, lineWidth(), midLineWidth() );
    348         }
    349         else
    350         {
    351             qDrawShadePanel( painter, frameRect(), palette(),
    352                 frameShadow() == Sunken, lineWidth() );
    353         }
    354     }
    355 }
    356 
    357 //! Calls repaint()
    358 void QwtPlotGLCanvas::replot()
    359 {
    360     repaint();
    361 }
    362 
    363 /*!
    364    \return Empty path
    365 */
    366 QPainterPath QwtPlotGLCanvas::borderPath( const QRect &rect ) const
    367 {
    368     Q_UNUSED( rect );
    369     return QPainterPath();
    370 }
    371 
    372 //! \return The rectangle where the frame is drawn in.
    373 QRect QwtPlotGLCanvas::frameRect() const
    374 {
    375     const int fw = frameWidth();
    376     return contentsRect().adjusted( -fw, -fw, fw, fw );
    377 }
     224        painter.begin( this );
     225        draw( &painter );
     226    }
     227
     228    if ( hasFocusIndicator )
     229        drawFocusIndicator( &painter );
     230}
     231
     232//! No operation - reserved for some potential use in the future
     233void QwtPlotGLCanvas::resizeGL( int, int )
     234{
     235    // nothing to do
     236}
     237
     238#include "moc_qwt_plot_glcanvas.cpp"
  • trunk/BNC/qwt/qwt_plot_glcanvas.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include <qframe.h>
     14#include "qwt_plot_abstract_canvas.h"
     15
    1516#include <qgl.h>
    16 #include <qpainterpath.h>
    1717
    1818class QwtPlot;
    1919
    2020/*!
    21   \brief An alternative canvas for a QwtPlot derived from QGLWidget
     21   \brief An alternative canvas for a QwtPlot derived from QGLWidget
    2222
    23   QwtPlotGLCanvas implements the very basics to act as canvas
    24   inside of a QwtPlot widget. It might be extended to a full
    25   featured alternative to QwtPlotCanvas in a future version of Qwt.
     23   QwtPlotGLCanvas implements the very basics to act as canvas
     24   inside of a QwtPlot widget. It might be extended to a full
     25   featured alternative to QwtPlotCanvas in a future version of Qwt.
    2626
    27   Even if QwtPlotGLCanvas is not derived from QFrame it imitates
    28   its API. When using style sheets it supports the box model - beside
    29   backgrounds with rounded borders.
     27   Even if QwtPlotGLCanvas is not derived from QFrame it imitates
     28   its API. When using style sheets it supports the box model - beside
     29   backgrounds with rounded borders.
    3030
    31   \sa QwtPlot::setCanvas(), QwtPlotCanvas
     31   Since Qt 5.4 QOpenGLWidget is available, that is used by QwtPlotOpenGLCanvas.
    3232
    33   \note With Qt4 you might want to use the QPaintEngine::OpenGL paint engine
     33   \sa QwtPlot::setCanvas(), QwtPlotCanvas, QwtPlotOpenGLCanvas
     34
     35   \note With Qt4 you might want to use the QPaintEngine::OpenGL paint engine
    3436        ( see QGL::setPreferredPaintEngine() ). On a Linux test system
    3537        QPaintEngine::OpenGL2 shows very basic problems like translated
    3638        geometries.
    37 */
    38 class QWT_EXPORT QwtPlotGLCanvas: public QGLWidget
     39
     40   \note Another way for getting hardware accelerated graphics is using
     41        an OpenGL offscreen buffer ( QwtPlotCanvas::OpenGLBuffer ) with QwtPlotCanvas.
     42        Performance is worse, than rendering straight to a QGLWidget, but is usually
     43        better integrated into a desktop application.
     44 */
     45class QWT_EXPORT QwtPlotGLCanvas : public QGLWidget, public QwtPlotAbstractGLCanvas
    3946{
    4047    Q_OBJECT
    4148
    42     Q_ENUMS( Shape Shadow )
    43 
    44     Q_PROPERTY( Shadow frameShadow READ frameShadow WRITE setFrameShadow )
    45     Q_PROPERTY( Shape frameShape READ frameShape WRITE setFrameShape )
     49    Q_PROPERTY( QFrame::Shadow frameShadow READ frameShadow WRITE setFrameShadow )
     50    Q_PROPERTY( QFrame::Shape frameShape READ frameShape WRITE setFrameShape )
    4651    Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth )
    4752    Q_PROPERTY( int midLineWidth READ midLineWidth WRITE setMidLineWidth )
    … …  
    4954    Q_PROPERTY( QRect frameRect READ frameRect DESIGNABLE false )
    5055
    51 public:
    52     /*!
    53         \brief Frame shadow
     56    Q_PROPERTY( double borderRadius READ borderRadius WRITE setBorderRadius )
    5457
    55          Unfortunately it is not possible to use QFrame::Shadow
    56          as a property of a widget that is not derived from QFrame.
    57          The following enum is made for the designer only. It is safe
    58          to use QFrame::Shadow instead.
    59      */
    60     enum Shadow
    61     {
    62         //! QFrame::Plain
    63         Plain = QFrame::Plain,
    64 
    65         //! QFrame::Raised
    66         Raised = QFrame::Raised,
    67 
    68         //! QFrame::Sunken
    69         Sunken = QFrame::Sunken
    70     };
    71 
    72     /*!
    73         \brief Frame shape
    74 
    75         Unfortunately it is not possible to use QFrame::Shape
    76         as a property of a widget that is not derived from QFrame.
    77         The following enum is made for the designer only. It is safe
    78         to use QFrame::Shadow instead.
    79 
    80         \note QFrame::StyledPanel and QFrame::WinPanel are unsupported
    81               and will be displayed as QFrame::Panel.
    82      */
    83     enum Shape
    84     {
    85         NoFrame = QFrame::NoFrame,
    86 
    87         Box = QFrame::Box,
    88         Panel = QFrame::Panel
    89     };
    90 
    91     explicit QwtPlotGLCanvas( QwtPlot * = NULL );
     58  public:
     59    explicit QwtPlotGLCanvas( QwtPlot* = NULL );
     60    explicit QwtPlotGLCanvas( const QGLFormat&, QwtPlot* = NULL );
    9261    virtual ~QwtPlotGLCanvas();
    9362
    94     void setFrameStyle( int style );
    95     int frameStyle() const;
     63    Q_INVOKABLE virtual void invalidateBackingStore() QWT_OVERRIDE;
     64    Q_INVOKABLE QPainterPath borderPath( const QRect& ) const;
    9665
    97     void setFrameShadow( Shadow );
    98     Shadow frameShadow() const;
     66    virtual bool event( QEvent* ) QWT_OVERRIDE;
    9967
    100     void setFrameShape( Shape );
    101     Shape frameShape() const;
    102 
    103     void setLineWidth( int );
    104     int lineWidth() const;
    105 
    106     void setMidLineWidth( int );
    107     int midLineWidth() const;
    108 
    109     int frameWidth() const;
    110     QRect frameRect() const;
    111 
    112     Q_INVOKABLE QPainterPath borderPath( const QRect & ) const;
    113 
    114     virtual bool event( QEvent * );
    115 
    116 public Q_SLOTS:
     68  public Q_SLOTS:
    11769    void replot();
    11870
    119 protected:
    120     virtual void paintEvent( QPaintEvent * );
     71  protected:
     72    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
    12173
    122     virtual void drawBackground( QPainter * );
    123     virtual void drawBorder( QPainter * );
    124     virtual void drawItems( QPainter * );
     74    virtual void initializeGL() QWT_OVERRIDE;
     75    virtual void paintGL() QWT_OVERRIDE;
     76    virtual void resizeGL( int width, int height ) QWT_OVERRIDE;
    12577
    126 private:
     78  private:
     79    void init();
     80    virtual void clearBackingStore() QWT_OVERRIDE;
     81
    12782    class PrivateData;
    128     PrivateData *d_data;
     83    PrivateData* m_data;
    12984};
    13085
  • trunk/BNC/qwt/qwt_plot_grid.cpp

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_scale_map.h"
    1414#include "qwt_scale_div.h"
    15 #include "qwt_math.h"
     15
    1616#include <qpainter.h>
    1717#include <qpen.h>
    1818
     19static inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 )
     20{
     21    return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );
     22}
     23
    1924class QwtPlotGrid::PrivateData
    2025{
    21 public:
    22     PrivateData():
    23         xEnabled( true ),
    24         yEnabled( true ),
    25         xMinEnabled( false ),
    26         yMinEnabled( false )
     26  public:
     27    PrivateData()
     28        : xEnabled( true )
     29        , yEnabled( true )
     30        , xMinEnabled( false )
     31        , yMinEnabled( false )
    2732    {
    2833    }
    … …  
    4146
    4247//! Enables major grid, disables minor grid
    43 QwtPlotGrid::QwtPlotGrid():
    44     QwtPlotItem( QwtText( "Grid" ) )
    45 {
    46     d_data = new PrivateData;
     48QwtPlotGrid::QwtPlotGrid()
     49    : QwtPlotItem( QwtText( "Grid" ) )
     50{
     51    m_data = new PrivateData;
    4752
    4853    setItemInterest( QwtPlotItem::ScaleInterest, true );
    … …  
    5358QwtPlotGrid::~QwtPlotGrid()
    5459{
    55     delete d_data;
     60    delete m_data;
    5661}
    5762
    … …  
    6368
    6469/*!
    65   \brief Enable or disable vertical grid lines
    66   \param on Enable (true) or disable
    67 
    68   \sa Minor grid lines can be enabled or disabled with
     70   \brief Enable or disable vertical grid lines
     71   \param on Enable (true) or disable
     72
     73   \sa Minor grid lines can be enabled or disabled with
    6974      enableXMin()
    70 */
     75 */
    7176void QwtPlotGrid::enableX( bool on )
    7277{
    73     if ( d_data->xEnabled != on )
    74     {
    75         d_data->xEnabled = on;
    76 
    77         legendChanged();
    78         itemChanged();
    79     }
    80 }
    81 
    82 /*!
    83   \brief Enable or disable horizontal grid lines
    84   \param on Enable (true) or disable
    85   \sa Minor grid lines can be enabled or disabled with enableYMin()
    86 */
     78    if ( m_data->xEnabled != on )
     79    {
     80        m_data->xEnabled = on;
     81
     82        legendChanged();
     83        itemChanged();
     84    }
     85}
     86
     87/*!
     88   \brief Enable or disable horizontal grid lines
     89   \param on Enable (true) or disable
     90   \sa Minor grid lines can be enabled or disabled with enableYMin()
     91 */
    8792void QwtPlotGrid::enableY( bool on )
    8893{
    89     if ( d_data->yEnabled != on )
    90     {
    91         d_data->yEnabled = on;
    92 
    93         legendChanged();
    94         itemChanged();
    95     }
    96 }
    97 
    98 /*!
    99   \brief Enable or disable  minor vertical grid lines.
    100   \param on Enable (true) or disable
    101   \sa enableX()
    102 */
     94    if ( m_data->yEnabled != on )
     95    {
     96        m_data->yEnabled = on;
     97
     98        legendChanged();
     99        itemChanged();
     100    }
     101}
     102
     103/*!
     104   \brief Enable or disable  minor vertical grid lines.
     105   \param on Enable (true) or disable
     106   \sa enableX()
     107 */
    103108void QwtPlotGrid::enableXMin( bool on )
    104109{
    105     if ( d_data->xMinEnabled != on )
    106     {
    107         d_data->xMinEnabled = on;
    108 
    109         legendChanged();
    110         itemChanged();
    111     }
    112 }
    113 
    114 /*!
    115   \brief Enable or disable minor horizontal grid lines
    116   \param on Enable (true) or disable
    117   \sa enableY()
    118 */
     110    if ( m_data->xMinEnabled != on )
     111    {
     112        m_data->xMinEnabled = on;
     113
     114        legendChanged();
     115        itemChanged();
     116    }
     117}
     118
     119/*!
     120   \brief Enable or disable minor horizontal grid lines
     121   \param on Enable (true) or disable
     122   \sa enableY()
     123 */
    119124void QwtPlotGrid::enableYMin( bool on )
    120125{
    121     if ( d_data->yMinEnabled != on )
    122     {
    123         d_data->yMinEnabled = on;
    124 
    125         legendChanged();
    126         itemChanged();
    127     }
    128 }
    129 
    130 /*!
    131   Assign an x axis scale division
    132 
    133   \param scaleDiv Scale division
    134 */
    135 void QwtPlotGrid::setXDiv( const QwtScaleDiv &scaleDiv )
    136 {
    137     if ( d_data->xScaleDiv != scaleDiv )
    138     {
    139         d_data->xScaleDiv = scaleDiv;
    140         itemChanged();
    141     }
    142 }
    143 
    144 /*!
    145   Assign a y axis division
    146 
    147   \param scaleDiv Scale division
    148 */
    149 void QwtPlotGrid::setYDiv( const QwtScaleDiv &scaleDiv )
    150 {
    151     if ( d_data->yScaleDiv != scaleDiv )
    152     {
    153         d_data->yScaleDiv = scaleDiv;
    154         itemChanged();
    155     }
    156 }
    157 
    158 /*!
    159   Build and assign a pen for both major and minor grid lines
    160 
    161   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    162   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    163   to hide this incompatibility.
    164 
    165   \param color Pen color
    166   \param width Pen width
    167   \param style Pen style
    168 
    169   \sa pen(), brush()
    170  */
    171 void QwtPlotGrid::setPen( const QColor &color, qreal width, Qt::PenStyle style )
     126    if ( m_data->yMinEnabled != on )
     127    {
     128        m_data->yMinEnabled = on;
     129
     130        legendChanged();
     131        itemChanged();
     132    }
     133}
     134
     135/*!
     136   Assign an x axis scale division
     137
     138   \param scaleDiv Scale division
     139 */
     140void QwtPlotGrid::setXDiv( const QwtScaleDiv& scaleDiv )
     141{
     142    if ( m_data->xScaleDiv != scaleDiv )
     143    {
     144        m_data->xScaleDiv = scaleDiv;
     145        itemChanged();
     146    }
     147}
     148
     149/*!
     150   Assign a y axis division
     151
     152   \param scaleDiv Scale division
     153 */
     154void QwtPlotGrid::setYDiv( const QwtScaleDiv& scaleDiv )
     155{
     156    if ( m_data->yScaleDiv != scaleDiv )
     157    {
     158        m_data->yScaleDiv = scaleDiv;
     159        itemChanged();
     160    }
     161}
     162
     163/*!
     164   Build and assign a pen for both major and minor grid lines
     165
     166   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     167   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     168   to hide this incompatibility.
     169
     170   \param color Pen color
     171   \param width Pen width
     172   \param style Pen style
     173
     174   \sa pen(), brush()
     175 */
     176void QwtPlotGrid::setPen( const QColor& color, qreal width, Qt::PenStyle style )
    172177{
    173178    setPen( QPen( color, width, style ) );
    … …  
    175180
    176181/*!
    177   Assign a pen for both major and minor grid lines
    178 
    179   \param pen Pen
    180   \sa setMajorPen(), setMinorPen()
    181 */
    182 void QwtPlotGrid::setPen( const QPen &pen )
    183 {
    184     if ( d_data->majorPen != pen || d_data->minorPen != pen )
    185     {
    186         d_data->majorPen = pen;
    187         d_data->minorPen = pen;
    188 
    189         legendChanged();
    190         itemChanged();
    191     }
    192 }
    193 
    194 /*!
    195   Build and assign a pen for both major grid lines
    196 
    197   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    198   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    199   to hide this incompatibility.
    200 
    201   \param color Pen color
    202   \param width Pen width
    203   \param style Pen style
    204 
    205   \sa pen(), brush()
    206  */
    207 void QwtPlotGrid::setMajorPen( const QColor &color, qreal width, Qt::PenStyle style )
     182   Assign a pen for both major and minor grid lines
     183
     184   \param pen Pen
     185   \sa setMajorPen(), setMinorPen()
     186 */
     187void QwtPlotGrid::setPen( const QPen& pen )
     188{
     189    if ( m_data->majorPen != pen || m_data->minorPen != pen )
     190    {
     191        m_data->majorPen = pen;
     192        m_data->minorPen = pen;
     193
     194        legendChanged();
     195        itemChanged();
     196    }
     197}
     198
     199/*!
     200   Build and assign a pen for both major grid lines
     201
     202   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     203   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     204   to hide this incompatibility.
     205
     206   \param color Pen color
     207   \param width Pen width
     208   \param style Pen style
     209
     210   \sa pen(), brush()
     211 */
     212void QwtPlotGrid::setMajorPen( const QColor& color, qreal width, Qt::PenStyle style )
    208213{
    209214    setMajorPen( QPen( color, width, style ) );
    … …  
    211216
    212217/*!
    213   Assign a pen for the major grid lines
    214 
    215   \param pen Pen
    216   \sa majorPen(), setMinorPen(), setPen()
    217 */
    218 void QwtPlotGrid::setMajorPen( const QPen &pen )
    219 {
    220     if ( d_data->majorPen != pen )
    221     {
    222         d_data->majorPen = pen;
    223 
    224         legendChanged();
    225         itemChanged();
    226     }
    227 }
    228 
    229 /*!
    230   Build and assign a pen for the minor grid lines
    231 
    232   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    233   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    234   to hide this incompatibility.
    235 
    236   \param color Pen color
    237   \param width Pen width
    238   \param style Pen style
    239 
    240   \sa pen(), brush()
    241  */
    242 void QwtPlotGrid::setMinorPen( const QColor &color, qreal width, Qt::PenStyle style )
     218   Assign a pen for the major grid lines
     219
     220   \param pen Pen
     221   \sa majorPen(), setMinorPen(), setPen()
     222 */
     223void QwtPlotGrid::setMajorPen( const QPen& pen )
     224{
     225    if ( m_data->majorPen != pen )
     226    {
     227        m_data->majorPen = pen;
     228
     229        legendChanged();
     230        itemChanged();
     231    }
     232}
     233
     234/*!
     235   Build and assign a pen for the minor grid lines
     236
     237   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     238   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     239   to hide this incompatibility.
     240
     241   \param color Pen color
     242   \param width Pen width
     243   \param style Pen style
     244
     245   \sa pen(), brush()
     246 */
     247void QwtPlotGrid::setMinorPen( const QColor& color, qreal width, Qt::PenStyle style )
    243248{
    244249    setMinorPen( QPen( color, width, style ) );
    … …  
    246251
    247252/*!
    248   Assign a pen for the minor grid lines
    249 
    250   \param pen Pen
    251   \sa minorPen(), setMajorPen(), setPen()
    252 */
    253 void QwtPlotGrid::setMinorPen( const QPen &pen )
    254 {
    255     if ( d_data->minorPen != pen )
    256     {
    257         d_data->minorPen = pen;
    258 
    259         legendChanged();
    260         itemChanged();
    261     }
    262 }
    263 
    264 /*!
    265   \brief Draw the grid
    266 
    267   The grid is drawn into the bounding rectangle such that
    268   grid lines begin and end at the rectangle's borders. The X and Y
    269   maps are used to map the scale divisions into the drawing region
    270   screen.
    271 
    272   \param painter  Painter
    273   \param xMap X axis map
    274   \param yMap Y axis
    275   \param canvasRect Contents rectangle of the plot canvas
    276 */
    277 void QwtPlotGrid::draw( QPainter *painter,
    278     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    279     const QRectF &canvasRect ) const
     253   Assign a pen for the minor grid lines
     254
     255   \param pen Pen
     256   \sa minorPen(), setMajorPen(), setPen()
     257 */
     258void QwtPlotGrid::setMinorPen( const QPen& pen )
     259{
     260    if ( m_data->minorPen != pen )
     261    {
     262        m_data->minorPen = pen;
     263
     264        legendChanged();
     265        itemChanged();
     266    }
     267}
     268
     269/*!
     270   \brief Draw the grid
     271
     272   The grid is drawn into the bounding rectangle such that
     273   grid lines begin and end at the rectangle's borders. The X and Y
     274   maps are used to map the scale divisions into the drawing region
     275   screen.
     276
     277   \param painter  Painter
     278   \param xMap X axis map
     279   \param yMap Y axis
     280   \param canvasRect Contents rectangle of the plot canvas
     281 */
     282void QwtPlotGrid::draw( QPainter* painter,
     283    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     284    const QRectF& canvasRect ) const
    280285{
    281286    //  draw minor grid lines
    282     QPen minorPen = d_data->minorPen;
     287    QPen minorPen = m_data->minorPen;
    283288    minorPen.setCapStyle( Qt::FlatCap );
    284289
    285290    painter->setPen( minorPen );
    286291
    287     if ( d_data->xEnabled && d_data->xMinEnabled )
     292    if ( m_data->xEnabled && m_data->xMinEnabled )
    288293    {
    289294        drawLines( painter, canvasRect, Qt::Vertical, xMap,
    290             d_data->xScaleDiv.ticks( QwtScaleDiv::MinorTick ) );
     295            m_data->xScaleDiv.ticks( QwtScaleDiv::MinorTick ) );
    291296        drawLines( painter, canvasRect, Qt::Vertical, xMap,
    292             d_data->xScaleDiv.ticks( QwtScaleDiv::MediumTick ) );
    293     }
    294 
    295     if ( d_data->yEnabled && d_data->yMinEnabled )
     297            m_data->xScaleDiv.ticks( QwtScaleDiv::MediumTick ) );
     298    }
     299
     300    if ( m_data->yEnabled && m_data->yMinEnabled )
    296301    {
    297302        drawLines( painter, canvasRect, Qt::Horizontal, yMap,
    298             d_data->yScaleDiv.ticks( QwtScaleDiv::MinorTick ) );
     303            m_data->yScaleDiv.ticks( QwtScaleDiv::MinorTick ) );
    299304        drawLines( painter, canvasRect, Qt::Horizontal, yMap,
    300             d_data->yScaleDiv.ticks( QwtScaleDiv::MediumTick ) );
     305            m_data->yScaleDiv.ticks( QwtScaleDiv::MediumTick ) );
    301306    }
    302307
    303308    //  draw major grid lines
    304     QPen majorPen = d_data->majorPen;
     309    QPen majorPen = m_data->majorPen;
    305310    majorPen.setCapStyle( Qt::FlatCap );
    306311
    307312    painter->setPen( majorPen );
    308313
    309     if ( d_data->xEnabled )
     314    if ( m_data->xEnabled )
    310315    {
    311316        drawLines( painter, canvasRect, Qt::Vertical, xMap,
    312             d_data->xScaleDiv.ticks( QwtScaleDiv::MajorTick ) );
    313     }
    314 
    315     if ( d_data->yEnabled )
     317            m_data->xScaleDiv.ticks( QwtScaleDiv::MajorTick ) );
     318    }
     319
     320    if ( m_data->yEnabled )
    316321    {
    317322        drawLines( painter, canvasRect, Qt::Horizontal, yMap,
    318             d_data->yScaleDiv.ticks( QwtScaleDiv::MajorTick ) );
    319     }
    320 }
    321 
    322 void QwtPlotGrid::drawLines( QPainter *painter, const QRectF &canvasRect,
    323     Qt::Orientation orientation, const QwtScaleMap &scaleMap,
    324     const QList<double> &values ) const
     323            m_data->yScaleDiv.ticks( QwtScaleDiv::MajorTick ) );
     324    }
     325}
     326
     327void QwtPlotGrid::drawLines( QPainter* painter, const QRectF& canvasRect,
     328    Qt::Orientation orientation, const QwtScaleMap& scaleMap,
     329    const QList< double >& values ) const
    325330{
    326331    const double x1 = canvasRect.left();
    … …  
    340345        {
    341346            if ( qwtFuzzyGreaterOrEqual( value, y1 ) &&
    342                 qwtFuzzyLessOrEqual( value, y2 ) )
     347                qwtFuzzyGreaterOrEqual( y2, value ) )
    343348            {
    344349                QwtPainter::drawLine( painter, x1, value, x2, value );
    … …  
    348353        {
    349354            if ( qwtFuzzyGreaterOrEqual( value, x1 ) &&
    350                 qwtFuzzyLessOrEqual( value, x2 ) )
     355                qwtFuzzyGreaterOrEqual( x2, value ) )
    351356            {
    352357                QwtPainter::drawLine( painter, value, y1, value, y2 );
    … …  
    357362
    358363/*!
    359   \return the pen for the major grid lines
    360   \sa setMajorPen(), setMinorPen(), setPen()
    361 */
    362 const QPen &QwtPlotGrid::majorPen() const
    363 {
    364     return d_data->majorPen;
    365 }
    366 
    367 /*!
    368   \return the pen for the minor grid lines
    369   \sa setMinorPen(), setMajorPen(), setPen()
    370 */
    371 const QPen &QwtPlotGrid::minorPen() const
    372 {
    373     return d_data->minorPen;
    374 }
    375 
    376 /*!
    377   \return true if vertical grid lines are enabled
    378   \sa enableX()
    379 */
     364   \return the pen for the major grid lines
     365   \sa setMajorPen(), setMinorPen(), setPen()
     366 */
     367const QPen& QwtPlotGrid::majorPen() const
     368{
     369    return m_data->majorPen;
     370}
     371
     372/*!
     373   \return the pen for the minor grid lines
     374   \sa setMinorPen(), setMajorPen(), setPen()
     375 */
     376const QPen& QwtPlotGrid::minorPen() const
     377{
     378    return m_data->minorPen;
     379}
     380
     381/*!
     382   \return true if vertical grid lines are enabled
     383   \sa enableX()
     384 */
    380385bool QwtPlotGrid::xEnabled() const
    381386{
    382     return d_data->xEnabled;
    383 }
    384 
    385 /*!
    386   \return true if minor vertical grid lines are enabled
    387   \sa enableXMin()
    388 */
     387    return m_data->xEnabled;
     388}
     389
     390/*!
     391   \return true if minor vertical grid lines are enabled
     392   \sa enableXMin()
     393 */
    389394bool QwtPlotGrid::xMinEnabled() const
    390395{
    391     return d_data->xMinEnabled;
    392 }
    393 
    394 /*!
    395   \return true if horizontal grid lines are enabled
    396   \sa enableY()
    397 */
     396    return m_data->xMinEnabled;
     397}
     398
     399/*!
     400   \return true if horizontal grid lines are enabled
     401   \sa enableY()
     402 */
    398403bool QwtPlotGrid::yEnabled() const
    399404{
    400     return d_data->yEnabled;
    401 }
    402 
    403 /*!
    404   \return true if minor horizontal grid lines are enabled
    405   \sa enableYMin()
    406 */
     405    return m_data->yEnabled;
     406}
     407
     408/*!
     409   \return true if minor horizontal grid lines are enabled
     410   \sa enableYMin()
     411 */
    407412bool QwtPlotGrid::yMinEnabled() const
    408413{
    409     return d_data->yMinEnabled;
     414    return m_data->yMinEnabled;
    410415}
    411416
    412417
    413418/*! \return the scale division of the x axis */
    414 const QwtScaleDiv &QwtPlotGrid::xScaleDiv() const
    415 {
    416     return d_data->xScaleDiv;
     419const QwtScaleDiv& QwtPlotGrid::xScaleDiv() const
     420{
     421    return m_data->xScaleDiv;
    417422}
    418423
    419424/*! \return the scale division of the y axis */
    420 const QwtScaleDiv &QwtPlotGrid::yScaleDiv() const
    421 {
    422     return d_data->yScaleDiv;
     425const QwtScaleDiv& QwtPlotGrid::yScaleDiv() const
     426{
     427    return m_data->yScaleDiv;
    423428}
    424429
    … …  
    430435
    431436   \sa QwtPlot::updateAxes()
    432 */
     437 */
    433438void QwtPlotGrid::updateScaleDiv( const QwtScaleDiv& xScaleDiv,
    434439    const QwtScaleDiv& yScaleDiv )
  • trunk/BNC/qwt/qwt_plot_grid.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_item.h"
    15 #include "qwt_scale_div.h"
    1615
    1716class QPainter;
    … …  
    2120
    2221/*!
    23   \brief A class which draws a coordinate grid
     22   \brief A class which draws a coordinate grid
    2423
    25   The QwtPlotGrid class can be used to draw a coordinate grid.
    26   A coordinate grid consists of major and minor vertical
    27   and horizontal grid lines. The locations of the grid lines
    28   are determined by the X and Y scale divisions which can
    29   be assigned with setXDiv() and setYDiv().
    30   The draw() member draws the grid within a bounding
    31   rectangle.
    32 */
     24   The QwtPlotGrid class can be used to draw a coordinate grid.
     25   A coordinate grid consists of major and minor vertical
     26   and horizontal grid lines. The locations of the grid lines
     27   are determined by the X and Y scale divisions which can
     28   be assigned with setXDiv() and setYDiv().
     29   The draw() member draws the grid within a bounding
     30   rectangle.
     31 */
    3332
    34 class QWT_EXPORT QwtPlotGrid: public QwtPlotItem
     33class QWT_EXPORT QwtPlotGrid : public QwtPlotItem
    3534{
    36 public:
     35  public:
    3736    explicit QwtPlotGrid();
    3837    virtual ~QwtPlotGrid();
    3938
    40     virtual int rtti() const;
     39    virtual int rtti() const QWT_OVERRIDE;
    4140
    4241    void enableX( bool );
    … …  
    5251    bool yMinEnabled() const;
    5352
    54     void setXDiv( const QwtScaleDiv & );
    55     const QwtScaleDiv &xScaleDiv() const;
     53    void setXDiv( const QwtScaleDiv& );
     54    const QwtScaleDiv& xScaleDiv() const;
    5655
    57     void setYDiv( const QwtScaleDiv & );
    58     const QwtScaleDiv &yScaleDiv() const;
     56    void setYDiv( const QwtScaleDiv& );
     57    const QwtScaleDiv& yScaleDiv() const;
    5958
    60     void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    61     void setPen( const QPen & );
     59    void setPen( const QColor&,
     60        qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    6261
    63     void setMajorPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    64     void setMajorPen( const QPen & );
     62    void setPen( const QPen& );
     63
     64    void setMajorPen( const QColor&,
     65        qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
     66
     67    void setMajorPen( const QPen& );
    6568    const QPen& majorPen() const;
    6669
    67     void setMinorPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    68     void setMinorPen( const QPen & );
     70    void setMinorPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
     71    void setMinorPen( const QPen& );
    6972    const QPen& minorPen() const;
    7073
    71     virtual void draw( QPainter *,
    72         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    73         const QRectF &canvasRect ) const;
     74    virtual void draw( QPainter*,
     75        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     76        const QRectF& canvasRect ) const QWT_OVERRIDE;
    7477
    7578    virtual void updateScaleDiv(
    76         const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv );
     79        const QwtScaleDiv& xScaleDiv, const QwtScaleDiv& yScaleDiv ) QWT_OVERRIDE;
    7780
    78 private:
    79     void drawLines( QPainter *, const QRectF &,
    80         Qt::Orientation, const QwtScaleMap &,
    81         const QList<double> & ) const;
     81  private:
     82    void drawLines( QPainter*, const QRectF&,
     83        Qt::Orientation, const QwtScaleMap&,
     84        const QList< double >& ) const;
    8285
    8386    class PrivateData;
    84     PrivateData *d_data;
     87    PrivateData* m_data;
    8588};
    8689
  • trunk/BNC/qwt/qwt_plot_histogram.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_histogram.h"
    11 #include "qwt_plot.h"
    1211#include "qwt_painter.h"
    1312#include "qwt_column_symbol.h"
    1413#include "qwt_scale_map.h"
     14#include "qwt_graphic.h"
     15
    1516#include <qstring.h>
    1617#include <qpainter.h>
    1718
    18 static inline bool qwtIsCombinable( const QwtInterval &d1,
    19     const QwtInterval &d2 )
     19static inline bool qwtIsCombinable( const QwtInterval& d1,
     20    const QwtInterval& d2 )
    2021{
    2122    if ( d1.isValid() && d2.isValid() )
    … …  
    3637class QwtPlotHistogram::PrivateData
    3738{
    38 public:
    39     PrivateData():
    40         baseline( 0.0 ),
    41         style( Columns ),
    42         symbol( NULL )
     39  public:
     40    PrivateData()
     41        : baseline( 0.0 )
     42        , style( Columns )
     43        , symbol( NULL )
    4344    {
    4445    }
    … …  
    5455    QBrush brush;
    5556    QwtPlotHistogram::HistogramStyle style;
    56     const QwtColumnSymbol *symbol;
     57    const QwtColumnSymbol* symbol;
    5758};
    5859
    5960/*!
    60   Constructor
    61   \param title Title of the histogram.
    62 */
    63 QwtPlotHistogram::QwtPlotHistogram( const QwtText &title ):
    64     QwtPlotSeriesItem( title )
     61   Constructor
     62   \param title Title of the histogram.
     63 */
     64QwtPlotHistogram::QwtPlotHistogram( const QwtText& title )
     65    : QwtPlotSeriesItem( title )
    6566{
    6667    init();
    … …  
    6869
    6970/*!
    70   Constructor
    71   \param title Title of the histogram.
    72 */
    73 QwtPlotHistogram::QwtPlotHistogram( const QString &title ):
    74     QwtPlotSeriesItem( title )
     71   Constructor
     72   \param title Title of the histogram.
     73 */
     74QwtPlotHistogram::QwtPlotHistogram( const QString& title )
     75    : QwtPlotSeriesItem( title )
    7576{
    7677    init();
    … …  
    8081QwtPlotHistogram::~QwtPlotHistogram()
    8182{
    82     delete d_data;
     83    delete m_data;
    8384}
    8485
    … …  
    8687void QwtPlotHistogram::init()
    8788{
    88     d_data = new PrivateData();
     89    m_data = new PrivateData();
    8990    setData( new QwtIntervalSeriesData() );
    9091
    … …  
    9697
    9798/*!
    98   Set the histogram's drawing style
    99 
    100   \param style Histogram style
    101   \sa HistogramStyle, style()
    102 */
     99   Set the histogram's drawing style
     100
     101   \param style Histogram style
     102   \sa HistogramStyle, style()
     103 */
    103104void QwtPlotHistogram::setStyle( HistogramStyle style )
    104105{
    105     if ( style != d_data->style )
    106     {
    107         d_data->style = style;
     106    if ( style != m_data->style )
     107    {
     108        m_data->style = style;
    108109
    109110        legendChanged();
    … …  
    115116    \return Style of the histogram
    116117    \sa HistogramStyle, setStyle()
    117 */
     118 */
    118119QwtPlotHistogram::HistogramStyle QwtPlotHistogram::style() const
    119120{
    120     return d_data->style;
    121 }
    122 
    123 /*!
    124   Build and assign a pen
    125 
    126   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    127   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    128   to hide this incompatibility.
    129 
    130   \param color Pen color
    131   \param width Pen width
    132   \param style Pen style
    133 
    134   \sa pen(), brush()
    135  */
    136 void QwtPlotHistogram::setPen( const QColor &color, qreal width, Qt::PenStyle style )
     121    return m_data->style;
     122}
     123
     124/*!
     125   Build and assign a pen
     126
     127   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     128   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     129   to hide this incompatibility.
     130
     131   \param color Pen color
     132   \param width Pen width
     133   \param style Pen style
     134
     135   \sa pen(), brush()
     136 */
     137void QwtPlotHistogram::setPen( const QColor& color, qreal width, Qt::PenStyle style )
    137138{
    138139    setPen( QPen( color, width, style ) );
    … …  
    140141
    141142/*!
    142   Assign a pen, that is used in a style() depending way.
    143 
    144   \param pen New pen
    145   \sa pen(), brush()
    146 */
    147 void QwtPlotHistogram::setPen( const QPen &pen )
    148 {
    149     if ( pen != d_data->pen )
    150     {
    151         d_data->pen = pen;
     143   Assign a pen, that is used in a style() depending way.
     144
     145   \param pen New pen
     146   \sa pen(), brush()
     147 */
     148void QwtPlotHistogram::setPen( const QPen& pen )
     149{
     150    if ( pen != m_data->pen )
     151    {
     152        m_data->pen = pen;
    152153
    153154        legendChanged();
    … …  
    157158
    158159/*!
    159   \return Pen used in a style() depending way.
    160   \sa setPen(), brush()
    161 */
    162 const QPen &QwtPlotHistogram::pen() const
    163 {
    164     return d_data->pen;
    165 }
    166 
    167 /*!
    168   Assign a brush, that is used in a style() depending way.
    169 
    170   \param brush New brush
    171   \sa pen(), brush()
    172 */
    173 void QwtPlotHistogram::setBrush( const QBrush &brush )
    174 {
    175     if ( brush != d_data->brush )
    176     {
    177         d_data->brush = brush;
     160   \return Pen used in a style() depending way.
     161   \sa setPen(), brush()
     162 */
     163const QPen& QwtPlotHistogram::pen() const
     164{
     165    return m_data->pen;
     166}
     167
     168/*!
     169   Assign a brush, that is used in a style() depending way.
     170
     171   \param brush New brush
     172   \sa pen(), brush()
     173 */
     174void QwtPlotHistogram::setBrush( const QBrush& brush )
     175{
     176    if ( brush != m_data->brush )
     177    {
     178        m_data->brush = brush;
    178179
    179180        legendChanged();
    … …  
    183184
    184185/*!
    185   \return Brush used in a style() depending way.
    186   \sa setPen(), brush()
    187 */
    188 const QBrush &QwtPlotHistogram::brush() const
    189 {
    190     return d_data->brush;
    191 }
    192 
    193 /*!
    194   \brief Assign a symbol
    195 
    196   In Column style an optional symbol can be assigned, that is responsible
    197   for displaying the rectangle that is defined by the interval and
    198   the distance between baseline() and value. When no symbol has been
    199   defined the area is displayed as plain rectangle using pen() and brush().
    200 
    201   \sa style(), symbol(), drawColumn(), pen(), brush()
    202 
    203   \note In applications, where different intervals need to be displayed
     186   \return Brush used in a style() depending way.
     187   \sa setPen(), brush()
     188 */
     189const QBrush& QwtPlotHistogram::brush() const
     190{
     191    return m_data->brush;
     192}
     193
     194/*!
     195   \brief Assign a symbol
     196
     197   In Column style an optional symbol can be assigned, that is responsible
     198   for displaying the rectangle that is defined by the interval and
     199   the distance between baseline() and value. When no symbol has been
     200   defined the area is displayed as plain rectangle using pen() and brush().
     201
     202   \sa style(), symbol(), drawColumn(), pen(), brush()
     203
     204   \note In applications, where different intervals need to be displayed
    204205        in a different way ( f.e different colors or even using different symbols)
    205206        it is recommended to overload drawColumn().
    206 */
    207 void QwtPlotHistogram::setSymbol( const QwtColumnSymbol *symbol )
    208 {
    209     if ( symbol != d_data->symbol )
    210     {
    211         delete d_data->symbol;
    212         d_data->symbol = symbol;
     207 */
     208void QwtPlotHistogram::setSymbol( const QwtColumnSymbol* symbol )
     209{
     210    if ( symbol != m_data->symbol )
     211    {
     212        delete m_data->symbol;
     213        m_data->symbol = symbol;
    213214
    214215        legendChanged();
    … …  
    218219
    219220/*!
    220   \return Current symbol or NULL, when no symbol has been assigned
    221   \sa setSymbol()
    222 */
    223 const QwtColumnSymbol *QwtPlotHistogram::symbol() const
    224 {
    225     return d_data->symbol;
    226 }
    227 
    228 /*!
    229   \brief Set the value of the baseline
    230 
    231   Each column representing an QwtIntervalSample is defined by its
    232   interval and the interval between baseline and the value of the sample.
    233 
    234   The default value of the baseline is 0.0.
    235 
    236   \param value Value of the baseline
    237   \sa baseline()
    238 */
     221   \return Current symbol or NULL, when no symbol has been assigned
     222   \sa setSymbol()
     223 */
     224const QwtColumnSymbol* QwtPlotHistogram::symbol() const
     225{
     226    return m_data->symbol;
     227}
     228
     229/*!
     230   \brief Set the value of the baseline
     231
     232   Each column representing an QwtIntervalSample is defined by its
     233   interval and the interval between baseline and the value of the sample.
     234
     235   The default value of the baseline is 0.0.
     236
     237   \param value Value of the baseline
     238   \sa baseline()
     239 */
    239240void QwtPlotHistogram::setBaseline( double value )
    240241{
    241     if ( d_data->baseline != value )
    242     {
    243         d_data->baseline = value;
     242    if ( m_data->baseline != value )
     243    {
     244        m_data->baseline = value;
    244245        itemChanged();
    245246    }
    … …  
    247248
    248249/*!
    249   \return Value of the baseline
    250   \sa setBaseline()
    251 */
     250   \return Value of the baseline
     251   \sa setBaseline()
     252 */
    252253double QwtPlotHistogram::baseline() const
    253254{
    254     return d_data->baseline;
    255 }
    256 
    257 /*!
    258   \return Bounding rectangle of all samples.
    259   For an empty series the rectangle is invalid.
    260 */
     255    return m_data->baseline;
     256}
     257
     258/*!
     259   \return Bounding rectangle of all samples.
     260   For an empty series the rectangle is invalid.
     261 */
    261262QRectF QwtPlotHistogram::boundingRect() const
    262263{
    … …  
    270271            rect.height(), rect.width() );
    271272
    272         if ( rect.left() > d_data->baseline )
    273             rect.setLeft( d_data->baseline );
    274         else if ( rect.right() < d_data->baseline )
    275             rect.setRight( d_data->baseline );
     273        if ( rect.left() > m_data->baseline )
     274            rect.setLeft( m_data->baseline );
     275        else if ( rect.right() < m_data->baseline )
     276            rect.setRight( m_data->baseline );
    276277    }
    277278    else
    278279    {
    279         if ( rect.bottom() < d_data->baseline )
    280             rect.setBottom( d_data->baseline );
    281         else if ( rect.top() > d_data->baseline )
    282             rect.setTop( d_data->baseline );
     280        if ( rect.bottom() < m_data->baseline )
     281            rect.setBottom( m_data->baseline );
     282        else if ( rect.top() > m_data->baseline )
     283            rect.setTop( m_data->baseline );
    283284    }
    284285
    … …  
    293294
    294295/*!
    295   Initialize data with an array of samples.
    296   \param samples Vector of points
    297 */
     296   Initialize data with an array of samples.
     297   \param samples Vector of points
     298 */
    298299void QwtPlotHistogram::setSamples(
    299     const QVector<QwtIntervalSample> &samples )
     300    const QVector< QwtIntervalSample >& samples )
    300301{
    301302    setData( new QwtIntervalSeriesData( samples ) );
    … …  
    303304
    304305/*!
    305   Assign a series of samples
    306 
    307   setSamples() is just a wrapper for setData() without any additional
    308   value - beside that it is easier to find for the developer.
    309 
    310   \param data Data
    311   \warning The item takes ownership of the data object, deleting
     306   Assign a series of samples
     307
     308   setSamples() is just a wrapper for setData() without any additional
     309   value - beside that it is easier to find for the developer.
     310
     311   \param data Data
     312   \warning The item takes ownership of the data object, deleting
    312313           it when its not used anymore.
    313 */
     314 */
    314315void QwtPlotHistogram::setSamples(
    315     QwtSeriesData<QwtIntervalSample> *data )
     316    QwtSeriesData< QwtIntervalSample >* data )
    316317{
    317318    setData( data );
    … …  
    319320
    320321/*!
    321   Draw a subset of the histogram samples
    322 
    323   \param painter Painter
    324   \param xMap Maps x-values into pixel coordinates.
    325   \param yMap Maps y-values into pixel coordinates.
    326   \param canvasRect Contents rectangle of the canvas
    327   \param from Index of the first sample to be painted
    328   \param to Index of the last sample to be painted. If to < 0 the
     322   Draw a subset of the histogram samples
     323
     324   \param painter Painter
     325   \param xMap Maps x-values into pixel coordinates.
     326   \param yMap Maps y-values into pixel coordinates.
     327   \param canvasRect Contents rectangle of the canvas
     328   \param from Index of the first sample to be painted
     329   \param to Index of the last sample to be painted. If to < 0 the
    329330         series will be painted to its last sample.
    330331
    331   \sa drawOutline(), drawLines(), drawColumns
    332 */
    333 void QwtPlotHistogram::drawSeries( QPainter *painter,
    334     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    335     const QRectF &canvasRect, int from, int to ) const
     332   \sa drawOutline(), drawLines(), drawColumns
     333 */
     334void QwtPlotHistogram::drawSeries( QPainter* painter,
     335    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     336    const QRectF& canvasRect, int from, int to ) const
    336337{
    337338    Q_UNUSED( canvasRect )
    … …  
    343344        to = dataSize() - 1;
    344345
    345     switch ( d_data->style )
     346    switch ( m_data->style )
    346347    {
    347348        case Outline:
    … …  
    360361
    361362/*!
    362   Draw a histogram in Outline style()
    363 
    364   \param painter Painter
    365   \param xMap Maps x-values into pixel coordinates.
    366   \param yMap Maps y-values into pixel coordinates.
    367   \param from Index of the first sample to be painted
    368   \param to Index of the last sample to be painted. If to < 0 the
     363   Draw a histogram in Outline style()
     364
     365   \param painter Painter
     366   \param xMap Maps x-values into pixel coordinates.
     367   \param yMap Maps y-values into pixel coordinates.
     368   \param from Index of the first sample to be painted
     369   \param to Index of the last sample to be painted. If to < 0 the
    369370         histogram will be painted to its last point.
    370371
    371   \sa setStyle(), style()
    372   \warning The outline style requires, that the intervals are in increasing
     372   \sa setStyle(), style()
     373   \warning The outline style requires, that the intervals are in increasing
    373374           order and not overlapping.
    374 */
    375 void QwtPlotHistogram::drawOutline( QPainter *painter,
    376     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
     375 */
     376void QwtPlotHistogram::drawOutline( QPainter* painter,
     377    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
    377378    int from, int to ) const
    378379{
    … …  
    447448
    448449/*!
    449   Draw a histogram in Columns style()
    450 
    451   \param painter Painter
    452   \param xMap Maps x-values into pixel coordinates.
    453   \param yMap Maps y-values into pixel coordinates.
    454   \param from Index of the first sample to be painted
    455   \param to Index of the last sample to be painted. If to < 0 the
     450   Draw a histogram in Columns style()
     451
     452   \param painter Painter
     453   \param xMap Maps x-values into pixel coordinates.
     454   \param yMap Maps y-values into pixel coordinates.
     455   \param from Index of the first sample to be painted
     456   \param to Index of the last sample to be painted. If to < 0 the
    456457         histogram will be painted to its last point.
    457458
    458   \sa setStyle(), style(), setSymbol(), drawColumn()
    459 */
    460 void QwtPlotHistogram::drawColumns( QPainter *painter,
    461     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
     459   \sa setStyle(), style(), setSymbol(), drawColumn()
     460 */
     461void QwtPlotHistogram::drawColumns( QPainter* painter,
     462    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
    462463    int from, int to ) const
    463464{
    464     painter->setPen( d_data->pen );
    465     painter->setBrush( d_data->brush );
    466 
    467     const QwtSeriesData<QwtIntervalSample> *series = data();
     465    painter->setPen( m_data->pen );
     466    painter->setBrush( m_data->brush );
     467
     468    const QwtSeriesData< QwtIntervalSample >* series = data();
    468469
    469470    for ( int i = from; i <= to; i++ )
    … …  
    479480
    480481/*!
    481   Draw a histogram in Lines style()
    482 
    483   \param painter Painter
    484   \param xMap Maps x-values into pixel coordinates.
    485   \param yMap Maps y-values into pixel coordinates.
    486   \param from Index of the first sample to be painted
    487   \param to Index of the last sample to be painted. If to < 0 the
     482   Draw a histogram in Lines style()
     483
     484   \param painter Painter
     485   \param xMap Maps x-values into pixel coordinates.
     486   \param yMap Maps y-values into pixel coordinates.
     487   \param from Index of the first sample to be painted
     488   \param to Index of the last sample to be painted. If to < 0 the
    488489         histogram will be painted to its last point.
    489490
    490   \sa setStyle(), style(), setPen()
    491 */
    492 void QwtPlotHistogram::drawLines( QPainter *painter,
    493     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
     491   \sa setStyle(), style(), setPen()
     492 */
     493void QwtPlotHistogram::drawLines( QPainter* painter,
     494    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
    494495    int from, int to ) const
    495496{
    496497    const bool doAlign = QwtPainter::roundingAlignment( painter );
    497498
    498     painter->setPen( d_data->pen );
     499    painter->setPen( m_data->pen );
    499500    painter->setBrush( Qt::NoBrush );
    500501
    501     const QwtSeriesData<QwtIntervalSample> *series = data();
     502    const QwtSeriesData< QwtIntervalSample >* series = data();
    502503
    503504    for ( int i = from; i <= to; i++ )
    … …  
    549550
    550551//! Internal, used by the Outline style.
    551 void QwtPlotHistogram::flushPolygon( QPainter *painter,
    552     double baseLine, QPolygonF &polygon ) const
     552void QwtPlotHistogram::flushPolygon( QPainter* painter,
     553    double baseLine, QPolygonF& polygon ) const
    553554{
    554555    if ( polygon.size() == 0 )
    … …  
    560561        polygon += QPointF( polygon.last().x(), baseLine );
    561562
    562     if ( d_data->brush.style() != Qt::NoBrush )
     563    if ( m_data->brush.style() != Qt::NoBrush )
    563564    {
    564565        painter->setPen( Qt::NoPen );
    565         painter->setBrush( d_data->brush );
     566        painter->setBrush( m_data->brush );
    566567
    567568        if ( orientation() == Qt::Horizontal )
    … …  
    581582        polygon.pop_back();
    582583    }
    583     if ( d_data->pen.style() != Qt::NoPen )
     584    if ( m_data->pen.style() != Qt::NoPen )
    584585    {
    585586        painter->setBrush( Qt::NoBrush );
    586         painter->setPen( d_data->pen );
     587        painter->setPen( m_data->pen );
    587588        QwtPainter::drawPolyline( painter, polygon );
    588589    }
    … …  
    591592
    592593/*!
    593   Calculate the area that is covered by a sample
    594 
    595   \param sample Sample
    596   \param xMap Maps x-values into pixel coordinates.
    597   \param yMap Maps y-values into pixel coordinates.
    598 
    599   \return Rectangle, that is covered by a sample
    600 */
    601 QwtColumnRect QwtPlotHistogram::columnRect( const QwtIntervalSample &sample,
    602     const QwtScaleMap &xMap, const QwtScaleMap &yMap ) const
     594   Calculate the area that is covered by a sample
     595
     596   \param sample Sample
     597   \param xMap Maps x-values into pixel coordinates.
     598   \param yMap Maps y-values into pixel coordinates.
     599
     600   \return Rectangle, that is covered by a sample
     601 */
     602QwtColumnRect QwtPlotHistogram::columnRect( const QwtIntervalSample& sample,
     603    const QwtScaleMap& xMap, const QwtScaleMap& yMap ) const
    603604{
    604605    QwtColumnRect rect;
    605606
    606     const QwtInterval &iv = sample.interval;
     607    const QwtInterval& iv = sample.interval;
    607608    if ( !iv.isValid() )
    608609        return rect;
    … …  
    611612    {
    612613        const double x0 = xMap.transform( baseline() );
    613         const double x  = xMap.transform( sample.value );
     614        const double x = xMap.transform( sample.value );
    614615        const double y1 = yMap.transform( iv.minValue() );
    615616        const double y2 = yMap.transform( iv.maxValue() );
    … …  
    618619        rect.vInterval.setInterval( y1, y2, iv.borderFlags() );
    619620        rect.direction = ( x < x0 ) ? QwtColumnRect::RightToLeft :
    620                          QwtColumnRect::LeftToRight;
     621            QwtColumnRect::LeftToRight;
    621622    }
    622623    else
    … …  
    637638
    638639/*!
    639   Draw a column for a sample in Columns style().
    640 
    641   When a symbol() has been set the symbol is used otherwise the
    642   column is displayed as plain rectangle using pen() and brush().
    643 
    644   \param painter Painter
    645   \param rect Rectangle where to paint the column in paint device coordinates
    646   \param sample Sample to be displayed
    647 
    648   \note In applications, where different intervals need to be displayed
     640   Draw a column for a sample in Columns style().
     641
     642   When a symbol() has been set the symbol is used otherwise the
     643   column is displayed as plain rectangle using pen() and brush().
     644
     645   \param painter Painter
     646   \param rect Rectangle where to paint the column in paint device coordinates
     647   \param sample Sample to be displayed
     648
     649   \note In applications, where different intervals need to be displayed
    649650        in a different way ( f.e different colors or even using different symbols)
    650651        it is recommended to overload drawColumn().
    651 */
    652 void QwtPlotHistogram::drawColumn( QPainter *painter,
    653     const QwtColumnRect &rect, const QwtIntervalSample &sample ) const
     652 */
     653void QwtPlotHistogram::drawColumn( QPainter* painter,
     654    const QwtColumnRect& rect, const QwtIntervalSample& sample ) const
    654655{
    655656    Q_UNUSED( sample );
    656657
    657     if ( d_data->symbol &&
    658         ( d_data->symbol->style() != QwtColumnSymbol::NoStyle ) )
    659     {
    660         d_data->symbol->draw( painter, rect );
     658    if ( m_data->symbol &&
     659        ( m_data->symbol->style() != QwtColumnSymbol::NoStyle ) )
     660    {
     661        m_data->symbol->draw( painter, rect );
    661662    }
    662663    else
    … …  
    676677
    677678/*!
    678   A plain rectangle without pen using the brush()
    679 
    680   \param index Index of the legend entry
     679   A plain rectangle without pen using the brush()
     680
     681   \param index Index of the legend entry
    681682                ( ignored as there is only one )
    682   \param size Icon size
    683   \return A graphic displaying the icon
    684 
    685   \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
    686 */
    687 QwtGraphic QwtPlotHistogram::legendIcon( int index,
    688     const QSizeF &size ) const
     683   \param size Icon size
     684   \return A graphic displaying the icon
     685
     686   \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
     687 */
     688QwtGraphic QwtPlotHistogram::legendIcon( int index, const QSizeF& size ) const
    689689{
    690690    Q_UNUSED( index );
    691     return defaultIcon( d_data->brush, size );
    692 }
     691    return defaultIcon( m_data->brush, size );
     692}
  • trunk/BNC/qwt/qwt_plot_histogram.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_seriesitem.h"
    15 #include "qwt_column_symbol.h"
    16 #include <qcolor.h>
    17 #include <qvector.h>
    1815
    19 class QwtIntervalData;
    20 class QString;
     16class QwtColumnSymbol;
     17class QwtColumnRect;
     18class QColor;
    2119class QPolygonF;
    2220
     21#if QT_VERSION < 0x060000
     22template< typename T > class QVector;
     23#endif
     24
    2325/*!
    24   \brief QwtPlotHistogram represents a series of samples, where an interval
     26   \brief QwtPlotHistogram represents a series of samples, where an interval
    2527         is associated with a value ( \f$y = f([x1,x2])\f$ ).
    2628
    27   The representation depends on the style() and an optional symbol()
    28   that is displayed for each interval.
     29   The representation depends on the style() and an optional symbol()
     30   that is displayed for each interval.
    2931
    30   \note The term "histogram" is used in a different way in the areas of
     32   \note The term "histogram" is used in a different way in the areas of
    3133        digital image processing and statistics. Wikipedia introduces the
    3234        terms "image histogram" and "color histogram" to avoid confusions.
    … …  
    3436        is no applicable plot item for a "color histogram" yet.
    3537
    36   \sa QwtPlotBarChart, QwtPlotMultiBarChart
    37 */
     38   \sa QwtPlotBarChart, QwtPlotMultiBarChart
     39 */
    3840
    39 class QWT_EXPORT QwtPlotHistogram:
    40     public QwtPlotSeriesItem, public QwtSeriesStore<QwtIntervalSample>
     41class QWT_EXPORT QwtPlotHistogram
     42    : public QwtPlotSeriesItem
     43    , public QwtSeriesStore< QwtIntervalSample >
    4144{
    42 public:
     45  public:
    4346    /*!
    4447        Histogram styles.
    … …  
    4649
    4750        \sa setStyle(), style(), setSymbol(), symbol(), setBaseline()
    48     */
     51     */
    4952    enum HistogramStyle
    5053    {
    … …  
    7780    };
    7881
    79     explicit QwtPlotHistogram( const QString &title = QString() );
    80     explicit QwtPlotHistogram( const QwtText &title );
     82    explicit QwtPlotHistogram( const QString& title = QString() );
     83    explicit QwtPlotHistogram( const QwtText& title );
    8184    virtual ~QwtPlotHistogram();
    8285
    83     virtual int rtti() const;
     86    virtual int rtti() const QWT_OVERRIDE;
    8487
    85     void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    86     void setPen( const QPen & );
    87     const QPen &pen() const;
     88    void setPen( const QColor&,
     89        qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    8890
    89     void setBrush( const QBrush & );
    90     const QBrush &brush() const;
     91    void setPen( const QPen& );
     92    const QPen& pen() const;
    9193
    92     void setSamples( const QVector<QwtIntervalSample> & );
    93     void setSamples( QwtSeriesData<QwtIntervalSample> * );
     94    void setBrush( const QBrush& );
     95    const QBrush& brush() const;
     96
     97    void setSamples( const QVector< QwtIntervalSample >& );
     98    void setSamples( QwtSeriesData< QwtIntervalSample >* );
    9499
    95100    void setBaseline( double );
    … …  
    99104    HistogramStyle style() const;
    100105
    101     void setSymbol( const QwtColumnSymbol * );
    102     const QwtColumnSymbol *symbol() const;
     106    void setSymbol( const QwtColumnSymbol* );
     107    const QwtColumnSymbol* symbol() const;
    103108
    104     virtual void drawSeries( QPainter *,
    105         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    106         const QRectF &canvasRect, int from, int to ) const;
     109    virtual void drawSeries( QPainter*,
     110        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     111        const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE;
    107112
    108     virtual QRectF boundingRect() const;
     113    virtual QRectF boundingRect() const QWT_OVERRIDE;
    109114
    110     virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
     115    virtual QwtGraphic legendIcon(
     116        int index, const QSizeF& ) const QWT_OVERRIDE;
    111117
    112 protected:
    113     virtual QwtColumnRect columnRect( const QwtIntervalSample &,
    114         const QwtScaleMap &, const QwtScaleMap & ) const;
     118  protected:
     119    virtual QwtColumnRect columnRect( const QwtIntervalSample&,
     120        const QwtScaleMap&, const QwtScaleMap& ) const;
    115121
    116     virtual void drawColumn( QPainter *, const QwtColumnRect &,
    117         const QwtIntervalSample & ) const;
     122    virtual void drawColumn( QPainter*, const QwtColumnRect&,
     123        const QwtIntervalSample& ) const;
    118124
    119     void drawColumns( QPainter *,
    120         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
     125    void drawColumns( QPainter*,
     126        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
    121127        int from, int to ) const;
    122128
    123     void drawOutline( QPainter *,
    124         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
     129    void drawOutline( QPainter*,
     130        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
    125131        int from, int to ) const;
    126132
    127     void drawLines( QPainter *,
    128          const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    129          int from, int to ) const;
     133    void drawLines( QPainter*,
     134        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     135        int from, int to ) const;
    130136
    131 private:
     137  private:
    132138    void init();
    133     void flushPolygon( QPainter *, double baseLine, QPolygonF & ) const;
     139    void flushPolygon( QPainter*, double baseLine, QPolygonF& ) const;
    134140
    135141    class PrivateData;
    136     PrivateData *d_data;
     142    PrivateData* m_data;
    137143};
    138144
  • trunk/BNC/qwt/qwt_plot_intervalcurve.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_clipper.h"
    1414#include "qwt_painter.h"
    15 #include <string.h>
     15#include "qwt_graphic.h"
     16#include "qwt_text.h"
    1617
    1718#include <qpainter.h>
    18 
    19 static inline bool qwtIsHSampleInside( const QwtIntervalSample &sample,
     19#include <qmath.h>
     20#include <cstring>
     21
     22static inline bool qwtIsHSampleInside( const QwtIntervalSample& sample,
    2023    double xMin, double xMax, double yMin, double yMax )
    2124{
    … …  
    3033}
    3134
    32 static inline bool qwtIsVSampleInside( const QwtIntervalSample &sample,
     35static inline bool qwtIsVSampleInside( const QwtIntervalSample& sample,
    3336    double xMin, double xMax, double yMin, double yMax )
    3437{
    … …  
    4346}
    4447
    45 class QwtPlotIntervalCurve::PrivateData
    46 {
    47 public:
    48     PrivateData():
    49         style( QwtPlotIntervalCurve::Tube ),
    50         symbol( NULL ),
    51         pen( Qt::black ),
    52         brush( Qt::white )
    53     {
    54         paintAttributes = QwtPlotIntervalCurve::ClipPolygons;
    55         paintAttributes |= QwtPlotIntervalCurve::ClipSymbol;
    56 
    57         pen.setCapStyle( Qt::FlatCap );
    58     }
    59 
    60     ~PrivateData()
    61     {
    62         delete symbol;
    63     }
    64 
    65     QwtPlotIntervalCurve::CurveStyle style;
    66     const QwtIntervalSymbol *symbol;
    67 
    68     QPen pen;
    69     QBrush brush;
    70 
    71     QwtPlotIntervalCurve::PaintAttributes paintAttributes;
    72 };
    73 
    74 /*!
    75   Constructor
    76   \param title Title of the curve
    77 */
    78 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText &title ):
    79     QwtPlotSeriesItem( title )
    80 {
    81     init();
    82 }
    83 
    84 /*!
    85   Constructor
    86   \param title Title of the curve
    87 */
    88 QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString &title ):
    89     QwtPlotSeriesItem( QwtText( title ) )
    90 {
    91     init();
    92 }
    93 
    94 //! Destructor
    95 QwtPlotIntervalCurve::~QwtPlotIntervalCurve()
    96 {
    97     delete d_data;
    98 }
    99 
    100 //! Initialize internal members
    101 void QwtPlotIntervalCurve::init()
    102 {
    103     setItemAttribute( QwtPlotItem::Legend, true );
    104     setItemAttribute( QwtPlotItem::AutoScale, true );
    105 
    106     d_data = new PrivateData;
    107     setData( new QwtIntervalSeriesData() );
    108 
    109     setZ( 19.0 );
    110 }
    111 
    112 //! \return QwtPlotItem::Rtti_PlotIntervalCurve
    113 int QwtPlotIntervalCurve::rtti() const
    114 {
    115     return QwtPlotIntervalCurve::Rtti_PlotIntervalCurve;
    116 }
    117 
    118 /*!
    119   Specify an attribute how to draw the curve
    120 
    121   \param attribute Paint attribute
    122   \param on On/Off
    123   \sa testPaintAttribute()
    124 */
    125 void QwtPlotIntervalCurve::setPaintAttribute(
    126     PaintAttribute attribute, bool on )
    127 {
    128     if ( on )
    129         d_data->paintAttributes |= attribute;
     48static inline int qwtInterpolated( int from, int to, double ratio )
     49{
     50    return qRound( from + ratio * ( to - from ) );
     51}
     52
     53static int qwtStartIndex( int from, double min, double max,
     54    const QwtSeriesData< QwtIntervalSample >* samples )
     55{
     56    /*
     57        As we know, that the value coordinates are montonically
     58        increasing/decreasing we can find the first sample before
     59        entering the interval using a binary search algo.
     60     */
     61
     62    struct lessThan
     63    {
     64        inline bool operator()( const double value,
     65            const QwtIntervalSample& sample ) const
     66        {
     67            return value < sample.value;
     68        }
     69    };
     70
     71    struct greaterThan
     72    {
     73        inline bool operator()( const double value,
     74            const QwtIntervalSample& sample ) const
     75        {
     76            return value > sample.value;
     77        }
     78    };
     79
     80    int idx;
     81
     82    if ( samples->firstSample().value < samples->lastSample().value )
     83    {
     84        idx = qwtUpperSampleIndex< QwtIntervalSample >(
     85            *samples, min, lessThan() );
     86    }
    13087    else
    131         d_data->paintAttributes &= ~attribute;
    132 }
    133 
    134 /*!
    135     \return True, when attribute is enabled
    136     \sa PaintAttribute, setPaintAttribute()
    137 */
    138 bool QwtPlotIntervalCurve::testPaintAttribute(
    139     PaintAttribute attribute ) const
    140 {
    141     return ( d_data->paintAttributes & attribute );
    142 }
    143 
    144 /*!
    145   Initialize data with an array of samples.
    146   \param samples Vector of samples
    147 */
    148 void QwtPlotIntervalCurve::setSamples(
    149     const QVector<QwtIntervalSample> &samples )
    150 {
    151     setData( new QwtIntervalSeriesData( samples ) );
    152 }
    153 
    154 /*!
    155   Assign a series of samples
    156 
    157   setSamples() is just a wrapper for setData() without any additional
    158   value - beside that it is easier to find for the developer.
    159 
    160   \param data Data
    161   \warning The item takes ownership of the data object, deleting
    162            it when its not used anymore.
    163 */
    164 void QwtPlotIntervalCurve::setSamples(
    165     QwtSeriesData<QwtIntervalSample> *data )
    166 {
    167     setData( data );
    168 }
    169 
    170 /*!
    171   Set the curve's drawing style
    172 
    173   \param style Curve style
    174   \sa CurveStyle, style()
    175 */
    176 void QwtPlotIntervalCurve::setStyle( CurveStyle style )
    177 {
    178     if ( style != d_data->style )
    179     {
    180         d_data->style = style;
    181 
    182         legendChanged();
    183         itemChanged();
    184     }
    185 }
    186 
    187 /*!
    188     \return Style of the curve
    189     \sa setStyle()
    190 */
    191 QwtPlotIntervalCurve::CurveStyle QwtPlotIntervalCurve::style() const
    192 {
    193     return d_data->style;
    194 }
    195 
    196 /*!
    197   Assign a symbol.
    198 
    199   \param symbol Symbol
    200   \sa symbol()
    201 */
    202 void QwtPlotIntervalCurve::setSymbol( const QwtIntervalSymbol *symbol )
    203 {
    204     if ( symbol != d_data->symbol )
    205     {
    206         delete d_data->symbol;
    207         d_data->symbol = symbol;
    208 
    209         legendChanged();
    210         itemChanged();
    211     }
    212 }
    213 
    214 /*!
    215   \return Current symbol or NULL, when no symbol has been assigned
    216   \sa setSymbol()
    217 */
    218 const QwtIntervalSymbol *QwtPlotIntervalCurve::symbol() const
    219 {
    220     return d_data->symbol;
    221 }
    222 
    223 /*!
    224   Build and assign a pen
    225 
    226   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    227   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    228   to hide this incompatibility.
    229 
    230   \param color Pen color
    231   \param width Pen width
    232   \param style Pen style
    233 
    234   \sa pen(), brush()
    235  */
    236 void QwtPlotIntervalCurve::setPen( const QColor &color, qreal width, Qt::PenStyle style )
    237 {
    238     setPen( QPen( color, width, style ) );
    239 }
    240 
    241 /*!
    242   \brief Assign a pen
    243   \param pen New pen
    244   \sa pen(), brush()
    245 */
    246 void QwtPlotIntervalCurve::setPen( const QPen &pen )
    247 {
    248     if ( pen != d_data->pen )
    249     {
    250         d_data->pen = pen;
    251 
    252         legendChanged();
    253         itemChanged();
    254     }
    255 }
    256 
    257 /*!
    258     \return Pen used to draw the lines
    259     \sa setPen(), brush()
    260 */
    261 const QPen& QwtPlotIntervalCurve::pen() const
    262 {
    263     return d_data->pen;
    264 }
    265 
    266 /*!
    267   Assign a brush.
    268 
    269   The brush is used to fill the area in Tube style().
    270 
    271   \param brush Brush
    272   \sa brush(), pen(), setStyle(), CurveStyle
    273 */
    274 void QwtPlotIntervalCurve::setBrush( const QBrush &brush )
    275 {
    276     if ( brush != d_data->brush )
    277     {
    278         d_data->brush = brush;
    279 
    280         legendChanged();
    281         itemChanged();
    282     }
    283 }
    284 
    285 /*!
    286   \return Brush used to fill the area in Tube style()
    287   \sa setBrush(), setStyle(), CurveStyle
    288 */
    289 const QBrush& QwtPlotIntervalCurve::brush() const
    290 {
    291     return d_data->brush;
    292 }
    293 
    294 /*!
    295   \return Bounding rectangle of all samples.
    296   For an empty series the rectangle is invalid.
    297 */
    298 QRectF QwtPlotIntervalCurve::boundingRect() const
    299 {
    300     QRectF rect = QwtPlotSeriesItem::boundingRect();
    301     if ( orientation() == Qt::Vertical )
    302         rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() );
    303 
    304     return rect;
    305 }
    306 
    307 /*!
    308   Draw a subset of the samples
    309 
    310   \param painter Painter
    311   \param xMap Maps x-values into pixel coordinates.
    312   \param yMap Maps y-values into pixel coordinates.
    313   \param canvasRect Contents rectangle of the canvas
    314   \param from Index of the first sample to be painted
    315   \param to Index of the last sample to be painted. If to < 0 the
    316          series will be painted to its last sample.
    317 
    318   \sa drawTube(), drawSymbols()
    319 */
    320 void QwtPlotIntervalCurve::drawSeries( QPainter *painter,
    321     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    322     const QRectF &canvasRect, int from, int to ) const
    323 {
    324     if ( to < 0 )
    325         to = dataSize() - 1;
    326 
    327     if ( from < 0 )
    328         from = 0;
    329 
    330     if ( from > to )
    331         return;
    332 
    333     switch ( d_data->style )
    334     {
    335         case Tube:
    336             drawTube( painter, xMap, yMap, canvasRect, from, to );
    337             break;
    338 
    339         case NoCurve:
    340         default:
    341             break;
    342     }
    343 
    344     if ( d_data->symbol &&
    345         ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
    346     {
    347         drawSymbols( painter, *d_data->symbol,
    348             xMap, yMap, canvasRect, from, to );
    349     }
    350 }
    351 
    352 /*!
    353   Draw a tube
    354 
    355   Builds 2 curves from the upper and lower limits of the intervals
    356   and draws them with the pen(). The area between the curves is
    357   filled with the brush().
    358 
    359   \param painter Painter
    360   \param xMap Maps x-values into pixel coordinates.
    361   \param yMap Maps y-values into pixel coordinates.
    362   \param canvasRect Contents rectangle of the canvas
    363   \param from Index of the first sample to be painted
    364   \param to Index of the last sample to be painted. If to < 0 the
    365          series will be painted to its last sample.
    366 
    367   \sa drawSeries(), drawSymbols()
    368 */
    369 void QwtPlotIntervalCurve::drawTube( QPainter *painter,
    370     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    371     const QRectF &canvasRect, int from, int to ) const
     88    {
     89        idx = qwtUpperSampleIndex< QwtIntervalSample >(
     90            *samples, max, greaterThan() );
     91    }
     92
     93    if ( idx >= 0 )
     94    {
     95        idx = qMax( from, idx );
     96        if ( idx > 0 )
     97        {
     98            // we need to fill the area before the first sample
     99            idx--;
     100        }
     101    }
     102
     103    return idx;
     104}
     105
     106namespace
     107{
     108    class LinesRenderer
     109    {
     110      public:
     111        LinesRenderer( Qt::Orientation,
     112            const QwtScaleMap&, const QwtScaleMap&, const QRectF& );
     113
     114        void addSamples( const QwtSeriesData< QwtIntervalSample >*, int from, int to );
     115
     116        QVector< QLine > fillLines;
     117        QVector< QLine > borderLines;
     118
     119      private:
     120        bool addSample( const QwtIntervalSample& );
     121        void flush();
     122
     123        bool append( int value, int min, int max );
     124
     125        void addFillLineAt( int value, int min, int max );
     126        void addFillLines( int value, int min, int max );
     127
     128        void addBorderLineAt( int value, int min, int max );
     129        void addBorderLine( int, int, int, int );
     130
     131        const bool m_vertical;
     132
     133        const QwtScaleMap& m_valueMap;
     134        const QwtScaleMap& m_intervalMap;
     135
     136        const bool m_inverting;
     137        bool m_pending;
     138
     139        // all ints are in paint device coordinates
     140
     141        int m_intvMin, m_intvMax;   // interval boundaries of the canvas
     142        int m_valueMin, m_valueMax; // value boundaries of the canvas
     143
     144        int m_value; // value of the last sample being processed
     145
     146        struct
     147        {
     148            inline void reset( int value )
     149            {
     150                min = max = last = value;
     151            }
     152
     153            inline void extend( int value )
     154            {
     155                if ( value < min )
     156                    min = value;
     157                else if ( value > max )
     158                    max = value;
     159
     160                last = value;
     161            }
     162
     163            int min, max, last;
     164
     165        } m_lower, m_upper;
     166    };
     167
     168    LinesRenderer::LinesRenderer( Qt::Orientation orientation,
     169            const QwtScaleMap& xMap, const QwtScaleMap& yMap, const QRectF& rect )
     170        : m_vertical( orientation == Qt::Vertical )
     171        , m_valueMap( m_vertical ? xMap : yMap )
     172        , m_intervalMap( m_vertical ? yMap : xMap )
     173        , m_inverting( m_intervalMap.isInverting() )
     174        , m_pending( false )
     175        , m_value( 0 )
     176    {
     177        QRectF r = rect;
     178        if ( !m_vertical )
     179            r.setSize( QSizeF( r.height(), r.width() ) );
     180
     181        m_intvMin = qFloor( r.top() );
     182        m_intvMax = qCeil( r.bottom() );
     183
     184        m_valueMin = qFloor( r.left() );
     185        m_valueMax = qCeil( r.right() );
     186
     187        const int steps = m_valueMax - m_valueMin + 1;
     188
     189        // one line for each pixel
     190        fillLines.reserve( steps );
     191
     192        /*
     193            for both border lines:
     194                one line ( min/max ) of the samples lying on the same pixel
     195                one line connecting the pixels
     196         */
     197        borderLines.reserve( 4 * steps );
     198    }
     199
     200    void LinesRenderer::addSamples(
     201        const QwtSeriesData< QwtIntervalSample >* samples, int from, int to )
     202    {
     203        const double v1 = m_valueMap.invTransform( m_valueMin );
     204        const double v2 = m_valueMap.invTransform( m_valueMax );
     205
     206        from = qwtStartIndex( from, qMin( v1, v2 ), qMax( v1, v2 ), samples );
     207
     208        if ( from >= 0 )
     209        {
     210            for ( int i = from; i <= to; i++ )
     211            {
     212                if ( addSample( samples->sample( i ) ) )
     213                    break;
     214            }
     215        }
     216
     217        flush();
     218    }
     219
     220    inline bool LinesRenderer::addSample( const QwtIntervalSample& sample )
     221    {
     222        const double value = qRound( m_valueMap.transform( sample.value ) );
     223
     224        const int min = qRound( m_intervalMap.transform( sample.interval.minValue() ) );
     225        const int max = qRound( m_intervalMap.transform( sample.interval.maxValue() ) );
     226
     227        return m_inverting ? append( value, max, min ) : append( value, max, min );
     228    }
     229
     230    inline bool LinesRenderer::append(
     231        const int value, const int lower, const int upper )
     232    {
     233        if ( !m_pending )
     234        {
     235            m_value = value;
     236            m_lower.reset( lower );
     237            m_upper.reset( upper );
     238
     239            m_pending = true;
     240
     241            return false;
     242        }
     243
     244        if ( value != m_value )
     245        {
     246            addFillLines( value, lower, upper );
     247            addBorderLineAt( m_value, m_lower.min, m_lower.max );
     248            addBorderLineAt( m_value, m_upper.min, m_upper.max );
     249
     250            addBorderLine( m_value, m_lower.last, value, lower );
     251            addBorderLine( m_value, m_upper.last, value, upper );
     252
     253            if ( ( value > m_value ) ? ( value > m_valueMax ) : ( value < m_valueMin ) )
     254            {
     255                m_pending = false;
     256                return true;
     257            }
     258
     259            m_value = value;
     260
     261            m_lower.reset( lower );
     262            m_upper.reset( upper );
     263        }
     264        else
     265        {
     266            m_lower.extend( lower );
     267            m_upper.extend( upper );
     268        }
     269
     270        return false;
     271    }
     272
     273    inline void LinesRenderer::flush()
     274    {
     275        if ( m_pending )
     276        {
     277            addFillLineAt( m_value, m_lower.min, m_upper.max );
     278            addBorderLineAt( m_value, m_lower.min, m_lower.max );
     279            addBorderLineAt( m_value, m_upper.min, m_upper.max );
     280        }
     281    }
     282
     283    inline void LinesRenderer::addFillLines(
     284        const int value, const int lower, const int upper )
     285    {
     286        addFillLineAt( m_value, m_lower.min, m_upper.max );
     287
     288        const double delta = value - m_value;
     289
     290        if ( value > m_value )
     291        {
     292            for ( int v = m_value + 1; v < value; v++ )
     293            {
     294                const double ratio = ( v - m_value ) / delta;
     295
     296                addFillLineAt( v,
     297                    qwtInterpolated( m_lower.last, lower, ratio ),
     298                    qwtInterpolated( m_upper.last, upper, ratio ) );
     299            }
     300        }
     301        else
     302        {
     303            for ( int v = m_value - 1; v > value; v-- )
     304            {
     305                const double ratio = ( v - m_value ) / delta;
     306
     307                addFillLineAt( v,
     308                    qwtInterpolated( m_lower.last, lower, ratio ),
     309                    qwtInterpolated( m_upper.last, upper, ratio ) );
     310            }
     311        }
     312    }
     313
     314    inline void LinesRenderer::addFillLineAt( int value, int min, int max )
     315    {
     316        if ( ( min != max ) && ( max > m_intvMin ) && ( min < m_intvMax ) )
     317        {
     318            min = qMax( min, m_intvMin );
     319            max = qMin( max, m_intvMax );
     320
     321            if( m_vertical )
     322                fillLines += QLine( value, min, value, max );
     323            else
     324                fillLines += QLine( min, value, max, value );
     325        }
     326    }
     327
     328    inline void LinesRenderer::addBorderLineAt( int value, int min, int max )
     329    {
     330        if ( min != max )
     331            addBorderLine( value, min, value, max );
     332    }
     333
     334    inline void LinesRenderer::addBorderLine( int x1, int y1, int x2, int y2 )
     335    {
     336        if( m_vertical )
     337            borderLines += QLine( x1, y1, x2, y2 );
     338        else
     339            borderLines += QLine( y1, x1, y2, x2 );
     340    }
     341}
     342
     343static void qwtDrawTubeLines(
     344    const QwtPlotIntervalCurve* curve, QPainter* painter,
     345    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     346    const QRectF& canvasRect, int from, int to)
     347{
     348    LinesRenderer renderer( curve->orientation(), xMap, yMap, canvasRect );
     349    renderer.addSamples( curve->data(), from, to );
     350
     351    if ( curve->brush().style() != Qt::NoBrush )
     352    {
     353        painter->save();
     354
     355        painter->setPen( curve->brush().color() );
     356        painter->setRenderHint( QPainter::Antialiasing, false );
     357        painter->drawLines( renderer.fillLines );
     358
     359        painter->restore();
     360    }
     361
     362    if ( curve->pen().style() != Qt::NoPen )
     363    {
     364        painter->save();
     365
     366        painter->setPen( curve->pen() );
     367        painter->drawLines( renderer.borderLines );
     368
     369        painter->restore();
     370    }
     371}
     372
     373static void qwtDrawTube(
     374    const QwtPlotIntervalCurve* curve, QPainter* painter,
     375    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     376    const QRectF& canvasRect, int from, int to )
    372377{
    373378    const bool doAlign = QwtPainter::roundingAlignment( painter );
    … …  
    377382    const size_t size = to - from + 1;
    378383    QPolygonF polygon( 2 * size );
    379     QPointF *points = polygon.data();
     384    QPointF* points = polygon.data();
    380385
    381386    for ( uint i = 0; i < size; i++ )
    382387    {
    383         QPointF &minValue = points[i];
    384         QPointF &maxValue = points[2 * size - 1 - i];
    385 
    386         const QwtIntervalSample intervalSample = sample( from + i );
    387         if ( orientation() == Qt::Vertical )
     388        QPointF& minValue = points[i];
     389        QPointF& maxValue = points[2 * size - 1 - i];
     390
     391        const QwtIntervalSample intervalSample = curve->sample( from + i );
     392        if ( curve->orientation() == Qt::Vertical )
    388393        {
    389394            double x = xMap.transform( intervalSample.value );
    390395            double y1 = yMap.transform( intervalSample.interval.minValue() );
    391396            double y2 = yMap.transform( intervalSample.interval.maxValue() );
     397
    392398            if ( doAlign )
    393399            {
    … …  
    407413            double x1 = xMap.transform( intervalSample.interval.minValue() );
    408414            double x2 = xMap.transform( intervalSample.interval.maxValue() );
     415
    409416            if ( doAlign )
    410417            {
    … …  
    421428    }
    422429
    423     if ( d_data->brush.style() != Qt::NoBrush )
     430    const bool doClip = curve->testPaintAttribute( QwtPlotIntervalCurve::ClipPolygons );
     431
     432    if ( curve->brush().style() != Qt::NoBrush )
    424433    {
    425434        painter->setPen( QPen( Qt::NoPen ) );
    426         painter->setBrush( d_data->brush );
    427 
    428         if ( d_data->paintAttributes & ClipPolygons )
     435        painter->setBrush( curve->brush() );
     436
     437        if ( doClip )
    429438        {
    430439            const qreal m = 1.0;
    431             const QPolygonF p = QwtClipper::clipPolygonF(
    432                canvasRect.adjusted( -m, -m, m, m ), polygon, true );
     440            const QPolygonF p = QwtClipper::clippedPolygonF(
     441                canvasRect.adjusted( -m, -m, m, m ), polygon, true );
    433442
    434443            QwtPainter::drawPolygon( painter, p );
    … …  
    440449    }
    441450
    442     if ( d_data->pen.style() != Qt::NoPen )
    443     {
    444         painter->setPen( d_data->pen );
     451    if ( curve->pen().style() != Qt::NoPen )
     452    {
     453        painter->setPen( curve->pen() );
    445454        painter->setBrush( Qt::NoBrush );
    446455
    447         if ( d_data->paintAttributes & ClipPolygons )
    448         {
    449             qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF() );
     456        if ( doClip )
     457        {
     458            qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
    450459            const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
    451460
    452             QPolygonF p;
    453 
    454             p.resize( size );
    455             ::memcpy( p.data(), points, size * sizeof( QPointF ) );
    456             p = QwtClipper::clipPolygonF( clipRect, p );
    457             QwtPainter::drawPolyline( painter, p );
    458 
    459             p.resize( size );
    460             ::memcpy( p.data(), points + size, size * sizeof( QPointF ) );
    461             p = QwtClipper::clipPolygonF( clipRect, p );
    462             QwtPainter::drawPolyline( painter, p );
     461            QPolygonF p( size );
     462
     463            std::memcpy( p.data(), points, size * sizeof( QPointF ) );
     464            QwtPainter::drawPolyline( painter,
     465                QwtClipper::clippedPolygonF( clipRect, p ) );
     466
     467            std::memcpy( p.data(), points + size, size * sizeof( QPointF ) );
     468            QwtPainter::drawPolyline( painter,
     469                QwtClipper::clippedPolygonF( clipRect, p ) );
    463470        }
    464471        else
    … …  
    472479}
    473480
    474 /*!
    475   Draw symbols for a subset of the samples
    476 
    477   \param painter Painter
    478   \param symbol Interval symbol
    479   \param xMap x map
    480   \param yMap y map
    481   \param canvasRect Contents rectangle of the canvas
    482   \param from Index of the first sample to be painted
    483   \param to Index of the last sample to be painted
    484 
    485   \sa setSymbol(), drawSeries(), drawTube()
    486 */
     481class QwtPlotIntervalCurve::PrivateData
     482{
     483  public:
     484    PrivateData():
     485        style( QwtPlotIntervalCurve::Tube ),
     486        symbol( NULL ),
     487        pen( Qt::black ),
     488        brush( Qt::white )
     489    {
     490        paintAttributes = QwtPlotIntervalCurve::ClipPolygons;
     491        paintAttributes |= QwtPlotIntervalCurve::ClipSymbol;
     492
     493        pen.setCapStyle( Qt::FlatCap );
     494    }
     495
     496    ~PrivateData()
     497    {
     498        delete symbol;
     499    }
     500
     501    QwtPlotIntervalCurve::CurveStyle style;
     502    const QwtIntervalSymbol* symbol;
     503
     504    QPen pen;
     505    QBrush brush;
     506
     507    QwtPlotIntervalCurve::PaintAttributes paintAttributes;
     508};
     509
     510/*!
     511   Constructor
     512   \param title Title of the curve
     513 */
     514QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText& title )
     515    : QwtPlotSeriesItem( title )
     516{
     517    init();
     518}
     519
     520/*!
     521   Constructor
     522   \param title Title of the curve
     523 */
     524QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString& title )
     525    : QwtPlotSeriesItem( QwtText( title ) )
     526{
     527    init();
     528}
     529
     530//! Destructor
     531QwtPlotIntervalCurve::~QwtPlotIntervalCurve()
     532{
     533    delete m_data;
     534}
     535
     536//! Initialize internal members
     537void QwtPlotIntervalCurve::init()
     538{
     539    setItemAttribute( QwtPlotItem::Legend, true );
     540    setItemAttribute( QwtPlotItem::AutoScale, true );
     541
     542    m_data = new PrivateData;
     543    setData( new QwtIntervalSeriesData() );
     544
     545    setZ( 19.0 );
     546}
     547
     548//! \return QwtPlotItem::Rtti_PlotIntervalCurve
     549int QwtPlotIntervalCurve::rtti() const
     550{
     551    return QwtPlotIntervalCurve::Rtti_PlotIntervalCurve;
     552}
     553
     554/*!
     555   Specify an attribute how to draw the curve
     556
     557   \param attribute Paint attribute
     558   \param on On/Off
     559   \sa testPaintAttribute()
     560 */
     561void QwtPlotIntervalCurve::setPaintAttribute(
     562    PaintAttribute attribute, bool on )
     563{
     564    if ( on )
     565        m_data->paintAttributes |= attribute;
     566    else
     567        m_data->paintAttributes &= ~attribute;
     568}
     569
     570/*!
     571    \return True, when attribute is enabled
     572    \sa PaintAttribute, setPaintAttribute()
     573 */
     574bool QwtPlotIntervalCurve::testPaintAttribute(
     575    PaintAttribute attribute ) const
     576{
     577    return ( m_data->paintAttributes & attribute );
     578}
     579
     580/*!
     581   Initialize data with an array of samples.
     582   \param samples Vector of samples
     583 */
     584void QwtPlotIntervalCurve::setSamples(
     585    const QVector< QwtIntervalSample >& samples )
     586{
     587    setData( new QwtIntervalSeriesData( samples ) );
     588}
     589
     590/*!
     591   Assign a series of samples
     592
     593   setSamples() is just a wrapper for setData() without any additional
     594   value - beside that it is easier to find for the developer.
     595
     596   \param data Data
     597   \warning The item takes ownership of the data object, deleting
     598           it when its not used anymore.
     599 */
     600void QwtPlotIntervalCurve::setSamples(
     601    QwtSeriesData< QwtIntervalSample >* data )
     602{
     603    setData( data );
     604}
     605
     606/*!
     607   Set the curve's drawing style
     608
     609   \param style Curve style
     610   \sa CurveStyle, style()
     611 */
     612void QwtPlotIntervalCurve::setStyle( CurveStyle style )
     613{
     614    if ( style != m_data->style )
     615    {
     616        m_data->style = style;
     617
     618        legendChanged();
     619        itemChanged();
     620    }
     621}
     622
     623/*!
     624    \return Style of the curve
     625    \sa setStyle()
     626 */
     627QwtPlotIntervalCurve::CurveStyle QwtPlotIntervalCurve::style() const
     628{
     629    return m_data->style;
     630}
     631
     632/*!
     633   Assign a symbol.
     634
     635   \param symbol Symbol
     636   \sa symbol()
     637 */
     638void QwtPlotIntervalCurve::setSymbol( const QwtIntervalSymbol* symbol )
     639{
     640    if ( symbol != m_data->symbol )
     641    {
     642        delete m_data->symbol;
     643        m_data->symbol = symbol;
     644
     645        legendChanged();
     646        itemChanged();
     647    }
     648}
     649
     650/*!
     651   \return Current symbol or NULL, when no symbol has been assigned
     652   \sa setSymbol()
     653 */
     654const QwtIntervalSymbol* QwtPlotIntervalCurve::symbol() const
     655{
     656    return m_data->symbol;
     657}
     658
     659/*!
     660   Build and assign a pen
     661
     662   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     663   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     664   to hide this incompatibility.
     665
     666   \param color Pen color
     667   \param width Pen width
     668   \param style Pen style
     669
     670   \sa pen(), brush()
     671 */
     672void QwtPlotIntervalCurve::setPen( const QColor& color, qreal width, Qt::PenStyle style )
     673{
     674    setPen( QPen( color, width, style ) );
     675}
     676
     677/*!
     678   \brief Assign a pen
     679   \param pen New pen
     680   \sa pen(), brush()
     681 */
     682void QwtPlotIntervalCurve::setPen( const QPen& pen )
     683{
     684    if ( pen != m_data->pen )
     685    {
     686        m_data->pen = pen;
     687
     688        legendChanged();
     689        itemChanged();
     690    }
     691}
     692
     693/*!
     694    \return Pen used to draw the lines
     695    \sa setPen(), brush()
     696 */
     697const QPen& QwtPlotIntervalCurve::pen() const
     698{
     699    return m_data->pen;
     700}
     701
     702/*!
     703   Assign a brush.
     704
     705   The brush is used to fill the area in Tube style().
     706
     707   \param brush Brush
     708   \sa brush(), pen(), setStyle(), CurveStyle
     709 */
     710void QwtPlotIntervalCurve::setBrush( const QBrush& brush )
     711{
     712    if ( brush != m_data->brush )
     713    {
     714        m_data->brush = brush;
     715
     716        legendChanged();
     717        itemChanged();
     718    }
     719}
     720
     721/*!
     722   \return Brush used to fill the area in Tube style()
     723   \sa setBrush(), setStyle(), CurveStyle
     724 */
     725const QBrush& QwtPlotIntervalCurve::brush() const
     726{
     727    return m_data->brush;
     728}
     729
     730/*!
     731   \return Bounding rectangle of all samples.
     732   For an empty series the rectangle is invalid.
     733 */
     734QRectF QwtPlotIntervalCurve::boundingRect() const
     735{
     736    QRectF rect = QwtPlotSeriesItem::boundingRect();
     737    if ( orientation() == Qt::Vertical )
     738        rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() );
     739
     740    return rect;
     741}
     742
     743/*!
     744   Draw a subset of the samples
     745
     746   \param painter Painter
     747   \param xMap Maps x-values into pixel coordinates.
     748   \param yMap Maps y-values into pixel coordinates.
     749   \param canvasRect Contents rectangle of the canvas
     750   \param from Index of the first sample to be painted
     751   \param to Index of the last sample to be painted. If to < 0 the
     752         series will be painted to its last sample.
     753
     754   \sa drawTube(), drawSymbols()
     755 */
     756void QwtPlotIntervalCurve::drawSeries( QPainter* painter,
     757    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     758    const QRectF& canvasRect, int from, int to ) const
     759{
     760    if ( to < 0 )
     761        to = dataSize() - 1;
     762
     763    if ( from < 0 )
     764        from = 0;
     765
     766    if ( from > to )
     767        return;
     768
     769    if ( m_data->style == Tube )
     770        drawTube( painter, xMap, yMap, canvasRect, from, to );
     771
     772    if ( m_data->symbol &&
     773        ( m_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
     774    {
     775        drawSymbols( painter, *m_data->symbol,
     776            xMap, yMap, canvasRect, from, to );
     777    }
     778}
     779
     780/*!
     781   Draw a tube
     782
     783   Builds 2 curves from the upper and lower limits of the intervals
     784   and draws them with the pen(). The area between the curves is
     785   filled with the brush().
     786
     787   \param painter Painter
     788   \param xMap Maps x-values into pixel coordinates.
     789   \param yMap Maps y-values into pixel coordinates.
     790   \param canvasRect Contents rectangle of the canvas
     791   \param from Index of the first sample to be painted
     792   \param to Index of the last sample to be painted. If to < 0 the
     793         series will be painted to its last sample.
     794
     795   \sa drawSeries(), drawSymbols()
     796 */
     797void QwtPlotIntervalCurve::drawTube(
     798    QPainter* painter, const QwtScaleMap& xMap,
     799    const QwtScaleMap& yMap, const QRectF& canvasRect, int from, int to) const
     800{
     801    if ( ( m_data->pen.style() == Qt::NoPen ) &&
     802        ( m_data->brush.style() == Qt::NoBrush ) )
     803    {
     804        return;
     805    }
     806
     807    const bool useLines = testPaintAttribute( TubeAsLines )
     808        && QwtPainter::roundingAlignment( painter );
     809
     810    if ( useLines )
     811        qwtDrawTubeLines( this, painter, xMap, yMap, canvasRect, from, to );
     812    else
     813        qwtDrawTube( this, painter, xMap, yMap, canvasRect, from, to );
     814}
     815
     816/*!
     817   Draw symbols for a subset of the samples
     818
     819   \param painter Painter
     820   \param symbol Interval symbol
     821   \param xMap x map
     822   \param yMap y map
     823   \param canvasRect Contents rectangle of the canvas
     824   \param from Index of the first sample to be painted
     825   \param to Index of the last sample to be painted
     826
     827   \sa setSymbol(), drawSeries(), drawTube()
     828 */
    487829void QwtPlotIntervalCurve::drawSymbols(
    488     QPainter *painter, const QwtIntervalSymbol &symbol,
    489     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    490     const QRectF &canvasRect, int from, int to ) const
     830    QPainter* painter, const QwtIntervalSymbol& symbol,
     831    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     832    const QRectF& canvasRect, int from, int to ) const
    491833{
    492834    painter->save();
    … …  
    505847    const double yMax = tr.bottom();
    506848
    507     const bool doClip = d_data->paintAttributes & ClipSymbol;
     849    const bool doClip = m_data->paintAttributes & ClipSymbol;
    508850
    509851    for ( int i = from; i <= to; i++ )
    … …  
    541883
    542884/*!
    543   \return Icon for the legend
    544 
    545   In case of Tube style() the icon is a plain rectangle filled with the brush().
    546   If a symbol is assigned it is scaled to size.
    547 
    548   \param index Index of the legend entry
     885   \return Icon for the legend
     886
     887   In case of Tube style() the icon is a plain rectangle filled with the brush().
     888   If a symbol is assigned it is scaled to size.
     889
     890   \param index Index of the legend entry
    549891               ( ignored as there is only one )
    550   \param size Icon size
    551 
    552   \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
    553 */
     892   \param size Icon size
     893
     894   \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
     895 */
    554896QwtGraphic QwtPlotIntervalCurve::legendIcon(
    555     int index, const QSizeF &size ) const
     897    int index, const QSizeF& size ) const
    556898{
    557899    Q_UNUSED( index );
    … …  
    568910        testRenderHint( QwtPlotItem::RenderAntialiased ) );
    569911
    570     if ( d_data->style == Tube )
     912    if ( m_data->style == Tube )
    571913    {
    572914        QRectF r( 0, 0, size.width(), size.height() );
    573         painter.fillRect( r, d_data->brush );
    574     }
    575 
    576     if ( d_data->symbol &&
    577         ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
    578     {
    579         QPen pen = d_data->symbol->pen();
     915        painter.fillRect( r, m_data->brush );
     916    }
     917
     918    if ( m_data->symbol &&
     919        ( m_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) )
     920    {
     921        QPen pen = m_data->symbol->pen();
    580922        pen.setWidthF( pen.widthF() );
    581923        pen.setCapStyle( Qt::FlatCap );
    582924
    583925        painter.setPen( pen );
    584         painter.setBrush( d_data->symbol->brush() );
     926        painter.setBrush( m_data->symbol->brush() );
    585927
    586928        if ( orientation() == Qt::Vertical )
    … …  
    588930            const double x = 0.5 * size.width();
    589931
    590             d_data->symbol->draw( &painter, orientation(),
     932            m_data->symbol->draw( &painter, orientation(),
    591933                QPointF( x, 0 ), QPointF( x, size.height() - 1.0 ) );
    592934        }
    … …  
    595937            const double y = 0.5 * size.height();
    596938
    597             d_data->symbol->draw( &painter, orientation(),
     939            m_data->symbol->draw( &painter, orientation(),
    598940                QPointF( 0.0, y ), QPointF( size.width() - 1.0, y ) );
    599941        }
  • trunk/BNC/qwt/qwt_plot_intervalcurve.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_seriesitem.h"
    15 #include "qwt_series_data.h"
    1615
    1716class QwtIntervalSymbol;
     17template< typename T > class QwtSeriesData;
    1818
    1919/*!
    20   \brief QwtPlotIntervalCurve represents a series of samples, where each value
     20   \brief QwtPlotIntervalCurve represents a series of samples, where each value
    2121         is associated with an interval ( \f$[y1,y2] = f(x)\f$ ).
    2222
    23   The representation depends on the style() and an optional symbol()
    24   that is displayed for each interval. QwtPlotIntervalCurve might be used
    25   to display error bars or the area between 2 curves.
    26 */
    27 class QWT_EXPORT QwtPlotIntervalCurve:
    28     public QwtPlotSeriesItem, public QwtSeriesStore<QwtIntervalSample>
     23   The representation depends on the style() and an optional symbol()
     24   that is displayed for each interval. QwtPlotIntervalCurve might be used
     25   to display error bars or the area between 2 curves.
     26 */
     27class QWT_EXPORT QwtPlotIntervalCurve
     28    : public QwtPlotSeriesItem
     29    , public QwtSeriesStore< QwtIntervalSample >
    2930{
    30 public:
     31  public:
    3132    /*!
    3233        \brief Curve styles.
    … …  
    3435
    3536        \sa setStyle(), style()
    36     */
     37     */
    3738    enum CurveStyle
    3839    {
    … …  
    6061        Attributes to modify the drawing algorithm.
    6162        \sa setPaintAttribute(), testPaintAttribute()
    62     */
     63     */
    6364    enum PaintAttribute
    6465    {
    6566        /*!
    66           Clip polygons before painting them. In situations, where points
    67           are far outside the visible area (f.e when zooming deep) this
    68           might be a substantial improvement for the painting performance.
     67           Clip polygons before painting them. In situations, where points
     68           are far outside the visible area (f.e when zooming deep) this
     69           might be a substantial improvement for the painting performance.
    6970         */
    7071        ClipPolygons = 0x01,
    7172
    7273        //! Check if a symbol is on the plot canvas before painting it.
    73         ClipSymbol   = 0x02
     74        ClipSymbol   = 0x02,
     75
     76        /*!
     77           Fill the tube with horizontal or vertical lines and unite
     78           overlapping border lines. This attribute is useful for large
     79           data sets, where consecutive samples are often mapped to the same
     80           coordinate.
     81
     82           Beside other minor visual differences the filling is always
     83           monochrome - using brush().color().
     84
     85           This algorithm is very fast and effective and can be used inside
     86           a replot cycle. In the worst case the number of lines to be rendered
     87           will be 5 times the ( width/height - depending on the orientation() )
     88           of the plot canvas.
     89
     90           \note Has only an effect, when drawing to a paint device
     91                 in integer coordinates ( f.e. all widgets on screen ).
     92
     93           \sa QwtPlotCurve::FilterPointsAggressive
     94         */
     95        TubeAsLines = 0x10
    7496    };
    7597
    76     //! Paint attributes
    77     typedef QFlags<PaintAttribute> PaintAttributes;
     98    Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute )
    7899
    79     explicit QwtPlotIntervalCurve( const QString &title = QString() );
    80     explicit QwtPlotIntervalCurve( const QwtText &title );
     100    explicit QwtPlotIntervalCurve( const QString& title = QString() );
     101    explicit QwtPlotIntervalCurve( const QwtText& title );
    81102
    82103    virtual ~QwtPlotIntervalCurve();
    83104
    84     virtual int rtti() const;
     105    virtual int rtti() const QWT_OVERRIDE;
    85106
    86107    void setPaintAttribute( PaintAttribute, bool on = true );
    87108    bool testPaintAttribute( PaintAttribute ) const;
    88109
    89     void setSamples( const QVector<QwtIntervalSample> & );
    90     void setSamples( QwtSeriesData<QwtIntervalSample> * );
     110    void setSamples( const QVector< QwtIntervalSample >& );
     111    void setSamples( QwtSeriesData< QwtIntervalSample >* );
    91112
    92     void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    93     void setPen( const QPen & );
    94     const QPen &pen() const;
     113    void setPen( const QColor&,
     114        qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    95115
    96     void setBrush( const QBrush & );
    97     const QBrush &brush() const;
     116    void setPen( const QPen& );
     117    const QPen& pen() const;
     118
     119    void setBrush( const QBrush& );
     120    const QBrush& brush() const;
    98121
    99122    void setStyle( CurveStyle style );
    100123    CurveStyle style() const;
    101124
    102     void setSymbol( const QwtIntervalSymbol * );
    103     const QwtIntervalSymbol *symbol() const;
     125    void setSymbol( const QwtIntervalSymbol* );
     126    const QwtIntervalSymbol* symbol() const;
    104127
    105     virtual void drawSeries( QPainter *,
    106         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    107         const QRectF &canvasRect, int from, int to ) const;
     128    virtual void drawSeries( QPainter*,
     129        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     130        const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE;
    108131
    109     virtual QRectF boundingRect() const;
     132    virtual QRectF boundingRect() const QWT_OVERRIDE;
    110133
    111     virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
     134    virtual QwtGraphic legendIcon(
     135        int index, const QSizeF& ) const QWT_OVERRIDE;
    112136
    113 protected:
     137  protected:
    114138
    115139    void init();
    116140
    117     virtual void drawTube( QPainter *,
    118         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    119         const QRectF &canvasRect, int from, int to ) const;
     141    virtual void drawTube( QPainter*,
     142        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     143        const QRectF& canvasRect, int from, int to ) const;
    120144
    121     virtual void drawSymbols( QPainter *, const QwtIntervalSymbol &,
    122         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    123         const QRectF &canvasRect, int from, int to ) const;
     145    virtual void drawSymbols( QPainter*, const QwtIntervalSymbol&,
     146        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     147        const QRectF& canvasRect, int from, int to ) const;
    124148
    125 private:
     149  private:
    126150    class PrivateData;
    127     PrivateData *d_data;
     151    PrivateData* m_data;
    128152};
    129153
  • trunk/BNC/qwt/qwt_plot_item.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212#include "qwt_plot.h"
    1313#include "qwt_legend_data.h"
    14 #include "qwt_scale_div.h"
     14#include "qwt_scale_map.h"
    1515#include "qwt_graphic.h"
     16
    1617#include <qpainter.h>
    1718
    1819class QwtPlotItem::PrivateData
    1920{
    20 public:
    21     PrivateData():
    22         plot( NULL ),
    23         isVisible( true ),
    24         attributes( 0 ),
    25         interests( 0 ),
    26         renderHints( 0 ),
    27         renderThreadCount( 1 ),
    28         z( 0.0 ),
    29         xAxis( QwtPlot::xBottom ),
    30         yAxis( QwtPlot::yLeft ),
    31         legendIconSize( 8, 8 )
    32     {
    33     }
    34 
    35     mutable QwtPlot *plot;
     21  public:
     22    PrivateData()
     23        : plot( NULL )
     24        , isVisible( true )
     25        , renderThreadCount( 1 )
     26        , z( 0.0 )
     27        , xAxisId( QwtAxis::XBottom )
     28        , yAxisId( QwtAxis::YLeft )
     29        , legendIconSize( 8, 8 )
     30    {
     31    }
     32
     33    mutable QwtPlot* plot;
    3634
    3735    bool isVisible;
    … …  
    4543    double z;
    4644
    47     int xAxis;
    48     int yAxis;
     45    QwtAxisId xAxisId;
     46    QwtAxisId yAxisId;
    4947
    5048    QwtText title;
    … …  
    5452/*!
    5553   Constructor
     54 */
     55QwtPlotItem::QwtPlotItem()
     56{
     57    m_data = new PrivateData;
     58}
     59
     60/*!
     61   Constructor
    5662   \param title Title of the item
    57 */
    58 QwtPlotItem::QwtPlotItem( const QwtText &title )
    59 {
    60     d_data = new PrivateData;
    61     d_data->title = title;
     63 */
     64QwtPlotItem::QwtPlotItem( const QString& title )
     65{
     66    m_data = new PrivateData;
     67    m_data->title = title;
     68}
     69
     70/*!
     71   Constructor
     72   \param title Title of the item
     73 */
     74QwtPlotItem::QwtPlotItem( const QwtText& title )
     75{
     76    m_data = new PrivateData;
     77    m_data->title = title;
    6278}
    6379
    … …  
    6682{
    6783    attach( NULL );
    68     delete d_data;
    69 }
    70 
    71 /*!
    72   \brief Attach the item to a plot.
    73 
    74   This method will attach a QwtPlotItem to the QwtPlot argument. It will first
    75   detach the QwtPlotItem from any plot from a previous call to attach (if
    76   necessary). If a NULL argument is passed, it will detach from any QwtPlot it
    77   was attached to.
    78 
    79   \param plot Plot widget
    80   \sa detach()
    81 */
    82 void QwtPlotItem::attach( QwtPlot *plot )
    83 {
    84     if ( plot == d_data->plot )
     84    delete m_data;
     85}
     86
     87/*!
     88   \brief Attach the item to a plot.
     89
     90   This method will attach a QwtPlotItem to the QwtPlot argument. It will first
     91   detach the QwtPlotItem from any plot from a previous call to attach (if
     92   necessary). If a NULL argument is passed, it will detach from any QwtPlot it
     93   was attached to.
     94
     95   \param plot Plot widget
     96   \sa detach()
     97 */
     98void QwtPlotItem::attach( QwtPlot* plot )
     99{
     100    if ( plot == m_data->plot )
    85101        return;
    86102
    87     if ( d_data->plot )
    88         d_data->plot->attachItem( this, false );
    89 
    90     d_data->plot = plot;
    91 
    92     if ( d_data->plot )
    93         d_data->plot->attachItem( this, true );
     103    if ( m_data->plot )
     104        m_data->plot->attachItem( this, false );
     105
     106    m_data->plot = plot;
     107
     108    if ( m_data->plot )
     109        m_data->plot->attachItem( this, true );
    94110}
    95111
    … …  
    100116   detach() is equivalent to calling attach( NULL )
    101117   \sa attach()
    102 */
     118 */
    103119void QwtPlotItem::detach()
    104120{
    … …  
    117133   \return rtti value
    118134   \sa RttiValues
    119 */
     135 */
    120136int QwtPlotItem::rtti() const
    121137{
    … …  
    124140
    125141//! Return attached plot
    126 QwtPlot *QwtPlotItem::plot() const
    127 {
    128     return d_data->plot;
     142QwtPlot* QwtPlotItem::plot() const
     143{
     144    return m_data->plot;
    129145}
    130146
    … …  
    133149
    134150   \return setZ(), QwtPlotDict::itemList()
    135 */
     151 */
    136152double QwtPlotItem::z() const
    137153{
    138     return d_data->z;
     154    return m_data->z;
    139155}
    140156
    … …  
    146162   \param z Z-value
    147163   \sa z(), QwtPlotDict::itemList()
    148 */
     164 */
    149165void QwtPlotItem::setZ( double z )
    150166{
    151     if ( d_data->z != z )
    152     {
    153         if ( d_data->plot ) // update the z order
    154             d_data->plot->attachItem( this, false );
    155 
    156         d_data->z = z;
    157 
    158         if ( d_data->plot )
    159             d_data->plot->attachItem( this, true );
     167    if ( m_data->z != z )
     168    {
     169        if ( m_data->plot ) // update the z order
     170            m_data->plot->attachItem( this, false );
     171
     172        m_data->z = z;
     173
     174        if ( m_data->plot )
     175            m_data->plot->attachItem( this, true );
    160176
    161177        itemChanged();
    … …  
    168184   \param title Title
    169185   \sa title()
    170 */
    171 void QwtPlotItem::setTitle( const QString &title )
     186 */
     187void QwtPlotItem::setTitle( const QString& title )
    172188{
    173189    setTitle( QwtText( title ) );
    … …  
    179195   \param title Title
    180196   \sa title()
    181 */
    182 void QwtPlotItem::setTitle( const QwtText &title )
    183 {
    184     if ( d_data->title != title )
    185     {
    186         d_data->title = title;
     197 */
     198void QwtPlotItem::setTitle( const QwtText& title )
     199{
     200    if ( m_data->title != title )
     201    {
     202        m_data->title = title;
    187203
    188204        legendChanged();
    … …  
    196212   \return Title of the item
    197213   \sa setTitle()
    198 */
    199 const QwtText &QwtPlotItem::title() const
    200 {
    201     return d_data->title;
     214 */
     215const QwtText& QwtPlotItem::title() const
     216{
     217    return m_data->title;
    202218}
    203219
    … …  
    209225
    210226   \sa testItemAttribute(), ItemInterest
    211 */
     227 */
    212228void QwtPlotItem::setItemAttribute( ItemAttribute attribute, bool on )
    213229{
    214     if ( d_data->attributes.testFlag( attribute ) != on )
     230    if ( m_data->attributes.testFlag( attribute ) != on )
    215231    {
    216232        if ( on )
    217             d_data->attributes |= attribute;
     233            m_data->attributes |= attribute;
    218234        else
    219             d_data->attributes &= ~attribute;
     235            m_data->attributes &= ~attribute;
    220236
    221237        if ( attribute == QwtPlotItem::Legend )
    222             legendChanged();
     238        {
     239            if ( on )
     240            {
     241                legendChanged();
     242            }
     243            else
     244            {
     245                /*
     246                    In the special case of taking an item from
     247                    the legend we can't use legendChanged() as
     248                    it depends on QwtPlotItem::Legend being enabled
     249                 */
     250                if ( m_data->plot )
     251                    m_data->plot->updateLegend( this );
     252            }
     253        }
    223254
    224255        itemChanged();
    … …  
    232263   \return true/false
    233264   \sa setItemAttribute(), ItemInterest
    234 */
     265 */
    235266bool QwtPlotItem::testItemAttribute( ItemAttribute attribute ) const
    236267{
    237     return d_data->attributes.testFlag( attribute );
     268    return m_data->attributes.testFlag( attribute );
    238269}
    239270
    … …  
    245276
    246277   \sa testItemInterest(), ItemAttribute
    247 */
     278 */
    248279void QwtPlotItem::setItemInterest( ItemInterest interest, bool on )
    249280{
    250     if ( d_data->interests.testFlag( interest ) != on )
     281    if ( m_data->interests.testFlag( interest ) != on )
    251282    {
    252283        if ( on )
    253             d_data->interests |= interest;
     284            m_data->interests |= interest;
    254285        else
    255             d_data->interests &= ~interest;
     286            m_data->interests &= ~interest;
    256287
    257288        itemChanged();
    … …  
    265296   \return true/false
    266297   \sa setItemInterest(), ItemAttribute
    267 */
     298 */
    268299bool QwtPlotItem::testItemInterest( ItemInterest interest ) const
    269300{
    270     return d_data->interests.testFlag( interest );
     301    return m_data->interests.testFlag( interest );
    271302}
    272303
    … …  
    278309
    279310   \sa testRenderHint(), RenderHint
    280 */
     311 */
    281312void QwtPlotItem::setRenderHint( RenderHint hint, bool on )
    282313{
    283     if ( d_data->renderHints.testFlag( hint ) != on )
     314    if ( m_data->renderHints.testFlag( hint ) != on )
    284315    {
    285316        if ( on )
    286             d_data->renderHints |= hint;
     317            m_data->renderHints |= hint;
    287318        else
    288             d_data->renderHints &= ~hint;
     319            m_data->renderHints &= ~hint;
    289320
    290321        itemChanged();
    … …  
    298329   \return true/false
    299330   \sa setRenderHint(), RenderHint
    300 */
     331 */
    301332bool QwtPlotItem::testRenderHint( RenderHint hint ) const
    302333{
    303     return d_data->renderHints.testFlag( hint );
     334    return m_data->renderHints.testFlag( hint );
    304335}
    305336
    … …  
    316347
    317348   The default thread count is 1 ( = no additional threads )
    318 */
     349 */
    319350void QwtPlotItem::setRenderThreadCount( uint numThreads )
    320351{
    321     d_data->renderThreadCount = numThreads;
     352    m_data->renderThreadCount = numThreads;
    322353}
    323354
    … …  
    326357           If numThreads() is set to 0, the system specific
    327358           ideal thread count is used.
    328 */
     359 */
    329360uint QwtPlotItem::renderThreadCount() const
    330361{
    331     return d_data->renderThreadCount;
     362    return m_data->renderThreadCount;
    332363}
    333364
    … …  
    339370   \param size Size
    340371   \sa legendIconSize(), legendIcon()
    341 */
    342 void QwtPlotItem::setLegendIconSize( const QSize &size )
    343 {
    344     if ( d_data->legendIconSize != size )
    345     {
    346         d_data->legendIconSize = size;
     372 */
     373void QwtPlotItem::setLegendIconSize( const QSize& size )
     374{
     375    if ( m_data->legendIconSize != size )
     376    {
     377        m_data->legendIconSize = size;
    347378        legendChanged();
    348379    }
    … …  
    352383   \return Legend icon size
    353384   \sa setLegendIconSize(), legendIcon()
    354 */
     385 */
    355386QSize QwtPlotItem::legendIconSize() const
    356387{
    357     return d_data->legendIconSize;
     388    return m_data->legendIconSize;
    358389}
    359390
    … …  
    370401 */
    371402QwtGraphic QwtPlotItem::legendIcon(
    372     int index, const QSizeF &size ) const
     403    int index, const QSizeF& size ) const
    373404{
    374405    Q_UNUSED( index )
    … …  
    390421 */
    391422QwtGraphic QwtPlotItem::defaultIcon(
    392     const QBrush &brush, const QSizeF &size ) const
     423    const QBrush& brush, const QSizeF& size ) const
    393424{
    394425    QwtGraphic icon;
    … …  
    423454    \param on Show if true, otherwise hide
    424455    \sa isVisible(), show(), hide()
    425 */
     456 */
    426457void QwtPlotItem::setVisible( bool on )
    427458{
    428     if ( on != d_data->isVisible )
    429     {
    430         d_data->isVisible = on;
     459    if ( on != m_data->isVisible )
     460    {
     461        m_data->isVisible = on;
    431462        itemChanged();
    432463    }
    … …  
    436467    \return true if visible
    437468    \sa setVisible(), show(), hide()
    438 */
     469 */
    439470bool QwtPlotItem::isVisible() const
    440471{
    441     return d_data->isVisible;
     472    return m_data->isVisible;
    442473}
    443474
    … …  
    447478
    448479   \sa QwtPlot::legendChanged(), QwtPlot::autoRefresh()
    449 */
     480 */
    450481void QwtPlotItem::itemChanged()
    451482{
    452     if ( d_data->plot )
    453         d_data->plot->autoRefresh();
     483    if ( m_data->plot )
     484        m_data->plot->autoRefresh();
    454485}
    455486
    … …  
    457488   Update the legend of the parent plot.
    458489   \sa QwtPlot::updateLegend(), itemChanged()
    459 */
     490 */
    460491void QwtPlotItem::legendChanged()
    461492{
    462     if ( testItemAttribute( QwtPlotItem::Legend ) && d_data->plot )
    463         d_data->plot->updateLegend( this );
     493    if ( testItemAttribute( QwtPlotItem::Legend ) && m_data->plot )
     494        m_data->plot->updateLegend( this );
    464495}
    465496
    … …  
    469500   The item will painted according to the coordinates of its Axes.
    470501
    471    \param xAxis X Axis ( QwtPlot::xBottom or QwtPlot::xTop )
    472    \param yAxis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight )
    473 
    474    \sa setXAxis(), setYAxis(), xAxis(), yAxis(), QwtPlot::Axis
    475 */
    476 void QwtPlotItem::setAxes( int xAxis, int yAxis )
    477 {
    478     if ( xAxis == QwtPlot::xBottom || xAxis == QwtPlot::xTop )
    479         d_data->xAxis = xAxis;
    480 
    481     if ( yAxis == QwtPlot::yLeft || yAxis == QwtPlot::yRight )
    482         d_data->yAxis = yAxis;
     502   \param xAxisId X Axis
     503   \param yAxisId Y Axis
     504
     505   \sa setXAxis(), setYAxis(), xAxis(), yAxis()
     506 */
     507void QwtPlotItem::setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId )
     508{
     509    if ( QwtAxis::isXAxis( xAxisId ) )
     510        m_data->xAxisId = xAxisId;
     511
     512    if ( QwtAxis::isYAxis( yAxisId ) )
     513        m_data->yAxisId = yAxisId;
    483514
    484515    itemChanged();
    … …  
    490521   The item will painted according to the coordinates its Axes.
    491522
    492    \param axis X Axis ( QwtPlot::xBottom or QwtPlot::xTop )
    493    \sa setAxes(), setYAxis(), xAxis(), QwtPlot::Axis
    494 */
    495 void QwtPlotItem::setXAxis( int axis )
    496 {
    497     if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
    498     {
    499         d_data->xAxis = axis;
     523   \param axisId X Axis
     524   \sa setAxes(), setYAxis(), xAxis()
     525 */
     526void QwtPlotItem::setXAxis( QwtAxisId axisId )
     527{
     528    if ( QwtAxis::isXAxis( axisId ) )
     529    {
     530        m_data->xAxisId = axisId;
    500531        itemChanged();
    501532    }
    … …  
    507538   The item will painted according to the coordinates its Axes.
    508539
    509    \param axis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight )
    510    \sa setAxes(), setXAxis(), yAxis(), QwtPlot::Axis
    511 */
    512 void QwtPlotItem::setYAxis( int axis )
    513 {
    514     if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
    515     {
    516         d_data->yAxis = axis;
     540   \param axisId Y Axis
     541   \sa setAxes(), setXAxis(), yAxis()
     542 */
     543void QwtPlotItem::setYAxis( QwtAxisId axisId )
     544{
     545    if ( QwtAxis::isYAxis( axisId ) )
     546    {
     547        m_data->yAxisId = axisId;
    517548        itemChanged();
    518549    }
    … …  
    520551
    521552//! Return xAxis
    522 int QwtPlotItem::xAxis() const
    523 {
    524     return d_data->xAxis;
     553QwtAxisId QwtPlotItem::xAxis() const
     554{
     555    return m_data->xAxisId;
    525556}
    526557
    527558//! Return yAxis
    528 int QwtPlotItem::yAxis() const
    529 {
    530     return d_data->yAxis;
     559QwtAxisId QwtPlotItem::yAxis() const
     560{
     561    return m_data->yAxisId;
    531562}
    532563
    … …  
    534565   \return An invalid bounding rect: QRectF(1.0, 1.0, -2.0, -2.0)
    535566   \note A width or height < 0.0 is ignored by the autoscaler
    536 */
     567 */
    537568QRectF QwtPlotItem::boundingRect() const
    538569{
    … …  
    562593   \sa QwtPlot::getCanvasMarginsHint(), QwtPlot::updateCanvasMargins()
    563594 */
    564 void QwtPlotItem::getCanvasMarginHint( const QwtScaleMap &xMap,
    565     const QwtScaleMap &yMap, const QRectF &canvasRect,
    566     double &left, double &top, double &right, double &bottom ) const
     595void QwtPlotItem::getCanvasMarginHint( const QwtScaleMap& xMap,
     596    const QwtScaleMap& yMap, const QRectF& canvasRect,
     597    double& left, double& top, double& right, double& bottom ) const
    567598{
    568599    Q_UNUSED( xMap );
    … …  
    593624   \sa title(), legendIcon(), QwtLegend, QwtPlotLegendItem
    594625 */
    595 QList<QwtLegendData> QwtPlotItem::legendData() const
     626QList< QwtLegendData > QwtPlotItem::legendData() const
    596627{
    597628    QwtLegendData data;
    … …  
    600631    label.setRenderFlags( label.renderFlags() & Qt::AlignLeft );
    601632
    602     QVariant titleValue;
    603     qVariantSetValue( titleValue, label );
    604     data.setValue( QwtLegendData::TitleRole, titleValue );
     633    data.setValue( QwtLegendData::TitleRole,
     634        QVariant::fromValue( label ) );
    605635
    606636    const QwtGraphic graphic = legendIcon( 0, legendIconSize() );
    607637    if ( !graphic.isNull() )
    608638    {
    609         QVariant iconValue;
    610         qVariantSetValue( iconValue, graphic );
    611         data.setValue( QwtLegendData::IconRole, iconValue );
    612     }
    613 
    614     QList<QwtLegendData> list;
     639        data.setValue( QwtLegendData::IconRole,
     640            QVariant::fromValue( graphic ) );
     641    }
     642
     643    QList< QwtLegendData > list;
    615644    list += data;
    616645
    … …  
    633662
    634663   \sa QwtPlot::updateAxes(), ScaleInterest
    635 */
    636 void QwtPlotItem::updateScaleDiv( const QwtScaleDiv &xScaleDiv,
    637     const QwtScaleDiv &yScaleDiv )
     664 */
     665void QwtPlotItem::updateScaleDiv( const QwtScaleDiv& xScaleDiv,
     666    const QwtScaleDiv& yScaleDiv )
    638667{
    639668    Q_UNUSED( xScaleDiv );
    … …  
    659688         legendData() and legendIcon()
    660689 */
    661 void QwtPlotItem::updateLegend( const QwtPlotItem *item,
    662     const QList<QwtLegendData> &data )
     690void QwtPlotItem::updateLegend( const QwtPlotItem* item,
     691    const QList< QwtLegendData >& data )
    663692{
    664693    Q_UNUSED( item );
    … …  
    673702
    674703   \return Bounding scale rect of the scale maps, not normalized
    675 */
    676 QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap,
    677     const QwtScaleMap &yMap ) const
     704 */
     705QRectF QwtPlotItem::scaleRect( const QwtScaleMap& xMap,
     706    const QwtScaleMap& yMap ) const
    678707{
    679708    return QRectF( xMap.s1(), yMap.s1(),
    … …  
    688717
    689718   \return Bounding paint rectangle of the scale maps, not normalized
    690 */
    691 QRectF QwtPlotItem::paintRect( const QwtScaleMap &xMap,
    692     const QwtScaleMap &yMap ) const
     719 */
     720QRectF QwtPlotItem::paintRect( const QwtScaleMap& xMap,
     721    const QwtScaleMap& yMap ) const
    693722{
    694723    const QRectF rect( xMap.p1(), yMap.p1(),
  • trunk/BNC/qwt/qwt_plot_item.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_text.h"
    15 #include "qwt_legend_data.h"
    16 #include "qwt_graphic.h"
    17 #include <qrect.h>
    18 #include <qlist.h>
     14#include "qwt_axis_id.h"
    1915#include <qmetatype.h>
    2016
    21 class QPainter;
    2217class QwtScaleMap;
    2318class QwtScaleDiv;
    2419class QwtPlot;
     20class QwtText;
     21class QwtGraphic;
     22class QwtLegendData;
     23class QRectF;
     24class QPainter;
     25class QString;
     26template< typename T > class QList;
    2527
    2628/*!
    27   \brief Base class for items on the plot canvas
    28 
    29   A plot item is "something", that can be painted on the plot canvas,
    30   or only affects the scales of the plot widget. They can be categorized as:
    31 
    32   - Representator\n
     29   \brief Base class for items on the plot canvas
     30
     31   A plot item is "something", that can be painted on the plot canvas,
     32   or only affects the scales of the plot widget. They can be categorized as:
     33
     34   - Representator\n
    3335    A "Representator" is an item that represents some sort of data
    3436    on the plot canvas. The different representator classes are organized
    … …  
    4244    - ...
    4345
    44   - Decorators\n
     46   - Decorators\n
    4547    A "Decorator" is an item, that displays additional information, that
    4648    is not related to any data:
    … …  
    5052    - ...
    5153
    52   Depending on the QwtPlotItem::ItemAttribute flags, an item is included
    53   into autoscaling or has an entry on the legend.
    54 
    55   Before misusing the existing item classes it might be better to
    56   implement a new type of plot item
    57   ( don't implement a watermark as spectrogram ).
    58   Deriving a new type of QwtPlotItem primarily means to implement
    59   the YourPlotItem::draw() method.
    60 
    61   \sa The cpuplot example shows the implementation of additional plot items.
    62 */
     54   Depending on the QwtPlotItem::ItemAttribute flags, an item is included
     55   into autoscaling or has an entry on the legend.
     56
     57   Before misusing the existing item classes it might be better to
     58   implement a new type of plot item
     59   ( don't implement a watermark as spectrogram ).
     60   Deriving a new type of QwtPlotItem primarily means to implement
     61   the YourPlotItem::draw() method.
     62
     63   \sa The cpuplot example shows the implementation of additional plot items.
     64 */
    6365
    6466class QWT_EXPORT QwtPlotItem
    6567{
    66 public:
     68  public:
    6769    /*!
    6870        \brief Runtime type information
    … …  
    103105        Rtti_PlotSpectrogram,
    104106
    105         //! For QwtPlotSvgItem
    106         Rtti_PlotSVG,
     107        //! For QwtPlotGraphicItem, QwtPlotSvgItem
     108        Rtti_PlotGraphic,
    107109
    108110        //! For QwtPlotTradingCurve
    … …  
    123125        //! For QwtPlotZoneItem
    124126        Rtti_PlotZone,
     127
     128        //! For QwtPlotVectorField
     129        Rtti_PlotVectorField,
    125130
    126131        /*!
    … …  
    160165    };
    161166
    162     //! Plot Item Attributes
    163     typedef QFlags<ItemAttribute> ItemAttributes;
     167    Q_DECLARE_FLAGS( ItemAttributes, ItemAttribute )
    164168
    165169    /*!
    … …  
    194198    };
    195199
    196     //! Plot Item Interests
    197     typedef QFlags<ItemInterest> ItemInterests;
     200    Q_DECLARE_FLAGS( ItemInterests, ItemInterest )
    198201
    199202    //! Render hints
    … …  
    204207    };
    205208
    206     //! Render hints
    207     typedef QFlags<RenderHint> RenderHints;
    208 
    209     explicit QwtPlotItem( const QwtText &title = QwtText() );
     209    Q_DECLARE_FLAGS( RenderHints, RenderHint )
     210
     211    explicit QwtPlotItem();
     212    explicit QwtPlotItem( const QString& title );
     213    explicit QwtPlotItem( const QwtText& title );
     214
    210215    virtual ~QwtPlotItem();
    211216
    212     void attach( QwtPlot *plot );
     217    void attach( QwtPlot* plot );
    213218    void detach();
    214219
    215     QwtPlot *plot() const;
    216 
    217     void setTitle( const QString &title );
    218     void setTitle( const QwtText &title );
    219     const QwtText &title() const;
     220    QwtPlot* plot() const;
     221
     222    void setTitle( const QString& title );
     223    void setTitle( const QwtText& title );
     224    const QwtText& title() const;
    220225
    221226    virtual int rtti() const;
    … …  
    233238    uint renderThreadCount() const;
    234239
    235     void setLegendIconSize( const QSize & );
     240    void setLegendIconSize( const QSize& );
    236241    QSize legendIconSize() const;
    237242
    … …  
    244249    bool isVisible () const;
    245250
    246     void setAxes( int xAxis, int yAxis );
    247 
    248     void setXAxis( int axis );
    249     int xAxis() const;
    250 
    251     void setYAxis( int axis );
    252     int yAxis() const;
     251    void setAxes( QwtAxisId xAxis, QwtAxisId yAxis );
     252
     253    void setXAxis( QwtAxisId );
     254    QwtAxisId xAxis() const;
     255
     256    void setYAxis( QwtAxisId );
     257    QwtAxisId yAxis() const;
    253258
    254259    virtual void itemChanged();
    … …  
    256261
    257262    /*!
    258       \brief Draw the item
    259 
    260       \param painter Painter
    261       \param xMap Maps x-values into pixel coordinates.
    262       \param yMap Maps y-values into pixel coordinates.
    263       \param canvasRect Contents rect of the canvas in painter coordinates
    264     */
    265     virtual void draw( QPainter *painter,
    266         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    267         const QRectF &canvasRect ) const = 0;
     263       \brief Draw the item
     264
     265       \param painter Painter
     266       \param xMap Maps x-values into pixel coordinates.
     267       \param yMap Maps y-values into pixel coordinates.
     268       \param canvasRect Contents rect of the canvas in painter coordinates
     269     */
     270    virtual void draw( QPainter* painter,
     271        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     272        const QRectF& canvasRect ) const = 0;
    268273
    269274    virtual QRectF boundingRect() const;
    270275
    271276    virtual void getCanvasMarginHint(
    272         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    273         const QRectF &canvasRect,
    274         double &left, double &top, double &right, double &bottom) const;
     277        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     278        const QRectF& canvasRect,
     279        double& left, double& top, double& right, double& bottom) const;
    275280
    276281    virtual void updateScaleDiv(
    277282        const QwtScaleDiv&, const QwtScaleDiv& );
    278283
    279     virtual void updateLegend( const QwtPlotItem *,
    280         const QList<QwtLegendData> & );
    281 
    282     QRectF scaleRect( const QwtScaleMap &, const QwtScaleMap & ) const;
    283     QRectF paintRect( const QwtScaleMap &, const QwtScaleMap & ) const;
    284 
    285     virtual QList<QwtLegendData> legendData() const;
    286 
    287     virtual QwtGraphic legendIcon( int index, const QSizeF  & ) const;
    288 
    289 protected:
    290     QwtGraphic defaultIcon( const QBrush &, const QSizeF & ) const;
    291 
    292 private:
    293     // Disabled copy constructor and operator=
    294     QwtPlotItem( const QwtPlotItem & );
    295     QwtPlotItem &operator=( const QwtPlotItem & );
     284    virtual void updateLegend( const QwtPlotItem*,
     285        const QList< QwtLegendData >& );
     286
     287    QRectF scaleRect( const QwtScaleMap&, const QwtScaleMap& ) const;
     288    QRectF paintRect( const QwtScaleMap&, const QwtScaleMap& ) const;
     289
     290    virtual QList< QwtLegendData > legendData() const;
     291
     292    virtual QwtGraphic legendIcon( int index, const QSizeF& ) const;
     293
     294  protected:
     295    QwtGraphic defaultIcon( const QBrush&, const QSizeF& ) const;
     296
     297  private:
     298    Q_DISABLE_COPY(QwtPlotItem)
    296299
    297300    class PrivateData;
    298     PrivateData *d_data;
     301    PrivateData* m_data;
    299302};
    300303
    … …  
    303306Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::RenderHints )
    304307
    305 Q_DECLARE_METATYPE( QwtPlotItem * )
     308Q_DECLARE_METATYPE( QwtPlotItem* )
    306309
    307310#endif
  • trunk/BNC/qwt/qwt_plot_layout.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_scale_widget.h"
    1414#include "qwt_abstract_legend.h"
    15 #include <qscrollbar.h>
    16 #include <qmath.h>
    17 
    18 class QwtPlotLayout::LayoutData
    19 {
    20 public:
    21     void init( const QwtPlot *, const QRectF &rect );
    22 
    23     struct t_legendData
    24     {
    25         int frameWidth;
    26         int hScrollExtent;
    27         int vScrollExtent;
    28         QSize hint;
    29     } legend;
    30 
    31     struct t_titleData
    32     {
    33         QwtText text;
    34         int frameWidth;
    35     } title;
    36 
    37     struct t_footerData
    38     {
    39         QwtText text;
    40         int frameWidth;
    41     } footer;
    42 
    43     struct t_scaleData
    44     {
    45         bool isEnabled;
    46         const QwtScaleWidget *scaleWidget;
    47         QFont scaleFont;
    48         int start;
    49         int end;
    50         int baseLineOffset;
    51         double tickOffset;
    52         int dimWithoutTitle;
    53     } scale[QwtPlot::axisCnt];
    54 
    55     struct t_canvasData
    56     {
    57         int contentsMargins[ QwtPlot::axisCnt ];
    58 
    59     } canvas;
    60 };
    61 
    62 /*
    63   Extract all layout relevant data from the plot components
    64 */
    65 void QwtPlotLayout::LayoutData::init( const QwtPlot *plot, const QRectF &rect )
    66 {
    67     // legend
    68 
    69     if ( plot->legend() )
    70     {
    71         legend.frameWidth = plot->legend()->frameWidth();
    72         legend.hScrollExtent =
    73             plot->legend()->scrollExtent( Qt::Horizontal );
    74         legend.vScrollExtent =
    75             plot->legend()->scrollExtent( Qt::Vertical );
    76 
    77         const QSize hint = plot->legend()->sizeHint();
    78 
    79         const int w = qMin( hint.width(), qFloor( rect.width() ) );
    80 
    81         int h = plot->legend()->heightForWidth( w );
    82         if ( h <= 0 )
    83             h = hint.height();
    84 
    85         legend.hint = QSize( w, h );
    86     }
    87 
    88     // title
    89 
    90     title.frameWidth = 0;
    91     title.text = QwtText();
    92 
    93     if ( plot->titleLabel() )
    94     {
    95         const QwtTextLabel *label = plot->titleLabel();
    96         title.text = label->text();
    97         if ( !( title.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) )
    98             title.text.setFont( label->font() );
    99 
    100         title.frameWidth = plot->titleLabel()->frameWidth();
    101     }
    102 
    103     // footer
    104 
    105     footer.frameWidth = 0;
    106     footer.text = QwtText();
    107 
    108     if ( plot->footerLabel() )
    109     {
    110         const QwtTextLabel *label = plot->footerLabel();
    111         footer.text = label->text();
    112         if ( !( footer.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) )
    113             footer.text.setFont( label->font() );
    114 
    115         footer.frameWidth = plot->footerLabel()->frameWidth();
    116     }
    117 
    118     // scales
    119 
    120     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    121     {
    122         if ( plot->axisEnabled( axis ) )
    123         {
    124             const QwtScaleWidget *scaleWidget = plot->axisWidget( axis );
    125 
    126             scale[axis].isEnabled = true;
    127 
    128             scale[axis].scaleWidget = scaleWidget;
    129 
    130             scale[axis].scaleFont = scaleWidget->font();
    131 
    132             scale[axis].start = scaleWidget->startBorderDist();
    133             scale[axis].end = scaleWidget->endBorderDist();
    134 
    135             scale[axis].baseLineOffset = scaleWidget->margin();
    136             scale[axis].tickOffset = scaleWidget->margin();
    137             if ( scaleWidget->scaleDraw()->hasComponent(
    138                 QwtAbstractScaleDraw::Ticks ) )
    139             {
    140                 scale[axis].tickOffset +=
    141                     scaleWidget->scaleDraw()->maxTickLength();
    142             }
    143 
    144             scale[axis].dimWithoutTitle = scaleWidget->dimForLength(
    145                 QWIDGETSIZE_MAX, scale[axis].scaleFont );
    146 
    147             if ( !scaleWidget->title().isEmpty() )
    148             {
    149                 scale[axis].dimWithoutTitle -=
    150                     scaleWidget->titleHeightForWidth( QWIDGETSIZE_MAX );
    151             }
    152         }
    153         else
    154         {
    155             scale[axis].isEnabled = false;
    156             scale[axis].start = 0;
    157             scale[axis].end = 0;
    158             scale[axis].baseLineOffset = 0;
    159             scale[axis].tickOffset = 0.0;
    160             scale[axis].dimWithoutTitle = 0;
    161         }
    162     }
    163 
    164     // canvas
    165 
    166     plot->canvas()->getContentsMargins(
    167         &canvas.contentsMargins[ QwtPlot::yLeft ],
    168         &canvas.contentsMargins[ QwtPlot::xTop ],
    169         &canvas.contentsMargins[ QwtPlot::yRight ],
    170         &canvas.contentsMargins[ QwtPlot::xBottom ] );
    171 }
    172 
    173 class QwtPlotLayout::PrivateData
    174 {
    175 public:
    176     PrivateData():
    177         spacing( 5 )
    178     {
    179     }
    180 
    181     QRectF titleRect;
    182     QRectF footerRect;
    183     QRectF legendRect;
    184     QRectF scaleRect[QwtPlot::axisCnt];
    185     QRectF canvasRect;
    186 
    187     QwtPlotLayout::LayoutData layoutData;
    188 
    189     QwtPlot::LegendPosition legendPos;
    190     double legendRatio;
    191     unsigned int spacing;
    192     unsigned int canvasMargin[QwtPlot::axisCnt];
    193     bool alignCanvasToScales[QwtPlot::axisCnt];
    194 };
    195 
    196 /*!
    197   \brief Constructor
    198  */
    199 
    200 QwtPlotLayout::QwtPlotLayout()
    201 {
    202     d_data = new PrivateData;
    203 
    204     setLegendPosition( QwtPlot::BottomLegend );
    205     setCanvasMargin( 4 );
    206     setAlignCanvasToScales( false );
    207 
    208     invalidate();
    209 }
    210 
    211 //! Destructor
    212 QwtPlotLayout::~QwtPlotLayout()
    213 {
    214     delete d_data;
    215 }
    216 
    217 /*!
    218   Change a margin of the canvas. The margin is the space
    219   above/below the scale ticks. A negative margin will
    220   be set to -1, excluding the borders of the scales.
    221 
    222   \param margin New margin
    223   \param axis One of QwtPlot::Axis. Specifies where the position of the margin.
    224               -1 means margin at all borders.
    225   \sa canvasMargin()
    226 
    227   \warning The margin will have no effect when alignCanvasToScale() is true
    228 */
    229 
    230 void QwtPlotLayout::setCanvasMargin( int margin, int axis )
    231 {
    232     if ( margin < -1 )
    233         margin = -1;
    234 
    235     if ( axis == -1 )
    236     {
    237         for ( axis = 0; axis < QwtPlot::axisCnt; axis++ )
    238             d_data->canvasMargin[axis] = margin;
    239     }
    240     else if ( axis >= 0 && axis < QwtPlot::axisCnt )
    241         d_data->canvasMargin[axis] = margin;
    242 }
    243 
    244 /*!
    245     \param axisId Axis index
    246     \return Margin around the scale tick borders
    247     \sa setCanvasMargin()
    248 */
    249 int QwtPlotLayout::canvasMargin( int axisId ) const
    250 {
    251     if ( axisId < 0 || axisId >= QwtPlot::axisCnt )
     15#include "qwt_math.h"
     16
     17#include <qmargins.h>
     18
     19namespace
     20{
     21    class LayoutData
     22    {
     23      public:
     24        struct LegendData
     25        {
     26            void init( const QwtAbstractLegend* legend )
     27            {
     28                if ( legend )
     29                {
     30                    frameWidth = legend->frameWidth();
     31                    hScrollExtent = legend->scrollExtent( Qt::Horizontal );
     32                    vScrollExtent = legend->scrollExtent( Qt::Vertical );
     33
     34                    hint = legend->sizeHint();
     35                }
     36            }
     37
     38            QSize legendHint( const QwtAbstractLegend* legend, const QRectF& rect ) const
     39            {
     40                const int w = qMin( hint.width(), qwtFloor( rect.width() ) );
     41
     42                int h = legend->heightForWidth( w );
     43                if ( h <= 0 )
     44                    h = hint.height();
     45
     46                return QSize( w, h );
     47            }
     48
     49            int frameWidth;
     50            int hScrollExtent;
     51            int vScrollExtent;
     52            QSize hint;
     53        };
     54
     55        struct LabelData
     56        {
     57            void init( const QwtTextLabel* label )
     58            {
     59                frameWidth = 0;
     60                text = QwtText();
     61
     62                if ( label )
     63                {
     64                    text = label->text();
     65                    if ( !( text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) )
     66                        text.setFont( label->font() );
     67
     68                    frameWidth = label->frameWidth();
     69                }
     70            }
     71
     72            QwtText text;
     73            int frameWidth;
     74        };
     75
     76        struct ScaleData
     77        {
     78            void init( const QwtScaleWidget* axisWidget )
     79            {
     80                isVisible = true;
     81
     82                scaleWidget = axisWidget;
     83                scaleFont = axisWidget->font();
     84
     85                start = axisWidget->startBorderDist();
     86                end = axisWidget->endBorderDist();
     87
     88                baseLineOffset = axisWidget->margin();
     89
     90                tickOffset = axisWidget->margin();
     91                if ( axisWidget->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) )
     92                    tickOffset += axisWidget->scaleDraw()->maxTickLength();
     93
     94                dimWithoutTitle = axisWidget->dimForLength( QWIDGETSIZE_MAX, scaleFont );
     95                if ( !axisWidget->title().isEmpty() )
     96                    dimWithoutTitle -= axisWidget->titleHeightForWidth( QWIDGETSIZE_MAX );
     97            }
     98
     99            void reset()
     100            {
     101                isVisible = false;
     102                start = 0;
     103                end = 0;
     104                baseLineOffset = 0;
     105                tickOffset = 0.0;
     106                dimWithoutTitle = 0;
     107            }
     108
     109            bool isVisible;
     110            const QwtScaleWidget* scaleWidget;
     111            QFont scaleFont;
     112            int start;
     113            int end;
     114            int baseLineOffset;
     115            double tickOffset;
     116            int dimWithoutTitle;
     117        };
     118
     119        struct CanvasData
     120        {
     121            void init( const QWidget* canvas )
     122            {
     123                const QMargins m = canvas->contentsMargins();
     124
     125                contentsMargins[ QwtAxis::YLeft ] = m.left();
     126                contentsMargins[ QwtAxis::XTop ] = m.top();
     127                contentsMargins[ QwtAxis::YRight ] = m.right();
     128                contentsMargins[ QwtAxis::XBottom ] = m.bottom();
     129            }
     130
     131            int contentsMargins[ QwtAxis::AxisPositions ];
     132        };
     133
     134      public:
     135        enum Label
     136        {
     137            Title,
     138            Footer,
     139
     140            NumLabels
     141        };
     142
     143        LayoutData( const QwtPlot* );
     144        bool hasSymmetricYAxes() const;
     145
     146        inline ScaleData& axisData( QwtAxisId axisId )
     147        {
     148            return m_scaleData[ axisId ];
     149        }
     150
     151        inline const ScaleData& axisData( QwtAxisId axisId ) const
     152        {
     153            return m_scaleData[ axisId ];
     154        }
     155
     156        inline double tickOffset( int axisPos ) const
     157        {
     158            return axisData( axisPos ).tickOffset;
     159        }
     160
     161        LegendData legendData;
     162        LabelData labelData[ NumLabels ];
     163        CanvasData canvasData;
     164
     165      private:
     166        ScaleData m_scaleData[ QwtAxis::AxisPositions ];
     167    };
     168
     169    /*
     170       Extract all layout relevant data from the plot components
     171     */
     172    LayoutData::LayoutData( const QwtPlot* plot )
     173    {
     174        legendData.init( plot->legend() );
     175        labelData[ Title ].init( plot->titleLabel() );
     176        labelData[ Footer ].init( plot->footerLabel() );
     177
     178        for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     179        {
     180            {
     181                const QwtAxisId axisId( axisPos );
     182
     183                ScaleData& scaleData = axisData( axisId );
     184
     185                if ( plot->isAxisVisible( axisId ) )
     186                {
     187                    const QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
     188                    scaleData.init( scaleWidget );
     189                }
     190                else
     191                {
     192                    scaleData.reset();
     193                }
     194            }
     195        }
     196
     197        canvasData.init( plot->canvas() );
     198    }
     199
     200    bool LayoutData::hasSymmetricYAxes() const
     201    {
     202        using namespace QwtAxis;
     203        return m_scaleData[ YLeft ].isVisible == m_scaleData[ YRight ].isVisible;
     204    }
     205}
     206
     207namespace
     208{
     209    class LayoutHintData
     210    {
     211      public:
     212        LayoutHintData( const QwtPlot* plot );
     213
     214        int alignedSize( const QwtAxisId ) const;
     215
     216        inline int yAxesWidth() const
     217        {
     218            using namespace QwtAxis;
     219            return axesWidth( YLeft ) + axesWidth( YRight );
     220        }
     221
     222        inline int yAxesHeight() const
     223        {
     224            using namespace QwtAxis;
     225            return qMax( axesHeight( YLeft ), axesHeight( YRight ) );
     226        }
     227
     228        inline int xAxesHeight() const
     229        {
     230            using namespace QwtAxis;
     231            return axesHeight( XTop ) + axesHeight( XBottom );
     232        }
     233
     234        inline int xAxesWidth() const
     235        {
     236            using namespace QwtAxis;
     237            return qMax( axesWidth( XTop ), axesWidth( XBottom ) );
     238        }
     239
     240      private:
     241
     242        struct ScaleData
     243        {
     244            ScaleData()
     245            {
     246                w = h = minLeft = minRight = tickOffset = 0;
     247            }
     248
     249            int w;
     250            int h;
     251            int minLeft;
     252            int minRight;
     253            int tickOffset;
     254
     255        };
     256
     257        const ScaleData& axisData( QwtAxisId axisId ) const
     258        {
     259            return m_scaleData[ axisId ];
     260        }
     261
     262        ScaleData& axisData( QwtAxisId axisId )
     263        {
     264            return m_scaleData[ axisId ];
     265        }
     266
     267        inline int axesWidth( int axisPos ) const
     268        {
     269            return m_scaleData[axisPos].w;
     270        }
     271
     272        inline int axesHeight( int axisPos ) const
     273        {
     274            return m_scaleData[axisPos].h;
     275        }
     276
     277        int m_canvasBorder[QwtAxis::AxisPositions];
     278        ScaleData m_scaleData[QwtAxis::AxisPositions];
     279    };
     280
     281    LayoutHintData::LayoutHintData( const QwtPlot* plot )
     282    {
     283        using namespace QwtAxis;
     284
     285        const QMargins m = plot->canvas()->contentsMargins();
     286
     287        int contentsMargins[ 4 ];
     288        contentsMargins[ YLeft ] = m.left();
     289        contentsMargins[ XTop ] = m.top();
     290        contentsMargins[ YRight ] = m.right();
     291        contentsMargins[ XBottom ] = m.bottom();
     292
     293        for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ )
     294        {
     295            m_canvasBorder[axisPos] = contentsMargins[axisPos] +
     296                plot->plotLayout()->canvasMargin( axisPos ) + 1;
     297            {
     298                const QwtAxisId axisId( axisPos );
     299
     300                if ( plot->isAxisVisible( axisId ) )
     301                {
     302                    const QwtScaleWidget* scl = plot->axisWidget( axisId );
     303
     304                    const QSize hint = scl->minimumSizeHint();
     305
     306                    ScaleData& sd = axisData( axisId );
     307                    sd.w = hint.width();
     308                    sd.h = hint.height();
     309                    scl->getBorderDistHint( sd.minLeft, sd.minRight );
     310
     311                    {
     312                        sd.tickOffset = scl->margin();
     313                        if ( scl->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) )
     314                            sd.tickOffset += qwtCeil( scl->scaleDraw()->maxTickLength() );
     315                    }
     316                }
     317            }
     318        }
     319
     320        for ( int axis = 0; axis < AxisPositions; axis++ )
     321        {
     322            const int sz = alignedSize( axis );
     323
     324            ScaleData& sd = axisData( axis );
     325            if ( isXAxis( axis ) )
     326                sd.w = sz;
     327            else
     328                sd.h = sz;
     329        }
     330    }
     331
     332    int LayoutHintData::alignedSize( const QwtAxisId axisId ) const
     333    {
     334        using namespace QwtAxis;
     335
     336        const ScaleData& sd = axisData( axisId );
     337
     338        if ( sd.w && isXAxis( axisId ) )
     339        {
     340            int w = sd.w;
     341
     342            if ( const int leftW = axesWidth( YLeft ) )
     343            {
     344                const int shiftLeft = sd.minLeft - m_canvasBorder[YLeft];
     345                if ( shiftLeft > 0 )
     346                    w -= qMin( shiftLeft, leftW );
     347            }
     348
     349            if ( const int rightW = axesWidth( YRight ) )
     350            {
     351                const int shiftRight = sd.minRight - m_canvasBorder[YRight];
     352                if ( shiftRight > 0 )
     353                    w -= qMin( shiftRight, rightW );
     354            }
     355
     356            return w;
     357        }
     358
     359        if ( sd.h && isYAxis( axisId ) )
     360        {
     361            int h = sd.h;
     362
     363            if ( axesHeight( XBottom ) )
     364            {
     365                const int shiftBottom = sd.minLeft - m_canvasBorder[XBottom];
     366                if ( shiftBottom > 0 )
     367                    h -= qMin( shiftBottom, axisData( XBottom ).tickOffset );
     368            }
     369
     370            if ( axesHeight( XTop ) )
     371            {
     372                const int shiftTop = sd.minRight - m_canvasBorder[XTop];
     373                if ( shiftTop > 0 )
     374                    h -= qMin( shiftTop, axisData( XTop ).tickOffset );
     375            }
     376
     377            return h;
     378        }
     379
    252380        return 0;
    253 
    254     return d_data->canvasMargin[axisId];
    255 }
    256 
    257 /*!
    258   \brief Set the align-canvas-to-axis-scales flag for all axes
    259 
    260   \param on True/False
    261   \sa setAlignCanvasToScale(), alignCanvasToScale()
    262 */
    263 void QwtPlotLayout::setAlignCanvasToScales( bool on )
    264 {
    265     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    266         d_data->alignCanvasToScales[axis] = on;
    267 }
    268 
    269 /*!
    270   Change the align-canvas-to-axis-scales setting. The canvas may:
    271 
    272   - extend beyond the axis scale ends to maximize its size,
    273   - align with the axis scale ends to control its size.
    274 
    275   The axisId parameter is somehow confusing as it identifies a border
    276   of the plot and not the axes, that are aligned. F.e when QwtPlot::yLeft
    277   is set, the left end of the the x-axes ( QwtPlot::xTop, QwtPlot::xBottom )
    278   is aligned.
    279 
    280   \param axisId Axis index
    281   \param on New align-canvas-to-axis-scales setting
    282 
    283   \sa setCanvasMargin(), alignCanvasToScale(), setAlignCanvasToScales()
    284   \warning In case of on == true canvasMargin() will have no effect
    285 */
    286 void QwtPlotLayout::setAlignCanvasToScale( int axisId, bool on )
    287 {
    288     if ( axisId >= 0 && axisId < QwtPlot::axisCnt )
    289         d_data->alignCanvasToScales[axisId] = on;
    290 }
    291 
    292 /*!
    293   Return the align-canvas-to-axis-scales setting. The canvas may:
    294   - extend beyond the axis scale ends to maximize its size
    295   - align with the axis scale ends to control its size.
    296 
    297   \param axisId Axis index
    298   \return align-canvas-to-axis-scales setting
    299   \sa setAlignCanvasToScale(), setAlignCanvasToScale(), setCanvasMargin()
    300 */
    301 bool QwtPlotLayout::alignCanvasToScale( int axisId ) const
    302 {
    303     if ( axisId < 0 || axisId >= QwtPlot::axisCnt )
    304         return false;
    305 
    306     return d_data->alignCanvasToScales[ axisId ];
    307 }
    308 
    309 /*!
    310   Change the spacing of the plot. The spacing is the distance
    311   between the plot components.
    312 
    313   \param spacing New spacing
    314   \sa setCanvasMargin(), spacing()
    315 */
    316 void QwtPlotLayout::setSpacing( int spacing )
    317 {
    318     d_data->spacing = qMax( 0, spacing );
    319 }
    320 
    321 /*!
    322   \return Spacing
    323   \sa margin(), setSpacing()
    324 */
    325 int QwtPlotLayout::spacing() const
    326 {
    327     return d_data->spacing;
    328 }
    329 
    330 /*!
    331   \brief Specify the position of the legend
    332   \param pos The legend's position.
    333   \param ratio Ratio between legend and the bounding rectangle
    334                of title, footer, canvas and axes. The legend will be shrunk
    335                if it would need more space than the given ratio.
    336                The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
    337                it will be reset to the default ratio.
    338                The default vertical/horizontal ratio is 0.33/0.5.
    339 
    340   \sa QwtPlot::setLegendPosition()
    341 */
    342 
    343 void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos, double ratio )
    344 {
    345     if ( ratio > 1.0 )
    346         ratio = 1.0;
    347 
    348     switch ( pos )
    349     {
    350         case QwtPlot::TopLegend:
    351         case QwtPlot::BottomLegend:
    352             if ( ratio <= 0.0 )
    353                 ratio = 0.33;
    354             d_data->legendRatio = ratio;
    355             d_data->legendPos = pos;
    356             break;
    357         case QwtPlot::LeftLegend:
    358         case QwtPlot::RightLegend:
    359             if ( ratio <= 0.0 )
    360                 ratio = 0.5;
    361             d_data->legendRatio = ratio;
    362             d_data->legendPos = pos;
    363             break;
    364         default:
    365             break;
    366     }
    367 }
    368 
    369 /*!
    370   \brief Specify the position of the legend
    371   \param pos The legend's position. Valid values are
    372       \c QwtPlot::LeftLegend, \c QwtPlot::RightLegend,
    373       \c QwtPlot::TopLegend, \c QwtPlot::BottomLegend.
    374 
    375   \sa QwtPlot::setLegendPosition()
    376 */
    377 void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos )
    378 {
    379     setLegendPosition( pos, 0.0 );
    380 }
    381 
    382 /*!
    383   \return Position of the legend
    384   \sa setLegendPosition(), QwtPlot::setLegendPosition(),
    385       QwtPlot::legendPosition()
    386 */
    387 QwtPlot::LegendPosition QwtPlotLayout::legendPosition() const
    388 {
    389     return d_data->legendPos;
    390 }
    391 
    392 /*!
    393   Specify the relative size of the legend in the plot
    394   \param ratio Ratio between legend and the bounding rectangle
    395                of title, footer, canvas and axes. The legend will be shrunk
    396                if it would need more space than the given ratio.
    397                The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
    398                it will be reset to the default ratio.
    399                The default vertical/horizontal ratio is 0.33/0.5.
    400 */
    401 void QwtPlotLayout::setLegendRatio( double ratio )
    402 {
    403     setLegendPosition( legendPosition(), ratio );
    404 }
    405 
    406 /*!
    407   \return The relative size of the legend in the plot.
    408   \sa setLegendPosition()
    409 */
    410 double QwtPlotLayout::legendRatio() const
    411 {
    412     return d_data->legendRatio;
    413 }
    414 
    415 /*!
    416   \brief Set the geometry for the title
    417 
    418   This method is intended to be used from derived layouts
    419   overloading activate()
    420 
    421   \sa titleRect(), activate()
    422  */
    423 void QwtPlotLayout::setTitleRect( const QRectF &rect )
    424 {
    425     d_data->titleRect = rect;
    426 }
    427 
    428 /*!
    429   \return Geometry for the title
    430   \sa activate(), invalidate()
    431 */
    432 QRectF QwtPlotLayout::titleRect() const
    433 {
    434     return d_data->titleRect;
    435 }
    436 
    437 /*!
    438   \brief Set the geometry for the footer
    439 
    440   This method is intended to be used from derived layouts
    441   overloading activate()
    442 
    443   \sa footerRect(), activate()
    444  */
    445 void QwtPlotLayout::setFooterRect( const QRectF &rect )
    446 {
    447     d_data->footerRect = rect;
    448 }
    449 
    450 /*!
    451   \return Geometry for the footer
    452   \sa activate(), invalidate()
    453 */
    454 QRectF QwtPlotLayout::footerRect() const
    455 {
    456     return d_data->footerRect;
    457 }
    458 
    459 /*!
    460   \brief Set the geometry for the legend
    461 
    462   This method is intended to be used from derived layouts
    463   overloading activate()
    464 
    465   \param rect Rectangle for the legend
    466 
    467   \sa legendRect(), activate()
    468  */
    469 void QwtPlotLayout::setLegendRect( const QRectF &rect )
    470 {
    471     d_data->legendRect = rect;
    472 }
    473 
    474 /*!
    475   \return Geometry for the legend
    476   \sa activate(), invalidate()
    477 */
    478 QRectF QwtPlotLayout::legendRect() const
    479 {
    480     return d_data->legendRect;
    481 }
    482 
    483 /*!
    484   \brief Set the geometry for an axis
    485 
    486   This method is intended to be used from derived layouts
    487   overloading activate()
    488 
    489   \param axis Axis index
    490   \param rect Rectangle for the scale
    491 
    492   \sa scaleRect(), activate()
    493  */
    494 void QwtPlotLayout::setScaleRect( int axis, const QRectF &rect )
    495 {
    496     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    497         d_data->scaleRect[axis] = rect;
    498 }
    499 
    500 /*!
    501   \param axis Axis index
    502   \return Geometry for the scale
    503   \sa activate(), invalidate()
    504 */
    505 QRectF QwtPlotLayout::scaleRect( int axis ) const
    506 {
    507     if ( axis < 0 || axis >= QwtPlot::axisCnt )
    508     {
    509         static QRectF dummyRect;
    510         return dummyRect;
    511     }
    512     return d_data->scaleRect[axis];
    513 }
    514 
    515 /*!
    516   \brief Set the geometry for the canvas
    517 
    518   This method is intended to be used from derived layouts
    519   overloading activate()
    520 
    521   \sa canvasRect(), activate()
    522  */
    523 void QwtPlotLayout::setCanvasRect( const QRectF &rect )
    524 {
    525     d_data->canvasRect = rect;
    526 }
    527 
    528 /*!
    529   \return Geometry for the canvas
    530   \sa activate(), invalidate()
    531 */
    532 QRectF QwtPlotLayout::canvasRect() const
    533 {
    534     return d_data->canvasRect;
    535 }
    536 
    537 /*!
    538   Invalidate the geometry of all components.
    539   \sa activate()
    540 */
    541 void QwtPlotLayout::invalidate()
    542 {
    543     d_data->titleRect = d_data->footerRect
    544         = d_data->legendRect = d_data->canvasRect = QRect();
    545 
    546     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    547         d_data->scaleRect[axis] = QRect();
    548 }
    549 
    550 /*!
    551   \return Minimum size hint
    552   \param plot Plot widget
    553 
    554   \sa QwtPlot::minimumSizeHint()
    555 */
    556 
    557 QSize QwtPlotLayout::minimumSizeHint( const QwtPlot *plot ) const
    558 {
    559     class ScaleData
    560     {
    561     public:
    562         ScaleData()
    563         {
    564             w = h = minLeft = minRight = tickOffset = 0;
    565         }
    566 
    567         int w;
    568         int h;
    569         int minLeft;
    570         int minRight;
    571         int tickOffset;
    572     } scaleData[QwtPlot::axisCnt];
    573 
    574     int canvasBorder[QwtPlot::axisCnt];
    575 
    576     int fw;
    577     plot->canvas()->getContentsMargins( &fw, NULL, NULL, NULL );
    578 
    579     int axis;
    580     for ( axis = 0; axis < QwtPlot::axisCnt; axis++ )
    581     {
    582         if ( plot->axisEnabled( axis ) )
    583         {
    584             const QwtScaleWidget *scl = plot->axisWidget( axis );
    585             ScaleData &sd = scaleData[axis];
    586 
    587             const QSize hint = scl->minimumSizeHint();
    588             sd.w = hint.width();
    589             sd.h = hint.height();
    590             scl->getBorderDistHint( sd.minLeft, sd.minRight );
    591             sd.tickOffset = scl->margin();
    592             if ( scl->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) )
    593                 sd.tickOffset += qCeil( scl->scaleDraw()->maxTickLength() );
    594         }
    595 
    596         canvasBorder[axis] = fw + d_data->canvasMargin[axis] + 1;
    597     }
    598 
    599 
    600     for ( axis = 0; axis < QwtPlot::axisCnt; axis++ )
    601     {
    602         ScaleData &sd = scaleData[axis];
    603         if ( sd.w && ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) )
    604         {
    605             if ( ( sd.minLeft > canvasBorder[QwtPlot::yLeft] )
    606                 && scaleData[QwtPlot::yLeft].w )
    607             {
    608                 int shiftLeft = sd.minLeft - canvasBorder[QwtPlot::yLeft];
    609                 if ( shiftLeft > scaleData[QwtPlot::yLeft].w )
    610                     shiftLeft = scaleData[QwtPlot::yLeft].w;
    611 
    612                 sd.w -= shiftLeft;
    613             }
    614             if ( ( sd.minRight > canvasBorder[QwtPlot::yRight] )
    615                 && scaleData[QwtPlot::yRight].w )
    616             {
    617                 int shiftRight = sd.minRight - canvasBorder[QwtPlot::yRight];
    618                 if ( shiftRight > scaleData[QwtPlot::yRight].w )
    619                     shiftRight = scaleData[QwtPlot::yRight].w;
    620 
    621                 sd.w -= shiftRight;
    622             }
    623         }
    624 
    625         if ( sd.h && ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) )
    626         {
    627             if ( ( sd.minLeft > canvasBorder[QwtPlot::xBottom] ) &&
    628                 scaleData[QwtPlot::xBottom].h )
    629             {
    630                 int shiftBottom = sd.minLeft - canvasBorder[QwtPlot::xBottom];
    631                 if ( shiftBottom > scaleData[QwtPlot::xBottom].tickOffset )
    632                     shiftBottom = scaleData[QwtPlot::xBottom].tickOffset;
    633 
    634                 sd.h -= shiftBottom;
    635             }
    636             if ( ( sd.minLeft > canvasBorder[QwtPlot::xTop] ) &&
    637                 scaleData[QwtPlot::xTop].h )
    638             {
    639                 int shiftTop = sd.minRight - canvasBorder[QwtPlot::xTop];
    640                 if ( shiftTop > scaleData[QwtPlot::xTop].tickOffset )
    641                     shiftTop = scaleData[QwtPlot::xTop].tickOffset;
    642 
    643                 sd.h -= shiftTop;
    644             }
    645         }
    646     }
    647 
    648     const QWidget *canvas = plot->canvas();
    649 
    650     int left, top, right, bottom;
    651     canvas->getContentsMargins( &left, &top, &right, &bottom );
    652 
    653     const QSize minCanvasSize = canvas->minimumSize();
    654 
    655     int w = scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w;
    656     int cw = qMax( scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w )
    657         + left + 1 + right + 1;
    658     w += qMax( cw, minCanvasSize.width() );
    659 
    660     int h = scaleData[QwtPlot::xBottom].h + scaleData[QwtPlot::xTop].h;
    661     int ch = qMax( scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h )
    662         + top + 1 + bottom + 1;
    663     h += qMax( ch, minCanvasSize.height() );
    664 
    665     const QwtTextLabel *labels[2];
    666     labels[0] = plot->titleLabel();
    667     labels[1] = plot->footerLabel();
    668 
    669     for ( int i = 0; i < 2; i++ )
    670     {
    671         const QwtTextLabel *label   = labels[i];
    672         if ( label && !label->text().isEmpty() )
    673         {
    674             // If only QwtPlot::yLeft or QwtPlot::yRight is showing,
    675             // we center on the plot canvas.
    676             const bool centerOnCanvas = !( plot->axisEnabled( QwtPlot::yLeft )
    677                 && plot->axisEnabled( QwtPlot::yRight ) );
    678 
    679             int labelW = w;
    680             if ( centerOnCanvas )
    681             {
    682                 labelW -= scaleData[QwtPlot::yLeft].w
    683                     + scaleData[QwtPlot::yRight].w;
    684             }
    685 
    686             int labelH = label->heightForWidth( labelW );
    687             if ( labelH > labelW ) // Compensate for a long title
    688             {
    689                 w = labelW = labelH;
    690                 if ( centerOnCanvas )
    691                 {
    692                     w += scaleData[QwtPlot::yLeft].w
    693                         + scaleData[QwtPlot::yRight].w;
    694                 }
    695 
    696                 labelH = label->heightForWidth( labelW );
    697             }
    698             h += labelH + d_data->spacing;
    699         }
    700     }
    701 
    702     // Compute the legend contribution
    703 
    704     const QwtAbstractLegend *legend = plot->legend();
    705     if ( legend && !legend->isEmpty() )
    706     {
    707         if ( d_data->legendPos == QwtPlot::LeftLegend
    708             || d_data->legendPos == QwtPlot::RightLegend )
    709         {
    710             int legendW = legend->sizeHint().width();
    711             int legendH = legend->heightForWidth( legendW );
    712 
    713             if ( legend->frameWidth() > 0 )
    714                 w += d_data->spacing;
    715 
    716             if ( legendH > h )
    717                 legendW += legend->scrollExtent( Qt::Horizontal );
    718 
    719             if ( d_data->legendRatio < 1.0 )
    720                 legendW = qMin( legendW, int( w / ( 1.0 - d_data->legendRatio ) ) );
    721 
    722             w += legendW + d_data->spacing;
    723         }
    724         else // QwtPlot::Top, QwtPlot::Bottom
    725         {
    726             int legendW = qMin( legend->sizeHint().width(), w );
    727             int legendH = legend->heightForWidth( legendW );
    728 
    729             if ( legend->frameWidth() > 0 )
    730                 h += d_data->spacing;
    731 
    732             if ( d_data->legendRatio < 1.0 )
    733                 legendH = qMin( legendH, int( h / ( 1.0 - d_data->legendRatio ) ) );
    734 
    735             h += legendH + d_data->spacing;
    736         }
    737     }
    738 
    739     return QSize( w, h );
    740 }
    741 
    742 /*!
    743   Find the geometry for the legend
    744 
    745   \param options Options how to layout the legend
    746   \param rect Rectangle where to place the legend
    747 
    748   \return Geometry for the legend
    749   \sa Options
    750 */
    751 
    752 QRectF QwtPlotLayout::layoutLegend( Options options,
    753     const QRectF &rect ) const
    754 {
    755     const QSize hint( d_data->layoutData.legend.hint );
    756 
     381    }
     382}
     383
     384namespace
     385{
     386    class LayoutEngine
     387    {
     388      public:
     389        struct Dimensions
     390        {
     391            Dimensions()
     392            {
     393                dimTitle = dimFooter = 0;
     394                for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     395                    m_dimAxes[axisPos] = 0;
     396            }
     397
     398            inline int dimAxis( QwtAxisId axisId ) const
     399            {
     400                return m_dimAxes[ axisId ];
     401            }
     402
     403            void setDimAxis( QwtAxisId axisId, int dim )
     404            {
     405                m_dimAxes[ axisId ] = dim;
     406            }
     407
     408            inline int dimAxes( int axisPos ) const
     409            {
     410                return m_dimAxes[ axisPos ];
     411            }
     412
     413            inline int dimYAxes() const
     414            {
     415                return dimAxes( QwtAxis::YLeft ) + dimAxes( QwtAxis::YRight );
     416            }
     417
     418            inline int dimXAxes() const
     419            {
     420                return dimAxes( QwtAxis::XTop ) + dimAxes( QwtAxis::XBottom );
     421            }
     422
     423            inline QRectF centered( const QRectF& rect, const QRectF& labelRect ) const
     424            {
     425                QRectF r = labelRect;
     426                r.setX( rect.left() + dimAxes( QwtAxis::YLeft ) );
     427                r.setWidth( rect.width() - dimYAxes() );
     428
     429                return r;
     430            }
     431
     432            inline QRectF innerRect( const QRectF& rect ) const
     433            {
     434                QRectF r(
     435                    rect.x() + dimAxes( QwtAxis::YLeft ),
     436                    rect.y() + dimAxes( QwtAxis::XTop ),
     437                    rect.width() - dimYAxes(),
     438                    rect.height() - dimXAxes() );
     439
     440                if ( r.width() < 0 )
     441                {
     442                    r.setX( rect.center().x() );
     443                    r.setWidth( 0 );
     444                }
     445                if ( r.height() < 0 )
     446                {
     447                    r.setY( rect.center().y() );
     448                    r.setHeight( 0 );
     449                }
     450
     451                return r;
     452            }
     453
     454            int dimTitle;
     455            int dimFooter;
     456
     457          private:
     458            int m_dimAxes[QwtAxis::AxisPositions];
     459        };
     460
     461        LayoutEngine()
     462            : m_legendPos( QwtPlot::BottomLegend )
     463            , m_legendRatio( 1.0 )
     464            , m_spacing( 5 )
     465        {
     466        }
     467
     468        QRectF layoutLegend( QwtPlotLayout::Options,
     469            const LayoutData::LegendData&, const QRectF&, const QSize& ) const;
     470
     471        QRectF alignLegend( const QSize& legendHint,
     472            const QRectF& canvasRect, const QRectF& legendRect ) const;
     473
     474        void alignScales( QwtPlotLayout::Options,
     475            const LayoutData&, QRectF& canvasRect,
     476            QRectF scaleRect[QwtAxis::AxisPositions] ) const;
     477
     478        Dimensions layoutDimensions( QwtPlotLayout::Options,
     479            const LayoutData&, const QRectF& ) const;
     480
     481        inline void setSpacing( unsigned int spacing ) { m_spacing = spacing; }
     482        inline unsigned int spacing() const { return m_spacing; }
     483
     484        inline void setAlignCanvas( int axisPos, bool on ) { m_alignCanvas[ axisPos ] = on; }
     485        inline bool alignCanvas( int axisPos ) const { return m_alignCanvas[ axisPos ]; }
     486
     487        inline void setCanvasMargin( int axisPos, int margin ) { m_canvasMargin[ axisPos ] = margin; }
     488        inline int canvasMargin( int axisPos ) const { return m_canvasMargin[ axisPos ]; }
     489
     490        inline void setLegendPos( QwtPlot::LegendPosition pos ) { m_legendPos = pos; }
     491        inline QwtPlot::LegendPosition legendPos() const { return m_legendPos; }
     492
     493        inline void setLegendRatio( double ratio ) { m_legendRatio = ratio; }
     494        inline double legendRatio() const { return m_legendRatio; }
     495
     496      private:
     497        int heightForWidth( LayoutData::Label, const LayoutData&,
     498            QwtPlotLayout::Options, double width, int axesWidth ) const;
     499
     500        QwtPlot::LegendPosition m_legendPos;
     501        double m_legendRatio;
     502
     503        unsigned int m_canvasMargin[QwtAxis::AxisPositions];
     504        bool m_alignCanvas[QwtAxis::AxisPositions];
     505
     506        unsigned int m_spacing;
     507    };
     508}
     509
     510QRectF LayoutEngine::layoutLegend( QwtPlotLayout::Options options,
     511    const LayoutData::LegendData& legendData,
     512    const QRectF& rect, const QSize& legendHint ) const
     513{
    757514    int dim;
    758     if ( d_data->legendPos == QwtPlot::LeftLegend
    759         || d_data->legendPos == QwtPlot::RightLegend )
     515    if ( m_legendPos == QwtPlot::LeftLegend
     516        || m_legendPos == QwtPlot::RightLegend )
    760517    {
    761518        // We don't allow vertical legends to take more than
    762519        // half of the available space.
    763520
    764         dim = qMin( hint.width(), int( rect.width() * d_data->legendRatio ) );
    765 
    766         if ( !( options & IgnoreScrollbars ) )
    767         {
    768             if ( hint.height() > rect.height() )
     521        dim = qMin( legendHint.width(), int( rect.width() * m_legendRatio ) );
     522
     523        if ( !( options & QwtPlotLayout::IgnoreScrollbars ) )
     524        {
     525            if ( legendHint.height() > rect.height() )
    769526            {
    770527                // The legend will need additional
    771528                // space for the vertical scrollbar.
    772529
    773                 dim += d_data->layoutData.legend.hScrollExtent;
     530                dim += legendData.hScrollExtent;
    774531            }
    775532        }
    … …  
    777534    else
    778535    {
    779         dim = qMin( hint.height(), int( rect.height() * d_data->legendRatio ) );
    780         dim = qMax( dim, d_data->layoutData.legend.vScrollExtent );
     536        dim = qMin( legendHint.height(), int( rect.height() * m_legendRatio ) );
     537        dim = qMax( dim, legendData.vScrollExtent );
    781538    }
    782539
    783540    QRectF legendRect = rect;
    784     switch ( d_data->legendPos )
     541    switch ( m_legendPos )
    785542    {
    786543        case QwtPlot::LeftLegend:
     544        {
    787545            legendRect.setWidth( dim );
    788546            break;
     547        }
    789548        case QwtPlot::RightLegend:
     549        {
    790550            legendRect.setX( rect.right() - dim );
    791551            legendRect.setWidth( dim );
    792552            break;
     553        }
    793554        case QwtPlot::TopLegend:
     555        {
    794556            legendRect.setHeight( dim );
    795557            break;
     558        }
    796559        case QwtPlot::BottomLegend:
     560        {
    797561            legendRect.setY( rect.bottom() - dim );
    798562            legendRect.setHeight( dim );
    799563            break;
     564        }
    800565    }
    801566
    … …  
    803568}
    804569
    805 /*!
    806   Align the legend to the canvas
    807 
    808   \param canvasRect Geometry of the canvas
    809   \param legendRect Maximum geometry for the legend
    810 
    811   \return Geometry for the aligned legend
    812 */
    813 QRectF QwtPlotLayout::alignLegend( const QRectF &canvasRect,
    814     const QRectF &legendRect ) const
     570QRectF LayoutEngine::alignLegend( const QSize& legendHint,
     571    const QRectF& canvasRect, const QRectF& legendRect ) const
    815572{
    816573    QRectF alignedRect = legendRect;
    817574
    818     if ( d_data->legendPos == QwtPlot::BottomLegend
    819         || d_data->legendPos == QwtPlot::TopLegend )
    820     {
    821         if ( d_data->layoutData.legend.hint.width() < canvasRect.width() )
     575    if ( m_legendPos == QwtPlot::BottomLegend
     576        || m_legendPos == QwtPlot::TopLegend )
     577    {
     578        if ( legendHint.width() < canvasRect.width() )
    822579        {
    823580            alignedRect.setX( canvasRect.x() );
    … …  
    827584    else
    828585    {
    829         if ( d_data->layoutData.legend.hint.height() < canvasRect.height() )
     586        if ( legendHint.height() < canvasRect.height() )
    830587        {
    831588            alignedRect.setY( canvasRect.y() );
    … …  
    837594}
    838595
    839 /*!
    840   Expand all line breaks in text labels, and calculate the height
    841   of their widgets in orientation of the text.
    842 
    843   \param options Options how to layout the legend
    844   \param rect Bounding rectangle for title, footer, axes and canvas.
    845   \param dimTitle Expanded height of the title widget
    846   \param dimFooter Expanded height of the footer widget
    847   \param dimAxes Expanded heights of the axis in axis orientation.
    848 
    849   \sa Options
    850 */
    851 void QwtPlotLayout::expandLineBreaks( Options options, const QRectF &rect,
    852     int &dimTitle, int &dimFooter, int dimAxes[QwtPlot::axisCnt] ) const
    853 {
    854     dimTitle = dimFooter = 0;
    855     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    856         dimAxes[axis] = 0;
    857 
    858     int backboneOffset[QwtPlot::axisCnt];
    859     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    860     {
    861         backboneOffset[axis] = 0;
    862         if ( !( options & IgnoreFrames ) )
    863             backboneOffset[axis] += d_data->layoutData.canvas.contentsMargins[ axis ];
    864 
    865         if ( !d_data->alignCanvasToScales[axis] )
    866             backboneOffset[axis] += d_data->canvasMargin[axis];
     596int LayoutEngine::heightForWidth(
     597    LayoutData::Label labelType, const LayoutData& layoutData,
     598    QwtPlotLayout::Options options,
     599    double width, int axesWidth ) const
     600{
     601    const LayoutData::LabelData& labelData = layoutData.labelData[ labelType ];
     602
     603    if ( labelData.text.isEmpty() )
     604        return 0;
     605
     606    double w = width;
     607
     608    if ( !layoutData.hasSymmetricYAxes() )
     609    {
     610        // center to the canvas
     611        w -= axesWidth;
     612    }
     613
     614    int d = qwtCeil( labelData.text.heightForWidth( w ) );
     615    if ( !( options & QwtPlotLayout::IgnoreFrames ) )
     616        d += 2 * labelData.frameWidth;
     617
     618    return d;
     619}
     620
     621LayoutEngine::Dimensions LayoutEngine::layoutDimensions( QwtPlotLayout::Options options,
     622    const LayoutData& layoutData, const QRectF& rect ) const
     623{
     624    using namespace QwtAxis;
     625
     626    Dimensions dimensions;
     627
     628    int backboneOffset[AxisPositions];
     629    for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ )
     630    {
     631        backboneOffset[axisPos] = 0;
     632        if ( !( options & QwtPlotLayout::IgnoreFrames ) )
     633            backboneOffset[axisPos] += layoutData.canvasData.contentsMargins[axisPos];
     634
     635        if ( !m_alignCanvas[axisPos] )
     636            backboneOffset[axisPos] += m_canvasMargin[axisPos];
    867637    }
    868638
    … …  
    880650        // axis ... . So we loop as long until no size changes.
    881651
    882         if ( !( ( options & IgnoreTitle ) ||
    883             d_data->layoutData.title.text.isEmpty() ) )
    884         {
    885             double w = rect.width();
    886 
    887             if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled
    888                 != d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
    889             {
    890                 // center to the canvas
    891                 w -= dimAxes[QwtPlot::yLeft] + dimAxes[QwtPlot::yRight];
    892             }
    893 
    894             int d = qCeil( d_data->layoutData.title.text.heightForWidth( w ) );
    895             if ( !( options & IgnoreFrames ) )
    896                 d += 2 * d_data->layoutData.title.frameWidth;
    897 
    898             if ( d > dimTitle )
    899             {
    900                 dimTitle = d;
     652        if ( !( options & QwtPlotLayout::IgnoreTitle ) )
     653        {
     654            const int d = heightForWidth(
     655                LayoutData::Title, layoutData, options,
     656                rect.width(), dimensions.dimYAxes() );
     657
     658            if ( d > dimensions.dimTitle )
     659            {
     660                dimensions.dimTitle = d;
    901661                done = false;
    902662            }
    903663        }
    904664
    905         if ( !( ( options & IgnoreFooter ) ||
    906             d_data->layoutData.footer.text.isEmpty() ) )
    907         {
    908             double w = rect.width();
    909 
    910             if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled
    911                 != d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
    912             {
    913                 // center to the canvas
    914                 w -= dimAxes[QwtPlot::yLeft] + dimAxes[QwtPlot::yRight];
    915             }
    916 
    917             int d = qCeil( d_data->layoutData.footer.text.heightForWidth( w ) );
    918             if ( !( options & IgnoreFrames ) )
    919                 d += 2 * d_data->layoutData.footer.frameWidth;
    920 
    921             if ( d > dimFooter )
    922             {
    923                 dimFooter = d;
     665        if ( !( options & QwtPlotLayout::IgnoreFooter ) )
     666        {
     667            const int d = heightForWidth(
     668                LayoutData::Footer, layoutData, options,
     669                rect.width(), dimensions.dimYAxes() );
     670
     671            if ( d > dimensions.dimFooter )
     672            {
     673                dimensions.dimFooter = d;
    924674                done = false;
    925675            }
    926676        }
    927677
    928         for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    929         {
    930             const struct LayoutData::t_scaleData &scaleData =
    931                 d_data->layoutData.scale[axis];
    932 
    933             if ( scaleData.isEnabled )
    934             {
    935                 double length;
    936                 if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
    937                 {
    938                     length = rect.width() - dimAxes[QwtPlot::yLeft]
    939                         - dimAxes[QwtPlot::yRight];
    940                     length -= scaleData.start + scaleData.end;
    941 
    942                     if ( dimAxes[QwtPlot::yRight] > 0 )
     678        for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ )
     679        {
     680            {
     681                const QwtAxisId axisId( axisPos );
     682
     683                const LayoutData::ScaleData& scaleData = layoutData.axisData( axisId );
     684
     685                if ( scaleData.isVisible )
     686                {
     687                    double length;
     688                    if ( isXAxis( axisPos ) )
     689                    {
     690                        length = rect.width() - dimensions.dimYAxes();
     691                        length -= scaleData.start + scaleData.end;
     692
     693                        if ( dimensions.dimAxes( YRight ) > 0 )
     694                            length -= 1;
     695
     696                        length += qMin( dimensions.dimAxes( YLeft ),
     697                            scaleData.start - backboneOffset[YLeft] );
     698
     699                        length += qMin( dimensions.dimAxes( YRight ),
     700                            scaleData.end - backboneOffset[YRight] );
     701                    }
     702                    else // y axis
     703                    {
     704                        length = rect.height() - dimensions.dimXAxes();
     705                        length -= scaleData.start + scaleData.end;
    943706                        length -= 1;
    944707
    945                     length += qMin( dimAxes[QwtPlot::yLeft],
    946                         scaleData.start - backboneOffset[QwtPlot::yLeft] );
    947                     length += qMin( dimAxes[QwtPlot::yRight],
    948                         scaleData.end - backboneOffset[QwtPlot::yRight] );
    949                 }
    950                 else // QwtPlot::yLeft, QwtPlot::yRight
    951                 {
    952                     length = rect.height() - dimAxes[QwtPlot::xTop]
    953                         - dimAxes[QwtPlot::xBottom];
    954                     length -= scaleData.start + scaleData.end;
    955                     length -= 1;
    956 
    957                     if ( dimAxes[QwtPlot::xBottom] <= 0 )
    958                         length -= 1;
    959                     if ( dimAxes[QwtPlot::xTop] <= 0 )
    960                         length -= 1;
    961 
    962                     if ( dimAxes[QwtPlot::xBottom] > 0 )
    963                     {
    964                         length += qMin(
    965                             d_data->layoutData.scale[QwtPlot::xBottom].tickOffset,
    966                             double( scaleData.start - backboneOffset[QwtPlot::xBottom] ) );
    967                     }
    968                     if ( dimAxes[QwtPlot::xTop] > 0 )
    969                     {
    970                         length += qMin(
    971                             d_data->layoutData.scale[QwtPlot::xTop].tickOffset,
    972                             double( scaleData.end - backboneOffset[QwtPlot::xTop] ) );
    973                     }
    974 
    975                     if ( dimTitle > 0 )
    976                         length -= dimTitle + d_data->spacing;
    977                 }
    978 
    979                 int d = scaleData.dimWithoutTitle;
    980                 if ( !scaleData.scaleWidget->title().isEmpty() )
    981                 {
    982                     d += scaleData.scaleWidget->titleHeightForWidth( qFloor( length ) );
    983                 }
    984 
    985 
    986                 if ( d > dimAxes[axis] )
    987                 {
    988                     dimAxes[axis] = d;
    989                     done = false;
    990                 }
    991             }
    992         }
    993     }
    994 }
    995 
    996 /*!
    997   Align the ticks of the axis to the canvas borders using
    998   the empty corners.
    999 
    1000   \param options Layout options
    1001   \param canvasRect Geometry of the canvas ( IN/OUT )
    1002   \param scaleRect Geometries of the scales ( IN/OUT )
    1003 
    1004   \sa Options
    1005 */
    1006 
    1007 void QwtPlotLayout::alignScales( Options options,
    1008     QRectF &canvasRect, QRectF scaleRect[QwtPlot::axisCnt] ) const
    1009 {
    1010     int backboneOffset[QwtPlot::axisCnt];
    1011     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    1012     {
    1013         backboneOffset[axis] = 0;
    1014 
    1015         if ( !d_data->alignCanvasToScales[axis] )
    1016         {
    1017             backboneOffset[axis] += d_data->canvasMargin[axis];
    1018         }
    1019 
    1020         if ( !( options & IgnoreFrames ) )
    1021         {
    1022             backboneOffset[axis] +=
    1023                 d_data->layoutData.canvas.contentsMargins[axis];
    1024         }
    1025     }
    1026 
    1027     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    1028     {
    1029         if ( !scaleRect[axis].isValid() )
    1030             continue;
    1031 
    1032         const int startDist = d_data->layoutData.scale[axis].start;
    1033         const int endDist = d_data->layoutData.scale[axis].end;
    1034 
    1035         QRectF &axisRect = scaleRect[axis];
    1036 
    1037         if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
    1038         {
    1039             const QRectF &leftScaleRect = scaleRect[QwtPlot::yLeft];
    1040             const int leftOffset =
    1041                 backboneOffset[QwtPlot::yLeft] - startDist;
    1042 
    1043             if ( leftScaleRect.isValid() )
    1044             {
    1045                 const double dx = leftOffset + leftScaleRect.width();
    1046                 if ( d_data->alignCanvasToScales[QwtPlot::yLeft] && dx < 0.0 )
    1047                 {
    1048                     /*
    1049                       The axis needs more space than the width
    1050                       of the left scale.
    1051                      */
    1052                     const double cLeft = canvasRect.left(); // qreal -> double
    1053                     canvasRect.setLeft( qMax( cLeft, axisRect.left() - dx ) );
     708                        if ( dimensions.dimAxes( XBottom ) <= 0 )
     709                            length -= 1;
     710
     711                        if ( dimensions.dimAxes( XTop ) <= 0 )
     712                            length -= 1;
     713
     714                        /*
     715                           The tick labels of the y axes are always left/right from the
     716                           backbone/ticks of the x axes - but we have to take care,
     717                           that the labels don't overlap.
     718                         */
     719                        if ( dimensions.dimAxes( XBottom ) > 0 )
     720                        {
     721                            length += qMin(
     722                                layoutData.tickOffset( XBottom ),
     723                                double( scaleData.start - backboneOffset[XBottom] ) );
     724                        }
     725
     726                        if ( dimensions.dimAxes( XTop ) > 0 )
     727                        {
     728                            length += qMin(
     729                                layoutData.tickOffset( XTop ),
     730                                double( scaleData.end - backboneOffset[XTop] ) );
     731                        }
     732
     733                        if ( dimensions.dimTitle > 0 )
     734                            length -= dimensions.dimTitle + m_spacing;
     735                    }
     736
     737                    int d = scaleData.dimWithoutTitle;
     738                    if ( !scaleData.scaleWidget->title().isEmpty() )
     739                    {
     740                        d += scaleData.scaleWidget->titleHeightForWidth( qwtFloor( length ) );
     741                    }
     742
     743
     744                    if ( d > dimensions.dimAxis( axisId ) )
     745                    {
     746                        dimensions.setDimAxis( axisId, d );
     747                        done = false;
     748                    }
     749                }
     750            }
     751        }
     752    }
     753
     754    return dimensions;
     755}
     756
     757void LayoutEngine::alignScales( QwtPlotLayout::Options options,
     758    const LayoutData& layoutData, QRectF& canvasRect,
     759    QRectF scaleRect[QwtAxis::AxisPositions] ) const
     760{
     761    using namespace QwtAxis;
     762
     763    int backboneOffset[AxisPositions];
     764    for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ )
     765    {
     766        backboneOffset[axisPos] = 0;
     767
     768        if ( !m_alignCanvas[axisPos] )
     769        {
     770            backboneOffset[axisPos] += m_canvasMargin[axisPos];
     771        }
     772
     773        if ( !( options & QwtPlotLayout::IgnoreFrames ) )
     774        {
     775            backboneOffset[axisPos] +=
     776                layoutData.canvasData.contentsMargins[axisPos];
     777        }
     778    }
     779
     780    for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ )
     781    {
     782        {
     783            QRectF& axisRect = scaleRect[axisPos];
     784            if ( !axisRect.isValid() )
     785                continue;
     786
     787            const QwtAxisId axisId( axisPos );
     788
     789            const int startDist = layoutData.axisData( axisId ).start;
     790            const int endDist = layoutData.axisData( axisId ).end;
     791
     792            if ( isXAxis( axisPos ) )
     793            {
     794                const QRectF& leftScaleRect = scaleRect[YLeft];
     795                const int leftOffset = backboneOffset[YLeft] - startDist;
     796
     797                if ( leftScaleRect.isValid() )
     798                {
     799                    const double dx = leftOffset + leftScaleRect.width();
     800                    if ( m_alignCanvas[YLeft] && dx < 0.0 )
     801                    {
     802                        /*
     803                           The axis needs more space than the width
     804                           of the left scale.
     805                         */
     806                        const double cLeft = canvasRect.left(); // qreal -> double
     807                        canvasRect.setLeft( qwtMaxF( cLeft, axisRect.left() - dx ) );
     808                    }
     809                    else
     810                    {
     811                        const double minLeft = leftScaleRect.left();
     812                        const double left = axisRect.left() + leftOffset;
     813                        axisRect.setLeft( qwtMaxF( left, minLeft ) );
     814                    }
    1054815                }
    1055816                else
    1056817                {
    1057                     const double minLeft = leftScaleRect.left();
    1058                     const double left = axisRect.left() + leftOffset;
    1059                     axisRect.setLeft( qMax( left, minLeft ) );
     818                    if ( m_alignCanvas[YLeft] && leftOffset < 0 )
     819                    {
     820                        canvasRect.setLeft( qwtMaxF( canvasRect.left(),
     821                            axisRect.left() - leftOffset ) );
     822                    }
     823                    else
     824                    {
     825                        if ( leftOffset > 0 )
     826                            axisRect.setLeft( axisRect.left() + leftOffset );
     827                    }
     828                }
     829
     830                const QRectF& rightScaleRect = scaleRect[YRight];
     831                const int rightOffset = backboneOffset[YRight] - endDist + 1;
     832
     833                if ( rightScaleRect.isValid() )
     834                {
     835                    const double dx = rightOffset + rightScaleRect.width();
     836                    if ( m_alignCanvas[YRight] && dx < 0 )
     837                    {
     838                        /*
     839                           The axis needs more space than the width
     840                           of the right scale.
     841                         */
     842                        const double cRight = canvasRect.right(); // qreal -> double
     843                        canvasRect.setRight( qwtMinF( cRight, axisRect.right() + dx ) );
     844                    }
     845
     846                    const double maxRight = rightScaleRect.right();
     847                    const double right = axisRect.right() - rightOffset;
     848                    axisRect.setRight( qwtMinF( right, maxRight ) );
     849                }
     850                else
     851                {
     852                    if ( m_alignCanvas[YRight] && rightOffset < 0 )
     853                    {
     854                        canvasRect.setRight( qwtMinF( canvasRect.right(),
     855                            axisRect.right() + rightOffset ) );
     856                    }
     857                    else
     858                    {
     859                        if ( rightOffset > 0 )
     860                            axisRect.setRight( axisRect.right() - rightOffset );
     861                    }
     862                }
     863            }
     864            else // y axes
     865            {
     866                const QRectF& bottomScaleRect = scaleRect[XBottom];
     867                const int bottomOffset = backboneOffset[XBottom] - endDist + 1;
     868
     869                if ( bottomScaleRect.isValid() )
     870                {
     871                    const double dy = bottomOffset + bottomScaleRect.height();
     872                    if ( m_alignCanvas[XBottom] && dy < 0 )
     873                    {
     874                        /*
     875                           The axis needs more space than the height
     876                           of the bottom scale.
     877                         */
     878                        const double cBottom = canvasRect.bottom(); // qreal -> double
     879                        canvasRect.setBottom( qwtMinF( cBottom, axisRect.bottom() + dy ) );
     880                    }
     881                    else
     882                    {
     883                        const double maxBottom = bottomScaleRect.top() +
     884                            layoutData.tickOffset( XBottom );
     885                        const double bottom = axisRect.bottom() - bottomOffset;
     886                        axisRect.setBottom( qwtMinF( bottom, maxBottom ) );
     887                    }
     888                }
     889                else
     890                {
     891                    if ( m_alignCanvas[XBottom] && bottomOffset < 0 )
     892                    {
     893                        canvasRect.setBottom( qwtMinF( canvasRect.bottom(),
     894                            axisRect.bottom() + bottomOffset ) );
     895                    }
     896                    else
     897                    {
     898                        if ( bottomOffset > 0 )
     899                            axisRect.setBottom( axisRect.bottom() - bottomOffset );
     900                    }
     901                }
     902
     903                const QRectF& topScaleRect = scaleRect[XTop];
     904                const int topOffset = backboneOffset[XTop] - startDist;
     905
     906                if ( topScaleRect.isValid() )
     907                {
     908                    const double dy = topOffset + topScaleRect.height();
     909                    if ( m_alignCanvas[XTop] && dy < 0 )
     910                    {
     911                        /*
     912                           The axis needs more space than the height
     913                           of the top scale.
     914                         */
     915                        const double cTop = canvasRect.top(); // qreal -> double
     916                        canvasRect.setTop( qwtMaxF( cTop, axisRect.top() - dy ) );
     917                    }
     918                    else
     919                    {
     920                        const double minTop = topScaleRect.bottom() -
     921                            layoutData.tickOffset( XTop );
     922
     923                        const double top = axisRect.top() + topOffset;
     924                        axisRect.setTop( qwtMaxF( top, minTop ) );
     925                    }
     926                }
     927                else
     928                {
     929                    if ( m_alignCanvas[XTop] && topOffset < 0 )
     930                    {
     931                        canvasRect.setTop( qwtMaxF( canvasRect.top(),
     932                            axisRect.top() - topOffset ) );
     933                    }
     934                    else
     935                    {
     936                        if ( topOffset > 0 )
     937                            axisRect.setTop( axisRect.top() + topOffset );
     938                    }
     939                }
     940            }
     941        }
     942    }
     943
     944    /*
     945       The canvas has been aligned to the scale with largest
     946       border distances. Now we have to realign the other scale.
     947     */
     948
     949    for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ )
     950    {
     951        {
     952            const QwtAxisId axisId( axisPos );
     953
     954            QRectF& sRect = scaleRect[axisPos];
     955            const LayoutData::ScaleData& axisData = layoutData.axisData( axisId );
     956
     957            if ( !sRect.isValid() )
     958                continue;
     959
     960            if ( isXAxis( axisPos ) )
     961            {
     962                if ( m_alignCanvas[YLeft] )
     963                {
     964                    double y = canvasRect.left() - axisData.start;
     965                    if ( !( options & QwtPlotLayout::IgnoreFrames ) )
     966                        y += layoutData.canvasData.contentsMargins[YLeft];
     967
     968                    sRect.setLeft( y );
     969                }
     970
     971                if ( m_alignCanvas[YRight] )
     972                {
     973                    double y = canvasRect.right() - 1 + axisData.end;
     974                    if ( !( options & QwtPlotLayout::IgnoreFrames ) )
     975                        y -= layoutData.canvasData.contentsMargins[YRight];
     976
     977                    sRect.setRight( y );
     978                }
     979
     980                if ( m_alignCanvas[axisPos] )
     981                {
     982                    if ( axisPos == XTop )
     983                        sRect.setBottom( canvasRect.top() );
     984                    else
     985                        sRect.setTop( canvasRect.bottom() );
    1060986                }
    1061987            }
    1062988            else
    1063989            {
    1064                 if ( d_data->alignCanvasToScales[QwtPlot::yLeft] && leftOffset < 0 )
    1065                 {
    1066                     canvasRect.setLeft( qMax( canvasRect.left(),
    1067                         axisRect.left() - leftOffset ) );
    1068                 }
    1069                 else
    1070                 {
    1071                     if ( leftOffset > 0 )
    1072                         axisRect.setLeft( axisRect.left() + leftOffset );
    1073                 }
    1074             }
    1075 
    1076             const QRectF &rightScaleRect = scaleRect[QwtPlot::yRight];
    1077             const int rightOffset =
    1078                 backboneOffset[QwtPlot::yRight] - endDist + 1;
    1079 
    1080             if ( rightScaleRect.isValid() )
    1081             {
    1082                 const double dx = rightOffset + rightScaleRect.width();
    1083                 if ( d_data->alignCanvasToScales[QwtPlot::yRight] && dx < 0 )
    1084                 {
    1085                     /*
    1086                       The axis needs more space than the width
    1087                       of the right scale.
    1088                      */
    1089                     const double cRight = canvasRect.right(); // qreal -> double
    1090                     canvasRect.setRight( qMin( cRight, axisRect.right() + dx ) );
    1091                 }
    1092 
    1093                 const double maxRight = rightScaleRect.right();
    1094                 const double right = axisRect.right() - rightOffset;
    1095                 axisRect.setRight( qMin( right, maxRight ) );
    1096             }
    1097             else
    1098             {
    1099                 if ( d_data->alignCanvasToScales[QwtPlot::yRight] && rightOffset < 0 )
    1100                 {
    1101                     canvasRect.setRight( qMin( canvasRect.right(),
    1102                         axisRect.right() + rightOffset ) );
    1103                 }
    1104                 else
    1105                 {
    1106                     if ( rightOffset > 0 )
    1107                         axisRect.setRight( axisRect.right() - rightOffset );
    1108                 }
    1109             }
    1110         }
    1111         else // QwtPlot::yLeft, QwtPlot::yRight
    1112         {
    1113             const QRectF &bottomScaleRect = scaleRect[QwtPlot::xBottom];
    1114             const int bottomOffset =
    1115                 backboneOffset[QwtPlot::xBottom] - endDist + 1;
    1116 
    1117             if ( bottomScaleRect.isValid() )
    1118             {
    1119                 const double dy = bottomOffset + bottomScaleRect.height();
    1120                 if ( d_data->alignCanvasToScales[QwtPlot::xBottom] && dy < 0 )
    1121                 {
    1122                     /*
    1123                       The axis needs more space than the height
    1124                       of the bottom scale.
    1125                      */
    1126                     const double cBottom = canvasRect.bottom(); // qreal -> double
    1127                     canvasRect.setBottom( qMin( cBottom, axisRect.bottom() + dy ) );
    1128                 }
    1129                 else
    1130                 {
    1131                     const double maxBottom = bottomScaleRect.top() +
    1132                         d_data->layoutData.scale[QwtPlot::xBottom].tickOffset;
    1133                     const double bottom = axisRect.bottom() - bottomOffset;
    1134                     axisRect.setBottom( qMin( bottom, maxBottom ) );
    1135                 }
    1136             }
    1137             else
    1138             {
    1139                 if ( d_data->alignCanvasToScales[QwtPlot::xBottom] && bottomOffset < 0 )
    1140                 {
    1141                     canvasRect.setBottom( qMin( canvasRect.bottom(),
    1142                         axisRect.bottom() + bottomOffset ) );
    1143                 }
    1144                 else
    1145                 {
    1146                     if ( bottomOffset > 0 )
    1147                         axisRect.setBottom( axisRect.bottom() - bottomOffset );
    1148                 }
    1149             }
    1150 
    1151             const QRectF &topScaleRect = scaleRect[QwtPlot::xTop];
    1152             const int topOffset = backboneOffset[QwtPlot::xTop] - startDist;
    1153 
    1154             if ( topScaleRect.isValid() )
    1155             {
    1156                 const double dy = topOffset + topScaleRect.height();
    1157                 if ( d_data->alignCanvasToScales[QwtPlot::xTop] && dy < 0 )
    1158                 {
    1159                     /*
    1160                       The axis needs more space than the height
    1161                       of the top scale.
    1162                      */
    1163                     const double cTop = canvasRect.top(); // qreal -> double
    1164                     canvasRect.setTop( qMax( cTop, axisRect.top() - dy ) );
    1165                 }
    1166                 else
    1167                 {
    1168                     const double minTop = topScaleRect.bottom() -
    1169                         d_data->layoutData.scale[QwtPlot::xTop].tickOffset;
    1170                     const double top = axisRect.top() + topOffset;
    1171                     axisRect.setTop( qMax( top, minTop ) );
    1172                 }
    1173             }
    1174             else
    1175             {
    1176                 if ( d_data->alignCanvasToScales[QwtPlot::xTop] && topOffset < 0 )
    1177                 {
    1178                     canvasRect.setTop( qMax( canvasRect.top(),
    1179                         axisRect.top() - topOffset ) );
    1180                 }
    1181                 else
    1182                 {
    1183                     if ( topOffset > 0 )
    1184                         axisRect.setTop( axisRect.top() + topOffset );
    1185                 }
    1186             }
    1187         }
    1188     }
    1189 
    1190     /*
    1191       The canvas has been aligned to the scale with largest
    1192       border distances. Now we have to realign the other scale.
    1193      */
    1194 
    1195 
    1196     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    1197     {
    1198         QRectF &sRect = scaleRect[axis];
    1199 
    1200         if ( !sRect.isValid() )
    1201             continue;
    1202 
    1203         if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
    1204         {
    1205             if ( d_data->alignCanvasToScales[QwtPlot::yLeft] )
    1206             {
    1207                 double y = canvasRect.left() - d_data->layoutData.scale[axis].start;
    1208                 if ( !( options & IgnoreFrames ) )
    1209                     y += d_data->layoutData.canvas.contentsMargins[ QwtPlot::yLeft ];
    1210 
    1211                 sRect.setLeft( y );
    1212             }
    1213             if ( d_data->alignCanvasToScales[QwtPlot::yRight] )
    1214             {
    1215                 double y = canvasRect.right() - 1 + d_data->layoutData.scale[axis].end;
    1216                 if ( !( options & IgnoreFrames ) )
    1217                     y -= d_data->layoutData.canvas.contentsMargins[ QwtPlot::yRight ];
    1218 
    1219                 sRect.setRight( y );
    1220             }
    1221 
    1222             if ( d_data->alignCanvasToScales[ axis ] )
    1223             {
    1224                 if ( axis == QwtPlot::xTop )
    1225                     sRect.setBottom( canvasRect.top() );
    1226                 else
    1227                     sRect.setTop( canvasRect.bottom() );
    1228             }
     990                if ( m_alignCanvas[XTop] )
     991                {
     992                    double x = canvasRect.top() - axisData.start;
     993                    if ( !( options & QwtPlotLayout::IgnoreFrames ) )
     994                        x += layoutData.canvasData.contentsMargins[XTop];
     995
     996                    sRect.setTop( x );
     997                }
     998
     999                if ( m_alignCanvas[XBottom] )
     1000                {
     1001                    double x = canvasRect.bottom() - 1 + axisData.end;
     1002                    if ( !( options & QwtPlotLayout::IgnoreFrames ) )
     1003                        x -= layoutData.canvasData.contentsMargins[XBottom];
     1004
     1005                    sRect.setBottom( x );
     1006                }
     1007
     1008                if ( m_alignCanvas[axisPos] )
     1009                {
     1010                    if ( axisPos == YLeft )
     1011                        sRect.setRight( canvasRect.left() );
     1012                    else
     1013                        sRect.setLeft( canvasRect.right() );
     1014                }
     1015            }
     1016        }
     1017    }
     1018}
     1019
     1020class QwtPlotLayout::PrivateData
     1021{
     1022  public:
     1023    QRectF titleRect;
     1024    QRectF footerRect;
     1025    QRectF legendRect;
     1026    QRectF scaleRects[QwtAxis::AxisPositions];
     1027    QRectF canvasRect;
     1028
     1029    LayoutEngine engine;
     1030};
     1031
     1032/*!
     1033   \brief Constructor
     1034 */
     1035
     1036QwtPlotLayout::QwtPlotLayout()
     1037{
     1038    m_data = new PrivateData;
     1039
     1040    setLegendPosition( QwtPlot::BottomLegend );
     1041    setCanvasMargin( 4 );
     1042    setAlignCanvasToScales( false );
     1043
     1044    invalidate();
     1045}
     1046
     1047//! Destructor
     1048QwtPlotLayout::~QwtPlotLayout()
     1049{
     1050    delete m_data;
     1051}
     1052
     1053/*!
     1054   Change a margin of the canvas. The margin is the space
     1055   above/below the scale ticks. A negative margin will
     1056   be set to -1, excluding the borders of the scales.
     1057
     1058   \param margin New margin
     1059   \param axisPos One of QwtAxis::Position. Specifies where the position of the margin.
     1060              -1 means margin at all borders.
     1061   \sa canvasMargin()
     1062
     1063   \warning The margin will have no effect when alignCanvasToScale() is true
     1064 */
     1065
     1066void QwtPlotLayout::setCanvasMargin( int margin, int axisPos )
     1067{
     1068    if ( margin < -1 )
     1069        margin = -1;
     1070
     1071    LayoutEngine& engine = m_data->engine;
     1072
     1073    if ( axisPos == -1 )
     1074    {
     1075        for ( axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     1076            engine.setCanvasMargin( axisPos, margin );
     1077    }
     1078    else if ( QwtAxis::isValid( axisPos ) )
     1079    {
     1080        engine.setCanvasMargin( axisPos, margin );
     1081    }
     1082}
     1083
     1084/*!
     1085    \param axisPos Axis position
     1086    \return Margin around the scale tick borders
     1087    \sa setCanvasMargin()
     1088 */
     1089int QwtPlotLayout::canvasMargin( int axisPos ) const
     1090{
     1091    if ( !QwtAxis::isValid( axisPos ) )
     1092        return 0;
     1093
     1094    return m_data->engine.canvasMargin( axisPos );
     1095}
     1096
     1097/*!
     1098   \brief Set the align-canvas-to-axis-scales flag for all axes
     1099
     1100   \param on True/False
     1101   \sa setAlignCanvasToScale(), alignCanvasToScale()
     1102 */
     1103void QwtPlotLayout::setAlignCanvasToScales( bool on )
     1104{
     1105    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     1106        m_data->engine.setAlignCanvas( axisPos, on );
     1107}
     1108
     1109/*!
     1110   Change the align-canvas-to-axis-scales setting. The canvas may:
     1111
     1112   - extend beyond the axis scale ends to maximize its size,
     1113   - align with the axis scale ends to control its size.
     1114
     1115   The axisId parameter is somehow confusing as it identifies a border
     1116   of the plot and not the axes, that are aligned. F.e when QwtAxis::YLeft
     1117   is set, the left end of the the x-axes ( QwtAxis::XTop, QwtAxis::XBottom )
     1118   is aligned.
     1119
     1120   \param axisPos Axis position
     1121   \param on New align-canvas-to-axis-scales setting
     1122
     1123   \sa setCanvasMargin(), alignCanvasToScale(), setAlignCanvasToScales()
     1124   \warning In case of on == true canvasMargin() will have no effect
     1125 */
     1126void QwtPlotLayout::setAlignCanvasToScale( int axisPos, bool on )
     1127{
     1128    if ( QwtAxis::isValid( axisPos ) )
     1129        m_data->engine.setAlignCanvas( axisPos, on );
     1130}
     1131
     1132/*!
     1133   Return the align-canvas-to-axis-scales setting. The canvas may:
     1134   - extend beyond the axis scale ends to maximize its size
     1135   - align with the axis scale ends to control its size.
     1136
     1137   \param axisPos Axis position
     1138   \return align-canvas-to-axis-scales setting
     1139   \sa setAlignCanvasToScale(), setAlignCanvasToScale(), setCanvasMargin()
     1140 */
     1141bool QwtPlotLayout::alignCanvasToScale( int axisPos ) const
     1142{
     1143    if ( !QwtAxis::isValid( axisPos ) )
     1144        return false;
     1145
     1146    return m_data->engine.alignCanvas( axisPos );
     1147}
     1148
     1149/*!
     1150   Change the spacing of the plot. The spacing is the distance
     1151   between the plot components.
     1152
     1153   \param spacing New spacing
     1154   \sa setCanvasMargin(), spacing()
     1155 */
     1156void QwtPlotLayout::setSpacing( int spacing )
     1157{
     1158    m_data->engine.setSpacing( qMax( 0, spacing ) );
     1159}
     1160
     1161/*!
     1162   \return Spacing
     1163   \sa margin(), setSpacing()
     1164 */
     1165int QwtPlotLayout::spacing() const
     1166{
     1167    return m_data->engine.spacing();
     1168}
     1169
     1170/*!
     1171   \brief Specify the position of the legend
     1172   \param pos The legend's position.
     1173   \param ratio Ratio between legend and the bounding rectangle
     1174               of title, footer, canvas and axes. The legend will be shrunk
     1175               if it would need more space than the given ratio.
     1176               The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
     1177               it will be reset to the default ratio.
     1178               The default vertical/horizontal ratio is 0.33/0.5.
     1179
     1180   \sa QwtPlot::setLegendPosition()
     1181 */
     1182
     1183void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos, double ratio )
     1184{
     1185    if ( ratio > 1.0 )
     1186        ratio = 1.0;
     1187
     1188    LayoutEngine& engine = m_data->engine;
     1189
     1190    switch ( pos )
     1191    {
     1192        case QwtPlot::TopLegend:
     1193        case QwtPlot::BottomLegend:
     1194        {
     1195            if ( ratio <= 0.0 )
     1196                ratio = 0.33;
     1197
     1198            engine.setLegendRatio( ratio );
     1199            engine.setLegendPos( pos );
     1200
     1201            break;
     1202        }
     1203        case QwtPlot::LeftLegend:
     1204        case QwtPlot::RightLegend:
     1205        {
     1206            if ( ratio <= 0.0 )
     1207                ratio = 0.5;
     1208
     1209            engine.setLegendRatio( ratio );
     1210            engine.setLegendPos( pos );
     1211
     1212            break;
     1213        }
     1214        default:
     1215            break;
     1216    }
     1217}
     1218
     1219/*!
     1220   \brief Specify the position of the legend
     1221   \param pos The legend's position. Valid values are
     1222      \c QwtPlot::LeftLegend, \c QwtPlot::RightLegend,
     1223      \c QwtPlot::TopLegend, \c QwtPlot::BottomLegend.
     1224
     1225   \sa QwtPlot::setLegendPosition()
     1226 */
     1227void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos )
     1228{
     1229    setLegendPosition( pos, 0.0 );
     1230}
     1231
     1232/*!
     1233   \return Position of the legend
     1234   \sa setLegendPosition(), QwtPlot::setLegendPosition(),
     1235      QwtPlot::legendPosition()
     1236 */
     1237QwtPlot::LegendPosition QwtPlotLayout::legendPosition() const
     1238{
     1239    return m_data->engine.legendPos();
     1240}
     1241
     1242/*!
     1243   Specify the relative size of the legend in the plot
     1244   \param ratio Ratio between legend and the bounding rectangle
     1245               of title, footer, canvas and axes. The legend will be shrunk
     1246               if it would need more space than the given ratio.
     1247               The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
     1248               it will be reset to the default ratio.
     1249               The default vertical/horizontal ratio is 0.33/0.5.
     1250 */
     1251void QwtPlotLayout::setLegendRatio( double ratio )
     1252{
     1253    setLegendPosition( legendPosition(), ratio );
     1254}
     1255
     1256/*!
     1257   \return The relative size of the legend in the plot.
     1258   \sa setLegendPosition()
     1259 */
     1260double QwtPlotLayout::legendRatio() const
     1261{
     1262    return m_data->engine.legendRatio();
     1263}
     1264
     1265/*!
     1266   \brief Set the geometry for the title
     1267
     1268   This method is intended to be used from derived layouts
     1269   overloading activate()
     1270
     1271   \sa titleRect(), activate()
     1272 */
     1273void QwtPlotLayout::setTitleRect( const QRectF& rect )
     1274{
     1275    m_data->titleRect = rect;
     1276}
     1277
     1278/*!
     1279   \return Geometry for the title
     1280   \sa activate(), invalidate()
     1281 */
     1282QRectF QwtPlotLayout::titleRect() const
     1283{
     1284    return m_data->titleRect;
     1285}
     1286
     1287/*!
     1288   \brief Set the geometry for the footer
     1289
     1290   This method is intended to be used from derived layouts
     1291   overloading activate()
     1292
     1293   \sa footerRect(), activate()
     1294 */
     1295void QwtPlotLayout::setFooterRect( const QRectF& rect )
     1296{
     1297    m_data->footerRect = rect;
     1298}
     1299
     1300/*!
     1301   \return Geometry for the footer
     1302   \sa activate(), invalidate()
     1303 */
     1304QRectF QwtPlotLayout::footerRect() const
     1305{
     1306    return m_data->footerRect;
     1307}
     1308
     1309/*!
     1310   \brief Set the geometry for the legend
     1311
     1312   This method is intended to be used from derived layouts
     1313   overloading activate()
     1314
     1315   \param rect Rectangle for the legend
     1316
     1317   \sa legendRect(), activate()
     1318 */
     1319void QwtPlotLayout::setLegendRect( const QRectF& rect )
     1320{
     1321    m_data->legendRect = rect;
     1322}
     1323
     1324/*!
     1325   \return Geometry for the legend
     1326   \sa activate(), invalidate()
     1327 */
     1328QRectF QwtPlotLayout::legendRect() const
     1329{
     1330    return m_data->legendRect;
     1331}
     1332
     1333/*!
     1334   \brief Set the geometry for an axis
     1335
     1336   This method is intended to be used from derived layouts
     1337   overloading activate()
     1338
     1339   \param axisId Axis
     1340   \param rect Rectangle for the scale
     1341
     1342   \sa scaleRect(), activate()
     1343 */
     1344void QwtPlotLayout::setScaleRect( QwtAxisId axisId, const QRectF& rect )
     1345{
     1346    if ( QwtAxis::isValid( axisId ) )
     1347        m_data->scaleRects[axisId] = rect;
     1348}
     1349
     1350/*!
     1351   \param axisId Axis
     1352   \return Geometry for the scale
     1353   \sa activate(), invalidate()
     1354 */
     1355QRectF QwtPlotLayout::scaleRect( QwtAxisId axisId ) const
     1356{
     1357    if ( QwtAxis::isValid( axisId ) )
     1358        return m_data->scaleRects[axisId];
     1359
     1360    return QRectF();
     1361}
     1362
     1363/*!
     1364   \brief Set the geometry for the canvas
     1365
     1366   This method is intended to be used from derived layouts
     1367   overloading activate()
     1368
     1369   \sa canvasRect(), activate()
     1370 */
     1371void QwtPlotLayout::setCanvasRect( const QRectF& rect )
     1372{
     1373    m_data->canvasRect = rect;
     1374}
     1375
     1376/*!
     1377   \return Geometry for the canvas
     1378   \sa activate(), invalidate()
     1379 */
     1380QRectF QwtPlotLayout::canvasRect() const
     1381{
     1382    return m_data->canvasRect;
     1383}
     1384
     1385/*!
     1386   Invalidate the geometry of all components.
     1387   \sa activate()
     1388 */
     1389void QwtPlotLayout::invalidate()
     1390{
     1391    m_data->titleRect = m_data->footerRect =
     1392        m_data->legendRect = m_data->canvasRect = QRectF();
     1393
     1394    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     1395        m_data->scaleRects[axisPos] = QRect();
     1396}
     1397
     1398/*!
     1399   \return Minimum size hint
     1400   \param plot Plot widget
     1401
     1402   \sa QwtPlot::minimumSizeHint()
     1403 */
     1404QSize QwtPlotLayout::minimumSizeHint( const QwtPlot* plot ) const
     1405{
     1406    LayoutHintData hintData( plot );
     1407
     1408    const int xAxesWidth = hintData.xAxesWidth();
     1409    const int yAxesHeight = hintData.yAxesHeight();
     1410
     1411    const QWidget* canvas = plot->canvas();
     1412
     1413    const QMargins m = canvas->contentsMargins();
     1414    const QSize minCanvasSize = canvas->minimumSize();
     1415
     1416    int w = hintData.yAxesWidth();
     1417    int cw = xAxesWidth + m.left() + 1 + m.right() + 1;
     1418    w += qMax( cw, minCanvasSize.width() );
     1419
     1420    int h = hintData.xAxesHeight();
     1421    int ch = yAxesHeight + m.top() + 1 + m.bottom() + 1;
     1422    h += qMax( ch, minCanvasSize.height() );
     1423
     1424    const QwtTextLabel* labels[2];
     1425    labels[0] = plot->titleLabel();
     1426    labels[1] = plot->footerLabel();
     1427
     1428    for ( int i = 0; i < 2; i++ )
     1429    {
     1430        const QwtTextLabel* label = labels[i];
     1431        if ( label && !label->text().isEmpty() )
     1432        {
     1433            // we center on the plot canvas.
     1434            const bool centerOnCanvas = !( plot->isAxisVisible( QwtAxis::YLeft )
     1435                && plot->isAxisVisible( QwtAxis::YRight ) );
     1436
     1437            int labelW = w;
     1438            if ( centerOnCanvas )
     1439            {
     1440                labelW -= hintData.yAxesWidth();
     1441            }
     1442
     1443            int labelH = label->heightForWidth( labelW );
     1444            if ( labelH > labelW ) // Compensate for a long title
     1445            {
     1446                w = labelW = labelH;
     1447                if ( centerOnCanvas )
     1448                    w += hintData.yAxesWidth();
     1449
     1450                labelH = label->heightForWidth( labelW );
     1451            }
     1452            h += labelH + spacing();
     1453        }
     1454    }
     1455
     1456    // Compute the legend contribution
     1457
     1458    const QwtAbstractLegend* legend = plot->legend();
     1459    if ( legend && !legend->isEmpty() )
     1460    {
     1461        const LayoutEngine& engine = m_data->engine;
     1462
     1463        if ( engine.legendPos() == QwtPlot::LeftLegend
     1464            || engine.legendPos() == QwtPlot::RightLegend )
     1465        {
     1466            int legendW = legend->sizeHint().width();
     1467            int legendH = legend->heightForWidth( legendW );
     1468
     1469            if ( legend->frameWidth() > 0 )
     1470                w += spacing();
     1471
     1472            if ( legendH > h )
     1473                legendW += legend->scrollExtent( Qt::Horizontal );
     1474
     1475            if ( engine.legendRatio() < 1.0 )
     1476                legendW = qMin( legendW, int( w / ( 1.0 - engine.legendRatio() ) ) );
     1477
     1478            w += legendW + spacing();
    12291479        }
    12301480        else
    12311481        {
    1232             if ( d_data->alignCanvasToScales[QwtPlot::xTop] )
    1233             {
    1234                 double x = canvasRect.top() - d_data->layoutData.scale[axis].start;
    1235                 if ( !( options & IgnoreFrames ) )
    1236                     x += d_data->layoutData.canvas.contentsMargins[ QwtPlot::xTop ];
    1237 
    1238                 sRect.setTop( x );
    1239             }
    1240             if ( d_data->alignCanvasToScales[QwtPlot::xBottom] )
    1241             {
    1242                 double x = canvasRect.bottom() - 1 + d_data->layoutData.scale[axis].end;
    1243                 if ( !( options & IgnoreFrames ) )
    1244                     x -= d_data->layoutData.canvas.contentsMargins[ QwtPlot::xBottom ];
    1245 
    1246                 sRect.setBottom( x );
    1247             }
    1248 
    1249             if ( d_data->alignCanvasToScales[ axis ] )
    1250             {
    1251                 if ( axis == QwtPlot::yLeft )
    1252                     sRect.setRight( canvasRect.left() );
    1253                 else
    1254                     sRect.setLeft( canvasRect.right() );
    1255             }
    1256         }
    1257     }
    1258 }
    1259 
    1260 /*!
    1261   \brief Recalculate the geometry of all components.
    1262 
    1263   \param plot Plot to be layout
    1264   \param plotRect Rectangle where to place the components
    1265   \param options Layout options
    1266 
    1267   \sa invalidate(), titleRect(), footerRect()
     1482            int legendW = qMin( legend->sizeHint().width(), w );
     1483            int legendH = legend->heightForWidth( legendW );
     1484
     1485            if ( legend->frameWidth() > 0 )
     1486                h += spacing();
     1487
     1488            if ( engine.legendRatio() < 1.0 )
     1489                legendH = qMin( legendH, int( h / ( 1.0 - engine.legendRatio() ) ) );
     1490
     1491            h += legendH + spacing();
     1492        }
     1493    }
     1494
     1495    return QSize( w, h );
     1496}
     1497
     1498/*!
     1499   \brief Recalculate the geometry of all components.
     1500
     1501   \param plot Plot to be layout
     1502   \param plotRect Rectangle where to place the components
     1503   \param options Layout options
     1504
     1505   \sa invalidate(), titleRect(), footerRect()
    12681506      legendRect(), scaleRect(), canvasRect()
    1269 */
    1270 void QwtPlotLayout::activate( const QwtPlot *plot,
    1271     const QRectF &plotRect, Options options )
     1507 */
     1508void QwtPlotLayout::activate( const QwtPlot* plot,
     1509    const QRectF& plotRect, Options options )
    12721510{
    12731511    invalidate();
    … …  
    12761514
    12771515    // We extract all layout relevant parameters from the widgets,
    1278     // and save them to d_data->layoutData.
    1279 
    1280     d_data->layoutData.init( plot, rect );
     1516    // and save them to m_data->layoutData.
     1517
     1518    LayoutData layoutData( plot );
     1519
     1520    QSize legendHint;
    12811521
    12821522    if ( !( options & IgnoreLegend )
    12831523        && plot->legend() && !plot->legend()->isEmpty() )
    12841524    {
    1285         d_data->legendRect = layoutLegend( options, rect );
    1286 
    1287         // subtract d_data->legendRect from rect
     1525        legendHint = layoutData.legendData.legendHint( plot->legend(), rect );
     1526
     1527        m_data->legendRect = m_data->engine.layoutLegend(
     1528            options, layoutData.legendData, rect, legendHint );
     1529
     1530        // subtract m_data->legendRect from rect
    12881531
    12891532        const QRegion region( rect.toRect() );
    1290         rect = region.subtracted( d_data->legendRect.toRect() ).boundingRect();
    1291 
    1292         switch ( d_data->legendPos )
     1533        rect = region.subtracted( m_data->legendRect.toRect() ).boundingRect();
     1534
     1535        switch ( m_data->engine.legendPos() )
    12931536        {
    12941537            case QwtPlot::LeftLegend:
    1295                 rect.setLeft( rect.left() + d_data->spacing );
     1538            {
     1539                rect.setLeft( rect.left() + spacing() );
    12961540                break;
     1541            }
    12971542            case QwtPlot::RightLegend:
    1298                 rect.setRight( rect.right() - d_data->spacing );
     1543            {
     1544                rect.setRight( rect.right() - spacing() );
    12991545                break;
     1546            }
    13001547            case QwtPlot::TopLegend:
    1301                 rect.setTop( rect.top() + d_data->spacing );
     1548            {
     1549                rect.setTop( rect.top() + spacing() );
    13021550                break;
     1551            }
    13031552            case QwtPlot::BottomLegend:
    1304                 rect.setBottom( rect.bottom() - d_data->spacing );
     1553            {
     1554                rect.setBottom( rect.bottom() - spacing() );
    13051555                break;
     1556            }
    13061557        }
    13071558    }
    … …  
    13221573     |      Footer       |
    13231574     +---+-----------+---+
    1324     */
     1575     */
    13251576
    13261577    // title, footer and axes include text labels. The height of each
    … …  
    13281579    // for the label. A line break in a horizontal text will reduce
    13291580    // the available width for vertical texts and vice versa.
    1330     // expandLineBreaks finds the height/width for title, footer and axes
     1581    // layoutDimensions finds the height/width for title, footer and axes
    13311582    // including all line breaks.
    13321583
    1333     int dimTitle, dimFooter, dimAxes[QwtPlot::axisCnt];
    1334     expandLineBreaks( options, rect, dimTitle, dimFooter, dimAxes );
    1335 
    1336     if ( dimTitle > 0 )
    1337     {
    1338         d_data->titleRect.setRect(
    1339             rect.left(), rect.top(), rect.width(), dimTitle );
    1340 
    1341         rect.setTop( d_data->titleRect.bottom() + d_data->spacing );
    1342 
    1343         if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled !=
    1344             d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
     1584    using namespace QwtAxis;
     1585
     1586    const LayoutEngine::Dimensions dimensions =
     1587        m_data->engine.layoutDimensions( options, layoutData, rect );
     1588
     1589    if ( dimensions.dimTitle > 0 )
     1590    {
     1591        QRectF& labelRect = m_data->titleRect;
     1592
     1593        labelRect.setRect( rect.left(), rect.top(), rect.width(), dimensions.dimTitle );
     1594
     1595        rect.setTop( labelRect.bottom() + spacing() );
     1596
     1597        if ( !layoutData.hasSymmetricYAxes() )
    13451598        {
    13461599            // if only one of the y axes is missing we align
    13471600            // the title centered to the canvas
    13481601
    1349             d_data->titleRect.setX( rect.left() + dimAxes[QwtPlot::yLeft] );
    1350             d_data->titleRect.setWidth( rect.width()
    1351                 - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] );
    1352         }
    1353     }
    1354 
    1355     if ( dimFooter > 0 )
    1356     {
    1357         d_data->footerRect.setRect(
    1358             rect.left(), rect.bottom() - dimFooter, rect.width(), dimFooter );
    1359 
    1360         rect.setBottom( d_data->footerRect.top() - d_data->spacing );
    1361 
    1362         if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled !=
    1363             d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
     1602            labelRect = dimensions.centered( rect, labelRect );
     1603        }
     1604    }
     1605
     1606    if ( dimensions.dimFooter > 0 )
     1607    {
     1608        QRectF& labelRect = m_data->footerRect;
     1609
     1610        labelRect.setRect( rect.left(), rect.bottom() - dimensions.dimFooter,
     1611            rect.width(), dimensions.dimFooter );
     1612
     1613        rect.setBottom( labelRect.top() - spacing() );
     1614
     1615        if ( !layoutData.hasSymmetricYAxes() )
    13641616        {
    13651617            // if only one of the y axes is missing we align
    13661618            // the footer centered to the canvas
    13671619
    1368             d_data->footerRect.setX( rect.left() + dimAxes[QwtPlot::yLeft] );
    1369             d_data->footerRect.setWidth( rect.width()
    1370                 - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] );
    1371         }
    1372     }
    1373 
    1374     d_data->canvasRect.setRect(
    1375         rect.x() + dimAxes[QwtPlot::yLeft],
    1376         rect.y() + dimAxes[QwtPlot::xTop],
    1377         rect.width() - dimAxes[QwtPlot::yRight] - dimAxes[QwtPlot::yLeft],
    1378         rect.height() - dimAxes[QwtPlot::xBottom] - dimAxes[QwtPlot::xTop] );
    1379 
    1380     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
     1620            labelRect = dimensions.centered( rect, labelRect );
     1621        }
     1622    }
     1623
     1624    m_data->canvasRect = dimensions.innerRect( rect );
     1625
     1626    for ( int axisPos = 0; axisPos < AxisPositions; axisPos++ )
    13811627    {
    13821628        // set the rects for the axes
    13831629
    1384         if ( dimAxes[axis] )
    1385         {
    1386             int dim = dimAxes[axis];
    1387             QRectF &scaleRect = d_data->scaleRect[axis];
    1388 
    1389             scaleRect = d_data->canvasRect;
    1390             switch ( axis )
    1391             {
    1392                 case QwtPlot::yLeft:
    1393                     scaleRect.setX( d_data->canvasRect.left() - dim );
    1394                     scaleRect.setWidth( dim );
    1395                     break;
    1396                 case QwtPlot::yRight:
    1397                     scaleRect.setX( d_data->canvasRect.right() );
    1398                     scaleRect.setWidth( dim );
    1399                     break;
    1400                 case QwtPlot::xBottom:
    1401                     scaleRect.setY( d_data->canvasRect.bottom() );
    1402                     scaleRect.setHeight( dim );
    1403                     break;
    1404                 case QwtPlot::xTop:
    1405                     scaleRect.setY( d_data->canvasRect.top() - dim );
    1406                     scaleRect.setHeight( dim );
    1407                     break;
    1408             }
    1409             scaleRect = scaleRect.normalized();
     1630        const int pos = 0;
     1631        {
     1632            const QwtAxisId axisId( axisPos );
     1633
     1634            if ( dimensions.dimAxis( axisId ) )
     1635            {
     1636                const int dim = dimensions.dimAxis( axisId );
     1637
     1638                const QRectF& canvasRect = m_data->canvasRect;
     1639
     1640                QRectF& scaleRect = m_data->scaleRects[axisId];
     1641                scaleRect = canvasRect;
     1642
     1643                switch ( axisPos )
     1644                {
     1645                    case YLeft:
     1646                    {
     1647                        scaleRect.setX( canvasRect.left() - pos - dim );
     1648                        scaleRect.setWidth( dim );
     1649                        break;
     1650                    }
     1651                    case YRight:
     1652                    {
     1653                        scaleRect.setX( canvasRect.right() + pos );
     1654                        scaleRect.setWidth( dim );
     1655                        break;
     1656                    }
     1657                    case XBottom:
     1658                    {
     1659                        scaleRect.setY( canvasRect.bottom() + pos );
     1660                        scaleRect.setHeight( dim );
     1661                        break;
     1662                    }
     1663                    case XTop:
     1664                    {
     1665                        scaleRect.setY( canvasRect.top() - pos - dim );
     1666                        scaleRect.setHeight( dim );
     1667                        break;
     1668                    }
     1669                }
     1670                scaleRect = scaleRect.normalized();
     1671            }
    14101672        }
    14111673    }
    … …  
    14311693    // left/right of the min/max ticks are moved into them.
    14321694
    1433     alignScales( options, d_data->canvasRect, d_data->scaleRect );
    1434 
    1435     if ( !d_data->legendRect.isEmpty() )
     1695    m_data->engine.alignScales( options, layoutData,
     1696        m_data->canvasRect, m_data->scaleRects );
     1697
     1698    if ( !m_data->legendRect.isEmpty() )
    14361699    {
    14371700        // We prefer to align the legend to the canvas - not to
    14381701        // the complete plot - if possible.
    14391702
    1440         d_data->legendRect = alignLegend( d_data->canvasRect, d_data->legendRect );
    1441     }
    1442 }
     1703        m_data->legendRect = m_data->engine.alignLegend(
     1704            legendHint, m_data->canvasRect, m_data->legendRect );
     1705    }
     1706}
  • trunk/BNC/qwt/qwt_plot_layout.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot.h"
     15#include "qwt_axis_id.h"
    1516
    1617/*!
    17   \brief Layout engine for QwtPlot.
     18   \brief Layout engine for QwtPlot.
    1819
    19   It is used by the QwtPlot widget to organize its internal widgets
    20   or by QwtPlot::print() to render its content to a QPaintDevice like
    21   a QPrinter, QPixmap/QImage or QSvgRenderer.
     20   It is used by the QwtPlot widget to organize its internal widgets
     21   or by QwtPlot::print() to render its content to a QPaintDevice like
     22   a QPrinter, QPixmap/QImage or QSvgRenderer.
    2223
    23   \sa QwtPlot::setPlotLayout()
    24 */
     24   \sa QwtPlot::setPlotLayout()
     25 */
    2526
    2627class QWT_EXPORT QwtPlotLayout
    2728{
    28 public:
     29  public:
    2930    /*!
    30       Options to configure the plot layout engine
    31       \sa activate(), QwtPlotRenderer
     31       Options to configure the plot layout engine
     32       \sa activate(), QwtPlotRenderer
    3233     */
    3334    enum Option
    … …  
    3738
    3839        /*!
    39           Ignore the dimension of the scrollbars. There are no
    40           scrollbars, when the plot is not rendered to widgets.
     40           Ignore the dimension of the scrollbars. There are no
     41           scrollbars, when the plot is not rendered to widgets.
    4142         */
    4243        IgnoreScrollbars = 0x02,
    … …  
    5556    };
    5657
    57     //! Layout options
    58     typedef QFlags<Option> Options;
     58    Q_DECLARE_FLAGS( Options, Option )
    5959
    6060    explicit QwtPlotLayout();
    … …  
    7979    double legendRatio() const;
    8080
    81     virtual QSize minimumSizeHint( const QwtPlot * ) const;
     81    virtual QSize minimumSizeHint( const QwtPlot* ) const;
    8282
    83     virtual void activate( const QwtPlot *,
    84         const QRectF &plotRect, Options options = Options() );
     83    virtual void activate( const QwtPlot*,
     84        const QRectF& plotRect, Options options = Options() );
    8585
    8686    virtual void invalidate();
    … …  
    8989    QRectF footerRect() const;
    9090    QRectF legendRect() const;
    91     QRectF scaleRect( int axis ) const;
     91    QRectF scaleRect( QwtAxisId ) const;
    9292    QRectF canvasRect() const;
    9393
    94     class LayoutData;
     94  protected:
    9595
    96 protected:
     96    void setTitleRect( const QRectF& );
     97    void setFooterRect( const QRectF& );
     98    void setLegendRect( const QRectF& );
     99    void setScaleRect( QwtAxisId, const QRectF& );
     100    void setCanvasRect( const QRectF& );
    97101
    98     void setTitleRect( const QRectF & );
    99     void setFooterRect( const QRectF & );
    100     void setLegendRect( const QRectF & );
    101     void setScaleRect( int axis, const QRectF & );
    102     void setCanvasRect( const QRectF & );
     102  private:
     103    Q_DISABLE_COPY(QwtPlotLayout)
    103104
    104     QRectF layoutLegend( Options options, const QRectF & ) const;
    105     QRectF alignLegend( const QRectF &canvasRect,
    106         const QRectF &legendRect ) const;
    107 
    108     void expandLineBreaks( Options options, const QRectF &rect,
    109         int &dimTitle, int &dimFooter, int dimAxes[QwtPlot::axisCnt] ) const;
    110 
    111     void alignScales( Options options, QRectF &canvasRect,
    112         QRectF scaleRect[QwtPlot::axisCnt] ) const;
    113 
    114 private:
    115105    class PrivateData;
    116 
    117     PrivateData *d_data;
     106    PrivateData* m_data;
    118107};
    119108
  • trunk/BNC/qwt/qwt_plot_legenditem.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_plot_legenditem.h"
    1111#include "qwt_dyngrid_layout.h"
    12 #include "qwt_scale_map.h"
    13 #include "qwt_painter.h"
     12#include "qwt_text.h"
     13#include "qwt_graphic.h"
     14#include "qwt_legend_data.h"
     15#include "qwt_math.h"
     16
    1417#include <qlayoutitem.h>
    1518#include <qpen.h>
    1619#include <qbrush.h>
    1720#include <qpainter.h>
    18 #include <qmath.h>
    19 
    20 class QwtLegendLayoutItem: public QLayoutItem
    21 {
    22 public:
    23     QwtLegendLayoutItem( const QwtPlotLegendItem *, const QwtPlotItem * );
    24     virtual ~QwtLegendLayoutItem();
    25 
    26     const QwtPlotItem *plotItem() const;
    27 
    28     void setData( const QwtLegendData & );
    29     const QwtLegendData &data() const;
    30 
    31     virtual Qt::Orientations expandingDirections() const;
    32     virtual QRect geometry() const;
    33     virtual bool hasHeightForWidth() const;
    34     virtual int heightForWidth( int w ) const;
    35     virtual bool isEmpty() const;
    36     virtual QSize maximumSize() const;
    37     virtual int minimumHeightForWidth( int w ) const;
    38     virtual QSize minimumSize() const;
    39     virtual void setGeometry( const QRect & r );
    40     virtual QSize sizeHint() const;
    41 
    42 private:
    43 
    44     const QwtPlotLegendItem *d_legendItem;
    45     const QwtPlotItem *d_plotItem;
    46     QwtLegendData d_data;
    47 
    48     QRect d_rect;
    49 };
    50 
    51 QwtLegendLayoutItem::QwtLegendLayoutItem(
    52         const QwtPlotLegendItem *legendItem, const QwtPlotItem *plotItem ):
    53     d_legendItem( legendItem ),
    54     d_plotItem( plotItem)
    55 {
    56 }
    57 
    58 QwtLegendLayoutItem::~QwtLegendLayoutItem()
    59 {
    60 }
    61 
    62 const QwtPlotItem *QwtLegendLayoutItem::plotItem() const
    63 {
    64     return d_plotItem;
    65 }
    66 
    67 void QwtLegendLayoutItem::setData( const QwtLegendData &data )
    68 {
    69     d_data = data;
    70 }
    71 
    72 const QwtLegendData &QwtLegendLayoutItem::data() const
    73 {
    74     return d_data;
    75 }
    76 
    77 Qt::Orientations QwtLegendLayoutItem::expandingDirections() const
    78 {
    79     return Qt::Horizontal;
    80 }
    81 
    82 bool QwtLegendLayoutItem::hasHeightForWidth() const
    83 {
    84     return !d_data.title().isEmpty();
    85 }
    86 
    87 int QwtLegendLayoutItem::minimumHeightForWidth( int w ) const
    88 {
    89     return d_legendItem->heightForWidth( d_data, w );
    90 }
    91 
    92 int QwtLegendLayoutItem::heightForWidth( int w ) const
    93 {
    94     return d_legendItem->heightForWidth( d_data, w );
    95 }
    96 
    97 bool QwtLegendLayoutItem::isEmpty() const
    98 {
    99     return false;
    100 }
    101 
    102 QSize QwtLegendLayoutItem::maximumSize() const
    103 {
    104     return QSize( QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX );
    105 }
    106 
    107 QSize QwtLegendLayoutItem::minimumSize() const
    108 {
    109     return d_legendItem->minimumSize( d_data );
    110 }
    111 
    112 QSize QwtLegendLayoutItem::sizeHint() const
    113 {
    114     return minimumSize();
    115 }
    116 
    117 void QwtLegendLayoutItem::setGeometry( const QRect &rect )
    118 {
    119     d_rect = rect;
    120 }
    121 
    122 QRect QwtLegendLayoutItem::geometry() const
    123 {
    124     return d_rect;
     21
     22namespace
     23{
     24    class LayoutItem QWT_FINAL : public QLayoutItem
     25    {
     26      public:
     27        LayoutItem( const QwtPlotLegendItem*, const QwtPlotItem* );
     28        virtual ~LayoutItem();
     29
     30        const QwtPlotItem* plotItem() const;
     31
     32        void setData( const QwtLegendData& );
     33        const QwtLegendData& data() const;
     34
     35        virtual Qt::Orientations expandingDirections() const QWT_OVERRIDE;
     36        virtual QRect geometry() const QWT_OVERRIDE;
     37        virtual bool hasHeightForWidth() const QWT_OVERRIDE;
     38        virtual int heightForWidth( int ) const QWT_OVERRIDE;
     39        virtual bool isEmpty() const QWT_OVERRIDE;
     40        virtual QSize maximumSize() const QWT_OVERRIDE;
     41        virtual int minimumHeightForWidth( int ) const QWT_OVERRIDE;
     42        virtual QSize minimumSize() const QWT_OVERRIDE;
     43        virtual void setGeometry( const QRect& ) QWT_OVERRIDE;
     44        virtual QSize sizeHint() const QWT_OVERRIDE;
     45
     46      private:
     47
     48        const QwtPlotLegendItem* m_legendItem;
     49        const QwtPlotItem* m_plotItem;
     50        QwtLegendData m_data;
     51
     52        QRect m_rect;
     53    };
     54
     55    LayoutItem::LayoutItem(
     56            const QwtPlotLegendItem* legendItem, const QwtPlotItem* plotItem )
     57        : m_legendItem( legendItem )
     58        , m_plotItem( plotItem)
     59    {
     60    }
     61
     62    LayoutItem::~LayoutItem()
     63    {
     64    }
     65
     66    const QwtPlotItem* LayoutItem::plotItem() const
     67    {
     68        return m_plotItem;
     69    }
     70
     71    void LayoutItem::setData( const QwtLegendData& data )
     72    {
     73        m_data = data;
     74    }
     75
     76    const QwtLegendData& LayoutItem::data() const
     77    {
     78        return m_data;
     79    }
     80
     81    Qt::Orientations LayoutItem::expandingDirections() const
     82    {
     83        return Qt::Horizontal;
     84    }
     85
     86    bool LayoutItem::hasHeightForWidth() const
     87    {
     88        return !m_data.title().isEmpty();
     89    }
     90
     91    int LayoutItem::minimumHeightForWidth( int w ) const
     92    {
     93        return m_legendItem->heightForWidth( m_data, w );
     94    }
     95
     96    int LayoutItem::heightForWidth( int w ) const
     97    {
     98        return m_legendItem->heightForWidth( m_data, w );
     99    }
     100
     101    bool LayoutItem::isEmpty() const
     102    {
     103        return false;
     104    }
     105
     106    QSize LayoutItem::maximumSize() const
     107    {
     108        return QSize( QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX );
     109    }
     110
     111    QSize LayoutItem::minimumSize() const
     112    {
     113        return m_legendItem->minimumSize( m_data );
     114    }
     115
     116    QSize LayoutItem::sizeHint() const
     117    {
     118        return minimumSize();
     119    }
     120
     121    void LayoutItem::setGeometry( const QRect& rect )
     122    {
     123        m_rect = rect;
     124    }
     125
     126    QRect LayoutItem::geometry() const
     127    {
     128        return m_rect;
     129    }
    125130}
    126131
    127132class QwtPlotLegendItem::PrivateData
    128133{
    129 public:
    130     PrivateData():
    131         itemMargin( 4 ),
    132         itemSpacing( 4 ),
    133         borderRadius( 0.0 ),
    134         borderPen( Qt::NoPen ),
    135         backgroundBrush( Qt::NoBrush ),
    136         backgroundMode( QwtPlotLegendItem::LegendBackground ),
    137         borderDistance( 10 ),
    138         alignment( Qt::AlignRight | Qt::AlignBottom )
    139     {
     134  public:
     135    PrivateData()
     136        : itemMargin( 4 )
     137        , itemSpacing( 4 )
     138        , borderRadius( 0.0 )
     139        , borderPen( Qt::NoPen )
     140        , backgroundBrush( Qt::NoBrush )
     141        , backgroundMode( QwtPlotLegendItem::LegendBackground )
     142        , canvasAlignment( Qt::AlignRight | Qt::AlignBottom )
     143    {
     144        canvasOffset[ 0 ] = canvasOffset[1] = 10;
    140145        layout = new QwtDynGridLayout();
    141146        layout->setMaxColumns( 2 );
    … …  
    160165    QwtPlotLegendItem::BackgroundMode backgroundMode;
    161166
    162     int borderDistance;
    163     Qt::Alignment alignment;
    164 
    165     QMap< const QwtPlotItem *, QList<QwtLegendLayoutItem *> > map;
    166     QwtDynGridLayout *layout;
     167    int canvasOffset[2];
     168    Qt::Alignment canvasAlignment;
     169
     170    QMap< const QwtPlotItem*, QList< LayoutItem* > > map;
     171    QwtDynGridLayout* layout;
    167172};
    168173
    169174//! Constructor
    170 QwtPlotLegendItem::QwtPlotLegendItem():
    171     QwtPlotItem( QwtText( "Legend" ) )
    172 {
    173     d_data = new PrivateData;
     175QwtPlotLegendItem::QwtPlotLegendItem()
     176    : QwtPlotItem( QwtText( "Legend" ) )
     177{
     178    m_data = new PrivateData;
    174179
    175180    setItemInterest( QwtPlotItem::LegendInterest, true );
    … …  
    181186{
    182187    clearLegend();
    183     delete d_data;
     188    delete m_data;
    184189}
    185190
    … …  
    191196
    192197/*!
    193   \brief Set the alignmnet
    194 
    195   Alignment means the position of the legend relative
    196   to the geometry of the plot canvas.
    197 
    198   \param alignment Alignment flags
    199 
    200   \sa alignment(), setMaxColumns()
    201 
    202   \note To align a legend with many items horizontally
     198   \brief Set the alignmnet
     199
     200   Alignment means the position of the legend relative
     201   to the geometry of the plot canvas.
     202
     203   \param alignment Alignment flags
     204
     205   \sa alignmentInCanvas(), setMaxColumns()
     206
     207   \note To align a legend with many items horizontally
    203208        the number of columns need to be limited
    204209 */
    205 void QwtPlotLegendItem::setAlignment( Qt::Alignment alignment )
    206 {
    207     if ( d_data->alignment != alignment )
    208     {
    209         d_data->alignment = alignment;
    210         itemChanged();
    211     }
    212 }
    213 
    214 /*!
    215   \return Alignment flags
    216   \sa setAlignment()
    217  */
    218 Qt::Alignment QwtPlotLegendItem::alignment() const
    219 {
    220     return d_data->alignment;
    221 }
    222 
    223 /*!
    224   \brief Limit the number of columns
    225 
    226   When aligning the legend horizontally ( Qt::AlignLeft, Qt::AlignRight )
    227   the number of columns needs to be limited to avoid, that
    228   the width of the legend grows with an increasing number of entries.
    229 
    230   \param maxColumns Maximum number of columns. 0 means unlimited.
    231   \sa maxColumns(), QwtDynGridLayout::setMaxColumns()
     210void QwtPlotLegendItem::setAlignmentInCanvas( Qt::Alignment alignment )
     211{
     212    if ( m_data->canvasAlignment != alignment )
     213    {
     214        m_data->canvasAlignment = alignment;
     215        itemChanged();
     216    }
     217}
     218
     219/*!
     220   \return Alignment flags
     221   \sa setAlignmentInCanvas()
     222 */
     223Qt::Alignment QwtPlotLegendItem::alignmentInCanvas() const
     224{
     225    return m_data->canvasAlignment;
     226}
     227
     228/*!
     229   \brief Limit the number of columns
     230
     231   When aligning the legend horizontally ( Qt::AlignLeft, Qt::AlignRight )
     232   the number of columns needs to be limited to avoid, that
     233   the width of the legend grows with an increasing number of entries.
     234
     235   \param maxColumns Maximum number of columns. 0 means unlimited.
     236   \sa maxColumns(), QwtDynGridLayout::setMaxColumns()
    232237 */
    233238void QwtPlotLegendItem::setMaxColumns( uint maxColumns )
    234239{
    235     if ( maxColumns != d_data->layout->maxColumns() )
    236     {
    237         d_data->layout->setMaxColumns( maxColumns );
    238         itemChanged();
    239     }
    240 }
    241 
    242 /*!
    243   \return Maximum number of columns
    244   \sa maxColumns(), QwtDynGridLayout::maxColumns()
     240    if ( maxColumns != m_data->layout->maxColumns() )
     241    {
     242        m_data->layout->setMaxColumns( maxColumns );
     243        itemChanged();
     244    }
     245}
     246
     247/*!
     248   \return Maximum number of columns
     249   \sa maxColumns(), QwtDynGridLayout::maxColumns()
    245250 */
    246251uint QwtPlotLegendItem::maxColumns() const
    247252{
    248     return d_data->layout->maxColumns();
    249 }
    250 
    251 /*!
    252   \brief Set the margin around legend items
    253 
    254   The default setting for the margin is 0.
    255 
    256   \param margin Margin in pixels
    257   \sa margin(), setSpacing(), setItemMargin(), setItemSpacing
     253    return m_data->layout->maxColumns();
     254}
     255
     256/*!
     257   \brief Set the margin around legend items
     258
     259   The default setting for the margin is 0.
     260
     261   \param margin Margin in pixels
     262   \sa margin(), setSpacing(), setItemMargin(), setItemSpacing
    258263 */
    259264void QwtPlotLegendItem::setMargin( int margin )
    … …  
    262267    if ( margin != this->margin() )
    263268    {
    264         d_data->layout->setContentsMargins(
     269        m_data->layout->setContentsMargins(
    265270            margin, margin, margin, margin );
    266271
    … …  
    270275
    271276/*!
    272   \return Margin around the legend items
    273   \sa setMargin(), spacing(), itemMargin(), itemSpacing()
     277   \return Margin around the legend items
     278   \sa setMargin(), spacing(), itemMargin(), itemSpacing()
    274279 */
    275280int QwtPlotLegendItem::margin() const
    276281{
    277282    int left;
    278     d_data->layout->getContentsMargins( &left, NULL, NULL, NULL );
     283    m_data->layout->getContentsMargins( &left, NULL, NULL, NULL );
    279284
    280285    return left;
    … …  
    282287
    283288/*!
    284   \brief Set the spacing between the legend items
    285 
    286   \param spacing Spacing in pixels
    287   \sa spacing(), setMargin()
    288 */
     289   \brief Set the spacing between the legend items
     290
     291   \param spacing Spacing in pixels
     292   \sa spacing(), setMargin()
     293 */
    289294void QwtPlotLegendItem::setSpacing( int spacing )
    290295{
    291296    spacing = qMax( spacing, 0 );
    292     if ( spacing != d_data->layout->spacing() )
    293     {
    294         d_data->layout->setSpacing( spacing );
    295         itemChanged();
    296     }
    297 }
    298 
    299 /*!
    300   \return Spacing between the legend items
    301   \sa setSpacing(), margin(), itemSpacing(), itemMargin()
     297    if ( spacing != m_data->layout->spacing() )
     298    {
     299        m_data->layout->setSpacing( spacing );
     300        itemChanged();
     301    }
     302}
     303
     304/*!
     305   \return Spacing between the legend items
     306   \sa setSpacing(), margin(), itemSpacing(), itemMargin()
    302307 */
    303308int QwtPlotLegendItem::spacing() const
    304309{
    305     return d_data->layout->spacing();
    306 }
    307 
    308 /*!
    309   Set the margin around each item
    310 
    311   \param margin Margin
    312   \sa itemMargin(), setItemSpacing(), setMargin(), setSpacing()
     310    return m_data->layout->spacing();
     311}
     312
     313/*!
     314   Set the margin around each item
     315
     316   \param margin Margin
     317   \sa itemMargin(), setItemSpacing(), setMargin(), setSpacing()
    313318 */
    314319void QwtPlotLegendItem::setItemMargin( int margin )
    315320{
    316321    margin = qMax( margin, 0 );
    317     if ( margin != d_data->itemMargin )
    318     {
    319         d_data->itemMargin = margin;
    320 
    321         d_data->layout->invalidate();
    322         itemChanged();
    323     }
    324 }
    325 
    326 /*!
    327   \return Margin around each item
    328   \sa setItemMargin(), itemSpacing(), margin(), spacing()
    329 */
     322    if ( margin != m_data->itemMargin )
     323    {
     324        m_data->itemMargin = margin;
     325
     326        m_data->layout->invalidate();
     327        itemChanged();
     328    }
     329}
     330
     331/*!
     332   \return Margin around each item
     333   \sa setItemMargin(), itemSpacing(), margin(), spacing()
     334 */
    330335int QwtPlotLegendItem::itemMargin() const
    331336{
    332     return d_data->itemMargin;
    333 }
    334 
    335 /*!
    336   Set the spacing inside of each item
    337 
    338   \param spacing Spacing
    339   \sa itemSpacing(), setItemMargin(), setMargin(), setSpacing()
     337    return m_data->itemMargin;
     338}
     339
     340/*!
     341   Set the spacing inside of each item
     342
     343   \param spacing Spacing
     344   \sa itemSpacing(), setItemMargin(), setMargin(), setSpacing()
    340345 */
    341346void QwtPlotLegendItem::setItemSpacing( int spacing )
    342347{
    343348    spacing = qMax( spacing, 0 );
    344     if ( spacing != d_data->itemSpacing )
    345     {
    346         d_data->itemSpacing = spacing;
    347 
    348         d_data->layout->invalidate();
    349         itemChanged();
    350     }
    351 
    352 }
    353 
    354 /*!
    355   \return Spacing inside of each item
    356   \sa setItemSpacing(), itemMargin(), margin(), spacing()
    357 */
     349    if ( spacing != m_data->itemSpacing )
     350    {
     351        m_data->itemSpacing = spacing;
     352
     353        m_data->layout->invalidate();
     354        itemChanged();
     355    }
     356
     357}
     358
     359/*!
     360   \return Spacing inside of each item
     361   \sa setItemSpacing(), itemMargin(), margin(), spacing()
     362 */
    358363int QwtPlotLegendItem::itemSpacing() const
    359364{
    360     return d_data->itemSpacing;
     365    return m_data->itemSpacing;
    361366}
    362367
    … …  
    366371   \param font Legend font
    367372   \sa font()
    368 */
    369 void QwtPlotLegendItem::setFont( const QFont &font )
    370 {
    371     if ( font != d_data->font )
    372     {
    373         d_data->font = font;
    374 
    375         d_data->layout->invalidate();
     373 */
     374void QwtPlotLegendItem::setFont( const QFont& font )
     375{
     376    if ( font != m_data->font )
     377    {
     378        m_data->font = font;
     379
     380        m_data->layout->invalidate();
    376381        itemChanged();
    377382    }
    … …  
    381386   \return Font used for drawing the text label
    382387   \sa setFont()
    383 */
     388 */
    384389QFont QwtPlotLegendItem::font() const
    385390{
    386     return d_data->font;
    387 }
    388 
    389 /*!
    390   \brief Set the margin between the legend and the canvas border
    391 
    392   The default setting for the margin is 10 pixels.
    393 
    394   \param distance Margin in pixels
    395   \sa setMargin()
    396  */
    397 void QwtPlotLegendItem::setBorderDistance( int distance )
    398 {
    399     if ( distance < 0 )
    400         distance = -1;
    401 
    402     if ( distance != d_data->borderDistance )
    403     {
    404         d_data->borderDistance = distance;
    405         itemChanged();
    406     }
    407 }
    408 
    409 /*!
    410   \return Margin between the legend and the canvas border
    411   \sa margin()
    412  */
    413 int QwtPlotLegendItem::borderDistance() const
    414 {
    415     return d_data->borderDistance;
    416 }
    417 
    418 /*!
    419   Set the radius for the border
    420 
    421   \param radius A value <= 0 defines a rectangular border
    422   \sa borderRadius(), setBorderPen()
     391    return m_data->font;
     392}
     393
     394/*!
     395   \brief Set the distance between the legend and the canvas border
     396
     397   The default setting is 10 pixels.
     398
     399   \param orientations Qt::Horizontal is for the left/right,
     400                      Qt::Vertical for the top/bottom offset.
     401
     402   \param numPixels Distance in pixels
     403   \sa setMargin()
     404 */
     405void QwtPlotLegendItem::setOffsetInCanvas(
     406    Qt::Orientations orientations, int numPixels )
     407{
     408    if ( numPixels < 0 )
     409        numPixels = -1;
     410
     411    bool isChanged = false;
     412
     413    int* offset = m_data->canvasOffset;
     414
     415    if ( orientations & Qt::Horizontal )
     416    {
     417        if ( numPixels != offset[0] )
     418        {
     419            offset[0] = numPixels;
     420            isChanged = true;
     421        }
     422    }
     423
     424    if ( orientations & Qt::Vertical )
     425    {
     426        if ( numPixels != offset[1] )
     427        {
     428            offset[1] = numPixels;
     429            isChanged = true;
     430        }
     431    }
     432
     433    if ( isChanged )
     434        itemChanged();
     435}
     436
     437/*!
     438   \param orientation Qt::Horizontal is for the left/right,
     439                      Qt::Vertical for the top/bottom padding.
     440
     441   \return Distance between the legend and the canvas border
     442   \sa setOffsetInCanvas()
     443 */
     444int QwtPlotLegendItem::offsetInCanvas(
     445    Qt::Orientation orientation ) const
     446{
     447    const int index = ( orientation == Qt::Vertical ) ? 1 : 0;
     448    return m_data->canvasOffset[index];
     449}
     450
     451/*!
     452   Set the radius for the border
     453
     454   \param radius A value <= 0 defines a rectangular border
     455   \sa borderRadius(), setBorderPen()
    423456 */
    424457void QwtPlotLegendItem::setBorderRadius( double radius )
    425458{
    426     radius = qMax( 0.0, radius );
    427 
    428     if ( radius != d_data->borderRadius )
    429     {
    430         d_data->borderRadius = radius;
    431         itemChanged();
    432     }
    433 }
    434 
    435 /*!
    436   \return Radius of the border
    437   \sa setBorderRadius(), setBorderPen()
     459    radius = qwtMaxF( 0.0, radius );
     460
     461    if ( radius != m_data->borderRadius )
     462    {
     463        m_data->borderRadius = radius;
     464        itemChanged();
     465    }
     466}
     467
     468/*!
     469   \return Radius of the border
     470   \sa setBorderRadius(), setBorderPen()
    438471 */
    439472double QwtPlotLegendItem::borderRadius() const
    440473{
    441     return d_data->borderRadius;
    442 }
    443 
    444 /*!
    445   Set the pen for drawing the border
    446 
    447   \param pen Border pen
    448   \sa borderPen(), setBackgroundBrush()
    449  */
    450 void QwtPlotLegendItem::setBorderPen( const QPen &pen )
    451 {
    452     if ( d_data->borderPen != pen )
    453     {
    454         d_data->borderPen = pen;
    455         itemChanged();
    456     }
    457 }
    458 
    459 /*!
    460   \return Pen for drawing the border
    461   \sa setBorderPen(), backgroundBrush()
     474    return m_data->borderRadius;
     475}
     476
     477/*!
     478   Set the pen for drawing the border
     479
     480   \param pen Border pen
     481   \sa borderPen(), setBackgroundBrush()
     482 */
     483void QwtPlotLegendItem::setBorderPen( const QPen& pen )
     484{
     485    if ( m_data->borderPen != pen )
     486    {
     487        m_data->borderPen = pen;
     488        itemChanged();
     489    }
     490}
     491
     492/*!
     493   \return Pen for drawing the border
     494   \sa setBorderPen(), backgroundBrush()
    462495 */
    463496QPen QwtPlotLegendItem::borderPen() const
    464497{
    465     return d_data->borderPen;
    466 }
    467 
    468 /*!
    469   \brief Set the background brush
    470 
    471   The brush is used to fill the background
    472 
    473   \param brush Brush
    474   \sa backgroundBrush(), setBackgroundMode(), drawBackground()
    475  */
    476 void QwtPlotLegendItem::setBackgroundBrush( const QBrush &brush )
    477 {
    478     if ( d_data->backgroundBrush != brush )
    479     {
    480         d_data->backgroundBrush = brush;
    481         itemChanged();
    482     }
    483 }
    484 
    485 /*!
    486   \return Brush is used to fill the background
    487   \sa setBackgroundBrush(), backgroundMode(), drawBackground()
     498    return m_data->borderPen;
     499}
     500
     501/*!
     502   \brief Set the background brush
     503
     504   The brush is used to fill the background
     505
     506   \param brush Brush
     507   \sa backgroundBrush(), setBackgroundMode(), drawBackground()
     508 */
     509void QwtPlotLegendItem::setBackgroundBrush( const QBrush& brush )
     510{
     511    if ( m_data->backgroundBrush != brush )
     512    {
     513        m_data->backgroundBrush = brush;
     514        itemChanged();
     515    }
     516}
     517
     518/*!
     519   \return Brush is used to fill the background
     520   \sa setBackgroundBrush(), backgroundMode(), drawBackground()
    488521 */
    489522QBrush QwtPlotLegendItem::backgroundBrush() const
    490523{
    491     return d_data->backgroundBrush;
    492 }
    493 
    494 /*!
    495   \brief Set the background mode
    496 
    497   Depending on the mode the complete legend or each item
    498   might have an background.
    499 
    500   The default setting is LegendBackground.
     524    return m_data->backgroundBrush;
     525}
     526
     527/*!
     528   \brief Set the background mode
     529
     530   Depending on the mode the complete legend or each item
     531   might have an background.
     532
     533   The default setting is LegendBackground.
    501534
    502535   \sa backgroundMode(), setBackgroundBrush(), drawBackground()
    … …  
    504537void QwtPlotLegendItem::setBackgroundMode( BackgroundMode mode )
    505538{
    506     if ( mode != d_data->backgroundMode )
    507     {
    508         d_data->backgroundMode = mode;
    509         itemChanged();
    510     }
    511 }
    512 
    513 /*!
    514   \return backgroundMode
    515   \sa setBackgroundMode(), backgroundBrush(), drawBackground()
     539    if ( mode != m_data->backgroundMode )
     540    {
     541        m_data->backgroundMode = mode;
     542        itemChanged();
     543    }
     544}
     545
     546/*!
     547   \return backgroundMode
     548   \sa setBackgroundMode(), backgroundBrush(), drawBackground()
    516549 */
    517550QwtPlotLegendItem::BackgroundMode QwtPlotLegendItem::backgroundMode() const
    518551{
    519     return d_data->backgroundMode;
    520 }
    521 
    522 /*!
    523   \brief Set the pen for drawing text labels
    524 
    525   \param pen Text pen
    526   \sa textPen(), setFont()
    527  */
    528 void QwtPlotLegendItem::setTextPen( const QPen &pen )
    529 {
    530     if ( d_data->textPen != pen )
    531     {
    532         d_data->textPen = pen;
    533         itemChanged();
    534     }
    535 }
    536 
    537 /*!
    538   \return Pen for drawing text labels
    539   \sa setTextPen(), font()
     552    return m_data->backgroundMode;
     553}
     554
     555/*!
     556   \brief Set the pen for drawing text labels
     557
     558   \param pen Text pen
     559   \sa textPen(), setFont()
     560 */
     561void QwtPlotLegendItem::setTextPen( const QPen& pen )
     562{
     563    if ( m_data->textPen != pen )
     564    {
     565        m_data->textPen = pen;
     566        itemChanged();
     567    }
     568}
     569
     570/*!
     571   \return Pen for drawing text labels
     572   \sa setTextPen(), font()
    540573 */
    541574QPen QwtPlotLegendItem::textPen() const
    542575{
    543     return d_data->textPen;
    544 }
    545 
    546 /*!
    547   Draw the legend
    548 
    549   \param painter Painter
    550   \param xMap x Scale Map
    551   \param yMap y Scale Map
    552   \param canvasRect Contents rectangle of the canvas in painter coordinates
    553 */
    554 void QwtPlotLegendItem::draw( QPainter *painter,
    555     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    556     const QRectF &canvasRect ) const
     576    return m_data->textPen;
     577}
     578
     579/*!
     580   Draw the legend
     581
     582   \param painter Painter
     583   \param xMap x Scale Map
     584   \param yMap y Scale Map
     585   \param canvasRect Contents rectangle of the canvas in painter coordinates
     586 */
     587void QwtPlotLegendItem::draw( QPainter* painter,
     588    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     589    const QRectF& canvasRect ) const
    557590{
    558591    Q_UNUSED( xMap );
    559592    Q_UNUSED( yMap );
    560593
    561     d_data->layout->setGeometry( geometry( canvasRect ) );
    562     if ( d_data->layout->geometry().isEmpty() )
     594    m_data->layout->setGeometry( geometry( canvasRect ) );
     595    if ( m_data->layout->geometry().isEmpty() )
    563596    {
    564597        // don't draw a legend when having no content
    … …  
    566599    }
    567600
    568     if ( d_data->backgroundMode == QwtPlotLegendItem::LegendBackground )
    569         drawBackground( painter, d_data->layout->geometry() );
    570 
    571     for ( int i = 0; i <  d_data->layout->count(); i++ )
    572     {
    573         const QwtLegendLayoutItem *layoutItem =
    574             static_cast<QwtLegendLayoutItem *>( d_data->layout->itemAt( i ) );
    575 
    576         if ( d_data->backgroundMode == QwtPlotLegendItem::ItemBackground )
     601    if ( m_data->backgroundMode == QwtPlotLegendItem::LegendBackground )
     602        drawBackground( painter, m_data->layout->geometry() );
     603
     604    for ( int i = 0; i < m_data->layout->count(); i++ )
     605    {
     606        const LayoutItem* layoutItem =
     607            static_cast< LayoutItem* >( m_data->layout->itemAt( i ) );
     608
     609        if ( m_data->backgroundMode == QwtPlotLegendItem::ItemBackground )
    577610            drawBackground( painter, layoutItem->geometry() );
    578611
    … …  
    587620
    588621/*!
    589   Draw a rounded rect
    590 
    591   \param painter Painter
    592   \param rect Bounding rectangle
    593 
    594   \sa setBorderRadius(), setBorderPen(),
     622   Draw a rounded rect
     623
     624   \param painter Painter
     625   \param rect Bounding rectangle
     626
     627   \sa setBorderRadius(), setBorderPen(),
    595628      setBackgroundBrush(), setBackgroundMode()
    596629 */
    597630void QwtPlotLegendItem::drawBackground(
    598     QPainter *painter, const QRectF &rect ) const
     631    QPainter* painter, const QRectF& rect ) const
    599632{
    600633    painter->save();
    601634
    602     painter->setPen( d_data->borderPen );
    603     painter->setBrush( d_data->backgroundBrush );
    604 
    605     const double radius = d_data->borderRadius;
     635    painter->setPen( m_data->borderPen );
     636    painter->setBrush( m_data->backgroundBrush );
     637
     638    const double radius = m_data->borderRadius;
    606639    painter->drawRoundedRect( rect, radius, radius );
    607640
    … …  
    610643
    611644/*!
    612   Calculate the geometry of the legend on the canvas
    613 
    614   \param canvasRect Geometry of the canvas
    615   \return Geometry of the legend
    616 */
    617 QRect QwtPlotLegendItem::geometry( const QRectF &canvasRect ) const
     645   Calculate the geometry of the legend on the canvas
     646
     647   \param canvasRect Geometry of the canvas
     648   \return Geometry of the legend
     649 */
     650QRect QwtPlotLegendItem::geometry( const QRectF& canvasRect ) const
    618651{
    619652    QRect rect;
    620     rect.setSize( d_data->layout->sizeHint() );
    621 
    622     int margin = d_data->borderDistance;
    623     if ( d_data->alignment & Qt::AlignHCenter )
     653    rect.setSize( m_data->layout->sizeHint() );
     654
     655    if ( m_data->canvasAlignment & Qt::AlignHCenter )
    624656    {
    625657        int x = qRound( canvasRect.center().x() );
    626658        rect.moveCenter( QPoint( x, rect.center().y() ) );
    627659    }
    628     else if ( d_data->alignment & Qt::AlignRight )
    629     {
    630         rect.moveRight( qFloor( canvasRect.right() - margin ) );
     660    else if ( m_data->canvasAlignment & Qt::AlignRight )
     661    {
     662        const int offset = offsetInCanvas( Qt::Horizontal );
     663        rect.moveRight( qwtFloor( canvasRect.right() - offset ) );
    631664    }
    632665    else
    633666    {
    634         rect.moveLeft( qCeil( canvasRect.left() + margin ) );
    635     }
    636 
    637     if ( d_data->alignment & Qt::AlignVCenter )
     667        const int offset = offsetInCanvas( Qt::Horizontal );
     668        rect.moveLeft( qwtCeil( canvasRect.left() + offset ) );
     669    }
     670
     671    if ( m_data->canvasAlignment & Qt::AlignVCenter )
    638672    {
    639673        int y = qRound( canvasRect.center().y() );
    640674        rect.moveCenter( QPoint( rect.center().x(), y ) );
    641675    }
    642     else if ( d_data->alignment & Qt::AlignBottom )
    643     {
    644         rect.moveBottom( qFloor( canvasRect.bottom() - margin ) );
     676    else if ( m_data->canvasAlignment & Qt::AlignBottom )
     677    {
     678        const int offset = offsetInCanvas( Qt::Vertical );
     679        rect.moveBottom( qwtFloor( canvasRect.bottom() - offset ) );
    645680    }
    646681    else
    647682    {
    648         rect.moveTop( qCeil( canvasRect.top() + margin ) );
     683        const int offset = offsetInCanvas( Qt::Vertical );
     684        rect.moveTop( qwtCeil( canvasRect.top() + offset ) );
    649685    }
    650686
    … …  
    653689
    654690/*!
    655   Update the legend items according to modifications of a
    656   plot item
    657 
    658   \param plotItem Plot item
    659   \param data Attributes of the legend entries
    660  */
    661 void QwtPlotLegendItem::updateLegend( const QwtPlotItem *plotItem,
    662         const QList<QwtLegendData> &data )
     691   Update the legend items according to modifications of a
     692   plot item
     693
     694   \param plotItem Plot item
     695   \param data Attributes of the legend entries
     696 */
     697void QwtPlotLegendItem::updateLegend( const QwtPlotItem* plotItem,
     698    const QList< QwtLegendData >& data )
    663699{
    664700    if ( plotItem == NULL )
    665701        return;
    666702
    667     QList<QwtLegendLayoutItem *> layoutItems;
    668 
    669     QMap<const QwtPlotItem *, QList<QwtLegendLayoutItem *> >::iterator it =
    670         d_data->map.find( plotItem );
    671     if ( it != d_data->map.end() )
     703    QList< LayoutItem* > layoutItems;
     704
     705    QMap< const QwtPlotItem*, QList< LayoutItem* > >::const_iterator it =
     706        m_data->map.constFind( plotItem );
     707    if ( it != m_data->map.constEnd() )
    672708        layoutItems = it.value();
    673709
    … …  
    680716        for ( int i = 0; i < layoutItems.size(); i++ )
    681717        {
    682             d_data->layout->removeItem( layoutItems[i] );
     718            m_data->layout->removeItem( layoutItems[i] );
    683719            delete layoutItems[i];
    684720        }
    685721        layoutItems.clear();
    686722
    687         if ( it != d_data->map.end() )
    688             d_data->map.remove( plotItem );
     723        if ( it != m_data->map.constEnd() )
     724            m_data->map.remove( plotItem );
    689725
    690726        if ( !data.isEmpty() )
    691727        {
     728            layoutItems.reserve( data.size() );
     729
    692730            for ( int i = 0; i < data.size(); i++ )
    693731            {
    694                 QwtLegendLayoutItem *layoutItem =
    695                     new QwtLegendLayoutItem( this, plotItem );
    696                 d_data->layout->addItem( layoutItem );
     732                LayoutItem* layoutItem =
     733                    new LayoutItem( this, plotItem );
     734                m_data->layout->addItem( layoutItem );
    697735                layoutItems += layoutItem;
    698736            }
    699737
    700             d_data->map.insert( plotItem, layoutItems );
     738            m_data->map.insert( plotItem, layoutItems );
    701739        }
    702740    }
    … …  
    713751    if ( changed )
    714752    {
    715         d_data->layout->invalidate();
     753        m_data->layout->invalidate();
    716754        itemChanged();
    717755    }
    … …  
    721759void QwtPlotLegendItem::clearLegend()
    722760{
    723     if ( !d_data->map.isEmpty() )
    724     {
    725         d_data->map.clear();
    726 
    727         for ( int i = d_data->layout->count() - 1; i >= 0; i-- )
    728             delete d_data->layout->takeAt( i );
    729 
    730         itemChanged();
    731     }
    732 }
    733 
    734 /*!
    735   Draw an entry on the legend
    736 
    737   \param painter Qt Painter
    738   \param plotItem Plot item, represented by the entry
    739   \param data Attributes of the legend entry
    740   \param rect Bounding rectangle for the entry
    741  */
    742 void QwtPlotLegendItem::drawLegendData( QPainter *painter,
    743     const QwtPlotItem *plotItem, const QwtLegendData &data,
    744     const QRectF &rect ) const
     761    if ( !m_data->map.isEmpty() )
     762    {
     763        m_data->map.clear();
     764
     765        for ( int i = m_data->layout->count() - 1; i >= 0; i-- )
     766            delete m_data->layout->takeAt( i );
     767
     768        itemChanged();
     769    }
     770}
     771
     772/*!
     773   Draw an entry on the legend
     774
     775   \param painter Qt Painter
     776   \param plotItem Plot item, represented by the entry
     777   \param data Attributes of the legend entry
     778   \param rect Bounding rectangle for the entry
     779 */
     780void QwtPlotLegendItem::drawLegendData( QPainter* painter,
     781    const QwtPlotItem* plotItem, const QwtLegendData& data,
     782    const QRectF& rect ) const
    745783{
    746784    Q_UNUSED( plotItem );
    747785
    748     const int m = d_data->itemMargin;
     786    const int m = m_data->itemMargin;
    749787    const QRectF r = rect.toRect().adjusted( m, m, -m, -m );
    750788
    … …  
    763801        graphic.render( painter, iconRect, Qt::KeepAspectRatio );
    764802
    765         titleOff += iconRect.width() + d_data->itemSpacing;
     803        titleOff += iconRect.width() + m_data->itemSpacing;
    766804    }
    767805
    … …  
    778816
    779817/*!
    780   Minimum size hint needed to display an entry
    781 
    782   \param data Attributes of the legend entry
    783   \return Minimum size
    784  */
    785 QSize QwtPlotLegendItem::minimumSize( const QwtLegendData &data ) const
    786 {
    787     QSize size( 2 * d_data->itemMargin, 2 * d_data->itemMargin );
     818   Minimum size hint needed to display an entry
     819
     820   \param data Attributes of the legend entry
     821   \return Minimum size
     822 */
     823QSize QwtPlotLegendItem::minimumSize( const QwtLegendData& data ) const
     824{
     825    QSize size( 2 * m_data->itemMargin, 2 * m_data->itemMargin );
    788826
    789827    if ( !data.isValid() )
    … …  
    806844        const QSizeF sz = text.textSize( font() );
    807845
    808         w += qCeil( sz.width() );
    809         h = qMax( h, qCeil( sz.height() ) );
     846        w += qwtCeil( sz.width() );
     847        h = qMax( h, qwtCeil( sz.height() ) );
    810848    }
    811849
    812850    if ( graphic.width() > 0 && !text.isEmpty() )
    813         w += d_data->itemSpacing;
     851        w += m_data->itemSpacing;
    814852
    815853    size += QSize( w, h );
    … …  
    818856
    819857/*!
    820   \return The preferred height, for a width.
    821   \param data Attributes of the legend entry
    822   \param width Width
    823 */
     858   \return The preferred height, for a width.
     859   \param data Attributes of the legend entry
     860   \param width Width
     861 */
    824862int QwtPlotLegendItem::heightForWidth(
    825     const QwtLegendData &data, int width ) const
    826 {
    827     width -= 2 * d_data->itemMargin;
     863    const QwtLegendData& data, int width ) const
     864{
     865    width -= 2 * m_data->itemMargin;
    828866
    829867    const QwtGraphic graphic = data.icon();
    … …  
    834872
    835873    if ( graphic.width() > 0 )
    836         width -= graphic.width() + d_data->itemSpacing;
     874        width -= graphic.width() + m_data->itemSpacing;
    837875
    838876    int h = text.heightForWidth( width, font() );
    839     h += 2 * d_data->itemMargin;
     877    h += 2 * m_data->itemMargin;
    840878
    841879    return qMax( graphic.height(), h );
    … …  
    843881
    844882/*!
    845   \return All plot items with an entry on the legend
    846   \note A plot item might have more than one entry on the legend
    847  */
    848 QList< const QwtPlotItem * > QwtPlotLegendItem::plotItems() const
    849 {
    850     return d_data->map.keys();
    851 }
    852 
    853 /*!
    854   \return Geometries of the items of a plot item
    855   \note Usually a plot item has only one entry on the legend
    856 */
     883   \return All plot items with an entry on the legend
     884   \note A plot item might have more than one entry on the legend
     885 */
     886QList< const QwtPlotItem* > QwtPlotLegendItem::plotItems() const
     887{
     888    return m_data->map.keys();
     889}
     890
     891/*!
     892   \return Geometries of the items of a plot item
     893   \note Usually a plot item has only one entry on the legend
     894 */
    857895QList< QRect > QwtPlotLegendItem::legendGeometries(
    858     const QwtPlotItem *plotItem ) const
    859 {
    860     QList<QwtLegendLayoutItem *> layoutItems;
    861 
    862     QMap<const QwtPlotItem *, QList<QwtLegendLayoutItem *> >::iterator it =
    863         d_data->map.find( plotItem );
    864     if ( it != d_data->map.end() )
     896    const QwtPlotItem* plotItem ) const
     897{
     898    QList< LayoutItem* > layoutItems;
     899
     900    QMap< const QwtPlotItem*, QList< LayoutItem* > >::const_iterator it =
     901        m_data->map.constFind( plotItem );
     902    if ( it != m_data->map.constEnd() )
    865903        layoutItems = it.value();
    866904
    867     QList<QRect> geometries;
     905    QList< QRect > geometries;
     906    geometries.reserve(layoutItems.size() );
     907
    868908    for ( int i = 0; i < layoutItems.size(); i++ )
    869909        geometries += layoutItems[i]->geometry();
  • trunk/BNC/qwt/qwt_plot_legenditem.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_item.h"
    15 #include "qwt_legend_data.h"
    1615
    1716class QFont;
    1817
    1918/*!
    20   \brief A class which draws a legend inside the plot canvas
     19   \brief A class which draws a legend inside the plot canvas
    2120
    22   QwtPlotLegendItem can be used to draw a inside the plot canvas.
    23   It can be used together with a QwtLegend or instead of it
    24   to have more space for the plot canvas.
     21   QwtPlotLegendItem can be used to draw a inside the plot canvas.
     22   It can be used together with a QwtLegend or instead of it
     23   to have more space for the plot canvas.
    2524
    26   In opposite to QwtLegend the legend item is not interactive.
    27   To identify mouse clicks on a legend item an event filter
    28   needs to be installed catching mouse events ob the plot canvas.
    29   The geometries of the legend items are available using
    30   legendGeometries().
     25   In opposite to QwtLegend the legend item is not interactive.
     26   To identify mouse clicks on a legend item an event filter
     27   needs to be installed catching mouse events ob the plot canvas.
     28   The geometries of the legend items are available using
     29   legendGeometries().
    3130
    32   The legend item is aligned to plot canvas according to
    33   its alignment() flags. It might have a background for the
    34   complete legend ( usually semi transparent ) or for
    35   each legend item.
     31   The legend item is aligned to plot canvas according to
     32   its alignment() flags. It might have a background for the
     33   complete legend ( usually semi transparent ) or for
     34   each legend item.
    3635
    37   \note An external QwtLegend with a transparent background
     36   \note An external QwtLegend with a transparent background
    3837        on top the plot canvas might be another option
    3938        with a similar effect.
    40 */
     39 */
    4140
    42 class QWT_EXPORT QwtPlotLegendItem: public QwtPlotItem
     41class QWT_EXPORT QwtPlotLegendItem : public QwtPlotItem
    4342{
    44 public:
     43  public:
    4544    /*!
    46       \brief Background mode
     45       \brief Background mode
    4746
    48       Depending on the mode the complete legend or each item
    49       might have an background.
     47       Depending on the mode the complete legend or each item
     48       might have an background.
    5049
    51       The default setting is LegendBackground.
     50       The default setting is LegendBackground.
    5251
    5352       \sa setBackgroundMode(), setBackgroundBrush(), drawBackground()
    … …  
    6564    virtual ~QwtPlotLegendItem();
    6665
    67     virtual int rtti() const;
     66    virtual int rtti() const QWT_OVERRIDE;
    6867
    69     void setAlignment( Qt::Alignment );
    70     Qt::Alignment alignment() const;
     68    void setAlignmentInCanvas( Qt::Alignment );
     69    Qt::Alignment alignmentInCanvas() const;
     70
     71    void setOffsetInCanvas( Qt::Orientations, int numPixels );
     72    int offsetInCanvas( Qt::Orientation ) const;
    7173
    7274    void setMaxColumns( uint );
    … …  
    8890    QFont font() const;
    8991
    90     void setBorderDistance( int );
    91     int borderDistance() const;
    92 
    9392    void setBorderRadius( double );
    9493    double borderRadius() const;
    9594
    96     void setBorderPen( const QPen & );
     95    void setBorderPen( const QPen& );
    9796    QPen borderPen() const;
    9897
    99     void setBackgroundBrush( const QBrush & );
     98    void setBackgroundBrush( const QBrush& );
    10099    QBrush backgroundBrush() const;
    101100
    … …  
    103102    BackgroundMode backgroundMode() const;
    104103
    105     void setTextPen( const QPen & );
     104    void setTextPen( const QPen& );
    106105    QPen textPen() const;
    107106
    108     virtual void draw( QPainter *,
    109         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    110         const QRectF &canvasRect ) const;
     107    virtual void draw( QPainter*,
     108        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     109        const QRectF& canvasRect ) const QWT_OVERRIDE;
    111110
    112111    void clearLegend();
    113112
    114     virtual void updateLegend( const QwtPlotItem *,
    115         const QList<QwtLegendData> & );
     113    virtual void updateLegend( const QwtPlotItem*,
     114        const QList< QwtLegendData >& ) QWT_OVERRIDE;
    116115
    117     virtual QRect geometry( const QRectF &canvasRect ) const;
     116    virtual QRect geometry( const QRectF& canvasRect ) const;
    118117
    119     virtual QSize minimumSize( const QwtLegendData & ) const;
    120     virtual int heightForWidth( const QwtLegendData &, int width ) const;
     118    virtual QSize minimumSize( const QwtLegendData& ) const;
     119    virtual int heightForWidth( const QwtLegendData&, int width ) const;
    121120
    122     QList< const QwtPlotItem * > plotItems() const;
    123     QList< QRect > legendGeometries( const QwtPlotItem * ) const;
     121    QList< const QwtPlotItem* > plotItems() const;
     122    QList< QRect > legendGeometries( const QwtPlotItem* ) const;
    124123
    125 protected:
    126     virtual void drawLegendData( QPainter *painter,
    127         const QwtPlotItem *, const QwtLegendData &, const QRectF & ) const;
     124  protected:
     125    virtual void drawLegendData( QPainter*,
     126        const QwtPlotItem*, const QwtLegendData&, const QRectF& ) const;
    128127
    129     virtual void drawBackground( QPainter *, const QRectF &rect ) const;
     128    virtual void drawBackground( QPainter*, const QRectF& rect ) const;
    130129
    131 private:
     130  private:
    132131    class PrivateData;
    133     PrivateData *d_data;
     132    PrivateData* m_data;
    134133};
    135134
  • trunk/BNC/qwt/qwt_plot_magnifier.cpp

    r8127 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_scale_div.h"
     11#include "qwt_scale_map.h"
    1212#include "qwt_plot_magnifier.h"
    13 #include <qevent.h>
    1413
    1514class QwtPlotMagnifier::PrivateData
    1615{
    17 public:
     16  public:
    1817    PrivateData()
    1918    {
    20         for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
     19        for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
    2120            isAxisEnabled[axis] = true;
    2221    }
    2322
    24     bool isAxisEnabled[QwtPlot::axisCnt];
     23    bool isAxisEnabled[QwtAxis::AxisPositions];
    2524};
    2625
    … …  
    2827   Constructor
    2928   \param canvas Plot canvas to be magnified
    30 */
    31 QwtPlotMagnifier::QwtPlotMagnifier( QWidget *canvas ):
    32     QwtMagnifier( canvas )
     29 */
     30QwtPlotMagnifier::QwtPlotMagnifier( QWidget* canvas )
     31    : QwtMagnifier( canvas )
    3332{
    34     d_data = new PrivateData();
     33    m_data = new PrivateData();
    3534}
    3635
    … …  
    3837QwtPlotMagnifier::~QwtPlotMagnifier()
    3938{
    40     delete d_data;
     39    delete m_data;
    4140}
    4241
    … …  
    4746   All other axes will remain unchanged.
    4847
    49    \param axis Axis, see QwtPlot::Axis
     48   \param axisId Axis
    5049   \param on On/Off
    5150
    5251   \sa isAxisEnabled()
    53 */
    54 void QwtPlotMagnifier::setAxisEnabled( int axis, bool on )
     52 */
     53void QwtPlotMagnifier::setAxisEnabled( QwtAxisId axisId, bool on )
    5554{
    56     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    57         d_data->isAxisEnabled[axis] = on;
     55    if ( QwtAxis::isValid( axisId ) )
     56        m_data->isAxisEnabled[axisId] = on;
    5857}
    5958
    … …  
    6160   Test if an axis is enabled
    6261
    63    \param axis Axis, see QwtPlot::Axis
     62   \param axisId Axis
    6463   \return True, if the axis is enabled
    6564
    6665   \sa setAxisEnabled()
    67 */
    68 bool QwtPlotMagnifier::isAxisEnabled( int axis ) const
     66 */
     67bool QwtPlotMagnifier::isAxisEnabled( QwtAxisId axisId ) const
    6968{
    70     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    71         return d_data->isAxisEnabled[axis];
     69    if ( QwtAxis::isValid( axisId ) )
     70        return m_data->isAxisEnabled[axisId];
    7271
    7372    return true;
    … …  
    7574
    7675//! Return observed plot canvas
    77 QWidget *QwtPlotMagnifier::canvas()
     76QWidget* QwtPlotMagnifier::canvas()
    7877{
    7978    return parentWidget();
    … …  
    8180
    8281//! Return Observed plot canvas
    83 const QWidget *QwtPlotMagnifier::canvas() const
     82const QWidget* QwtPlotMagnifier::canvas() const
    8483{
    8584    return parentWidget();
    … …  
    8786
    8887//! Return plot widget, containing the observed plot canvas
    89 QwtPlot *QwtPlotMagnifier::plot()
     88QwtPlot* QwtPlotMagnifier::plot()
    9089{
    91     QWidget *w = canvas();
     90    QWidget* w = canvas();
    9291    if ( w )
    9392        w = w->parentWidget();
    9493
    95     return qobject_cast<QwtPlot *>( w );
     94    return qobject_cast< QwtPlot* >( w );
    9695}
    9796
    9897//! Return plot widget, containing the observed plot canvas
    99 const QwtPlot *QwtPlotMagnifier::plot() const
     98const QwtPlot* QwtPlotMagnifier::plot() const
    10099{
    101     const QWidget *w = canvas();
     100    const QWidget* w = canvas();
    102101    if ( w )
    103102        w = w->parentWidget();
    104103
    105     return qobject_cast<const QwtPlot *>( w );
     104    return qobject_cast< const QwtPlot* >( w );
    106105}
    107106
    … …  
    109108   Zoom in/out the axes scales
    110109   \param factor A value < 1.0 zooms in, a value > 1.0 zooms out.
    111 */
     110 */
    112111void QwtPlotMagnifier::rescale( double factor )
    113112{
    … …  
    125124    plt->setAutoReplot( false );
    126125
    127     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
     126    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
    128127    {
    129         if ( isAxisEnabled( axisId ) )
    130128        {
    131             const QwtScaleMap scaleMap = plt->canvasMap( axisId );
     129            const QwtAxisId axisId( axisPos );
    132130
    133             double v1 = scaleMap.s1();
    134             double v2 = scaleMap.s2();
     131            if ( isAxisEnabled( axisId ) )
     132            {
     133                const QwtScaleMap scaleMap = plt->canvasMap( axisId );
    135134
    136             if ( scaleMap.transformation() )
    137             {
    138                 // the coordinate system of the paint device is always linear
     135                double v1 = scaleMap.s1();
     136                double v2 = scaleMap.s2();
    139137
    140                 v1 = scaleMap.transform( v1 ); // scaleMap.p1()
    141                 v2 = scaleMap.transform( v2 ); // scaleMap.p2()
     138                if ( scaleMap.transformation() )
     139                {
     140                    // the coordinate system of the paint device is always linear
     141
     142                    v1 = scaleMap.transform( v1 ); // scaleMap.p1()
     143                    v2 = scaleMap.transform( v2 ); // scaleMap.p2()
     144                }
     145
     146                const double center = 0.5 * ( v1 + v2 );
     147                const double width_2 = 0.5 * ( v2 - v1 ) * factor;
     148
     149                v1 = center - width_2;
     150                v2 = center + width_2;
     151
     152                if ( scaleMap.transformation() )
     153                {
     154                    v1 = scaleMap.invTransform( v1 );
     155                    v2 = scaleMap.invTransform( v2 );
     156                }
     157
     158                plt->setAxisScale( axisId, v1, v2 );
     159                doReplot = true;
    142160            }
    143 
    144             const double center = 0.5 * ( v1 + v2 );
    145             const double width_2 = 0.5 * ( v2 - v1 ) * factor;
    146 
    147             v1 = center - width_2;
    148             v2 = center + width_2;
    149 
    150             if ( scaleMap.transformation() )
    151             {
    152                 v1 = scaleMap.invTransform( v1 );
    153                 v2 = scaleMap.invTransform( v2 );
    154             }
    155 
    156             plt->setAxisScale( axisId, v1, v2 );
    157             doReplot = true;
    158161        }
    159162    }
    … …  
    164167        plt->replot();
    165168}
     169
     170#include "moc_qwt_plot_magnifier.cpp"
  • trunk/BNC/qwt/qwt_plot_magnifier.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_PLOT_MAGNIFIER_H
    11 #define QWT_PLOT_MAGNIFIER_H 1
     11#define QWT_PLOT_MAGNIFIER_H
    1212
    1313#include "qwt_global.h"
     14#include "qwt_axis_id.h"
    1415#include "qwt_magnifier.h"
    1516
    … …  
    1718
    1819/*!
    19   \brief QwtPlotMagnifier provides zooming, by magnifying in steps.
     20   \brief QwtPlotMagnifier provides zooming, by magnifying in steps.
    2021
    21   Using QwtPlotMagnifier a plot can be zoomed in/out in steps using
    22   keys, the mouse wheel or moving a mouse button in vertical direction.
     22   Using QwtPlotMagnifier a plot can be zoomed in/out in steps using
     23   keys, the mouse wheel or moving a mouse button in vertical direction.
    2324
    24   Together with QwtPlotZoomer and QwtPlotPanner it is possible to implement
    25   individual and powerful navigation of the plot canvas.
     25   Together with QwtPlotZoomer and QwtPlotPanner it is possible to implement
     26   individual and powerful navigation of the plot canvas.
    2627
    27   \sa QwtPlotZoomer, QwtPlotPanner, QwtPlot
    28 */
    29 class QWT_EXPORT QwtPlotMagnifier: public QwtMagnifier
     28   \sa QwtPlotZoomer, QwtPlotPanner, QwtPlot
     29 */
     30class QWT_EXPORT QwtPlotMagnifier : public QwtMagnifier
    3031{
    3132    Q_OBJECT
    3233
    33 public:
    34     explicit QwtPlotMagnifier( QWidget * );
     34  public:
     35    explicit QwtPlotMagnifier( QWidget* );
    3536    virtual ~QwtPlotMagnifier();
    3637
    37     void setAxisEnabled( int axis, bool on );
    38     bool isAxisEnabled( int axis ) const;
     38    void setAxisEnabled( QwtAxisId, bool on );
     39    bool isAxisEnabled( QwtAxisId ) const;
    3940
    40     QWidget *canvas();
    41     const QWidget *canvas() const;
     41    QWidget* canvas();
     42    const QWidget* canvas() const;
    4243
    43     QwtPlot *plot();
    44     const QwtPlot *plot() const;
     44    QwtPlot* plot();
     45    const QwtPlot* plot() const;
    4546
    46 protected:
    47     virtual void rescale( double factor );
     47  public Q_SLOTS:
     48    virtual void rescale( double factor ) QWT_OVERRIDE;
    4849
    49 private:
     50  private:
    5051    class PrivateData;
    51     PrivateData *d_data;
     52    PrivateData* m_data;
    5253};
    5354
  • trunk/BNC/qwt/qwt_plot_marker.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_symbol.h"
    1414#include "qwt_text.h"
     15#include "qwt_graphic.h"
    1516#include "qwt_math.h"
     17
    1618#include <qpainter.h>
    1719
    1820class QwtPlotMarker::PrivateData
    1921{
    20 public:
    21     PrivateData():
    22         labelAlignment( Qt::AlignCenter ),
    23         labelOrientation( Qt::Horizontal ),
    24         spacing( 2 ),
    25         symbol( NULL ),
    26         style( QwtPlotMarker::NoLine ),
    27         xValue( 0.0 ),
    28         yValue( 0.0 )
     22  public:
     23    PrivateData()
     24        : labelAlignment( Qt::AlignCenter )
     25        , labelOrientation( Qt::Horizontal )
     26        , spacing( 2 )
     27        , symbol( NULL )
     28        , style( QwtPlotMarker::NoLine )
     29        , xValue( 0.0 )
     30        , yValue( 0.0 )
    2931    {
    3032    }
    … …  
    4143
    4244    QPen pen;
    43     const QwtSymbol *symbol;
     45    const QwtSymbol* symbol;
    4446    LineStyle style;
    4547
    … …  
    4951
    5052//! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine
    51 QwtPlotMarker::QwtPlotMarker( const QString &title ):
    52     QwtPlotItem( QwtText( title ) )
    53 {
    54     d_data = new PrivateData;
     53QwtPlotMarker::QwtPlotMarker()
     54{
     55    m_data = new PrivateData;
    5556    setZ( 30.0 );
    5657}
    5758
    5859//! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine
    59 QwtPlotMarker::QwtPlotMarker( const QwtText &title ):
    60     QwtPlotItem( title )
    61 {
    62     d_data = new PrivateData;
     60QwtPlotMarker::QwtPlotMarker( const QString& title )
     61    : QwtPlotItem( QwtText( title ) )
     62{
     63    m_data = new PrivateData;
     64    setZ( 30.0 );
     65}
     66
     67//! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine
     68QwtPlotMarker::QwtPlotMarker( const QwtText& title )
     69    : QwtPlotItem( title )
     70{
     71    m_data = new PrivateData;
    6372    setZ( 30.0 );
    6473}
    … …  
    6776QwtPlotMarker::~QwtPlotMarker()
    6877{
    69     delete d_data;
     78    delete m_data;
    7079}
    7180
    … …  
    7988QPointF QwtPlotMarker::value() const
    8089{
    81     return QPointF( d_data->xValue, d_data->yValue );
     90    return QPointF( m_data->xValue, m_data->yValue );
    8291}
    8392
    … …  
    8594double QwtPlotMarker::xValue() const
    8695{
    87     return d_data->xValue;
     96    return m_data->xValue;
    8897}
    8998
    … …  
    91100double QwtPlotMarker::yValue() const
    92101{
    93     return d_data->yValue;
     102    return m_data->yValue;
    94103}
    95104
    … …  
    103112void QwtPlotMarker::setValue( double x, double y )
    104113{
    105     if ( x != d_data->xValue || y != d_data->yValue )
    106     {
    107         d_data->xValue = x;
    108         d_data->yValue = y;
     114    if ( x != m_data->xValue || y != m_data->yValue )
     115    {
     116        m_data->xValue = x;
     117        m_data->yValue = y;
    109118        itemChanged();
    110119    }
    … …  
    114123void QwtPlotMarker::setXValue( double x )
    115124{
    116     setValue( x, d_data->yValue );
     125    setValue( x, m_data->yValue );
    117126}
    118127
    … …  
    120129void QwtPlotMarker::setYValue( double y )
    121130{
    122     setValue( d_data->xValue, y );
    123 }
    124 
    125 /*!
    126   Draw the marker
    127 
    128   \param painter Painter
    129   \param xMap x Scale Map
    130   \param yMap y Scale Map
    131   \param canvasRect Contents rectangle of the canvas in painter coordinates
    132 */
    133 void QwtPlotMarker::draw( QPainter *painter,
    134     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    135     const QRectF &canvasRect ) const
    136 {
    137     const QPointF pos( xMap.transform( d_data->xValue ),
    138         yMap.transform( d_data->yValue ) );
    139 
    140     // draw lines
     131    setValue( m_data->xValue, y );
     132}
     133
     134/*!
     135   Draw the marker
     136
     137   \param painter Painter
     138   \param xMap x Scale Map
     139   \param yMap y Scale Map
     140   \param canvasRect Contents rectangle of the canvas in painter coordinates
     141 */
     142void QwtPlotMarker::draw( QPainter* painter,
     143    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     144    const QRectF& canvasRect ) const
     145{
     146    const QPointF pos( xMap.transform( m_data->xValue ),
     147        yMap.transform( m_data->yValue ) );
    141148
    142149    drawLines( painter, canvasRect, pos );
    143 
    144     // draw symbol
    145     if ( d_data->symbol &&
    146         ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
    147     {
    148         const QSizeF sz = d_data->symbol->size();
    149 
    150         const QRectF clipRect = canvasRect.adjusted(
    151             -sz.width(), -sz.height(), sz.width(), sz.height() );
    152 
    153         if ( clipRect.contains( pos ) )
    154             d_data->symbol->drawSymbol( painter, pos );
    155     }
    156 
     150    drawSymbol( painter, canvasRect, pos );
    157151    drawLabel( painter, canvasRect, pos );
    158152}
    159153
    160154/*!
    161   Draw the lines marker
    162 
    163   \param painter Painter
    164   \param canvasRect Contents rectangle of the canvas in painter coordinates
    165   \param pos Position of the marker, translated into widget coordinates
    166 
    167   \sa drawLabel(), QwtSymbol::drawSymbol()
    168 */
    169 void QwtPlotMarker::drawLines( QPainter *painter,
    170     const QRectF &canvasRect, const QPointF &pos ) const
    171 {
    172     if ( d_data->style == NoLine )
     155   Draw the lines marker
     156
     157   \param painter Painter
     158   \param canvasRect Contents rectangle of the canvas in painter coordinates
     159   \param pos Position of the marker, translated into widget coordinates
     160
     161   \sa drawLabel(), drawSymbol()
     162 */
     163void QwtPlotMarker::drawLines( QPainter* painter,
     164    const QRectF& canvasRect, const QPointF& pos ) const
     165{
     166    if ( m_data->style == NoLine )
    173167        return;
    174168
    175169    const bool doAlign = QwtPainter::roundingAlignment( painter );
    176170
    177     painter->setPen( d_data->pen );
    178     if ( d_data->style == QwtPlotMarker::HLine ||
    179         d_data->style == QwtPlotMarker::Cross )
     171    painter->setPen( m_data->pen );
     172    if ( m_data->style == QwtPlotMarker::HLine ||
     173        m_data->style == QwtPlotMarker::Cross )
    180174    {
    181175        double y = pos.y();
    … …  
    186180            y, canvasRect.right() - 1.0, y );
    187181    }
    188     if ( d_data->style == QwtPlotMarker::VLine ||
    189         d_data->style == QwtPlotMarker::Cross )
     182    if ( m_data->style == QwtPlotMarker::VLine ||
     183        m_data->style == QwtPlotMarker::Cross )
    190184    {
    191185        double x = pos.x();
    … …  
    199193
    200194/*!
    201   Align and draw the text label of the marker
    202 
    203   \param painter Painter
    204   \param canvasRect Contents rectangle of the canvas in painter coordinates
    205   \param pos Position of the marker, translated into widget coordinates
    206 
    207   \sa drawLabel(), QwtSymbol::drawSymbol()
    208 */
    209 void QwtPlotMarker::drawLabel( QPainter *painter,
    210     const QRectF &canvasRect, const QPointF &pos ) const
    211 {
    212     if ( d_data->label.isEmpty() )
     195   Draw the symbol of the marker
     196
     197   \param painter Painter
     198   \param canvasRect Contents rectangle of the canvas in painter coordinates
     199   \param pos Position of the marker, translated into widget coordinates
     200
     201   \sa drawLabel(), QwtSymbol::drawSymbol()
     202 */
     203void QwtPlotMarker::drawSymbol( QPainter* painter,
     204    const QRectF& canvasRect, const QPointF& pos ) const
     205{
     206    if ( m_data->symbol == NULL )
    213207        return;
    214208
    215     Qt::Alignment align = d_data->labelAlignment;
     209    const QwtSymbol& symbol = *m_data->symbol;
     210
     211    if ( symbol.style() != QwtSymbol::NoSymbol )
     212    {
     213        const QSizeF sz = symbol.size();
     214
     215        const QRectF clipRect = canvasRect.adjusted(
     216            -sz.width(), -sz.height(), sz.width(), sz.height() );
     217
     218        if ( clipRect.contains( pos ) )
     219            symbol.drawSymbol( painter, pos );
     220    }
     221}
     222
     223/*!
     224   Align and draw the text label of the marker
     225
     226   \param painter Painter
     227   \param canvasRect Contents rectangle of the canvas in painter coordinates
     228   \param pos Position of the marker, translated into widget coordinates
     229
     230   \sa drawLabel(), drawSymbol()
     231 */
     232void QwtPlotMarker::drawLabel( QPainter* painter,
     233    const QRectF& canvasRect, const QPointF& pos ) const
     234{
     235    if ( m_data->label.isEmpty() )
     236        return;
     237
     238    Qt::Alignment align = m_data->labelAlignment;
    216239    QPointF alignPos = pos;
    217240
    218241    QSizeF symbolOff( 0, 0 );
    219242
    220     switch ( d_data->style )
     243    switch ( m_data->style )
    221244    {
    222245        case QwtPlotMarker::VLine:
    … …  
    225248            // the alignment flags are relative to the canvas
    226249
    227             if ( d_data->labelAlignment & Qt::AlignTop )
     250            if ( m_data->labelAlignment & Qt::AlignTop )
    228251            {
    229252                alignPos.setY( canvasRect.top() );
    … …  
    231254                align |= Qt::AlignBottom;
    232255            }
    233             else if ( d_data->labelAlignment & Qt::AlignBottom )
     256            else if ( m_data->labelAlignment & Qt::AlignBottom )
    234257            {
    235258                // In HLine-style the x-position is pointless and
    … …  
    248271        case QwtPlotMarker::HLine:
    249272        {
    250             if ( d_data->labelAlignment & Qt::AlignLeft )
     273            if ( m_data->labelAlignment & Qt::AlignLeft )
    251274            {
    252275                alignPos.setX( canvasRect.left() );
    … …  
    254277                align |= Qt::AlignRight;
    255278            }
    256             else if ( d_data->labelAlignment & Qt::AlignRight )
     279            else if ( m_data->labelAlignment & Qt::AlignRight )
    257280            {
    258281                alignPos.setX( canvasRect.right() - 1 );
    … …  
    268291        default:
    269292        {
    270             if ( d_data->symbol &&
    271                 ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
     293            if ( m_data->symbol &&
     294                ( m_data->symbol->style() != QwtSymbol::NoSymbol ) )
    272295            {
    273                 symbolOff = d_data->symbol->size() + QSizeF( 1, 1 );
     296                symbolOff = m_data->symbol->size() + QSizeF( 1, 1 );
    274297                symbolOff /= 2;
    275298            }
    … …  
    277300    }
    278301
    279     qreal pw2 = d_data->pen.widthF() / 2.0;
     302    qreal pw2 = m_data->pen.widthF() / 2.0;
    280303    if ( pw2 == 0.0 )
    281304        pw2 = 0.5;
    282305
    283     const int spacing = d_data->spacing;
    284 
    285     const qreal xOff = qMax( pw2, symbolOff.width() );
    286     const qreal yOff = qMax( pw2, symbolOff.height() );
    287 
    288     const QSizeF textSize = d_data->label.textSize( painter->font() );
     306    const int spacing = m_data->spacing;
     307
     308    const qreal xOff = qwtMaxF( pw2, symbolOff.width() );
     309    const qreal yOff = qwtMaxF( pw2, symbolOff.height() );
     310
     311    const QSizeF textSize = m_data->label.textSize( painter->font() );
    289312
    290313    if ( align & Qt::AlignLeft )
    291314    {
    292315        alignPos.rx() -= xOff + spacing;
    293         if ( d_data->labelOrientation == Qt::Vertical )
     316        if ( m_data->labelOrientation == Qt::Vertical )
    294317            alignPos.rx() -= textSize.height();
    295318        else
    … …  
    302325    else
    303326    {
    304         if ( d_data->labelOrientation == Qt::Vertical )
     327        if ( m_data->labelOrientation == Qt::Vertical )
    305328            alignPos.rx() -= textSize.height() / 2;
    306329        else
    … …  
    311334    {
    312335        alignPos.ry() -= yOff + spacing;
    313         if ( d_data->labelOrientation != Qt::Vertical )
     336        if ( m_data->labelOrientation != Qt::Vertical )
    314337            alignPos.ry() -= textSize.height();
    315338    }
    … …  
    317340    {
    318341        alignPos.ry() += yOff + spacing;
    319         if ( d_data->labelOrientation == Qt::Vertical )
     342        if ( m_data->labelOrientation == Qt::Vertical )
    320343            alignPos.ry() += textSize.width();
    321344    }
    322345    else
    323346    {
    324         if ( d_data->labelOrientation == Qt::Vertical )
     347        if ( m_data->labelOrientation == Qt::Vertical )
    325348            alignPos.ry() += textSize.width() / 2;
    326349        else
    … …  
    329352
    330353    painter->translate( alignPos.x(), alignPos.y() );
    331     if ( d_data->labelOrientation == Qt::Vertical )
     354    if ( m_data->labelOrientation == Qt::Vertical )
    332355        painter->rotate( -90.0 );
    333356
    334357    const QRectF textRect( 0, 0, textSize.width(), textSize.height() );
    335     d_data->label.draw( painter, textRect );
    336 }
    337 
    338 /*!
    339   \brief Set the line style
    340   \param style Line style.
    341   \sa lineStyle()
    342 */
     358    m_data->label.draw( painter, textRect );
     359}
     360
     361/*!
     362   \brief Set the line style
     363   \param style Line style.
     364   \sa lineStyle()
     365 */
    343366void QwtPlotMarker::setLineStyle( LineStyle style )
    344367{
    345     if ( style != d_data->style )
    346     {
    347         d_data->style = style;
     368    if ( style != m_data->style )
     369    {
     370        m_data->style = style;
    348371
    349372        legendChanged();
    … …  
    353376
    354377/*!
    355   \return the line style
    356   \sa setLineStyle()
    357 */
     378   \return the line style
     379   \sa setLineStyle()
     380 */
    358381QwtPlotMarker::LineStyle QwtPlotMarker::lineStyle() const
    359382{
    360     return d_data->style;
    361 }
    362 
    363 /*!
    364   \brief Assign a symbol
    365   \param symbol New symbol
    366   \sa symbol()
    367 */
    368 void QwtPlotMarker::setSymbol( const QwtSymbol *symbol )
    369 {
    370     if ( symbol != d_data->symbol )
    371     {
    372         delete d_data->symbol;
    373         d_data->symbol = symbol;
     383    return m_data->style;
     384}
     385
     386/*!
     387   \brief Assign a symbol
     388   \param symbol New symbol
     389   \sa symbol()
     390 */
     391void QwtPlotMarker::setSymbol( const QwtSymbol* symbol )
     392{
     393    if ( symbol != m_data->symbol )
     394    {
     395        delete m_data->symbol;
     396        m_data->symbol = symbol;
    374397
    375398        if ( symbol )
    … …  
    382405
    383406/*!
    384   \return the symbol
    385   \sa setSymbol(), QwtSymbol
    386 */
    387 const QwtSymbol *QwtPlotMarker::symbol() const
    388 {
    389     return d_data->symbol;
    390 }
    391 
    392 /*!
    393   \brief Set the label
    394   \param label Label text
    395   \sa label()
    396 */
     407   \return the symbol
     408   \sa setSymbol(), QwtSymbol
     409 */
     410const QwtSymbol* QwtPlotMarker::symbol() const
     411{
     412    return m_data->symbol;
     413}
     414
     415/*!
     416   \brief Set the label
     417   \param label Label text
     418   \sa label()
     419 */
    397420void QwtPlotMarker::setLabel( const QwtText& label )
    398421{
    399     if ( label != d_data->label )
    400     {
    401         d_data->label = label;
     422    if ( label != m_data->label )
     423    {
     424        m_data->label = label;
    402425        itemChanged();
    403426    }
    … …  
    405428
    406429/*!
    407   \return the label
    408   \sa setLabel()
    409 */
     430   \return the label
     431   \sa setLabel()
     432 */
    410433QwtText QwtPlotMarker::label() const
    411434{
    412     return d_data->label;
    413 }
    414 
    415 /*!
    416   \brief Set the alignment of the label
    417 
    418   In case of QwtPlotMarker::HLine the alignment is relative to the
    419   y position of the marker, but the horizontal flags correspond to the
    420   canvas rectangle. In case of QwtPlotMarker::VLine the alignment is
    421   relative to the x position of the marker, but the vertical flags
    422   correspond to the canvas rectangle.
    423 
    424   In all other styles the alignment is relative to the marker's position.
    425 
    426   \param align Alignment.
    427   \sa labelAlignment(), labelOrientation()
    428 */
     435    return m_data->label;
     436}
     437
     438/*!
     439   \brief Set the alignment of the label
     440
     441   In case of QwtPlotMarker::HLine the alignment is relative to the
     442   y position of the marker, but the horizontal flags correspond to the
     443   canvas rectangle. In case of QwtPlotMarker::VLine the alignment is
     444   relative to the x position of the marker, but the vertical flags
     445   correspond to the canvas rectangle.
     446
     447   In all other styles the alignment is relative to the marker's position.
     448
     449   \param align Alignment.
     450   \sa labelAlignment(), labelOrientation()
     451 */
    429452void QwtPlotMarker::setLabelAlignment( Qt::Alignment align )
    430453{
    431     if ( align != d_data->labelAlignment )
    432     {
    433         d_data->labelAlignment = align;
     454    if ( align != m_data->labelAlignment )
     455    {
     456        m_data->labelAlignment = align;
    434457        itemChanged();
    435458    }
    … …  
    437460
    438461/*!
    439   \return the label alignment
    440   \sa setLabelAlignment(), setLabelOrientation()
    441 */
     462   \return the label alignment
     463   \sa setLabelAlignment(), setLabelOrientation()
     464 */
    442465Qt::Alignment QwtPlotMarker::labelAlignment() const
    443466{
    444     return d_data->labelAlignment;
    445 }
    446 
    447 /*!
    448   \brief Set the orientation of the label
    449 
    450   When orientation is Qt::Vertical the label is rotated by 90.0 degrees
    451   ( from bottom to top ).
    452 
    453   \param orientation Orientation of the label
    454 
    455   \sa labelOrientation(), setLabelAlignment()
    456 */
     467    return m_data->labelAlignment;
     468}
     469
     470/*!
     471   \brief Set the orientation of the label
     472
     473   When orientation is Qt::Vertical the label is rotated by 90.0 degrees
     474   ( from bottom to top ).
     475
     476   \param orientation Orientation of the label
     477
     478   \sa labelOrientation(), setLabelAlignment()
     479 */
    457480void QwtPlotMarker::setLabelOrientation( Qt::Orientation orientation )
    458481{
    459     if ( orientation != d_data->labelOrientation )
    460     {
    461         d_data->labelOrientation = orientation;
     482    if ( orientation != m_data->labelOrientation )
     483    {
     484        m_data->labelOrientation = orientation;
    462485        itemChanged();
    463486    }
    … …  
    465488
    466489/*!
    467   \return the label orientation
    468   \sa setLabelOrientation(), labelAlignment()
    469 */
     490   \return the label orientation
     491   \sa setLabelOrientation(), labelAlignment()
     492 */
    470493Qt::Orientation QwtPlotMarker::labelOrientation() const
    471494{
    472     return d_data->labelOrientation;
    473 }
    474 
    475 /*!
    476   \brief Set the spacing
    477 
    478   When the label is not centered on the marker position, the spacing
    479   is the distance between the position and the label.
    480 
    481   \param spacing Spacing
    482   \sa spacing(), setLabelAlignment()
    483 */
     495    return m_data->labelOrientation;
     496}
     497
     498/*!
     499   \brief Set the spacing
     500
     501   When the label is not centered on the marker position, the spacing
     502   is the distance between the position and the label.
     503
     504   \param spacing Spacing
     505   \sa spacing(), setLabelAlignment()
     506 */
    484507void QwtPlotMarker::setSpacing( int spacing )
    485508{
    … …  
    487510        spacing = 0;
    488511
    489     if ( spacing == d_data->spacing )
     512    if ( spacing == m_data->spacing )
    490513        return;
    491514
    492     d_data->spacing = spacing;
     515    m_data->spacing = spacing;
    493516    itemChanged();
    494517}
    495518
    496519/*!
    497   \return the spacing
    498   \sa setSpacing()
    499 */
     520   \return the spacing
     521   \sa setSpacing()
     522 */
    500523int QwtPlotMarker::spacing() const
    501524{
    502     return d_data->spacing;
    503 }
    504 
    505 /*!
    506   Build and assign a line pen
    507 
    508   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    509   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    510   to hide this incompatibility.
    511 
    512   \param color Pen color
    513   \param width Pen width
    514   \param style Pen style
    515 
    516   \sa pen(), brush()
    517  */
    518 void QwtPlotMarker::setLinePen( const QColor &color, qreal width, Qt::PenStyle style )
     525    return m_data->spacing;
     526}
     527
     528/*!
     529   Build and assign a line pen
     530
     531   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     532   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     533   to hide this incompatibility.
     534
     535   \param color Pen color
     536   \param width Pen width
     537   \param style Pen style
     538
     539   \sa pen(), brush()
     540 */
     541void QwtPlotMarker::setLinePen( const QColor& color, qreal width, Qt::PenStyle style )
    519542{
    520543    setLinePen( QPen( color, width, style ) );
    … …  
    522545
    523546/*!
    524   Specify a pen for the line.
    525 
    526   \param pen New pen
    527   \sa linePen()
    528 */
    529 void QwtPlotMarker::setLinePen( const QPen &pen )
    530 {
    531     if ( pen != d_data->pen )
    532     {
    533         d_data->pen = pen;
     547   Specify a pen for the line.
     548
     549   \param pen New pen
     550   \sa linePen()
     551 */
     552void QwtPlotMarker::setLinePen( const QPen& pen )
     553{
     554    if ( pen != m_data->pen )
     555    {
     556        m_data->pen = pen;
    534557
    535558        legendChanged();
    … …  
    539562
    540563/*!
    541   \return the line pen
    542   \sa setLinePen()
    543 */
    544 const QPen &QwtPlotMarker::linePen() const
    545 {
    546     return d_data->pen;
     564   \return the line pen
     565   \sa setLinePen()
     566 */
     567const QPen& QwtPlotMarker::linePen() const
     568{
     569    return m_data->pen;
    547570}
    548571
    … …  
    551574    // width/height of -1 does not affect the autoscale calculation
    552575
    553     switch (d_data->style)
     576    switch (m_data->style)
    554577    {
    555578        case QwtPlotMarker::HLine:
    556             return QRectF( d_data->xValue, d_data->yValue, -1.0, 0.0 );
     579            return QRectF( m_data->xValue, m_data->yValue, -1.0, 0.0 );
    557580
    558581        case QwtPlotMarker::VLine:
    559             return QRectF( d_data->xValue, d_data->yValue, 0.0, -1.0 );
    560 
    561         default :
    562             return QRectF( d_data->xValue, d_data->yValue, 0.0, 0.0 );
     582            return QRectF( m_data->xValue, m_data->yValue, 0.0, -1.0 );
     583
     584        default:
     585            return QRectF( m_data->xValue, m_data->yValue, 0.0, 0.0 );
    563586    }
    564587}
    … …  
    572595
    573596   \sa setLegendIconSize(), legendData()
    574 */
    575 QwtGraphic QwtPlotMarker::legendIcon( int index,
    576     const QSizeF &size ) const
     597 */
     598QwtGraphic QwtPlotMarker::legendIcon( int index, const QSizeF& size ) const
    577599{
    578600    Q_UNUSED( index );
    … …  
    589611        testRenderHint( QwtPlotItem::RenderAntialiased ) );
    590612
    591     if ( d_data->style != QwtPlotMarker::NoLine )
    592     {
    593         painter.setPen( d_data->pen );
    594 
    595         if ( d_data->style == QwtPlotMarker::HLine ||
    596             d_data->style == QwtPlotMarker::Cross )
     613    if ( m_data->style != QwtPlotMarker::NoLine )
     614    {
     615        painter.setPen( m_data->pen );
     616
     617        if ( m_data->style == QwtPlotMarker::HLine ||
     618            m_data->style == QwtPlotMarker::Cross )
    597619        {
    598620            const double y = 0.5 * size.height();
    … …  
    602624        }
    603625
    604         if ( d_data->style == QwtPlotMarker::VLine ||
    605             d_data->style == QwtPlotMarker::Cross )
     626        if ( m_data->style == QwtPlotMarker::VLine ||
     627            m_data->style == QwtPlotMarker::Cross )
    606628        {
    607629            const double x = 0.5 * size.width();
    … …  
    612634    }
    613635
    614     if ( d_data->symbol )
     636    if ( m_data->symbol )
    615637    {
    616638        const QRect r( 0.0, 0.0, size.width(), size.height() );
    617         d_data->symbol->drawSymbol( &painter, r );
     639        m_data->symbol->drawSymbol( &painter, r );
    618640    }
    619641
  • trunk/BNC/qwt/qwt_plot_marker.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#define QWT_PLOT_MARKER_H
    1212
    13 #include <qpen.h>
    14 #include <qfont.h>
    15 #include <qstring.h>
    16 #include <qbrush.h>
    1713#include "qwt_global.h"
    1814#include "qwt_plot_item.h"
    1915
     16class QString;
    2017class QRectF;
    2118class QwtText;
    … …  
    2320
    2421/*!
    25   \brief A class for drawing markers
     22   \brief A class for drawing markers
    2623
    27   A marker can be a horizontal line, a vertical line,
    28   a symbol, a label or any combination of them, which can
    29   be drawn around a center point inside a bounding rectangle.
     24   A marker can be a horizontal line, a vertical line,
     25   a symbol, a label or any combination of them, which can
     26   be drawn around a center point inside a bounding rectangle.
    3027
    31   The setSymbol() member assigns a symbol to the marker.
    32   The symbol is drawn at the specified point.
     28   The setSymbol() member assigns a symbol to the marker.
     29   The symbol is drawn at the specified point.
    3330
    34   With setLabel(), a label can be assigned to the marker.
    35   The setLabelAlignment() member specifies where the label is
    36   drawn. All the Align*-constants in Qt::AlignmentFlags (see Qt documentation)
    37   are valid. The interpretation of the alignment depends on the marker's
    38   line style. The alignment refers to the center point of
    39   the marker, which means, for example, that the label would be printed
    40   left above the center point if the alignment was set to
    41   Qt::AlignLeft | Qt::AlignTop.
     31   With setLabel(), a label can be assigned to the marker.
     32   The setLabelAlignment() member specifies where the label is
     33   drawn. All the Align*-constants in Qt::AlignmentFlags (see Qt documentation)
     34   are valid. The interpretation of the alignment depends on the marker's
     35   line style. The alignment refers to the center point of
     36   the marker, which means, for example, that the label would be printed
     37   left above the center point if the alignment was set to
     38   Qt::AlignLeft | Qt::AlignTop.
    4239
    43   \note QwtPlotTextLabel is intended to align a text label
     40   \note QwtPlotTextLabel is intended to align a text label
    4441        according to the geometry of canvas
    4542        ( unrelated to plot coordinates )
    46 */
     43 */
    4744
    48 class QWT_EXPORT QwtPlotMarker: public QwtPlotItem
     45class QWT_EXPORT QwtPlotMarker : public QwtPlotItem
    4946{
    50 public:
     47  public:
    5148
    5249    /*!
    5350        Line styles.
    5451        \sa setLineStyle(), lineStyle()
    55     */
     52     */
    5653    enum LineStyle
    5754    {
    … …  
    6966    };
    7067
    71     explicit QwtPlotMarker( const QString &title = QString() );
    72     explicit QwtPlotMarker( const QwtText &title );
     68    explicit QwtPlotMarker();
     69    explicit QwtPlotMarker( const QString& title );
     70    explicit QwtPlotMarker( const QwtText& title );
    7371
    7472    virtual ~QwtPlotMarker();
    7573
    76     virtual int rtti() const;
     74    virtual int rtti() const QWT_OVERRIDE;
    7775
    7876    double xValue() const;
    … …  
    8381    void setYValue( double );
    8482    void setValue( double, double );
    85     void setValue( const QPointF & );
     83    void setValue( const QPointF& );
    8684
    8785    void setLineStyle( LineStyle );
    8886    LineStyle lineStyle() const;
    8987
    90     void setLinePen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    91     void setLinePen( const QPen & );
    92     const QPen &linePen() const;
     88    void setLinePen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
     89    void setLinePen( const QPen& );
     90    const QPen& linePen() const;
    9391
    94     void setSymbol( const QwtSymbol * );
    95     const QwtSymbol *symbol() const;
     92    void setSymbol( const QwtSymbol* );
     93    const QwtSymbol* symbol() const;
    9694
    9795    void setLabel( const QwtText& );
    … …  
    107105    int spacing() const;
    108106
    109     virtual void draw( QPainter *,
    110         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    111         const QRectF & ) const;
     107    virtual void draw( QPainter*,
     108        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     109        const QRectF& ) const QWT_OVERRIDE;
    112110
    113     virtual QRectF boundingRect() const;
     111    virtual QRectF boundingRect() const QWT_OVERRIDE;
    114112
    115     virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
     113    virtual QwtGraphic legendIcon(
     114        int index, const QSizeF& ) const QWT_OVERRIDE;
    116115
    117 protected:
    118     virtual void drawLines( QPainter *,
    119         const QRectF &, const QPointF & ) const;
     116  protected:
     117    virtual void drawLines( QPainter*,
     118        const QRectF&, const QPointF& ) const;
    120119
    121     virtual void drawLabel( QPainter *,
    122         const QRectF &, const QPointF & ) const;
     120    virtual void drawSymbol( QPainter*,
     121        const QRectF&, const QPointF& ) const;
    123122
    124 private:
     123    virtual void drawLabel( QPainter*,
     124        const QRectF&, const QPointF& ) const;
     125
     126  private:
    125127
    126128    class PrivateData;
    127     PrivateData *d_data;
     129    PrivateData* m_data;
    128130};
    129131
  • trunk/BNC/qwt/qwt_plot_multi_barchart.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_scale_map.h"
    1212#include "qwt_column_symbol.h"
    13 #include "qwt_painter.h"
    14 #include <qpainter.h>
    15 #include <qpalette.h>
     13#include "qwt_text.h"
     14#include "qwt_graphic.h"
     15#include "qwt_legend_data.h"
     16#include "qwt_math.h"
     17
    1618#include <qmap.h>
    1719
    1820inline static bool qwtIsIncreasing(
    19     const QwtScaleMap &map, const QVector<double> &values )
     21    const QwtScaleMap& map, const QVector< double >& values )
    2022{
    2123    bool isInverting = map.isInverting();
    … …  
    3335class QwtPlotMultiBarChart::PrivateData
    3436{
    35 public:
    36     PrivateData():
    37         style( QwtPlotMultiBarChart::Grouped )
     37  public:
     38    PrivateData()
     39        : style( QwtPlotMultiBarChart::Grouped )
    3840    {
    3941    }
    4042
    4143    QwtPlotMultiBarChart::ChartStyle style;
    42     QList<QwtText> barTitles;
    43     QMap<int, QwtColumnSymbol *> symbolMap;
     44    QList< QwtText > barTitles;
     45    QMap< int, QwtColumnSymbol* > symbolMap;
    4446};
    4547
    4648/*!
    47   Constructor
    48   \param title Title of the chart
    49 */
    50 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QwtText &title ):
    51     QwtPlotAbstractBarChart( title )
     49   Constructor
     50   \param title Title of the chart
     51 */
     52QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QwtText& title )
     53    : QwtPlotAbstractBarChart( title )
    5254{
    5355    init();
    … …  
    5557
    5658/*!
    57   Constructor
    58   \param title Title of the chart
    59 */
    60 QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QString &title ):
    61     QwtPlotAbstractBarChart( QwtText( title ) )
     59   Constructor
     60   \param title Title of the chart
     61 */
     62QwtPlotMultiBarChart::QwtPlotMultiBarChart( const QString& title )
     63    : QwtPlotAbstractBarChart( QwtText( title ) )
    6264{
    6365    init();
    … …  
    6870{
    6971    resetSymbolMap();
    70     delete d_data;
     72    delete m_data;
    7173}
    7274
    7375void QwtPlotMultiBarChart::init()
    7476{
    75     d_data = new PrivateData;
     77    m_data = new PrivateData;
    7678    setData( new QwtSetSeriesData() );
    7779}
    … …  
    8486
    8587/*!
    86   Initialize data with an array of samples.
    87   \param samples Vector of points
    88 */
     88   Initialize data with an array of samples.
     89   \param samples Vector of points
     90 */
    8991void QwtPlotMultiBarChart::setSamples(
    90     const QVector<QwtSetSample> &samples )
     92    const QVector< QwtSetSample >& samples )
    9193{
    9294    setData( new QwtSetSeriesData( samples ) );
    … …  
    9496
    9597/*!
    96   Initialize data with an array of samples.
    97   \param samples Vector of points
    98 */
     98   Initialize data with an array of samples.
     99   \param samples Vector of points
     100 */
    99101void QwtPlotMultiBarChart::setSamples(
    100     const QVector< QVector<double> > &samples )
    101 {
    102     QVector<QwtSetSample> s;
     102    const QVector< QVector< double > >& samples )
     103{
     104    QVector< QwtSetSample > s;
     105    s.reserve( samples.size() );
     106
    103107    for ( int i = 0; i < samples.size(); i++ )
    104108        s += QwtSetSample( i, samples[ i ] );
    … …  
    108112
    109113/*!
    110   Assign a series of samples
    111 
    112   setSamples() is just a wrapper for setData() without any additional
    113   value - beside that it is easier to find for the developer.
    114 
    115   \param data Data
    116   \warning The item takes ownership of the data object, deleting
     114   Assign a series of samples
     115
     116   setSamples() is just a wrapper for setData() without any additional
     117   value - beside that it is easier to find for the developer.
     118
     119   \param data Data
     120   \warning The item takes ownership of the data object, deleting
    117121           it when its not used anymore.
    118 */
     122 */
    119123void QwtPlotMultiBarChart::setSamples(
    120     QwtSeriesData<QwtSetSample> *data )
     124    QwtSeriesData< QwtSetSample >* data )
    121125{
    122126    setData( data );
    … …  
    124128
    125129/*!
    126   \brief Set the titles for the bars
    127 
    128   The titles are used for the legend.
    129 
    130   \param titles Bar titles
    131 
    132   \sa barTitles(), legendData()
    133  */
    134 void QwtPlotMultiBarChart::setBarTitles( const QList<QwtText> &titles )
    135 {
    136     d_data->barTitles = titles;
     130   \brief Set the titles for the bars
     131
     132   The titles are used for the legend.
     133
     134   \param titles Bar titles
     135
     136   \sa barTitles(), legendData()
     137 */
     138void QwtPlotMultiBarChart::setBarTitles( const QList< QwtText >& titles )
     139{
     140    m_data->barTitles = titles;
    137141    itemChanged();
    138142}
    139143
    140144/*!
    141   \return Bar titles
    142   \sa setBarTitles(), legendData()
    143  */
    144 QList<QwtText> QwtPlotMultiBarChart::barTitles() const
    145 {
    146     return d_data->barTitles;
    147 }
    148 
    149 /*!
    150   \brief Add a symbol to the symbol map
    151 
    152   Assign a default symbol for drawing the bar representing all values
    153   with the same index in a set.
    154 
    155   \param valueIndex Index of a value in a set
    156   \param symbol Symbol used for drawing a bar
    157 
    158   \sa symbol(), resetSymbolMap(), specialSymbol()
    159 */
    160 void QwtPlotMultiBarChart::setSymbol( int valueIndex, QwtColumnSymbol *symbol )
     145   \return Bar titles
     146   \sa setBarTitles(), legendData()
     147 */
     148QList< QwtText > QwtPlotMultiBarChart::barTitles() const
     149{
     150    return m_data->barTitles;
     151}
     152
     153/*!
     154   \brief Add a symbol to the symbol map
     155
     156   Assign a default symbol for drawing the bar representing all values
     157   with the same index in a set.
     158
     159   \param valueIndex Index of a value in a set
     160   \param symbol Symbol used for drawing a bar
     161
     162   \sa symbol(), resetSymbolMap(), specialSymbol()
     163 */
     164void QwtPlotMultiBarChart::setSymbol( int valueIndex, QwtColumnSymbol* symbol )
    161165{
    162166    if ( valueIndex < 0 )
    163167        return;
    164168
    165     QMap<int, QwtColumnSymbol *>::iterator it =
    166         d_data->symbolMap.find(valueIndex);
    167     if ( it == d_data->symbolMap.end() )
     169    QMap< int, QwtColumnSymbol* >::iterator it =
     170        m_data->symbolMap.find(valueIndex);
     171    if ( it == m_data->symbolMap.end() )
    168172    {
    169173        if ( symbol != NULL )
    170174        {
    171             d_data->symbolMap.insert( valueIndex, symbol );
     175            m_data->symbolMap.insert( valueIndex, symbol );
    172176
    173177            legendChanged();
    … …  
    183187            if ( symbol == NULL )
    184188            {
    185                 d_data->symbolMap.remove( valueIndex );
     189                m_data->symbolMap.remove( valueIndex );
    186190            }
    187191            else
    … …  
    197201
    198202/*!
    199   Find a symbol in the symbol map
    200 
    201   \param valueIndex Index of a value in a set
    202   \return The symbol, that had been set by setSymbol() or NULL.
    203 
    204   \sa setSymbol(), specialSymbol(), drawBar()
    205 */
    206 const QwtColumnSymbol *QwtPlotMultiBarChart::symbol( int valueIndex ) const
    207 {
    208     QMap<int, QwtColumnSymbol *>::const_iterator it =
    209         d_data->symbolMap.constFind( valueIndex );
    210 
    211     return ( it == d_data->symbolMap.constEnd() ) ? NULL : it.value();
    212 }
    213 
    214 /*!
    215   Find a symbol in the symbol map
    216 
    217   \param valueIndex Index of a value in a set
    218   \return The symbol, that had been set by setSymbol() or NULL.
    219 
    220   \sa setSymbol(), specialSymbol(), drawBar()
    221 */
    222 QwtColumnSymbol *QwtPlotMultiBarChart::symbol( int valueIndex )
    223 {
    224     QMap<int, QwtColumnSymbol *>::const_iterator it =
    225         d_data->symbolMap.constFind( valueIndex );
    226 
    227     return ( it == d_data->symbolMap.constEnd() ) ? NULL : it.value();
    228 }
    229 
    230 /*!
    231   Remove all symbols from the symbol map
     203   Find a symbol in the symbol map
     204
     205   \param valueIndex Index of a value in a set
     206   \return The symbol, that had been set by setSymbol() or NULL.
     207
     208   \sa setSymbol(), specialSymbol(), drawBar()
     209 */
     210const QwtColumnSymbol* QwtPlotMultiBarChart::symbol( int valueIndex ) const
     211{
     212    QMap< int, QwtColumnSymbol* >::const_iterator it =
     213        m_data->symbolMap.constFind( valueIndex );
     214
     215    return ( it == m_data->symbolMap.constEnd() ) ? NULL : it.value();
     216}
     217
     218/*!
     219   Find a symbol in the symbol map
     220
     221   \param valueIndex Index of a value in a set
     222   \return The symbol, that had been set by setSymbol() or NULL.
     223
     224   \sa setSymbol(), specialSymbol(), drawBar()
     225 */
     226QwtColumnSymbol* QwtPlotMultiBarChart::symbol( int valueIndex )
     227{
     228    QMap< int, QwtColumnSymbol* >::const_iterator it =
     229        m_data->symbolMap.constFind( valueIndex );
     230
     231    return ( it == m_data->symbolMap.constEnd() ) ? NULL : it.value();
     232}
     233
     234/*!
     235   Remove all symbols from the symbol map
    232236 */
    233237void QwtPlotMultiBarChart::resetSymbolMap()
    234238{
    235     qDeleteAll( d_data->symbolMap );
    236     d_data->symbolMap.clear();
    237 }
    238 
    239 /*!
    240   \brief Create a symbol for special values
    241 
    242   Usually the symbols for displaying a bar are set by setSymbols() and
    243   common for all sets. By overloading specialSymbol() it is possible to
    244   create a temporary symbol() for displaying a special value.
    245 
    246   The symbol has to be created by new each time specialSymbol() is
    247   called. As soon as the symbol is painted this symbol gets deleted.
    248 
    249   When no symbol ( NULL ) is returned, the value will be displayed
    250   with the standard symbol that is used for all symbols with the same
    251   valueIndex.
    252 
    253   \param sampleIndex Index of the sample
    254   \param valueIndex Index of the value in the set
    255 
    256   \return NULL, meaning that the value is not special
    257 
    258  */
    259 QwtColumnSymbol *QwtPlotMultiBarChart::specialSymbol(
     239    qDeleteAll( m_data->symbolMap );
     240    m_data->symbolMap.clear();
     241}
     242
     243/*!
     244   \brief Create a symbol for special values
     245
     246   Usually the symbols for displaying a bar are set by setSymbols() and
     247   common for all sets. By overloading specialSymbol() it is possible to
     248   create a temporary symbol() for displaying a special value.
     249
     250   The symbol has to be created by new each time specialSymbol() is
     251   called. As soon as the symbol is painted this symbol gets deleted.
     252
     253   When no symbol ( NULL ) is returned, the value will be displayed
     254   with the standard symbol that is used for all symbols with the same
     255   valueIndex.
     256
     257   \param sampleIndex Index of the sample
     258   \param valueIndex Index of the value in the set
     259
     260   \return NULL, meaning that the value is not special
     261
     262 */
     263QwtColumnSymbol* QwtPlotMultiBarChart::specialSymbol(
    260264    int sampleIndex, int valueIndex ) const
    261265{
    … …  
    267271
    268272/*!
    269   Set the style of the chart
    270 
    271   \param style Chart style
    272   \sa style()
     273   Set the style of the chart
     274
     275   \param style Chart style
     276   \sa style()
    273277 */
    274278void QwtPlotMultiBarChart::setStyle( ChartStyle style )
    275279{
    276     if ( style != d_data->style )
    277     {
    278         d_data->style = style;
     280    if ( style != m_data->style )
     281    {
     282        m_data->style = style;
    279283
    280284        legendChanged();
    … …  
    284288
    285289/*!
    286   \return Style of the chart
    287   \sa setStyle()
     290   \return Style of the chart
     291   \sa setStyle()
    288292 */
    289293QwtPlotMultiBarChart::ChartStyle QwtPlotMultiBarChart::style() const
    290294{
    291     return d_data->style;
    292 }
    293 
    294 /*!
    295   \return Bounding rectangle of all samples.
    296   For an empty series the rectangle is invalid.
    297 */
     295    return m_data->style;
     296}
     297
     298/*!
     299   \return Bounding rectangle of all samples.
     300   For an empty series the rectangle is invalid.
     301 */
    298302QRectF QwtPlotMultiBarChart::boundingRect() const
    299303{
    … …  
    307311    QRectF rect;
    308312
    309     if ( d_data->style != QwtPlotMultiBarChart::Stacked )
     313    if ( m_data->style != QwtPlotMultiBarChart::Stacked )
    310314    {
    311315        rect = QwtPlotSeriesItem::boundingRect();
    … …  
    326330        yMin = yMax = baseLine;
    327331
    328         const QwtSeriesData<QwtSetSample> *series = data();
     332        const QwtSeriesData< QwtSetSample >* series = data();
    329333
    330334        for ( size_t i = 0; i < numSamples; i++ )
    … …  
    337341            else
    338342            {
    339                 xMin = qMin( xMin, sample.value );
    340                 xMax = qMax( xMax, sample.value );
     343                xMin = qwtMinF( xMin, sample.value );
     344                xMax = qwtMaxF( xMax, sample.value );
    341345            }
    342346
    343347            const double y = baseLine + sample.added();
    344348
    345             yMin = qMin( yMin, y );
    346             yMax = qMax( yMax, y );
     349            yMin = qwtMinF( yMin, y );
     350            yMax = qwtMaxF( yMax, y );
    347351        }
    348352        rect.setRect( xMin, yMin, xMax - xMin, yMax - yMin );
    … …  
    356360
    357361/*!
    358   Draw an interval of the bar chart
    359 
    360   \param painter Painter
    361   \param xMap Maps x-values into pixel coordinates.
    362   \param yMap Maps y-values into pixel coordinates.
    363   \param canvasRect Contents rectangle of the canvas
    364   \param from Index of the first point to be painted
    365   \param to Index of the last point to be painted. If to < 0 the
     362   Draw an interval of the bar chart
     363
     364   \param painter Painter
     365   \param xMap Maps x-values into pixel coordinates.
     366   \param yMap Maps y-values into pixel coordinates.
     367   \param canvasRect Contents rectangle of the canvas
     368   \param from Index of the first point to be painted
     369   \param to Index of the last point to be painted. If to < 0 the
    366370         curve will be painted to its last point.
    367371
    368   \sa drawSymbols()
    369 */
    370 void QwtPlotMultiBarChart::drawSeries( QPainter *painter,
    371     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    372     const QRectF &canvasRect, int from, int to ) const
     372   \sa drawSymbols()
     373 */
     374void QwtPlotMultiBarChart::drawSeries( QPainter* painter,
     375    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     376    const QRectF& canvasRect, int from, int to ) const
    373377{
    374378    if ( to < 0 )
    … …  
    397401
    398402/*!
    399   Draw a sample
    400 
    401   \param painter Painter
    402   \param xMap x map
    403   \param yMap y map
    404   \param canvasRect Contents rectangle of the canvas
    405   \param boundingInterval Bounding interval of sample values
    406   \param index Index of the sample to be painted
    407   \param sample Sample value
    408 
    409   \sa drawSeries()
    410 */
    411 void QwtPlotMultiBarChart::drawSample( QPainter *painter,
    412     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    413     const QRectF &canvasRect, const QwtInterval &boundingInterval,
     403   Draw a sample
     404
     405   \param painter Painter
     406   \param xMap x map
     407   \param yMap y map
     408   \param canvasRect Contents rectangle of the canvas
     409   \param boundingInterval Bounding interval of sample values
     410   \param index Index of the sample to be painted
     411   \param sample Sample value
     412
     413   \sa drawSeries()
     414 */
     415void QwtPlotMultiBarChart::drawSample( QPainter* painter,
     416    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     417    const QRectF& canvasRect, const QwtInterval& boundingInterval,
    414418    int index, const QwtSetSample& sample ) const
    415419{
    … …  
    430434    }
    431435
    432     if ( d_data->style == Stacked )
     436    if ( m_data->style == Stacked )
    433437    {
    434438        drawStackedBars( painter, xMap, yMap,
    … …  
    443447
    444448/*!
    445   Draw a grouped sample
    446 
    447   \param painter Painter
    448   \param xMap x map
    449   \param yMap y map
    450   \param canvasRect Contents rectangle of the canvas
    451   \param index Index of the sample to be painted
    452   \param sampleWidth Boundng width for all bars of the smaple
    453   \param sample Sample
    454 
    455   \sa drawSeries(), sampleWidth()
    456 */
    457 void QwtPlotMultiBarChart::drawGroupedBars( QPainter *painter,
    458     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    459     const QRectF &canvasRect, int index, double sampleWidth,
     449   Draw a grouped sample
     450
     451   \param painter Painter
     452   \param xMap x map
     453   \param yMap y map
     454   \param canvasRect Contents rectangle of the canvas
     455   \param index Index of the sample to be painted
     456   \param sampleWidth Bounding width for all bars of the sample
     457   \param sample Sample
     458
     459   \sa drawSeries(), sampleWidth()
     460 */
     461void QwtPlotMultiBarChart::drawGroupedBars( QPainter* painter,
     462    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     463    const QRectF& canvasRect, int index, double sampleWidth,
    460464    const QwtSetSample& sample ) const
    461465{
    … …  
    523527
    524528/*!
    525   Draw a stacked sample
    526 
    527   \param painter Painter
    528   \param xMap x map
    529   \param yMap y map
    530   \param canvasRect Contents rectangle of the canvas
    531   \param index Index of the sample to be painted
    532   \param sampleWidth Width of the bars
    533   \param sample Sample
    534 
    535   \sa drawSeries(), sampleWidth()
    536 */
    537 void QwtPlotMultiBarChart::drawStackedBars( QPainter *painter,
    538     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    539     const QRectF &canvasRect, int index,
     529   Draw a stacked sample
     530
     531   \param painter Painter
     532   \param xMap x map
     533   \param yMap y map
     534   \param canvasRect Contents rectangle of the canvas
     535   \param index Index of the sample to be painted
     536   \param sampleWidth Width of the bars
     537   \param sample Sample
     538
     539   \sa drawSeries(), sampleWidth()
     540 */
     541void QwtPlotMultiBarChart::drawStackedBars( QPainter* painter,
     542    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     543    const QRectF& canvasRect, int index,
    540544    double sampleWidth, const QwtSetSample& sample ) const
    541545{
    … …  
    636640
    637641/*!
    638   Draw a bar
    639 
    640   \param painter Painter
    641   \param sampleIndex Index of the sample - might be -1 when the
     642   Draw a bar
     643
     644   \param painter Painter
     645   \param sampleIndex Index of the sample - might be -1 when the
    642646                     bar is painted for the legend
    643   \param valueIndex Index of a value in a set
    644   \param rect Directed target rectangle for the bar
    645 
    646   \sa drawSeries()
    647 */
    648 void QwtPlotMultiBarChart::drawBar( QPainter *painter,
    649     int sampleIndex, int valueIndex, const QwtColumnRect &rect ) const
    650 {
    651     const QwtColumnSymbol *specialSym = NULL;
     647   \param valueIndex Index of a value in a set
     648   \param rect Directed target rectangle for the bar
     649
     650   \sa drawSeries()
     651 */
     652void QwtPlotMultiBarChart::drawBar( QPainter* painter,
     653    int sampleIndex, int valueIndex, const QwtColumnRect& rect ) const
     654{
     655    const QwtColumnSymbol* specialSym = NULL;
    652656    if ( sampleIndex >= 0 )
    653657        specialSym = specialSymbol( sampleIndex, valueIndex );
    654658
    655     const QwtColumnSymbol *sym = specialSym;
     659    const QwtColumnSymbol* sym = specialSym;
    656660    if ( sym == NULL )
    657661        sym = symbol( valueIndex );
    … …  
    674678
    675679/*!
    676   \return Information to be displayed on the legend
    677 
    678   The chart is represented by a list of entries - one for each bar title.
    679   Each element contains a bar title and an icon showing its corresponding bar.
    680 
    681   \sa barTitles(), legendIcon(), legendIconSize()
    682 */
    683 QList<QwtLegendData> QwtPlotMultiBarChart::legendData() const
    684 {
    685     QList<QwtLegendData> list;
    686 
    687     for ( int i = 0; i < d_data->barTitles.size(); i++ )
     680   \return Information to be displayed on the legend
     681
     682   The chart is represented by a list of entries - one for each bar title.
     683   Each element contains a bar title and an icon showing its corresponding bar.
     684
     685   \sa barTitles(), legendIcon(), legendIconSize()
     686 */
     687QList< QwtLegendData > QwtPlotMultiBarChart::legendData() const
     688{
     689    QList< QwtLegendData > list;
     690    list.reserve( m_data->barTitles.size() );
     691
     692    for ( int i = 0; i < m_data->barTitles.size(); i++ )
    688693    {
    689694        QwtLegendData data;
    690695
    691         QVariant titleValue;
    692         qVariantSetValue( titleValue, d_data->barTitles[i] );
    693         data.setValue( QwtLegendData::TitleRole, titleValue );
     696        data.setValue( QwtLegendData::TitleRole,
     697            QVariant::fromValue( m_data->barTitles[i] ) );
    694698
    695699        if ( !legendIconSize().isEmpty() )
    696700        {
    697             QVariant iconValue;
    698             qVariantSetValue( iconValue,
    699                 legendIcon( i, legendIconSize() ) );
    700 
    701             data.setValue( QwtLegendData::IconRole, iconValue );
     701            data.setValue( QwtLegendData::IconRole,
     702                QVariant::fromValue( legendIcon( i, legendIconSize() ) ) );
    702703        }
    703704
    … …  
    709710
    710711/*!
    711   \return Icon for representing a bar on the legend
    712 
    713   \param index Index of the bar
    714   \param size Icon size
    715 
    716   \return An icon showing a bar
    717   \sa drawBar(), legendData()
     712   \return Icon for representing a bar on the legend
     713
     714   \param index Index of the bar
     715   \param size Icon size
     716
     717   \return An icon showing a bar
     718   \sa drawBar(), legendData()
    718719 */
    719720QwtGraphic QwtPlotMultiBarChart::legendIcon( int index,
    720     const QSizeF &size ) const
     721    const QSizeF& size ) const
    721722{
    722723    QwtColumnRect column;
  • trunk/BNC/qwt/qwt_plot_multi_barchart.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_abstract_barchart.h"
    15 #include "qwt_series_data.h"
    1615
    1716class QwtColumnRect;
    1817class QwtColumnSymbol;
     18template< typename T > class QwtSeriesData;
    1919
    2020/*!
    21   \brief QwtPlotMultiBarChart displays a series of a samples that consist
     21   \brief QwtPlotMultiBarChart displays a series of a samples that consist
    2222         each of a set of values.
    2323
    24   Each value is displayed as a bar, the bars of each set can be organized
    25   side by side or accumulated.
     24   Each value is displayed as a bar, the bars of each set can be organized
     25   side by side or accumulated.
    2626
    27   Each bar of a set is rendered by a QwtColumnSymbol, that is set by setSymbol().
    28   The bars of different sets use the same symbols. Exceptions are possible
    29   by overloading specialSymbol() or overloading drawBar().
     27   Each bar of a set is rendered by a QwtColumnSymbol, that is set by setSymbol().
     28   The bars of different sets use the same symbols. Exceptions are possible
     29   by overloading specialSymbol() or overloading drawBar().
    3030
    31   Depending on its orientation() the bars are displayed horizontally
    32   or vertically. The bars cover the interval between the baseline()
    33   and the value.
     31   Depending on its orientation() the bars are displayed horizontally
     32   or vertically. The bars cover the interval between the baseline()
     33   and the value.
    3434
    35   In opposite to most other plot items, QwtPlotMultiBarChart returns more
    36   than one entry for the legend - one for each symbol.
     35   In opposite to most other plot items, QwtPlotMultiBarChart returns more
     36   than one entry for the legend - one for each symbol.
    3737
    38   \sa QwtPlotBarChart, QwtPlotHistogram
     38   \sa QwtPlotBarChart, QwtPlotHistogram
    3939      QwtPlotSeriesItem::orientation(), QwtPlotAbstractBarChart::baseline()
    4040 */
    41 class QWT_EXPORT QwtPlotMultiBarChart:
    42     public QwtPlotAbstractBarChart, public QwtSeriesStore<QwtSetSample>
     41class QWT_EXPORT QwtPlotMultiBarChart
     42    : public QwtPlotAbstractBarChart
     43    , public QwtSeriesStore< QwtSetSample >
    4344{
    44 public:
     45  public:
    4546    /*!
    4647        \brief Chart styles.
    … …  
    4849        The default setting is QwtPlotMultiBarChart::Grouped.
    4950        \sa setStyle(), style()
    50     */
     51     */
    5152    enum ChartStyle
    5253    {
    … …  
    6263    };
    6364
    64     explicit QwtPlotMultiBarChart( const QString &title = QString() );
    65     explicit QwtPlotMultiBarChart( const QwtText &title );
     65    explicit QwtPlotMultiBarChart( const QString& title = QString() );
     66    explicit QwtPlotMultiBarChart( const QwtText& title );
    6667
    6768    virtual ~QwtPlotMultiBarChart();
    6869
    69     virtual int rtti() const;
     70    virtual int rtti() const QWT_OVERRIDE;
    7071
    71     void setBarTitles( const QList<QwtText> & );
    72     QList<QwtText> barTitles() const;
     72    void setBarTitles( const QList< QwtText >& );
     73    QList< QwtText > barTitles() const;
    7374
    74     void setSamples( const QVector<QwtSetSample> & );
    75     void setSamples( const QVector< QVector<double> > & );
    76     void setSamples( QwtSeriesData<QwtSetSample> * );
     75    void setSamples( const QVector< QwtSetSample >& );
     76    void setSamples( const QVector< QVector< double > >& );
     77    void setSamples( QwtSeriesData< QwtSetSample >* );
    7778
    7879    void setStyle( ChartStyle style );
    7980    ChartStyle style() const;
    8081
    81     void setSymbol( int valueIndex, QwtColumnSymbol * );
    82     const QwtColumnSymbol *symbol( int valueIndex ) const;
     82    void setSymbol( int valueIndex, QwtColumnSymbol* );
     83    const QwtColumnSymbol* symbol( int valueIndex ) const;
    8384
    8485    void resetSymbolMap();
    8586
    86     virtual void drawSeries( QPainter *painter,
    87         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    88         const QRectF &canvasRect, int from, int to ) const;
     87    virtual void drawSeries( QPainter*,
     88        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     89        const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE;
    8990
    90     virtual QRectF boundingRect() const;
     91    virtual QRectF boundingRect() const QWT_OVERRIDE;
    9192
    92     virtual QList<QwtLegendData> legendData() const;
     93    virtual QList< QwtLegendData > legendData() const QWT_OVERRIDE;
    9394
    94     virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
     95    virtual QwtGraphic legendIcon(
     96        int index, const QSizeF& ) const QWT_OVERRIDE;
    9597
    96 protected:
    97     QwtColumnSymbol *symbol( int valueIndex );
     98  protected:
     99    QwtColumnSymbol* symbol( int valueIndex );
    98100
    99     virtual QwtColumnSymbol *specialSymbol(
     101    virtual QwtColumnSymbol* specialSymbol(
    100102        int sampleIndex, int valueIndex ) const;
    101103
    102     virtual void drawSample( QPainter *painter,
    103         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    104         const QRectF &canvasRect, const QwtInterval &boundingInterval,
    105         int index, const QwtSetSample& sample ) const;
     104    virtual void drawSample( QPainter*,
     105        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     106        const QRectF& canvasRect, const QwtInterval& boundingInterval,
     107        int index, const QwtSetSample& ) const;
    106108
    107     virtual void drawBar( QPainter *, int sampleIndex,
    108         int valueIndex, const QwtColumnRect & ) const;
     109    virtual void drawBar( QPainter*, int sampleIndex,
     110        int valueIndex, const QwtColumnRect& ) const;
    109111
    110     void drawStackedBars( QPainter *painter,
    111         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    112         const QRectF &canvasRect, int index,
    113         double sampleWidth, const QwtSetSample& sample ) const;
     112    void drawStackedBars( QPainter*,
     113        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     114        const QRectF& canvasRect, int index,
     115        double sampleWidth, const QwtSetSample& ) const;
    114116
    115     void drawGroupedBars( QPainter *painter,
    116         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    117         const QRectF &canvasRect, int index,
    118         double sampleWidth, const QwtSetSample& sample ) const;
     117    void drawGroupedBars( QPainter*,
     118        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     119        const QRectF& canvasRect, int index,
     120        double sampleWidth, const QwtSetSample& ) const;
    119121
    120 private:
     122  private:
    121123    void init();
    122124
    123125    class PrivateData;
    124     PrivateData *d_data;
     126    PrivateData* m_data;
    125127};
    126128
  • trunk/BNC/qwt/qwt_plot_panner.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_scale_div.h"
    1212#include "qwt_plot.h"
     13#include "qwt_scale_map.h"
    1314#include "qwt_painter.h"
     15
    1416#include <qbitmap.h>
    1517#include <qstyle.h>
    1618#include <qstyleoption.h>
     19#include <qpainter.h>
    1720#include <qpainterpath.h>
    1821
     22static QBitmap qwtBorderMask( const QWidget* canvas, const QSize& size )
     23{
    1924#if QT_VERSION >= 0x050000
    20 #if QT_VERSION < 0x050100
    21 #define QWT_USE_WINDOW_HANDLE 1
     25    const qreal pixelRatio = QwtPainter::devicePixelRatio( canvas );
    2226#endif
    23 #endif
    24 
    25 #ifdef QWT_USE_WINDOW_HANDLE
    26 #include <qwindow.h>
    27 #endif
    28 
    29 static QBitmap qwtBorderMask( const QWidget *canvas, const QSize &size )
    30 {
    31 #if QT_VERSION >= 0x050000
    32     qreal pixelRatio = 1.0;
    33 
    34 #ifdef QWT_USE_WINDOW_HANDLE
    35     pixelRatio = canvas->windowHandle()->devicePixelRatio();
    36 #else
    37     pixelRatio = canvas->devicePixelRatio();
    38 #endif
    39 #endif
    4027
    4128    const QRect r( 0, 0, size.width(), size.height() );
    … …  
    4431
    4532    ( void )QMetaObject::invokeMethod(
    46         const_cast< QWidget *>( canvas ), "borderPath", Qt::DirectConnection,
     33        const_cast< QWidget* >( canvas ), "borderPath", Qt::DirectConnection,
    4734        Q_RETURN_ARG( QPainterPath, borderPath ), Q_ARG( QRect, r ) );
    4835
    … …  
    5340
    5441#if QT_VERSION >= 0x050000
    55         QBitmap mask( size * pixelRatio );
     42        QBitmap mask( size* pixelRatio );
    5643        mask.setDevicePixelRatio( pixelRatio );
    5744#else
    … …  
    6754
    6855#if QT_VERSION >= 0x050000
    69     QImage image( size * pixelRatio, QImage::Format_ARGB32_Premultiplied );
     56    QImage image( size* pixelRatio, QImage::Format_ARGB32_Premultiplied );
    7057    image.setDevicePixelRatio( pixelRatio );
    7158#else
    … …  
    9481        const QVariant frameWidth = canvas->property( "frameWidth" );
    9582
    96         if ( borderRadius.type() == QVariant::Double
    97             && frameWidth.type() == QVariant::Int )
     83        if ( borderRadius.canConvert< double >() && frameWidth.canConvert< int >() )
    9884        {
    99             const double br = borderRadius.toDouble();
    100             const int fw = frameWidth.toInt();
     85            const double br = borderRadius.value< double >();
     86            const int fw = frameWidth.value< int >();
    10187
    10288            if ( br > 0.0 && fw > 0 )
    … …  
    121107class QwtPlotPanner::PrivateData
    122108{
    123 public:
     109  public:
    124110    PrivateData()
    125111    {
    126         for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
     112        for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
    127113            isAxisEnabled[axis] = true;
    128114    }
    129115
    130     bool isAxisEnabled[QwtPlot::axisCnt];
     116    bool isAxisEnabled[QwtAxis::AxisPositions];
    131117};
    132118
    133119/*!
    134   \brief A panner for the canvas of a QwtPlot
    135 
    136   The panner is enabled for all axes
    137 
    138   \param canvas Plot canvas to pan, also the parent object
    139 
    140   \sa setAxisEnabled()
    141 */
    142 QwtPlotPanner::QwtPlotPanner( QWidget *canvas ):
    143     QwtPanner( canvas )
    144 {
    145     d_data = new PrivateData();
     120   \brief A panner for the canvas of a QwtPlot
     121
     122   The panner is enabled for all axes
     123
     124   \param canvas Plot canvas to pan, also the parent object
     125
     126   \sa setAxisEnabled()
     127 */
     128QwtPlotPanner::QwtPlotPanner( QWidget* canvas )
     129    : QwtPanner( canvas )
     130{
     131    m_data = new PrivateData();
    146132
    147133    connect( this, SIGNAL(panned(int,int)),
    … …  
    152138QwtPlotPanner::~QwtPlotPanner()
    153139{
    154     delete d_data;
     140    delete m_data;
    155141}
    156142
    … …  
    161147   result of panning. All other axes will remain unchanged.
    162148
    163    \param axis Axis, see QwtPlot::Axis
     149   \param axisId Axis id
    164150   \param on On/Off
    165151
    166152   \sa isAxisEnabled(), moveCanvas()
    167 */
    168 void QwtPlotPanner::setAxisEnabled( int axis, bool on )
    169 {
    170     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    171         d_data->isAxisEnabled[axis] = on;
     153 */
     154void QwtPlotPanner::setAxisEnabled( QwtAxisId axisId, bool on )
     155{
     156    if ( QwtAxis::isValid( axisId ) )
     157        m_data->isAxisEnabled[axisId] = on;
    172158}
    173159
    … …  
    175161   Test if an axis is enabled
    176162
    177    \param axis Axis, see QwtPlot::Axis
     163   \param axisId Axis
    178164   \return True, if the axis is enabled
    179165
    180166   \sa setAxisEnabled(), moveCanvas()
    181 */
    182 bool QwtPlotPanner::isAxisEnabled( int axis ) const
    183 {
    184     if ( axis >= 0 && axis < QwtPlot::axisCnt )
    185         return d_data->isAxisEnabled[axis];
     167 */
     168bool QwtPlotPanner::isAxisEnabled( QwtAxisId axisId ) const
     169{
     170    if ( QwtAxis::isValid( axisId ) )
     171        return m_data->isAxisEnabled[axisId];
    186172
    187173    return true;
    … …  
    189175
    190176//! Return observed plot canvas
    191 QWidget *QwtPlotPanner::canvas()
     177QWidget* QwtPlotPanner::canvas()
    192178{
    193179    return parentWidget();
    … …  
    195181
    196182//! Return Observed plot canvas
    197 const QWidget *QwtPlotPanner::canvas() const
     183const QWidget* QwtPlotPanner::canvas() const
    198184{
    199185    return parentWidget();
    … …  
    201187
    202188//! Return plot widget, containing the observed plot canvas
    203 QwtPlot *QwtPlotPanner::plot()
    204 {
    205     QWidget *w = canvas();
     189QwtPlot* QwtPlotPanner::plot()
     190{
     191    QWidget* w = canvas();
    206192    if ( w )
    207193        w = w->parentWidget();
    208194
    209     return qobject_cast<QwtPlot *>( w );
     195    return qobject_cast< QwtPlot* >( w );
    210196}
    211197
    212198//! Return plot widget, containing the observed plot canvas
    213 const QwtPlot *QwtPlotPanner::plot() const
    214 {
    215     const QWidget *w = canvas();
     199const QwtPlot* QwtPlotPanner::plot() const
     200{
     201    const QWidget* w = canvas();
    216202    if ( w )
    217203        w = w->parentWidget();
    218204
    219     return qobject_cast<const QwtPlot *>( w );
     205    return qobject_cast< const QwtPlot* >( w );
    220206}
    221207
    … …  
    227213
    228214   \sa QwtPanner::panned()
    229 */
     215 */
    230216void QwtPlotPanner::moveCanvas( int dx, int dy )
    231217{
    … …  
    233219        return;
    234220
    235     QwtPlot *plot = this->plot();
     221    QwtPlot* plot = this->plot();
    236222    if ( plot == NULL )
    237223        return;
    … …  
    240226    plot->setAutoReplot( false );
    241227
    242     for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
    243     {
    244         if ( !d_data->isAxisEnabled[axis] )
    245             continue;
    246 
    247         const QwtScaleMap map = plot->canvasMap( axis );
    248 
    249         const double p1 = map.transform( plot->axisScaleDiv( axis ).lowerBound() );
    250         const double p2 = map.transform( plot->axisScaleDiv( axis ).upperBound() );
    251 
    252         double d1, d2;
    253         if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
     228    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     229    {
    254230        {
    255             d1 = map.invTransform( p1 - dx );
    256             d2 = map.invTransform( p2 - dx );
     231            const QwtAxisId axisId( axisPos );
     232
     233            if ( !m_data->isAxisEnabled[axisId] )
     234                continue;
     235
     236            const QwtScaleMap map = plot->canvasMap( axisId );
     237
     238            const double p1 = map.transform( plot->axisScaleDiv( axisId ).lowerBound() );
     239            const double p2 = map.transform( plot->axisScaleDiv( axisId ).upperBound() );
     240
     241            double d1, d2;
     242            if ( QwtAxis::isXAxis( axisPos ) )
     243            {
     244                d1 = map.invTransform( p1 - dx );
     245                d2 = map.invTransform( p2 - dx );
     246            }
     247            else
     248            {
     249                d1 = map.invTransform( p1 - dy );
     250                d2 = map.invTransform( p2 - dy );
     251            }
     252
     253            plot->setAxisScale( axisId, d1, d2 );
    257254        }
    258         else
    259         {
    260             d1 = map.invTransform( p1 - dy );
    261             d2 = map.invTransform( p2 - dy );
    262         }
    263 
    264         plot->setAxisScale( axis, d1, d2 );
    265255    }
    266256
    … …  
    274264   \return Mask as bitmap
    275265   \sa QwtPlotCanvas::borderPath()
    276 */
     266 */
    277267QBitmap QwtPlotPanner::contentsMask() const
    278268{
    … …  
    288278QPixmap QwtPlotPanner::grab() const
    289279{
    290     const QWidget *cv = canvas();
     280    const QWidget* cv = canvas();
    291281    if ( cv && cv->inherits( "QGLWidget" ) )
    292282    {
    … …  
    297287
    298288        QPainter painter( &pm );
    299         const_cast<QwtPlot *>( plot() )->drawCanvas( &painter );
     289        const_cast< QwtPlot* >( plot() )->drawCanvas( &painter );
    300290
    301291        return pm;
    … …  
    305295}
    306296
     297#include "moc_qwt_plot_panner.cpp"
  • trunk/BNC/qwt/qwt_plot_panner.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_PLOT_PANNER_H
    11 #define QWT_PLOT_PANNER_H 1
     11#define QWT_PLOT_PANNER_H
    1212
    1313#include "qwt_global.h"
    1414#include "qwt_panner.h"
     15#include "qwt_axis_id.h"
    1516
    1617class QwtPlot;
    1718
    1819/*!
    19   \brief QwtPlotPanner provides panning of a plot canvas
     20   \brief QwtPlotPanner provides panning of a plot canvas
    2021
    21   QwtPlotPanner is a panner for a plot canvas, that
    22   adjusts the scales of the axes after dropping
    23   the canvas on its new position.
     22   QwtPlotPanner is a panner for a plot canvas, that
     23   adjusts the scales of the axes after dropping
     24   the canvas on its new position.
    2425
    25   Together with QwtPlotZoomer and QwtPlotMagnifier powerful ways
    26   of navigating on a QwtPlot widget can be implemented easily.
     26   Together with QwtPlotZoomer and QwtPlotMagnifier powerful ways
     27   of navigating on a QwtPlot widget can be implemented easily.
    2728
    28   \note The axes are not updated, while dragging the canvas
    29   \sa QwtPlotZoomer, QwtPlotMagnifier
    30 */
    31 class QWT_EXPORT QwtPlotPanner: public QwtPanner
     29   \note The axes are not updated, while dragging the canvas
     30   \sa QwtPlotZoomer, QwtPlotMagnifier
     31 */
     32class QWT_EXPORT QwtPlotPanner : public QwtPanner
    3233{
    3334    Q_OBJECT
    3435
    35 public:
    36     explicit QwtPlotPanner( QWidget * );
     36  public:
     37    explicit QwtPlotPanner( QWidget* );
    3738    virtual ~QwtPlotPanner();
    3839
    39     QWidget *canvas();
    40     const QWidget *canvas() const;
     40    QWidget* canvas();
     41    const QWidget* canvas() const;
    4142
    42     QwtPlot *plot();
    43     const QwtPlot *plot() const;
     43    QwtPlot* plot();
     44    const QwtPlot* plot() const;
    4445
    45     void setAxisEnabled( int axis, bool on );
    46     bool isAxisEnabled( int axis ) const;
     46    void setAxisEnabled( QwtAxisId axisId, bool on );
     47    bool isAxisEnabled( QwtAxisId ) const;
    4748
    48 protected Q_SLOTS:
     49  public Q_SLOTS:
    4950    virtual void moveCanvas( int dx, int dy );
    5051
    51 protected:
    52     virtual QBitmap contentsMask() const;
    53     virtual QPixmap grab() const;
     52  protected:
     53    virtual QBitmap contentsMask() const QWT_OVERRIDE;
     54    virtual QPixmap grab() const QWT_OVERRIDE;
    5455
    55 private:
     56  private:
    5657    class PrivateData;
    57     PrivateData *d_data;
     58    PrivateData* m_data;
    5859};
    5960
  • trunk/BNC/qwt/qwt_plot_picker.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_plot_picker.h"
    1111#include "qwt_plot.h"
     12#include "qwt_text.h"
    1213#include "qwt_scale_div.h"
    13 #include "qwt_painter.h"
    1414#include "qwt_scale_map.h"
    1515#include "qwt_picker_machine.h"
    1616
    17 /*!
    18   \brief Create a plot picker
    19 
    20   The picker is set to those x- and y-axis of the plot
    21   that are enabled. If both or no x-axis are enabled, the picker
    22   is set to QwtPlot::xBottom. If both or no y-axis are
    23   enabled, it is set to QwtPlot::yLeft.
    24 
    25   \param canvas Plot canvas to observe, also the parent object
    26 
    27   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
    28 */
    29 
    30 QwtPlotPicker::QwtPlotPicker( QWidget *canvas ):
    31     QwtPicker( canvas ),
    32     d_xAxis( -1 ),
    33     d_yAxis( -1 )
    34 {
     17class QwtPlotPicker::PrivateData
     18{
     19  public:
     20    PrivateData():
     21        xAxisId( -1 ),
     22        yAxisId( -1 )
     23    {
     24    }
     25
     26    QwtAxisId xAxisId;
     27    QwtAxisId yAxisId;
     28};
     29
     30/*!
     31   \brief Create a plot picker
     32
     33   The picker is set to those x- and y-axis of the plot
     34   that are enabled. If both or no x-axis are enabled, the picker
     35   is set to QwtAxis::XBottom. If both or no y-axis are
     36   enabled, it is set to QwtAxis::YLeft.
     37
     38   \param canvas Plot canvas to observe, also the parent object
     39
     40   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
     41 */
     42
     43QwtPlotPicker::QwtPlotPicker( QWidget* canvas )
     44    : QwtPicker( canvas )
     45{
     46    m_data = new PrivateData;
     47
    3548    if ( !canvas )
    3649        return;
    3750
     51    const QwtPlot* plot = QwtPlotPicker::plot();
    3852    // attach axes
    3953
    40     int xAxis = QwtPlot::xBottom;
    41 
    42     const QwtPlot *plot = QwtPlotPicker::plot();
    43     if ( !plot->axisEnabled( QwtPlot::xBottom ) &&
    44         plot->axisEnabled( QwtPlot::xTop ) )
    45     {
    46         xAxis = QwtPlot::xTop;
    47     }
    48 
    49     int yAxis = QwtPlot::yLeft;
    50     if ( !plot->axisEnabled( QwtPlot::yLeft ) &&
    51         plot->axisEnabled( QwtPlot::yRight ) )
    52     {
    53         yAxis = QwtPlot::yRight;
    54     }
    55 
    56     setAxis( xAxis, yAxis );
    57 }
    58 
    59 /*!
    60   Create a plot picker
    61 
    62   \param xAxis Set the x axis of the picker
    63   \param yAxis Set the y axis of the picker
    64   \param canvas Plot canvas to observe, also the parent object
    65 
    66   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
    67 */
    68 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis, QWidget *canvas ):
    69     QwtPicker( canvas ),
    70     d_xAxis( xAxis ),
    71     d_yAxis( yAxis )
    72 {
    73 }
    74 
    75 /*!
    76   Create a plot picker
    77 
    78   \param xAxis X axis of the picker
    79   \param yAxis Y axis of the picker
    80   \param rubberBand Rubber band style
    81   \param trackerMode Tracker mode
    82   \param canvas Plot canvas to observe, also the parent object
    83 
    84   \sa QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(),
     54    using namespace QwtAxis;
     55
     56    int xAxis = XBottom;
     57    if ( !plot->isAxisVisible( XBottom ) && plot->isAxisVisible( XTop ) )
     58        xAxis = XTop;
     59
     60    int yAxis = YLeft;
     61    if ( !plot->isAxisVisible( YLeft ) && plot->isAxisVisible( YRight ) )
     62        yAxis = YRight;
     63
     64    setAxes( xAxis, yAxis );
     65}
     66
     67/*!
     68   Create a plot picker
     69
     70   \param xAxisId X axis of the picker
     71   \param yAxisId Y axis of the picker
     72   \param canvas Plot canvas to observe, also the parent object
     73
     74   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
     75 */
     76QwtPlotPicker::QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId, QWidget* canvas )
     77    : QwtPicker( canvas )
     78{
     79    m_data = new PrivateData;
     80    m_data->xAxisId = xAxisId;
     81    m_data->yAxisId = yAxisId;
     82}
     83
     84/*!
     85   Create a plot picker
     86
     87   \param xAxisId X axis of the picker
     88   \param yAxisId Y axis of the picker
     89   \param rubberBand Rubber band style
     90   \param trackerMode Tracker mode
     91   \param canvas Plot canvas to observe, also the parent object
     92
     93   \sa QwtPicker, QwtPicker::setSelectionFlags(), QwtPicker::setRubberBand(),
    8594      QwtPicker::setTrackerMode
    8695
    87   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
    88 */
    89 QwtPlotPicker::QwtPlotPicker( int xAxis, int yAxis,
    90         RubberBand rubberBand, DisplayMode trackerMode,
    91         QWidget *canvas ):
    92     QwtPicker( rubberBand, trackerMode, canvas ),
    93     d_xAxis( xAxis ),
    94     d_yAxis( yAxis )
    95 {
     96   \sa QwtPlot::autoReplot(), QwtPlot::replot(), scaleRect()
     97 */
     98QwtPlotPicker::QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId,
     99        RubberBand rubberBand, DisplayMode trackerMode, QWidget* canvas )
     100    : QwtPicker( rubberBand, trackerMode, canvas )
     101{
     102    m_data = new PrivateData;
     103    m_data->xAxisId = xAxisId;
     104    m_data->yAxisId = yAxisId;
    96105}
    97106
    … …  
    99108QwtPlotPicker::~QwtPlotPicker()
    100109{
     110    delete m_data;
    101111}
    102112
    103113//! \return Observed plot canvas
    104 QWidget *QwtPlotPicker::canvas()
     114QWidget* QwtPlotPicker::canvas()
    105115{
    106116    return parentWidget();
    … …  
    108118
    109119//! \return Observed plot canvas
    110 const QWidget *QwtPlotPicker::canvas() const
     120const QWidget* QwtPlotPicker::canvas() const
    111121{
    112122    return parentWidget();
    … …  
    114124
    115125//! \return Plot widget, containing the observed plot canvas
    116 QwtPlot *QwtPlotPicker::plot()
    117 {
    118     QWidget *w = canvas();
     126QwtPlot* QwtPlotPicker::plot()
     127{
     128    QWidget* w = canvas();
    119129    if ( w )
    120130        w = w->parentWidget();
    121131
    122     return qobject_cast<QwtPlot *>( w );
     132    return qobject_cast< QwtPlot* >( w );
    123133}
    124134
    125135//! \return Plot widget, containing the observed plot canvas
    126 const QwtPlot *QwtPlotPicker::plot() const
    127 {
    128     const QWidget *w = canvas();
     136const QwtPlot* QwtPlotPicker::plot() const
     137{
     138    const QWidget* w = canvas();
    129139    if ( w )
    130140        w = w->parentWidget();
    131141
    132     return qobject_cast<const QwtPlot *>( w );
    133 }
    134 
    135 /*!
    136   \return Normalized bounding rectangle of the axes
    137   \sa QwtPlot::autoReplot(), QwtPlot::replot().
    138 */
     142    return qobject_cast< const QwtPlot* >( w );
     143}
     144
     145/*!
     146   \return Normalized bounding rectangle of the axes
     147   \sa QwtPlot::autoReplot(), QwtPlot::replot().
     148 */
    139149QRectF QwtPlotPicker::scaleRect() const
    140150{
    … …  
    143153    if ( plot() )
    144154    {
    145         const QwtScaleDiv &xs = plot()->axisScaleDiv( xAxis() );
    146         const QwtScaleDiv &ys = plot()->axisScaleDiv( yAxis() );
     155        const QwtScaleDiv& xs = plot()->axisScaleDiv( xAxis() );
     156        const QwtScaleDiv& ys = plot()->axisScaleDiv( yAxis() );
    147157
    148158        rect = QRectF( xs.lowerBound(), ys.lowerBound(),
    … …  
    155165
    156166/*!
    157   Set the x and y axes of the picker
    158 
    159   \param xAxis X axis
    160   \param yAxis Y axis
    161 */
    162 void QwtPlotPicker::setAxis( int xAxis, int yAxis )
    163 {
    164     const QwtPlot *plt = plot();
     167   Set the x and y axes of the picker
     168
     169   \param xAxisId X axis
     170   \param yAxisId Y axis
     171 */
     172void QwtPlotPicker::setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId )
     173{
     174    const QwtPlot* plt = plot();
    165175    if ( !plt )
    166176        return;
    167177
    168     if ( xAxis != d_xAxis || yAxis != d_yAxis )
    169     {
    170         d_xAxis = xAxis;
    171         d_yAxis = yAxis;
     178    if ( xAxisId != m_data->xAxisId || yAxisId != m_data->yAxisId )
     179    {
     180        m_data->xAxisId = xAxisId;
     181        m_data->yAxisId = yAxisId;
    172182    }
    173183}
    174184
    175185//! Return x axis
    176 int QwtPlotPicker::xAxis() const
    177 {
    178     return d_xAxis;
     186QwtAxisId QwtPlotPicker::xAxis() const
     187{
     188    return m_data->xAxisId;
    179189}
    180190
    181191//! Return y axis
    182 int QwtPlotPicker::yAxis() const
    183 {
    184     return d_yAxis;
    185 }
    186 
    187 /*!
    188   Translate a pixel position into a position string
    189 
    190   \param pos Position in pixel coordinates
    191   \return Position string
    192 */
    193 QwtText QwtPlotPicker::trackerText( const QPoint &pos ) const
     192QwtAxisId QwtPlotPicker::yAxis() const
     193{
     194    return m_data->yAxisId;
     195}
     196
     197/*!
     198   Translate a pixel position into a position string
     199
     200   \param pos Position in pixel coordinates
     201   \return Position string
     202 */
     203QwtText QwtPlotPicker::trackerText( const QPoint& pos ) const
    194204{
    195205    if ( plot() == NULL )
    … …  
    200210
    201211/*!
    202   \brief Translate a position into a position string
    203 
    204   In case of HLineRubberBand the label is the value of the
    205   y position, in case of VLineRubberBand the value of the x position.
    206   Otherwise the label contains x and y position separated by a ',' .
    207 
    208   The format for the double to string conversion is "%.4f".
    209 
    210   \param pos Position
    211   \return Position string
    212 */
    213 QwtText QwtPlotPicker::trackerTextF( const QPointF &pos ) const
     212   \brief Translate a position into a position string
     213
     214   In case of HLineRubberBand the label is the value of the
     215   y position, in case of VLineRubberBand the value of the x position.
     216   Otherwise the label contains x and y position separated by a ',' .
     217
     218   The format for the double to string conversion is "%.4f".
     219
     220   \param pos Position
     221   \return Position string
     222 */
     223QwtText QwtPlotPicker::trackerTextF( const QPointF& pos ) const
    214224{
    215225    QString text;
    … …  
    218228    {
    219229        case HLineRubberBand:
    220             text.sprintf( "%.4f", pos.y() );
     230            text = QString::number( pos.y(), 'f', 4 );
    221231            break;
    222232        case VLineRubberBand:
    223             text.sprintf( "%.4f", pos.x() );
     233            text = QString::number( pos.x(), 'f', 4 );
    224234            break;
    225235        default:
    226             text.sprintf( "%.4f, %.4f", pos.x(), pos.y() );
     236            text = QString::number( pos.x(), 'f', 4 )
     237                + ", " + QString::number( pos.y(), 'f', 4 );
    227238    }
    228239    return QwtText( text );
    … …  
    230241
    231242/*!
    232   Append a point to the selection and update rubber band and tracker.
    233 
    234   \param pos Additional point
    235   \sa isActive, begin(), end(), move(), appended()
    236 
    237   \note The appended(const QPoint &), appended(const QDoublePoint &)
     243   Append a point to the selection and update rubber band and tracker.
     244
     245   \param pos Additional point
     246   \sa isActive, begin(), end(), move(), appended()
     247
     248   \note The appended(const QPoint &), appended(const QDoublePoint &)
    238249        signals are emitted.
    239 */
    240 void QwtPlotPicker::append( const QPoint &pos )
     250 */
     251void QwtPlotPicker::append( const QPoint& pos )
    241252{
    242253    QwtPicker::append( pos );
    … …  
    245256
    246257/*!
    247   Move the last point of the selection
    248 
    249   \param pos New position
    250   \sa isActive, begin(), end(), append()
    251 
    252   \note The moved(const QPoint &), moved(const QDoublePoint &)
     258   Move the last point of the selection
     259
     260   \param pos New position
     261   \sa isActive, begin(), end(), append()
     262
     263   \note The moved(const QPoint &), moved(const QDoublePoint &)
    253264        signals are emitted.
    254 */
    255 void QwtPlotPicker::move( const QPoint &pos )
     265 */
     266void QwtPlotPicker::move( const QPoint& pos )
    256267{
    257268    QwtPicker::move( pos );
    … …  
    260271
    261272/*!
    262   Close a selection setting the state to inactive.
    263 
    264   \param ok If true, complete the selection and emit selected signals
     273   Close a selection setting the state to inactive.
     274
     275   \param ok If true, complete the selection and emit selected signals
    265276            otherwise discard the selection.
    266   \return True if the selection has been accepted, false otherwise
    267 */
     277   \return True if the selection has been accepted, false otherwise
     278 */
    268279
    269280bool QwtPlotPicker::end( bool ok )
    … …  
    273284        return false;
    274285
    275     QwtPlot *plot = QwtPlotPicker::plot();
     286    QwtPlot* plot = QwtPlotPicker::plot();
    276287    if ( !plot )
    277288        return false;
    … …  
    309320        case QwtPickerMachine::PolygonSelection:
    310321        {
    311             QVector<QPointF> dpa( points.count() );
     322            QVector< QPointF > dpa( points.count() );
    312323            for ( int i = 0; i < points.count(); i++ )
    313324                dpa[i] = invTransform( points[i] );
    … …  
    327338    \return Rectangle in plot coordinates
    328339    \sa transform()
    329 */
    330 QRectF QwtPlotPicker::invTransform( const QRect &rect ) const
    331 {
    332     const QwtScaleMap xMap = plot()->canvasMap( d_xAxis );
    333     const QwtScaleMap yMap = plot()->canvasMap( d_yAxis );
     340 */
     341QRectF QwtPlotPicker::invTransform( const QRect& rect ) const
     342{
     343    const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
     344    const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
    334345
    335346    return QwtScaleMap::invTransform( xMap, yMap, rect );
    … …  
    340351    \return Rectangle in pixel coordinates
    341352    \sa invTransform()
    342 */
    343 QRect QwtPlotPicker::transform( const QRectF &rect ) const
    344 {
    345     const QwtScaleMap xMap = plot()->canvasMap( d_xAxis );
    346     const QwtScaleMap yMap = plot()->canvasMap( d_yAxis );
     353 */
     354QRect QwtPlotPicker::transform( const QRectF& rect ) const
     355{
     356    const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
     357    const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
    347358
    348359    return QwtScaleMap::transform( xMap, yMap, rect ).toRect();
    … …  
    353364    \return Point in plot coordinates
    354365    \sa transform()
    355 */
    356 QPointF QwtPlotPicker::invTransform( const QPoint &pos ) const
    357 {
    358     QwtScaleMap xMap = plot()->canvasMap( d_xAxis );
    359     QwtScaleMap yMap = plot()->canvasMap( d_yAxis );
     366 */
     367QPointF QwtPlotPicker::invTransform( const QPoint& pos ) const
     368{
     369    const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
     370    const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
    360371
    361372    return QPointF(
    362373        xMap.invTransform( pos.x() ),
    363374        yMap.invTransform( pos.y() )
    364     );
     375        );
    365376}
    366377
    … …  
    369380    \return Point in pixel coordinates
    370381    \sa invTransform()
    371 */
    372 QPoint QwtPlotPicker::transform( const QPointF &pos ) const
    373 {
    374     QwtScaleMap xMap = plot()->canvasMap( d_xAxis );
    375     QwtScaleMap yMap = plot()->canvasMap( d_yAxis );
    376 
    377     const QPointF p( xMap.transform( pos.x() ),
    378         yMap.transform( pos.y() ) );
     382 */
     383QPoint QwtPlotPicker::transform( const QPointF& pos ) const
     384{
     385    const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
     386    const QwtScaleMap yMap = plot()->canvasMap( yAxis() );
     387
     388    const QPointF p( xMap.transform( pos.x() ), yMap.transform( pos.y() ) );
    379389
    380390    return p.toPoint();
    381391}
     392
     393#include "moc_qwt_plot_picker.cpp"
  • trunk/BNC/qwt/qwt_plot_picker.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_picker.h"
    15 #include <qvector.h>
     15#include "qwt_axis_id.h"
    1616
    1717class QwtPlot;
     18class QPointF;
     19class QRectF;
     20
     21#if QT_VERSION < 0x060000
     22template< typename T > class QVector;
     23#endif
    1824
    1925/*!
    20   \brief QwtPlotPicker provides selections on a plot canvas
     26   \brief QwtPlotPicker provides selections on a plot canvas
    2127
    22   QwtPlotPicker is a QwtPicker tailored for selections on
    23   a plot canvas. It is set to a x-Axis and y-Axis and
    24   translates all pixel coordinates into this coordinate system.
    25 */
     28   QwtPlotPicker is a QwtPicker tailored for selections on
     29   a plot canvas. It is set to a x-Axis and y-Axis and
     30   translates all pixel coordinates into this coordinate system.
     31 */
    2632
    27 class QWT_EXPORT QwtPlotPicker: public QwtPicker
     33class QWT_EXPORT QwtPlotPicker : public QwtPicker
    2834{
    2935    Q_OBJECT
    3036
    31 public:
    32     explicit QwtPlotPicker( QWidget *canvas );
     37  public:
     38    explicit QwtPlotPicker( QWidget* canvas );
    3339    virtual ~QwtPlotPicker();
    3440
    35     explicit QwtPlotPicker( int xAxis, int yAxis, QWidget * );
     41    explicit QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId, QWidget* );
    3642
    37     explicit QwtPlotPicker( int xAxis, int yAxis,
    38         RubberBand rubberBand, DisplayMode trackerMode, QWidget * );
     43    explicit QwtPlotPicker( QwtAxisId xAxisId, QwtAxisId yAxisId,
     44        RubberBand rubberBand, DisplayMode trackerMode, QWidget* );
    3945
    40     virtual void setAxis( int xAxis, int yAxis );
     46    virtual void setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId );
    4147
    42     int xAxis() const;
    43     int yAxis() const;
     48    QwtAxisId xAxis() const;
     49    QwtAxisId yAxis() const;
    4450
    45     QwtPlot *plot();
    46     const QwtPlot *plot() const;
     51    QwtPlot* plot();
     52    const QwtPlot* plot() const;
    4753
    48     QWidget *canvas();
    49     const QWidget *canvas() const;
     54    QWidget* canvas();
     55    const QWidget* canvas() const;
    5056
    51 Q_SIGNALS:
     57  Q_SIGNALS:
    5258
    5359    /*!
    54       A signal emitted in case of QwtPickerMachine::PointSelection.
    55       \param pos Selected point
    56     */
    57     void selected( const QPointF &pos );
     60       A signal emitted in case of QwtPickerMachine::PointSelection.
     61       \param pos Selected point
     62     */
     63    void selected( const QPointF& pos );
    5864
    5965    /*!
    60       A signal emitted in case of QwtPickerMachine::RectSelection.
    61       \param rect Selected rectangle
    62     */
    63     void selected( const QRectF &rect );
     66       A signal emitted in case of QwtPickerMachine::RectSelection.
     67       \param rect Selected rectangle
     68     */
     69    void selected( const QRectF& rect );
    6470
    6571    /*!
    66       A signal emitting the selected points,
    67       at the end of a selection.
     72       A signal emitting the selected points,
     73       at the end of a selection.
    6874
    69       \param pa Selected points
    70     */
    71     void selected( const QVector<QPointF> &pa );
     75       \param pa Selected points
     76     */
     77    void selected( const QVector< QPointF >& pa );
    7278
    7379    /*!
    74       A signal emitted when a point has been appended to the selection
     80       A signal emitted when a point has been appended to the selection
    7581
    76       \param pos Position of the appended point.
    77       \sa append(). moved()
    78     */
    79     void appended( const QPointF &pos );
     82       \param pos Position of the appended point.
     83       \sa append(). moved()
     84     */
     85    void appended( const QPointF& pos );
    8086
    8187    /*!
    82       A signal emitted whenever the last appended point of the
    83       selection has been moved.
     88       A signal emitted whenever the last appended point of the
     89       selection has been moved.
    8490
    85       \param pos Position of the moved last point of the selection.
    86       \sa move(), appended()
    87     */
    88     void moved( const QPointF &pos );
     91       \param pos Position of the moved last point of the selection.
     92       \sa move(), appended()
     93     */
     94    void moved( const QPointF& pos );
    8995
    90 protected:
     96  protected:
    9197    QRectF scaleRect() const;
    9298
    93     QRectF invTransform( const QRect & ) const;
    94     QRect transform( const QRectF & ) const;
     99    QRectF invTransform( const QRect& ) const;
     100    QRect transform( const QRectF& ) const;
    95101
    96     QPointF invTransform( const QPoint & ) const;
    97     QPoint transform( const QPointF & ) const;
     102    QPointF invTransform( const QPoint& ) const;
     103    QPoint transform( const QPointF& ) const;
    98104
    99     virtual QwtText trackerText( const QPoint & ) const;
    100     virtual QwtText trackerTextF( const QPointF & ) const;
     105    virtual QwtText trackerText( const QPoint& ) const QWT_OVERRIDE;
     106    virtual QwtText trackerTextF( const QPointF& ) const;
    101107
    102     virtual void move( const QPoint & );
    103     virtual void append( const QPoint & );
    104     virtual bool end( bool ok = true );
     108    virtual void move( const QPoint& ) QWT_OVERRIDE;
     109    virtual void append( const QPoint& ) QWT_OVERRIDE;
     110    virtual bool end( bool ok = true ) QWT_OVERRIDE;
    105111
    106 private:
    107     int d_xAxis;
    108     int d_yAxis;
     112  private:
     113    class PrivateData;
     114    PrivateData* m_data;
    109115};
    110116
  • trunk/BNC/qwt/qwt_plot_rasteritem.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_scale_map.h"
    1212#include "qwt_painter.h"
    13 #include <qapplication.h>
    14 #include <qdesktopwidget.h>
     13#include "qwt_text.h"
     14#include "qwt_interval.h"
     15#include "qwt_math.h"
     16
    1517#include <qpainter.h>
    1618#include <qpaintengine.h>
    17 #include <qmath.h>
    18 #if QT_VERSION >= 0x040400
    1919#include <qthread.h>
    2020#include <qfuture.h>
    2121#include <qtconcurrentrun.h>
    22 #endif
    23 #include <float.h>
     22
     23#include <limits>
    2424
    2525class QwtPlotRasterItem::PrivateData
    2626{
    27 public:
    28     PrivateData():
    29         alpha( -1 ),
    30         paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution )
     27  public:
     28    PrivateData()
     29        : alpha( -1 )
     30        , paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution )
    3131    {
    3232        cache.policy = QwtPlotRasterItem::NoCache;
    … …  
    4747
    4848
    49 static QRectF qwtAlignRect(const QRectF &rect)
     49static QRectF qwtAlignRect(const QRectF& rect)
    5050{
    5151    QRectF r;
    … …  
    5858}
    5959
    60 static QRectF qwtStripRect(const QRectF &rect, const QRectF &area,
    61     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    62     const QwtInterval &xInterval, const QwtInterval &yInterval)
     60static QRectF qwtStripRect(const QRectF& rect, const QRectF& area,
     61    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     62    const QwtInterval& xInterval, const QwtInterval& yInterval)
    6363{
    6464    QRectF r = rect;
    … …  
    110110}
    111111
    112 static QImage qwtExpandImage(const QImage &image,
    113     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    114     const QRectF &area, const QRectF &area2, const QRectF &paintRect,
    115     const QwtInterval &xInterval, const QwtInterval &yInterval )
     112static QImage qwtExpandImage(const QImage& image,
     113    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     114    const QRectF& area, const QRectF& area2, const QRectF& paintRect,
     115    const QwtInterval& xInterval, const QwtInterval& yInterval )
    116116{
    117117    const QRectF strippedRect = qwtStripRect(paintRect, area2,
    … …  
    123123
    124124    const QRectF r = QwtScaleMap::transform(xMap, yMap, area).normalized();
    125     const double pw = ( r.width() - 1) / w;
    126     const double ph = ( r.height() - 1) / h;
     125    const double pw = ( r.width() - 1 ) / w;
     126    const double ph = ( r.height() - 1 ) / h;
    127127
    128128    double px0, py0;
    … …  
    193193                }
    194194
    195                 const quint32 *line1 =
    196                     reinterpret_cast<const quint32 *>( image.scanLine( y1 ) );
     195                const quint32* line1 =
     196                    reinterpret_cast< const quint32* >( image.scanLine( y1 ) );
    197197
    198198                for ( int x1 = 0; x1 < w; x1++ )
    … …  
    225225                    for ( int y2 = yy1; y2 < yy2; y2++ )
    226226                    {
    227                         quint32 *line2 = reinterpret_cast<quint32 *>(
     227                        quint32* line2 = reinterpret_cast< quint32* >(
    228228                            expanded.scanLine( y2 ) );
    229229
    … …  
    263263                }
    264264
    265                 const uchar *line1 = image.scanLine( y1 );
     265                const uchar* line1 = image.scanLine( y1 );
    266266
    267267                for ( int x1 = 0; x1 < w; x1++ )
    … …  
    293293                    for ( int y2 = yy1; y2 < yy2; y2++ )
    294294                    {
    295                         uchar *line2 = expanded.scanLine( y2 );
     295                        uchar* line2 = expanded.scanLine( y2 );
    296296                        memset( line2 + xx1, line1[x1], xx2 - xx1 );
    297297                    }
    … …  
    307307}
    308308
    309 static QRectF qwtExpandToPixels(const QRectF &rect, const QRectF &pixelRect)
     309static QRectF qwtExpandToPixels(const QRectF& rect, const QRectF& pixelRect)
    310310{
    311311    const double pw = pixelRect.width();
    … …  
    318318
    319319    QRectF r;
    320     r.setLeft( pixelRect.left() - qCeil( dx1 / pw ) * pw );
    321     r.setTop( pixelRect.top() - qCeil( dy1 / ph ) * ph );
    322     r.setRight( pixelRect.right() - qFloor( dx2 / pw ) * pw );
    323     r.setBottom( pixelRect.bottom() - qFloor( dy2 / ph ) * ph );
     320    r.setLeft( pixelRect.left() - qwtCeil( dx1 / pw ) * pw );
     321    r.setTop( pixelRect.top() - qwtCeil( dy1 / ph ) * ph );
     322    r.setRight( pixelRect.right() - qwtFloor( dx2 / pw ) * pw );
     323    r.setBottom( pixelRect.bottom() - qwtFloor( dy2 / ph ) * ph );
    324324
    325325    return r;
    326326}
    327327
    328 static void qwtTransformMaps( const QTransform &tr,
    329     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    330     QwtScaleMap &xxMap, QwtScaleMap &yyMap )
     328static void qwtTransformMaps( const QTransform& tr,
     329    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     330    QwtScaleMap& xxMap, QwtScaleMap& yyMap )
    331331{
    332332    const QPointF p1 = tr.map( QPointF( xMap.p1(), yMap.p1() ) );
    … …  
    340340}
    341341
    342 static void qwtAdjustMaps( QwtScaleMap &xMap, QwtScaleMap &yMap,
    343     const QRectF &area, const QRectF &paintRect)
     342static void qwtAdjustMaps( QwtScaleMap& xMap, QwtScaleMap& yMap,
     343    const QRectF& area, const QRectF& paintRect)
    344344{
    345345    double sx1 = area.left();
    … …  
    354354        qSwap(sy1, sy2);
    355355
    356     xMap.setPaintInterval(paintRect.left(), paintRect.right());
     356    xMap.setPaintInterval(paintRect.left(), paintRect.right() );
    357357    xMap.setScaleInterval(sx1, sx2);
    358358
    359     yMap.setPaintInterval(paintRect.top(), paintRect.bottom());
     359    yMap.setPaintInterval(paintRect.top(), paintRect.bottom() );
    360360    yMap.setScaleInterval(sy1, sy2);
    361361}
    362362
    363363static bool qwtUseCache( QwtPlotRasterItem::CachePolicy policy,
    364     const QPainter *painter )
     364    const QPainter* painter )
    365365{
    366366    bool doCache = false;
    … …  
    375375            case QPaintEngine::SVG:
    376376            case QPaintEngine::Pdf:
     377#if QT_VERSION < 0x060000
    377378            case QPaintEngine::PostScript:
     379#endif
    378380            case QPaintEngine::MacPrinter:
    379381            case QPaintEngine::Picture:
    … …  
    403405        for ( int y = y0; y <= y1; y++ )
    404406        {
    405             QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) );
    406             const unsigned char *line = from->scanLine( y );
     407            QRgb* alphaLine = reinterpret_cast< QRgb* >( to->scanLine( y ) );
     408            const unsigned char* line = from->scanLine( y );
    407409
    408410            for ( int x = x0; x <= x1; x++ )
    … …  
    414416        for ( int y = y0; y <= y1; y++ )
    415417        {
    416             QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) );
    417             const QRgb *line = reinterpret_cast<const QRgb *>( from->scanLine( y ) );
     418            QRgb* alphaLine = reinterpret_cast< QRgb* >( to->scanLine( y ) );
     419            const QRgb* line = reinterpret_cast< const QRgb* >( from->scanLine( y ) );
    418420
    419421            for ( int x = x0; x <= x1; x++ )
    … …  
    430432
    431433//! Constructor
    432 QwtPlotRasterItem::QwtPlotRasterItem( const QString& title ):
    433     QwtPlotItem( QwtText( title ) )
     434QwtPlotRasterItem::QwtPlotRasterItem( const QString& title )
     435    : QwtPlotItem( QwtText( title ) )
    434436{
    435437    init();
    … …  
    437439
    438440//! Constructor
    439 QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title ):
    440     QwtPlotItem( title )
     441QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title )
     442    : QwtPlotItem( title )
    441443{
    442444    init();
    … …  
    446448QwtPlotRasterItem::~QwtPlotRasterItem()
    447449{
    448     delete d_data;
     450    delete m_data;
    449451}
    450452
    451453void QwtPlotRasterItem::init()
    452454{
    453     d_data = new PrivateData();
     455    m_data = new PrivateData();
    454456
    455457    setItemAttribute( QwtPlotItem::AutoScale, true );
    … …  
    460462
    461463/*!
    462   Specify an attribute how to draw the raster item
    463 
    464   \param attribute Paint attribute
    465   \param on On/Off
    466   /sa PaintAttribute, testPaintAttribute()
    467 */
     464   Specify an attribute how to draw the raster item
     465
     466   \param attribute Paint attribute
     467   \param on On/Off
     468   /sa PaintAttribute, testPaintAttribute()
     469 */
    468470void QwtPlotRasterItem::setPaintAttribute( PaintAttribute attribute, bool on )
    469471{
    470472    if ( on )
    471         d_data->paintAttributes |= attribute;
     473        m_data->paintAttributes |= attribute;
    472474    else
    473         d_data->paintAttributes &= ~attribute;
     475        m_data->paintAttributes &= ~attribute;
    474476}
    475477
    … …  
    477479    \return True, when attribute is enabled
    478480    \sa PaintAttribute, setPaintAttribute()
    479 */
     481 */
    480482bool QwtPlotRasterItem::testPaintAttribute( PaintAttribute attribute ) const
    481483{
    482     return ( d_data->paintAttributes & attribute );
     484    return ( m_data->paintAttributes & attribute );
    483485}
    484486
    … …  
    505507
    506508   \sa alpha()
    507 */
     509 */
    508510void QwtPlotRasterItem::setAlpha( int alpha )
    509511{
    … …  
    514516        alpha = 255;
    515517
    516     if ( alpha != d_data->alpha )
    517     {
    518         d_data->alpha = alpha;
     518    if ( alpha != m_data->alpha )
     519    {
     520        m_data->alpha = alpha;
    519521
    520522        itemChanged();
    … …  
    523525
    524526/*!
    525   \return Alpha value of the raster item
    526   \sa setAlpha()
    527 */
     527   \return Alpha value of the raster item
     528   \sa setAlpha()
     529 */
    528530int QwtPlotRasterItem::alpha() const
    529531{
    530     return d_data->alpha;
    531 }
    532 
    533 /*!
    534   Change the cache policy
    535 
    536   The default policy is NoCache
    537 
    538   \param policy Cache policy
    539   \sa CachePolicy, cachePolicy()
    540 */
     532    return m_data->alpha;
     533}
     534
     535/*!
     536   Change the cache policy
     537
     538   The default policy is NoCache
     539
     540   \param policy Cache policy
     541   \sa CachePolicy, cachePolicy()
     542 */
    541543void QwtPlotRasterItem::setCachePolicy(
    542544    QwtPlotRasterItem::CachePolicy policy )
    543545{
    544     if ( d_data->cache.policy != policy )
    545     {
    546         d_data->cache.policy = policy;
     546    if ( m_data->cache.policy != policy )
     547    {
     548        m_data->cache.policy = policy;
    547549
    548550        invalidateCache();
    … …  
    552554
    553555/*!
    554   \return Cache policy
    555   \sa CachePolicy, setCachePolicy()
    556 */
     556   \return Cache policy
     557   \sa CachePolicy, setCachePolicy()
     558 */
    557559QwtPlotRasterItem::CachePolicy QwtPlotRasterItem::cachePolicy() const
    558560{
    559     return d_data->cache.policy;
     561    return m_data->cache.policy;
    560562}
    561563
    … …  
    563565   Invalidate the paint cache
    564566   \sa setCachePolicy()
    565 */
     567 */
    566568void QwtPlotRasterItem::invalidateCache()
    567569{
    568     d_data->cache.image = QImage();
    569     d_data->cache.area = QRect();
    570     d_data->cache.size = QSize();
     570    m_data->cache.image = QImage();
     571    m_data->cache.area = QRect();
     572    m_data->cache.size = QSize();
    571573}
    572574
    … …  
    596598
    597599   \sa render(), renderImage()
    598 */
    599 QRectF QwtPlotRasterItem::pixelHint( const QRectF &area ) const
     600 */
     601QRectF QwtPlotRasterItem::pixelHint( const QRectF& area ) const
    600602{
    601603    Q_UNUSED( area );
    … …  
    604606
    605607/*!
    606   \brief Draw the raster data
    607   \param painter Painter
    608   \param xMap X-Scale Map
    609   \param yMap Y-Scale Map
    610   \param canvasRect Contents rectangle of the plot canvas
    611 */
    612 void QwtPlotRasterItem::draw( QPainter *painter,
    613     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    614     const QRectF &canvasRect ) const
    615 {
    616     if ( canvasRect.isEmpty() || d_data->alpha == 0 )
     608   \brief Draw the raster data
     609   \param painter Painter
     610   \param xMap X-Scale Map
     611   \param yMap Y-Scale Map
     612   \param canvasRect Contents rectangle of the plot canvas
     613 */
     614void QwtPlotRasterItem::draw( QPainter* painter,
     615    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     616    const QRectF& canvasRect ) const
     617{
     618    if ( canvasRect.isEmpty() || m_data->alpha == 0 )
    617619        return;
    618620
    619     const bool doCache = qwtUseCache( d_data->cache.policy, painter );
     621    const bool doCache = qwtUseCache( m_data->cache.policy, painter );
    620622
    621623    const QwtInterval xInterval = interval( Qt::XAxis );
    … …  
    626628        precision/quality. So we always render the image in
    627629        paint device resolution.
    628     */
     630     */
    629631
    630632    QwtScaleMap xxMap, yyMap;
    … …  
    657659        {
    658660            /*
    659               When the resolution of the data pixels is higher than
    660               the resolution of the target device we render in
    661               target device resolution.
     661               When the resolution of the data pixels is higher than
     662               the resolution of the target device we render in
     663               target device resolution.
    662664             */
    663665            pixelRect = QRectF();
    … …  
    666668        {
    667669            /*
    668               If only one dimension is of the data pixel is higher
    669               we expand the pixel rect to the resolution of the target device.
     670               If only one dimension is of the data pixel is higher
     671               we expand the pixel rect to the resolution of the target device.
    670672             */
    671673
    … …  
    692694        // data pixels we render in resolution of the paint device.
    693695
     696        auto imageSize = paintRect.size();
     697
     698#if QT_VERSION >= 0x050000
     699        const auto pixelRatio = QwtPainter::devicePixelRatio( painter->device() );
     700        imageSize *= pixelRatio;
     701#endif
     702
    694703        image = compose(xxMap, yyMap,
    695             area, paintRect, paintRect.size().toSize(), doCache);
     704            area, paintRect, imageSize.toSize(), doCache);
     705
    696706        if ( image.isNull() )
    697707            return;
    698708
     709#if QT_VERSION >= 0x050000
     710        image.setDevicePixelRatio( pixelRatio );
     711#endif
     712
    699713        // Remove pixels at the boundaries, when explicitly
    700714        // excluded in the intervals
    … …  
    706720        {
    707721            const QRect r(
    708                 qRound( imageRect.x() - paintRect.x()),
     722                qRound( imageRect.x() - paintRect.x() ),
    709723                qRound( imageRect.y() - paintRect.y() ),
    710724                qRound( imageRect.width() ),
    … …  
    773787
    774788   \param axis X, Y, or Z axis
    775 */
     789 */
    776790QwtInterval QwtPlotRasterItem::interval(Qt::Axis axis) const
    777791{
    … …  
    783797   \return Bounding rectangle of the data
    784798   \sa QwtPlotRasterItem::interval()
    785 */
     799 */
    786800QRectF QwtPlotRasterItem::boundingRect() const
    787801{
    … …  
    801815    else
    802816    {
    803         r.setLeft(-0.5 * FLT_MAX);
    804         r.setWidth(FLT_MAX);
     817        const qreal max = std::numeric_limits< float >::max();
     818
     819        r.setLeft( -0.5 * max );
     820        r.setWidth( max );
    805821    }
    806822
    … …  
    812828    else
    813829    {
    814         r.setTop(-0.5 * FLT_MAX);
    815         r.setHeight(FLT_MAX);
     830        const qreal max = std::numeric_limits< float >::max();
     831
     832        r.setTop( -0.5 * max );
     833        r.setHeight( max );
    816834    }
    817835
    … …  
    820838
    821839QImage QwtPlotRasterItem::compose(
    822     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    823     const QRectF &imageArea, const QRectF &paintRect,
    824     const QSize &imageSize, bool doCache) const
     840    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     841    const QRectF& imageArea, const QRectF& paintRect,
     842    const QSize& imageSize, bool doCache) const
    825843{
    826844    QImage image;
    … …  
    830848    if ( doCache )
    831849    {
    832         if ( !d_data->cache.image.isNull()
    833             && d_data->cache.area == imageArea
    834             && d_data->cache.size == paintRect.size() )
    835         {
    836             image = d_data->cache.image;
     850        if ( !m_data->cache.image.isNull()
     851            && m_data->cache.area == imageArea
     852            && m_data->cache.size == paintRect.size() )
     853        {
     854            image = m_data->cache.image;
    837855        }
    838856    }
    … …  
    858876        if ( doCache )
    859877        {
    860             d_data->cache.area = imageArea;
    861             d_data->cache.size = paintRect.size();
    862             d_data->cache.image = image;
    863         }
    864     }
    865 
    866     if ( d_data->alpha >= 0 && d_data->alpha < 255 )
     878            m_data->cache.area = imageArea;
     879            m_data->cache.size = paintRect.size();
     880            m_data->cache.image = image;
     881        }
     882    }
     883
     884    if ( m_data->alpha >= 0 && m_data->alpha < 255 )
    867885    {
    868886        QImage alphaImage( image.size(), QImage::Format_ARGB32 );
    869887
    870 #if QT_VERSION >= 0x040400 && !defined(QT_NO_QFUTURE)
     888#if !defined( QT_NO_QFUTURE )
    871889        uint numThreads = renderThreadCount();
    872890
    … …  
    879897        const int numRows = image.height() / numThreads;
    880898
    881         QList< QFuture<void> > futures;
     899        QVector< QFuture< void > > futures;
     900        futures.reserve( numThreads - 1 );
     901
    882902        for ( uint i = 0; i < numThreads; i++ )
    883903        {
    … …  
    886906            {
    887907                tile.setHeight( image.height() - i * numRows );
    888                 qwtToRgba( &image, &alphaImage, tile, d_data->alpha );
     908                qwtToRgba( &image, &alphaImage, tile, m_data->alpha );
    889909            }
    890910            else
    891911            {
    892912                futures += QtConcurrent::run(
    893                     &qwtToRgba, &image, &alphaImage, tile, d_data->alpha );
     913                    &qwtToRgba, &image, &alphaImage, tile, m_data->alpha );
    894914            }
    895915        }
    … …  
    898918#else
    899919        const QRect tile( 0, 0, image.width(), image.height() );
    900         qwtToRgba( &image, &alphaImage, tile, d_data->alpha );
     920        qwtToRgba( &image, &alphaImage, tile, m_data->alpha );
    901921#endif
    902922        image = alphaImage;
    … …  
    916936
    917937   \return Calculated scale map
    918 */
     938 */
    919939QwtScaleMap QwtPlotRasterItem::imageMap(
    920940    Qt::Orientation orientation,
    921     const QwtScaleMap &map, const QRectF &area,
    922     const QSize &imageSize, double pixelSize) const
     941    const QwtScaleMap& map, const QRectF& area,
     942    const QSize& imageSize, double pixelSize) const
    923943{
    924944    double p1, p2, s1, s2;
  • trunk/BNC/qwt/qwt_plot_rasteritem.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_item.h"
    15 #include "qwt_interval.h"
    16 #include <qglobal.h>
     15
    1716#include <qstring.h>
    18 #include <qimage.h>
     17
     18class QwtInterval;
    1919
    2020/*!
    21   \brief A class, which displays raster data
     21   \brief A class, which displays raster data
    2222
    23   Raster data is a grid of pixel values, that can be represented
    24   as a QImage. It is used for many types of information like
    25   spectrograms, cartograms, geographical maps ...
     23   Raster data is a grid of pixel values, that can be represented
     24   as a QImage. It is used for many types of information like
     25   spectrograms, cartograms, geographical maps ...
    2626
    27   Often a plot has several types of raster data organized in layers.
    28   ( f.e a geographical map, with weather statistics ).
    29   Using setAlpha() raster items can be stacked easily.
     27   Often a plot has several types of raster data organized in layers.
     28   ( f.e a geographical map, with weather statistics ).
     29   Using setAlpha() raster items can be stacked easily.
    3030
    31   QwtPlotRasterItem is only implemented for images of the following formats:
    32   QImage::Format_Indexed8, QImage::Format_ARGB32.
     31   QwtPlotRasterItem is only implemented for images of the following formats:
     32   QImage::Format_Indexed8, QImage::Format_ARGB32.
    3333
    34   \sa QwtPlotSpectrogram
    35 */
     34   \sa QwtPlotSpectrogram
     35 */
    3636
    37 class QWT_EXPORT QwtPlotRasterItem: public QwtPlotItem
     37class QWT_EXPORT QwtPlotRasterItem : public QwtPlotItem
    3838{
    39 public:
     39  public:
    4040    /*!
    41       \brief Cache policy
    42       The default policy is NoCache
     41       \brief Cache policy
     42       The default policy is NoCache
    4343     */
    4444    enum CachePolicy
    4545    {
    4646        /*!
    47           renderImage() is called each time the item has to be repainted
     47           renderImage() is called each time the item has to be repainted
    4848         */
    4949        NoCache,
    5050
    5151        /*!
    52           renderImage() is called, whenever the image cache is not valid,
    53           or the scales, or the size of the canvas has changed.
     52           renderImage() is called, whenever the image cache is not valid,
     53           or the scales, or the size of the canvas has changed.
    5454
    55           This type of cache is useful for improving the performance
    56           of hide/show operations or manipulations of the alpha value.
    57           All other situations are handled by the canvas backing store.
     55           This type of cache is useful for improving the performance
     56           of hide/show operations or manipulations of the alpha value.
     57           All other situations are handled by the canvas backing store.
    5858         */
    5959        PaintCache
    … …  
    6363        Attributes to modify the drawing algorithm.
    6464        \sa setPaintAttribute(), testPaintAttribute()
    65     */
     65     */
    6666    enum PaintAttribute
    6767    {
    6868        /*!
    69           When the image is rendered according to the data pixels
    70           ( QwtRasterData::pixelHint() ) it can be expanded to paint
    71           device resolution before it is passed to QPainter.
    72           The expansion algorithm rounds the pixel borders in the same
    73           way as the axis ticks, what is usually better than the
    74           scaling algorithm implemented in Qt.
    75           Disabling this flag might make sense, to reduce the size of a
    76           document/file. If this is possible for a document format
    77           depends on the implementation of the specific QPaintEngine.
     69           When the image is rendered according to the data pixels
     70           ( QwtRasterData::pixelHint() ) it can be expanded to paint
     71           device resolution before it is passed to QPainter.
     72           The expansion algorithm rounds the pixel borders in the same
     73           way as the axis ticks, what is usually better than the
     74           scaling algorithm implemented in Qt.
     75           Disabling this flag might make sense, to reduce the size of a
     76           document/file. If this is possible for a document format
     77           depends on the implementation of the specific QPaintEngine.
    7878         */
    7979
    … …  
    8181    };
    8282
    83     //! Paint attributes
    84     typedef QFlags<PaintAttribute> PaintAttributes;
     83    Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute )
    8584
    8685    explicit QwtPlotRasterItem( const QString& title = QString() );
    … …  
    9998    void invalidateCache();
    10099
    101     virtual void draw( QPainter *,
    102         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    103         const QRectF &canvasRect ) const;
     100    virtual void draw( QPainter*,
     101        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     102        const QRectF& canvasRect ) const QWT_OVERRIDE;
    104103
    105     virtual QRectF pixelHint( const QRectF & ) const;
     104    virtual QRectF pixelHint( const QRectF& ) const;
    106105
    107106    virtual QwtInterval interval(Qt::Axis) const;
    108     virtual QRectF boundingRect() const;
     107    virtual QRectF boundingRect() const QWT_OVERRIDE;
    109108
    110 protected:
     109  protected:
    111110    /*!
    112       \brief Render an image
     111       \brief Render an image
    113112
    114       An implementation of render() might iterate over all
    115       pixels of imageRect. Each pixel has to be translated into
    116       the corresponding position in scale coordinates using the maps.
    117       This position can be used to look up a value in a implementation
    118       specific way and to map it into a color.
     113       An implementation of render() might iterate over all
     114       pixels of imageRect. Each pixel has to be translated into
     115       the corresponding position in scale coordinates using the maps.
     116       This position can be used to look up a value in a implementation
     117       specific way and to map it into a color.
    119118
    120       \param xMap X-Scale Map
    121       \param yMap Y-Scale Map
    122       \param area Requested area for the image in scale coordinates
    123       \param imageSize Requested size of the image
     119       \param xMap X-Scale Map
     120       \param yMap Y-Scale Map
     121       \param area Requested area for the image in scale coordinates
     122       \param imageSize Requested size of the image
    124123
    125       \return Rendered image
     124       \return Rendered image
    126125     */
    127     virtual QImage renderImage( const QwtScaleMap &xMap,
    128         const QwtScaleMap &yMap, const QRectF &area,
    129         const QSize &imageSize ) const = 0;
     126    virtual QImage renderImage( const QwtScaleMap& xMap,
     127        const QwtScaleMap& yMap, const QRectF& area,
     128        const QSize& imageSize ) const = 0;
    130129
    131130    virtual QwtScaleMap imageMap( Qt::Orientation,
    132         const QwtScaleMap &map, const QRectF &area,
    133         const QSize &imageSize, double pixelSize) const;
     131        const QwtScaleMap& map, const QRectF& area,
     132        const QSize& imageSize, double pixelSize) const;
    134133
    135 private:
    136     QwtPlotRasterItem( const QwtPlotRasterItem & );
    137     QwtPlotRasterItem &operator=( const QwtPlotRasterItem & );
     134  private:
     135    explicit QwtPlotRasterItem( const QwtPlotRasterItem& );
     136    QwtPlotRasterItem& operator=( const QwtPlotRasterItem& );
    138137
    139138    void init();
    140139
    141     QImage compose( const QwtScaleMap &, const QwtScaleMap &,
    142         const QRectF &imageArea, const QRectF &paintRect,
    143         const QSize &imageSize, bool doCache) const;
     140    QImage compose( const QwtScaleMap&, const QwtScaleMap&,
     141        const QRectF& imageArea, const QRectF& paintRect,
     142        const QSize& imageSize, bool doCache) const;
    144143
    145144
    146145    class PrivateData;
    147     PrivateData *d_data;
     146    PrivateData* m_data;
    148147};
    149148
  • trunk/BNC/qwt/qwt_plot_renderer.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    2828#include <qimagewriter.h>
    2929#include <qvariant.h>
     30#include <qmargins.h>
    3031
    3132#ifndef QWT_NO_SVG
    3233#ifdef QT_SVG_LIB
    33 #if QT_VERSION >= 0x040500
    3434#define QWT_FORMAT_SVG 1
    35 #endif
    3635#endif
    3736#endif
    … …  
    7372#endif
    7473
     74static qreal qwtScalePenWidth( const QwtPlot* plot )
     75{
     76    qreal pw = 0.0;
     77
     78    for ( int axisId = 0; axisId < QwtAxis::AxisPositions; axisId++ )
     79    {
     80        if ( plot->isAxisVisible( axisId ) )
     81            pw = qMax( pw, plot->axisScaleDraw( axisId )->penWidthF() );
     82    }
     83
     84    return pw;
     85}
     86
     87static QColor qwtScalePenColor( const QwtPlot* plot )
     88{
     89    const QPalette pal = plot->axisWidget( QwtAxis::YLeft )->palette();
     90    return pal.color( QPalette::WindowText );
     91}
     92
    7593static QPainterPath qwtCanvasClip(
    76     const QWidget* canvas, const QRectF &canvasRect )
     94    const QWidget* canvas, const QRectF& canvasRect )
    7795{
    7896    // The clip region is calculated in integers
    … …  
    8098    // calculate it in target device resolution
    8199
    82     int x1 = qCeil( canvasRect.left() );
    83     int x2 = qFloor( canvasRect.right() );
    84     int y1 = qCeil( canvasRect.top() );
    85     int y2 = qFloor( canvasRect.bottom() );
     100    int x1 = qwtCeil( canvasRect.left() );
     101    int x2 = qwtFloor( canvasRect.right() );
     102    int y1 = qwtCeil( canvasRect.top() );
     103    int y2 = qwtFloor( canvasRect.bottom() );
    86104
    87105    const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 );
    … …  
    90108
    91109    ( void ) QMetaObject::invokeMethod(
    92         const_cast< QWidget *>( canvas ), "borderPath",
     110        const_cast< QWidget* >( canvas ), "borderPath",
    93111        Qt::DirectConnection,
    94112        Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) );
    … …  
    97115}
    98116
    99 static inline QFont qwtResolvedFont( const QWidget *widget )
     117static inline QFont qwtResolvedFont( const QWidget* widget )
    100118{
    101119    QFont font = widget->font();
     120#if QT_VERSION >= 0x060000
     121    font.setResolveMask( QFont::AllPropertiesResolved );
     122#else
    102123    font.resolve( QFont::AllPropertiesResolved );
     124#endif
    103125
    104126    return font;
    … …  
    107129class QwtPlotRenderer::PrivateData
    108130{
    109 public:
    110     PrivateData():
    111         discardFlags( QwtPlotRenderer::DiscardNone ),
    112         layoutFlags( QwtPlotRenderer::DefaultLayout )
     131  public:
     132    PrivateData()
     133        : discardFlags( QwtPlotRenderer::DiscardNone )
     134        , layoutFlags( QwtPlotRenderer::DefaultLayout )
    113135    {
    114136    }
    … …  
    121143   Constructor
    122144   \param parent Parent object
    123 */
    124 QwtPlotRenderer::QwtPlotRenderer( QObject *parent ):
    125     QObject( parent )
    126 {
    127     d_data = new PrivateData;
     145 */
     146QwtPlotRenderer::QwtPlotRenderer( QObject* parent )
     147    : QObject( parent )
     148{
     149    m_data = new PrivateData;
    128150}
    129151
    … …  
    131153QwtPlotRenderer::~QwtPlotRenderer()
    132154{
    133     delete d_data;
    134 }
    135 
    136 /*!
    137   Change a flag, indicating what to discard from rendering
    138 
    139   \param flag Flag to change
    140   \param on On/Off
    141 
    142   \sa DiscardFlag, testDiscardFlag(), setDiscardFlags(), discardFlags()
    143 */
     155    delete m_data;
     156}
     157
     158/*!
     159   Change a flag, indicating what to discard from rendering
     160
     161   \param flag Flag to change
     162   \param on On/Off
     163
     164   \sa DiscardFlag, testDiscardFlag(), setDiscardFlags(), discardFlags()
     165 */
    144166void QwtPlotRenderer::setDiscardFlag( DiscardFlag flag, bool on )
    145167{
    146168    if ( on )
    147         d_data->discardFlags |= flag;
     169        m_data->discardFlags |= flag;
    148170    else
    149         d_data->discardFlags &= ~flag;
    150 }
    151 
    152 /*!
    153   \return True, if flag is enabled.
    154   \param flag Flag to be tested
    155   \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags()
    156 */
     171        m_data->discardFlags &= ~flag;
     172}
     173
     174/*!
     175   \return True, if flag is enabled.
     176   \param flag Flag to be tested
     177   \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags()
     178 */
    157179bool QwtPlotRenderer::testDiscardFlag( DiscardFlag flag ) const
    158180{
    159     return d_data->discardFlags & flag;
    160 }
    161 
    162 /*!
    163   Set the flags, indicating what to discard from rendering
    164 
    165   \param flags Flags
    166   \sa DiscardFlag, setDiscardFlag(), testDiscardFlag(), discardFlags()
    167 */
     181    return m_data->discardFlags & flag;
     182}
     183
     184/*!
     185   Set the flags, indicating what to discard from rendering
     186
     187   \param flags Flags
     188   \sa DiscardFlag, setDiscardFlag(), testDiscardFlag(), discardFlags()
     189 */
    168190void QwtPlotRenderer::setDiscardFlags( DiscardFlags flags )
    169191{
    170     d_data->discardFlags = flags;
    171 }
    172 
    173 /*!
    174   \return Flags, indicating what to discard from rendering
    175   \sa DiscardFlag, setDiscardFlags(), setDiscardFlag(), testDiscardFlag()
    176 */
     192    m_data->discardFlags = flags;
     193}
     194
     195/*!
     196   \return Flags, indicating what to discard from rendering
     197   \sa DiscardFlag, setDiscardFlags(), setDiscardFlag(), testDiscardFlag()
     198 */
    177199QwtPlotRenderer::DiscardFlags QwtPlotRenderer::discardFlags() const
    178200{
    179     return d_data->discardFlags;
    180 }
    181 
    182 /*!
    183   Change a layout flag
    184 
    185   \param flag Flag to change
    186   \param on On/Off
    187 
    188   \sa LayoutFlag, testLayoutFlag(), setLayoutFlags(), layoutFlags()
    189 */
     201    return m_data->discardFlags;
     202}
     203
     204/*!
     205   Change a layout flag
     206
     207   \param flag Flag to change
     208   \param on On/Off
     209
     210   \sa LayoutFlag, testLayoutFlag(), setLayoutFlags(), layoutFlags()
     211 */
    190212void QwtPlotRenderer::setLayoutFlag( LayoutFlag flag, bool on )
    191213{
    192214    if ( on )
    193         d_data->layoutFlags |= flag;
     215        m_data->layoutFlags |= flag;
    194216    else
    195         d_data->layoutFlags &= ~flag;
    196 }
    197 
    198 /*!
    199   \return True, if flag is enabled.
    200   \param flag Flag to be tested
    201   \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags()
    202 */
     217        m_data->layoutFlags &= ~flag;
     218}
     219
     220/*!
     221   \return True, if flag is enabled.
     222   \param flag Flag to be tested
     223   \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags()
     224 */
    203225bool QwtPlotRenderer::testLayoutFlag( LayoutFlag flag ) const
    204226{
    205     return d_data->layoutFlags & flag;
    206 }
    207 
    208 /*!
    209   Set the layout flags
    210 
    211   \param flags Flags
    212   \sa LayoutFlag, setLayoutFlag(), testLayoutFlag(), layoutFlags()
    213 */
     227    return m_data->layoutFlags & flag;
     228}
     229
     230/*!
     231   Set the layout flags
     232
     233   \param flags Flags
     234   \sa LayoutFlag, setLayoutFlag(), testLayoutFlag(), layoutFlags()
     235 */
    214236void QwtPlotRenderer::setLayoutFlags( LayoutFlags flags )
    215237{
    216     d_data->layoutFlags = flags;
    217 }
    218 
    219 /*!
    220   \return Layout flags
    221   \sa LayoutFlag, setLayoutFlags(), setLayoutFlag(), testLayoutFlag()
    222 */
     238    m_data->layoutFlags = flags;
     239}
     240
     241/*!
     242   \return Layout flags
     243   \sa LayoutFlag, setLayoutFlags(), setLayoutFlag(), testLayoutFlag()
     244 */
    223245QwtPlotRenderer::LayoutFlags QwtPlotRenderer::layoutFlags() const
    224246{
    225     return d_data->layoutFlags;
    226 }
    227 
    228 /*!
    229   Render a plot to a file
    230 
    231   The format of the document will be auto-detected from the
    232   suffix of the file name.
    233 
    234   \param plot Plot widget
    235   \param fileName Path of the file, where the document will be stored
    236   \param sizeMM Size for the document in millimeters.
    237   \param resolution Resolution in dots per Inch (dpi)
    238 */
    239 void QwtPlotRenderer::renderDocument( QwtPlot *plot,
    240     const QString &fileName, const QSizeF &sizeMM, int resolution )
     247    return m_data->layoutFlags;
     248}
     249
     250/*!
     251   Render a plot to a file
     252
     253   The format of the document will be auto-detected from the
     254   suffix of the file name.
     255
     256   \param plot Plot widget
     257   \param fileName Path of the file, where the document will be stored
     258   \param sizeMM Size for the document in millimeters.
     259   \param resolution Resolution in dots per Inch (dpi)
     260 */
     261void QwtPlotRenderer::renderDocument( QwtPlot* plot,
     262    const QString& fileName, const QSizeF& sizeMM, int resolution )
    241263{
    242264    renderDocument( plot, fileName,
    … …  
    245267
    246268/*!
    247   Render a plot to a file
    248 
    249   Supported formats are:
    250 
    251   - pdf\n
     269   Render a plot to a file
     270
     271   Supported formats are:
     272
     273   - pdf\n
    252274    Portable Document Format PDF
    253   - ps\n
     275   - ps\n
    254276    Postcript
    255   - svg\n
     277   - svg\n
    256278    Scalable Vector Graphics SVG
    257   - all image formats supported by Qt\n
     279   - all image formats supported by Qt\n
    258280    see QImageWriter::supportedImageFormats()
    259281
    260   Scalable vector graphic formats like PDF or SVG are superior to
    261   raster graphics formats.
    262 
    263   \param plot Plot widget
    264   \param fileName Path of the file, where the document will be stored
    265   \param format Format for the document
    266   \param sizeMM Size for the document in millimeters.
    267   \param resolution Resolution in dots per Inch (dpi)
    268 
    269   \sa renderTo(), render(), QwtPainter::setRoundingAlignment()
    270 */
    271 void QwtPlotRenderer::renderDocument( QwtPlot *plot,
    272     const QString &fileName, const QString &format,
    273     const QSizeF &sizeMM, int resolution )
     282   Scalable vector graphic formats like PDF or SVG are superior to
     283   raster graphics formats.
     284
     285   \param plot Plot widget
     286   \param fileName Path of the file, where the document will be stored
     287   \param format Format for the document
     288   \param sizeMM Size for the document in millimeters.
     289   \param resolution Resolution in dots per Inch (dpi)
     290
     291   \sa renderTo(), render(), QwtPainter::setRoundingAlignment()
     292 */
     293void QwtPlotRenderer::renderDocument( QwtPlot* plot,
     294    const QString& fileName, const QString& format,
     295    const QSizeF& sizeMM, int resolution )
    274296{
    275297    if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 )
    … …  
    292314#if QWT_PDF_WRITER
    293315        QPdfWriter pdfWriter( fileName );
    294         pdfWriter.setPageSizeMM( sizeMM );
     316        pdfWriter.setPageSize( QPageSize( sizeMM, QPageSize::Millimeter ) );
    295317        pdfWriter.setTitle( title );
    296318        pdfWriter.setPageMargins( QMarginsF() );
    … …  
    366388
    367389/*!
    368   \brief Render the plot to a \c QPaintDevice
    369 
    370   This function renders the contents of a QwtPlot instance to
    371   \c QPaintDevice object. The target rectangle is derived from
    372   its device metrics.
    373 
    374   \param plot Plot to be rendered
    375   \param paintDevice device to paint on, f.e a QImage
    376 
    377   \sa renderDocument(), render(), QwtPainter::setRoundingAlignment()
    378 */
     390   \brief Render the plot to a \c QPaintDevice
     391
     392   This function renders the contents of a QwtPlot instance to
     393   \c QPaintDevice object. The target rectangle is derived from
     394   its device metrics.
     395
     396   \param plot Plot to be rendered
     397   \param paintDevice device to paint on, f.e a QImage
     398
     399   \sa renderDocument(), render(), QwtPainter::setRoundingAlignment()
     400 */
    379401
    380402void QwtPlotRenderer::renderTo(
    381     QwtPlot *plot, QPaintDevice &paintDevice ) const
     403    QwtPlot* plot, QPaintDevice& paintDevice ) const
    382404{
    383405    int w = paintDevice.width();
    … …  
    389411
    390412/*!
    391   \brief Render the plot to a QPrinter
    392 
    393   This function renders the contents of a QwtPlot instance to
    394   \c QPaintDevice object. The size is derived from the printer
    395   metrics.
    396 
    397   \param plot Plot to be rendered
    398   \param printer Printer to paint on
    399 
    400   \sa renderDocument(), render(), QwtPainter::setRoundingAlignment()
    401 */
     413   \brief Render the plot to a QPrinter
     414
     415   This function renders the contents of a QwtPlot instance to
     416   \c QPaintDevice object. The size is derived from the printer
     417   metrics.
     418
     419   \param plot Plot to be rendered
     420   \param printer Printer to paint on
     421
     422   \sa renderDocument(), render(), QwtPainter::setRoundingAlignment()
     423 */
    402424
    403425#ifndef QT_NO_PRINTER
    404426
    405427void QwtPlotRenderer::renderTo(
    406     QwtPlot *plot, QPrinter &printer ) const
     428    QwtPlot* plot, QPrinter& printer ) const
    407429{
    408430    int w = printer.width();
    … …  
    423445
    424446/*!
    425   \brief Render the plot to a QSvgGenerator
    426 
    427   If the generator has a view box, the plot will be rendered into it.
    428   If it has no viewBox but a valid size the target coordinates
    429   will be (0, 0, generator.width(), generator.height()). Otherwise
    430   the target rectangle will be QRectF(0, 0, 800, 600);
    431 
    432   \param plot Plot to be rendered
    433   \param generator SVG generator
    434 */
     447   \brief Render the plot to a QSvgGenerator
     448
     449   If the generator has a view box, the plot will be rendered into it.
     450   If it has no viewBox but a valid size the target coordinates
     451   will be (0, 0, generator.width(), generator.height()). Otherwise
     452   the target rectangle will be QRectF(0, 0, 800, 600);
     453
     454   \param plot Plot to be rendered
     455   \param generator SVG generator
     456 */
    435457void QwtPlotRenderer::renderTo(
    436     QwtPlot *plot, QSvgGenerator &generator ) const
     458    QwtPlot* plot, QSvgGenerator& generator ) const
    437459{
    438460    QRectF rect = generator.viewBoxF();
    … …  
    450472
    451473/*!
    452   Paint the contents of a QwtPlot instance into a given rectangle.
    453 
    454   \param plot Plot to be rendered
    455   \param painter Painter
    456   \param plotRect Bounding rectangle
    457 
    458   \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment()
    459 */
    460 void QwtPlotRenderer::render( QwtPlot *plot,
    461     QPainter *painter, const QRectF &plotRect ) const
     474   Paint the contents of a QwtPlot instance into a given rectangle.
     475
     476   \param plot Plot to be rendered
     477   \param painter Painter
     478   \param plotRect Bounding rectangle
     479
     480   \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment()
     481 */
     482void QwtPlotRenderer::render( QwtPlot* plot,
     483    QPainter* painter, const QRectF& plotRect ) const
    462484{
    463485    if ( painter == 0 || !painter->isActive() ||
    464             !plotRect.isValid() || plot->size().isNull() )
     486        !plotRect.isValid() || plot->size().isNull() )
    465487    {
    466488        return;
    467489    }
    468490
    469     if ( !( d_data->discardFlags & DiscardBackground ) )
     491    if ( !( m_data->discardFlags & DiscardBackground ) )
    470492        QwtPainter::drawBackgound( painter, plotRect, plot );
    471493
    472494    /*
    473       The layout engine uses the same methods as they are used
    474       by the Qt layout system. Therefore we need to calculate the
    475       layout in screen coordinates and paint with a scaled painter.
     495       The layout engine uses the same methods as they are used
     496       by the Qt layout system. Therefore we need to calculate the
     497       layout in screen coordinates and paint with a scaled painter.
    476498     */
    477499    QTransform transform;
    … …  
    482504    QRectF layoutRect = transform.inverted().mapRect( plotRect );
    483505
    484     if ( !( d_data->discardFlags & DiscardBackground ) )
     506    if ( !( m_data->discardFlags & DiscardBackground ) )
    485507    {
    486508        // subtract the contents margins
    487509
    488         int left, top, right, bottom;
    489         plot->getContentsMargins( &left, &top, &right, &bottom );
    490         layoutRect.adjust( left, top, -right, -bottom );
    491     }
    492 
    493     QwtPlotLayout *layout = plot->plotLayout();
    494 
    495     int baseLineDists[QwtPlot::axisCnt];
    496     int canvasMargins[QwtPlot::axisCnt];
    497 
    498     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    499     {
    500         canvasMargins[ axisId ] = layout->canvasMargin( axisId );
    501 
    502         if ( d_data->layoutFlags & FrameWithScales )
    503         {
    504             QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
     510        const QMargins m = plot->contentsMargins();
     511        layoutRect.adjust( m.left(), m.top(), -m.right(), -m.bottom() );
     512    }
     513
     514    QwtPlotLayout* layout = plot->plotLayout();
     515
     516    int baseLineDists[QwtAxis::AxisPositions];
     517    int canvasMargins[QwtAxis::AxisPositions];
     518
     519    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     520    {
     521        canvasMargins[axisPos] = layout->canvasMargin( axisPos );
     522
     523        if ( m_data->layoutFlags & FrameWithScales )
     524        {
     525            const QwtAxisId axisId( axisPos );
     526
     527            QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
    505528            if ( scaleWidget )
    506529            {
    507                 baseLineDists[axisId] = scaleWidget->margin();
     530                baseLineDists[axisPos] = scaleWidget->margin();
    508531                scaleWidget->setMargin( 0 );
    509532            }
    510533
    511             if ( !plot->axisEnabled( axisId ) )
     534            if ( !plot->isAxisVisible( axisId ) )
    512535            {
    513536                // When we have a scale the frame is painted on
    … …  
    515538                // need to introduce a margin around the canvas
    516539
    517                 switch( axisId )
     540                const qreal fw = qwtScalePenWidth( plot );
     541
     542                switch( axisPos )
    518543                {
    519                     case QwtPlot::yLeft:
    520                         layoutRect.adjust( 1, 0, 0, 0 );
     544                    case QwtAxis::YLeft:
     545                        layoutRect.adjust( fw, 0, 0, 0 );
    521546                        break;
    522                     case QwtPlot::yRight:
    523                         layoutRect.adjust( 0, 0, -1, 0 );
     547
     548                    case QwtAxis::YRight:
     549                        layoutRect.adjust( 0, 0, -fw, 0 );
    524550                        break;
    525                     case QwtPlot::xTop:
    526                         layoutRect.adjust( 0, 1, 0, 0 );
     551
     552                    case QwtAxis::XTop:
     553                        layoutRect.adjust( 0, fw, 0, 0 );
    527554                        break;
    528                     case QwtPlot::xBottom:
    529                         layoutRect.adjust( 0, 0, 0, -1 );
     555
     556                    case QwtAxis::XBottom:
     557                        layoutRect.adjust( 0, 0, 0, -fw );
    530558                        break;
     559
    531560                    default:
    532                         break;
     561                        ;
    533562                }
    534563            }
    … …  
    540569    QwtPlotLayout::Options layoutOptions = QwtPlotLayout::IgnoreScrollbars;
    541570
    542     if ( ( d_data->layoutFlags & FrameWithScales ) ||
    543         ( d_data->discardFlags & DiscardCanvasFrame ) )
     571    if ( ( m_data->layoutFlags & FrameWithScales ) ||
     572        ( m_data->discardFlags & DiscardCanvasFrame ) )
    544573    {
    545574        layoutOptions |= QwtPlotLayout::IgnoreFrames;
    546575    }
    547576
    548     if ( d_data->discardFlags & DiscardLegend )
     577    if ( m_data->discardFlags & DiscardLegend )
    549578        layoutOptions |= QwtPlotLayout::IgnoreLegend;
    550579
    551     if ( d_data->discardFlags & DiscardTitle )
     580    if ( m_data->discardFlags & DiscardTitle )
    552581        layoutOptions |= QwtPlotLayout::IgnoreTitle;
    553582
    554     if ( d_data->discardFlags & DiscardFooter )
     583    if ( m_data->discardFlags & DiscardFooter )
    555584        layoutOptions |= QwtPlotLayout::IgnoreFooter;
    556585
    … …  
    559588    // canvas
    560589
    561     QwtScaleMap maps[QwtPlot::axisCnt];
     590    QwtScaleMap maps[QwtAxis::AxisPositions];
    562591    buildCanvasMaps( plot, layout->canvasRect(), maps );
    563592    if ( updateCanvasMargins( plot, layout->canvasRect(), maps ) )
    … …  
    577606    renderCanvas( plot, painter, layout->canvasRect(), maps );
    578607
    579     if ( !( d_data->discardFlags & DiscardTitle )
     608    if ( !( m_data->discardFlags & DiscardTitle )
    580609        && ( !plot->titleLabel()->text().isEmpty() ) )
    581610    {
    … …  
    583612    }
    584613
    585     if ( !( d_data->discardFlags & DiscardFooter )
     614    if ( !( m_data->discardFlags & DiscardFooter )
    586615        && ( !plot->footerLabel()->text().isEmpty() ) )
    587616    {
    … …  
    589618    }
    590619
    591     if ( !( d_data->discardFlags & DiscardLegend )
     620    if ( !( m_data->discardFlags & DiscardLegend )
    592621        && plot->legend() && !plot->legend()->isEmpty() )
    593622    {
    … …  
    595624    }
    596625
    597     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    598     {
    599         QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
    600         if ( scaleWidget )
    601         {
    602             int baseDist = scaleWidget->margin();
    603 
    604             int startDist, endDist;
    605             scaleWidget->getBorderDistHint( startDist, endDist );
    606 
    607             renderScale( plot, painter, axisId, startDist, endDist,
    608                 baseDist, layout->scaleRect( axisId ) );
     626    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     627    {
     628        {
     629            const QwtAxisId axisId( axisPos );
     630
     631            QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
     632            if ( scaleWidget )
     633            {
     634                int baseDist = scaleWidget->margin();
     635
     636                int startDist, endDist;
     637                scaleWidget->getBorderDistHint( startDist, endDist );
     638
     639                renderScale( plot, painter, axisId, startDist, endDist,
     640                    baseDist, layout->scaleRect( axisId ) );
     641            }
    609642        }
    610643    }
    … …  
    613646
    614647    // restore all setting to their original attributes.
    615     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    616     {
    617         if ( d_data->layoutFlags & FrameWithScales )
    618         {
    619             QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
     648    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     649    {
     650        if ( m_data->layoutFlags & FrameWithScales )
     651        {
     652            const QwtAxisId axisId( axisPos );
     653
     654            QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
    620655            if ( scaleWidget  )
    621                 scaleWidget->setMargin( baseLineDists[axisId] );
    622         }
    623 
    624         layout->setCanvasMargin( canvasMargins[axisId] );
     656                scaleWidget->setMargin( baseLineDists[axisPos] );
     657        }
     658
     659        layout->setCanvasMargin( canvasMargins[axisPos] );
    625660    }
    626661
    … …  
    630665
    631666/*!
    632   Render the title into a given rectangle.
    633 
    634   \param plot Plot widget
    635   \param painter Painter
    636   \param titleRect Bounding rectangle for the title
    637 */
    638 void QwtPlotRenderer::renderTitle( const QwtPlot *plot,
    639     QPainter *painter, const QRectF &titleRect ) const
     667   Render the title into a given rectangle.
     668
     669   \param plot Plot widget
     670   \param painter Painter
     671   \param titleRect Bounding rectangle for the title
     672 */
     673void QwtPlotRenderer::renderTitle( const QwtPlot* plot,
     674    QPainter* painter, const QRectF& titleRect ) const
    640675{
    641676    painter->setFont( qwtResolvedFont( plot->titleLabel() ) );
    642677
    643678    const QColor color = plot->titleLabel()->palette().color(
    644             QPalette::Active, QPalette::Text );
     679        QPalette::Active, QPalette::Text );
    645680
    646681    painter->setPen( color );
    … …  
    649684
    650685/*!
    651   Render the footer into a given rectangle.
    652 
    653   \param plot Plot widget
    654   \param painter Painter
    655   \param footerRect Bounding rectangle for the footer
    656 */
    657 void QwtPlotRenderer::renderFooter( const QwtPlot *plot,
    658     QPainter *painter, const QRectF &footerRect ) const
     686   Render the footer into a given rectangle.
     687
     688   \param plot Plot widget
     689   \param painter Painter
     690   \param footerRect Bounding rectangle for the footer
     691 */
     692void QwtPlotRenderer::renderFooter( const QwtPlot* plot,
     693    QPainter* painter, const QRectF& footerRect ) const
    659694{
    660695    painter->setFont( qwtResolvedFont( plot->footerLabel() ) );
    661696
    662697    const QColor color = plot->footerLabel()->palette().color(
    663             QPalette::Active, QPalette::Text );
     698        QPalette::Active, QPalette::Text );
    664699
    665700    painter->setPen( color );
    … …  
    668703
    669704/*!
    670   Render the legend into a given rectangle.
    671 
    672   \param plot Plot widget
    673   \param painter Painter
    674   \param legendRect Bounding rectangle for the legend
    675 */
    676 void QwtPlotRenderer::renderLegend( const QwtPlot *plot,
    677     QPainter *painter, const QRectF &legendRect ) const
     705   Render the legend into a given rectangle.
     706
     707   \param plot Plot widget
     708   \param painter Painter
     709   \param legendRect Bounding rectangle for the legend
     710 */
     711void QwtPlotRenderer::renderLegend( const QwtPlot* plot,
     712    QPainter* painter, const QRectF& legendRect ) const
    678713{
    679714    if ( plot->legend() )
    680715    {
    681         bool fillBackground = !( d_data->discardFlags & DiscardBackground );
     716        bool fillBackground = !( m_data->discardFlags & DiscardBackground );
    682717        plot->legend()->renderLegend( painter, legendRect, fillBackground );
    683718    }
    … …  
    685720
    686721/*!
    687   \brief Paint a scale into a given rectangle.
    688   Paint the scale into a given rectangle.
    689 
    690   \param plot Plot widget
    691   \param painter Painter
    692   \param axisId Axis
    693   \param startDist Start border distance
    694   \param endDist End border distance
    695   \param baseDist Base distance
    696   \param scaleRect Bounding rectangle for the scale
    697 */
    698 void QwtPlotRenderer::renderScale( const QwtPlot *plot,
    699     QPainter *painter,
    700     int axisId, int startDist, int endDist, int baseDist,
    701     const QRectF &scaleRect ) const
    702 {
    703     if ( !plot->axisEnabled( axisId ) )
     722   \brief Paint a scale into a given rectangle.
     723   Paint the scale into a given rectangle.
     724
     725   \param plot Plot widget
     726   \param painter Painter
     727   \param axisId Axis
     728   \param startDist Start border distance
     729   \param endDist End border distance
     730   \param baseDist Base distance
     731   \param scaleRect Bounding rectangle for the scale
     732 */
     733void QwtPlotRenderer::renderScale( const QwtPlot* plot, QPainter* painter,
     734    QwtAxisId axisId, int startDist, int endDist, int baseDist,
     735    const QRectF& scaleRect ) const
     736{
     737    if ( !plot->isAxisVisible( axisId ) )
    704738        return;
    705739
    706     const QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
     740    const QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
    707741    if ( scaleWidget->isColorBarEnabled()
    708742        && scaleWidget->colorBarWidth() > 0 )
    … …  
    717751    double x, y, w;
    718752
     753    qreal off = 0.0;
     754    if ( m_data->layoutFlags & FrameWithScales )
     755        off = qwtScalePenWidth( plot );
     756
    719757    switch ( axisId )
    720758    {
    721         case QwtPlot::yLeft:
    722         {
    723             x = scaleRect.right() - 1.0 - baseDist;
     759        case QwtAxis::YLeft:
     760        {
     761            x = scaleRect.right() - 1.0 - baseDist - off;
    724762            y = scaleRect.y() + startDist;
    725763            w = scaleRect.height() - startDist - endDist;
    … …  
    727765            break;
    728766        }
    729         case QwtPlot::yRight:
    730         {
    731             x = scaleRect.left() + baseDist;
     767        case QwtAxis::YRight:
     768        {
     769            x = scaleRect.left() + baseDist + off;
    732770            y = scaleRect.y() + startDist;
    733771            w = scaleRect.height() - startDist - endDist;
    … …  
    735773            break;
    736774        }
    737         case QwtPlot::xTop:
     775        case QwtAxis::XTop:
    738776        {
    739777            x = scaleRect.left() + startDist;
    740             y = scaleRect.bottom() - 1.0 - baseDist;
     778            y = scaleRect.bottom() - 1.0 - baseDist - off;
    741779            w = scaleRect.width() - startDist - endDist;
    742780            align = QwtScaleDraw::TopScale;
    743781            break;
    744782        }
    745         case QwtPlot::xBottom:
     783        case QwtAxis::XBottom:
    746784        {
    747785            x = scaleRect.left() + startDist;
    748             y = scaleRect.top() + baseDist;
     786            y = scaleRect.top() + baseDist + off;
    749787            w = scaleRect.width() - startDist - endDist;
    750788            align = QwtScaleDraw::BottomScale;
    … …  
    759797    painter->setFont( qwtResolvedFont( scaleWidget ) );
    760798
    761     QwtScaleDraw *sd = const_cast<QwtScaleDraw *>( scaleWidget->scaleDraw() );
     799    QwtScaleDraw* sd = const_cast< QwtScaleDraw* >( scaleWidget->scaleDraw() );
    762800    const QPointF sdPos = sd->pos();
    763801    const double sdLength = sd->length();
     802
     803    const bool hasBackbone = sd->hasComponent( QwtAbstractScaleDraw::Backbone );
     804
     805    if ( m_data->layoutFlags & FrameWithScales )
     806        sd->enableComponent( QwtAbstractScaleDraw::Backbone, false );
    764807
    765808    sd->move( x, y );
    … …  
    773816    sd->move( sdPos );
    774817    sd->setLength( sdLength );
     818    sd->enableComponent( QwtAbstractScaleDraw::Backbone, hasBackbone );
    775819
    776820    painter->restore();
    … …  
    778822
    779823/*!
    780   Render the canvas into a given rectangle.
    781 
    782   \param plot Plot widget
    783   \param painter Painter
    784   \param maps Maps mapping between plot and paint device coordinates
    785   \param canvasRect Canvas rectangle
    786 */
    787 void QwtPlotRenderer::renderCanvas( const QwtPlot *plot,
    788     QPainter *painter, const QRectF &canvasRect,
    789     const QwtScaleMap *maps ) const
    790 {
    791     const QWidget *canvas = plot->canvas();
     824   Render the canvas into a given rectangle.
     825
     826   \param plot Plot widget
     827   \param painter Painter
     828   \param maps Maps mapping between plot and paint device coordinates
     829   \param canvasRect Canvas rectangle
     830 */
     831void QwtPlotRenderer::renderCanvas( const QwtPlot* plot,
     832    QPainter* painter, const QRectF& canvasRect,
     833    const QwtScaleMap* maps ) const
     834{
     835    const QWidget* canvas = plot->canvas();
    792836
    793837    QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 );
    794838
    795     if ( d_data->layoutFlags & FrameWithScales )
     839    if ( m_data->layoutFlags & FrameWithScales )
    796840    {
    797841        painter->save();
    798842
    799         r.adjust( -1.0, -1.0, 1.0, 1.0 );
    800         painter->setPen( QPen( Qt::black ) );
    801 
    802         if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
     843        QPen pen;
     844        pen.setColor( qwtScalePenColor( plot ) );
     845        pen.setWidth( qwtScalePenWidth( plot ) );
     846        pen.setJoinStyle( Qt::MiterJoin );
     847
     848        painter->setPen( pen );
     849
     850        const qreal pw2 = 0.5 * pen.widthF();
     851        r.adjust( -pw2, -pw2, pw2, pw2 );
     852
     853        if ( !( m_data->discardFlags & DiscardCanvasBackground ) )
    803854        {
    804855            const QBrush bgBrush =
    … …  
    823874        painter->save();
    824875
    825         if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
     876        if ( !( m_data->discardFlags & DiscardCanvasBackground ) )
    826877        {
    827878            QwtPainter::drawBackgound( painter, r, canvas );
    … …  
    845896        QPainterPath clipPath;
    846897
    847         int frameWidth = 0;
    848 
    849         if ( !( d_data->discardFlags & DiscardCanvasFrame ) )
     898        double frameWidth = 0.0;
     899
     900        if ( !( m_data->discardFlags & DiscardCanvasFrame ) )
    850901        {
    851902            const QVariant fw = canvas->property( "frameWidth" );
    852             if ( fw.type() == QVariant::Int )
    853                 frameWidth = fw.toInt();
     903            if ( fw.canConvert< double >() )
     904                frameWidth = fw.value< double >();
    854905
    855906            clipPath = qwtCanvasClip( canvas, canvasRect );
    … …  
    870921        }
    871922
    872         if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
     923        if ( !( m_data->discardFlags & DiscardCanvasBackground ) )
    873924        {
    874925            QwtPainter::drawBackgound( painter, innerRect, canvas );
    … …  
    888939
    889940            const QVariant borderRadius = canvas->property( "borderRadius" );
    890             if ( borderRadius.type() == QVariant::Double
    891                 && borderRadius.toDouble() > 0.0 )
     941            if ( borderRadius.canConvert< double >()
     942                && borderRadius.value< double >() > 0.0 )
    892943            {
    893                 const double radius = borderRadius.toDouble();
     944                const double radius = borderRadius.value< double >();
    894945
    895946                QwtPainter::drawRoundedFrame( painter, canvasRect,
    … …  
    915966   \param canvasRect Target rectangle
    916967   \param maps Scale maps to be calculated
    917 */
    918 void QwtPlotRenderer::buildCanvasMaps( const QwtPlot *plot,
    919     const QRectF &canvasRect, QwtScaleMap maps[] ) const
    920 {
    921     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    922     {
    923         maps[axisId].setTransformation(
    924             plot->axisScaleEngine( axisId )->transformation() );
    925 
    926         const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId );
    927         maps[axisId].setScaleInterval(
    928             scaleDiv.lowerBound(), scaleDiv.upperBound() );
    929 
    930         double from, to;
    931         if ( plot->axisEnabled( axisId ) )
    932         {
    933             const int sDist = plot->axisWidget( axisId )->startBorderDist();
    934             const int eDist = plot->axisWidget( axisId )->endBorderDist();
    935             const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );
    936 
    937             if ( axisId == QwtPlot::xTop || axisId == QwtPlot::xBottom )
     968 */
     969void QwtPlotRenderer::buildCanvasMaps( const QwtPlot* plot,
     970    const QRectF& canvasRect, QwtScaleMap maps[] ) const
     971{
     972    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     973    {
     974        {
     975            const QwtAxisId axisId( axisPos );
     976
     977            QwtScaleMap& scaleMap = maps[axisId];
     978
     979            scaleMap.setTransformation(
     980                plot->axisScaleEngine( axisId )->transformation() );
     981
     982            const QwtScaleDiv& scaleDiv = plot->axisScaleDiv( axisId );
     983            scaleMap.setScaleInterval(
     984                scaleDiv.lowerBound(), scaleDiv.upperBound() );
     985
     986            double from, to;
     987            if ( plot->isAxisVisible( axisId ) )
    938988            {
    939                 from = scaleRect.left() + sDist;
    940                 to = scaleRect.right() - eDist;
     989                const int sDist = plot->axisWidget( axisId )->startBorderDist();
     990                const int eDist = plot->axisWidget( axisId )->endBorderDist();
     991                const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );
     992
     993                if ( QwtAxis::isXAxis( axisPos ) )
     994                {
     995                    from = scaleRect.left() + sDist;
     996                    to = scaleRect.right() - eDist;
     997                }
     998                else
     999                {
     1000                    from = scaleRect.bottom() - eDist;
     1001                    to = scaleRect.top() + sDist;
     1002                }
    9411003            }
    9421004            else
    9431005            {
    944                 from = scaleRect.bottom() - eDist;
    945                 to = scaleRect.top() + sDist;
     1006                int margin = 0;
     1007                if ( !plot->plotLayout()->alignCanvasToScale( axisPos ) )
     1008                    margin = plot->plotLayout()->canvasMargin( axisPos );
     1009
     1010                if ( QwtAxis::isYAxis( axisPos ) )
     1011                {
     1012                    from = canvasRect.bottom() - margin;
     1013                    to = canvasRect.top() + margin;
     1014                }
     1015                else
     1016                {
     1017                    from = canvasRect.left() + margin;
     1018                    to = canvasRect.right() - margin;
     1019                }
    9461020            }
    947         }
    948         else
    949         {
    950             int margin = 0;
    951             if ( !plot->plotLayout()->alignCanvasToScale( axisId ) )
    952                 margin = plot->plotLayout()->canvasMargin( axisId );
    953 
    954             if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight )
    955             {
    956                 from = canvasRect.bottom() - margin;
    957                 to = canvasRect.top() + margin;
    958             }
    959             else
    960             {
    961                 from = canvasRect.left() + margin;
    962                 to = canvasRect.right() - margin;
    963             }
    964         }
    965         maps[axisId].setPaintInterval( from, to );
    966     }
    967 }
    968 
    969 bool QwtPlotRenderer::updateCanvasMargins( QwtPlot *plot,
    970     const QRectF &canvasRect, const QwtScaleMap maps[] ) const
    971 {
    972     double margins[QwtPlot::axisCnt];
     1021            scaleMap.setPaintInterval( from, to );
     1022        }
     1023    }
     1024}
     1025
     1026bool QwtPlotRenderer::updateCanvasMargins( QwtPlot* plot,
     1027    const QRectF& canvasRect, const QwtScaleMap maps[] ) const
     1028{
     1029    using namespace QwtAxis;
     1030
     1031    double margins[AxisPositions];
    9731032    plot->getCanvasMarginsHint( maps, canvasRect,
    974         margins[QwtPlot::yLeft], margins[QwtPlot::xTop],
    975         margins[QwtPlot::yRight], margins[QwtPlot::xBottom] );
     1033        margins[YLeft], margins[XTop], margins[YRight], margins[XBottom] );
    9761034
    9771035    bool marginsChanged = false;
    978     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
     1036    for ( int axisId = 0; axisId < AxisPositions; axisId++ )
    9791037    {
    9801038        if ( margins[axisId] >= 0.0 )
    9811039        {
    982             const int m = qCeil( margins[axisId] );
     1040            const int m = qwtCeil( margins[axisId] );
    9831041            plot->plotLayout()->setCanvasMargin( m, axisId);
    9841042            marginsChanged = true;
    … …  
    9991057   \return True, when exporting was successful
    10001058   \sa renderDocument()
    1001 */
    1002 bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString &documentName,
    1003      const QSizeF &sizeMM, int resolution )
     1059 */
     1060bool QwtPlotRenderer::exportTo( QwtPlot* plot, const QString& documentName,
     1061    const QSizeF& sizeMM, int resolution )
    10041062{
    10051063    if ( plot == NULL )
    … …  
    10111069
    10121070#ifndef QT_NO_FILEDIALOG
    1013     const QList<QByteArray> imageFormats =
     1071    const QList< QByteArray > imageFormats =
    10141072        QImageWriter::supportedImageFormats();
    10151073
    … …  
    10521110    return true;
    10531111}
     1112
     1113#include "moc_qwt_plot_renderer.cpp"
  • trunk/BNC/qwt/qwt_plot_renderer.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
     14#include "qwt_axis_id.h"
     15
    1416#include <qobject.h>
    1517#include <qsize.h>
    … …  
    3436    \brief Renderer for exporting a plot to a document, a printer
    3537           or anything else, that is supported by QPainter/QPaintDevice
    36 */
    37 class QWT_EXPORT QwtPlotRenderer: public QObject
     38 */
     39class QWT_EXPORT QwtPlotRenderer : public QObject
    3840{
    3941    Q_OBJECT
    4042
    41 public:
    42     //! Disard flags
     43  public:
     44    //! Discard flags
    4345    enum DiscardFlag
    4446    {
    … …  
    7274    };
    7375
    74     //! Disard flags
    75     typedef QFlags<DiscardFlag> DiscardFlags;
     76    Q_DECLARE_FLAGS( DiscardFlags, DiscardFlag )
    7677
    7778    /*!
    … …  
    8586
    8687        /*!
    87           Instead of the scales a box is painted around the plot canvas,
    88           where the scale ticks are aligned to.
     88           Instead of the scales a box is painted around the plot canvas,
     89           where the scale ticks are aligned to.
    8990         */
    9091        FrameWithScales = 0x01
    9192    };
    9293
    93     //! Layout flags
    94     typedef QFlags<LayoutFlag> LayoutFlags;
     94    Q_DECLARE_FLAGS( LayoutFlags, LayoutFlag )
    9595
    96     explicit QwtPlotRenderer( QObject * = NULL );
     96    explicit QwtPlotRenderer( QObject* = NULL );
    9797    virtual ~QwtPlotRenderer();
    9898
    … …  
    109109    LayoutFlags layoutFlags() const;
    110110
    111     void renderDocument( QwtPlot *, const QString &fileName,
    112         const QSizeF &sizeMM, int resolution = 85 );
     111    void renderDocument( QwtPlot*, const QString& fileName,
     112        const QSizeF& sizeMM, int resolution = 85 );
    113113
    114     void renderDocument( QwtPlot *,
    115         const QString &fileName, const QString &format,
    116         const QSizeF &sizeMM, int resolution = 85 );
     114    void renderDocument( QwtPlot*,
     115        const QString& fileName, const QString& format,
     116        const QSizeF& sizeMM, int resolution = 85 );
    117117
    118118#ifndef QWT_NO_SVG
    119119#ifdef QT_SVG_LIB
    120 #if QT_VERSION >= 0x040500
    121     void renderTo( QwtPlot *, QSvgGenerator & ) const;
    122 #endif
     120    void renderTo( QwtPlot*, QSvgGenerator& ) const;
    123121#endif
    124122#endif
    125123
    126124#ifndef QT_NO_PRINTER
    127     void renderTo( QwtPlot *, QPrinter & ) const;
     125    void renderTo( QwtPlot*, QPrinter& ) const;
    128126#endif
    129127
    130     void renderTo( QwtPlot *, QPaintDevice & ) const;
     128    void renderTo( QwtPlot*, QPaintDevice& ) const;
    131129
    132     virtual void render( QwtPlot *,
    133         QPainter *, const QRectF &plotRect ) const;
     130    virtual void render( QwtPlot*,
     131        QPainter*, const QRectF& plotRect ) const;
    134132
    135     virtual void renderTitle( const QwtPlot *,
    136         QPainter *, const QRectF &titleRect ) const;
     133    virtual void renderTitle( const QwtPlot*,
     134        QPainter*, const QRectF& titleRect ) const;
    137135
    138     virtual void renderFooter( const QwtPlot *,
    139         QPainter *, const QRectF &footerRect ) const;
     136    virtual void renderFooter( const QwtPlot*,
     137        QPainter*, const QRectF& footerRect ) const;
    140138
    141     virtual void renderScale( const QwtPlot *, QPainter *,
    142         int axisId, int startDist, int endDist,
    143         int baseDist, const QRectF &scaleRect ) const;
     139    virtual void renderScale( const QwtPlot*, QPainter*,
     140        QwtAxisId, int startDist, int endDist,
     141        int baseDist, const QRectF& scaleRect ) const;
    144142
    145     virtual void renderCanvas( const QwtPlot *,
    146         QPainter *, const QRectF &canvasRect,
     143    virtual void renderCanvas( const QwtPlot*,
     144        QPainter*, const QRectF& canvasRect,
    147145        const QwtScaleMap* maps ) const;
    148146
    149147    virtual void renderLegend(
    150         const QwtPlot *, QPainter *, const QRectF &legendRect ) const;
     148        const QwtPlot*, QPainter*, const QRectF& legendRect ) const;
    151149
    152     bool exportTo( QwtPlot *, const QString &documentName,
    153         const QSizeF &sizeMM = QSizeF( 300, 200 ), int resolution = 85 );
     150    bool exportTo( QwtPlot*, const QString& documentName,
     151        const QSizeF& sizeMM = QSizeF( 300, 200 ), int resolution = 85 );
    154152
    155 private:
    156     void buildCanvasMaps( const QwtPlot *,
    157         const QRectF &, QwtScaleMap maps[] ) const;
     153  private:
     154    void buildCanvasMaps( const QwtPlot*,
     155        const QRectF&, QwtScaleMap maps[] ) const;
    158156
    159     bool updateCanvasMargins( QwtPlot *,
    160         const QRectF &, const QwtScaleMap maps[] ) const;
     157    bool updateCanvasMargins( QwtPlot*,
     158        const QRectF&, const QwtScaleMap maps[] ) const;
    161159
    162 private:
     160  private:
    163161    class PrivateData;
    164     PrivateData *d_data;
     162    PrivateData* m_data;
    165163};
    166164
  • 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"
  • trunk/BNC/qwt/qwt_plot_rescaler.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_PLOT_RESCALER_H
    11 #define QWT_PLOT_RESCALER_H 1
     11#define QWT_PLOT_RESCALER_H
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_interval.h"
    1514#include "qwt_plot.h"
     15
    1616#include <qobject.h>
    1717
    1818class QwtPlot;
     19class QwtInterval;
    1920class QResizeEvent;
    2021
    … …  
    2425    QwtPlotRescaler auto adjusts the axes of a QwtPlot according
    2526    to fixed aspect ratios.
    26 */
     27 */
    2728
    28 class QWT_EXPORT QwtPlotRescaler: public QObject
     29class QWT_EXPORT QwtPlotRescaler : public QObject
    2930{
    30 public:
     31    Q_OBJECT
     32
     33  public:
    3134    /*!
    32       The rescale policy defines how to rescale the reference axis and
    33       their depending axes.
     35       The rescale policy defines how to rescale the reference axis and
     36       their depending axes.
    3437
    35       \sa ExpandingDirection, setIntervalHint()
    36     */
     38       \sa ExpandingDirection, setIntervalHint()
     39     */
    3740    enum RescalePolicy
    3841    {
    3942        /*!
    40           The interval of the reference axis remains unchanged, when the
    41           geometry of the canvas changes. All other axes
    42           will be adjusted according to their aspect ratio.
     43           The interval of the reference axis remains unchanged, when the
     44           geometry of the canvas changes. All other axes
     45           will be adjusted according to their aspect ratio.
    4346         */
    4447        Fixed,
    4548
    4649        /*!
    47           The interval of the reference axis will be shrunk/expanded,
    48           when the geometry of the canvas changes. All other axes
    49           will be adjusted according to their aspect ratio.
     50           The interval of the reference axis will be shrunk/expanded,
     51           when the geometry of the canvas changes. All other axes
     52           will be adjusted according to their aspect ratio.
    5053
    51           The interval, that is represented by one pixel is fixed.
     54           The interval, that is represented by one pixel is fixed.
    5255
    5356         */
    … …  
    5558
    5659        /*!
    57           The intervals of the axes are calculated, so that all axes include
    58           their interval hint.
     60           The intervals of the axes are calculated, so that all axes include
     61           their interval hint.
    5962         */
    6063        Fitting
    … …  
    7780    };
    7881
    79     explicit QwtPlotRescaler( QWidget *canvas,
    80         int referenceAxis = QwtPlot::xBottom,
     82    explicit QwtPlotRescaler( QWidget* canvas,
     83        QwtAxisId referenceAxis = QwtAxis::XBottom,
    8184        RescalePolicy = Expanding );
    8285
    … …  
    9093
    9194    void setExpandingDirection( ExpandingDirection );
    92     void setExpandingDirection( int axis, ExpandingDirection );
    93     ExpandingDirection expandingDirection( int axis ) const;
     95    void setExpandingDirection( QwtAxisId, ExpandingDirection );
     96    ExpandingDirection expandingDirection( QwtAxisId ) const;
    9497
    95     void setReferenceAxis( int axis );
    96     int referenceAxis() const;
     98    void setReferenceAxis( QwtAxisId );
     99    QwtAxisId referenceAxis() const;
    97100
    98101    void setAspectRatio( double ratio );
    99     void setAspectRatio( int axis, double ratio );
    100     double aspectRatio( int axis ) const;
     102    void setAspectRatio( QwtAxisId, double ratio );
     103    double aspectRatio( QwtAxisId ) const;
    101104
    102     void setIntervalHint( int axis, const QwtInterval& );
    103     QwtInterval intervalHint( int axis ) const;
     105    void setIntervalHint( QwtAxisId, const QwtInterval& );
     106    QwtInterval intervalHint( QwtAxisId ) const;
    104107
    105     QWidget *canvas();
    106     const QWidget *canvas() const;
     108    QWidget* canvas();
     109    const QWidget* canvas() const;
    107110
    108     QwtPlot *plot();
    109     const QwtPlot *plot() const;
     111    QwtPlot* plot();
     112    const QwtPlot* plot() const;
    110113
    111     virtual bool eventFilter( QObject *, QEvent * );
     114    virtual bool eventFilter( QObject*, QEvent* ) QWT_OVERRIDE;
    112115
    113116    void rescale() const;
    114117
    115 protected:
    116     virtual void canvasResizeEvent( QResizeEvent * );
     118  protected:
     119    virtual void canvasResizeEvent( QResizeEvent* );
    117120
    118     virtual void rescale( const QSize &oldSize, const QSize &newSize ) const;
     121    virtual void rescale( const QSize& oldSize, const QSize& newSize ) const;
    119122    virtual QwtInterval expandScale(
    120         int axis, const QSize &oldSize, const QSize &newSize ) const;
     123        QwtAxisId, const QSize& oldSize, const QSize& newSize ) const;
    121124
    122125    virtual QwtInterval syncScale(
    123         int axis, const QwtInterval& reference,
    124         const QSize &size ) const;
     126        QwtAxisId, const QwtInterval& reference, const QSize& size ) const;
    125127
    126128    virtual void updateScales(
    127         QwtInterval intervals[QwtPlot::axisCnt] ) const;
     129        QwtInterval intervals[QwtAxis::AxisPositions] ) const;
    128130
    129     Qt::Orientation orientation( int axis ) const;
    130     QwtInterval interval( int axis ) const;
    131     QwtInterval expandInterval( const QwtInterval &,
     131    Qt::Orientation orientation( QwtAxisId ) const;
     132    QwtInterval interval( QwtAxisId ) const;
     133    QwtInterval expandInterval( const QwtInterval&,
    132134        double width, ExpandingDirection ) const;
    133135
    134 private:
    135     double pixelDist( int axis, const QSize & ) const;
     136  private:
     137    double pixelDist( QwtAxisId, const QSize& ) const;
    136138
    137139    class AxisData;
    138140    class PrivateData;
    139     PrivateData *d_data;
     141    PrivateData* m_data;
    140142};
    141143
  • trunk/BNC/qwt/qwt_plot_scaleitem.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212#include "qwt_scale_map.h"
    1313#include "qwt_interval.h"
     14#include "qwt_text.h"
     15
    1416#include <qpalette.h>
    1517#include <qpainter.h>
    … …  
    1719class QwtPlotScaleItem::PrivateData
    1820{
    19 public:
    20     PrivateData():
    21         position( 0.0 ),
    22         borderDistance( -1 ),
    23         scaleDivFromAxis( true ),
    24         scaleDraw( new QwtScaleDraw() )
     21  public:
     22    PrivateData()
     23        : position( 0.0 )
     24        , borderDistance( -1 )
     25        , scaleDivFromAxis( true )
     26        , scaleDraw( new QwtScaleDraw() )
    2527    {
    2628    }
    … …  
    3133    }
    3234
    33     QwtInterval scaleInterval( const QRectF &,
    34         const QwtScaleMap &, const QwtScaleMap & ) const;
     35    QwtInterval scaleInterval( const QRectF&,
     36        const QwtScaleMap&, const QwtScaleMap& ) const;
    3537
    3638    QPalette palette;
    … …  
    3941    int borderDistance;
    4042    bool scaleDivFromAxis;
    41     QwtScaleDraw *scaleDraw;
     43    QwtScaleDraw* scaleDraw;
    4244};
    4345
    44 QwtInterval QwtPlotScaleItem::PrivateData::scaleInterval( const QRectF &canvasRect,
    45     const QwtScaleMap &xMap, const QwtScaleMap &yMap ) const
     46QwtInterval QwtPlotScaleItem::PrivateData::scaleInterval( const QRectF& canvasRect,
     47    const QwtScaleMap& xMap, const QwtScaleMap& yMap ) const
    4648{
    4749    QwtInterval interval;
    … …  
    7072
    7173   \sa setPosition(), setAlignment()
    72 */
     74 */
    7375QwtPlotScaleItem::QwtPlotScaleItem(
    74         QwtScaleDraw::Alignment alignment, const double pos ):
    75     QwtPlotItem( QwtText( "Scale" ) )
    76 {
    77     d_data = new PrivateData;
    78     d_data->position = pos;
    79     d_data->scaleDraw->setAlignment( alignment );
     76        QwtScaleDraw::Alignment alignment, const double pos )
     77    : QwtPlotItem( QwtText( "Scale" ) )
     78{
     79    m_data = new PrivateData;
     80    m_data->position = pos;
     81    m_data->scaleDraw->setAlignment( alignment );
    8082
    8183    setItemInterest( QwtPlotItem::ScaleInterest, true );
    … …  
    8688QwtPlotScaleItem::~QwtPlotScaleItem()
    8789{
    88     delete d_data;
     90    delete m_data;
    8991}
    9092
    … …  
    103105   \param scaleDiv Scale division
    104106   \sa scaleDiv(), setScaleDivFromAxis(), isScaleDivFromAxis()
    105 */
     107 */
    106108void QwtPlotScaleItem::setScaleDiv( const QwtScaleDiv& scaleDiv )
    107109{
    108     d_data->scaleDivFromAxis = false;
    109     d_data->scaleDraw->setScaleDiv( scaleDiv );
     110    m_data->scaleDivFromAxis = false;
     111    m_data->scaleDraw->setScaleDiv( scaleDiv );
    110112}
    111113
    … …  
    113115const QwtScaleDiv& QwtPlotScaleItem::scaleDiv() const
    114116{
    115     return d_data->scaleDraw->scaleDiv();
     117    return m_data->scaleDraw->scaleDiv();
    116118}
    117119
    … …  
    122124   \param on true/false
    123125   \sa isScaleDivFromAxis()
    124 */
     126 */
    125127void QwtPlotScaleItem::setScaleDivFromAxis( bool on )
    126128{
    127     if ( on != d_data->scaleDivFromAxis )
    128     {
    129         d_data->scaleDivFromAxis = on;
     129    if ( on != m_data->scaleDivFromAxis )
     130    {
     131        m_data->scaleDivFromAxis = on;
    130132        if ( on )
    131133        {
    132             const QwtPlot *plt = plot();
     134            const QwtPlot* plt = plot();
    133135            if ( plt )
    134136            {
    … …  
    145147           the corresponding axis is enabled.
    146148   \sa setScaleDiv(), setScaleDivFromAxis()
    147 */
     149 */
    148150bool QwtPlotScaleItem::isScaleDivFromAxis() const
    149151{
    150     return d_data->scaleDivFromAxis;
     152    return m_data->scaleDivFromAxis;
    151153}
    152154
    … …  
    154156   Set the palette
    155157   \sa QwtAbstractScaleDraw::draw(), palette()
    156 */
    157 void QwtPlotScaleItem::setPalette( const QPalette &palette )
    158 {
    159     if ( palette != d_data->palette )
    160     {
    161         d_data->palette = palette;
     158 */
     159void QwtPlotScaleItem::setPalette( const QPalette& palette )
     160{
     161    if ( palette != m_data->palette )
     162    {
     163        m_data->palette = palette;
    162164
    163165        legendChanged();
    … …  
    169171   \return palette
    170172   \sa setPalette()
    171 */
     173 */
    172174QPalette QwtPlotScaleItem::palette() const
    173175{
    174     return d_data->palette;
     176    return m_data->palette;
    175177}
    176178
    … …  
    178180   Change the tick label font
    179181   \sa font()
    180 */
    181 void QwtPlotScaleItem::setFont( const QFont &font )
    182 {
    183     if ( font != d_data->font )
    184     {
    185         d_data->font = font;
     182 */
     183void QwtPlotScaleItem::setFont( const QFont& font )
     184{
     185    if ( font != m_data->font )
     186    {
     187        m_data->font = font;
    186188        itemChanged();
    187189    }
    … …  
    191193   \return tick label font
    192194   \sa setFont()
    193 */
     195 */
    194196QFont QwtPlotScaleItem::font() const
    195197{
    196     return d_data->font;
    197 }
    198 
    199 /*!
    200   \brief Set a scale draw
    201 
    202   \param scaleDraw object responsible for drawing scales.
    203 
    204   The main use case for replacing the default QwtScaleDraw is
    205   to overload QwtAbstractScaleDraw::label, to replace or swallow
    206   tick labels.
    207 
    208   \sa scaleDraw()
    209 */
    210 void QwtPlotScaleItem::setScaleDraw( QwtScaleDraw *scaleDraw )
     198    return m_data->font;
     199}
     200
     201/*!
     202   \brief Set a scale draw
     203
     204   \param scaleDraw object responsible for drawing scales.
     205
     206   The main use case for replacing the default QwtScaleDraw is
     207   to overload QwtAbstractScaleDraw::label, to replace or swallow
     208   tick labels.
     209
     210   \sa scaleDraw()
     211 */
     212void QwtPlotScaleItem::setScaleDraw( QwtScaleDraw* scaleDraw )
    211213{
    212214    if ( scaleDraw == NULL )
    213215        return;
    214216
    215     if ( scaleDraw != d_data->scaleDraw )
    216         delete d_data->scaleDraw;
    217 
    218     d_data->scaleDraw = scaleDraw;
    219 
    220     const QwtPlot *plt = plot();
     217    if ( scaleDraw != m_data->scaleDraw )
     218        delete m_data->scaleDraw;
     219
     220    m_data->scaleDraw = scaleDraw;
     221
     222    const QwtPlot* plt = plot();
    221223    if ( plt )
    222224    {
    … …  
    231233   \return Scale draw
    232234   \sa setScaleDraw()
    233 */
    234 const QwtScaleDraw *QwtPlotScaleItem::scaleDraw() const
    235 {
    236     return d_data->scaleDraw;
     235 */
     236const QwtScaleDraw* QwtPlotScaleItem::scaleDraw() const
     237{
     238    return m_data->scaleDraw;
    237239}
    238240
    … …  
    240242   \return Scale draw
    241243   \sa setScaleDraw()
    242 */
    243 QwtScaleDraw *QwtPlotScaleItem::scaleDraw()
    244 {
    245     return d_data->scaleDraw;
     244 */
     245QwtScaleDraw* QwtPlotScaleItem::scaleDraw()
     246{
     247    return m_data->scaleDraw;
    246248}
    247249
    … …  
    256258   \param pos New position
    257259   \sa position(), setAlignment()
    258 */
     260 */
    259261void QwtPlotScaleItem::setPosition( double pos )
    260262{
    261     if ( d_data->position != pos )
    262     {
    263         d_data->position = pos;
    264         d_data->borderDistance = -1;
     263    if ( m_data->position != pos )
     264    {
     265        m_data->position = pos;
     266        m_data->borderDistance = -1;
    265267        itemChanged();
    266268    }
    … …  
    270272   \return Position of the scale
    271273   \sa setPosition(), setAlignment()
    272 */
     274 */
    273275double QwtPlotScaleItem::position() const
    274276{
    275     return d_data->position;
     277    return m_data->position;
    276278}
    277279
    … …  
    291293
    292294   \sa setPosition(), borderDistance()
    293 */
     295 */
    294296void QwtPlotScaleItem::setBorderDistance( int distance )
    295297{
    … …  
    297299        distance = -1;
    298300
    299     if ( distance != d_data->borderDistance )
    300     {
    301         d_data->borderDistance = distance;
     301    if ( distance != m_data->borderDistance )
     302    {
     303        m_data->borderDistance = distance;
    302304        itemChanged();
    303305    }
    … …  
    307309   \return Distance from a canvas border
    308310   \sa setBorderDistance(), setPosition()
    309 */
     311 */
    310312int QwtPlotScaleItem::borderDistance() const
    311313{
    312     return d_data->borderDistance;
     314    return m_data->borderDistance;
    313315}
    314316
    … …  
    328330
    329331   \sa scaleDraw(), QwtScaleDraw::alignment(), setPosition()
    330 */
     332 */
    331333void QwtPlotScaleItem::setAlignment( QwtScaleDraw::Alignment alignment )
    332334{
    333     QwtScaleDraw *sd = d_data->scaleDraw;
     335    QwtScaleDraw* sd = m_data->scaleDraw;
    334336    if ( sd->alignment() != alignment )
    335337    {
    … …  
    340342
    341343/*!
    342   \brief Draw the scale
    343 */
    344 void QwtPlotScaleItem::draw( QPainter *painter,
    345     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    346     const QRectF &canvasRect ) const
    347 {
    348     QwtScaleDraw *sd = d_data->scaleDraw;
    349 
    350     if ( d_data->scaleDivFromAxis )
     344   \brief Draw the scale
     345 */
     346void QwtPlotScaleItem::draw( QPainter* painter,
     347    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     348    const QRectF& canvasRect ) const
     349{
     350    QwtScaleDraw* sd = m_data->scaleDraw;
     351
     352    if ( m_data->scaleDivFromAxis )
    351353    {
    352354        const QwtInterval interval =
    353             d_data->scaleInterval( canvasRect, xMap, yMap );
     355            m_data->scaleInterval( canvasRect, xMap, yMap );
    354356
    355357        if ( interval != sd->scaleDiv().interval() )
    … …  
    368370    {
    369371        double y;
    370         if ( d_data->borderDistance >= 0 )
     372        if ( m_data->borderDistance >= 0 )
    371373        {
    372374            if ( sd->alignment() == QwtScaleDraw::BottomScale )
    373                 y = canvasRect.top() + d_data->borderDistance;
     375                y = canvasRect.top() + m_data->borderDistance;
    374376            else
    375377            {
    376                 y = canvasRect.bottom() - d_data->borderDistance;
     378                y = canvasRect.bottom() - m_data->borderDistance;
    377379            }
    378380
    … …  
    380382        else
    381383        {
    382             y = yMap.transform( d_data->position );
     384            y = yMap.transform( m_data->position );
    383385        }
    384386
    … …  
    389391        sd->setLength( canvasRect.width() - 1 );
    390392
    391         QwtTransform *transform = NULL;
     393        QwtTransform* transform = NULL;
    392394        if ( xMap.transformation() )
    393395            transform = xMap.transformation()->copy();
    … …  
    398400    {
    399401        double x;
    400         if ( d_data->borderDistance >= 0 )
     402        if ( m_data->borderDistance >= 0 )
    401403        {
    402404            if ( sd->alignment() == QwtScaleDraw::RightScale )
    403                 x = canvasRect.left() + d_data->borderDistance;
     405                x = canvasRect.left() + m_data->borderDistance;
    404406            else
    405407            {
    406                 x = canvasRect.right() - d_data->borderDistance;
     408                x = canvasRect.right() - m_data->borderDistance;
    407409            }
    408410        }
    409411        else
    410412        {
    411             x = xMap.transform( d_data->position );
     413            x = xMap.transform( m_data->position );
    412414        }
    413415        if ( x < canvasRect.left() || x > canvasRect.right() )
    … …  
    417419        sd->setLength( canvasRect.height() - 1 );
    418420
    419         QwtTransform *transform = NULL;
     421        QwtTransform* transform = NULL;
    420422        if ( yMap.transformation() )
    421423            transform = yMap.transformation()->copy();
    … …  
    424426    }
    425427
    426     painter->setFont( d_data->font );
    427 
    428     sd->draw( painter, d_data->palette );
     428    painter->setFont( m_data->font );
     429
     430    sd->draw( painter, m_data->palette );
    429431}
    430432
    … …  
    439441
    440442   \sa QwtPlot::updateAxes()
    441 */
     443 */
    442444
    443445void QwtPlotScaleItem::updateScaleDiv( const QwtScaleDiv& xScaleDiv,
    444446    const QwtScaleDiv& yScaleDiv )
    445447{
    446     QwtScaleDraw *scaleDraw = d_data->scaleDraw;
    447 
    448     if ( d_data->scaleDivFromAxis && scaleDraw )
    449     {
    450         const QwtScaleDiv &scaleDiv =
     448    QwtScaleDraw* scaleDraw = m_data->scaleDraw;
     449
     450    if ( m_data->scaleDivFromAxis && scaleDraw )
     451    {
     452        const QwtScaleDiv& scaleDiv =
    451453            scaleDraw->orientation() == Qt::Horizontal ? xScaleDiv : yScaleDiv;
    452454
    453         const QwtPlot *plt = plot();
     455        const QwtPlot* plt = plot();
    454456        if ( plt != NULL )
    455457        {
    456458            const QRectF canvasRect = plt->canvas()->contentsRect();
    457459
    458             const QwtInterval interval = d_data->scaleInterval(
     460            const QwtInterval interval = m_data->scaleInterval(
    459461                canvasRect, plt->canvasMap( xAxis() ), plt->canvasMap( yAxis() ) );
    460462
  • trunk/BNC/qwt/qwt_plot_scaleitem.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1818
    1919/*!
    20   \brief A class which draws a scale inside the plot canvas
     20   \brief A class which draws a scale inside the plot canvas
    2121
    22   QwtPlotScaleItem can be used to draw an axis inside the plot canvas.
    23   It might by synchronized to one of the axis of the plot, but can
    24   also display its own ticks and labels.
     22   QwtPlotScaleItem can be used to draw an axis inside the plot canvas.
     23   It might by synchronized to one of the axis of the plot, but can
     24   also display its own ticks and labels.
    2525
    26   It is allowed to synchronize the scale item with a disabled axis.
    27   In plots with vertical and horizontal scale items, it might be
    28   necessary to remove ticks at the intersections, by overloading
    29   updateScaleDiv().
     26   It is allowed to synchronize the scale item with a disabled axis.
     27   In plots with vertical and horizontal scale items, it might be
     28   necessary to remove ticks at the intersections, by overloading
     29   updateScaleDiv().
    3030
    31   The scale might be at a specific position (f.e 0.0) or it might be
    32   aligned to a canvas border.
     31   The scale might be at a specific position (f.e 0.0) or it might be
     32   aligned to a canvas border.
    3333
    34   \par Example
     34   \par Example
    3535    The following example shows how to replace the left axis, by a scale item
    3636    at the x position 0.0.
    3737    \code
    3838      QwtPlotScaleItem *scaleItem = new QwtPlotScaleItem( QwtScaleDraw::RightScale, 0.0 );
    39       scaleItem->setFont( plot->axisWidget( QwtPlot::yLeft )->font() );
     39      scaleItem->setFont( plot->axisWidget( QwtAxis::YLeft )->font() );
    4040      scaleItem->attach(plot);
    4141
    42       plot->enableAxis( QwtPlot::yLeft, false );
     42      plot->setAxisVisible( QwtAxis::YLeft, false );
    4343    \endcode
    44   \endpar
    45 */
     44 */
    4645
    47 class QWT_EXPORT QwtPlotScaleItem: public QwtPlotItem
     46class QWT_EXPORT QwtPlotScaleItem : public QwtPlotItem
    4847{
    49 public:
     48  public:
    5049    explicit QwtPlotScaleItem(
    5150        QwtScaleDraw::Alignment = QwtScaleDraw::BottomScale,
    … …  
    5453    virtual ~QwtPlotScaleItem();
    5554
    56     virtual int rtti() const;
     55    virtual int rtti() const QWT_OVERRIDE;
    5756
    5857    void setScaleDiv( const QwtScaleDiv& );
    … …  
    6261    bool isScaleDivFromAxis() const;
    6362
    64     void setPalette( const QPalette & );
     63    void setPalette( const QPalette& );
    6564    QPalette palette() const;
    6665
    … …  
    6867    QFont font() const;
    6968
    70     void setScaleDraw( QwtScaleDraw * );
     69    void setScaleDraw( QwtScaleDraw* );
    7170
    72     const QwtScaleDraw *scaleDraw() const;
    73     QwtScaleDraw *scaleDraw();
     71    const QwtScaleDraw* scaleDraw() const;
     72    QwtScaleDraw* scaleDraw();
    7473
    7574    void setPosition( double pos );
    … …  
    8180    void setAlignment( QwtScaleDraw::Alignment );
    8281
    83     virtual void draw( QPainter *,
    84         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    85         const QRectF &canvasRect ) const;
     82    virtual void draw( QPainter*,
     83        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     84        const QRectF& canvasRect ) const QWT_OVERRIDE;
    8685
    87     virtual void updateScaleDiv( const QwtScaleDiv &, const QwtScaleDiv & );
     86    virtual void updateScaleDiv(
     87        const QwtScaleDiv&, const QwtScaleDiv& ) QWT_OVERRIDE;
    8888
    89 private:
     89  private:
    9090    class PrivateData;
    91     PrivateData *d_data;
     91    PrivateData* m_data;
    9292};
    9393
  • trunk/BNC/qwt/qwt_plot_seriesitem.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_seriesitem.h"
     11#include "qwt_scale_div.h"
     12#include "qwt_text.h"
    1113
    1214class QwtPlotSeriesItem::PrivateData
    1315{
    14 public:
    15     PrivateData():
    16         orientation( Qt::Vertical )
     16  public:
     17    PrivateData()
     18        : orientation( Qt::Vertical )
    1719    {
    1820    }
    … …  
    2224
    2325/*!
    24   Constructor
    25   \param title Title of the curve
    26 */
    27 QwtPlotSeriesItem::QwtPlotSeriesItem( const QwtText &title ):
    28     QwtPlotItem( title )
     26   Constructor
     27   \param title Title of the curve
     28 */
     29QwtPlotSeriesItem::QwtPlotSeriesItem( const QwtText& title )
     30    : QwtPlotItem( title )
    2931{
    30     d_data = new PrivateData();
     32    m_data = new PrivateData();
    3133    setItemInterest( QwtPlotItem::ScaleInterest, true );
    3234}
    3335
    3436/*!
    35   Constructor
    36   \param title Title of the curve
    37 */
    38 QwtPlotSeriesItem::QwtPlotSeriesItem( const QString &title ):
    39     QwtPlotItem( QwtText( title ) )
     37   Constructor
     38   \param title Title of the curve
     39 */
     40QwtPlotSeriesItem::QwtPlotSeriesItem( const QString& title )
     41    : QwtPlotItem( QwtText( title ) )
    4042{
    41     d_data = new PrivateData();
     43    m_data = new PrivateData();
    4244    setItemInterest( QwtPlotItem::ScaleInterest, true );
    4345}
    … …  
    4648QwtPlotSeriesItem::~QwtPlotSeriesItem()
    4749{
    48     delete d_data;
     50    delete m_data;
    4951}
    5052
    5153/*!
    52   Set the orientation of the item.
     54   Set the orientation of the item.
    5355
    54   The orientation() might be used in specific way by a plot item.
    55   F.e. a QwtPlotCurve uses it to identify how to display the curve
    56   int QwtPlotCurve::Steps or QwtPlotCurve::Sticks style.
     56   The orientation() might be used in specific way by a plot item.
     57   F.e. a QwtPlotCurve uses it to identify how to display the curve
     58   int QwtPlotCurve::Steps or QwtPlotCurve::Sticks style.
    5759
    58   \sa orientation()
    59 */
     60   \sa orientation()
     61 */
    6062void QwtPlotSeriesItem::setOrientation( Qt::Orientation orientation )
    6163{
    62     if ( d_data->orientation != orientation )
     64    if ( m_data->orientation != orientation )
    6365    {
    64         d_data->orientation = orientation;
     66        m_data->orientation = orientation;
    6567
    6668        legendChanged();
    … …  
    7072
    7173/*!
    72   \return Orientation of the plot item
    73   \sa setOrientation()
    74 */
     74   \return Orientation of the plot item
     75   \sa setOrientation()
     76 */
    7577Qt::Orientation QwtPlotSeriesItem::orientation() const
    7678{
    77     return d_data->orientation;
     79    return m_data->orientation;
    7880}
    7981
    8082/*!
    81   \brief Draw the complete series
     83   \brief Draw the complete series
    8284
    83   \param painter Painter
    84   \param xMap Maps x-values into pixel coordinates.
    85   \param yMap Maps y-values into pixel coordinates.
    86   \param canvasRect Contents rectangle of the canvas
    87 */
    88 void QwtPlotSeriesItem::draw( QPainter *painter,
    89         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    90         const QRectF &canvasRect ) const
     85   \param painter Painter
     86   \param xMap Maps x-values into pixel coordinates.
     87   \param yMap Maps y-values into pixel coordinates.
     88   \param canvasRect Contents rectangle of the canvas
     89 */
     90void QwtPlotSeriesItem::draw( QPainter* painter,
     91    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     92    const QRectF& canvasRect ) const
    9193{
    9294    drawSeries( painter, xMap, yMap, canvasRect, 0, -1 );
    … …  
    99101
    100102void QwtPlotSeriesItem::updateScaleDiv(
    101     const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv )
     103    const QwtScaleDiv& xScaleDiv, const QwtScaleDiv& yScaleDiv )
    102104{
    103105    const QRectF rect = QRectF(
  • trunk/BNC/qwt/qwt_plot_seriesitem.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_item.h"
    15 #include "qwt_scale_div.h"
    16 #include "qwt_series_data.h"
    1715#include "qwt_series_store.h"
    1816
     17#include <qstring.h>
     18
     19class QwtScaleDiv;
     20
    1921/*!
    20   \brief Base class for plot items representing a series of samples
    21 */
    22 class QWT_EXPORT QwtPlotSeriesItem: public QwtPlotItem,
     22   \brief Base class for plot items representing a series of samples
     23 */
     24class QWT_EXPORT QwtPlotSeriesItem : public QwtPlotItem,
    2325    public virtual QwtAbstractSeriesStore
    2426{
    25 public:
    26     explicit QwtPlotSeriesItem( const QString &title = QString() );
    27     explicit QwtPlotSeriesItem( const QwtText &title );
     27  public:
     28    explicit QwtPlotSeriesItem( const QString& title = QString() );
     29    explicit QwtPlotSeriesItem( const QwtText& title );
    2830
    2931    virtual ~QwtPlotSeriesItem();
    … …  
    3234    Qt::Orientation orientation() const;
    3335
    34     virtual void draw( QPainter *,
    35         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    36         const QRectF & ) const;
     36    virtual void draw( QPainter*,
     37        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     38        const QRectF& canvasRect ) const QWT_OVERRIDE;
    3739
    3840    /*!
    39       Draw a subset of the samples
     41       Draw a subset of the samples
    4042
    41       \param painter Painter
    42       \param xMap Maps x-values into pixel coordinates.
    43       \param yMap Maps y-values into pixel coordinates.
    44       \param canvasRect Contents rectangle of the canvas
    45       \param from Index of the first point to be painted
    46       \param to Index of the last point to be painted. If to < 0 the
     43       \param painter Painter
     44       \param xMap Maps x-values into pixel coordinates.
     45       \param yMap Maps y-values into pixel coordinates.
     46       \param canvasRect Contents rectangle of the canvas
     47       \param from Index of the first point to be painted
     48       \param to Index of the last point to be painted. If to < 0 the
    4749             curve will be painted to its last point.
    48     */
    49     virtual void drawSeries( QPainter *painter,
    50         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    51         const QRectF &canvasRect, int from, int to ) const = 0;
     50     */
     51    virtual void drawSeries( QPainter* painter,
     52        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     53        const QRectF& canvasRect, int from, int to ) const = 0;
    5254
    53     virtual QRectF boundingRect() const;
     55    virtual QRectF boundingRect() const QWT_OVERRIDE;
    5456
    5557    virtual void updateScaleDiv(
    56         const QwtScaleDiv &, const QwtScaleDiv & );
     58        const QwtScaleDiv&, const QwtScaleDiv& ) QWT_OVERRIDE;
    5759
    58 protected:
    59     virtual void dataChanged();
     60  protected:
     61    virtual void dataChanged() QWT_OVERRIDE;
    6062
    61 private:
     63  private:
    6264    class PrivateData;
    63     PrivateData *d_data;
     65    PrivateData* m_data;
    6466};
    6567
  • trunk/BNC/qwt/qwt_plot_shapeitem.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_plot_shapeitem.h"
    1111#include "qwt_scale_map.h"
     12#include "qwt_text.h"
     13#include "qwt_graphic.h"
    1214#include "qwt_painter.h"
    13 #include "qwt_curve_fitter.h"
     15#include "qwt_weeding_curve_fitter.h"
    1416#include "qwt_clipper.h"
    15 
    16 static QPainterPath qwtTransformPath( const QwtScaleMap &xMap,
    17         const QwtScaleMap &yMap, const QPainterPath &path, bool doAlign )
     17#include "qwt_math.h"
     18
     19#include <qpainter.h>
     20#include <qpainterpath.h>
     21
     22static QPainterPath qwtTransformPath( const QwtScaleMap& xMap,
     23    const QwtScaleMap& yMap, const QPainterPath& path, bool doAlign )
    1824{
    1925    QPainterPath shape;
    … …  
    2228    for ( int i = 0; i < path.elementCount(); i++ )
    2329    {
    24         const QPainterPath::Element &element = path.elementAt( i );
     30        const QPainterPath::Element element = path.elementAt( i );
    2531
    2632        double x = xMap.transform( element.x );
    … …  
    5359            case QPainterPath::CurveToElement:
    5460            {
    55                 const QPainterPath::Element& element1 = path.elementAt( ++i );
     61                const QPainterPath::Element element1 = path.elementAt( ++i );
    5662                const double x1 = xMap.transform( element1.x );
    5763                const double y1 = yMap.transform( element1.y );
    5864
    59                 const QPainterPath::Element& element2 = path.elementAt( ++i );
     65                const QPainterPath::Element element2 = path.elementAt( ++i );
    6066                const double x2 = xMap.transform( element2.x );
    6167                const double y2 = yMap.transform( element2.y );
    … …  
    7783class QwtPlotShapeItem::PrivateData
    7884{
    79 public:
    80     PrivateData():
    81         legendMode( QwtPlotShapeItem::LegendColor ),
    82         renderTolerance( 0.0 )
     85  public:
     86    PrivateData()
     87        : legendMode( QwtPlotShapeItem::LegendColor )
     88        , renderTolerance( 0.0 )
    8389    {
    8490    }
    … …  
    103109
    104110   \param title Title
    105 */
    106 QwtPlotShapeItem::QwtPlotShapeItem( const QString& title ):
    107     QwtPlotItem( QwtText( title ) )
     111 */
     112QwtPlotShapeItem::QwtPlotShapeItem( const QString& title )
     113    : QwtPlotItem( QwtText( title ) )
    108114{
    109115    init();
    … …  
    118124
    119125   \param title Title
    120 */
    121 QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title ):
    122     QwtPlotItem( title )
     126 */
     127QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title )
     128    : QwtPlotItem( title )
    123129{
    124130    init();
    … …  
    128134QwtPlotShapeItem::~QwtPlotShapeItem()
    129135{
    130     delete d_data;
     136    delete m_data;
    131137}
    132138
    133139void QwtPlotShapeItem::init()
    134140{
    135     d_data = new PrivateData();
    136     d_data->boundingRect = QwtPlotItem::boundingRect();
     141    m_data = new PrivateData();
     142    m_data->boundingRect = QwtPlotItem::boundingRect();
    137143
    138144    setItemAttribute( QwtPlotItem::AutoScale, true );
    … …  
    149155
    150156/*!
    151   Specify an attribute how to draw the shape
    152 
    153   \param attribute Paint attribute
    154   \param on On/Off
    155   \sa testPaintAttribute()
    156 */
     157   Specify an attribute how to draw the shape
     158
     159   \param attribute Paint attribute
     160   \param on On/Off
     161   \sa testPaintAttribute()
     162 */
    157163void QwtPlotShapeItem::setPaintAttribute( PaintAttribute attribute, bool on )
    158164{
    159165    if ( on )
    160         d_data->paintAttributes |= attribute;
     166        m_data->paintAttributes |= attribute;
    161167    else
    162         d_data->paintAttributes &= ~attribute;
    163 }
    164 
    165 /*!
    166   \return True, when attribute is enabled
    167   \sa setPaintAttribute()
    168 */
     168        m_data->paintAttributes &= ~attribute;
     169}
     170
     171/*!
     172   \return True, when attribute is enabled
     173   \sa setPaintAttribute()
     174 */
    169175bool QwtPlotShapeItem::testPaintAttribute( PaintAttribute attribute ) const
    170176{
    171     return ( d_data->paintAttributes & attribute );
    172 }
    173 
    174 /*!
    175   Set the mode how to represent the item on the legend
    176 
    177   \param mode Mode
    178   \sa legendMode()
     177    return ( m_data->paintAttributes & attribute );
     178}
     179
     180/*!
     181   Set the mode how to represent the item on the legend
     182
     183   \param mode Mode
     184   \sa legendMode()
    179185 */
    180186void QwtPlotShapeItem::setLegendMode( LegendMode mode )
    181187{
    182     if ( mode != d_data->legendMode )
    183     {
    184         d_data->legendMode = mode;
     188    if ( mode != m_data->legendMode )
     189    {
     190        m_data->legendMode = mode;
    185191        legendChanged();
    186192    }
    … …  
    188194
    189195/*!
    190   \return Mode how to represent the item on the legend
    191   \sa legendMode()
     196   \return Mode how to represent the item on the legend
     197   \sa legendMode()
    192198 */
    193199QwtPlotShapeItem::LegendMode QwtPlotShapeItem::legendMode() const
    194200{
    195     return d_data->legendMode;
     201    return m_data->legendMode;
    196202}
    197203
    … …  
    199205QRectF QwtPlotShapeItem::boundingRect() const
    200206{
    201     return d_data->boundingRect;
    202 }
    203 
    204 /*!
    205   \brief Set a path built from a rectangle
    206 
    207   \param rect Rectangle
    208   \sa setShape(), setPolygon(), shape()
    209  */
    210 void QwtPlotShapeItem::setRect( const QRectF &rect )
     207    return m_data->boundingRect;
     208}
     209
     210/*!
     211   \brief Set a path built from a rectangle
     212
     213   \param rect Rectangle
     214   \sa setShape(), setPolygon(), shape()
     215 */
     216void QwtPlotShapeItem::setRect( const QRectF& rect )
    211217{
    212218    QPainterPath path;
    … …  
    217223
    218224/*!
    219   \brief Set a path built from a polygon
    220 
    221   \param polygon Polygon
    222   \sa setShape(), setRect(), shape()
    223  */
    224 void QwtPlotShapeItem::setPolygon( const QPolygonF &polygon )
     225   \brief Set a path built from a polygon
     226
     227   \param polygon Polygon
     228   \sa setShape(), setRect(), shape()
     229 */
     230void QwtPlotShapeItem::setPolygon( const QPolygonF& polygon )
    225231{
    226232    QPainterPath shape;
    … …  
    231237
    232238/*!
    233   \brief Set the shape to be displayed
    234 
    235   \param shape Shape
    236   \sa setShape(), shape()
    237  */
    238 void QwtPlotShapeItem::setShape( const QPainterPath &shape )
    239 {
    240     if ( shape != d_data->shape )
    241     {
    242         d_data->shape = shape;
     239   \brief Set the shape to be displayed
     240
     241   \param shape Shape
     242   \sa setShape(), shape()
     243 */
     244void QwtPlotShapeItem::setShape( const QPainterPath& shape )
     245{
     246    if ( shape != m_data->shape )
     247    {
     248        m_data->shape = shape;
    243249        if ( shape.isEmpty() )
    244250        {
    245             d_data->boundingRect = QwtPlotItem::boundingRect();
     251            m_data->boundingRect = QwtPlotItem::boundingRect();
    246252        }
    247253        else
    248254        {
    249             d_data->boundingRect = shape.boundingRect();
     255            m_data->boundingRect = shape.boundingRect();
    250256        }
    251257
    … …  
    255261
    256262/*!
    257   \return Shape to be displayed
    258   \sa setShape()
     263   \return Shape to be displayed
     264   \sa setShape()
    259265 */
    260266QPainterPath QwtPlotShapeItem::shape() const
    261267{
    262     return d_data->shape;
    263 }
    264 
    265 /*!
    266   Build and assign a pen
    267 
    268   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    269   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    270   to hide this incompatibility.
    271 
    272   \param color Pen color
    273   \param width Pen width
    274   \param style Pen style
    275 
    276   \sa pen(), brush()
    277  */
    278 void QwtPlotShapeItem::setPen( const QColor &color, qreal width, Qt::PenStyle style )
     268    return m_data->shape;
     269}
     270
     271/*!
     272   Build and assign a pen
     273
     274   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     275   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     276   to hide this incompatibility.
     277
     278   \param color Pen color
     279   \param width Pen width
     280   \param style Pen style
     281
     282   \sa pen(), brush()
     283 */
     284void QwtPlotShapeItem::setPen( const QColor& color, qreal width, Qt::PenStyle style )
    279285{
    280286    setPen( QPen( color, width, style ) );
    … …  
    282288
    283289/*!
    284   \brief Assign a pen
    285 
    286   The pen is used to draw the outline of the shape
    287 
    288   \param pen Pen
    289   \sa pen(), brush()
    290 */
    291 void QwtPlotShapeItem::setPen( const QPen &pen )
    292 {
    293     if ( pen != d_data->pen )
    294     {
    295         d_data->pen = pen;
     290   \brief Assign a pen
     291
     292   The pen is used to draw the outline of the shape
     293
     294   \param pen Pen
     295   \sa pen(), brush()
     296 */
     297void QwtPlotShapeItem::setPen( const QPen& pen )
     298{
     299    if ( pen != m_data->pen )
     300    {
     301        m_data->pen = pen;
    296302        itemChanged();
    297303    }
    … …  
    301307    \return Pen used to draw the outline of the shape
    302308    \sa setPen(), brush()
    303 */
     309 */
    304310QPen QwtPlotShapeItem::pen() const
    305311{
    306     return d_data->pen;
    307 }
    308 
    309 /*!
    310   Assign a brush.
    311 
    312   The brush is used to fill the path
    313 
    314   \param brush Brush
    315   \sa brush(), pen()
    316 */
    317 void QwtPlotShapeItem::setBrush( const QBrush &brush )
    318 {
    319     if ( brush != d_data->brush )
    320     {
    321         d_data->brush = brush;
     312    return m_data->pen;
     313}
     314
     315/*!
     316   Assign a brush.
     317
     318   The brush is used to fill the path
     319
     320   \param brush Brush
     321   \sa brush(), pen()
     322 */
     323void QwtPlotShapeItem::setBrush( const QBrush& brush )
     324{
     325    if ( brush != m_data->brush )
     326    {
     327        m_data->brush = brush;
    322328        itemChanged();
    323329    }
    … …  
    325331
    326332/*!
    327   \return Brush used to fill the shape
    328   \sa setBrush(), pen()
    329 */
     333   \return Brush used to fill the shape
     334   \sa setBrush(), pen()
     335 */
    330336QBrush QwtPlotShapeItem::brush() const
    331337{
    332     return d_data->brush;
    333 }
    334 
    335 /*!
    336   \brief Set the tolerance for the weeding optimization
    337 
    338   After translating the shape into target device coordinate
    339   ( usually widget geometries ) the painter path can be simplified
    340   by a point weeding algorithm ( Douglas-Peucker ).
    341 
    342   For shapes built from curves and ellipses weeding might
    343   have the opposite effect because they have to be expanded
    344   to polygons.
    345 
    346   \param tolerance Accepted error when reducing the number of points
     338    return m_data->brush;
     339}
     340
     341/*!
     342   \brief Set the tolerance for the weeding optimization
     343
     344   After translating the shape into target device coordinate
     345   ( usually widget geometries ) the painter path can be simplified
     346   by a point weeding algorithm ( Douglas-Peucker ).
     347
     348   For shapes built from curves and ellipses weeding might
     349   have the opposite effect because they have to be expanded
     350   to polygons.
     351
     352   \param tolerance Accepted error when reducing the number of points
    347353                   A value <= 0.0 disables weeding.
    348354
    349   \sa renderTolerance(), QwtWeedingCurveFitter
     355   \sa renderTolerance(), QwtWeedingCurveFitter
    350356 */
    351357void QwtPlotShapeItem::setRenderTolerance( double tolerance )
    352358{
    353     tolerance = qMax( tolerance, 0.0 );
    354 
    355     if ( tolerance != d_data->renderTolerance )
    356     {
    357         d_data->renderTolerance = tolerance;
     359    tolerance = qwtMaxF( tolerance, 0.0 );
     360
     361    if ( tolerance != m_data->renderTolerance )
     362    {
     363        m_data->renderTolerance = tolerance;
    358364        itemChanged();
    359365    }
    … …  
    361367
    362368/*!
    363   \return Tolerance for the weeding optimization
    364   \sa setRenderTolerance()
     369   \return Tolerance for the weeding optimization
     370   \sa setRenderTolerance()
    365371 */
    366372double QwtPlotShapeItem::renderTolerance() const
    367373{
    368     return d_data->renderTolerance;
    369 }
    370 
    371 /*!
    372   Draw the shape item
    373 
    374   \param painter Painter
    375   \param xMap X-Scale Map
    376   \param yMap Y-Scale Map
    377   \param canvasRect Contents rect of the plot canvas
    378 */
    379 void QwtPlotShapeItem::draw( QPainter *painter,
    380     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    381     const QRectF &canvasRect ) const
    382 {
    383     if ( d_data->shape.isEmpty() )
     374    return m_data->renderTolerance;
     375}
     376
     377/*!
     378   Draw the shape item
     379
     380   \param painter Painter
     381   \param xMap X-Scale Map
     382   \param yMap Y-Scale Map
     383   \param canvasRect Contents rect of the plot canvas
     384 */
     385void QwtPlotShapeItem::draw( QPainter* painter,
     386    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     387    const QRectF& canvasRect ) const
     388{
     389    if ( m_data->shape.isEmpty() )
    384390        return;
    385391
    386     if ( d_data->pen.style() == Qt::NoPen
    387         && d_data->brush.style() == Qt::NoBrush )
     392    if ( m_data->pen.style() == Qt::NoPen
     393        && m_data->brush.style() == Qt::NoBrush )
    388394    {
    389395        return;
    … …  
    393399        xMap, yMap, canvasRect.toRect() );
    394400
    395     const QRectF &br = d_data->boundingRect;
     401    const QRectF& br = m_data->boundingRect;
    396402
    397403    if ( ( br.left() > cr.right() ) || ( br.right() < cr.left() )
    398404        || ( br.top() > cr.bottom() ) || ( br.bottom() < cr.top() ) )
    399405    {
    400         // outside the visisble area
     406        // outside the visible area
    401407        return;
    402408    }
    … …  
    405411
    406412    QPainterPath path = qwtTransformPath( xMap, yMap,
    407         d_data->shape, doAlign );
     413        m_data->shape, doAlign );
    408414
    409415    if ( testPaintAttribute( QwtPlotShapeItem::ClipPolygons ) )
    410416    {
    411         qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
    412         QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
     417        const qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
     418        const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
    413419
    414420        QPainterPath clippedPath;
    415421        clippedPath.setFillRule( path.fillRule() );
    416422
    417         const QList<QPolygonF> polygons = path.toSubpathPolygons();
     423        QList< QPolygonF > polygons = path.toSubpathPolygons();
    418424        for ( int i = 0; i < polygons.size(); i++ )
    419425        {
    420             const QPolygonF p = QwtClipper::clipPolygonF(
    421                 clipRect, polygons[i], true );
    422 
    423             clippedPath.addPolygon( p );
     426            QwtClipper::clipPolygonF( clipRect, polygons[i], true );
     427            clippedPath.addPolygon( polygons[i] );
    424428
    425429        }
    … …  
    428432    }
    429433
    430     if ( d_data->renderTolerance > 0.0 )
    431     {
    432         QwtWeedingCurveFitter fitter( d_data->renderTolerance );
     434    if ( m_data->renderTolerance > 0.0 )
     435    {
     436        QwtWeedingCurveFitter fitter( m_data->renderTolerance );
    433437
    434438        QPainterPath fittedPath;
    435439        fittedPath.setFillRule( path.fillRule() );
    436440
    437         const QList<QPolygonF> polygons = path.toSubpathPolygons();
     441        const QList< QPolygonF > polygons = path.toSubpathPolygons();
    438442        for ( int i = 0; i < polygons.size(); i++ )
    439443            fittedPath.addPolygon( fitter.fitCurve( polygons[ i ] ) );
    … …  
    442446    }
    443447
    444     painter->setPen( d_data->pen );
    445     painter->setBrush( d_data->brush );
     448    painter->setPen( m_data->pen );
     449    painter->setBrush( m_data->brush );
    446450
    447451    painter->drawPath( path );
    … …  
    449453
    450454/*!
    451   \return A rectangle filled with the color of the brush ( or the pen )
    452 
    453   \param index Index of the legend entry
     455   \return A rectangle filled with the color of the brush ( or the pen )
     456
     457   \param index Index of the legend entry
    454458                ( usually there is only one )
    455   \param size Icon size
    456 
    457   \sa setLegendIconSize(), legendData()
    458 */
     459   \param size Icon size
     460
     461   \sa setLegendIconSize(), legendData()
     462 */
    459463QwtGraphic QwtPlotShapeItem::legendIcon( int index,
    460     const QSizeF &size ) const
     464    const QSizeF& size ) const
    461465{
    462466    Q_UNUSED( index );
    … …  
    468472        return icon;
    469473
    470     if ( d_data->legendMode == QwtPlotShapeItem::LegendShape )
    471     {
    472         const QRectF &br = d_data->boundingRect;
     474    if ( m_data->legendMode == QwtPlotShapeItem::LegendShape )
     475    {
     476        const QRectF& br = m_data->boundingRect;
    473477
    474478        QPainter painter( &icon );
    … …  
    478482        painter.translate( -br.topLeft() );
    479483
    480         painter.setPen( d_data->pen );
    481         painter.setBrush( d_data->brush );
    482         painter.drawPath( d_data->shape );
     484        painter.setPen( m_data->pen );
     485        painter.setBrush( m_data->brush );
     486        painter.drawPath( m_data->shape );
    483487    }
    484488    else
    485489    {
    486490        QColor iconColor;
    487         if ( d_data->brush.style() != Qt::NoBrush )
    488             iconColor = d_data->brush.color();
     491        if ( m_data->brush.style() != Qt::NoBrush )
     492            iconColor = m_data->brush.color();
    489493        else
    490             iconColor = d_data->pen.color();
     494            iconColor = m_data->pen.color();
    491495
    492496        icon = defaultIcon( iconColor, size );
  • trunk/BNC/qwt/qwt_plot_shapeitem.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_item.h"
    15 #include <qpainterpath.h>
     15
     16#include <qstring.h>
     17
     18class QPainterPath;
     19class QPolygonF;
    1620
    1721/*!
    18   \brief A plot item, which displays any graphical shape,
     22   \brief A plot item, which displays any graphical shape,
    1923         that can be defined by a QPainterPath
    2024
    21   A QPainterPath is a shape composed from intersecting and uniting
    22   regions, rectangles, ellipses or irregular areas defined by lines, and curves.
    23   QwtPlotShapeItem displays a shape with a pen and brush.
     25   A QPainterPath is a shape composed from intersecting and uniting
     26   regions, rectangles, ellipses or irregular areas defined by lines, and curves.
     27   QwtPlotShapeItem displays a shape with a pen and brush.
    2428
    25   QwtPlotShapeItem offers a couple of optimizations like clipping or weeding.
    26   These algorithms need to convert the painter path into polygons that might be
    27   less performant for paths built from curves and ellipses.
     29   QwtPlotShapeItem offers a couple of optimizations like clipping or weeding.
     30   These algorithms need to convert the painter path into polygons that might be
     31   less performant for paths built from curves and ellipses.
    2832
    29   \sa QwtPlotZone
    30 */
    31 class QWT_EXPORT QwtPlotShapeItem: public QwtPlotItem
     33   More complex shapes, that can't be expressed by a QPainterPath can be displayed
     34   using QwtPlotGraphicItem.
     35
     36   \sa QwtPlotZone, QwtPlotGraphicItem
     37 */
     38class QWT_EXPORT QwtPlotShapeItem : public QwtPlotItem
    3239{
    33 public:
     40  public:
    3441    /*!
    3542        Attributes to modify the drawing algorithm.
    … …  
    3744
    3845        \sa setPaintAttribute(), testPaintAttribute()
    39     */
     46     */
    4047    enum PaintAttribute
    4148    {
    4249        /*!
    43           Clip polygons before painting them. In situations, where points
    44           are far outside the visible area (f.e when zooming deep) this
    45           might be a substantial improvement for the painting performance
     50           Clip polygons before painting them. In situations, where points
     51           are far outside the visible area (f.e when zooming deep) this
     52           might be a substantial improvement for the painting performance
    4653
    47           But polygon clipping will convert the painter path into
    48           polygons what might introduce a negative impact on the
    49           performance of paths composed from curves or ellipses.
     54           But polygon clipping will convert the painter path into
     55           polygons what might introduce a negative impact on the
     56           performance of paths composed from curves or ellipses.
    5057         */
    5158        ClipPolygons = 0x01,
    5259    };
    5360
    54     //! Paint attributes
    55     typedef QFlags<PaintAttribute> PaintAttributes;
     61    Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute )
    5662
    5763    //! Mode how to display the item on the legend
    … …  
    6571    };
    6672
    67     explicit QwtPlotShapeItem( const QString &title = QString() );
    68     explicit QwtPlotShapeItem( const QwtText &title );
     73    explicit QwtPlotShapeItem( const QString& title = QString() );
     74    explicit QwtPlotShapeItem( const QwtText& title );
    6975
    7076    virtual ~QwtPlotShapeItem();
    … …  
    7682    LegendMode legendMode() const;
    7783
    78     void setRect( const QRectF & );
    79     void setPolygon( const QPolygonF & );
     84    void setRect( const QRectF& );
     85    void setPolygon( const QPolygonF& );
    8086
    81     void setShape( const QPainterPath & );
     87    void setShape( const QPainterPath& );
    8288    QPainterPath shape() const;
    8389
    84     void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    85     void setPen( const QPen & );
     90    void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
     91    void setPen( const QPen& );
    8692    QPen pen() const;
    8793
    88     void setBrush( const QBrush & );
     94    void setBrush( const QBrush& );
    8995    QBrush brush() const;
    9096
    … …  
    9298    double renderTolerance() const;
    9399
    94     virtual QRectF boundingRect() const;
     100    virtual QRectF boundingRect() const QWT_OVERRIDE;
    95101
    96     virtual void draw( QPainter *,
    97         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    98         const QRectF &canvasRect ) const;
     102    virtual void draw( QPainter*,
     103        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     104        const QRectF& canvasRect ) const QWT_OVERRIDE;
    99105
    100     virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
     106    virtual QwtGraphic legendIcon(
     107        int index, const QSizeF& ) const QWT_OVERRIDE;
    101108
    102     virtual int rtti() const;
     109    virtual int rtti() const QWT_OVERRIDE;
    103110
    104 private:
     111  private:
    105112    void init();
    106113
    107114    class PrivateData;
    108     PrivateData *d_data;
     115    PrivateData* m_data;
    109116};
    110117
  • trunk/BNC/qwt/qwt_plot_spectrocurve.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212#include "qwt_scale_map.h"
    1313#include "qwt_painter.h"
     14#include "qwt_text.h"
     15
    1416#include <qpainter.h>
    1517
    1618class QwtPlotSpectroCurve::PrivateData
    1719{
    18 public:
    19     PrivateData():
    20         colorRange( 0.0, 1000.0 ),
    21         penWidth(0.0),
    22         paintAttributes( QwtPlotSpectroCurve::ClipPoints )
     20  public:
     21    PrivateData()
     22        : colorRange( 0.0, 1000.0 )
     23        , penWidth( 0.0 )
     24        , paintAttributes( QwtPlotSpectroCurve::ClipPoints )
    2325    {
    2426        colorMap = new QwtLinearColorMap();
    … …  
    3032    }
    3133
    32     QwtColorMap *colorMap;
     34    QwtColorMap* colorMap;
    3335    QwtInterval colorRange;
    34     QVector<QRgb> colorTable;
     36    QVector< QRgb > colorTable;
    3537    double penWidth;
    3638    QwtPlotSpectroCurve::PaintAttributes paintAttributes;
    … …  
    3840
    3941/*!
    40   Constructor
    41   \param title Title of the curve
    42 */
    43 QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QwtText &title ):
    44     QwtPlotSeriesItem( title )
     42   Constructor
     43   \param title Title of the curve
     44 */
     45QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QwtText& title )
     46    : QwtPlotSeriesItem( title )
    4547{
    4648    init();
    … …  
    4850
    4951/*!
    50   Constructor
    51   \param title Title of the curve
    52 */
    53 QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QString &title ):
    54     QwtPlotSeriesItem( QwtText( title ) )
     52   Constructor
     53   \param title Title of the curve
     54 */
     55QwtPlotSpectroCurve::QwtPlotSpectroCurve( const QString& title )
     56    : QwtPlotSeriesItem( QwtText( title ) )
    5557{
    5658    init();
    … …  
    6062QwtPlotSpectroCurve::~QwtPlotSpectroCurve()
    6163{
    62     delete d_data;
    63 }
    64 
    65 /*!
    66   \brief Initialize data members
    67 */
     64    delete m_data;
     65}
     66
     67/*!
     68   \brief Initialize data members
     69 */
    6870void QwtPlotSpectroCurve::init()
    6971{
    … …  
    7173    setItemAttribute( QwtPlotItem::AutoScale );
    7274
    73     d_data = new PrivateData;
     75    m_data = new PrivateData;
    7476    setData( new QwtPoint3DSeriesData() );
    7577
    … …  
    8486
    8587/*!
    86   Specify an attribute how to draw the curve
    87 
    88   \param attribute Paint attribute
    89   \param on On/Off
    90   /sa PaintAttribute, testPaintAttribute()
    91 */
     88   Specify an attribute how to draw the curve
     89
     90   \param attribute Paint attribute
     91   \param on On/Off
     92   /sa PaintAttribute, testPaintAttribute()
     93 */
    9294void QwtPlotSpectroCurve::setPaintAttribute( PaintAttribute attribute, bool on )
    9395{
    9496    if ( on )
    95         d_data->paintAttributes |= attribute;
     97        m_data->paintAttributes |= attribute;
    9698    else
    97         d_data->paintAttributes &= ~attribute;
     99        m_data->paintAttributes &= ~attribute;
    98100}
    99101
    … …  
    101103    \return True, when attribute is enabled
    102104    \sa PaintAttribute, setPaintAttribute()
    103 */
     105 */
    104106bool QwtPlotSpectroCurve::testPaintAttribute( PaintAttribute attribute ) const
    105107{
    106     return ( d_data->paintAttributes & attribute );
    107 }
    108 
    109 /*!
    110   Initialize data with an array of samples.
    111   \param samples Vector of points
    112 */
    113 void QwtPlotSpectroCurve::setSamples( const QVector<QwtPoint3D> &samples )
     108    return ( m_data->paintAttributes & attribute );
     109}
     110
     111/*!
     112   Initialize data with an array of samples.
     113   \param samples Vector of points
     114 */
     115void QwtPlotSpectroCurve::setSamples( const QVector< QwtPoint3D >& samples )
    114116{
    115117    setData( new QwtPoint3DSeriesData( samples ) );
    … …  
    117119
    118120/*!
    119   Assign a series of samples
    120 
    121   setSamples() is just a wrapper for setData() without any additional
    122   value - beside that it is easier to find for the developer.
    123 
    124   \param data Data
    125   \warning The item takes ownership of the data object, deleting
     121   Assign a series of samples
     122
     123   setSamples() is just a wrapper for setData() without any additional
     124   value - beside that it is easier to find for the developer.
     125
     126   \param data Data
     127   \warning The item takes ownership of the data object, deleting
    126128           it when its not used anymore.
    127 */
     129 */
    128130void QwtPlotSpectroCurve::setSamples(
    129     QwtSeriesData<QwtPoint3D> *data )
     131    QwtSeriesData< QwtPoint3D >* data )
    130132{
    131133    setData( data );
    … …  
    133135
    134136/*!
    135   Change the color map
    136 
    137   Often it is useful to display the mapping between intensities and
    138   colors as an additional plot axis, showing a color bar.
    139 
    140   \param colorMap Color Map
    141 
    142   \sa colorMap(), setColorRange(), QwtColorMap::color(),
     137   Change the color map
     138
     139   Often it is useful to display the mapping between intensities and
     140   colors as an additional plot axis, showing a color bar.
     141
     142   \param colorMap Color Map
     143
     144   \sa colorMap(), setColorRange(), QwtColorMap::color(),
    143145      QwtScaleWidget::setColorBarEnabled(), QwtScaleWidget::setColorMap()
    144 */
    145 void QwtPlotSpectroCurve::setColorMap( QwtColorMap *colorMap )
    146 {
    147     if ( colorMap != d_data->colorMap )
    148     {
    149         delete d_data->colorMap;
    150         d_data->colorMap = colorMap;
     146 */
     147void QwtPlotSpectroCurve::setColorMap( QwtColorMap* colorMap )
     148{
     149    if ( colorMap != m_data->colorMap )
     150    {
     151        delete m_data->colorMap;
     152        m_data->colorMap = colorMap;
    151153    }
    152154
    … …  
    158160   \return Color Map used for mapping the intensity values to colors
    159161   \sa setColorMap(), setColorRange(), QwtColorMap::color()
    160 */
    161 const QwtColorMap *QwtPlotSpectroCurve::colorMap() const
    162 {
    163     return d_data->colorMap;
     162 */
     163const QwtColorMap* QwtPlotSpectroCurve::colorMap() const
     164{
     165    return m_data->colorMap;
    164166}
    165167
    … …  
    171173
    172174   \sa colorRange(), setColorMap(), QwtColorMap::color()
    173 */
    174 void QwtPlotSpectroCurve::setColorRange( const QwtInterval &interval )
    175 {
    176     if ( interval != d_data->colorRange )
    177     {
    178         d_data->colorRange = interval;
     175 */
     176void QwtPlotSpectroCurve::setColorRange( const QwtInterval& interval )
     177{
     178    if ( interval != m_data->colorRange )
     179    {
     180        m_data->colorRange = interval;
    179181
    180182        legendChanged();
    … …  
    184186
    185187/*!
    186   \return Value interval, that corresponds to the color map
    187   \sa setColorRange(), setColorMap(), QwtColorMap::color()
    188 */
    189 QwtInterval &QwtPlotSpectroCurve::colorRange() const
    190 {
    191     return d_data->colorRange;
    192 }
    193 
    194 /*!
    195   Assign a pen width
    196 
    197   \param penWidth New pen width
    198   \sa penWidth()
    199 */
     188   \return Value interval, that corresponds to the color map
     189   \sa setColorRange(), setColorMap(), QwtColorMap::color()
     190 */
     191QwtInterval& QwtPlotSpectroCurve::colorRange() const
     192{
     193    return m_data->colorRange;
     194}
     195
     196/*!
     197   Assign a pen width
     198
     199   \param penWidth New pen width
     200   \sa penWidth()
     201 */
    200202void QwtPlotSpectroCurve::setPenWidth(double penWidth)
    201203{
    … …  
    203205        penWidth = 0.0;
    204206
    205     if ( d_data->penWidth != penWidth )
    206     {
    207         d_data->penWidth = penWidth;
     207    if ( m_data->penWidth != penWidth )
     208    {
     209        m_data->penWidth = penWidth;
    208210
    209211        legendChanged();
    … …  
    213215
    214216/*!
    215   \return Pen width used to draw a dot
    216   \sa setPenWidth()
    217 */
     217   \return Pen width used to draw a dot
     218   \sa setPenWidth()
     219 */
    218220double QwtPlotSpectroCurve::penWidth() const
    219221{
    220     return d_data->penWidth;
    221 }
    222 
    223 /*!
    224   Draw a subset of the points
    225 
    226   \param painter Painter
    227   \param xMap Maps x-values into pixel coordinates.
    228   \param yMap Maps y-values into pixel coordinates.
    229   \param canvasRect Contents rectangle of the canvas
    230   \param from Index of the first sample to be painted
    231   \param to Index of the last sample to be painted. If to < 0 the
     222    return m_data->penWidth;
     223}
     224
     225/*!
     226   Draw a subset of the points
     227
     228   \param painter Painter
     229   \param xMap Maps x-values into pixel coordinates.
     230   \param yMap Maps y-values into pixel coordinates.
     231   \param canvasRect Contents rectangle of the canvas
     232   \param from Index of the first sample to be painted
     233   \param to Index of the last sample to be painted. If to < 0 the
    232234         series will be painted to its last sample.
    233235
    234   \sa drawDots()
    235 */
    236 void QwtPlotSpectroCurve::drawSeries( QPainter *painter,
    237     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    238     const QRectF &canvasRect, int from, int to ) const
     236   \sa drawDots()
     237 */
     238void QwtPlotSpectroCurve::drawSeries( QPainter* painter,
     239    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     240    const QRectF& canvasRect, int from, int to ) const
    239241{
    240242    if ( !painter || dataSize() <= 0 )
    … …  
    254256
    255257/*!
    256   Draw a subset of the points
    257 
    258   \param painter Painter
    259   \param xMap Maps x-values into pixel coordinates.
    260   \param yMap Maps y-values into pixel coordinates.
    261   \param canvasRect Contents rectangle of the canvas
    262   \param from Index of the first sample to be painted
    263   \param to Index of the last sample to be painted. If to < 0 the
     258   Draw a subset of the points
     259
     260   \param painter Painter
     261   \param xMap Maps x-values into pixel coordinates.
     262   \param yMap Maps y-values into pixel coordinates.
     263   \param canvasRect Contents rectangle of the canvas
     264   \param from Index of the first sample to be painted
     265   \param to Index of the last sample to be painted. If to < 0 the
    264266         series will be painted to its last sample.
    265267
    266   \sa drawSeries()
    267 */
    268 void QwtPlotSpectroCurve::drawDots( QPainter *painter,
    269     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    270     const QRectF &canvasRect, int from, int to ) const
    271 {
    272     if ( !d_data->colorRange.isValid() )
     268   \sa drawSeries()
     269 */
     270void QwtPlotSpectroCurve::drawDots( QPainter* painter,
     271    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     272    const QRectF& canvasRect, int from, int to ) const
     273{
     274    if ( !m_data->colorRange.isValid() )
    273275        return;
    274276
    275277    const bool doAlign = QwtPainter::roundingAlignment( painter );
    276278
    277     const QwtColorMap::Format format = d_data->colorMap->format();
     279    const QwtColorMap::Format format = m_data->colorMap->format();
    278280    if ( format == QwtColorMap::Indexed )
    279         d_data->colorTable = d_data->colorMap->colorTable( d_data->colorRange );
    280 
    281     const QwtSeriesData<QwtPoint3D> *series = data();
     281        m_data->colorTable = m_data->colorMap->colorTable256();
     282
     283    const QwtSeriesData< QwtPoint3D >* series = data();
    282284
    283285    for ( int i = from; i <= to; i++ )
    … …  
    293295        }
    294296
    295         if ( d_data->paintAttributes & QwtPlotSpectroCurve::ClipPoints )
     297        if ( m_data->paintAttributes & QwtPlotSpectroCurve::ClipPoints )
    296298        {
    297299            if ( !canvasRect.contains( xi, yi ) )
    … …  
    301303        if ( format == QwtColorMap::RGB )
    302304        {
    303             const QRgb rgb = d_data->colorMap->rgb(
    304                 d_data->colorRange, sample.z() );
    305 
    306             painter->setPen( QPen( QColor::fromRgba( rgb ), d_data->penWidth ) );
     305            const QRgb rgb = m_data->colorMap->rgb(
     306                m_data->colorRange, sample.z() );
     307
     308            painter->setPen( QPen( QColor::fromRgba( rgb ), m_data->penWidth ) );
    307309        }
    308310        else
    309311        {
    310             const unsigned char index = d_data->colorMap->colorIndex(
    311                 d_data->colorRange, sample.z() );
    312 
    313             painter->setPen( QPen( QColor::fromRgba( d_data->colorTable[index] ),
    314                 d_data->penWidth ) );
     312            const unsigned char index = m_data->colorMap->colorIndex(
     313                256, m_data->colorRange, sample.z() );
     314
     315            painter->setPen( QPen( QColor::fromRgba( m_data->colorTable[index] ),
     316                m_data->penWidth ) );
    315317        }
    316318
    … …  
    318320    }
    319321
    320     d_data->colorTable.clear();
    321 }
     322    m_data->colorTable.clear();
     323}
  • trunk/BNC/qwt/qwt_plot_spectrocurve.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_seriesitem.h"
    15 #include "qwt_series_data.h"
    1615
    17 class QwtSymbol;
    1816class QwtColorMap;
    1917
    … …  
    2119    \brief Curve that displays 3D points as dots, where the z coordinate is
    2220           mapped to a color.
    23 */
    24 class QWT_EXPORT QwtPlotSpectroCurve:
    25     public QwtPlotSeriesItem, public QwtSeriesStore<QwtPoint3D>
     21 */
     22class QWT_EXPORT QwtPlotSpectroCurve
     23    : public QwtPlotSeriesItem
     24    , public QwtSeriesStore< QwtPoint3D >
    2625{
    27 public:
     26  public:
    2827    //! Paint attributes
    2928    enum PaintAttribute
    … …  
    3332    };
    3433
    35     //! Paint attributes
    36     typedef QFlags<PaintAttribute> PaintAttributes;
     34    Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute )
    3735
    38     explicit QwtPlotSpectroCurve( const QString &title = QString() );
    39     explicit QwtPlotSpectroCurve( const QwtText &title );
     36    explicit QwtPlotSpectroCurve( const QString& title = QString() );
     37    explicit QwtPlotSpectroCurve( const QwtText& title );
    4038
    4139    virtual ~QwtPlotSpectroCurve();
    4240
    43     virtual int rtti() const;
     41    virtual int rtti() const QWT_OVERRIDE;
    4442
    4543    void setPaintAttribute( PaintAttribute, bool on = true );
    4644    bool testPaintAttribute( PaintAttribute ) const;
    4745
    48     void setSamples( const QVector<QwtPoint3D> & );
    49     void setSamples( QwtSeriesData<QwtPoint3D> * );
     46    void setSamples( const QVector< QwtPoint3D >& );
     47    void setSamples( QwtSeriesData< QwtPoint3D >* );
    5048
    5149
    52     void setColorMap( QwtColorMap * );
    53     const QwtColorMap *colorMap() const;
     50    void setColorMap( QwtColorMap* );
     51    const QwtColorMap* colorMap() const;
    5452
    55     void setColorRange( const QwtInterval & );
    56     QwtInterval & colorRange() const;
     53    void setColorRange( const QwtInterval& );
     54    QwtInterval& colorRange() const;
    5755
    58     virtual void drawSeries( QPainter *,
    59         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    60         const QRectF &canvasRect, int from, int to ) const;
     56    virtual void drawSeries( QPainter*,
     57        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     58        const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE;
    6159
    6260    void setPenWidth( double );
    6361    double penWidth() const;
    6462
    65 protected:
    66     virtual void drawDots( QPainter *,
    67         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    68         const QRectF &canvasRect, int from, int to ) const;
     63  protected:
     64    virtual void drawDots( QPainter*,
     65        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     66        const QRectF& canvasRect, int from, int to ) const;
    6967
    70 private:
     68  private:
    7169    void init();
    7270
    7371    class PrivateData;
    74     PrivateData *d_data;
     72    PrivateData* m_data;
    7573};
    7674
  • trunk/BNC/qwt/qwt_plot_spectrogram.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_scale_map.h"
    1414#include "qwt_color_map.h"
     15#include "qwt_math.h"
     16
    1517#include <qimage.h>
    1618#include <qpen.h>
    1719#include <qpainter.h>
    18 #include <qmath.h>
    19 #include <qalgorithms.h>
    20 #if QT_VERSION >= 0x040400
    2120#include <qthread.h>
    2221#include <qfuture.h>
    2322#include <qtconcurrentrun.h>
     23
     24#define DEBUG_RENDER 0
     25
     26#if DEBUG_RENDER
     27#include <qelapsedtimer.h>
    2428#endif
    2529
    26 #define DEBUG_RENDER 0
    27 
    28 #if DEBUG_RENDER
    29 #include <QElapsedTimer>
    30 #endif
     30#include <algorithm>
     31
     32static inline bool qwtIsNaN( double d )
     33{
     34    // qt_is_nan is private header and qIsNaN is not inlined
     35    // so we need these code here too
     36
     37    const uchar* ch = (const uchar*)&d;
     38    if ( QSysInfo::ByteOrder == QSysInfo::BigEndian )
     39    {
     40        return ( ch[0] & 0x7f ) == 0x7f && ch[1] > 0xf0;
     41    }
     42    else
     43    {
     44        return ( ch[7] & 0x7f ) == 0x7f && ch[6] > 0xf0;
     45    }
     46}
    3147
    3248class QwtPlotSpectrogram::PrivateData
    3349{
    34 public:
    35     PrivateData():
    36         data( NULL )
     50  public:
     51    PrivateData()
     52        : data( NULL )
     53        , colorTableSize( 0 )
    3754    {
    3855        colorMap = new QwtLinearColorMap();
    … …  
    4461#endif
    4562    }
     63
    4664    ~PrivateData()
    4765    {
    … …  
    5068    }
    5169
    52     QwtRasterData *data;
    53     QwtColorMap *colorMap;
     70    void updateColorTable()
     71    {
     72        if ( colorMap->format() == QwtColorMap::Indexed )
     73        {
     74            colorTable = colorMap->colorTable256();
     75        }
     76        else
     77        {
     78            if ( colorTableSize == 0 )
     79                colorTable.clear();
     80            else
     81                colorTable = colorMap->colorTable( colorTableSize );
     82        }
     83    }
     84
     85    QwtRasterData* data;
     86    QwtColorMap* colorMap;
    5487    DisplayModes displayMode;
    5588
    56     QList<double> contourLevels;
     89    QList< double > contourLevels;
    5790    QPen defaultContourPen;
    5891    QwtRasterData::ConrecFlags conrecFlags;
     92
     93    int colorTableSize;
     94    QVector< QRgb > colorTable;
    5995};
    6096
    … …  
    69105
    70106   \sa QwtPlotItem::setItemAttribute(), QwtPlotItem::setZ()
    71 */
    72 QwtPlotSpectrogram::QwtPlotSpectrogram( const QString &title ):
    73     QwtPlotRasterItem( title )
    74 {
    75     d_data = new PrivateData();
     107 */
     108QwtPlotSpectrogram::QwtPlotSpectrogram( const QString& title )
     109    : QwtPlotRasterItem( title )
     110{
     111    m_data = new PrivateData();
    76112
    77113    setItemAttribute( QwtPlotItem::AutoScale, true );
    … …  
    84120QwtPlotSpectrogram::~QwtPlotSpectrogram()
    85121{
    86     delete d_data;
     122    delete m_data;
    87123}
    88124
    … …  
    102138
    103139   \sa DisplayMode, displayMode()
    104 */
     140 */
    105141void QwtPlotSpectrogram::setDisplayMode( DisplayMode mode, bool on )
    106142{
    107     if ( on != bool( mode & d_data->displayMode ) )
     143    if ( on != bool( mode & m_data->displayMode ) )
    108144    {
    109145        if ( on )
    110             d_data->displayMode |= mode;
     146            m_data->displayMode |= mode;
    111147        else
    112             d_data->displayMode &= ~mode;
     148            m_data->displayMode &= ~mode;
    113149    }
    114150
    … …  
    122158   \param mode Display mode
    123159   \return true if mode is enabled
    124 */
     160 */
    125161bool QwtPlotSpectrogram::testDisplayMode( DisplayMode mode ) const
    126162{
    127     return ( d_data->displayMode & mode );
    128 }
    129 
    130 /*!
    131   Change the color map
    132 
    133   Often it is useful to display the mapping between intensities and
    134   colors as an additional plot axis, showing a color bar.
    135 
    136   \param colorMap Color Map
    137 
    138   \sa colorMap(), QwtScaleWidget::setColorBarEnabled(),
     163    return ( m_data->displayMode & mode );
     164}
     165
     166/*!
     167   Change the color map
     168
     169   Often it is useful to display the mapping between intensities and
     170   colors as an additional plot axis, showing a color bar.
     171
     172   \param colorMap Color Map
     173
     174   \sa colorMap(), QwtScaleWidget::setColorBarEnabled(),
    139175      QwtScaleWidget::setColorMap()
    140 */
    141 void QwtPlotSpectrogram::setColorMap( QwtColorMap *colorMap )
    142 {
    143     if ( d_data->colorMap != colorMap )
    144     {
    145         delete d_data->colorMap;
    146         d_data->colorMap = colorMap;
    147     }
     176 */
     177void QwtPlotSpectrogram::setColorMap( QwtColorMap* colorMap )
     178{
     179    if ( colorMap == NULL )
     180        return;
     181
     182    if ( colorMap != m_data->colorMap )
     183    {
     184        delete m_data->colorMap;
     185        m_data->colorMap = colorMap;
     186    }
     187
     188    m_data->updateColorTable();
    148189
    149190    invalidateCache();
    … …  
    156197   \return Color Map used for mapping the intensity values to colors
    157198   \sa setColorMap()
    158 */
    159 const QwtColorMap *QwtPlotSpectrogram::colorMap() const
    160 {
    161     return d_data->colorMap;
    162 }
    163 
    164 /*!
    165   Build and assign the default pen for the contour lines
    166 
    167   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    168   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    169   to hide this incompatibility.
    170 
    171   \param color Pen color
    172   \param width Pen width
    173   \param style Pen style
    174 
    175   \sa pen(), brush()
     199 */
     200const QwtColorMap* QwtPlotSpectrogram::colorMap() const
     201{
     202    return m_data->colorMap;
     203}
     204
     205/*!
     206    Limit the number of colors being used by the color map
     207
     208    When using a color table the mapping from the value into a color
     209    is usually faster as it can be done by simple lookups into a
     210    precalculated color table.
     211
     212    Setting a table size > 0 enables using a color table, while setting
     213    the size to 0 disables it.
     214
     215    The default size = 0, and no color table is used.
     216
     217    \param numColors Number of colors. 0 means not using a color table
     218    \note The colorTableSize has no effect when using a color table
     219          of QwtColorMap::Indexed, where the size is always 256.
     220
     221
     222    \sa QwtColorMap::colorTable(), colorTableSize()
     223 */
     224void QwtPlotSpectrogram::setColorTableSize( int numColors )
     225{
     226    numColors = qMax( numColors, 0 );
     227    if ( numColors != m_data->colorTableSize )
     228    {
     229        m_data->colorTableSize = numColors;
     230        m_data->updateColorTable();
     231        invalidateCache();
     232    }
     233}
     234/*!
     235    \return Size of the color table, 0 means not using a color table
     236    \sa QwtColorMap::colorTable(), setColorTableSize()
     237 */
     238int QwtPlotSpectrogram::colorTableSize() const
     239{
     240    return m_data->colorTableSize;
     241}
     242
     243/*!
     244   Build and assign the default pen for the contour lines
     245
     246   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     247   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     248   to hide this incompatibility.
     249
     250   \param color Pen color
     251   \param width Pen width
     252   \param style Pen style
     253
     254   \sa pen(), brush()
    176255 */
    177256void QwtPlotSpectrogram::setDefaultContourPen(
    178     const QColor &color, qreal width, Qt::PenStyle style )
     257    const QColor& color, qreal width, Qt::PenStyle style )
    179258{
    180259    setDefaultContourPen( QPen( color, width, style ) );
    … …  
    190269
    191270   \sa defaultContourPen(), contourPen()
    192 */
    193 void QwtPlotSpectrogram::setDefaultContourPen( const QPen &pen )
    194 {
    195     if ( pen != d_data->defaultContourPen )
    196     {
    197         d_data->defaultContourPen = pen;
     271 */
     272void QwtPlotSpectrogram::setDefaultContourPen( const QPen& pen )
     273{
     274    if ( pen != m_data->defaultContourPen )
     275    {
     276        m_data->defaultContourPen = pen;
    198277
    199278        legendChanged();
    … …  
    205284   \return Default contour pen
    206285   \sa setDefaultContourPen()
    207 */
     286 */
    208287QPen QwtPlotSpectrogram::defaultContourPen() const
    209288{
    210     return d_data->defaultContourPen;
     289    return m_data->defaultContourPen;
    211290}
    212291
    … …  
    221300
    222301   \sa setDefaultContourPen(), setColorMap(), setContourLevels()
    223 */
     302 */
    224303QPen QwtPlotSpectrogram::contourPen( double level ) const
    225304{
    226     if ( d_data->data == NULL || d_data->colorMap == NULL )
     305    if ( m_data->data == NULL || m_data->colorMap == NULL )
    227306        return QPen();
    228307
    229     const QwtInterval intensityRange = d_data->data->interval(Qt::ZAxis);
    230     const QColor c( d_data->colorMap->rgb( intensityRange, level ) );
     308    const QwtInterval intensityRange = m_data->data->interval(Qt::ZAxis);
     309    const QColor c( m_data->colorMap->rgb( intensityRange, level ) );
    231310
    232311    return QPen( c );
    … …  
    242321   \sa testConrecFlag(), renderContourLines(),
    243322       QwtRasterData::contourLines()
    244 */
     323 */
    245324void QwtPlotSpectrogram::setConrecFlag(
    246325    QwtRasterData::ConrecFlag flag, bool on )
    247326{
    248     if ( bool( d_data->conrecFlags & flag ) == on )
     327    if ( bool( m_data->conrecFlags & flag ) == on )
    249328        return;
    250329
    251330    if ( on )
    252         d_data->conrecFlags |= flag;
     331        m_data->conrecFlags |= flag;
    253332    else
    254         d_data->conrecFlags &= ~flag;
     333        m_data->conrecFlags &= ~flag;
    255334
    256335    itemChanged();
    … …  
    268347   \sa setConrecClag(), renderContourLines(),
    269348       QwtRasterData::contourLines()
    270 */
     349 */
    271350bool QwtPlotSpectrogram::testConrecFlag(
    272351    QwtRasterData::ConrecFlag flag ) const
    273352{
    274     return d_data->conrecFlags & flag;
     353    return m_data->conrecFlags & flag;
    275354}
    276355
    … …  
    283362
    284363   \note contourLevels returns the same levels but sorted.
    285 */
    286 void QwtPlotSpectrogram::setContourLevels( const QList<double> &levels )
    287 {
    288     d_data->contourLevels = levels;
    289     qSort( d_data->contourLevels );
     364 */
     365void QwtPlotSpectrogram::setContourLevels( const QList< double >& levels )
     366{
     367    m_data->contourLevels = levels;
     368    std::sort( m_data->contourLevels.begin(), m_data->contourLevels.end() );
    290369
    291370    legendChanged();
    … …  
    300379   \sa contourLevels(), renderContourLines(),
    301380       QwtRasterData::contourLines()
    302 */
    303 QList<double> QwtPlotSpectrogram::contourLevels() const
    304 {
    305     return d_data->contourLevels;
    306 }
    307 
    308 /*!
    309   Set the data to be displayed
    310 
    311   \param data Spectrogram Data
    312   \sa data()
    313 */
    314 void QwtPlotSpectrogram::setData( QwtRasterData *data )
    315 {
    316     if ( data != d_data->data )
    317     {
    318         delete d_data->data;
    319         d_data->data = data;
     381 */
     382QList< double > QwtPlotSpectrogram::contourLevels() const
     383{
     384    return m_data->contourLevels;
     385}
     386
     387/*!
     388   Set the data to be displayed
     389
     390   \param data Spectrogram Data
     391   \sa data()
     392 */
     393void QwtPlotSpectrogram::setData( QwtRasterData* data )
     394{
     395    if ( data != m_data->data )
     396    {
     397        delete m_data->data;
     398        m_data->data = data;
    320399
    321400        invalidateCache();
    … …  
    325404
    326405/*!
    327   \return Spectrogram data
    328   \sa setData()
    329 */
    330 const QwtRasterData *QwtPlotSpectrogram::data() const
    331 {
    332     return d_data->data;
    333 }
    334 
    335 /*!
    336   \return Spectrogram data
    337   \sa setData()
    338 */
    339 QwtRasterData *QwtPlotSpectrogram::data()
    340 {
    341     return d_data->data;
     406   \return Spectrogram data
     407   \sa setData()
     408 */
     409const QwtRasterData* QwtPlotSpectrogram::data() const
     410{
     411    return m_data->data;
     412}
     413
     414/*!
     415   \return Spectrogram data
     416   \sa setData()
     417 */
     418QwtRasterData* QwtPlotSpectrogram::data()
     419{
     420    return m_data->data;
    342421}
    343422
    … …  
    350429   \param axis X, Y, or Z axis
    351430   \sa QwtRasterData::interval()
    352 */
     431 */
    353432QwtInterval QwtPlotSpectrogram::interval(Qt::Axis axis) const
    354433{
    355     if ( d_data->data == NULL )
     434    if ( m_data->data == NULL )
    356435        return QwtInterval();
    357436
    358     return d_data->data->interval( axis );
     437    return m_data->data->interval( axis );
    359438}
    360439
    … …  
    374453   \sa QwtPlotRasterItem::pixelHint(), QwtRasterData::pixelHint(),
    375454       render(), renderImage()
    376 */
    377 QRectF QwtPlotSpectrogram::pixelHint( const QRectF &area ) const
    378 {
    379     if ( d_data->data == NULL )
     455 */
     456QRectF QwtPlotSpectrogram::pixelHint( const QRectF& area ) const
     457{
     458    if ( m_data->data == NULL )
    380459        return QRectF();
    381460
    382     return d_data->data->pixelHint( area );
     461    return m_data->data->pixelHint( area );
    383462}
    384463
    … …  
    388467   For each pixel of area the value is mapped into a color.
    389468
    390   \param xMap X-Scale Map
    391   \param yMap Y-Scale Map
    392   \param area Requested area for the image in scale coordinates
    393   \param imageSize Size of the requested image
     469   \param xMap X-Scale Map
     470   \param yMap Y-Scale Map
     471   \param area Requested area for the image in scale coordinates
     472   \param imageSize Size of the requested image
    394473
    395474   \return A QImage::Format_Indexed8 or QImage::Format_ARGB32 depending
    … …  
    398477   \sa QwtRasterData::value(), QwtColorMap::rgb(),
    399478       QwtColorMap::colorIndex()
    400 */
     479 */
    401480QImage QwtPlotSpectrogram::renderImage(
    402     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    403     const QRectF &area, const QSize &imageSize ) const
    404 {
    405     if ( imageSize.isEmpty() || d_data->data == NULL
    406         || d_data->colorMap == NULL )
     481    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     482    const QRectF& area, const QSize& imageSize ) const
     483{
     484    if ( imageSize.isEmpty() || m_data->data == NULL
     485        || m_data->colorMap == NULL )
    407486    {
    408487        return QImage();
    409488    }
    410489
    411     const QwtInterval intensityRange = d_data->data->interval( Qt::ZAxis );
     490    const QwtInterval intensityRange = m_data->data->interval( Qt::ZAxis );
    412491    if ( !intensityRange.isValid() )
    413492        return QImage();
    414493
    415     QImage::Format format = ( d_data->colorMap->format() == QwtColorMap::RGB )
     494    const QImage::Format format = ( m_data->colorMap->format() == QwtColorMap::RGB )
    416495        ? QImage::Format_ARGB32 : QImage::Format_Indexed8;
    417496
    418497    QImage image( imageSize, format );
    419498
    420     if ( d_data->colorMap->format() == QwtColorMap::Indexed )
    421         image.setColorTable( d_data->colorMap->colorTable( intensityRange ) );
    422 
    423     d_data->data->initRaster( area, image.size() );
     499    if ( m_data->colorMap->format() == QwtColorMap::Indexed )
     500        image.setColorTable( m_data->colorMap->colorTable256() );
     501
     502    m_data->data->initRaster( area, image.size() );
    424503
    425504#if DEBUG_RENDER
    … …  
    428507#endif
    429508
    430 #if QT_VERSION >= 0x040400 && !defined(QT_NO_QFUTURE)
     509#if !defined( QT_NO_QFUTURE )
    431510    uint numThreads = renderThreadCount();
    432511
    … …  
    439518    const int numRows = imageSize.height() / numThreads;
    440519
    441     QList< QFuture<void> > futures;
     520    QVector< QFuture< void > > futures;
     521    futures.reserve( numThreads - 1 );
     522
    442523    for ( uint i = 0; i < numThreads; i++ )
    443524    {
    … …  
    451532        {
    452533            futures += QtConcurrent::run(
     534#if QT_VERSION >= 0x060000
     535                &QwtPlotSpectrogram::renderTile, this,
     536#else
    453537                this, &QwtPlotSpectrogram::renderTile,
     538#endif
    454539                xMap, yMap, tile, &image );
    455540        }
    456541    }
     542
    457543    for ( int i = 0; i < futures.size(); i++ )
    458544        futures[i].waitForFinished();
    459545
    460 #else // QT_VERSION < 0x040400
     546#else
    461547    const QRect tile( 0, 0, image.width(), image.height() );
    462548    renderTile( xMap, yMap, tile, &image );
    … …  
    468554#endif
    469555
    470     d_data->data->discardRaster();
     556    m_data->data->discardRaster();
    471557
    472558    return image;
    … …  
    483569    \param tile Geometry of the tile in image coordinates
    484570    \param image Image to be rendered
    485 */
     571 */
    486572void QwtPlotSpectrogram::renderTile(
    487     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    488     const QRect &tile, QImage *image ) const
    489 {
    490     const QwtInterval range = d_data->data->interval( Qt::ZAxis );
    491     if ( !range.isValid() )
     573    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     574    const QRect& tile, QImage* image ) const
     575{
     576    const QwtInterval range = m_data->data->interval( Qt::ZAxis );
     577    if ( range.width() <= 0.0 )
    492578        return;
    493579
    494     if ( d_data->colorMap->format() == QwtColorMap::RGB )
    495     {
     580    const bool hasGaps = !m_data->data->testAttribute( QwtRasterData::WithoutGaps );
     581
     582    if ( m_data->colorMap->format() == QwtColorMap::RGB )
     583    {
     584        const int numColors = m_data->colorTable.size();
     585        const QRgb* rgbTable = m_data->colorTable.constData();
     586        const QwtColorMap* colorMap = m_data->colorMap;
     587
    496588        for ( int y = tile.top(); y <= tile.bottom(); y++ )
    497589        {
    498590            const double ty = yMap.invTransform( y );
    499591
    500             QRgb *line = reinterpret_cast<QRgb *>( image->scanLine( y ) );
     592            QRgb* line = reinterpret_cast< QRgb* >( image->scanLine( y ) );
    501593            line += tile.left();
    502594
    … …  
    505597                const double tx = xMap.invTransform( x );
    506598
    507                 *line++ = d_data->colorMap->rgb( range,
    508                     d_data->data->value( tx, ty ) );
     599                const double value = m_data->data->value( tx, ty );
     600
     601                if ( hasGaps && qwtIsNaN( value ) )
     602                {
     603                    *line++ = 0u;
     604                }
     605                else if ( numColors == 0 )
     606                {
     607                    *line++ = colorMap->rgb( range, value );
     608                }
     609                else
     610                {
     611                    const uint index = colorMap->colorIndex( numColors, range, value );
     612                    *line++ = rgbTable[index];
     613                }
    509614            }
    510615        }
    511616    }
    512     else if ( d_data->colorMap->format() == QwtColorMap::Indexed )
     617    else if ( m_data->colorMap->format() == QwtColorMap::Indexed )
    513618    {
    514619        for ( int y = tile.top(); y <= tile.bottom(); y++ )
    … …  
    516621            const double ty = yMap.invTransform( y );
    517622
    518             unsigned char *line = image->scanLine( y );
     623            unsigned char* line = image->scanLine( y );
    519624            line += tile.left();
    520625
    … …  
    523628                const double tx = xMap.invTransform( x );
    524629
    525                 *line++ = d_data->colorMap->colorIndex( range,
    526                     d_data->data->value( tx, ty ) );
     630                const double value = m_data->data->value( tx, ty );
     631
     632                if ( hasGaps && qwtIsNaN( value ) )
     633                {
     634                    *line++ = 0;
     635                }
     636                else
     637                {
     638                    const uint index = m_data->colorMap->colorIndex( 256, range, value );
     639                    *line++ = static_cast< unsigned char >( index );
     640                }
    527641            }
    528642        }
    … …  
    546660
    547661   \sa drawContourLines(), QwtRasterData::contourLines()
    548 */
     662 */
    549663QSize QwtPlotSpectrogram::contourRasterSize(
    550     const QRectF &area, const QRect &rect ) const
     664    const QRectF& area, const QRect& rect ) const
    551665{
    552666    QSize raster = rect.size() / 2;
    … …  
    555669    if ( !pixelRect.isEmpty() )
    556670    {
    557         const QSize res( qCeil( rect.width() / pixelRect.width() ),
    558             qCeil( rect.height() / pixelRect.height() ) );
     671        const QSize res( qwtCeil( rect.width() / pixelRect.width() ),
     672            qwtCeil( rect.height() / pixelRect.height() ) );
    559673        raster = raster.boundedTo( res );
    560674    }
    … …  
    572686   \sa contourLevels(), setConrecFlag(),
    573687       QwtRasterData::contourLines()
    574 */
     688 */
    575689QwtRasterData::ContourLines QwtPlotSpectrogram::renderContourLines(
    576     const QRectF &rect, const QSize &raster ) const
    577 {
    578     if ( d_data->data == NULL )
     690    const QRectF& rect, const QSize& raster ) const
     691{
     692    if ( m_data->data == NULL )
    579693        return QwtRasterData::ContourLines();
    580694
    581     return d_data->data->contourLines( rect, raster,
    582         d_data->contourLevels, d_data->conrecFlags );
     695    return m_data->data->contourLines( rect, raster,
     696        m_data->contourLevels, m_data->conrecFlags );
    583697}
    584698
    … …  
    592706
    593707   \sa renderContourLines(), defaultContourPen(), contourPen()
    594 */
    595 void QwtPlotSpectrogram::drawContourLines( QPainter *painter,
    596         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    597         const QwtRasterData::ContourLines &contourLines ) const
    598 {
    599     if ( d_data->data == NULL )
     708 */
     709void QwtPlotSpectrogram::drawContourLines( QPainter* painter,
     710    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     711    const QwtRasterData::ContourLines& contourLines ) const
     712{
     713    if ( m_data->data == NULL )
    600714        return;
    601715
    602     const int numLevels = d_data->contourLevels.size();
     716    const int numLevels = m_data->contourLevels.size();
    603717    for ( int l = 0; l < numLevels; l++ )
    604718    {
    605         const double level = d_data->contourLevels[l];
     719        const double level = m_data->contourLevels[l];
    606720
    607721        QPen pen = defaultContourPen();
    … …  
    614728        painter->setPen( pen );
    615729
    616         const QPolygonF &lines = contourLines[level];
     730        const QPolygonF& lines = contourLines[level];
    617731        for ( int i = 0; i < lines.size(); i += 2 )
    618732        {
    619733            const QPointF p1( xMap.transform( lines[i].x() ),
    620734                yMap.transform( lines[i].y() ) );
    621             const QPointF p2( xMap.transform( lines[i+1].x() ),
    622                 yMap.transform( lines[i+1].y() ) );
     735            const QPointF p2( xMap.transform( lines[i + 1].x() ),
     736                yMap.transform( lines[i + 1].y() ) );
    623737
    624738            QwtPainter::drawLine( painter, p1, p2 );
    … …  
    628742
    629743/*!
    630   \brief Draw the spectrogram
    631 
    632   \param painter Painter
    633   \param xMap Maps x-values into pixel coordinates.
    634   \param yMap Maps y-values into pixel coordinates.
    635   \param canvasRect Contents rectangle of the canvas in painter coordinates
    636 
    637   \sa setDisplayMode(), renderImage(),
     744   \brief Draw the spectrogram
     745
     746   \param painter Painter
     747   \param xMap Maps x-values into pixel coordinates.
     748   \param yMap Maps y-values into pixel coordinates.
     749   \param canvasRect Contents rectangle of the canvas in painter coordinates
     750
     751   \sa setDisplayMode(), renderImage(),
    638752      QwtPlotRasterItem::draw(), drawContourLines()
    639 */
    640 void QwtPlotSpectrogram::draw( QPainter *painter,
    641     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    642     const QRectF &canvasRect ) const
    643 {
    644     if ( d_data->displayMode & ImageMode )
     753 */
     754void QwtPlotSpectrogram::draw( QPainter* painter,
     755    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     756    const QRectF& canvasRect ) const
     757{
     758    if ( m_data->displayMode & ImageMode )
    645759        QwtPlotRasterItem::draw( painter, xMap, yMap, canvasRect );
    646760
    647     if ( d_data->displayMode & ContourMode )
     761    if ( m_data->displayMode & ContourMode )
    648762    {
    649763        // Add some pixels at the borders
  • trunk/BNC/qwt/qwt_plot_spectrogram.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1414#include "qwt_raster_data.h"
    1515#include "qwt_plot_rasteritem.h"
    16 #include <qlist.h>
    1716
    1817class QwtColorMap;
     18template< typename T > class QList;
    1919
    2020/*!
    21   \brief A plot item, which displays a spectrogram
     21   \brief A plot item, which displays a spectrogram
    2222
    23   A spectrogram displays 3-dimensional data, where the 3rd dimension
    24   ( the intensity ) is displayed using colors. The colors are calculated
    25   from the values using a color map.
     23   A spectrogram displays 3-dimensional data, where the 3rd dimension
     24   ( the intensity ) is displayed using colors. The colors are calculated
     25   from the values using a color map.
    2626
    27   On multi-core systems the performance of the image composition
    28   can often be improved by dividing the area into tiles - each of them
    29   rendered in a different thread ( see QwtPlotItem::setRenderThreadCount() ).
     27   On multi-core systems the performance of the image composition
     28   can often be improved by dividing the area into tiles - each of them
     29   rendered in a different thread ( see QwtPlotItem::setRenderThreadCount() ).
    3030
    31   In ContourMode contour lines are painted for the contour levels.
     31   In ContourMode contour lines are painted for the contour levels.
    3232
    33   \image html spectrogram3.png
     33   \sa QwtRasterData, QwtColorMap, QwtPlotItem::setRenderThreadCount()
     34 */
    3435
    35   \sa QwtRasterData, QwtColorMap, QwtPlotItem::setRenderThreadCount()
    36 */
    37 
    38 class QWT_EXPORT QwtPlotSpectrogram: public QwtPlotRasterItem
     36class QWT_EXPORT QwtPlotSpectrogram : public QwtPlotRasterItem
    3937{
    40 public:
     38  public:
    4139    /*!
    42       The display mode controls how the raster data will be represented.
    43       \sa setDisplayMode(), testDisplayMode()
    44     */
     40       The display mode controls how the raster data will be represented.
     41       \sa setDisplayMode(), testDisplayMode()
     42     */
    4543
    4644    enum DisplayMode
    … …  
    5351    };
    5452
    55     //! Display modes
    56     typedef QFlags<DisplayMode> DisplayModes;
     53    Q_DECLARE_FLAGS( DisplayModes, DisplayMode )
    5754
    58     explicit QwtPlotSpectrogram( const QString &title = QString() );
     55    explicit QwtPlotSpectrogram( const QString& title = QString() );
    5956    virtual ~QwtPlotSpectrogram();
    6057
    … …  
    6259    bool testDisplayMode( DisplayMode ) const;
    6360
    64     void setData( QwtRasterData *data );
    65     const QwtRasterData *data() const;
    66     QwtRasterData *data();
     61    void setData( QwtRasterData* data );
     62    const QwtRasterData* data() const;
     63    QwtRasterData* data();
    6764
    68     void setColorMap( QwtColorMap * );
    69     const QwtColorMap *colorMap() const;
     65    void setColorMap( QwtColorMap* );
     66    const QwtColorMap* colorMap() const;
    7067
    71     virtual QwtInterval interval(Qt::Axis) const;
    72     virtual QRectF pixelHint( const QRectF & ) const;
     68    void setColorTableSize( int numColors );
     69    int colorTableSize() const;
    7370
    74     void setDefaultContourPen( const QColor &,
     71    virtual QwtInterval interval( Qt::Axis ) const QWT_OVERRIDE;
     72    virtual QRectF pixelHint( const QRectF& ) const QWT_OVERRIDE;
     73
     74    void setDefaultContourPen( const QColor&,
    7575        qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    76     void setDefaultContourPen( const QPen & );
     76    void setDefaultContourPen( const QPen& );
    7777    QPen defaultContourPen() const;
    7878
    … …  
    8282    bool testConrecFlag( QwtRasterData::ConrecFlag ) const;
    8383
    84     void setContourLevels( const QList<double> & );
    85     QList<double> contourLevels() const;
     84    void setContourLevels( const QList< double >& );
     85    QList< double > contourLevels() const;
    8686
    87     virtual int rtti() const;
     87    virtual int rtti() const QWT_OVERRIDE;
    8888
    89     virtual void draw( QPainter *,
    90         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    91         const QRectF &canvasRect ) const;
     89    virtual void draw( QPainter*,
     90        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     91        const QRectF& canvasRect ) const QWT_OVERRIDE;
    9292
    93 protected:
     93  protected:
    9494    virtual QImage renderImage(
    95         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    96         const QRectF &area, const QSize &imageSize ) const;
     95        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     96        const QRectF& area, const QSize& imageSize ) const QWT_OVERRIDE;
    9797
    9898    virtual QSize contourRasterSize(
    99         const QRectF &, const QRect & ) const;
     99        const QRectF&, const QRect& ) const;
    100100
    101101    virtual QwtRasterData::ContourLines renderContourLines(
    102         const QRectF &rect, const QSize &raster ) const;
     102        const QRectF& rect, const QSize& raster ) const;
    103103
    104     virtual void drawContourLines( QPainter *,
    105         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
     104    virtual void drawContourLines( QPainter*,
     105        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
    106106        const QwtRasterData::ContourLines& ) const;
    107107
    108     void renderTile( const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    109         const QRect &tile, QImage * ) const;
     108    void renderTile( const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     109        const QRect& tile, QImage* ) const;
    110110
    111 private:
     111  private:
    112112    class PrivateData;
    113     PrivateData *d_data;
     113    PrivateData* m_data;
    114114};
    115115
  • trunk/BNC/qwt/qwt_plot_svgitem.cpp

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_plot_svgitem.h"
    11 #include "qwt_scale_map.h"
    12 #include "qwt_painter.h"
    13 #include <qpainter.h>
     11#include "qwt_text.h"
     12#include "qwt_graphic.h"
     13
    1414#include <qsvgrenderer.h>
    15 
    16 class QwtPlotSvgItem::PrivateData
    17 {
    18 public:
    19     PrivateData()
    20     {
    21     }
    22 
    23     QRectF boundingRect;
    24     QSvgRenderer renderer;
    25 };
    2615
    2716/*!
    2817   \brief Constructor
    29 
    30    Sets the following item attributes:
    31    - QwtPlotItem::AutoScale: true
    32    - QwtPlotItem::Legend:    false
    33 
    3418   \param title Title
    35 */
    36 QwtPlotSvgItem::QwtPlotSvgItem( const QString& title ):
    37     QwtPlotItem( QwtText( title ) )
     19 */
     20QwtPlotSvgItem::QwtPlotSvgItem( const QString& title )
     21    : QwtPlotGraphicItem( QwtText( title ) )
    3822{
    39     init();
    4023}
    4124
    4225/*!
    4326   \brief Constructor
    44 
    45    Sets the following item attributes:
    46    - QwtPlotItem::AutoScale: true
    47    - QwtPlotItem::Legend:    false
    48 
    4927   \param title Title
    50 */
    51 QwtPlotSvgItem::QwtPlotSvgItem( const QwtText& title ):
    52     QwtPlotItem( title )
     28 */
     29QwtPlotSvgItem::QwtPlotSvgItem( const QwtText& title )
     30    : QwtPlotGraphicItem( title )
    5331{
    54     init();
    5532}
    5633
    … …  
    5835QwtPlotSvgItem::~QwtPlotSvgItem()
    5936{
    60     delete d_data;
    61 }
    62 
    63 void QwtPlotSvgItem::init()
    64 {
    65     d_data = new PrivateData();
    66     d_data->boundingRect = QwtPlotItem::boundingRect();
    67 
    68     setItemAttribute( QwtPlotItem::AutoScale, true );
    69     setItemAttribute( QwtPlotItem::Legend, false );
    70 
    71     setZ( 8.0 );
    72 }
    73 
    74 //! \return QwtPlotItem::Rtti_PlotSVG
    75 int QwtPlotSvgItem::rtti() const
    76 {
    77     return QwtPlotItem::Rtti_PlotSVG;
    7837}
    7938
    … …  
    8544
    8645   \return true, if the SVG file could be loaded
    87 */
    88 bool QwtPlotSvgItem::loadFile( const QRectF &rect,
    89     const QString &fileName )
     46 */
     47bool QwtPlotSvgItem::loadFile( const QRectF& rect,
     48    const QString& fileName )
    9049{
    91     d_data->boundingRect = rect;
    92     const bool ok = d_data->renderer.load( fileName );
     50    QwtGraphic graphic;
    9351
    94     legendChanged();
    95     itemChanged();
     52    QSvgRenderer renderer;
     53
     54    const bool ok = renderer.load( fileName );
     55    if ( ok )
     56    {
     57        QPainter p( &graphic );
     58        renderer.render( &p );
     59    }
     60
     61    setGraphic( rect, graphic );
    9662
    9763    return ok;
    … …  
    10571
    10672   \return true, if the SVG data could be loaded
    107 */
    108 bool QwtPlotSvgItem::loadData( const QRectF &rect,
    109     const QByteArray &data )
     73 */
     74bool QwtPlotSvgItem::loadData( const QRectF& rect,
     75    const QByteArray& data )
    11076{
    111     d_data->boundingRect = rect;
    112     const bool ok = d_data->renderer.load( data );
     77    QwtGraphic graphic;
    11378
    114     legendChanged();
    115     itemChanged();
     79    QSvgRenderer renderer;
     80
     81    const bool ok = renderer.load( data );
     82    if ( ok )
     83    {
     84        QPainter p( &graphic );
     85        renderer.render( &p );
     86    }
     87
     88    setGraphic( rect, graphic );
    11689
    11790    return ok;
    11891}
    119 
    120 //! Bounding rectangle of the item
    121 QRectF QwtPlotSvgItem::boundingRect() const
    122 {
    123     return d_data->boundingRect;
    124 }
    125 
    126 //! \return Renderer used to render the SVG data
    127 const QSvgRenderer &QwtPlotSvgItem::renderer() const
    128 {
    129     return d_data->renderer;
    130 }
    131 
    132 //! \return Renderer used to render the SVG data
    133 QSvgRenderer &QwtPlotSvgItem::renderer()
    134 {
    135     return d_data->renderer;
    136 }
    137 
    138 /*!
    139   Draw the SVG item
    140 
    141   \param painter Painter
    142   \param xMap X-Scale Map
    143   \param yMap Y-Scale Map
    144   \param canvasRect Contents rect of the plot canvas
    145 */
    146 void QwtPlotSvgItem::draw( QPainter *painter,
    147     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    148     const QRectF &canvasRect ) const
    149 {
    150     const QRectF cRect = QwtScaleMap::invTransform(
    151         xMap, yMap, canvasRect.toRect() );
    152     const QRectF bRect = boundingRect();
    153     if ( bRect.isValid() && cRect.isValid() )
    154     {
    155         QRectF rect = bRect;
    156         if ( bRect.contains( cRect ) )
    157             rect = cRect;
    158 
    159         const QRectF r = QwtScaleMap::transform( xMap, yMap, rect );
    160         render( painter, viewBox( rect ), r );
    161     }
    162 }
    163 
    164 /*!
    165   Render the SVG data
    166 
    167   \param painter Painter
    168   \param viewBox View Box, see QSvgRenderer::viewBox()
    169   \param rect Target rectangle on the paint device
    170 */
    171 void QwtPlotSvgItem::render( QPainter *painter,
    172     const QRectF &viewBox, const QRectF &rect ) const
    173 {
    174     if ( !viewBox.isValid() )
    175         return;
    176 
    177     QRectF r = rect;
    178 
    179     if ( QwtPainter::roundingAlignment( painter ) )
    180     {
    181         r.setLeft ( qRound( r.left() ) );
    182         r.setRight ( qRound( r.right() ) );
    183         r.setTop ( qRound( r.top() ) );
    184         r.setBottom ( qRound( r.bottom() ) );
    185     }
    186 
    187     d_data->renderer.setViewBox( viewBox );
    188     d_data->renderer.render( painter, r );
    189 }
    190 
    191 /*!
    192   Calculate the view box from rect and boundingRect().
    193 
    194   \param rect Rectangle in scale coordinates
    195   \return View box, see QSvgRenderer::viewBox()
    196 */
    197 QRectF QwtPlotSvgItem::viewBox( const QRectF &rect ) const
    198 {
    199     const QSize sz = d_data->renderer.defaultSize();
    200     const QRectF br = boundingRect();
    201 
    202     if ( !rect.isValid() || !br.isValid() || sz.isNull() )
    203         return QRectF();
    204 
    205     QwtScaleMap xMap;
    206     xMap.setScaleInterval( br.left(), br.right() );
    207     xMap.setPaintInterval( 0, sz.width() );
    208 
    209     QwtScaleMap yMap;
    210     yMap.setScaleInterval( br.top(), br.bottom() );
    211     yMap.setPaintInterval( sz.height(), 0 );
    212 
    213     const double x1 = xMap.transform( rect.left() );
    214     const double x2 = xMap.transform( rect.right() );
    215     const double y1 = yMap.transform( rect.bottom() );
    216     const double y2 = yMap.transform( rect.top() );
    217 
    218     return QRectF( x1, y1, x2 - x1, y2 - y1 );
    219 }
  • trunk/BNC/qwt/qwt_plot_svgitem.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    88 *****************************************************************************/
    99
    10 #ifndef QWT_PLOT_SVGITEM_H
    11 #define QWT_PLOT_SVGITEM_H
     10#ifndef QWT_PLOT_SVG_ITEM_H
     11#define QWT_PLOT_SVG_ITEM_H
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_plot_item.h"
    15 #include <qstring.h>
     14#include "qwt_plot_graphicitem.h"
    1615
    17 class QSvgRenderer;
    1816class QByteArray;
    1917
    2018/*!
    21   \brief A plot item, which displays
     19   \brief A plot item, which displays
    2220         data in Scalable Vector Graphics (SVG) format.
    2321
    24   SVG images are often used to display maps
    25 */
     22   SVG images are often used to display maps
    2623
    27 class QWT_EXPORT QwtPlotSvgItem: public QwtPlotItem
     24   QwtPlotSvgItem is only a small convenience wrapper class for
     25   QwtPlotGraphicItem, that creates a QwtGraphic from SVG data.
     26 */
     27
     28class QWT_EXPORT QwtPlotSvgItem : public QwtPlotGraphicItem
    2829{
    29 public:
     30  public:
    3031    explicit QwtPlotSvgItem( const QString& title = QString() );
    3132    explicit QwtPlotSvgItem( const QwtText& title );
    3233    virtual ~QwtPlotSvgItem();
    3334
    34     bool loadFile( const QRectF&, const QString &fileName );
    35     bool loadData( const QRectF&, const QByteArray & );
    36 
    37     virtual QRectF boundingRect() const;
    38 
    39     virtual void draw( QPainter *,
    40         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    41         const QRectF &canvasRect ) const;
    42 
    43     virtual int rtti() const;
    44 
    45 protected:
    46     const QSvgRenderer &renderer() const;
    47     QSvgRenderer &renderer();
    48 
    49     void render( QPainter *,
    50         const QRectF &viewBox, const QRectF &rect ) const;
    51 
    52     QRectF viewBox( const QRectF &rect ) const;
    53 
    54 private:
    55     void init();
    56 
    57     class PrivateData;
    58     PrivateData *d_data;
     35    bool loadFile( const QRectF&, const QString& fileName );
     36    bool loadData( const QRectF&, const QByteArray& );
    5937};
    6038
  • trunk/BNC/qwt/qwt_plot_textlabel.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_plot_textlabel.h"
    1111#include "qwt_painter.h"
    12 #include "qwt_scale_map.h"
     12#include "qwt_text.h"
     13#include "qwt_math.h"
     14
    1315#include <qpainter.h>
     16#include <qpaintengine.h>
    1417#include <qpixmap.h>
    15 #include <qmath.h>
    1618
    1719static QRect qwtItemRect( int renderFlags,
    18     const QRectF &rect, const QSizeF &itemSize )
     20    const QRectF& rect, const QSizeF& itemSize )
    1921{
    2022    int x;
    … …  
    5153class QwtPlotTextLabel::PrivateData
    5254{
    53 public:
    54     PrivateData():
    55         margin( 5 )
     55  public:
     56    PrivateData()
     57        : margin( 5 )
    5658    {
    5759    }
    … …  
    7678
    7779   \sa QwtPlotItem::setItemAttribute(), QwtPlotItem::setZ()
    78 */
    79 
    80 QwtPlotTextLabel::QwtPlotTextLabel():
    81     QwtPlotItem( QwtText( "Label" ) )
    82 {
    83     d_data = new PrivateData;
     80 */
     81
     82QwtPlotTextLabel::QwtPlotTextLabel()
     83    : QwtPlotItem( QwtText( "Label" ) )
     84{
     85    m_data = new PrivateData;
    8486
    8587    setItemAttribute( QwtPlotItem::AutoScale, false );
    … …  
    9294QwtPlotTextLabel::~QwtPlotTextLabel()
    9395{
    94     delete d_data;
     96    delete m_data;
    9597}
    9698
    … …  
    102104
    103105/*!
    104   Set the text
    105 
    106   The label will be aligned to the plot canvas according to
    107   the alignment flags of text.
    108 
    109   \param text Text to be displayed
    110 
    111   \sa text(), QwtText::renderFlags()
    112 */
    113 void QwtPlotTextLabel::setText( const QwtText &text )
    114 {
    115     if ( d_data->text != text )
    116     {
    117         d_data->text = text;
     106   Set the text
     107
     108   The label will be aligned to the plot canvas according to
     109   the alignment flags of text.
     110
     111   \param text Text to be displayed
     112
     113   \sa text(), QwtText::renderFlags()
     114 */
     115void QwtPlotTextLabel::setText( const QwtText& text )
     116{
     117    if ( m_data->text != text )
     118    {
     119        m_data->text = text;
    118120
    119121        invalidateCache();
    … …  
    123125
    124126/*!
    125   \return Text to be displayed
    126   \sa setText()
    127 */
     127   \return Text to be displayed
     128   \sa setText()
     129 */
    128130QwtText QwtPlotTextLabel::text() const
    129131{
    130     return d_data->text;
    131 }
    132 
    133 /*!
    134   Set the margin
    135 
    136   The margin is the distance between the contentsRect()
    137   of the plot canvas and the rectangle where the label can
    138   be displayed.
    139 
    140   \param margin Margin
    141 
    142   \sa margin(), textRect()
     132    return m_data->text;
     133}
     134
     135/*!
     136   Set the margin
     137
     138   The margin is the distance between the contentsRect()
     139   of the plot canvas and the rectangle where the label can
     140   be displayed.
     141
     142   \param margin Margin
     143
     144   \sa margin(), textRect()
    143145 */
    144146void QwtPlotTextLabel::setMargin( int margin )
    145147{
    146148    margin = qMax( margin, 0 );
    147     if ( d_data->margin != margin )
    148     {
    149         d_data->margin = margin;
     149    if ( m_data->margin != margin )
     150    {
     151        m_data->margin = margin;
    150152        itemChanged();
    151153    }
    … …  
    153155
    154156/*!
    155   \return Margin added to the contentsMargins() of the canvas
    156   \sa setMargin()
    157 */
     157   \return Margin added to the contentsMargins() of the canvas
     158   \sa setMargin()
     159 */
    158160int QwtPlotTextLabel::margin() const
    159161{
    160     return d_data->margin;
    161 }
    162 
    163 /*!
    164   Draw the text label
    165 
    166   \param painter Painter
    167   \param xMap x Scale Map
    168   \param yMap y Scale Map
    169   \param canvasRect Contents rectangle of the canvas in painter coordinates
    170 
    171   \sa textRect()
    172 */
    173 
    174 void QwtPlotTextLabel::draw( QPainter *painter,
    175     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    176     const QRectF &canvasRect ) const
     162    return m_data->margin;
     163}
     164
     165/*!
     166   Draw the text label
     167
     168   \param painter Painter
     169   \param xMap x Scale Map
     170   \param yMap y Scale Map
     171   \param canvasRect Contents rectangle of the canvas in painter coordinates
     172
     173   \sa textRect()
     174 */
     175
     176void QwtPlotTextLabel::draw( QPainter* painter,
     177    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     178    const QRectF& canvasRect ) const
    177179{
    178180    Q_UNUSED( xMap );
    179181    Q_UNUSED( yMap );
    180182
    181     const int m = d_data->margin;
     183    const int m = m_data->margin;
    182184
    183185    const QRectF rect = textRect( canvasRect.adjusted( m, m, -m, -m ),
    184         d_data->text.textSize( painter->font() ) );
     186        m_data->text.textSize( painter->font() ) );
    185187
    186188    bool doCache = QwtPainter::roundingAlignment( painter );
    … …  
    208210
    209211        int pw = 0;
    210         if ( d_data->text.borderPen().style() != Qt::NoPen )
    211             pw = qMax( d_data->text.borderPen().width(), 1 );
     212        if ( m_data->text.borderPen().style() != Qt::NoPen )
     213            pw = qMax( m_data->text.borderPen().width(), 1 );
    212214
    213215        QRect pixmapRect;
    214         pixmapRect.setLeft( qFloor( rect.left() ) - pw );
    215         pixmapRect.setTop( qFloor( rect.top() ) - pw );
    216         pixmapRect.setRight( qCeil( rect.right() ) + pw );
    217         pixmapRect.setBottom( qCeil( rect.bottom() ) + pw );
    218 
    219 #define QWT_HIGH_DPI 1
    220 
    221 #if QT_VERSION >= 0x050100 && QWT_HIGH_DPI
    222         const qreal pixelRatio = painter->device()->devicePixelRatio();
     216        pixmapRect.setLeft( qwtFloor( rect.left() ) - pw );
     217        pixmapRect.setTop( qwtFloor( rect.top() ) - pw );
     218        pixmapRect.setRight( qwtCeil( rect.right() ) + pw );
     219        pixmapRect.setBottom( qwtCeil( rect.bottom() ) + pw );
     220
     221#if QT_VERSION >= 0x050000
     222        const qreal pixelRatio = QwtPainter::devicePixelRatio( painter->device() );
    223223        const QSize scaledSize = pixmapRect.size() * pixelRatio;
    224224#else
    225225        const QSize scaledSize = pixmapRect.size();
    226226#endif
    227         if ( d_data->pixmap.isNull() ||
    228             ( scaledSize != d_data->pixmap.size() )  )
     227
     228        if ( m_data->pixmap.isNull() ||
     229            ( scaledSize != m_data->pixmap.size() ) )
    229230        {
    230             d_data->pixmap = QPixmap( scaledSize );
    231 #if QT_VERSION >= 0x050100 && QWT_HIGH_DPI
    232             d_data->pixmap.setDevicePixelRatio( pixelRatio );
     231            m_data->pixmap = QPixmap( scaledSize );
     232#if QT_VERSION >= 0x050000
     233            m_data->pixmap.setDevicePixelRatio( pixelRatio );
    233234#endif
    234             d_data->pixmap.fill( Qt::transparent );
     235            m_data->pixmap.fill( Qt::transparent );
    235236
    236237            const QRect r( pw, pw,
    237238                pixmapRect.width() - 2 * pw, pixmapRect.height() - 2 * pw );
    238239
    239             QPainter pmPainter( &d_data->pixmap );
    240             d_data->text.draw( &pmPainter, r );
     240            QPainter pmPainter( &m_data->pixmap );
     241            m_data->text.draw( &pmPainter, r );
    241242        }
    242243
    243         painter->drawPixmap( pixmapRect, d_data->pixmap );
     244        painter->drawPixmap( pixmapRect, m_data->pixmap );
    244245    }
    245246    else
    246247    {
    247         d_data->text.draw( painter, rect );
     248        m_data->text.draw( painter, rect );
    248249    }
    249250}
    … …  
    261262 */
    262263QRectF QwtPlotTextLabel::textRect(
    263     const QRectF &rect, const QSizeF &textSize ) const
    264 {
    265     return qwtItemRect( d_data->text.renderFlags(), rect, textSize );
     264    const QRectF& rect, const QSizeF& textSize ) const
     265{
     266    return qwtItemRect( m_data->text.renderFlags(), rect, textSize );
    266267}
    267268
    … …  
    269270void QwtPlotTextLabel::invalidateCache()
    270271{
    271     d_data->pixmap = QPixmap();
    272 }
     272    m_data->pixmap = QPixmap();
     273}
  • trunk/BNC/qwt/qwt_plot_textlabel.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_PLOT_TEXT_LABEL_H
    11 #define QWT_PLOT_TEXT_LABEL_H 1
     11#define QWT_PLOT_TEXT_LABEL_H
    1212
    1313#include "qwt_global.h"
    1414#include "qwt_plot_item.h"
    15 #include "qwt_text.h"
     15
     16class QwtText;
    1617
    1718/*!
    18   \brief A plot item, which displays a text label
     19   \brief A plot item, which displays a text label
    1920
    20   QwtPlotTextLabel displays a text label aligned to the plot canvas.
     21   QwtPlotTextLabel displays a text label aligned to the plot canvas.
    2122
    22   In opposite to QwtPlotMarker the position of the label is unrelated to
    23   plot coordinates.
     23   In opposite to QwtPlotMarker the position of the label is unrelated to
     24   plot coordinates.
    2425
    25   As drawing a text is an expensive operation the label is cached
    26   in a pixmap to speed up replots.
     26   As drawing a text is an expensive operation the label is cached
     27   in a pixmap to speed up replots.
    2728
    28   \par Example
     29   \par Example
    2930    The following code shows how to add a title.
    3031    \code
    … …  
    4041      titleItem->attach( plot );
    4142    \endcode
    42   \endpar
    4343
    44   \sa QwtPlotMarker
    45 */
     44   \sa QwtPlotMarker
     45 */
    4646
    47 class QWT_EXPORT QwtPlotTextLabel: public QwtPlotItem
     47class QWT_EXPORT QwtPlotTextLabel : public QwtPlotItem
    4848{
    49 public:
     49  public:
    5050    QwtPlotTextLabel();
    5151    virtual ~QwtPlotTextLabel();
    5252
    53     virtual int rtti() const;
     53    virtual int rtti() const QWT_OVERRIDE;
    5454
    55     void setText( const QwtText & );
     55    void setText( const QwtText& );
    5656    QwtText text() const;
    5757
    … …  
    5959    int margin() const;
    6060
    61     virtual QRectF textRect( const QRectF &, const QSizeF & ) const;
     61    virtual QRectF textRect( const QRectF&, const QSizeF& ) const;
    6262
    63 protected:
    64     virtual void draw( QPainter *,
    65         const QwtScaleMap &, const QwtScaleMap &,
    66         const QRectF &) const;
     63  protected:
     64    virtual void draw( QPainter*,
     65        const QwtScaleMap&, const QwtScaleMap&,
     66        const QRectF&) const QWT_OVERRIDE;
    6767
    6868    void invalidateCache();
    6969
    70 private:
     70  private:
    7171    class PrivateData;
    72     PrivateData *d_data;
     72    PrivateData* m_data;
    7373};
    7474
  • trunk/BNC/qwt/qwt_plot_tradingcurve.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_plot_tradingcurve.h"
    1111#include "qwt_scale_map.h"
    12 #include "qwt_clipper.h"
    1312#include "qwt_painter.h"
     13#include "qwt_text.h"
     14#include "qwt_graphic.h"
     15#include "qwt_math.h"
     16
    1417#include <qpainter.h>
    1518
    16 static inline bool qwtIsSampleInside( const QwtOHLCSample &sample,
     19static inline bool qwtIsSampleInside( const QwtOHLCSample& sample,
    1720    double tMin, double tMax, double vMin, double vMax )
    1821{
    … …  
    2831class QwtPlotTradingCurve::PrivateData
    2932{
    30 public:
    31     PrivateData():
    32         symbolStyle( QwtPlotTradingCurve::CandleStick ),
    33         symbolExtent( 0.6 ),
    34         minSymbolWidth( 2.0 ),
    35         maxSymbolWidth( -1.0 ),
    36         paintAttributes( QwtPlotTradingCurve::ClipSymbols )
     33  public:
     34    PrivateData()
     35        : symbolStyle( QwtPlotTradingCurve::CandleStick )
     36        , symbolExtent( 0.6 )
     37        , minSymbolWidth( 2.0 )
     38        , maxSymbolWidth( -1.0 )
     39        , paintAttributes( QwtPlotTradingCurve::ClipSymbols )
    3740    {
    3841        symbolBrush[0] = QBrush( Qt::white );
    … …  
    5255
    5356/*!
    54   Constructor
    55   \param title Title of the curve
    56 */
    57 QwtPlotTradingCurve::QwtPlotTradingCurve( const QwtText &title ):
    58     QwtPlotSeriesItem( title )
     57   Constructor
     58   \param title Title of the curve
     59 */
     60QwtPlotTradingCurve::QwtPlotTradingCurve( const QwtText& title )
     61    : QwtPlotSeriesItem( title )
    5962{
    6063    init();
    … …  
    6265
    6366/*!
    64   Constructor
    65   \param title Title of the curve
    66 */
    67 QwtPlotTradingCurve::QwtPlotTradingCurve( const QString &title ):
    68     QwtPlotSeriesItem( QwtText( title ) )
     67   Constructor
     68   \param title Title of the curve
     69 */
     70QwtPlotTradingCurve::QwtPlotTradingCurve( const QString& title )
     71    : QwtPlotSeriesItem( QwtText( title ) )
    6972{
    7073    init();
    … …  
    7477QwtPlotTradingCurve::~QwtPlotTradingCurve()
    7578{
    76     delete d_data;
     79    delete m_data;
    7780}
    7881
    … …  
    8386    setItemAttribute( QwtPlotItem::AutoScale, true );
    8487
    85     d_data = new PrivateData;
     88    m_data = new PrivateData;
    8689    setData( new QwtTradingChartData() );
    8790
    … …  
    9699
    97100/*!
    98   Specify an attribute how to draw the curve
    99 
    100   \param attribute Paint attribute
    101   \param on On/Off
    102   \sa testPaintAttribute()
    103 */
     101   Specify an attribute how to draw the curve
     102
     103   \param attribute Paint attribute
     104   \param on On/Off
     105   \sa testPaintAttribute()
     106 */
    104107void QwtPlotTradingCurve::setPaintAttribute(
    105108    PaintAttribute attribute, bool on )
    106109{
    107110    if ( on )
    108         d_data->paintAttributes |= attribute;
     111        m_data->paintAttributes |= attribute;
    109112    else
    110         d_data->paintAttributes &= ~attribute;
     113        m_data->paintAttributes &= ~attribute;
    111114}
    112115
    … …  
    114117    \return True, when attribute is enabled
    115118    \sa PaintAttribute, setPaintAttribute()
    116 */
     119 */
    117120bool QwtPlotTradingCurve::testPaintAttribute(
    118121    PaintAttribute attribute ) const
    119122{
    120     return ( d_data->paintAttributes & attribute );
    121 }
    122 
    123 /*!
    124   Initialize data with an array of samples.
    125   \param samples Vector of samples
    126 
    127   \sa QwtPlotSeriesItem::setData()
    128 */
     123    return ( m_data->paintAttributes & attribute );
     124}
     125
     126/*!
     127   Initialize data with an array of samples.
     128   \param samples Vector of samples
     129
     130   \sa QwtPlotSeriesItem::setData()
     131 */
    129132void QwtPlotTradingCurve::setSamples(
    130     const QVector<QwtOHLCSample> &samples )
     133    const QVector< QwtOHLCSample >& samples )
    131134{
    132135    setData( new QwtTradingChartData( samples ) );
    … …  
    134137
    135138/*!
    136   Assign a series of samples
    137 
    138   setSamples() is just a wrapper for setData() without any additional
    139   value - beside that it is easier to find for the developer.
    140 
    141   \param data Data
    142   \warning The item takes ownership of the data object, deleting
     139   Assign a series of samples
     140
     141   setSamples() is just a wrapper for setData() without any additional
     142   value - beside that it is easier to find for the developer.
     143
     144   \param data Data
     145   \warning The item takes ownership of the data object, deleting
    143146           it when its not used anymore.
    144 */
     147 */
    145148void QwtPlotTradingCurve::setSamples(
    146     QwtSeriesData<QwtOHLCSample> *data )
     149    QwtSeriesData< QwtOHLCSample >* data )
    147150{
    148151    setData( data );
    … …  
    150153
    151154/*!
    152   Set the symbol style
    153 
    154   \param style Symbol style
    155 
    156   \sa symbolStyle(), setSymbolExtent(),
     155   Set the symbol style
     156
     157   \param style Symbol style
     158
     159   \sa symbolStyle(), setSymbolExtent(),
    157160      setSymbolPen(), setSymbolBrush()
    158 */
     161 */
    159162void QwtPlotTradingCurve::setSymbolStyle( SymbolStyle style )
    160163{
    161     if ( style != d_data->symbolStyle )
    162     {
    163         d_data->symbolStyle = style;
     164    if ( style != m_data->symbolStyle )
     165    {
     166        m_data->symbolStyle = style;
    164167
    165168        legendChanged();
    … …  
    169172
    170173/*!
    171   \return Symbol style
    172   \sa setSymbolStyle(), symbolExtent(), symbolPen(), symbolBrush()
    173 */
     174   \return Symbol style
     175   \sa setSymbolStyle(), symbolExtent(), symbolPen(), symbolBrush()
     176 */
    174177QwtPlotTradingCurve::SymbolStyle QwtPlotTradingCurve::symbolStyle() const
    175178{
    176     return d_data->symbolStyle;
    177 }
    178 
    179 /*!
    180   Build and assign the symbol pen
    181 
    182   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    183   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    184   to hide this incompatibility.
    185 
    186   \param color Pen color
    187   \param width Pen width
    188   \param style Pen style
    189 
    190   \sa pen(), brush()
     179    return m_data->symbolStyle;
     180}
     181
     182/*!
     183   Build and assign the symbol pen
     184
     185   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     186   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     187   to hide this incompatibility.
     188
     189   \param color Pen color
     190   \param width Pen width
     191   \param style Pen style
     192
     193   \sa pen(), brush()
    191194 */
    192195void QwtPlotTradingCurve::setSymbolPen(
    193     const QColor &color, qreal width, Qt::PenStyle style )
     196    const QColor& color, qreal width, Qt::PenStyle style )
    194197{
    195198    setSymbolPen( QPen( color, width, style ) );
    … …  
    197200
    198201/*!
    199   \brief Set the symbol pen
    200 
    201   The symbol pen is used for rendering the lines of the
    202   bar or candlestick symbols
    203 
    204   \sa symbolPen(), setSymbolBrush()
    205 */
    206 void QwtPlotTradingCurve::setSymbolPen( const QPen &pen )
    207 {
    208     if ( pen != d_data->symbolPen )
    209     {
    210         d_data->symbolPen = pen;
     202   \brief Set the symbol pen
     203
     204   The symbol pen is used for rendering the lines of the
     205   bar or candlestick symbols
     206
     207   \sa symbolPen(), setSymbolBrush()
     208 */
     209void QwtPlotTradingCurve::setSymbolPen( const QPen& pen )
     210{
     211    if ( pen != m_data->symbolPen )
     212    {
     213        m_data->symbolPen = pen;
    211214
    212215        legendChanged();
    … …  
    216219
    217220/*!
    218   \return Symbol pen
    219   \sa setSymbolPen(), symbolBrush()
    220 */
     221   \return Symbol pen
     222   \sa setSymbolPen(), symbolBrush()
     223 */
    221224QPen QwtPlotTradingCurve::symbolPen() const
    222225{
    223     return d_data->symbolPen;
    224 }
    225 
    226 /*!
    227   Set the symbol brush
    228 
    229   \param direction Direction type
    230   \param brush Brush used to fill the body of all candlestick
     226    return m_data->symbolPen;
     227}
     228
     229/*!
     230   Set the symbol brush
     231
     232   \param direction Direction type
     233   \param brush Brush used to fill the body of all candlestick
    231234               symbols with the direction
    232235
    233   \sa symbolBrush(), setSymbolPen()
    234 */
     236   \sa symbolBrush(), setSymbolPen()
     237 */
    235238void QwtPlotTradingCurve::setSymbolBrush(
    236     Direction direction, const QBrush &brush )
     239    Direction direction, const QBrush& brush )
    237240{
    238241    // silencing -Wtautological-constant-out-of-range-compare
    … …  
    241244        return;
    242245
    243     if ( brush != d_data->symbolBrush[ index ] )
    244     {
    245         d_data->symbolBrush[ index ] = brush;
     246    if ( brush != m_data->symbolBrush[ index ] )
     247    {
     248        m_data->symbolBrush[ index ] = brush;
    246249
    247250        legendChanged();
    … …  
    251254
    252255/*!
    253   \param direction
    254   \return Brush used to fill the body of all candlestick
     256   \param direction
     257   \return Brush used to fill the body of all candlestick
    255258          symbols with the direction
    256259
    257   \sa setSymbolPen(), symbolBrush()
    258 */
     260   \sa setSymbolPen(), symbolBrush()
     261 */
    259262QBrush QwtPlotTradingCurve::symbolBrush( Direction direction ) const
    260263{
    … …  
    263266        return QBrush();
    264267
    265     return d_data->symbolBrush[ index ];
    266 }
    267 
    268 /*!
    269   \brief Set the extent of the symbol
    270 
    271   The width of the symbol is given in scale coordinates. When painting
    272   a symbol the width is scaled into paint device coordinates
    273   by scaledSymbolWidth(). The scaled width is bounded by
    274   minSymbolWidth(), maxSymbolWidth()
    275 
    276   \param extent Symbol width in scale coordinates
    277 
    278   \sa symbolExtent(), scaledSymbolWidth(),
     268    return m_data->symbolBrush[ index ];
     269}
     270
     271/*!
     272   \brief Set the extent of the symbol
     273
     274   The width of the symbol is given in scale coordinates. When painting
     275   a symbol the width is scaled into paint device coordinates
     276   by scaledSymbolWidth(). The scaled width is bounded by
     277   minSymbolWidth(), maxSymbolWidth()
     278
     279   \param extent Symbol width in scale coordinates
     280
     281   \sa symbolExtent(), scaledSymbolWidth(),
    279282      setMinSymbolWidth(), setMaxSymbolWidth()
    280 */
     283 */
    281284void QwtPlotTradingCurve::setSymbolExtent( double extent )
    282285{
    283     extent = qMax( 0.0, extent );
    284     if ( extent != d_data->symbolExtent )
    285     {
    286         d_data->symbolExtent = extent;
     286    extent = qwtMaxF( 0.0, extent );
     287    if ( extent != m_data->symbolExtent )
     288    {
     289        m_data->symbolExtent = extent;
    287290
    288291        legendChanged();
    … …  
    292295
    293296/*!
    294   \return Extent of a symbol in scale coordinates
    295   \sa setSymbolExtent(), scaledSymbolWidth(),
     297   \return Extent of a symbol in scale coordinates
     298   \sa setSymbolExtent(), scaledSymbolWidth(),
    296299      minSymbolWidth(), maxSymbolWidth()
    297 */
     300 */
    298301double QwtPlotTradingCurve::symbolExtent() const
    299302{
    300     return d_data->symbolExtent;
    301 }
    302 
    303 /*!
    304   Set a minimum for the symbol width
    305 
    306   \param width Width in paint device coordinates
    307   \sa minSymbolWidth(), setMaxSymbolWidth(), setSymbolExtent()
     303    return m_data->symbolExtent;
     304}
     305
     306/*!
     307   Set a minimum for the symbol width
     308
     309   \param width Width in paint device coordinates
     310   \sa minSymbolWidth(), setMaxSymbolWidth(), setSymbolExtent()
    308311 */
    309312void QwtPlotTradingCurve::setMinSymbolWidth( double width )
    310313{
    311     width = qMax( width, 0.0 );
    312     if ( width != d_data->minSymbolWidth )
    313     {
    314         d_data->minSymbolWidth = width;
     314    width = qwtMaxF( width, 0.0 );
     315    if ( width != m_data->minSymbolWidth )
     316    {
     317        m_data->minSymbolWidth = width;
    315318
    316319        legendChanged();
    … …  
    320323
    321324/*!
    322   \return Minmum for the symbol width
    323   \sa setMinSymbolWidth(), maxSymbolWidth(), symbolExtent()
     325   \return Minmum for the symbol width
     326   \sa setMinSymbolWidth(), maxSymbolWidth(), symbolExtent()
    324327 */
    325328double QwtPlotTradingCurve::minSymbolWidth() const
    326329{
    327     return d_data->minSymbolWidth;
    328 }
    329 
    330 /*!
    331   Set a maximum for the symbol width
    332 
    333   A value <= 0.0 means an unlimited width
    334 
    335   \param width Width in paint device coordinates
    336   \sa maxSymbolWidth(), setMinSymbolWidth(), setSymbolExtent()
     330    return m_data->minSymbolWidth;
     331}
     332
     333/*!
     334   Set a maximum for the symbol width
     335
     336   A value <= 0.0 means an unlimited width
     337
     338   \param width Width in paint device coordinates
     339   \sa maxSymbolWidth(), setMinSymbolWidth(), setSymbolExtent()
    337340 */
    338341void QwtPlotTradingCurve::setMaxSymbolWidth( double width )
    339342{
    340     if ( width != d_data->maxSymbolWidth )
    341     {
    342         d_data->maxSymbolWidth = width;
     343    if ( width != m_data->maxSymbolWidth )
     344    {
     345        m_data->maxSymbolWidth = width;
    343346
    344347        legendChanged();
    … …  
    348351
    349352/*!
    350   \return Maximum for the symbol width
    351   \sa setMaxSymbolWidth(), minSymbolWidth(), symbolExtent()
     353   \return Maximum for the symbol width
     354   \sa setMaxSymbolWidth(), minSymbolWidth(), symbolExtent()
    352355 */
    353356double QwtPlotTradingCurve::maxSymbolWidth() const
    354357{
    355     return d_data->maxSymbolWidth;
    356 }
    357 
    358 /*!
    359   \return Bounding rectangle of all samples.
    360   For an empty series the rectangle is invalid.
    361 */
     358    return m_data->maxSymbolWidth;
     359}
     360
     361/*!
     362   \return Bounding rectangle of all samples.
     363   For an empty series the rectangle is invalid.
     364 */
    362365QRectF QwtPlotTradingCurve::boundingRect() const
    363366{
    … …  
    370373
    371374/*!
    372   Draw an interval of the curve
    373 
    374   \param painter Painter
    375   \param xMap Maps x-values into pixel coordinates.
    376   \param yMap Maps y-values into pixel coordinates.
    377   \param canvasRect Contents rectangle of the canvas
    378   \param from Index of the first point to be painted
    379   \param to Index of the last point to be painted. If to < 0 the
     375   Draw an interval of the curve
     376
     377   \param painter Painter
     378   \param xMap Maps x-values into pixel coordinates.
     379   \param yMap Maps y-values into pixel coordinates.
     380   \param canvasRect Contents rectangle of the canvas
     381   \param from Index of the first point to be painted
     382   \param to Index of the last point to be painted. If to < 0 the
    380383         curve will be painted to its last point.
    381384
    382   \sa drawSymbols()
    383 */
    384 void QwtPlotTradingCurve::drawSeries( QPainter *painter,
    385     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    386     const QRectF &canvasRect, int from, int to ) const
     385   \sa drawSymbols()
     386 */
     387void QwtPlotTradingCurve::drawSeries( QPainter* painter,
     388    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     389    const QRectF& canvasRect, int from, int to ) const
    387390{
    388391    if ( to < 0 )
    … …  
    397400    painter->save();
    398401
    399     if ( d_data->symbolStyle != QwtPlotTradingCurve::NoSymbol )
     402    if ( m_data->symbolStyle != QwtPlotTradingCurve::NoSymbol )
    400403        drawSymbols( painter, xMap, yMap, canvasRect, from, to );
    401404
    … …  
    404407
    405408/*!
    406   Draw symbols
    407 
    408   \param painter Painter
    409   \param xMap x map
    410   \param yMap y map
    411   \param canvasRect Contents rectangle of the canvas
    412   \param from Index of the first point to be painted
    413   \param to Index of the last point to be painted
    414 
    415   \sa drawSeries()
    416 */
    417 void QwtPlotTradingCurve::drawSymbols( QPainter *painter,
    418     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    419     const QRectF &canvasRect, int from, int to ) const
     409   Draw symbols
     410
     411   \param painter Painter
     412   \param xMap x map
     413   \param yMap y map
     414   \param canvasRect Contents rectangle of the canvas
     415   \param from Index of the first point to be painted
     416   \param to Index of the last point to be painted
     417
     418   \sa drawSeries()
     419 */
     420void QwtPlotTradingCurve::drawSymbols( QPainter* painter,
     421    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     422    const QRectF& canvasRect, int from, int to ) const
    420423{
    421424    const QRectF tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect );
    422425
    423     const QwtScaleMap *timeMap, *valueMap;
     426    const QwtScaleMap* timeMap, * valueMap;
    424427    double tMin, tMax, vMin, vMax;
    425428
    … …  
    447450
    448451    const bool inverted = timeMap->isInverting();
    449     const bool doClip = d_data->paintAttributes & ClipSymbols;
     452    const bool doClip = m_data->paintAttributes & ClipSymbols;
    450453    const bool doAlign = QwtPainter::roundingAlignment( painter );
    451454
    452455    double symbolWidth = scaledSymbolWidth( xMap, yMap, canvasRect );
    453456    if ( doAlign )
    454         symbolWidth = qFloor( 0.5 * symbolWidth ) * 2.0;
    455 
    456     QPen pen = d_data->symbolPen;
     457        symbolWidth = std::floor( 0.5 * symbolWidth ) * 2.0;
     458
     459    QPen pen = m_data->symbolPen;
    457460    pen.setCapStyle( Qt::FlatCap );
    458461
    … …  
    486489            }
    487490
    488             switch( d_data->symbolStyle )
     491            switch( m_data->symbolStyle )
    489492            {
    490493                case Bar:
    … …  
    496499                case CandleStick:
    497500                {
    498                     painter->setBrush( d_data->symbolBrush[ brushIndex ] );
     501                    painter->setBrush( m_data->symbolBrush[ brushIndex ] );
    499502                    drawCandleStick( painter, translatedSample,
    500503                        orient, symbolWidth );
    … …  
    503506                default:
    504507                {
    505                     if ( d_data->symbolStyle >= UserSymbol )
     508                    if ( m_data->symbolStyle >= UserSymbol )
    506509                    {
    507                         painter->setBrush( d_data->symbolBrush[ brushIndex ] );
    508                         drawUserSymbol( painter, d_data->symbolStyle,
     510                        painter->setBrush( m_data->symbolBrush[ brushIndex ] );
     511                        drawUserSymbol( painter, m_data->symbolStyle,
    509512                            translatedSample, orient, inverted, symbolWidth );
    510513                    }
    … …  
    516519
    517520/*!
    518   \brief Draw a symbol for a symbol style >= UserSymbol
    519 
    520   The implementation does nothing and is intended to be overloaded
    521 
    522   \param painter Qt painter, initialized with pen/brush
    523   \param symbolStyle Symbol style
    524   \param sample Samples already translated into paint device coordinates
    525   \param orientation Vertical or horizontal
    526   \param inverted True, when the opposite scale
     521   \brief Draw a symbol for a symbol style >= UserSymbol
     522
     523   The implementation does nothing and is intended to be overloaded
     524
     525   \param painter Qt painter, initialized with pen/brush
     526   \param symbolStyle Symbol style
     527   \param sample Samples already translated into paint device coordinates
     528   \param orientation Vertical or horizontal
     529   \param inverted True, when the opposite scale
    527530                  ( Qt::Vertical: x, Qt::Horizontal: y ) is increasing
    528531                  in the opposite direction as QPainter coordinates.
    529   \param symbolWidth Width of the symbol in paint device coordinates
    530 */
    531 void QwtPlotTradingCurve::drawUserSymbol( QPainter *painter,
    532     SymbolStyle symbolStyle, const QwtOHLCSample &sample,
     532   \param symbolWidth Width of the symbol in paint device coordinates
     533 */
     534void QwtPlotTradingCurve::drawUserSymbol( QPainter* painter,
     535    SymbolStyle symbolStyle, const QwtOHLCSample& sample,
    533536    Qt::Orientation orientation, bool inverted, double symbolWidth ) const
    534537{
    … …  
    542545
    543546/*!
    544   \brief Draw a bar
    545 
    546   \param painter Qt painter, initialized with pen/brush
    547   \param sample Sample, already translated into paint device coordinates
    548   \param orientation Vertical or horizontal
    549   \param inverted When inverted is false the open tick is painted
     547   \brief Draw a bar
     548
     549   \param painter Qt painter, initialized with pen/brush
     550   \param sample Sample, already translated into paint device coordinates
     551   \param orientation Vertical or horizontal
     552   \param inverted When inverted is false the open tick is painted
    550553                  to the left/top, otherwise it is painted right/bottom.
    551554                  The close tick is painted in the opposite direction
    … …  
    553556                  painted in the opposite d
    554557                  opposite direction.
    555   \param width Width or height of the candle, depending on the orientation
    556 
    557   \sa Bar
    558 */
    559 void QwtPlotTradingCurve::drawBar( QPainter *painter,
    560     const QwtOHLCSample &sample, Qt::Orientation orientation,
     558   \param width Width or height of the candle, depending on the orientation
     559
     560   \sa Bar
     561 */
     562void QwtPlotTradingCurve::drawBar( QPainter* painter,
     563    const QwtOHLCSample& sample, Qt::Orientation orientation,
    561564    bool inverted, double width ) const
    562565{
    … …  
    587590
    588591/*!
    589   \brief Draw a candle stick
    590 
    591   \param painter Qt painter, initialized with pen/brush
    592   \param sample Samples already translated into paint device coordinates
    593   \param orientation Vertical or horizontal
    594   \param width Width or height of the candle, depending on the orientation
    595 
    596   \sa CandleStick
    597 */
    598 void QwtPlotTradingCurve::drawCandleStick( QPainter *painter,
    599     const QwtOHLCSample &sample, Qt::Orientation orientation,
     592   \brief Draw a candle stick
     593
     594   \param painter Qt painter, initialized with pen/brush
     595   \param sample Samples already translated into paint device coordinates
     596   \param orientation Vertical or horizontal
     597   \param width Width or height of the candle, depending on the orientation
     598
     599   \sa CandleStick
     600 */
     601void QwtPlotTradingCurve::drawCandleStick( QPainter* painter,
     602    const QwtOHLCSample& sample, Qt::Orientation orientation,
    600603    double width ) const
    601604{
    602605    const double t = sample.time;
    603     const double v1 = qMin( sample.low, sample.high );
    604     const double v2 = qMin( sample.open, sample.close );
    605     const double v3 = qMax( sample.low, sample.high );
    606     const double v4 = qMax( sample.open, sample.close );
     606    const double v1 = qwtMinF( sample.low, sample.high );
     607    const double v2 = qwtMinF( sample.open, sample.close );
     608    const double v3 = qwtMaxF( sample.low, sample.high );
     609    const double v4 = qwtMaxF( sample.open, sample.close );
    607610
    608611    if ( orientation == Qt::Vertical )
    … …  
    629632
    630633/*!
    631   \return A rectangle filled with the color of the symbol pen
    632 
    633   \param index Index of the legend entry
     634   \return A rectangle filled with the color of the symbol pen
     635
     636   \param index Index of the legend entry
    634637                ( usually there is only one )
    635   \param size Icon size
    636 
    637   \sa setLegendIconSize(), legendData()
    638 */
     638   \param size Icon size
     639
     640   \sa setLegendIconSize(), legendData()
     641 */
    639642QwtGraphic QwtPlotTradingCurve::legendIcon( int index,
    640     const QSizeF &size ) const
     643    const QSizeF& size ) const
    641644{
    642645    Q_UNUSED( index );
    643     return defaultIcon( d_data->symbolPen.color(), size );
    644 }
    645 
    646 /*!
    647   Calculate the symbol width in paint coordinates
    648 
    649   The width is calculated by scaling the symbol extent into
    650   paint device coordinates bounded by the minimum/maximum
    651   symbol width.
    652 
    653   \param xMap Maps x-values into pixel coordinates.
    654   \param yMap Maps y-values into pixel coordinates.
    655   \param canvasRect Contents rectangle of the canvas
    656 
    657   \return Symbol width in paint coordinates
    658 
    659   \sa symbolExtent(), minSymbolWidth(), maxSymbolWidth()
    660 */
     646    return defaultIcon( m_data->symbolPen.color(), size );
     647}
     648
     649/*!
     650   Calculate the symbol width in paint coordinates
     651
     652   The width is calculated by scaling the symbol extent into
     653   paint device coordinates bounded by the minimum/maximum
     654   symbol width.
     655
     656   \param xMap Maps x-values into pixel coordinates.
     657   \param yMap Maps y-values into pixel coordinates.
     658   \param canvasRect Contents rectangle of the canvas
     659
     660   \return Symbol width in paint coordinates
     661
     662   \sa symbolExtent(), minSymbolWidth(), maxSymbolWidth()
     663 */
    661664double QwtPlotTradingCurve::scaledSymbolWidth(
    662     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    663     const QRectF &canvasRect ) const
     665    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     666    const QRectF& canvasRect ) const
    664667{
    665668    Q_UNUSED( canvasRect );
    666669
    667     if ( d_data->maxSymbolWidth > 0.0 &&
    668         d_data->minSymbolWidth >= d_data->maxSymbolWidth )
    669     {
    670         return d_data->minSymbolWidth;
    671     }
    672 
    673     const QwtScaleMap *map =
     670    if ( m_data->maxSymbolWidth > 0.0 &&
     671        m_data->minSymbolWidth >= m_data->maxSymbolWidth )
     672    {
     673        return m_data->minSymbolWidth;
     674    }
     675
     676    const QwtScaleMap* map =
    674677        ( orientation() == Qt::Vertical ) ? &xMap : &yMap;
    675678
    676     const double pos = map->transform( map->s1() + d_data->symbolExtent );
     679    const double pos = map->transform( map->s1() + m_data->symbolExtent );
    677680
    678681    double width = qAbs( pos - map->p1() );
    679682
    680     width = qMax( width,  d_data->minSymbolWidth );
    681     if ( d_data->maxSymbolWidth > 0.0 )
    682         width = qMin( width, d_data->maxSymbolWidth );
     683    width = qwtMaxF( width,  m_data->minSymbolWidth );
     684    if ( m_data->maxSymbolWidth > 0.0 )
     685        width = qwtMinF( width, m_data->maxSymbolWidth );
    683686
    684687    return width;
  • trunk/BNC/qwt/qwt_plot_tradingcurve.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_seriesitem.h"
    15 #include "qwt_series_data.h"
    1615
    1716/*!
    18   \brief QwtPlotTradingCurve illustrates movements in the price of a
     17   \brief QwtPlotTradingCurve illustrates movements in the price of a
    1918         financial instrument over time.
    2019
    21   QwtPlotTradingCurve supports candlestick or bar ( OHLC ) charts
    22   that are used in the domain of technical analysis.
     20   QwtPlotTradingCurve supports candlestick or bar ( OHLC ) charts
     21   that are used in the domain of technical analysis.
    2322
    24   While the length ( height or width depending on orientation() )
    25   of each symbol depends on the corresponding OHLC sample the size
    26   of the other dimension can be controlled using:
     23   While the length ( height or width depending on orientation() )
     24   of each symbol depends on the corresponding OHLC sample the size
     25   of the other dimension can be controlled using:
    2726
    28   - setSymbolExtent()
    29   - setSymbolMinWidth()
    30   - setSymbolMaxWidth()
     27   - setSymbolExtent()
     28   - setSymbolMinWidth()
     29   - setSymbolMaxWidth()
    3130
    32   The extent is a size in scale coordinates, so that the symbol width
    33   is increasing when the plot is zoomed in. Minimum/Maximum width
    34   is in widget coordinates independent from the zoom level.
    35   When setting the minimum and maximum to the same value, the width of
    36   the symbol is fixed.
    37 */
    38 class QWT_EXPORT QwtPlotTradingCurve:
    39     public QwtPlotSeriesItem, public QwtSeriesStore<QwtOHLCSample>
     31   The extent is a size in scale coordinates, so that the symbol width
     32   is increasing when the plot is zoomed in. Minimum/Maximum width
     33   is in widget coordinates independent from the zoom level.
     34   When setting the minimum and maximum to the same value, the width of
     35   the symbol is fixed.
     36 */
     37class QWT_EXPORT QwtPlotTradingCurve
     38    : public QwtPlotSeriesItem
     39    , public QwtSeriesStore< QwtOHLCSample >
    4040{
    41 public:
     41  public:
    4242    /*!
    4343        \brief Symbol styles.
    … …  
    4545        The default setting is QwtPlotSeriesItem::CandleStick.
    4646        \sa setSymbolStyle(), symbolStyle()
    47     */
     47     */
    4848    enum SymbolStyle
    4949    {
    … …  
    5252
    5353        /*!
    54           A line on the chart shows the price range (the highest and lowest
    55           prices) over one unit of time, e.g. one day or one hour.
    56           Tick marks project from each side of the line indicating the
    57           opening and closing price.
     54           A line on the chart shows the price range (the highest and lowest
     55           prices) over one unit of time, e.g. one day or one hour.
     56           Tick marks project from each side of the line indicating the
     57           opening and closing price.
    5858         */
    5959        Bar,
    6060
    6161        /*!
    62           The range between opening/closing price are displayed as
    63           a filled box. The fill brush depends on the direction of the
    64           price movement. The box is connected to the highest/lowest
    65           values by lines.
    66         */
     62           The range between opening/closing price are displayed as
     63           a filled box. The fill brush depends on the direction of the
     64           price movement. The box is connected to the highest/lowest
     65           values by lines.
     66         */
    6767        CandleStick,
    6868
    6969        /*!
    70           SymbolTypes >= UserSymbol are displayed by drawUserSymbol(),
    71           that needs to be overloaded and implemented in derived
    72           curve classes.
     70           SymbolTypes >= UserSymbol are displayed by drawUserSymbol(),
     71           that needs to be overloaded and implemented in derived
     72           curve classes.
    7373
    74           \sa drawUserSymbol()
    75         */
     74           \sa drawUserSymbol()
     75         */
    7676        UserSymbol = 100
    7777    };
    … …  
    9292        Attributes to modify the drawing algorithm.
    9393        \sa setPaintAttribute(), testPaintAttribute()
    94     */
     94     */
    9595    enum PaintAttribute
    9696    {
    … …  
    9999    };
    100100
    101     //! Paint attributes
    102     typedef QFlags<PaintAttribute> PaintAttributes;
     101    Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute )
    103102
    104     explicit QwtPlotTradingCurve( const QString &title = QString() );
    105     explicit QwtPlotTradingCurve( const QwtText &title );
     103    explicit QwtPlotTradingCurve( const QString& title = QString() );
     104    explicit QwtPlotTradingCurve( const QwtText& title );
    106105
    107106    virtual ~QwtPlotTradingCurve();
    108107
    109     virtual int rtti() const;
     108    virtual int rtti() const QWT_OVERRIDE;
    110109
    111110    void setPaintAttribute( PaintAttribute, bool on = true );
    112111    bool testPaintAttribute( PaintAttribute ) const;
    113112
    114     void setSamples( const QVector<QwtOHLCSample> & );
    115     void setSamples( QwtSeriesData<QwtOHLCSample> * );
     113    void setSamples( const QVector< QwtOHLCSample >& );
     114    void setSamples( QwtSeriesData< QwtOHLCSample >* );
    116115
    117116    void setSymbolStyle( SymbolStyle style );
    118117    SymbolStyle symbolStyle() const;
    119118
    120     void setSymbolPen( const QColor &,
     119    void setSymbolPen( const QColor&,
    121120        qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    122     void setSymbolPen( const QPen & );
     121    void setSymbolPen( const QPen& );
    123122    QPen symbolPen() const;
    124123
    125     void setSymbolBrush( Direction, const QBrush & );
     124    void setSymbolBrush( Direction, const QBrush& );
    126125    QBrush symbolBrush( Direction ) const;
    127126
    … …  
    135134    double maxSymbolWidth() const;
    136135
    137     virtual void drawSeries( QPainter *painter,
    138         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    139         const QRectF &canvasRect, int from, int to ) const;
     136    virtual void drawSeries( QPainter*,
     137        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     138        const QRectF& canvasRect, int from, int to ) const QWT_OVERRIDE;
    140139
    141     virtual QRectF boundingRect() const;
     140    virtual QRectF boundingRect() const QWT_OVERRIDE;
    142141
    143     virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
     142    virtual QwtGraphic legendIcon( int index, const QSizeF& ) const QWT_OVERRIDE;
    144143
    145 protected:
     144  protected:
    146145
    147146    void init();
    148147
    149     virtual void drawSymbols( QPainter *,
    150         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    151         const QRectF &canvasRect, int from, int to ) const;
     148    virtual void drawSymbols( QPainter*,
     149        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     150        const QRectF& canvasRect, int from, int to ) const;
    152151
    153     virtual void drawUserSymbol( QPainter *,
    154         SymbolStyle, const QwtOHLCSample &,
     152    virtual void drawUserSymbol( QPainter*,
     153        SymbolStyle, const QwtOHLCSample&,
    155154        Qt::Orientation, bool inverted, double symbolWidth ) const;
    156155
    157     void drawBar( QPainter *painter, const QwtOHLCSample &,
     156    void drawBar( QPainter*, const QwtOHLCSample&,
    158157        Qt::Orientation, bool inverted, double width ) const;
    159158
    160     void drawCandleStick( QPainter *, const QwtOHLCSample &,
     159    void drawCandleStick( QPainter*, const QwtOHLCSample&,
    161160        Qt::Orientation, double width ) const;
    162161
    163162    virtual double scaledSymbolWidth(
    164         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    165         const QRectF &canvasRect ) const;
     163        const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     164        const QRectF& canvasRect ) const;
    166165
    167 private:
     166  private:
    168167    class PrivateData;
    169     PrivateData *d_data;
     168    PrivateData* m_data;
    170169};
    171170
  • trunk/BNC/qwt/qwt_plot_zoneitem.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_painter.h"
    1212#include "qwt_scale_map.h"
     13#include "qwt_text.h"
     14#include "qwt_interval.h"
     15
    1316#include <qpainter.h>
    1417
    1518class QwtPlotZoneItem::PrivateData
    1619{
    17 public:
    18     PrivateData():
    19         orientation( Qt::Vertical ),
    20         pen( Qt::NoPen )
     20  public:
     21    PrivateData()
     22        : orientation( Qt::Vertical )
     23        , pen( Qt::NoPen )
    2124    {
    2225        QColor c( Qt::darkGray );
    … …  
    4447
    4548   \sa QwtPlotItem::setItemAttribute(), QwtPlotItem::setZ()
    46 */
    47 QwtPlotZoneItem::QwtPlotZoneItem():
    48     QwtPlotItem( QwtText( "Zone" ) )
    49 {
    50     d_data = new PrivateData;
     49 */
     50QwtPlotZoneItem::QwtPlotZoneItem()
     51    : QwtPlotItem( QwtText( "Zone" ) )
     52{
     53    m_data = new PrivateData;
    5154
    5255    setItemAttribute( QwtPlotItem::AutoScale, false );
    … …  
    5962QwtPlotZoneItem::~QwtPlotZoneItem()
    6063{
    61     delete d_data;
     64    delete m_data;
    6265}
    6366
    … …  
    6972
    7073/*!
    71   Build and assign a pen
    72 
    73   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
    74   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
    75   to hide this incompatibility.
    76 
    77   \param color Pen color
    78   \param width Pen width
    79   \param style Pen style
    80 
    81   \sa pen(), brush()
    82  */
    83 void QwtPlotZoneItem::setPen( const QColor &color, qreal width, Qt::PenStyle style )
     74   Build and assign a pen
     75
     76   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     77   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     78   to hide this incompatibility.
     79
     80   \param color Pen color
     81   \param width Pen width
     82   \param style Pen style
     83
     84   \sa pen(), brush()
     85 */
     86void QwtPlotZoneItem::setPen( const QColor& color, qreal width, Qt::PenStyle style )
    8487{
    8588    setPen( QPen( color, width, style ) );
    … …  
    8790
    8891/*!
    89   \brief Assign a pen
    90 
    91   The pen is used to draw the border lines of the zone
    92 
    93   \param pen Pen
    94   \sa pen(), setBrush()
    95 */
    96 void QwtPlotZoneItem::setPen( const QPen &pen )
    97 {
    98     if ( d_data->pen != pen )
    99     {
    100         d_data->pen = pen;
     92   \brief Assign a pen
     93
     94   The pen is used to draw the border lines of the zone
     95
     96   \param pen Pen
     97   \sa pen(), setBrush()
     98 */
     99void QwtPlotZoneItem::setPen( const QPen& pen )
     100{
     101    if ( m_data->pen != pen )
     102    {
     103        m_data->pen = pen;
    101104        itemChanged();
    102105    }
    … …  
    104107
    105108/*!
    106   \return Pen used to draw the border lines
    107   \sa setPen(), brush()
    108 */
    109 const QPen &QwtPlotZoneItem::pen() const
    110 {
    111     return d_data->pen;
    112 }
    113 
    114 /*!
    115   \brief Assign a brush
    116 
    117   The brush is used to fill the zone
    118 
    119   \param brush Brush
    120   \sa pen(), setBrush()
    121 */
    122 void QwtPlotZoneItem::setBrush( const QBrush &brush )
    123 {
    124     if ( d_data->brush != brush )
    125     {
    126         d_data->brush = brush;
     109   \return Pen used to draw the border lines
     110   \sa setPen(), brush()
     111 */
     112const QPen& QwtPlotZoneItem::pen() const
     113{
     114    return m_data->pen;
     115}
     116
     117/*!
     118   \brief Assign a brush
     119
     120   The brush is used to fill the zone
     121
     122   \param brush Brush
     123   \sa pen(), setBrush()
     124 */
     125void QwtPlotZoneItem::setBrush( const QBrush& brush )
     126{
     127    if ( m_data->brush != brush )
     128    {
     129        m_data->brush = brush;
    127130        itemChanged();
    128131    }
    … …  
    130133
    131134/*!
    132   \return Brush used to fill the zone
    133   \sa setPen(), brush()
    134 */
    135 const QBrush &QwtPlotZoneItem::brush() const
    136 {
    137     return d_data->brush;
    138 }
    139 
    140 /*!
    141   \brief Set the orientation of the zone
    142 
    143   A horizontal zone highlights an interval of the y axis,
    144   a vertical zone of the x axis. It is unbounded in the
    145   opposite direction.
    146 
    147   \sa orientation(), QwtPlotItem::setAxes()
    148 */
     135   \return Brush used to fill the zone
     136   \sa setPen(), brush()
     137 */
     138const QBrush& QwtPlotZoneItem::brush() const
     139{
     140    return m_data->brush;
     141}
     142
     143/*!
     144   \brief Set the orientation of the zone
     145
     146   A horizontal zone highlights an interval of the y axis,
     147   a vertical zone of the x axis. It is unbounded in the
     148   opposite direction.
     149
     150   \sa orientation(), QwtPlotItem::setAxes()
     151 */
    149152void QwtPlotZoneItem::setOrientation( Qt::Orientation orientation )
    150153{
    151     if ( d_data->orientation != orientation )
    152     {
    153         d_data->orientation = orientation;
     154    if ( m_data->orientation != orientation )
     155    {
     156        m_data->orientation = orientation;
    154157        itemChanged();
    155158    }
    … …  
    157160
    158161/*!
    159   \return Orientation of the zone
    160   \sa setOrientation()
    161  */
    162 Qt::Orientation QwtPlotZoneItem::orientation()
    163 {
    164     return d_data->orientation;
    165 }
    166 
    167 /*!
    168   Set the interval of the zone
    169 
    170   For a horizontal zone the interval is related to the y axis,
    171   for a vertical zone it is related to the x axis.
    172 
    173   \param min Minimum of the interval
    174   \param max Maximum of the interval
    175 
    176   \sa interval(), setOrientation()
     162   \return Orientation of the zone
     163   \sa setOrientation()
     164 */
     165Qt::Orientation QwtPlotZoneItem::orientation() const
     166{
     167    return m_data->orientation;
     168}
     169
     170/*!
     171   Set the interval of the zone
     172
     173   For a horizontal zone the interval is related to the y axis,
     174   for a vertical zone it is related to the x axis.
     175
     176   \param min Minimum of the interval
     177   \param max Maximum of the interval
     178
     179   \sa interval(), setOrientation()
    177180 */
    178181void QwtPlotZoneItem::setInterval( double min, double max )
    … …  
    182185
    183186/*!
    184   Set the interval of the zone
    185 
    186   For a horizontal zone the interval is related to the y axis,
    187   for a vertical zone it is related to the x axis.
    188 
    189   \param interval Zone interval
    190 
    191   \sa interval(), setOrientation()
    192  */
    193 void QwtPlotZoneItem::setInterval( const QwtInterval &interval )
    194 {
    195     if ( d_data->interval != interval )
    196     {
    197         d_data->interval = interval;
     187   Set the interval of the zone
     188
     189   For a horizontal zone the interval is related to the y axis,
     190   for a vertical zone it is related to the x axis.
     191
     192   \param interval Zone interval
     193
     194   \sa interval(), setOrientation()
     195 */
     196void QwtPlotZoneItem::setInterval( const QwtInterval& interval )
     197{
     198    if ( m_data->interval != interval )
     199    {
     200        m_data->interval = interval;
    198201        itemChanged();
    199202    }
    … …  
    201204
    202205/*!
    203   \return Zone interval
    204   \sa setInterval(), orientation()
     206   \return Zone interval
     207   \sa setInterval(), orientation()
    205208 */
    206209QwtInterval QwtPlotZoneItem::interval() const
    207210{
    208     return d_data->interval;
    209 }
    210 
    211 /*!
    212   Draw the zone
    213 
    214   \param painter Painter
    215   \param xMap x Scale Map
    216   \param yMap y Scale Map
    217   \param canvasRect Contents rectangle of the canvas in painter coordinates
    218 */
    219 
    220 void QwtPlotZoneItem::draw( QPainter *painter,
    221     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    222     const QRectF &canvasRect ) const
    223 {
    224     if ( !d_data->interval.isValid() )
     211    return m_data->interval;
     212}
     213
     214/*!
     215   Draw the zone
     216
     217   \param painter Painter
     218   \param xMap x Scale Map
     219   \param yMap y Scale Map
     220   \param canvasRect Contents rectangle of the canvas in painter coordinates
     221 */
     222
     223void QwtPlotZoneItem::draw( QPainter* painter,
     224    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     225    const QRectF& canvasRect ) const
     226{
     227    if ( !m_data->interval.isValid() )
    225228        return;
    226229
    227     QPen pen = d_data->pen;
     230    QPen pen = m_data->pen;
    228231    pen.setCapStyle( Qt::FlatCap );
    229232
    230233    const bool doAlign = QwtPainter::roundingAlignment( painter );
    231234
    232     if ( d_data->orientation == Qt::Horizontal )
    233     {
    234         double y1 = yMap.transform( d_data->interval.minValue() );
    235         double y2 = yMap.transform( d_data->interval.maxValue() );
     235    if ( m_data->orientation == Qt::Horizontal )
     236    {
     237        double y1 = yMap.transform( m_data->interval.minValue() );
     238        double y2 = yMap.transform( m_data->interval.maxValue() );
    236239
    237240        if ( doAlign )
    … …  
    244247        r = r.normalized();
    245248
    246         if ( ( d_data->brush.style() != Qt::NoBrush ) && ( y1 != y2 ) )
    247         {
    248             QwtPainter::fillRect( painter, r, d_data->brush );
    249         }
    250 
    251         if ( d_data->pen.style() != Qt::NoPen )
    252         {
    253             painter->setPen( d_data->pen );
     249        if ( ( m_data->brush.style() != Qt::NoBrush ) && ( y1 != y2 ) )
     250        {
     251            QwtPainter::fillRect( painter, r, m_data->brush );
     252        }
     253
     254        if ( m_data->pen.style() != Qt::NoPen )
     255        {
     256            painter->setPen( m_data->pen );
    254257
    255258            QwtPainter::drawLine( painter, r.left(), r.top(), r.right(), r.top() );
    … …  
    259262    else
    260263    {
    261         double x1 = xMap.transform( d_data->interval.minValue() );
    262         double x2 = xMap.transform( d_data->interval.maxValue() );
     264        double x1 = xMap.transform( m_data->interval.minValue() );
     265        double x2 = xMap.transform( m_data->interval.maxValue() );
    263266
    264267        if ( doAlign )
    … …  
    271274        r = r.normalized();
    272275
    273         if ( ( d_data->brush.style() != Qt::NoBrush ) && ( x1 != x2 ) )
    274         {
    275             QwtPainter::fillRect( painter, r, d_data->brush );
    276         }
    277 
    278         if ( d_data->pen.style() != Qt::NoPen )
    279         {
    280             painter->setPen( d_data->pen );
     276        if ( ( m_data->brush.style() != Qt::NoBrush ) && ( x1 != x2 ) )
     277        {
     278            QwtPainter::fillRect( painter, r, m_data->brush );
     279        }
     280
     281        if ( m_data->pen.style() != Qt::NoPen )
     282        {
     283            painter->setPen( m_data->pen );
    281284
    282285            QwtPainter::drawLine( painter, r.left(), r.top(), r.left(), r.bottom() );
    … …  
    287290
    288291/*!
    289   The bounding rectangle is build from the interval in one direction
    290   and something invalid for the opposite direction.
    291 
    292   \return An invalid rectangle with valid boundaries in one direction
    293 */
     292   The bounding rectangle is build from the interval in one direction
     293   and something invalid for the opposite direction.
     294
     295   \return An invalid rectangle with valid boundaries in one direction
     296 */
    294297QRectF QwtPlotZoneItem::boundingRect() const
    295298{
    296299    QRectF br = QwtPlotItem::boundingRect();
    297300
    298     const QwtInterval &intv = d_data->interval;
     301    const QwtInterval& intv = m_data->interval;
    299302
    300303    if ( intv.isValid() )
    301304    {
    302         if ( d_data->orientation == Qt::Horizontal )
     305        if ( m_data->orientation == Qt::Horizontal )
    303306        {
    304307            br.setTop( intv.minValue() );
  • trunk/BNC/qwt/qwt_plot_zoneitem.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_item.h"
    15 #include "qwt_interval.h"
    1615
     16#include <qnamespace.h>
     17
     18class QwtInterval;
    1719class QPen;
    1820class QBrush;
    1921
    2022/*!
    21   \brief A plot item, which displays a zone
     23   \brief A plot item, which displays a zone
    2224
    23   A horizontal zone highlights an interval of the y axis - a vertical
    24   zone an interval of the x axis - and is unbounded in the opposite direction.
    25   It is filled with a brush and its border lines are optionally displayed with a pen.
     25   A horizontal zone highlights an interval of the y axis - a vertical
     26   zone an interval of the x axis - and is unbounded in the opposite direction.
     27   It is filled with a brush and its border lines are optionally displayed with a pen.
    2628
    27   \note For displaying an area that is bounded for x and y coordinates
     29   \note For displaying an area that is bounded for x and y coordinates
    2830        use QwtPlotShapeItem
    29 */
     31 */
    3032
    31 class QWT_EXPORT QwtPlotZoneItem:
     33class QWT_EXPORT QwtPlotZoneItem :
    3234    public QwtPlotItem
    3335{
    34 public:
     36  public:
    3537    explicit QwtPlotZoneItem();
    3638    virtual ~QwtPlotZoneItem();
    3739
    38     virtual int rtti() const;
     40    virtual int rtti() const QWT_OVERRIDE;
    3941
    4042    void setOrientation( Qt::Orientation );
    41     Qt::Orientation orientation();
     43    Qt::Orientation orientation() const;
    4244
    4345    void setInterval( double min, double max );
    44     void setInterval( const QwtInterval & );
     46    void setInterval( const QwtInterval& );
    4547    QwtInterval interval() const;
    4648
    47     void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    48     void setPen( const QPen & );
    49     const QPen &pen() const;
     49    void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
     50    void setPen( const QPen& );
     51    const QPen& pen() const;
    5052
    51     void setBrush( const QBrush & );
    52     const QBrush &brush() const;
     53    void setBrush( const QBrush& );
     54    const QBrush& brush() const;
    5355
    54     virtual void draw( QPainter *,
    55         const QwtScaleMap &, const QwtScaleMap &,
    56         const QRectF &) const;
     56    virtual void draw( QPainter*,
     57        const QwtScaleMap&, const QwtScaleMap&,
     58        const QRectF& canvasRect ) const QWT_OVERRIDE;
    5759
    58     virtual QRectF boundingRect() const;
     60    virtual QRectF boundingRect() const QWT_OVERRIDE;
    5961
    60 private:
     62  private:
    6163    class PrivateData;
    62     PrivateData *d_data;
     64    PrivateData* m_data;
    6365};
    6466
  • trunk/BNC/qwt/qwt_plot_zoomer.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_plot.h"
    1212#include "qwt_scale_div.h"
     13#include "qwt_scale_map.h"
     14#include "qwt_interval.h"
    1315#include "qwt_picker_machine.h"
    14 #include <qalgorithms.h>
     16
     17#include <qstack.h>
    1518
    1619static QwtInterval qwtExpandedZoomInterval( double v1, double v2,
    … …  
    5053}
    5154
    52 static QRectF qwtExpandedZoomRect( const QRectF &zoomRect, const QSizeF &minSize,
     55static QRectF qwtExpandedZoomRect( const QRectF& zoomRect, const QSizeF& minSize,
    5356    const QwtTransform* transformX, const QwtTransform* transformY )
    5457{
    … …  
    7881class QwtPlotZoomer::PrivateData
    7982{
    80 public:
     83  public:
    8184    uint zoomRectIndex;
    82     QStack<QRectF> zoomStack;
     85    QStack< QRectF > zoomStack;
    8386
    8487    int maxStackDepth;
    … …  
    8689
    8790/*!
    88   \brief Create a zoomer for a plot canvas.
    89 
    90   The zoomer is set to those x- and y-axis of the parent plot of the
    91   canvas that are enabled. If both or no x-axis are enabled, the picker
    92   is set to QwtPlot::xBottom. If both or no y-axis are
    93   enabled, it is set to QwtPlot::yLeft.
    94 
    95   The zoomer is initialized with a QwtPickerDragRectMachine,
    96   the tracker mode is set to QwtPicker::ActiveOnly and the rubber band
    97   is set to QwtPicker::RectRubberBand
    98 
    99   \param canvas Plot canvas to observe, also the parent object
    100   \param doReplot Call QwtPlot::replot() for the attached plot before initializing
     91   \brief Create a zoomer for a plot canvas.
     92
     93   The zoomer is set to those x- and y-axis of the parent plot of the
     94   canvas that are enabled. If both or no x-axis are enabled, the picker
     95   is set to QwtAxis::XBottom. If both or no y-axis are
     96   enabled, it is set to QwtAxis::YLeft.
     97
     98   The zoomer is initialized with a QwtPickerDragRectMachine,
     99   the tracker mode is set to QwtPicker::ActiveOnly and the rubber band
     100   is set to QwtPicker::RectRubberBand
     101
     102   \param canvas Plot canvas to observe, also the parent object
     103   \param doReplot Call QwtPlot::replot() for the attached plot before initializing
    101104                  the zoomer with its scales. This might be necessary,
    102105                  when the plot is in a state with pending scale changes.
    103106
    104   \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase()
    105 */
    106 QwtPlotZoomer::QwtPlotZoomer( QWidget *canvas, bool doReplot ):
    107     QwtPlotPicker( canvas )
     107   \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase()
     108 */
     109QwtPlotZoomer::QwtPlotZoomer( QWidget* canvas, bool doReplot )
     110    : QwtPlotPicker( canvas )
    108111{
    109112    if ( canvas )
    … …  
    112115
    113116/*!
    114   \brief Create a zoomer for a plot canvas.
    115 
    116   The zoomer is initialized with a QwtPickerDragRectMachine,
    117   the tracker mode is set to QwtPicker::ActiveOnly and the rubber band
    118   is set to QwtPicker;;RectRubberBand
    119 
    120   \param xAxis X axis of the zoomer
    121   \param yAxis Y axis of the zoomer
    122   \param canvas Plot canvas to observe, also the parent object
    123   \param doReplot Call QwtPlot::replot() for the attached plot before initializing
     117   \brief Create a zoomer for a plot canvas.
     118
     119   The zoomer is initialized with a QwtPickerDragRectMachine,
     120   the tracker mode is set to QwtPicker::ActiveOnly and the rubber band
     121   is set to QwtPicker::RectRubberBand
     122
     123   \param xAxisId X axis of the zoomer
     124   \param yAxisId Y axis of the zoomer
     125   \param canvas Plot canvas to observe, also the parent object
     126   \param doReplot Call QwtPlot::replot() for the attached plot before initializing
    124127                  the zoomer with its scales. This might be necessary,
    125128                  when the plot is in a state with pending scale changes.
    126129
    127   \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase()
    128 */
    129 
    130 QwtPlotZoomer::QwtPlotZoomer( int xAxis, int yAxis,
    131         QWidget *canvas, bool doReplot ):
    132     QwtPlotPicker( xAxis, yAxis, canvas )
     130   \sa QwtPlot::autoReplot(), QwtPlot::replot(), setZoomBase()
     131 */
     132
     133QwtPlotZoomer::QwtPlotZoomer( QwtAxisId xAxisId, QwtAxisId yAxisId,
     134        QWidget* canvas, bool doReplot )
     135    : QwtPlotPicker( xAxisId, yAxisId, canvas )
    133136{
    134137    if ( canvas )
    … …  
    139142void QwtPlotZoomer::init( bool doReplot )
    140143{
    141     d_data = new PrivateData;
    142 
    143     d_data->maxStackDepth = -1;
     144    m_data = new PrivateData;
     145
     146    m_data->maxStackDepth = -1;
    144147
    145148    setTrackerMode( ActiveOnly );
    … …  
    155158QwtPlotZoomer::~QwtPlotZoomer()
    156159{
    157     delete d_data;
    158 }
    159 
    160 /*!
    161   \brief Limit the number of recursive zoom operations to depth.
    162 
    163   A value of -1 set the depth to unlimited, 0 disables zooming.
    164   If the current zoom rectangle is below depth, the plot is unzoomed.
    165 
    166   \param depth Maximum for the stack depth
    167   \sa maxStackDepth()
    168   \note depth doesn't include the zoom base, so zoomStack().count() might be
     160    delete m_data;
     161}
     162
     163/*!
     164   \brief Limit the number of recursive zoom operations to depth.
     165
     166   A value of -1 set the depth to unlimited, 0 disables zooming.
     167   If the current zoom rectangle is below depth, the plot is unzoomed.
     168
     169   \param depth Maximum for the stack depth
     170   \sa maxStackDepth()
     171   \note depth doesn't include the zoom base, so zoomStack().count() might be
    169172              maxStackDepth() + 1.
    170 */
     173 */
    171174void QwtPlotZoomer::setMaxStackDepth( int depth )
    172175{
    173     d_data->maxStackDepth = depth;
     176    m_data->maxStackDepth = depth;
    174177
    175178    if ( depth >= 0 )
    176179    {
    177         // unzoom if the current depth is below d_data->maxStackDepth
     180        // unzoom if the current depth is below m_data->maxStackDepth
    178181
    179182        const int zoomOut =
    180             int( d_data->zoomStack.count() ) - 1 - depth; // -1 for the zoom base
     183            m_data->zoomStack.count() - 1 - depth; // -1 for the zoom base
    181184
    182185        if ( zoomOut > 0 )
    183186        {
    184187            zoom( -zoomOut );
    185             for ( int i = int( d_data->zoomStack.count() ) - 1;
    186                 i > int( d_data->zoomRectIndex ); i-- )
     188            for ( int i = m_data->zoomStack.count() - 1;
     189                i > int( m_data->zoomRectIndex ); i-- )
    187190            {
    188                 ( void )d_data->zoomStack.pop(); // remove trailing rects
     191                ( void )m_data->zoomStack.pop(); // remove trailing rects
    189192            }
    190193        }
    … …  
    193196
    194197/*!
    195   \return Maximal depth of the zoom stack.
    196   \sa setMaxStackDepth()
    197 */
     198   \return Maximal depth of the zoom stack.
     199   \sa setMaxStackDepth()
     200 */
    198201int QwtPlotZoomer::maxStackDepth() const
    199202{
    200     return d_data->maxStackDepth;
    201 }
    202 
    203 /*!
    204   \return The zoom stack. zoomStack()[0] is the zoom base,
     203    return m_data->maxStackDepth;
     204}
     205
     206/*!
     207   \return The zoom stack. zoomStack()[0] is the zoom base,
    205208          zoomStack()[1] the first zoomed rectangle.
    206209
    207   \sa setZoomStack(), zoomRectIndex()
    208 */
    209 const QStack<QRectF> &QwtPlotZoomer::zoomStack() const
    210 {
    211     return d_data->zoomStack;
    212 }
    213 
    214 /*!
    215   \return Initial rectangle of the zoomer
    216   \sa setZoomBase(), zoomRect()
    217 */
     210   \sa setZoomStack(), zoomRectIndex()
     211 */
     212const QStack< QRectF >& QwtPlotZoomer::zoomStack() const
     213{
     214    return m_data->zoomStack;
     215}
     216
     217/*!
     218   \return Initial rectangle of the zoomer
     219   \sa setZoomBase(), zoomRect()
     220 */
    218221QRectF QwtPlotZoomer::zoomBase() const
    219222{
    220     return d_data->zoomStack[0];
    221 }
    222 
    223 /*!
    224   Reinitialized the zoom stack with scaleRect() as base.
    225 
    226   \param doReplot Call QwtPlot::replot() for the attached plot before initializing
     223    return m_data->zoomStack[0];
     224}
     225
     226/*!
     227   Reinitialized the zoom stack with scaleRect() as base.
     228
     229   \param doReplot Call QwtPlot::replot() for the attached plot before initializing
    227230                  the zoomer with its scales. This might be necessary,
    228231                  when the plot is in a state with pending scale changes.
    229232
    230   \sa zoomBase(), scaleRect() QwtPlot::autoReplot(), QwtPlot::replot().
    231 */
     233   \sa zoomBase(), scaleRect() QwtPlot::autoReplot(), QwtPlot::replot().
     234 */
    232235void QwtPlotZoomer::setZoomBase( bool doReplot )
    233236{
    234     QwtPlot *plt = plot();
     237    QwtPlot* plt = plot();
    235238    if ( plt == NULL )
    236239        return;
    … …  
    239242        plt->replot();
    240243
    241     d_data->zoomStack.clear();
    242     d_data->zoomStack.push( scaleRect() );
    243     d_data->zoomRectIndex = 0;
     244    m_data->zoomStack.clear();
     245    m_data->zoomStack.push( scaleRect() );
     246    m_data->zoomRectIndex = 0;
    244247
    245248    rescale();
    … …  
    247250
    248251/*!
    249   \brief Set the initial size of the zoomer.
    250 
    251   base is united with the current scaleRect() and the zoom stack is
    252   reinitialized with it as zoom base. plot is zoomed to scaleRect().
    253 
    254   \param base Zoom base
    255 
    256   \sa zoomBase(), scaleRect()
    257 */
    258 void QwtPlotZoomer::setZoomBase( const QRectF &base )
    259 {
    260     const QwtPlot *plt = plot();
     252   \brief Set the initial size of the zoomer.
     253
     254   base is united with the current scaleRect() and the zoom stack is
     255   reinitialized with it as zoom base. plot is zoomed to scaleRect().
     256
     257   \param base Zoom base
     258
     259   \sa zoomBase(), scaleRect()
     260 */
     261void QwtPlotZoomer::setZoomBase( const QRectF& base )
     262{
     263    const QwtPlot* plt = plot();
    261264    if ( !plt )
    262265        return;
    … …  
    265268    const QRectF bRect = base | sRect;
    266269
    267     d_data->zoomStack.clear();
    268     d_data->zoomStack.push( bRect );
    269     d_data->zoomRectIndex = 0;
     270    m_data->zoomStack.clear();
     271    m_data->zoomStack.push( bRect );
     272    m_data->zoomRectIndex = 0;
    270273
    271274    if ( base != sRect )
    272275    {
    273         d_data->zoomStack.push( sRect );
    274         d_data->zoomRectIndex++;
     276        m_data->zoomStack.push( sRect );
     277        m_data->zoomRectIndex++;
    275278    }
    276279
    … …  
    279282
    280283/*!
    281   \return Rectangle at the current position on the zoom stack.
    282   \sa zoomRectIndex(), scaleRect().
    283 */
     284   \return Rectangle at the current position on the zoom stack.
     285   \sa zoomRectIndex(), scaleRect().
     286 */
    284287QRectF QwtPlotZoomer::zoomRect() const
    285288{
    286     return d_data->zoomStack[d_data->zoomRectIndex];
    287 }
    288 
    289 /*!
    290   \return Index of current position of zoom stack.
    291 */
     289    return m_data->zoomStack[m_data->zoomRectIndex];
     290}
     291
     292/*!
     293   \return Index of current position of zoom stack.
     294 */
    292295uint QwtPlotZoomer::zoomRectIndex() const
    293296{
    294     return d_data->zoomRectIndex;
    295 }
    296 
    297 /*!
    298   \brief Zoom in
    299 
    300   Clears all rectangles above the current position of the
    301   zoom stack and pushes the normalized rectangle on it.
    302 
    303   \note If the maximal stack depth is reached, zoom is ignored.
    304   \note The zoomed signal is emitted.
    305 */
    306 
    307 void QwtPlotZoomer::zoom( const QRectF &rect )
    308 {
    309     if ( d_data->maxStackDepth >= 0 &&
    310             int( d_data->zoomRectIndex ) >= d_data->maxStackDepth )
     297    return m_data->zoomRectIndex;
     298}
     299
     300/*!
     301   \brief Zoom in
     302
     303   Clears all rectangles above the current position of the
     304   zoom stack and pushes the normalized rectangle on it.
     305
     306   \note If the maximal stack depth is reached, zoom is ignored.
     307   \note The zoomed signal is emitted.
     308 */
     309
     310void QwtPlotZoomer::zoom( const QRectF& rect )
     311{
     312    if ( m_data->maxStackDepth >= 0 &&
     313        int( m_data->zoomRectIndex ) >= m_data->maxStackDepth )
    311314    {
    312315        return;
    … …  
    314317
    315318    const QRectF zoomRect = rect.normalized();
    316     if ( zoomRect != d_data->zoomStack[d_data->zoomRectIndex] )
    317     {
    318         for ( uint i = int( d_data->zoomStack.count() ) - 1;
    319            i > d_data->zoomRectIndex; i-- )
     319    if ( zoomRect != m_data->zoomStack[m_data->zoomRectIndex] )
     320    {
     321        for ( uint i = m_data->zoomStack.count() - 1;
     322            i > m_data->zoomRectIndex; i-- )
    320323        {
    321             ( void )d_data->zoomStack.pop();
     324            ( void )m_data->zoomStack.pop();
    322325        }
    323326
    324         d_data->zoomStack.push( zoomRect );
    325         d_data->zoomRectIndex++;
     327        m_data->zoomStack.push( zoomRect );
     328        m_data->zoomRectIndex++;
    326329
    327330        rescale();
    … …  
    332335
    333336/*!
    334   \brief Zoom in or out
    335 
    336   Activate a rectangle on the zoom stack with an offset relative
    337   to the current position. Negative values of offset will zoom out,
    338   positive zoom in. A value of 0 zooms out to the zoom base.
    339 
    340   \param offset Offset relative to the current position of the zoom stack.
    341   \note The zoomed signal is emitted.
    342   \sa zoomRectIndex()
    343 */
     337   \brief Zoom in or out
     338
     339   Activate a rectangle on the zoom stack with an offset relative
     340   to the current position. Negative values of offset will zoom out,
     341   positive zoom in. A value of 0 zooms out to the zoom base.
     342
     343   \param offset Offset relative to the current position of the zoom stack.
     344   \note The zoomed signal is emitted.
     345   \sa zoomRectIndex()
     346 */
    344347void QwtPlotZoomer::zoom( int offset )
    345348{
     349    int newIndex;
     350
    346351    if ( offset == 0 )
    347         d_data->zoomRectIndex = 0;
     352    {
     353        newIndex = 0;
     354    }
    348355    else
    349356    {
    350         int newIndex = d_data->zoomRectIndex + offset;
    351         newIndex = qMax( 0, newIndex );
    352         newIndex = qMin( int( d_data->zoomStack.count() ) - 1, newIndex );
    353 
    354         d_data->zoomRectIndex = uint( newIndex );
    355     }
    356 
    357     rescale();
    358 
    359     Q_EMIT zoomed( zoomRect() );
    360 }
    361 
    362 /*!
    363   \brief Assign a zoom stack
    364 
    365   In combination with other types of navigation it might be useful to
    366   modify to manipulate the complete zoom stack.
    367 
    368   \param zoomStack New zoom stack
    369   \param zoomRectIndex Index of the current position of zoom stack.
     357        newIndex = m_data->zoomRectIndex + offset;
     358        newIndex = qBound( 0, newIndex, m_data->zoomStack.count() - 1 );
     359    }
     360
     361    if ( newIndex != static_cast< int >( m_data->zoomRectIndex ) )
     362    {
     363        m_data->zoomRectIndex = newIndex;
     364        rescale();
     365        Q_EMIT zoomed( zoomRect() );
     366    }
     367}
     368
     369/*!
     370   \brief Assign a zoom stack
     371
     372   In combination with other types of navigation it might be useful to
     373   modify to manipulate the complete zoom stack.
     374
     375   \param zoomStack New zoom stack
     376   \param zoomRectIndex Index of the current position of zoom stack.
    370377                       In case of -1 the current position is at the top
    371378                       of the stack.
    372379
    373   \note The zoomed signal might be emitted.
    374   \sa zoomStack(), zoomRectIndex()
    375 */
     380   \note The zoomed signal might be emitted.
     381   \sa zoomStack(), zoomRectIndex()
     382 */
    376383void QwtPlotZoomer::setZoomStack(
    377     const QStack<QRectF> &zoomStack, int zoomRectIndex )
     384    const QStack< QRectF >& zoomStack, int zoomRectIndex )
    378385{
    379386    if ( zoomStack.isEmpty() )
    380387        return;
    381388
    382     if ( d_data->maxStackDepth >= 0 &&
    383         int( zoomStack.count() ) > d_data->maxStackDepth )
     389    if ( m_data->maxStackDepth >= 0 &&
     390        zoomStack.count() > m_data->maxStackDepth )
    384391    {
    385392        return;
    386393    }
    387394
    388     if ( zoomRectIndex < 0 || zoomRectIndex > int( zoomStack.count() ) )
     395    if ( zoomRectIndex < 0 || zoomRectIndex > zoomStack.count() )
    389396        zoomRectIndex = zoomStack.count() - 1;
    390397
    391398    const bool doRescale = zoomStack[zoomRectIndex] != zoomRect();
    392399
    393     d_data->zoomStack = zoomStack;
    394     d_data->zoomRectIndex = uint( zoomRectIndex );
     400    m_data->zoomStack = zoomStack;
     401    m_data->zoomRectIndex = uint( zoomRectIndex );
    395402
    396403    if ( doRescale )
    … …  
    402409
    403410/*!
    404   Adjust the observed plot to zoomRect()
    405 
    406   \note Initiates QwtPlot::replot()
    407 */
     411   Adjust the observed plot to zoomRect()
     412
     413   \note Initiates QwtPlot::replot()
     414 */
    408415
    409416void QwtPlotZoomer::rescale()
    410417{
    411     QwtPlot *plt = plot();
     418    QwtPlot* plt = plot();
    412419    if ( !plt )
    413420        return;
    414421
    415     const QRectF &rect = d_data->zoomStack[d_data->zoomRectIndex];
     422    const QRectF& rect = m_data->zoomStack[m_data->zoomRectIndex];
    416423    if ( rect != scaleRect() )
    417424    {
    … …  
    440447
    441448/*!
    442   Reinitialize the axes, and set the zoom base to their scales.
    443 
    444   \param xAxis X axis
    445   \param yAxis Y axis
    446 */
    447 
    448 void QwtPlotZoomer::setAxis( int xAxis, int yAxis )
    449 {
    450     if ( xAxis != QwtPlotPicker::xAxis() || yAxis != QwtPlotPicker::yAxis() )
    451     {
    452         QwtPlotPicker::setAxis( xAxis, yAxis );
     449   Reinitialize the axes, and set the zoom base to their scales.
     450
     451   \param xAxisId X axis
     452   \param yAxisId Y axis
     453 */
     454
     455void QwtPlotZoomer::setAxes( QwtAxisId xAxisId, QwtAxisId yAxisId )
     456{
     457    if ( xAxisId != QwtPlotPicker::xAxis() || yAxisId != QwtPlotPicker::yAxis() )
     458    {
     459        QwtPlotPicker::setAxes( xAxisId, yAxisId );
    453460        setZoomBase( scaleRect() );
    454461    }
    … …  
    464471   \note The mouse events can be changed, using
    465472         QwtEventPattern::setMousePattern: 2, 1
    466 */
    467 void QwtPlotZoomer::widgetMouseReleaseEvent( QMouseEvent *me )
     473 */
     474void QwtPlotZoomer::widgetMouseReleaseEvent( QMouseEvent* me )
    468475{
    469476    if ( mouseMatch( MouseSelect2, me ) )
    … …  
    486493   \note The keys codes can be changed, using
    487494         QwtEventPattern::setKeyPattern: 3, 4, 5
    488 */
    489 
    490 void QwtPlotZoomer::widgetKeyPressEvent( QKeyEvent *ke )
     495 */
     496
     497void QwtPlotZoomer::widgetKeyPressEvent( QKeyEvent* ke )
    491498{
    492499    if ( !isActive() )
    … …  
    504511
    505512/*!
    506   Move the current zoom rectangle.
    507 
    508   \param dx X offset
    509   \param dy Y offset
    510 
    511   \note The changed rectangle is limited by the zoom base
    512 */
     513   Move the current zoom rectangle.
     514
     515   \param dx X offset
     516   \param dy Y offset
     517
     518   \note The changed rectangle is limited by the zoom base
     519 */
    513520void QwtPlotZoomer::moveBy( double dx, double dy )
    514521{
    515     const QRectF &rect = d_data->zoomStack[d_data->zoomRectIndex];
     522    const QRectF& rect = m_data->zoomStack[m_data->zoomRectIndex];
    516523    moveTo( QPointF( rect.left() + dx, rect.top() + dy ) );
    517524}
    518525
    519526/*!
    520   Move the the current zoom rectangle.
    521 
    522   \param pos New position
    523 
    524   \sa QRectF::moveTo()
    525   \note The changed rectangle is limited by the zoom base
    526 */
    527 void QwtPlotZoomer::moveTo( const QPointF &pos )
     527   Move the the current zoom rectangle.
     528
     529   \param pos New position
     530
     531   \sa QRectF::moveTo()
     532   \note The changed rectangle is limited by the zoom base
     533 */
     534void QwtPlotZoomer::moveTo( const QPointF& pos )
    528535{
    529536    double x = pos.x();
    … …  
    542549    if ( x != zoomRect().left() || y != zoomRect().top() )
    543550    {
    544         d_data->zoomStack[d_data->zoomRectIndex].moveTo( x, y );
     551        m_data->zoomStack[m_data->zoomRectIndex].moveTo( x, y );
    545552        rescale();
    546553    }
    … …  
    548555
    549556/*!
    550   \brief Check and correct a selected rectangle
    551 
    552   Reject rectangles with a height or width < 2, otherwise
    553   expand the selected rectangle to a minimum size of 11x11
    554   and accept it.
    555 
    556   \return true If the rectangle is accepted, or has been changed
     557   \brief Check and correct a selected rectangle
     558
     559   Reject rectangles with a height or width < 2, otherwise
     560   expand the selected rectangle to a minimum size of 11x11
     561   and accept it.
     562
     563   \return true If the rectangle is accepted, or has been changed
    557564          to an accepted one.
    558 */
    559 
    560 bool QwtPlotZoomer::accept( QPolygon &pa ) const
     565 */
     566
     567bool QwtPlotZoomer::accept( QPolygon& pa ) const
    561568{
    562569    if ( pa.count() < 2 )
    563570        return false;
    564571
    565     QRect rect = QRect( pa[0], pa[int( pa.count() ) - 1] );
     572    QRect rect = QRect( pa.first(), pa.last() );
    566573    rect = rect.normalized();
    567574
    … …  
    584591
    585592/*!
    586   \brief Limit zooming by a minimum rectangle
    587 
    588   \return zoomBase().width() / 10e4, zoomBase().height() / 10e4
    589 */
     593   \brief Limit zooming by a minimum rectangle
     594
     595   \return zoomBase().width() / 10e4, zoomBase().height() / 10e4
     596 */
    590597QSizeF QwtPlotZoomer::minZoomSize() const
    591598{
    592     return QSizeF( d_data->zoomStack[0].width() / 10e4,
    593         d_data->zoomStack[0].height() / 10e4 );
    594 }
    595 
    596 /*!
    597   Rejects selections, when the stack depth is too deep, or
    598   the zoomed rectangle is minZoomSize().
    599 
    600   \sa minZoomSize(), maxStackDepth()
    601 */
     599    return QSizeF( m_data->zoomStack[0].width() / 10e4,
     600        m_data->zoomStack[0].height() / 10e4 );
     601}
     602
     603/*!
     604   Rejects selections, when the stack depth is too deep, or
     605   the zoomed rectangle is minZoomSize().
     606
     607   \sa minZoomSize(), maxStackDepth()
     608 */
    602609void QwtPlotZoomer::begin()
    603610{
    604     if ( d_data->maxStackDepth >= 0 )
    605     {
    606         if ( d_data->zoomRectIndex >= uint( d_data->maxStackDepth ) )
     611    if ( m_data->maxStackDepth >= 0 )
     612    {
     613        if ( m_data->zoomRectIndex >= uint( m_data->maxStackDepth ) )
    607614            return;
    608615    }
    … …  
    612619    {
    613620        const QSizeF sz =
    614             d_data->zoomStack[d_data->zoomRectIndex].size() * 0.9999;
     621            m_data->zoomStack[m_data->zoomRectIndex].size() * 0.9999;
    615622
    616623        if ( minSize.width() >= sz.width() &&
    … …  
    625632
    626633/*!
    627   Expand the selected rectangle to minZoomSize() and zoom in
    628   if accepted.
    629 
    630   \param ok If true, complete the selection and emit selected signals
     634   Expand the selected rectangle to minZoomSize() and zoom in
     635   if accepted.
     636
     637   \param ok If true, complete the selection and emit selected signals
    631638            otherwise discard the selection.
    632639
    633   \sa accept(), minZoomSize()
    634   \return True if the selection has been accepted, false otherwise
    635 */
     640   \sa accept(), minZoomSize()
     641   \return True if the selection has been accepted, false otherwise
     642 */
    636643bool QwtPlotZoomer::end( bool ok )
    637644{
    … …  
    640647        return false;
    641648
    642     QwtPlot *plot = QwtPlotZoomer::plot();
     649    QwtPlot* plot = QwtPlotZoomer::plot();
    643650    if ( !plot )
    644651        return false;
    645652
    646     const QPolygon &pa = selection();
     653    const QPolygon& pa = selection();
    647654    if ( pa.count() < 2 )
    648655        return false;
    649656
    650     QRect rect = QRect( pa[0], pa[int( pa.count() - 1 )] );
     657    QRect rect = QRect( pa.first(), pa.last() );
    651658    rect = rect.normalized();
    652659
    … …  
    663670    return true;
    664671}
     672
     673#include "moc_qwt_plot_zoomer.cpp"
  • trunk/BNC/qwt/qwt_plot_zoomer.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_plot_picker.h"
    15 #include <qstack.h>
     15
     16class QSizeF;
     17template< typename T > class QStack;
    1618
    1719/*!
    18   \brief QwtPlotZoomer provides stacked zooming for a plot widget
     20   \brief QwtPlotZoomer provides stacked zooming for a plot widget
    1921
    20   QwtPlotZoomer selects rectangles from user inputs ( mouse or keyboard )
    21   translates them into plot coordinates and adjusts the axes to them.
    22   The selection is supported by a rubber band and optionally by displaying
    23   the coordinates of the current mouse position.
     22   QwtPlotZoomer selects rectangles from user inputs ( mouse or keyboard )
     23   translates them into plot coordinates and adjusts the axes to them.
     24   The selection is supported by a rubber band and optionally by displaying
     25   the coordinates of the current mouse position.
    2426
    25   Zooming can be repeated as often as possible, limited only by
    26   maxStackDepth() or minZoomSize().  Each rectangle is pushed on a stack.
     27   Zooming can be repeated as often as possible, limited only by
     28   maxStackDepth() or minZoomSize().  Each rectangle is pushed on a stack.
    2729
    28   The default setting how to select rectangles is
    29   a QwtPickerDragRectMachine with the following bindings:
     30   The default setting how to select rectangles is
     31   a QwtPickerDragRectMachine with the following bindings:
    3032
    31   - QwtEventPattern::MouseSelect1\n
     33   - QwtEventPattern::MouseSelect1\n
    3234    The first point of the zoom rectangle is selected by a mouse press,
    3335    the second point from the position, where the mouse is released.
    3436
    35   - QwtEventPattern::KeySelect1\n
     37   - QwtEventPattern::KeySelect1\n
    3638    The first key press selects the first, the second key press
    3739    selects the second point.
    3840
    39   - QwtEventPattern::KeyAbort\n
     41   - QwtEventPattern::KeyAbort\n
    4042    Discard the selection in the state, where the first point
    4143    is selected.
    4244
    43   To traverse the zoom stack the following bindings are used:
     45   To traverse the zoom stack the following bindings are used:
    4446
    45   - QwtEventPattern::MouseSelect3, QwtEventPattern::KeyUndo\n
     47   - QwtEventPattern::MouseSelect3, QwtEventPattern::KeyUndo\n
    4648    Zoom out one position on the zoom stack
    4749
    48   - QwtEventPattern::MouseSelect6, QwtEventPattern::KeyRedo\n
     50   - QwtEventPattern::MouseSelect6, QwtEventPattern::KeyRedo\n
    4951    Zoom in one position on the zoom stack
    5052
    51   - QwtEventPattern::MouseSelect2, QwtEventPattern::KeyHome\n
     53   - QwtEventPattern::MouseSelect2, QwtEventPattern::KeyHome\n
    5254    Zoom to the zoom base
    5355
    54   The setKeyPattern() and setMousePattern() functions can be used
    55   to configure the zoomer actions. The following example
    56   shows, how to configure the 'I' and 'O' keys for zooming in and out
    57   one position on the zoom stack. The "Home" key is used to
    58   "unzoom" the plot.
     56   The setKeyPattern() and setMousePattern() functions can be used
     57   to configure the zoomer actions. The following example
     58   shows, how to configure the 'I' and 'O' keys for zooming in and out
     59   one position on the zoom stack. The "Home" key is used to
     60   "unzoom" the plot.
    5961
    60   \code
     62   \code
    6163   zoomer = new QwtPlotZoomer( plot );
    6264   zoomer->setKeyPattern( QwtEventPattern::KeyRedo, Qt::Key_I, Qt::ShiftModifier );
    6365   zoomer->setKeyPattern( QwtEventPattern::KeyUndo, Qt::Key_O, Qt::ShiftModifier );
    6466   zoomer->setKeyPattern( QwtEventPattern::KeyHome, Qt::Key_Home );
    65   \endcode
     67   \endcode
    6668
    67   QwtPlotZoomer is tailored for plots with one x and y axis, but it is
    68   allowed to attach a second QwtPlotZoomer ( without rubber band and tracker )
    69   for the other axes.
     69   QwtPlotZoomer is tailored for plots with one x and y axis, but it is
     70   allowed to attach a second QwtPlotZoomer ( without rubber band and tracker )
     71   for the other axes.
    7072
    71   \note The realtime example includes an derived zoomer class that adds
     73   \note The realtime example includes an derived zoomer class that adds
    7274        scrollbars to the plot canvas.
    7375
    74   \sa QwtPlotPanner, QwtPlotMagnifier
    75 */
     76   \sa QwtPlotPanner, QwtPlotMagnifier
     77 */
    7678
    77 class QWT_EXPORT QwtPlotZoomer: public QwtPlotPicker
     79class QWT_EXPORT QwtPlotZoomer : public QwtPlotPicker
    7880{
    7981    Q_OBJECT
    80 public:
    81     explicit QwtPlotZoomer( QWidget *, bool doReplot = true );
    82     explicit QwtPlotZoomer( int xAxis, int yAxis,
    83                             QWidget *, bool doReplot = true );
     82  public:
     83    explicit QwtPlotZoomer( QWidget*, bool doReplot = true );
     84    explicit QwtPlotZoomer( QwtAxisId xAxis, QwtAxisId yAxis,
     85        QWidget*, bool doReplot = true );
    8486
    8587    virtual ~QwtPlotZoomer();
    8688
    8789    virtual void setZoomBase( bool doReplot = true );
    88     virtual void setZoomBase( const QRectF & );
     90    virtual void setZoomBase( const QRectF& );
    8991
    9092    QRectF zoomBase() const;
    9193    QRectF zoomRect() const;
    9294
    93     virtual void setAxis( int xAxis, int yAxis );
     95    virtual void setAxes( QwtAxisId xAxis, QwtAxisId yAxis ) QWT_OVERRIDE;
    9496
    9597    void setMaxStackDepth( int );
    9698    int maxStackDepth() const;
    9799
    98     const QStack<QRectF> &zoomStack() const;
    99     void setZoomStack( const QStack<QRectF> &,
     100    const QStack< QRectF >& zoomStack() const;
     101    void setZoomStack( const QStack< QRectF >&,
    100102        int zoomRectIndex = -1 );
    101103
    102104    uint zoomRectIndex() const;
    103105
    104 public Q_SLOTS:
     106  public Q_SLOTS:
    105107    void moveBy( double dx, double dy );
    106     virtual void moveTo( const QPointF & );
     108    virtual void moveTo( const QPointF& );
    107109
    108     virtual void zoom( const QRectF & );
     110    virtual void zoom( const QRectF& );
    109111    virtual void zoom( int offset );
    110112
    111 Q_SIGNALS:
     113  Q_SIGNALS:
    112114    /*!
    113       A signal emitting the zoomRect(), when the plot has been
    114       zoomed in or out.
     115       A signal emitting the zoomRect(), when the plot has been
     116       zoomed in or out.
    115117
    116       \param rect Current zoom rectangle.
    117     */
     118       \param rect Current zoom rectangle.
     119     */
    118120
    119     void zoomed( const QRectF &rect );
     121    void zoomed( const QRectF& rect );
    120122
    121 protected:
     123  protected:
    122124    virtual void rescale();
    123125
    124126    virtual QSizeF minZoomSize() const;
    125127
    126     virtual void widgetMouseReleaseEvent( QMouseEvent * );
    127     virtual void widgetKeyPressEvent( QKeyEvent * );
     128    virtual void widgetMouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE;
     129    virtual void widgetKeyPressEvent( QKeyEvent* ) QWT_OVERRIDE;
    128130
    129     virtual void begin();
    130     virtual bool end( bool ok = true );
    131     virtual bool accept( QPolygon & ) const;
     131    virtual void begin() QWT_OVERRIDE;
     132    virtual bool end( bool ok = true ) QWT_OVERRIDE;
     133    virtual bool accept( QPolygon& ) const QWT_OVERRIDE;
    132134
    133 private:
     135  private:
    134136    void init( bool doReplot );
    135137
    136138    class PrivateData;
    137     PrivateData *d_data;
     139    PrivateData* m_data;
    138140};
    139141
  • trunk/BNC/qwt/qwt_point_3d.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_point_3d.h"
    1111
     12#if QT_VERSION >= 0x050200
     13
     14static QwtPoint3D qwtPointToPoint3D( const QPointF& point )
     15{
     16    return QwtPoint3D( point );
     17}
     18
     19#endif
     20
     21namespace
     22{
     23    static const struct RegisterQwtPoint3D
     24    {
     25        inline RegisterQwtPoint3D()
     26        {
     27            qRegisterMetaType< QwtPoint3D >();
     28
     29#if QT_VERSION >= 0x050200
     30            QMetaType::registerConverter< QPointF, QwtPoint3D >( qwtPointToPoint3D );
     31#endif
     32        }
     33    } qwtRegisterQwtPoint3D;
     34}
     35
    1236#ifndef QT_NO_DEBUG_STREAM
    1337
    14 QDebug operator<<( QDebug debug, const QwtPoint3D &point )
     38#include <qdebug.h>
     39
     40QDebug operator<<( QDebug debug, const QwtPoint3D& point )
    1541{
    1642    debug.nospace() << "QwtPoint3D(" << point.x()
    17         << "," << point.y() << "," << point.z() << ")";
     43                    << "," << point.y() << "," << point.z() << ")";
    1844    return debug.space();
    1945}
  • trunk/BNC/qwt/qwt_point_3d.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010/*! \file */
    1111#ifndef QWT_POINT_3D_H
    12 #define QWT_POINT_3D_H 1
     12#define QWT_POINT_3D_H
    1313
    1414#include "qwt_global.h"
    1515#include <qpoint.h>
    16 #ifndef QT_NO_DEBUG_STREAM
    17 #include <qdebug.h>
    18 #endif
     16#include <qmetatype.h>
    1917
    2018/*!
    21   \brief QwtPoint3D class defines a 3D point in double coordinates
    22 */
     19   \brief QwtPoint3D class defines a 3D point in double coordinates
     20 */
    2321
    2422class QWT_EXPORT QwtPoint3D
    2523{
    26 public:
     24  public:
    2725    QwtPoint3D();
    2826    QwtPoint3D( double x, double y, double z );
    29     QwtPoint3D( const QwtPoint3D & );
    30     QwtPoint3D( const QPointF & );
     27    QwtPoint3D( const QPointF& );
    3128
    3229    bool isNull()    const;
    … …  
    3633    double z() const;
    3734
    38     double &rx();
    39     double &ry();
    40     double &rz();
     35    double& rx();
     36    double& ry();
     37    double& rz();
    4138
    4239    void setX( double x );
    … …  
    4643    QPointF toPoint() const;
    4744
    48     bool operator==( const QwtPoint3D & ) const;
    49     bool operator!=( const QwtPoint3D & ) const;
     45    bool operator==( const QwtPoint3D& ) const;
     46    bool operator!=( const QwtPoint3D& ) const;
    5047
    51 private:
    52     double d_x;
    53     double d_y;
    54     double d_z;
     48  private:
     49    double m_x;
     50    double m_y;
     51    double m_z;
    5552};
    5653
    57 Q_DECLARE_TYPEINFO(QwtPoint3D, Q_MOVABLE_TYPE);
     54Q_DECLARE_TYPEINFO( QwtPoint3D, Q_MOVABLE_TYPE );
     55Q_DECLARE_METATYPE( QwtPoint3D )
    5856
    5957#ifndef QT_NO_DEBUG_STREAM
    60 QWT_EXPORT QDebug operator<<( QDebug, const QwtPoint3D & );
     58QWT_EXPORT QDebug operator<<( QDebug, const QwtPoint3D& );
    6159#endif
    6260
    … …  
    6462    Constructs a null point.
    6563    \sa isNull()
    66 */
    67 inline QwtPoint3D::QwtPoint3D():
    68     d_x( 0.0 ),
    69     d_y( 0.0 ),
    70     d_z( 0.0 )
     64 */
     65inline QwtPoint3D::QwtPoint3D()
     66    : m_x( 0.0 )
     67    , m_y( 0.0 )
     68    , m_z( 0.0 )
    7169{
    7270}
    7371
    7472//! Constructs a point with coordinates specified by x, y and z.
    75 inline QwtPoint3D::QwtPoint3D( double x, double y, double z = 0.0 ):
    76     d_x( x ),
    77     d_y( y ),
    78     d_z( z )
    79 {
    80 }
    81 
    82 /*!
    83     Copy constructor.
    84     Constructs a point using the values of the point specified.
    85 */
    86 inline QwtPoint3D::QwtPoint3D( const QwtPoint3D &other ):
    87     d_x( other.d_x ),
    88     d_y( other.d_y ),
    89     d_z( other.d_z )
     73inline QwtPoint3D::QwtPoint3D( double x, double y, double z = 0.0 )
     74    : m_x( x )
     75    , m_y( y )
     76    , m_z( z )
    9077{
    9178}
    … …  
    9481    Constructs a point with x and y coordinates from a 2D point,
    9582    and a z coordinate of 0.
    96 */
    97 inline QwtPoint3D::QwtPoint3D( const QPointF &other ):
    98     d_x( other.x() ),
    99     d_y( other.y() ),
    100     d_z( 0.0 )
     83 */
     84inline QwtPoint3D::QwtPoint3D( const QPointF& other )
     85    : m_x( other.x() )
     86    , m_y( other.y() )
     87    , m_z( 0.0 )
    10188{
    10289}
    … …  
    10794    A point is considered to be null if x, y and z-coordinates
    10895    are equal to zero.
    109 */
     96 */
    11097inline bool QwtPoint3D::isNull() const
    11198{
    112     return d_x == 0.0 && d_y == 0.0 && d_z == 0.0;
     99    return m_x == 0.0 && m_y == 0.0 && m_z == 0.0;
    113100}
    114101
    … …  
    116103inline double QwtPoint3D::x() const
    117104{
    118     return d_x;
     105    return m_x;
    119106}
    120107
    … …  
    122109inline double QwtPoint3D::y() const
    123110{
    124     return d_y;
     111    return m_y;
    125112}
    126113
    … …  
    128115inline double QwtPoint3D::z() const
    129116{
    130     return d_z;
     117    return m_z;
    131118}
    132119
    133120//! \return A reference to the x-coordinate of the point.
    134 inline double &QwtPoint3D::rx()
     121inline double& QwtPoint3D::rx()
    135122{
    136     return d_x;
     123    return m_x;
    137124}
    138125
    139126//! \return A reference to the y-coordinate of the point.
    140 inline double &QwtPoint3D::ry()
     127inline double& QwtPoint3D::ry()
    141128{
    142     return d_y;
     129    return m_y;
    143130}
    144131
    145132//! \return A reference to the z-coordinate of the point.
    146 inline double &QwtPoint3D::rz()
     133inline double& QwtPoint3D::rz()
    147134{
    148     return d_z;
     135    return m_z;
    149136}
    150137
    … …  
    152139inline void QwtPoint3D::setX( double x )
    153140{
    154     d_x = x;
     141    m_x = x;
    155142}
    156143
    … …  
    158145inline void QwtPoint3D::setY( double y )
    159146{
    160     d_y = y;
     147    m_y = y;
    161148}
    162149
    … …  
    164151inline void QwtPoint3D::setZ( double z )
    165152{
    166     d_z = z;
     153    m_z = z;
    167154}
    168155
    169156/*!
    170157   \return 2D point, where the z coordinate is dropped.
    171 */
     158 */
    172159inline QPointF QwtPoint3D::toPoint() const
    173160{
    174     return QPointF( d_x, d_y );
     161    return QPointF( m_x, m_y );
    175162}
    176163
    177164//! \return True, if this point and other are equal; otherwise returns false.
    178 inline bool QwtPoint3D::operator==( const QwtPoint3D &other ) const
     165inline bool QwtPoint3D::operator==( const QwtPoint3D& other ) const
    179166{
    180     return ( d_x == other.d_x ) && ( d_y == other.d_y ) && ( d_z == other.d_z );
     167    return ( m_x == other.m_x ) && ( m_y == other.m_y ) && ( m_z == other.m_z );
    181168}
    182169
    183170//! \return True if this rect and other are different; otherwise returns false.
    184 inline bool QwtPoint3D::operator!=( const QwtPoint3D &other ) const
     171inline bool QwtPoint3D::operator!=( const QwtPoint3D& other ) const
    185172{
    186173    return !operator==( other );
  • trunk/BNC/qwt/qwt_point_data.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_point_data.h"
    11 #include "qwt_math.h"
    12 #include <string.h>
    13 
    14 /*!
    15   Constructor
    16 
    17   \param x Array of x values
    18   \param y Array of y values
    19 
    20   \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()
    21 */
    22 QwtPointArrayData::QwtPointArrayData(
    23         const QVector<double> &x, const QVector<double> &y ):
    24     d_x( x ),
    25     d_y( y )
    26 {
    27 }
    28 
    29 /*!
    30   Constructor
    31 
    32   \param x Array of x values
    33   \param y Array of y values
    34   \param size Size of the x and y arrays
    35   \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()
    36 */
    37 QwtPointArrayData::QwtPointArrayData( const double *x,
    38         const double *y, size_t size )
    39 {
    40     d_x.resize( size );
    41     ::memcpy( d_x.data(), x, size * sizeof( double ) );
    42 
    43     d_y.resize( size );
    44     ::memcpy( d_y.data(), y, size * sizeof( double ) );
    45 }
    46 
    47 /*!
    48   \brief Calculate the bounding rectangle
    49 
    50   The bounding rectangle is calculated once by iterating over all
    51   points and is stored for all following requests.
    52 
    53   \return Bounding rectangle
    54 */
    55 QRectF QwtPointArrayData::boundingRect() const
    56 {
    57     if ( d_boundingRect.width() < 0 )
    58         d_boundingRect = qwtBoundingRect( *this );
    59 
    60     return d_boundingRect;
    61 }
    62 
    63 //! \return Size of the data set
    64 size_t QwtPointArrayData::size() const
    65 {
    66     return qMin( d_x.size(), d_y.size() );
    67 }
    68 
    69 /*!
    70   Return the sample at position i
    71 
    72   \param index Index
    73   \return Sample at position i
    74 */
    75 QPointF QwtPointArrayData::sample( size_t index ) const
    76 {
    77     return QPointF( d_x[int( index )], d_y[int( index )] );
    78 }
    79 
    80 //! \return Array of the x-values
    81 const QVector<double> &QwtPointArrayData::xData() const
    82 {
    83     return d_x;
    84 }
    85 
    86 //! \return Array of the y-values
    87 const QVector<double> &QwtPointArrayData::yData() const
    88 {
    89     return d_y;
    90 }
    91 
    92 /*!
    93   Constructor
    94 
    95   \param x Array of x values
    96   \param y Array of y values
    97   \param size Size of the x and y arrays
    98 
    99   \warning The programmer must assure that the memory blocks referenced
    100            by the pointers remain valid during the lifetime of the
    101            QwtPlotCPointer object.
    102 
    103   \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples()
    104 */
    105 QwtCPointerData::QwtCPointerData(
    106         const double *x, const double *y, size_t size ):
    107     d_x( x ),
    108     d_y( y ),
    109     d_size( size )
    110 {
    111 }
    112 
    113 /*!
    114   \brief Calculate the bounding rectangle
    115 
    116   The bounding rectangle is calculated once by iterating over all
    117   points and is stored for all following requests.
    118 
    119   \return Bounding rectangle
    120 */
    121 QRectF QwtCPointerData::boundingRect() const
    122 {
    123     if ( d_boundingRect.width() < 0 )
    124         d_boundingRect = qwtBoundingRect( *this );
    125 
    126     return d_boundingRect;
    127 }
    128 
    129 //! \return Size of the data set
    130 size_t QwtCPointerData::size() const
    131 {
    132     return d_size;
    133 }
    134 
    135 /*!
    136   Return the sample at position i
    137 
    138   \param index Index
    139   \return Sample at position i
    140 */
    141 QPointF QwtCPointerData::sample( size_t index ) const
    142 {
    143     return QPointF( d_x[int( index )], d_y[int( index )] );
    144 }
    145 
    146 //! \return Array of the x-values
    147 const double *QwtCPointerData::xData() const
    148 {
    149     return d_x;
    150 }
    151 
    152 //! \return Array of the y-values
    153 const double *QwtCPointerData::yData() const
    154 {
    155     return d_y;
    156 }
    15711
    15812/*!
    … …  
    16317
    16418   \sa setInterval(), setSize()
    165 */
     19 */
    16620QwtSyntheticPointData::QwtSyntheticPointData(
    167         size_t size, const QwtInterval &interval ):
    168     d_size( size ),
    169     d_interval( interval )
     21        size_t size, const QwtInterval& interval )
     22    : m_size( size )
     23    , m_interval( interval )
    17024{
    17125}
    17226
    17327/*!
    174   Change the number of points
     28   Change the number of points
    17529
    176   \param size Number of points
    177   \sa size(), setInterval()
    178 */
     30   \param size Number of points
     31   \sa size(), setInterval()
     32 */
    17933void QwtSyntheticPointData::setSize( size_t size )
    18034{
    181     d_size = size;
     35    m_size = size;
    18236}
    18337
    18438/*!
    185   \return Number of points
    186   \sa setSize(), interval()
    187 */
     39   \return Number of points
     40   \sa setSize(), interval()
     41 */
    18842size_t QwtSyntheticPointData::size() const
    18943{
    190     return d_size;
     44    return m_size;
    19145}
    19246
    … …  
    19650   \param interval Interval
    19751   \sa interval(), setSize()
    198 */
    199 void QwtSyntheticPointData::setInterval( const QwtInterval &interval )
     52 */
     53void QwtSyntheticPointData::setInterval( const QwtInterval& interval )
    20054{
    201     d_interval = interval.normalized();
     55    m_interval = interval.normalized();
    20256}
    20357
    … …  
    20559   \return Bounding interval
    20660   \sa setInterval(), size()
    207 */
     61 */
    20862QwtInterval QwtSyntheticPointData::interval() const
    20963{
    210     return d_interval;
     64    return m_interval;
    21165}
    21266
    … …  
    22175
    22276   \sa rectOfInterest()
    223 */
    224 void QwtSyntheticPointData::setRectOfInterest( const QRectF &rect )
     77 */
     78void QwtSyntheticPointData::setRectOfInterest( const QRectF& rect )
    22579{
    226     d_rectOfInterest = rect;
    227     d_intervalOfInterest = QwtInterval(
     80    m_rectOfInterest = rect;
     81    m_intervalOfInterest = QwtInterval(
    22882        rect.left(), rect.right() ).normalized();
    22983}
    … …  
    23286   \return "rectangle of interest"
    23387   \sa setRectOfInterest()
    234 */
     88 */
    23589QRectF QwtSyntheticPointData::rectOfInterest() const
    23690{
    237     return d_rectOfInterest;
     91    return m_rectOfInterest;
    23892}
    23993
    24094/*!
    241   \brief Calculate the bounding rectangle
     95   \brief Calculate the bounding rectangle
    24296
    243   This implementation iterates over all points, what could often
    244   be implemented much faster using the characteristics of the series.
    245   When there are many points it is recommended to overload and
    246   reimplement this method using the characteristics of the series
    247   ( if possible ).
     97   This implementation iterates over all points, what could often
     98   be implemented much faster using the characteristics of the series.
     99   When there are many points it is recommended to overload and
     100   reimplement this method using the characteristics of the series
     101   ( if possible ).
    248102
    249   \return Bounding rectangle
    250 */
     103   \return Bounding rectangle
     104 */
    251105QRectF QwtSyntheticPointData::boundingRect() const
    252106{
    253     if ( d_size == 0 ||
    254         !( d_interval.isValid() || d_intervalOfInterest.isValid() ) )
     107    if ( m_size == 0 ||
     108        !( m_interval.isValid() || m_intervalOfInterest.isValid() ) )
    255109    {
    256110        return QRectF( 1.0, 1.0, -2.0, -2.0 ); // something invalid
    … …  
    268122   \warning For invalid indices ( index < 0 || index >= size() )
    269123            (0, 0) is returned.
    270 */
     124 */
    271125QPointF QwtSyntheticPointData::sample( size_t index ) const
    272126{
    273     if ( index >= d_size )
     127    if ( index >= m_size )
    274128        return QPointF( 0, 0 );
    275129
    … …  
    291145
    292146   \sa interval(), rectOfInterest(), y()
    293 */
     147 */
    294148double QwtSyntheticPointData::x( uint index ) const
    295149{
    296     const QwtInterval &interval = d_interval.isValid() ?
    297         d_interval : d_intervalOfInterest;
     150    const QwtInterval& interval = m_interval.isValid() ?
     151        m_interval : m_intervalOfInterest;
    298152
    299153    if ( !interval.isValid() )
    300154        return 0.0;
    301155
    302     if ( d_size <= 1 )
     156    if ( m_size <= 1 )
    303157        return interval.minValue();
    304158
    305     const double dx = interval.width() / ( d_size - 1 );
     159    const double dx = interval.width() / ( m_size - 1 );
    306160    return interval.minValue() + index * dx;
    307161}
  • trunk/BNC/qwt/qwt_point_data.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_POINT_DATA_H
    11 #define QWT_POINT_DATA_H 1
     11#define QWT_POINT_DATA_H
    1212
    1313#include "qwt_global.h"
    1414#include "qwt_series_data.h"
    1515
    16 /*!
    17   \brief Interface for iterating over two QVector<double> objects.
    18 */
    19 class QWT_EXPORT QwtPointArrayData: public QwtSeriesData<QPointF>
    20 {
    21 public:
    22     QwtPointArrayData( const QVector<double> &x, const QVector<double> &y );
    23     QwtPointArrayData( const double *x, const double *y, size_t size );
    24 
    25     virtual QRectF boundingRect() const;
    26 
    27     virtual size_t size() const;
    28     virtual QPointF sample( size_t index ) const;
    29 
    30     const QVector<double> &xData() const;
    31     const QVector<double> &yData() const;
    32 
    33 private:
    34     QVector<double> d_x;
    35     QVector<double> d_y;
     16#include <cstring>
     17
     18/*!
     19   \brief Interface for iterating over two QVector<T> objects.
     20 */
     21template< typename T >
     22class QwtPointArrayData : public QwtSeriesData< QPointF >
     23{
     24  public:
     25    QwtPointArrayData( const QVector< T >& x, const QVector< T >& y );
     26    QwtPointArrayData( const T* x, const T* y, size_t size );
     27
     28    virtual size_t size() const QWT_OVERRIDE;
     29    virtual QPointF sample( size_t index ) const QWT_OVERRIDE;
     30
     31    const QVector< T >& xData() const;
     32    const QVector< T >& yData() const;
     33
     34  private:
     35    QVector< T > m_x;
     36    QVector< T > m_y;
    3637};
    3738
    3839/*!
    39   \brief Data class containing two pointers to memory blocks of doubles.
    40  */
    41 class QWT_EXPORT QwtCPointerData: public QwtSeriesData<QPointF>
    42 {
    43 public:
    44     QwtCPointerData( const double *x, const double *y, size_t size );
    45 
    46     virtual QRectF boundingRect() const;
    47     virtual size_t size() const;
    48     virtual QPointF sample( size_t index ) const;
    49 
    50     const double *xData() const;
    51     const double *yData() const;
    52 
    53 private:
    54     const double *d_x;
    55     const double *d_y;
    56     size_t d_size;
     40   \brief Data class containing two pointers to memory blocks of T.
     41 */
     42template< typename T >
     43class QwtCPointerData : public QwtSeriesData< QPointF >
     44{
     45  public:
     46    QwtCPointerData( const T* x, const T* y, size_t size );
     47
     48    virtual size_t size() const QWT_OVERRIDE;
     49    virtual QPointF sample( size_t index ) const QWT_OVERRIDE;
     50
     51    const T* xData() const;
     52    const T* yData() const;
     53
     54  private:
     55    const T* m_x;
     56    const T* m_y;
     57    size_t m_size;
    5758};
    5859
    5960/*!
    60   \brief Synthetic point data
    61 
    62   QwtSyntheticPointData provides a fixed number of points for an interval.
    63   The points are calculated in equidistant steps in x-direction.
    64 
    65   If the interval is invalid, the points are calculated for
    66   the "rectangle of interest", what normally is the displayed area on the
    67   plot canvas. In this mode you get different levels of detail, when
    68   zooming in/out.
    69 
    70   \par Example
    71 
    72   The following example shows how to implement a sinus curve.
    73 
    74   \code
    75 #include <cmath>
    76 #include <qwt_series_data.h>
    77 #include <qwt_plot_curve.h>
    78 #include <qwt_plot.h>
    79 #include <qapplication.h>
    80 
    81 class SinusData: public QwtSyntheticPointData
    82 {
    83 public:
     61   \brief Interface for iterating over a QVector<T>.
     62
     63   The memory contains the y coordinates, while the index is
     64   interpreted as x coordinate.
     65 */
     66template< typename T >
     67class QwtValuePointData : public QwtSeriesData< QPointF >
     68{
     69  public:
     70    QwtValuePointData( const QVector< T >& y );
     71    QwtValuePointData( const T* y, size_t size );
     72
     73    virtual size_t size() const QWT_OVERRIDE;
     74    virtual QPointF sample( size_t index ) const QWT_OVERRIDE;
     75
     76    const QVector< T >& yData() const;
     77
     78  private:
     79    QVector< T > m_y;
     80};
     81
     82/*!
     83   \brief Data class containing a pointer to memory of y coordinates
     84
     85   The memory contains the y coordinates, while the index is
     86   interpreted as x coordinate.
     87 */
     88template< typename T >
     89class QwtCPointerValueData : public QwtSeriesData< QPointF >
     90{
     91  public:
     92    QwtCPointerValueData( const T* y, size_t size );
     93
     94    virtual size_t size() const QWT_OVERRIDE;
     95    virtual QPointF sample( size_t index ) const QWT_OVERRIDE;
     96
     97    const T* yData() const;
     98
     99  private:
     100    const T* m_y;
     101    size_t m_size;
     102};
     103
     104/*!
     105   \brief Synthetic point data
     106
     107   QwtSyntheticPointData provides a fixed number of points for an interval.
     108   The points are calculated in equidistant steps in x-direction.
     109
     110   If the interval is invalid, the points are calculated for
     111   the "rectangle of interest", what normally is the displayed area on the
     112   plot canvas. In this mode you get different levels of detail, when
     113   zooming in/out.
     114
     115   \par Example
     116
     117   The following example shows how to implement a sinus curve.
     118
     119   \code
     120 #include <cmath>
     121 #include <qwt_series_data.h>
     122 #include <qwt_plot_curve.h>
     123 #include <qwt_plot.h>
     124 #include <qapplication.h>
     125
     126   class SinusData: public QwtSyntheticPointData
     127   {
     128   public:
    84129    SinusData():
    85130        QwtSyntheticPointData( 100 )
    … …  
    91136        return qSin( x );
    92137    }
    93 };
    94 
    95 int main(int argc, char **argv)
    96 {
     138   };
     139
     140   int main(int argc, char **argv)
     141   {
    97142    QApplication a( argc, argv );
    98143
    99144    QwtPlot plot;
    100     plot.setAxisScale( QwtPlot::xBottom, 0.0, 10.0 );
    101     plot.setAxisScale( QwtPlot::yLeft, -1.0, 1.0 );
     145    plot.setAxisScale( QwtAxis::XBottom, 0.0, 10.0 );
     146    plot.setAxisScale( QwtAxis::YLeft, -1.0, 1.0 );
    102147
    103148    QwtPlotCurve *curve = new QwtPlotCurve( "y = sin(x)" );
    … …  
    107152    plot.show();
    108153    return a.exec();
    109 }
     154   }
    110155   \endcode
    111 */
    112 class QWT_EXPORT QwtSyntheticPointData: public QwtSeriesData<QPointF>
    113 {
    114 public:
     156 */
     157class QWT_EXPORT QwtSyntheticPointData : public QwtSeriesData< QPointF >
     158{
     159  public:
    115160    QwtSyntheticPointData( size_t size,
    116         const QwtInterval & = QwtInterval() );
     161        const QwtInterval& = QwtInterval() );
    117162
    118163    void setSize( size_t size );
    119     virtual size_t size() const;
     164    virtual size_t size() const QWT_OVERRIDE;
    120165
    121166    void setInterval( const QwtInterval& );
    122167    QwtInterval interval() const;
    123168
    124     virtual QRectF boundingRect() const;
    125     virtual QPointF sample( size_t index ) const;
     169    virtual QRectF boundingRect() const QWT_OVERRIDE;
     170    virtual QPointF sample( size_t index ) const QWT_OVERRIDE;
    126171
    127172    /*!
    … …  
    134179    virtual double x( uint index ) const;
    135180
    136     virtual void setRectOfInterest( const QRectF & );
     181    virtual void setRectOfInterest( const QRectF& ) QWT_OVERRIDE;
    137182    QRectF rectOfInterest() const;
    138183
    139 private:
    140     size_t d_size;
    141     QwtInterval d_interval;
    142     QRectF d_rectOfInterest;
    143     QwtInterval d_intervalOfInterest;
     184  private:
     185    size_t m_size;
     186    QwtInterval m_interval;
     187    QRectF m_rectOfInterest;
     188    QwtInterval m_intervalOfInterest;
    144189};
    145190
     191/*!
     192   Constructor
     193
     194   \param x Array of x values
     195   \param y Array of y values
     196
     197   \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()
     198 */
     199template< typename T >
     200QwtPointArrayData< T >::QwtPointArrayData(
     201        const QVector< T >& x, const QVector< T >& y )
     202    : m_x( x )
     203    , m_y( y )
     204{
     205}
     206
     207/*!
     208   Constructor
     209
     210   \param x Array of x values
     211   \param y Array of y values
     212   \param size Size of the x and y arrays
     213   \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()
     214 */
     215template< typename T >
     216QwtPointArrayData< T >::QwtPointArrayData( const T* x, const T* y, size_t size )
     217{
     218    m_x.resize( size );
     219    std::memcpy( m_x.data(), x, size * sizeof( T ) );
     220
     221    m_y.resize( size );
     222    std::memcpy( m_y.data(), y, size * sizeof( T ) );
     223}
     224
     225//! \return Size of the data set
     226template< typename T >
     227size_t QwtPointArrayData< T >::size() const
     228{
     229    return qMin( m_x.size(), m_y.size() );
     230}
     231
     232/*!
     233   Return the sample at position i
     234
     235   \param index Index
     236   \return Sample at position i
     237 */
     238template< typename T >
     239QPointF QwtPointArrayData< T >::sample( size_t index ) const
     240{
     241    return QPointF( m_x[int( index )], m_y[int( index )] );
     242}
     243
     244//! \return Array of the x-values
     245template< typename T >
     246const QVector< T >& QwtPointArrayData< T >::xData() const
     247{
     248    return m_x;
     249}
     250
     251//! \return Array of the y-values
     252template< typename T >
     253const QVector< T >& QwtPointArrayData< T >::yData() const
     254{
     255    return m_y;
     256}
     257
     258/*!
     259   Constructor
     260
     261   \param y Array of y values
     262
     263   \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()
     264 */
     265template< typename T >
     266QwtValuePointData< T >::QwtValuePointData( const QVector< T >& y )
     267    : m_y( y )
     268{
     269}
     270
     271/*!
     272   Constructor
     273
     274   \param y Array of y values
     275   \param size Size of the x and y arrays
     276   \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()
     277 */
     278template< typename T >
     279QwtValuePointData< T >::QwtValuePointData( const T* y, size_t size )
     280{
     281    m_y.resize( size );
     282    std::memcpy( m_y.data(), y, size * sizeof( T ) );
     283}
     284
     285//! \return Size of the data set
     286template< typename T >
     287size_t QwtValuePointData< T >::size() const
     288{
     289    return m_y.size();
     290}
     291
     292/*!
     293   Return the sample at position i
     294
     295   \param index Index
     296   \return Sample at position i
     297 */
     298template< typename T >
     299QPointF QwtValuePointData< T >::sample( size_t index ) const
     300{
     301    return QPointF( index, m_y[int( index )] );
     302}
     303
     304//! \return Array of the y-values
     305template< typename T >
     306const QVector< T >& QwtValuePointData< T >::yData() const
     307{
     308    return m_y;
     309}
     310
     311/*!
     312   Constructor
     313
     314   \param x Array of x values
     315   \param y Array of y values
     316   \param size Size of the x and y arrays
     317
     318   \warning The programmer must assure that the memory blocks referenced
     319           by the pointers remain valid during the lifetime of the
     320           QwtPlotCPointer object.
     321
     322   \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples()
     323 */
     324
     325template< typename T >
     326QwtCPointerData< T >::QwtCPointerData( const T* x, const T* y, size_t size )
     327    : m_x( x )
     328    , m_y( y )
     329    , m_size( size )
     330{
     331}
     332
     333//! \return Size of the data set
     334template< typename T >
     335size_t QwtCPointerData< T >::size() const
     336{
     337    return m_size;
     338}
     339
     340/*!
     341   Return the sample at position i
     342
     343   \param index Index
     344   \return Sample at position i
     345 */
     346template< typename T >
     347QPointF QwtCPointerData< T >::sample( size_t index ) const
     348{
     349    return QPointF( m_x[int( index )], m_y[int( index )] );
     350}
     351
     352//! \return Array of the x-values
     353template< typename T >
     354const T* QwtCPointerData< T >::xData() const
     355{
     356    return m_x;
     357}
     358
     359//! \return Array of the y-values
     360template< typename T >
     361const T* QwtCPointerData< T >::yData() const
     362{
     363    return m_y;
     364}
     365
     366/*!
     367   Constructor
     368
     369   \param y Array of y values
     370   \param size Size of the x and y arrays
     371
     372   \warning The programmer must assure that the memory blocks referenced
     373           by the pointers remain valid during the lifetime of the
     374           QwtCPointerValueData object.
     375
     376   \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples()
     377 */
     378
     379template< typename T >
     380QwtCPointerValueData< T >::QwtCPointerValueData( const T* y, size_t size )
     381    : m_y( y )
     382    , m_size( size )
     383{
     384}
     385
     386//! \return Size of the data set
     387template< typename T >
     388size_t QwtCPointerValueData< T >::size() const
     389{
     390    return m_size;
     391}
     392
     393/*!
     394   Return the sample at position i
     395
     396   \param index Index
     397   \return Sample at position i
     398 */
     399template< typename T >
     400QPointF QwtCPointerValueData< T >::sample( size_t index ) const
     401{
     402    return QPointF( index, m_y[ int( index ) ] );
     403}
     404
     405//! \return Array of the y-values
     406template< typename T >
     407const T* QwtCPointerValueData< T >::yData() const
     408{
     409    return m_y;
     410}
     411
    146412#endif
  • trunk/BNC/qwt/qwt_point_mapper.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_scale_map.h"
    1212#include "qwt_pixel_matrix.h"
     13#include "qwt_series_data.h"
     14#include "qwt_math.h"
     15
    1316#include <qpolygon.h>
    1417#include <qimage.h>
    … …  
    1619#include <qpainter.h>
    1720
    18 #if QT_VERSION >= 0x040400
    19 
    2021#include <qthread.h>
    2122#include <qfuture.h>
    2223#include <qtconcurrentrun.h>
    2324
    24 #if !defined(QT_NO_QFUTURE)
     25#if !defined( QT_NO_QFUTURE )
    2526#define QWT_USE_THREADS 1
    2627#endif
    2728
     29static QRectF qwtInvalidRect( 0.0, 0.0, -1.0, -1.0 );
     30
     31static inline int qwtRoundValue( double value )
     32{
     33    return qRound( value );
     34}
     35
     36static inline double qwtRoundValueF( double value )
     37{
     38#if 1
     39    // MS Windows and at least IRIX does not have C99's nearbyint() function
     40    return ( value >= 0.0 ) ? std::floor( value + 0.5 ) : std::ceil( value - 0.5 );
     41#else
     42    return nearbyint( value );
    2843#endif
    29 
    30 static QRectF qwtInvalidRect( 0.0, 0.0, -1.0, -1.0 );
     44}
     45
     46static Qt::Orientation qwtProbeOrientation(
     47    const QwtSeriesData< QPointF >* series, int from, int to )
     48{
     49    if ( to - from < 20 )
     50    {
     51        // not enough points to "have an orientation"
     52        return Qt::Horizontal;
     53    }
     54
     55    const double x0 = series->sample( from ).x();
     56    const double xn = series->sample( to ).x();
     57
     58    if ( x0 == xn )
     59        return Qt::Vertical;
     60
     61    const int step = ( to - from ) / 10;
     62    const bool isIncreasing = xn > x0;
     63
     64    double x1 = x0;
     65    for ( int i = from + step; i < to; i += step )
     66    {
     67        const double x2 = series->sample( i ).x();
     68        if ( x2 != x1 )
     69        {
     70            if ( ( x2 > x1 ) != isIncreasing )
     71                return Qt::Vertical;
     72        }
     73
     74        x1 = x2;
     75    }
     76
     77    return Qt::Horizontal;
     78}
     79
     80namespace
     81{
     82    template< class Polygon, class Point >
     83    class QwtPolygonQuadrupelX
     84    {
     85      public:
     86        inline void start( int x, int y )
     87        {
     88            m_x0 = x;
     89            m_y1 = m_yMin = m_yMax = m_y2 = y;
     90        }
     91
     92        inline bool append( int x, int y )
     93        {
     94            if ( m_x0 != x )
     95                return false;
     96
     97            if ( y < m_yMin )
     98                m_yMin = y;
     99            else if ( y > m_yMax )
     100                m_yMax = y;
     101
     102            m_y2 = y;
     103
     104            return true;
     105        }
     106
     107        inline void flush( Polygon& polyline )
     108        {
     109            appendTo( m_y1, polyline );
     110
     111            if ( m_y2 > m_y1 )
     112                qSwap( m_yMin, m_yMax );
     113
     114            if ( m_yMax != m_y1 )
     115                appendTo( m_yMax, polyline );
     116
     117            if ( m_yMin != m_yMax )
     118                appendTo( m_yMin, polyline );
     119
     120            if ( m_y2 != m_yMin )
     121                appendTo( m_y2, polyline );
     122        }
     123
     124      private:
     125        inline void appendTo( int y, Polygon& polyline )
     126        {
     127            polyline += Point( m_x0, y );
     128        }
     129
     130      private:
     131        int m_x0, m_y1, m_yMin, m_yMax, m_y2;
     132    };
     133
     134    template< class Polygon, class Point >
     135    class QwtPolygonQuadrupelY
     136    {
     137      public:
     138        inline void start( int x, int y )
     139        {
     140            m_y0 = y;
     141            m_x1 = m_xMin = m_xMax = m_x2 = x;
     142        }
     143
     144        inline bool append( int x, int y )
     145        {
     146            if ( m_y0 != y )
     147                return false;
     148
     149            if ( x < m_xMin )
     150                m_xMin = x;
     151            else if ( x > m_xMax )
     152                m_xMax = x;
     153
     154            m_x2 = x;
     155
     156            return true;
     157        }
     158
     159        inline void flush( Polygon& polyline )
     160        {
     161            appendTo( m_x1, polyline );
     162
     163            if ( m_x2 > m_x1 )
     164                qSwap( m_xMin, m_xMax );
     165
     166            if ( m_xMax != m_x1 )
     167                appendTo( m_xMax, polyline );
     168
     169            if ( m_xMin != m_xMax )
     170                appendTo( m_xMin, polyline );
     171
     172            if ( m_x2 != m_xMin )
     173                appendTo( m_x2, polyline );
     174        }
     175
     176      private:
     177        inline void appendTo( int x, Polygon& polyline )
     178        {
     179            polyline += Point( x, m_y0 );
     180        }
     181
     182        int m_y0, m_x1, m_xMin, m_xMax, m_x2;
     183    };
     184}
     185
     186template< class Polygon, class Point, class PolygonQuadrupel >
     187static Polygon qwtMapPointsQuad( const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     188    const QwtSeriesData< QPointF >* series, int from, int to )
     189{
     190    const QPointF sample0 = series->sample( from );
     191
     192    PolygonQuadrupel q;
     193    q.start( qwtRoundValue( xMap.transform( sample0.x() ) ),
     194        qwtRoundValue( yMap.transform( sample0.y() ) ) );
     195
     196    Polygon polyline;
     197    for ( int i = from; i <= to; i++ )
     198    {
     199        const QPointF sample = series->sample( i );
     200
     201        const int x = qwtRoundValue( xMap.transform( sample.x() ) );
     202        const int y = qwtRoundValue( yMap.transform( sample.y() ) );
     203
     204        if ( !q.append( x, y ) )
     205        {
     206            q.flush( polyline );
     207            q.start( x, y );
     208        }
     209    }
     210    q.flush( polyline );
     211
     212    return polyline;
     213}
     214
     215template< class Polygon, class Point, class PolygonQuadrupel >
     216static Polygon qwtMapPointsQuad( const Polygon& polyline )
     217{
     218    const int numPoints = polyline.size();
     219
     220    if ( numPoints < 3 )
     221        return polyline;
     222
     223    const Point* points = polyline.constData();
     224
     225    Polygon polylineXY;
     226
     227    PolygonQuadrupel q;
     228    q.start( points[0].x(), points[0].y() );
     229
     230    for ( int i = 0; i < numPoints; i++ )
     231    {
     232        const int x = points[i].x();
     233        const int y = points[i].y();
     234
     235        if ( !q.append( x, y ) )
     236        {
     237            q.flush( polylineXY );
     238            q.start( x, y );
     239        }
     240    }
     241    q.flush( polylineXY );
     242
     243    return polylineXY;
     244}
     245
     246
     247template< class Polygon, class Point >
     248static Polygon qwtMapPointsQuad( const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     249    const QwtSeriesData< QPointF >* series, int from, int to )
     250{
     251    Polygon polyline;
     252    if ( from > to )
     253        return polyline;
     254
     255    /*
     256        probing some values, to decide if it is better
     257        to start with x or y coordinates
     258     */
     259    const Qt::Orientation orientation = qwtProbeOrientation( series, from, to );
     260
     261    if ( orientation == Qt::Horizontal )
     262    {
     263        polyline = qwtMapPointsQuad< Polygon, Point,
     264            QwtPolygonQuadrupelY< Polygon, Point > >( xMap, yMap, series, from, to );
     265
     266        polyline = qwtMapPointsQuad< Polygon, Point,
     267            QwtPolygonQuadrupelX< Polygon, Point > >( polyline );
     268    }
     269    else
     270    {
     271        polyline = qwtMapPointsQuad< Polygon, Point,
     272            QwtPolygonQuadrupelX< Polygon, Point > >( xMap, yMap, series, from, to );
     273
     274        polyline = qwtMapPointsQuad< Polygon, Point,
     275            QwtPolygonQuadrupelY< Polygon, Point > >( polyline );
     276    }
     277
     278    return polyline;
     279}
    31280
    32281// Helper class to work around the 5 parameters
    … …  
    34283class QwtDotsCommand
    35284{
    36 public:
    37     const QwtSeriesData<QPointF> *series;
     285  public:
     286    const QwtSeriesData< QPointF >* series;
    38287    int from;
    39288    int to;
    … …  
    42291
    43292static void qwtRenderDots(
    44     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    45     const QwtDotsCommand command, const QPoint &pos, QImage *image )
     293    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     294    const QwtDotsCommand& command, const QPoint& pos, QImage* image )
    46295{
    47296    const QRgb rgb = command.rgb;
    48     QRgb *bits = reinterpret_cast<QRgb *>( image->bits() );
     297    QRgb* bits = reinterpret_cast< QRgb* >( image->bits() );
    49298
    50299    const int w = image->width();
    … …  
    58307        const QPointF sample = command.series->sample( i );
    59308
    60         const int x = static_cast<int>( xMap.transform( sample.x() ) + 0.5 ) - x0;
    61         const int y = static_cast<int>( yMap.transform( sample.y() ) + 0.5 ) - y0;
     309        const int x = static_cast< int >( xMap.transform( sample.x() ) + 0.5 ) - x0;
     310        const int y = static_cast< int >( yMap.transform( sample.y() ) + 0.5 ) - y0;
    62311
    63312        if ( x >= 0 && x < w && y >= 0 && y < h )
    … …  
    66315}
    67316
    68 static inline int qwtRoundValue( double value )
    69 {
    70     return qRound( value );
    71 }
    72 
    73317// some functors, so that the compile can inline
    74318struct QwtRoundI
    75319{
    76     inline int operator()( double value )
     320    inline int operator()( double value ) const
    77321    {
    78322        return qwtRoundValue( value );
    … …  
    82326struct QwtRoundF
    83327{
    84     inline double operator()( double value )
    85     {
    86 #if 1
    87         // MS Windows and at least IRIX does not have C99's nearbyint() function
    88         return ( value >= 0.0 ) ? ::floor( value + 0.5 ) : ::ceil( value - 0.5 );
    89 #else
    90         // slightly faster than the code above
    91         return nearbyint( value );
    92 #endif
     328    inline double operator()( double value ) const
     329    {
     330        return qwtRoundValueF( value );
    93331    }
    94332};
    … …  
    96334struct QwtNoRoundF
    97335{
    98     inline double operator()( double value )
     336    inline double operator()( double value ) const
    99337    {
    100338        return value;
    … …  
    105343// the bounding rectangle
    106344
    107 template<class Polygon, class Point, class Round>
     345template< class Polygon, class Point, class Round >
    108346static inline Polygon qwtToPoints(
    109     const QRectF &boundingRect,
    110     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    111     const QwtSeriesData<QPointF> *series,
     347    const QRectF& boundingRect,
     348    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     349    const QwtSeriesData< QPointF >* series,
    112350    int from, int to, Round round )
    113351{
    114352    Polygon polyline( to - from + 1 );
    115     Point *points = polyline.data();
     353    Point* points = polyline.data();
    116354
    117355    int numPoints = 0;
    … …  
    164402
    165403static inline QPolygon qwtToPointsI(
    166     const QRectF &boundingRect,
    167     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    168     const QwtSeriesData<QPointF> *series,
     404    const QRectF& boundingRect,
     405    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     406    const QwtSeriesData< QPointF >* series,
    169407    int from, int to )
    170408{
    171     return qwtToPoints<QPolygon, QPoint>(
     409    return qwtToPoints< QPolygon, QPoint >(
    172410        boundingRect, xMap, yMap, series, from, to, QwtRoundI() );
    173411}
    174412
    175 template<class Round>
     413template< class Round >
    176414static inline QPolygonF qwtToPointsF(
    177     const QRectF &boundingRect,
    178     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    179     const QwtSeriesData<QPointF> *series,
     415    const QRectF& boundingRect,
     416    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     417    const QwtSeriesData< QPointF >* series,
    180418    int from, int to, Round round )
    181419{
    182     return qwtToPoints<QPolygonF, QPointF>(
     420    return qwtToPoints< QPolygonF, QPointF >(
    183421        boundingRect, xMap, yMap, series, from, to, round );
    184422}
    … …  
    187425// points mapped to the same position
    188426
    189 template<class Polygon, class Point, class Round>
     427template< class Polygon, class Point, class Round >
    190428static inline Polygon qwtToPolylineFiltered(
    191     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    192     const QwtSeriesData<QPointF> *series,
     429    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     430    const QwtSeriesData< QPointF >* series,
    193431    int from, int to, Round round )
    194432{
    … …  
    199437
    200438    Polygon polyline( to - from + 1 );
    201     Point *points = polyline.data();
     439    Point* points = polyline.data();
    202440
    203441    const QPointF sample0 = series->sample( from );
    … …  
    223461
    224462static inline QPolygon qwtToPolylineFilteredI(
    225     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    226     const QwtSeriesData<QPointF> *series,
     463    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     464    const QwtSeriesData< QPointF >* series,
    227465    int from, int to )
    228466{
    229     return qwtToPolylineFiltered<QPolygon, QPoint>(
     467    return qwtToPolylineFiltered< QPolygon, QPoint >(
    230468        xMap, yMap, series, from, to, QwtRoundI() );
    231469}
    232470
    233 template<class Round>
     471template< class Round >
    234472static inline QPolygonF qwtToPolylineFilteredF(
    235     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    236     const QwtSeriesData<QPointF> *series,
     473    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     474    const QwtSeriesData< QPointF >* series,
    237475    int from, int to, Round round )
    238476{
    239     return qwtToPolylineFiltered<QPolygonF, QPointF>(
     477    return qwtToPolylineFiltered< QPolygonF, QPointF >(
    240478        xMap, yMap, series, from, to, round );
    241479}
    242480
    243 template<class Polygon, class Point>
     481template< class Polygon, class Point >
    244482static inline Polygon qwtToPointsFiltered(
    245     const QRectF &boundingRect,
    246     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    247     const QwtSeriesData<QPointF> *series, int from, int to )
     483    const QRectF& boundingRect,
     484    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     485    const QwtSeriesData< QPointF >* series, int from, int to )
    248486{
    249487    // F.e. in scatter plots ( no connecting lines ) we
    … …  
    251489
    252490    Polygon polygon( to - from + 1 );
    253     Point *points = polygon.data();
     491    Point* points = polygon.data();
    254492
    255493    QwtPixelMatrix pixelMatrix( boundingRect.toAlignedRect() );
    … …  
    277515
    278516static inline QPolygon qwtToPointsFilteredI(
    279     const QRectF &boundingRect,
    280     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    281     const QwtSeriesData<QPointF> *series, int from, int to )
    282 {
    283     return qwtToPointsFiltered<QPolygon, QPoint>(
     517    const QRectF& boundingRect,
     518    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     519    const QwtSeriesData< QPointF >* series, int from, int to )
     520{
     521    return qwtToPointsFiltered< QPolygon, QPoint >(
    284522        boundingRect, xMap, yMap, series, from, to );
    285523}
    286524
    287525static inline QPolygonF qwtToPointsFilteredF(
    288     const QRectF &boundingRect,
    289     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    290     const QwtSeriesData<QPointF> *series, int from, int to )
    291 {
    292     return qwtToPointsFiltered<QPolygonF, QPointF>(
     526    const QRectF& boundingRect,
     527    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     528    const QwtSeriesData< QPointF >* series, int from, int to )
     529{
     530    return qwtToPointsFiltered< QPolygonF, QPointF >(
    293531        boundingRect, xMap, yMap, series, from, to );
    294532}
    … …  
    296534class QwtPointMapper::PrivateData
    297535{
    298 public:
    299     PrivateData():
    300         boundingRect( qwtInvalidRect )
     536  public:
     537    PrivateData()
     538        : boundingRect( qwtInvalidRect )
    301539    {
    302540    }
    … …  
    309547QwtPointMapper::QwtPointMapper()
    310548{
    311     d_data = new PrivateData();
     549    m_data = new PrivateData();
    312550}
    313551
    … …  
    315553QwtPointMapper::~QwtPointMapper()
    316554{
    317     delete d_data;
    318 }
    319 
    320 /*!
    321   Set the flags affecting the transformation process
    322 
    323   \param flags Flags
    324   \sa flags(), setFlag()
     555    delete m_data;
     556}
     557
     558/*!
     559   Set the flags affecting the transformation process
     560
     561   \param flags Flags
     562   \sa flags(), setFlag()
    325563 */
    326564void QwtPointMapper::setFlags( TransformationFlags flags )
    327565{
    328     d_data->flags = flags;
    329 }
    330 
    331 /*!
    332   \return Flags affecting the transformation process
    333   \sa setFlags(), setFlag()
     566    m_data->flags = flags;
     567}
     568
     569/*!
     570   \return Flags affecting the transformation process
     571   \sa setFlags(), setFlag()
    334572 */
    335573QwtPointMapper::TransformationFlags QwtPointMapper::flags() const
    336574{
    337     return d_data->flags;
    338 }
    339 
    340 /*!
    341   Modify a flag affecting the transformation process
    342 
    343   \param flag Flag type
    344   \param on Value
    345 
    346   \sa flag(), setFlags()
     575    return m_data->flags;
     576}
     577
     578/*!
     579   Modify a flag affecting the transformation process
     580
     581   \param flag Flag type
     582   \param on Value
     583
     584   \sa flag(), setFlags()
    347585 */
    348586void QwtPointMapper::setFlag( TransformationFlag flag, bool on )
    349587{
    350588    if ( on )
    351         d_data->flags |= flag;
     589        m_data->flags |= flag;
    352590    else
    353         d_data->flags &= ~flag;
    354 }
    355 
    356 /*!
    357   \return True, when the flag is set
    358   \param flag Flag type
    359   \sa setFlag(), setFlags()
     591        m_data->flags &= ~flag;
     592}
     593
     594/*!
     595   \return True, when the flag is set
     596   \param flag Flag type
     597   \sa setFlag(), setFlags()
    360598 */
    361599bool QwtPointMapper::testFlag( TransformationFlag flag ) const
    362600{
    363     return d_data->flags & flag;
    364 }
    365 
    366 /*!
    367   Set a bounding rectangle for the point mapping algorithm
    368 
    369   A valid bounding rectangle can be used for optimizations
    370 
    371   \param rect Bounding rectangle
    372   \sa boundingRect()
    373  */
    374 void QwtPointMapper::setBoundingRect( const QRectF &rect )
    375 {
    376     d_data->boundingRect = rect;
    377 }
    378 
    379 /*!
    380   \return Bounding rectangle
    381   \sa setBoundingRect()
     601    return m_data->flags & flag;
     602}
     603
     604/*!
     605   Set a bounding rectangle for the point mapping algorithm
     606
     607   A valid bounding rectangle can be used for optimizations
     608
     609   \param rect Bounding rectangle
     610   \sa boundingRect()
     611 */
     612void QwtPointMapper::setBoundingRect( const QRectF& rect )
     613{
     614    m_data->boundingRect = rect;
     615}
     616
     617/*!
     618   \return Bounding rectangle
     619   \sa setBoundingRect()
    382620 */
    383621QRectF QwtPointMapper::boundingRect() const
    384622{
    385     return d_data->boundingRect;
    386 }
    387 
    388 /*!
    389   \brief Translate a series of points into a QPolygonF
    390 
    391   When the WeedOutPoints flag is enabled consecutive points,
    392   that are mapped to the same position will be one point.
    393 
    394   When RoundPoints is set all points are rounded to integers
    395   but returned as PolygonF - what only makes sense
    396   when the further processing of the values need a QPolygonF.
    397 
    398   \param xMap x map
    399   \param yMap y map
    400   \param series Series of points to be mapped
    401   \param from Index of the first point to be painted
    402   \param to Index of the last point to be painted
    403 
    404   \return Translated polygon
    405 */
     623    return m_data->boundingRect;
     624}
     625
     626/*!
     627   \brief Translate a series of points into a QPolygonF
     628
     629   When the WeedOutPoints flag is enabled consecutive points,
     630   that are mapped to the same position will be one point.
     631
     632   When RoundPoints is set all points are rounded to integers
     633   but returned as PolygonF - what only makes sense
     634   when the further processing of the values need a QPolygonF.
     635
     636   When RoundPoints & WeedOutIntermediatePoints is enabled an even more
     637   aggressive weeding algorithm is enabled.
     638
     639   \param xMap x map
     640   \param yMap y map
     641   \param series Series of points to be mapped
     642   \param from Index of the first point to be painted
     643   \param to Index of the last point to be painted
     644
     645   \return Translated polygon
     646 */
    406647QPolygonF QwtPointMapper::toPolygonF(
    407     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    408     const QwtSeriesData<QPointF> *series, int from, int to ) const
     648    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     649    const QwtSeriesData< QPointF >* series, int from, int to ) const
    409650{
    410651    QPolygonF polyline;
    411652
    412     if ( d_data->flags & WeedOutPoints )
    413     {
    414         if ( d_data->flags & RoundPoints )
     653    if ( m_data->flags & RoundPoints )
     654    {
     655        if ( m_data->flags & WeedOutIntermediatePoints )
     656        {
     657            polyline = qwtMapPointsQuad< QPolygonF, QPointF >(
     658                xMap, yMap, series, from, to );
     659        }
     660        else if ( m_data->flags & WeedOutPoints )
    415661        {
    416662            polyline = qwtToPolylineFilteredF(
    … …  
    419665        else
    420666        {
     667            polyline = qwtToPointsF( qwtInvalidRect,
     668                xMap, yMap, series, from, to, QwtRoundF() );
     669        }
     670    }
     671    else
     672    {
     673        if ( m_data->flags & WeedOutPoints )
     674        {
    421675            polyline = qwtToPolylineFilteredF(
    422676                xMap, yMap, series, from, to, QwtNoRoundF() );
    423677        }
    424     }
    425     else
    426     {
    427         if ( d_data->flags & RoundPoints )
    428         {
    429             polyline = qwtToPointsF( qwtInvalidRect,
    430                 xMap, yMap, series, from, to, QwtRoundF() );
    431         }
    432678        else
    433679        {
    … …  
    441687
    442688/*!
    443   \brief Translate a series of points into a QPolygon
    444 
    445   When the WeedOutPoints flag is enabled consecutive points,
    446   that are mapped to the same position will be one point.
    447 
    448   \param xMap x map
    449   \param yMap y map
    450   \param series Series of points to be mapped
    451   \param from Index of the first point to be painted
    452   \param to Index of the last point to be painted
    453 
    454   \return Translated polygon
    455 */
     689   \brief Translate a series of points into a QPolygon
     690
     691   When the WeedOutPoints flag is enabled consecutive points,
     692   that are mapped to the same position will be one point.
     693
     694   \param xMap x map
     695   \param yMap y map
     696   \param series Series of points to be mapped
     697   \param from Index of the first point to be painted
     698   \param to Index of the last point to be painted
     699
     700   \return Translated polygon
     701 */
    456702QPolygon QwtPointMapper::toPolygon(
    457     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    458     const QwtSeriesData<QPointF> *series, int from, int to ) const
     703    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     704    const QwtSeriesData< QPointF >* series, int from, int to ) const
    459705{
    460706    QPolygon polyline;
    461707
    462     if ( d_data->flags & WeedOutPoints )
     708    if ( m_data->flags & WeedOutIntermediatePoints )
     709    {
     710        // TODO WeedOutIntermediatePointsY ...
     711        polyline = qwtMapPointsQuad< QPolygon, QPoint >(
     712            xMap, yMap, series, from, to );
     713    }
     714    else if ( m_data->flags & WeedOutPoints )
    463715    {
    464716        polyline = qwtToPolylineFilteredI(
    … …  
    475727
    476728/*!
    477   \brief Translate a series into a QPolygonF
    478 
    479   - WeedOutPoints & RoundPoints & boundingRect().isValid()
     729   \brief Translate a series into a QPolygonF
     730
     731   - WeedOutPoints & RoundPoints & boundingRect().isValid()
    480732    All points that are mapped to the same position
    481733    will be one point. Points outside of the bounding
    482734    rectangle are ignored.
    483735
    484   - WeedOutPoints & RoundPoints & !boundingRect().isValid()
     736   - WeedOutPoints & RoundPoints & !boundingRect().isValid()
    485737    All consecutive points that are mapped to the same position
    486738    will one point
    487739
    488   - WeedOutPoints & !RoundPoints
     740   - WeedOutPoints & !RoundPoints
    489741    All consecutive points that are mapped to the same position
    490742    will one point
    491743
    492   - !WeedOutPoints & boundingRect().isValid()
     744   - !WeedOutPoints & boundingRect().isValid()
    493745    Points outside of the bounding rectangle are ignored.
    494746
    495   When RoundPoints is set all points are rounded to integers
    496   but returned as PolygonF - what only makes sense
    497   when the further processing of the values need a QPolygonF.
    498 
    499   \param xMap x map
    500   \param yMap y map
    501   \param series Series of points to be mapped
    502   \param from Index of the first point to be painted
    503   \param to Index of the last point to be painted
    504 
    505   \return Translated polygon
    506 */
     747   When RoundPoints is set all points are rounded to integers
     748   but returned as PolygonF - what only makes sense
     749   when the further processing of the values need a QPolygonF.
     750
     751   \param xMap x map
     752   \param yMap y map
     753   \param series Series of points to be mapped
     754   \param from Index of the first point to be painted
     755   \param to Index of the last point to be painted
     756
     757   \return Translated polygon
     758 */
    507759QPolygonF QwtPointMapper::toPointsF(
    508     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    509     const QwtSeriesData<QPointF> *series, int from, int to ) const
     760    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     761    const QwtSeriesData< QPointF >* series, int from, int to ) const
    510762{
    511763    QPolygonF points;
    512764
    513     if ( d_data->flags & WeedOutPoints )
    514     {
    515         if ( d_data->flags & RoundPoints )
    516         {
    517             if ( d_data->boundingRect.isValid() )
     765    if ( m_data->flags & WeedOutPoints )
     766    {
     767        if ( m_data->flags & RoundPoints )
     768        {
     769            if ( m_data->boundingRect.isValid() )
    518770            {
    519                 points = qwtToPointsFilteredF( d_data->boundingRect,
     771                points = qwtToPointsFilteredF( m_data->boundingRect,
    520772                    xMap, yMap, series, from, to );
    521773            }
    … …  
    541793    else
    542794    {
    543         if ( d_data->flags & RoundPoints )
    544         {
    545             points = qwtToPointsF( d_data->boundingRect,
     795        if ( m_data->flags & RoundPoints )
     796        {
     797            points = qwtToPointsF( m_data->boundingRect,
    546798                xMap, yMap, series, from, to, QwtRoundF() );
    547799        }
    548800        else
    549801        {
    550             points = qwtToPointsF( d_data->boundingRect,
     802            points = qwtToPointsF( m_data->boundingRect,
    551803                xMap, yMap, series, from, to, QwtNoRoundF() );
    552804        }
    … …  
    557809
    558810/*!
    559   \brief Translate a series of points into a QPolygon
    560 
    561   - WeedOutPoints & boundingRect().isValid()
     811   \brief Translate a series of points into a QPolygon
     812
     813   - WeedOutPoints & boundingRect().isValid()
    562814    All points that are mapped to the same position
    563815    will be one point. Points outside of the bounding
    564816    rectangle are ignored.
    565817
    566   - WeedOutPoints & !boundingRect().isValid()
     818   - WeedOutPoints & !boundingRect().isValid()
    567819    All consecutive points that are mapped to the same position
    568820    will one point
    569821
    570   - !WeedOutPoints & boundingRect().isValid()
     822   - !WeedOutPoints & boundingRect().isValid()
    571823    Points outside of the bounding rectangle are ignored.
    572824
    573   \param xMap x map
    574   \param yMap y map
    575   \param series Series of points to be mapped
    576   \param from Index of the first point to be painted
    577   \param to Index of the last point to be painted
    578 
    579   \return Translated polygon
    580 */
     825   \param xMap x map
     826   \param yMap y map
     827   \param series Series of points to be mapped
     828   \param from Index of the first point to be painted
     829   \param to Index of the last point to be painted
     830
     831   \return Translated polygon
     832 */
    581833QPolygon QwtPointMapper::toPoints(
    582     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    583     const QwtSeriesData<QPointF> *series, int from, int to ) const
     834    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     835    const QwtSeriesData< QPointF >* series, int from, int to ) const
    584836{
    585837    QPolygon points;
    586838
    587     if ( d_data->flags & WeedOutPoints )
    588     {
    589         if ( d_data->boundingRect.isValid() )
    590         {
    591             points = qwtToPointsFilteredI( d_data->boundingRect,
     839    if ( m_data->flags & WeedOutPoints )
     840    {
     841        if ( m_data->boundingRect.isValid() )
     842        {
     843            points = qwtToPointsFilteredI( m_data->boundingRect,
    592844                xMap, yMap, series, from, to );
    593845        }
    … …  
    604856    {
    605857        points = qwtToPointsI(
    606             d_data->boundingRect, xMap, yMap, series, from, to );
     858            m_data->boundingRect, xMap, yMap, series, from, to );
    607859    }
    608860
    … …  
    612864
    613865/*!
    614   \brief Translate a series into a QImage
    615 
    616   \param xMap x map
    617   \param yMap y map
    618   \param series Series of points to be mapped
    619   \param from Index of the first point to be painted
    620   \param to Index of the last point to be painted
    621   \param pen Pen used for drawing a point
     866   \brief Translate a series into a QImage
     867
     868   \param xMap x map
     869   \param yMap y map
     870   \param series Series of points to be mapped
     871   \param from Index of the first point to be painted
     872   \param to Index of the last point to be painted
     873   \param pen Pen used for drawing a point
    622874             of the image, where a point is mapped to
    623   \param antialiased True, when the dots should be displayed
     875   \param antialiased True, when the dots should be displayed
    624876                     antialiased
    625   \param numThreads Number of threads to be used for rendering.
     877   \param numThreads Number of threads to be used for rendering.
    626878                   If numThreads is set to 0, the system specific
    627879                   ideal thread count is used.
    628880
    629   \return Image displaying the series
    630 */
     881   \return Image displaying the series
     882 */
    631883QImage QwtPointMapper::toImage(
    632     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    633     const QwtSeriesData<QPointF> *series, int from, int to,
    634     const QPen &pen, bool antialiased, uint numThreads ) const
     884    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     885    const QwtSeriesData< QPointF >* series, int from, int to,
     886    const QPen& pen, bool antialiased, uint numThreads ) const
    635887{
    636888    Q_UNUSED( antialiased )
    … …  
    649901    // where every sample is mapped to one pixel only.
    650902
    651     const QRect rect = d_data->boundingRect.toAlignedRect();
     903    const QRect rect = m_data->boundingRect.toAlignedRect();
    652904
    653905    QImage image( rect.size(), QImage::Format_ARGB32 );
    … …  
    663915        const int numPoints = ( to - from + 1 ) / numThreads;
    664916
    665         QList< QFuture<void> > futures;
     917        QList< QFuture< void > > futures;
    666918        for ( uint i = 0; i < numThreads; i++ )
    667919        {
  • trunk/BNC/qwt/qwt_point_mapper.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_series_data.h"
    15 #include <qimage.h>
    1614
    1715class QwtScaleMap;
     16template< typename T > class QwtSeriesData;
    1817class QPolygonF;
     18class QPointF;
     19class QRectF;
    1920class QPolygon;
     21class QPen;
     22class QImage;
    2023
    2124/*!
    22   \brief A helper class for translating a series of points
     25   \brief A helper class for translating a series of points
    2326
    24   QwtPointMapper is a collection of methods and optimizations
    25   for translating a series of points into paint device coordinates.
    26   It is used by QwtPlotCurve but might also be useful for
    27   similar plot items displaying a QwtSeriesData<QPointF>.
     27   QwtPointMapper is a collection of methods and optimizations
     28   for translating a series of points into paint device coordinates.
     29   It is used by QwtPlotCurve but might also be useful for
     30   similar plot items displaying a QwtSeriesData<QPointF>.
    2831 */
    2932class QWT_EXPORT QwtPointMapper
    3033{
    31 public:
     34  public:
    3235    /*!
    33       \brief Flags affecting the transformation process
    34       \sa setFlag(), setFlags()
     36       \brief Flags affecting the transformation process
     37       \sa setFlag(), setFlags()
    3538     */
    3639    enum TransformationFlag
    … …  
    4043
    4144        /*!
    42           Try to remove points, that are translated to the
    43           same position.
     45           Try to remove points, that are translated to the
     46           same position.
    4447         */
    45         WeedOutPoints = 0x02
     48        WeedOutPoints = 0x02,
     49
     50        /*!
     51           An even more aggressive weeding algorithm, that
     52           can be used in toPolygon().
     53
     54           A consecutive chunk of points being mapped to the
     55           same x coordinate is reduced to 4 points:
     56
     57              - first point
     58              - point with the minimum y coordinate
     59              - point with the maximum y coordinate
     60              - last point
     61
     62           In the worst case ( first and last points are never one of the extremes )
     63           the number of points will be 4 times the width.
     64
     65           As the algorithm is fast it can be used inside of
     66           a polyline render cycle.
     67         */
     68        WeedOutIntermediatePoints = 0x04
    4669    };
    4770
    48     /*!
    49       \brief Flags affecting the transformation process
    50       \sa setFlag(), setFlags()
    51      */
    52     typedef QFlags<TransformationFlag> TransformationFlags;
     71    Q_DECLARE_FLAGS( TransformationFlags, TransformationFlag )
    5372
    5473    QwtPointMapper();
    … …  
    6180    bool testFlag( TransformationFlag ) const;
    6281
    63     void setBoundingRect( const QRectF & );
     82    void setBoundingRect( const QRectF& );
    6483    QRectF boundingRect() const;
    6584
    66     QPolygonF toPolygonF( const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    67         const QwtSeriesData<QPointF> *series, int from, int to ) const;
     85    QPolygonF toPolygonF( const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     86        const QwtSeriesData< QPointF >* series, int from, int to ) const;
    6887
    69     QPolygon toPolygon( const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    70         const QwtSeriesData<QPointF> *series, int from, int to ) const;
     88    QPolygon toPolygon( const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     89        const QwtSeriesData< QPointF >* series, int from, int to ) const;
    7190
    72     QPolygon toPoints( const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    73         const QwtSeriesData<QPointF> *series, int from, int to ) const;
     91    QPolygon toPoints( const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     92        const QwtSeriesData< QPointF >* series, int from, int to ) const;
    7493
    75     QPolygonF toPointsF( const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    76         const QwtSeriesData<QPointF> *series, int from, int to ) const;
     94    QPolygonF toPointsF( const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     95        const QwtSeriesData< QPointF >* series, int from, int to ) const;
    7796
    78     QImage toImage( const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    79         const QwtSeriesData<QPointF> *series, int from, int to,
    80         const QPen &, bool antialiased, uint numThreads ) const;
     97    QImage toImage( const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     98        const QwtSeriesData< QPointF >* series, int from, int to,
     99        const QPen&, bool antialiased, uint numThreads ) const;
    81100
    82 private:
     101  private:
     102    Q_DISABLE_COPY(QwtPointMapper)
     103
    83104    class PrivateData;
    84     PrivateData *d_data;
     105    PrivateData* m_data;
    85106};
    86107
  • trunk/BNC/qwt/qwt_point_polar.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * QwtPolar Widget Library
    33 * Copyright (C) 2008   Uwe Rathmann
    … …  
    1010#include "qwt_math.h"
    1111
    12 #if QT_VERSION < 0x040601
    13 #define qAtan2(y, x) ::atan2(y, x)
     12#if QT_VERSION >= 0x050200
     13
     14static QwtPointPolar qwtPointToPolar( const QPointF& point )
     15{
     16    return QwtPointPolar( point );
     17}
     18
    1419#endif
     20
     21namespace
     22{
     23    static const struct RegisterQwtPointPolar
     24    {
     25        inline RegisterQwtPointPolar()
     26        {
     27            qRegisterMetaType< QwtPointPolar >();
     28
     29#if QT_VERSION >= 0x050200
     30            QMetaType::registerConverter< QPointF, QwtPointPolar >( qwtPointToPolar );
     31            QMetaType::registerConverter< QwtPointPolar, QPointF >( &QwtPointPolar::toPoint );
     32#endif
     33        }
     34
     35    } qwtRegisterQwtPointPolar;
     36}
    1537
    1638/*!
    … …  
    1941   \param p Point in Cartesian coordinates
    2042   \sa setPoint(), toPoint()
    21 */
    22 QwtPointPolar::QwtPointPolar( const QPointF &p )
     43 */
     44QwtPointPolar::QwtPointPolar( const QPointF& p )
    2345{
    24     d_radius = qSqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
    25     d_azimuth = qAtan2( p.y(), p.x() );
     46    m_radius = std::sqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
     47    m_azimuth = std::atan2( p.y(), p.x() );
    2648}
    2749
    … …  
    2951   Convert and assign values from a point in Cartesian coordinates
    3052   \param p Point in Cartesian coordinates
    31 */
    32 void QwtPointPolar::setPoint( const QPointF &p )
     53 */
     54void QwtPointPolar::setPoint( const QPointF& p )
    3355{
    34     d_radius = qSqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
    35     d_azimuth = qAtan2( p.y(), p.x() );
     56    m_radius = std::sqrt( qwtSqr( p.x() ) + qwtSqr( p.y() ) );
     57    m_azimuth = std::atan2( p.y(), p.x() );
    3658}
    3759
    … …  
    4365   \note Invalid or null points will be returned as QPointF(0.0, 0.0)
    4466   \sa isValid(), isNull()
    45 */
     67 */
    4668QPointF QwtPointPolar::toPoint() const
    4769{
    48     if ( d_radius <= 0.0 )
     70    if ( m_radius <= 0.0 )
    4971        return QPointF( 0.0, 0.0 );
    5072
    51     const double x = d_radius * qCos( d_azimuth );
    52     const double y = d_radius * qSin( d_azimuth );
     73    const double x = m_radius * std::cos( m_azimuth );
     74    const double y = m_radius * std::sin( m_azimuth );
    5375
    5476    return QPointF( x, y );
    … …  
    6587
    6688    \sa normalized()
    67 */
    68 bool QwtPointPolar::operator==( const QwtPointPolar &other ) const
     89 */
     90bool QwtPointPolar::operator==( const QwtPointPolar& other ) const
    6991{
    70     return d_radius == other.d_radius && d_azimuth == other.d_azimuth;
     92    return m_radius == other.m_radius && m_azimuth == other.m_azimuth;
    7193}
    7294
    … …  
    80102    \return True if the point is not equal to other; otherwise return false.
    81103    \sa normalized()
    82 */
    83 bool QwtPointPolar::operator!=( const QwtPointPolar &other ) const
     104 */
     105bool QwtPointPolar::operator!=( const QwtPointPolar& other ) const
    84106{
    85     return d_radius != other.d_radius || d_azimuth != other.d_azimuth;
     107    return m_radius != other.m_radius || m_azimuth != other.m_azimuth;
    86108}
    87109
    … …  
    93115
    94116   \return Normalized point
    95 */
     117 */
    96118QwtPointPolar QwtPointPolar::normalized() const
    97119{
    98     const double radius = qMax( d_radius, 0.0 );
     120    const double radius = qwtMaxF( m_radius, 0.0 );
    99121
    100     double azimuth = d_azimuth;
     122    double azimuth = m_azimuth;
    101123    if ( azimuth < -2.0 * M_PI || azimuth >= 2 * M_PI )
    102         azimuth = ::fmod( d_azimuth, 2 * M_PI );
     124        azimuth = std::fmod( m_azimuth, 2 * M_PI );
    103125
    104126    if ( azimuth < 0.0 )
    … …  
    110132#ifndef QT_NO_DEBUG_STREAM
    111133
    112 QDebug operator<<( QDebug debug, const QwtPointPolar &point )
     134#include <qdebug.h>
     135
     136QDebug operator<<( QDebug debug, const QwtPointPolar& point )
    113137{
    114138    debug.nospace() << "QwtPointPolar("
    115         << point.azimuth() << "," << point.radius() << ")";
     139                    << point.azimuth() << "," << point.radius() << ")";
    116140
    117141    return debug.space();
  • trunk/BNC/qwt/qwt_point_polar.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010/*! \file */
    11 #ifndef _QWT_POINT_POLAR_H_
    12 #define _QWT_POINT_POLAR_H_ 1
     11#ifndef QWT_POINT_POLAR_H
     12#define QWT_POINT_POLAR_H
    1313
    1414#include "qwt_global.h"
    1515#include "qwt_math.h"
     16
    1617#include <qpoint.h>
    17 #ifndef QT_NO_DEBUG_STREAM
    18 #include <qdebug.h>
    19 #endif
     18#include <qmetatype.h>
     19#include <qmath.h>
    2020
    2121/*!
    22   \brief A point in polar coordinates
     22   \brief A point in polar coordinates
    2323
    24   In polar coordinates a point is determined by an angle and a distance.
    25   See http://en.wikipedia.org/wiki/Polar_coordinate_system
    26 */
     24   In polar coordinates a point is determined by an angle and a distance.
     25   See http://en.wikipedia.org/wiki/Polar_coordinate_system
     26 */
    2727
    2828class QWT_EXPORT QwtPointPolar
    2929{
    30 public:
     30  public:
    3131    QwtPointPolar();
    3232    QwtPointPolar( double azimuth, double radius );
    33     QwtPointPolar( const QPointF & );
     33    QwtPointPolar( const QPointF& );
    3434
    35     void setPoint( const QPointF & );
     35    void setPoint( const QPointF& );
    3636    QPointF toPoint() const;
    3737
    … …  
    4242    double azimuth() const;
    4343
    44     double &rRadius();
    45     double &rAzimuth();
     44    double& rRadius();
     45    double& rAzimuth();
    4646
    4747    void setRadius( double );
    4848    void setAzimuth( double );
    4949
    50     bool operator==( const QwtPointPolar & ) const;
    51     bool operator!=( const QwtPointPolar & ) const;
     50    bool operator==( const QwtPointPolar& ) const;
     51    bool operator!=( const QwtPointPolar& ) const;
    5252
    5353    QwtPointPolar normalized() const;
    5454
    55     double _value; // Change by LM
     55  private:
     56    double m_azimuth;
     57    double m_radius;
     58};
    5659
    57 private:
    58     double d_azimuth;
    59     double d_radius;
    60 };
     60Q_DECLARE_TYPEINFO( QwtPointPolar, Q_MOVABLE_TYPE );
     61Q_DECLARE_METATYPE( QwtPointPolar )
     62
     63#ifndef QT_NO_DEBUG_STREAM
     64QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar& );
     65#endif
    6166
    6267/*!
    6368    Constructs a null point, with a radius and azimuth set to 0.0.
    6469    \sa QPointF::isNull()
    65 */
    66 inline QwtPointPolar::QwtPointPolar():
    67     d_azimuth( 0.0 ),
    68     d_radius( 0.0 )
     70 */
     71inline QwtPointPolar::QwtPointPolar()
     72    : m_azimuth( 0.0 )
     73    , m_radius( 0.0 )
    6974{
    7075}
    … …  
    7580   \param azimuth Azimuth
    7681   \param radius Radius
    77 */
    78 inline QwtPointPolar::QwtPointPolar( double azimuth, double radius ):
    79     d_azimuth( azimuth ),
    80     d_radius( radius )
     82 */
     83inline QwtPointPolar::QwtPointPolar( double azimuth, double radius )
     84    : m_azimuth( azimuth )
     85    , m_radius( radius )
    8186{
    8287}
    … …  
    8590inline bool QwtPointPolar::isValid() const
    8691{
    87     return d_radius >= 0.0;
     92    return m_radius >= 0.0;
    8893}
    8994
    … …  
    9196inline bool QwtPointPolar::isNull() const
    9297{
    93     return d_radius == 0.0;
     98    return m_radius == 0.0;
    9499}
    95100
    … …  
    97102inline double QwtPointPolar::radius() const
    98103{
    99     return d_radius;
     104    return m_radius;
    100105}
    101106
    … …  
    103108inline double QwtPointPolar::azimuth() const
    104109{
    105     return d_azimuth;
     110    return m_azimuth;
    106111}
    107112
    108113//! Returns the radius.
    109 inline double &QwtPointPolar::rRadius()
     114inline double& QwtPointPolar::rRadius()
    110115{
    111     return d_radius;
     116    return m_radius;
    112117}
    113118
    114119//! Returns the azimuth.
    115 inline double &QwtPointPolar::rAzimuth()
     120inline double& QwtPointPolar::rAzimuth()
    116121{
    117     return d_azimuth;
     122    return m_azimuth;
    118123}
    119124
    … …  
    121126inline void QwtPointPolar::setRadius( double radius )
    122127{
    123     d_radius = radius;
     128    m_radius = radius;
    124129}
    125130
    126 //! Sets the atimuth to atimuth.
     131//! Sets the azimuth to azimuth.
    127132inline void QwtPointPolar::setAzimuth( double azimuth )
    128133{
    129     d_azimuth = azimuth;
     134    m_azimuth = azimuth;
    130135}
    131136
    132 #ifndef QT_NO_DEBUG_STREAM
    133 QWT_EXPORT QDebug operator<<( QDebug, const QwtPointPolar & );
    134 #endif
    135 
    136 inline QPoint qwtPolar2Pos( const QPoint &pole,
     137inline QPoint qwtPolar2Pos( const QPoint& pole,
    137138    double radius, double angle )
    138139{
    139     const double x = pole.x() + radius * qCos( angle );
    140     const double y = pole.y() - radius * qSin( angle );
     140    const double x = pole.x() + radius * std::cos( angle );
     141    const double y = pole.y() - radius * std::sin( angle );
    141142
    142143    return QPoint( qRound( x ), qRound( y ) );
    143144}
    144145
    145 inline QPoint qwtDegree2Pos( const QPoint &pole,
     146inline QPoint qwtDegree2Pos( const QPoint& pole,
    146147    double radius, double angle )
    147148{
    … …  
    149150}
    150151
    151 inline QPointF qwtPolar2Pos( const QPointF &pole,
     152inline QPointF qwtPolar2Pos( const QPointF& pole,
    152153    double radius, double angle )
    153154{
    154     const double x = pole.x() + radius * qCos( angle );
    155     const double y = pole.y() - radius * qSin( angle );
     155    const double x = pole.x() + radius * std::cos( angle );
     156    const double y = pole.y() - radius * std::sin( angle );
    156157
    157158    return QPointF( x, y);
    158159}
    159160
    160 inline QPointF qwtDegree2Pos( const QPointF &pole,
     161inline QPointF qwtDegree2Pos( const QPointF& pole,
    161162    double radius, double angle )
    162163{
    … …  
    164165}
    165166
    166 inline QPointF qwtFastPolar2Pos( const QPointF &pole,
     167inline QPointF qwtFastPolar2Pos( const QPointF& pole,
    167168    double radius, double angle )
    168169{
    169 #if QT_VERSION < 0x040601
    170     const double x = pole.x() + radius * ::cos( angle );
    171     const double y = pole.y() - radius * ::sin( angle );
    172 #else
    173170    const double x = pole.x() + radius * qFastCos( angle );
    174171    const double y = pole.y() - radius * qFastSin( angle );
    175 #endif
    176172
    177173    return QPointF( x, y);
    178174}
    179175
    180 inline QPointF qwtFastDegree2Pos( const QPointF &pole,
     176inline QPointF qwtFastDegree2Pos( const QPointF& pole,
    181177    double radius, double angle )
    182178{
    … …  
    184180}
    185181
    186 inline QwtPointPolar qwtFastPos2Polar( const QPointF &pos )
     182inline QwtPointPolar qwtFastPos2Polar( const QPointF& pos )
    187183{
    188184    return QwtPointPolar( qwtFastAtan2( pos.y(), pos.x() ),
  • trunk/BNC/qwt/qwt_raster_data.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_raster_data.h"
    1111#include "qwt_point_3d.h"
     12#include "qwt_interval.h"
     13
     14#include <qrect.h>
     15#include <qpolygon.h>
    1216#include <qnumeric.h>
     17#include <qlist.h>
     18#include <qmap.h>
    1319
    1420class QwtRasterData::ContourPlane
    1521{
    16 public:
    17     inline ContourPlane( double z ):
    18         d_z( z )
     22  public:
     23    explicit inline ContourPlane( double z ):
     24        m_z( z )
    1925    {
    2026    }
    … …  
    2329        QPointF line[2], bool ignoreOnPlane ) const;
    2430
    25     inline double z() const { return d_z; }
    26 
    27 private:
     31    inline double z() const { return m_z; }
     32
     33  private:
    2834    inline int compare( double z ) const;
    2935    inline QPointF intersection(
    30         const QwtPoint3D& p1, const QwtPoint3D &p2 ) const;
    31 
    32     double d_z;
     36        const QwtPoint3D& p1, const QwtPoint3D& p2 ) const;
     37
     38    double m_z;
    3339};
    3440
    … …  
    6571    };
    6672
    67     const int edgeType = tab[eq1+1][eq2+1][eq3+1];
     73    const int edgeType = tab[eq1 + 1][eq2 + 1][eq3 + 1];
    6874    switch ( edgeType )
    6975    {
    … …  
    135141inline int QwtRasterData::ContourPlane::compare( double z ) const
    136142{
    137     if ( z > d_z )
     143    if ( z > m_z )
    138144        return 1;
    139145
    140     if ( z < d_z )
     146    if ( z < m_z )
    141147        return -1;
    142148
    … …  
    145151
    146152inline QPointF QwtRasterData::ContourPlane::intersection(
    147     const QwtPoint3D& p1, const QwtPoint3D &p2 ) const
    148 {
    149     const double h1 = p1.z() - d_z;
    150     const double h2 = p2.z() - d_z;
     153    const QwtPoint3D& p1, const QwtPoint3D& p2 ) const
     154{
     155    const double h1 = p1.z() - m_z;
     156    const double h2 = p2.z() - m_z;
    151157
    152158    const double x = ( h2 * p1.x() - h1 * p2.x() ) / ( h2 - h1 );
    … …  
    156162}
    157163
     164class QwtRasterData::PrivateData
     165{
     166  public:
     167    QwtRasterData::Attributes attributes;
     168};
     169
    158170//! Constructor
    159171QwtRasterData::QwtRasterData()
    160172{
     173    m_data = new PrivateData();
    161174}
    162175
    … …  
    164177QwtRasterData::~QwtRasterData()
    165178{
    166 }
    167 
    168 /*!
    169    Set the bounding interval for the x, y or z coordinates.
    170 
    171    \param axis Axis
    172    \param interval Bounding interval
    173 
    174    \sa interval()
    175 */
    176 void QwtRasterData::setInterval( Qt::Axis axis, const QwtInterval &interval )
    177 {
    178     d_intervals[axis] = interval;
    179 }
    180 
    181 /*!
    182   \brief Initialize a raster
    183 
    184   Before the composition of an image QwtPlotSpectrogram calls initRaster(),
    185   announcing the area and its resolution that will be requested.
    186 
    187   The default implementation does nothing, but for data sets that
    188   are stored in files, it might be good idea to reimplement initRaster(),
    189   where the data is resampled and loaded into memory.
    190 
    191   \param area Area of the raster
    192   \param raster Number of horizontal and vertical pixels
    193 
    194   \sa initRaster(), value()
    195 */
    196 void QwtRasterData::initRaster( const QRectF &area, const QSize &raster )
     179    delete m_data;
     180}
     181
     182/*!
     183   Specify an attribute of the data
     184
     185   \param attribute Attribute
     186   \param on On/Off
     187   /sa Attribute, testAttribute()
     188 */
     189void QwtRasterData::setAttribute( Attribute attribute, bool on )
     190{
     191    if ( on )
     192        m_data->attributes |= attribute;
     193    else
     194        m_data->attributes &= ~attribute;
     195}
     196
     197/*!
     198    \return True, when attribute is enabled
     199    \sa Attribute, setAttribute()
     200 */
     201bool QwtRasterData::testAttribute( Attribute attribute ) const
     202{
     203    return m_data->attributes & attribute;
     204}
     205
     206/*!
     207   \brief Initialize a raster
     208
     209   Before the composition of an image QwtPlotSpectrogram calls initRaster(),
     210   announcing the area and its resolution that will be requested.
     211
     212   The default implementation does nothing, but for data sets that
     213   are stored in files, it might be good idea to reimplement initRaster(),
     214   where the data is resampled and loaded into memory.
     215
     216   \param area Area of the raster
     217   \param raster Number of horizontal and vertical pixels
     218
     219   \sa initRaster(), value()
     220 */
     221void QwtRasterData::initRaster( const QRectF& area, const QSize& raster )
    197222{
    198223    Q_UNUSED( area );
    … …  
    201226
    202227/*!
    203   \brief Discard a raster
    204 
    205   After the composition of an image QwtPlotSpectrogram calls discardRaster().
    206 
    207   The default implementation does nothing, but if data has been loaded
    208   in initRaster(), it could deleted now.
    209 
    210   \sa initRaster(), value()
    211 */
     228   \brief Discard a raster
     229
     230   After the composition of an image QwtPlotSpectrogram calls discardRaster().
     231
     232   The default implementation does nothing, but if data has been loaded
     233   in initRaster(), it could deleted now.
     234
     235   \sa initRaster(), value()
     236 */
    212237void QwtRasterData::discardRaster()
    213238{
    … …  
    239264
    240265   \return Bounding rectangle of a pixel
    241 */
    242 QRectF QwtRasterData::pixelHint( const QRectF &area ) const
     266 */
     267QRectF QwtRasterData::pixelHint( const QRectF& area ) const
    243268{
    244269    Q_UNUSED( area );
    … …  
    258283   An adaption of CONREC, a simple contouring algorithm.
    259284   http://local.wasp.uwa.edu.au/~pbourke/papers/conrec/
    260 */
     285 */
    261286QwtRasterData::ContourLines QwtRasterData::contourLines(
    262     const QRectF &rect, const QSize &raster,
    263     const QList<double> &levels, ConrecFlags flags ) const
     287    const QRectF& rect, const QSize& raster,
     288    const QList< double >& levels, ConrecFlags flags ) const
    264289{
    265290    ContourLines contourLines;
    … …  
    279304        ignoreOutOfRange = flags & IgnoreOutOfRange;
    280305
    281     QwtRasterData *that = const_cast<QwtRasterData *>( this );
     306    QwtRasterData* that = const_cast< QwtRasterData* >( this );
    282307    that->initRaster( rect, raster );
    283 
    284 #if __GNUC__ >= 9
    285 #pragma GCC diagnostic push
    286 #pragma GCC diagnostic ignored "-Wdeprecated-copy"
    287 #endif
    288308
    289309    for ( int y = 0; y < raster.height() - 1; y++ )
    … …  
    313333                xy[TopRight].setZ(
    314334                    value( xy[TopRight].x(), xy[TopRight].y() )
    315                 );
     335                    );
    316336
    317337                xy[BottomRight].setX( pos.x() );
    … …  
    319339                xy[BottomRight].setZ(
    320340                    value( xy[BottomRight].x(), xy[BottomRight].y() )
    321                 );
     341                    );
    322342            }
    323343
    … …  
    332352            xy[TopRight].setZ(
    333353                value( xy[TopRight].x(), xy[TopRight].y() )
    334             );
     354                );
    335355            xy[BottomRight].setZ(
    336356                value( xy[BottomRight].x(), xy[BottomRight].y() )
    337             );
     357                );
    338358
    339359            double zMin = xy[TopLeft].z();
    … …  
    380400                if ( level < zMin || level > zMax )
    381401                    continue;
    382                 QPolygonF &lines = contourLines[level];
     402                QPolygonF& lines = contourLines[level];
    383403                const ContourPlane plane( level );
    384404
    … …  
    404424    }
    405425
    406 #if __GNUC__ >= 9
    407 #pragma GCC diagnostic pop
    408 #endif
    409 
    410426    that->discardRaster();
    411427
  • trunk/BNC/qwt/qwt_raster_data.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_RASTER_DATA_H
    11 #define QWT_RASTER_DATA_H 1
     11#define QWT_RASTER_DATA_H
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_interval.h"
    15 #include <qmap.h>
    16 #include <qlist.h>
    17 #include <qpolygon.h>
     14#include <qnamespace.h>
    1815
    19 class QwtScaleMap;
     16class QwtInterval;
     17class QPolygonF;
     18class QRectF;
     19class QSize;
     20template< typename T > class QList;
     21template< class Key, class T > class QMap;
    2022
    2123/*!
    22   \brief QwtRasterData defines an interface to any type of raster data.
     24   \brief QwtRasterData defines an interface to any type of raster data.
    2325
    24   QwtRasterData is an abstract interface, that is used by
    25   QwtPlotRasterItem to find the values at the pixels of its raster.
     26   QwtRasterData is an abstract interface, that is used by
     27   QwtPlotRasterItem to find the values at the pixels of its raster.
    2628
    27   Often a raster item is used to display values from a matrix. Then the
    28   derived raster data class needs to implement some sort of resampling,
    29   that maps the raster of the matrix into the requested raster of
    30   the raster item ( depending on resolution and scales of the canvas ).
    31 */
     29   Gaps inside the bounding rectangle of the data can be indicated by NaN
     30   values ( when WithoutGaps is disabled ).
     31
     32   Often a raster item is used to display values from a matrix. Then the
     33   derived raster data class needs to implement some sort of resampling,
     34   that maps the raster of the matrix into the requested raster of
     35   the raster item ( depending on resolution and scales of the canvas ).
     36
     37   QwtMatrixRasterData implements raster data, that returns values from
     38   a given 2D matrix.
     39
     40   \sa QwtMatrixRasterData
     41 */
    3242class QWT_EXPORT QwtRasterData
    3343{
    34 public:
     44  public:
    3545    //! Contour lines
    36     typedef QMap<double, QPolygonF> ContourLines;
     46    typedef QMap< double, QPolygonF > ContourLines;
     47
     48    /*!
     49       \brief Raster data attributes
     50
     51       Additional information that is used to improve processing
     52       of the data.
     53     */
     54    enum Attribute
     55    {
     56        /*!
     57           The bounding rectangle of the data is spanned by
     58           the interval(Qt::XAxis) and interval(Qt::YAxis).
     59
     60           WithoutGaps indicates, that the data has no gaps
     61           ( unknown values ) in this area and the result of
     62           value() does not need to be checked for NaN values.
     63
     64           Enabling this flag will have an positive effect on
     65           the performance of rendering a QwtPlotSpectrogram.
     66
     67           The default setting is false.
     68
     69           \note NaN values indicate an undefined value
     70         */
     71        WithoutGaps = 0x01
     72    };
     73
     74    Q_DECLARE_FLAGS( Attributes, Attribute )
    3775
    3876    //! Flags to modify the contour algorithm
    … …  
    4684    };
    4785
    48     //! Flags to modify the contour algorithm
    49     typedef QFlags<ConrecFlag> ConrecFlags;
     86    Q_DECLARE_FLAGS( ConrecFlags, ConrecFlag )
    5087
    5188    QwtRasterData();
    5289    virtual ~QwtRasterData();
    5390
    54     virtual void setInterval( Qt::Axis, const QwtInterval & );
    55     const QwtInterval &interval(Qt::Axis) const;
     91    void setAttribute( Attribute, bool on = true );
     92    bool testAttribute( Attribute ) const;
    5693
    57     virtual QRectF pixelHint( const QRectF & ) const;
     94    /*!
     95       \return Bounding interval for an axis
     96       \sa setInterval
     97     */
     98    virtual QwtInterval interval( Qt::Axis ) const = 0;
    5899
    59     virtual void initRaster( const QRectF &, const QSize& raster );
     100    virtual QRectF pixelHint( const QRectF& ) const;
     101
     102    virtual void initRaster( const QRectF&, const QSize& raster );
    60103    virtual void discardRaster();
    61104
    … …  
    64107       \param x X value in plot coordinates
    65108       \param y Y value in plot coordinates
    66     */
     109     */
    67110    virtual double value( double x, double y ) const = 0;
    68111
    69     virtual ContourLines contourLines( const QRectF &rect,
    70         const QSize &raster, const QList<double> &levels,
     112    virtual ContourLines contourLines( const QRectF& rect,
     113        const QSize& raster, const QList< double >& levels,
    71114        ConrecFlags ) const;
    72115
    … …  
    74117    class ContourPlane;
    75118
    76 private:
    77     // Disabled copy constructor and operator=
    78     QwtRasterData( const QwtRasterData & );
    79     QwtRasterData &operator=( const QwtRasterData & );
     119  private:
     120    Q_DISABLE_COPY(QwtRasterData)
    80121
    81     QwtInterval d_intervals[3];
     122    class PrivateData;
     123    PrivateData* m_data;
    82124};
    83125
    84 /*!
    85    \return Bounding interval for a axis
    86    \sa setInterval
    87 */
    88 inline const QwtInterval &QwtRasterData::interval( Qt::Axis axis) const
    89 {
    90     return d_intervals[axis];
    91 }
    92 
    93126Q_DECLARE_OPERATORS_FOR_FLAGS( QwtRasterData::ConrecFlags )
     127Q_DECLARE_OPERATORS_FOR_FLAGS( QwtRasterData::Attributes )
    94128
    95129#endif
  • trunk/BNC/qwt/qwt_round_scale_draw.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212#include "qwt_scale_div.h"
    1313#include "qwt_scale_map.h"
     14#include "qwt_text.h"
    1415#include "qwt_math.h"
    15 #include <qpen.h>
     16
    1617#include <qpainter.h>
    17 #include <qfontmetrics.h>
    18 #include <qmath.h>
    1918
    2019class QwtRoundScaleDraw::PrivateData
    2120{
    22 public:
    23     PrivateData():
    24         center( 50.0, 50.0 ),
    25         radius( 50.0 ),
    26         startAngle( -135.0 ),
    27         endAngle( 135.0 )
     21  public:
     22    PrivateData()
     23        : center( 50.0, 50.0 )
     24        , radius( 50.0 )
     25        , startAngle( -135.0 )
     26        , endAngle( 135.0 )
    2827    {
    2928    }
    … …  
    3736
    3837/*!
    39   \brief Constructor
    40 
    41   The range of the scale is initialized to [0, 100],
    42   The center is set to (50, 50) with a radius of 50.
    43   The angle range is set to [-135, 135].
    44 */
     38   \brief Constructor
     39
     40   The range of the scale is initialized to [0, 100],
     41   The center is set to (50, 50) with a radius of 50.
     42   The angle range is set to [-135, 135].
     43 */
    4544QwtRoundScaleDraw::QwtRoundScaleDraw()
    4645{
    47     d_data = new QwtRoundScaleDraw::PrivateData;
     46    m_data = new QwtRoundScaleDraw::PrivateData;
    4847
    4948    setRadius( 50 );
    50     scaleMap().setPaintInterval( d_data->startAngle, d_data->endAngle );
     49    scaleMap().setPaintInterval( m_data->startAngle, m_data->endAngle );
    5150}
    5251
    … …  
    5453QwtRoundScaleDraw::~QwtRoundScaleDraw()
    5554{
    56     delete d_data;
    57 }
    58 
    59 /*!
    60   Change of radius the scale
    61 
    62   Radius is the radius of the backbone without ticks and labels.
    63 
    64   \param radius New Radius
    65   \sa moveCenter()
    66 */
     55    delete m_data;
     56}
     57
     58/*!
     59   Change of radius the scale
     60
     61   Radius is the radius of the backbone without ticks and labels.
     62
     63   \param radius New Radius
     64   \sa moveCenter()
     65 */
    6766void QwtRoundScaleDraw::setRadius( double radius )
    6867{
    69     d_data->radius = radius;
    70 }
    71 
    72 /*!
    73   Get the radius
    74 
    75   Radius is the radius of the backbone without ticks and labels.
    76 
    77   \return Radius of the scale
    78   \sa setRadius(), extent()
    79 */
     68    m_data->radius = radius;
     69}
     70
     71/*!
     72   Get the radius
     73
     74   Radius is the radius of the backbone without ticks and labels.
     75
     76   \return Radius of the scale
     77   \sa setRadius(), extent()
     78 */
    8079double QwtRoundScaleDraw::radius() const
    8180{
    82     return d_data->radius;
     81    return m_data->radius;
    8382}
    8483
    … …  
    8887   \param center New center
    8988   \sa setRadius()
    90 */
    91 void QwtRoundScaleDraw::moveCenter( const QPointF &center )
    92 {
    93     d_data->center = center;
     89 */
     90void QwtRoundScaleDraw::moveCenter( const QPointF& center )
     91{
     92    m_data->center = center;
    9493}
    9594
    … …  
    9796QPointF QwtRoundScaleDraw::center() const
    9897{
    99     return d_data->center;
    100 }
    101 
    102 /*!
    103   \brief Adjust the baseline circle segment for round scales.
    104 
    105   The baseline will be drawn from min(angle1,angle2) to max(angle1, angle2).
    106   The default setting is [ -135, 135 ].
    107   An angle of 0 degrees corresponds to the 12 o'clock position,
    108   and positive angles count in a clockwise direction.
    109   \param angle1
    110   \param angle2 boundaries of the angle interval in degrees.
    111   \warning <ul>
    112   <li>The angle range is limited to [-360, 360] degrees. Angles exceeding
     98    return m_data->center;
     99}
     100
     101/*!
     102   \brief Adjust the baseline circle segment for round scales.
     103
     104   The baseline will be drawn from min(angle1,angle2) to max(angle1, angle2).
     105   The default setting is [ -135, 135 ].
     106   An angle of 0 degrees corresponds to the 12 o'clock position,
     107   and positive angles count in a clockwise direction.
     108   \param angle1
     109   \param angle2 boundaries of the angle interval in degrees.
     110   \warning <ul>
     111   <li>The angle range is limited to [-360, 360] degrees. Angles exceeding
    113112      this range will be clipped.
    114   <li>For angles more or equal than 360 degrees above or below min(angle1, angle2),
     113   <li>For angles more or equal than 360 degrees above or below min(angle1, angle2),
    115114      scale marks will not be drawn.
    116   <li>If you need a counterclockwise scale, use QwtScaleDiv::setInterval()
    117   </ul>
    118 */
     115   <li>If you need a counterclockwise scale, use QwtScaleDiv::setInterval()
     116   </ul>
     117 */
    119118void QwtRoundScaleDraw::setAngleRange( double angle1, double angle2 )
    120119{
    … …  
    124123#endif
    125124
    126     d_data->startAngle = angle1;
    127     d_data->endAngle = angle2;
    128 
    129     if ( d_data->startAngle == d_data->endAngle )
    130     {
    131         d_data->startAngle -= 1;
    132         d_data->endAngle += 1;
    133     }
    134 
    135     scaleMap().setPaintInterval( d_data->startAngle, d_data->endAngle );
     125    m_data->startAngle = angle1;
     126    m_data->endAngle = angle2;
     127
     128    if ( m_data->startAngle == m_data->endAngle )
     129    {
     130        m_data->startAngle -= 1;
     131        m_data->endAngle += 1;
     132    }
     133
     134    scaleMap().setPaintInterval( m_data->startAngle, m_data->endAngle );
    136135}
    137136
    … …  
    143142
    144143   \sa drawTick(), drawBackbone()
    145 */
    146 void QwtRoundScaleDraw::drawLabel( QPainter *painter, double value ) const
     144 */
     145void QwtRoundScaleDraw::drawLabel( QPainter* painter, double value ) const
    147146{
    148147    const double tval = scaleMap().transform( value );
    149     if ( ( tval >= d_data->startAngle + 360.0 )
    150         || ( tval <= d_data->startAngle - 360.0 ) )
     148    if ( ( tval >= m_data->startAngle + 360.0 )
     149        || ( tval <= m_data->startAngle - 360.0 ) )
    151150    {
    152151        return;
    … …  
    157156        return;
    158157
    159     double radius = d_data->radius;
     158    double radius = m_data->radius;
    160159    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ||
    161160        hasComponent( QwtAbstractScaleDraw::Backbone ) )
    … …  
    170169    const double arc = qwtRadians( tval );
    171170
    172     const double x = d_data->center.x() +
    173         ( radius + sz.width() / 2.0 ) * qSin( arc );
    174     const double y = d_data->center.y() -
    175         ( radius + sz.height() / 2.0 ) * qCos( arc );
     171    const double x = m_data->center.x() +
     172        ( radius + sz.width() / 2.0 ) * std::sin( arc );
     173    const double y = m_data->center.y() -
     174        ( radius + sz.height() / 2.0 ) * std::cos( arc );
    176175
    177176    const QRectF r( x - sz.width() / 2, y - sz.height() / 2,
    … …  
    188187
    189188   \sa drawBackbone(), drawLabel()
    190 */
    191 void QwtRoundScaleDraw::drawTick( QPainter *painter, double value, double len ) const
     189 */
     190void QwtRoundScaleDraw::drawTick( QPainter* painter, double value, double len ) const
    192191{
    193192    if ( len <= 0 )
    … …  
    196195    const double tval = scaleMap().transform( value );
    197196
    198     const double cx = d_data->center.x();
    199     const double cy = d_data->center.y();
    200     const double radius = d_data->radius;
    201 
    202     if ( ( tval < d_data->startAngle + 360.0 )
    203         && ( tval > d_data->startAngle - 360.0 ) )
     197    const double cx = m_data->center.x();
     198    const double cy = m_data->center.y();
     199    const double radius = m_data->radius;
     200
     201    if ( ( tval < m_data->startAngle + 360.0 )
     202        && ( tval > m_data->startAngle - 360.0 ) )
    204203    {
    205204        const double arc = qwtRadians( tval );
    206205
    207         const double sinArc = qSin( arc );
    208         const double cosArc = qCos( arc );
     206        const double sinArc = std::sin( arc );
     207        const double cosArc = std::cos( arc );
    209208
    210209        const double x1 = cx + radius * sinArc;
    … …  
    222221
    223222   \sa drawTick(), drawLabel()
    224 */
    225 void QwtRoundScaleDraw::drawBackbone( QPainter *painter ) const
     223 */
     224void QwtRoundScaleDraw::drawBackbone( QPainter* painter ) const
    226225{
    227226    const double deg1 = scaleMap().p1();
    228227    const double deg2 = scaleMap().p2();
    229228
    230     const int a1 = qRound( qMin( deg1, deg2 ) - 90 );
    231     const int a2 = qRound( qMax( deg1, deg2 ) - 90 );
    232 
    233     const double radius = d_data->radius;
    234     const double x = d_data->center.x() - radius;
    235     const double y = d_data->center.y() - radius;
     229    const int a1 = qRound( qwtMinF( deg1, deg2 ) - 90 );
     230    const int a2 = qRound( qwtMaxF( deg1, deg2 ) - 90 );
     231
     232    const double radius = m_data->radius;
     233    const double x = m_data->center.x() - radius;
     234    const double y = m_data->center.y() - radius;
    236235
    237236    painter->drawArc( QRectF( x, y, 2 * radius, 2 * radius ),
    … …  
    253252            calculates only an upper limit, that might be a
    254253            few pixels too large
    255 */
    256 double QwtRoundScaleDraw::extent( const QFont &font ) const
     254 */
     255double QwtRoundScaleDraw::extent( const QFont& font ) const
    257256{
    258257    double d = 0.0;
    … …  
    260259    if ( hasComponent( QwtAbstractScaleDraw::Labels ) )
    261260    {
    262         const QwtScaleDiv &sd = scaleDiv();
    263         const QList<double> &ticks = sd.ticks( QwtScaleDiv::MajorTick );
     261        const QwtScaleDiv& sd = scaleDiv();
     262        const QList< double >& ticks = sd.ticks( QwtScaleDiv::MajorTick );
    264263        for ( int i = 0; i < ticks.count(); i++ )
    265264        {
    … …  
    269268
    270269            const double tval = scaleMap().transform( value );
    271             if ( ( tval < d_data->startAngle + 360 )
    272                 && ( tval > d_data->startAngle - 360 ) )
     270            if ( ( tval < m_data->startAngle + 360 )
     271                && ( tval > m_data->startAngle - 360 ) )
    273272            {
    274273                const QwtText label = tickLabel( font, value );
    … …  
    281280                const double off = qMax( sz.width(), sz.height() );
    282281
    283                 double x = off * qSin( arc );
    284                 double y = off * qCos( arc );
    285 
    286                 const double dist = qSqrt( x * x + y * y );
     282                double x = off * std::sin( arc );
     283                double y = off * std::cos( arc );
     284
     285                const double dist = std::sqrt( x * x + y * y );
    287286                if ( dist > d )
    288287                    d = dist;
    … …  
    298297    if ( hasComponent( QwtAbstractScaleDraw::Backbone ) )
    299298    {
    300         const double pw = qMax( 1, penWidth() );  // pen width can be zero
    301         d += pw;
     299        d += qwtMaxF( penWidthF(), 1.0 );
    302300    }
    303301
    304302    if ( hasComponent( QwtAbstractScaleDraw::Labels ) &&
    305303        ( hasComponent( QwtAbstractScaleDraw::Ticks ) ||
    306             hasComponent( QwtAbstractScaleDraw::Backbone ) ) )
     304        hasComponent( QwtAbstractScaleDraw::Backbone ) ) )
    307305    {
    308306        d += spacing();
    309307    }
    310308
    311     d = qMax( d, minimumExtent() );
     309    d = qwtMaxF( d, minimumExtent() );
    312310
    313311    return d;
  • trunk/BNC/qwt/qwt_round_scale_draw.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_abstract_scale_draw.h"
     15
    1516#include <qpoint.h>
    1617
    1718/*!
    18   \brief A class for drawing round scales
     19   \brief A class for drawing round scales
    1920
    20   QwtRoundScaleDraw can be used to draw round scales.
    21   The circle segment can be adjusted by setAngleRange().
    22   The geometry of the scale can be specified with
    23   moveCenter() and setRadius().
     21   QwtRoundScaleDraw can be used to draw round scales.
     22   The circle segment can be adjusted by setAngleRange().
     23   The geometry of the scale can be specified with
     24   moveCenter() and setRadius().
    2425
    25   After a scale division has been specified as a QwtScaleDiv object
    26   using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s),
    27   the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
    28 */
     26   After a scale division has been specified as a QwtScaleDiv object
     27   using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s),
     28   the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
     29 */
    2930
    30 class QWT_EXPORT QwtRoundScaleDraw: public QwtAbstractScaleDraw
     31class QWT_EXPORT QwtRoundScaleDraw : public QwtAbstractScaleDraw
    3132{
    32 public:
     33  public:
    3334    QwtRoundScaleDraw();
    3435    virtual ~QwtRoundScaleDraw();
    … …  
    3839
    3940    void moveCenter( double x, double y );
    40     void moveCenter( const QPointF & );
     41    void moveCenter( const QPointF& );
    4142    QPointF center() const;
    4243
    4344    void setAngleRange( double angle1, double angle2 );
    4445
    45     virtual double extent( const QFont & ) const;
     46    virtual double extent( const QFont& ) const QWT_OVERRIDE;
    4647
    47 protected:
    48     virtual void drawTick( QPainter *, double value, double len ) const;
    49     virtual void drawBackbone( QPainter * ) const;
    50     virtual void drawLabel( QPainter *, double val ) const;
     48  protected:
     49    virtual void drawTick( QPainter*,
     50        double value, double len ) const QWT_OVERRIDE;
    5151
    52 private:
    53     QwtRoundScaleDraw( const QwtRoundScaleDraw & );
    54     QwtRoundScaleDraw &operator=( const QwtRoundScaleDraw &other );
     52    virtual void drawBackbone(
     53        QPainter* ) const QWT_OVERRIDE;
    5554
     55    virtual void drawLabel(
     56        QPainter*, double value ) const QWT_OVERRIDE;
     57
     58  private:
    5659    class PrivateData;
    57     PrivateData *d_data;
     60    PrivateData* m_data;
    5861};
    5962
  • trunk/BNC/qwt/qwt_samples.h

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_SAMPLES_H
    11 #define QWT_SAMPLES_H 1
     11#define QWT_SAMPLES_H
    1212
    1313#include "qwt_global.h"
    1414#include "qwt_interval.h"
     15
    1516#include <qvector.h>
    1617#include <qrect.h>
    … …  
    1920class QWT_EXPORT QwtIntervalSample
    2021{
    21 public:
     22  public:
    2223    QwtIntervalSample();
    23     QwtIntervalSample( double, const QwtInterval & );
     24    QwtIntervalSample( double, const QwtInterval& );
    2425    QwtIntervalSample( double value, double min, double max );
    2526
    26     bool operator==( const QwtIntervalSample & ) const;
    27     bool operator!=( const QwtIntervalSample & ) const;
     27    bool operator==( const QwtIntervalSample& ) const;
     28    bool operator!=( const QwtIntervalSample& ) const;
    2829
    2930    //! Value
    … …  
    3536
    3637/*!
    37   Constructor
    38   The value is set to 0.0, the interval is invalid
    39 */
    40 inline QwtIntervalSample::QwtIntervalSample():
    41     value( 0.0 )
     38   Constructor
     39   The value is set to 0.0, the interval is invalid
     40 */
     41inline QwtIntervalSample::QwtIntervalSample()
     42    : value( 0.0 )
    4243{
    4344}
    4445
    4546//! Constructor
    46 inline QwtIntervalSample::QwtIntervalSample(
    47         double v, const QwtInterval &intv ):
    48     value( v ),
    49     interval( intv )
     47inline QwtIntervalSample::QwtIntervalSample( double v, const QwtInterval& intv )
     48    : value( v )
     49    , interval( intv )
    5050{
    5151}
    5252
    5353//! Constructor
    54 inline QwtIntervalSample::QwtIntervalSample(
    55         double v, double min, double max ):
    56     value( v ),
    57     interval( min, max )
     54inline QwtIntervalSample::QwtIntervalSample( double v, double min, double max )
     55    : value( v )
     56    , interval( min, max )
    5857{
    5958}
    6059
    6160//! Compare operator
    62 inline bool QwtIntervalSample::operator==(
    63     const QwtIntervalSample &other ) const
     61inline bool QwtIntervalSample::operator==( const QwtIntervalSample& other ) const
    6462{
    6563    return value == other.value && interval == other.interval;
    … …  
    6765
    6866//! Compare operator
    69 inline bool QwtIntervalSample::operator!=(
    70     const QwtIntervalSample &other ) const
     67inline bool QwtIntervalSample::operator!=( const QwtIntervalSample& other ) const
    7168{
    7269    return !( *this == other );
    … …  
    7673class QWT_EXPORT QwtSetSample
    7774{
    78 public:
     75  public:
    7976    QwtSetSample();
    80     QwtSetSample( double, const QVector<double> & = QVector<double>() );
    81 
    82     bool operator==( const QwtSetSample &other ) const;
    83     bool operator!=( const QwtSetSample &other ) const;
     77    explicit QwtSetSample( double, const QVector< double >& = QVector< double >( ) );
     78
     79    bool operator==( const QwtSetSample& other ) const;
     80    bool operator!=( const QwtSetSample& other ) const;
    8481
    8582    double added() const;
    … …  
    8986
    9087    //! Vector of values associated to value
    91     QVector<double> set;
     88    QVector< double > set;
    9289};
    9390
    9491/*!
    95   Constructor
    96   The value is set to 0.0
    97 */
    98 inline QwtSetSample::QwtSetSample():
    99     value( 0.0 )
    100 {
    101 }
    102 
    103 /*!
    104   Constructor
    105 
    106   \param v Value
    107   \param s Set of values
    108 */
    109 inline QwtSetSample::QwtSetSample( double v, const QVector< double > &s ):
    110     value( v ),
    111     set( s )
     92   Constructor
     93   The value is set to 0.0
     94 */
     95inline QwtSetSample::QwtSetSample()
     96    : value( 0.0 )
     97{
     98}
     99
     100/*!
     101   Constructor
     102
     103   \param v Value
     104   \param s Set of values
     105 */
     106inline QwtSetSample::QwtSetSample( double v, const QVector< double >& s )
     107    : value( v )
     108    , set( s )
    112109{
    113110}
    114111
    115112//! Compare operator
    116 inline bool QwtSetSample::operator==( const QwtSetSample &other ) const
     113inline bool QwtSetSample::operator==( const QwtSetSample& other ) const
    117114{
    118115    return value == other.value && set == other.set;
    … …  
    120117
    121118//! Compare operator
    122 inline bool QwtSetSample::operator!=( const QwtSetSample &other ) const
     119inline bool QwtSetSample::operator!=( const QwtSetSample& other ) const
    123120{
    124121    return !( *this == other );
    … …  
    143140
    144141   \sa QwtTradingChartData
    145 */
     142 */
    146143class QWT_EXPORT QwtOHLCSample
    147144{
    148 public:
     145  public:
    149146    QwtOHLCSample( double time = 0.0,
    150147        double open = 0.0, double high = 0.0,
    … …  
    156153
    157154    /*!
    158       Time of the sample, usually a number representing
    159       a specific interval - like a day.
    160     */
     155       Time of the sample, usually a number representing
     156       a specific interval - like a day.
     157     */
    161158    double time;
    162159
    … …  
    174171};
    175172
    176 
    177 /*!
    178   Constructor
    179 
    180   \param t Time value
    181   \param o Open value
    182   \param h High value
    183   \param l Low value
    184   \param c Close value
    185 */
    186 inline QwtOHLCSample::QwtOHLCSample( double t,
    187         double o, double h, double l, double c ):
    188     time( t ),
    189     open( o ),
    190     high( h ),
    191     low( l ),
    192     close( c )
    193 {
    194 }
    195 
    196 /*!
    197   \brief Check if a sample is valid
    198 
    199   A sample is valid, when all of the following checks are true:
    200 
    201   - low <= high
    202   - low <= open <= high
    203   - low <= close <= high
    204 
    205   \return True, when the sample is valid
     173/*!
     174   Constructor
     175
     176   \param t Time value
     177   \param o Open value
     178   \param h High value
     179   \param l Low value
     180   \param c Close value
     181 */
     182inline QwtOHLCSample::QwtOHLCSample(
     183        double t, double o, double h, double l, double c )
     184    : time( t )
     185    , open( o )
     186    , high( h )
     187    , low( l )
     188    , close( c )
     189{
     190}
     191
     192/*!
     193   \brief Check if a sample is valid
     194
     195   A sample is valid, when all of the following checks are true:
     196
     197   - low <= high
     198   - low <= open <= high
     199   - low <= close <= high
     200
     201   \return True, when the sample is valid
    206202 */
    207203inline bool QwtOHLCSample::isValid() const
    208204{
    209205    return ( low <= high )
    210         && ( open >= low )
    211         && ( open <= high )
    212         && ( close >= low )
    213         && ( close <= high );
     206           && ( open >= low )
     207           && ( open <= high )
     208           && ( close >= low )
     209           && ( close <= high );
    214210}
    215211
    … …  
    237233}
    238234
     235/*!
     236   \brief Sample used in vector fields
     237
     238   A vector field sample is a position and a vector - usually
     239   representing some direction and magnitude - attached to this position.
     240
     241   \sa QwtVectorFieldData
     242 */
     243class QWT_EXPORT QwtVectorFieldSample
     244{
     245  public:
     246    QwtVectorFieldSample( double x = 0.0, double y = 0.0,
     247        double vx = 0.0, double vy = 0.0 );
     248
     249    QwtVectorFieldSample( const QPointF& pos,
     250        double vx = 0.0, double vy = 0.0 );
     251
     252    QPointF pos() const;
     253
     254    bool isNull() const;
     255
     256    //! x coordinate of the position
     257    double x;
     258
     259    //! y coordinate of the position
     260    double y;
     261
     262    //! x coordinate of the vector
     263    double vx;
     264
     265    //! y coordinate of the vector
     266    double vy;
     267};
     268
     269/*!
     270   \brief Constructor
     271
     272   \param posX x coordinate of the position
     273   \param posY y coordinate of the position
     274   \param vectorX x coordinate of the vector
     275   \param vectorY y coordinate of the vector
     276 */
     277inline QwtVectorFieldSample::QwtVectorFieldSample(
     278        double posX, double posY, double vectorX, double vectorY )
     279    : x( posX )
     280    , y( posY )
     281    , vx( vectorX )
     282    , vy( vectorY )
     283{
     284}
     285
     286/*!
     287   \brief Constructor
     288
     289   \param pos Position
     290   \param vectorX x coordinate of the vector
     291   \param vectorY y coordinate of the vector
     292 */
     293inline QwtVectorFieldSample::QwtVectorFieldSample(
     294        const QPointF& pos, double vectorX, double vectorY )
     295    : x( pos.x() )
     296    , y( pos.y() )
     297    , vx( vectorX )
     298    , vy( vectorY )
     299{
     300}
     301
     302//! \return x/y coordinates as QPointF
     303inline QPointF QwtVectorFieldSample::pos() const
     304{
     305    return QPointF( x, y );
     306}
     307
     308//! \return true, if vx and vy are 0
     309inline bool QwtVectorFieldSample::isNull() const
     310{
     311    return ( vx == 0.0 ) && ( vy == 0.0 );
     312}
     313
    239314#endif
  • trunk/BNC/qwt/qwt_sampling_thread.cpp

    r4271 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_sampling_thread.h"
    11 #include "qwt_system_clock.h"
     11#include <qelapsedtimer.h>
    1212
    1313class QwtSamplingThread::PrivateData
    1414{
    15 public:
    16     QwtSystemClock clock;
    17 
    18     double interval;
    19     bool isStopped;
     15  public:
     16    QElapsedTimer timer;
     17    double msecsInterval;
    2018};
    2119
    22 
    2320//! Constructor
    24 QwtSamplingThread::QwtSamplingThread( QObject *parent ):
    25     QThread( parent )
     21QwtSamplingThread::QwtSamplingThread( QObject* parent )
     22    : QThread( parent )
    2623{
    27     d_data = new PrivateData;
    28     d_data->interval = 1000; // 1 second
    29     d_data->isStopped = true;
     24    m_data = new PrivateData;
     25    m_data->msecsInterval = 1e3; // 1 second
    3026}
    3127
    … …  
    3329QwtSamplingThread::~QwtSamplingThread()
    3430{
    35     delete d_data;
     31    delete m_data;
    3632}
    3733
    … …  
    4036   The default interval is 1000.0 ( = 1s )
    4137
    42    \param interval Interval
     38   \param msecs Interval
    4339   \sa interval()
    44 */
    45 void QwtSamplingThread::setInterval( double interval )
     40 */
     41void QwtSamplingThread::setInterval( double msecs )
    4642{
    47     if ( interval < 0.0 )
    48         interval = 0.0;
     43    if ( msecs < 0.0 )
     44        msecs = 0.0;
    4945
    50     d_data->interval = interval;
     46    m_data->msecsInterval = msecs;
    5147}
    5248
    … …  
    5450   \return Interval (in ms), between 2 calls of sample()
    5551   \sa setInterval()
    56 */
     52 */
    5753double QwtSamplingThread::interval() const
    5854{
    59     return d_data->interval;
     55    return m_data->msecsInterval;
    6056}
    6157
    … …  
    6359   \return Time (in ms) since the thread was started
    6460   \sa QThread::start(), run()
    65 */
     61 */
    6662double QwtSamplingThread::elapsed() const
    6763{
    68     if ( d_data->isStopped )
    69         return 0.0;
     64    if ( m_data->timer.isValid() )
     65        return m_data->timer.nsecsElapsed() / 1e6;
    7066
    71     return d_data->clock.elapsed();
     67    return 0.0;
    7268}
    7369
    … …  
    7571   Terminate the collecting thread
    7672   \sa QThread::start(), run()
    77 */
     73 */
    7874void QwtSamplingThread::stop()
    7975{
    80     d_data->isStopped = true;
     76    m_data->timer.invalidate();
    8177}
    8278
    … …  
    8480   Loop collecting samples started from QThread::start()
    8581   \sa stop()
    86 */
     82 */
    8783void QwtSamplingThread::run()
    8884{
    89     d_data->clock.start();
    90     d_data->isStopped = false;
     85    m_data->timer.start();
    9186
    92     while ( !d_data->isStopped )
     87    /*
     88        We should have all values in nsecs/qint64, but
     89        this would break existing code. TODO ...
     90        Anyway - for QThread::usleep we even need microseconds( usecs )
     91     */
     92    while ( m_data->timer.isValid() )
    9393    {
    94         const double elapsed = d_data->clock.elapsed();
    95         sample( elapsed / 1000.0 );
     94        const qint64 timestamp = m_data->timer.nsecsElapsed();
     95        sample( timestamp / 1e9 ); // seconds
    9696
    97         if ( d_data->interval > 0.0 )
     97        if ( m_data->msecsInterval > 0.0 )
    9898        {
    99             const double msecs =
    100                 d_data->interval - ( d_data->clock.elapsed() - elapsed );
     99            const double interval = m_data->msecsInterval * 1e3;
     100            const double elapsed = ( m_data->timer.nsecsElapsed() - timestamp ) / 1e3;
    101101
    102             if ( msecs > 0.0 )
    103                 usleep( qRound( 1000.0 * msecs ) );
     102            const double usecs = interval - elapsed;
     103
     104            if ( usecs > 0.0 )
     105                QThread::usleep( qRound( usecs ) );
    104106        }
    105107    }
    106108}
     109
     110#include "moc_qwt_sampling_thread.cpp"
  • trunk/BNC/qwt/qwt_sampling_thread.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    88 *****************************************************************************/
    99
    10 #ifndef _QWT_SAMPLING_THREAD_H_
    11 #define _QWT_SAMPLING_THREAD_H_
     10#ifndef QWT_SAMPLING_THREAD_H
     11#define QWT_SAMPLING_THREAD_H
    1212
    1313#include "qwt_global.h"
    … …  
    1515
    1616/*!
    17   \brief A thread collecting samples at regular intervals.
     17   \brief A thread collecting samples at regular intervals.
    1818
    19   Continuous signals are converted into a discrete signal by
    20   collecting samples at regular intervals. A discrete signal
    21   can be displayed by a QwtPlotSeriesItem on a QwtPlot widget.
     19   Continuous signals are converted into a discrete signal by
     20   collecting samples at regular intervals. A discrete signal
     21   can be displayed by a QwtPlotSeriesItem on a QwtPlot widget.
    2222
    23   QwtSamplingThread starts a thread calling periodically sample(),
    24   to collect and store ( or emit ) a single sample.
     23   QwtSamplingThread starts a thread calling periodically sample(),
     24   to collect and store ( or emit ) a single sample.
    2525
    26   \sa QwtPlotCurve, QwtPlotSeriesItem
    27 */
    28 class QWT_EXPORT QwtSamplingThread: public QThread
     26   \sa QwtPlotCurve, QwtPlotSeriesItem
     27 */
     28class QWT_EXPORT QwtSamplingThread : public QThread
    2929{
    3030    Q_OBJECT
    3131
    32 public:
     32  public:
    3333    virtual ~QwtSamplingThread();
    3434
    … …  
    3636    double elapsed() const;
    3737
    38 public Q_SLOTS:
     38  public Q_SLOTS:
    3939    void setInterval( double interval );
    4040    void stop();
    4141
    42 protected:
    43     explicit QwtSamplingThread( QObject *parent = NULL );
     42  protected:
     43    explicit QwtSamplingThread( QObject* parent = NULL );
    4444
    45     virtual void run();
     45    virtual void run() QWT_OVERRIDE;
    4646
    4747    /*!
    4848       Collect a sample
    4949
    50        \param elapsed Time since the thread was started in milliseconds
     50       \param elapsed Time since the thread was started in seconds
     51       \note Due to a bug in previous version elapsed was passed as
     52             seconds instead of miliseconds. To avoid breaking existing
     53             code we stay with seconds for now.
    5154     */
    5255    virtual void sample( double elapsed ) = 0;
    5356
    54 private:
     57  private:
    5558    class PrivateData;
    56     PrivateData *d_data;
     59    PrivateData* m_data;
    5760};
    5861
  • trunk/BNC/qwt/qwt_scale_div.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_scale_div.h"
    11 #include "qwt_math.h"
    12 #include <qalgorithms.h>
    13 
    14 /*!
    15   Construct a division without ticks
    16 
    17   \param lowerBound First boundary
    18   \param upperBound Second boundary
    19 
    20   \note lowerBound might be greater than upperBound for inverted scales
    21  */
    22 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound ):
    23     d_lowerBound( lowerBound ),
    24     d_upperBound( upperBound )
    25 {
    26 }
    27 
    28 /*!
    29   Construct a scale division
    30 
    31   \param interval Interval
    32   \param ticks List of major, medium and minor ticks
    33 */
    34 QwtScaleDiv::QwtScaleDiv( const QwtInterval &interval,
    35         QList<double> ticks[NTickTypes] ):
    36     d_lowerBound( interval.minValue() ),
    37     d_upperBound( interval.maxValue() )
     11#include "qwt_interval.h"
     12
     13/*!
     14   Construct a division without ticks
     15
     16   \param lowerBound First boundary
     17   \param upperBound Second boundary
     18
     19   \note lowerBound might be greater than upperBound for inverted scales
     20 */
     21QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound )
     22    : m_lowerBound( lowerBound )
     23    , m_upperBound( upperBound )
     24{
     25}
     26
     27/*!
     28   Construct a scale division
     29
     30   \param interval Interval
     31   \param ticks List of major, medium and minor ticks
     32 */
     33QwtScaleDiv::QwtScaleDiv( const QwtInterval& interval,
     34        QList< double > ticks[NTickTypes] )
     35    : m_lowerBound( interval.minValue() )
     36    , m_upperBound( interval.maxValue() )
    3837{
    3938    for ( int i = 0; i < NTickTypes; i++ )
    40         d_ticks[i] = ticks[i];
    41 }
    42 
    43 /*!
    44   Construct a scale division
    45 
    46   \param lowerBound First boundary
    47   \param upperBound Second boundary
    48   \param ticks List of major, medium and minor ticks
    49 
    50   \note lowerBound might be greater than upperBound for inverted scales
    51 */
     39        m_ticks[i] = ticks[i];
     40}
     41
     42/*!
     43   Construct a scale division
     44
     45   \param lowerBound First boundary
     46   \param upperBound Second boundary
     47   \param ticks List of major, medium and minor ticks
     48
     49   \note lowerBound might be greater than upperBound for inverted scales
     50 */
    5251QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
    53         QList<double> ticks[NTickTypes] ):
    54     d_lowerBound( lowerBound ),
    55     d_upperBound( upperBound )
     52        QList< double > ticks[NTickTypes] )
     53    : m_lowerBound( lowerBound )
     54    , m_upperBound( upperBound )
    5655{
    5756    for ( int i = 0; i < NTickTypes; i++ )
    58         d_ticks[i] = ticks[i];
    59 }
    60 
    61 /*!
    62   Construct a scale division
    63 
    64   \param lowerBound First boundary
    65   \param upperBound Second boundary
    66   \param minorTicks List of minor ticks
    67   \param mediumTicks List medium ticks
    68   \param majorTicks List of major ticks
    69 
    70   \note lowerBound might be greater than upperBound for inverted scales
    71 */
     57        m_ticks[i] = ticks[i];
     58}
     59
     60/*!
     61   Construct a scale division
     62
     63   \param lowerBound First boundary
     64   \param upperBound Second boundary
     65   \param minorTicks List of minor ticks
     66   \param mediumTicks List medium ticks
     67   \param majorTicks List of major ticks
     68
     69   \note lowerBound might be greater than upperBound for inverted scales
     70 */
    7271QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
    73         const QList<double> &minorTicks,
    74         const QList<double> &mediumTicks,
    75         const QList<double> &majorTicks ):
    76     d_lowerBound( lowerBound ),
    77     d_upperBound( upperBound )
    78 {
    79     d_ticks[ MinorTick ] = minorTicks;
    80     d_ticks[ MediumTick ] = mediumTicks;
    81     d_ticks[ MajorTick ] = majorTicks;
    82 }
    83 
    84 /*!
    85   Change the interval
    86 
    87   \param lowerBound First boundary
    88   \param upperBound Second boundary
    89 
    90   \note lowerBound might be greater than upperBound for inverted scales
    91 */
     72        const QList< double >& minorTicks,
     73        const QList< double >& mediumTicks,
     74        const QList< double >& majorTicks )
     75    : m_lowerBound( lowerBound )
     76    , m_upperBound( upperBound )
     77{
     78    m_ticks[ MinorTick ] = minorTicks;
     79    m_ticks[ MediumTick ] = mediumTicks;
     80    m_ticks[ MajorTick ] = majorTicks;
     81}
     82
     83/*!
     84   Change the interval
     85
     86   \param lowerBound First boundary
     87   \param upperBound Second boundary
     88
     89   \note lowerBound might be greater than upperBound for inverted scales
     90 */
    9291void QwtScaleDiv::setInterval( double lowerBound, double upperBound )
    9392{
    94     d_lowerBound = lowerBound;
    95     d_upperBound = upperBound;
     93    m_lowerBound = lowerBound;
     94    m_upperBound = upperBound;
    9695}
    9796
    … …  
    10099
    101100   \param interval Interval
    102 */
    103 void QwtScaleDiv::setInterval( const QwtInterval &interval )
    104 {
    105     d_lowerBound = interval.minValue();
    106     d_upperBound = interval.maxValue();
    107 }
    108 
    109 /*!
    110   \return lowerBound -> upperBound
    111 */
     101 */
     102void QwtScaleDiv::setInterval( const QwtInterval& interval )
     103{
     104    m_lowerBound = interval.minValue();
     105    m_upperBound = interval.maxValue();
     106}
     107
     108/*!
     109   \return lowerBound -> upperBound
     110 */
    112111QwtInterval QwtScaleDiv::interval() const
    113112{
    114     return QwtInterval( d_lowerBound, d_upperBound );
    115 }
    116 
    117 /*!
    118   Set the first boundary
    119 
    120   \param lowerBound First boundary
    121   \sa lowerBiound(), setUpperBound()
     113    return QwtInterval( m_lowerBound, m_upperBound );
     114}
     115
     116/*!
     117   Set the first boundary
     118
     119   \param lowerBound First boundary
     120   \sa lowerBound(), setUpperBound()
    122121 */
    123122void QwtScaleDiv::setLowerBound( double lowerBound  )
    124123{
    125     d_lowerBound = lowerBound;
    126 }
    127 
    128 /*!
    129   \return First boundary
    130   \sa upperBound()
    131 */
     124    m_lowerBound = lowerBound;
     125}
     126
     127/*!
     128   \return First boundary
     129   \sa upperBound()
     130 */
    132131double QwtScaleDiv::lowerBound() const
    133132{
    134     return d_lowerBound;
    135 }
    136 
    137 /*!
    138   Set the second boundary
    139 
    140   \param upperBound Second boundary
    141   \sa upperBound(), setLowerBound()
     133    return m_lowerBound;
     134}
     135
     136/*!
     137   Set the second boundary
     138
     139   \param upperBound Second boundary
     140   \sa upperBound(), setLowerBound()
    142141 */
    143142void QwtScaleDiv::setUpperBound( double upperBound  )
    144143{
    145     d_upperBound = upperBound;
    146 }
    147 
    148 /*!
    149   \return upper bound
    150   \sa lowerBound()
    151 */
     144    m_upperBound = upperBound;
     145}
     146
     147/*!
     148   \return upper bound
     149   \sa lowerBound()
     150 */
    152151double QwtScaleDiv::upperBound() const
    153152{
    154     return d_upperBound;
    155 }
    156 
    157 /*!
    158   \return upperBound() - lowerBound()
    159 */
     153    return m_upperBound;
     154}
     155
     156/*!
     157   \return upperBound() - lowerBound()
     158 */
    160159double QwtScaleDiv::range() const
    161160{
    162     return d_upperBound - d_lowerBound;
    163 }
    164 
    165 /*!
    166   \brief Equality operator
    167   \return true if this instance is equal to other
    168 */
    169 bool QwtScaleDiv::operator==( const QwtScaleDiv &other ) const
    170 {
    171     if ( d_lowerBound != other.d_lowerBound ||
    172         d_upperBound != other.d_upperBound )
     161    return m_upperBound - m_lowerBound;
     162}
     163
     164/*!
     165   \brief Equality operator
     166   \return true if this instance is equal to other
     167 */
     168bool QwtScaleDiv::operator==( const QwtScaleDiv& other ) const
     169{
     170    if ( m_lowerBound != other.m_lowerBound ||
     171        m_upperBound != other.m_upperBound )
    173172    {
    174173        return false;
    … …  
    177176    for ( int i = 0; i < NTickTypes; i++ )
    178177    {
    179         if ( d_ticks[i] != other.d_ticks[i] )
     178        if ( m_ticks[i] != other.m_ticks[i] )
    180179            return false;
    181180    }
    … …  
    185184
    186185/*!
    187   \brief Inequality
    188   \return true if this instance is not equal to other
    189 */
    190 bool QwtScaleDiv::operator!=( const QwtScaleDiv &other ) const
     186   \brief Inequality
     187   \return true if this instance is not equal to other
     188 */
     189bool QwtScaleDiv::operator!=( const QwtScaleDiv& other ) const
    191190{
    192191    return ( !( *this == other ) );
    … …  
    196195bool QwtScaleDiv::isEmpty() const
    197196{
    198     return ( d_lowerBound == d_upperBound );
     197    return ( m_lowerBound == m_upperBound );
    199198}
    200199
    … …  
    202201bool QwtScaleDiv::isIncreasing() const
    203202{
    204     return d_lowerBound <= d_upperBound;
    205 }
    206 
    207 /*!
    208   Return if a value is between lowerBound() and upperBound()
    209 
    210   \param value Value
    211   \return true/false
    212 */
     203    return m_lowerBound <= m_upperBound;
     204}
     205
     206/*!
     207   Return if a value is between lowerBound() and upperBound()
     208
     209   \param value Value
     210   \return true/false
     211 */
    213212bool QwtScaleDiv::contains( double value ) const
    214213{
    215     const double min = qMin( d_lowerBound, d_upperBound );
    216     const double max = qMax( d_lowerBound, d_upperBound );
     214    const double min = qMin( m_lowerBound, m_upperBound );
     215    const double max = qMax( m_lowerBound, m_upperBound );
    217216
    218217    return value >= min && value <= max;
    … …  
    225224void QwtScaleDiv::invert()
    226225{
    227     qSwap( d_lowerBound, d_upperBound );
     226    qSwap( m_lowerBound, m_upperBound );
    228227
    229228    for ( int i = 0; i < NTickTypes; i++ )
    230229    {
    231         QList<double>& ticks = d_ticks[i];
     230        QList< double >& ticks = m_ticks[i];
    232231
    233232        const int size = ticks.count();
    … …  
    240239
    241240/*!
    242   \return A scale division with inverted boundaries and ticks
    243   \sa invert()
     241   \return A scale division with inverted boundaries and ticks
     242   \sa invert()
    244243 */
    245244QwtScaleDiv QwtScaleDiv::inverted() const
    … …  
    261260
    262261   \note lowerBound might be greater than upperBound for inverted scales
    263 */
     262 */
    264263QwtScaleDiv QwtScaleDiv::bounded(
    265264    double lowerBound, double upperBound ) const
    … …  
    273272    for ( int tickType = 0; tickType < QwtScaleDiv::NTickTypes; tickType++ )
    274273    {
    275         const QList<double> &ticks = d_ticks[ tickType ];
    276 
    277         QList<double> boundedTicks;
     274        const QList< double >& ticks = m_ticks[ tickType ];
     275
     276        QList< double > boundedTicks;
    278277        for ( int i = 0; i < ticks.size(); i++ )
    279278        {
    … …  
    293292    Assign ticks
    294293
    295    \param type MinorTick, MediumTick or MajorTick
     294   \param tickType MinorTick, MediumTick or MajorTick
    296295   \param ticks Values of the tick positions
    297 */
    298 void QwtScaleDiv::setTicks( int type, const QList<double> &ticks )
    299 {
    300     if ( type >= 0 && type < NTickTypes )
    301         d_ticks[type] = ticks;
     296 */
     297void QwtScaleDiv::setTicks( int tickType, const QList< double >& ticks )
     298{
     299    if ( tickType >= 0 && tickType < NTickTypes )
     300        m_ticks[tickType] = ticks;
    302301}
    303302
    … …  
    305304   Return a list of ticks
    306305
    307    \param type MinorTick, MediumTick or MajorTick
     306   \param tickType MinorTick, MediumTick or MajorTick
    308307   \return Tick list
    309 */
    310 QList<double> QwtScaleDiv::ticks( int type ) const
    311 {
    312     if ( type >= 0 && type < NTickTypes )
    313         return d_ticks[type];
    314 
    315     return QList<double>();
     308 */
     309QList< double > QwtScaleDiv::ticks( int tickType ) const
     310{
     311    if ( tickType >= 0 && tickType < NTickTypes )
     312        return m_ticks[tickType];
     313
     314    return QList< double >();
    316315}
    317316
    318317#ifndef QT_NO_DEBUG_STREAM
    319318
    320 QDebug operator<<( QDebug debug, const QwtScaleDiv &scaleDiv )
     319#include <qdebug.h>
     320
     321QDebug operator<<( QDebug debug, const QwtScaleDiv& scaleDiv )
    321322{
    322323    debug << scaleDiv.lowerBound() << "<->" << scaleDiv.upperBound();
  • trunk/BNC/qwt/qwt_scale_div.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include "qwt_interval.h"
    1514#include <qlist.h>
    1615
    17 #ifndef QT_NO_DEBUG_STREAM
    18 #include <qdebug.h>
    19 #endif
     16class QwtInterval;
    2017
    2118/*!
    22   \brief A class representing a scale division
     19   \brief A class representing a scale division
    2320
    24   A Qwt scale is defined by its boundaries and 3 list
    25   for the positions of the major, medium and minor ticks.
     21   A Qwt scale is defined by its boundaries and 3 list
     22   for the positions of the major, medium and minor ticks.
    2623
    27   The upperBound() might be smaller than the lowerBound()
    28   to indicate inverted scales.
     24   The upperBound() might be smaller than the lowerBound()
     25   to indicate inverted scales.
    2926
    30   Scale divisions can be calculated from a QwtScaleEngine.
     27   Scale divisions can be calculated from a QwtScaleEngine.
    3128
    32   \sa QwtScaleEngine::divideScale(), QwtPlot::setAxisScaleDiv(),
     29   \sa QwtScaleEngine::divideScale(), QwtPlot::setAxisScaleDiv(),
    3330      QwtAbstractSlider::setScaleDiv()
    34 */
     31 */
    3532
    3633class QWT_EXPORT QwtScaleDiv
    3734{
    38 public:
     35  public:
    3936    //! Scale tick types
    4037    enum TickType
    … …  
    5956        double upperBound = 0.0 );
    6057
    61     explicit QwtScaleDiv( const QwtInterval &, QList<double>[NTickTypes] );
     58    explicit QwtScaleDiv( const QwtInterval&, QList< double >[NTickTypes] );
    6259
    6360    explicit QwtScaleDiv( double lowerBound, double upperBound,
    64         QList<double>[NTickTypes] );
     61        QList< double >[NTickTypes] );
    6562
    6663    explicit QwtScaleDiv( double lowerBound, double upperBound,
    67         const QList<double> &minorTicks, const QList<double> &mediumTicks,
    68         const QList<double> &majorTicks );
     64        const QList< double >& minorTicks, const QList< double >& mediumTicks,
     65        const QList< double >& majorTicks );
    6966
    70     bool operator==( const QwtScaleDiv & ) const;
    71     bool operator!=( const QwtScaleDiv & ) const;
     67    bool operator==( const QwtScaleDiv& ) const;
     68    bool operator!=( const QwtScaleDiv& ) const;
    7269
    7370    void setInterval( double lowerBound, double upperBound );
    74     void setInterval( const QwtInterval & );
     71    void setInterval( const QwtInterval& );
    7572    QwtInterval interval() const;
    7673
    … …  
    8582    bool contains( double value ) const;
    8683
    87     void setTicks( int tickType, const QList<double> & );
    88     QList<double> ticks( int tickType ) const;
     84    void setTicks( int tickType, const QList< double >& );
     85    QList< double > ticks( int tickType ) const;
    8986
    9087    bool isEmpty() const;
    … …  
    9693    QwtScaleDiv bounded( double lowerBound, double upperBound ) const;
    9794
    98 private:
    99     double d_lowerBound;
    100     double d_upperBound;
    101     QList<double> d_ticks[NTickTypes];
     95  private:
     96    double m_lowerBound;
     97    double m_upperBound;
     98    QList< double > m_ticks[NTickTypes];
    10299};
    103100
    … …  
    105102
    106103#ifndef QT_NO_DEBUG_STREAM
    107 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleDiv & );
     104QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleDiv& );
    108105#endif
    109106
  • trunk/BNC/qwt/qwt_scale_draw.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_math.h"
    1414#include "qwt_painter.h"
    15 #include <qpen.h>
     15#include "qwt_text.h"
     16
    1617#include <qpainter.h>
     18#include <qpaintengine.h>
    1719#include <qmath.h>
    1820
    19 #if QT_VERSION < 0x040601
    20 #define qFastSin(x) qSin(x)
    21 #define qFastCos(x) qCos(x)
     21static inline double qwtEffectivePenWidth( const QwtAbstractScaleDraw* scaleDraw )
     22{
     23    return qwtMaxF( scaleDraw->penWidthF(), 1.0 );
     24}
     25
     26namespace QwtScaleRendererReal
     27{
     28    inline qreal penWidth( const QPainter* painter, const QwtScaleDraw* scaleDraw )
     29    {
     30        qreal width = scaleDraw->penWidthF();
     31#if 1
     32        if ( width <= 0.0 )
     33            width = 1.0;
    2234#endif
    2335
     36        if ( painter->pen().isCosmetic() )
     37        {
     38            const QTransform& transform = painter->transform();
     39
     40            switch ( scaleDraw->alignment() )
     41            {
     42                case QwtScaleDraw::LeftScale:
     43                case QwtScaleDraw::RightScale:
     44                {
     45                    width /= transform.m11();
     46                    break;
     47                }
     48                case QwtScaleDraw::TopScale:
     49                case QwtScaleDraw::BottomScale:
     50                {
     51                    width /= transform.m22();
     52                    break;
     53                }
     54            }
     55        }
     56
     57        return width;
     58    }
     59
     60    inline void drawBackbone( QPainter* painter, const QwtScaleDraw* scaleDraw )
     61    {
     62        const qreal pw2 = 0.5 * penWidth( painter, scaleDraw );
     63
     64        const QPointF pos = scaleDraw->pos();
     65        const qreal length = scaleDraw->length();
     66
     67        switch ( scaleDraw->alignment() )
     68        {
     69            case QwtScaleDraw::LeftScale:
     70            {
     71                const qreal x = pos.x() + 1.0 - pw2;
     72                QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length );
     73
     74                break;
     75            }
     76            case QwtScaleDraw::RightScale:
     77            {
     78                const qreal x = pos.x() - 1.0 + pw2;
     79                QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length );
     80
     81                break;
     82            }
     83            case QwtScaleDraw::TopScale:
     84            {
     85                const qreal y = pos.y() + 1.0 - pw2;
     86                QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y );
     87
     88                break;
     89            }
     90            case QwtScaleDraw::BottomScale:
     91            {
     92                const qreal y = pos.y() - 1.0 + pw2;
     93                QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y );
     94
     95                break;
     96            }
     97        }
     98    }
     99
     100    inline void drawTick( QPainter* painter,
     101        const QwtScaleDraw* scaleDraw, qreal tickPos, qreal tickLength )
     102    {
     103        const QPointF pos = scaleDraw->pos();
     104
     105        qreal pw = 0.0;
     106
     107        if ( scaleDraw->hasComponent( QwtScaleDraw::Backbone ) )
     108            pw = penWidth( painter, scaleDraw );
     109
     110        const qreal length = tickLength + pw;
     111
     112        /*
     113            Those correction offsets have been found by try and error.
     114            They need to be understood and replaced by a calculation,
     115            that makes sense. TODO ...
     116         */
     117        const qreal off1 = 1.0;
     118        const qreal off2 = ( scaleDraw->penWidthF() <= 0.0 ) ? 0.5 : 0.0;
     119
     120        switch ( scaleDraw->alignment() )
     121        {
     122            case QwtScaleDraw::LeftScale:
     123            {
     124                const qreal x = pos.x() + off1 - off2;
     125                QwtPainter::drawLine( painter, x, tickPos, x - length, tickPos );
     126
     127                break;
     128            }
     129            case QwtScaleDraw::RightScale:
     130            {
     131                const qreal x = pos.x() - off1 + off2;
     132                QwtPainter::drawLine( painter, x, tickPos, x + length, tickPos );
     133                break;
     134            }
     135            case QwtScaleDraw::TopScale:
     136            {
     137                const qreal y = pos.y() + off1 - 2 * off2;
     138                QwtPainter::drawLine( painter, tickPos, y, tickPos, y - length );
     139
     140                break;
     141            }
     142            case QwtScaleDraw::BottomScale:
     143            {
     144                const qreal y = pos.y() - off1 + off2;
     145                QwtPainter::drawLine( painter, tickPos, y, tickPos, y + length );
     146
     147                break;
     148            }
     149        }
     150    }
     151}
     152
     153namespace QwtScaleRendererInt
     154{
     155    inline void drawBackbone( QPainter* painter, const QwtScaleDraw* scaleDraw )
     156    {
     157        const int pw = qMax( qRound( scaleDraw->penWidthF() ), 1 );
     158
     159        const qreal length = scaleDraw->length();
     160        const QPointF pos = scaleDraw->pos();
     161
     162        switch ( scaleDraw->alignment() )
     163        {
     164            case QwtScaleDraw::LeftScale:
     165            {
     166                const qreal x = qRound( pos.x() - ( pw - 1 ) / 2 );
     167                QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length );
     168
     169                break;
     170            }
     171            case QwtScaleDraw::RightScale:
     172            {
     173                const qreal x = qRound( pos.x() + pw / 2 );
     174                QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + length );
     175
     176                break;
     177            }
     178            case QwtScaleDraw::TopScale:
     179            {
     180                const qreal y = qRound( pos.y() - ( pw - 1 ) / 2 );
     181                QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y );
     182
     183                break;
     184            }
     185            case QwtScaleDraw::BottomScale:
     186            {
     187                const qreal y = qRound( pos.y() + pw / 2 );
     188                QwtPainter::drawLine( painter, pos.x(), y, pos.x() + length, y );
     189
     190                break;
     191            }
     192        }
     193    }
     194
     195    inline void drawTick( QPainter* painter,
     196        const QwtScaleDraw* scaleDraw, qreal tickPos, qreal tickLength )
     197    {
     198        const QPointF pos = scaleDraw->pos();
     199        tickPos = qRound( tickPos );
     200
     201        int pw = 0;
     202        if ( scaleDraw->hasComponent( QwtScaleDraw::Backbone ) )
     203            pw = qMax( qRound( scaleDraw->penWidthF() ), 1 );
     204
     205        int len = qMax( qRound( tickLength ), 1 );
     206
     207        // the width of ticks at the borders might extent the backbone
     208        len += pw;
     209
     210        if ( painter->pen().capStyle() == Qt::FlatCap )
     211            len++; // the end point is not rendered
     212
     213        qreal off = 0.0;
     214
     215        if ( painter->paintEngine()->type() == QPaintEngine::X11 )
     216        {
     217            if ( pw == 1 )
     218            {
     219                // In opposite to raster, X11 paints the end point
     220                off = 1.0;
     221            }
     222        }
     223
     224        switch ( scaleDraw->alignment() )
     225        {
     226            case QwtScaleDraw::LeftScale:
     227            {
     228                const qreal x1 = qRound( pos.x() ) + 1;
     229                const qreal x2 = x1 - len + 1;
     230
     231                QwtPainter::drawLine( painter, x2, tickPos, x1 - off, tickPos );
     232
     233                break;
     234            }
     235            case QwtScaleDraw::RightScale:
     236            {
     237                const qreal x1 = qRound( pos.x() );
     238                const qreal x2 = x1 + len - 1;
     239
     240                QwtPainter::drawLine( painter, x1, tickPos, x2 - off, tickPos );
     241
     242                break;
     243            }
     244            case QwtScaleDraw::BottomScale:
     245            {
     246                const qreal y1 = qRound( pos.y() );
     247                const qreal y2 = y1 + len - 1;
     248
     249                QwtPainter::drawLine( painter, tickPos, y1, tickPos, y2 - off );
     250
     251                break;
     252            }
     253            case QwtScaleDraw::TopScale:
     254            {
     255                const qreal y1 = qRound( pos.y() );
     256                const qreal y2 = y1 - len + 1;
     257
     258                QwtPainter::drawLine( painter, tickPos, y2 + 1, tickPos, y1 + 1 - off );
     259
     260                break;
     261            }
     262        }
     263    }
     264}
     265
    24266class QwtScaleDraw::PrivateData
    25267{
    26 public:
    27     PrivateData():
    28         len( 0 ),
    29         alignment( QwtScaleDraw::BottomScale ),
    30         labelAlignment( 0 ),
    31         labelRotation( 0.0 )
     268  public:
     269    PrivateData()
     270        : len( 0 )
     271        , alignment( QwtScaleDraw::BottomScale )
     272        , labelRotation( 0.0 )
    32273    {
    33274    }
    … …  
    43284
    44285/*!
    45   \brief Constructor
    46 
    47   The range of the scale is initialized to [0, 100],
    48   The position is at (0, 0) with a length of 100.
    49   The orientation is QwtAbstractScaleDraw::Bottom.
    50 */
     286   \brief Constructor
     287
     288   The range of the scale is initialized to [0, 100],
     289   The position is at (0, 0) with a length of 100.
     290   The orientation is QwtAbstractScaleDraw::Bottom.
     291 */
    51292QwtScaleDraw::QwtScaleDraw()
    52293{
    53     d_data = new QwtScaleDraw::PrivateData;
     294    m_data = new QwtScaleDraw::PrivateData;
    54295    setLength( 100 );
    55296}
    … …  
    58299QwtScaleDraw::~QwtScaleDraw()
    59300{
    60     delete d_data;
     301    delete m_data;
    61302}
    62303
    … …  
    65306   \sa setAlignment()
    66307   \return Alignment of the scale
    67 */
     308 */
    68309QwtScaleDraw::Alignment QwtScaleDraw::alignment() const
    69310{
    70     return d_data->alignment;
     311    return m_data->alignment;
    71312}
    72313
    … …  
    78319   The default alignment is QwtScaleDraw::BottomScale
    79320   \sa alignment()
    80 */
     321 */
    81322void QwtScaleDraw::setAlignment( Alignment align )
    82323{
    83     d_data->alignment = align;
    84 }
    85 
    86 /*!
    87   Return the orientation
    88 
    89   TopScale, BottomScale are horizontal (Qt::Horizontal) scales,
    90   LeftScale, RightScale are vertical (Qt::Vertical) scales.
    91 
    92   \return Orientation of the scale
    93 
    94   \sa alignment()
    95 */
     324    m_data->alignment = align;
     325}
     326
     327/*!
     328   Return the orientation
     329
     330   TopScale, BottomScale are horizontal (Qt::Horizontal) scales,
     331   LeftScale, RightScale are vertical (Qt::Vertical) scales.
     332
     333   \return Orientation of the scale
     334
     335   \sa alignment()
     336 */
    96337Qt::Orientation QwtScaleDraw::orientation() const
    97338{
    98     switch ( d_data->alignment )
     339    switch ( m_data->alignment )
    99340    {
    100341        case TopScale:
    … …  
    109350
    110351/*!
    111   \brief Determine the minimum border distance
    112 
    113   This member function returns the minimum space
    114   needed to draw the mark labels at the scale's endpoints.
    115 
    116   \param font Font
    117   \param start Start border distance
    118   \param end End border distance
    119 */
     352   \brief Determine the minimum border distance
     353
     354   This member function returns the minimum space
     355   needed to draw the mark labels at the scale's endpoints.
     356
     357   \param font Font
     358   \param start Start border distance
     359   \param end End border distance
     360 */
    120361void QwtScaleDraw::getBorderDistHint(
    121     const QFont &font, int &start, int &end ) const
     362    const QFont& font, int& start, int& end ) const
    122363{
    123364    start = 0;
    … …  
    127368        return;
    128369
    129     const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
     370    const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
    130371    if ( ticks.count() == 0 )
    131372        return;
    … …  
    179420        e = 0.0;
    180421
    181     start = qCeil( s );
    182     end = qCeil( e );
    183 }
    184 
    185 /*!
    186   Determine the minimum distance between two labels, that is necessary
    187   that the texts don't overlap.
    188 
    189   \param font Font
    190   \return The maximum width of a label
    191 
    192   \sa getBorderDistHint()
    193 */
    194 
    195 int QwtScaleDraw::minLabelDist( const QFont &font ) const
     422    start = qwtCeil( s );
     423    end = qwtCeil( e );
     424}
     425
     426/*!
     427   Determine the minimum distance between two labels, that is necessary
     428   that the texts don't overlap.
     429
     430   \param font Font
     431   \return The maximum width of a label
     432
     433   \sa getBorderDistHint()
     434 */
     435
     436int QwtScaleDraw::minLabelDist( const QFont& font ) const
    196437{
    197438    if ( !hasComponent( QwtAbstractScaleDraw::Labels ) )
    198439        return 0;
    199440
    200     const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
     441    const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
    201442    if ( ticks.isEmpty() )
    202443        return 0;
    … …  
    279520
    280521   \sa minLength()
    281 */
    282 double QwtScaleDraw::extent( const QFont &font ) const
     522 */
     523double QwtScaleDraw::extent( const QFont& font ) const
    283524{
    284525    double d = 0;
    … …  
    302543    if ( hasComponent( QwtAbstractScaleDraw::Backbone ) )
    303544    {
    304         const double pw = qMax( 1, penWidth() );  // pen width can be zero
    305         d += pw;
    306     }
    307 
    308     d = qMax( d, minimumExtent() );
     545        d += qwtEffectivePenWidth( this );
     546    }
     547
     548    d = qwtMaxF( d, minimumExtent() );
    309549    return d;
    310550}
    … …  
    317557
    318558   \sa extent()
    319 */
    320 int QwtScaleDraw::minLength( const QFont &font ) const
     559 */
     560int QwtScaleDraw::minLength( const QFont& font ) const
    321561{
    322562    int startDist, endDist;
    323563    getBorderDistHint( font, startDist, endDist );
    324564
    325     const QwtScaleDiv &sd = scaleDiv();
     565    const QwtScaleDiv& sd = scaleDiv();
    326566
    327567    const uint minorCount =
    … …  
    338578    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) )
    339579    {
    340         const double pw = qMax( 1, penWidth() );  // penwidth can be zero
     580        const double pw = qwtEffectivePenWidth( this );
    341581        lengthForTicks = qCeil( ( majorCount + minorCount ) * ( pw + 1.0 ) );
    342582    }
    … …  
    353593   \param value Value
    354594   \return Position, where to paint a label
    355 */
     595 */
    356596QPointF QwtScaleDraw::labelPosition( double value ) const
    357597{
    … …  
    359599    double dist = spacing();
    360600    if ( hasComponent( QwtAbstractScaleDraw::Backbone ) )
    361         dist += qMax( 1, penWidth() );
     601        dist += qwtEffectivePenWidth( this );
    362602
    363603    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) )
    … …  
    371611        case RightScale:
    372612        {
    373             px = d_data->pos.x() + dist;
     613            px = m_data->pos.x() + dist;
    374614            py = tval;
    375615            break;
    … …  
    377617        case LeftScale:
    378618        {
    379             px = d_data->pos.x() - dist;
     619            px = m_data->pos.x() - dist;
    380620            py = tval;
    381621            break;
    … …  
    384624        {
    385625            px = tval;
    386             py = d_data->pos.y() + dist;
     626            py = m_data->pos.y() + dist;
    387627            break;
    388628        }
    … …  
    390630        {
    391631            px = tval;
    392             py = d_data->pos.y() - dist;
     632            py = m_data->pos.y() - dist;
    393633            break;
    394634        }
    … …  
    406646
    407647   \sa drawBackbone(), drawLabel()
    408 */
    409 void QwtScaleDraw::drawTick( QPainter *painter, double value, double len ) const
     648 */
     649void QwtScaleDraw::drawTick( QPainter* painter, double value, double len ) const
    410650{
    411651    if ( len <= 0 )
    412652        return;
    413653
    414     const bool roundingAlignment = QwtPainter::roundingAlignment( painter );
    415 
    416     QPointF pos = d_data->pos;
    417 
    418     double tval = scaleMap().transform( value );
    419     if ( roundingAlignment )
    420         tval = qRound( tval );
    421 
    422     const int pw = penWidth();
    423     int a = 0;
    424     if ( pw > 1 && roundingAlignment )
    425         a = 1;
    426 
    427     switch ( alignment() )
    428     {
    429         case LeftScale:
    430         {
    431             double x1 = pos.x() + a;
    432             double x2 = pos.x() + a - pw - len;
    433             if ( roundingAlignment )
    434             {
    435                 x1 = qRound( x1 );
    436                 x2 = qRound( x2 );
    437             }
    438 
    439             QwtPainter::drawLine( painter, x1, tval, x2, tval );
    440             break;
    441         }
    442 
    443         case RightScale:
    444         {
    445             double x1 = pos.x();
    446             double x2 = pos.x() + pw + len;
    447             if ( roundingAlignment )
    448             {
    449                 x1 = qRound( x1 );
    450                 x2 = qRound( x2 );
    451             }
    452 
    453             QwtPainter::drawLine( painter, x1, tval, x2, tval );
    454             break;
    455         }
    456 
    457         case BottomScale:
    458         {
    459             double y1 = pos.y();
    460             double y2 = pos.y() + pw + len;
    461             if ( roundingAlignment )
    462             {
    463                 y1 = qRound( y1 );
    464                 y2 = qRound( y2 );
    465             }
    466 
    467             QwtPainter::drawLine( painter, tval, y1, tval, y2 );
    468             break;
    469         }
    470 
    471         case TopScale:
    472         {
    473             double y1 = pos.y() + a;
    474             double y2 = pos.y() - pw - len + a;
    475             if ( roundingAlignment )
    476             {
    477                 y1 = qRound( y1 );
    478                 y2 = qRound( y2 );
    479             }
    480 
    481             QwtPainter::drawLine( painter, tval, y1, tval, y2 );
    482             break;
    483         }
    484     }
     654    const double tval = scaleMap().transform( value );
     655
     656    if ( QwtPainter::roundingAlignment( painter ) )
     657        QwtScaleRendererInt::drawTick( painter, this, tval, len );
     658    else
     659        QwtScaleRendererReal::drawTick( painter, this, tval, len );
    485660}
    486661
    … …  
    490665
    491666   \sa drawTick(), drawLabel()
    492 */
    493 void QwtScaleDraw::drawBackbone( QPainter *painter ) const
    494 {
    495     const bool doAlign = QwtPainter::roundingAlignment( painter );
    496 
    497     const QPointF &pos = d_data->pos;
    498     const double len = d_data->len;
    499     const int pw = qMax( penWidth(), 1 );
    500 
    501     // pos indicates a border not the center of the backbone line
    502     // so we need to shift its position depending on the pen width
    503     // and the alignment of the scale
    504 
    505     double off;
    506     if ( doAlign )
    507     {
    508         if ( alignment() == LeftScale || alignment() == TopScale )
    509             off = ( pw - 1 ) / 2;
    510         else
    511             off = pw / 2;
    512     }
     667 */
     668void QwtScaleDraw::drawBackbone( QPainter* painter ) const
     669{
     670    if ( QwtPainter::roundingAlignment( painter ) )
     671        QwtScaleRendererInt::drawBackbone( painter, this );
    513672    else
    514     {
    515         off = 0.5 * penWidth();
    516     }
    517 
    518     switch ( alignment() )
    519     {
    520         case LeftScale:
    521         {
    522             double x = pos.x() - off;
    523             if ( doAlign )
    524                 x = qRound( x );
    525 
    526             QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + len );
    527             break;
    528         }
    529         case RightScale:
    530         {
    531             double x = pos.x() + off;
    532             if ( doAlign )
    533                 x = qRound( x );
    534 
    535             QwtPainter::drawLine( painter, x, pos.y(), x, pos.y() + len );
    536             break;
    537         }
    538         case TopScale:
    539         {
    540             double y = pos.y() - off;
    541             if ( doAlign )
    542                 y = qRound( y );
    543 
    544             QwtPainter::drawLine( painter, pos.x(), y, pos.x() + len, y );
    545             break;
    546         }
    547         case BottomScale:
    548         {
    549             double y = pos.y() + off;
    550             if ( doAlign )
    551                 y = qRound( y );
    552 
    553             QwtPainter::drawLine( painter, pos.x(), y, pos.x() + len, y );
    554             break;
    555         }
    556     }
    557 }
    558 
    559 /*!
    560   \brief Move the position of the scale
    561 
    562   The meaning of the parameter pos depends on the alignment:
    563   <dl>
    564   <dt>QwtScaleDraw::LeftScale
    565   <dd>The origin is the topmost point of the
     673        QwtScaleRendererReal::drawBackbone( painter, this );
     674}
     675
     676/*!
     677   \brief Move the position of the scale
     678
     679   The meaning of the parameter pos depends on the alignment:
     680   <dl>
     681   <dt>QwtScaleDraw::LeftScale
     682   <dd>The origin is the topmost point of the
    566683      backbone. The backbone is a vertical line.
    567684      Scale marks and labels are drawn
    568685      at the left of the backbone.
    569   <dt>QwtScaleDraw::RightScale
    570   <dd>The origin is the topmost point of the
     686   <dt>QwtScaleDraw::RightScale
     687   <dd>The origin is the topmost point of the
    571688      backbone. The backbone is a vertical line.
    572689      Scale marks and labels are drawn
    573690      at the right of the backbone.
    574   <dt>QwtScaleDraw::TopScale
    575   <dd>The origin is the leftmost point of the
     691   <dt>QwtScaleDraw::TopScale
     692   <dd>The origin is the leftmost point of the
    576693      backbone. The backbone is a horizontal line.
    577694      Scale marks and labels are drawn
    578695      above the backbone.
    579   <dt>QwtScaleDraw::BottomScale
    580   <dd>The origin is the leftmost point of the
     696   <dt>QwtScaleDraw::BottomScale
     697   <dd>The origin is the leftmost point of the
    581698      backbone. The backbone is a horizontal line
    582699      Scale marks and labels are drawn
    583700      below the backbone.
    584   </dl>
    585 
    586   \param pos Origin of the scale
    587 
    588   \sa pos(), setLength()
    589 */
    590 void QwtScaleDraw::move( const QPointF &pos )
    591 {
    592     d_data->pos = pos;
     701   </dl>
     702
     703   \param pos Origin of the scale
     704
     705   \sa pos(), setLength()
     706 */
     707void QwtScaleDraw::move( const QPointF& pos )
     708{
     709    m_data->pos = pos;
    593710    updateMap();
    594711}
    … …  
    597714   \return Origin of the scale
    598715   \sa move(), length()
    599 */
     716 */
    600717QPointF QwtScaleDraw::pos() const
    601718{
    602     return d_data->pos;
    603 }
    604 
    605 /*!
    606   Set the length of the backbone.
    607 
    608   The length doesn't include the space needed for
    609   overlapping labels.
    610 
    611   \param length Length of the backbone
    612 
    613   \sa move(), minLabelDist()
    614 */
     719    return m_data->pos;
     720}
     721
     722/*!
     723   Set the length of the backbone.
     724
     725   The length doesn't include the space needed for
     726   overlapping labels.
     727
     728   \param length Length of the backbone
     729
     730   \sa move(), minLabelDist()
     731 */
    615732void QwtScaleDraw::setLength( double length )
    616733{
    617 #if 1
    618734    if ( length >= 0 && length < 10 )
    619735        length = 10;
    620736
    621     // why should we accept negative lengths ???
     737    // f.e the left/bottom scales of a polar plot
    622738    if ( length < 0 && length > -10 )
    623739        length = -10;
    624 #else
    625     length = qMax( length, 10 );
    626 #endif
    627 
    628     d_data->len = length;
     740
     741    m_data->len = length;
    629742    updateMap();
    630743}
    … …  
    633746   \return the length of the backbone
    634747   \sa setLength(), pos()
    635 */
     748 */
    636749double QwtScaleDraw::length() const
    637750{
    638     return d_data->len;
     751    return m_data->len;
    639752}
    640753
    … …  
    646759
    647760   \sa drawTick(), drawBackbone(), boundingLabelRect()
    648 */
    649 void QwtScaleDraw::drawLabel( QPainter *painter, double value ) const
     761 */
     762void QwtScaleDraw::drawLabel( QPainter* painter, double value ) const
    650763{
    651764    QwtText lbl = tickLabel( painter->font(), value );
    … …  
    668781
    669782/*!
    670   \brief Find the bounding rectangle for the label.
    671 
    672   The coordinates of the rectangle are absolute ( calculated from pos() ).
    673   in direction of the tick.
    674 
    675   \param font Font used for painting
    676   \param value Value
    677 
    678   \return Bounding rectangle
    679   \sa labelRect()
    680 */
    681 QRect QwtScaleDraw::boundingLabelRect( const QFont &font, double value ) const
     783   \brief Find the bounding rectangle for the label.
     784
     785   The coordinates of the rectangle are absolute ( calculated from pos() ).
     786   in direction of the tick.
     787
     788   \param font Font used for painting
     789   \param value Value
     790
     791   \return Bounding rectangle
     792   \sa labelRect()
     793 */
     794QRect QwtScaleDraw::boundingLabelRect( const QFont& font, double value ) const
    682795{
    683796    QwtText lbl = tickLabel( font, value );
    … …  
    701814   \return Transformation matrix
    702815   \sa setLabelAlignment(), setLabelRotation()
    703 */
     816 */
    704817QTransform QwtScaleDraw::labelTransformation(
    705     const QPointF &pos, const QSizeF &size ) const
     818    const QPointF& pos, const QSizeF& size ) const
    706819{
    707820    QTransform transform;
    … …  
    763876
    764877/*!
    765   Find the bounding rectangle for the label. The coordinates of
    766   the rectangle are relative to spacing + tick length from the backbone
    767   in direction of the tick.
    768 
    769   \param font Font used for painting
    770   \param value Value
     878   Find the bounding rectangle for the label. The coordinates of
     879   the rectangle are relative to spacing + tick length from the backbone
     880   in direction of the tick.
     881
     882   \param font Font used for painting
     883   \param value Value
    771884
    772885   \return Bounding rectangle that is needed to draw a label
    773 */
    774 QRectF QwtScaleDraw::labelRect( const QFont &font, double value ) const
     886 */
     887QRectF QwtScaleDraw::labelRect( const QFont& font, double value ) const
    775888{
    776889    QwtText lbl = tickLabel( font, value );
    … …  
    796909
    797910   \return Size that is needed to draw a label
    798 */
    799 QSizeF QwtScaleDraw::labelSize( const QFont &font, double value ) const
     911 */
     912QSizeF QwtScaleDraw::labelSize( const QFont& font, double value ) const
    800913{
    801914    return labelRect( font, value ).size();
    … …  
    803916
    804917/*!
    805   Rotate all labels.
    806 
    807   When changing the rotation, it might be necessary to
    808   adjust the label flags too. Finding a useful combination is
    809   often the result of try and error.
    810 
    811   \param rotation Angle in degrees. When changing the label rotation,
     918   Rotate all labels.
     919
     920   When changing the rotation, it might be necessary to
     921   adjust the label flags too. Finding a useful combination is
     922   often the result of try and error.
     923
     924   \param rotation Angle in degrees. When changing the label rotation,
    812925                  the label flags often needs to be adjusted too.
    813926
    814   \sa setLabelAlignment(), labelRotation(), labelAlignment().
    815 
    816 */
     927   \sa setLabelAlignment(), labelRotation(), labelAlignment().
     928
     929 */
    817930void QwtScaleDraw::setLabelRotation( double rotation )
    818931{
    819     d_data->labelRotation = rotation;
    820 }
    821 
    822 /*!
    823   \return the label rotation
    824   \sa setLabelRotation(), labelAlignment()
    825 */
     932    m_data->labelRotation = rotation;
     933}
     934
     935/*!
     936   \return the label rotation
     937   \sa setLabelRotation(), labelAlignment()
     938 */
    826939double QwtScaleDraw::labelRotation() const
    827940{
    828     return d_data->labelRotation;
    829 }
    830 
    831 /*!
    832   \brief Change the label flags
    833 
    834   Labels are aligned to the point tick length + spacing away from the backbone.
    835 
    836   The alignment is relative to the orientation of the label text.
    837   In case of an flags of 0 the label will be aligned
    838   depending on the orientation of the scale:
     941    return m_data->labelRotation;
     942}
     943
     944/*!
     945   \brief Change the label flags
     946
     947   Labels are aligned to the point tick length + spacing away from the backbone.
     948
     949   The alignment is relative to the orientation of the label text.
     950   In case of an flags of 0 the label will be aligned
     951   depending on the orientation of the scale:
    839952
    840953      QwtScaleDraw::TopScale: Qt::AlignHCenter | Qt::AlignTop\n
    … …  
    843956      QwtScaleDraw::RightScale: Qt::AlignRight | Qt::AlignVCenter\n
    844957
    845   Changing the alignment is often necessary for rotated labels.
    846 
    847   \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h>
    848 
    849   \sa setLabelRotation(), labelRotation(), labelAlignment()
    850   \warning The various alignments might be confusing.
     958   Changing the alignment is often necessary for rotated labels.
     959
     960   \param alignment Or'd Qt::AlignmentFlags see <qnamespace.h>
     961
     962   \sa setLabelRotation(), labelRotation(), labelAlignment()
     963   \warning The various alignments might be confusing.
    851964           The alignment of the label is not the alignment
    852965           of the scale and is not the alignment of the flags
    853966           ( QwtText::flags() ) returned from QwtAbstractScaleDraw::label().
    854 */
     967 */
    855968
    856969void QwtScaleDraw::setLabelAlignment( Qt::Alignment alignment )
    857970{
    858     d_data->labelAlignment = alignment;
    859 }
    860 
    861 /*!
    862   \return the label flags
    863   \sa setLabelAlignment(), labelRotation()
    864 */
     971    m_data->labelAlignment = alignment;
     972}
     973
     974/*!
     975   \return the label flags
     976   \sa setLabelAlignment(), labelRotation()
     977 */
    865978Qt::Alignment QwtScaleDraw::labelAlignment() const
    866979{
    867     return d_data->labelAlignment;
    868 }
    869 
    870 /*!
    871   \param font Font
    872   \return the maximum width of a label
    873 */
    874 int QwtScaleDraw::maxLabelWidth( const QFont &font ) const
     980    return m_data->labelAlignment;
     981}
     982
     983/*!
     984   \param font Font
     985   \return the maximum width of a label
     986 */
     987int QwtScaleDraw::maxLabelWidth( const QFont& font ) const
    875988{
    876989    double maxWidth = 0.0;
    877990
    878     const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
     991    const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
    879992    for ( int i = 0; i < ticks.count(); i++ )
    880993    {
    … …  
    8921005
    8931006/*!
    894   \param font Font
    895   \return the maximum height of a label
    896 */
    897 int QwtScaleDraw::maxLabelHeight( const QFont &font ) const
     1007   \param font Font
     1008   \return the maximum height of a label
     1009 */
     1010int QwtScaleDraw::maxLabelHeight( const QFont& font ) const
    8981011{
    8991012    double maxHeight = 0.0;
    9001013
    901     const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
     1014    const QList< double >& ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick );
    9021015    for ( int i = 0; i < ticks.count(); i++ )
    9031016    {
    … …  
    9161029void QwtScaleDraw::updateMap()
    9171030{
    918     const QPointF pos = d_data->pos;
    919     double len = d_data->len;
    920 
    921     QwtScaleMap &sm = scaleMap();
     1031    const QPointF pos = m_data->pos;
     1032    double len = m_data->len;
     1033
     1034    QwtScaleMap& sm = scaleMap();
    9221035    if ( orientation() == Qt::Vertical )
    9231036        sm.setPaintInterval( pos.y() + len, pos.y() );
  • trunk/BNC/qwt/qwt_scale_draw.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_abstract_scale_draw.h"
     15
    1516#include <qpoint.h>
    16 #include <qrect.h>
    17 #include <qtransform.h>
     17
     18class QTransform;
     19class QSizeF;
     20class QRectF;
     21class QRect;
    1822
    1923/*!
    20   \brief A class for drawing scales
     24   \brief A class for drawing scales
    2125
    22   QwtScaleDraw can be used to draw linear or logarithmic scales.
    23   A scale has a position, an alignment and a length, which can be specified .
    24   The labels can be rotated and aligned
    25   to the ticks using setLabelRotation() and setLabelAlignment().
     26   QwtScaleDraw can be used to draw linear or logarithmic scales.
     27   A scale has a position, an alignment and a length, which can be specified .
     28   The labels can be rotated and aligned
     29   to the ticks using setLabelRotation() and setLabelAlignment().
    2630
    27   After a scale division has been specified as a QwtScaleDiv object
    28   using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s),
    29   the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
    30 */
    31 class QWT_EXPORT QwtScaleDraw: public QwtAbstractScaleDraw
     31   After a scale division has been specified as a QwtScaleDiv object
     32   using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s),
     33   the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
     34 */
     35class QWT_EXPORT QwtScaleDraw : public QwtAbstractScaleDraw
    3236{
    33 public:
     37  public:
    3438    /*!
    3539        Alignment of the scale draw
    … …  
    5458    virtual ~QwtScaleDraw();
    5559
    56     void getBorderDistHint( const QFont &, int &start, int &end ) const;
    57     int minLabelDist( const QFont & ) const;
     60    void getBorderDistHint( const QFont&, int& start, int& end ) const;
     61    int minLabelDist( const QFont& ) const;
    5862
    59     int minLength( const QFont & ) const;
    60     virtual double extent( const QFont & ) const;
     63    int minLength( const QFont& ) const;
     64    virtual double extent( const QFont& ) const QWT_OVERRIDE;
    6165
    6266    void move( double x, double y );
    63     void move( const QPointF & );
     67    void move( const QPointF& );
    6468    void setLength( double length );
    6569
    … …  
    7882    double labelRotation() const;
    7983
    80     int maxLabelHeight( const QFont & ) const;
    81     int maxLabelWidth( const QFont & ) const;
     84    int maxLabelHeight( const QFont& ) const;
     85    int maxLabelWidth( const QFont& ) const;
    8286
    8387    QPointF labelPosition( double value ) const;
    8488
    85     QRectF labelRect( const QFont &, double value ) const;
    86     QSizeF labelSize( const QFont &, double value ) const;
     89    QRectF labelRect( const QFont&, double value ) const;
     90    QSizeF labelSize( const QFont&, double value ) const;
    8791
    88     QRect boundingLabelRect( const QFont &, double value ) const;
     92    QRect boundingLabelRect( const QFont&, double value ) const;
    8993
    90 protected:
    91     QTransform labelTransformation( const QPointF &, const QSizeF & ) const;
     94  protected:
     95    QTransform labelTransformation( const QPointF&, const QSizeF& ) const;
    9296
    93     virtual void drawTick( QPainter *, double value, double len ) const;
    94     virtual void drawBackbone( QPainter * ) const;
    95     virtual void drawLabel( QPainter *, double value ) const;
     97    virtual void drawTick( QPainter*,
     98        double value, double len ) const QWT_OVERRIDE;
    9699
    97 private:
    98     QwtScaleDraw( const QwtScaleDraw & );
    99     QwtScaleDraw &operator=( const QwtScaleDraw &other );
     100    virtual void drawBackbone( QPainter* ) const QWT_OVERRIDE;
     101    virtual void drawLabel( QPainter*, double value ) const QWT_OVERRIDE;
    100102
     103  private:
    101104    void updateMap();
    102105
    103106    class PrivateData;
    104     PrivateData *d_data;
     107    PrivateData* m_data;
    105108};
    106109
    … …  
    112115
    113116   \sa move(const QPointF &)
    114 */
     117 */
    115118inline void QwtScaleDraw::move( double x, double y )
    116119{
  • trunk/BNC/qwt/qwt_scale_engine.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_scale_engine.h"
    1111#include "qwt_math.h"
    12 #include "qwt_scale_map.h"
    13 #include <qalgorithms.h>
    14 #include <qmath.h>
    15 #include <float.h>
     12#include "qwt_interval.h"
     13#include "qwt_transform.h"
     14
     15#include <qdebug.h>
     16
    1617#include <limits>
    1718
    18 #if QT_VERSION < 0x040601
    19 #define qFabs(x) ::fabs(x)
    20 #define qExp(x) ::exp(x)
    21 #endif
    22 
    2319static inline double qwtLog( double base, double value )
    2420{
    25     return log( value ) / log( base );
    26 }
    27 
    28 static inline QwtInterval qwtLogInterval( double base, const QwtInterval &interval )
     21    return std::log( value ) / std::log( base );
     22}
     23
     24static inline QwtInterval qwtLogInterval( double base, const QwtInterval& interval )
    2925{
    3026    return QwtInterval( qwtLog( base, interval.minValue() ),
    31             qwtLog( base, interval.maxValue() ) );
    32 }
    33 
    34 static inline QwtInterval qwtPowInterval( double base, const QwtInterval &interval )
    35 {
    36     return QwtInterval( qPow( base, interval.minValue() ),
    37             qPow( base, interval.maxValue() ) );
    38 }
    39 
    40 static inline long double qwtIntervalWidthL( const QwtInterval &interval )
    41 {
    42     if ( !interval.isValid() )
    43         return 0.0;
    44 
    45     return static_cast<long double>( interval.maxValue() )
    46         - static_cast<long double>( interval.minValue() );
     27        qwtLog( base, interval.maxValue() ) );
     28}
     29
     30static inline QwtInterval qwtPowInterval( double base, const QwtInterval& interval )
     31{
     32    return QwtInterval( std::pow( base, interval.minValue() ),
     33        std::pow( base, interval.maxValue() ) );
    4734}
    4835
    … …  
    5845    {
    5946        // # ticks per interval
    60         const int numTicks = qCeil( qAbs( intervalSize / minStep ) ) - 1;
     47        const int numTicks = qwtCeil( qAbs( intervalSize / minStep ) ) - 1;
    6148
    6249        // Do the minor steps fit into the interval?
    63         if ( qwtFuzzyCompare( ( numTicks +  1 ) * qAbs( minStep ),
     50        if ( qwtFuzzyCompare( ( numTicks + 1 ) * qAbs( minStep ),
    6451            qAbs( intervalSize ), intervalSize ) > 0 )
    6552        {
    … …  
    8572            const double stepSize = intervalSize / numSteps;
    8673
    87             const double p = ::floor( ::log( stepSize ) / ::log( base ) );
    88             const double fraction = qPow( base, p );
     74            const double p = std::floor( std::log( stepSize ) / std::log( base ) );
     75            const double fraction = std::pow( base, p );
    8976
    9077            for ( uint n = base; n > 1; n /= 2 )
    … …  
    11097
    11198/*!
    112   Ceil a value, relative to an interval
    113 
    114   \param value Value to be ceiled
    115   \param intervalSize Interval size
    116 
    117   \return Rounded value
    118 
    119   \sa floorEps()
    120 */
     99   Ceil a value, relative to an interval
     100
     101   \param value Value to be ceiled
     102   \param intervalSize Interval size
     103
     104   \return Rounded value
     105
     106   \sa floorEps()
     107 */
    121108double QwtScaleArithmetic::ceilEps( double value,
    122109    double intervalSize )
    … …  
    125112
    126113    value = ( value - eps ) / intervalSize;
    127     return ::ceil( value ) * intervalSize;
    128 }
    129 
    130 /*!
    131   Floor a value, relative to an interval
    132 
    133   \param value Value to be floored
    134   \param intervalSize Interval size
    135 
    136   \return Rounded value
    137   \sa floorEps()
    138 */
     114    return std::ceil( value ) * intervalSize;
     115}
     116
     117/*!
     118   Floor a value, relative to an interval
     119
     120   \param value Value to be floored
     121   \param intervalSize Interval size
     122
     123   \return Rounded value
     124   \sa floorEps()
     125 */
    139126double QwtScaleArithmetic::floorEps( double value, double intervalSize )
    140127{
    … …  
    142129
    143130    value = ( value + eps ) / intervalSize;
    144     return ::floor( value ) * intervalSize;
    145 }
    146 
    147 /*!
    148   \brief Divide an interval into steps
    149 
    150   \f$stepSize = (intervalSize - intervalSize * 10e^{-6}) / numSteps\f$
    151 
    152   \param intervalSize Interval size
    153   \param numSteps Number of steps
    154   \return Step size
    155 */
     131    return std::floor( value ) * intervalSize;
     132}
     133
     134/*!
     135   \brief Divide an interval into steps
     136
     137   \f$stepSize = (intervalSize - intervalSize * 10e^{-6}) / numSteps\f$
     138
     139   \param intervalSize Interval size
     140   \param numSteps Number of steps
     141   \return Step size
     142 */
    156143double QwtScaleArithmetic::divideEps( double intervalSize, double numSteps )
    157144{
    … …  
    163150
    164151/*!
    165   Calculate a step size for a given interval
    166 
    167   \param intervalSize Interval size
    168   \param numSteps Number of steps
    169   \param base Base for the division ( usually 10 )
    170 
    171   \return Calculated step size
     152   Calculate a step size for a given interval
     153
     154   \param intervalSize Interval size
     155   \param numSteps Number of steps
     156   \param base Base for the division ( usually 10 )
     157
     158   \return Calculated step size
    172159 */
    173160double QwtScaleArithmetic::divideInterval(
    … …  
    181168        return 0.0;
    182169
    183     const double lx = qwtLog( base, qFabs( v ) );
    184     const double p = ::floor( lx );
    185 
    186     const double fraction = qPow( base, lx - p );
     170    const double lx = qwtLog( base, std::fabs( v ) );
     171    const double p = std::floor( lx );
     172
     173    const double fraction = std::pow( base, lx - p );
    187174
    188175    uint n = base;
    … …  
    190177        n /= 2;
    191178
    192     double stepSize = n * qPow( base, p );
     179    double stepSize = n * std::pow( base, p );
    193180    if ( v < 0 )
    194181        stepSize = -stepSize;
    … …  
    199186class QwtScaleEngine::PrivateData
    200187{
    201 public:
     188  public:
    202189    PrivateData():
    203190        attributes( QwtScaleEngine::NoAttribute ),
    … …  
    228215
    229216/*!
    230   Constructor
    231 
    232   \param base Base of the scale engine
    233   \sa setBase()
     217   Constructor
     218
     219   \param base Base of the scale engine
     220   \sa setBase()
    234221 */
    235222QwtScaleEngine::QwtScaleEngine( uint base )
    236223{
    237     d_data = new PrivateData;
     224    m_data = new PrivateData;
    238225    setBase( base );
    239226}
    … …  
    243230QwtScaleEngine::~QwtScaleEngine ()
    244231{
    245     delete d_data;
     232    delete m_data;
    246233}
    247234
    … …  
    259246
    260247 */
    261 void QwtScaleEngine::setTransformation( QwtTransform *transform )
    262 {
    263     if ( transform != d_data->transform )
    264     {
    265         delete d_data->transform;
    266         d_data->transform = transform;
     248void QwtScaleEngine::setTransformation( QwtTransform* transform )
     249{
     250    if ( transform != m_data->transform )
     251    {
     252        delete m_data->transform;
     253        m_data->transform = transform;
    267254    }
    268255}
    … …  
    273260   NULL is returned, indicating no transformation.
    274261
    275    \return A clone of the transfomation
     262   \return A clone of the transformation
    276263   \sa setTransformation()
    277264 */
    278 QwtTransform *QwtScaleEngine::transformation() const
    279 {
    280     QwtTransform *transform = NULL;
    281     if ( d_data->transform )
    282         transform = d_data->transform->copy();
     265QwtTransform* QwtScaleEngine::transformation() const
     266{
     267    QwtTransform* transform = NULL;
     268    if ( m_data->transform )
     269        transform = m_data->transform->copy();
    283270
    284271    return transform;
    … …  
    290277
    291278    \sa setMargins()
    292 */
     279 */
    293280double QwtScaleEngine::lowerMargin() const
    294281{
    295     return d_data->lowerMargin;
     282    return m_data->lowerMargin;
    296283}
    297284
    … …  
    301288
    302289    \sa setMargins()
    303 */
     290 */
    304291double QwtScaleEngine::upperMargin() const
    305292{
    306     return d_data->upperMargin;
    307 }
    308 
    309 /*!
    310   \brief Specify margins at the scale's endpoints
    311   \param lower minimum distance between the scale's lower boundary and the
     293    return m_data->upperMargin;
     294}
     295
     296/*!
     297   \brief Specify margins at the scale's endpoints
     298   \param lower minimum distance between the scale's lower boundary and the
    312299             smallest enclosed value
    313   \param upper minimum distance between the scale's upper boundary and the
     300   \param upper minimum distance between the scale's upper boundary and the
    314301             greatest enclosed value
    315302
    316   Margins can be used to leave a minimum amount of space between
    317   the enclosed intervals and the boundaries of the scale.
    318 
    319   \warning
    320   \li QwtLogScaleEngine measures the margins in decades.
    321 
    322   \sa upperMargin(), lowerMargin()
    323 */
     303   Margins can be used to leave a minimum amount of space between
     304   the enclosed intervals and the boundaries of the scale.
     305
     306   \warning
     307   \li QwtLogScaleEngine measures the margins in decades.
     308
     309   \sa upperMargin(), lowerMargin()
     310 */
    324311
    325312void QwtScaleEngine::setMargins( double lower, double upper )
    326313{
    327     d_data->lowerMargin = qMax( lower, 0.0 );
    328     d_data->upperMargin = qMax( upper, 0.0 );
    329 }
    330 
    331 /*!
    332   Calculate a step size for an interval size
    333 
    334   \param intervalSize Interval size
    335   \param numSteps Number of steps
    336 
    337   \return Step size
    338 */
     314    m_data->lowerMargin = qwtMaxF( lower, 0.0 );
     315    m_data->upperMargin = qwtMaxF( upper, 0.0 );
     316}
     317
     318/*!
     319   Calculate a step size for an interval size
     320
     321   \param intervalSize Interval size
     322   \param numSteps Number of steps
     323
     324   \return Step size
     325 */
    339326double QwtScaleEngine::divideInterval(
    340327    double intervalSize, int numSteps ) const
    341328{
    342329    return QwtScaleArithmetic::divideInterval(
    343         intervalSize, numSteps, d_data->base );
    344 }
    345 
    346 /*!
    347   Check if an interval "contains" a value
    348 
    349   \param interval Interval
    350   \param value Value
    351 
    352   \return True, when the value is inside the interval
    353 */
     330        intervalSize, numSteps, m_data->base );
     331}
     332
     333/*!
     334   Check if an interval "contains" a value
     335
     336   \param interval Interval
     337   \param value Value
     338
     339   \return True, when the value is inside the interval
     340 */
    354341bool QwtScaleEngine::contains(
    355     const QwtInterval &interval, double value ) const
     342    const QwtInterval& interval, double value ) const
    356343{
    357344    if ( !interval.isValid() )
    … …  
    368355
    369356/*!
    370   Remove ticks from a list, that are not inside an interval
    371 
    372   \param ticks Tick list
    373   \param interval Interval
    374 
    375   \return Stripped tick list
    376 */
    377 QList<double> QwtScaleEngine::strip( const QList<double>& ticks,
    378     const QwtInterval &interval ) const
     357   Remove ticks from a list, that are not inside an interval
     358
     359   \param ticks Tick list
     360   \param interval Interval
     361
     362   \return Stripped tick list
     363 */
     364QList< double > QwtScaleEngine::strip( const QList< double >& ticks,
     365    const QwtInterval& interval ) const
    379366{
    380367    if ( !interval.isValid() || ticks.count() == 0 )
    381         return QList<double>();
     368        return QList< double >();
    382369
    383370    if ( contains( interval, ticks.first() )
    … …  
    387374    }
    388375
    389     QList<double> strippedTicks;
     376    QList< double > strippedTicks;
    390377    for ( int i = 0; i < ticks.count(); i++ )
    391378    {
    … …  
    397384
    398385/*!
    399   \brief Build an interval around a value
    400 
    401   In case of v == 0.0 the interval is [-0.5, 0.5],
    402   otherwide it is [0.5 * v, 1.5 * v]
    403 
    404   \param value Initial value
    405   \return Calculated interval
    406 */
     386   \brief Build an interval around a value
     387
     388   In case of v == 0.0 the interval is [-0.5, 0.5],
     389   otherwise it is [0.5 * v, 1.5 * v]
     390
     391   \param value Initial value
     392   \return Calculated interval
     393 */
    407394
    408395QwtInterval QwtScaleEngine::buildInterval( double value ) const
    409396{
    410397    const double delta = ( value == 0.0 ) ? 0.5 : qAbs( 0.5 * value );
    411 
    412     if ( DBL_MAX - delta < value )
    413         return QwtInterval( DBL_MAX - delta, DBL_MAX );
    414 
    415     if ( -DBL_MAX + delta > value )
    416         return QwtInterval( -DBL_MAX, -DBL_MAX + delta );
     398    const double max = std::numeric_limits< double >::max();
     399
     400    if ( max - delta < value )
     401        return QwtInterval( max - delta, max );
     402
     403    if ( -max + delta > value )
     404        return QwtInterval( -max, -max + delta );
    417405
    418406    return QwtInterval( value - delta, value + delta );
    … …  
    420408
    421409/*!
    422   Change a scale attribute
    423 
    424   \param attribute Attribute to change
    425   \param on On/Off
    426 
    427   \sa Attribute, testAttribute()
    428 */
     410   Change a scale attribute
     411
     412   \param attribute Attribute to change
     413   \param on On/Off
     414
     415   \sa Attribute, testAttribute()
     416 */
    429417void QwtScaleEngine::setAttribute( Attribute attribute, bool on )
    430418{
    431419    if ( on )
    432         d_data->attributes |= attribute;
     420        m_data->attributes |= attribute;
    433421    else
    434         d_data->attributes &= ~attribute;
    435 }
    436 
    437 /*!
    438   \return True, if attribute is enabled.
    439 
    440   \param attribute Attribute to be tested
    441   \sa Attribute, setAttribute()
    442 */
     422        m_data->attributes &= ~attribute;
     423}
     424
     425/*!
     426   \return True, if attribute is enabled.
     427
     428   \param attribute Attribute to be tested
     429   \sa Attribute, setAttribute()
     430 */
    443431bool QwtScaleEngine::testAttribute( Attribute attribute ) const
    444432{
    445     return ( d_data->attributes & attribute );
    446 }
    447 
    448 /*!
    449   Change the scale attribute
    450 
    451   \param attributes Set scale attributes
    452   \sa Attribute, attributes()
    453 */
     433    return ( m_data->attributes & attribute );
     434}
     435
     436/*!
     437   Change the scale attribute
     438
     439   \param attributes Set scale attributes
     440   \sa Attribute, attributes()
     441 */
    454442void QwtScaleEngine::setAttributes( Attributes attributes )
    455443{
    456     d_data->attributes = attributes;
    457 }
    458 
    459 /*!
    460   \return Scale attributes
    461   \sa Attribute, setAttributes(), testAttribute()
    462 */
     444    m_data->attributes = attributes;
     445}
     446
     447/*!
     448   \return Scale attributes
     449   \sa Attribute, setAttributes(), testAttribute()
     450 */
    463451QwtScaleEngine::Attributes QwtScaleEngine::attributes() const
    464452{
    465     return d_data->attributes;
    466 }
    467 
    468 /*!
    469   \brief Specify a reference point
    470   \param reference New reference value
    471 
    472   The reference point is needed if options IncludeReference or
    473   Symmetric are active. Its default value is 0.0.
    474 
    475   \sa Attribute
    476 */
     453    return m_data->attributes;
     454}
     455
     456/*!
     457   \brief Specify a reference point
     458   \param reference New reference value
     459
     460   The reference point is needed if options IncludeReference or
     461   Symmetric are active. Its default value is 0.0.
     462
     463   \sa Attribute
     464 */
    477465void QwtScaleEngine::setReference( double reference )
    478466{
    479     d_data->referenceValue = reference;
    480 }
    481 
    482 /*!
    483   \return the reference value
    484   \sa setReference(), setAttribute()
    485 */
     467    m_data->referenceValue = reference;
     468}
     469
     470/*!
     471   \return the reference value
     472   \sa setReference(), setAttribute()
     473 */
    486474double QwtScaleEngine::reference() const
    487475{
    488     return d_data->referenceValue;
    489 }
    490 
    491 /*!
    492   Set the base of the scale engine
    493 
    494   While a base of 10 is what 99.9% of all applications need
    495   certain scales might need a different base: f.e 2
    496 
    497   The default setting is 10
    498 
    499   \param base Base of the engine
    500 
    501   \sa base()
     476    return m_data->referenceValue;
     477}
     478
     479/*!
     480   Set the base of the scale engine
     481
     482   While a base of 10 is what 99.9% of all applications need
     483   certain scales might need a different base: f.e 2
     484
     485   The default setting is 10
     486
     487   \param base Base of the engine
     488
     489   \sa base()
    502490 */
    503491void QwtScaleEngine::setBase( uint base )
    504492{
    505     d_data->base = qMax( base, 2U );
    506 }
    507 
    508 /*!
    509   \return base Base of the scale engine
    510   \sa setBase()
     493    m_data->base = qMax( base, 2U );
     494}
     495
     496/*!
     497   \return base Base of the scale engine
     498   \sa setBase()
    511499 */
    512500uint QwtScaleEngine::base() const
    513501{
    514     return d_data->base;
    515 }
    516 
    517 /*!
    518   Constructor
    519 
    520   \param base Base of the scale engine
    521   \sa setBase()
     502    return m_data->base;
     503}
     504
     505/*!
     506   Constructor
     507
     508   \param base Base of the scale engine
     509   \sa setBase()
    522510 */
    523511QwtLinearScaleEngine::QwtLinearScaleEngine( uint base ):
    … …  
    532520
    533521/*!
    534   Align and divide an interval
    535 
    536   \param maxNumSteps Max. number of steps
    537   \param x1 First limit of the interval (In/Out)
    538   \param x2 Second limit of the interval (In/Out)
    539   \param stepSize Step size (Out)
    540 
    541   \sa setAttribute()
    542 */
     522   Align and divide an interval
     523
     524   \param maxNumSteps Max. number of steps
     525   \param x1 First limit of the interval (In/Out)
     526   \param x2 Second limit of the interval (In/Out)
     527   \param stepSize Step size (Out)
     528
     529   \sa setAttribute()
     530 */
    543531void QwtLinearScaleEngine::autoScale( int maxNumSteps,
    544     double &x1, double &x2, double &stepSize ) const
     532    double& x1, double& x2, double& stepSize ) const
    545533{
    546534    QwtInterval interval( x1, x2 );
    … …  
    586574
    587575   \return Calculated scale division
    588 */
     576 */
    589577QwtScaleDiv QwtLinearScaleEngine::divideScale( double x1, double x2,
    590578    int maxMajorSteps, int maxMinorSteps, double stepSize ) const
    … …  
    592580    QwtInterval interval = QwtInterval( x1, x2 ).normalized();
    593581
    594     if ( qwtIntervalWidthL( interval ) > std::numeric_limits<double>::max() )
     582    if ( interval.widthL() > std::numeric_limits< double >::max() )
    595583    {
    596584        qWarning() << "QwtLinearScaleEngine::divideScale: overflow";
    … …  
    615603    if ( stepSize != 0.0 )
    616604    {
    617         QList<double> ticks[QwtScaleDiv::NTickTypes];
     605        QList< double > ticks[QwtScaleDiv::NTickTypes];
    618606        buildTicks( interval, stepSize, maxMinorSteps, ticks );
    619607
    … …  
    636624
    637625   \sa buildMajorTicks(), buildMinorTicks
    638 */
     626 */
    639627void QwtLinearScaleEngine::buildTicks(
    640628    const QwtInterval& interval, double stepSize, int maxMinorSteps,
    641     QList<double> ticks[QwtScaleDiv::NTickTypes] ) const
     629    QList< double > ticks[QwtScaleDiv::NTickTypes] ) const
    642630{
    643631    const QwtInterval boundingInterval = align( interval, stepSize );
    … …  
    656644        ticks[i] = strip( ticks[i], interval );
    657645
    658         // ticks very close to 0.0 are
    659         // explicitely set to 0.0
     646        // ticks very close to 0.0 are explicitly set to 0.0
    660647
    661648        for ( int j = 0; j < ticks[i].count(); j++ )
    … …  
    674661
    675662   \return Calculated ticks
    676 */
    677 QList<double> QwtLinearScaleEngine::buildMajorTicks(
    678     const QwtInterval &interval, double stepSize ) const
     663 */
     664QList< double > QwtLinearScaleEngine::buildMajorTicks(
     665    const QwtInterval& interval, double stepSize ) const
    679666{
    680667    int numTicks = qRound( interval.width() / stepSize ) + 1;
    … …  
    682669        numTicks = 10000;
    683670
    684     QList<double> ticks;
     671    QList< double > ticks;
     672    ticks.reserve( numTicks );
    685673
    686674    ticks += interval.minValue();
    … …  
    701689   \param mediumTicks Array to be filled with the calculated medium ticks
    702690
    703 */
     691 */
    704692void QwtLinearScaleEngine::buildMinorTicks(
    705     const QList<double>& majorTicks,
     693    const QList< double >& majorTicks,
    706694    int maxMinorSteps, double stepSize,
    707     QList<double> &minorTicks,
    708     QList<double> &mediumTicks ) const
     695    QList< double >& minorTicks,
     696    QList< double >& mediumTicks ) const
    709697{
    710698    double minStep = qwtStepSize( stepSize, maxMinorSteps, base() );
    … …  
    713701
    714702    // # ticks per interval
    715     const int numTicks = qCeil( qAbs( stepSize / minStep ) ) - 1;
     703    const int numTicks = qwtCeil( qAbs( stepSize / minStep ) ) - 1;
    716704
    717705    int medIndex = -1;
    … …  
    741729
    742730/*!
    743   \brief Align an interval to a step size
    744 
    745   The limits of an interval are aligned that both are integer
    746   multiples of the step size.
    747 
    748   \param interval Interval
    749   \param stepSize Step size
    750 
    751   \return Aligned interval
    752 */
     731   \brief Align an interval to a step size
     732
     733   The limits of an interval are aligned that both are integer
     734   multiples of the step size.
     735
     736   \param interval Interval
     737   \param stepSize Step size
     738
     739   \return Aligned interval
     740 */
    753741QwtInterval QwtLinearScaleEngine::align(
    754     const QwtInterval &interval, double stepSize ) const
     742    const QwtInterval& interval, double stepSize ) const
    755743{
    756744    double x1 = interval.minValue();
    … …  
    761749
    762750    const double eps = 0.000000000001; // since Qt 4.8: qFuzzyIsNull
    763     if ( -DBL_MAX + stepSize <= x1 )
     751    const double max = std::numeric_limits< double >::max();
     752
     753    if ( -max + stepSize <= x1 )
    764754    {
    765755        const double x = QwtScaleArithmetic::floorEps( x1, stepSize );
    … …  
    768758    }
    769759
    770     if ( DBL_MAX - stepSize >= x2 )
     760    if ( max - stepSize >= x2 )
    771761    {
    772762        const double x = QwtScaleArithmetic::ceilEps( x2, stepSize );
    … …  
    779769
    780770/*!
    781   Constructor
    782 
    783   \param base Base of the scale engine
    784   \sa setBase()
     771   Constructor
     772
     773   \param base Base of the scale engine
     774   \sa setBase()
    785775 */
    786776QwtLogScaleEngine::QwtLogScaleEngine( uint base ):
    … …  
    804794
    805795   \sa QwtScaleEngine::setAttribute()
    806 */
     796 */
    807797void QwtLogScaleEngine::autoScale( int maxNumSteps,
    808     double &x1, double &x2, double &stepSize ) const
     798    double& x1, double& x2, double& stepSize ) const
    809799{
    810800    if ( x1 > x2 )
    … …  
    813803    const double logBase = base();
    814804
    815     QwtInterval interval( x1 / qPow( logBase, lowerMargin() ),
    816         x2 * qPow( logBase, upperMargin() ) );
     805    QwtInterval interval( x1 / std::pow( logBase, lowerMargin() ),
     806        x2 * std::pow( logBase, upperMargin() ) );
    817807
    818808    if ( interval.maxValue() / interval.minValue() < logBase )
    … …  
    828818
    829819        QwtInterval linearInterval = QwtInterval( x1, x2 ).normalized();
    830         linearInterval = linearInterval.limited( LOG_MIN, LOG_MAX );
     820        linearInterval = linearInterval.limited(
     821            QwtLogTransform::LogMin, QwtLogTransform::LogMax );
    831822
    832823        if ( linearInterval.maxValue() / linearInterval.minValue() < logBase )
    833824        {
    834             // the aligned scale is still less than one step
    835 
    836 #if 1
    837             // this code doesn't make any sense, but for compatibility
    838             // reasons we keep it until 6.2. But it will be ignored
    839             // in divideScale
    840 
    841             if ( stepSize < 0.0 )
    842                 stepSize = -qwtLog( logBase, qAbs( stepSize ) );
    843             else
    844                 stepSize = qwtLog( logBase, stepSize );
    845 #endif
    846 
     825            stepSize = 0.0;
    847826            return;
    848827        }
    … …  
    850829
    851830    double logRef = 1.0;
    852     if ( reference() > LOG_MIN / 2 )
    853         logRef = qMin( reference(), LOG_MAX / 2 );
     831    if ( reference() > QwtLogTransform::LogMin / 2 )
     832        logRef = qwtMinF( reference(), QwtLogTransform::LogMax / 2 );
    854833
    855834    if ( testAttribute( QwtScaleEngine::Symmetric ) )
    856835    {
    857         const double delta = qMax( interval.maxValue() / logRef,
     836        const double delta = qwtMaxF( interval.maxValue() / logRef,
    858837            logRef / interval.minValue() );
    859838        interval.setInterval( logRef / delta, logRef * delta );
    … …  
    863842        interval = interval.extend( logRef );
    864843
    865     interval = interval.limited( LOG_MIN, LOG_MAX );
     844    interval = interval.limited( QwtLogTransform::LogMin, QwtLogTransform::LogMax );
    866845
    867846    if ( interval.width() == 0.0 )
    … …  
    897876
    898877   \return Calculated scale division
    899 */
     878 */
    900879QwtScaleDiv QwtLogScaleEngine::divideScale( double x1, double x2,
    901880    int maxMajorSteps, int maxMinorSteps, double stepSize ) const
    902881{
    903882    QwtInterval interval = QwtInterval( x1, x2 ).normalized();
    904     interval = interval.limited( LOG_MIN, LOG_MAX );
     883    interval = interval.limited( QwtLogTransform::LogMin, QwtLogTransform::LogMax );
    905884
    906885    if ( interval.width() <= 0 )
    … …  
    937916    if ( stepSize != 0.0 )
    938917    {
    939         QList<double> ticks[QwtScaleDiv::NTickTypes];
     918        QList< double > ticks[QwtScaleDiv::NTickTypes];
    940919        buildTicks( interval, stepSize, maxMinorSteps, ticks );
    941920
    … …  
    958937
    959938   \sa buildMajorTicks(), buildMinorTicks
    960 */
     939 */
    961940void QwtLogScaleEngine::buildTicks(
    962941    const QwtInterval& interval, double stepSize, int maxMinorSteps,
    963     QList<double> ticks[QwtScaleDiv::NTickTypes] ) const
     942    QList< double > ticks[QwtScaleDiv::NTickTypes] ) const
    964943{
    965944    const QwtInterval boundingInterval = align( interval, stepSize );
    … …  
    985964
    986965   \return Calculated ticks
    987 */
    988 QList<double> QwtLogScaleEngine::buildMajorTicks(
    989     const QwtInterval &interval, double stepSize ) const
     966 */
     967QList< double > QwtLogScaleEngine::buildMajorTicks(
     968    const QwtInterval& interval, double stepSize ) const
    990969{
    991970    double width = qwtLogInterval( base(), interval ).width();
    … …  
    995974        numTicks = 10000;
    996975
    997     const double lxmin = ::log( interval.minValue() );
    998     const double lxmax = ::log( interval.maxValue() );
     976    const double lxmin = std::log( interval.minValue() );
     977    const double lxmax = std::log( interval.maxValue() );
    999978    const double lstep = ( lxmax - lxmin ) / double( numTicks - 1 );
    1000979
    1001     QList<double> ticks;
     980    QList< double > ticks;
     981    ticks.reserve( numTicks );
    1002982
    1003983    ticks += interval.minValue();
    1004984
    1005985    for ( int i = 1; i < numTicks - 1; i++ )
    1006         ticks += qExp( lxmin + double( i ) * lstep );
     986        ticks += std::exp( lxmin + double( i ) * lstep );
    1007987
    1008988    ticks += interval.maxValue();
    … …  
    1019999   \param minorTicks Array to be filled with the calculated minor ticks
    10201000   \param mediumTicks Array to be filled with the calculated medium ticks
    1021 */
     1001 */
    10221002void QwtLogScaleEngine::buildMinorTicks(
    1023     const QList<double> &majorTicks,
     1003    const QList< double >& majorTicks,
    10241004    int maxMinorSteps, double stepSize,
    1025     QList<double> &minorTicks,
    1026     QList<double> &mediumTicks ) const
     1005    QList< double >& minorTicks,
     1006    QList< double >& mediumTicks ) const
    10271007{
    10281008    const double logBase = base();
    … …  
    10811061
    10821062        // Do the minor steps fit into the interval?
    1083         if ( qwtFuzzyCompare( ( numTicks +  1 ) * minStep,
     1063        if ( qwtFuzzyCompare( ( numTicks + 1 ) * minStep,
    10841064            stepSize, stepSize ) > 0 )
    10851065        {
    … …  
    10951075
    10961076        // substep factor = base^substeps
    1097         const qreal minFactor = qMax( qPow( logBase, minStep ), qreal( logBase ) );
     1077        const qreal minFactor = qwtMaxF( std::pow( logBase, minStep ), logBase );
    10981078
    10991079        for ( int i = 0; i < majorTicks.count(); i++ )
    … …  
    11141094
    11151095/*!
    1116   \brief Align an interval to a step size
    1117 
    1118   The limits of an interval are aligned that both are integer
    1119   multiples of the step size.
    1120 
    1121   \param interval Interval
    1122   \param stepSize Step size
    1123 
    1124   \return Aligned interval
    1125 */
     1096   \brief Align an interval to a step size
     1097
     1098   The limits of an interval are aligned that both are integer
     1099   multiples of the step size.
     1100
     1101   \param interval Interval
     1102   \param stepSize Step size
     1103
     1104   \return Aligned interval
     1105 */
    11261106QwtInterval QwtLogScaleEngine::align(
    1127     const QwtInterval &interval, double stepSize ) const
     1107    const QwtInterval& interval, double stepSize ) const
    11281108{
    11291109    const QwtInterval intv = qwtLogInterval( base(), interval );
  • trunk/BNC/qwt/qwt_scale_engine.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_scale_div.h"
    15 #include "qwt_interval.h"
    16 
     15
     16class QwtInterval;
    1717class QwtTransform;
    1818
    1919/*!
    20   \brief Arithmetic including a tolerance
    21 */
     20   \brief Arithmetic including a tolerance
     21 */
    2222class QWT_EXPORT QwtScaleArithmetic
    2323{
    24 public:
     24  public:
    2525    static double ceilEps( double value, double intervalSize );
    2626    static double floorEps( double value, double intervalSize );
    … …  
    3333
    3434/*!
    35   \brief Base class for scale engines.
    36 
    37   A scale engine tries to find "reasonable" ranges and step sizes
    38   for scales.
    39 
    40   The layout of the scale can be varied with setAttribute().
    41 
    42   Qwt offers implementations for logarithmic and linear scales.
    43 */
     35   \brief Base class for scale engines.
     36
     37   A scale engine tries to find "reasonable" ranges and step sizes
     38   for scales.
     39
     40   The layout of the scale can be varied with setAttribute().
     41
     42   Qwt offers implementations for logarithmic and linear scales.
     43 */
    4444
    4545class QWT_EXPORT QwtScaleEngine
    4646{
    47 public:
     47  public:
    4848    /*!
    4949       Layout attributes
    … …  
    7676    };
    7777
    78     //! Layout attributes
    79     typedef QFlags<Attribute> Attributes;
     78    Q_DECLARE_FLAGS( Attributes, Attribute )
    8079
    8180    explicit QwtScaleEngine( uint base = 10 );
    … …  
    9998
    10099    /*!
    101       Align and divide an interval
    102 
    103       \param maxNumSteps Max. number of steps
    104       \param x1 First limit of the interval (In/Out)
    105       \param x2 Second limit of the interval (In/Out)
    106       \param stepSize Step size (Return value)
    107     */
     100       Align and divide an interval
     101
     102       \param maxNumSteps Max. number of steps
     103       \param x1 First limit of the interval (In/Out)
     104       \param x2 Second limit of the interval (In/Out)
     105       \param stepSize Step size (Return value)
     106     */
    108107    virtual void autoScale( int maxNumSteps,
    109         double &x1, double &x2, double &stepSize ) const = 0;
     108        double& x1, double& x2, double& stepSize ) const = 0;
    110109
    111110    /*!
    112       \brief Calculate a scale division
    113 
    114       \param x1 First interval limit
    115       \param x2 Second interval limit
    116       \param maxMajorSteps Maximum for the number of major steps
    117       \param maxMinorSteps Maximum number of minor steps
    118       \param stepSize Step size. If stepSize == 0.0, the scaleEngine
     111       \brief Calculate a scale division
     112
     113       \param x1 First interval limit
     114       \param x2 Second interval limit
     115       \param maxMajorSteps Maximum for the number of major steps
     116       \param maxMinorSteps Maximum number of minor steps
     117       \param stepSize Step size. If stepSize == 0.0, the scaleEngine
    119118                   calculates one.
    120119
    121       \return Calculated scale division
    122     */
     120       \return Calculated scale division
     121     */
    123122    virtual QwtScaleDiv divideScale( double x1, double x2,
    124123        int maxMajorSteps, int maxMinorSteps,
    125124        double stepSize = 0.0 ) const = 0;
    126125
    127     void setTransformation( QwtTransform * );
    128     QwtTransform *transformation() const;
    129 
    130 protected:
    131     bool contains( const QwtInterval &, double value ) const;
    132     QList<double> strip( const QList<double>&, const QwtInterval & ) const;
     126    void setTransformation( QwtTransform* );
     127    QwtTransform* transformation() const;
     128
     129  protected:
     130    bool contains( const QwtInterval&, double value ) const;
     131    QList< double > strip( const QList< double >&, const QwtInterval& ) const;
    133132
    134133    double divideInterval( double intervalSize, int numSteps ) const;
    … …  
    136135    QwtInterval buildInterval( double value ) const;
    137136
    138 private:
     137  private:
     138    Q_DISABLE_COPY(QwtScaleEngine)
     139
    139140    class PrivateData;
    140     PrivateData *d_data;
    141 };
    142 
    143 /*!
    144   \brief A scale engine for linear scales
    145 
    146   The step size will fit into the pattern
    147   \f$\left\{ 1,2,5\right\} \cdot 10^{n}\f$, where n is an integer.
    148 */
    149 
    150 class QWT_EXPORT QwtLinearScaleEngine: public QwtScaleEngine
    151 {
    152 public:
    153     QwtLinearScaleEngine( uint base = 10 );
     141    PrivateData* m_data;
     142};
     143
     144/*!
     145   \brief A scale engine for linear scales
     146
     147   The step size will fit into the pattern
     148   \f$\left\{ 1,2,5\right\} \cdot 10^{n}\f$, where n is an integer.
     149 */
     150
     151class QWT_EXPORT QwtLinearScaleEngine : public QwtScaleEngine
     152{
     153  public:
     154    explicit QwtLinearScaleEngine( uint base = 10 );
    154155    virtual ~QwtLinearScaleEngine();
    155156
    156157    virtual void autoScale( int maxNumSteps,
    157         double &x1, double &x2, double &stepSize ) const;
     158        double& x1, double& x2, double& stepSize ) const QWT_OVERRIDE;
    158159
    159160    virtual QwtScaleDiv divideScale( double x1, double x2,
    160161        int maxMajorSteps, int maxMinorSteps,
    161         double stepSize = 0.0 ) const;
    162 
    163 
    164 protected:
     162        double stepSize = 0.0 ) const QWT_OVERRIDE;
     163
     164
     165  protected:
    165166    QwtInterval align( const QwtInterval&, double stepSize ) const;
    166167
    167168    void buildTicks(
    168         const QwtInterval &, double stepSize, int maxMinorSteps,
    169         QList<double> ticks[QwtScaleDiv::NTickTypes] ) const;
    170 
    171     QList<double> buildMajorTicks(
    172         const QwtInterval &interval, double stepSize ) const;
    173 
    174     void buildMinorTicks( const QList<double>& majorTicks,
     169        const QwtInterval&, double stepSize, int maxMinorSteps,
     170        QList< double > ticks[QwtScaleDiv::NTickTypes] ) const;
     171
     172    QList< double > buildMajorTicks(
     173        const QwtInterval& interval, double stepSize ) const;
     174
     175    void buildMinorTicks( const QList< double >& majorTicks,
    175176        int maxMinorSteps, double stepSize,
    176         QList<double> &minorTicks, QList<double> &mediumTicks ) const;
    177 };
    178 
    179 /*!
    180   \brief A scale engine for logarithmic scales
    181 
    182   The step size is measured in *decades*
    183   and the major step size will be adjusted to fit the pattern
    184   \f$\left\{ 1,2,3,5\right\} \cdot 10^{n}\f$, where n is a natural number
    185   including zero.
    186 
    187   \warning the step size as well as the margins are measured in *decades*.
    188 */
    189 
    190 class QWT_EXPORT QwtLogScaleEngine: public QwtScaleEngine
    191 {
    192 public:
    193     QwtLogScaleEngine( uint base = 10 );
     177        QList< double >& minorTicks, QList< double >& mediumTicks ) const;
     178};
     179
     180/*!
     181   \brief A scale engine for logarithmic scales
     182
     183   The step size is measured in *decades*
     184   and the major step size will be adjusted to fit the pattern
     185   \f$\left\{ 1,2,3,5\right\} \cdot 10^{n}\f$, where n is a natural number
     186   including zero.
     187
     188   \warning the step size as well as the margins are measured in *decades*.
     189 */
     190
     191class QWT_EXPORT QwtLogScaleEngine : public QwtScaleEngine
     192{
     193  public:
     194    explicit QwtLogScaleEngine( uint base = 10 );
    194195    virtual ~QwtLogScaleEngine();
    195196
    196197    virtual void autoScale( int maxNumSteps,
    197         double &x1, double &x2, double &stepSize ) const;
     198        double& x1, double& x2, double& stepSize ) const QWT_OVERRIDE;
    198199
    199200    virtual QwtScaleDiv divideScale( double x1, double x2,
    200201        int maxMajorSteps, int maxMinorSteps,
    201         double stepSize = 0.0 ) const;
    202 
    203 protected:
     202        double stepSize = 0.0 ) const QWT_OVERRIDE;
     203
     204  protected:
    204205    QwtInterval align( const QwtInterval&, double stepSize ) const;
    205206
    206207    void buildTicks(
    207         const QwtInterval &, double stepSize, int maxMinorSteps,
    208         QList<double> ticks[QwtScaleDiv::NTickTypes] ) const;
    209 
    210     QList<double> buildMajorTicks(
    211         const QwtInterval &interval, double stepSize ) const;
    212 
    213     void buildMinorTicks( const QList<double>& majorTicks,
     208        const QwtInterval&, double stepSize, int maxMinorSteps,
     209        QList< double > ticks[QwtScaleDiv::NTickTypes] ) const;
     210
     211    QList< double > buildMajorTicks(
     212        const QwtInterval& interval, double stepSize ) const;
     213
     214    void buildMinorTicks( const QList< double >& majorTicks,
    214215        int maxMinorSteps, double stepSize,
    215         QList<double> &minorTicks, QList<double> &mediumTicks ) const;
     216        QList< double >& minorTicks, QList< double >& mediumTicks ) const;
    216217};
    217218
  • trunk/BNC/qwt/qwt_scale_map.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_scale_map.h"
    1111#include "qwt_math.h"
     12
    1213#include <qrect.h>
    1314#include <qdebug.h>
    1415
    1516/*!
    16   \brief Constructor
    17 
    18   The scale and paint device intervals are both set to [0,1].
    19 */
    20 QwtScaleMap::QwtScaleMap():
    21     d_s1( 0.0 ),
    22     d_s2( 1.0 ),
    23     d_p1( 0.0 ),
    24     d_p2( 1.0 ),
    25     d_cnv( 1.0 ),
    26     d_ts1( 0.0 ),
    27     d_transform( NULL )
     17   \brief Constructor
     18
     19   The scale and paint device intervals are both set to [0,1].
     20 */
     21QwtScaleMap::QwtScaleMap()
     22    : m_s1( 0.0 )
     23    , m_s2( 1.0 )
     24    , m_p1( 0.0 )
     25    , m_p2( 1.0 )
     26    , m_cnv( 1.0 )
     27    , m_ts1( 0.0 )
     28    , m_transform( NULL )
    2829{
    2930}
    3031
    3132//! Copy constructor
    32 QwtScaleMap::QwtScaleMap( const QwtScaleMap& other ):
    33     d_s1( other.d_s1 ),
    34     d_s2( other.d_s2 ),
    35     d_p1( other.d_p1 ),
    36     d_p2( other.d_p2 ),
    37     d_cnv( other.d_cnv ),
    38     d_ts1( other.d_ts1 ),
    39     d_transform( NULL )
    40 {
    41     if ( other.d_transform )
    42         d_transform = other.d_transform->copy();
    43 }
    44 
    45 /*!
    46   Destructor
    47 */
     33QwtScaleMap::QwtScaleMap( const QwtScaleMap& other )
     34    : m_s1( other.m_s1 )
     35    , m_s2( other.m_s2 )
     36    , m_p1( other.m_p1 )
     37    , m_p2( other.m_p2 )
     38    , m_cnv( other.m_cnv )
     39    , m_ts1( other.m_ts1 )
     40    , m_transform( NULL )
     41{
     42    if ( other.m_transform )
     43        m_transform = other.m_transform->copy();
     44}
     45
     46/*!
     47   Destructor
     48 */
    4849QwtScaleMap::~QwtScaleMap()
    4950{
    50     delete d_transform;
     51    delete m_transform;
    5152}
    5253
    5354//! Assignment operator
    54 QwtScaleMap &QwtScaleMap::operator=( const QwtScaleMap & other )
    55 {
    56     d_s1 = other.d_s1;
    57     d_s2 = other.d_s2;
    58     d_p1 = other.d_p1;
    59     d_p2 = other.d_p2;
    60     d_cnv = other.d_cnv;
    61     d_ts1 = other.d_ts1;
    62 
    63     delete d_transform;
    64     d_transform = NULL;
    65 
    66     if ( other.d_transform )
    67         d_transform = other.d_transform->copy();
     55QwtScaleMap& QwtScaleMap::operator=( const QwtScaleMap& other )
     56{
     57    m_s1 = other.m_s1;
     58    m_s2 = other.m_s2;
     59    m_p1 = other.m_p1;
     60    m_p2 = other.m_p2;
     61    m_cnv = other.m_cnv;
     62    m_ts1 = other.m_ts1;
     63
     64    delete m_transform;
     65    m_transform = NULL;
     66
     67    if ( other.m_transform )
     68        m_transform = other.m_transform->copy();
    6869
    6970    return *this;
    … …  
    7273/*!
    7374   Initialize the map with a transformation
    74 */
    75 void QwtScaleMap::setTransformation( QwtTransform *transform )
    76 {
    77     if ( transform != d_transform )
     75 */
     76void QwtScaleMap::setTransformation( QwtTransform* transform )
     77{
     78    if ( transform != m_transform )
    7879    {
    79         delete d_transform;
    80         d_transform = transform;
     80        delete m_transform;
     81        m_transform = transform;
    8182    }
    8283
    83     setScaleInterval( d_s1, d_s2 );
     84    setScaleInterval( m_s1, m_s2 );
    8485}
    8586
    8687//! Get the transformation
    87 const QwtTransform *QwtScaleMap::transformation() const
    88 {
    89     return d_transform;
    90 }
    91 
    92 /*!
    93   \brief Specify the borders of the scale interval
    94   \param s1 first border
    95   \param s2 second border
    96   \warning scales might be aligned to
     88const QwtTransform* QwtScaleMap::transformation() const
     89{
     90    return m_transform;
     91}
     92
     93/*!
     94   \brief Specify the borders of the scale interval
     95   \param s1 first border
     96   \param s2 second border
     97   \warning scales might be aligned to
    9798           transformation depending boundaries
    98 */
     99 */
    99100void QwtScaleMap::setScaleInterval( double s1, double s2 )
    100101{
    101     d_s1 = s1;
    102     d_s2 = s2;
    103 
    104     if ( d_transform )
     102    m_s1 = s1;
     103    m_s2 = s2;
     104
     105    if ( m_transform )
    105106    {
    106         d_s1 = d_transform->bounded( d_s1 );
    107         d_s2 = d_transform->bounded( d_s2 );
     107        m_s1 = m_transform->bounded( m_s1 );
     108        m_s2 = m_transform->bounded( m_s2 );
    108109    }
    109110
    … …  
    112113
    113114/*!
    114   \brief Specify the borders of the paint device interval
    115   \param p1 first border
    116   \param p2 second border
    117 */
     115   \brief Specify the borders of the paint device interval
     116   \param p1 first border
     117   \param p2 second border
     118 */
    118119void QwtScaleMap::setPaintInterval( double p1, double p2 )
    119120{
    120     d_p1 = p1;
    121     d_p2 = p2;
     121    m_p1 = p1;
     122    m_p2 = p2;
    122123
    123124    updateFactor();
    … …  
    126127void QwtScaleMap::updateFactor()
    127128{
    128     d_ts1 = d_s1;
    129     double ts2 = d_s2;
    130 
    131     if ( d_transform )
     129    m_ts1 = m_s1;
     130    double ts2 = m_s2;
     131
     132    if ( m_transform )
    132133    {
    133         d_ts1 = d_transform->transform( d_ts1 );
    134         ts2 = d_transform->transform( ts2 );
     134        m_ts1 = m_transform->transform( m_ts1 );
     135        ts2 = m_transform->transform( ts2 );
    135136    }
    136137
    137     d_cnv = 1.0;
    138     if ( d_ts1 != ts2 )
    139         d_cnv = ( d_p2 - d_p1 ) / ( ts2 - d_ts1 );
     138    m_cnv = 1.0;
     139    if ( m_ts1 != ts2 )
     140        m_cnv = ( m_p2 - m_p1 ) / ( ts2 - m_ts1 );
    140141}
    141142
    … …  
    149150
    150151   \sa invTransform()
    151 */
    152 QRectF QwtScaleMap::transform( const QwtScaleMap &xMap,
    153     const QwtScaleMap &yMap, const QRectF &rect )
     152 */
     153QRectF QwtScaleMap::transform( const QwtScaleMap& xMap,
     154    const QwtScaleMap& yMap, const QRectF& rect )
    154155{
    155156    double x1 = xMap.transform( rect.left() );
    … …  
    183184   \return Position in scale coordinates
    184185   \sa transform()
    185 */
    186 QPointF QwtScaleMap::invTransform( const QwtScaleMap &xMap,
    187     const QwtScaleMap &yMap, const QPointF &pos )
     186 */
     187QPointF QwtScaleMap::invTransform( const QwtScaleMap& xMap,
     188    const QwtScaleMap& yMap, const QPointF& pos )
    188189{
    189190    return QPointF(
    190191        xMap.invTransform( pos.x() ),
    191192        yMap.invTransform( pos.y() )
    192     );
     193        );
    193194}
    194195
    … …  
    202203
    203204   \sa invTransform()
    204 */
    205 QPointF QwtScaleMap::transform( const QwtScaleMap &xMap,
    206     const QwtScaleMap &yMap, const QPointF &pos )
     205 */
     206QPointF QwtScaleMap::transform( const QwtScaleMap& xMap,
     207    const QwtScaleMap& yMap, const QPointF& pos )
    207208{
    208209    return QPointF(
    209210        xMap.transform( pos.x() ),
    210211        yMap.transform( pos.y() )
    211     );
     212        );
    212213}
    213214
    … …  
    220221   \return Rectangle in scale coordinates
    221222   \sa transform()
    222 */
    223 QRectF QwtScaleMap::invTransform( const QwtScaleMap &xMap,
    224     const QwtScaleMap &yMap, const QRectF &rect )
     223 */
     224QRectF QwtScaleMap::invTransform( const QwtScaleMap& xMap,
     225    const QwtScaleMap& yMap, const QRectF& rect )
    225226{
    226227    const double x1 = xMap.invTransform( rect.left() );
    … …  
    235236#ifndef QT_NO_DEBUG_STREAM
    236237
    237 QDebug operator<<( QDebug debug, const QwtScaleMap &map )
     238QDebug operator<<( QDebug debug, const QwtScaleMap& map )
    238239{
    239240    debug.nospace() << "QwtScaleMap("
    240         << map.transformation()
    241         << ", s:" << map.s1() << "->" << map.s2()
    242         << ", p:" << map.p1() << "->" << map.p2()
    243         << ")";
     241                    << map.transformation()
     242                    << ", s:" << map.s1() << "->" << map.s2()
     243                    << ", p:" << map.p1() << "->" << map.p2()
     244                    << ")";
    244245
    245246    return debug.space();
  • trunk/BNC/qwt/qwt_scale_map.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_transform.h"
    15 #include <qrect.h>
    1615
    17 #ifndef QT_NO_DEBUG_STREAM
    18 #include <qdebug.h>
    19 #endif
    20 
     16class QPointF;
    2117class QRectF;
    2218
    … …  
    2723   of a scale into the linear coordinate system of a paint device
    2824   and vice versa.
    29 */
     25 */
    3026class QWT_EXPORT QwtScaleMap
    3127{
    32 public:
     28  public:
    3329    QwtScaleMap();
    3430    QwtScaleMap( const QwtScaleMap& );
    … …  
    3632    ~QwtScaleMap();
    3733
    38     QwtScaleMap &operator=( const QwtScaleMap & );
     34    QwtScaleMap& operator=( const QwtScaleMap& );
    3935
    40     void setTransformation( QwtTransform * );
    41     const QwtTransform *transformation() const;
     36    void setTransformation( QwtTransform* );
     37    const QwtTransform* transformation() const;
    4238
    4339    void setPaintInterval( double p1, double p2 );
    … …  
    5652    double sDist() const;
    5753
    58     static QRectF transform( const QwtScaleMap &,
    59         const QwtScaleMap &, const QRectF & );
    60     static QRectF invTransform( const QwtScaleMap &,
    61         const QwtScaleMap &, const QRectF & );
     54    static QRectF transform( const QwtScaleMap&,
     55        const QwtScaleMap&, const QRectF& );
    6256
    63     static QPointF transform( const QwtScaleMap &,
    64         const QwtScaleMap &, const QPointF & );
    65     static QPointF invTransform( const QwtScaleMap &,
    66         const QwtScaleMap &, const QPointF & );
     57    static QRectF invTransform( const QwtScaleMap&,
     58        const QwtScaleMap&, const QRectF& );
     59
     60    static QPointF transform( const QwtScaleMap&,
     61        const QwtScaleMap&, const QPointF& );
     62
     63    static QPointF invTransform( const QwtScaleMap&,
     64        const QwtScaleMap&, const QPointF& );
    6765
    6866    bool isInverting() const;
    6967
    70 private:
     68  private:
    7169    void updateFactor();
    7270
    73     double d_s1, d_s2;     // scale interval boundaries
    74     double d_p1, d_p2;     // paint device interval boundaries
     71    double m_s1, m_s2;     // scale interval boundaries
     72    double m_p1, m_p2;     // paint device interval boundaries
    7573
    76     double d_cnv;       // conversion factor
    77     double d_ts1;
     74    double m_cnv;       // conversion factor
     75    double m_ts1;
    7876
    79     QwtTransform *d_transform;
     77    QwtTransform* m_transform;
    8078};
    8179
    8280/*!
    8381    \return First border of the scale interval
    84 */
     82 */
    8583inline double QwtScaleMap::s1() const
    8684{
    87     return d_s1;
     85    return m_s1;
    8886}
    8987
    9088/*!
    9189    \return Second border of the scale interval
    92 */
     90 */
    9391inline double QwtScaleMap::s2() const
    9492{
    95     return d_s2;
     93    return m_s2;
    9694}
    9795
    9896/*!
    9997    \return First border of the paint interval
    100 */
     98 */
    10199inline double QwtScaleMap::p1() const
    102100{
    103     return d_p1;
     101    return m_p1;
    104102}
    105103
    106104/*!
    107105    \return Second border of the paint interval
    108 */
     106 */
    109107inline double QwtScaleMap::p2() const
    110108{
    111     return d_p2;
     109    return m_p2;
    112110}
    113111
    114112/*!
    115113    \return qwtAbs(p2() - p1())
    116 */
     114 */
    117115inline double QwtScaleMap::pDist() const
    118116{
    119     return qAbs( d_p2 - d_p1 );
     117    return qAbs( m_p2 - m_p1 );
    120118}
    121119
    122120/*!
    123121    \return qwtAbs(s2() - s1())
    124 */
     122 */
    125123inline double QwtScaleMap::sDist() const
    126124{
    127     return qAbs( d_s2 - d_s1 );
     125    return qAbs( m_s2 - m_s1 );
    128126}
    129127
    130128/*!
    131   Transform a point related to the scale interval into an point
    132   related to the interval of the paint device
     129   Transform a point related to the scale interval into an point
     130   related to the interval of the paint device
    133131
    134   \param s Value relative to the coordinates of the scale
    135   \return Transformed value
     132   \param s Value relative to the coordinates of the scale
     133   \return Transformed value
    136134
    137   \sa invTransform()
    138 */
     135   \sa invTransform()
     136 */
    139137inline double QwtScaleMap::transform( double s ) const
    140138{
    141     if ( d_transform )
    142         s = d_transform->transform( s );
     139    if ( m_transform )
     140        s = m_transform->transform( s );
    143141
    144     return d_p1 + ( s - d_ts1 ) * d_cnv;
     142    return m_p1 + ( s - m_ts1 ) * m_cnv;
    145143}
    146144
    147145/*!
    148   Transform an paint device value into a value in the
    149   interval of the scale.
     146   Transform an paint device value into a value in the
     147   interval of the scale.
    150148
    151   \param p Value relative to the coordinates of the paint device
    152   \return Transformed value
     149   \param p Value relative to the coordinates of the paint device
     150   \return Transformed value
    153151
    154   \sa transform()
    155 */
     152   \sa transform()
     153 */
    156154inline double QwtScaleMap::invTransform( double p ) const
    157155{
    158     double s = d_ts1 + ( p - d_p1 ) / d_cnv;
    159     if ( d_transform )
    160         s = d_transform->invTransform( s );
     156    double s = m_ts1 + ( p - m_p1 ) / m_cnv;
     157    if ( m_transform )
     158        s = m_transform->invTransform( s );
    161159
    162160    return s;
    … …  
    166164inline bool QwtScaleMap::isInverting() const
    167165{
    168     return ( ( d_p1 < d_p2 ) != ( d_s1 < d_s2 ) );
     166    return ( ( m_p1 < m_p2 ) != ( m_s1 < m_s2 ) );
    169167}
    170168
    171169#ifndef QT_NO_DEBUG_STREAM
    172 QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap & );
     170QWT_EXPORT QDebug operator<<( QDebug, const QwtScaleMap& );
    173171#endif
    174172
  • trunk/BNC/qwt/qwt_scale_widget.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1515#include "qwt_scale_div.h"
    1616#include "qwt_text.h"
     17#include "qwt_interval.h"
    1718#include "qwt_scale_engine.h"
     19
    1820#include <qpainter.h>
    1921#include <qevent.h>
    20 #include <qmath.h>
    2122#include <qstyle.h>
    2223#include <qstyleoption.h>
    2324#include <qapplication.h>
     25#include <qmargins.h>
    2426
    2527class QwtScaleWidget::PrivateData
    2628{
    27 public:
    28     PrivateData():
    29         scaleDraw( NULL )
     29  public:
     30    PrivateData()
     31        : scaleDraw( NULL )
    3032    {
    3133        colorBar.colorMap = NULL;
    … …  
    3840    }
    3941
    40     QwtScaleDraw *scaleDraw;
     42    QwtScaleDraw* scaleDraw;
    4143
    4244    int borderDist[2];
    … …  
    5658        int width;
    5759        QwtInterval interval;
    58         QwtColorMap *colorMap;
     60        QwtColorMap* colorMap;
    5961    } colorBar;
    6062};
    6163
    6264/*!
    63   \brief Create a scale with the position QwtScaleWidget::Left
    64   \param parent Parent widget
    65 */
    66 QwtScaleWidget::QwtScaleWidget( QWidget *parent ):
    67     QWidget( parent )
     65   \brief Create a scale with the position QwtScaleWidget::Left
     66   \param parent Parent widget
     67 */
     68QwtScaleWidget::QwtScaleWidget( QWidget* parent )
     69    : QWidget( parent )
    6870{
    6971    initScale( QwtScaleDraw::LeftScale );
    … …  
    7173
    7274/*!
    73   \brief Constructor
    74   \param align Alignment.
    75   \param parent Parent widget
    76 */
    77 QwtScaleWidget::QwtScaleWidget(
    78         QwtScaleDraw::Alignment align, QWidget *parent ):
    79     QWidget( parent )
     75   \brief Constructor
     76   \param align Alignment.
     77   \param parent Parent widget
     78 */
     79QwtScaleWidget::QwtScaleWidget( QwtScaleDraw::Alignment align, QWidget* parent )
     80    : QWidget( parent )
    8081{
    8182    initScale( align );
    … …  
    8586QwtScaleWidget::~QwtScaleWidget()
    8687{
    87     delete d_data;
     88    delete m_data;
    8889}
    8990
    … …  
    9192void QwtScaleWidget::initScale( QwtScaleDraw::Alignment align )
    9293{
    93     d_data = new PrivateData;
    94 
    95     d_data->layoutFlags = 0;
     94    m_data = new PrivateData;
     95
    9696    if ( align == QwtScaleDraw::RightScale )
    97         d_data->layoutFlags |= TitleInverted;
    98 
    99     d_data->borderDist[0] = 0;
    100     d_data->borderDist[1] = 0;
    101     d_data->minBorderDist[0] = 0;
    102     d_data->minBorderDist[1] = 0;
    103     d_data->margin = 4;
    104     d_data->titleOffset = 0;
    105     d_data->spacing = 2;
    106 
    107     d_data->scaleDraw = new QwtScaleDraw;
    108     d_data->scaleDraw->setAlignment( align );
    109     d_data->scaleDraw->setLength( 10 );
    110 
    111     d_data->scaleDraw->setScaleDiv(
     97        m_data->layoutFlags |= TitleInverted;
     98
     99    m_data->borderDist[0] = 0;
     100    m_data->borderDist[1] = 0;
     101    m_data->minBorderDist[0] = 0;
     102    m_data->minBorderDist[1] = 0;
     103    m_data->margin = 4;
     104    m_data->titleOffset = 0;
     105    m_data->spacing = 2;
     106
     107    m_data->scaleDraw = new QwtScaleDraw;
     108    m_data->scaleDraw->setAlignment( align );
     109    m_data->scaleDraw->setLength( 10 );
     110
     111    m_data->scaleDraw->setScaleDiv(
    112112        QwtLinearScaleEngine().divideScale( 0.0, 100.0, 10, 5 ) );
    113113
    114     d_data->colorBar.colorMap = new QwtLinearColorMap();
    115     d_data->colorBar.isEnabled = false;
    116     d_data->colorBar.width = 10;
     114    m_data->colorBar.colorMap = new QwtLinearColorMap();
     115    m_data->colorBar.isEnabled = false;
     116    m_data->colorBar.width = 10;
    117117
    118118    const int flags = Qt::AlignHCenter
    119119        | Qt::TextExpandTabs | Qt::TextWordWrap;
    120     d_data->title.setRenderFlags( flags );
    121     d_data->title.setFont( font() );
     120    m_data->title.setRenderFlags( flags );
     121    m_data->title.setFont( font() );
    122122
    123123    QSizePolicy policy( QSizePolicy::MinimumExpanding,
    124124        QSizePolicy::Fixed );
    125     if ( d_data->scaleDraw->orientation() == Qt::Vertical )
     125    if ( m_data->scaleDraw->orientation() == Qt::Vertical )
    126126        policy.transpose();
    127127
    … …  
    138138
    139139   \sa testLayoutFlag(), LayoutFlag
    140 */
     140 */
    141141void QwtScaleWidget::setLayoutFlag( LayoutFlag flag, bool on )
    142142{
    143     if ( ( ( d_data->layoutFlags & flag ) != 0 ) != on )
     143    if ( ( ( m_data->layoutFlags & flag ) != 0 ) != on )
    144144    {
    145145        if ( on )
    146             d_data->layoutFlags |= flag;
     146            m_data->layoutFlags |= flag;
    147147        else
    148             d_data->layoutFlags &= ~flag;
     148            m_data->layoutFlags &= ~flag;
    149149
    150150        update();
    … …  
    158158   \return true/false
    159159   \sa setLayoutFlag(), LayoutFlag
    160 */
     160 */
    161161bool QwtScaleWidget::testLayoutFlag( LayoutFlag flag ) const
    162162{
    163     return ( d_data->layoutFlags & flag );
    164 }
    165 
    166 /*!
    167   Give title new text contents
    168 
    169   \param title New title
    170   \sa title(), setTitle(const QwtText &);
    171 */
    172 void QwtScaleWidget::setTitle( const QString &title )
    173 {
    174     if ( d_data->title.text() != title )
    175     {
    176         d_data->title.setText( title );
     163    return ( m_data->layoutFlags & flag );
     164}
     165
     166/*!
     167   Give title new text contents
     168
     169   \param title New title
     170   \sa title(), setTitle(const QwtText &);
     171 */
     172void QwtScaleWidget::setTitle( const QString& title )
     173{
     174    if ( m_data->title.text() != title )
     175    {
     176        m_data->title.setText( title );
    177177        layoutScale();
    178178    }
    … …  
    180180
    181181/*!
    182   Give title new text contents
    183 
    184   \param title New title
    185   \sa title()
    186   \warning The title flags are interpreted in
     182   Give title new text contents
     183
     184   \param title New title
     185   \sa title()
     186   \warning The title flags are interpreted in
    187187               direction of the label, AlignTop, AlignBottom can't be set
    188188               as the title will always be aligned to the scale.
    189 */
    190 void QwtScaleWidget::setTitle( const QwtText &title )
     189 */
     190void QwtScaleWidget::setTitle( const QwtText& title )
    191191{
    192192    QwtText t = title;
    … …  
    194194    t.setRenderFlags( flags );
    195195
    196     if ( t != d_data->title )
    197     {
    198         d_data->title = t;
     196    if ( t != m_data->title )
     197    {
     198        m_data->title = t;
    199199        layoutScale();
    200200    }
    … …  
    202202
    203203/*!
    204   Change the alignment
    205 
    206   \param alignment New alignment
    207   \sa alignment()
    208 */
     204   Change the alignment
     205
     206   \param alignment New alignment
     207   \sa alignment()
     208 */
    209209void QwtScaleWidget::setAlignment( QwtScaleDraw::Alignment alignment )
    210210{
    211     if ( d_data->scaleDraw )
    212         d_data->scaleDraw->setAlignment( alignment );
     211    if ( m_data->scaleDraw == NULL )
     212        return;
     213
     214    m_data->scaleDraw->setAlignment( alignment );
    213215
    214216    if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
    215217    {
    216         QSizePolicy policy( QSizePolicy::MinimumExpanding,
    217             QSizePolicy::Fixed );
    218         if ( d_data->scaleDraw->orientation() == Qt::Vertical )
     218        QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
     219        if ( m_data->scaleDraw->orientation() == Qt::Vertical )
    219220            policy.transpose();
    220221
    … …  
    231232    \return position
    232233    \sa setPosition()
    233 */
     234 */
    234235QwtScaleDraw::Alignment QwtScaleWidget::alignment() const
    235236{
    … …  
    241242
    242243/*!
    243   Specify distances of the scale's endpoints from the
    244   widget's borders. The actual borders will never be less
    245   than minimum border distance.
    246   \param dist1 Left or top Distance
    247   \param dist2 Right or bottom distance
    248   \sa borderDist()
    249 */
     244   Specify distances of the scale's endpoints from the
     245   widget's borders. The actual borders will never be less
     246   than minimum border distance.
     247   \param dist1 Left or top Distance
     248   \param dist2 Right or bottom distance
     249   \sa borderDist()
     250 */
    250251void QwtScaleWidget::setBorderDist( int dist1, int dist2 )
    251252{
    252     if ( dist1 != d_data->borderDist[0] || dist2 != d_data->borderDist[1] )
    253     {
    254         d_data->borderDist[0] = dist1;
    255         d_data->borderDist[1] = dist2;
     253    if ( dist1 != m_data->borderDist[0] || dist2 != m_data->borderDist[1] )
     254    {
     255        m_data->borderDist[0] = dist1;
     256        m_data->borderDist[1] = dist2;
    256257        layoutScale();
    257258    }
    … …  
    259260
    260261/*!
    261   \brief Specify the margin to the colorBar/base line.
    262   \param margin Margin
    263   \sa margin()
    264 */
     262   \brief Specify the margin to the colorBar/base line.
     263   \param margin Margin
     264   \sa margin()
     265 */
    265266void QwtScaleWidget::setMargin( int margin )
    266267{
    267268    margin = qMax( 0, margin );
    268     if ( margin != d_data->margin )
    269     {
    270         d_data->margin = margin;
     269    if ( margin != m_data->margin )
     270    {
     271        m_data->margin = margin;
    271272        layoutScale();
    272273    }
    … …  
    274275
    275276/*!
    276   \brief Specify the distance between color bar, scale and title
    277   \param spacing Spacing
    278   \sa spacing()
    279 */
     277   \brief Specify the distance between color bar, scale and title
     278   \param spacing Spacing
     279   \sa spacing()
     280 */
    280281void QwtScaleWidget::setSpacing( int spacing )
    281282{
    282283    spacing = qMax( 0, spacing );
    283     if ( spacing != d_data->spacing )
    284     {
    285         d_data->spacing = spacing;
     284    if ( spacing != m_data->spacing )
     285    {
     286        m_data->spacing = spacing;
    286287        layoutScale();
    287288    }
    … …  
    289290
    290291/*!
    291   \brief Change the alignment for the labels.
    292 
    293   \sa QwtScaleDraw::setLabelAlignment(), setLabelRotation()
    294 */
     292   \brief Change the alignment for the labels.
     293
     294   \sa QwtScaleDraw::setLabelAlignment(), setLabelRotation()
     295 */
    295296void QwtScaleWidget::setLabelAlignment( Qt::Alignment alignment )
    296297{
    297     d_data->scaleDraw->setLabelAlignment( alignment );
     298    m_data->scaleDraw->setLabelAlignment( alignment );
    298299    layoutScale();
    299300}
    300301
    301302/*!
    302   \brief Change the rotation for the labels.
    303   See QwtScaleDraw::setLabelRotation().
    304 
    305   \param rotation Rotation
    306   \sa QwtScaleDraw::setLabelRotation(), setLabelFlags()
    307 */
     303   \brief Change the rotation for the labels.
     304   See QwtScaleDraw::setLabelRotation().
     305
     306   \param rotation Rotation
     307   \sa QwtScaleDraw::setLabelRotation(), setLabelFlags()
     308 */
    308309void QwtScaleWidget::setLabelRotation( double rotation )
    309310{
    310     d_data->scaleDraw->setLabelRotation( rotation );
     311    m_data->scaleDraw->setLabelRotation( rotation );
    311312    layoutScale();
    312313}
    313314
    314315/*!
    315   Set a scale draw
    316 
    317   scaleDraw has to be created with new and will be deleted in
    318   ~QwtScaleWidget() or the next call of setScaleDraw().
    319   scaleDraw will be initialized with the attributes of
    320   the previous scaleDraw object.
    321 
    322   \param scaleDraw ScaleDraw object
    323   \sa scaleDraw()
    324 */
    325 void QwtScaleWidget::setScaleDraw( QwtScaleDraw *scaleDraw )
    326 {
    327     if ( ( scaleDraw == NULL ) || ( scaleDraw == d_data->scaleDraw ) )
     316   Set a scale draw
     317
     318   scaleDraw has to be created with new and will be deleted in
     319   ~QwtScaleWidget() or the next call of setScaleDraw().
     320   scaleDraw will be initialized with the attributes of
     321   the previous scaleDraw object.
     322
     323   \param scaleDraw ScaleDraw object
     324   \sa scaleDraw()
     325 */
     326void QwtScaleWidget::setScaleDraw( QwtScaleDraw* scaleDraw )
     327{
     328    if ( ( scaleDraw == NULL ) || ( scaleDraw == m_data->scaleDraw ) )
    328329        return;
    329330
    330     const QwtScaleDraw* sd = d_data->scaleDraw;
     331    const QwtScaleDraw* sd = m_data->scaleDraw;
    331332    if ( sd )
    332333    {
    … …  
    334335        scaleDraw->setScaleDiv( sd->scaleDiv() );
    335336
    336         QwtTransform *transform = NULL;
     337        QwtTransform* transform = NULL;
    337338        if ( sd->scaleMap().transformation() )
    338339            transform = sd->scaleMap().transformation()->copy();
    … …  
    341342    }
    342343
    343     delete d_data->scaleDraw;
    344     d_data->scaleDraw = scaleDraw;
     344    delete m_data->scaleDraw;
     345    m_data->scaleDraw = scaleDraw;
    345346
    346347    layoutScale();
    … …  
    350351    \return scaleDraw of this scale
    351352    \sa setScaleDraw(), QwtScaleDraw::setScaleDraw()
    352 */
    353 const QwtScaleDraw *QwtScaleWidget::scaleDraw() const
    354 {
    355     return d_data->scaleDraw;
     353 */
     354const QwtScaleDraw* QwtScaleWidget::scaleDraw() const
     355{
     356    return m_data->scaleDraw;
    356357}
    357358
    … …  
    359360    \return scaleDraw of this scale
    360361    \sa QwtScaleDraw::setScaleDraw()
    361 */
    362 QwtScaleDraw *QwtScaleWidget::scaleDraw()
    363 {
    364     return d_data->scaleDraw;
     362 */
     363QwtScaleDraw* QwtScaleWidget::scaleDraw()
     364{
     365    return m_data->scaleDraw;
    365366}
    366367
    … …  
    368369    \return title
    369370    \sa setTitle()
    370 */
     371 */
    371372QwtText QwtScaleWidget::title() const
    372373{
    373     return d_data->title;
     374    return m_data->title;
    374375}
    375376
    … …  
    377378    \return start border distance
    378379    \sa setBorderDist()
    379 */
     380 */
    380381int QwtScaleWidget::startBorderDist() const
    381382{
    382     return d_data->borderDist[0];
     383    return m_data->borderDist[0];
    383384}
    384385
    … …  
    386387    \return end border distance
    387388    \sa setBorderDist()
    388 */
     389 */
    389390int QwtScaleWidget::endBorderDist() const
    390391{
    391     return d_data->borderDist[1];
     392    return m_data->borderDist[1];
    392393}
    393394
    … …  
    395396    \return margin
    396397    \sa setMargin()
    397 */
     398 */
    398399int QwtScaleWidget::margin() const
    399400{
    400     return d_data->margin;
     401    return m_data->margin;
    401402}
    402403
    … …  
    404405    \return distance between scale and title
    405406    \sa setMargin()
    406 */
     407 */
    407408int QwtScaleWidget::spacing() const
    408409{
    409     return d_data->spacing;
    410 }
    411 
    412 /*!
    413   \brief paintEvent
    414 */
    415 void QwtScaleWidget::paintEvent( QPaintEvent *event )
     410    return m_data->spacing;
     411}
     412
     413/*!
     414   \brief paintEvent
     415 */
     416void QwtScaleWidget::paintEvent( QPaintEvent* event )
    416417{
    417418    QPainter painter( this );
    … …  
    419420
    420421    QStyleOption opt;
    421     opt.init(this);
     422    opt.initFrom(this);
    422423    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
    423424
    … …  
    426427
    427428/*!
    428   \brief draw the scale
    429 */
    430 void QwtScaleWidget::draw( QPainter *painter ) const
    431 {
    432     d_data->scaleDraw->draw( painter, palette() );
    433 
    434     if ( d_data->colorBar.isEnabled && d_data->colorBar.width > 0 &&
    435         d_data->colorBar.interval.isValid() )
     429   \brief draw the scale
     430 */
     431void QwtScaleWidget::draw( QPainter* painter ) const
     432{
     433    m_data->scaleDraw->draw( painter, palette() );
     434
     435    if ( m_data->colorBar.isEnabled && m_data->colorBar.width > 0 &&
     436        m_data->colorBar.interval.isValid() )
    436437    {
    437438        drawColorBar( painter, colorBarRect( contentsRect() ) );
    … …  
    439440
    440441    QRect r = contentsRect();
    441     if ( d_data->scaleDraw->orientation() == Qt::Horizontal )
    442     {
    443         r.setLeft( r.left() + d_data->borderDist[0] );
    444         r.setWidth( r.width() - d_data->borderDist[1] );
     442    if ( m_data->scaleDraw->orientation() == Qt::Horizontal )
     443    {
     444        r.setLeft( r.left() + m_data->borderDist[0] );
     445        r.setWidth( r.width() - m_data->borderDist[1] );
    445446    }
    446447    else
    447448    {
    448         r.setTop( r.top() + d_data->borderDist[0] );
    449         r.setHeight( r.height() - d_data->borderDist[1] );
    450     }
    451 
    452     if ( !d_data->title.isEmpty() )
    453         drawTitle( painter, d_data->scaleDraw->alignment(), r );
    454 }
    455 
    456 /*!
    457   Calculate the the rectangle for the color bar
    458 
    459   \param rect Bounding rectangle for all components of the scale
    460   \return Rectangle for the color bar
    461 */
     449        r.setTop( r.top() + m_data->borderDist[0] );
     450        r.setHeight( r.height() - m_data->borderDist[1] );
     451    }
     452
     453    if ( !m_data->title.isEmpty() )
     454        drawTitle( painter, m_data->scaleDraw->alignment(), r );
     455}
     456
     457/*!
     458   Calculate the the rectangle for the color bar
     459
     460   \param rect Bounding rectangle for all components of the scale
     461   \return Rectangle for the color bar
     462 */
    462463QRectF QwtScaleWidget::colorBarRect( const QRectF& rect ) const
    463464{
    464465    QRectF cr = rect;
    465466
    466     if ( d_data->scaleDraw->orientation() == Qt::Horizontal )
    467     {
    468         cr.setLeft( cr.left() + d_data->borderDist[0] );
    469         cr.setWidth( cr.width() - d_data->borderDist[1] + 1 );
     467    if ( m_data->scaleDraw->orientation() == Qt::Horizontal )
     468    {
     469        cr.setLeft( cr.left() + m_data->borderDist[0] );
     470        cr.setWidth( cr.width() - m_data->borderDist[1] + 1 );
    470471    }
    471472    else
    472473    {
    473         cr.setTop( cr.top() + d_data->borderDist[0] );
    474         cr.setHeight( cr.height() - d_data->borderDist[1] + 1 );
    475     }
    476 
    477     switch ( d_data->scaleDraw->alignment() )
     474        cr.setTop( cr.top() + m_data->borderDist[0] );
     475        cr.setHeight( cr.height() - m_data->borderDist[1] + 1 );
     476    }
     477
     478    switch ( m_data->scaleDraw->alignment() )
    478479    {
    479480        case QwtScaleDraw::LeftScale:
    480481        {
    481             cr.setLeft( cr.right() - d_data->margin
    482                 - d_data->colorBar.width );
    483             cr.setWidth( d_data->colorBar.width );
     482            cr.setLeft( cr.right() - m_data->margin
     483                - m_data->colorBar.width );
     484            cr.setWidth( m_data->colorBar.width );
    484485            break;
    485486        }
    … …  
    487488        case QwtScaleDraw::RightScale:
    488489        {
    489             cr.setLeft( cr.left() + d_data->margin );
    490             cr.setWidth( d_data->colorBar.width );
     490            cr.setLeft( cr.left() + m_data->margin );
     491            cr.setWidth( m_data->colorBar.width );
    491492            break;
    492493        }
    … …  
    494495        case QwtScaleDraw::BottomScale:
    495496        {
    496             cr.setTop( cr.top() + d_data->margin );
    497             cr.setHeight( d_data->colorBar.width );
     497            cr.setTop( cr.top() + m_data->margin );
     498            cr.setHeight( m_data->colorBar.width );
    498499            break;
    499500        }
    … …  
    501502        case QwtScaleDraw::TopScale:
    502503        {
    503             cr.setTop( cr.bottom() - d_data->margin
    504                 - d_data->colorBar.width );
    505             cr.setHeight( d_data->colorBar.width );
     504            cr.setTop( cr.bottom() - m_data->margin
     505                - m_data->colorBar.width );
     506            cr.setHeight( m_data->colorBar.width );
    506507            break;
    507508        }
    … …  
    512513
    513514/*!
    514   Event handler for resize events
    515   \param event Resize event
    516 */
    517 void QwtScaleWidget::resizeEvent( QResizeEvent *event )
     515   Change Event handler
     516   \param event Change event
     517
     518   Invalidates internal caches if necessary
     519 */
     520void QwtScaleWidget::changeEvent( QEvent* event )
     521{
     522    if ( event->type() == QEvent::LocaleChange )
     523    {
     524        m_data->scaleDraw->invalidateCache();
     525    }
     526
     527    QWidget::changeEvent( event );
     528}
     529
     530/*!
     531   Event handler for resize events
     532   \param event Resize event
     533 */
     534void QwtScaleWidget::resizeEvent( QResizeEvent* event )
    518535{
    519536    Q_UNUSED( event );
    … …  
    522539
    523540/*!
    524   Recalculate the scale's geometry and layout based on
    525   the current geometry and fonts.
    526 
    527   \param update_geometry Notify the layout system and call update
     541   Recalculate the scale's geometry and layout based on
     542   the current geometry and fonts.
     543
     544   \param update_geometry Notify the layout system and call update
    528545                         to redraw the scale
    529 */
     546 */
    530547
    531548void QwtScaleWidget::layoutScale( bool update_geometry )
    … …  
    533550    int bd0, bd1;
    534551    getBorderDistHint( bd0, bd1 );
    535     if ( d_data->borderDist[0] > bd0 )
    536         bd0 = d_data->borderDist[0];
    537     if ( d_data->borderDist[1] > bd1 )
    538         bd1 = d_data->borderDist[1];
     552    if ( m_data->borderDist[0] > bd0 )
     553        bd0 = m_data->borderDist[0];
     554    if ( m_data->borderDist[1] > bd1 )
     555        bd1 = m_data->borderDist[1];
    539556
    540557    int colorBarWidth = 0;
    541     if ( d_data->colorBar.isEnabled && d_data->colorBar.interval.isValid() )
    542         colorBarWidth = d_data->colorBar.width + d_data->spacing;
     558    if ( m_data->colorBar.isEnabled && m_data->colorBar.interval.isValid() )
     559        colorBarWidth = m_data->colorBar.width + m_data->spacing;
    543560
    544561    const QRectF r = contentsRect();
    545562    double x, y, length;
    546563
    547     if ( d_data->scaleDraw->orientation() == Qt::Vertical )
     564    if ( m_data->scaleDraw->orientation() == Qt::Vertical )
    548565    {
    549566        y = r.top() + bd0;
    550567        length = r.height() - ( bd0 + bd1 );
    551568
    552         if ( d_data->scaleDraw->alignment() == QwtScaleDraw::LeftScale )
    553             x = r.right() - 1.0 - d_data->margin - colorBarWidth;
     569        if ( m_data->scaleDraw->alignment() == QwtScaleDraw::LeftScale )
     570            x = r.right() - 1.0 - m_data->margin - colorBarWidth;
    554571        else
    555             x = r.left() + d_data->margin + colorBarWidth;
     572            x = r.left() + m_data->margin + colorBarWidth;
    556573    }
    557574    else
    … …  
    560577        length = r.width() - ( bd0 + bd1 );
    561578
    562         if ( d_data->scaleDraw->alignment() == QwtScaleDraw::BottomScale )
    563             y = r.top() + d_data->margin + colorBarWidth;
     579        if ( m_data->scaleDraw->alignment() == QwtScaleDraw::BottomScale )
     580            y = r.top() + m_data->margin + colorBarWidth;
    564581        else
    565             y = r.bottom() - 1.0 - d_data->margin - colorBarWidth;
    566     }
    567 
    568     d_data->scaleDraw->move( x, y );
    569     d_data->scaleDraw->setLength( length );
    570 
    571     const int extent = qCeil( d_data->scaleDraw->extent( font() ) );
    572 
    573     d_data->titleOffset =
    574         d_data->margin + d_data->spacing + colorBarWidth + extent;
     582            y = r.bottom() - 1.0 - m_data->margin - colorBarWidth;
     583    }
     584
     585    m_data->scaleDraw->move( x, y );
     586    m_data->scaleDraw->setLength( length );
     587
     588    const int extent = qwtCeil( m_data->scaleDraw->extent( font() ) );
     589
     590    m_data->titleOffset =
     591        m_data->margin + m_data->spacing + colorBarWidth + extent;
    575592
    576593    if ( update_geometry )
    … …  
    599616
    600617/*!
    601   Draw the color bar of the scale widget
    602 
    603   \param painter Painter
    604   \param rect Bounding rectangle for the color bar
    605 
    606   \sa setColorBarEnabled()
    607 */
    608 void QwtScaleWidget::drawColorBar( QPainter *painter, const QRectF& rect ) const
    609 {
    610     if ( !d_data->colorBar.interval.isValid() )
     618   Draw the color bar of the scale widget
     619
     620   \param painter Painter
     621   \param rect Bounding rectangle for the color bar
     622
     623   \sa setColorBarEnabled()
     624 */
     625void QwtScaleWidget::drawColorBar( QPainter* painter, const QRectF& rect ) const
     626{
     627    if ( !m_data->colorBar.interval.isValid() )
    611628        return;
    612629
    613     const QwtScaleDraw* sd = d_data->scaleDraw;
    614 
    615     QwtPainter::drawColorBar( painter, *d_data->colorBar.colorMap,
    616         d_data->colorBar.interval.normalized(), sd->scaleMap(),
     630    const QwtScaleDraw* sd = m_data->scaleDraw;
     631
     632    QwtPainter::drawColorBar( painter, *m_data->colorBar.colorMap,
     633        m_data->colorBar.interval.normalized(), sd->scaleMap(),
    617634        sd->orientation(), rect );
    618635}
    619636
    620637/*!
    621   Rotate and paint a title according to its position into a given rectangle.
    622 
    623   \param painter Painter
    624   \param align Alignment
    625   \param rect Bounding rectangle
    626 */
    627 
    628 void QwtScaleWidget::drawTitle( QPainter *painter,
    629     QwtScaleDraw::Alignment align, const QRectF &rect ) const
     638   Rotate and paint a title according to its position into a given rectangle.
     639
     640   \param painter Painter
     641   \param align Alignment
     642   \param rect Bounding rectangle
     643 */
     644
     645void QwtScaleWidget::drawTitle( QPainter* painter,
     646    QwtScaleDraw::Alignment align, const QRectF& rect ) const
    630647{
    631648    QRectF r = rect;
    632649    double angle;
    633     int flags = d_data->title.renderFlags() &
     650    int flags = m_data->title.renderFlags() &
    634651        ~( Qt::AlignTop | Qt::AlignBottom | Qt::AlignVCenter );
    635652
    … …  
    640657            flags |= Qt::AlignTop;
    641658            r.setRect( r.left(), r.bottom(),
    642                 r.height(), r.width() - d_data->titleOffset );
     659                r.height(), r.width() - m_data->titleOffset );
    643660            break;
    644661
    … …  
    646663            angle = -90.0;
    647664            flags |= Qt::AlignTop;
    648             r.setRect( r.left() + d_data->titleOffset, r.bottom(),
    649                 r.height(), r.width() - d_data->titleOffset );
     665            r.setRect( r.left() + m_data->titleOffset, r.bottom(),
     666                r.height(), r.width() - m_data->titleOffset );
    650667            break;
    651668
    … …  
    653670            angle = 0.0;
    654671            flags |= Qt::AlignBottom;
    655             r.setTop( r.top() + d_data->titleOffset );
     672            r.setTop( r.top() + m_data->titleOffset );
    656673            break;
    657674
    … …  
    660677            angle = 0.0;
    661678            flags |= Qt::AlignTop;
    662             r.setBottom( r.bottom() - d_data->titleOffset );
     679            r.setBottom( r.bottom() - m_data->titleOffset );
    663680            break;
    664681    }
    665682
    666     if ( d_data->layoutFlags & TitleInverted )
     683    if ( m_data->layoutFlags & TitleInverted )
    667684    {
    668685        if ( align == QwtScaleDraw::LeftScale
    … …  
    683700        painter->rotate( angle );
    684701
    685     QwtText title = d_data->title;
     702    QwtText title = m_data->title;
    686703    title.setRenderFlags( flags );
    687704    title.draw( painter, QRectF( 0.0, 0.0, r.width(), r.height() ) );
    … …  
    691708
    692709/*!
    693   \brief Notify a change of the scale
    694 
    695   This virtual function can be overloaded by derived
    696   classes. The default implementation updates the geometry
    697   and repaints the widget.
    698 */
     710   \brief Notify a change of the scale
     711
     712   This virtual function can be overloaded by derived
     713   classes. The default implementation updates the geometry
     714   and repaints the widget.
     715 */
    699716
    700717void QwtScaleWidget::scaleChange()
    … …  
    704721
    705722/*!
    706   \return a size hint
    707 */
     723   \return a size hint
     724 */
    708725QSize QwtScaleWidget::sizeHint() const
    709726{
    … …  
    712729
    713730/*!
    714   \return a minimum size hint
    715 */
     731   \return a minimum size hint
     732 */
    716733QSize QwtScaleWidget::minimumSizeHint() const
    717734{
    718     const Qt::Orientation o = d_data->scaleDraw->orientation();
     735    const Qt::Orientation o = m_data->scaleDraw->orientation();
    719736
    720737    // Border Distance cannot be less than the scale borderDistHint
    … …  
    723740    int mbd1, mbd2;
    724741    getBorderDistHint( mbd1, mbd2 );
    725     length += qMax( 0, d_data->borderDist[0] - mbd1 );
    726     length += qMax( 0, d_data->borderDist[1] - mbd2 );
    727     length += d_data->scaleDraw->minLength( font() );
     742    length += qMax( 0, m_data->borderDist[0] - mbd1 );
     743    length += qMax( 0, m_data->borderDist[1] - mbd2 );
     744    length += m_data->scaleDraw->minLength( font() );
    728745
    729746    int dim = dimForLength( length, font() );
    … …  
    739756        size.transpose();
    740757
    741     int left, right, top, bottom;
    742     getContentsMargins( &left, &top, &right, &bottom );
    743     return size + QSize( left + right, top + bottom );
    744 }
    745 
    746 /*!
    747   \brief Find the height of the title for a given width.
    748   \param width Width
    749   \return height Height
     758    const QMargins m = contentsMargins();
     759    return size + QSize( m.left() + m.right(), m.top() + m.bottom() );
     760}
     761
     762/*!
     763   \brief Find the height of the title for a given width.
     764   \param width Width
     765   \return height Height
    750766 */
    751767
    752768int QwtScaleWidget::titleHeightForWidth( int width ) const
    753769{
    754     return qCeil( d_data->title.heightForWidth( width, font() ) );
    755 }
    756 
    757 /*!
    758   \brief Find the minimum dimension for a given length.
     770    return qwtCeil( m_data->title.heightForWidth( width, font() ) );
     771}
     772
     773/*!
     774   \brief Find the minimum dimension for a given length.
    759775         dim is the height, length the width seen in
    760776         direction of the title.
    761   \param length width for horizontal, height for vertical scales
    762   \param scaleFont Font of the scale
    763   \return height for horizontal, width for vertical scales
    764 */
    765 
    766 int QwtScaleWidget::dimForLength( int length, const QFont &scaleFont ) const
    767 {
    768     const int extent = qCeil( d_data->scaleDraw->extent( scaleFont ) );
    769 
    770     int dim = d_data->margin + extent + 1;
    771 
    772     if ( !d_data->title.isEmpty() )
    773         dim += titleHeightForWidth( length ) + d_data->spacing;
    774 
    775     if ( d_data->colorBar.isEnabled && d_data->colorBar.interval.isValid() )
    776         dim += d_data->colorBar.width + d_data->spacing;
     777   \param length width for horizontal, height for vertical scales
     778   \param scaleFont Font of the scale
     779   \return height for horizontal, width for vertical scales
     780 */
     781
     782int QwtScaleWidget::dimForLength( int length, const QFont& scaleFont ) const
     783{
     784    const int extent = qwtCeil( m_data->scaleDraw->extent( scaleFont ) );
     785
     786    int dim = m_data->margin + extent + 1;
     787
     788    if ( !m_data->title.isEmpty() )
     789        dim += titleHeightForWidth( length ) + m_data->spacing;
     790
     791    if ( m_data->colorBar.isEnabled && m_data->colorBar.interval.isValid() )
     792        dim += m_data->colorBar.width + m_data->spacing;
    777793
    778794    return dim;
    … …  
    780796
    781797/*!
    782   \brief Calculate a hint for the border distances.
    783 
    784   This member function calculates the distance
    785   of the scale's endpoints from the widget borders which
    786   is required for the mark labels to fit into the widget.
    787   The maximum of this distance an the minimum border distance
    788   is returned.
    789 
    790   \param start Return parameter for the border width at
     798   \brief Calculate a hint for the border distances.
     799
     800   This member function calculates the distance
     801   of the scale's endpoints from the widget borders which
     802   is required for the mark labels to fit into the widget.
     803   The maximum of this distance an the minimum border distance
     804   is returned.
     805
     806   \param start Return parameter for the border width at
    791807               the beginning of the scale
    792   \param end Return parameter for the border width at the
     808   \param end Return parameter for the border width at the
    793809             end of the scale
    794810
    795   \warning
    796   <ul> <li>The minimum border distance depends on the font.</ul>
    797   \sa setMinBorderDist(), getMinBorderDist(), setBorderDist()
    798 */
    799 void QwtScaleWidget::getBorderDistHint( int &start, int &end ) const
    800 {
    801     d_data->scaleDraw->getBorderDistHint( font(), start, end );
    802 
    803     if ( start < d_data->minBorderDist[0] )
    804         start = d_data->minBorderDist[0];
    805 
    806     if ( end < d_data->minBorderDist[1] )
    807         end = d_data->minBorderDist[1];
    808 }
    809 
    810 /*!
    811   Set a minimum value for the distances of the scale's endpoints from
    812   the widget borders. This is useful to avoid that the scales
    813   are "jumping", when the tick labels or their positions change
    814   often.
    815 
    816   \param start Minimum for the start border
    817   \param end Minimum for the end border
    818   \sa getMinBorderDist(), getBorderDistHint()
    819 */
     811   \warning
     812   <ul> <li>The minimum border distance depends on the font.</ul>
     813   \sa setMinBorderDist(), getMinBorderDist(), setBorderDist()
     814 */
     815void QwtScaleWidget::getBorderDistHint( int& start, int& end ) const
     816{
     817    m_data->scaleDraw->getBorderDistHint( font(), start, end );
     818
     819    if ( start < m_data->minBorderDist[0] )
     820        start = m_data->minBorderDist[0];
     821
     822    if ( end < m_data->minBorderDist[1] )
     823        end = m_data->minBorderDist[1];
     824}
     825
     826/*!
     827   Set a minimum value for the distances of the scale's endpoints from
     828   the widget borders. This is useful to avoid that the scales
     829   are "jumping", when the tick labels or their positions change
     830   often.
     831
     832   \param start Minimum for the start border
     833   \param end Minimum for the end border
     834   \sa getMinBorderDist(), getBorderDistHint()
     835 */
    820836void QwtScaleWidget::setMinBorderDist( int start, int end )
    821837{
    822     d_data->minBorderDist[0] = start;
    823     d_data->minBorderDist[1] = end;
    824 }
    825 
    826 /*!
    827   Get the minimum value for the distances of the scale's endpoints from
    828   the widget borders.
    829 
    830   \param start Return parameter for the border width at
     838    m_data->minBorderDist[0] = start;
     839    m_data->minBorderDist[1] = end;
     840}
     841
     842/*!
     843   Get the minimum value for the distances of the scale's endpoints from
     844   the widget borders.
     845
     846   \param start Return parameter for the border width at
    831847               the beginning of the scale
    832   \param end Return parameter for the border width at the
     848   \param end Return parameter for the border width at the
    833849             end of the scale
    834850
    835   \sa setMinBorderDist(), getBorderDistHint()
    836 */
    837 void QwtScaleWidget::getMinBorderDist( int &start, int &end ) const
    838 {
    839     start = d_data->minBorderDist[0];
    840     end = d_data->minBorderDist[1];
    841 }
    842 
    843 /*!
    844   \brief Assign a scale division
    845 
    846   The scale division determines where to set the tick marks.
    847 
    848   \param scaleDiv Scale Division
    849   \sa For more information about scale divisions, see QwtScaleDiv.
    850 */
    851 void QwtScaleWidget::setScaleDiv( const QwtScaleDiv &scaleDiv )
    852 {
    853     QwtScaleDraw *sd = d_data->scaleDraw;
     851   \sa setMinBorderDist(), getBorderDistHint()
     852 */
     853void QwtScaleWidget::getMinBorderDist( int& start, int& end ) const
     854{
     855    start = m_data->minBorderDist[0];
     856    end = m_data->minBorderDist[1];
     857}
     858
     859/*!
     860   \brief Assign a scale division
     861
     862   The scale division determines where to set the tick marks.
     863
     864   \param scaleDiv Scale Division
     865   \sa For more information about scale divisions, see QwtScaleDiv.
     866 */
     867void QwtScaleWidget::setScaleDiv( const QwtScaleDiv& scaleDiv )
     868{
     869    QwtScaleDraw* sd = m_data->scaleDraw;
    854870    if ( sd->scaleDiv() != scaleDiv )
    855871    {
    … …  
    862878
    863879/*!
    864   Set the transformation
    865 
    866   \param transformation Transformation
    867   \sa QwtAbstractScaleDraw::scaleDraw(), QwtScaleMap
    868  */
    869 void QwtScaleWidget::setTransformation( QwtTransform *transformation )
    870 {
    871     d_data->scaleDraw->setTransformation( transformation );
     880   Set the transformation
     881
     882   \param transformation Transformation
     883   \sa QwtAbstractScaleDraw::scaleDraw(), QwtScaleMap
     884 */
     885void QwtScaleWidget::setTransformation( QwtTransform* transformation )
     886{
     887    m_data->scaleDraw->setTransformation( transformation );
    872888    layoutScale();
    873889}
    874890
    875891/*!
    876   En/disable a color bar associated to the scale
    877   \sa isColorBarEnabled(), setColorBarWidth()
    878 */
     892   En/disable a color bar associated to the scale
     893   \sa isColorBarEnabled(), setColorBarWidth()
     894 */
    879895void QwtScaleWidget::setColorBarEnabled( bool on )
    880896{
    881     if ( on != d_data->colorBar.isEnabled )
    882     {
    883         d_data->colorBar.isEnabled = on;
     897    if ( on != m_data->colorBar.isEnabled )
     898    {
     899        m_data->colorBar.isEnabled = on;
    884900        layoutScale();
    885901    }
    … …  
    887903
    888904/*!
    889   \return true, when the color bar is enabled
    890   \sa setColorBarEnabled(), setColorBarWidth()
    891 */
     905   \return true, when the color bar is enabled
     906   \sa setColorBarEnabled(), setColorBarWidth()
     907 */
    892908bool QwtScaleWidget::isColorBarEnabled() const
    893909{
    894     return d_data->colorBar.isEnabled;
    895 }
    896 
    897 /*!
    898   Set the width of the color bar
    899 
    900   \param width Width
    901   \sa colorBarWidth(), setColorBarEnabled()
    902 */
     910    return m_data->colorBar.isEnabled;
     911}
     912
     913/*!
     914   Set the width of the color bar
     915
     916   \param width Width
     917   \sa colorBarWidth(), setColorBarEnabled()
     918 */
    903919void QwtScaleWidget::setColorBarWidth( int width )
    904920{
    905     if ( width != d_data->colorBar.width )
    906     {
    907         d_data->colorBar.width = width;
     921    if ( width != m_data->colorBar.width )
     922    {
     923        m_data->colorBar.width = width;
    908924        if ( isColorBarEnabled() )
    909925            layoutScale();
    … …  
    912928
    913929/*!
    914   \return Width of the color bar
    915   \sa setColorBarEnabled(), setColorBarEnabled()
    916 */
     930   \return Width of the color bar
     931   \sa setColorBarEnabled(), setColorBarEnabled()
     932 */
    917933int QwtScaleWidget::colorBarWidth() const
    918934{
    919     return d_data->colorBar.width;
    920 }
    921 
    922 /*!
    923   \return Value interval for the color bar
    924   \sa setColorMap(), colorMap()
    925 */
     935    return m_data->colorBar.width;
     936}
     937
     938/*!
     939   \return Value interval for the color bar
     940   \sa setColorMap(), colorMap()
     941 */
    926942QwtInterval QwtScaleWidget::colorBarInterval() const
    927943{
    928     return d_data->colorBar.interval;
    929 }
    930 
    931 /*!
    932   Set the color map and value interval, that are used for displaying
    933   the color bar.
    934 
    935   \param interval Value interval
    936   \param colorMap Color map
    937 
    938   \sa colorMap(), colorBarInterval()
    939 */
     944    return m_data->colorBar.interval;
     945}
     946
     947/*!
     948   Set the color map and value interval, that are used for displaying
     949   the color bar.
     950
     951   \param interval Value interval
     952   \param colorMap Color map
     953
     954   \sa colorMap(), colorBarInterval()
     955 */
    940956void QwtScaleWidget::setColorMap(
    941     const QwtInterval &interval, QwtColorMap *colorMap )
    942 {
    943     d_data->colorBar.interval = interval;
    944 
    945     if ( colorMap != d_data->colorBar.colorMap )
    946     {
    947         delete d_data->colorBar.colorMap;
    948         d_data->colorBar.colorMap = colorMap;
     957    const QwtInterval& interval, QwtColorMap* colorMap )
     958{
     959    m_data->colorBar.interval = interval;
     960
     961    if ( colorMap != m_data->colorBar.colorMap )
     962    {
     963        delete m_data->colorBar.colorMap;
     964        m_data->colorBar.colorMap = colorMap;
    949965    }
    950966
    … …  
    954970
    955971/*!
    956   \return Color map
    957   \sa setColorMap(), colorBarInterval()
    958 */
    959 const QwtColorMap *QwtScaleWidget::colorMap() const
    960 {
    961     return d_data->colorBar.colorMap;
    962 }
     972   \return Color map
     973   \sa setColorMap(), colorBarInterval()
     974 */
     975const QwtColorMap* QwtScaleWidget::colorMap() const
     976{
     977    return m_data->colorBar.colorMap;
     978}
     979
     980#include "moc_qwt_scale_widget.cpp"
  • trunk/BNC/qwt/qwt_scale_widget.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1414#include "qwt_text.h"
    1515#include "qwt_scale_draw.h"
     16
    1617#include <qwidget.h>
    1718#include <qfont.h>
    … …  
    2526
    2627/*!
    27   \brief A Widget which contains a scale
     28   \brief A Widget which contains a scale
    2829
    29   This Widget can be used to decorate composite widgets with
    30   a scale.
    31 */
     30   This Widget can be used to decorate composite widgets with
     31   a scale.
     32 */
    3233
    3334class QWT_EXPORT QwtScaleWidget : public QWidget
    … …  
    3536    Q_OBJECT
    3637
    37 public:
     38  public:
    3839    //! Layout flags of the title
    3940    enum LayoutFlag
    4041    {
    4142        /*!
    42           The title of vertical scales is painted from top to bottom.
    43           Otherwise it is painted from bottom to top.
     43           The title of vertical scales is painted from top to bottom.
     44           Otherwise it is painted from bottom to top.
    4445         */
    4546        TitleInverted = 1
    4647    };
    4748
    48     //! Layout flags of the title
    49     typedef QFlags<LayoutFlag> LayoutFlags;
     49    Q_DECLARE_FLAGS( LayoutFlags, LayoutFlag )
    5050
    51     explicit QwtScaleWidget( QWidget *parent = NULL );
    52     explicit QwtScaleWidget( QwtScaleDraw::Alignment, QWidget *parent = NULL );
     51    explicit QwtScaleWidget( QWidget* parent = NULL );
     52    explicit QwtScaleWidget( QwtScaleDraw::Alignment, QWidget* parent = NULL );
    5353    virtual ~QwtScaleWidget();
    5454
    55 Q_SIGNALS:
     55  Q_SIGNALS:
    5656    //! Signal emitted, whenever the scale division changes
    5757    void scaleDivChanged();
    5858
    59 public:
    60     void setTitle( const QString &title );
    61     void setTitle( const QwtText &title );
     59  public:
     60    void setTitle( const QString& title );
     61    void setTitle( const QwtText& title );
    6262    QwtText title() const;
    6363
    … …  
    6969    int endBorderDist() const;
    7070
    71     void getBorderDistHint( int &start, int &end ) const;
     71    void getBorderDistHint( int& start, int& end ) const;
    7272
    73     void getMinBorderDist( int &start, int &end ) const;
     73    void getMinBorderDist( int& start, int& end ) const;
    7474    void setMinBorderDist( int start, int end );
    7575
    … …  
    8080    int spacing() const;
    8181
    82     void setScaleDiv( const QwtScaleDiv & );
    83     void setTransformation( QwtTransform * );
     82    void setScaleDiv( const QwtScaleDiv& );
     83    void setTransformation( QwtTransform* );
    8484
    85     void setScaleDraw( QwtScaleDraw * );
    86     const QwtScaleDraw *scaleDraw() const;
    87     QwtScaleDraw *scaleDraw();
     85    void setScaleDraw( QwtScaleDraw* );
     86    const QwtScaleDraw* scaleDraw() const;
     87    QwtScaleDraw* scaleDraw();
    8888
    8989    void setLabelAlignment( Qt::Alignment );
    … …  
    9696    int colorBarWidth() const;
    9797
    98     void setColorMap( const QwtInterval &, QwtColorMap * );
     98    void setColorMap( const QwtInterval&, QwtColorMap* );
    9999
    100100    QwtInterval colorBarInterval() const;
    101     const QwtColorMap *colorMap() const;
     101    const QwtColorMap* colorMap() const;
    102102
    103     virtual QSize sizeHint() const;
    104     virtual QSize minimumSizeHint() const;
     103    virtual QSize sizeHint() const QWT_OVERRIDE;
     104    virtual QSize minimumSizeHint() const QWT_OVERRIDE;
    105105
    106106    int titleHeightForWidth( int width ) const;
    107     int dimForLength( int length, const QFont &scaleFont ) const;
     107    int dimForLength( int length, const QFont& scaleFont ) const;
    108108
    109     void drawColorBar( QPainter *painter, const QRectF & ) const;
    110     void drawTitle( QPainter *painter, QwtScaleDraw::Alignment,
    111         const QRectF &rect ) const;
     109    void drawColorBar( QPainter*, const QRectF& ) const;
     110    void drawTitle( QPainter*, QwtScaleDraw::Alignment,
     111        const QRectF& rect ) const;
    112112
    113113    void setAlignment( QwtScaleDraw::Alignment );
    … …  
    116116    QRectF colorBarRect( const QRectF& ) const;
    117117
    118 protected:
    119     virtual void paintEvent( QPaintEvent * );
    120     virtual void resizeEvent( QResizeEvent * );
     118  protected:
     119    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
     120    virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE;
     121    virtual void changeEvent( QEvent* ) QWT_OVERRIDE;
    121122
    122     void draw( QPainter * ) const;
     123    void draw( QPainter* ) const;
    123124
    124125    void scaleChange();
    125126    void layoutScale( bool update_geometry = true );
    126127
    127 private:
     128  private:
    128129    void initScale( QwtScaleDraw::Alignment );
    129130
    130131    class PrivateData;
    131     PrivateData *d_data;
     132    PrivateData* m_data;
    132133};
    133134
  • trunk/BNC/qwt/qwt_series_data.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_series_data.h"
    11 #include "qwt_math.h"
    12 
    13 static inline QRectF qwtBoundingRect( const QPointF &sample )
     11#include "qwt_point_polar.h"
     12
     13static inline QRectF qwtBoundingRect( const QPointF& sample )
    1414{
    1515    return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
    1616}
    1717
    18 static inline QRectF qwtBoundingRect( const QwtPoint3D &sample )
     18static inline QRectF qwtBoundingRect( const QwtPoint3D& sample )
    1919{
    2020    return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
    2121}
    2222
    23 static inline QRectF qwtBoundingRect( const QwtPointPolar &sample )
     23static inline QRectF qwtBoundingRect( const QwtPointPolar& sample )
    2424{
    2525    return QRectF( sample.azimuth(), sample.radius(), 0.0, 0.0 );
    2626}
    2727
    28 static inline QRectF qwtBoundingRect( const QwtIntervalSample &sample )
     28static inline QRectF qwtBoundingRect( const QwtIntervalSample& sample )
    2929{
    3030    return QRectF( sample.interval.minValue(), sample.value,
    … …  
    3232}
    3333
    34 static inline QRectF qwtBoundingRect( const QwtSetSample &sample )
     34static inline QRectF qwtBoundingRect( const QwtSetSample& sample )
    3535{
    3636    if ( sample.set.empty() )
    … …  
    5252}
    5353
    54 static inline QRectF qwtBoundingRect( const QwtOHLCSample &sample )
     54static inline QRectF qwtBoundingRect( const QwtOHLCSample& sample )
    5555{
    5656    const QwtInterval interval = sample.boundingInterval();
    … …  
    5858}
    5959
    60 /*!
    61   \brief Calculate the bounding rectangle of a series subset
    62 
    63   Slow implementation, that iterates over the series.
    64 
    65   \param series Series
    66   \param from Index of the first sample, <= 0 means from the beginning
    67   \param to Index of the last sample, < 0 means to the end
    68 
    69   \return Bounding rectangle
    70 */
    71 
    72 template <class T>
    73 QRectF qwtBoundingRectT(
    74     const QwtSeriesData<T>& series, int from, int to )
     60static inline QRectF qwtBoundingRect( const QwtVectorFieldSample& sample )
     61{
     62    /*
     63        When displaying a sample as an arrow its length will be
     64        proportional to the magnitude - but not the same.
     65        As the factor between length and magnitude is not known
     66        we can't include vx/vy into the bounding rectangle.
     67     */
     68
     69    return QRectF( sample.x, sample.y, 0, 0 );
     70}
     71
     72/*!
     73   \brief Calculate the bounding rectangle of a series subset
     74
     75   Slow implementation, that iterates over the series.
     76
     77   \param series Series
     78   \param from Index of the first sample, <= 0 means from the beginning
     79   \param to Index of the last sample, < 0 means to the end
     80
     81   \return Bounding rectangle
     82 */
     83
     84template< class T >
     85QRectF qwtBoundingRectT( const QwtSeriesData< T >& series, int from, int to )
    7586{
    7687    QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
    … …  
    113124
    114125/*!
    115   \brief Calculate the bounding rectangle of a series subset
    116 
    117   Slow implementation, that iterates over the series.
    118 
    119   \param series Series
    120   \param from Index of the first sample, <= 0 means from the beginning
    121   \param to Index of the last sample, < 0 means to the end
    122 
    123   \return Bounding rectangle
    124 */
    125 QRectF qwtBoundingRect(
    126     const QwtSeriesData<QPointF> &series, int from, int to )
    127 {
    128     return qwtBoundingRectT<QPointF>( series, from, to );
    129 }
    130 
    131 /*!
    132   \brief Calculate the bounding rectangle of a series subset
    133 
    134   Slow implementation, that iterates over the series.
    135 
    136   \param series Series
    137   \param from Index of the first sample, <= 0 means from the beginning
    138   \param to Index of the last sample, < 0 means to the end
    139 
    140   \return Bounding rectangle
    141 */
    142 QRectF qwtBoundingRect(
    143     const QwtSeriesData<QwtPoint3D> &series, int from, int to )
    144 {
    145     return qwtBoundingRectT<QwtPoint3D>( series, from, to );
    146 }
    147 
    148 /*!
    149   \brief Calculate the bounding rectangle of a series subset
    150 
    151   The horizontal coordinates represent the azimuth, the
    152   vertical coordinates the radius.
    153 
    154   Slow implementation, that iterates over the series.
    155 
    156   \param series Series
    157   \param from Index of the first sample, <= 0 means from the beginning
    158   \param to Index of the last sample, < 0 means to the end
    159 
    160   \return Bounding rectangle
    161 */
    162 QRectF qwtBoundingRect(
    163     const QwtSeriesData<QwtPointPolar> &series, int from, int to )
    164 {
    165     return qwtBoundingRectT<QwtPointPolar>( series, from, to );
    166 }
    167 
    168 /*!
    169   \brief Calculate the bounding rectangle of a series subset
    170 
    171   Slow implementation, that iterates over the series.
    172 
    173   \param series Series
    174   \param from Index of the first sample, <= 0 means from the beginning
    175   \param to Index of the last sample, < 0 means to the end
    176 
    177   \return Bounding rectangle
    178 */
    179 QRectF qwtBoundingRect(
    180     const QwtSeriesData<QwtIntervalSample>& series, int from, int to )
    181 {
    182     return qwtBoundingRectT<QwtIntervalSample>( series, from, to );
    183 }
    184 
    185 /*!
    186   \brief Calculate the bounding rectangle of a series subset
    187 
    188   Slow implementation, that iterates over the series.
    189 
    190   \param series Series
    191   \param from Index of the first sample, <= 0 means from the beginning
    192   \param to Index of the last sample, < 0 means to the end
    193 
    194   \return Bounding rectangle
    195 */
    196 QRectF qwtBoundingRect(
    197     const QwtSeriesData<QwtOHLCSample>& series, int from, int to )
    198 {
    199     return qwtBoundingRectT<QwtOHLCSample>( series, from, to );
    200 }
    201 
    202 /*!
    203   \brief Calculate the bounding rectangle of a series subset
    204 
    205   Slow implementation, that iterates over the series.
    206 
    207   \param series Series
    208   \param from Index of the first sample, <= 0 means from the beginning
    209   \param to Index of the last sample, < 0 means to the end
    210 
    211   \return Bounding rectangle
    212 */
    213 QRectF qwtBoundingRect(
    214     const QwtSeriesData<QwtSetSample>& series, int from, int to )
    215 {
    216     return qwtBoundingRectT<QwtSetSample>( series, from, to );
    217 }
    218 
    219 /*!
    220    Constructor
    221    \param samples Samples
    222 */
    223 QwtPointSeriesData::QwtPointSeriesData(
    224         const QVector<QPointF> &samples ):
    225     QwtArraySeriesData<QPointF>( samples )
    226 {
    227 }
    228 
    229 /*!
    230   \brief Calculate the bounding rectangle
    231 
    232   The bounding rectangle is calculated once by iterating over all
    233   points and is stored for all following requests.
    234 
    235   \return Bounding rectangle
    236 */
    237 QRectF QwtPointSeriesData::boundingRect() const
    238 {
    239     if ( d_boundingRect.width() < 0.0 )
    240         d_boundingRect = qwtBoundingRect( *this );
    241 
    242     return d_boundingRect;
    243 }
    244 
    245 /*!
    246    Constructor
    247    \param samples Samples
    248 */
    249 QwtPoint3DSeriesData::QwtPoint3DSeriesData(
    250         const QVector<QwtPoint3D> &samples ):
    251     QwtArraySeriesData<QwtPoint3D>( samples )
    252 {
    253 }
    254 
    255 /*!
    256   \brief Calculate the bounding rectangle
    257 
    258   The bounding rectangle is calculated once by iterating over all
    259   points and is stored for all following requests.
    260 
    261   \return Bounding rectangle
    262 */
    263 QRectF QwtPoint3DSeriesData::boundingRect() const
    264 {
    265     if ( d_boundingRect.width() < 0.0 )
    266         d_boundingRect = qwtBoundingRect( *this );
    267 
    268     return d_boundingRect;
    269 }
    270 
    271 /*!
    272    Constructor
    273    \param samples Samples
    274 */
    275 QwtIntervalSeriesData::QwtIntervalSeriesData(
    276         const QVector<QwtIntervalSample> &samples ):
    277     QwtArraySeriesData<QwtIntervalSample>( samples )
    278 {
    279 }
    280 
    281 /*!
    282   \brief Calculate the bounding rectangle
    283 
    284   The bounding rectangle is calculated once by iterating over all
    285   points and is stored for all following requests.
    286 
    287   \return Bounding rectangle
    288 */
    289 QRectF QwtIntervalSeriesData::boundingRect() const
    290 {
    291     if ( d_boundingRect.width() < 0.0 )
    292         d_boundingRect = qwtBoundingRect( *this );
    293 
    294     return d_boundingRect;
    295 }
    296 
    297 /*!
    298    Constructor
    299    \param samples Samples
    300 */
    301 QwtSetSeriesData::QwtSetSeriesData(
    302         const QVector<QwtSetSample> &samples ):
    303     QwtArraySeriesData<QwtSetSample>( samples )
    304 {
    305 }
    306 
    307 /*!
    308   \brief Calculate the bounding rectangle
    309 
    310   The bounding rectangle is calculated once by iterating over all
    311   points and is stored for all following requests.
    312 
    313   \return Bounding rectangle
    314 */
    315 QRectF QwtSetSeriesData::boundingRect() const
    316 {
    317     if ( d_boundingRect.width() < 0.0 )
    318         d_boundingRect = qwtBoundingRect( *this );
    319 
    320     return d_boundingRect;
    321 }
    322 
    323 /*!
    324    Constructor
    325    \param samples Samples
    326 */
    327 QwtTradingChartData::QwtTradingChartData(
    328         const QVector<QwtOHLCSample> &samples ):
    329     QwtArraySeriesData<QwtOHLCSample>( samples )
    330 {
    331 }
    332 
    333 /*!
    334   \brief Calculate the bounding rectangle
    335 
    336   The bounding rectangle is calculated once by iterating over all
    337   points and is stored for all following requests.
    338 
    339   \return Bounding rectangle
    340 */
    341 QRectF QwtTradingChartData::boundingRect() const
    342 {
    343     if ( d_boundingRect.width() < 0.0 )
    344         d_boundingRect = qwtBoundingRect( *this );
    345 
    346     return d_boundingRect;
    347 }
     126   \brief Calculate the bounding rectangle of a series subset
     127
     128   Slow implementation, that iterates over the series.
     129
     130   \param series Series
     131   \param from Index of the first sample, <= 0 means from the beginning
     132   \param to Index of the last sample, < 0 means to the end
     133
     134   \return Bounding rectangle
     135 */
     136QRectF qwtBoundingRect( const QwtSeriesData< QPointF >& series, int from, int to )
     137{
     138    return qwtBoundingRectT< QPointF >( series, from, to );
     139}
     140
     141/*!
     142   \brief Calculate the bounding rectangle of a series subset
     143
     144   Slow implementation, that iterates over the series.
     145
     146   \param series Series
     147   \param from Index of the first sample, <= 0 means from the beginning
     148   \param to Index of the last sample, < 0 means to the end
     149
     150   \return Bounding rectangle
     151 */
     152QRectF qwtBoundingRect(
     153    const QwtSeriesData< QwtPoint3D >& series, int from, int to )
     154{
     155    return qwtBoundingRectT< QwtPoint3D >( series, from, to );
     156}
     157
     158/*!
     159   \brief Calculate the bounding rectangle of a series subset
     160
     161   The horizontal coordinates represent the azimuth, the
     162   vertical coordinates the radius.
     163
     164   Slow implementation, that iterates over the series.
     165
     166   \param series Series
     167   \param from Index of the first sample, <= 0 means from the beginning
     168   \param to Index of the last sample, < 0 means to the end
     169
     170   \return Bounding rectangle
     171 */
     172QRectF qwtBoundingRect(
     173    const QwtSeriesData< QwtPointPolar >& series, int from, int to )
     174{
     175    return qwtBoundingRectT< QwtPointPolar >( series, from, to );
     176}
     177
     178/*!
     179   \brief Calculate the bounding rectangle of a series subset
     180
     181   Slow implementation, that iterates over the series.
     182
     183   \param series Series
     184   \param from Index of the first sample, <= 0 means from the beginning
     185   \param to Index of the last sample, < 0 means to the end
     186
     187   \return Bounding rectangle
     188 */
     189QRectF qwtBoundingRect(
     190    const QwtSeriesData< QwtIntervalSample >& series, int from, int to )
     191{
     192    return qwtBoundingRectT< QwtIntervalSample >( series, from, to );
     193}
     194
     195/*!
     196   \brief Calculate the bounding rectangle of a series subset
     197
     198   Slow implementation, that iterates over the series.
     199
     200   \param series Series
     201   \param from Index of the first sample, <= 0 means from the beginning
     202   \param to Index of the last sample, < 0 means to the end
     203
     204   \return Bounding rectangle
     205 */
     206QRectF qwtBoundingRect(
     207    const QwtSeriesData< QwtOHLCSample >& series, int from, int to )
     208{
     209    return qwtBoundingRectT< QwtOHLCSample >( series, from, to );
     210}
     211
     212/*!
     213   \brief Calculate the bounding rectangle of a series subset
     214
     215   Slow implementation, that iterates over the series.
     216
     217   \param series Series
     218   \param from Index of the first sample, <= 0 means from the beginning
     219   \param to Index of the last sample, < 0 means to the end
     220
     221   \return Bounding rectangle
     222 */
     223QRectF qwtBoundingRect(
     224    const QwtSeriesData< QwtSetSample >& series, int from, int to )
     225{
     226    return qwtBoundingRectT< QwtSetSample >( series, from, to );
     227}
     228
     229/*!
     230   \brief Calculate the bounding rectangle of a series subset
     231
     232   Slow implementation, that iterates over the series.
     233
     234   \param series Series
     235   \param from Index of the first sample, <= 0 means from the beginning
     236   \param to Index of the last sample, < 0 means to the end
     237
     238   \return Bounding rectangle
     239 */
     240QRectF qwtBoundingRect(
     241    const QwtSeriesData< QwtVectorFieldSample >& series, int from, int to )
     242{
     243    return qwtBoundingRectT< QwtVectorFieldSample >( series, from, to );
     244}
  • trunk/BNC/qwt/qwt_series_data.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_SERIES_DATA_H
    11 #define QWT_SERIES_DATA_H 1
     11#define QWT_SERIES_DATA_H
    1212
    1313#include "qwt_global.h"
    1414#include "qwt_samples.h"
    1515#include "qwt_point_3d.h"
    16 #include "qwt_point_polar.h"
     16
    1717#include <qvector.h>
    1818#include <qrect.h>
     19
     20class QwtPointPolar;
    1921
    2022/*!
    … …  
    4143     but often it is possible to implement a more efficient algorithm
    4244     depending on the characteristics of the series.
    43      The member d_boundingRect is intended for caching the calculated rectangle.
    44 
    45 */
    46 template <typename T>
     45     The member cachedBoundingRect is intended for caching the calculated rectangle.
     46
     47 */
     48template< typename T >
    4749class QwtSeriesData
    4850{
    49 public:
     51  public:
    5052    //! Constructor
    5153    QwtSeriesData();
    … …  
    6062
    6163    /*!
    62       Return a sample
    63       \param i Index
    64       \return Sample at position i
     64       Return a sample
     65       \param i Index
     66       \return Sample at position i
    6567     */
    6668    virtual T sample( size_t i ) const = 0;
    67 
    68     /*!
    69        Calculate the bounding rect of all samples
    70 
    71        The bounding rect is necessary for autoscaling and can be used
    72        for a couple of painting optimizations.
    73 
    74        qwtBoundingRect(...) offers slow implementations iterating
    75        over the samples. For large sets it is recommended to implement
    76        something faster f.e. by caching the bounding rectangle.
    77 
    78        \return Bounding rectangle
    79      */
    80     virtual QRectF boundingRect() const = 0;
    8169
    8270#else
    … …  
    8472    virtual size_t size() const { return 0; }
    8573    virtual T sample( size_t i ) const { return T(); }
    86     virtual QRectF boundingRect() const { return d_boundingRect; }
    8774#endif
     75
     76    /*!
     77        Returns the first sample in the list.
     78        \warning This function assumes that the list isn't empty.
     79     */
     80    inline T firstSample() const { return sample( 0 ); }
     81
     82    /*!
     83        Returns the first sample in the list.
     84        \warning This function assumes that the list isn't empty.
     85     */
     86    inline T lastSample() const { return sample( size() - 1 ); }
     87
     88    /*!
     89       Calculate the bounding rect of all samples
     90
     91       The bounding rect is necessary for autoscaling and can be used
     92       for a couple of painting optimizations.
     93
     94       qwtBoundingRect(...) offers slow implementations iterating
     95       over the samples. For large sets it is recommended to implement
     96       something faster.
     97
     98       \return Bounding rectangle
     99     */
     100     virtual QRectF boundingRect() const
     101     {
     102        if ( cachedBoundingRect.width() < 0.0 )
     103            cachedBoundingRect = qwtBoundingRect( *this );
     104
     105        return cachedBoundingRect;
     106     }
    88107
    89108    /*!
    … …  
    97116
    98117       \param rect Rectangle of interest
    99     */
    100     virtual void setRectOfInterest( const QRectF &rect );
    101 
    102 protected:
     118     */
     119    virtual void setRectOfInterest( const QRectF& rect );
     120
     121  protected:
    103122    //! Can be used to cache a calculated bounding rectangle
    104     mutable QRectF d_boundingRect;
    105 
    106 private:
    107     QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
     123    mutable QRectF cachedBoundingRect;
     124
     125  private:
     126    QwtSeriesData< T >& operator=( const QwtSeriesData< T >& );
    108127};
    109128
    110 template <typename T>
    111 QwtSeriesData<T>::QwtSeriesData():
    112     d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
    113 {
    114 }
    115 
    116 template <typename T>
    117 QwtSeriesData<T>::~QwtSeriesData()
    118 {
    119 }
    120 
    121 template <typename T>
    122 void QwtSeriesData<T>::setRectOfInterest( const QRectF & )
     129template< typename T >
     130QwtSeriesData< T >::QwtSeriesData()
     131    : cachedBoundingRect( 0.0, 0.0, -1.0, -1.0 )
     132{
     133}
     134
     135template< typename T >
     136QwtSeriesData< T >::~QwtSeriesData()
     137{
     138}
     139
     140template< typename T >
     141void QwtSeriesData< T >::setRectOfInterest( const QRectF& )
    123142{
    124143}
    125144
    126145/*!
    127   \brief Template class for data, that is organized as QVector
    128 
    129   QVector uses implicit data sharing and can be
    130   passed around as argument efficiently.
    131 */
    132 template <typename T>
    133 class QwtArraySeriesData: public QwtSeriesData<T>
    134 {
    135 public:
     146   \brief Template class for data, that is organized as QVector
     147
     148   QVector uses implicit data sharing and can be
     149   passed around as argument efficiently.
     150 */
     151template< typename T >
     152class QwtArraySeriesData : public QwtSeriesData< T >
     153{
     154  public:
    136155    //! Constructor
    137156    QwtArraySeriesData();
    … …  
    140159       Constructor
    141160       \param samples Array of samples
    142     */
    143     QwtArraySeriesData( const QVector<T> &samples );
    144 
    145     /*!
    146       Assign an array of samples
    147       \param samples Array of samples
    148     */
    149     void setSamples( const QVector<T> &samples );
     161     */
     162    explicit QwtArraySeriesData( const QVector< T >& samples );
     163
     164    /*!
     165       Assign an array of samples
     166       \param samples Array of samples
     167     */
     168    void setSamples( const QVector< T >& samples );
    150169
    151170    //! \return Array of samples
    152     const QVector<T> samples() const;
     171    const QVector< T > samples() const;
    153172
    154173    //! \return Number of samples
    155     virtual size_t size() const;
    156 
    157     /*!
    158       \return Sample at a specific position
    159 
    160       \param index Index
    161       \return Sample at position index
    162     */
    163     virtual T sample( size_t index ) const;
    164 
    165 protected:
     174    virtual size_t size() const QWT_OVERRIDE;
     175
     176    /*!
     177       \return Sample at a specific position
     178
     179       \param index Index
     180       \return Sample at position index
     181     */
     182    virtual T sample( size_t index ) const QWT_OVERRIDE;
     183
     184  protected:
    166185    //! Vector of samples
    167     QVector<T> d_samples;
     186    QVector< T > m_samples;
    168187};
    169188
    170 template <typename T>
    171 QwtArraySeriesData<T>::QwtArraySeriesData()
    172 {
    173 }
    174 
    175 template <typename T>
    176 QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
    177     d_samples( samples )
    178 {
    179 }
    180 
    181 template <typename T>
    182 void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
    183 {
    184     QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
    185     d_samples = samples;
    186 }
    187 
    188 template <typename T>
    189 const QVector<T> QwtArraySeriesData<T>::samples() const
    190 {
    191     return d_samples;
    192 }
    193 
    194 template <typename T>
    195 size_t QwtArraySeriesData<T>::size() const
    196 {
    197     return d_samples.size();
    198 }
    199 
    200 template <typename T>
    201 T QwtArraySeriesData<T>::sample( size_t i ) const
    202 {
    203     return d_samples[ static_cast<int>( i ) ];
     189template< typename T >
     190QwtArraySeriesData< T >::QwtArraySeriesData()
     191{
     192}
     193
     194template< typename T >
     195QwtArraySeriesData< T >::QwtArraySeriesData( const QVector< T >& samples )
     196    : m_samples( samples )
     197{
     198}
     199
     200template< typename T >
     201void QwtArraySeriesData< T >::setSamples( const QVector< T >& samples )
     202{
     203    QwtSeriesData< T >::cachedBoundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
     204    m_samples = samples;
     205}
     206
     207template< typename T >
     208const QVector< T > QwtArraySeriesData< T >::samples() const
     209{
     210    return m_samples;
     211}
     212
     213template< typename T >
     214size_t QwtArraySeriesData< T >::size() const
     215{
     216    return m_samples.size();
     217}
     218
     219template< typename T >
     220T QwtArraySeriesData< T >::sample( size_t i ) const
     221{
     222    return m_samples[ static_cast< int >( i ) ];
    204223}
    205224
    206225//! Interface for iterating over an array of points
    207 class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF>
    208 {
    209 public:
    210     QwtPointSeriesData(
    211         const QVector<QPointF> & = QVector<QPointF>() );
    212 
    213     virtual QRectF boundingRect() const;
    214 };
     226typedef QwtArraySeriesData< QPointF > QwtPointSeriesData;
    215227
    216228//! Interface for iterating over an array of 3D points
    217 class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D>
    218 {
    219 public:
    220     QwtPoint3DSeriesData(
    221         const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
    222     virtual QRectF boundingRect() const;
    223 };
     229typedef QwtArraySeriesData< QwtPoint3D > QwtPoint3DSeriesData;
    224230
    225231//! Interface for iterating over an array of intervals
    226 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
    227 {
    228 public:
    229     QwtIntervalSeriesData(
    230         const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
    231 
    232     virtual QRectF boundingRect() const;
    233 };
     232typedef QwtArraySeriesData< QwtIntervalSample > QwtIntervalSeriesData;
    234233
    235234//! Interface for iterating over an array of samples
    236 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
    237 {
    238 public:
    239     QwtSetSeriesData(
    240         const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
    241 
    242     virtual QRectF boundingRect() const;
    243 };
    244 
    245 /*!
    246     Interface for iterating over an array of OHLC samples
    247 */
    248 class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample>
    249 {
    250 public:
    251     QwtTradingChartData(
    252         const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() );
    253 
    254     virtual QRectF boundingRect() const;
    255 };
    256 
    257 QWT_EXPORT QRectF qwtBoundingRect(
    258     const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
    259 
    260 QWT_EXPORT QRectF qwtBoundingRect(
    261     const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
    262 
    263 QWT_EXPORT QRectF qwtBoundingRect(
    264     const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
    265 
    266 QWT_EXPORT QRectF qwtBoundingRect(
    267     const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
    268 
    269 QWT_EXPORT QRectF qwtBoundingRect(
    270     const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
    271 
    272 QWT_EXPORT QRectF qwtBoundingRect(
    273     const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 );
     235typedef QwtArraySeriesData< QwtSetSample > QwtSetSeriesData;
     236
     237//! Interface for iterating over an array of vector field samples
     238typedef QwtArraySeriesData< QwtVectorFieldSample > QwtVectorFieldData;
     239
     240//!  Interface for iterating over an array of OHLC samples
     241typedef QwtArraySeriesData< QwtOHLCSample > QwtTradingChartData;
     242
     243QWT_EXPORT QRectF qwtBoundingRect(
     244    const QwtSeriesData< QPointF >&, int from = 0, int to = -1 );
     245
     246QWT_EXPORT QRectF qwtBoundingRect(
     247    const QwtSeriesData< QwtPoint3D >&, int from = 0, int to = -1 );
     248
     249QWT_EXPORT QRectF qwtBoundingRect(
     250    const QwtSeriesData< QwtPointPolar >&, int from = 0, int to = -1 );
     251
     252QWT_EXPORT QRectF qwtBoundingRect(
     253    const QwtSeriesData< QwtIntervalSample >&, int from = 0, int to = -1 );
     254
     255QWT_EXPORT QRectF qwtBoundingRect(
     256    const QwtSeriesData< QwtSetSample >&, int from = 0, int to = -1 );
     257
     258QWT_EXPORT QRectF qwtBoundingRect(
     259    const QwtSeriesData< QwtOHLCSample >&, int from = 0, int to = -1 );
     260
     261QWT_EXPORT QRectF qwtBoundingRect(
     262    const QwtSeriesData< QwtVectorFieldSample >&, int from = 0, int to = -1 );
    274263
    275264/*!
    … …  
    281270    value the return value will be -1.
    282271
    283   \par Example
     272   \par Example
    284273    The following example shows finds a point of curve from an x
    285274    coordinate
    286275    \code
    287       #include <qwt_series_data.h>
    288       #include <qwt_plot_curve.h>
     276 #include <qwt_series_data.h>
     277 #include <qwt_plot_curve.h>
    289278
    290279      struct compareX
    … …  
    299288      {
    300289          int index = qwtUpperSampleIndex<QPointF>(
    301               *curve->data(), x, compareX() );
     290 * curve->data(), x, compareX() );
    302291
    303292          if ( index == -1 &&
    … …  
    319308
    320309    \endcode
    321   \endpar
    322 
    323   \param series Series of samples
    324   \param value Value
    325   \param lessThan Compare operation
    326 
    327   \note The samples must be sorted according to the order specified
     310   \endpar
     311
     312   \param series Series of samples
     313   \param value Value
     314   \param lessThan Compare operation
     315
     316   \note The samples must be sorted according to the order specified
    328317        by the lessThan object
    329318 */
    330 template <typename T, typename LessThan>
    331 inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series,
     319template< typename T, typename LessThan >
     320inline int qwtUpperSampleIndex( const QwtSeriesData< T >& series,
    332321    double value, LessThan lessThan  )
    333322{
    334323    const int indexMax = series.size() - 1;
    335324
    336     if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) )  )
     325    if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
    337326        return -1;
    338327
  • trunk/BNC/qwt/qwt_series_store.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1515
    1616/*!
    17   \brief Bridge between QwtSeriesStore and QwtPlotSeriesItem
    18 
    19   QwtAbstractSeriesStore is an abstract interface only
    20   to make it possible to isolate the template based methods ( QwtSeriesStore )
    21   from the regular methods ( QwtPlotSeriesItem ) to make it possible
    22   to derive from QwtPlotSeriesItem without any hassle with templates.
    23 */
     17   \brief Bridge between QwtSeriesStore and QwtPlotSeriesItem
     18
     19   QwtAbstractSeriesStore is an abstract interface only
     20   to make it possible to isolate the template based methods ( QwtSeriesStore )
     21   from the regular methods ( QwtPlotSeriesItem ) to make it possible
     22   to derive from QwtPlotSeriesItem without any hassle with templates.
     23 */
    2424class QwtAbstractSeriesStore
    2525{
    26 protected:
     26  public:
    2727    //! Destructor
    2828    virtual ~QwtAbstractSeriesStore() {}
    2929
     30  protected:
    3031#ifndef QWT_PYTHON_WRAPPER
    3132    //! dataChanged() indicates, that the series has been changed.
    … …  
    3334
    3435    /*!
    35       Set a the "rectangle of interest" for the stored series
    36       \sa QwtSeriesData<T>::setRectOfInterest()
    37      */
    38     virtual void setRectOfInterest( const QRectF & ) = 0;
     36       Set a the "rectangle of interest" for the stored series
     37       \sa QwtSeriesData<T>::setRectOfInterest()
     38     */
     39    virtual void setRectOfInterest( const QRectF& ) = 0;
    3940
    4041    //! \return Bounding rectangle of the stored series
    … …  
    4647    // Needed for generating the python bindings, but not for using them !
    4748    virtual void dataChanged() {}
    48     virtual void setRectOfInterest( const QRectF & ) {}
    49     virtual QRectF dataRect() const { return  QRectF( 0.0, 0.0, -1.0, -1.0 ); }
     49    virtual void setRectOfInterest( const QRectF& ) {}
     50    virtual QRectF dataRect() const { return QRectF( 0.0, 0.0, -1.0, -1.0 ); }
    5051    virtual size_t dataSize() const { return 0; }
    5152#endif
    … …  
    5354
    5455/*!
    55   \brief Class storing a QwtSeriesData object
    56 
    57   QwtSeriesStore and QwtPlotSeriesItem are intended as base classes for all
    58   plot items iterating over a series of samples. Both classes share
    59   a virtual base class ( QwtAbstractSeriesStore ) to bridge between them.
    60 
    61   QwtSeriesStore offers the template based part for the plot item API, so
    62   that QwtPlotSeriesItem can be derived without any hassle with templates.
     56   \brief Class storing a QwtSeriesData object
     57
     58   QwtSeriesStore and QwtPlotSeriesItem are intended as base classes for all
     59   plot items iterating over a series of samples. Both classes share
     60   a virtual base class ( QwtAbstractSeriesStore ) to bridge between them.
     61
     62   QwtSeriesStore offers the template based part for the plot item API, so
     63   that QwtPlotSeriesItem can be derived without any hassle with templates.
    6364 */
    64 template <typename T>
    65 class QwtSeriesStore: public virtual QwtAbstractSeriesStore
    66 {
    67 public:
    68     /*!
    69       \brief Constructor
    70       The store contains no series
    71     */
    72     explicit QwtSeriesStore<T>();
     65template< typename T >
     66class QwtSeriesStore : public virtual QwtAbstractSeriesStore
     67{
     68  public:
     69    /*!
     70       \brief Constructor
     71       The store contains no series
     72     */
     73    explicit QwtSeriesStore();
    7374
    7475    //! Destructor
    75     ~QwtSeriesStore<T>();
    76 
    77     /*!
    78       Assign a series of samples
    79 
    80       \param series Data
    81       \warning The item takes ownership of the data object, deleting
     76    ~QwtSeriesStore();
     77
     78    /*!
     79       Assign a series of samples
     80
     81       \param series Data
     82       \warning The item takes ownership of the data object, deleting
    8283               it when its not used anymore.
    83     */
    84     void setData( QwtSeriesData<T> *series );
     84     */
     85    void setData( QwtSeriesData< T >* series );
    8586
    8687    //! \return the the series data
    87     QwtSeriesData<T> *data();
     88    QwtSeriesData< T >* data();
    8889
    8990    //! \return the the series data
    90     const QwtSeriesData<T> *data() const;
     91    const QwtSeriesData< T >* data() const;
    9192
    9293    /*!
    9394        \param index Index
    9495        \return Sample at position index
    95     */
     96     */
    9697    T sample( int index ) const;
    9798
    9899    /*!
    99       \return Number of samples of the series
    100       \sa setData(), QwtSeriesData<T>::size()
    101     */
    102     virtual size_t dataSize() const;
    103 
    104     /*!
    105       \return Bounding rectangle of the series
     100       \return Number of samples of the series
     101       \sa setData(), QwtSeriesData<T>::size()
     102     */
     103    virtual size_t dataSize() const QWT_OVERRIDE;
     104
     105    /*!
     106       \return Bounding rectangle of the series
    106107              or an invalid rectangle, when no series is stored
    107108
    108       \sa QwtSeriesData<T>::boundingRect()
    109     */
    110     virtual QRectF dataRect() const;
    111 
    112     /*!
    113       Set a the "rect of interest" for the series
    114 
    115       \param rect Rectangle of interest
    116       \sa QwtSeriesData<T>::setRectOfInterest()
    117     */
    118     virtual void setRectOfInterest( const QRectF &rect );
    119 
    120     /*!
    121       Replace a series without deleting the previous one
    122 
    123       \param series New series
    124       \return Previously assigned series
    125      */
    126     QwtSeriesData<T> *swapData( QwtSeriesData<T> *series );
    127 
    128 private:
    129     QwtSeriesData<T> *d_series;
     109       \sa QwtSeriesData<T>::boundingRect()
     110     */
     111    virtual QRectF dataRect() const QWT_OVERRIDE;
     112
     113    /*!
     114       Set a the "rect of interest" for the series
     115
     116       \param rect Rectangle of interest
     117       \sa QwtSeriesData<T>::setRectOfInterest()
     118     */
     119    virtual void setRectOfInterest( const QRectF& rect ) QWT_OVERRIDE;
     120
     121    /*!
     122       Replace a series without deleting the previous one
     123
     124       \param series New series
     125       \return Previously assigned series
     126     */
     127    QwtSeriesData< T >* swapData( QwtSeriesData< T >* series );
     128
     129  private:
     130    QwtSeriesData< T >* m_series;
    130131};
    131132
    132 template <typename T>
    133 QwtSeriesStore<T>::QwtSeriesStore():
    134     d_series( NULL )
    135 {
    136 }
    137 
    138 template <typename T>
    139 QwtSeriesStore<T>::~QwtSeriesStore()
    140 {
    141     delete d_series;
    142 }
    143 
    144 template <typename T>
    145 inline QwtSeriesData<T> *QwtSeriesStore<T>::data()
    146 {
    147     return d_series;
    148 }
    149 
    150 template <typename T>
    151 inline const QwtSeriesData<T> *QwtSeriesStore<T>::data() const
    152 {
    153     return d_series;
    154 }
    155 
    156 template <typename T>
    157 inline T QwtSeriesStore<T>::sample( int index ) const
    158 {
    159     return d_series ? d_series->sample( index ) : T();
    160 }
    161 
    162 template <typename T>
    163 void QwtSeriesStore<T>::setData( QwtSeriesData<T> *series )
    164 {
    165     if ( d_series != series )
     133template< typename T >
     134QwtSeriesStore< T >::QwtSeriesStore()
     135    : m_series( NULL )
     136{
     137}
     138
     139template< typename T >
     140QwtSeriesStore< T >::~QwtSeriesStore()
     141{
     142    delete m_series;
     143}
     144
     145template< typename T >
     146inline QwtSeriesData< T >* QwtSeriesStore< T >::data()
     147{
     148    return m_series;
     149}
     150
     151template< typename T >
     152inline const QwtSeriesData< T >* QwtSeriesStore< T >::data() const
     153{
     154    return m_series;
     155}
     156
     157template< typename T >
     158inline T QwtSeriesStore< T >::sample( int index ) const
     159{
     160    return m_series ? m_series->sample( index ) : T();
     161}
     162
     163template< typename T >
     164void QwtSeriesStore< T >::setData( QwtSeriesData< T >* series )
     165{
     166    if ( m_series != series )
    166167    {
    167         delete d_series;
    168         d_series = series;
     168        delete m_series;
     169        m_series = series;
    169170        dataChanged();
    170171    }
    171172}
    172173
    173 template <typename T>
    174 size_t QwtSeriesStore<T>::dataSize() const
    175 {
    176     if ( d_series == NULL )
     174template< typename T >
     175size_t QwtSeriesStore< T >::dataSize() const
     176{
     177    if ( m_series == NULL )
    177178        return 0;
    178179
    179     return d_series->size();
    180 }
    181 
    182 template <typename T>
    183 QRectF QwtSeriesStore<T>::dataRect() const
    184 {
    185     if ( d_series == NULL )
     180    return m_series->size();
     181}
     182
     183template< typename T >
     184QRectF QwtSeriesStore< T >::dataRect() const
     185{
     186    if ( m_series == NULL )
    186187        return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
    187188
    188     return d_series->boundingRect();
    189 }
    190 
    191 template <typename T>
    192 void QwtSeriesStore<T>::setRectOfInterest( const QRectF &rect )
    193 {
    194     if ( d_series )
    195         d_series->setRectOfInterest( rect );
    196 }
    197 
    198 template <typename T>
    199 QwtSeriesData<T>* QwtSeriesStore<T>::swapData( QwtSeriesData<T> *series )
    200 {
    201     QwtSeriesData<T> * swappedSeries = d_series;
    202     d_series = series;
     189    return m_series->boundingRect();
     190}
     191
     192template< typename T >
     193void QwtSeriesStore< T >::setRectOfInterest( const QRectF& rect )
     194{
     195    if ( m_series )
     196        m_series->setRectOfInterest( rect );
     197}
     198
     199template< typename T >
     200QwtSeriesData< T >* QwtSeriesStore< T >::swapData( QwtSeriesData< T >* series )
     201{
     202    QwtSeriesData< T >* swappedSeries = m_series;
     203    m_series = series;
    203204
    204205    return swappedSeries;
  • trunk/BNC/qwt/qwt_slider.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212#include "qwt_scale_draw.h"
    1313#include "qwt_scale_map.h"
     14#include "qwt_math.h"
     15#include "qwt.h"
     16
    1417#include <qevent.h>
    1518#include <qdrawutil.h>
    1619#include <qpainter.h>
    17 #include <qalgorithms.h>
    18 #include <qmath.h>
    1920#include <qstyle.h>
    2021#include <qstyleoption.h>
    21 #include <qapplication.h>
    22 
    23 static QSize qwtHandleSize( const QSize &size,
     22#include <qmargins.h>
     23
     24static QSize qwtHandleSize( const QSize& size,
    2425    Qt::Orientation orientation, bool hasTrough )
    2526{
    … …  
    6970class QwtSlider::PrivateData
    7071{
    71 public:
    72     PrivateData():
    73         repeatTimerId( 0 ),
    74         updateInterval( 150 ),
    75         stepsIncrement( 0 ),
    76         pendingValueChange( false ),
    77         borderWidth( 2 ),
    78         spacing( 4 ),
    79         scalePosition( QwtSlider::TrailingScale ),
    80         hasTrough( true ),
    81         hasGroove( false ),
    82         mouseOffset( 0 )
     72  public:
     73    PrivateData()
     74        : repeatTimerId( 0 )
     75        , updateInterval( 150 )
     76        , stepsIncrement( 0 )
     77        , pendingValueChange( false )
     78        , borderWidth( 2 )
     79        , spacing( 4 )
     80        , scalePosition( QwtSlider::TrailingScale )
     81        , hasTrough( true )
     82        , hasGroove( false )
     83        , mouseOffset( 0 )
    8384    {
    8485    }
    … …  
    107108};
    108109/*!
    109   Construct vertical slider in QwtSlider::Trough style
    110   with a scale to the left.
    111 
    112   The scale is initialized to [0.0, 100.0] and the value set to 0.0.
    113 
    114   \param parent Parent widget
    115 
    116   \sa setOrientation(), setScalePosition(), setBackgroundStyle()
    117 */
    118 QwtSlider::QwtSlider( QWidget *parent ):
    119     QwtAbstractSlider( parent )
     110   Construct vertical slider in QwtSlider::Trough style
     111   with a scale to the left.
     112
     113   The scale is initialized to [0.0, 100.0] and the value set to 0.0.
     114
     115   \param parent Parent widget
     116
     117   \sa setOrientation(), setScalePosition(), setBackgroundStyle()
     118 */
     119QwtSlider::QwtSlider( QWidget* parent )
     120    : QwtAbstractSlider( parent )
    120121{
    121122    initSlider( Qt::Vertical );
    … …  
    123124
    124125/*!
    125   Construct a slider in QwtSlider::Trough style
    126 
    127   When orientation is Qt::Vertical the scale will be aligned to
    128   the left - otherwise at the the top of the slider.
    129 
    130   The scale is initialized to [0.0, 100.0] and the value set to 0.0.
    131 
    132   \param parent Parent widget
    133   \param orientation Orientation of the slider.
    134 */
    135 QwtSlider::QwtSlider( Qt::Orientation orientation, QWidget *parent ):
    136     QwtAbstractSlider( parent )
     126   Construct a slider in QwtSlider::Trough style
     127
     128   When orientation is Qt::Vertical the scale will be aligned to
     129   the left - otherwise at the the top of the slider.
     130
     131   The scale is initialized to [0.0, 100.0] and the value set to 0.0.
     132
     133   \param parent Parent widget
     134   \param orientation Orientation of the slider.
     135 */
     136QwtSlider::QwtSlider( Qt::Orientation orientation, QWidget* parent )
     137    : QwtAbstractSlider( parent )
    137138{
    138139    initSlider( orientation );
    … …  
    142143QwtSlider::~QwtSlider()
    143144{
    144     delete d_data;
     145    delete m_data;
    145146}
    146147
    … …  
    154155    setAttribute( Qt::WA_WState_OwnSizePolicy, false );
    155156
    156     d_data = new QwtSlider::PrivateData;
    157 
    158     d_data->orientation = orientation;
     157    m_data = new QwtSlider::PrivateData;
     158
     159    m_data->orientation = orientation;
    159160
    160161    scaleDraw()->setAlignment(
    161         qwtScaleDrawAlignment( orientation, d_data->scalePosition ) );
     162        qwtScaleDrawAlignment( orientation, m_data->scalePosition ) );
    162163    scaleDraw()->setLength( 100 );
    163164
    … …  
    167168
    168169/*!
    169   \brief Set the orientation.
    170   \param orientation Allowed values are Qt::Horizontal and Qt::Vertical.
    171 
    172   \sa orientation(), scalePosition()
    173 */
     170   \brief Set the orientation.
     171   \param orientation Allowed values are Qt::Horizontal and Qt::Vertical.
     172
     173   \sa orientation(), scalePosition()
     174 */
    174175void QwtSlider::setOrientation( Qt::Orientation orientation )
    175176{
    176     if ( orientation == d_data->orientation )
     177    if ( orientation == m_data->orientation )
    177178        return;
    178179
    179     d_data->orientation = orientation;
     180    m_data->orientation = orientation;
    180181
    181182    scaleDraw()->setAlignment(
    182         qwtScaleDrawAlignment( orientation, d_data->scalePosition ) );
     183        qwtScaleDrawAlignment( orientation, m_data->scalePosition ) );
    183184
    184185    if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
    … …  
    196197
    197198/*!
    198   \return Orientation
    199   \sa setOrientation()
    200 */
     199   \return Orientation
     200   \sa setOrientation()
     201 */
    201202Qt::Orientation QwtSlider::orientation() const
    202203{
    203     return d_data->orientation;
    204 }
    205 
    206 /*!
    207   \brief Change the position of the scale
    208   \param scalePosition Position of the scale.
    209 
    210   \sa ScalePosition, scalePosition()
    211 */
     204    return m_data->orientation;
     205}
     206
     207/*!
     208   \brief Change the position of the scale
     209   \param scalePosition Position of the scale.
     210
     211   \sa ScalePosition, scalePosition()
     212 */
    212213void QwtSlider::setScalePosition( ScalePosition scalePosition )
    213214{
    214     if ( d_data->scalePosition == scalePosition )
     215    if ( m_data->scalePosition == scalePosition )
    215216        return;
    216217
    217     d_data->scalePosition = scalePosition;
     218    m_data->scalePosition = scalePosition;
    218219    scaleDraw()->setAlignment(
    219         qwtScaleDrawAlignment( d_data->orientation, scalePosition ) );
     220        qwtScaleDrawAlignment( m_data->orientation, scalePosition ) );
    220221
    221222    if ( testAttribute( Qt::WA_WState_Polished ) )
    … …  
    224225
    225226/*!
    226   \return Position of the scale
    227   \sa setScalePosition()
     227   \return Position of the scale
     228   \sa setScalePosition()
    228229 */
    229230QwtSlider::ScalePosition QwtSlider::scalePosition() const
    230231{
    231     return d_data->scalePosition;
    232 }
    233 
    234 /*!
    235   \brief Change the slider's border width
    236 
    237   The border width is used for drawing the slider handle and the
    238   trough.
    239 
    240   \param width Border width
    241   \sa borderWidth()
    242 */
     232    return m_data->scalePosition;
     233}
     234
     235/*!
     236   \brief Change the slider's border width
     237
     238   The border width is used for drawing the slider handle and the
     239   trough.
     240
     241   \param width Border width
     242   \sa borderWidth()
     243 */
    243244void QwtSlider::setBorderWidth( int width )
    244245{
    … …  
    246247        width = 0;
    247248
    248     if ( width != d_data->borderWidth )
    249     {
    250         d_data->borderWidth = width;
     249    if ( width != m_data->borderWidth )
     250    {
     251        m_data->borderWidth = width;
    251252
    252253        if ( testAttribute( Qt::WA_WState_Polished ) )
    … …  
    256257
    257258/*!
    258   \return the border width.
    259   \sa setBorderWidth()
    260 */
     259   \return the border width.
     260   \sa setBorderWidth()
     261 */
    261262int QwtSlider::borderWidth() const
    262263{
    263     return d_data->borderWidth;
    264 }
    265 
    266 /*!
    267   \brief Change the spacing between trough and scale
    268 
    269   A spacing of 0 means, that the backbone of the scale is covered
    270   by the trough.
    271 
    272   The default setting is 4 pixels.
    273 
    274   \param spacing Number of pixels
    275   \sa spacing();
    276 */
     264    return m_data->borderWidth;
     265}
     266
     267/*!
     268   \brief Change the spacing between trough and scale
     269
     270   A spacing of 0 means, that the backbone of the scale is covered
     271   by the trough.
     272
     273   The default setting is 4 pixels.
     274
     275   \param spacing Number of pixels
     276   \sa spacing();
     277 */
    277278void QwtSlider::setSpacing( int spacing )
    278279{
    … …  
    280281        spacing = 0;
    281282
    282     if ( spacing != d_data->spacing  )
    283     {
    284         d_data->spacing = spacing;
     283    if ( spacing != m_data->spacing  )
     284    {
     285        m_data->spacing = spacing;
    285286
    286287        if ( testAttribute( Qt::WA_WState_Polished ) )
    … …  
    290291
    291292/*!
    292   \return Number of pixels between slider and scale
    293   \sa setSpacing()
    294 */
     293   \return Number of pixels between slider and scale
     294   \sa setSpacing()
     295 */
    295296int QwtSlider::spacing() const
    296297{
    297     return d_data->spacing;
    298 }
    299 
    300 /*!
    301   \brief Set the slider's handle size
    302 
    303   When the size is empty the slider handle will be painted with a
    304   default size depending on its orientation() and backgroundStyle().
    305 
    306   \param size New size
    307 
    308   \sa handleSize()
    309 */
    310 void QwtSlider::setHandleSize( const QSize &size )
    311 {
    312     if ( size != d_data->handleSize )
    313     {
    314         d_data->handleSize = size;
     298    return m_data->spacing;
     299}
     300
     301/*!
     302   \brief Set the slider's handle size
     303
     304   When the size is empty the slider handle will be painted with a
     305   default size depending on its orientation() and backgroundStyle().
     306
     307   \param size New size
     308
     309   \sa handleSize()
     310 */
     311void QwtSlider::setHandleSize( const QSize& size )
     312{
     313    if ( size != m_data->handleSize )
     314    {
     315        m_data->handleSize = size;
    315316
    316317        if ( testAttribute( Qt::WA_WState_Polished ) )
    … …  
    320321
    321322/*!
    322   \return Size of the handle.
    323   \sa setHandleSize()
    324 */
     323   \return Size of the handle.
     324   \sa setHandleSize()
     325 */
    325326QSize QwtSlider::handleSize() const
    326327{
    327     return d_data->handleSize;
    328 }
    329 
    330 /*!
    331   \brief Set a scale draw
    332 
    333   For changing the labels of the scales, it
    334   is necessary to derive from QwtScaleDraw and
    335   overload QwtScaleDraw::label().
    336 
    337   \param scaleDraw ScaleDraw object, that has to be created with
     328    return m_data->handleSize;
     329}
     330
     331/*!
     332   \brief Set a scale draw
     333
     334   For changing the labels of the scales, it
     335   is necessary to derive from QwtScaleDraw and
     336   overload QwtScaleDraw::label().
     337
     338   \param scaleDraw ScaleDraw object, that has to be created with
    338339                   new and will be deleted in ~QwtSlider() or the next
    339340                   call of setScaleDraw().
    340341
    341   \sa scaleDraw()
    342 */
    343 void QwtSlider::setScaleDraw( QwtScaleDraw *scaleDraw )
    344 {
    345     const QwtScaleDraw *previousScaleDraw = this->scaleDraw();
     342   \sa scaleDraw()
     343 */
     344void QwtSlider::setScaleDraw( QwtScaleDraw* scaleDraw )
     345{
     346    const QwtScaleDraw* previousScaleDraw = this->scaleDraw();
    346347    if ( scaleDraw == NULL || scaleDraw == previousScaleDraw )
    347348        return;
    … …  
    357358
    358359/*!
    359   \return the scale draw of the slider
    360   \sa setScaleDraw()
    361 */
    362 const QwtScaleDraw *QwtSlider::scaleDraw() const
    363 {
    364     return static_cast<const QwtScaleDraw *>( abstractScaleDraw() );
    365 }
    366 
    367 /*!
    368   \return the scale draw of the slider
    369   \sa setScaleDraw()
    370 */
    371 QwtScaleDraw *QwtSlider::scaleDraw()
    372 {
    373     return static_cast<QwtScaleDraw *>( abstractScaleDraw() );
     360   \return the scale draw of the slider
     361   \sa setScaleDraw()
     362 */
     363const QwtScaleDraw* QwtSlider::scaleDraw() const
     364{
     365    return static_cast< const QwtScaleDraw* >( abstractScaleDraw() );
     366}
     367
     368/*!
     369   \return the scale draw of the slider
     370   \sa setScaleDraw()
     371 */
     372QwtScaleDraw* QwtSlider::scaleDraw()
     373{
     374    return static_cast< QwtScaleDraw* >( abstractScaleDraw() );
    374375}
    375376
    … …  
    384385
    385386/*!
    386   \brief Specify the update interval for automatic scrolling
    387 
    388   The minimal accepted value is 50 ms.
    389 
    390   \param interval Update interval in milliseconds
    391 
    392   \sa setUpdateInterval()
    393 */
     387   \brief Specify the update interval for automatic scrolling
     388
     389   The minimal accepted value is 50 ms.
     390
     391   \param interval Update interval in milliseconds
     392
     393   \sa setUpdateInterval()
     394 */
    394395void QwtSlider::setUpdateInterval( int interval )
    395396{
    396     d_data->updateInterval = qMax( interval, 50 );
    397 }
    398 
    399 /*!
    400   \return Update interval in milliseconds for automatic scrolling
    401   \sa setUpdateInterval()
     397    m_data->updateInterval = qMax( interval, 50 );
     398}
     399
     400/*!
     401   \return Update interval in milliseconds for automatic scrolling
     402   \sa setUpdateInterval()
    402403 */
    403404int QwtSlider::updateInterval() const
    404405{
    405     return d_data->updateInterval;
     406    return m_data->updateInterval;
    406407}
    407408
    … …  
    411412   \param painter Painter
    412413   \param sliderRect Bounding rectangle of the slider
    413 */
     414 */
    414415void QwtSlider::drawSlider(
    415     QPainter *painter, const QRect &sliderRect ) const
     416    QPainter* painter, const QRect& sliderRect ) const
    416417{
    417418    QRect innerRect( sliderRect );
    418419
    419     if ( d_data->hasTrough )
    420     {
    421         const int bw = d_data->borderWidth;
     420    if ( m_data->hasTrough )
     421    {
     422        const int bw = m_data->borderWidth;
    422423        innerRect = sliderRect.adjusted( bw, bw, -bw, -bw );
    423424
    … …  
    426427    }
    427428
    428     const QSize handleSize = qwtHandleSize( d_data->handleSize,
    429         d_data->orientation, d_data->hasTrough );
    430 
    431     if ( d_data->hasGroove )
    432     {
     429    if ( m_data->hasGroove )
     430    {
     431        const QSize handleSize = qwtHandleSize( m_data->handleSize,
     432            m_data->orientation, m_data->hasTrough );
     433
    433434        const int slotExtent = 4;
    434435        const int slotMargin = 4;
    … …  
    456457
    457458        QBrush brush = palette().brush( QPalette::Dark );
    458         qDrawShadePanel( painter, slotRect, palette(), true, 1 , &brush );
     459        qDrawShadePanel( painter, slotRect, palette(), true, 1, &brush );
    459460    }
    460461
    … …  
    464465
    465466/*!
    466   Draw the thumb at a position
    467 
    468   \param painter Painter
    469   \param handleRect Bounding rectangle of the handle
    470   \param pos Position of the handle marker in widget coordinates
    471 */
    472 void QwtSlider::drawHandle( QPainter *painter,
    473     const QRect &handleRect, int pos ) const
    474 {
    475     const int bw = d_data->borderWidth;
     467   Draw the thumb at a position
     468
     469   \param painter Painter
     470   \param handleRect Bounding rectangle of the handle
     471   \param pos Position of the handle marker in widget coordinates
     472 */
     473void QwtSlider::drawHandle( QPainter* painter,
     474    const QRect& handleRect, int pos ) const
     475{
     476    const int bw = m_data->borderWidth;
    476477
    477478    qDrawShadePanel( painter,
    … …  
    493494
    494495/*!
    495   \brief Determine what to do when the user presses a mouse button.
    496 
    497   \param pos Mouse position
    498 
    499   \retval True, when handleRect() contains pos
    500   \sa scrolledTo()
    501 */
    502 bool QwtSlider::isScrollPosition( const QPoint &pos ) const
     496   \brief Determine what to do when the user presses a mouse button.
     497
     498   \param pos Mouse position
     499
     500   \retval True, when handleRect() contains pos
     501   \sa scrolledTo()
     502 */
     503bool QwtSlider::isScrollPosition( const QPoint& pos ) const
    503504{
    504505    if ( handleRect().contains( pos ) )
    … …  
    507508            ? pos.x() : pos.y();
    508509
    509         d_data->mouseOffset = v - transform( value() );
     510        m_data->mouseOffset = v - transform( value() );
    510511        return true;
    511512    }
    … …  
    515516
    516517/*!
    517   \brief Determine the value for a new position of the
     518   \brief Determine the value for a new position of the
    518519         slider handle.
    519520
    520   \param pos Mouse position
    521 
    522   \return Value for the mouse position
    523   \sa isScrollPosition()
    524 */
    525 double QwtSlider::scrolledTo( const QPoint &pos ) const
     521   \param pos Mouse position
     522
     523   \return Value for the mouse position
     524   \sa isScrollPosition()
     525 */
     526double QwtSlider::scrolledTo( const QPoint& pos ) const
    526527{
    527528    int p = ( orientation() == Qt::Horizontal )
    528529        ? pos.x() : pos.y();
    529530
    530     p -= d_data->mouseOffset;
     531    p -= m_data->mouseOffset;
    531532
    532533    int min = transform( lowerBound() );
    … …  
    543544   Mouse press event handler
    544545   \param event Mouse event
    545 */
    546 void QwtSlider::mousePressEvent( QMouseEvent *event )
     546 */
     547void QwtSlider::mousePressEvent( QMouseEvent* event )
    547548{
    548549    if ( isReadOnly() )
    … …  
    554555    const QPoint pos = event->pos();
    555556
    556     if ( isValid() && d_data->sliderRect.contains( pos ) )
     557    if ( isValid() && m_data->sliderRect.contains( pos ) )
    557558    {
    558559        if ( !handleRect().contains( pos ) )
    … …  
    560561            const int markerPos = transform( value() );
    561562
    562             d_data->stepsIncrement = pageSteps();
    563 
    564             if ( d_data->orientation == Qt::Horizontal )
     563            m_data->stepsIncrement = pageSteps();
     564
     565            if ( m_data->orientation == Qt::Horizontal )
    565566            {
    566567                if ( pos.x() < markerPos )
    567                     d_data->stepsIncrement = -d_data->stepsIncrement;
     568                    m_data->stepsIncrement = -m_data->stepsIncrement;
    568569            }
    569570            else
    570571            {
    571572                if ( pos.y() < markerPos )
    572                     d_data->stepsIncrement = -d_data->stepsIncrement;
     573                    m_data->stepsIncrement = -m_data->stepsIncrement;
    573574            }
    574575
    575576            if ( isInverted() )
    576                 d_data->stepsIncrement = -d_data->stepsIncrement;
     577                m_data->stepsIncrement = -m_data->stepsIncrement;
    577578
    578579            const double v = value();
    579             incrementValue( d_data->stepsIncrement );
     580            incrementValue( m_data->stepsIncrement );
    580581
    581582            if ( v != value() )
    … …  
    584585                    Q_EMIT valueChanged( value() );
    585586                else
    586                     d_data->pendingValueChange = true;
     587                    m_data->pendingValueChange = true;
    587588
    588589                Q_EMIT sliderMoved( value() );
    589590            }
    590591
    591             d_data->timerTick = false;
    592             d_data->repeatTimerId = startTimer( qMax( 250, 2 * updateInterval() ) );
     592            m_data->timerTick = false;
     593            m_data->repeatTimerId = startTimer( qMax( 250, 2 * updateInterval() ) );
    593594
    594595            return;
    … …  
    602603   Mouse release event handler
    603604   \param event Mouse event
    604 */
    605 void QwtSlider::mouseReleaseEvent( QMouseEvent *event )
    606 {
    607     if ( d_data->repeatTimerId > 0 )
    608     {
    609         killTimer( d_data->repeatTimerId );
    610         d_data->repeatTimerId = 0;
    611         d_data->timerTick = false;
    612         d_data->stepsIncrement = 0;
    613     }
    614 
    615     if ( d_data->pendingValueChange )
    616     {
    617         d_data->pendingValueChange = false;
     605 */
     606void QwtSlider::mouseReleaseEvent( QMouseEvent* event )
     607{
     608    if ( m_data->repeatTimerId > 0 )
     609    {
     610        killTimer( m_data->repeatTimerId );
     611        m_data->repeatTimerId = 0;
     612        m_data->timerTick = false;
     613        m_data->stepsIncrement = 0;
     614    }
     615
     616    if ( m_data->pendingValueChange )
     617    {
     618        m_data->pendingValueChange = false;
    618619        Q_EMIT valueChanged( value() );
    619620    }
    … …  
    629630
    630631   \param event Mouse event
    631 */
    632 void QwtSlider::timerEvent( QTimerEvent *event )
    633 {
    634     if ( event->timerId() != d_data->repeatTimerId )
     632 */
     633void QwtSlider::timerEvent( QTimerEvent* event )
     634{
     635    if ( event->timerId() != m_data->repeatTimerId )
    635636    {
    636637        QwtAbstractSlider::timerEvent( event );
    … …  
    640641    if ( !isValid() )
    641642    {
    642         killTimer( d_data->repeatTimerId );
    643         d_data->repeatTimerId = 0;
     643        killTimer( m_data->repeatTimerId );
     644        m_data->repeatTimerId = 0;
    644645        return;
    645646    }
    646647
    647648    const double v = value();
    648     incrementValue( d_data->stepsIncrement );
     649    incrementValue( m_data->stepsIncrement );
    649650
    650651    if ( v != value() )
    … …  
    653654            Q_EMIT valueChanged( value() );
    654655        else
    655             d_data->pendingValueChange = true;
     656            m_data->pendingValueChange = true;
    656657
    657658        Q_EMIT sliderMoved( value() );
    658659    }
    659660
    660     if ( !d_data->timerTick )
     661    if ( !m_data->timerTick )
    661662    {
    662663        // restart the timer with a shorter interval
    663         killTimer( d_data->repeatTimerId );
    664         d_data->repeatTimerId = startTimer( updateInterval() );
    665 
    666         d_data->timerTick = true;
     664        killTimer( m_data->repeatTimerId );
     665        m_data->repeatTimerId = startTimer( updateInterval() );
     666
     667        m_data->timerTick = true;
    667668    }
    668669}
    … …  
    671672   Qt paint event handler
    672673   \param event Paint event
    673 */
    674 void QwtSlider::paintEvent( QPaintEvent *event )
     674 */
     675void QwtSlider::paintEvent( QPaintEvent* event )
    675676{
    676677    QPainter painter( this );
    … …  
    678679
    679680    QStyleOption opt;
    680     opt.init(this);
     681    opt.initFrom(this);
    681682    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
    682683
    683     if ( d_data->scalePosition != QwtSlider::NoScale )
    684     {
    685         if ( !d_data->sliderRect.contains( event->rect() ) )
     684    if ( m_data->scalePosition != QwtSlider::NoScale )
     685    {
     686        if ( !m_data->sliderRect.contains( event->rect() ) )
    686687            scaleDraw()->draw( &painter, palette() );
    687688    }
    688689
    689     drawSlider( &painter, d_data->sliderRect );
     690    drawSlider( &painter, m_data->sliderRect );
    690691
    691692    if ( hasFocus() )
    692         QwtPainter::drawFocusRect( &painter, this, d_data->sliderRect );
     693        QwtPainter::drawFocusRect( &painter, this, m_data->sliderRect );
    693694}
    694695
    … …  
    696697   Qt resize event handler
    697698   \param event Resize event
    698 */
    699 void QwtSlider::resizeEvent( QResizeEvent *event )
    700 {
    701     Q_UNUSED( event );
    702 
     699 */
     700void QwtSlider::resizeEvent( QResizeEvent* event )
     701{
    703702    layoutSlider( false );
     703    QwtAbstractSlider::resizeEvent( event );
     704}
     705
     706/*!
     707   Qt event handler
     708   \param event Event
     709
     710   \return true, if event was recognized and processed
     711 */
     712bool QwtSlider::event( QEvent* event )
     713{
     714    if ( event->type() == QEvent::PolishRequest )
     715        layoutSlider( false );
     716
     717    return QwtAbstractSlider::event( event );
    704718}
    705719
    … …  
    707721   Handles QEvent::StyleChange and QEvent::FontChange events
    708722   \param event Change event
    709 */
    710 void QwtSlider::changeEvent( QEvent *event )
     723 */
     724void QwtSlider::changeEvent( QEvent* event )
    711725{
    712726    if ( event->type() == QEvent::StyleChange ||
    … …  
    721735
    722736/*!
    723   Recalculate the slider's geometry and layout based on
    724   the current geometry and fonts.
    725 
    726   \param update_geometry  notify the layout system and call update
     737   Recalculate the slider's geometry and layout based on
     738   the current geometry and fonts.
     739
     740   \param update_geometry  notify the layout system and call update
    727741         to redraw the scale
    728 */
     742 */
    729743void QwtSlider::layoutSlider( bool update_geometry )
    730744{
    731745    int bw = 0;
    732     if ( d_data->hasTrough )
    733         bw = d_data->borderWidth;
    734 
    735     const QSize handleSize = qwtHandleSize( d_data->handleSize,
    736         d_data->orientation, d_data->hasTrough );
     746    if ( m_data->hasTrough )
     747        bw = m_data->borderWidth;
     748
     749    const QSize handleSize = qwtHandleSize( m_data->handleSize,
     750        m_data->orientation, m_data->hasTrough );
    737751
    738752    QRect sliderRect = contentsRect();
    … …  
    752766
    753767    int scaleMargin = 0;
    754     if ( d_data->scalePosition != QwtSlider::NoScale )
     768    if ( m_data->scalePosition != QwtSlider::NoScale )
    755769    {
    756770        int d1, d2;
    … …  
    762776    int scaleX, scaleY, scaleLength;
    763777
    764     if ( d_data->orientation == Qt::Horizontal )
     778    if ( m_data->orientation == Qt::Horizontal )
    765779    {
    766780        const int handleMargin = handleSize.width() / 2 - 1;
    … …  
    791805    // now align slider and scale according to the ScalePosition
    792806
    793     if ( d_data->orientation == Qt::Horizontal )
     807    if ( m_data->orientation == Qt::Horizontal )
    794808    {
    795809        const int h = handleSize.height() + 2 * bw;
    796810
    797         if ( d_data->scalePosition == QwtSlider::TrailingScale )
     811        if ( m_data->scalePosition == QwtSlider::TrailingScale )
    798812        {
    799813            sliderRect.setTop( sliderRect.bottom() + 1 - h );
    800             scaleY = sliderRect.top() - d_data->spacing;
     814            scaleY = sliderRect.top() - m_data->spacing;
    801815        }
    802816        else
    803817        {
    804818            sliderRect.setHeight( h );
    805             scaleY = sliderRect.bottom() + 1 + d_data->spacing;
     819            scaleY = sliderRect.bottom() + 1 + m_data->spacing;
    806820        }
    807821    }
    … …  
    810824        const int w = handleSize.width() + 2 * bw;
    811825
    812         if ( d_data->scalePosition == QwtSlider::LeadingScale )
     826        if ( m_data->scalePosition == QwtSlider::LeadingScale )
    813827        {
    814828            sliderRect.setWidth( w );
    815             scaleX = sliderRect.right() + 1 + d_data->spacing;
     829            scaleX = sliderRect.right() + 1 + m_data->spacing;
    816830        }
    817831        else
    818832        {
    819833            sliderRect.setLeft( sliderRect.right() + 1 - w );
    820             scaleX = sliderRect.left() - d_data->spacing;
     834            scaleX = sliderRect.left() - m_data->spacing;
    821835        }
    822836    }
    823837
    824     d_data->sliderRect = sliderRect;
     838    m_data->sliderRect = sliderRect;
    825839
    826840    scaleDraw()->move( scaleX, scaleY );
    … …  
    829843    if ( update_geometry )
    830844    {
    831         d_data->sizeHintCache = QSize(); // invalidate
     845        m_data->sizeHintCache = QSize(); // invalidate
    832846        updateGeometry();
    833847        update();
    … …  
    836850
    837851/*!
    838   En/Disable the trough
    839 
    840   The slider can be cutomized by showing a trough for the
    841   handle.
    842 
    843   \param on When true, the groove is visible
    844   \sa hasTrough(), setGroove()
     852   En/Disable the trough
     853
     854   The slider can be customized by showing a trough for the
     855   handle.
     856
     857   \param on When true, the groove is visible
     858   \sa hasTrough(), setGroove()
    845859 */
    846860void QwtSlider::setTrough( bool on )
    847861{
    848     if ( d_data->hasTrough != on )
    849     {
    850         d_data->hasTrough = on;
     862    if ( m_data->hasTrough != on )
     863    {
     864        m_data->hasTrough = on;
    851865
    852866        if ( testAttribute( Qt::WA_WState_Polished ) )
    … …  
    856870
    857871/*!
    858   \return True, when the trough is visisble
    859   \sa setTrough(), hasGroove()
     872   \return True, when the trough is visible
     873   \sa setTrough(), hasGroove()
    860874 */
    861875bool QwtSlider::hasTrough() const
    862876{
    863     return d_data->hasTrough;
    864 }
    865 
    866 /*!
    867   En/Disable the groove
    868 
    869   The slider can be cutomized by showing a groove for the
    870   handle.
    871 
    872   \param on When true, the groove is visible
    873   \sa hasGroove(), setThrough()
     877    return m_data->hasTrough;
     878}
     879
     880/*!
     881   En/Disable the groove
     882
     883   The slider can be customized by showing a groove for the
     884   handle.
     885
     886   \param on When true, the groove is visible
     887   \sa hasGroove(), setThrough()
    874888 */
    875889void QwtSlider::setGroove( bool on )
    876890{
    877     if ( d_data->hasGroove != on )
    878     {
    879         d_data->hasGroove = on;
     891    if ( m_data->hasGroove != on )
     892    {
     893        m_data->hasGroove = on;
    880894
    881895        if ( testAttribute( Qt::WA_WState_Polished ) )
    … …  
    885899
    886900/*!
    887   \return True, when the groove is visisble
    888   \sa setGroove(), hasTrough()
     901   \return True, when the groove is visible
     902   \sa setGroove(), hasTrough()
    889903 */
    890904bool QwtSlider::hasGroove() const
    891905{
    892     return d_data->hasGroove;
    893 }
    894 
    895 /*!
    896   \return minimumSizeHint()
    897 */
     906    return m_data->hasGroove;
     907}
     908
     909/*!
     910   \return minimumSizeHint()
     911 */
    898912QSize QwtSlider::sizeHint() const
    899913{
    900914    const QSize hint = minimumSizeHint();
    901     return hint.expandedTo( QApplication::globalStrut() );
    902 }
    903 
    904 /*!
    905   \return Minimum size hint
    906   \sa sizeHint()
    907 */
     915    return qwtExpandedToGlobalStrut( hint );
     916}
     917
     918/*!
     919   \return Minimum size hint
     920   \sa sizeHint()
     921 */
    908922QSize QwtSlider::minimumSizeHint() const
    909923{
    910     if ( !d_data->sizeHintCache.isEmpty() )
    911         return d_data->sizeHintCache;
    912 
    913     const QSize handleSize = qwtHandleSize( d_data->handleSize,
    914         d_data->orientation, d_data->hasTrough );
     924    if ( !m_data->sizeHintCache.isEmpty() )
     925        return m_data->sizeHintCache;
     926
     927    const QSize handleSize = qwtHandleSize( m_data->handleSize,
     928        m_data->orientation, m_data->hasTrough );
    915929
    916930    int bw = 0;
    917     if ( d_data->hasTrough )
    918         bw = d_data->borderWidth;
     931    if ( m_data->hasTrough )
     932        bw = m_data->borderWidth;
    919933
    920934    int sliderLength = 0;
    921935    int scaleExtent = 0;
    922936
    923     if ( d_data->scalePosition != QwtSlider::NoScale )
     937    if ( m_data->scalePosition != QwtSlider::NoScale )
    924938    {
    925939        int d1, d2;
    … …  
    929943
    930944        int handleBorderDist;
    931         if ( d_data->orientation == Qt::Horizontal )
     945        if ( m_data->orientation == Qt::Horizontal )
    932946            handleBorderDist = handleSize.width();
    933947        else
    … …  
    941955        }
    942956
    943         scaleExtent += d_data->spacing;
    944         scaleExtent += qCeil( scaleDraw()->extent( font() ) );
     957        scaleExtent += m_data->spacing;
     958        scaleExtent += qwtCeil( scaleDraw()->extent( font() ) );
    945959    }
    946960
    … …  
    950964    int h = 0;
    951965
    952     if ( d_data->orientation == Qt::Horizontal )
     966    if ( m_data->orientation == Qt::Horizontal )
    953967    {
    954968        w = sliderLength;
    … …  
    962976
    963977    // finally add margins
    964     int left, right, top, bottom;
    965     getContentsMargins( &left, &top, &right, &bottom );
    966 
    967     w += left + right;
    968     h += top + bottom;
    969 
    970     d_data->sizeHintCache = QSize( w, h );
    971     return d_data->sizeHintCache;
     978    const QMargins m = contentsMargins();
     979
     980    w += m.left() + m.right();
     981    h += m.top() + m.bottom();
     982
     983    m_data->sizeHintCache = QSize( w, h );
     984    return m_data->sizeHintCache;
    972985}
    973986
    … …  
    982995    const int markerPos = transform( value() );
    983996
    984     QPoint center = d_data->sliderRect.center();
    985     if ( d_data->orientation == Qt::Horizontal )
     997    QPoint center = m_data->sliderRect.center();
     998    if ( m_data->orientation == Qt::Horizontal )
    986999        center.setX( markerPos );
    9871000    else
    … …  
    9891002
    9901003    QRect rect;
    991     rect.setSize( qwtHandleSize( d_data->handleSize,
    992         d_data->orientation, d_data->hasTrough ) );
     1004    rect.setSize( qwtHandleSize( m_data->handleSize,
     1005        m_data->orientation, m_data->hasTrough ) );
    9931006    rect.moveCenter( center );
    9941007
    … …  
    9971010
    9981011/*!
    999  \return Bounding rectangle of the slider - without the scale
     1012   \return Bounding rectangle of the slider - without the scale
    10001013 */
    10011014QRect QwtSlider::sliderRect() const
    10021015{
    1003     return d_data->sliderRect;
    1004 }
     1016    return m_data->sliderRect;
     1017}
     1018
     1019#include "moc_qwt_slider.cpp"
  • trunk/BNC/qwt/qwt_slider.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1717
    1818/*!
    19   \brief The Slider Widget
     19   \brief The Slider Widget
    2020
    21   QwtSlider is a slider widget which operates on an interval
    22   of type double. Its position is related to a scale showing
    23   the current value.
     21   QwtSlider is a slider widget which operates on an interval
     22   of type double. Its position is related to a scale showing
     23   the current value.
    2424
    25   The slider can be customized by having a through, a groove - or both.
     25   The slider can be customized by having a through, a groove - or both.
    2626
    27   \image html sliders.png
    28 */
     27   \image html sliders.png
     28 */
    2929
    30 class QWT_EXPORT QwtSlider: public QwtAbstractSlider
     30class QWT_EXPORT QwtSlider : public QwtAbstractSlider
    3131{
    3232    Q_OBJECT
    … …  
    3535
    3636    Q_PROPERTY( Qt::Orientation orientation
    37                 READ orientation WRITE setOrientation )
     37        READ orientation WRITE setOrientation )
    3838    Q_PROPERTY( ScalePosition scalePosition READ scalePosition
    3939        WRITE setScalePosition )
    … …  
    4646    Q_PROPERTY( int spacing READ spacing WRITE setSpacing )
    4747
    48 public:
     48  public:
    4949
    5050    /*!
    51       Position of the scale
    52       \sa QwtSlider(), setScalePosition(), setOrientation()
     51       Position of the scale
     52       \sa QwtSlider(), setScalePosition(), setOrientation()
    5353     */
    5454    enum ScalePosition
    … …  
    6464    };
    6565
    66     explicit QwtSlider( QWidget *parent = NULL );
    67     explicit QwtSlider( Qt::Orientation, QWidget *parent = NULL );
     66    explicit QwtSlider( QWidget* parent = NULL );
     67    explicit QwtSlider( Qt::Orientation, QWidget* parent = NULL );
    6868
    6969    virtual ~QwtSlider();
    … …  
    8181    bool hasGroove() const;
    8282
    83     void setHandleSize( const QSize & );
     83    void setHandleSize( const QSize& );
    8484    QSize handleSize() const;
    8585
    … …  
    9090    int spacing() const;
    9191
    92     virtual QSize sizeHint() const;
    93     virtual QSize minimumSizeHint() const;
     92    virtual QSize sizeHint() const QWT_OVERRIDE;
     93    virtual QSize minimumSizeHint() const QWT_OVERRIDE;
    9494
    95     void setScaleDraw( QwtScaleDraw * );
    96     const QwtScaleDraw *scaleDraw() const;
     95    void setScaleDraw( QwtScaleDraw* );
     96    const QwtScaleDraw* scaleDraw() const;
    9797
    9898    void setUpdateInterval( int );
    9999    int updateInterval() const;
    100100
    101 protected:
    102     virtual double scrolledTo( const QPoint & ) const;
    103     virtual bool isScrollPosition( const QPoint & ) const;
     101  protected:
     102    virtual double scrolledTo( const QPoint& ) const QWT_OVERRIDE;
     103    virtual bool isScrollPosition( const QPoint& ) const QWT_OVERRIDE;
    104104
    105     virtual void drawSlider ( QPainter *, const QRect & ) const;
    106     virtual void drawHandle( QPainter *, const QRect &, int pos ) const;
     105    virtual void drawSlider ( QPainter*, const QRect& ) const;
     106    virtual void drawHandle( QPainter*, const QRect&, int pos ) const;
    107107
    108     virtual void mousePressEvent( QMouseEvent * );
    109     virtual void mouseReleaseEvent( QMouseEvent * );
    110     virtual void resizeEvent( QResizeEvent * );
    111     virtual void paintEvent ( QPaintEvent * );
    112     virtual void changeEvent( QEvent * );
    113     virtual void timerEvent( QTimerEvent * );
     108    virtual void mousePressEvent( QMouseEvent* ) QWT_OVERRIDE;
     109    virtual void mouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE;
     110    virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE;
     111    virtual void paintEvent ( QPaintEvent* ) QWT_OVERRIDE;
     112    virtual void changeEvent( QEvent* ) QWT_OVERRIDE;
     113    virtual void timerEvent( QTimerEvent* ) QWT_OVERRIDE;
    114114
    115     virtual void scaleChange();
     115    virtual bool event( QEvent* ) QWT_OVERRIDE;
     116
     117    virtual void scaleChange() QWT_OVERRIDE;
    116118
    117119    QRect sliderRect() const;
    118120    QRect handleRect() const;
    119121
    120 private:
    121     QwtScaleDraw *scaleDraw();
     122  private:
     123    QwtScaleDraw* scaleDraw();
    122124
    123125    void layoutSlider( bool );
    … …  
    125127
    126128    class PrivateData;
    127     PrivateData *d_data;
     129    PrivateData* m_data;
    128130};
    129131
  • trunk/BNC/qwt/qwt_spline.cpp

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_spline.h"
    11 #include "qwt_math.h"
     11#include "qwt_spline_parametrization.h"
     12#include "qwt_spline_polynomial.h"
     13#include "qwt_bezier.h"
     14
     15#include <qpainterpath.h>
     16
     17namespace QwtSplineC1P
     18{
     19    struct param
     20    {
     21        param( const QwtSplineParametrization* p ):
     22            parameter( p )
     23        {
     24        }
     25
     26        inline double operator()( const QPointF& p1, const QPointF& p2 ) const
     27        {
     28            return parameter->valueIncrement( p1, p2 );
     29        }
     30
     31        const QwtSplineParametrization* parameter;
     32    };
     33
     34    struct paramY
     35    {
     36        inline double operator()( const QPointF& p1, const QPointF& p2 ) const
     37        {
     38            return QwtSplineParametrization::valueIncrementY( p1, p2 );
     39        }
     40    };
     41
     42    struct paramUniform
     43    {
     44        inline double operator()( const QPointF& p1, const QPointF& p2 ) const
     45        {
     46            return QwtSplineParametrization::valueIncrementUniform( p1, p2 );
     47        }
     48    };
     49
     50    struct paramCentripetal
     51    {
     52        inline double operator()( const QPointF& p1, const QPointF& p2 ) const
     53        {
     54            return QwtSplineParametrization::valueIncrementCentripetal( p1, p2 );
     55        }
     56    };
     57
     58    struct paramChordal
     59    {
     60        inline double operator()( const QPointF& p1, const QPointF& p2 ) const
     61        {
     62            return QwtSplineParametrization::valueIncrementChordal( p1, p2 );
     63        }
     64    };
     65
     66    struct paramManhattan
     67    {
     68        inline double operator()( const QPointF& p1, const QPointF& p2 ) const
     69        {
     70            return QwtSplineParametrization::valueIncrementManhattan( p1, p2 );
     71        }
     72    };
     73
     74    class PathStore
     75    {
     76      public:
     77        inline void init( int size )
     78        {
     79            Q_UNUSED(size);
     80        }
     81
     82        inline void start( double x1, double y1 )
     83        {
     84            path.moveTo( x1, y1 );
     85        }
     86
     87        inline void addCubic( double cx1, double cy1,
     88            double cx2, double cy2, double x2, double y2 )
     89        {
     90            path.cubicTo( cx1, cy1, cx2, cy2, x2, y2 );
     91        }
     92
     93        inline void end()
     94        {
     95            path.closeSubpath();
     96        }
     97
     98        QPainterPath path;
     99    };
     100
     101    class ControlPointsStore
     102    {
     103      public:
     104        inline ControlPointsStore():
     105            m_cp( NULL )
     106        {
     107        }
     108
     109        inline void init( int size )
     110        {
     111            controlPoints.resize( size );
     112            m_cp = controlPoints.data();
     113        }
     114
     115        inline void start( double x1, double y1 )
     116        {
     117            Q_UNUSED( x1 );
     118            Q_UNUSED( y1 );
     119        }
     120
     121        inline void addCubic( double cx1, double cy1,
     122            double cx2, double cy2, double x2, double y2 )
     123        {
     124            Q_UNUSED( x2 );
     125            Q_UNUSED( y2 );
     126
     127            QLineF& l = *m_cp++;
     128            l.setLine( cx1, cy1, cx2, cy2 );
     129        }
     130
     131        inline void end()
     132        {
     133        }
     134
     135        QVector< QLineF > controlPoints;
     136
     137      private:
     138        QLineF* m_cp;
     139    };
     140
     141    double slopeBoundary( int boundaryCondition, double boundaryValue,
     142        const QPointF& p1, const QPointF& p2, double slope1 )
     143    {
     144        const double dx = p2.x() - p1.x();
     145        const double dy = p2.y() - p1.y();
     146
     147        double m = 0.0;
     148
     149        switch( boundaryCondition )
     150        {
     151            case QwtSpline::Clamped1:
     152            {
     153                m = boundaryValue;
     154                break;
     155            }
     156            case QwtSpline::Clamped2:
     157            {
     158                const double c2 = 0.5 * boundaryValue;
     159                const double c1 = slope1;
     160
     161                m = 0.5 * ( 3.0 * dy / dx - c1 - c2 * dx );
     162                break;
     163            }
     164            case QwtSpline::Clamped3:
     165            {
     166                const double c3 = boundaryValue / 6.0;
     167                m = c3 * dx * dx + 2 * dy / dx - slope1;
     168                break;
     169            }
     170            case QwtSpline::LinearRunout:
     171            {
     172                const double s = dy / dx;
     173                const double r = qBound( 0.0, boundaryValue, 1.0 );
     174
     175                m = s - r * ( s - slope1 );
     176                break;
     177            }
     178            default:
     179            {
     180                m = dy / dx; // something
     181            }
     182        }
     183
     184        return m;
     185    }
     186}
     187
     188template< class SplineStore >
     189static inline SplineStore qwtSplineC1PathParamX(
     190    const QwtSplineC1* spline, const QPolygonF& points )
     191{
     192    const int n = points.size();
     193
     194    const QVector< double > m = spline->slopes( points );
     195    if ( m.size() != n )
     196        return SplineStore();
     197
     198    const QPointF* pd = points.constData();
     199    const double* md = m.constData();
     200
     201    SplineStore store;
     202    store.init( m.size() - 1 );
     203    store.start( pd[0].x(), pd[0].y() );
     204
     205    for ( int i = 0; i < n - 1; i++ )
     206    {
     207        const double dx3 = ( pd[i + 1].x() - pd[i].x() ) / 3.0;
     208
     209        store.addCubic( pd[i].x() + dx3, pd[i].y() + md[i] * dx3,
     210            pd[i + 1].x() - dx3, pd[i + 1].y() - md[i + 1] * dx3,
     211            pd[i + 1].x(), pd[i + 1].y() );
     212    }
     213
     214    return store;
     215}
     216
     217template< class SplineStore >
     218static inline SplineStore qwtSplineC1PathParamY(
     219    const QwtSplineC1* spline, const QPolygonF& points )
     220{
     221    const int n = points.size();
     222
     223    QPolygonF pointsFlipped( n );
     224    for ( int i = 0; i < n; i++ )
     225    {
     226        pointsFlipped[i].setX( points[i].y() );
     227        pointsFlipped[i].setY( points[i].x() );
     228    }
     229
     230    const QVector< double > m = spline->slopes( pointsFlipped );
     231    if ( m.size() != n )
     232        return SplineStore();
     233
     234    const QPointF* pd = pointsFlipped.constData();
     235    const double* md = m.constData();
     236
     237    SplineStore store;
     238    store.init( m.size() - 1 );
     239    store.start( pd[0].y(), pd[0].x() );
     240
     241    QVector< QLineF > lines( n );
     242    for ( int i = 0; i < n - 1; i++ )
     243    {
     244        const double dx3 = ( pd[i + 1].x() - pd[i].x() ) / 3.0;
     245
     246        store.addCubic( pd[i].y() + md[i] * dx3, pd[i].x() + dx3,
     247            pd[i + 1].y() - md[i + 1] * dx3, pd[i + 1].x() - dx3,
     248            pd[i + 1].y(), pd[i + 1].x() );
     249    }
     250
     251    return store;
     252}
     253
     254template< class SplineStore, class Param >
     255static inline SplineStore qwtSplineC1PathParametric(
     256    const QwtSplineC1* spline, const QPolygonF& points, Param param )
     257{
     258    const bool isClosing = ( spline->boundaryType() == QwtSpline::ClosedPolygon );
     259    const int n = points.size();
     260
     261    QPolygonF pointsX, pointsY;
     262    pointsX.resize( isClosing ? n + 1 : n );
     263    pointsY.resize( isClosing ? n + 1 : n );
     264
     265    QPointF* px = pointsX.data();
     266    QPointF* py = pointsY.data();
     267    const QPointF* p = points.constData();
     268
     269    double t = 0.0;
     270
     271    px[0].rx() = py[0].rx() = t;
     272    px[0].ry() = p[0].x();
     273    py[0].ry() = p[0].y();
     274
     275    int numParamPoints = 1;
     276    for ( int i = 1; i < n; i++ )
     277    {
     278        const double td = param( points[i - 1], points[i] );
     279        if ( td > 0.0 )
     280        {
     281            t += td;
     282
     283            px[numParamPoints].rx() = py[numParamPoints].rx() = t;
     284
     285            px[numParamPoints].ry() = p[i].x();
     286            py[numParamPoints].ry() = p[i].y();
     287
     288            numParamPoints++;
     289        }
     290    }
     291
     292    if ( isClosing )
     293    {
     294        const double td = param( points[n - 1], points[0] );
     295
     296        if ( td > 0.0 )
     297        {
     298            t += td;
     299
     300            px[numParamPoints].rx() = py[numParamPoints].rx() = t;
     301
     302            px[numParamPoints].ry() = p[0].x();
     303            py[numParamPoints].ry() = p[0].y();
     304
     305            numParamPoints++;
     306        }
     307    }
     308
     309    if ( pointsX.size() != numParamPoints )
     310    {
     311        pointsX.resize( numParamPoints );
     312        pointsY.resize( numParamPoints );
     313    }
     314
     315    const QVector< double > slopesX = spline->slopes( pointsX );
     316    const QVector< double > slopesY = spline->slopes( pointsY );
     317
     318    const double* mx = slopesX.constData();
     319    const double* my = slopesY.constData();
     320
     321    // we don't need it anymore
     322    pointsX.clear();
     323    pointsY.clear();
     324
     325    SplineStore store;
     326    store.init( isClosing ? n : n - 1 );
     327    store.start( points[0].x(), points[0].y() );
     328
     329    int j = 0;
     330
     331    for ( int i = 0; i < n - 1; i++ )
     332    {
     333        const QPointF& p1 = p[i];
     334        const QPointF& p2 = p[i + 1];
     335
     336        const double td = param( p1, p2 );
     337
     338        if ( td != 0.0 )
     339        {
     340            const double t3 = td / 3.0;
     341
     342            const double cx1 = p1.x() + mx[j] * t3;
     343            const double cy1 = p1.y() + my[j] * t3;
     344
     345            const double cx2 = p2.x() - mx[j + 1] * t3;
     346            const double cy2 = p2.y() - my[j + 1] * t3;
     347
     348            store.addCubic( cx1, cy1, cx2, cy2, p2.x(), p2.y() );
     349
     350            j++;
     351        }
     352        else
     353        {
     354            // setting control points to the ends
     355            store.addCubic( p1.x(), p1.y(), p2.x(), p2.y(), p2.x(), p2.y() );
     356        }
     357    }
     358
     359    if ( isClosing )
     360    {
     361        const QPointF& p1 = p[n - 1];
     362        const QPointF& p2 = p[0];
     363
     364        const double td = param( p1, p2 );
     365
     366        if ( td != 0.0 )
     367        {
     368            const double t3 = td / 3.0;
     369
     370            const double cx1 = p1.x() + mx[j] * t3;
     371            const double cy1 = p1.y() + my[j] * t3;
     372
     373            const double cx2 = p2.x() - mx[0] * t3;
     374            const double cy2 = p2.y() - my[0] * t3;
     375
     376            store.addCubic( cx1, cy1, cx2, cy2, p2.x(), p2.y() );
     377        }
     378        else
     379        {
     380            store.addCubic( p1.x(), p1.y(), p2.x(), p2.y(), p2.x(), p2.y() );
     381        }
     382
     383        store.end();
     384    }
     385
     386    return store;
     387}
     388
     389template< QwtSplinePolynomial toPolynomial( const QPointF&, double, const QPointF&, double ) >
     390static QPolygonF qwtPolygonParametric( double distance,
     391    const QPolygonF& points, const QVector< double >& values, bool withNodes )
     392{
     393    QPolygonF fittedPoints;
     394
     395    const QPointF* p = points.constData();
     396    const double* v = values.constData();
     397
     398    fittedPoints += p[0];
     399    double t = distance;
     400
     401    const int n = points.size();
     402
     403    for ( int i = 0; i < n - 1; i++ )
     404    {
     405        const QPointF& p1 = p[i];
     406        const QPointF& p2 = p[i + 1];
     407
     408        const QwtSplinePolynomial polynomial = toPolynomial( p1, v[i], p2, v[i + 1] );
     409
     410        const double l = p2.x() - p1.x();
     411
     412        while ( t < l )
     413        {
     414            fittedPoints += QPointF( p1.x() + t, p1.y() + polynomial.valueAt( t ) );
     415            t += distance;
     416        }
     417
     418        if ( withNodes )
     419        {
     420            if ( qFuzzyCompare( fittedPoints.last().x(), p2.x() ) )
     421                fittedPoints.last() = p2;
     422            else
     423                fittedPoints += p2;
     424        }
     425        else
     426        {
     427            t -= l;
     428        }
     429    }
     430
     431    return fittedPoints;
     432}
    12433
    13434class QwtSpline::PrivateData
    14435{
    15 public:
    16     PrivateData():
    17         splineType( QwtSpline::Natural )
    18     {
    19     }
    20 
    21     QwtSpline::SplineType splineType;
    22 
    23     // coefficient vectors
    24     QVector<double> a;
    25     QVector<double> b;
    26     QVector<double> c;
    27 
    28     // control points
    29     QPolygonF points;
     436  public:
     437    PrivateData()
     438        : boundaryType( QwtSpline::ConditionalBoundaries )
     439    {
     440        parametrization = new QwtSplineParametrization(
     441            QwtSplineParametrization::ParameterChordal );
     442
     443        // parabolic runout at both ends
     444
     445        boundaryConditions[0].type = QwtSpline::Clamped3;
     446        boundaryConditions[0].value = 0.0;
     447
     448        boundaryConditions[1].type = QwtSpline::Clamped3;
     449        boundaryConditions[1].value = 0.0;
     450    }
     451
     452    ~PrivateData()
     453    {
     454        delete parametrization;
     455    }
     456
     457    QwtSplineParametrization* parametrization;
     458    QwtSpline::BoundaryType boundaryType;
     459
     460    struct
     461    {
     462        int type;
     463        double value;
     464
     465    } boundaryConditions[2];
    30466};
    31467
    32 static int lookup( double x, const QPolygonF &values )
    33 {
    34 #if 0
    35 //qLowerBound/qHigherBound ???
    36 #endif
    37     int i1;
    38     const int size = values.size();
    39 
    40     if ( x <= values[0].x() )
    41         i1 = 0;
    42     else if ( x >= values[size - 2].x() )
    43         i1 = size - 2;
    44     else
    45     {
    46         i1 = 0;
    47         int i2 = size - 2;
    48         int i3 = 0;
    49 
    50         while ( i2 - i1 > 1 )
    51         {
    52             i3 = i1 + ( ( i2 - i1 ) >> 1 );
    53 
    54             if ( values[i3].x() > x )
    55                 i2 = i3;
    56             else
    57                 i1 = i3;
    58         }
    59     }
    60     return i1;
    61 }
    62 
    63 //! Constructor
     468/*!
     469   \fn QPainterPath QwtSpline::painterPath( const QPolygonF &points ) const
     470
     471   Approximates a polygon piecewise with cubic Bezier curves
     472   and returns them as QPainterPath.
     473
     474   \param points Control points
     475   \return Painter path, that can be rendered by QPainter
     476
     477   \sa polygon(), QwtBezier
     478 */
     479
     480/*!
     481   \brief Interpolate a curve by a polygon
     482
     483   Interpolates a polygon piecewise with Bezier curves
     484   interpolating them in a 2nd pass by polygons.
     485
     486   The interpolation is based on "Piecewise Linear Approximation of Bézier Curves"
     487   by Roger Willcocks ( http://www.rops.org )
     488
     489   \param points Control points
     490   \param tolerance Maximum for the accepted error of the approximation
     491
     492   \return polygon approximating the interpolating polynomials
     493
     494   \sa bezierControlLines(), QwtBezier
     495 */
     496QPolygonF QwtSpline::polygon( const QPolygonF& points, double tolerance ) const
     497{
     498    if ( tolerance <= 0.0 )
     499        return QPolygonF();
     500
     501    const QPainterPath path = painterPath( points );
     502    const int n = path.elementCount();
     503    if ( n == 0 )
     504        return QPolygonF();
     505
     506    const QPainterPath::Element el = path.elementAt( 0 );
     507    if ( el.type != QPainterPath::MoveToElement )
     508        return QPolygonF();
     509
     510    QPointF p1( el.x, el.y );
     511
     512    QPolygonF polygon;
     513    QwtBezier bezier( tolerance );
     514
     515    for ( int i = 1; i < n; i += 3 )
     516    {
     517        const QPainterPath::Element el1 = path.elementAt( i );
     518        const QPainterPath::Element el2 = path.elementAt( i + 1 );
     519        const QPainterPath::Element el3 = path.elementAt( i + 2 );
     520
     521        const QPointF cp1( el1.x, el1.y );
     522        const QPointF cp2( el2.x, el2.y );
     523        const QPointF p2( el3.x, el3.y );
     524
     525        bezier.appendToPolygon( p1, cp1, cp2, p2, polygon );
     526
     527        p1 = p2;
     528    }
     529
     530    return polygon;
     531}
     532
     533/*!
     534   \brief Constructor
     535
     536   The default setting is a non closing spline with chordal parametrization
     537
     538   \sa setParametrization(), setBoundaryType()
     539 */
    64540QwtSpline::QwtSpline()
    65541{
    66     d_data = new PrivateData;
    67 }
    68 
    69 /*!
    70    Copy constructor
    71    \param other Spline used for initialization
    72 */
    73 QwtSpline::QwtSpline( const QwtSpline& other )
    74 {
    75     d_data = new PrivateData( *other.d_data );
    76 }
    77 
    78 /*!
    79    Assignment operator
    80    \param other Spline used for initialization
    81    \return *this
    82 */
    83 QwtSpline &QwtSpline::operator=( const QwtSpline & other )
    84 {
    85     *d_data = *other.d_data;
    86     return *this;
     542    m_data = new PrivateData;
    87543}
    88544
    … …  
    90546QwtSpline::~QwtSpline()
    91547{
    92     delete d_data;
    93 }
    94 
    95 /*!
    96    Select the algorithm used for calculating the spline
    97 
    98    \param splineType Spline type
    99    \sa splineType()
    100 */
    101 void QwtSpline::setSplineType( SplineType splineType )
    102 {
    103     d_data->splineType = splineType;
    104 }
    105 
    106 /*!
    107    \return the spline type
    108    \sa setSplineType()
    109 */
    110 QwtSpline::SplineType QwtSpline::splineType() const
    111 {
    112     return d_data->splineType;
    113 }
    114 
    115 /*!
    116   \brief Calculate the spline coefficients
    117 
    118   Depending on the value of \a periodic, this function
    119   will determine the coefficients for a natural or a periodic
    120   spline and store them internally.
    121 
    122   \param points Points
    123   \return true if successful
    124   \warning The sequence of x (but not y) values has to be strictly monotone
    125            increasing, which means <code>points[i].x() < points[i+1].x()</code>.
    126        If this is not the case, the function will return false
    127 */
    128 bool QwtSpline::setPoints( const QPolygonF& points )
    129 {
    130     const int size = points.size();
    131     if ( size <= 2 )
    132     {
    133         reset();
    134         return false;
    135     }
    136 
    137     d_data->points = points;
    138 
    139     d_data->a.resize( size - 1 );
    140     d_data->b.resize( size - 1 );
    141     d_data->c.resize( size - 1 );
    142 
    143     bool ok;
    144     if ( d_data->splineType == Periodic )
    145         ok = buildPeriodicSpline( points );
    146     else
    147         ok = buildNaturalSpline( points );
    148 
    149     if ( !ok )
    150         reset();
    151 
    152     return ok;
    153 }
    154 
    155 /*!
    156    \return Points, that have been by setPoints()
    157 */
    158 QPolygonF QwtSpline::points() const
    159 {
    160     return d_data->points;
    161 }
    162 
    163 //! \return A coefficients
    164 const QVector<double> &QwtSpline::coefficientsA() const
    165 {
    166     return d_data->a;
    167 }
    168 
    169 //! \return B coefficients
    170 const QVector<double> &QwtSpline::coefficientsB() const
    171 {
    172     return d_data->b;
    173 }
    174 
    175 //! \return C coefficients
    176 const QVector<double> &QwtSpline::coefficientsC() const
    177 {
    178     return d_data->c;
    179 }
    180 
    181 
    182 //! Free allocated memory and set size to 0
    183 void QwtSpline::reset()
    184 {
    185     d_data->a.resize( 0 );
    186     d_data->b.resize( 0 );
    187     d_data->c.resize( 0 );
    188     d_data->points.resize( 0 );
    189 }
    190 
    191 //! True if valid
    192 bool QwtSpline::isValid() const
    193 {
    194     return d_data->a.size() > 0;
    195 }
    196 
    197 /*!
    198   Calculate the interpolated function value corresponding
    199   to a given argument x.
    200 
    201   \param x Coordinate
    202   \return Interpolated coordinate
    203 */
    204 double QwtSpline::value( double x ) const
    205 {
    206     if ( d_data->a.size() == 0 )
     548    delete m_data;
     549}
     550
     551/*!
     552   The locality of an spline interpolation identifies how many adjacent
     553   polynomials are affected, when changing the position of one point.
     554
     555   A locality of 'n' means, that changing the coordinates of a point
     556   has an effect on 'n' leading and 'n' following polynomials.
     557   Those polynomials can be calculated from a local subpolygon.
     558
     559   A value of 0 means, that the interpolation is not local and any modification
     560   of the polygon requires to recalculate all polynomials ( f.e cubic splines ).
     561
     562   \return Order of locality
     563 */
     564uint QwtSpline::locality() const
     565{
     566    return 0;
     567}
     568
     569/*!
     570   Define the parametrization for a parametric spline approximation
     571   The default setting is a chordal parametrization.
     572
     573   \param type Type of parametrization, usually one of QwtSplineParametrization::Type
     574   \sa parametrization()
     575 */
     576void QwtSpline::setParametrization( int type )
     577{
     578    if ( m_data->parametrization->type() != type )
     579    {
     580        delete m_data->parametrization;
     581        m_data->parametrization = new QwtSplineParametrization( type );
     582    }
     583}
     584
     585/*!
     586   Define the parametrization for a parametric spline approximation
     587   The default setting is a chordal parametrization.
     588
     589   \param parametrization Parametrization
     590   \sa parametrization()
     591 */
     592void QwtSpline::setParametrization( QwtSplineParametrization* parametrization )
     593{
     594    if ( ( parametrization != NULL ) && ( m_data->parametrization != parametrization ) )
     595    {
     596        delete m_data->parametrization;
     597        m_data->parametrization = parametrization;
     598    }
     599}
     600
     601/*!
     602   \return parametrization
     603   \sa setParametrization()
     604 */
     605const QwtSplineParametrization* QwtSpline::parametrization() const
     606{
     607    return m_data->parametrization;
     608}
     609
     610/*!
     611   Define the boundary type for the endpoints of the approximating
     612   spline.
     613
     614   \param boundaryType Boundary type
     615   \sa boundaryType()
     616 */
     617void QwtSpline::setBoundaryType( BoundaryType boundaryType )
     618{
     619    m_data->boundaryType = boundaryType;
     620}
     621
     622/*!
     623   \return Boundary type
     624   \sa setBoundaryType()
     625 */
     626QwtSpline::BoundaryType QwtSpline::boundaryType() const
     627{
     628    return m_data->boundaryType;
     629}
     630
     631/*!
     632   \brief Define the condition for an endpoint of the spline
     633
     634   \param position At the beginning or the end of the spline
     635   \param condition Condition
     636
     637   \sa BoundaryCondition, QwtSplineC2::BoundaryCondition, boundaryCondition()
     638 */
     639void QwtSpline::setBoundaryCondition( BoundaryPosition position, int condition )
     640{
     641    if ( ( position == QwtSpline::AtBeginning ) || ( position == QwtSpline::AtEnd ) )
     642        m_data->boundaryConditions[position].type = condition;
     643}
     644
     645/*!
     646   \return Condition for an endpoint of the spline
     647   \param position At the beginning or the end of the spline
     648
     649   \sa setBoundaryCondition(), boundaryValue(), setBoundaryConditions()
     650 */
     651int QwtSpline::boundaryCondition( BoundaryPosition position ) const
     652{
     653    if ( ( position == QwtSpline::AtBeginning ) || ( position == QwtSpline::AtEnd ) )
     654        return m_data->boundaryConditions[position].type;
     655
     656    return m_data->boundaryConditions[0].type; // should never happen
     657}
     658
     659/*!
     660   \brief Define the boundary value
     661
     662   The boundary value is an parameter used in combination with
     663   the boundary condition. Its meaning depends on the condition.
     664
     665   \param position At the beginning or the end of the spline
     666   \param value Value used for the condition at the end point
     667
     668   \sa boundaryValue(), setBoundaryCondition()
     669 */
     670void QwtSpline::setBoundaryValue( BoundaryPosition position, double value )
     671{
     672    if ( ( position == QwtSpline::AtBeginning ) || ( position == QwtSpline::AtEnd ) )
     673        m_data->boundaryConditions[position].value = value;
     674}
     675
     676/*!
     677   \return Boundary value
     678   \param position At the beginning or the end of the spline
     679
     680   \sa setBoundaryValue(), boundaryCondition()
     681 */
     682double QwtSpline::boundaryValue( BoundaryPosition position ) const
     683{
     684    if ( ( position == QwtSpline::AtBeginning ) || ( position == QwtSpline::AtEnd ) )
     685        return m_data->boundaryConditions[position].value;
     686
     687    return m_data->boundaryConditions[0].value; // should never happen
     688}
     689
     690/*!
     691   \brief Define the condition at the endpoints of a spline
     692
     693   \param condition Condition
     694   \param valueBegin Used for the condition at the beginning of te spline
     695   \param valueEnd Used for the condition at the end of te spline
     696
     697   \sa BoundaryCondition, QwtSplineC2::BoundaryCondition,
     698      testBoundaryCondition(), setBoundaryValue()
     699 */
     700void QwtSpline::setBoundaryConditions(
     701    int condition, double valueBegin, double valueEnd )
     702{
     703    setBoundaryCondition( QwtSpline::AtBeginning, condition );
     704    setBoundaryValue( QwtSpline::AtBeginning, valueBegin );
     705
     706    setBoundaryCondition( QwtSpline::AtEnd, condition );
     707    setBoundaryValue( QwtSpline::AtEnd, valueEnd );
     708}
     709
     710//! \brief Constructor
     711QwtSplineInterpolating::QwtSplineInterpolating()
     712{
     713}
     714
     715//! Destructor
     716QwtSplineInterpolating::~QwtSplineInterpolating()
     717{
     718}
     719
     720/*! \fn QVector<QLineF> QwtSplineInterpolating::bezierControlLines( const QPolygonF &points ) const
     721
     722   \brief Interpolate a curve with Bezier curves
     723
     724   Interpolates a polygon piecewise with cubic Bezier curves
     725   and returns the 2 control points of each curve as QLineF.
     726
     727   \param points Control points
     728   \return Control points of the interpolating Bezier curves
     729 */
     730
     731/*!
     732   \brief Interpolate a curve with Bezier curves
     733
     734   Interpolates a polygon piecewise with cubic Bezier curves
     735   and returns them as QPainterPath.
     736
     737   The implementation calculates the Bezier control lines first
     738   and converts them into painter path elements in an additional loop.
     739
     740   \param points Control points
     741   \return Painter path, that can be rendered by QPainter
     742
     743   \note Derived spline classes might overload painterPath() to avoid
     744        the extra loops for converting results into a QPainterPath
     745
     746   \sa bezierControlLines()
     747 */
     748QPainterPath QwtSplineInterpolating::painterPath( const QPolygonF& points ) const
     749{
     750    const int n = points.size();
     751
     752    QPainterPath path;
     753    if ( n == 0 )
     754        return path;
     755
     756    if ( n == 1 )
     757    {
     758        path.moveTo( points[0] );
     759        return path;
     760    }
     761
     762    if ( n == 2 )
     763    {
     764        path.addPolygon( points );
     765        return path;
     766    }
     767
     768    const QVector< QLineF > controlLines = bezierControlLines( points );
     769    if ( controlLines.size() < n - 1 )
     770        return path;
     771
     772    const QPointF* p = points.constData();
     773    const QLineF* l = controlLines.constData();
     774
     775    path.moveTo( p[0] );
     776    for ( int i = 0; i < n - 1; i++ )
     777        path.cubicTo( l[i].p1(), l[i].p2(), p[i + 1] );
     778
     779    if ( ( boundaryType() == QwtSpline::ClosedPolygon )
     780        && ( controlLines.size() >= n ) )
     781    {
     782        path.cubicTo( l[n - 1].p1(), l[n - 1].p2(), p[0] );
     783        path.closeSubpath();
     784    }
     785
     786    return path;
     787}
     788
     789/*!
     790   \brief Interpolate a curve by a polygon
     791
     792   Interpolates a polygon piecewise with Bezier curves
     793   approximating them by polygons.
     794
     795   The approximation is based on "Piecewise Linear Approximation of Bézier Curves"
     796   by Roger Willcocks ( http://www.rops.org )
     797
     798   \param points Control points
     799   \param tolerance Maximum for the accepted error of the approximation
     800
     801   \return polygon approximating the interpolating polynomials
     802
     803   \sa bezierControlLines(), QwtSplineBezier::toPolygon()
     804 */
     805QPolygonF QwtSplineInterpolating::polygon(
     806    const QPolygonF& points, double tolerance ) const
     807{
     808    if ( tolerance <= 0.0 )
     809        return QPolygonF();
     810
     811    const QVector< QLineF > controlLines = bezierControlLines( points );
     812    if ( controlLines.isEmpty() )
     813        return QPolygonF();
     814
     815    const bool isClosed = boundaryType() == QwtSpline::ClosedPolygon;
     816
     817    QwtBezier bezier( tolerance );
     818
     819    const QPointF* p = points.constData();
     820    const QLineF* cl = controlLines.constData();
     821
     822    const int n = controlLines.size();
     823
     824    QPolygonF polygon;
     825
     826    for ( int i = 0; i < n - 1; i++ )
     827    {
     828        const QLineF& l = cl[i];
     829        bezier.appendToPolygon( p[i], l.p1(), l.p2(), p[i + 1], polygon );
     830    }
     831
     832    const QPointF& pn = isClosed ? p[0] : p[n];
     833    const QLineF& l = cl[n - 1];
     834
     835    bezier.appendToPolygon( p[n - 1], l.p1(), l.p2(), pn, polygon );
     836
     837    return polygon;
     838}
     839
     840/*!
     841   \brief Find an interpolated polygon with "equidistant" points
     842
     843   When withNodes is disabled all points of the resulting polygon
     844   will be equidistant according to the parametrization.
     845
     846   When withNodes is enabled the resulting polygon will also include
     847   the control points and the interpolated points are always aligned to
     848   the control point before ( points[i] + i * distance ).
     849
     850   The implementation calculates bezier curves first and calculates
     851   the interpolated points in a second run.
     852
     853   \param points Control nodes of the spline
     854   \param distance Distance between 2 points according
     855                  to the parametrization
     856   \param withNodes When true, also add the control
     857                   nodes ( even if not being equidistant )
     858
     859   \return Interpolating polygon
     860
     861   \sa bezierControlLines()
     862 */
     863QPolygonF QwtSplineInterpolating::equidistantPolygon( const QPolygonF& points,
     864    double distance, bool withNodes ) const
     865{
     866    if ( distance <= 0.0 )
     867        return QPolygonF();
     868
     869    const int n = points.size();
     870    if ( n <= 1 )
     871        return points;
     872
     873    if ( n == 2 )
     874    {
     875        // TODO
     876        return points;
     877    }
     878
     879    QPolygonF path;
     880
     881    const QVector< QLineF > controlLines = bezierControlLines( points );
     882
     883    if ( controlLines.size() < n - 1 )
     884        return path;
     885
     886    path += points.first();
     887    double t = distance;
     888
     889    const QPointF* p = points.constData();
     890    const QLineF* cl = controlLines.constData();
     891
     892    const QwtSplineParametrization* param = parametrization();
     893
     894    for ( int i = 0; i < n - 1; i++ )
     895    {
     896        const double l = param->valueIncrement( p[i], p[i + 1] );
     897
     898        while ( t < l )
     899        {
     900            path += QwtBezier::pointAt( p[i], cl[i].p1(),
     901                cl[i].p2(), p[i + 1], t / l );
     902
     903            t += distance;
     904        }
     905
     906        if ( withNodes )
     907        {
     908            if ( qFuzzyCompare( path.last().x(), p[i + 1].x() ) )
     909                path.last() = p[i + 1];
     910            else
     911                path += p[i + 1];
     912
     913            t = distance;
     914        }
     915        else
     916        {
     917            t -= l;
     918        }
     919    }
     920
     921    if ( ( boundaryType() == QwtSpline::ClosedPolygon )
     922        && ( controlLines.size() >= n ) )
     923    {
     924        const double l = param->valueIncrement( p[n - 1], p[0] );
     925
     926        while ( t < l )
     927        {
     928            path += QwtBezier::pointAt( p[n - 1], cl[n - 1].p1(),
     929                cl[n - 1].p2(), p[0], t / l );
     930
     931            t += distance;
     932        }
     933
     934        if ( qFuzzyCompare( path.last().x(), p[0].x() ) )
     935            path.last() = p[0];
     936        else
     937            path += p[0];
     938    }
     939
     940    return path;
     941}
     942
     943//! Constructor
     944QwtSplineG1::QwtSplineG1()
     945{
     946}
     947
     948//! Destructor
     949QwtSplineG1::~QwtSplineG1()
     950{
     951}
     952
     953/*!
     954   \brief Constructor
     955
     956   The default setting is a non closing spline with no parametrization
     957   ( QwtSplineParametrization::ParameterX ).
     958
     959   \sa QwtSpline::setParametrization(),
     960      QwtSpline::setBoundaryType()
     961 */
     962QwtSplineC1::QwtSplineC1()
     963{
     964    setParametrization( QwtSplineParametrization::ParameterX );
     965}
     966
     967//! Destructor
     968QwtSplineC1::~QwtSplineC1()
     969{
     970}
     971
     972/*!
     973   \param points Control points
     974   \param slopeNext Value of the first derivative at the second point
     975
     976   \return value of the first derivative at the first point
     977   \sa slopeAtEnd(), QwtSpline::boundaryCondition(), QwtSpline::boundaryValue()
     978 */
     979double QwtSplineC1::slopeAtBeginning( const QPolygonF& points, double slopeNext ) const
     980{
     981    if ( points.size() < 2 )
    207982        return 0.0;
    208983
    209     const int i = lookup( x, d_data->points );
    210 
    211     const double delta = x - d_data->points[i].x();
    212     return( ( ( ( d_data->a[i] * delta ) + d_data->b[i] )
    213         * delta + d_data->c[i] ) * delta + d_data->points[i].y() );
    214 }
    215 
    216 /*!
    217   \brief Determines the coefficients for a natural spline
    218   \return true if successful
    219 */
    220 bool QwtSpline::buildNaturalSpline( const QPolygonF &points )
    221 {
    222     int i;
    223 
    224     const QPointF *p = points.data();
    225     const int size = points.size();
    226 
    227     double *a = d_data->a.data();
    228     double *b = d_data->b.data();
    229     double *c = d_data->c.data();
    230 
    231     //  set up tridiagonal equation system; use coefficient
    232     //  vectors as temporary buffers
    233     QVector<double> h( size - 1 );
    234     for ( i = 0; i < size - 1; i++ )
    235     {
    236         h[i] = p[i+1].x() - p[i].x();
    237         if ( h[i] <= 0 )
    238             return false;
    239     }
    240 
    241     QVector<double> d( size - 1 );
    242     double dy1 = ( p[1].y() - p[0].y() ) / h[0];
    243     for ( i = 1; i < size - 1; i++ )
    244     {
    245         b[i] = c[i] = h[i];
    246         a[i] = 2.0 * ( h[i-1] + h[i] );
    247 
    248         const double dy2 = ( p[i+1].y() - p[i].y() ) / h[i];
    249         d[i] = 6.0 * ( dy1 - dy2 );
    250         dy1 = dy2;
    251     }
    252 
    253     //
    254     // solve it
    255     //
    256 
    257     // L-U Factorization
    258     for ( i = 1; i < size - 2; i++ )
    259     {
    260         c[i] /= a[i];
    261         a[i+1] -= b[i] * c[i];
    262     }
    263 
    264     // forward elimination
    265     QVector<double> s( size );
    266     s[1] = d[1];
    267     for ( i = 2; i < size - 1; i++ )
    268         s[i] = d[i] - c[i-1] * s[i-1];
    269 
    270     // backward elimination
    271     s[size - 2] = - s[size - 2] / a[size - 2];
    272     for ( i = size - 3; i > 0; i-- )
    273         s[i] = - ( s[i] + b[i] * s[i+1] ) / a[i];
    274     s[size - 1] = s[0] = 0.0;
    275 
    276     //
    277     // Finally, determine the spline coefficients
    278     //
    279     for ( i = 0; i < size - 1; i++ )
    280     {
    281         a[i] = ( s[i+1] - s[i] ) / ( 6.0 * h[i] );
    282         b[i] = 0.5 * s[i];
    283         c[i] = ( p[i+1].y() - p[i].y() ) / h[i]
    284             - ( s[i+1] + 2.0 * s[i] ) * h[i] / 6.0;
    285     }
    286 
    287     return true;
    288 }
    289 
    290 /*!
    291   \brief Determines the coefficients for a periodic spline
    292   \return true if successful
    293 */
    294 bool QwtSpline::buildPeriodicSpline( const QPolygonF &points )
    295 {
    296     int i;
    297 
    298     const QPointF *p = points.data();
    299     const int size = points.size();
    300 
    301     double *a = d_data->a.data();
    302     double *b = d_data->b.data();
    303     double *c = d_data->c.data();
    304 
    305     QVector<double> d( size - 1 );
    306     QVector<double> h( size - 1 );
    307     QVector<double> s( size );
    308 
    309     //
    310     //  setup equation system; use coefficient
    311     //  vectors as temporary buffers
    312     //
    313     for ( i = 0; i < size - 1; i++ )
    314     {
    315         h[i] = p[i+1].x() - p[i].x();
    316         if ( h[i] <= 0.0 )
    317             return false;
    318     }
    319 
    320     const int imax = size - 2;
    321     double htmp = h[imax];
    322     double dy1 = ( p[0].y() - p[imax].y() ) / htmp;
    323     for ( i = 0; i <= imax; i++ )
    324     {
    325         b[i] = c[i] = h[i];
    326         a[i] = 2.0 * ( htmp + h[i] );
    327         const double dy2 = ( p[i+1].y() - p[i].y() ) / h[i];
    328         d[i] = 6.0 * ( dy1 - dy2 );
    329         dy1 = dy2;
    330         htmp = h[i];
    331     }
    332 
    333     //
    334     // solve it
    335     //
    336 
    337     // L-U Factorization
    338     a[0] = qSqrt( a[0] );
    339     c[0] = h[imax] / a[0];
    340     double sum = 0;
    341 
    342     for ( i = 0; i < imax - 1; i++ )
    343     {
    344         b[i] /= a[i];
    345         if ( i > 0 )
    346             c[i] = - c[i-1] * b[i-1] / a[i];
    347         a[i+1] = qSqrt( a[i+1] - qwtSqr( b[i] ) );
    348         sum += qwtSqr( c[i] );
    349     }
    350     b[imax-1] = ( b[imax-1] - c[imax-2] * b[imax-2] ) / a[imax-1];
    351     a[imax] = qSqrt( a[imax] - qwtSqr( b[imax-1] ) - sum );
    352 
    353 
    354     // forward elimination
    355     s[0] = d[0] / a[0];
    356     sum = 0;
    357     for ( i = 1; i < imax; i++ )
    358     {
    359         s[i] = ( d[i] - b[i-1] * s[i-1] ) / a[i];
    360         sum += c[i-1] * s[i-1];
    361     }
    362     s[imax] = ( d[imax] - b[imax-1] * s[imax-1] - sum ) / a[imax];
    363 
    364 
    365     // backward elimination
    366     s[imax] = - s[imax] / a[imax];
    367     s[imax-1] = -( s[imax-1] + b[imax-1] * s[imax] ) / a[imax-1];
    368     for ( i = imax - 2; i >= 0; i-- )
    369         s[i] = - ( s[i] + b[i] * s[i+1] + c[i] * s[imax] ) / a[i];
    370 
    371     //
    372     // Finally, determine the spline coefficients
    373     //
    374     s[size-1] = s[0];
    375     for ( i = 0; i < size - 1; i++ )
    376     {
    377         a[i] = ( s[i+1] - s[i] ) / ( 6.0 * h[i] );
    378         b[i] = 0.5 * s[i];
    379         c[i] = ( p[i+1].y() - p[i].y() )
    380             / h[i] - ( s[i+1] + 2.0 * s[i] ) * h[i] / 6.0;
    381     }
    382 
    383     return true;
    384 }
     984    return QwtSplineC1P::slopeBoundary(
     985        boundaryCondition( QwtSpline::AtBeginning ),
     986        boundaryValue( QwtSpline::AtBeginning ),
     987        points[0], points[1], slopeNext );
     988}
     989
     990/*!
     991   \param points Control points
     992   \param slopeBefore Value of the first derivative at the point before the last one
     993
     994   \return value of the first derivative at the last point
     995   \sa slopeAtBeginning(), QwtSpline::boundaryCondition(), QwtSpline::boundaryValue()
     996 */
     997double QwtSplineC1::slopeAtEnd( const QPolygonF& points, double slopeBefore ) const
     998{
     999    const int n = points.size();
     1000
     1001    const QPointF p1( points[n - 1].x(), -points[n - 1].y() );
     1002    const QPointF p2( points[n - 2].x(), -points[n - 2].y() );
     1003
     1004    const int condition = boundaryCondition( QwtSpline::AtEnd );
     1005
     1006    double value = boundaryValue( QwtSpline::AtEnd );
     1007    if ( condition != QwtSpline::LinearRunout )
     1008    {
     1009        // beside LinearRunout the boundaryValue is a slope or curvature
     1010        // and needs to be inverted too
     1011        value = -value;
     1012    }
     1013
     1014    const double slope = QwtSplineC1P::slopeBoundary( condition, value, p1, p2, -slopeBefore );
     1015    return -slope;
     1016}
     1017
     1018/*! \fn QVector<double> QwtSplineC1::slopes( const QPolygonF &points ) const
     1019
     1020   \brief Find the first derivative at the control points
     1021
     1022   \param points Control nodes of the spline
     1023   \return Vector with the values of the 2nd derivate at the control points
     1024
     1025   \note The x coordinates need to be increasing or decreasing
     1026 */
     1027
     1028/*!
     1029   \brief Calculate an interpolated painter path
     1030
     1031   Interpolates a polygon piecewise into cubic Bezier curves
     1032   and returns them as QPainterPath.
     1033
     1034   The implementation calculates the slopes at the control points
     1035   and converts them into painter path elements in an additional loop.
     1036
     1037   \param points Control points
     1038   \return QPainterPath Painter path, that can be rendered by QPainter
     1039
     1040   \note Derived spline classes might overload painterPath() to avoid
     1041        the extra loops for converting results into a QPainterPath
     1042 */
     1043QPainterPath QwtSplineC1::painterPath( const QPolygonF& points ) const
     1044{
     1045    const int n = points.size();
     1046    if ( n <= 2 )
     1047        return QwtSplineInterpolating::painterPath( points );
     1048
     1049    using namespace QwtSplineC1P;
     1050
     1051    PathStore store;
     1052    switch( parametrization()->type() )
     1053    {
     1054        case QwtSplineParametrization::ParameterX:
     1055        {
     1056            store = qwtSplineC1PathParamX< PathStore >( this, points );
     1057            break;
     1058        }
     1059        case QwtSplineParametrization::ParameterY:
     1060        {
     1061            store = qwtSplineC1PathParamY< PathStore >( this, points );
     1062            break;
     1063        }
     1064        case QwtSplineParametrization::ParameterUniform:
     1065        {
     1066            store = qwtSplineC1PathParametric< PathStore >(
     1067                this, points, paramUniform() );
     1068            break;
     1069        }
     1070        case QwtSplineParametrization::ParameterCentripetal:
     1071        {
     1072            store = qwtSplineC1PathParametric< PathStore >(
     1073                this, points, paramCentripetal() );
     1074            break;
     1075        }
     1076        case QwtSplineParametrization::ParameterChordal:
     1077        {
     1078            store = qwtSplineC1PathParametric< PathStore >(
     1079                this, points, paramChordal() );
     1080            break;
     1081        }
     1082        default:
     1083        {
     1084            store = qwtSplineC1PathParametric< PathStore >(
     1085                this, points, param( parametrization() ) );
     1086        }
     1087    }
     1088
     1089    return store.path;
     1090}
     1091
     1092/*!
     1093   \brief Interpolate a curve with Bezier curves
     1094
     1095   Interpolates a polygon piecewise with cubic Bezier curves
     1096   and returns the 2 control points of each curve as QLineF.
     1097
     1098   \param points Control points
     1099   \return Control points of the interpolating Bezier curves
     1100 */
     1101QVector< QLineF > QwtSplineC1::bezierControlLines( const QPolygonF& points ) const
     1102{
     1103    using namespace QwtSplineC1P;
     1104
     1105    const int n = points.size();
     1106    if ( n <= 2 )
     1107        return QVector< QLineF >();
     1108
     1109    ControlPointsStore store;
     1110    switch( parametrization()->type() )
     1111    {
     1112        case QwtSplineParametrization::ParameterX:
     1113        {
     1114            store = qwtSplineC1PathParamX< ControlPointsStore >( this, points );
     1115            break;
     1116        }
     1117        case QwtSplineParametrization::ParameterY:
     1118        {
     1119            store = qwtSplineC1PathParamY< ControlPointsStore >( this, points );
     1120            break;
     1121        }
     1122        case QwtSplineParametrization::ParameterUniform:
     1123        {
     1124            store = qwtSplineC1PathParametric< ControlPointsStore >(
     1125                this, points, paramUniform() );
     1126            break;
     1127        }
     1128        case QwtSplineParametrization::ParameterCentripetal:
     1129        {
     1130            store = qwtSplineC1PathParametric< ControlPointsStore >(
     1131                this, points, paramCentripetal() );
     1132            break;
     1133        }
     1134        case QwtSplineParametrization::ParameterChordal:
     1135        {
     1136            store = qwtSplineC1PathParametric< ControlPointsStore >(
     1137                this, points, paramChordal() );
     1138            break;
     1139        }
     1140        default:
     1141        {
     1142            store = qwtSplineC1PathParametric< ControlPointsStore >(
     1143                this, points, param( parametrization() ) );
     1144        }
     1145    }
     1146
     1147    return store.controlPoints;
     1148}
     1149
     1150/*!
     1151   \brief Find an interpolated polygon with "equidistant" points
     1152
     1153   The implementation is optimzed for non parametric curves
     1154   ( QwtSplineParametrization::ParameterX ) and falls back to
     1155   QwtSpline::equidistantPolygon() otherwise.
     1156
     1157   \param points Control nodes of the spline
     1158   \param distance Distance between 2 points according
     1159                  to the parametrization
     1160   \param withNodes When true, also add the control
     1161                   nodes ( even if not being equidistant )
     1162
     1163   \return Interpolating polygon
     1164
     1165   \sa QwtSpline::equidistantPolygon()
     1166 */
     1167QPolygonF QwtSplineC1::equidistantPolygon( const QPolygonF& points,
     1168    double distance, bool withNodes ) const
     1169{
     1170    if ( parametrization()->type() == QwtSplineParametrization::ParameterX )
     1171    {
     1172        if ( points.size() > 2 )
     1173        {
     1174            const QVector< double > m = slopes( points );
     1175            if ( m.size() != points.size() )
     1176                return QPolygonF();
     1177
     1178            return qwtPolygonParametric< QwtSplinePolynomial::fromSlopes >(
     1179                distance, points, m, withNodes );
     1180        }
     1181    }
     1182
     1183    return QwtSplineInterpolating::equidistantPolygon( points, distance, withNodes );
     1184}
     1185
     1186/*!
     1187   \brief Calculate the interpolating polynomials for a non parametric spline
     1188
     1189   C1 spline interpolations are based on finding values for the first
     1190   derivates at the control points. The interpolating polynomials can
     1191   be calculated from the the first derivates using QwtSplinePolynomial::fromSlopes().
     1192
     1193   The default implementation is a two pass calculation. In derived classes it
     1194   might be overloaded by a one pass implementation.
     1195
     1196   \param points Control points
     1197   \return Interpolating polynomials
     1198
     1199   \note The x coordinates need to be increasing or decreasing
     1200 */
     1201QVector< QwtSplinePolynomial > QwtSplineC1::polynomials(
     1202    const QPolygonF& points ) const
     1203{
     1204    QVector< QwtSplinePolynomial > polynomials;
     1205
     1206    const QVector< double > m = slopes( points );
     1207    if ( m.size() < 2 )
     1208        return polynomials;
     1209
     1210    polynomials.reserve( m.size() - 1 );
     1211    for ( int i = 1; i < m.size(); i++ )
     1212    {
     1213        polynomials += QwtSplinePolynomial::fromSlopes(
     1214            points[i - 1], m[i - 1], points[i], m[i] );
     1215    }
     1216
     1217    return polynomials;
     1218}
     1219
     1220/*!
     1221   \brief Constructor
     1222
     1223   The default setting is a non closing spline with no parametrization
     1224   ( QwtSplineParametrization::ParameterX ).
     1225
     1226   \sa QwtSpline::setParametrization(), QwtSpline::setBoundaryType()
     1227 */
     1228QwtSplineC2::QwtSplineC2()
     1229{
     1230}
     1231
     1232//! Destructor
     1233QwtSplineC2::~QwtSplineC2()
     1234{
     1235}
     1236
     1237/*!
     1238   \brief Interpolate a curve with Bezier curves
     1239
     1240   Interpolates a polygon piecewise with cubic Bezier curves
     1241   and returns them as QPainterPath.
     1242
     1243   \param points Control points
     1244   \return Painter path, that can be rendered by QPainter
     1245
     1246   \note The implementation simply calls QwtSplineC1::painterPath(), but is
     1247        intended to be replaced by a one pass calculation some day.
     1248 */
     1249QPainterPath QwtSplineC2::painterPath( const QPolygonF& points ) const
     1250{
     1251    // could be implemented from curvatures without the extra
     1252    // loop for calculating the slopes vector. TODO ...
     1253
     1254    return QwtSplineC1::painterPath( points );
     1255}
     1256
     1257/*!
     1258   \brief Interpolate a curve with Bezier curves
     1259
     1260   Interpolates a polygon piecewise with cubic Bezier curves
     1261   and returns the 2 control points of each curve as QLineF.
     1262
     1263   \param points Control points
     1264   \return Control points of the interpolating Bezier curves
     1265
     1266   \note The implementation simply calls QwtSplineC1::bezierControlLines(),
     1267        but is intended to be replaced by a more efficient implementation
     1268        that builds the polynomials by the curvatures some day.
     1269 */
     1270QVector< QLineF > QwtSplineC2::bezierControlLines( const QPolygonF& points ) const
     1271{
     1272    // could be implemented from curvatures without the extra
     1273    // loop for calculating the slopes vector. TODO ...
     1274
     1275    return QwtSplineC1::bezierControlLines( points );
     1276}
     1277
     1278/*!
     1279   \brief Find an interpolated polygon with "equidistant" points
     1280
     1281   The implementation is optimzed for non parametric curves
     1282   ( QwtSplineParametrization::ParameterX ) and falls back to
     1283   QwtSpline::equidistantPolygon() otherwise.
     1284
     1285   \param points Control nodes of the spline
     1286   \param distance Distance between 2 points according
     1287                  to the parametrization
     1288   \param withNodes When true, also add the control
     1289                   nodes ( even if not being equidistant )
     1290
     1291   \return Interpolating polygon
     1292
     1293   \sa QwtSpline::equidistantPolygon()
     1294 */
     1295QPolygonF QwtSplineC2::equidistantPolygon( const QPolygonF& points,
     1296    double distance, bool withNodes ) const
     1297{
     1298    if ( parametrization()->type() == QwtSplineParametrization::ParameterX )
     1299    {
     1300        if ( points.size() > 2 )
     1301        {
     1302            const QVector< double > cv = curvatures( points );
     1303            if ( cv.size() != points.size() )
     1304                return QPolygonF();
     1305
     1306            return qwtPolygonParametric< QwtSplinePolynomial::fromCurvatures >(
     1307                distance, points, cv, withNodes );
     1308        }
     1309    }
     1310
     1311    return QwtSplineInterpolating::equidistantPolygon( points, distance, withNodes );
     1312}
     1313
     1314/*! \fn QVector<double> QwtSplineC2::curvatures( const QPolygonF &points ) const
     1315
     1316   \brief Find the second derivative at the control points
     1317
     1318   \param points Control nodes of the spline
     1319   \return Vector with the values of the 2nd derivate at the control points
     1320
     1321   \sa slopes()
     1322   \note The x coordinates need to be increasing or decreasing
     1323 */
     1324
     1325/*!
     1326   \brief Find the first derivative at the control points
     1327
     1328   An implementation calculating the 2nd derivatives and then building
     1329   the slopes in a 2nd loop. QwtSplineCubic overloads it with a more
     1330   performant implementation doing it in one loop.
     1331
     1332   \param points Control nodes of the spline
     1333   \return Vector with the values of the 1nd derivate at the control points
     1334
     1335   \sa curvatures()
     1336
     1337   \note The x coordinates need to be increasing or decreasing
     1338 */
     1339QVector< double > QwtSplineC2::slopes( const QPolygonF& points ) const
     1340{
     1341    const QVector< double > curvatures = this->curvatures( points );
     1342    if ( curvatures.size() < 2 )
     1343        return QVector< double >();
     1344
     1345    QVector< double > slopes( curvatures.size() );
     1346
     1347    const double* cv = curvatures.constData();
     1348    double* m = slopes.data();
     1349
     1350    const int n = points.size();
     1351    const QPointF* p = points.constData();
     1352
     1353    QwtSplinePolynomial polynomial;
     1354
     1355    for ( int i = 0; i < n - 1; i++ )
     1356    {
     1357        polynomial = QwtSplinePolynomial::fromCurvatures( p[i], cv[i], p[i + 1], cv[i + 1] );
     1358        m[i] = polynomial.c1;
     1359    }
     1360
     1361    m[n - 1] = polynomial.slopeAt( p[n - 1].x() - p[n - 2].x() );
     1362
     1363    return slopes;
     1364}
     1365
     1366/*!
     1367   \brief Calculate the interpolating polynomials for a non parametric spline
     1368
     1369   C2 spline interpolations are based on finding values for the second
     1370   derivates of f at the control points. The interpolating polynomials can
     1371   be calculated from the the second derivates using QwtSplinePolynomial::fromCurvatures.
     1372
     1373   The default implementation is a 2 pass calculation. In derived classes it
     1374   might be overloaded by a one pass implementation.
     1375
     1376   \param points Control points
     1377   \return Interpolating polynomials
     1378
     1379   \note The x coordinates need to be increasing or decreasing
     1380 */
     1381QVector< QwtSplinePolynomial > QwtSplineC2::polynomials( const QPolygonF& points ) const
     1382{
     1383    QVector< QwtSplinePolynomial > polynomials;
     1384
     1385    const QVector< double > curvatures = this->curvatures( points );
     1386    if ( curvatures.size() < 2 )
     1387        return polynomials;
     1388
     1389    const QPointF* p = points.constData();
     1390    const double* cv = curvatures.constData();
     1391    const int n = curvatures.size();
     1392    polynomials.reserve( n - 1 );
     1393
     1394    for ( int i = 1; i < n; i++ )
     1395    {
     1396        polynomials += QwtSplinePolynomial::fromCurvatures(
     1397            p[i - 1], cv[i - 1], p[i], cv[i] );
     1398    }
     1399
     1400    return polynomials;
     1401}
  • trunk/BNC/qwt/qwt_spline.h

    r4271 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include <qpolygon.h>
    15 #include <qvector.h>
    16 
    17 /*!
    18   \brief A class for spline interpolation
    19 
    20   The QwtSpline class is used for cubical spline interpolation.
    21   Two types of splines, natural and periodic, are supported.
    22 
    23   \par Usage:
    24   <ol>
    25   <li>First call setPoints() to determine the spline coefficients
    26       for a tabulated function y(x).
    27   <li>After the coefficients have been set up, the interpolated
    28       function value for an argument x can be determined by calling
    29       QwtSpline::value().
    30   </ol>
    31 
    32   \par Example:
    33   \code
    34 #include <qwt_spline.h>
    35 
    36 QPolygonF interpolate(const QPolygonF& points, int numValues)
    37 {
    38     QwtSpline spline;
    39     if ( !spline.setPoints(points) )
    40         return points;
    41 
    42     QPolygonF interpolatedPoints(numValues);
    43 
    44     const double delta =
    45         (points[numPoints - 1].x() - points[0].x()) / (points.size() - 1);
    46     for(i = 0; i < points.size(); i++)  / interpolate
     14#include "qwt_spline.h"
     15
     16class QwtSplineParametrization;
     17class QwtSplinePolynomial;
     18class QPainterPath;
     19class QLineF;
     20class QPolygonF;
     21
     22#if QT_VERSION < 0x060000
     23template< typename T > class QVector;
     24#endif
     25
     26/*!
     27   \brief Base class for all splines
     28
     29   A spline is a curve represented by a sequence of polynomials. Spline approximation
     30   is the process of finding polynomials for a given set of points.
     31   When the algorithm preserves the initial points it is called interpolating.
     32
     33   Splines can be classified according to conditions of the polynomials that
     34   are met at the start/endpoints of the pieces:
     35
     36   - Geometric Continuity
     37
     38    - G0: polynomials are joined
     39    - G1: first derivatives are proportional at the join point
     40          The curve tangents thus have the same direction, but not necessarily the
     41          same magnitude. i.e., C1'(1) = (a,b,c) and C2'(0) = (k*a, k*b, k*c).
     42    - G2: first and second derivatives are proportional at join point
     43
     44   - Parametric Continuity
     45
     46    - C0: curves are joined
     47    - C1: first derivatives equal
     48    - C2: first and second derivatives are equal
     49
     50   Geometric continuity requires the geometry to be continuous, while parametric
     51   continuity requires that the underlying parameterization be continuous as well.
     52   Parametric continuity of order n implies geometric continuity of order n,
     53   but not vice-versa.
     54
     55   QwtSpline is the base class for spline approximations of any continuity.
     56 */
     57class QWT_EXPORT QwtSpline
     58{
     59  public:
     60    /*!
     61       Boundary type specifying the spline at its endpoints
     62
     63       \sa setBoundaryType(), boundaryType()
     64     */
     65    enum BoundaryType
    4766    {
    48         const double x = points[0].x() + i * delta;
    49         interpolatedPoints[i].setX(x);
    50         interpolatedPoints[i].setY(spline.value(x));
    51     }
    52     return interpolatedPoints;
    53 }
    54   \endcode
    55 */
    56 
    57 class QWT_EXPORT QwtSpline
    58 {
    59 public:
    60     //! Spline type
    61     enum SplineType
     67        /*!
     68           The polynomials at the start/endpoint depend on specific conditions
     69
     70           \sa QwtSpline::BoundaryCondition
     71         */
     72        ConditionalBoundaries,
     73
     74        /*!
     75           The polynomials at the start/endpoint are found by using
     76           imaginary additional points. Additional points at the end
     77           are found by translating points from the beginning or v.v.
     78         */
     79        PeriodicPolygon,
     80
     81        /*!
     82           ClosedPolygon is similar to PeriodicPolygon beside, that
     83           the interpolation includes the connection between the last
     84           and the first control point.
     85
     86           \note Only works for parametrizations, where the parameter increment
     87                for the the final closing line is positive.
     88                This excludes QwtSplineParametrization::ParameterX and
     89                QwtSplineParametrization::ParameterY
     90         */
     91
     92        ClosedPolygon
     93    };
     94
     95    /*!
     96       position of a boundary condition
     97       \sa boundaryCondition(), boundaryValue()
     98     */
     99    enum BoundaryPosition
    62100    {
    63         //! A natural spline
    64         Natural,
    65 
    66         //! A periodic spline
    67         Periodic
     101        //! the condition is at the beginning of the polynomial
     102        AtBeginning,
     103
     104        //! the condition is at the end of the polynomial
     105        AtEnd
    68106    };
    69107
     108    /*!
     109       \brief Boundary condition
     110
     111       A spline algorithm calculates polynomials by looking
     112       a couple of points back/ahead ( locality() ). At the ends
     113       additional rules are necessary to compensate the missing
     114       points.
     115
     116       \sa boundaryCondition(), boundaryValue()
     117       \sa QwtSplineC2::BoundaryConditionC2
     118     */
     119    enum BoundaryCondition
     120    {
     121        /*!
     122           The first derivative at the end point is given
     123           \sa boundaryValue()
     124         */
     125        Clamped1,
     126
     127        /*!
     128           The second derivative at the end point is given
     129
     130           \sa boundaryValue()
     131           \note a condition having a second derivative of 0
     132                is also called "natural".
     133         */
     134        Clamped2,
     135
     136        /*!
     137           The third derivative at the end point is given
     138
     139           \sa boundaryValue()
     140           \note a condition having a third derivative of 0
     141                is also called "parabolic runout".
     142         */
     143        Clamped3,
     144
     145        /*!
     146           The first derivate at the endpoint is related to the first derivative
     147           at its neighbour by the boundary value. F,e when the boundary
     148           value at the end is 1.0 then the slope at the last 2 points is
     149           the same.
     150
     151           \sa boundaryValue().
     152         */
     153        LinearRunout
     154    };
     155
    70156    QwtSpline();
    71     QwtSpline( const QwtSpline & );
    72 
    73     ~QwtSpline();
    74 
    75     QwtSpline &operator=( const QwtSpline & );
    76 
    77     void setSplineType( SplineType );
    78     SplineType splineType() const;
    79 
    80     bool setPoints( const QPolygonF& points );
    81     QPolygonF points() const;
    82 
    83     void reset();
    84 
    85     bool isValid() const;
    86     double value( double x ) const;
    87 
    88     const QVector<double> &coefficientsA() const;
    89     const QVector<double> &coefficientsB() const;
    90     const QVector<double> &coefficientsC() const;
    91 
    92 protected:
    93     bool buildNaturalSpline( const QPolygonF & );
    94     bool buildPeriodicSpline( const QPolygonF & );
    95 
    96 private:
     157    virtual ~QwtSpline();
     158
     159    void setParametrization( int type );
     160    void setParametrization( QwtSplineParametrization* );
     161    const QwtSplineParametrization* parametrization() const;
     162
     163    void setBoundaryType( BoundaryType );
     164    BoundaryType boundaryType() const;
     165
     166    void setBoundaryValue( BoundaryPosition, double value );
     167    double boundaryValue( BoundaryPosition ) const;
     168
     169    void setBoundaryCondition( BoundaryPosition, int condition );
     170    int boundaryCondition( BoundaryPosition ) const;
     171
     172    void setBoundaryConditions( int condition,
     173        double valueBegin = 0.0, double valueEnd = 0.0 );
     174
     175    virtual QPolygonF polygon( const QPolygonF&, double tolerance ) const;
     176    virtual QPainterPath painterPath( const QPolygonF& ) const = 0;
     177
     178    virtual uint locality() const;
     179
     180  private:
     181    Q_DISABLE_COPY(QwtSpline)
     182
    97183    class PrivateData;
    98     PrivateData *d_data;
     184    PrivateData* m_data;
     185};
     186
     187/*!
     188   \brief Base class for a spline interpolation
     189
     190   Spline interpolation is the process of interpolating a set of points
     191   piecewise with polynomials. The initial set of points is preserved.
     192 */
     193class QWT_EXPORT QwtSplineInterpolating : public QwtSpline
     194{
     195  public:
     196    QwtSplineInterpolating();
     197    virtual ~QwtSplineInterpolating();
     198
     199    virtual QPolygonF equidistantPolygon( const QPolygonF&,
     200        double distance, bool withNodes ) const;
     201
     202    virtual QPolygonF polygon(
     203        const QPolygonF&, double tolerance ) const QWT_OVERRIDE;
     204
     205    virtual QPainterPath painterPath( const QPolygonF& ) const QWT_OVERRIDE;
     206    virtual QVector< QLineF > bezierControlLines( const QPolygonF& ) const = 0;
     207
     208  private:
     209    Q_DISABLE_COPY(QwtSplineInterpolating)
     210};
     211
     212/*!
     213   \brief Base class for spline interpolations providing a
     214         first order geometric continuity ( G1 ) between adjoining curves
     215 */
     216class QWT_EXPORT QwtSplineG1 : public QwtSplineInterpolating
     217{
     218  public:
     219    QwtSplineG1();
     220    virtual ~QwtSplineG1();
     221};
     222
     223/*!
     224   \brief Base class for spline interpolations providing a
     225         first order parametric continuity ( C1 ) between adjoining curves
     226
     227   All interpolations with C1 continuity are based on rules for finding
     228   the 1. derivate at some control points.
     229
     230   In case of non parametric splines those points are the curve points, while
     231   for parametric splines the calculation is done twice using a parameter value t.
     232
     233   \sa QwtSplineParametrization
     234 */
     235class QWT_EXPORT QwtSplineC1 : public QwtSplineG1
     236{
     237  public:
     238    QwtSplineC1();
     239    virtual ~QwtSplineC1();
     240
     241    virtual QPainterPath painterPath( const QPolygonF& ) const QWT_OVERRIDE;
     242    virtual QVector< QLineF > bezierControlLines( const QPolygonF& ) const QWT_OVERRIDE;
     243
     244    virtual QPolygonF equidistantPolygon( const QPolygonF&,
     245        double distance, bool withNodes ) const QWT_OVERRIDE;
     246
     247    // these methods are the non parametric part
     248    virtual QVector< QwtSplinePolynomial > polynomials( const QPolygonF& ) const;
     249    virtual QVector< double > slopes( const QPolygonF& ) const = 0;
     250
     251    virtual double slopeAtBeginning( const QPolygonF&, double slopeNext ) const;
     252    virtual double slopeAtEnd( const QPolygonF&, double slopeBefore ) const;
     253};
     254
     255/*!
     256   \brief Base class for spline interpolations providing a
     257         second order parametric continuity ( C2 ) between adjoining curves
     258
     259   All interpolations with C2 continuity are based on rules for finding
     260   the 2. derivate at some control points.
     261
     262   In case of non parametric splines those points are the curve points, while
     263   for parametric splines the calculation is done twice using a parameter value t.
     264
     265   \sa QwtSplineParametrization
     266 */
     267class QWT_EXPORT QwtSplineC2 : public QwtSplineC1
     268{
     269  public:
     270    /*!
     271       Boundary condition that requires C2 continuity
     272
     273       \sa QwtSpline::boundaryCondition, QwtSpline::BoundaryCondition
     274     */
     275    enum BoundaryConditionC2
     276    {
     277        /*!
     278           The second derivate at the endpoint is related to the second derivatives
     279           at the 2 neighbours: cv[0] := 2.0 * cv[1] - cv[2].
     280
     281           \note boundaryValue() is ignored
     282         */
     283        CubicRunout = LinearRunout + 1,
     284
     285        /*!
     286           The 3rd derivate at the endpoint matches the 3rd derivate at its neighbours.
     287           Or in other words: the first/last curve segment extents the polynomial of its
     288           neighboured polynomial
     289
     290           \note boundaryValue() is ignored
     291         */
     292        NotAKnot
     293    };
     294
     295    QwtSplineC2();
     296    virtual ~QwtSplineC2();
     297
     298    virtual QPainterPath painterPath( const QPolygonF& ) const QWT_OVERRIDE;
     299    virtual QVector< QLineF > bezierControlLines( const QPolygonF& ) const QWT_OVERRIDE;
     300
     301    virtual QPolygonF equidistantPolygon( const QPolygonF&,
     302        double distance, bool withNodes ) const QWT_OVERRIDE;
     303
     304    // calculating the parametric equations
     305    virtual QVector< QwtSplinePolynomial > polynomials( const QPolygonF& ) const QWT_OVERRIDE;
     306    virtual QVector< double > slopes( const QPolygonF& ) const QWT_OVERRIDE;
     307    virtual QVector< double > curvatures( const QPolygonF& ) const = 0;
    99308};
    100309
  • trunk/BNC/qwt/qwt_symbol.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_painter.h"
    1212#include "qwt_graphic.h"
    13 #include <qapplication.h>
     13#include "qwt_math.h"
     14
    1415#include <qpainter.h>
    1516#include <qpainterpath.h>
    1617#include <qpixmap.h>
    1718#include <qpaintengine.h>
    18 #include <qmath.h>
    1919#ifndef QWT_NO_SVG
    2020#include <qsvgrenderer.h>
    … …  
    3232}
    3333
    34 static QwtGraphic qwtPathGraphic( const QPainterPath &path,
    35     const QPen &pen, const QBrush& brush )
     34static QwtGraphic qwtPathGraphic( const QPainterPath& path,
     35    const QPen& pen, const QBrush& brush )
    3636{
    3737    QwtGraphic graphic;
    … …  
    4848
    4949static inline QRectF qwtScaledBoundingRect(
    50     const QwtGraphic &graphic, const QSizeF size )
     50    const QwtGraphic& graphic, const QSizeF size )
    5151{
    5252    QSizeF scaledSize = size;
    … …  
    6767}
    6868
    69 static inline void qwtDrawPixmapSymbols( QPainter *painter,
    70     const QPointF *points, int numPoints, const QwtSymbol &symbol )
     69static inline void qwtDrawPixmapSymbols( QPainter* painter,
     70    const QPointF* points, int numPoints, const QwtSymbol& symbol )
    7171{
    7272    QSize size = symbol.size();
    … …  
    102102#ifndef QWT_NO_SVG
    103103
    104 static inline void qwtDrawSvgSymbols( QPainter *painter,
    105     const QPointF *points, int numPoints,
    106     QSvgRenderer *renderer, const QwtSymbol &symbol )
     104static inline void qwtDrawSvgSymbols( QPainter* painter,
     105    const QPointF* points, int numPoints,
     106    QSvgRenderer* renderer, const QwtSymbol& symbol )
    107107{
    108108    if ( renderer == NULL || !renderer->isValid() )
    … …  
    139139#endif
    140140
    141 static inline void qwtDrawGraphicSymbols( QPainter *painter,
    142     const QPointF *points, int numPoints, const QwtGraphic &graphic,
    143     const QwtSymbol &symbol )
     141static inline void qwtDrawGraphicSymbols( QPainter* painter,
     142    const QPointF* points, int numPoints, const QwtGraphic& graphic,
     143    const QwtSymbol& symbol )
    144144{
    145145    const QRectF pointRect = graphic.controlPointRect();
    … …  
    178178}
    179179
    180 static inline void qwtDrawEllipseSymbols( QPainter *painter,
    181     const QPointF *points, int numPoints, const QwtSymbol &symbol )
     180static inline void qwtDrawEllipseSymbols( QPainter* painter,
     181    const QPointF* points, int numPoints, const QwtSymbol& symbol )
    182182{
    183183    painter->setBrush( symbol.brush() );
    … …  
    220220}
    221221
    222 static inline void qwtDrawRectSymbols( QPainter *painter,
    223     const QPointF *points, int numPoints, const QwtSymbol &symbol )
     222static inline void qwtDrawRectSymbols( QPainter* painter,
     223    const QPointF* points, int numPoints, const QwtSymbol& symbol )
    224224{
    225225    const QSize size = symbol.size();
    … …  
    265265}
    266266
    267 static inline void qwtDrawDiamondSymbols( QPainter *painter,
    268     const QPointF *points, int numPoints, const QwtSymbol &symbol )
     267static inline void qwtDrawDiamondSymbols( QPainter* painter,
     268    const QPointF* points, int numPoints, const QwtSymbol& symbol )
    269269{
    270270    const QSize size = symbol.size();
    … …  
    300300        for ( int i = 0; i < numPoints; i++ )
    301301        {
    302             const QPointF &pos = points[i];
     302            const QPointF& pos = points[i];
    303303
    304304            const double x1 = pos.x() - 0.5 * size.width();
    … …  
    319319
    320320static inline void qwtDrawTriangleSymbols(
    321     QPainter *painter, QwtTriangle::Type type,
    322     const QPointF *points, int numPoints,
    323     const QwtSymbol &symbol )
     321    QPainter* painter, QwtTriangle::Type type,
     322    const QPointF* points, int numPoints,
     323    const QwtSymbol& symbol )
    324324{
    325325    const QSize size = symbol.size();
    … …  
    338338    if ( doAlign )
    339339    {
    340         sw2 = qFloor( sw2 );
    341         sh2 = qFloor( sh2 );
     340        sw2 = std::floor( sw2 );
     341        sh2 = std::floor( sh2 );
    342342    }
    343343
    344344    QPolygonF triangle( 3 );
    345     QPointF *trianglePoints = triangle.data();
     345    QPointF* trianglePoints = triangle.data();
    346346
    347347    for ( int i = 0; i < numPoints; i++ )
    348348    {
    349         const QPointF &pos = points[i];
     349        const QPointF& pos = points[i];
    350350
    351351        double x = pos.x();
    … …  
    423423
    424424static inline void qwtDrawLineSymbols(
    425     QPainter *painter, int orientations,
    426     const QPointF *points, int numPoints, const QwtSymbol &symbol )
     425    QPainter* painter, int orientations,
     426    const QPointF* points, int numPoints, const QwtSymbol& symbol )
    427427{
    428428    const QSize size = symbol.size();
    … …  
    442442    if ( QwtPainter::roundingAlignment( painter ) )
    443443    {
    444         const int sw = qFloor( size.width() );
    445         const int sh = qFloor( size.height() );
     444        const int sw = qwtFloor( size.width() );
     445        const int sh = qwtFloor( size.height() );
    446446        const int sw2 = size.width() / 2;
    447447        const int sh2 = size.height() / 2;
    … …  
    492492}
    493493
    494 static inline void qwtDrawXCrossSymbols( QPainter *painter,
    495     const QPointF *points, int numPoints, const QwtSymbol &symbol )
     494static inline void qwtDrawXCrossSymbols( QPainter* painter,
     495    const QPointF* points, int numPoints, const QwtSymbol& symbol )
    496496{
    497497    const QSize size = symbol.size();
    … …  
    516516        for ( int i = 0; i < numPoints; i++ )
    517517        {
    518             const QPointF &pos = points[i];
     518            const QPointF& pos = points[i];
    519519
    520520            const int x = qRound( pos.x() );
    … …  
    539539        for ( int i = 0; i < numPoints; i++ )
    540540        {
    541             const QPointF &pos = points[i];
     541            const QPointF& pos = points[i];
    542542
    543543            const double x1 = pos.x() - sw2;
    … …  
    552552}
    553553
    554 static inline void qwtDrawStar1Symbols( QPainter *painter,
    555     const QPointF *points, int numPoints, const QwtSymbol &symbol )
     554static inline void qwtDrawStar1Symbols( QPainter* painter,
     555    const QPointF* points, int numPoints, const QwtSymbol& symbol )
    556556{
    557557    const QSize size = symbol.size();
    … …  
    575575            QwtPainter::drawLine( painter,
    576576                qRound( r.left() + d1 ), qRound( r.bottom() - d1 ),
    577                 qRound( r .right() - d1), qRound( r.top() + d1 ) );
     577                qRound( r.right() - d1), qRound( r.top() + d1 ) );
    578578
    579579            const QPoint c = r.center();
    … …  
    596596
    597597            const QPointF c = r.center();
    598             const double d1  = r.width() / 2.0 * ( 1.0 - sqrt1_2 );
     598            const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );
    599599
    600600            QwtPainter::drawLine( painter,
    … …  
    614614}
    615615
    616 static inline void qwtDrawStar2Symbols( QPainter *painter,
    617     const QPointF *points, int numPoints, const QwtSymbol &symbol )
     616static inline void qwtDrawStar2Symbols( QPainter* painter,
     617    const QPointF* points, int numPoints, const QwtSymbol& symbol )
    618618{
    619619    QPen pen = symbol.pen();
    … …  
    631631
    632632    QPolygonF star( 12 );
    633     QPointF *starPoints = star.data();
     633    QPointF* starPoints = star.data();
    634634
    635635    const bool doAlign = QwtPainter::roundingAlignment( painter );
    … …  
    705705}
    706706
    707 static inline void qwtDrawHexagonSymbols( QPainter *painter,
    708     const QPointF *points, int numPoints, const QwtSymbol &symbol )
     707static inline void qwtDrawHexagonSymbols( QPainter* painter,
     708    const QPointF* points, int numPoints, const QwtSymbol& symbol )
    709709{
    710710    painter->setBrush( symbol.brush() );
    … …  
    717717
    718718    QPolygonF hexaPolygon( 6 );
    719     QPointF *hexaPoints = hexaPolygon.data();
     719    QPointF* hexaPoints = hexaPolygon.data();
    720720
    721721    const bool doAlign = QwtPainter::roundingAlignment( painter );
    … …  
    735735        if ( doAlign )
    736736        {
    737             x1 = qCeil( x1 );
    738             y1 = qCeil( y1 );
     737            x1 = std::ceil( x1 );
     738            y1 = std::ceil( y1 );
    739739        }
    740740
    … …  
    770770class QwtSymbol::PrivateData
    771771{
    772 public:
    773     PrivateData( QwtSymbol::Style st, const QBrush &br,
    774             const QPen &pn, const QSize &sz ):
    775         style( st ),
    776         size( sz ),
    777         brush( br ),
    778         pen( pn ),
    779         isPinPointEnabled( false )
     772  public:
     773    PrivateData( QwtSymbol::Style st, const QBrush& br,
     774            const QPen& pn, const QSize& sz )
     775        : style( st )
     776        , size( sz )
     777        , brush( br )
     778        , pen( pn )
     779        , isPinPointEnabled( false )
    780780    {
    781781        cache.policy = QwtSymbol::AutoCache;
    … …  
    822822    struct SVG
    823823    {
    824         QSvgRenderer *renderer;
     824        QSvgRenderer* renderer;
    825825    } svg;
    826826#endif
    … …  
    835835
    836836/*!
    837   Default Constructor
    838   \param style Symbol Style
    839 
    840   The symbol is constructed with gray interior,
    841   black outline with zero width, no size and style 'NoSymbol'.
    842 */
     837   Default Constructor
     838   \param style Symbol Style
     839
     840   The symbol is constructed with gray interior,
     841   black outline with zero width, no size and style 'NoSymbol'.
     842 */
    843843QwtSymbol::QwtSymbol( Style style )
    844844{
    845     d_data = new PrivateData( style, QBrush( Qt::gray ),
     845    m_data = new PrivateData( style, QBrush( Qt::gray ),
    846846        QPen( Qt::black, 0 ), QSize() );
    847847}
    848848
    849849/*!
    850   \brief Constructor
    851   \param style Symbol Style
    852   \param brush brush to fill the interior
    853   \param pen outline pen
    854   \param size size
    855 
    856   \sa setStyle(), setBrush(), setPen(), setSize()
    857 */
    858 QwtSymbol::QwtSymbol( QwtSymbol::Style style, const QBrush &brush,
    859     const QPen &pen, const QSize &size )
    860 {
    861     d_data = new PrivateData( style, brush, pen, size );
    862 }
    863 
    864 /*!
    865   \brief Constructor
    866 
    867   The symbol gets initialized by a painter path. The style is
    868   set to QwtSymbol::Path, the size is set to empty ( the path
    869   is displayed unscaled ).
    870 
    871   \param path painter path
    872   \param brush brush to fill the interior
    873   \param pen outline pen
    874 
    875   \sa setPath(), setBrush(), setPen(), setSize()
    876 */
    877 
    878 QwtSymbol::QwtSymbol( const QPainterPath &path,
    879     const QBrush &brush, const QPen &pen )
    880 {
    881     d_data = new PrivateData( QwtSymbol::Path, brush, pen, QSize() );
     850   \brief Constructor
     851   \param style Symbol Style
     852   \param brush brush to fill the interior
     853   \param pen outline pen
     854   \param size size
     855
     856   \sa setStyle(), setBrush(), setPen(), setSize()
     857 */
     858QwtSymbol::QwtSymbol( QwtSymbol::Style style, const QBrush& brush,
     859    const QPen& pen, const QSize& size )
     860{
     861    m_data = new PrivateData( style, brush, pen, size );
     862}
     863
     864/*!
     865   \brief Constructor
     866
     867   The symbol gets initialized by a painter path. The style is
     868   set to QwtSymbol::Path, the size is set to empty ( the path
     869   is displayed unscaled ).
     870
     871   \param path painter path
     872   \param brush brush to fill the interior
     873   \param pen outline pen
     874
     875   \sa setPath(), setBrush(), setPen(), setSize()
     876 */
     877
     878QwtSymbol::QwtSymbol( const QPainterPath& path,
     879    const QBrush& brush, const QPen& pen )
     880{
     881    m_data = new PrivateData( QwtSymbol::Path, brush, pen, QSize() );
    882882    setPath( path );
    883883}
    … …  
    886886QwtSymbol::~QwtSymbol()
    887887{
    888     delete d_data;
    889 }
    890 
    891 /*!
    892   Change the cache policy
    893 
    894   The default policy is AutoCache
    895 
    896   \param policy Cache policy
    897   \sa CachePolicy, cachePolicy()
    898 */
     888    delete m_data;
     889}
     890
     891/*!
     892   Change the cache policy
     893
     894   The default policy is AutoCache
     895
     896   \param policy Cache policy
     897   \sa CachePolicy, cachePolicy()
     898 */
    899899void QwtSymbol::setCachePolicy(
    900900    QwtSymbol::CachePolicy policy )
    901901{
    902     if ( d_data->cache.policy != policy )
    903     {
    904         d_data->cache.policy = policy;
     902    if ( m_data->cache.policy != policy )
     903    {
     904        m_data->cache.policy = policy;
    905905        invalidateCache();
    906906    }
    … …  
    908908
    909909/*!
    910   \return Cache policy
    911   \sa CachePolicy, setCachePolicy()
    912 */
     910   \return Cache policy
     911   \sa CachePolicy, setCachePolicy()
     912 */
    913913QwtSymbol::CachePolicy QwtSymbol::cachePolicy() const
    914914{
    915     return d_data->cache.policy;
    916 }
    917 
    918 /*!
    919   \brief Set a painter path as symbol
    920 
    921   The symbol is represented by a painter path, where the
    922   origin ( 0, 0 ) of the path coordinate system is mapped to
    923   the position of the symbol.
    924 
    925   When the symbol has valid size the painter path gets scaled
    926   to fit into the size. Otherwise the symbol size depends on
    927   the bounding rectangle of the path.
    928 
    929   \par Example
     915    return m_data->cache.policy;
     916}
     917
     918/*!
     919   \brief Set a painter path as symbol
     920
     921   The symbol is represented by a painter path, where the
     922   origin ( 0, 0 ) of the path coordinate system is mapped to
     923   the position of the symbol.
     924
     925   When the symbol has valid size the painter path gets scaled
     926   to fit into the size. Otherwise the symbol size depends on
     927   the bounding rectangle of the path.
     928
     929   \par Example
    930930    The following code defines a symbol drawing an arrow:
    931931
    932932    \code
    933       #include <qwt_symbol.h>
     933 #include <qwt_symbol.h>
    934934
    935935      QwtSymbol *symbol = new QwtSymbol();
    … …  
    958958      setSize( 10, 14 );
    959959    \endcode
    960   \endpar
    961 
    962   \param path Painter path
    963 
    964   \note The style is implicitely set to QwtSymbol::Path.
    965   \sa path(), setSize()
    966  */
    967 void QwtSymbol::setPath( const QPainterPath &path )
    968 {
    969     d_data->style = QwtSymbol::Path;
    970     d_data->path.path = path;
    971     d_data->path.graphic.reset();
     960
     961   \param path Painter path
     962
     963   \note The style is implicitly set to QwtSymbol::Path.
     964   \sa path(), setSize()
     965 */
     966void QwtSymbol::setPath( const QPainterPath& path )
     967{
     968    m_data->style = QwtSymbol::Path;
     969    m_data->path.path = path;
     970    m_data->path.graphic.reset();
    972971}
    973972
    … …  
    975974   \return Painter path for displaying the symbol
    976975   \sa setPath()
    977 */
    978 const QPainterPath &QwtSymbol::path() const
    979 {
    980     return d_data->path.path;
    981 }
    982 
    983 /*!
    984   Set a pixmap as symbol
    985 
    986   \param pixmap Pixmap
    987 
    988   \sa pixmap(), setGraphic()
    989 
    990   \note the style() is set to QwtSymbol::Pixmap
    991   \note brush() and pen() have no effect
    992  */
    993 void QwtSymbol::setPixmap( const QPixmap &pixmap )
    994 {
    995     d_data->style = QwtSymbol::Pixmap;
    996     d_data->pixmap.pixmap = pixmap;
    997 }
    998 
    999 /*!
    1000   \return Assigned pixmap
    1001   \sa setPixmap()
    1002  */
    1003 const QPixmap &QwtSymbol::pixmap() const
    1004 {
    1005     return d_data->pixmap.pixmap;
    1006 }
    1007 
    1008 /*!
    1009   Set a graphic as symbol
    1010 
    1011   \param graphic Graphic
    1012 
    1013   \sa graphic(), setPixmap()
    1014 
    1015   \note the style() is set to QwtSymbol::Graphic
    1016   \note brush() and pen() have no effect
    1017  */
    1018 void QwtSymbol::setGraphic( const QwtGraphic &graphic )
    1019 {
    1020     d_data->style = QwtSymbol::Graphic;
    1021     d_data->graphic.graphic = graphic;
    1022 }
    1023 
    1024 /*!
    1025   \return Assigned graphic
    1026   \sa setGraphic()
    1027  */
    1028 const QwtGraphic &QwtSymbol::graphic() const
    1029 {
    1030     return d_data->graphic.graphic;
     976 */
     977const QPainterPath& QwtSymbol::path() const
     978{
     979    return m_data->path.path;
     980}
     981
     982/*!
     983   Set a pixmap as symbol
     984
     985   \param pixmap Pixmap
     986
     987   \sa pixmap(), setGraphic()
     988
     989   \note the style() is set to QwtSymbol::Pixmap
     990   \note brush() and pen() have no effect
     991 */
     992void QwtSymbol::setPixmap( const QPixmap& pixmap )
     993{
     994    m_data->style = QwtSymbol::Pixmap;
     995    m_data->pixmap.pixmap = pixmap;
     996}
     997
     998/*!
     999   \return Assigned pixmap
     1000   \sa setPixmap()
     1001 */
     1002const QPixmap& QwtSymbol::pixmap() const
     1003{
     1004    return m_data->pixmap.pixmap;
     1005}
     1006
     1007/*!
     1008   Set a graphic as symbol
     1009
     1010   \param graphic Graphic
     1011
     1012   \sa graphic(), setPixmap()
     1013
     1014   \note the style() is set to QwtSymbol::Graphic
     1015   \note brush() and pen() have no effect
     1016 */
     1017void QwtSymbol::setGraphic( const QwtGraphic& graphic )
     1018{
     1019    m_data->style = QwtSymbol::Graphic;
     1020    m_data->graphic.graphic = graphic;
     1021}
     1022
     1023/*!
     1024   \return Assigned graphic
     1025   \sa setGraphic()
     1026 */
     1027const QwtGraphic& QwtSymbol::graphic() const
     1028{
     1029    return m_data->graphic.graphic;
    10311030}
    10321031
    … …  
    10341033
    10351034/*!
    1036   Set a SVG icon as symbol
    1037 
    1038   \param svgDocument SVG icon
    1039 
    1040   \sa setGraphic(), setPixmap()
    1041 
    1042   \note the style() is set to QwtSymbol::SvgDocument
    1043   \note brush() and pen() have no effect
    1044  */
    1045 void QwtSymbol::setSvgDocument( const QByteArray &svgDocument )
    1046 {
    1047     d_data->style = QwtSymbol::SvgDocument;
    1048     if ( d_data->svg.renderer == NULL )
    1049         d_data->svg.renderer = new QSvgRenderer();
    1050 
    1051     d_data->svg.renderer->load( svgDocument );
     1035   Set a SVG icon as symbol
     1036
     1037   \param svgDocument SVG icon
     1038
     1039   \sa setGraphic(), setPixmap()
     1040
     1041   \note the style() is set to QwtSymbol::SvgDocument
     1042   \note brush() and pen() have no effect
     1043 */
     1044void QwtSymbol::setSvgDocument( const QByteArray& svgDocument )
     1045{
     1046    m_data->style = QwtSymbol::SvgDocument;
     1047    if ( m_data->svg.renderer == NULL )
     1048        m_data->svg.renderer = new QSvgRenderer();
     1049
     1050    m_data->svg.renderer->load( svgDocument );
    10521051}
    10531052
    … …  
    10551054
    10561055/*!
    1057   \brief Specify the symbol's size
    1058 
    1059   If the 'h' parameter is left out or less than 0,
    1060   and the 'w' parameter is greater than or equal to 0,
    1061   the symbol size will be set to (w,w).
    1062 
    1063   \param width Width
    1064   \param height Height (defaults to -1)
    1065 
    1066   \sa size()
    1067 */
     1056   \brief Specify the symbol's size
     1057
     1058   If the 'h' parameter is left out or less than 0,
     1059   and the 'w' parameter is greater than or equal to 0,
     1060   the symbol size will be set to (w,w).
     1061
     1062   \param width Width
     1063   \param height Height (defaults to -1)
     1064
     1065   \sa size()
     1066 */
    10681067void QwtSymbol::setSize( int width, int height )
    10691068{
    … …  
    10791078
    10801079   \sa size()
    1081 */
    1082 void QwtSymbol::setSize( const QSize &size )
    1083 {
    1084     if ( size.isValid() && size != d_data->size )
    1085     {
    1086         d_data->size = size;
     1080 */
     1081void QwtSymbol::setSize( const QSize& size )
     1082{
     1083    if ( size.isValid() && size != m_data->size )
     1084    {
     1085        m_data->size = size;
    10871086        invalidateCache();
    10881087    }
    … …  
    10921091   \return Size
    10931092   \sa setSize()
    1094 */
     1093 */
    10951094const QSize& QwtSymbol::size() const
    10961095{
    1097     return d_data->size;
    1098 }
    1099 
    1100 /*!
    1101   \brief Assign a brush
    1102 
    1103   The brush is used to draw the interior of the symbol.
    1104   \param brush Brush
    1105 
    1106   \sa brush()
    1107 */
    1108 void QwtSymbol::setBrush( const QBrush &brush )
    1109 {
    1110     if ( brush != d_data->brush )
    1111     {
    1112         d_data->brush = brush;
     1096    return m_data->size;
     1097}
     1098
     1099/*!
     1100   \brief Assign a brush
     1101
     1102   The brush is used to draw the interior of the symbol.
     1103   \param brush Brush
     1104
     1105   \sa brush()
     1106 */
     1107void QwtSymbol::setBrush( const QBrush& brush )
     1108{
     1109    if ( brush != m_data->brush )
     1110    {
     1111        m_data->brush = brush;
    11131112        invalidateCache();
    11141113
    1115         if ( d_data->style == QwtSymbol::Path )
    1116             d_data->path.graphic.reset();
    1117     }
    1118 }
    1119 
    1120 /*!
    1121   \return Brush
    1122   \sa setBrush()
    1123 */
     1114        if ( m_data->style == QwtSymbol::Path )
     1115            m_data->path.graphic.reset();
     1116    }
     1117}
     1118
     1119/*!
     1120   \return Brush
     1121   \sa setBrush()
     1122 */
    11241123const QBrush& QwtSymbol::brush() const
    11251124{
    1126     return d_data->brush;
    1127 }
    1128 
    1129 /*!
    1130   Build and assign a pen
    1131 
    1132   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 )
    1133   what makes it non cosmetic ( see QPen::isCosmetic() ).
    1134   This method has been introduced to hide this incompatibility.
    1135 
    1136   \param color Pen color
    1137   \param width Pen width
    1138   \param style Pen style
    1139 
    1140   \sa pen(), brush()
    1141  */
    1142 void QwtSymbol::setPen( const QColor &color,
     1125    return m_data->brush;
     1126}
     1127
     1128/*!
     1129   Build and assign a pen
     1130
     1131   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 )
     1132   what makes it non cosmetic ( see QPen::isCosmetic() ).
     1133   This method has been introduced to hide this incompatibility.
     1134
     1135   \param color Pen color
     1136   \param width Pen width
     1137   \param style Pen style
     1138
     1139   \sa pen(), brush()
     1140 */
     1141void QwtSymbol::setPen( const QColor& color,
    11431142    qreal width, Qt::PenStyle style )
    11441143{
    … …  
    11471146
    11481147/*!
    1149   Assign a pen
    1150 
    1151   The pen is used to draw the symbol's outline.
    1152 
    1153   \param pen Pen
    1154   \sa pen(), setBrush()
    1155 */
    1156 void QwtSymbol::setPen( const QPen &pen )
    1157 {
    1158     if ( pen != d_data->pen )
    1159     {
    1160         d_data->pen = pen;
     1148   Assign a pen
     1149
     1150   The pen is used to draw the symbol's outline.
     1151
     1152   \param pen Pen
     1153   \sa pen(), setBrush()
     1154 */
     1155void QwtSymbol::setPen( const QPen& pen )
     1156{
     1157    if ( pen != m_data->pen )
     1158    {
     1159        m_data->pen = pen;
    11611160        invalidateCache();
    11621161
    1163         if ( d_data->style == QwtSymbol::Path )
    1164             d_data->path.graphic.reset();
    1165     }
    1166 }
    1167 
    1168 /*!
    1169   \return Pen
    1170   \sa setPen(), brush()
    1171 */
     1162        if ( m_data->style == QwtSymbol::Path )
     1163            m_data->path.graphic.reset();
     1164    }
     1165}
     1166
     1167/*!
     1168   \return Pen
     1169   \sa setPen(), brush()
     1170 */
    11721171const QPen& QwtSymbol::pen() const
    11731172{
    1174     return d_data->pen;
    1175 }
    1176 
    1177 /*!
    1178   \brief Set the color of the symbol
    1179 
    1180   Change the color of the brush for symbol types with a filled area.
    1181   For all other symbol types the color will be assigned to the pen.
    1182 
    1183   \param color Color
    1184 
    1185   \sa setBrush(), setPen(), brush(), pen()
    1186 */
    1187 void QwtSymbol::setColor( const QColor &color )
    1188 {
    1189     switch ( d_data->style )
     1173    return m_data->pen;
     1174}
     1175
     1176/*!
     1177   \brief Set the color of the symbol
     1178
     1179   Change the color of the brush for symbol types with a filled area.
     1180   For all other symbol types the color will be assigned to the pen.
     1181
     1182   \param color Color
     1183
     1184   \sa setBrush(), setPen(), brush(), pen()
     1185 */
     1186void QwtSymbol::setColor( const QColor& color )
     1187{
     1188    switch ( m_data->style )
    11901189    {
    11911190        case QwtSymbol::Ellipse:
    … …  
    12001199        case QwtSymbol::Hexagon:
    12011200        {
    1202             if ( d_data->brush.color() != color )
     1201            if ( m_data->brush.color() != color )
    12031202            {
    1204                 d_data->brush.setColor( color );
     1203                m_data->brush.setColor( color );
    12051204                invalidateCache();
    12061205            }
    … …  
    12131212        case QwtSymbol::Star1:
    12141213        {
    1215             if ( d_data->pen.color() != color )
     1214            if ( m_data->pen.color() != color )
    12161215            {
    1217                 d_data->pen.setColor( color );
     1216                m_data->pen.setColor( color );
    12181217                invalidateCache();
    12191218            }
    … …  
    12221221        default:
    12231222        {
    1224             if ( d_data->brush.color() != color ||
    1225                 d_data->pen.color() != color )
     1223            if ( m_data->brush.color() != color ||
     1224                m_data->pen.color() != color )
    12261225            {
    12271226                invalidateCache();
    12281227            }
    12291228
    1230             d_data->brush.setColor( color );
    1231             d_data->pen.setColor( color );
    1232         }
    1233     }
    1234 }
    1235 
    1236 /*!
    1237   \brief Set and enable a pin point
    1238 
    1239   The position of a complex symbol is not always aligned to its center
    1240   ( f.e an arrow, where the peak points to a position ). The pin point
    1241   defines the position inside of a Pixmap, Graphic, SvgDocument
    1242   or PainterPath symbol where the represented point has to
    1243   be aligned to.
    1244 
    1245   \param pos Position
    1246   \param enable En/Disable the pin point alignment
    1247 
    1248   \sa pinPoint(), setPinPointEnabled()
    1249  */
    1250 void QwtSymbol::setPinPoint( const QPointF &pos, bool enable )
    1251 {
    1252     if ( d_data->pinPoint != pos )
    1253     {
    1254         d_data->pinPoint = pos;
    1255         if ( d_data->isPinPointEnabled )
     1229            m_data->brush.setColor( color );
     1230            m_data->pen.setColor( color );
     1231        }
     1232    }
     1233}
     1234
     1235/*!
     1236   \brief Set and enable a pin point
     1237
     1238   The position of a complex symbol is not always aligned to its center
     1239   ( f.e an arrow, where the peak points to a position ). The pin point
     1240   defines the position inside of a Pixmap, Graphic, SvgDocument
     1241   or PainterPath symbol where the represented point has to
     1242   be aligned to.
     1243
     1244   \param pos Position
     1245   \param enable En/Disable the pin point alignment
     1246
     1247   \sa pinPoint(), setPinPointEnabled()
     1248 */
     1249void QwtSymbol::setPinPoint( const QPointF& pos, bool enable )
     1250{
     1251    if ( m_data->pinPoint != pos )
     1252    {
     1253        m_data->pinPoint = pos;
     1254        if ( m_data->isPinPointEnabled )
    12561255        {
    12571256            invalidateCache();
    … …  
    12631262
    12641263/*!
    1265   \return Pin point
    1266   \sa setPinPoint(), setPinPointEnabled()
     1264   \return Pin point
     1265   \sa setPinPoint(), setPinPointEnabled()
    12671266 */
    12681267QPointF QwtSymbol::pinPoint() const
    12691268{
    1270     return d_data->pinPoint;
    1271 }
    1272 
    1273 /*!
    1274   En/Disable the pin point alignment
    1275 
    1276   \param on Enabled, when on is true
    1277   \sa setPinPoint(), isPinPointEnabled()
     1269    return m_data->pinPoint;
     1270}
     1271
     1272/*!
     1273   En/Disable the pin point alignment
     1274
     1275   \param on Enabled, when on is true
     1276   \sa setPinPoint(), isPinPointEnabled()
    12781277 */
    12791278void QwtSymbol::setPinPointEnabled( bool on )
    12801279{
    1281     if ( d_data->isPinPointEnabled != on )
    1282     {
    1283         d_data->isPinPointEnabled = on;
     1280    if ( m_data->isPinPointEnabled != on )
     1281    {
     1282        m_data->isPinPointEnabled = on;
    12841283        invalidateCache();
    12851284    }
    … …  
    12871286
    12881287/*!
    1289   \return True, when the pin point translation is enabled
    1290   \sa setPinPoint(), setPinPointEnabled()
     1288   \return True, when the pin point translation is enabled
     1289   \sa setPinPoint(), setPinPointEnabled()
    12911290 */
    12921291bool QwtSymbol::isPinPointEnabled() const
    12931292{
    1294     return d_data->isPinPointEnabled;
    1295 }
    1296 
    1297 /*!
    1298   Render an array of symbols
    1299 
    1300   Painting several symbols is more effective than drawing symbols
    1301   one by one, as a couple of layout calculations and setting of pen/brush
    1302   can be done once for the complete array.
    1303 
    1304   \param painter Painter
    1305   \param points Array of points
    1306   \param numPoints Number of points
    1307 */
    1308 void QwtSymbol::drawSymbols( QPainter *painter,
    1309     const QPointF *points, int numPoints ) const
     1293    return m_data->isPinPointEnabled;
     1294}
     1295
     1296/*!
     1297   Render an array of symbols
     1298
     1299   Painting several symbols is more effective than drawing symbols
     1300   one by one, as a couple of layout calculations and setting of pen/brush
     1301   can be done once for the complete array.
     1302
     1303   \param painter Painter
     1304   \param points Array of points
     1305   \param numPoints Number of points
     1306 */
     1307void QwtSymbol::drawSymbols( QPainter* painter,
     1308    const QPointF* points, int numPoints ) const
    13101309{
    13111310    if ( numPoints <= 0 )
    … …  
    13201319        !painter->transform().isScaling() )
    13211320    {
    1322         if ( d_data->cache.policy == QwtSymbol::Cache )
     1321        if ( m_data->cache.policy == QwtSymbol::Cache )
    13231322        {
    13241323            useCache = true;
    13251324        }
    1326         else if ( d_data->cache.policy == QwtSymbol::AutoCache )
    1327         {
    1328             if ( painter->paintEngine()->type() == QPaintEngine::Raster )
     1325        else if ( m_data->cache.policy == QwtSymbol::AutoCache )
     1326        {
     1327            switch( painter->paintEngine()->type() )
    13291328            {
    1330                 useCache = true;
    1331             }
    1332             else
    1333             {
    1334                 switch( d_data->style )
     1329                case QPaintEngine::OpenGL:
     1330                case QPaintEngine::OpenGL2:
    13351331                {
    1336                     case QwtSymbol::XCross:
    1337                     case QwtSymbol::HLine:
    1338                     case QwtSymbol::VLine:
    1339                     case QwtSymbol::Cross:
    1340                         break;
    1341 
    1342                     case QwtSymbol::Pixmap:
     1332                    // using a FBO as cache ?
     1333                    useCache = false;
     1334                    break;
     1335                }
     1336                case QPaintEngine::OpenVG:
     1337                case QPaintEngine::SVG:
     1338                case QPaintEngine::Pdf:
     1339                case QPaintEngine::Picture:
     1340                {
     1341                    // vector graphics
     1342                    useCache = false;
     1343                    break;
     1344                }
     1345                case QPaintEngine::X11:
     1346                {
     1347                    switch( m_data->style )
    13431348                    {
    1344                         if ( !d_data->size.isEmpty() &&
    1345                             d_data->size != d_data->pixmap.pixmap.size() )
     1349                        case QwtSymbol::XCross:
     1350                        case QwtSymbol::HLine:
     1351                        case QwtSymbol::VLine:
     1352                        case QwtSymbol::Cross:
    13461353                        {
    1347                             useCache = true;
     1354                            // for the very simple shapes using vector graphics is
     1355                            // usually faster.
     1356
     1357                            useCache = false;
     1358                            break;
    13481359                        }
    1349                         break;
     1360
     1361                        case QwtSymbol::Pixmap:
     1362                        {
     1363                            if ( m_data->size.isEmpty() ||
     1364                                m_data->size == m_data->pixmap.pixmap.size() )
     1365                            {
     1366                                // no need to have a pixmap cache for a pixmap
     1367                                // of the same size
     1368
     1369                                useCache = false;
     1370                            }
     1371                            break;
     1372                        }
     1373                        default:
     1374                            break;
    13501375                    }
    1351                     default:
    1352                         useCache = true;
     1376                    break;
     1377                }
     1378                default:
     1379                {
     1380                    useCache = true;
    13531381                }
    13541382            }
    … …  
    13601388        const QRect br = boundingRect();
    13611389
    1362         if ( d_data->cache.pixmap.isNull() )
    1363         {
    1364             d_data->cache.pixmap = QwtPainter::backingStore( NULL, br.size() );
    1365             d_data->cache.pixmap.fill( Qt::transparent );
    1366 
    1367             QPainter p( &d_data->cache.pixmap );
     1390        if ( m_data->cache.pixmap.isNull() )
     1391        {
     1392            m_data->cache.pixmap = QwtPainter::backingStore( NULL, br.size() );
     1393            m_data->cache.pixmap.fill( Qt::transparent );
     1394
     1395            QPainter p( &m_data->cache.pixmap );
    13681396            p.setRenderHints( painter->renderHints() );
    13691397            p.translate( -br.topLeft() );
    13701398
    1371             const QPointF pos;
     1399            const QPointF pos( 0.0, 0.0 );
    13721400            renderSymbols( &p, &pos, 1 );
    13731401        }
    … …  
    13811409            const int top = qRound( points[i].y() ) + dy;
    13821410
    1383             painter->drawPixmap( left, top, d_data->cache.pixmap );
     1411            painter->drawPixmap( left, top, m_data->cache.pixmap );
    13841412        }
    13851413    }
    … …  
    13931421
    13941422/*!
    1395   \brief Draw the symbol into a rectangle
    1396 
    1397   The symbol is painted centered and scaled into the target rectangle.
    1398   It is always painted uncached and the pin point is ignored.
    1399 
    1400   This method is primarily intended for drawing a symbol to
    1401   the legend.
    1402 
    1403   \param painter Painter
    1404   \param rect Target rectangle for the symbol
    1405 */
    1406 void QwtSymbol::drawSymbol( QPainter *painter, const QRectF &rect ) const
    1407 {
    1408     if ( d_data->style == QwtSymbol::NoSymbol )
     1423   \brief Draw the symbol into a rectangle
     1424
     1425   The symbol is painted centered and scaled into the target rectangle.
     1426   It is always painted uncached and the pin point is ignored.
     1427
     1428   This method is primarily intended for drawing a symbol to
     1429   the legend.
     1430
     1431   \param painter Painter
     1432   \param rect Target rectangle for the symbol
     1433 */
     1434void QwtSymbol::drawSymbol( QPainter* painter, const QRectF& rect ) const
     1435{
     1436    if ( m_data->style == QwtSymbol::NoSymbol )
    14091437        return;
    14101438
    1411     if ( d_data->style == QwtSymbol::Graphic )
    1412     {
    1413         d_data->graphic.graphic.render(
     1439    if ( m_data->style == QwtSymbol::Graphic )
     1440    {
     1441        m_data->graphic.graphic.render(
    14141442            painter, rect, Qt::KeepAspectRatio );
    14151443    }
    1416     else if ( d_data->style == QwtSymbol::Path )
    1417     {
    1418         if ( d_data->path.graphic.isNull() )
    1419         {
    1420             d_data->path.graphic = qwtPathGraphic(
    1421                 d_data->path.path, d_data->pen, d_data->brush );
    1422         }
    1423 
    1424         d_data->path.graphic.render(
     1444    else if ( m_data->style == QwtSymbol::Path )
     1445    {
     1446        if ( m_data->path.graphic.isNull() )
     1447        {
     1448            m_data->path.graphic = qwtPathGraphic(
     1449                m_data->path.path, m_data->pen, m_data->brush );
     1450        }
     1451
     1452        m_data->path.graphic.render(
    14251453            painter, rect, Qt::KeepAspectRatio );
    14261454        return;
    14271455    }
    1428     else if ( d_data->style == QwtSymbol::SvgDocument )
     1456    else if ( m_data->style == QwtSymbol::SvgDocument )
    14291457    {
    14301458#ifndef QWT_NO_SVG
    1431         if ( d_data->svg.renderer )
     1459        if ( m_data->svg.renderer )
    14321460        {
    14331461            QRectF scaledRect;
    14341462
    1435             QSizeF sz = d_data->svg.renderer->viewBoxF().size();
     1463            QSizeF sz = m_data->svg.renderer->viewBoxF().size();
    14361464            if ( !sz.isEmpty() )
    14371465            {
    … …  
    14451473            }
    14461474
    1447             d_data->svg.renderer->render(
     1475            m_data->svg.renderer->render(
    14481476                painter, scaledRect );
    14491477        }
    … …  
    14641492        painter->scale( ratio, ratio );
    14651493
    1466         const bool isPinPointEnabled = d_data->isPinPointEnabled;
    1467         d_data->isPinPointEnabled = false;
     1494        const bool isPinPointEnabled = m_data->isPinPointEnabled;
     1495        m_data->isPinPointEnabled = false;
    14681496
    14691497        const QPointF pos;
    14701498        renderSymbols( painter, &pos, 1 );
    14711499
    1472         d_data->isPinPointEnabled = isPinPointEnabled;
     1500        m_data->isPinPointEnabled = isPinPointEnabled;
    14731501
    14741502        painter->restore();
    … …  
    14771505
    14781506/*!
    1479   Render the symbol to series of points
    1480 
    1481   \param painter Qt painter
    1482   \param points Positions of the symbols
    1483   \param numPoints Number of points
    1484  */
    1485 void QwtSymbol::renderSymbols( QPainter *painter,
    1486     const QPointF *points, int numPoints ) const
    1487 {
    1488     switch ( d_data->style )
     1507   Render the symbol to series of points
     1508
     1509   \param painter Qt painter
     1510   \param points Positions of the symbols
     1511   \param numPoints Number of points
     1512 */
     1513void QwtSymbol::renderSymbols( QPainter* painter,
     1514    const QPointF* points, int numPoints ) const
     1515{
     1516    switch ( m_data->style )
    14891517    {
    14901518        case QwtSymbol::Ellipse:
    … …  
    15681596        case QwtSymbol::Path:
    15691597        {
    1570             if ( d_data->path.graphic.isNull() )
     1598            if ( m_data->path.graphic.isNull() )
    15711599            {
    1572                 d_data->path.graphic = qwtPathGraphic( d_data->path.path,
    1573                     d_data->pen, d_data->brush );
     1600                m_data->path.graphic = qwtPathGraphic( m_data->path.path,
     1601                    m_data->pen, m_data->brush );
    15741602            }
    15751603
    15761604            qwtDrawGraphicSymbols( painter, points, numPoints,
    1577                 d_data->path.graphic, *this );
     1605                m_data->path.graphic, *this );
    15781606            break;
    15791607        }
    … …  
    15861614        {
    15871615            qwtDrawGraphicSymbols( painter, points, numPoints,
    1588                 d_data->graphic.graphic, *this );
     1616                m_data->graphic.graphic, *this );
    15891617            break;
    15901618        }
    … …  
    15931621#ifndef QWT_NO_SVG
    15941622            qwtDrawSvgSymbols( painter, points, numPoints,
    1595                 d_data->svg.renderer, *this );
     1623                m_data->svg.renderer, *this );
    15961624#endif
    15971625            break;
    … …  
    16021630
    16031631/*!
    1604   Calculate the bounding rectangle for a symbol
    1605   at position (0,0).
    1606 
    1607   \return Bounding rectangle
     1632   Calculate the bounding rectangle for a symbol
     1633   at position (0,0).
     1634
     1635   \return Bounding rectangle
    16081636 */
    16091637QRect QwtSymbol::boundingRect() const
    … …  
    16131641    bool pinPointTranslation = false;
    16141642
    1615     switch ( d_data->style )
     1643    switch ( m_data->style )
    16161644    {
    16171645        case QwtSymbol::Ellipse:
    … …  
    16201648        {
    16211649            qreal pw = 0.0;
    1622             if ( d_data->pen.style() != Qt::NoPen )
    1623                 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) );
    1624 
    1625             rect.setSize( d_data->size + QSizeF( pw, pw ) );
     1650            if ( m_data->pen.style() != Qt::NoPen )
     1651                pw = QwtPainter::effectivePenWidth( m_data->pen );
     1652
     1653            rect.setSize( m_data->size + QSizeF( pw, pw ) );
    16261654            rect.moveCenter( QPointF( 0.0, 0.0 ) );
    16271655
    … …  
    16391667        {
    16401668            qreal pw = 0.0;
    1641             if ( d_data->pen.style() != Qt::NoPen )
    1642                 pw = qMax( d_data->pen.widthF(), qreal( 1.0 ) );
    1643 
    1644             rect.setSize( d_data->size + QSizeF( 2 * pw, 2 * pw ) );
     1669            if ( m_data->pen.style() != Qt::NoPen )
     1670                pw = QwtPainter::effectivePenWidth( m_data->pen );
     1671
     1672            rect.setSize( m_data->size + QSizeF( 2 * pw, 2 * pw ) );
    16451673            rect.moveCenter( QPointF( 0.0, 0.0 ) );
    16461674            break;
    … …  
    16481676        case QwtSymbol::Path:
    16491677        {
    1650             if ( d_data->path.graphic.isNull() )
     1678            if ( m_data->path.graphic.isNull() )
    16511679            {
    1652                 d_data->path.graphic = qwtPathGraphic(
    1653                     d_data->path.path, d_data->pen, d_data->brush );
     1680                m_data->path.graphic = qwtPathGraphic(
     1681                    m_data->path.path, m_data->pen, m_data->brush );
    16541682            }
    16551683
    16561684            rect = qwtScaledBoundingRect(
    1657                 d_data->path.graphic, d_data->size );
     1685                m_data->path.graphic, m_data->size );
    16581686            pinPointTranslation = true;
    16591687
    … …  
    16621690        case QwtSymbol::Pixmap:
    16631691        {
    1664             if ( d_data->size.isEmpty() )
    1665                 rect.setSize( d_data->pixmap.pixmap.size() );
     1692            if ( m_data->size.isEmpty() )
     1693                rect.setSize( m_data->pixmap.pixmap.size() );
    16661694            else
    1667                 rect.setSize( d_data->size );
     1695                rect.setSize( m_data->size );
    16681696
    16691697            pinPointTranslation = true;
    … …  
    16741702        {
    16751703            rect = qwtScaledBoundingRect(
    1676                 d_data->graphic.graphic, d_data->size );
     1704                m_data->graphic.graphic, m_data->size );
    16771705            pinPointTranslation = true;
    16781706
    … …  
    16821710        case QwtSymbol::SvgDocument:
    16831711        {
    1684             if ( d_data->svg.renderer )
    1685                 rect = d_data->svg.renderer->viewBoxF();
    1686 
    1687             if ( d_data->size.isValid() && !rect.isEmpty() )
     1712            if ( m_data->svg.renderer )
     1713                rect = m_data->svg.renderer->viewBoxF();
     1714
     1715            if ( m_data->size.isValid() && !rect.isEmpty() )
    16881716            {
    16891717                QSizeF sz = rect.size();
    16901718
    1691                 const double sx = d_data->size.width() / sz.width();
    1692                 const double sy = d_data->size.height() / sz.height();
     1719                const double sx = m_data->size.width() / sz.width();
     1720                const double sy = m_data->size.height() / sz.height();
    16931721
    16941722                QTransform transform;
    … …  
    17031731        default:
    17041732        {
    1705             rect.setSize( d_data->size );
     1733            rect.setSize( m_data->size );
    17061734            rect.moveCenter( QPointF( 0.0, 0.0 ) );
    17071735        }
    … …  
    17111739    {
    17121740        QPointF pinPoint( 0.0, 0.0 );
    1713         if ( d_data->isPinPointEnabled )
    1714             pinPoint = rect.center() - d_data->pinPoint;
     1741        if ( m_data->isPinPointEnabled )
     1742            pinPoint = rect.center() - m_data->pinPoint;
    17151743
    17161744        rect.moveCenter( pinPoint );
    … …  
    17181746
    17191747    QRect r;
    1720     r.setLeft( qFloor( rect.left() ) );
    1721     r.setTop( qFloor( rect.top() ) );
    1722     r.setRight( qCeil( rect.right() ) );
    1723     r.setBottom( qCeil( rect.bottom() ) );
    1724 
    1725     if ( d_data->style != QwtSymbol::Pixmap )
     1748    r.setLeft( qwtFloor( rect.left() ) );
     1749    r.setTop( qwtFloor( rect.top() ) );
     1750    r.setRight( qwtCeil( rect.right() ) );
     1751    r.setBottom( qwtCeil( rect.bottom() ) );
     1752
     1753    if ( m_data->style != QwtSymbol::Pixmap )
    17261754        r.adjust( -1, -1, 1, 1 ); // for antialiasing
    17271755
    … …  
    17301758
    17311759/*!
    1732   Invalidate the cached symbol pixmap
    1733 
    1734   The symbol invalidates its cache, whenever an attribute is changed
    1735   that has an effect ob how to display a symbol. In case of derived
    1736   classes with individual styles ( >= QwtSymbol::UserStyle ) it
    1737   might be necessary to call invalidateCache() for attributes
    1738   that are relevant for this style.
    1739 
    1740   \sa CachePolicy, setCachePolicy(), drawSymbols()
     1760   Invalidate the cached symbol pixmap
     1761
     1762   The symbol invalidates its cache, whenever an attribute is changed
     1763   that has an effect ob how to display a symbol. In case of derived
     1764   classes with individual styles ( >= QwtSymbol::UserStyle ) it
     1765   might be necessary to call invalidateCache() for attributes
     1766   that are relevant for this style.
     1767
     1768   \sa CachePolicy, setCachePolicy(), drawSymbols()
    17411769 */
    17421770void QwtSymbol::invalidateCache()
    17431771{
    1744     if ( !d_data->cache.pixmap.isNull() )
    1745         d_data->cache.pixmap = QPixmap();
    1746 }
    1747 
    1748 /*!
    1749   Specify the symbol style
    1750 
    1751   \param style Style
    1752   \sa style()
    1753 */
     1772    if ( !m_data->cache.pixmap.isNull() )
     1773        m_data->cache.pixmap = QPixmap();
     1774}
     1775
     1776/*!
     1777   Specify the symbol style
     1778
     1779   \param style Style
     1780   \sa style()
     1781 */
    17541782void QwtSymbol::setStyle( QwtSymbol::Style style )
    17551783{
    1756     if ( d_data->style != style )
    1757     {
    1758         d_data->style = style;
     1784    if ( m_data->style != style )
     1785    {
     1786        m_data->style = style;
    17591787        invalidateCache();
    17601788    }
    … …  
    17621790
    17631791/*!
    1764   \return Current symbol style
    1765   \sa setStyle()
    1766 */
     1792   \return Current symbol style
     1793   \sa setStyle()
     1794 */
    17671795QwtSymbol::Style QwtSymbol::style() const
    17681796{
    1769     return d_data->style;
    1770 }
     1797    return m_data->style;
     1798}
  • trunk/BNC/qwt/qwt_symbol.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
     14
    1415#include <qpolygon.h>
     16#include <qpen.h>
     17#include <qbrush.h>
    1518
    1619class QPainter;
    17 class QRect;
    1820class QSize;
    1921class QBrush;
    … …  
    2123class QColor;
    2224class QPointF;
    23 class QPolygonF;
    2425class QPainterPath;
    2526class QPixmap;
    … …  
    3031class QWT_EXPORT QwtSymbol
    3132{
    32 public:
     33  public:
    3334    /*!
    34       Symbol Style
    35       \sa setStyle(), style()
     35       Symbol Style
     36       \sa setStyle(), style()
    3637     */
    3738    enum Style
    … …  
    8687
    8788        /*!
    88           The symbol is represented by a painter path, where the
    89           origin ( 0, 0 ) of the path coordinate system is mapped to
    90           the position of the symbol.
    91 
    92           \sa setPath(), path()
     89           The symbol is represented by a painter path, where the
     90           origin ( 0, 0 ) of the path coordinate system is mapped to
     91           the position of the symbol.
     92
     93           \sa setPath(), path()
    9394         */
    9495        Path,
    9596
    9697        /*!
    97           The symbol is represented by a pixmap. The pixmap is centered
    98           or aligned to its pin point.
    99 
    100           \sa setPinPoint()
     98           The symbol is represented by a pixmap. The pixmap is centered
     99           or aligned to its pin point.
     100
     101           \sa setPinPoint()
    101102         */
    102103        Pixmap,
    103104
    104105        /*!
    105           The symbol is represented by a graphic. The graphic is centered
    106           or aligned to its pin point.
    107 
    108           \sa setPinPoint()
     106           The symbol is represented by a graphic. The graphic is centered
     107           or aligned to its pin point.
     108
     109           \sa setPinPoint()
    109110         */
    110111        Graphic,
    111112
    112113        /*!
    113           The symbol is represented by a SVG graphic. The graphic is centered
    114           or aligned to its pin point.
    115 
    116           \sa setPinPoint()
     114           The symbol is represented by a SVG graphic. The graphic is centered
     115           or aligned to its pin point.
     116
     117           \sa setPinPoint()
    117118         */
    118119        SvgDocument,
    119120
    120121        /*!
    121          Styles >= QwtSymbol::UserSymbol are reserved for derived
    122          classes of QwtSymbol that overload drawSymbols() with
    123          additional application specific symbol types.
     122           Styles >= QwtSymbol::UserSymbol are reserved for derived
     123           classes of QwtSymbol that overload drawSymbols() with
     124           additional application specific symbol types.
    124125         */
    125126        UserStyle = 1000
    … …  
    127128
    128129    /*!
    129       Depending on the render engine and the complexity of the
    130       symbol shape it might be faster to render the symbol
    131       to a pixmap and to paint this pixmap.
    132 
    133       F.e. the raster paint engine is a pure software renderer
    134       where in cache mode a draw operation usually ends in
    135       raster operation with the the backing store, that are usually
    136       faster, than the algorithms for rendering polygons.
    137       But the opposite can be expected for graphic pipelines
    138       that can make use of hardware acceleration.
    139 
    140       The default setting is AutoCache
    141 
    142       \sa setCachePolicy(), cachePolicy()
    143 
    144       \note The policy has no effect, when the symbol is painted
     130       Depending on the render engine and the complexity of the
     131       symbol shape it might be faster to render the symbol
     132       to a pixmap and to paint this pixmap.
     133
     134       F.e. the raster paint engine is a pure software renderer
     135       where in cache mode a draw operation usually ends in
     136       raster operation with the the backing store, that are usually
     137       faster, than the algorithms for rendering polygons.
     138       But the opposite can be expected for graphic pipelines
     139       that can make use of hardware acceleration.
     140
     141       The default setting is AutoCache
     142
     143       \sa setCachePolicy(), cachePolicy()
     144
     145       \note The policy has no effect, when the symbol is painted
    145146            to a vector graphics format ( PDF, SVG ).
    146       \warning Since Qt 4.8 raster is the default backend on X11
     147       \warning Since Qt 4.8 raster is the default backend on X11
    147148     */
    148149
    … …  
    164165    };
    165166
    166 public:
    167     QwtSymbol( Style = NoSymbol );
    168     QwtSymbol( Style, const QBrush &, const QPen &, const QSize & );
    169     QwtSymbol( const QPainterPath &, const QBrush &, const QPen & );
     167  public:
     168    explicit QwtSymbol( Style = NoSymbol );
     169    QwtSymbol( Style, const QBrush&, const QPen&, const QSize& );
     170    QwtSymbol( const QPainterPath&, const QBrush&, const QPen& );
    170171
    171172    virtual ~QwtSymbol();
    … …  
    174175    CachePolicy cachePolicy() const;
    175176
    176     void setSize( const QSize & );
     177    void setSize( const QSize& );
    177178    void setSize( int width, int height = -1 );
    178     const QSize &size() const;
    179 
    180     void setPinPoint( const QPointF &pos, bool enable = true );
     179    const QSize& size() const;
     180
     181    void setPinPoint( const QPointF& pos, bool enable = true );
    181182    QPointF pinPoint() const;
    182183
    … …  
    184185    bool isPinPointEnabled() const;
    185186
    186     virtual void setColor( const QColor & );
    187 
    188     void setBrush( const QBrush & );
    189     const QBrush &brush() const;
    190 
    191     void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    192     void setPen( const QPen & );
    193     const QPen &pen() const;
     187    virtual void setColor( const QColor& );
     188
     189    void setBrush( const QBrush& );
     190    const QBrush& brush() const;
     191
     192    void setPen( const QColor&, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
     193    void setPen( const QPen& );
     194    const QPen& pen() const;
    194195
    195196    void setStyle( Style );
    196197    Style style() const;
    197198
    198     void setPath( const QPainterPath & );
    199     const QPainterPath &path() const;
    200 
    201     void setPixmap( const QPixmap & );
    202     const QPixmap &pixmap() const;
    203 
    204     void setGraphic( const QwtGraphic & );
    205     const QwtGraphic &graphic() const;
     199    void setPath( const QPainterPath& );
     200    const QPainterPath& path() const;
     201
     202    void setPixmap( const QPixmap& );
     203    const QPixmap& pixmap() const;
     204
     205    void setGraphic( const QwtGraphic& );
     206    const QwtGraphic& graphic() const;
    206207
    207208#ifndef QWT_NO_SVG
    208     void setSvgDocument( const QByteArray & );
     209    void setSvgDocument( const QByteArray& );
    209210#endif
    210211
    211     void drawSymbol( QPainter *, const QRectF & ) const;
    212     void drawSymbol( QPainter *, const QPointF & ) const;
    213     void drawSymbols( QPainter *, const QPolygonF & ) const;
    214     void drawSymbols( QPainter *,
    215         const QPointF *, int numPoints ) const;
     212    void drawSymbol( QPainter*, const QRectF& ) const;
     213    void drawSymbol( QPainter*, const QPointF& ) const;
     214    void drawSymbols( QPainter*, const QPolygonF& ) const;
     215    void drawSymbols( QPainter*,
     216        const QPointF*, int numPoints ) const;
    216217
    217218    virtual QRect boundingRect() const;
    218219    void invalidateCache();
    219220
    220 protected:
    221     virtual void renderSymbols( QPainter *,
    222         const QPointF *, int numPoints ) const;
    223 
    224 private:
    225     // Disabled copy constructor and operator=
    226     QwtSymbol( const QwtSymbol & );
    227     QwtSymbol &operator=( const QwtSymbol & );
     221  protected:
     222    virtual void renderSymbols( QPainter*,
     223        const QPointF*, int numPoints ) const;
     224
     225  private:
     226    Q_DISABLE_COPY(QwtSymbol)
    228227
    229228    class PrivateData;
    230     PrivateData *d_data;
     229    PrivateData* m_data;
    231230};
    232231
    233232/*!
    234   \brief Draw the symbol at a specified position
    235 
    236   \param painter Painter
    237   \param pos Position of the symbol in screen coordinates
    238 */
     233   \brief Draw the symbol at a specified position
     234
     235   \param painter Painter
     236   \param pos Position of the symbol in screen coordinates
     237 */
    239238inline void QwtSymbol::drawSymbol(
    240     QPainter *painter, const QPointF &pos ) const
     239    QPainter* painter, const QPointF& pos ) const
    241240{
    242241    drawSymbols( painter, &pos, 1 );
    … …  
    244243
    245244/*!
    246   \brief Draw symbols at the specified points
    247 
    248   \param painter Painter
    249   \param points Positions of the symbols in screen coordinates
    250 */
     245   \brief Draw symbols at the specified points
     246
     247   \param painter Painter
     248   \param points Positions of the symbols in screen coordinates
     249 */
    251250
    252251inline void QwtSymbol::drawSymbols(
    253     QPainter *painter, const QPolygonF &points ) const
     252    QPainter* painter, const QPolygonF& points ) const
    254253{
    255254    drawSymbols( painter, points.data(), points.size() );
  • trunk/BNC/qwt/qwt_system_clock.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_system_clock.h"
    11 
    12 #if QT_VERSION >= 0x040800
    13 #define USE_ELAPSED_TIMER 1
    14 #endif
    15 
    16 #if USE_ELAPSED_TIMER
    17 
    1811#include <qelapsedtimer.h>
    1912
    20 class QwtSystemClock::PrivateData
     13//! \return true, if the elapsed timer is valid
     14bool QwtSystemClock::isNull() const
    2115{
    22 public:
    23     QElapsedTimer timer;
    24 };
    25 
    26 QwtSystemClock::QwtSystemClock()
    27 {
    28     d_data = new PrivateData();
     16    return m_timer.isValid();
    2917}
    3018
    31 QwtSystemClock::~QwtSystemClock()
     19//! Start the elapsed timer
     20void QwtSystemClock::start()
    3221{
    33     delete d_data;
     22    m_timer.start();
    3423}
    3524
    36 bool QwtSystemClock::isNull() const
    37 {
    38     return d_data->timer.isValid();
    39 }
    40 
    41 void QwtSystemClock::start()
    42 {
    43     d_data->timer.start();
    44 }
    45 
     25/*!
     26    Restart the elapsed timer
     27    \return elapsed time in multiples of milliseconds
     28 */
    4629double QwtSystemClock::restart()
    4730{
    48     const qint64 nsecs = d_data->timer.restart();
     31    const qint64 nsecs = m_timer.restart();
    4932    return nsecs / 1e6;
    5033}
    5134
     35//! \return elapsed time in multiples of milliseconds
    5236double QwtSystemClock::elapsed() const
    5337{
    54     const qint64 nsecs = d_data->timer.nsecsElapsed();
     38    const qint64 nsecs = m_timer.nsecsElapsed();
    5539    return nsecs / 1e6;
    5640}
    57 
    58 #else // !USE_ELAPSED_TIMER
    59 
    60 #include <qdatetime.h>
    61 
    62 #if !defined(Q_OS_WIN)
    63 #include <unistd.h>
    64 #endif
    65 
    66 #if defined(Q_OS_MAC)
    67 #include <stdint.h>
    68 #include <mach/mach_time.h>
    69 #define QWT_HIGH_RESOLUTION_CLOCK
    70 #elif defined(_POSIX_TIMERS)
    71 #include <time.h>
    72 #define QWT_HIGH_RESOLUTION_CLOCK
    73 #elif defined(Q_OS_WIN)
    74 #define QWT_HIGH_RESOLUTION_CLOCK
    75 #include <qt_windows.h>
    76 #endif
    77 
    78 #if defined(QWT_HIGH_RESOLUTION_CLOCK)
    79 
    80 class QwtHighResolutionClock
    81 {
    82 public:
    83     QwtHighResolutionClock();
    84 
    85     void start();
    86     double restart();
    87     double elapsed() const;
    88 
    89     bool isNull() const;
    90 
    91     static double precision();
    92 
    93 private:
    94 
    95 #if defined(Q_OS_MAC)
    96     static double msecsTo( uint64_t, uint64_t );
    97 
    98     uint64_t d_timeStamp;
    99 #elif defined(_POSIX_TIMERS)
    100 
    101     static double msecsTo( const struct timespec &,
    102         const struct timespec & );
    103 
    104     static bool isMonotonic();
    105 
    106     struct timespec d_timeStamp;
    107     clockid_t d_clockId;
    108 
    109 #elif defined(Q_OS_WIN)
    110 
    111     LARGE_INTEGER d_startTicks;
    112     LARGE_INTEGER d_ticksPerSecond;
    113 #endif
    114 };
    115 
    116 #if defined(Q_OS_MAC)
    117 QwtHighResolutionClock::QwtHighResolutionClock():
    118     d_timeStamp( 0 )
    119 {
    120 }
    121 
    122 double QwtHighResolutionClock::precision()
    123 {
    124     return 1e-6;
    125 }
    126 
    127 void QwtHighResolutionClock::start()
    128 {
    129     d_timeStamp = mach_absolute_time();
    130 }
    131 
    132 double QwtHighResolutionClock::restart()
    133 {
    134     const uint64_t timeStamp = mach_absolute_time();
    135     const double elapsed = msecsTo( d_timeStamp, timeStamp );
    136     d_timeStamp = timeStamp;
    137 
    138     return elapsed;
    139 }
    140 
    141 double QwtHighResolutionClock::elapsed() const
    142 {
    143     return msecsTo( d_timeStamp, mach_absolute_time() );
    144 }
    145 
    146 bool QwtHighResolutionClock::isNull() const
    147 {
    148     return d_timeStamp == 0;
    149 }
    150 
    151 double QwtHighResolutionClock::msecsTo(
    152     uint64_t from, uint64_t to )
    153 {
    154     const uint64_t difference = to - from;
    155 
    156     static double conversion = 0.0;
    157     if ( conversion == 0.0 )
    158     {
    159         mach_timebase_info_data_t info;
    160         kern_return_t err = mach_timebase_info( &info );
    161 
    162         // convert the timebase into ms
    163         if ( err == 0  )
    164             conversion = 1e-6 * ( double ) info.numer / ( double ) info.denom;
    165     }
    166 
    167     return conversion * ( double ) difference;
    168 }
    169 
    170 #elif defined(_POSIX_TIMERS)
    171 
    172 QwtHighResolutionClock::QwtHighResolutionClock()
    173 {
    174     d_clockId = isMonotonic() ? CLOCK_MONOTONIC : CLOCK_REALTIME;
    175     d_timeStamp.tv_sec = d_timeStamp.tv_nsec = 0;
    176 }
    177 
    178 double QwtHighResolutionClock::precision()
    179 {
    180     struct timespec resolution;
    181 
    182     int clockId = isMonotonic() ? CLOCK_MONOTONIC : CLOCK_REALTIME;
    183     ::clock_getres( clockId, &resolution );
    184 
    185     return resolution.tv_nsec / 1e3;
    186 }
    187 
    188 inline bool QwtHighResolutionClock::isNull() const
    189 {
    190     return d_timeStamp.tv_sec <= 0 && d_timeStamp.tv_nsec <= 0;
    191 }
    192 
    193 inline void QwtHighResolutionClock::start()
    194 {
    195     ::clock_gettime( d_clockId, &d_timeStamp );
    196 }
    197 
    198 double QwtHighResolutionClock::restart()
    199 {
    200     struct timespec timeStamp;
    201     ::clock_gettime( d_clockId, &timeStamp );
    202 
    203     const double elapsed = msecsTo( d_timeStamp, timeStamp );
    204 
    205     d_timeStamp = timeStamp;
    206     return elapsed;
    207 }
    208 
    209 inline double QwtHighResolutionClock::elapsed() const
    210 {
    211     struct timespec timeStamp;
    212     ::clock_gettime( d_clockId, &timeStamp );
    213 
    214     return msecsTo( d_timeStamp, timeStamp );
    215 }
    216 
    217 inline double QwtHighResolutionClock::msecsTo(
    218     const struct timespec &t1, const struct timespec &t2 )
    219 {
    220     return ( t2.tv_sec - t1.tv_sec ) * 1e3
    221         + ( t2.tv_nsec - t1.tv_nsec ) * 1e-6;
    222 }
    223 
    224 bool QwtHighResolutionClock::isMonotonic()
    225 {
    226     // code copied from qcore_unix.cpp
    227 
    228 #if (_POSIX_MONOTONIC_CLOCK-0 > 0)
    229     return true;
    230 #else
    231     static int returnValue = 0;
    232 
    233     if ( returnValue == 0 )
    234     {
    235 #if (_POSIX_MONOTONIC_CLOCK-0 < 0) || !defined(_SC_MONOTONIC_CLOCK)
    236         returnValue = -1;
    237 #elif (_POSIX_MONOTONIC_CLOCK == 0)
    238         // detect if the system support monotonic timers
    239         const long x = sysconf( _SC_MONOTONIC_CLOCK );
    240         returnValue = ( x >= 200112L ) ? 1 : -1;
    241 #endif
    242     }
    243 
    244     return returnValue != -1;
    245 #endif
    246 }
    247 
    248 #elif defined(Q_OS_WIN)
    249 
    250 QwtHighResolutionClock::QwtHighResolutionClock()
    251 {
    252     d_startTicks.QuadPart = 0;
    253     QueryPerformanceFrequency( &d_ticksPerSecond );
    254 }
    255 
    256 double QwtHighResolutionClock::precision()
    257 {
    258     LARGE_INTEGER ticks;
    259     if ( QueryPerformanceFrequency( &ticks ) && ticks.QuadPart > 0 )
    260         return 1e3 / ticks.QuadPart;
    261 
    262     return 0.0;
    263 }
    264 
    265 inline bool QwtHighResolutionClock::isNull() const
    266 {
    267     return d_startTicks.QuadPart <= 0;
    268 }
    269 
    270 inline void QwtHighResolutionClock::start()
    271 {
    272     QueryPerformanceCounter( &d_startTicks );
    273 }
    274 
    275 inline double QwtHighResolutionClock::restart()
    276 {
    277     LARGE_INTEGER ticks;
    278     QueryPerformanceCounter( &ticks );
    279 
    280     const double dt = ticks.QuadPart - d_startTicks.QuadPart;
    281     d_startTicks = ticks;
    282 
    283     return dt / d_ticksPerSecond.QuadPart * 1e3;
    284 }
    285 
    286 inline double QwtHighResolutionClock::elapsed() const
    287 {
    288     LARGE_INTEGER ticks;
    289     QueryPerformanceCounter( &ticks );
    290 
    291     const double dt = ticks.QuadPart - d_startTicks.QuadPart;
    292     return dt / d_ticksPerSecond.QuadPart * 1e3;
    293 }
    294 
    295 #endif
    296 
    297 #endif // QWT_HIGH_RESOLUTION_CLOCK
    298 
    299 class QwtSystemClock::PrivateData
    300 {
    301 public:
    302 #if defined(QWT_HIGH_RESOLUTION_CLOCK)
    303     QwtHighResolutionClock *clock;
    304 #endif
    305     QTime time;
    306 };
    307 
    308 //!  Constructs a null clock object.
    309 QwtSystemClock::QwtSystemClock()
    310 {
    311     d_data = new PrivateData;
    312 
    313 #if defined(QWT_HIGH_RESOLUTION_CLOCK)
    314     d_data->clock = NULL;
    315     if ( QwtHighResolutionClock::precision() > 0.0 )
    316         d_data->clock = new QwtHighResolutionClock;
    317 #endif
    318 }
    319 
    320 //! Destructor
    321 QwtSystemClock::~QwtSystemClock()
    322 {
    323 #if defined(QWT_HIGH_RESOLUTION_CLOCK)
    324     delete d_data->clock;
    325 #endif
    326     delete d_data;
    327 }
    328 
    329 /*!
    330   \return true if the clock has never been started.
    331 */
    332 bool QwtSystemClock::isNull() const
    333 {
    334 #if defined(QWT_HIGH_RESOLUTION_CLOCK)
    335     if ( d_data->clock )
    336         return d_data->clock->isNull();
    337 #endif
    338 
    339     return d_data->time.isNull();
    340 }
    341 
    342 /*!
    343   Sets the start time to the current time.
    344 */
    345 void QwtSystemClock::start()
    346 {
    347 #if defined(QWT_HIGH_RESOLUTION_CLOCK)
    348     if ( d_data->clock )
    349     {
    350         d_data->clock->start();
    351         return;
    352     }
    353 #endif
    354 
    355     d_data->time.start();
    356 }
    357 
    358 /*!
    359   Set the start time to the current time
    360   \return Time, that is elapsed since the previous start time.
    361 */
    362 double QwtSystemClock::restart()
    363 {
    364 #if defined(QWT_HIGH_RESOLUTION_CLOCK)
    365     if ( d_data->clock )
    366         return d_data->clock->restart();
    367 #endif
    368 
    369     return d_data->time.restart();
    370 }
    371 
    372 /*!
    373   \return Number of milliseconds that have elapsed since the last time
    374           start() or restart() was called or 0.0 for null clocks.
    375 */
    376 double QwtSystemClock::elapsed() const
    377 {
    378     double elapsed = 0.0;
    379 
    380 #if defined(QWT_HIGH_RESOLUTION_CLOCK)
    381     if ( d_data->clock )
    382     {
    383         if ( !d_data->clock->isNull() )
    384             elapsed = d_data->clock->elapsed();
    385 
    386         return elapsed;
    387     }
    388 #endif
    389 
    390     if ( !d_data->time.isNull() )
    391         elapsed = d_data->time.elapsed();
    392 
    393     return elapsed;
    394 }
    395 
    396 #endif
  • trunk/BNC/qwt/qwt_system_clock.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
     14#include <qelapsedtimer.h>
    1415
    1516/*!
    16   \brief QwtSystemClock provides high resolution clock time functions.
     17   \brief QwtSystemClock provides high resolution clock time functions.
    1718
    18   Sometimes the resolution offered by QTime ( millisecond ) is not accurate
    19   enough for implementing time measurements ( f.e. sampling ).
    20   QwtSystemClock offers a subset of the QTime functionality using higher
    21   resolution timers ( if possible ).
     19   Precision and time intervals are multiples of milliseconds (ms).
    2220
    23   Precision and time intervals are multiples of milliseconds (ms).
    24 
    25   ( QwtSystemClock is obsolete since Qt 4.8 as QElapsedTimer offers the same
    26     precision )
    27 
    28   \note The implementation uses high-resolution performance counter on Windows,
    29         mach_absolute_time() on the Mac or POSIX timers on other systems.
    30         If none is available it falls back on QTimer.
    31 */
     21   ( QwtSystemClock is deprecated as QElapsedTimer offers the same precision )
     22 */
    3223
    3324class QWT_EXPORT QwtSystemClock
    3425{
    35 public:
    36     QwtSystemClock();
    37     virtual ~QwtSystemClock();
    38 
     26  public:
    3927    bool isNull() const;
    4028
    … …  
    4331    double elapsed() const;
    4432
    45 private:
    46     class PrivateData;
    47     PrivateData *d_data;
     33  private:
     34    QElapsedTimer m_timer;
    4835};
    4936
  • trunk/BNC/qwt/qwt_text.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_painter.h"
    1212#include "qwt_text_engine.h"
     13#include "qwt_math.h"
     14
    1315#include <qmap.h>
    1416#include <qfont.h>
    … …  
    1719#include <qbrush.h>
    1820#include <qpainter.h>
    19 #include <qapplication.h>
    20 #include <qdesktopwidget.h>
    21 #include <qmath.h>
    22 
    23 class QwtTextEngineDict
    24 {
    25 public:
    26     static QwtTextEngineDict &dict();
    27 
    28     void setTextEngine( QwtText::TextFormat, QwtTextEngine * );
    29 
    30     const QwtTextEngine *textEngine( QwtText::TextFormat ) const;
    31     const QwtTextEngine *textEngine( const QString &,
    32         QwtText::TextFormat ) const;
    33 
    34 private:
    35     QwtTextEngineDict();
    36     ~QwtTextEngineDict();
    37 
    38     typedef QMap<int, QwtTextEngine *> EngineMap;
    39 
    40     inline const QwtTextEngine *engine( EngineMap::const_iterator &it ) const
    41     {
    42         return it.value();
    43     }
    44 
    45     EngineMap d_map;
    46 };
    47 
    48 QwtTextEngineDict &QwtTextEngineDict::dict()
    49 {
    50     static QwtTextEngineDict engineDict;
    51     return engineDict;
    52 }
    53 
    54 QwtTextEngineDict::QwtTextEngineDict()
    55 {
    56     d_map.insert( QwtText::PlainText, new QwtPlainTextEngine() );
    57 #ifndef QT_NO_RICHTEXT
    58     d_map.insert( QwtText::RichText, new QwtRichTextEngine() );
     21
     22#if QT_VERSION >= 0x050200
     23
     24static QwtText qwtStringToText( const QString& text )
     25{
     26    return QwtText( text );
     27}
     28
    5929#endif
    60 }
    61 
    62 QwtTextEngineDict::~QwtTextEngineDict()
    63 {
    64     for ( EngineMap::const_iterator it = d_map.constBegin();
    65         it != d_map.constEnd(); ++it )
    66     {
    67         const QwtTextEngine *textEngine = engine( it );
    68         delete textEngine;
    69     }
    70 }
    71 
    72 const QwtTextEngine *QwtTextEngineDict::textEngine( const QString& text,
    73     QwtText::TextFormat format ) const
    74 {
    75     if ( format == QwtText::AutoText )
    76     {
    77         for ( EngineMap::const_iterator it = d_map.begin();
    78             it != d_map.end(); ++it )
     30
     31namespace
     32{
     33    static const struct RegisterQwtText
     34    {
     35        inline RegisterQwtText()
    7936        {
    80             if ( it.key() != QwtText::PlainText )
     37            qRegisterMetaType< QwtText >();
     38
     39#if QT_VERSION >= 0x050200
     40            QMetaType::registerConverter< QString, QwtText >( qwtStringToText );
     41#endif
     42        }
     43
     44    } qwtRegisterQwtText;
     45}
     46
     47namespace
     48{
     49    class TextEngineDict
     50    {
     51      public:
     52        static TextEngineDict& dict();
     53
     54        void setTextEngine( QwtText::TextFormat, QwtTextEngine* );
     55
     56        const QwtTextEngine* textEngine( QwtText::TextFormat ) const;
     57        const QwtTextEngine* textEngine( const QString&,
     58            QwtText::TextFormat ) const;
     59
     60      private:
     61        TextEngineDict();
     62        ~TextEngineDict();
     63
     64        typedef QMap< int, QwtTextEngine* > EngineMap;
     65
     66        inline const QwtTextEngine* engine( EngineMap::const_iterator& it ) const
     67        {
     68            return it.value();
     69        }
     70
     71        EngineMap m_map;
     72    };
     73
     74    TextEngineDict& TextEngineDict::dict()
     75    {
     76        static TextEngineDict engineDict;
     77        return engineDict;
     78    }
     79
     80    TextEngineDict::TextEngineDict()
     81    {
     82        m_map.insert( QwtText::PlainText, new QwtPlainTextEngine() );
     83    #ifndef QT_NO_RICHTEXT
     84        m_map.insert( QwtText::RichText, new QwtRichTextEngine() );
     85    #endif
     86    }
     87
     88    TextEngineDict::~TextEngineDict()
     89    {
     90        for ( EngineMap::const_iterator it = m_map.constBegin();
     91            it != m_map.constEnd(); ++it )
     92        {
     93            const QwtTextEngine* textEngine = engine( it );
     94            delete textEngine;
     95        }
     96    }
     97
     98    const QwtTextEngine* TextEngineDict::textEngine( const QString& text,
     99        QwtText::TextFormat format ) const
     100    {
     101        if ( format == QwtText::AutoText )
     102        {
     103            for ( EngineMap::const_iterator it = m_map.begin();
     104                it != m_map.end(); ++it )
    81105            {
    82                 const QwtTextEngine *e = engine( it );
    83                 if ( e && e->mightRender( text ) )
    84                     return e;
     106                if ( it.key() != QwtText::PlainText )
     107                {
     108                    const QwtTextEngine* e = engine( it );
     109                    if ( e && e->mightRender( text ) )
     110                        return e;
     111                }
    85112            }
    86113        }
    87     }
    88 
    89     EngineMap::const_iterator it = d_map.find( format );
    90     if ( it != d_map.end() )
    91     {
    92         const QwtTextEngine *e = engine( it );
    93         if ( e )
    94             return e;
    95     }
    96 
    97     it = d_map.find( QwtText::PlainText );
    98     return engine( it );
    99 }
    100 
    101 void QwtTextEngineDict::setTextEngine( QwtText::TextFormat format,
    102     QwtTextEngine *engine )
    103 {
    104     if ( format == QwtText::AutoText )
    105         return;
    106 
    107     if ( format == QwtText::PlainText && engine == NULL )
    108         return;
    109 
    110     EngineMap::const_iterator it = d_map.constFind( format );
    111     if ( it != d_map.constEnd() )
    112     {
    113         delete this->engine( it );
    114         d_map.remove( format );
    115     }
    116 
    117     if ( engine != NULL )
    118         d_map.insert( format, engine );
    119 }
    120 
    121 const QwtTextEngine *QwtTextEngineDict::textEngine(
    122     QwtText::TextFormat format ) const
    123 {
    124     const QwtTextEngine *e = NULL;
    125 
    126     EngineMap::const_iterator it = d_map.find( format );
    127     if ( it != d_map.end() )
    128         e = engine( it );
    129 
    130     return e;
     114
     115        EngineMap::const_iterator it = m_map.find( format );
     116        if ( it != m_map.end() )
     117        {
     118            const QwtTextEngine* e = engine( it );
     119            if ( e )
     120                return e;
     121        }
     122
     123        it = m_map.find( QwtText::PlainText );
     124        return engine( it );
     125    }
     126
     127    void TextEngineDict::setTextEngine( QwtText::TextFormat format,
     128        QwtTextEngine* engine )
     129    {
     130        if ( format == QwtText::AutoText )
     131            return;
     132
     133        if ( format == QwtText::PlainText && engine == NULL )
     134            return;
     135
     136        EngineMap::const_iterator it = m_map.constFind( format );
     137        if ( it != m_map.constEnd() )
     138        {
     139            delete this->engine( it );
     140            m_map.remove( format );
     141        }
     142
     143        if ( engine != NULL )
     144            m_map.insert( format, engine );
     145    }
     146
     147    const QwtTextEngine* TextEngineDict::textEngine(
     148        QwtText::TextFormat format ) const
     149    {
     150        const QwtTextEngine* e = NULL;
     151
     152        EngineMap::const_iterator it = m_map.find( format );
     153        if ( it != m_map.end() )
     154            e = engine( it );
     155
     156        return e;
     157    }
    131158}
    132159
    133160class QwtText::PrivateData
    134161{
    135 public:
     162  public:
    136163    PrivateData():
    137164        renderFlags( Qt::AlignCenter ),
    … …  
    139166        borderPen( Qt::NoPen ),
    140167        backgroundBrush( Qt::NoBrush ),
    141         paintAttributes( 0 ),
    142         layoutAttributes( 0 ),
    143168        textEngine( NULL )
    144169    {
    … …  
    156181    QwtText::LayoutAttributes layoutAttributes;
    157182
    158     const QwtTextEngine *textEngine;
     183    const QwtTextEngine* textEngine;
    159184};
    160185
    161186class QwtText::LayoutCache
    162187{
    163 public:
     188  public:
    164189    void invalidate()
    165190    {
    … …  
    173198/*!
    174199   Constructor
     200 */
     201QwtText::QwtText()
     202{
     203    m_data = new PrivateData;
     204    m_data->textEngine = textEngine( m_data->text, PlainText );
     205
     206    m_layoutCache = new LayoutCache;
     207}
     208
     209/*!
     210   Constructor
    175211
    176212   \param text Text content
    177213   \param textFormat Text format
    178 */
    179 QwtText::QwtText( const QString &text, QwtText::TextFormat textFormat )
    180 {
    181     d_data = new PrivateData;
    182     d_data->text = text;
    183     d_data->textEngine = textEngine( text, textFormat );
    184 
    185     d_layoutCache = new LayoutCache;
     214 */
     215QwtText::QwtText( const QString& text, QwtText::TextFormat textFormat )
     216{
     217    m_data = new PrivateData;
     218    m_data->text = text;
     219    m_data->textEngine = textEngine( text, textFormat );
     220
     221    m_layoutCache = new LayoutCache;
    186222}
    187223
    188224//! Copy constructor
    189 QwtText::QwtText( const QwtText &other )
    190 {
    191     d_data = new PrivateData;
    192     *d_data = *other.d_data;
    193 
    194     d_layoutCache = new LayoutCache;
    195     *d_layoutCache = *other.d_layoutCache;
     225QwtText::QwtText( const QwtText& other )
     226{
     227    m_data = new PrivateData;
     228    *m_data = *other.m_data;
     229
     230    m_layoutCache = new LayoutCache;
     231    *m_layoutCache = *other.m_layoutCache;
    196232}
    197233
    … …  
    199235QwtText::~QwtText()
    200236{
    201     delete d_data;
    202     delete d_layoutCache;
     237    delete m_data;
     238    delete m_layoutCache;
    203239}
    204240
    205241//! Assignment operator
    206 QwtText &QwtText::operator=( const QwtText & other )
    207 {
    208     *d_data = *other.d_data;
    209     *d_layoutCache = *other.d_layoutCache;
     242QwtText& QwtText::operator=( const QwtText& other )
     243{
     244    *m_data = *other.m_data;
     245    *m_layoutCache = *other.m_layoutCache;
    210246    return *this;
    211247}
    212248
    213249//! Relational operator
    214 bool QwtText::operator==( const QwtText &other ) const
    215 {
    216     return d_data->renderFlags == other.d_data->renderFlags &&
    217         d_data->text == other.d_data->text &&
    218         d_data->font == other.d_data->font &&
    219         d_data->color == other.d_data->color &&
    220         d_data->borderRadius == other.d_data->borderRadius &&
    221         d_data->borderPen == other.d_data->borderPen &&
    222         d_data->backgroundBrush == other.d_data->backgroundBrush &&
    223         d_data->paintAttributes == other.d_data->paintAttributes &&
    224         d_data->textEngine == other.d_data->textEngine;
     250bool QwtText::operator==( const QwtText& other ) const
     251{
     252    return m_data->renderFlags == other.m_data->renderFlags &&
     253           m_data->text == other.m_data->text &&
     254           m_data->font == other.m_data->font &&
     255           m_data->color == other.m_data->color &&
     256           m_data->borderRadius == other.m_data->borderRadius &&
     257           m_data->borderPen == other.m_data->borderPen &&
     258           m_data->backgroundBrush == other.m_data->backgroundBrush &&
     259           m_data->paintAttributes == other.m_data->paintAttributes &&
     260           m_data->textEngine == other.m_data->textEngine;
    225261}
    226262
    227263//! Relational operator
    228 bool QwtText::operator!=( const QwtText &other ) const // invalidate
     264bool QwtText::operator!=( const QwtText& other ) const // invalidate
    229265{
    230266    return !( other == *this );
    … …  
    238274
    239275   \sa text()
    240 */
    241 void QwtText::setText( const QString &text,
     276 */
     277void QwtText::setText( const QString& text,
    242278    QwtText::TextFormat textFormat )
    243279{
    244     d_data->text = text;
    245     d_data->textEngine = textEngine( text, textFormat );
    246     d_layoutCache->invalidate();
     280    m_data->text = text;
     281    m_data->textEngine = textEngine( text, textFormat );
     282    m_layoutCache->invalidate();
    247283}
    248284
    … …  
    250286   \return Text as QString.
    251287   \sa setText()
    252 */
     288 */
    253289QString QwtText::text() const
    254290{
    255     return d_data->text;
     291    return m_data->text;
    256292}
    257293
    … …  
    265301   \sa renderFlags(), QwtTextEngine::draw()
    266302   \note Some renderFlags might have no effect, depending on the text format.
    267 */
     303 */
    268304void QwtText::setRenderFlags( int renderFlags )
    269305{
    270     if ( renderFlags != d_data->renderFlags )
    271     {
    272         d_data->renderFlags = renderFlags;
    273         d_layoutCache->invalidate();
     306    if ( renderFlags != m_data->renderFlags )
     307    {
     308        m_data->renderFlags = renderFlags;
     309        m_layoutCache->invalidate();
    274310    }
    275311}
    … …  
    278314   \return Render flags
    279315   \sa setRenderFlags()
    280 */
     316 */
    281317int QwtText::renderFlags() const
    282318{
    283     return d_data->renderFlags;
     319    return m_data->renderFlags;
    284320}
    285321
    … …  
    290326   \note Setting the font might have no effect, when
    291327         the text contains control sequences for setting fonts.
    292 */
    293 void QwtText::setFont( const QFont &font )
    294 {
    295     d_data->font = font;
     328 */
     329void QwtText::setFont( const QFont& font )
     330{
     331    m_data->font = font;
    296332    setPaintAttribute( PaintUsingTextFont );
    297333}
    … …  
    300336QFont QwtText::font() const
    301337{
    302     return d_data->font;
     338    return m_data->font;
    303339}
    304340
    … …  
    311347
    312348   \sa setFont(), font(), PaintAttributes
    313 */
    314 QFont QwtText::usedFont( const QFont &defaultFont ) const
    315 {
    316     if ( d_data->paintAttributes & PaintUsingTextFont )
    317         return d_data->font;
     349 */
     350QFont QwtText::usedFont( const QFont& defaultFont ) const
     351{
     352    if ( m_data->paintAttributes & PaintUsingTextFont )
     353        return m_data->font;
    318354
    319355    return defaultFont;
    … …  
    326362   \note Setting the color might have no effect, when
    327363         the text contains control sequences for setting colors.
    328 */
    329 void QwtText::setColor( const QColor &color )
    330 {
    331     d_data->color = color;
     364 */
     365void QwtText::setColor( const QColor& color )
     366{
     367    m_data->color = color;
    332368    setPaintAttribute( PaintUsingTextColor );
    333369}
    … …  
    336372QColor QwtText::color() const
    337373{
    338     return d_data->color;
    339 }
    340 
    341 /*!
    342   Return the color of the text, if it has one.
    343   Otherwise return defaultColor.
    344 
    345   \param defaultColor Default color
    346   \return Color used for drawing the text
    347 
    348   \sa setColor(), color(), PaintAttributes
    349 */
    350 QColor QwtText::usedColor( const QColor &defaultColor ) const
    351 {
    352     if ( d_data->paintAttributes & PaintUsingTextColor )
    353         return d_data->color;
     374    return m_data->color;
     375}
     376
     377/*!
     378   Return the color of the text, if it has one.
     379   Otherwise return defaultColor.
     380
     381   \param defaultColor Default color
     382   \return Color used for drawing the text
     383
     384   \sa setColor(), color(), PaintAttributes
     385 */
     386QColor QwtText::usedColor( const QColor& defaultColor ) const
     387{
     388    if ( m_data->paintAttributes & PaintUsingTextColor )
     389        return m_data->color;
    354390
    355391    return defaultColor;
    … …  
    357393
    358394/*!
    359   Set the radius for the corners of the border frame
    360 
    361   \param radius Radius of a rounded corner
    362   \sa borderRadius(), setBorderPen(), setBackgroundBrush()
    363 */
     395   Set the radius for the corners of the border frame
     396
     397   \param radius Radius of a rounded corner
     398   \sa borderRadius(), setBorderPen(), setBackgroundBrush()
     399 */
    364400void QwtText::setBorderRadius( double radius )
    365401{
    366     d_data->borderRadius = qMax( 0.0, radius );
    367 }
    368 
    369 /*!
    370   \return Radius for the corners of the border frame
    371   \sa setBorderRadius(), borderPen(), backgroundBrush()
    372 */
     402    m_data->borderRadius = qwtMaxF( 0.0, radius );
     403}
     404
     405/*!
     406   \return Radius for the corners of the border frame
     407   \sa setBorderRadius(), borderPen(), backgroundBrush()
     408 */
    373409double QwtText::borderRadius() const
    374410{
    375     return d_data->borderRadius;
     411    return m_data->borderRadius;
    376412}
    377413
    … …  
    381417   \param pen Background pen
    382418   \sa borderPen(), setBackgroundBrush()
    383 */
    384 void QwtText::setBorderPen( const QPen &pen )
    385 {
    386     d_data->borderPen = pen;
     419 */
     420void QwtText::setBorderPen( const QPen& pen )
     421{
     422    m_data->borderPen = pen;
    387423    setPaintAttribute( PaintBackground );
    388424}
    … …  
    391427   \return Background pen
    392428   \sa setBorderPen(), backgroundBrush()
    393 */
     429 */
    394430QPen QwtText::borderPen() const
    395431{
    396     return d_data->borderPen;
     432    return m_data->borderPen;
    397433}
    398434
    … …  
    402438   \param brush Background brush
    403439   \sa backgroundBrush(), setBorderPen()
    404 */
    405 void QwtText::setBackgroundBrush( const QBrush &brush )
    406 {
    407     d_data->backgroundBrush = brush;
     440 */
     441void QwtText::setBackgroundBrush( const QBrush& brush )
     442{
     443    m_data->backgroundBrush = brush;
    408444    setPaintAttribute( PaintBackground );
    409445}
    … …  
    412448   \return Background brush
    413449   \sa setBackgroundBrush(), borderPen()
    414 */
     450 */
    415451QBrush QwtText::backgroundBrush() const
    416452{
    417     return d_data->backgroundBrush;
     453    return m_data->backgroundBrush;
    418454}
    419455
    … …  
    427463         setBorderPen() and setBackgroundBrush()
    428464   \sa testPaintAttribute()
    429 */
     465 */
    430466void QwtText::setPaintAttribute( PaintAttribute attribute, bool on )
    431467{
    432468    if ( on )
    433         d_data->paintAttributes |= attribute;
     469        m_data->paintAttributes |= attribute;
    434470    else
    435         d_data->paintAttributes &= ~attribute;
     471        m_data->paintAttributes &= ~attribute;
    436472}
    437473
    … …  
    443479
    444480   \sa setPaintAttribute()
    445 */
     481 */
    446482bool QwtText::testPaintAttribute( PaintAttribute attribute ) const
    447483{
    448     return d_data->paintAttributes & attribute;
     484    return m_data->paintAttributes & attribute;
    449485}
    450486
    … …  
    455491   \param on On/Off
    456492   \sa testLayoutAttribute()
    457 */
     493 */
    458494void QwtText::setLayoutAttribute( LayoutAttribute attribute, bool on )
    459495{
    460496    if ( on )
    461         d_data->layoutAttributes |= attribute;
     497        m_data->layoutAttributes |= attribute;
    462498    else
    463         d_data->layoutAttributes &= ~attribute;
     499        m_data->layoutAttributes &= ~attribute;
    464500}
    465501
    … …  
    471507
    472508   \sa setLayoutAttribute()
    473 */
     509 */
    474510bool QwtText::testLayoutAttribute( LayoutAttribute attribute ) const
    475511{
    476     return d_data->layoutAttributes | attribute;
     512    return m_data->layoutAttributes | attribute;
     513}
     514
     515/*!
     516   Find the height for a given width
     517
     518   \param width Width
     519   \return Calculated height
     520 */
     521
     522double QwtText::heightForWidth( double width ) const
     523{
     524    return heightForWidth( width, QFont() );
    477525}
    478526
    … …  
    484532
    485533   \return Calculated height
    486 */
    487 double QwtText::heightForWidth( double width, const QFont &defaultFont ) const
     534 */
     535double QwtText::heightForWidth( double width, const QFont& defaultFont ) const
    488536{
    489537    // We want to calculate in screen metrics. So
    490538    // we need a font that uses screen metrics
    491539
    492     const QFont font( usedFont( defaultFont ), QApplication::desktop() );
     540    const QFont font = QwtPainter::scaledFont( usedFont( defaultFont ) );
    493541
    494542    double h = 0;
    495543
    496     if ( d_data->layoutAttributes & MinimumLayout )
     544    if ( m_data->layoutAttributes & MinimumLayout )
    497545    {
    498546        double left, right, top, bottom;
    499         d_data->textEngine->textMargins( font, d_data->text,
     547        m_data->textEngine->textMargins( font, m_data->text,
    500548            left, right, top, bottom );
    501549
    502         h = d_data->textEngine->heightForWidth(
    503             font, d_data->renderFlags, d_data->text,
     550        h = m_data->textEngine->heightForWidth(
     551            font, m_data->renderFlags, m_data->text,
    504552            width + left + right );
    505553
    … …  
    508556    else
    509557    {
    510         h = d_data->textEngine->heightForWidth(
    511             font, d_data->renderFlags, d_data->text, width );
     558        h = m_data->textEngine->heightForWidth(
     559            font, m_data->renderFlags, m_data->text, width );
    512560    }
    513561
    514562    return h;
     563}
     564
     565/*!
     566   Returns the size, that is needed to render text
     567
     568   \return Calculated size
     569 */
     570QSizeF QwtText::textSize() const
     571{
     572    return textSize( QFont() );
    515573}
    516574
    … …  
    520578   \param defaultFont Font of the text
    521579   \return Calculated size
    522 */
    523 QSizeF QwtText::textSize( const QFont &defaultFont ) const
     580 */
     581QSizeF QwtText::textSize( const QFont& defaultFont ) const
    524582{
    525583    // We want to calculate in screen metrics. So
    526584    // we need a font that uses screen metrics
    527585
    528     const QFont font( usedFont( defaultFont ), QApplication::desktop() );
    529 
    530     if ( !d_layoutCache->textSize.isValid()
    531         || d_layoutCache->font != font )
    532     {
    533         d_layoutCache->textSize = d_data->textEngine->textSize(
    534             font, d_data->renderFlags, d_data->text );
    535         d_layoutCache->font = font;
    536     }
    537 
    538     QSizeF sz = d_layoutCache->textSize;
    539 
    540     if ( d_data->layoutAttributes & MinimumLayout )
     586    const QFont font = QwtPainter::scaledFont( usedFont( defaultFont ) );
     587
     588    if ( !m_layoutCache->textSize.isValid()
     589        || m_layoutCache->font != font )
     590    {
     591        m_layoutCache->textSize = m_data->textEngine->textSize(
     592            font, m_data->renderFlags, m_data->text );
     593        m_layoutCache->font = font;
     594    }
     595
     596    QSizeF sz = m_layoutCache->textSize;
     597
     598    if ( m_data->layoutAttributes & MinimumLayout )
    541599    {
    542600        double left, right, top, bottom;
    543         d_data->textEngine->textMargins( font, d_data->text,
     601        m_data->textEngine->textMargins( font, m_data->text,
    544602            left, right, top, bottom );
    545603        sz -= QSizeF( left + right, top + bottom );
    … …  
    554612   \param painter Painter
    555613   \param rect Rectangle
    556 */
    557 void QwtText::draw( QPainter *painter, const QRectF &rect ) const
    558 {
    559     if ( d_data->paintAttributes & PaintBackground )
    560     {
    561         if ( d_data->borderPen != Qt::NoPen ||
    562             d_data->backgroundBrush != Qt::NoBrush )
     614 */
     615void QwtText::draw( QPainter* painter, const QRectF& rect ) const
     616{
     617    if ( m_data->paintAttributes & PaintBackground )
     618    {
     619        if ( m_data->borderPen != Qt::NoPen ||
     620            m_data->backgroundBrush != Qt::NoBrush )
    563621        {
    564622            painter->save();
    565623
    566             painter->setPen( d_data->borderPen );
    567             painter->setBrush( d_data->backgroundBrush );
    568 
    569             if ( d_data->borderRadius == 0 )
     624            painter->setPen( m_data->borderPen );
     625            painter->setBrush( m_data->backgroundBrush );
     626
     627            if ( m_data->borderRadius == 0 )
    570628            {
    571629                QwtPainter::drawRect( painter, rect );
    … …  
    575633                painter->setRenderHint( QPainter::Antialiasing, true );
    576634                painter->drawRoundedRect( rect,
    577                     d_data->borderRadius, d_data->borderRadius );
     635                    m_data->borderRadius, m_data->borderRadius );
    578636            }
    579637
    … …  
    584642    painter->save();
    585643
    586     if ( d_data->paintAttributes & PaintUsingTextFont )
    587     {
    588         painter->setFont( d_data->font );
    589     }
    590 
    591     if ( d_data->paintAttributes & PaintUsingTextColor )
    592     {
    593         if ( d_data->color.isValid() )
    594             painter->setPen( d_data->color );
     644    if ( m_data->paintAttributes & PaintUsingTextFont )
     645    {
     646        painter->setFont( m_data->font );
     647    }
     648
     649    if ( m_data->paintAttributes & PaintUsingTextColor )
     650    {
     651        if ( m_data->color.isValid() )
     652            painter->setPen( m_data->color );
    595653    }
    596654
    597655    QRectF expandedRect = rect;
    598     if ( d_data->layoutAttributes & MinimumLayout )
     656    if ( m_data->layoutAttributes & MinimumLayout )
    599657    {
    600658        // We want to calculate in screen metrics. So
    601659        // we need a font that uses screen metrics
    602660
    603         const QFont font( painter->font(), QApplication::desktop() );
     661        const QFont font = QwtPainter::scaledFont( painter->font() );
    604662
    605663        double left, right, top, bottom;
    606         d_data->textEngine->textMargins(
    607             font, d_data->text, left, right, top, bottom );
     664        m_data->textEngine->textMargins(
     665            font, m_data->text, left, right, top, bottom );
    608666
    609667        expandedRect.setTop( rect.top() - top );
    … …  
    613671    }
    614672
    615     d_data->textEngine->draw( painter, expandedRect,
    616         d_data->renderFlags, d_data->text );
     673    m_data->textEngine->draw( painter, expandedRect,
     674        m_data->renderFlags, m_data->text );
    617675
    618676    painter->restore();
    … …  
    627685
    628686   If no text engine is registered for the format QwtPlainTextEngine
    629    is returnd.
     687   is returned.
    630688
    631689   \param text Text, needed in case of AutoText
    … …  
    633691
    634692   \return Corresponding text engine
    635 */
    636 const QwtTextEngine *QwtText::textEngine( const QString &text,
     693 */
     694const QwtTextEngine* QwtText::textEngine( const QString& text,
    637695    QwtText::TextFormat format )
    638696{
    639     return QwtTextEngineDict::dict().textEngine( text, format );
     697    return TextEngineDict::dict().textEngine( text, format );
    640698}
    641699
    … …  
    651709   \param engine Text engine
    652710
    653    \sa QwtMathMLTextEngine
    654711   \warning Using QwtText::AutoText does nothing.
    655 */
     712 */
    656713void QwtText::setTextEngine( QwtText::TextFormat format,
    657     QwtTextEngine *engine )
    658 {
    659     QwtTextEngineDict::dict().setTextEngine( format, engine );
     714    QwtTextEngine* engine )
     715{
     716    TextEngineDict::dict().setTextEngine( format, engine );
    660717}
    661718
    … …  
    667724   \param format Text format
    668725   \return The text engine, or NULL if no engine is available.
    669 */
    670 const QwtTextEngine *QwtText::textEngine( QwtText::TextFormat format )
    671 {
    672     return  QwtTextEngineDict::dict().textEngine( format );
    673 }
     726 */
     727const QwtTextEngine* QwtText::textEngine( QwtText::TextFormat format )
     728{
     729    return TextEngineDict::dict().textEngine( format );
     730}
     731
     732//! \return text().isNull()
     733bool QwtText::isNull() const
     734{
     735    return m_data->text.isNull();
     736}
     737
     738//! \return text().isEmpty()
     739bool QwtText::isEmpty() const
     740{
     741    return m_data->text.isEmpty();
     742}
     743
  • trunk/BNC/qwt/qwt_text.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include <qstring.h>
    15 #include <qsize.h>
    16 #include <qfont.h>
    1714#include <qmetatype.h>
    1815
     16class QFont;
     17class QString;
    1918class QColor;
    2019class QPen;
    2120class QBrush;
     21class QSizeF;
    2222class QRectF;
    2323class QPainter;
    … …  
    2525
    2626/*!
    27   \brief A class representing a text
    28 
    29   A QwtText is a text including a set of attributes how to render it.
    30 
    31   - Format\n
     27   \brief A class representing a text
     28
     29   A QwtText is a text including a set of attributes how to render it.
     30
     31   - Format\n
    3232    A text might include control sequences (f.e tags) describing
    3333    how to render it. Each format (f.e MathML, TeX, Qt Rich Text)
    3434    has its own set of control sequences, that can be handles by
    3535    a special QwtTextEngine for this format.
    36   - Background\n
     36   - Background\n
    3737    A text might have a background, defined by a QPen and QBrush
    3838    to improve its visibility. The corners of the background might
    3939    be rounded.
    40   - Font\n
     40   - Font\n
    4141    A text might have an individual font.
    42   - Color\n
     42   - Color\n
    4343    A text might have an individual color.
    44   - Render Flags\n
     44   - Render Flags\n
    4545    Flags from Qt::AlignmentFlag and Qt::TextFlag used like in
    4646    QPainter::drawText().
    4747
    48   \sa QwtTextEngine, QwtTextLabel
    49 */
     48   \sa QwtTextEngine, QwtTextLabel
     49 */
    5050
    5151class QWT_EXPORT QwtText
    5252{
    53 public:
     53  public:
    5454
    5555    /*!
    56       \brief Text format
    57 
    58       The text format defines the QwtTextEngine, that is used to render
    59       the text.
    60 
    61       \sa QwtTextEngine, setTextEngine()
    62     */
     56       \brief Text format
     57
     58       The text format defines the QwtTextEngine, that is used to render
     59       the text.
     60
     61       \sa QwtTextEngine, setTextEngine()
     62     */
    6363
    6464    enum TextFormat
    6565    {
    6666        /*!
    67           The text format is determined using QwtTextEngine::mightRender() for
    68           all available text engines in increasing order > PlainText.
    69           If none of the text engines can render the text is rendered
    70           like QwtText::PlainText.
     67           The text format is determined using QwtTextEngine::mightRender() for
     68           all available text engines in increasing order > PlainText.
     69           If none of the text engines can render the text is rendered
     70           like QwtText::PlainText.
    7171         */
    7272        AutoText = 0,
    … …  
    7979
    8080        /*!
    81           Use a MathML (http://en.wikipedia.org/wiki/MathML) render engine
    82           to display the text. The Qwt MathML extension offers such an engine
    83           based on the MathML renderer of the former Qt solutions package.
    84           To enable MathML support the following code needs to be added to the
    85           application:
    86 
    87           \code
     81           Use a MathML (http://en.wikipedia.org/wiki/MathML) render engine
     82           to display the text. In earlier versions of Qwt such an engine
     83           was included - since Qwt 6.2 it can be found here:
     84           https://github.com/uwerat/qwt-mml-dev
     85
     86           To enable MathML support the following code needs to be added to the
     87           application:
     88
     89           \code
    8890            QwtText::setTextEngine( QwtText::MathMLText, new QwtMathMLTextEngine() );
    89           \endcode
     91           \endcode
    9092         */
    9193        MathMLText,
    9294
    9395        /*!
    94           Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine
    95           to display the text ( not implemented yet ).
     96           Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine
     97           to display the text ( not implemented yet ).
    9698         */
    9799        TeXText,
    98100
    99101        /*!
    100           The number of text formats can be extended using setTextEngine.
    101           Formats >= QwtText::OtherFormat are not used by Qwt.
     102           The number of text formats can be extended using setTextEngine.
     103           Formats >= QwtText::OtherFormat are not used by Qwt.
    102104         */
    103105        OtherFormat = 100
    … …  
    105107
    106108    /*!
    107       \brief Paint Attributes
    108 
    109       Font and color and background are optional attributes of a QwtText.
    110       The paint attributes hold the information, if they are set.
    111     */
     109       \brief Paint Attributes
     110
     111       Font and color and background are optional attributes of a QwtText.
     112       The paint attributes hold the information, if they are set.
     113     */
    112114    enum PaintAttribute
    113115    {
    … …  
    122124    };
    123125
    124     //! Paint attributes
    125     typedef QFlags<PaintAttribute> PaintAttributes;
     126    Q_DECLARE_FLAGS( PaintAttributes, PaintAttribute )
    126127
    127128    /*!
    128       \brief Layout Attributes
    129       The layout attributes affects some aspects of the layout of the text.
    130     */
     129       \brief Layout Attributes
     130       The layout attributes affects some aspects of the layout of the text.
     131     */
    131132    enum LayoutAttribute
    132133    {
    133134        /*!
    134           Layout the text without its margins. This mode is useful if a
    135           text needs to be aligned accurately, like the tick labels of a scale.
    136           If QwtTextEngine::textMargins is not implemented for the format
    137           of the text, MinimumLayout has no effect.
     135           Layout the text without its margins. This mode is useful if a
     136           text needs to be aligned accurately, like the tick labels of a scale.
     137           If QwtTextEngine::textMargins is not implemented for the format
     138           of the text, MinimumLayout has no effect.
    138139         */
    139140        MinimumLayout = 0x01
    140141    };
    141142
    142     //! Layout attributes
    143     typedef QFlags<LayoutAttribute> LayoutAttributes;
    144 
    145     QwtText( const QString & = QString(),
    146              TextFormat textFormat = AutoText );
    147     QwtText( const QwtText & );
     143    Q_DECLARE_FLAGS( LayoutAttributes, LayoutAttribute )
     144
     145    QwtText();
     146    QwtText( const QString&, TextFormat textFormat = AutoText );
     147    QwtText( const QwtText& );
     148
    148149    ~QwtText();
    149150
    150     QwtText &operator=( const QwtText & );
    151 
    152     bool operator==( const QwtText & ) const;
    153     bool operator!=( const QwtText & ) const;
    154 
    155     void setText( const QString &,
     151    QwtText& operator=( const QwtText& );
     152
     153    bool operator==( const QwtText& ) const;
     154    bool operator!=( const QwtText& ) const;
     155
     156    void setText( const QString&,
    156157        QwtText::TextFormat textFormat = AutoText );
    157158    QString text() const;
    … …  
    160161    bool isEmpty() const;
    161162
    162     void setFont( const QFont & );
     163    void setFont( const QFont& );
    163164    QFont font() const;
    164165
    165     QFont usedFont( const QFont & ) const;
     166    QFont usedFont( const QFont& ) const;
    166167
    167168    void setRenderFlags( int );
    168169    int renderFlags() const;
    169170
    170     void setColor( const QColor & );
     171    void setColor( const QColor& );
    171172    QColor color() const;
    172173
    173     QColor usedColor( const QColor & ) const;
     174    QColor usedColor( const QColor& ) const;
    174175
    175176    void setBorderRadius( double );
    176177    double borderRadius() const;
    177178
    178     void setBorderPen( const QPen & );
     179    void setBorderPen( const QPen& );
    179180    QPen borderPen() const;
    180181
    181     void setBackgroundBrush( const QBrush & );
     182    void setBackgroundBrush( const QBrush& );
    182183    QBrush backgroundBrush() const;
    183184
    … …  
    188189    bool testLayoutAttribute( LayoutAttribute ) const;
    189190
    190     double heightForWidth( double width, const QFont & = QFont() ) const;
    191     QSizeF textSize( const QFont & = QFont() ) const;
    192 
    193     void draw( QPainter *painter, const QRectF &rect ) const;
    194 
    195     static const QwtTextEngine *textEngine(
    196         const QString &text, QwtText::TextFormat = AutoText );
    197 
    198     static const QwtTextEngine *textEngine( QwtText::TextFormat );
    199     static void setTextEngine( QwtText::TextFormat, QwtTextEngine * );
    200 
    201 private:
     191    double heightForWidth( double width ) const;
     192    double heightForWidth( double width, const QFont& ) const;
     193
     194    QSizeF textSize() const;
     195    QSizeF textSize( const QFont& ) const;
     196
     197    void draw( QPainter* painter, const QRectF& rect ) const;
     198
     199    static const QwtTextEngine* textEngine(
     200        const QString& text, QwtText::TextFormat = AutoText );
     201
     202    static const QwtTextEngine* textEngine( QwtText::TextFormat );
     203    static void setTextEngine( QwtText::TextFormat, QwtTextEngine* );
     204
     205  private:
    202206    class PrivateData;
    203     PrivateData *d_data;
     207    PrivateData* m_data;
    204208
    205209    class LayoutCache;
    206     LayoutCache *d_layoutCache;
     210    LayoutCache* m_layoutCache;
    207211};
    208 
    209 //! \return text().isNull()
    210 inline bool QwtText::isNull() const
    211 {
    212     return text().isNull();
    213 }
    214 
    215 //! \return text().isEmpty()
    216 inline bool QwtText::isEmpty() const
    217 {
    218     return text().isEmpty();
    219 }
    220212
    221213Q_DECLARE_OPERATORS_FOR_FLAGS( QwtText::PaintAttributes )
  • trunk/BNC/qwt/qwt_text_engine.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_text_engine.h"
    11 #include "qwt_math.h"
    1211#include "qwt_painter.h"
     12
    1313#include <qpainter.h>
    1414#include <qpixmap.h>
    … …  
    2020#include <qabstracttextdocumentlayout.h>
    2121
    22 static QString taggedRichText( const QString &text, int flags )
     22static QString taggedRichText( const QString& text, int flags )
    2323{
    2424    QString richText = text;
    … …  
    2727    if ( flags & Qt::AlignJustify )
    2828    {
    29         richText.prepend( QString::fromLatin1( "<div align=\"justify\">" ) );
    30         richText.append( QString::fromLatin1( "</div>" ) );
     29        richText.prepend( QLatin1String( "<div align=\"justify\">" ) );
     30        richText.append( QLatin1String ( "</div>" ) );
    3131    }
    3232    else if ( flags & Qt::AlignRight )
    3333    {
    34         richText.prepend( QString::fromLatin1( "<div align=\"right\">" ) );
    35         richText.append( QString::fromLatin1( "</div>" ) );
     34        richText.prepend( QLatin1String ( "<div align=\"right\">" ) );
     35        richText.append( QLatin1String ( "</div>" ) );
    3636    }
    3737    else if ( flags & Qt::AlignHCenter )
    3838    {
    39         richText.prepend( QString::fromLatin1( "<div align=\"center\">" ) );
    40         richText.append( QString::fromLatin1( "</div>" ) );
     39        richText.prepend( QLatin1String ( "<div align=\"center\">" ) );
     40        richText.append( QLatin1String ( "</div>" ) );
    4141    }
    4242
    … …  
    4444}
    4545
    46 class QwtRichTextDocument: public QTextDocument
    47 {
    48 public:
    49     QwtRichTextDocument( const QString &text, int flags, const QFont &font )
    50     {
    51         setUndoRedoEnabled( false );
    52         setDefaultFont( font );
    53         setHtml( text );
    54 
    55         // make sure we have a document layout
    56         ( void )documentLayout();
    57 
    58         QTextOption option = defaultTextOption();
    59         if ( flags & Qt::TextWordWrap )
    60             option.setWrapMode( QTextOption::WordWrap );
    61         else
    62             option.setWrapMode( QTextOption::NoWrap );
    63 
    64         option.setAlignment( static_cast<Qt::Alignment>( flags ) );
    65         setDefaultTextOption( option );
    66 
    67         QTextFrame *root = rootFrame();
    68         QTextFrameFormat fm = root->frameFormat();
    69         fm.setBorder( 0 );
    70         fm.setMargin( 0 );
    71         fm.setPadding( 0 );
    72         fm.setBottomMargin( 0 );
    73         fm.setLeftMargin( 0 );
    74         root->setFrameFormat( fm );
    75 
    76         adjustSize();
    77     }
    78 };
     46namespace
     47{
     48    class QwtRichTextDocument : public QTextDocument
     49    {
     50      public:
     51        QwtRichTextDocument( const QString& text, int flags, const QFont& font )
     52        {
     53            setUndoRedoEnabled( false );
     54            setDefaultFont( font );
     55            setHtml( text );
     56
     57            // make sure we have a document layout
     58            ( void )documentLayout();
     59
     60            QTextOption option = defaultTextOption();
     61            if ( flags & Qt::TextWordWrap )
     62                option.setWrapMode( QTextOption::WordWrap );
     63            else
     64                option.setWrapMode( QTextOption::NoWrap );
     65
     66            option.setAlignment( static_cast< Qt::Alignment >( flags ) );
     67            setDefaultTextOption( option );
     68
     69            QTextFrame* root = rootFrame();
     70            QTextFrameFormat fm = root->frameFormat();
     71            fm.setBorder( 0 );
     72            fm.setMargin( 0 );
     73            fm.setPadding( 0 );
     74            fm.setBottomMargin( 0 );
     75            fm.setLeftMargin( 0 );
     76            root->setFrameFormat( fm );
     77
     78            adjustSize();
     79        }
     80    };
     81}
    7982
    8083class QwtPlainTextEngine::PrivateData
    8184{
    82 public:
    83     int effectiveAscent( const QFont &font ) const
     85  public:
     86    int effectiveAscent( const QFont& font ) const
    8487    {
    8588        const QString fontKey = font.key();
    8689
    87         QMap<QString, int>::const_iterator it =
    88             d_ascentCache.constFind( fontKey );
    89 
    90         if ( it != d_ascentCache.constEnd() )
     90        QMap< QString, int >::const_iterator it =
     91            m_ascentCache.constFind( fontKey );
     92
     93        if ( it != m_ascentCache.constEnd() )
    9194            return *it;
    9295
    9396        const int ascent = findAscent( font );
    94         d_ascentCache.insert( fontKey, ascent );
     97        m_ascentCache.insert( fontKey, ascent );
    9598
    9699        return ascent;
    97100    }
    98101
    99 private:
    100     int findAscent( const QFont &font ) const
     102  private:
     103    static int findAscent( const QFont& font )
    101104    {
    102105        static const QString dummy( "E" );
    … …  
    104107
    105108        const QFontMetrics fm( font );
    106         QPixmap pm( fm.width( dummy ), fm.height() );
     109
     110        QPixmap pm( QwtPainter::horizontalAdvance( fm, dummy ), fm.height() );
    107111        pm.fill( white );
    108112
    … …  
    117121        for ( row = 0; row < img.height(); row++ )
    118122        {
    119             const QRgb *line = reinterpret_cast<const QRgb *>(
     123            const QRgb* line = reinterpret_cast< const QRgb* >(
    120124                img.scanLine( row ) );
    121125
    … …  
    131135    }
    132136
    133     mutable QMap<QString, int> d_ascentCache;
     137    mutable QMap< QString, int > m_ascentCache;
    134138};
    135139
    … …  
    147151QwtPlainTextEngine::QwtPlainTextEngine()
    148152{
    149     d_data = new PrivateData;
     153    m_data = new PrivateData;
    150154}
    151155
    … …  
    153157QwtPlainTextEngine::~QwtPlainTextEngine()
    154158{
    155     delete d_data;
     159    delete m_data;
    156160}
    157161
    … …  
    165169
    166170   \return Calculated height
    167 */
     171 */
    168172double QwtPlainTextEngine::heightForWidth( const QFont& font, int flags,
    169         const QString& text, double width ) const
     173    const QString& text, double width ) const
    170174{
    171175    const QFontMetricsF fm( font );
    … …  
    177181
    178182/*!
    179   Returns the size, that is needed to render text
    180 
    181   \param font Font of the text
    182   \param flags Bitwise OR of the flags used like in QPainter::drawText
    183   \param text Text to be rendered
    184 
    185   \return Calculated size
    186 */
    187 QSizeF QwtPlainTextEngine::textSize( const QFont &font,
     183   Returns the size, that is needed to render text
     184
     185   \param font Font of the text
     186   \param flags Bitwise OR of the flags used like in QPainter::drawText
     187   \param text Text to be rendered
     188
     189   \return Calculated size
     190 */
     191QSizeF QwtPlainTextEngine::textSize( const QFont& font,
    188192    int flags, const QString& text ) const
    189193{
    … …  
    196200
    197201/*!
    198   Return margins around the texts
    199 
    200   \param font Font of the text
    201   \param left Return 0
    202   \param right Return 0
    203   \param top Return value for the top margin
    204   \param bottom Return value for the bottom margin
    205 */
    206 void QwtPlainTextEngine::textMargins( const QFont &font, const QString &,
    207     double &left, double &right, double &top, double &bottom ) const
     202   Return margins around the texts
     203
     204   \param font Font of the text
     205   \param left Return 0
     206   \param right Return 0
     207   \param top Return value for the top margin
     208   \param bottom Return value for the bottom margin
     209 */
     210void QwtPlainTextEngine::textMargins( const QFont& font, const QString&,
     211    double& left, double& right, double& top, double& bottom ) const
    208212{
    209213    left = right = top = 0;
    210214
    211215    const QFontMetricsF fm( font );
    212     top = fm.ascent() - d_data->effectiveAscent( font );
     216    top = fm.ascent() - m_data->effectiveAscent( font );
    213217    bottom = fm.descent();
    214218}
    215219
    216220/*!
    217   \brief Draw the text in a clipping rectangle
    218 
    219   A wrapper for QPainter::drawText.
    220 
    221   \param painter Painter
    222   \param rect Clipping rectangle
    223   \param flags Bitwise OR of the flags used like in QPainter::drawText
    224   \param text Text to be rendered
    225 */
    226 void QwtPlainTextEngine::draw( QPainter *painter, const QRectF &rect,
     221   \brief Draw the text in a clipping rectangle
     222
     223   A wrapper for QPainter::drawText.
     224
     225   \param painter Painter
     226   \param rect Clipping rectangle
     227   \param flags Bitwise OR of the flags used like in QPainter::drawText
     228   \param text Text to be rendered
     229 */
     230void QwtPlainTextEngine::draw( QPainter* painter, const QRectF& rect,
    227231    int flags, const QString& text ) const
    228232{
    … …  
    231235
    232236/*!
    233   Test if a string can be rendered by this text engine.
    234   \return Always true. All texts can be rendered by QwtPlainTextEngine
    235 */
    236 bool QwtPlainTextEngine::mightRender( const QString & ) const
     237   Test if a string can be rendered by this text engine.
     238   \return Always true. All texts can be rendered by QwtPlainTextEngine
     239 */
     240bool QwtPlainTextEngine::mightRender( const QString& ) const
    237241{
    238242    return true;
    … …  
    255259
    256260   \return Calculated height
    257 */
     261 */
    258262double QwtRichTextEngine::heightForWidth( const QFont& font, int flags,
    259         const QString& text, double width ) const
     263    const QString& text, double width ) const
    260264{
    261265    QwtRichTextDocument doc( text, flags, font );
    … …  
    266270
    267271/*!
    268   Returns the size, that is needed to render text
    269 
    270   \param font Font of the text
    271   \param flags Bitwise OR of the flags used like in QPainter::drawText()
    272   \param text Text to be rendered
    273 
    274   \return Calculated size
    275 */
    276 
    277 QSizeF QwtRichTextEngine::textSize( const QFont &font,
     272   Returns the size, that is needed to render text
     273
     274   \param font Font of the text
     275   \param flags Bitwise OR of the flags used like in QPainter::drawText()
     276   \param text Text to be rendered
     277
     278   \return Calculated size
     279 */
     280
     281QSizeF QwtRichTextEngine::textSize( const QFont& font,
    278282    int flags, const QString& text ) const
    279283{
    … …  
    292296
    293297/*!
    294   Draw the text in a clipping rectangle
    295 
    296   \param painter Painter
    297   \param rect Clipping rectangle
    298   \param flags Bitwise OR of the flags like in for QPainter::drawText()
    299   \param text Text to be rendered
    300 */
    301 void QwtRichTextEngine::draw( QPainter *painter, const QRectF &rect,
     298   Draw the text in a clipping rectangle
     299
     300   \param painter Painter
     301   \param rect Clipping rectangle
     302   \param flags Bitwise OR of the flags like in for QPainter::drawText()
     303   \param text Text to be rendered
     304 */
     305void QwtRichTextEngine::draw( QPainter* painter, const QRectF& rect,
    302306    int flags, const QString& text ) const
    303307{
    … …  
    313317
    314318   \return Tagged text
    315 */
    316 QString QwtRichTextEngine::taggedText( const QString &text, int flags ) const
     319 */
     320QString QwtRichTextEngine::taggedText( const QString& text, int flags ) const
    317321{
    318322    return taggedRichText( text, flags );
    … …  
    320324
    321325/*!
    322   Test if a string can be rendered by this text engine
    323 
    324   \param text Text to be tested
    325   \return Qt::mightBeRichText(text);
    326 */
    327 bool QwtRichTextEngine::mightRender( const QString &text ) const
     326   Test if a string can be rendered by this text engine
     327
     328   \param text Text to be tested
     329   \return Qt::mightBeRichText(text);
     330 */
     331bool QwtRichTextEngine::mightRender( const QString& text ) const
    328332{
    329333    return Qt::mightBeRichText( text );
    … …  
    331335
    332336/*!
    333   Return margins around the texts
    334 
    335   \param left Return 0
    336   \param right Return 0
    337   \param top Return 0
    338   \param bottom Return 0
    339 */
    340 void QwtRichTextEngine::textMargins( const QFont &, const QString &,
    341     double &left, double &right, double &top, double &bottom ) const
     337   Return margins around the texts
     338
     339   \param left Return 0
     340   \param right Return 0
     341   \param top Return 0
     342   \param bottom Return 0
     343 */
     344void QwtRichTextEngine::textMargins( const QFont&, const QString&,
     345    double& left, double& right, double& top, double& bottom ) const
    342346{
    343347    left = right = top = bottom = 0;
  • trunk/BNC/qwt/qwt_text_engine.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#ifndef QWT_TEXT_ENGINE_H
    11 #define QWT_TEXT_ENGINE_H 1
     11#define QWT_TEXT_ENGINE_H
    1212
    1313#include "qwt_global.h"
    … …  
    2020
    2121/*!
    22   \brief Abstract base class for rendering text strings
     22   \brief Abstract base class for rendering text strings
    2323
    24   A text engine is responsible for rendering texts for a
    25   specific text format. They are used by QwtText to render a text.
     24   A text engine is responsible for rendering texts for a
     25   specific text format. They are used by QwtText to render a text.
    2626
    27   QwtPlainTextEngine and QwtRichTextEngine are part of the Qwt library.
    28   The implementation of QwtMathMLTextEngine uses code from the
    29   Qt solution package. Because of license implications it is built into
    30   a separate library.
    31 
    32   \sa QwtText::setTextEngine()
    33 */
     27   \sa QwtText::setTextEngine()
     28 */
    3429
    3530class QWT_EXPORT QwtTextEngine
    3631{
    37 public:
     32  public:
    3833    virtual ~QwtTextEngine();
    3934
    4035    /*!
    41       Find the height for a given width
     36       Find the height for a given width
    4237
    43       \param font Font of the text
    44       \param flags Bitwise OR of the flags used like in QPainter::drawText
    45       \param text Text to be rendered
    46       \param width Width
     38       \param font Font of the text
     39       \param flags Bitwise OR of the flags used like in QPainter::drawText
     40       \param text Text to be rendered
     41       \param width Width
    4742
    48       \return Calculated height
     43       \return Calculated height
    4944     */
    50     virtual double heightForWidth( const QFont &font, int flags,
    51         const QString &text, double width ) const = 0;
     45    virtual double heightForWidth( const QFont& font, int flags,
     46        const QString& text, double width ) const = 0;
    5247
    5348    /*!
    54       Returns the size, that is needed to render text
     49       Returns the size, that is needed to render text
    5550
    56       \param font Font of the text
    57       \param flags Bitwise OR of the flags like in for QPainter::drawText
    58       \param text Text to be rendered
     51       \param font Font of the text
     52       \param flags Bitwise OR of the flags like in for QPainter::drawText
     53       \param text Text to be rendered
    5954
    60       \return Calculated size
     55       \return Calculated size
    6156     */
    62     virtual QSizeF textSize( const QFont &font, int flags,
    63         const QString &text ) const = 0;
     57    virtual QSizeF textSize( const QFont& font, int flags,
     58        const QString& text ) const = 0;
    6459
    6560    /*!
    66       Test if a string can be rendered by this text engine
     61       Test if a string can be rendered by this text engine
    6762
    68       \param text Text to be tested
    69       \return true, if it can be rendered
     63       \param text Text to be tested
     64       \return true, if it can be rendered
    7065     */
    71     virtual bool mightRender( const QString &text ) const = 0;
     66    virtual bool mightRender( const QString& text ) const = 0;
    7267
    7368    /*!
    74       Return margins around the texts
     69       Return margins around the texts
    7570
    76       The textSize might include margins around the
    77       text, like QFontMetrics::descent(). In situations
    78       where texts need to be aligned in detail, knowing
    79       these margins might improve the layout calculations.
     71       The textSize might include margins around the
     72       text, like QFontMetrics::descent(). In situations
     73       where texts need to be aligned in detail, knowing
     74       these margins might improve the layout calculations.
    8075
    81       \param font Font of the text
    82       \param text Text to be rendered
    83       \param left Return value for the left margin
    84       \param right Return value for the right margin
    85       \param top Return value for the top margin
    86       \param bottom Return value for the bottom margin
     76       \param font Font of the text
     77       \param text Text to be rendered
     78       \param left Return value for the left margin
     79       \param right Return value for the right margin
     80       \param top Return value for the top margin
     81       \param bottom Return value for the bottom margin
    8782     */
    88     virtual void textMargins( const QFont &font, const QString &text,
    89         double &left, double &right, double &top, double &bottom ) const = 0;
     83    virtual void textMargins( const QFont& font, const QString& text,
     84        double& left, double& right, double& top, double& bottom ) const = 0;
    9085
    9186    /*!
    92       Draw the text in a clipping rectangle
     87       Draw the text in a clipping rectangle
    9388
    94       \param painter Painter
    95       \param rect Clipping rectangle
    96       \param flags Bitwise OR of the flags like in for QPainter::drawText()
    97       \param text Text to be rendered
     89       \param painter Painter
     90       \param rect Clipping rectangle
     91       \param flags Bitwise OR of the flags like in for QPainter::drawText()
     92       \param text Text to be rendered
    9893     */
    99     virtual void draw( QPainter *painter, const QRectF &rect,
    100         int flags, const QString &text ) const = 0;
     94    virtual void draw( QPainter* painter, const QRectF& rect,
     95        int flags, const QString& text ) const = 0;
    10196
    102 protected:
     97  protected:
    10398    QwtTextEngine();
     99
     100  private:
     101    Q_DISABLE_COPY(QwtTextEngine)
    104102};
    105103
    106104
    107105/*!
    108   \brief A text engine for plain texts
     106   \brief A text engine for plain texts
    109107
    110   QwtPlainTextEngine renders texts using the basic Qt classes
    111   QPainter and QFontMetrics.
    112 */
    113 class QWT_EXPORT QwtPlainTextEngine: public QwtTextEngine
     108   QwtPlainTextEngine renders texts using the basic Qt classes
     109   QPainter and QFontMetrics.
     110 */
     111class QWT_EXPORT QwtPlainTextEngine : public QwtTextEngine
    114112{
    115 public:
     113  public:
    116114    QwtPlainTextEngine();
    117115    virtual ~QwtPlainTextEngine();
    118116
    119     virtual double heightForWidth( const QFont &font, int flags,
    120         const QString &text, double width ) const;
     117    virtual double heightForWidth( const QFont& font, int flags,
     118        const QString& text, double width ) const QWT_OVERRIDE;
    121119
    122     virtual QSizeF textSize( const QFont &font, int flags,
    123         const QString &text ) const;
     120    virtual QSizeF textSize( const QFont& font, int flags,
     121        const QString& text ) const QWT_OVERRIDE;
    124122
    125     virtual void draw( QPainter *painter, const QRectF &rect,
    126         int flags, const QString &text ) const;
     123    virtual void draw( QPainter*, const QRectF& rect,
     124        int flags, const QString& text ) const QWT_OVERRIDE;
    127125
    128     virtual bool mightRender( const QString & ) const;
     126    virtual bool mightRender( const QString& ) const QWT_OVERRIDE;
    129127
    130     virtual void textMargins( const QFont &, const QString &,
    131         double &left, double &right, double &top, double &bottom ) const;
     128    virtual void textMargins(
     129        const QFont&, const QString&,
     130        double& left, double& right,
     131        double& top, double& bottom ) const QWT_OVERRIDE;
    132132
    133 private:
     133  private:
    134134    class PrivateData;
    135     PrivateData *d_data;
     135    PrivateData* m_data;
    136136};
    137137
    … …  
    140140
    141141/*!
    142   \brief A text engine for Qt rich texts
     142   \brief A text engine for Qt rich texts
    143143
    144   QwtRichTextEngine renders Qt rich texts using the classes
    145   of the Scribe framework of Qt.
    146 */
    147 class QWT_EXPORT QwtRichTextEngine: public QwtTextEngine
     144   QwtRichTextEngine renders Qt rich texts using the classes
     145   of the Scribe framework of Qt.
     146 */
     147class QWT_EXPORT QwtRichTextEngine : public QwtTextEngine
    148148{
    149 public:
     149  public:
    150150    QwtRichTextEngine();
    151151
    152     virtual double heightForWidth( const QFont &font, int flags,
    153         const QString &text, double width ) const;
     152    virtual double heightForWidth( const QFont& font, int flags,
     153        const QString& text, double width ) const QWT_OVERRIDE;
    154154
    155     virtual QSizeF textSize( const QFont &font, int flags,
    156         const QString &text ) const;
     155    virtual QSizeF textSize( const QFont& font, int flags,
     156        const QString& text ) const QWT_OVERRIDE;
    157157
    158     virtual void draw( QPainter *painter, const QRectF &rect,
    159         int flags, const QString &text ) const;
     158    virtual void draw( QPainter*, const QRectF& rect,
     159        int flags, const QString& text ) const QWT_OVERRIDE;
    160160
    161     virtual bool mightRender( const QString & ) const;
     161    virtual bool mightRender( const QString& ) const QWT_OVERRIDE;
    162162
    163     virtual void textMargins( const QFont &, const QString &,
    164         double &left, double &right, double &top, double &bottom ) const;
     163    virtual void textMargins(
     164        const QFont&, const QString&,
     165        double& left, double& right,
     166        double& top, double& bottom ) const QWT_OVERRIDE;
    165167
    166 private:
    167     QString taggedText( const QString &, int flags ) const;
     168  private:
     169    QString taggedText( const QString&, int flags ) const;
    168170};
    169171
  • trunk/BNC/qwt/qwt_text_label.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_text.h"
    1212#include "qwt_painter.h"
     13#include "qwt_math.h"
     14
     15#include <qstyle.h>
     16#include <qstyleoption.h>
    1317#include <qpainter.h>
    1418#include <qevent.h>
    15 #include <qmath.h>
     19#include <qmargins.h>
    1620
    1721class QwtTextLabel::PrivateData
    1822{
    19 public:
    20     PrivateData():
    21         indent( 4 ),
    22         margin( 0 )
     23  public:
     24    PrivateData()
     25        : indent( 4 )
     26        , margin( 0 )
    2327    {
    2428    }
    … …  
    3034
    3135/*!
    32   Constructs an empty label.
    33   \param parent Parent widget
    34 */
    35 QwtTextLabel::QwtTextLabel( QWidget *parent ):
    36     QFrame( parent )
     36   Constructs an empty label.
     37   \param parent Parent widget
     38 */
     39QwtTextLabel::QwtTextLabel( QWidget* parent )
     40    : QFrame( parent )
    3741{
    3842    init();
    … …  
    4044
    4145/*!
    42   Constructs a label that displays the text, text
    43   \param parent Parent widget
    44   \param text Text
    45 */
    46 QwtTextLabel::QwtTextLabel( const QwtText &text, QWidget *parent ):
    47     QFrame( parent )
     46   Constructs a label that displays the text, text
     47   \param parent Parent widget
     48   \param text Text
     49 */
     50QwtTextLabel::QwtTextLabel( const QwtText& text, QWidget* parent )
     51    : QFrame( parent )
    4852{
    4953    init();
    50     d_data->text = text;
     54    m_data->text = text;
    5155}
    5256
    … …  
    5458QwtTextLabel::~QwtTextLabel()
    5559{
    56     delete d_data;
     60    delete m_data;
    5761}
    5862
    5963void QwtTextLabel::init()
    6064{
    61     d_data = new PrivateData();
     65    m_data = new PrivateData();
    6266    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
    6367}
    … …  
    6771   \sa plainText()
    6872 */
    69 void QwtTextLabel::setPlainText( const QString &text )
     73void QwtTextLabel::setPlainText( const QString& text )
    7074{
    7175    setText( QwtText( text ) );
    … …  
    8084QString QwtTextLabel::plainText() const
    8185{
    82     return d_data->text.text();
     86    return m_data->text.text();
    8387}
    8488
    … …  
    8892   \param textFormat Format of text
    8993
    90   \sa QwtText
    91 */
    92 void QwtTextLabel::setText( const QString &text,
     94   \sa QwtText
     95 */
     96void QwtTextLabel::setText( const QString& text,
    9397    QwtText::TextFormat textFormat )
    9498{
    95     d_data->text.setText( text, textFormat );
     99    m_data->text.setText( text, textFormat );
    96100
    97101    update();
    … …  
    102106   Change the label's text
    103107   \param text New text
    104 */
    105 void QwtTextLabel::setText( const QwtText &text )
    106 {
    107     d_data->text = text;
     108 */
     109void QwtTextLabel::setText( const QwtText& text )
     110{
     111    m_data->text = text;
    108112
    109113    update();
    … …  
    112116
    113117//! Return the text
    114 const QwtText &QwtTextLabel::text() const
    115 {
    116     return d_data->text;
     118const QwtText& QwtTextLabel::text() const
     119{
     120    return m_data->text;
    117121}
    118122
    … …  
    120124void QwtTextLabel::clear()
    121125{
    122     d_data->text = QwtText();
     126    m_data->text = QwtText();
    123127
    124128    update();
    … …  
    129133int QwtTextLabel::indent() const
    130134{
    131     return d_data->indent;
    132 }
    133 
    134 /*!
    135   Set label's text indent in pixels
    136   \param indent Indentation in pixels
    137 */
     135    return m_data->indent;
     136}
     137
     138/*!
     139   Set label's text indent in pixels
     140   \param indent Indentation in pixels
     141 */
    138142void QwtTextLabel::setIndent( int indent )
    139143{
    … …  
    141145        indent = 0;
    142146
    143     d_data->indent = indent;
     147    m_data->indent = indent;
    144148
    145149    update();
    … …  
    150154int QwtTextLabel::margin() const
    151155{
    152     return d_data->margin;
    153 }
    154 
    155 /*!
    156   Set label's margin in pixels
    157   \param margin Margin in pixels
    158 */
     156    return m_data->margin;
     157}
     158
     159/*!
     160   Set label's margin in pixels
     161   \param margin Margin in pixels
     162 */
    159163void QwtTextLabel::setMargin( int margin )
    160164{
    161     d_data->margin = margin;
     165    m_data->margin = margin;
    162166
    163167    update();
    … …  
    174178QSize QwtTextLabel::minimumSizeHint() const
    175179{
    176     QSizeF sz = d_data->text.textSize( font() );
    177 
    178     int mw = 2 * ( frameWidth() + d_data->margin );
    179     int mh = mw;
    180 
    181     int indent = d_data->indent;
     180    QSizeF sz = m_data->text.textSize( font() );
     181
     182    const QMargins m = contentsMargins();
     183
     184    int mw = m.left() + m.right() + 2 * m_data->margin;
     185    int mh = m.top() + m.bottom() + 2 * m_data->margin;
     186
     187    int indent = m_data->indent;
    182188    if ( indent <= 0 )
    183189        indent = defaultIndent();
    … …  
    185191    if ( indent > 0 )
    186192    {
    187         const int align = d_data->text.renderFlags();
     193        const int align = m_data->text.renderFlags();
    188194        if ( align & Qt::AlignLeft || align & Qt::AlignRight )
    189             mw += d_data->indent;
     195            mw += m_data->indent;
    190196        else if ( align & Qt::AlignTop || align & Qt::AlignBottom )
    191             mh += d_data->indent;
     197            mh += m_data->indent;
    192198    }
    193199
    194200    sz += QSizeF( mw, mh );
    195201
    196     return QSize( qCeil( sz.width() ), qCeil( sz.height() ) );
     202    return QSize( qwtCeil( sz.width() ), qwtCeil( sz.height() ) );
    197203}
    198204
    … …  
    200206   \param width Width
    201207   \return Preferred height for this widget, given the width.
    202 */
     208 */
    203209int QwtTextLabel::heightForWidth( int width ) const
    204210{
    205     const int renderFlags = d_data->text.renderFlags();
    206 
    207     int indent = d_data->indent;
     211    const int renderFlags = m_data->text.renderFlags();
     212
     213    int indent = m_data->indent;
    208214    if ( indent <= 0 )
    209215        indent = defaultIndent();
    210216
    211     width -= 2 * frameWidth();
     217    const QMargins m = contentsMargins();
     218
     219    width -= m.left() + m.right() - 2 * m_data->margin;
    212220    if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight )
    213221        width -= indent;
    214222
    215     int height = qCeil( d_data->text.heightForWidth( width, font() ) );
     223    int height = qwtCeil( m_data->text.heightForWidth( width, font() ) );
    216224    if ( ( renderFlags & Qt::AlignTop ) || ( renderFlags & Qt::AlignBottom ) )
    217225        height += indent;
    218226
    219     height += 2 * frameWidth();
     227    height += m.top() + m.bottom() + 2 * m_data->margin;
    220228
    221229    return height;
    … …  
    225233   Qt paint event
    226234   \param event Paint event
    227 */
    228 void QwtTextLabel::paintEvent( QPaintEvent *event )
     235 */
     236void QwtTextLabel::paintEvent( QPaintEvent* event )
    229237{
    230238    QPainter painter( this );
     239    painter.setClipRegion( event->region() );
     240
     241    QStyleOption opt;
     242    opt.initFrom(this);
     243    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
    231244
    232245    if ( !contentsRect().contains( event->rect() ) )
    233246    {
    234         painter.save();
    235247        painter.setClipRegion( event->region() & frameRect() );
    236248        drawFrame( &painter );
    237         painter.restore();
    238249    }
    239250
    … …  
    244255
    245256//! Redraw the text and focus indicator
    246 void QwtTextLabel::drawContents( QPainter *painter )
     257void QwtTextLabel::drawContents( QPainter* painter )
    247258{
    248259    const QRect r = textRect();
    … …  
    266277
    267278//! Redraw the text
    268 void QwtTextLabel::drawText( QPainter *painter, const QRectF &textRect )
    269 {
    270     d_data->text.draw( painter, textRect );
    271 }
    272 
    273 /*!
    274   Calculate geometry for the text in widget coordinates
    275   \return Geometry for the text
    276 */
     279void QwtTextLabel::drawText( QPainter* painter, const QRectF& textRect )
     280{
     281    m_data->text.draw( painter, textRect );
     282}
     283
     284/*!
     285   Calculate geometry for the text in widget coordinates
     286   \return Geometry for the text
     287 */
    277288QRect QwtTextLabel::textRect() const
    278289{
    279290    QRect r = contentsRect();
    280291
    281     if ( !r.isEmpty() && d_data->margin > 0 )
    282     {
    283         r.setRect( r.x() + d_data->margin, r.y() + d_data->margin,
    284             r.width() - 2 * d_data->margin, r.height() - 2 * d_data->margin );
     292    if ( !r.isEmpty() && m_data->margin > 0 )
     293    {
     294        const int m = m_data->margin;
     295        r.adjust( m, m, -m, -m );
    285296    }
    286297
    287298    if ( !r.isEmpty() )
    288299    {
    289         int indent = d_data->indent;
     300        int indent = m_data->indent;
    290301        if ( indent <= 0 )
    291302            indent = defaultIndent();
    … …  
    293304        if ( indent > 0 )
    294305        {
    295             const int renderFlags = d_data->text.renderFlags();
     306            const int renderFlags = m_data->text.renderFlags();
    296307
    297308            if ( renderFlags & Qt::AlignLeft )
     309            {
    298310                r.setX( r.x() + indent );
     311            }
    299312            else if ( renderFlags & Qt::AlignRight )
     313            {
    300314                r.setWidth( r.width() - indent );
     315            }
    301316            else if ( renderFlags & Qt::AlignTop )
     317            {
    302318                r.setY( r.y() + indent );
     319            }
    303320            else if ( renderFlags & Qt::AlignBottom )
     321            {
    304322                r.setHeight( r.height() - indent );
     323            }
    305324        }
    306325    }
    … …  
    315334
    316335    QFont fnt;
    317     if ( d_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) )
    318         fnt = d_data->text.font();
     336    if ( m_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) )
     337        fnt = m_data->text.font();
    319338    else
    320339        fnt = font();
    321340
    322     return QFontMetrics( fnt ).width( 'x' ) / 2;
    323 }
    324 
     341    return QwtPainter::horizontalAdvance( QFontMetrics( fnt ), 'x' ) / 2;
     342}
     343
     344#include "moc_qwt_text_label.cpp"
  • trunk/BNC/qwt/qwt_text_label.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include "qwt_text.h"
     15
    1516#include <qframe.h>
    1617
    … …  
    2122/*!
    2223   \brief A Widget which displays a QwtText
    23 */
     24 */
    2425
    2526class QWT_EXPORT QwtTextLabel : public QFrame
    … …  
    3132    Q_PROPERTY( QString plainText READ plainText WRITE setPlainText )
    3233
    33 public:
    34     explicit QwtTextLabel( QWidget *parent = NULL );
    35     explicit QwtTextLabel( const QwtText &, QWidget *parent = NULL );
     34  public:
     35    explicit QwtTextLabel( QWidget* parent = NULL );
     36    explicit QwtTextLabel( const QwtText&, QWidget* parent = NULL );
    3637    virtual ~QwtTextLabel();
    3738
    38     void setPlainText( const QString & );
     39    void setPlainText( const QString& );
    3940    QString plainText() const;
    4041
    41 public Q_SLOTS:
    42     void setText( const QString &,
     42  public Q_SLOTS:
     43    void setText( const QString&,
    4344        QwtText::TextFormat textFormat = QwtText::AutoText );
    44     virtual void setText( const QwtText & );
     45    virtual void setText( const QwtText& );
    4546
    4647    void clear();
    4748
    48 public:
    49     const QwtText &text() const;
     49  public:
     50    const QwtText& text() const;
    5051
    5152    int indent() const;
    … …  
    5556    void setMargin( int );
    5657
    57     virtual QSize sizeHint() const;
    58     virtual QSize minimumSizeHint() const;
    59     virtual int heightForWidth( int ) const;
     58    virtual QSize sizeHint() const QWT_OVERRIDE;
     59    virtual QSize minimumSizeHint() const QWT_OVERRIDE;
     60    virtual int heightForWidth( int ) const QWT_OVERRIDE;
    6061
    6162    QRect textRect() const;
    6263
    63     virtual void drawText( QPainter *, const QRectF & );
     64    virtual void drawText( QPainter*, const QRectF& );
    6465
    65 protected:
    66     virtual void paintEvent( QPaintEvent * );
    67     virtual void drawContents( QPainter * );
     66  protected:
     67    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
     68    virtual void drawContents( QPainter* );
    6869
    69 private:
     70  private:
    7071    void init();
    7172    int defaultIndent() const;
    7273
    7374    class PrivateData;
    74     PrivateData *d_data;
     75    PrivateData* m_data;
    7576};
    7677
  • trunk/BNC/qwt/qwt_thermo.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_thermo.h"
    11 #include "qwt_scale_engine.h"
    1211#include "qwt_scale_draw.h"
    1312#include "qwt_scale_map.h"
    1413#include "qwt_color_map.h"
     14#include "qwt_math.h"
     15
    1516#include <qpainter.h>
    1617#include <qevent.h>
    … …  
    1819#include <qstyle.h>
    1920#include <qstyleoption.h>
    20 #include <qmath.h>
    21 
    22 static inline void qwtDrawLine( QPainter *painter, int pos,
    23     const QColor &color, const QRect &pipeRect, const QRect &liquidRect,
     21#include <qmargins.h>
     22
     23#include <algorithm>
     24#include <functional>
     25
     26static inline void qwtDrawLine( QPainter* painter, int pos,
     27    const QColor& color, const QRect& pipeRect, const QRect& liquidRect,
    2428    Qt::Orientation orientation )
    2529{
    … …  
    3741}
    3842
    39 QVector<double> qwtTickList( const QwtScaleDiv &scaleDiv )
    40 {
    41     QVector<double> values;
     43static QVector< double > qwtTickList( const QwtScaleDiv& scaleDiv )
     44{
     45    QVector< double > values;
    4246
    4347    double lowerLimit = scaleDiv.interval().minValue();
    … …  
    5256        tickType < QwtScaleDiv::NTickTypes; tickType++ )
    5357    {
    54         const QList<double> ticks = scaleDiv.ticks( tickType );
     58        const QList< double > ticks = scaleDiv.ticks( tickType );
    5559
    5660        for ( int i = 0; i < ticks.count(); i++ )
    … …  
    6973class QwtThermo::PrivateData
    7074{
    71 public:
    72     PrivateData():
    73         orientation( Qt::Vertical ),
    74         scalePosition( QwtThermo::TrailingScale ),
    75         spacing( 3 ),
    76         borderWidth( 2 ),
    77         pipeWidth( 10 ),
    78         alarmLevel( 0.0 ),
    79         alarmEnabled( false ),
    80         autoFillPipe( true ),
    81         originMode( QwtThermo::OriginMinimum ),
    82         origin( 0.0 ),
    83         colorMap( NULL ),
    84         value( 0.0 )
     75  public:
     76    PrivateData()
     77        : orientation( Qt::Vertical )
     78        , scalePosition( QwtThermo::TrailingScale )
     79        , spacing( 3 )
     80        , borderWidth( 2 )
     81        , pipeWidth( 10 )
     82        , alarmLevel( 0.0 )
     83        , alarmEnabled( false )
     84        , autoFillPipe( true )
     85        , originMode( QwtThermo::OriginMinimum )
     86        , origin( 0.0 )
     87        , colorMap( NULL )
     88        , value( 0.0 )
    8589    {
    8690        rangeFlags = QwtInterval::IncludeBorders;
    … …  
    106110    double origin;
    107111
    108     QwtColorMap *colorMap;
     112    QwtColorMap* colorMap;
    109113
    110114    double value;
    … …  
    112116
    113117/*!
    114   Constructor
    115   \param parent Parent widget
    116 */
    117 QwtThermo::QwtThermo( QWidget *parent ):
    118     QwtAbstractScale( parent )
    119 {
    120     d_data = new PrivateData;
     118   Constructor
     119   \param parent Parent widget
     120 */
     121QwtThermo::QwtThermo( QWidget* parent )
     122    : QwtAbstractScale( parent )
     123{
     124    m_data = new PrivateData;
    121125
    122126    QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
    123     if ( d_data->orientation == Qt::Vertical )
     127    if ( m_data->orientation == Qt::Vertical )
    124128        policy.transpose();
    125129
    … …  
    133137QwtThermo::~QwtThermo()
    134138{
    135     delete d_data;
    136 }
    137 
    138 /*!
    139   \brief Exclude/Include min/max values
    140 
    141   According to the flags minValue() and maxValue()
    142   are included/excluded from the pipe. In case of an
    143   excluded value the corresponding tick is painted
    144   1 pixel off of the pipeRect().
    145 
    146   F.e. when a minimum
    147   of 0.0 has to be displayed as an empty pipe the minValue()
    148   needs to be excluded.
    149 
    150   \param flags Range flags
    151   \sa rangeFlags()
    152 */
     139    delete m_data;
     140}
     141
     142/*!
     143   \brief Exclude/Include min/max values
     144
     145   According to the flags minValue() and maxValue()
     146   are included/excluded from the pipe. In case of an
     147   excluded value the corresponding tick is painted
     148   1 pixel off of the pipeRect().
     149
     150   F.e. when a minimum
     151   of 0.0 has to be displayed as an empty pipe the minValue()
     152   needs to be excluded.
     153
     154   \param flags Range flags
     155   \sa rangeFlags()
     156 */
    153157void QwtThermo::setRangeFlags( QwtInterval::BorderFlags flags )
    154158{
    155     if ( d_data->rangeFlags != flags )
    156     {
    157         d_data->rangeFlags = flags;
     159    if ( m_data->rangeFlags != flags )
     160    {
     161        m_data->rangeFlags = flags;
    158162        update();
    159163    }
    … …  
    161165
    162166/*!
    163   \return Range flags
    164   \sa setRangeFlags()
    165 */
     167   \return Range flags
     168   \sa setRangeFlags()
     169 */
    166170QwtInterval::BorderFlags QwtThermo::rangeFlags() const
    167171{
    168     return d_data->rangeFlags;
    169 }
    170 
    171 /*!
    172   Set the current value.
    173 
    174   \param value New Value
    175   \sa value()
    176 */
     172    return m_data->rangeFlags;
     173}
     174
     175/*!
     176   Set the current value.
     177
     178   \param value New Value
     179   \sa value()
     180 */
    177181void QwtThermo::setValue( double value )
    178182{
    179     if ( d_data->value != value )
    180     {
    181         d_data->value = value;
     183    if ( m_data->value != value )
     184    {
     185        m_data->value = value;
    182186        update();
    183187    }
    … …  
    187191double QwtThermo::value() const
    188192{
    189     return d_data->value;
    190 }
    191 
    192 /*!
    193   \brief Set a scale draw
    194 
    195   For changing the labels of the scales, it
    196   is necessary to derive from QwtScaleDraw and
    197   overload QwtScaleDraw::label().
    198 
    199   \param scaleDraw ScaleDraw object, that has to be created with
     193    return m_data->value;
     194}
     195
     196/*!
     197   \brief Set a scale draw
     198
     199   For changing the labels of the scales, it
     200   is necessary to derive from QwtScaleDraw and
     201   overload QwtScaleDraw::label().
     202
     203   \param scaleDraw ScaleDraw object, that has to be created with
    200204                   new and will be deleted in ~QwtThermo() or the next
    201205                   call of setScaleDraw().
    202 */
    203 void QwtThermo::setScaleDraw( QwtScaleDraw *scaleDraw )
     206 */
     207void QwtThermo::setScaleDraw( QwtScaleDraw* scaleDraw )
    204208{
    205209    setAbstractScaleDraw( scaleDraw );
    … …  
    210214   \return the scale draw of the thermo
    211215   \sa setScaleDraw()
    212 */
    213 const QwtScaleDraw *QwtThermo::scaleDraw() const
    214 {
    215     return static_cast<const QwtScaleDraw *>( abstractScaleDraw() );
     216 */
     217const QwtScaleDraw* QwtThermo::scaleDraw() const
     218{
     219    return static_cast< const QwtScaleDraw* >( abstractScaleDraw() );
    216220}
    217221
    … …  
    219223   \return the scale draw of the thermo
    220224   \sa setScaleDraw()
    221 */
    222 QwtScaleDraw *QwtThermo::scaleDraw()
    223 {
    224     return static_cast<QwtScaleDraw *>( abstractScaleDraw() );
    225 }
    226 
    227 /*!
    228   Paint event handler
    229   \param event Paint event
    230 */
    231 void QwtThermo::paintEvent( QPaintEvent *event )
     225 */
     226QwtScaleDraw* QwtThermo::scaleDraw()
     227{
     228    return static_cast< QwtScaleDraw* >( abstractScaleDraw() );
     229}
     230
     231/*!
     232   Paint event handler
     233   \param event Paint event
     234 */
     235void QwtThermo::paintEvent( QPaintEvent* event )
    232236{
    233237    QPainter painter( this );
    … …  
    235239
    236240    QStyleOption opt;
    237     opt.init(this);
     241    opt.initFrom(this);
    238242    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
    239243
    … …  
    242246    if ( !tRect.contains( event->rect() ) )
    243247    {
    244         if ( d_data->scalePosition != QwtThermo::NoScale )
     248        if ( m_data->scalePosition != QwtThermo::NoScale )
    245249            scaleDraw()->draw( &painter, palette() );
    246250    }
    247251
    248     const int bw = d_data->borderWidth;
     252    const int bw = m_data->borderWidth;
    249253
    250254    const QBrush brush = palette().brush( QPalette::Base );
    … …  
    252256        tRect.adjusted( -bw, -bw, bw, bw ),
    253257        palette(), true, bw,
    254         d_data->autoFillPipe ? &brush : NULL );
     258        m_data->autoFillPipe ? &brush : NULL );
    255259
    256260    drawLiquid( &painter, tRect );
    … …  
    258262
    259263/*!
    260   Resize event handler
    261   \param event Resize event
    262 */
    263 void QwtThermo::resizeEvent( QResizeEvent *event )
     264   Resize event handler
     265   \param event Resize event
     266 */
     267void QwtThermo::resizeEvent( QResizeEvent* event )
    264268{
    265269    Q_UNUSED( event );
    … …  
    268272
    269273/*!
    270   Qt change event handler
    271   \param event Event
    272 */
    273 void QwtThermo::changeEvent( QEvent *event )
     274   Qt change event handler
     275   \param event Event
     276 */
     277void QwtThermo::changeEvent( QEvent* event )
    274278{
    275279    switch( event->type() )
    … …  
    287291
    288292/*!
    289   Recalculate the QwtThermo geometry and layout based on
    290   pipeRect() and the fonts.
    291 
    292   \param update_geometry notify the layout system and call update
     293   Recalculate the QwtThermo geometry and layout based on
     294   pipeRect() and the fonts.
     295
     296   \param update_geometry notify the layout system and call update
    293297         to redraw the scale
    294 */
     298 */
    295299void QwtThermo::layoutThermo( bool update_geometry )
    296300{
    297301    const QRect tRect = pipeRect();
    298     const int bw = d_data->borderWidth + d_data->spacing;
     302    const int bw = m_data->borderWidth + m_data->spacing;
    299303    const bool inverted = ( upperBound() < lowerBound() );
    300304
    301305    int from, to;
    302306
    303     if ( d_data->orientation == Qt::Horizontal )
     307    if ( m_data->orientation == Qt::Horizontal )
    304308    {
    305309        from = tRect.left();
    306310        to = tRect.right();
    307311
    308         if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )
     312        if ( m_data->rangeFlags & QwtInterval::ExcludeMinimum )
    309313        {
    310314            if ( inverted )
    … …  
    313317                from--;
    314318        }
    315         if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )
     319        if ( m_data->rangeFlags & QwtInterval::ExcludeMaximum )
    316320        {
    317321            if ( inverted )
    … …  
    321325        }
    322326
    323         if ( d_data->scalePosition == QwtThermo::TrailingScale )
     327        if ( m_data->scalePosition == QwtThermo::TrailingScale )
    324328        {
    325329            scaleDraw()->setAlignment( QwtScaleDraw::TopScale );
    … …  
    339343        to = tRect.bottom();
    340344
    341         if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )
     345        if ( m_data->rangeFlags & QwtInterval::ExcludeMinimum )
    342346        {
    343347            if ( inverted )
    … …  
    346350                to++;
    347351        }
    348         if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )
     352        if ( m_data->rangeFlags & QwtInterval::ExcludeMaximum )
    349353        {
    350354            if ( inverted )
    … …  
    354358        }
    355359
    356         if ( d_data->scalePosition == QwtThermo::LeadingScale )
     360        if ( m_data->scalePosition == QwtThermo::LeadingScale )
    357361        {
    358362            scaleDraw()->setAlignment( QwtScaleDraw::RightScale );
    … …  
    376380
    377381/*!
    378   \return Bounding rectangle of the pipe ( without borders )
     382   \return Bounding rectangle of the pipe ( without borders )
    379383          in widget coordinates
    380 */
     384 */
    381385QRect QwtThermo::pipeRect() const
    382386{
    383387    int mbd = 0;
    384     if ( d_data->scalePosition != QwtThermo::NoScale )
     388    if ( m_data->scalePosition != QwtThermo::NoScale )
    385389    {
    386390        int d1, d2;
    … …  
    388392        mbd = qMax( d1, d2 );
    389393    }
    390     const int bw = d_data->borderWidth;
     394    const int bw = m_data->borderWidth;
    391395    const int scaleOff = bw + mbd;
    392396
    … …  
    394398
    395399    QRect pipeRect = cr;
    396     if ( d_data->orientation == Qt::Horizontal )
     400    if ( m_data->orientation == Qt::Horizontal )
    397401    {
    398402        pipeRect.adjust( scaleOff, 0, -scaleOff, 0 );
    399403
    400         if ( d_data->scalePosition == QwtThermo::TrailingScale )
    401             pipeRect.setTop( cr.top() + cr.height() - bw - d_data->pipeWidth );
     404        if ( m_data->scalePosition == QwtThermo::TrailingScale )
     405            pipeRect.setTop( cr.top() + cr.height() - bw - m_data->pipeWidth );
    402406        else
    403407            pipeRect.setTop( bw );
    404408
    405         pipeRect.setHeight( d_data->pipeWidth );
     409        pipeRect.setHeight( m_data->pipeWidth );
    406410    }
    407411    else // Qt::Vertical
    … …  
    409413        pipeRect.adjust( 0, scaleOff, 0, -scaleOff );
    410414
    411         if ( d_data->scalePosition == QwtThermo::LeadingScale )
     415        if ( m_data->scalePosition == QwtThermo::LeadingScale )
    412416            pipeRect.setLeft( bw );
    413417        else
    414             pipeRect.setLeft( cr.left() + cr.width() - bw - d_data->pipeWidth );
    415 
    416         pipeRect.setWidth( d_data->pipeWidth );
     418            pipeRect.setLeft( cr.left() + cr.width() - bw - m_data->pipeWidth );
     419
     420        pipeRect.setWidth( m_data->pipeWidth );
    417421    }
    418422
    … …  
    421425
    422426/*!
    423   \brief Set the orientation.
    424   \param orientation Allowed values are Qt::Horizontal and Qt::Vertical.
    425 
    426   \sa orientation(), scalePosition()
    427 */
     427   \brief Set the orientation.
     428   \param orientation Allowed values are Qt::Horizontal and Qt::Vertical.
     429
     430   \sa orientation(), scalePosition()
     431 */
    428432void QwtThermo::setOrientation( Qt::Orientation orientation )
    429433{
    430     if ( orientation == d_data->orientation )
     434    if ( orientation == m_data->orientation )
    431435        return;
    432436
    433     d_data->orientation = orientation;
     437    m_data->orientation = orientation;
    434438
    435439    if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
    … …  
    446450
    447451/*!
    448   \return Orientation
    449   \sa setOrientation()
    450 */
     452   \return Orientation
     453   \sa setOrientation()
     454 */
    451455Qt::Orientation QwtThermo::orientation() const
    452456{
    453     return d_data->orientation;
    454 }
    455 
    456 /*!
    457   \brief Change how the origin is determined.
    458   \sa originMode(), serOrigin(), origin()
     457    return m_data->orientation;
     458}
     459
     460/*!
     461   \brief Change how the origin is determined.
     462   \sa originMode(), serOrigin(), origin()
    459463 */
    460464void QwtThermo::setOriginMode( OriginMode m )
    461465{
    462     if ( m == d_data->originMode )
     466    if ( m == m_data->originMode )
    463467        return;
    464468
    465     d_data->originMode = m;
     469    m_data->originMode = m;
    466470    update();
    467471}
    468472
    469473/*!
    470   \return Mode, how the origin is determined.
    471   \sa setOriginMode(), serOrigin(), origin()
     474   \return Mode, how the origin is determined.
     475   \sa setOriginMode(), serOrigin(), origin()
    472476 */
    473477QwtThermo::OriginMode QwtThermo::originMode() const
    474478{
    475     return d_data->originMode;
    476 }
    477 
    478 /*!
    479   \brief Specifies the custom origin.
    480 
    481   If originMode is set to OriginCustom this property controls where the
    482   liquid starts.
    483 
    484   \param origin New origin level
    485   \sa setOriginMode(), originMode(), origin()
     479    return m_data->originMode;
     480}
     481
     482/*!
     483   \brief Specifies the custom origin.
     484
     485   If originMode is set to OriginCustom this property controls where the
     486   liquid starts.
     487
     488   \param origin New origin level
     489   \sa setOriginMode(), originMode(), origin()
    486490 */
    487491void QwtThermo::setOrigin( double origin )
    488492{
    489     if ( origin == d_data->origin )
     493    if ( origin == m_data->origin )
    490494        return;
    491495
    492     d_data->origin = origin;
     496    m_data->origin = origin;
    493497    update();
    494498}
    495499
    496500/*!
    497   \return Origin of the thermo, when OriginCustom is enabled
    498   \sa setOrigin(), setOriginMode(), originMode()
     501   \return Origin of the thermo, when OriginCustom is enabled
     502   \sa setOrigin(), setOriginMode(), originMode()
    499503 */
    500504double QwtThermo::origin() const
    501505{
    502     return d_data->origin;
    503 }
    504 
    505 /*!
    506   \brief Change the position of the scale
    507   \param scalePosition Position of the scale.
    508 
    509   \sa ScalePosition, scalePosition()
    510 */
     506    return m_data->origin;
     507}
     508
     509/*!
     510   \brief Change the position of the scale
     511   \param scalePosition Position of the scale.
     512
     513   \sa ScalePosition, scalePosition()
     514 */
    511515void QwtThermo::setScalePosition( ScalePosition scalePosition )
    512516{
    513     if ( d_data->scalePosition == scalePosition )
     517    if ( m_data->scalePosition == scalePosition )
    514518        return;
    515519
    516     d_data->scalePosition = scalePosition;
     520    m_data->scalePosition = scalePosition;
    517521
    518522    if ( testAttribute( Qt::WA_WState_Polished ) )
    … …  
    523527   \return Scale position.
    524528   \sa setScalePosition()
    525 */
     529 */
    526530QwtThermo::ScalePosition QwtThermo::scalePosition() const
    527531{
    528     return d_data->scalePosition;
     532    return m_data->scalePosition;
    529533}
    530534
    … …  
    539543   \param painter Painter
    540544   \param pipeRect Bounding rectangle of the pipe without borders
    541 */
     545 */
    542546void QwtThermo::drawLiquid(
    543     QPainter *painter, const QRect &pipeRect ) const
     547    QPainter* painter, const QRect& pipeRect ) const
    544548{
    545549    painter->save();
    … …  
    551555    QRect liquidRect = fillRect( pipeRect );
    552556
    553     if ( d_data->colorMap != NULL )
     557    if ( m_data->colorMap != NULL )
    554558    {
    555559        const QwtInterval interval = scaleDiv().interval().normalized();
    … …  
    558562        // we calculate the colors for the rounded tick values
    559563
    560         QVector<double> values = qwtTickList( scaleDraw()->scaleDiv() );
     564        QVector< double > values = qwtTickList( scaleDraw()->scaleDiv() );
    561565
    562566        if ( scaleMap.isInverting() )
    563             qSort( values.begin(), values.end(), qGreater<double>() );
     567            std::sort( values.begin(), values.end(), std::greater< double >() );
    564568        else
    565             qSort( values.begin(), values.end(), qLess<double>() );
     569            std::sort( values.begin(), values.end(), std::less< double >() );
    566570
    567571        int from;
    … …  
    570574            from = qRound( scaleMap.transform( values[0] ) );
    571575            qwtDrawLine( painter, from,
    572                 d_data->colorMap->color( interval, values[0] ),
    573                 pipeRect, liquidRect, d_data->orientation );
     576                m_data->colorMap->color( interval, values[0] ),
     577                pipeRect, liquidRect, m_data->orientation );
    574578        }
    575579
    … …  
    583587
    584588                qwtDrawLine( painter, pos,
    585                     d_data->colorMap->color( interval, v ),
    586                     pipeRect, liquidRect, d_data->orientation );
     589                    m_data->colorMap->color( interval, v ),
     590                    pipeRect, liquidRect, m_data->orientation );
    587591            }
    588592
    589593            qwtDrawLine( painter, to,
    590                 d_data->colorMap->color( interval, values[i] ),
    591                 pipeRect, liquidRect, d_data->orientation );
     594                m_data->colorMap->color( interval, values[i] ),
     595                pipeRect, liquidRect, m_data->orientation );
    592596
    593597            from = to;
    … …  
    596600    else
    597601    {
    598         if ( !liquidRect.isEmpty() && d_data->alarmEnabled )
     602        if ( !liquidRect.isEmpty() && m_data->alarmEnabled )
    599603        {
    600604            const QRect r = alarmRect( liquidRect );
    … …  
    613617
    614618/*!
    615   \brief Change the spacing between pipe and scale
    616 
    617   A spacing of 0 means, that the backbone of the scale is below
    618   the pipe.
    619 
    620   The default setting is 3 pixels.
    621 
    622   \param spacing Number of pixels
    623   \sa spacing();
    624 */
     619   \brief Change the spacing between pipe and scale
     620
     621   A spacing of 0 means, that the backbone of the scale is below
     622   the pipe.
     623
     624   The default setting is 3 pixels.
     625
     626   \param spacing Number of pixels
     627   \sa spacing();
     628 */
    625629void QwtThermo::setSpacing( int spacing )
    626630{
    … …  
    628632        spacing = 0;
    629633
    630     if ( spacing != d_data->spacing  )
    631     {
    632         d_data->spacing = spacing;
     634    if ( spacing != m_data->spacing  )
     635    {
     636        m_data->spacing = spacing;
    633637        layoutThermo( true );
    634638    }
    … …  
    636640
    637641/*!
    638   \return Number of pixels between pipe and scale
    639   \sa setSpacing()
    640 */
     642   \return Number of pixels between pipe and scale
     643   \sa setSpacing()
     644 */
    641645int QwtThermo::spacing() const
    642646{
    643     return d_data->spacing;
     647    return m_data->spacing;
    644648}
    645649
    … …  
    648652   \param width Border width
    649653   \sa borderWidth()
    650 */
     654 */
    651655void QwtThermo::setBorderWidth( int width )
    652656{
    … …  
    654658        width = 0;
    655659
    656     if ( width != d_data->borderWidth  )
    657     {
    658         d_data->borderWidth = width;
     660    if ( width != m_data->borderWidth  )
     661    {
     662        m_data->borderWidth = width;
    659663        layoutThermo( true );
    660664    }
    … …  
    664668   \return Border width of the thermometer pipe.
    665669   \sa setBorderWidth()
    666 */
     670 */
    667671int QwtThermo::borderWidth() const
    668672{
    669     return d_data->borderWidth;
    670 }
    671 
    672 /*!
    673   \brief Assign a color map for the fill color
    674 
    675   \param colorMap Color map
    676   \warning The alarm threshold has no effect, when
     673    return m_data->borderWidth;
     674}
     675
     676/*!
     677   \brief Assign a color map for the fill color
     678
     679   \param colorMap Color map
     680   \warning The alarm threshold has no effect, when
    677681           a color map has been assigned
    678 */
    679 void QwtThermo::setColorMap( QwtColorMap *colorMap )
    680 {
    681     if ( colorMap != d_data->colorMap )
    682     {
    683         delete d_data->colorMap;
    684         d_data->colorMap = colorMap;
    685     }
    686 }
    687 
    688 /*!
    689   \return Color map for the fill color
    690   \warning The alarm threshold has no effect, when
     682 */
     683void QwtThermo::setColorMap( QwtColorMap* colorMap )
     684{
     685    if ( colorMap != m_data->colorMap )
     686    {
     687        delete m_data->colorMap;
     688        m_data->colorMap = colorMap;
     689    }
     690}
     691
     692/*!
     693   \return Color map for the fill color
     694   \warning The alarm threshold has no effect, when
    691695           a color map has been assigned
    692 */
    693 QwtColorMap *QwtThermo::colorMap()
    694 {
    695     return d_data->colorMap;
    696 }
    697 
    698 /*!
    699   \return Color map for the fill color
    700   \warning The alarm threshold has no effect, when
     696 */
     697QwtColorMap* QwtThermo::colorMap()
     698{
     699    return m_data->colorMap;
     700}
     701
     702/*!
     703   \return Color map for the fill color
     704   \warning The alarm threshold has no effect, when
    701705           a color map has been assigned
    702 */
    703 const QwtColorMap *QwtThermo::colorMap() const
    704 {
    705     return d_data->colorMap;
    706 }
    707 
    708 /*!
    709   \brief Change the brush of the liquid.
    710 
    711   Changes the QPalette::ButtonText brush of the palette.
    712 
    713   \param brush New brush.
    714   \sa fillBrush(), QWidget::setPalette()
    715 */
     706 */
     707const QwtColorMap* QwtThermo::colorMap() const
     708{
     709    return m_data->colorMap;
     710}
     711
     712/*!
     713   \brief Change the brush of the liquid.
     714
     715   Changes the QPalette::ButtonText brush of the palette.
     716
     717   \param brush New brush.
     718   \sa fillBrush(), QWidget::setPalette()
     719 */
    716720void QwtThermo::setFillBrush( const QBrush& brush )
    717721{
    … …  
    722726
    723727/*!
    724   \return Liquid ( QPalette::ButtonText ) brush.
    725   \sa setFillBrush(), QWidget::palette()
    726 */
     728   \return Liquid ( QPalette::ButtonText ) brush.
     729   \sa setFillBrush(), QWidget::palette()
     730 */
    727731QBrush QwtThermo::fillBrush() const
    728732{
    … …  
    731735
    732736/*!
    733   \brief Specify the liquid brush above the alarm threshold
    734 
    735   Changes the QPalette::Highlight brush of the palette.
    736 
    737   \param brush New brush.
    738   \sa alarmBrush(), QWidget::setPalette()
    739 
    740   \warning The alarm threshold has no effect, when
     737   \brief Specify the liquid brush above the alarm threshold
     738
     739   Changes the QPalette::Highlight brush of the palette.
     740
     741   \param brush New brush.
     742   \sa alarmBrush(), QWidget::setPalette()
     743
     744   \warning The alarm threshold has no effect, when
    741745           a color map has been assigned
    742 */
     746 */
    743747void QwtThermo::setAlarmBrush( const QBrush& brush )
    744748{
    … …  
    749753
    750754/*!
    751   \return Liquid brush ( QPalette::Highlight ) above the alarm threshold.
    752   \sa setAlarmBrush(), QWidget::palette()
    753 
    754   \warning The alarm threshold has no effect, when
     755   \return Liquid brush ( QPalette::Highlight ) above the alarm threshold.
     756   \sa setAlarmBrush(), QWidget::palette()
     757
     758   \warning The alarm threshold has no effect, when
    755759           a color map has been assigned
    756 */
     760 */
    757761QBrush QwtThermo::alarmBrush() const
    758762{
    … …  
    761765
    762766/*!
    763   Specify the alarm threshold.
    764 
    765   \param level Alarm threshold
    766   \sa alarmLevel()
    767 
    768   \warning The alarm threshold has no effect, when
     767   Specify the alarm threshold.
     768
     769   \param level Alarm threshold
     770   \sa alarmLevel()
     771
     772   \warning The alarm threshold has no effect, when
    769773           a color map has been assigned
    770 */
     774 */
    771775void QwtThermo::setAlarmLevel( double level )
    772776{
    773     d_data->alarmLevel = level;
    774     d_data->alarmEnabled = 1;
     777    m_data->alarmLevel = level;
     778    m_data->alarmEnabled = 1;
    775779    update();
    776780}
    777781
    778782/*!
    779   \return Alarm threshold.
    780   \sa setAlarmLevel()
    781 
    782   \warning The alarm threshold has no effect, when
     783   \return Alarm threshold.
     784   \sa setAlarmLevel()
     785
     786   \warning The alarm threshold has no effect, when
    783787           a color map has been assigned
    784 */
     788 */
    785789double QwtThermo::alarmLevel() const
    786790{
    787     return d_data->alarmLevel;
    788 }
    789 
    790 /*!
    791   Change the width of the pipe.
    792 
    793   \param width Width of the pipe
    794   \sa pipeWidth()
    795 */
     791    return m_data->alarmLevel;
     792}
     793
     794/*!
     795   Change the width of the pipe.
     796
     797   \param width Width of the pipe
     798   \sa pipeWidth()
     799 */
    796800void QwtThermo::setPipeWidth( int width )
    797801{
    798802    if ( width > 0 )
    799803    {
    800         d_data->pipeWidth = width;
     804        m_data->pipeWidth = width;
    801805        layoutThermo( true );
    802806    }
    … …  
    804808
    805809/*!
    806   \return Width of the pipe.
    807   \sa setPipeWidth()
    808 */
     810   \return Width of the pipe.
     811   \sa setPipeWidth()
     812 */
    809813int QwtThermo::pipeWidth() const
    810814{
    811     return d_data->pipeWidth;
    812 }
    813 
    814 /*!
    815   \brief Enable or disable the alarm threshold
    816   \param on true (disabled) or false (enabled)
    817 
    818   \warning The alarm threshold has no effect, when
     815    return m_data->pipeWidth;
     816}
     817
     818/*!
     819   \brief Enable or disable the alarm threshold
     820   \param on true (disabled) or false (enabled)
     821
     822   \warning The alarm threshold has no effect, when
    819823           a color map has been assigned
    820 */
     824 */
    821825void QwtThermo::setAlarmEnabled( bool on )
    822826{
    823     d_data->alarmEnabled = on;
     827    m_data->alarmEnabled = on;
    824828    update();
    825829}
    826830
    827831/*!
    828   \return True, when the alarm threshold is enabled.
    829 
    830   \warning The alarm threshold has no effect, when
     832   \return True, when the alarm threshold is enabled.
     833
     834   \warning The alarm threshold has no effect, when
    831835           a color map has been assigned
    832 */
     836 */
    833837bool QwtThermo::alarmEnabled() const
    834838{
    835     return d_data->alarmEnabled;
    836 }
    837 
    838 /*!
    839   \return the minimum size hint
    840   \sa minimumSizeHint()
    841 */
     839    return m_data->alarmEnabled;
     840}
     841
     842/*!
     843   \return the minimum size hint
     844   \sa minimumSizeHint()
     845 */
    842846QSize QwtThermo::sizeHint() const
    843847{
    … …  
    846850
    847851/*!
    848   \return Minimum size hint
    849   \warning The return value depends on the font and the scale.
    850   \sa sizeHint()
    851 */
     852   \return Minimum size hint
     853   \warning The return value depends on the font and the scale.
     854   \sa sizeHint()
     855 */
    852856QSize QwtThermo::minimumSizeHint() const
    853857{
    854858    int w = 0, h = 0;
    855859
    856     if ( d_data->scalePosition != NoScale )
    857     {
    858         const int sdExtent = qCeil( scaleDraw()->extent( font() ) );
     860    if ( m_data->scalePosition != NoScale )
     861    {
     862        const int sdExtent = qwtCeil( scaleDraw()->extent( font() ) );
    859863        const int sdLength = scaleDraw()->minLength( font() );
    860864
    861865        w = sdLength;
    862         h = d_data->pipeWidth + sdExtent + d_data->spacing;
     866        h = m_data->pipeWidth + sdExtent + m_data->spacing;
    863867
    864868    }
    … …  
    866870    {
    867871        w = 200;
    868         h = d_data->pipeWidth;
    869     }
    870 
    871     if ( d_data->orientation == Qt::Vertical )
     872        h = m_data->pipeWidth;
     873    }
     874
     875    if ( m_data->orientation == Qt::Vertical )
    872876        qSwap( w, h );
    873877
    874     w += 2 * d_data->borderWidth;
    875     h += 2 * d_data->borderWidth;
     878    w += 2 * m_data->borderWidth;
     879    h += 2 * m_data->borderWidth;
    876880
    877881    // finally add the margins
    878     int left, right, top, bottom;
    879     getContentsMargins( &left, &top, &right, &bottom );
    880     w += left + right;
    881     h += top + bottom;
     882    const QMargins m = contentsMargins();
     883    w += m.left() + m.right();
     884    h += m.top() + m.bottom();
    882885
    883886    return QSize( w, h );
    … …  
    885888
    886889/*!
    887   \brief Calculate the filled rectangle of the pipe
    888 
    889   \param pipeRect Rectangle of the pipe
    890   \return Rectangle to be filled ( fill and alarm brush )
    891 
    892   \sa pipeRect(), alarmRect()
    893  */
    894 QRect QwtThermo::fillRect( const QRect &pipeRect ) const
     890   \brief Calculate the filled rectangle of the pipe
     891
     892   \param pipeRect Rectangle of the pipe
     893   \return Rectangle to be filled ( fill and alarm brush )
     894
     895   \sa pipeRect(), alarmRect()
     896 */
     897QRect QwtThermo::fillRect( const QRect& pipeRect ) const
    895898{
    896899    double origin;
    897     if ( d_data->originMode == OriginMinimum )
     900    if ( m_data->originMode == OriginMinimum )
    898901    {
    899902        origin = qMin( lowerBound(), upperBound() );
    900903    }
    901     else if ( d_data->originMode == OriginMaximum )
     904    else if ( m_data->originMode == OriginMaximum )
    902905    {
    903906        origin = qMax( lowerBound(), upperBound() );
    … …  
    905908    else // OriginCustom
    906909    {
    907         origin = d_data->origin;
     910        origin = m_data->origin;
    908911    }
    909912
    910913    const QwtScaleMap scaleMap = scaleDraw()->scaleMap();
    911914
    912     int from = qRound( scaleMap.transform( d_data->value ) );
     915    int from = qRound( scaleMap.transform( m_data->value ) );
    913916    int to = qRound( scaleMap.transform( origin ) );
    914917
    … …  
    917920
    918921    QRect fillRect = pipeRect;
    919     if ( d_data->orientation == Qt::Horizontal )
     922    if ( m_data->orientation == Qt::Horizontal )
    920923    {
    921924        fillRect.setLeft( from );
    … …  
    932935
    933936/*!
    934   \brief Calculate the alarm rectangle of the pipe
    935 
    936   \param fillRect Filled rectangle in the pipe
    937   \return Rectangle to be filled with the alarm brush
    938 
    939   \sa pipeRect(), fillRect(), alarmLevel(), alarmBrush()
    940  */
    941 QRect QwtThermo::alarmRect( const QRect &fillRect ) const
     937   \brief Calculate the alarm rectangle of the pipe
     938
     939   \param fillRect Filled rectangle in the pipe
     940   \return Rectangle to be filled with the alarm brush
     941
     942   \sa pipeRect(), fillRect(), alarmLevel(), alarmBrush()
     943 */
     944QRect QwtThermo::alarmRect( const QRect& fillRect ) const
    942945{
    943946    QRect alarmRect( 0, 0, -1, -1); // something invalid
    944947
    945     if ( !d_data->alarmEnabled )
     948    if ( !m_data->alarmEnabled )
    946949        return alarmRect;
    947950
    … …  
    949952
    950953    bool increasing;
    951     if ( d_data->originMode == OriginCustom )
    952     {
    953         increasing = d_data->value > d_data->origin;
     954    if ( m_data->originMode == OriginCustom )
     955    {
     956        increasing = m_data->value > m_data->origin;
    954957    }
    955958    else
    956959    {
    957         increasing = d_data->originMode == OriginMinimum;
     960        increasing = m_data->originMode == OriginMinimum;
    958961    }
    959962
    960963    const QwtScaleMap map = scaleDraw()->scaleMap();
    961     const int alarmPos = qRound( map.transform( d_data->alarmLevel ) );
    962     const int valuePos = qRound( map.transform( d_data->value ) );
    963 
    964     if ( d_data->orientation == Qt::Horizontal )
     964    const int alarmPos = qRound( map.transform( m_data->alarmLevel ) );
     965    const int valuePos = qRound( map.transform( m_data->value ) );
     966
     967    if ( m_data->orientation == Qt::Horizontal )
    965968    {
    966969        int v1, v2;
    … …  
    10041007    return alarmRect;
    10051008}
     1009
     1010#include "moc_qwt_thermo.cpp"
  • trunk/BNC/qwt/qwt_thermo.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1919
    2020/*!
    21   \brief The Thermometer Widget
     21   \brief The Thermometer Widget
    2222
    23   QwtThermo is a widget which displays a value in an interval. It supports:
    24   - a horizontal or vertical layout;
    25   - a range;
    26   - a scale;
    27   - an alarm level.
     23   QwtThermo is a widget which displays a value in an interval. It supports:
     24   - a horizontal or vertical layout;
     25   - a range;
     26   - a scale;
     27   - an alarm level.
    2828
    29   \image html sysinfo.png
     29   \image html sysinfo.png
    3030
    31   The fill colors might be calculated from an optional color map
    32   If no color map has been assigned QwtThermo uses the
    33   following colors/brushes from the widget palette:
     31   The fill colors might be calculated from an optional color map
     32   If no color map has been assigned QwtThermo uses the
     33   following colors/brushes from the widget palette:
    3434
    35   - QPalette::Base
     35   - QPalette::Base
    3636    Background of the pipe
    37   - QPalette::ButtonText
     37   - QPalette::ButtonText
    3838    Fill brush below the alarm level
    39   - QPalette::Highlight
     39   - QPalette::Highlight
    4040    Fill brush for the values above the alarm level
    41   - QPalette::WindowText
     41   - QPalette::WindowText
    4242    For the axis of the scale
    43   - QPalette::Text
     43   - QPalette::Text
    4444    For the labels of the scale
    45 */
    46 class QWT_EXPORT QwtThermo: public QwtAbstractScale
     45 */
     46class QWT_EXPORT QwtThermo : public QwtAbstractScale
    4747{
    4848    Q_OBJECT
    … …  
    6363    Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
    6464    Q_PROPERTY( int pipeWidth READ pipeWidth WRITE setPipeWidth )
    65     Q_PROPERTY( double value READ value WRITE setValue )
     65    Q_PROPERTY( double value READ value WRITE setValue USER true )
    6666
    67 public:
     67  public:
    6868
    6969    /*!
    70       Position of the scale
    71       \sa setScalePosition(), setOrientation()
     70       Position of the scale
     71       \sa setScalePosition(), setOrientation()
    7272     */
    7373    enum ScalePosition
    … …  
    8484
    8585    /*!
    86       Origin mode. This property specifies where the beginning of the liquid
    87       is placed.
     86       Origin mode. This property specifies where the beginning of the liquid
     87       is placed.
    8888
    89       \sa setOriginMode(), setOrigin()
    90     */
     89       \sa setOriginMode(), setOrigin()
     90     */
    9191    enum OriginMode
    9292    {
    … …  
    101101    };
    102102
    103     explicit QwtThermo( QWidget *parent = NULL );
     103    explicit QwtThermo( QWidget* parent = NULL );
    104104    virtual ~QwtThermo();
    105105
    … …  
    122122    double origin() const;
    123123
    124     void setFillBrush( const QBrush & );
     124    void setFillBrush( const QBrush& );
    125125    QBrush fillBrush() const;
    126126
    127     void setAlarmBrush( const QBrush & );
     127    void setAlarmBrush( const QBrush& );
    128128    QBrush alarmBrush() const;
    129129
    … …  
    134134    bool alarmEnabled() const;
    135135
    136     void setColorMap( QwtColorMap * );
    137     QwtColorMap *colorMap();
    138     const QwtColorMap *colorMap() const;
     136    void setColorMap( QwtColorMap* );
     137    QwtColorMap* colorMap();
     138    const QwtColorMap* colorMap() const;
    139139
    140140    void setPipeWidth( int );
    … …  
    146146    double value() const;
    147147
    148     virtual QSize sizeHint() const;
    149     virtual QSize minimumSizeHint() const;
     148    virtual QSize sizeHint() const QWT_OVERRIDE;
     149    virtual QSize minimumSizeHint() const QWT_OVERRIDE;
    150150
    151     void setScaleDraw( QwtScaleDraw * );
    152     const QwtScaleDraw *scaleDraw() const;
     151    void setScaleDraw( QwtScaleDraw* );
     152    const QwtScaleDraw* scaleDraw() const;
    153153
    154 public Q_SLOTS:
     154  public Q_SLOTS:
    155155    virtual void setValue( double );
    156156
    157 protected:
    158     virtual void drawLiquid( QPainter *, const QRect & ) const;
    159     virtual void scaleChange();
     157  protected:
     158    virtual void drawLiquid( QPainter*, const QRect& ) const;
     159    virtual void scaleChange() QWT_OVERRIDE;
    160160
    161     virtual void paintEvent( QPaintEvent * );
    162     virtual void resizeEvent( QResizeEvent * );
    163     virtual void changeEvent( QEvent * );
     161    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
     162    virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE;
     163    virtual void changeEvent( QEvent* ) QWT_OVERRIDE;
    164164
    165     QwtScaleDraw *scaleDraw();
     165    QwtScaleDraw* scaleDraw();
    166166
    167167    QRect pipeRect() const;
    168     QRect fillRect( const QRect & ) const;
    169     QRect alarmRect( const QRect & ) const;
     168    QRect fillRect( const QRect& ) const;
     169    QRect alarmRect( const QRect& ) const;
    170170
    171 private:
     171  private:
    172172    void layoutThermo( bool );
    173173
    174174    class PrivateData;
    175     PrivateData *d_data;
     175    PrivateData* m_data;
    176176};
    177177
  • trunk/BNC/qwt/qwt_transform.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_math.h"
    1212
    13 #if QT_VERSION < 0x040601
    14 #define qExp(x) ::exp(x)
    15 #endif
    16 
    17 #if QT_VERSION >= 0x050400
    18 
    1913//! Smallest allowed value for logarithmic scales: 1.0e-150
    2014const double QwtLogTransform::LogMin = 1.0e-150;
    … …  
    2216//! Largest allowed value for logarithmic scales: 1.0e150
    2317const double QwtLogTransform::LogMax = 1.0e150;
    24 
    25 #else
    26 
    27 //! Smallest allowed value for logarithmic scales: 1.0e-150
    28 QT_STATIC_CONST_IMPL double QwtLogTransform::LogMin = 1.0e-150;
    29 
    30 //! Largest allowed value for logarithmic scales: 1.0e150
    31 QT_STATIC_CONST_IMPL double QwtLogTransform::LogMax = 1.0e150;
    32 
    33 #endif
    3418
    3519//! Constructor
    … …  
    4428
    4529/*!
    46   \param value Value to be bounded
    47   \return value unmodified
     30   \param value Value to be bounded
     31   \return value unmodified
    4832 */
    4933double QwtTransform::bounded( double value ) const
    … …  
    6448
    6549/*!
    66   \param value Value to be transformed
    67   \return value unmodified
     50   \param value Value to be transformed
     51   \return value unmodified
    6852 */
    6953double QwtNullTransform::transform( double value ) const
    … …  
    7357
    7458/*!
    75   \param value Value to be transformed
    76   \return value unmodified
     59   \param value Value to be transformed
     60   \return value unmodified
    7761 */
    7862double QwtNullTransform::invTransform( double value ) const
    … …  
    8266
    8367//! \return Clone of the transformation
    84 QwtTransform *QwtNullTransform::copy() const
     68QwtTransform* QwtNullTransform::copy() const
    8569{
    8670    return new QwtNullTransform();
    … …  
    9983
    10084/*!
    101   \param value Value to be transformed
    102   \return log( value )
     85   \param value Value to be transformed
     86   \return log( value )
    10387 */
    10488double QwtLogTransform::transform( double value ) const
    10589{
    106     return ::log( value );
     90    return std::log( value );
    10791}
    10892
    10993/*!
    110   \param value Value to be transformed
    111   \return exp( value )
     94   \param value Value to be transformed
     95   \return exp( value )
    11296 */
    11397double QwtLogTransform::invTransform( double value ) const
    11498{
    115     return qExp( value );
     99    return std::exp( value );
    116100}
    117101
    118102/*!
    119   \param value Value to be bounded
    120   \return qBound( LogMin, value, LogMax )
     103   \param value Value to be bounded
     104   \return qBound( LogMin, value, LogMax )
    121105 */
    122106double QwtLogTransform::bounded( double value ) const
    … …  
    126110
    127111//! \return Clone of the transformation
    128 QwtTransform *QwtLogTransform::copy() const
     112QwtTransform* QwtLogTransform::copy() const
    129113{
    130114    return new QwtLogTransform();
    … …  
    132116
    133117/*!
    134   Constructor
    135   \param exponent Exponent
    136 */
     118   Constructor
     119   \param exponent Exponent
     120 */
    137121QwtPowerTransform::QwtPowerTransform( double exponent ):
    138122    QwtTransform(),
    139     d_exponent( exponent )
     123    m_exponent( exponent )
    140124{
    141125}
    … …  
    147131
    148132/*!
    149   \param value Value to be transformed
    150   \return Exponentiation preserving the sign
     133   \param value Value to be transformed
     134   \return Exponentiation preserving the sign
    151135 */
    152136double QwtPowerTransform::transform( double value ) const
    153137{
    154138    if ( value < 0.0 )
    155         return -qPow( -value, 1.0 / d_exponent );
     139        return -std::pow( -value, 1.0 / m_exponent );
    156140    else
    157         return qPow( value, 1.0 / d_exponent );
     141        return std::pow( value, 1.0 / m_exponent );
    158142
    159143}
    160144
    161145/*!
    162   \param value Value to be transformed
    163   \return Inverse exponentiation preserving the sign
     146   \param value Value to be transformed
     147   \return Inverse exponentiation preserving the sign
    164148 */
    165149double QwtPowerTransform::invTransform( double value ) const
    166150{
    167151    if ( value < 0.0 )
    168         return -qPow( -value, d_exponent );
     152        return -std::pow( -value, m_exponent );
    169153    else
    170         return qPow( value, d_exponent );
     154        return std::pow( value, m_exponent );
    171155}
    172156
    173157//! \return Clone of the transformation
    174 QwtTransform *QwtPowerTransform::copy() const
     158QwtTransform* QwtPowerTransform::copy() const
    175159{
    176     return new QwtPowerTransform( d_exponent );
     160    return new QwtPowerTransform( m_exponent );
    177161}
  • trunk/BNC/qwt/qwt_transform.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    3232   - p = p1 + ( p2 - p1 ) * ( T( s ) - T( s1 ) / ( T( s2 ) - T( s1 ) );
    3333   - s = invT ( T( s1 ) + ( T( s2 ) - T( s1 ) ) * ( p - p1 ) / ( p2 - p1 ) );
    34 */
     34 */
    3535class QWT_EXPORT QwtTransform
    3636{
    37 public:
     37  public:
    3838    QwtTransform();
    3939    virtual ~QwtTransform();
    … …  
    6666
    6767    //! Virtualized copy operation
    68     virtual QwtTransform *copy() const = 0;
     68    virtual QwtTransform* copy() const = 0;
     69
     70  private:
     71    Q_DISABLE_COPY(QwtTransform)
    6972};
    7073
    … …  
    7578
    7679 */
    77 class QWT_EXPORT QwtNullTransform: public QwtTransform
     80class QWT_EXPORT QwtNullTransform : public QwtTransform
    7881{
    79 public:
     82  public:
    8083    QwtNullTransform();
    8184    virtual ~QwtNullTransform();
    8285
    83     virtual double transform( double value ) const;
    84     virtual double invTransform( double value ) const;
     86    virtual double transform( double value ) const QWT_OVERRIDE;
     87    virtual double invTransform( double value ) const QWT_OVERRIDE;
    8588
    86     virtual QwtTransform *copy() const;
     89    virtual QwtTransform* copy() const QWT_OVERRIDE;
    8790};
    8891/*!
    … …  
    9598         for log2(), log10() or any other logarithmic scale.
    9699 */
    97 class QWT_EXPORT QwtLogTransform: public QwtTransform
     100class QWT_EXPORT QwtLogTransform : public QwtTransform
    98101{
    99 public:
     102  public:
    100103    QwtLogTransform();
    101104    virtual ~QwtLogTransform();
    102105
    103     virtual double transform( double value ) const;
    104     virtual double invTransform( double value ) const;
     106    virtual double transform( double value ) const QWT_OVERRIDE;
     107    virtual double invTransform( double value ) const QWT_OVERRIDE;
    105108
    106     virtual double bounded( double value ) const;
     109    virtual double bounded( double value ) const QWT_OVERRIDE;
    107110
    108     virtual QwtTransform *copy() const;
     111    virtual QwtTransform* copy() const QWT_OVERRIDE;
    109112
    110 #if QT_VERSION >= 0x050400
    111113    static const double LogMin;
    112114    static const double LogMax;
    113 #else
    114     QT_STATIC_CONST double LogMin;
    115     QT_STATIC_CONST double LogMax;
    116 #endif
    117115};
    118116
    … …  
    125123   can be used for scales including negative values.
    126124 */
    127 class QWT_EXPORT QwtPowerTransform: public QwtTransform
     125class QWT_EXPORT QwtPowerTransform : public QwtTransform
    128126{
    129 public:
    130     QwtPowerTransform( double exponent );
     127  public:
     128    explicit QwtPowerTransform( double exponent );
    131129    virtual ~QwtPowerTransform();
    132130
    133     virtual double transform( double value ) const;
    134     virtual double invTransform( double value ) const;
     131    virtual double transform( double value ) const QWT_OVERRIDE;
     132    virtual double invTransform( double value ) const QWT_OVERRIDE;
    135133
    136     virtual QwtTransform *copy() const;
     134    virtual QwtTransform* copy() const QWT_OVERRIDE;
    137135
    138 private:
    139     const double d_exponent;
     136  private:
     137    const double m_exponent;
    140138};
    141139
  • trunk/BNC/qwt/qwt_wheel.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_math.h"
    1212#include "qwt_painter.h"
     13#include "qwt.h"
     14
    1315#include <qevent.h>
    1416#include <qdrawutil.h>
    … …  
    1618#include <qstyle.h>
    1719#include <qstyleoption.h>
    18 #include <qapplication.h>
    19 #include <qdatetime.h>
    20 
    21 #if QT_VERSION < 0x040601
    22 #define qFabs(x) ::fabs(x)
    23 #define qFastSin(x) ::sin(x)
    24 #define qExp(x) ::exp(x)
    25 #endif
     20#include <qelapsedtimer.h>
     21#include <qmath.h>
    2622
    2723class QwtWheel::PrivateData
    2824{
    29 public:
    30     PrivateData():
    31         orientation( Qt::Horizontal ),
    32         viewAngle( 175.0 ),
    33         totalAngle( 360.0 ),
    34         tickCount( 10 ),
    35         wheelBorderWidth( 2 ),
    36         borderWidth( 2 ),
    37         wheelWidth( 20 ),
    38         isScrolling( false ),
    39         mouseOffset( 0.0 ),
    40         tracking( true ),
    41         pendingValueChanged( false ),
    42         updateInterval( 50 ),
    43         mass( 0.0 ),
    44         timerId( 0 ),
    45         speed( 0.0 ),
    46         mouseValue( 0.0 ),
    47         flyingValue( 0.0 ),
    48         minimum( 0.0 ),
    49         maximum( 100.0 ),
    50         singleStep( 1.0 ),
    51         pageStepCount( 1 ),
    52         stepAlignment( true ),
    53         value( 0.0 ),
    54         inverted( false ),
    55         wrapping( false )
     25  public:
     26    PrivateData()
     27        : orientation( Qt::Horizontal )
     28        , viewAngle( 175.0 )
     29        , totalAngle( 360.0 )
     30        , tickCount( 10 )
     31        , wheelBorderWidth( 2 )
     32        , borderWidth( 2 )
     33        , wheelWidth( 20 )
     34        , mouseOffset( 0.0 )
     35        , updateInterval( 50 )
     36        , mass( 0.0 )
     37        , timerId( 0 )
     38        , speed( 0.0 )
     39        , mouseValue( 0.0 )
     40        , flyingValue( 0.0 )
     41        , minimum( 0.0 )
     42        , maximum( 100.0 )
     43        , singleStep( 1.0 )
     44        , pageStepCount( 1 )
     45        , value( 0.0 )
     46        , isScrolling( false )
     47        , tracking( true )
     48        , stepAlignment( true )
     49        , pendingValueChanged( false )
     50        , inverted( false )
     51        , wrapping( false )
    5652    {
    5753    }
    … …  
    6561    int wheelWidth;
    6662
    67     bool isScrolling;
    6863    double mouseOffset;
    69 
    70     bool tracking;
    71     bool pendingValueChanged; // when not tracking
    7264
    7365    int updateInterval;
    … …  
    7668    // for the flying wheel effect
    7769    int timerId;
    78     QTime time;
     70    QElapsedTimer timer;
    7971    double speed;
    8072    double mouseValue;
    … …  
    8678    double singleStep;
    8779    int pageStepCount;
     80
     81    double value;
     82
     83    bool isScrolling;
     84    bool tracking;
    8885    bool stepAlignment;
    89 
    90     double value;
    91 
     86    bool pendingValueChanged; // when not tracking
    9287    bool inverted;
    9388    bool wrapping;
    … …  
    9590
    9691//! Constructor
    97 QwtWheel::QwtWheel( QWidget *parent ):
     92QwtWheel::QwtWheel( QWidget* parent ):
    9893    QWidget( parent )
    9994{
    100     d_data = new PrivateData;
     95    m_data = new PrivateData;
    10196
    10297    setFocusPolicy( Qt::StrongFocus );
    … …  
    108103QwtWheel::~QwtWheel()
    109104{
    110     delete d_data;
    111 }
    112 
    113 /*!
    114   \brief En/Disable tracking
    115 
    116   If tracking is enabled (the default), the wheel emits the valueChanged()
    117   signal while the wheel is moving. If tracking is disabled, the wheel
    118   emits the valueChanged() signal only when the wheel movement is terminated.
    119 
    120   The wheelMoved() signal is emitted regardless id tracking is enabled or not.
    121 
    122   \param enable On/Off
    123   \sa isTracking()
     105    delete m_data;
     106}
     107
     108/*!
     109   \brief En/Disable tracking
     110
     111   If tracking is enabled (the default), the wheel emits the valueChanged()
     112   signal while the wheel is moving. If tracking is disabled, the wheel
     113   emits the valueChanged() signal only when the wheel movement is terminated.
     114
     115   The wheelMoved() signal is emitted regardless id tracking is enabled or not.
     116
     117   \param enable On/Off
     118   \sa isTracking()
    124119 */
    125120void QwtWheel::setTracking( bool enable )
    126121{
    127     d_data->tracking = enable;
    128 }
    129 
    130 /*!
    131   \return True, when tracking is enabled
    132   \sa setTracking(), valueChanged(), wheelMoved()
    133 */
     122    m_data->tracking = enable;
     123}
     124
     125/*!
     126   \return True, when tracking is enabled
     127   \sa setTracking(), valueChanged(), wheelMoved()
     128 */
    134129bool QwtWheel::isTracking() const
    135130{
    136     return d_data->tracking;
    137 }
    138 
    139 /*!
    140   \brief Specify the update interval when the wheel is flying
    141 
    142   Default and minimum value is 50 ms.
    143 
    144   \param interval Interval in milliseconds
    145   \sa updateInterval(), setMass(), setTracking()
    146 */
     131    return m_data->tracking;
     132}
     133
     134/*!
     135   \brief Specify the update interval when the wheel is flying
     136
     137   Default and minimum value is 50 ms.
     138
     139   \param interval Interval in milliseconds
     140   \sa updateInterval(), setMass(), setTracking()
     141 */
    147142void QwtWheel::setUpdateInterval( int interval )
    148143{
    149     d_data->updateInterval = qMax( interval, 50 );
    150 }
    151 
    152 /*!
    153   \return Update interval when the wheel is flying
    154   \sa setUpdateInterval(), mass(), isTracking()
     144    m_data->updateInterval = qMax( interval, 50 );
     145}
     146
     147/*!
     148   \return Update interval when the wheel is flying
     149   \sa setUpdateInterval(), mass(), isTracking()
    155150 */
    156151int QwtWheel::updateInterval() const
    157152{
    158     return d_data->updateInterval;
     153    return m_data->updateInterval;
    159154}
    160155
    … …  
    165160
    166161   \param event Mouse event
    167 */
    168 void QwtWheel::mousePressEvent( QMouseEvent *event )
     162 */
     163void QwtWheel::mousePressEvent( QMouseEvent* event )
    169164{
    170165    stopFlying();
    171166
    172     d_data->isScrolling = wheelRect().contains( event->pos() );
    173 
    174     if ( d_data->isScrolling )
    175     {
    176         d_data->time.start();
    177         d_data->speed = 0.0;
    178         d_data->mouseValue = valueAt( event->pos() );
    179         d_data->mouseOffset = d_data->mouseValue - d_data->value;
    180         d_data->pendingValueChanged = false;
     167    m_data->isScrolling = wheelRect().contains( event->pos() );
     168
     169    if ( m_data->isScrolling )
     170    {
     171        m_data->timer.start();
     172        m_data->speed = 0.0;
     173        m_data->mouseValue = valueAt( event->pos() );
     174        m_data->mouseOffset = m_data->mouseValue - m_data->value;
     175        m_data->pendingValueChanged = false;
    181176
    182177        Q_EMIT wheelPressed();
    … …  
    190185
    191186   \param event Mouse event
    192 */
    193 void QwtWheel::mouseMoveEvent( QMouseEvent *event )
    194 {
    195     if ( !d_data->isScrolling )
     187 */
     188void QwtWheel::mouseMoveEvent( QMouseEvent* event )
     189{
     190    if ( !m_data->isScrolling )
    196191        return;
    197192
    198193    double mouseValue = valueAt( event->pos() );
    199194
    200     if ( d_data->mass > 0.0 )
    201     {
    202         double ms = d_data->time.restart();
     195    if ( m_data->mass > 0.0 )
     196    {
     197        double ms = m_data->timer.restart();
    203198
    204199        // the interval when mouse move events are posted are somehow
    … …  
    207202        ms = qMax( ms, 5.0 );
    208203
    209         d_data->speed = ( mouseValue - d_data->mouseValue ) / ms;
    210     }
    211 
    212     d_data->mouseValue = mouseValue;
    213 
    214     double value = boundedValue( mouseValue - d_data->mouseOffset );
    215     if ( d_data->stepAlignment )
     204        m_data->speed = ( mouseValue - m_data->mouseValue ) / ms;
     205    }
     206
     207    m_data->mouseValue = mouseValue;
     208
     209    double value = boundedValue( mouseValue - m_data->mouseOffset );
     210    if ( m_data->stepAlignment )
    216211        value = alignedValue( value );
    217212
    218     if ( value != d_data->value )
    219     {
    220         d_data->value = value;
     213    if ( value != m_data->value )
     214    {
     215        m_data->value = value;
    221216
    222217        update();
    223218
    224         Q_EMIT wheelMoved( d_data->value );
    225 
    226         if ( d_data->tracking )
    227             Q_EMIT valueChanged( d_data->value );
     219        Q_EMIT wheelMoved( m_data->value );
     220
     221        if ( m_data->tracking )
     222            Q_EMIT valueChanged( m_data->value );
    228223        else
    229             d_data->pendingValueChanged = true;
     224            m_data->pendingValueChanged = true;
    230225    }
    231226}
    … …  
    238233
    239234   \param event Mouse event
    240 */
    241 
    242 void QwtWheel::mouseReleaseEvent( QMouseEvent *event )
     235 */
     236
     237void QwtWheel::mouseReleaseEvent( QMouseEvent* event )
    243238{
    244239    Q_UNUSED( event );
    245240
    246     if ( !d_data->isScrolling )
     241    if ( !m_data->isScrolling )
    247242        return;
    248243
    249     d_data->isScrolling = false;
     244    m_data->isScrolling = false;
    250245
    251246    bool startFlying = false;
    252247
    253     if ( d_data->mass > 0.0 )
    254     {
    255         const int ms = d_data->time.elapsed();
    256         if ( ( qFabs( d_data->speed ) > 0.0 ) && ( ms < 50 ) )
     248    if ( m_data->mass > 0.0 )
     249    {
     250        const qint64 ms = m_data->timer.elapsed();
     251        if ( ( std::fabs( m_data->speed ) > 0.0 ) && ( ms < 50 ) )
    257252            startFlying = true;
    258253    }
    … …  
    260255    if ( startFlying )
    261256    {
    262         d_data->flyingValue =
    263             boundedValue( d_data->mouseValue - d_data->mouseOffset );
    264 
    265         d_data->timerId = startTimer( d_data->updateInterval );
     257        m_data->flyingValue =
     258            boundedValue( m_data->mouseValue - m_data->mouseOffset );
     259
     260        m_data->timerId = startTimer( m_data->updateInterval );
    266261    }
    267262    else
    268263    {
    269         if ( d_data->pendingValueChanged )
    270             Q_EMIT valueChanged( d_data->value );
    271     }
    272 
    273     d_data->pendingValueChanged = false;
    274     d_data->mouseOffset = 0.0;
     264        if ( m_data->pendingValueChanged )
     265            Q_EMIT valueChanged( m_data->value );
     266    }
     267
     268    m_data->pendingValueChanged = false;
     269    m_data->mouseOffset = 0.0;
    275270
    276271    Q_EMIT wheelReleased();
    … …  
    278273
    279274/*!
    280   \brief Qt timer event
    281 
    282   The flying wheel effect is implemented using a timer
    283 
    284   \param event Timer event
    285 
    286   \sa updateInterval()
    287  */
    288 void QwtWheel::timerEvent( QTimerEvent *event )
    289 {
    290     if ( event->timerId() != d_data->timerId )
     275   \brief Qt timer event
     276
     277   The flying wheel effect is implemented using a timer
     278
     279   \param event Timer event
     280
     281   \sa updateInterval()
     282 */
     283void QwtWheel::timerEvent( QTimerEvent* event )
     284{
     285    if ( event->timerId() != m_data->timerId )
    291286    {
    292287        QWidget::timerEvent( event );
    … …  
    294289    }
    295290
    296     d_data->speed *= qExp( -d_data->updateInterval * 0.001 / d_data->mass );
    297 
    298     d_data->flyingValue += d_data->speed * d_data->updateInterval;
    299     d_data->flyingValue = boundedValue( d_data->flyingValue );
    300 
    301     double value = d_data->flyingValue;
    302     if ( d_data->stepAlignment )
     291    m_data->speed *= std::exp( -m_data->updateInterval * 0.001 / m_data->mass );
     292
     293    m_data->flyingValue += m_data->speed * m_data->updateInterval;
     294    m_data->flyingValue = boundedValue( m_data->flyingValue );
     295
     296    double value = m_data->flyingValue;
     297    if ( m_data->stepAlignment )
    303298        value = alignedValue( value );
    304299
    305     if ( qFabs( d_data->speed ) < 0.001 * d_data->singleStep )
    306     {
    307         // stop if d_data->speed < one step per second
     300    if ( std::fabs( m_data->speed ) < 0.001 * m_data->singleStep )
     301    {
     302        // stop if m_data->speed < one step per second
    308303        stopFlying();
    309304    }
    310305
    311     if ( value != d_data->value )
    312     {
    313         d_data->value = value;
     306    if ( value != m_data->value )
     307    {
     308        m_data->value = value;
    314309        update();
    315310
    316         if ( d_data->tracking || d_data->timerId == 0 )
    317             Q_EMIT valueChanged( d_data->value );
    318     }
    319 }
    320 
    321 
    322 /*!
    323   \brief Handle wheel events
    324 
    325   In/Decrement the value
    326 
    327   \param event Wheel event
    328 */
    329 void QwtWheel::wheelEvent( QWheelEvent *event )
    330 {
    331     if ( !wheelRect().contains( event->pos() ) )
     311        if ( m_data->tracking || m_data->timerId == 0 )
     312            Q_EMIT valueChanged( m_data->value );
     313    }
     314}
     315
     316
     317/*!
     318   \brief Handle wheel events
     319
     320   In/Decrement the value
     321
     322   \param event Wheel event
     323 */
     324void QwtWheel::wheelEvent( QWheelEvent* event )
     325{
     326#if QT_VERSION < 0x050e00
     327    const QPoint wheelPos = event->pos();
     328    const int wheelDelta = event->delta();
     329#else
     330    const QPoint wheelPos = event->position().toPoint();
     331
     332    const QPoint delta = event->angleDelta();
     333    const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
     334        ? delta.x() : delta.y();
     335#endif
     336
     337    if ( !wheelRect().contains( wheelPos ) )
    332338    {
    333339        event->ignore();
    … …  
    335341    }
    336342
    337     if ( d_data->isScrolling )
     343    if ( m_data->isScrolling )
    338344        return;
    339345
    … …  
    342348    double increment = 0.0;
    343349
    344     if ( ( event->modifiers() & Qt::ControlModifier) ||
     350    if ( ( event->modifiers() & Qt::ControlModifier ) ||
    345351        ( event->modifiers() & Qt::ShiftModifier ) )
    346352    {
    347353        // one page regardless of delta
    348         increment = d_data->singleStep * d_data->pageStepCount;
    349         if ( event->delta() < 0 )
     354        increment = m_data->singleStep * m_data->pageStepCount;
     355        if ( wheelDelta < 0 )
    350356            increment = -increment;
    351357    }
    352358    else
    353359    {
    354         const int numSteps = event->delta() / 120;
    355         increment = d_data->singleStep * numSteps;
    356     }
    357 
    358     if ( d_data->orientation == Qt::Vertical && d_data->inverted )
     360        const int numSteps = wheelDelta / 120;
     361        increment = m_data->singleStep * numSteps;
     362    }
     363
     364    if ( m_data->orientation == Qt::Vertical && m_data->inverted )
    359365        increment = -increment;
    360366
    361     double value = boundedValue( d_data->value + increment );
    362 
    363     if ( d_data->stepAlignment )
     367    double value = boundedValue( m_data->value + increment );
     368
     369    if ( m_data->stepAlignment )
    364370        value = alignedValue( value );
    365371
    366     if ( value != d_data->value )
    367     {
    368         d_data->value = value;
     372    if ( value != m_data->value )
     373    {
     374        m_data->value = value;
    369375        update();
    370376
    371         Q_EMIT valueChanged( d_data->value );
    372         Q_EMIT wheelMoved( d_data->value );
    373     }
    374 }
    375 
    376 /*!
    377   Handle key events
    378 
    379   - Qt::Key_Home\n
     377        Q_EMIT valueChanged( m_data->value );
     378        Q_EMIT wheelMoved( m_data->value );
     379    }
     380}
     381
     382/*!
     383   Handle key events
     384
     385   - Qt::Key_Home\n
    380386    Step to minimum()
    381387
    382   - Qt::Key_End\n
     388   - Qt::Key_End\n
    383389    Step to maximum()
    384390
    385   - Qt::Key_Up\n
     391   - Qt::Key_Up\n
    386392    In case of a horizontal or not inverted vertical wheel the value
    387393    will be incremented by the step size. For an inverted vertical wheel
    388394    the value will be decremented by the step size.
    389395
    390   - Qt::Key_Down\n
     396   - Qt::Key_Down\n
    391397    In case of a horizontal or not inverted vertical wheel the value
    392398    will be decremented by the step size. For an inverted vertical wheel
    393399    the value will be incremented by the step size.
    394400
    395   - Qt::Key_PageUp\n
     401   - Qt::Key_PageUp\n
    396402    The value will be incremented by pageStepSize() * singleStepSize().
    397403
    398   - Qt::Key_PageDown\n
     404   - Qt::Key_PageDown\n
    399405    The value will be decremented by pageStepSize() * singleStepSize().
    400406
    401   \param event Key event
    402 */
    403 void QwtWheel::keyPressEvent( QKeyEvent *event )
    404 {
    405     if ( d_data->isScrolling )
     407   \param event Key event
     408 */
     409void QwtWheel::keyPressEvent( QKeyEvent* event )
     410{
     411    if ( m_data->isScrolling )
    406412    {
    407413        // don't interfere mouse scrolling
    … …  
    409415    }
    410416
    411     double value = d_data->value;
     417    double value = m_data->value;
    412418    double increment = 0.0;
    413419
    … …  
    416422        case Qt::Key_Down:
    417423        {
    418             if ( d_data->orientation == Qt::Vertical && d_data->inverted )
    419                 increment = d_data->singleStep;
     424            if ( m_data->orientation == Qt::Vertical && m_data->inverted )
     425                increment = m_data->singleStep;
    420426            else
    421                 increment = -d_data->singleStep;
     427                increment = -m_data->singleStep;
    422428
    423429            break;
    … …  
    425431        case Qt::Key_Up:
    426432        {
    427             if ( d_data->orientation == Qt::Vertical && d_data->inverted )
    428                 increment = -d_data->singleStep;
     433            if ( m_data->orientation == Qt::Vertical && m_data->inverted )
     434                increment = -m_data->singleStep;
    429435            else
    430                 increment = d_data->singleStep;
     436                increment = m_data->singleStep;
    431437
    432438            break;
    … …  
    434440        case Qt::Key_Left:
    435441        {
    436             if ( d_data->orientation == Qt::Horizontal )
     442            if ( m_data->orientation == Qt::Horizontal )
    437443            {
    438                 if ( d_data->inverted )
    439                     increment = d_data->singleStep;
     444                if ( m_data->inverted )
     445                    increment = m_data->singleStep;
    440446                else
    441                     increment = -d_data->singleStep;
     447                    increment = -m_data->singleStep;
    442448            }
    443449            break;
    … …  
    445451        case Qt::Key_Right:
    446452        {
    447             if ( d_data->orientation == Qt::Horizontal )
     453            if ( m_data->orientation == Qt::Horizontal )
    448454            {
    449                 if ( d_data->inverted )
    450                     increment = -d_data->singleStep;
     455                if ( m_data->inverted )
     456                    increment = -m_data->singleStep;
    451457                else
    452                     increment = d_data->singleStep;
     458                    increment = m_data->singleStep;
    453459            }
    454460            break;
    … …  
    456462        case Qt::Key_PageUp:
    457463        {
    458             increment = d_data->pageStepCount * d_data->singleStep;
     464            increment = m_data->pageStepCount * m_data->singleStep;
    459465            break;
    460466        }
    461467        case Qt::Key_PageDown:
    462468        {
    463             increment = -d_data->pageStepCount * d_data->singleStep;
     469            increment = -m_data->pageStepCount * m_data->singleStep;
    464470            break;
    465471        }
    466472        case Qt::Key_Home:
    467473        {
    468             value = d_data->minimum;
     474            value = m_data->minimum;
    469475            break;
    470476        }
    471477        case Qt::Key_End:
    472478        {
    473             value = d_data->maximum;
     479            value = m_data->maximum;
    474480            break;
    475481        }
    476482        default:;
    477         {
    478             event->ignore();
    479         }
     483            {
     484                event->ignore();
     485            }
    480486    }
    481487
    … …  
    485491    if ( increment != 0.0 )
    486492    {
    487         value = boundedValue( d_data->value + increment );
    488 
    489         if ( d_data->stepAlignment )
     493        value = boundedValue( m_data->value + increment );
     494
     495        if ( m_data->stepAlignment )
    490496            value = alignedValue( value );
    491497    }
    492498
    493     if ( value != d_data->value )
    494     {
    495         d_data->value = value;
     499    if ( value != m_data->value )
     500    {
     501        m_data->value = value;
    496502        update();
    497503
    498         Q_EMIT valueChanged( d_data->value );
    499         Q_EMIT wheelMoved( d_data->value );
    500     }
    501 }
    502 
    503 /*!
    504   \brief Adjust the number of grooves in the wheel's surface.
    505 
    506   The number of grooves is limited to 6 <= count <= 50.
    507   Values outside this range will be clipped.
    508   The default value is 10.
    509 
    510   \param count Number of grooves per 360 degrees
    511   \sa tickCount()
    512 */
     504        Q_EMIT valueChanged( m_data->value );
     505        Q_EMIT wheelMoved( m_data->value );
     506    }
     507}
     508
     509/*!
     510   \brief Adjust the number of grooves in the wheel's surface.
     511
     512   The number of grooves is limited to 6 <= count <= 50.
     513   Values outside this range will be clipped.
     514   The default value is 10.
     515
     516   \param count Number of grooves per 360 degrees
     517   \sa tickCount()
     518 */
    513519void QwtWheel::setTickCount( int count )
    514520{
    515521    count = qBound( 6, count, 50 );
    516522
    517     if ( count != d_data->tickCount )
    518     {
    519         d_data->tickCount = qBound( 6, count, 50 );
     523    if ( count != m_data->tickCount )
     524    {
     525        m_data->tickCount = qBound( 6, count, 50 );
    520526        update();
    521527    }
    … …  
    523529
    524530/*!
    525   \return Number of grooves in the wheel's surface.
    526   \sa setTickCnt()
    527 */
     531   \return Number of grooves in the wheel's surface.
     532   \sa setTickCnt()
     533 */
    528534int QwtWheel::tickCount() const
    529535{
    530     return d_data->tickCount;
    531 }
    532 
    533 /*!
    534   \brief Set the wheel border width of the wheel.
    535 
    536   The wheel border must not be smaller than 1
    537   and is limited in dependence on the wheel's size.
    538   Values outside the allowed range will be clipped.
    539 
    540   The wheel border defaults to 2.
    541 
    542   \param borderWidth Border width
    543   \sa internalBorder()
    544 */
     536    return m_data->tickCount;
     537}
     538
     539/*!
     540   \brief Set the wheel border width of the wheel.
     541
     542   The wheel border must not be smaller than 1
     543   and is limited in dependence on the wheel's size.
     544   Values outside the allowed range will be clipped.
     545
     546   The wheel border defaults to 2.
     547
     548   \param borderWidth Border width
     549   \sa internalBorder()
     550 */
    545551void QwtWheel::setWheelBorderWidth( int borderWidth )
    546552{
    547553    const int d = qMin( width(), height() ) / 3;
    548554    borderWidth = qMin( borderWidth, d );
    549     d_data->wheelBorderWidth = qMax( borderWidth, 1 );
     555    m_data->wheelBorderWidth = qMax( borderWidth, 1 );
    550556    update();
    551557}
    … …  
    554560   \return Wheel border width
    555561   \sa setWheelBorderWidth()
    556 */
     562 */
    557563int QwtWheel::wheelBorderWidth() const
    558564{
    559     return d_data->wheelBorderWidth;
    560 }
    561 
    562 /*!
    563   \brief Set the border width
    564 
    565   The border defaults to 2.
    566 
    567   \param width Border width
    568   \sa borderWidth()
    569 */
     565    return m_data->wheelBorderWidth;
     566}
     567
     568/*!
     569   \brief Set the border width
     570
     571   The border defaults to 2.
     572
     573   \param width Border width
     574   \sa borderWidth()
     575 */
    570576void QwtWheel::setBorderWidth( int width )
    571577{
    572     d_data->borderWidth = qMax( width, 0 );
     578    m_data->borderWidth = qMax( width, 0 );
    573579    update();
    574580}
    … …  
    577583   \return Border width
    578584   \sa setBorderWidth()
    579 */
     585 */
    580586int QwtWheel::borderWidth() const
    581587{
    582     return d_data->borderWidth;
     588    return m_data->borderWidth;
    583589}
    584590
    585591/*!
    586592   \return Rectangle of the wheel without the outer border
    587 */
     593 */
    588594QRect QwtWheel::wheelRect() const
    589595{
    590     const int bw = d_data->borderWidth;
     596    const int bw = m_data->borderWidth;
    591597    return contentsRect().adjusted( bw, bw, -bw, -bw );
    592598}
    593599
    594600/*!
    595   \brief Set the total angle which the wheel can be turned.
    596 
    597   One full turn of the wheel corresponds to an angle of
    598   360 degrees. A total angle of n*360 degrees means
    599   that the wheel has to be turned n times around its axis
    600   to get from the minimum value to the maximum value.
    601 
    602   The default setting of the total angle is 360 degrees.
    603 
    604   \param angle total angle in degrees
    605   \sa totalAngle()
    606 */
     601   \brief Set the total angle which the wheel can be turned.
     602
     603   One full turn of the wheel corresponds to an angle of
     604   360 degrees. A total angle of n*360 degrees means
     605   that the wheel has to be turned n times around its axis
     606   to get from the minimum value to the maximum value.
     607
     608   The default setting of the total angle is 360 degrees.
     609
     610   \param angle total angle in degrees
     611   \sa totalAngle()
     612 */
    607613void QwtWheel::setTotalAngle( double angle )
    608614{
    … …  
    610616        angle = 0.0;
    611617
    612     d_data->totalAngle = angle;
     618    m_data->totalAngle = angle;
    613619    update();
    614620}
    615621
    616622/*!
    617   \return Total angle which the wheel can be turned.
    618   \sa setTotalAngle()
    619 */
     623   \return Total angle which the wheel can be turned.
     624   \sa setTotalAngle()
     625 */
    620626double QwtWheel::totalAngle() const
    621627{
    622     return d_data->totalAngle;
    623 }
    624 
    625 /*!
    626   \brief Set the wheel's orientation.
    627 
    628   The default orientation is Qt::Horizontal.
    629 
    630   \param orientation Qt::Horizontal or Qt::Vertical.
    631   \sa orientation()
    632 */
     628    return m_data->totalAngle;
     629}
     630
     631/*!
     632   \brief Set the wheel's orientation.
     633
     634   The default orientation is Qt::Horizontal.
     635
     636   \param orientation Qt::Horizontal or Qt::Vertical.
     637   \sa orientation()
     638 */
    633639void QwtWheel::setOrientation( Qt::Orientation orientation )
    634640{
    635     if ( d_data->orientation == orientation )
     641    if ( m_data->orientation == orientation )
    636642        return;
    637643
    … …  
    645651    }
    646652
    647     d_data->orientation = orientation;
     653    m_data->orientation = orientation;
    648654    update();
    649655}
    650656
    651657/*!
    652   \return Orientation
    653   \sa setOrientation()
    654 */
     658   \return Orientation
     659   \sa setOrientation()
     660 */
    655661Qt::Orientation QwtWheel::orientation() const
    656662{
    657     return d_data->orientation;
    658 }
    659 
    660 /*!
    661   \brief Specify the visible portion of the wheel.
    662 
    663   You may use this function for fine-tuning the appearance of
    664   the wheel. The default value is 175 degrees. The value is
    665   limited from 10 to 175 degrees.
    666 
    667   \param angle Visible angle in degrees
    668   \sa viewAngle(), setTotalAngle()
    669 */
     663    return m_data->orientation;
     664}
     665
     666/*!
     667   \brief Specify the visible portion of the wheel.
     668
     669   You may use this function for fine-tuning the appearance of
     670   the wheel. The default value is 175 degrees. The value is
     671   limited from 10 to 175 degrees.
     672
     673   \param angle Visible angle in degrees
     674   \sa viewAngle(), setTotalAngle()
     675 */
    670676void QwtWheel::setViewAngle( double angle )
    671677{
    672     d_data->viewAngle = qBound( 10.0, angle, 175.0 );
     678    m_data->viewAngle = qBound( 10.0, angle, 175.0 );
    673679    update();
    674680}
    675681
    676682/*!
    677   \return Visible portion of the wheel
    678   \sa setViewAngle(), totalAngle()
    679 */
     683   \return Visible portion of the wheel
     684   \sa setViewAngle(), totalAngle()
     685 */
    680686double QwtWheel::viewAngle() const
    681687{
    682     return d_data->viewAngle;
    683 }
    684 
    685 /*!
    686   Determine the value corresponding to a specified point
    687 
    688   \param pos Position
    689   \return Value corresponding to pos
    690 */
    691 double QwtWheel::valueAt( const QPoint &pos ) const
     688    return m_data->viewAngle;
     689}
     690
     691/*!
     692   Determine the value corresponding to a specified point
     693
     694   \param pos Position
     695   \return Value corresponding to pos
     696 */
     697double QwtWheel::valueAt( const QPoint& pos ) const
    692698{
    693699    const QRectF rect = wheelRect();
    694700
    695701    double w, dx;
    696     if ( d_data->orientation == Qt::Vertical )
     702    if ( m_data->orientation == Qt::Vertical )
    697703    {
    698704        w = rect.height();
    … …  
    708714        return 0.0;
    709715
    710     if ( d_data->inverted )
     716    if ( m_data->inverted )
    711717    {
    712718        dx = w - dx;
    … …  
    715721    // w pixels is an arc of viewAngle degrees,
    716722    // so we convert change in pixels to change in angle
    717     const double ang = dx * d_data->viewAngle / w;
     723    const double ang = dx * m_data->viewAngle / w;
    718724
    719725    // value range maps to totalAngle degrees,
    720726    // so convert the change in angle to a change in value
    721     const double val = ang * ( maximum() - minimum() ) / d_data->totalAngle;
     727    const double val = ang * ( maximum() - minimum() ) / m_data->totalAngle;
    722728
    723729    return val;
    … …  
    727733   \brief Qt Paint Event
    728734   \param event Paint event
    729 */
    730 void QwtWheel::paintEvent( QPaintEvent *event )
     735 */
     736void QwtWheel::paintEvent( QPaintEvent* event )
    731737{
    732738    QPainter painter( this );
    … …  
    734740
    735741    QStyleOption opt;
    736     opt.init(this);
     742    opt.initFrom(this);
    737743    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
    738744
    739745    qDrawShadePanel( &painter,
    740         contentsRect(), palette(), true, d_data->borderWidth );
     746        contentsRect(), palette(), true, m_data->borderWidth );
    741747
    742748    drawWheelBackground( &painter, wheelRect() );
    … …  
    752758   \param painter Painter
    753759   \param rect Geometry for the wheel
    754 */
     760 */
    755761void QwtWheel::drawWheelBackground(
    756     QPainter *painter, const QRectF &rect )
     762    QPainter* painter, const QRectF& rect )
    757763{
    758764    painter->save();
    … …  
    762768    //  draw shaded background
    763769    QLinearGradient gradient( rect.topLeft(),
    764         ( d_data->orientation == Qt::Horizontal ) ? rect.topRight() : rect.bottomLeft() );
     770        ( m_data->orientation == Qt::Horizontal ) ? rect.topRight() : rect.bottomLeft() );
    765771    gradient.setColorAt( 0.0, pal.color( QPalette::Button ) );
    766772    gradient.setColorAt( 0.2, pal.color( QPalette::Midlight ) );
    … …  
    773779
    774780    const QPen lightPen( palette().color( QPalette::Light ),
    775         d_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap );
     781        m_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap );
    776782    const QPen darkPen( pal.color( QPalette::Dark ),
    777         d_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap );
    778 
    779     const double bw2 = 0.5 * d_data->wheelBorderWidth;
    780 
    781     if ( d_data->orientation == Qt::Horizontal )
     783        m_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap );
     784
     785    const double bw2 = 0.5 * m_data->wheelBorderWidth;
     786
     787    if ( m_data->orientation == Qt::Horizontal )
    782788    {
    783789        painter->setPen( lightPen );
    … …  
    808814   \param painter Painter
    809815   \param rect Geometry for the wheel
    810 */
    811 void QwtWheel::drawTicks( QPainter *painter, const QRectF &rect )
    812 {
    813     const double range = d_data->maximum - d_data->minimum;
    814 
    815     if ( range == 0.0 || d_data->totalAngle == 0.0 )
     816 */
     817void QwtWheel::drawTicks( QPainter* painter, const QRectF& rect )
     818{
     819    const double range = m_data->maximum - m_data->minimum;
     820
     821    if ( range == 0.0 || m_data->totalAngle == 0.0 )
    816822    {
    817823        return;
    … …  
    823829        0, Qt::SolidLine, Qt::FlatCap );
    824830
    825     const double cnvFactor = qAbs( d_data->totalAngle / range );
    826     const double halfIntv = 0.5 * d_data->viewAngle / cnvFactor;
     831    const double cnvFactor = qAbs( m_data->totalAngle / range );
     832    const double halfIntv = 0.5 * m_data->viewAngle / cnvFactor;
    827833    const double loValue = value() - halfIntv;
    828834    const double hiValue = value() + halfIntv;
    829     const double tickWidth = 360.0 / double( d_data->tickCount ) / cnvFactor;
    830     const double sinArc = qFastSin( d_data->viewAngle * M_PI / 360.0 );
    831 
    832     if ( d_data->orientation == Qt::Horizontal )
     835    const double tickWidth = 360.0 / double( m_data->tickCount ) / cnvFactor;
     836    const double sinArc = qFastSin( m_data->viewAngle * M_PI / 360.0 );
     837
     838    if ( m_data->orientation == Qt::Horizontal )
    833839    {
    834840        const double radius = rect.width() * 0.5;
    835841
    836         double l1 = rect.top() + d_data->wheelBorderWidth;
    837         double l2 = rect.bottom() - d_data->wheelBorderWidth - 1;
     842        double l1 = rect.top() + m_data->wheelBorderWidth;
     843        double l2 = rect.bottom() - m_data->wheelBorderWidth - 1;
    838844
    839845        // draw one point over the border if border > 1
    840         if ( d_data->wheelBorderWidth > 1 )
     846        if ( m_data->wheelBorderWidth > 1 )
    841847        {
    842848            l1--;
    … …  
    848854
    849855        // draw tick marks
    850         for ( double tickValue = ::ceil( loValue / tickWidth ) * tickWidth;
     856        for ( double tickValue = std::ceil( loValue / tickWidth ) * tickWidth;
    851857            tickValue < hiValue; tickValue += tickWidth )
    852858        {
    … …  
    857863
    858864            double tickPos;
    859             if ( d_data->inverted )
     865            if ( m_data->inverted )
    860866                tickPos = rect.left() + off;
    861867            else
    … …  
    865871            {
    866872                painter->setPen( darkPen );
    867                 painter->drawLine( QPointF( tickPos - 1 , l1 ),
     873                painter->drawLine( QPointF( tickPos - 1, l1 ),
    868874                    QPointF( tickPos - 1,  l2 ) );
    869875                painter->setPen( lightPen );
    … …  
    877883        const double radius = rect.height() * 0.5;
    878884
    879         double l1 = rect.left() + d_data->wheelBorderWidth;
    880         double l2 = rect.right() - d_data->wheelBorderWidth - 1;
    881 
    882         if ( d_data->wheelBorderWidth > 1 )
     885        double l1 = rect.left() + m_data->wheelBorderWidth;
     886        double l2 = rect.right() - m_data->wheelBorderWidth - 1;
     887
     888        if ( m_data->wheelBorderWidth > 1 )
    883889        {
    884890            l1--;
    … …  
    889895        const double minpos = rect.top() + 2;
    890896
    891         for ( double tickValue = ::ceil( loValue / tickWidth ) * tickWidth;
     897        for ( double tickValue = std::ceil( loValue / tickWidth ) * tickWidth;
    892898            tickValue < hiValue; tickValue += tickWidth )
    893899        {
    … …  
    899905            double tickPos;
    900906
    901             if ( d_data->inverted )
     907            if ( m_data->inverted )
    902908                tickPos = rect.bottom() - off;
    903909            else
    … …  
    918924
    919925/*!
    920   \brief Set the width of the wheel
    921 
    922   Corresponds to the wheel height for horizontal orientation,
    923   and the wheel width for vertical orientation.
    924 
    925   \param width the wheel's width
    926   \sa wheelWidth()
    927 */
     926   \brief Set the width of the wheel
     927
     928   Corresponds to the wheel height for horizontal orientation,
     929   and the wheel width for vertical orientation.
     930
     931   \param width the wheel's width
     932   \sa wheelWidth()
     933 */
    928934void QwtWheel::setWheelWidth( int width )
    929935{
    930     d_data->wheelWidth = width;
     936    m_data->wheelWidth = width;
    931937    update();
    932938}
    933939
    934940/*!
    935   \return Width of the wheel
    936   \sa setWheelWidth()
    937 */
     941   \return Width of the wheel
     942   \sa setWheelWidth()
     943 */
    938944int QwtWheel::wheelWidth() const
    939945{
    940     return d_data->wheelWidth;
    941 }
    942 
    943 /*!
    944   \return a size hint
    945 */
     946    return m_data->wheelWidth;
     947}
     948
     949/*!
     950   \return a size hint
     951 */
    946952QSize QwtWheel::sizeHint() const
    947953{
    948954    const QSize hint = minimumSizeHint();
    949     return hint.expandedTo( QApplication::globalStrut() );
    950 }
    951 
    952 /*!
    953   \return Minimum size hint
    954   \warning The return value is based on the wheel width.
    955 */
     955    return qwtExpandedToGlobalStrut( hint );
     956}
     957
     958/*!
     959   \return Minimum size hint
     960   \warning The return value is based on the wheel width.
     961 */
    956962QSize QwtWheel::minimumSizeHint() const
    957963{
    958     QSize sz( 3 * d_data->wheelWidth + 2 * d_data->borderWidth,
    959         d_data->wheelWidth + 2 * d_data->borderWidth );
    960     if ( d_data->orientation != Qt::Horizontal )
     964    QSize sz( 3 * m_data->wheelWidth + 2 * m_data->borderWidth,
     965        m_data->wheelWidth + 2 * m_data->borderWidth );
     966    if ( m_data->orientation != Qt::Horizontal )
    961967        sz.transpose();
    962968
    … …  
    965971
    966972/*!
    967   \brief Set the step size of the counter
    968 
    969   A value <= 0.0 disables stepping
    970 
    971   \param stepSize Single step size
    972   \sa singleStep(), setPageStepCount()
    973 */
     973   \brief Set the step size of the counter
     974
     975   A value <= 0.0 disables stepping
     976
     977   \param stepSize Single step size
     978   \sa singleStep(), setPageStepCount()
     979 */
    974980void QwtWheel::setSingleStep( double stepSize )
    975981{
    976     d_data->singleStep = qMax( stepSize, 0.0 );
    977 }
    978 
    979 /*!
    980   \return Single step size
    981   \sa setSingleStep()
     982    m_data->singleStep = qwtMaxF( stepSize, 0.0 );
     983}
     984
     985/*!
     986   \return Single step size
     987   \sa setSingleStep()
    982988 */
    983989double QwtWheel::singleStep() const
    984990{
    985     return d_data->singleStep;
    986 }
    987 
    988 /*!
    989   \brief En/Disable step alignment
    990 
    991   When step alignment is enabled value changes initiated by
    992   user input ( mouse, keyboard, wheel ) are aligned to
    993   the multiples of the single step.
    994 
    995   \param on On/Off
    996   \sa stepAlignment(), setSingleStep()
     991    return m_data->singleStep;
     992}
     993
     994/*!
     995   \brief En/Disable step alignment
     996
     997   When step alignment is enabled value changes initiated by
     998   user input ( mouse, keyboard, wheel ) are aligned to
     999   the multiples of the single step.
     1000
     1001   \param on On/Off
     1002   \sa stepAlignment(), setSingleStep()
    9971003 */
    9981004void QwtWheel::setStepAlignment( bool on )
    9991005{
    1000     if ( on != d_data->stepAlignment )
    1001     {
    1002         d_data->stepAlignment = on;
    1003     }
    1004 }
    1005 
    1006 /*!
    1007   \return True, when the step alignment is enabled
    1008   \sa setStepAlignment(), singleStep()
     1006    if ( on != m_data->stepAlignment )
     1007    {
     1008        m_data->stepAlignment = on;
     1009    }
     1010}
     1011
     1012/*!
     1013   \return True, when the step alignment is enabled
     1014   \sa setStepAlignment(), singleStep()
    10091015 */
    10101016bool QwtWheel::stepAlignment() const
    10111017{
    1012     return d_data->stepAlignment;
    1013 }
    1014 
    1015 /*!
    1016   \brief Set the page step count
    1017 
    1018   pageStepCount is a multiplicator for the single step size
    1019   that typically corresponds to the user pressing PageUp or PageDown.
    1020 
    1021   A value of 0 disables page stepping.
    1022 
    1023   The default value is 1.
    1024 
    1025   \param count Multiplicator for the single step size
    1026   \sa pageStepCount(), setSingleStep()
     1018    return m_data->stepAlignment;
     1019}
     1020
     1021/*!
     1022   \brief Set the page step count
     1023
     1024   pageStepCount is a multiplicator for the single step size
     1025   that typically corresponds to the user pressing PageUp or PageDown.
     1026
     1027   A value of 0 disables page stepping.
     1028
     1029   The default value is 1.
     1030
     1031   \param count Multiplicator for the single step size
     1032   \sa pageStepCount(), setSingleStep()
    10271033 */
    10281034void QwtWheel::setPageStepCount( int count )
    10291035{
    1030     d_data->pageStepCount = qMax( 0, count );
    1031 }
    1032 
    1033 /*!
    1034   \return Page step count
    1035   \sa setPageStepCount(), singleStep()
     1036    m_data->pageStepCount = qMax( 0, count );
     1037}
     1038
     1039/*!
     1040   \return Page step count
     1041   \sa setPageStepCount(), singleStep()
    10361042 */
    10371043int QwtWheel::pageStepCount() const
    10381044{
    1039     return d_data->pageStepCount;
    1040 }
    1041 
    1042 /*!
    1043   \brief Set the minimum and maximum values
    1044 
    1045   The maximum is adjusted if necessary to ensure that the range remains valid.
    1046   The value might be modified to be inside of the range.
    1047 
    1048   \param min Minimum value
    1049   \param max Maximum value
    1050 
    1051   \sa minimum(), maximum()
     1045    return m_data->pageStepCount;
     1046}
     1047
     1048/*!
     1049   \brief Set the minimum and maximum values
     1050
     1051   The maximum is adjusted if necessary to ensure that the range remains valid.
     1052   The value might be modified to be inside of the range.
     1053
     1054   \param min Minimum value
     1055   \param max Maximum value
     1056
     1057   \sa minimum(), maximum()
    10521058 */
    10531059void QwtWheel::setRange( double min, double max )
    10541060{
    1055     max = qMax( min, max );
    1056 
    1057     if ( d_data->minimum == min && d_data->maximum == max )
     1061    max = qwtMaxF( min, max );
     1062
     1063    if ( m_data->minimum == min && m_data->maximum == max )
    10581064        return;
    10591065
    1060     d_data->minimum = min;
    1061     d_data->maximum = max;
    1062 
    1063     if ( d_data->value < min || d_data->value > max )
    1064     {
    1065         d_data->value = qBound( min, d_data->value, max );
     1066    m_data->minimum = min;
     1067    m_data->maximum = max;
     1068
     1069    if ( m_data->value < min || m_data->value > max )
     1070    {
     1071        m_data->value = qBound( min, m_data->value, max );
    10661072
    10671073        update();
    1068         Q_EMIT valueChanged( d_data->value );
    1069     }
    1070 }
    1071 /*!
    1072   Set the minimum value of the range
    1073 
    1074   \param value Minimum value
    1075   \sa setRange(), setMaximum(), minimum()
    1076 
    1077   \note The maximum is adjusted if necessary to ensure that the range remains valid.
    1078 */
     1074        Q_EMIT valueChanged( m_data->value );
     1075    }
     1076}
     1077/*!
     1078   Set the minimum value of the range
     1079
     1080   \param value Minimum value
     1081   \sa setRange(), setMaximum(), minimum()
     1082
     1083   \note The maximum is adjusted if necessary to ensure that the range remains valid.
     1084 */
    10791085void QwtWheel::setMinimum( double value )
    10801086{
    … …  
    10831089
    10841090/*!
    1085   \return The minimum of the range
    1086   \sa setRange(), setMinimum(), maximum()
    1087 */
     1091   \return The minimum of the range
     1092   \sa setRange(), setMinimum(), maximum()
     1093 */
    10881094double QwtWheel::minimum() const
    10891095{
    1090     return d_data->minimum;
    1091 }
    1092 
    1093 /*!
    1094   Set the maximum value of the range
    1095 
    1096   \param value Maximum value
    1097   \sa setRange(), setMinimum(), maximum()
    1098 */
     1096    return m_data->minimum;
     1097}
     1098
     1099/*!
     1100   Set the maximum value of the range
     1101
     1102   \param value Maximum value
     1103   \sa setRange(), setMinimum(), maximum()
     1104 */
    10991105void QwtWheel::setMaximum( double value )
    11001106{
    … …  
    11031109
    11041110/*!
    1105   \return The maximum of the range
    1106   \sa setRange(), setMaximum(), minimum()
    1107 */
     1111   \return The maximum of the range
     1112   \sa setRange(), setMaximum(), minimum()
     1113 */
    11081114double QwtWheel::maximum() const
    11091115{
    1110     return d_data->maximum;
    1111 }
    1112 
    1113 /*!
    1114   \brief Set a new value without adjusting to the step raster
    1115 
    1116   \param value New value
    1117 
    1118   \sa value(), valueChanged()
    1119   \warning The value is clipped when it lies outside the range.
    1120 */
     1116    return m_data->maximum;
     1117}
     1118
     1119/*!
     1120   \brief Set a new value without adjusting to the step raster
     1121
     1122   \param value New value
     1123
     1124   \sa value(), valueChanged()
     1125   \warning The value is clipped when it lies outside the range.
     1126 */
    11211127void QwtWheel::setValue( double value )
    11221128{
    11231129    stopFlying();
    1124     d_data->isScrolling = false;
    1125 
    1126     value = qBound( d_data->minimum, value, d_data->maximum );
    1127 
    1128     if ( d_data->value != value )
    1129     {
    1130         d_data->value = value;
     1130    m_data->isScrolling = false;
     1131
     1132    value = qBound( m_data->minimum, value, m_data->maximum );
     1133
     1134    if ( m_data->value != value )
     1135    {
     1136        m_data->value = value;
    11311137
    11321138        update();
    1133         Q_EMIT valueChanged( d_data->value );
    1134     }
    1135 }
    1136 
    1137 /*!
    1138   \return Current value of the wheel
    1139   \sa setValue(), valueChanged()
     1139        Q_EMIT valueChanged( m_data->value );
     1140    }
     1141}
     1142
     1143/*!
     1144   \return Current value of the wheel
     1145   \sa setValue(), valueChanged()
    11401146 */
    11411147double QwtWheel::value() const
    11421148{
    1143     return d_data->value;
    1144 }
    1145 
    1146 /*!
    1147   \brief En/Disable inverted appearance
    1148 
    1149   An inverted wheel increases its values in the opposite direction.
    1150   The direction of an inverted horizontal wheel will be from right to left
    1151   an inverted vertical wheel will increase from bottom to top.
    1152 
    1153   \param on En/Disable inverted appearance
    1154   \sa isInverted()
     1149    return m_data->value;
     1150}
     1151
     1152/*!
     1153   \brief En/Disable inverted appearance
     1154
     1155   An inverted wheel increases its values in the opposite direction.
     1156   The direction of an inverted horizontal wheel will be from right to left
     1157   an inverted vertical wheel will increase from bottom to top.
     1158
     1159   \param on En/Disable inverted appearance
     1160   \sa isInverted()
    11551161
    11561162 */
    11571163void QwtWheel::setInverted( bool on )
    11581164{
    1159     if ( d_data->inverted != on )
    1160     {
    1161         d_data->inverted = on;
     1165    if ( m_data->inverted != on )
     1166    {
     1167        m_data->inverted = on;
    11621168        update();
    11631169    }
    … …  
    11651171
    11661172/*!
    1167   \return True, when the wheel is inverted
    1168   \sa setInverted()
     1173   \return True, when the wheel is inverted
     1174   \sa setInverted()
    11691175 */
    11701176bool QwtWheel::isInverted() const
    11711177{
    1172     return d_data->inverted;
    1173 }
    1174 
    1175 /*!
    1176   \brief En/Disable wrapping
    1177 
    1178   If wrapping is true stepping up from maximum() value will take
    1179   you to the minimum() value and vice versa.
    1180 
    1181   \param on En/Disable wrapping
    1182   \sa wrapping()
     1178    return m_data->inverted;
     1179}
     1180
     1181/*!
     1182   \brief En/Disable wrapping
     1183
     1184   If wrapping is true stepping up from maximum() value will take
     1185   you to the minimum() value and vice versa.
     1186
     1187   \param on En/Disable wrapping
     1188   \sa wrapping()
    11831189 */
    11841190void QwtWheel::setWrapping( bool on )
    11851191{
    1186     d_data->wrapping = on;
    1187 }
    1188 
    1189 /*!
    1190   \return True, when wrapping is set
    1191   \sa setWrapping()
     1192    m_data->wrapping = on;
     1193}
     1194
     1195/*!
     1196   \return True, when wrapping is set
     1197   \sa setWrapping()
    11921198 */
    11931199bool QwtWheel::wrapping() const
    11941200{
    1195     return d_data->wrapping;
    1196 }
    1197 
    1198 /*!
    1199   \brief Set the slider's mass for flywheel effect.
    1200 
    1201   If the slider's mass is greater then 0, it will continue
    1202   to move after the mouse button has been released. Its speed
    1203   decreases with time at a rate depending on the slider's mass.
    1204   A large mass means that it will continue to move for a
    1205   long time.
    1206 
    1207   Derived widgets may overload this function to make it public.
    1208 
    1209   \param mass New mass in kg
    1210 
    1211   \bug If the mass is smaller than 1g, it is set to zero.
     1201    return m_data->wrapping;
     1202}
     1203
     1204/*!
     1205   \brief Set the slider's mass for flywheel effect.
     1206
     1207   If the slider's mass is greater then 0, it will continue
     1208   to move after the mouse button has been released. Its speed
     1209   decreases with time at a rate depending on the slider's mass.
     1210   A large mass means that it will continue to move for a
     1211   long time.
     1212
     1213   Derived widgets may overload this function to make it public.
     1214
     1215   \param mass New mass in kg
     1216
     1217   \bug If the mass is smaller than 1g, it is set to zero.
    12121218       The maximal mass is limited to 100kg.
    1213   \sa mass()
    1214 */
     1219   \sa mass()
     1220 */
    12151221void QwtWheel::setMass( double mass )
    12161222{
    12171223    if ( mass < 0.001 )
    12181224    {
    1219         d_data->mass = 0.0;
     1225        m_data->mass = 0.0;
    12201226    }
    12211227    else
    12221228    {
    1223         d_data->mass = qMin( 100.0, mass );
    1224     }
    1225 
    1226     if ( d_data->mass <= 0.0 )
     1229        m_data->mass = qwtMinF( 100.0, mass );
     1230    }
     1231
     1232    if ( m_data->mass <= 0.0 )
    12271233        stopFlying();
    12281234}
    12291235
    12301236/*!
    1231   \return mass
    1232   \sa setMass()
    1233 */
     1237   \return mass
     1238   \sa setMass()
     1239 */
    12341240double QwtWheel::mass() const
    12351241{
    1236     return d_data->mass;
     1242    return m_data->mass;
    12371243}
    12381244
    … …  
    12401246void QwtWheel::stopFlying()
    12411247{
    1242     if ( d_data->timerId != 0 )
    1243     {
    1244         killTimer( d_data->timerId );
    1245         d_data->timerId = 0;
    1246         d_data->speed = 0.0;
     1248    if ( m_data->timerId != 0 )
     1249    {
     1250        killTimer( m_data->timerId );
     1251        m_data->timerId = 0;
     1252        m_data->speed = 0.0;
    12471253    }
    12481254}
    … …  
    12501256double QwtWheel::boundedValue( double value ) const
    12511257{
    1252     const double range = d_data->maximum - d_data->minimum;
    1253 
    1254     if ( d_data->wrapping && range >= 0.0 )
    1255     {
    1256         if ( value < d_data->minimum )
    1257         {
    1258             value += ::ceil( ( d_data->minimum - value ) / range ) * range;
    1259         }
    1260         else if ( value > d_data->maximum )
    1261         {
    1262             value -= ::ceil( ( value - d_data->maximum ) / range ) * range;
     1258    const double range = m_data->maximum - m_data->minimum;
     1259
     1260    if ( m_data->wrapping && range >= 0.0 )
     1261    {
     1262        if ( value < m_data->minimum )
     1263        {
     1264            value += std::ceil( ( m_data->minimum - value ) / range ) * range;
     1265        }
     1266        else if ( value > m_data->maximum )
     1267        {
     1268            value -= std::ceil( ( value - m_data->maximum ) / range ) * range;
    12631269        }
    12641270    }
    12651271    else
    12661272    {
    1267         value = qBound( d_data->minimum, value, d_data->maximum );
     1273        value = qBound( m_data->minimum, value, m_data->maximum );
    12681274    }
    12691275
    … …  
    12731279double QwtWheel::alignedValue( double value ) const
    12741280{
    1275     const double stepSize = d_data->singleStep;
     1281    const double stepSize = m_data->singleStep;
    12761282
    12771283    if ( stepSize > 0.0 )
    12781284    {
    1279         value = d_data->minimum +
    1280             qRound( ( value - d_data->minimum ) / stepSize ) * stepSize;
     1285        value = m_data->minimum +
     1286            qRound( ( value - m_data->minimum ) / stepSize ) * stepSize;
    12811287
    12821288        if ( stepSize > 1e-12 )
    … …  
    12871293                value = 0.0;
    12881294            }
    1289             else if ( qFuzzyCompare( value, d_data->maximum ) )
     1295            else if ( qFuzzyCompare( value, m_data->maximum ) )
    12901296            {
    12911297                // correct rounding error at the border
    1292                 value = d_data->maximum;
     1298                value = m_data->maximum;
    12931299            }
    12941300        }
    … …  
    12981304}
    12991305
     1306#include "moc_qwt_wheel.cpp"
  • trunk/BNC/qwt/qwt_wheel.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1515
    1616/*!
    17   \brief The Wheel Widget
     17   \brief The Wheel Widget
    1818
    19   The wheel widget can be used to change values over a very large range
    20   in very small steps. Using the setMass() member, it can be configured
    21   as a flying wheel.
     19   The wheel widget can be used to change values over a very large range
     20   in very small steps. Using the setMass() member, it can be configured
     21   as a flying wheel.
    2222
    23   The default range of the wheel is [0.0, 100.0]
     23   The default range of the wheel is [0.0, 100.0]
    2424
    25   \sa The radio example.
    26 */
    27 class QWT_EXPORT QwtWheel: public QWidget
     25   \sa The radio example.
     26 */
     27class QWT_EXPORT QwtWheel : public QWidget
    2828{
    2929    Q_OBJECT
    3030
    3131    Q_PROPERTY( Qt::Orientation orientation
    32                 READ orientation WRITE setOrientation )
     32        READ orientation WRITE setOrientation )
    3333
    34     Q_PROPERTY( double value READ value WRITE setValue )
     34    Q_PROPERTY( double value READ value WRITE setValue NOTIFY valueChanged USER true  )
     35
    3536    Q_PROPERTY( double minimum READ minimum WRITE setMinimum )
    3637    Q_PROPERTY( double maximum READ maximum WRITE setMaximum )
    … …  
    5455    Q_PROPERTY( int wheelBorderWidth READ wheelBorderWidth WRITE setWheelBorderWidth )
    5556
    56 public:
    57     explicit QwtWheel( QWidget *parent = NULL );
     57  public:
     58    explicit QwtWheel( QWidget* parent = NULL );
    5859    virtual ~QwtWheel();
    5960
    … …  
    109110    double mass() const;
    110111
    111 public Q_SLOTS:
     112  public Q_SLOTS:
    112113    void setValue( double );
    113114    void setTotalAngle ( double );
    … …  
    115116    void setMass( double );
    116117
    117 Q_SIGNALS:
     118  Q_SIGNALS:
    118119
    119120    /*!
    120       \brief Notify a change of value.
     121       \brief Notify a change of value.
    121122
    122       When tracking is enabled this signal will be emitted every
    123       time the value changes.
     123       When tracking is enabled this signal will be emitted every
     124       time the value changes.
    124125
    125       \param value new value
    126       \sa setTracking()
    127     */
     126       \param value new value
     127       \sa setTracking()
     128     */
    128129    void valueChanged( double value );
    129130
    130131    /*!
    131       This signal is emitted when the user presses the
    132       the wheel with the mouse
    133     */
     132       This signal is emitted when the user presses the
     133       the wheel with the mouse
     134     */
    134135    void wheelPressed();
    135136
    136137    /*!
    137       This signal is emitted when the user releases the mouse
    138     */
     138       This signal is emitted when the user releases the mouse
     139     */
    139140    void wheelReleased();
    140141
    141142    /*!
    142       This signal is emitted when the user moves the
    143       wheel with the mouse.
     143       This signal is emitted when the user moves the
     144       wheel with the mouse.
    144145
    145       \param value new value
    146     */
     146       \param value new value
     147     */
    147148    void wheelMoved( double value );
    148149
    149 protected:
    150     virtual void paintEvent( QPaintEvent * );
    151     virtual void mousePressEvent( QMouseEvent * );
    152     virtual void mouseReleaseEvent( QMouseEvent * );
    153     virtual void mouseMoveEvent( QMouseEvent * );
    154     virtual void keyPressEvent( QKeyEvent * );
    155     virtual void wheelEvent( QWheelEvent * );
    156     virtual void timerEvent( QTimerEvent * );
     150  protected:
     151    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
     152    virtual void mousePressEvent( QMouseEvent* ) QWT_OVERRIDE;
     153    virtual void mouseReleaseEvent( QMouseEvent* ) QWT_OVERRIDE;
     154    virtual void mouseMoveEvent( QMouseEvent* ) QWT_OVERRIDE;
     155    virtual void keyPressEvent( QKeyEvent* ) QWT_OVERRIDE;
     156    virtual void wheelEvent( QWheelEvent* ) QWT_OVERRIDE;
     157    virtual void timerEvent( QTimerEvent* ) QWT_OVERRIDE;
    157158
    158159    void stopFlying();
    … …  
    160161    QRect wheelRect() const;
    161162
    162     virtual QSize sizeHint() const;
    163     virtual QSize minimumSizeHint() const;
     163    virtual QSize sizeHint() const QWT_OVERRIDE;
     164    virtual QSize minimumSizeHint() const QWT_OVERRIDE;
    164165
    165     virtual void drawTicks( QPainter *, const QRectF & );
    166     virtual void drawWheelBackground( QPainter *, const QRectF & );
     166    virtual void drawTicks( QPainter*, const QRectF& );
     167    virtual void drawWheelBackground( QPainter*, const QRectF& );
    167168
    168     virtual double valueAt( const QPoint & ) const;
     169    virtual double valueAt( const QPoint& ) const;
    169170
    170 private:
     171  private:
    171172    double alignedValue( double ) const;
    172173    double boundedValue( double ) const;
    173174
    174175    class PrivateData;
    175     PrivateData *d_data;
     176    PrivateData* m_data;
    176177};
    177178
  • trunk/BNC/qwt/qwt_widget_overlay.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_widget_overlay.h"
    1111#include "qwt_painter.h"
     12
    1213#include <qpainter.h>
    1314#include <qpaintengine.h>
    … …  
    1617#include <qevent.h>
    1718
     19#include <cstdlib>
     20
    1821static QImage::Format qwtMaskImageFormat()
    1922{
    … …  
    2427}
    2528
    26 static QRegion qwtAlphaMask(
    27     const QImage& image, const QVector<QRect> &rects )
     29static QRegion qwtAlphaMask( const QImage& image, const QRegion& region )
    2830{
    2931    const int w = image.width();
    3032    const int h = image.height();
    3133
    32     QRegion region;
     34    QRegion mask;
    3335    QRect rect;
    3436
     37#if QT_VERSION >= 0x050800
     38    for ( QRegion::const_iterator it = region.cbegin();
     39        it != region.cend(); ++it )
     40    {
     41        const QRect& r = *it;
     42#else
     43    const QVector< QRect > rects = region.rects();
    3544    for ( int i = 0; i < rects.size(); i++ )
    3645    {
     46        const QRect& r = rects[i];
     47#endif
    3748        int x1, x2, y1, y2;
    38         rects[i].getCoords( &x1, &y1, &x2, &y2 );
     49        r.getCoords( &x1, &y1, &x2, &y2 );
    3950
    4051        x1 = qMax( x1, 0 );
    … …  
    4859            int rx0 = -1;
    4960
    50             const uint *line =
    51                 reinterpret_cast<const uint *> ( image.scanLine( y ) ) + x1;
     61            const uint* line =
     62                reinterpret_cast< const uint* > ( image.scanLine( y ) ) + x1;
    5263            for ( int x = x1; x <= x2; x++ )
    5364            {
    … …  
    5869                    {
    5970                        rect.setCoords( rx0, y, x - 1, y );
    60                         region += rect;
     71                        mask += rect;
    6172                    }
    6273                    else
    … …  
    7283            {
    7384                rect.setCoords( rx0, y, x2, y );
    74                 region = region.united( rect );
     85                mask = mask.united( rect );
    7586            }
    7687        }
    7788    }
    7889
    79     return region;
     90    return mask;
    8091}
    8192
    8293class QwtWidgetOverlay::PrivateData
    8394{
    84 public:
    85     PrivateData():
    86         maskMode( QwtWidgetOverlay::MaskHint ),
    87         renderMode( QwtWidgetOverlay::AutoRenderMode ),
    88         rgbaBuffer( NULL )
     95  public:
     96    PrivateData()
     97        : maskMode( QwtWidgetOverlay::MaskHint )
     98        , renderMode( QwtWidgetOverlay::AutoRenderMode )
     99        , rgbaBuffer( NULL )
    89100    {
    90101    }
    … …  
    99110        if ( rgbaBuffer )
    100111        {
    101             ::free( rgbaBuffer );
     112            std::free( rgbaBuffer );
    102113            rgbaBuffer = NULL;
    103114        }
    … …  
    106117    MaskMode maskMode;
    107118    RenderMode renderMode;
    108     uchar *rgbaBuffer;
     119    uchar* rgbaBuffer;
    109120};
    110121
    … …  
    112123   \brief Constructor
    113124   \param widget Parent widget, where the overlay is aligned to
    114 */
    115 QwtWidgetOverlay::QwtWidgetOverlay( QWidget* widget ):
    116     QWidget( widget )
    117 {
    118     d_data = new PrivateData;
     125 */
     126QwtWidgetOverlay::QwtWidgetOverlay( QWidget* widget )
     127    : QWidget( widget )
     128{
     129    m_data = new PrivateData;
    119130
    120131    setAttribute( Qt::WA_TransparentForMouseEvents );
    … …  
    132143QwtWidgetOverlay::~QwtWidgetOverlay()
    133144{
    134     delete d_data;
     145    delete m_data;
    135146}
    136147
    … …  
    143154void QwtWidgetOverlay::setMaskMode( MaskMode mode )
    144155{
    145     if ( mode != d_data->maskMode )
    146     {
    147         d_data->maskMode = mode;
    148         d_data->resetRgbaBuffer();
     156    if ( mode != m_data->maskMode )
     157    {
     158        m_data->maskMode = mode;
     159        m_data->resetRgbaBuffer();
    149160    }
    150161}
    … …  
    156167QwtWidgetOverlay::MaskMode QwtWidgetOverlay::maskMode() const
    157168{
    158     return d_data->maskMode;
     169    return m_data->maskMode;
    159170}
    160171
    … …  
    164175
    165176   \sa RenderMode, renderMode()
    166 */
     177 */
    167178void QwtWidgetOverlay::setRenderMode( RenderMode mode )
    168179{
    169     d_data->renderMode = mode;
     180    m_data->renderMode = mode;
    170181}
    171182
    … …  
    176187QwtWidgetOverlay::RenderMode QwtWidgetOverlay::renderMode() const
    177188{
    178     return d_data->renderMode;
     189    return m_data->renderMode;
    179190}
    180191
    … …  
    190201void QwtWidgetOverlay::updateMask()
    191202{
    192     d_data->resetRgbaBuffer();
     203    m_data->resetRgbaBuffer();
    193204
    194205    QRegion mask;
    195206
    196     if ( d_data->maskMode == QwtWidgetOverlay::MaskHint )
     207    if ( m_data->maskMode == QwtWidgetOverlay::MaskHint )
    197208    {
    198209        mask = maskHint();
    199210    }
    200     else if ( d_data->maskMode == QwtWidgetOverlay::AlphaMask )
     211    else if ( m_data->maskMode == QwtWidgetOverlay::AlphaMask )
    201212    {
    202213        // TODO: the image doesn't need to be larger than
    … …  
    211222        // QImage::fill( 0 ) or memset()
    212223
    213         d_data->rgbaBuffer = ( uchar* )::calloc( width() * height(), 4 );
    214 
    215         QImage image( d_data->rgbaBuffer,
     224        m_data->rgbaBuffer = ( uchar* )::calloc( width() * height(), 4 );
     225
     226        QImage image( m_data->rgbaBuffer,
    216227            width(), height(), qwtMaskImageFormat() );
    217228
    … …  
    220231        painter.end();
    221232
    222         mask = qwtAlphaMask( image, hint.rects() );
    223 
    224         if ( d_data->renderMode == QwtWidgetOverlay::DrawOverlay )
     233        mask = qwtAlphaMask( image, hint );
     234
     235        if ( m_data->renderMode == QwtWidgetOverlay::DrawOverlay )
    225236        {
    226237            // we don't need the buffer later
    227             d_data->resetRgbaBuffer();
     238            m_data->resetRgbaBuffer();
    228239        }
    229240    }
    … …  
    243254
    244255/*!
    245   Paint event
    246   \param event Paint event
    247 
    248   \sa drawOverlay()
    249 */
     256   Paint event
     257   \param event Paint event
     258
     259   \sa drawOverlay()
     260 */
    250261void QwtWidgetOverlay::paintEvent( QPaintEvent* event )
    251262{
    252     const QRegion &clipRegion = event->region();
     263    const QRegion& clipRegion = event->region();
    253264
    254265    QPainter painter( this );
    255266
    256267    bool useRgbaBuffer = false;
    257     if ( d_data->renderMode == QwtWidgetOverlay::CopyAlphaMask )
     268    if ( m_data->renderMode == QwtWidgetOverlay::CopyAlphaMask )
    258269    {
    259270        useRgbaBuffer = true;
    260271    }
    261     else if ( d_data->renderMode == QwtWidgetOverlay::AutoRenderMode )
     272    else if ( m_data->renderMode == QwtWidgetOverlay::AutoRenderMode )
    262273    {
    263274        if ( painter.paintEngine()->type() == QPaintEngine::Raster )
    … …  
    265276    }
    266277
    267     if ( d_data->rgbaBuffer && useRgbaBuffer )
    268     {
    269         const QImage image( d_data->rgbaBuffer,
     278    if ( m_data->rgbaBuffer && useRgbaBuffer )
     279    {
     280        const QImage image( m_data->rgbaBuffer,
    270281            width(), height(), qwtMaskImageFormat() );
    271282
    272         QVector<QRect> rects;
    273         if ( clipRegion.rects().size() > 2000 )
     283        const int rectCount = clipRegion.rectCount();
     284
     285        if ( rectCount > 2000 )
    274286        {
    275287            // the region is to complex
    276288            painter.setClipRegion( clipRegion );
    277             rects += clipRegion.boundingRect();
     289
     290            const QRect r = clipRegion.boundingRect();
     291            painter.drawImage( r.topLeft(), image, r );
    278292        }
    279293        else
    280294        {
    281             rects = clipRegion.rects();
    282         }
    283 
    284         for ( int i = 0; i < rects.size(); i++ )
    285         {
    286             const QRect r = rects[i];
    287             painter.drawImage( r.topLeft(), image, r );
     295#if QT_VERSION >= 0x050800
     296            for ( QRegion::const_iterator it = clipRegion.cbegin();
     297                it != clipRegion.cend(); ++it )
     298            {
     299                const QRect& r = *it;
     300                painter.drawImage( r.topLeft(), image, r );
     301            }
     302#else
     303            const QVector< QRect > rects = clipRegion.rects();
     304            for ( int i = 0; i < rects.size(); i++ )
     305            {
     306                const QRect& r = rects[i];
     307                painter.drawImage( r.topLeft(), image, r );
     308            }
     309#endif
    288310        }
    289311    }
    … …  
    296318
    297319/*!
    298   Resize event
    299   \param event Resize event
    300 */
     320   Resize event
     321   \param event Resize event
     322 */
    301323void QwtWidgetOverlay::resizeEvent( QResizeEvent* event )
    302324{
    303325    Q_UNUSED( event );
    304326
    305     d_data->resetRgbaBuffer();
    306 }
    307 
    308 void QwtWidgetOverlay::draw( QPainter *painter ) const
    309 {
    310     QWidget *widget = const_cast< QWidget *>( parentWidget() );
    311     if ( widget )
    312     {
    313         painter->setClipRect( parentWidget()->contentsRect() );
     327    m_data->resetRgbaBuffer();
     328}
     329
     330void QwtWidgetOverlay::draw( QPainter* painter ) const
     331{
     332    if ( QWidget* widget = parentWidget() )
     333    {
     334        painter->setClipRect( widget->contentsRect() );
    314335
    315336        // something special for the plot canvas
    … …  
    324345                Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, rect() ) );
    325346
    326             if (!clipPath.isEmpty())
     347            if (!clipPath.isEmpty() )
    327348                painter->setClipPath( clipPath, Qt::IntersectClip );
    328349        }
    … …  
    356377
    357378/*!
    358   \brief Event filter
    359 
    360   Resize the overlay according to the size of the parent widget.
    361 
    362   \param object Object to be filtered
    363   \param event Event
    364 
    365   \return See QObject::eventFilter()
    366 */
     379   \brief Event filter
     380
     381   Resize the overlay according to the size of the parent widget.
     382
     383   \param object Object to be filtered
     384   \param event Event
     385
     386   \return See QObject::eventFilter()
     387 */
    367388
    368389bool QwtWidgetOverlay::eventFilter( QObject* object, QEvent* event )
    … …  
    370391    if ( object == parent() && event->type() == QEvent::Resize )
    371392    {
    372         QResizeEvent *resizeEvent = static_cast<QResizeEvent *>( event );
     393        QResizeEvent* resizeEvent = static_cast< QResizeEvent* >( event );
    373394        resize( resizeEvent->size() );
    374395    }
    … …  
    376397    return QObject::eventFilter( object, event );
    377398}
     399
     400#include "moc_qwt_widget_overlay.cpp"
  • trunk/BNC/qwt/qwt_widget_overlay.h

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_global.h"
    1414#include <qwidget.h>
    15 #include <qregion.h>
    1615
    1716class QPainter;
     17class QRegion;
    1818
    1919/*!
    … …  
    3838   \sa QwtPlotCanvas::BackingStore
    3939 */
    40 class QWT_EXPORT QwtWidgetOverlay: public QWidget
     40class QWT_EXPORT QwtWidgetOverlay : public QWidget
    4141{
    42 public:
     42    Q_OBJECT
     43
     44  public:
    4345    /*!
    4446       \brief Mask mode
    … …  
    112114    };
    113115
    114     QwtWidgetOverlay( QWidget* );
     116    explicit QwtWidgetOverlay( QWidget* );
    115117    virtual ~QwtWidgetOverlay();
    116118
    … …  
    121123    RenderMode renderMode() const;
    122124
     125    virtual bool eventFilter( QObject*, QEvent*) QWT_OVERRIDE;
     126
     127  public Q_SLOTS:
    123128    void updateOverlay();
    124129
    125     virtual bool eventFilter( QObject *, QEvent *);
    126 
    127 protected:
    128     virtual void paintEvent( QPaintEvent* event );
    129     virtual void resizeEvent( QResizeEvent* event );
     130  protected:
     131    virtual void paintEvent( QPaintEvent* ) QWT_OVERRIDE;
     132    virtual void resizeEvent( QResizeEvent* ) QWT_OVERRIDE;
    130133
    131134    virtual QRegion maskHint() const;
    … …  
    135138       \param painter Painter
    136139     */
    137     virtual void drawOverlay( QPainter *painter ) const = 0;
     140    virtual void drawOverlay( QPainter* painter ) const = 0;
    138141
    139 private:
     142  private:
    140143    void updateMask();
    141     void draw( QPainter * ) const;
     144    void draw( QPainter* ) const;
    142145
    143 private:
     146  private:
    144147    class PrivateData;
    145     PrivateData *d_data;
     148    PrivateData* m_data;
    146149};
    147150
  • trunk/BNC/qwt/src.pri

    r9383 r11158  
    1212    qwt.h \
    1313    qwt_abstract_scale_draw.h \
     14    qwt_bezier.h \
    1415    qwt_clipper.h \
    1516    qwt_color_map.h \
    16     qwt_compat.h \
    1717    qwt_column_symbol.h \
    1818    qwt_date.h \
    … …  
    4141    qwt_scale_map.h \
    4242    qwt_spline.h \
     43    qwt_spline_basis.h \
     44    qwt_spline_parametrization.h \
     45    qwt_spline_local.h \
     46    qwt_spline_cubic.h \
     47    qwt_spline_pleasing.h \
     48    qwt_spline_polynomial.h \
    4349    qwt_symbol.h \
    4450    qwt_system_clock.h \
    … …  
    5056
    5157SOURCES += \
     58    qwt.cpp \
    5259    qwt_abstract_scale_draw.cpp \
     60    qwt_bezier.cpp \
    5361    qwt_clipper.cpp \
    5462    qwt_color_map.cpp \
    … …  
    7785    qwt_scale_draw.cpp \
    7886    qwt_scale_map.cpp \
     87    qwt_scale_engine.cpp \
    7988    qwt_spline.cpp \
    80     qwt_scale_engine.cpp \
     89    qwt_spline_basis.cpp \
     90    qwt_spline_parametrization.cpp \
     91    qwt_spline_local.cpp \
     92    qwt_spline_cubic.cpp \
     93    qwt_spline_pleasing.cpp \
     94    qwt_spline_polynomial.cpp \
    8195    qwt_symbol.cpp \
    8296    qwt_system_clock.cpp \
    … …  
    91105
    92106    HEADERS += \
     107        qwt_axis.h \
     108        qwt_axis_id.h \
    93109        qwt_curve_fitter.h \
     110        qwt_spline_curve_fitter.h \
     111        qwt_weeding_curve_fitter.h \
    94112        qwt_event_pattern.h \
    95113        qwt_abstract_legend.h \
    … …  
    102120        qwt_plot_dict.h \
    103121        qwt_plot_directpainter.h \
     122        qwt_plot_graphicitem.h \
    104123        qwt_plot_grid.h \
    105124        qwt_plot_histogram.h \
    … …  
    121140        qwt_plot_seriesitem.h \
    122141        qwt_plot_shapeitem.h \
     142        qwt_plot_vectorfield.h \
     143        qwt_plot_abstract_canvas.h \
    123144        qwt_plot_canvas.h \
    124145        qwt_plot_panner.h \
    … …  
    130151        qwt_raster_data.h \
    131152        qwt_matrix_raster_data.h \
     153        qwt_vectorfield_symbol.h \
    132154        qwt_sampling_thread.h \
    133155        qwt_samples.h \
    … …  
    139161    SOURCES += \
    140162        qwt_curve_fitter.cpp \
     163        qwt_spline_curve_fitter.cpp \
     164        qwt_weeding_curve_fitter.cpp \
    141165        qwt_abstract_legend.cpp \
    142166        qwt_legend.cpp \
    … …  
    145169        qwt_plot.cpp \
    146170        qwt_plot_renderer.cpp \
    147         qwt_plot_xml.cpp \
    148171        qwt_plot_axis.cpp \
    149172        qwt_plot_curve.cpp \
    150173        qwt_plot_dict.cpp \
    151174        qwt_plot_directpainter.cpp \
     175        qwt_plot_graphicitem.cpp \
    152176        qwt_plot_grid.cpp \
    153177        qwt_plot_histogram.cpp \
    … …  
    165189        qwt_plot_seriesitem.cpp \
    166190        qwt_plot_shapeitem.cpp \
     191        qwt_plot_vectorfield.cpp \
    167192        qwt_plot_marker.cpp \
    168193        qwt_plot_textlabel.cpp \
    169194        qwt_plot_layout.cpp \
     195        qwt_plot_abstract_canvas.cpp \
    170196        qwt_plot_canvas.cpp \
    171197        qwt_plot_panner.cpp \
    … …  
    178204        qwt_raster_data.cpp \
    179205        qwt_matrix_raster_data.cpp \
     206        qwt_vectorfield_symbol.cpp \
    180207        qwt_sampling_thread.cpp \
    181208        qwt_series_data.cpp \
    … …  
    185212    contains(QWT_CONFIG, QwtOpenGL) {
    186213
    187         HEADERS += \
    188             qwt_plot_glcanvas.h
    189 
    190         SOURCES += \
    191             qwt_plot_glcanvas.cpp
     214        lessThan(QT_MAJOR_VERSION, 6) {
     215
     216            HEADERS += \
     217                qwt_plot_glcanvas.h
     218
     219            SOURCES += \
     220                qwt_plot_glcanvas.cpp
     221        }
     222
     223        greaterThan(QT_MAJOR_VERSION, 4) {
     224
     225            lessThan( QT_MAJOR_VERSION, 6) {
     226
     227                greaterThan(QT_MINOR_VERSION, 3) {
     228
     229                    HEADERS += qwt_plot_opengl_canvas.h
     230                    SOURCES += qwt_plot_opengl_canvas.cpp
     231                }
     232            }
     233            else {
     234                QT += openglwidgets
     235
     236                HEADERS += qwt_plot_opengl_canvas.h
     237                SOURCES += qwt_plot_opengl_canvas.cpp
     238            }
     239           
     240        }
     241
    192242    }
    193243
    … …  
    199249        SOURCES += \
    200250            qwt_plot_svgitem.cpp
     251    }
     252
     253    contains(QWT_CONFIG, QwtPolar) {
     254
     255        HEADERS += \
     256            qwt_polar.h \
     257            qwt_polar_canvas.h \
     258            qwt_polar_curve.h \
     259            qwt_polar_fitter.h \
     260            qwt_polar_grid.h \
     261            qwt_polar_itemdict.h \
     262            qwt_polar_item.h \
     263            qwt_polar_layout.h \
     264            qwt_polar_magnifier.h \
     265            qwt_polar_marker.h \
     266            qwt_polar_panner.h \
     267            qwt_polar_picker.h \
     268            qwt_polar_plot.h \
     269            qwt_polar_renderer.h \
     270            qwt_polar_spectrogram.h
     271
     272        SOURCES += \
     273            qwt_polar_canvas.cpp \
     274            qwt_polar_curve.cpp \
     275            qwt_polar_fitter.cpp \
     276            qwt_polar_grid.cpp \
     277            qwt_polar_item.cpp \
     278            qwt_polar_itemdict.cpp \
     279            qwt_polar_layout.cpp \
     280            qwt_polar_magnifier.cpp \
     281            qwt_polar_marker.cpp \
     282            qwt_polar_panner.cpp \
     283            qwt_polar_picker.cpp \
     284            qwt_polar_plot.cpp \
     285            qwt_polar_renderer.cpp \
     286            qwt_polar_spectrogram.cpp
    201287    }
    202288}
    … …  
    229315
    230316contains(QWT_CONFIG, QwtOpenGL) {
     317
     318   greaterThan(QT_MAJOR_VERSION, 4) {
     319
     320        qtHaveModule(opengl) {
     321            QT += opengl
     322        }
     323        else {
     324            warning("QwtOpenGL is enabled in qwtconfig.pri, but Qt has not been built with opengl support")
     325        }
     326    }
     327    else {
     328        QT += opengl
     329    }
    231330
    232331    QT += opengl
Note: See TracChangeset for help on using the changeset viewer.