Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_legend.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_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"
Note: See TracChangeset for help on using the changeset viewer.