Index: trunk/BNC/qwt/qwt_legend.cpp
===================================================================
--- trunk/BNC/qwt/qwt_legend.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_legend.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -12,135 +12,138 @@
 #include "qwt_dyngrid_layout.h"
 #include "qwt_math.h"
-#include "qwt_plot_item.h"
 #include "qwt_painter.h"
+#include "qwt_graphic.h"
+
 #include <qapplication.h>
 #include <qscrollbar.h>
 #include <qscrollarea.h>
 #include <qpainter.h>
-#include <qstyle.h>
-#include <qstyleoption.h>
-
-class QwtLegendMap
-{
-public:
-    inline bool isEmpty() const { return d_entries.isEmpty(); }
-
-    void insert( const QVariant &, const QList<QWidget *> & );
-    void remove( const QVariant & );
-
-    void removeWidget( const QWidget * );
-
-    QList<QWidget *> legendWidgets( const QVariant & ) const;
-    QVariant itemInfo( const QWidget * ) const;
-
-private:
-    // we don't know anything about itemInfo and therefore don't have
-    // any key that can be used for a map or hashtab.
-    // But a simple linear list is o.k. here, as we will never have
-    // more than a few entries.
-
-    class Entry
-    {
-    public:
-        QVariant itemInfo;
-        QList<QWidget *> widgets;
+#include <qmargins.h>
+
+namespace
+{
+    class LegendMap
+    {
+      public:
+        inline bool isEmpty() const { return m_entries.isEmpty(); }
+
+        void insert( const QVariant&, const QList< QWidget* >& );
+        void remove( const QVariant& );
+
+        void removeWidget( const QWidget* );
+
+        QList< QWidget* > legendWidgets( const QVariant& ) const;
+        QVariant itemInfo( const QWidget* ) const;
+
+      private:
+        // we don't know anything about itemInfo and therefore don't have
+        // any key that can be used for a map or hashtab.
+        // But a simple linear list is o.k. here, as we will never have
+        // more than a few entries.
+
+        class Entry
+        {
+          public:
+            QVariant itemInfo;
+            QList< QWidget* > widgets;
+        };
+
+        QList< Entry > m_entries;
     };
 
-    QList< Entry > d_entries;
+    void LegendMap::insert( const QVariant& itemInfo,
+        const QList< QWidget* >& widgets )
+    {
+        for ( int i = 0; i < m_entries.size(); i++ )
+        {
+            Entry& entry = m_entries[i];
+            if ( entry.itemInfo == itemInfo )
+            {
+                entry.widgets = widgets;
+                return;
+            }
+        }
+
+        Entry newEntry;
+        newEntry.itemInfo = itemInfo;
+        newEntry.widgets = widgets;
+
+        m_entries += newEntry;
+    }
+
+    void LegendMap::remove( const QVariant& itemInfo )
+    {
+        for ( int i = 0; i < m_entries.size(); i++ )
+        {
+            Entry& entry = m_entries[i];
+            if ( entry.itemInfo == itemInfo )
+            {
+                m_entries.removeAt( i );
+                return;
+            }
+        }
+    }
+
+    void LegendMap::removeWidget( const QWidget* widget )
+    {
+        QWidget* w = const_cast< QWidget* >( widget );
+
+        for ( int i = 0; i < m_entries.size(); i++ )
+            m_entries[ i ].widgets.removeAll( w );
+    }
+
+    QVariant LegendMap::itemInfo( const QWidget* widget ) const
+    {
+        if ( widget != NULL )
+        {
+            QWidget* w = const_cast< QWidget* >( widget );
+
+            for ( int i = 0; i < m_entries.size(); i++ )
+            {
+                const Entry& entry = m_entries[i];
+                if ( entry.widgets.indexOf( w ) >= 0 )
+                    return entry.itemInfo;
+            }
+        }
+
+        return QVariant();
+    }
+
+    QList< QWidget* > LegendMap::legendWidgets( const QVariant& itemInfo ) const
+    {
+        if ( itemInfo.isValid() )
+        {
+            for ( int i = 0; i < m_entries.size(); i++ )
+            {
+                const Entry& entry = m_entries[i];
+                if ( entry.itemInfo == itemInfo )
+                    return entry.widgets;
+            }
+        }
+
+        return QList< QWidget* >();
+    }
+}
+
+class QwtLegend::PrivateData
+{
+  public:
+    PrivateData()
+        : itemMode( QwtLegendData::ReadOnly )
+        , view( NULL )
+    {
+    }
+
+    QwtLegendData::Mode itemMode;
+    LegendMap itemMap;
+
+    class LegendView;
+    LegendView* view;
 };
 
-void QwtLegendMap::insert( const QVariant &itemInfo,
-    const QList<QWidget *> &widgets )
-{
-    for ( int i = 0; i < d_entries.size(); i++ )
-    {
-        Entry &entry = d_entries[i];
-        if ( entry.itemInfo == itemInfo )
-        {
-            entry.widgets = widgets;
-            return;
-        }
-    }
-
-    Entry newEntry;
-    newEntry.itemInfo = itemInfo;
-    newEntry.widgets = widgets;
-
-    d_entries += newEntry;
-}
-
-void QwtLegendMap::remove( const QVariant &itemInfo )
-{
-    for ( int i = 0; i < d_entries.size(); i++ )
-    {
-        Entry &entry = d_entries[i];
-        if ( entry.itemInfo == itemInfo )
-        {
-            d_entries.removeAt( i );
-            return;
-        }
-    }
-}
-
-void QwtLegendMap::removeWidget( const QWidget *widget )
-{
-    QWidget *w = const_cast<QWidget *>( widget );
-
-    for ( int i = 0; i < d_entries.size(); i++ )
-        d_entries[ i ].widgets.removeAll( w );
-}
-
-QVariant QwtLegendMap::itemInfo( const QWidget *widget ) const
-{
-    if ( widget != NULL )
-    {
-        QWidget *w = const_cast<QWidget *>( widget );
-
-        for ( int i = 0; i < d_entries.size(); i++ )
-        {
-            const Entry &entry = d_entries[i];
-            if ( entry.widgets.indexOf( w ) >= 0 )
-                return entry.itemInfo;
-        }
-    }
-
-    return QVariant();
-}
-
-QList<QWidget *> QwtLegendMap::legendWidgets( const QVariant &itemInfo ) const
-{
-    if ( itemInfo.isValid() )
-    {
-        for ( int i = 0; i < d_entries.size(); i++ )
-        {
-            const Entry &entry = d_entries[i];
-            if ( entry.itemInfo == itemInfo )
-                return entry.widgets;
-        }
-    }
-
-    return QList<QWidget *>();
-}
-
-class QwtLegend::PrivateData
-{
-public:
-    PrivateData():
-        itemMode( QwtLegendData::ReadOnly ),
-        view( NULL )
-    {
-    }
-
-    QwtLegendData::Mode itemMode;
-    QwtLegendMap itemMap;
-
-    class LegendView;
-    LegendView *view;
-};
-
-class QwtLegend::PrivateData::LegendView: public QScrollArea
-{
-public:
-    explicit LegendView( QWidget *parent ):
+class QwtLegend::PrivateData::LegendView QWT_FINAL : public QScrollArea
+{
+  public:
+    explicit LegendView( QWidget * parent ) :
         QScrollArea( parent )
     {
@@ -159,5 +162,5 @@
     }
 
-    virtual bool event( QEvent *event )
+    virtual bool event( QEvent* event ) QWT_OVERRIDE
     {
         if ( event->type() == QEvent::PolishRequest )
@@ -187,5 +190,5 @@
     }
 
-    virtual bool viewportEvent( QEvent *event )
+    virtual bool viewportEvent( QEvent* event ) QWT_OVERRIDE
     {
         bool ok = QScrollArea::viewportEvent( event );
@@ -223,5 +226,5 @@
     void layoutContents()
     {
-        const QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>(
+        const QwtDynGridLayout* tl = qobject_cast< QwtDynGridLayout* >(
             contentsWidget->layout() );
         if ( tl == NULL )
@@ -230,5 +233,6 @@
         const QSize visibleSize = viewport()->contentsRect().size();
 
-        const int minW = int( tl->maxItemWidth() ) + 2 * tl->margin();
+        const QMargins m = tl->contentsMargins();
+        const int minW = tl->maxItemWidth() + m.left() + m.right();
 
         int w = qMax( visibleSize.width(), minW );
@@ -245,31 +249,31 @@
     }
 
-    QWidget *contentsWidget;
+    QWidget* contentsWidget;
 };
 
 /*!
-  Constructor
-  \param parent Parent widget
-*/
-QwtLegend::QwtLegend( QWidget *parent ):
-    QwtAbstractLegend( parent )
+   Constructor
+   \param parent Parent widget
+ */
+QwtLegend::QwtLegend( QWidget* parent )
+    : QwtAbstractLegend( parent )
 {
     setFrameStyle( NoFrame );
 
-    d_data = new QwtLegend::PrivateData;
-
-    d_data->view = new QwtLegend::PrivateData::LegendView( this );
-    d_data->view->setObjectName( "QwtLegendView" );
-    d_data->view->setFrameStyle( NoFrame );
-
-    QwtDynGridLayout *gridLayout = new QwtDynGridLayout(
-        d_data->view->contentsWidget );
+    m_data = new QwtLegend::PrivateData;
+
+    m_data->view = new QwtLegend::PrivateData::LegendView( this );
+    m_data->view->setObjectName( "QwtLegendView" );
+    m_data->view->setFrameStyle( NoFrame );
+
+    QwtDynGridLayout* gridLayout = new QwtDynGridLayout(
+        m_data->view->contentsWidget );
     gridLayout->setAlignment( Qt::AlignHCenter | Qt::AlignTop );
 
-    d_data->view->contentsWidget->installEventFilter( this );
-
-    QVBoxLayout *layout = new QVBoxLayout( this );
+    m_data->view->contentsWidget->installEventFilter( this );
+
+    QVBoxLayout* layout = new QVBoxLayout( this );
     layout->setContentsMargins( 0, 0, 0, 0 );
-    layout->addWidget( d_data->view );
+    layout->addWidget( m_data->view );
 }
 
@@ -277,21 +281,21 @@
 QwtLegend::~QwtLegend()
 {
-    delete d_data;
-}
-
-/*!
-  \brief Set the maximum number of entries in a row
-
-  F.e when the maximum is set to 1 all items are aligned
-  vertically. 0 means unlimited
-
-  \param numColums Maximum number of entries in a row
-
-  \sa maxColumns(), QwtDynGridLayout::setMaxColumns()
+    delete m_data;
+}
+
+/*!
+   \brief Set the maximum number of entries in a row
+
+   F.e when the maximum is set to 1 all items are aligned
+   vertically. 0 means unlimited
+
+   \param numColums Maximum number of entries in a row
+
+   \sa maxColumns(), QwtDynGridLayout::setMaxColumns()
  */
 void QwtLegend::setMaxColumns( uint numColums )
 {
-    QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>(
-        d_data->view->contentsWidget->layout() );
+    QwtDynGridLayout* tl = qobject_cast< QwtDynGridLayout* >(
+        m_data->view->contentsWidget->layout() );
     if ( tl )
         tl->setMaxColumns( numColums );
@@ -301,6 +305,6 @@
 
 /*!
-  \return Maximum number of entries in a row
-  \sa setMaxColumns(), QwtDynGridLayout::maxColumns()
+   \return Maximum number of entries in a row
+   \sa setMaxColumns(), QwtDynGridLayout::maxColumns()
  */
 uint QwtLegend::maxColumns() const
@@ -308,6 +312,6 @@
     uint maxCols = 0;
 
-    const QwtDynGridLayout *tl = qobject_cast<const QwtDynGridLayout *>(
-        d_data->view->contentsWidget->layout() );
+    const QwtDynGridLayout* tl = qobject_cast< const QwtDynGridLayout* >(
+        m_data->view->contentsWidget->layout() );
     if ( tl )
         maxCols = tl->maxColumns();
@@ -317,89 +321,89 @@
 
 /*!
-  \brief Set the default mode for legend labels
-
-  Legend labels will be constructed according to the
-  attributes in a QwtLegendData object. When it doesn't
-  contain a value for the QwtLegendData::ModeRole the
-  label will be initialized with the default mode of the legend.
-
-  \param mode Default item mode
-
-  \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData()
-  \note Changing the mode doesn't have any effect on existing labels.
+   \brief Set the default mode for legend labels
+
+   Legend labels will be constructed according to the
+   attributes in a QwtLegendData object. When it doesn't
+   contain a value for the QwtLegendData::ModeRole the
+   label will be initialized with the default mode of the legend.
+
+   \param mode Default item mode
+
+   \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData()
+   \note Changing the mode doesn't have any effect on existing labels.
  */
 void QwtLegend::setDefaultItemMode( QwtLegendData::Mode mode )
 {
-    d_data->itemMode = mode;
-}
-
-/*!
-  \return Default item mode
-  \sa setDefaultItemMode()
-*/
+    m_data->itemMode = mode;
+}
+
+/*!
+   \return Default item mode
+   \sa setDefaultItemMode()
+ */
 QwtLegendData::Mode QwtLegend::defaultItemMode() const
 {
-    return d_data->itemMode;
-}
-
-/*!
-  The contents widget is the only child of the viewport of
-  the internal QScrollArea and the parent widget of all legend items.
-
-  \return Container widget of the legend items
-*/
-QWidget *QwtLegend::contentsWidget()
-{
-    return d_data->view->contentsWidget;
-}
-
-/*!
-  \return Horizontal scrollbar
-  \sa verticalScrollBar()
-*/
-QScrollBar *QwtLegend::horizontalScrollBar() const
-{
-    return d_data->view->horizontalScrollBar();
-}
-
-/*!
-  \return Vertical scrollbar
-  \sa horizontalScrollBar()
-*/
-QScrollBar *QwtLegend::verticalScrollBar() const
-{
-    return d_data->view->verticalScrollBar();
-}
-
-/*!
-  The contents widget is the only child of the viewport of
-  the internal QScrollArea and the parent widget of all legend items.
-
-  \return Container widget of the legend items
-
-*/
-const QWidget *QwtLegend::contentsWidget() const
-{
-    return d_data->view->contentsWidget;
-}
-
-/*!
-  \brief Update the entries for an item
-
-  \param itemInfo Info for an item
-  \param legendData List of legend entry attributes for the item
- */
-void QwtLegend::updateLegend( const QVariant &itemInfo,
-    const QList<QwtLegendData> &legendData )
-{
-    QList<QWidget *> widgetList = legendWidgets( itemInfo );
+    return m_data->itemMode;
+}
+
+/*!
+   The contents widget is the only child of the viewport of
+   the internal QScrollArea and the parent widget of all legend items.
+
+   \return Container widget of the legend items
+ */
+QWidget* QwtLegend::contentsWidget()
+{
+    return m_data->view->contentsWidget;
+}
+
+/*!
+   \return Horizontal scrollbar
+   \sa verticalScrollBar()
+ */
+QScrollBar* QwtLegend::horizontalScrollBar() const
+{
+    return m_data->view->horizontalScrollBar();
+}
+
+/*!
+   \return Vertical scrollbar
+   \sa horizontalScrollBar()
+ */
+QScrollBar* QwtLegend::verticalScrollBar() const
+{
+    return m_data->view->verticalScrollBar();
+}
+
+/*!
+   The contents widget is the only child of the viewport of
+   the internal QScrollArea and the parent widget of all legend items.
+
+   \return Container widget of the legend items
+
+ */
+const QWidget* QwtLegend::contentsWidget() const
+{
+    return m_data->view->contentsWidget;
+}
+
+/*!
+   \brief Update the entries for an item
+
+   \param itemInfo Info for an item
+   \param legendData List of legend entry attributes for the item
+ */
+void QwtLegend::updateLegend( const QVariant& itemInfo,
+    const QList< QwtLegendData >& legendData )
+{
+    QList< QWidget* > widgetList = legendWidgets( itemInfo );
 
     if ( widgetList.size() != legendData.size() )
     {
-        QLayout *contentsLayout = d_data->view->contentsWidget->layout();
+        QLayout* contentsLayout = m_data->view->contentsWidget->layout();
 
         while ( widgetList.size() > legendData.size() )
         {
-            QWidget *w = widgetList.takeLast();
+            QWidget* w = widgetList.takeLast();
 
             contentsLayout->removeWidget( w );
@@ -412,11 +416,9 @@
         }
 
-#if QT_VERSION >= 0x040700
         widgetList.reserve( legendData.size() );
-#endif
 
         for ( int i = widgetList.size(); i < legendData.size(); i++ )
         {
-            QWidget *widget = createWidget( legendData[i] );
+            QWidget* widget = createWidget( legendData[i] );
 
             if ( contentsLayout )
@@ -438,9 +440,9 @@
         if ( widgetList.isEmpty() )
         {
-            d_data->itemMap.remove( itemInfo );
+            m_data->itemMap.remove( itemInfo );
         }
         else
         {
-            d_data->itemMap.insert( itemInfo, widgetList );
+            m_data->itemMap.insert( itemInfo, widgetList );
         }
 
@@ -453,19 +455,19 @@
 
 /*!
-  \brief Create a widget to be inserted into the legend
-
-  The default implementation returns a QwtLegendLabel.
-
-  \param legendData Attributes of the legend entry
-  \return Widget representing data on the legend
-
-  \note updateWidget() will called soon after createWidget()
+   \brief Create a widget to be inserted into the legend
+
+   The default implementation returns a QwtLegendLabel.
+
+   \param legendData Attributes of the legend entry
+   \return Widget representing data on the legend
+
+   \note updateWidget() will called soon after createWidget()
         with the same attributes.
  */
-QWidget *QwtLegend::createWidget( const QwtLegendData &legendData ) const
+QWidget* QwtLegend::createWidget( const QwtLegendData& legendData ) const
 {
     Q_UNUSED( legendData );
 
-    QwtLegendLabel *label = new QwtLegendLabel();
+    QwtLegendLabel* label = new QwtLegendLabel();
     label->setItemMode( defaultItemMode() );
 
@@ -477,15 +479,15 @@
 
 /*!
-  \brief Update the widget
-
-  \param widget Usually a QwtLegendLabel
-  \param legendData Attributes to be displayed
-
-  \sa createWidget()
-  \note When widget is no QwtLegendLabel updateWidget() does nothing.
- */
-void QwtLegend::updateWidget( QWidget *widget, const QwtLegendData &legendData )
-{
-    QwtLegendLabel *label = qobject_cast<QwtLegendLabel *>( widget );
+   \brief Update the widget
+
+   \param widget Usually a QwtLegendLabel
+   \param legendData Attributes to be displayed
+
+   \sa createWidget()
+   \note When widget is no QwtLegendLabel updateWidget() does nothing.
+ */
+void QwtLegend::updateWidget( QWidget* widget, const QwtLegendData& legendData )
+{
+    QwtLegendLabel* label = qobject_cast< QwtLegendLabel* >( widget );
     if ( label )
     {
@@ -503,14 +505,14 @@
 void QwtLegend::updateTabOrder()
 {
-    QLayout *contentsLayout = d_data->view->contentsWidget->layout();
+    QLayout* contentsLayout = m_data->view->contentsWidget->layout();
     if ( contentsLayout )
     {
         // set tab focus chain
 
-        QWidget *w = NULL;
+        QWidget* w = NULL;
 
         for ( int i = 0; i < contentsLayout->count(); i++ )
         {
-            QLayoutItem *item = contentsLayout->itemAt( i );
+            QLayoutItem* item = contentsLayout->itemAt( i );
             if ( w && item->widget() )
                 QWidget::setTabOrder( w, item->widget() );
@@ -524,5 +526,5 @@
 QSize QwtLegend::sizeHint() const
 {
-    QSize hint = d_data->view->contentsWidget->sizeHint();
+    QSize hint = m_data->view->contentsWidget->sizeHint();
     hint += QSize( 2 * frameWidth(), 2 * frameWidth() );
 
@@ -531,12 +533,12 @@
 
 /*!
-  \return The preferred height, for a width.
-  \param width Width
-*/
+   \return The preferred height, for a width.
+   \param width Width
+ */
 int QwtLegend::heightForWidth( int width ) const
 {
     width -= 2 * frameWidth();
 
-    int h = d_data->view->contentsWidget->heightForWidth( width );
+    int h = m_data->view->contentsWidget->heightForWidth( width );
     if ( h >= 0 )
         h += 2 * frameWidth();
@@ -547,15 +549,15 @@
 
 /*!
-  Handle QEvent::ChildRemoved andQEvent::LayoutRequest events
-  for the contentsWidget().
-
-  \param object Object to be filtered
-  \param event Event
-
-  \return Forwarded to QwtAbstractLegend::eventFilter()
-*/
-bool QwtLegend::eventFilter( QObject *object, QEvent *event )
-{
-    if ( object == d_data->view->contentsWidget )
+   Handle QEvent::ChildRemoved and QEvent::LayoutRequest events
+   for the contentsWidget().
+
+   \param object Object to be filtered
+   \param event Event
+
+   \return Forwarded to QwtAbstractLegend::eventFilter()
+ */
+bool QwtLegend::eventFilter( QObject* object, QEvent* event )
+{
+    if ( object == m_data->view->contentsWidget )
     {
         switch ( event->type() )
@@ -563,6 +565,6 @@
             case QEvent::ChildRemoved:
             {
-                const QChildEvent *ce =
-                    static_cast<const QChildEvent *>(event);
+                const QChildEvent* ce =
+                    static_cast< const QChildEvent* >( event );
 
                 if ( ce->child()->isWidgetType() )
@@ -573,6 +575,6 @@
                         to remove it from the map.
                      */
-                    QWidget *w = reinterpret_cast< QWidget * >( ce->child() );
-                    d_data->itemMap.removeWidget( w );
+                    QWidget* w = reinterpret_cast< QWidget* >( ce->child() );
+                    m_data->itemMap.removeWidget( w );
                 }
                 break;
@@ -580,5 +582,5 @@
             case QEvent::LayoutRequest:
             {
-                d_data->view->layoutContents();
+                m_data->view->layoutContents();
 
                 if ( parentWidget() && parentWidget()->layout() == NULL )
@@ -609,17 +611,17 @@
 
 /*!
-  Called internally when the legend has been clicked on.
-  Emits a clicked() signal.
-*/
+   Called internally when the legend has been clicked on.
+   Emits a clicked() signal.
+ */
 void QwtLegend::itemClicked()
 {
-    QWidget *w = qobject_cast<QWidget *>( sender() );
+    QWidget* w = qobject_cast< QWidget* >( sender() );
     if ( w )
     {
-        const QVariant itemInfo = d_data->itemMap.itemInfo( w );
+        const QVariant itemInfo = m_data->itemMap.itemInfo( w );
         if ( itemInfo.isValid() )
         {
-            const QList<QWidget *> widgetList =
-                d_data->itemMap.legendWidgets( itemInfo );
+            const QList< QWidget* > widgetList =
+                m_data->itemMap.legendWidgets( itemInfo );
 
             const int index = widgetList.indexOf( w );
@@ -631,17 +633,17 @@
 
 /*!
-  Called internally when the legend has been checked
-  Emits a checked() signal.
-*/
+   Called internally when the legend has been checked
+   Emits a checked() signal.
+ */
 void QwtLegend::itemChecked( bool on )
 {
-    QWidget *w = qobject_cast<QWidget *>( sender() );
+    QWidget* w = qobject_cast< QWidget* >( sender() );
     if ( w )
     {
-        const QVariant itemInfo = d_data->itemMap.itemInfo( w );
+        const QVariant itemInfo = m_data->itemMap.itemInfo( w );
         if ( itemInfo.isValid() )
         {
-            const QList<QWidget *> widgetList =
-                d_data->itemMap.legendWidgets( itemInfo );
+            const QList< QWidget* > widgetList =
+                m_data->itemMap.legendWidgets( itemInfo );
 
             const int index = widgetList.indexOf( w );
@@ -653,16 +655,16 @@
 
 /*!
-  Render the legend into a given rectangle.
-
-  \param painter Painter
-  \param rect Bounding rectangle
-  \param fillBackground When true, fill rect with the widget background
-
-  \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself
-*/
-void QwtLegend::renderLegend( QPainter *painter,
-    const QRectF &rect, bool fillBackground ) const
-{
-    if ( d_data->itemMap.isEmpty() )
+   Render the legend into a given rectangle.
+
+   \param painter Painter
+   \param rect Bounding rectangle
+   \param fillBackground When true, fill rect with the widget background
+
+   \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself
+ */
+void QwtLegend::renderLegend( QPainter* painter,
+    const QRectF& rect, bool fillBackground ) const
+{
+    if ( m_data->itemMap.isEmpty() )
         return;
 
@@ -676,20 +678,19 @@
     }
 
-    const QwtDynGridLayout *legendLayout =
-        qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );
+    const QwtDynGridLayout* legendLayout =
+        qobject_cast< QwtDynGridLayout* >( contentsWidget()->layout() );
     if ( legendLayout == NULL )
         return;
 
-    int left, right, top, bottom;
-    getContentsMargins( &left, &top, &right, &bottom );
+    const QMargins m = contentsMargins();
 
     QRect layoutRect;
-    layoutRect.setLeft( qCeil( rect.left() ) + left );
-    layoutRect.setTop( qCeil( rect.top() ) + top );
-    layoutRect.setRight( qFloor( rect.right() ) - right );
-    layoutRect.setBottom( qFloor( rect.bottom() ) - bottom );
+    layoutRect.setLeft( qwtCeil( rect.left() ) + m.left() );
+    layoutRect.setTop( qwtCeil( rect.top() ) + m.top() );
+    layoutRect.setRight( qwtFloor( rect.right() ) - m.right() );
+    layoutRect.setBottom( qwtFloor( rect.bottom() ) - m.bottom() );
 
     uint numCols = legendLayout->columnsForWidth( layoutRect.width() );
-    const QList<QRect> itemRects =
+    const QList< QRect > itemRects =
         legendLayout->layoutItems( layoutRect, numCols );
 
@@ -698,6 +699,6 @@
     for ( int i = 0; i < legendLayout->count(); i++ )
     {
-        QLayoutItem *item = legendLayout->itemAt( i );
-        QWidget *w = item->widget();
+        QLayoutItem* item = legendLayout->itemAt( i );
+        QWidget* w = item->widget();
         if ( w )
         {
@@ -714,16 +715,16 @@
 
 /*!
-  Render a legend entry into a given rectangle.
-
-  \param painter Painter
-  \param widget Widget representing a legend entry
-  \param rect Bounding rectangle
-  \param fillBackground When true, fill rect with the widget background
-
-  \note When widget is not derived from QwtLegendLabel renderItem
+   Render a legend entry into a given rectangle.
+
+   \param painter Painter
+   \param widget Widget representing a legend entry
+   \param rect Bounding rectangle
+   \param fillBackground When true, fill rect with the widget background
+
+   \note When widget is not derived from QwtLegendLabel renderItem
         does nothing beside the background
-*/
-void QwtLegend::renderItem( QPainter *painter,
-    const QWidget *widget, const QRectF &rect, bool fillBackground ) const
+ */
+void QwtLegend::renderItem( QPainter* painter,
+    const QWidget* widget, const QRectF& rect, bool fillBackground ) const
 {
     if ( fillBackground )
@@ -736,10 +737,10 @@
     }
 
-    const QwtLegendLabel *label = qobject_cast<const QwtLegendLabel *>( widget );
+    const QwtLegendLabel* label = qobject_cast< const QwtLegendLabel* >( widget );
     if ( label )
     {
         // icon
 
-        const QwtGraphic &icon = label->data().icon();
+        const QwtGraphic& icon = label->data().icon();
         const QSizeF sz = icon.defaultSize();
 
@@ -756,32 +757,36 @@
 
         QFont labelFont = label->font();
+#if QT_VERSION >= 0x060000
+        labelFont.setResolveMask( QFont::AllPropertiesResolved );
+#else
         labelFont.resolve( QFont::AllPropertiesResolved );
+#endif
 
         painter->setFont( labelFont );
         painter->setPen( label->palette().color( QPalette::Text ) );
 
-        const_cast< QwtLegendLabel *>( label )->drawText( painter, titleRect );
-    }
-}
-
-/*!
-  \return List of widgets associated to a item
-  \param itemInfo Info about an item
-  \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo()
- */
-QList<QWidget *> QwtLegend::legendWidgets( const QVariant &itemInfo ) const
-{
-    return d_data->itemMap.legendWidgets( itemInfo );
-}
-
-/*!
-  \return First widget in the list of widgets associated to an item
-  \param itemInfo Info about an item
-  \sa itemInfo(), QwtPlot::itemToInfo()
-  \note Almost all types of items have only one widget
-*/
-QWidget *QwtLegend::legendWidget( const QVariant &itemInfo ) const
-{
-    const QList<QWidget *> list = d_data->itemMap.legendWidgets( itemInfo );
+        const_cast< QwtLegendLabel* >( label )->drawText( painter, titleRect );
+    }
+}
+
+/*!
+   \return List of widgets associated to a item
+   \param itemInfo Info about an item
+   \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo()
+ */
+QList< QWidget* > QwtLegend::legendWidgets( const QVariant& itemInfo ) const
+{
+    return m_data->itemMap.legendWidgets( itemInfo );
+}
+
+/*!
+   \return First widget in the list of widgets associated to an item
+   \param itemInfo Info about an item
+   \sa itemInfo(), QwtPlot::itemToInfo()
+   \note Almost all types of items have only one widget
+ */
+QWidget* QwtLegend::legendWidget( const QVariant& itemInfo ) const
+{
+    const QList< QWidget* > list = m_data->itemMap.legendWidgets( itemInfo );
     if ( list.isEmpty() )
         return NULL;
@@ -791,13 +796,13 @@
 
 /*!
-  Find the item that is associated to a widget
-
-  \param widget Widget on the legend
-  \return Associated item info
-  \sa legendWidget()
- */
-QVariant QwtLegend::itemInfo( const QWidget *widget ) const
-{
-    return d_data->itemMap.itemInfo( widget );
+   Find the item that is associated to a widget
+
+   \param widget Widget on the legend
+   \return Associated item info
+   \sa legendWidget()
+ */
+QVariant QwtLegend::itemInfo( const QWidget* widget ) const
+{
+    return m_data->itemMap.itemInfo( widget );
 }
 
@@ -805,5 +810,5 @@
 bool QwtLegend::isEmpty() const
 {
-    return d_data->itemMap.isEmpty();
+    return m_data->itemMap.isEmpty();
 }
 
@@ -826,2 +831,3 @@
 }
 
+#include "moc_qwt_legend.cpp"
