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


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

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_plot.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"
Note: See TracChangeset for help on using the changeset viewer.