Index: trunk/BNC/qwt/qwt_plot_shapeitem.cpp
===================================================================
--- trunk/BNC/qwt/qwt_plot_shapeitem.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_plot_shapeitem.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -10,10 +10,16 @@
 #include "qwt_plot_shapeitem.h"
 #include "qwt_scale_map.h"
+#include "qwt_text.h"
+#include "qwt_graphic.h"
 #include "qwt_painter.h"
-#include "qwt_curve_fitter.h"
+#include "qwt_weeding_curve_fitter.h"
 #include "qwt_clipper.h"
-
-static QPainterPath qwtTransformPath( const QwtScaleMap &xMap,
-        const QwtScaleMap &yMap, const QPainterPath &path, bool doAlign )
+#include "qwt_math.h"
+
+#include <qpainter.h>
+#include <qpainterpath.h>
+
+static QPainterPath qwtTransformPath( const QwtScaleMap& xMap,
+    const QwtScaleMap& yMap, const QPainterPath& path, bool doAlign )
 {
     QPainterPath shape;
@@ -22,5 +28,5 @@
     for ( int i = 0; i < path.elementCount(); i++ )
     {
-        const QPainterPath::Element &element = path.elementAt( i );
+        const QPainterPath::Element element = path.elementAt( i );
 
         double x = xMap.transform( element.x );
@@ -53,9 +59,9 @@
             case QPainterPath::CurveToElement:
             {
-                const QPainterPath::Element& element1 = path.elementAt( ++i );
+                const QPainterPath::Element element1 = path.elementAt( ++i );
                 const double x1 = xMap.transform( element1.x );
                 const double y1 = yMap.transform( element1.y );
 
-                const QPainterPath::Element& element2 = path.elementAt( ++i );
+                const QPainterPath::Element element2 = path.elementAt( ++i );
                 const double x2 = xMap.transform( element2.x );
                 const double y2 = yMap.transform( element2.y );
@@ -77,8 +83,8 @@
 class QwtPlotShapeItem::PrivateData
 {
-public:
-    PrivateData():
-        legendMode( QwtPlotShapeItem::LegendColor ),
-        renderTolerance( 0.0 )
+  public:
+    PrivateData()
+        : legendMode( QwtPlotShapeItem::LegendColor )
+        , renderTolerance( 0.0 )
     {
     }
@@ -103,7 +109,7 @@
 
    \param title Title
-*/
-QwtPlotShapeItem::QwtPlotShapeItem( const QString& title ):
-    QwtPlotItem( QwtText( title ) )
+ */
+QwtPlotShapeItem::QwtPlotShapeItem( const QString& title )
+    : QwtPlotItem( QwtText( title ) )
 {
     init();
@@ -118,7 +124,7 @@
 
    \param title Title
-*/
-QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title ):
-    QwtPlotItem( title )
+ */
+QwtPlotShapeItem::QwtPlotShapeItem( const QwtText& title )
+    : QwtPlotItem( title )
 {
     init();
@@ -128,11 +134,11 @@
 QwtPlotShapeItem::~QwtPlotShapeItem()
 {
-    delete d_data;
+    delete m_data;
 }
 
 void QwtPlotShapeItem::init()
 {
-    d_data = new PrivateData();
-    d_data->boundingRect = QwtPlotItem::boundingRect();
+    m_data = new PrivateData();
+    m_data->boundingRect = QwtPlotItem::boundingRect();
 
     setItemAttribute( QwtPlotItem::AutoScale, true );
@@ -149,38 +155,38 @@
 
 /*!
-  Specify an attribute how to draw the shape
-
-  \param attribute Paint attribute
-  \param on On/Off
-  \sa testPaintAttribute()
-*/
+   Specify an attribute how to draw the shape
+
+   \param attribute Paint attribute
+   \param on On/Off
+   \sa testPaintAttribute()
+ */
 void QwtPlotShapeItem::setPaintAttribute( PaintAttribute attribute, bool on )
 {
     if ( on )
-        d_data->paintAttributes |= attribute;
+        m_data->paintAttributes |= attribute;
     else
-        d_data->paintAttributes &= ~attribute;
-}
-
-/*!
-  \return True, when attribute is enabled
-  \sa setPaintAttribute()
-*/
+        m_data->paintAttributes &= ~attribute;
+}
+
+/*!
+   \return True, when attribute is enabled
+   \sa setPaintAttribute()
+ */
 bool QwtPlotShapeItem::testPaintAttribute( PaintAttribute attribute ) const
 {
-    return ( d_data->paintAttributes & attribute );
-}
-
-/*!
-  Set the mode how to represent the item on the legend
-
-  \param mode Mode
-  \sa legendMode()
+    return ( m_data->paintAttributes & attribute );
+}
+
+/*!
+   Set the mode how to represent the item on the legend
+
+   \param mode Mode
+   \sa legendMode()
  */
 void QwtPlotShapeItem::setLegendMode( LegendMode mode )
 {
-    if ( mode != d_data->legendMode )
-    {
-        d_data->legendMode = mode;
+    if ( mode != m_data->legendMode )
+    {
+        m_data->legendMode = mode;
         legendChanged();
     }
@@ -188,10 +194,10 @@
 
 /*!
-  \return Mode how to represent the item on the legend
-  \sa legendMode()
+   \return Mode how to represent the item on the legend
+   \sa legendMode()
  */
 QwtPlotShapeItem::LegendMode QwtPlotShapeItem::legendMode() const
 {
-    return d_data->legendMode;
+    return m_data->legendMode;
 }
 
@@ -199,14 +205,14 @@
 QRectF QwtPlotShapeItem::boundingRect() const
 {
-    return d_data->boundingRect;
-}
-
-/*!
-  \brief Set a path built from a rectangle
-
-  \param rect Rectangle
-  \sa setShape(), setPolygon(), shape()
- */
-void QwtPlotShapeItem::setRect( const QRectF &rect )
+    return m_data->boundingRect;
+}
+
+/*!
+   \brief Set a path built from a rectangle
+
+   \param rect Rectangle
+   \sa setShape(), setPolygon(), shape()
+ */
+void QwtPlotShapeItem::setRect( const QRectF& rect )
 {
     QPainterPath path;
@@ -217,10 +223,10 @@
 
 /*!
-  \brief Set a path built from a polygon
-
-  \param polygon Polygon
-  \sa setShape(), setRect(), shape()
- */
-void QwtPlotShapeItem::setPolygon( const QPolygonF &polygon )
+   \brief Set a path built from a polygon
+
+   \param polygon Polygon
+   \sa setShape(), setRect(), shape()
+ */
+void QwtPlotShapeItem::setPolygon( const QPolygonF& polygon )
 {
     QPainterPath shape;
@@ -231,21 +237,21 @@
 
 /*!
-  \brief Set the shape to be displayed
-
-  \param shape Shape
-  \sa setShape(), shape()
- */
-void QwtPlotShapeItem::setShape( const QPainterPath &shape )
-{
-    if ( shape != d_data->shape )
-    {
-        d_data->shape = shape;
+   \brief Set the shape to be displayed
+
+   \param shape Shape
+   \sa setShape(), shape()
+ */
+void QwtPlotShapeItem::setShape( const QPainterPath& shape )
+{
+    if ( shape != m_data->shape )
+    {
+        m_data->shape = shape;
         if ( shape.isEmpty() )
         {
-            d_data->boundingRect = QwtPlotItem::boundingRect();
+            m_data->boundingRect = QwtPlotItem::boundingRect();
         }
         else
         {
-            d_data->boundingRect = shape.boundingRect();
+            m_data->boundingRect = shape.boundingRect();
         }
 
@@ -255,26 +261,26 @@
 
 /*!
-  \return Shape to be displayed
-  \sa setShape()
+   \return Shape to be displayed
+   \sa setShape()
  */
 QPainterPath QwtPlotShapeItem::shape() const
 {
-    return d_data->shape;
-}
-
-/*!
-  Build and assign a pen
-
-  In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
-  non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
-  to hide this incompatibility.
-
-  \param color Pen color
-  \param width Pen width
-  \param style Pen style
-
-  \sa pen(), brush()
- */
-void QwtPlotShapeItem::setPen( const QColor &color, qreal width, Qt::PenStyle style )
+    return m_data->shape;
+}
+
+/*!
+   Build and assign a pen
+
+   In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
+   non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
+   to hide this incompatibility.
+
+   \param color Pen color
+   \param width Pen width
+   \param style Pen style
+
+   \sa pen(), brush()
+ */
+void QwtPlotShapeItem::setPen( const QColor& color, qreal width, Qt::PenStyle style )
 {
     setPen( QPen( color, width, style ) );
@@ -282,16 +288,16 @@
 
 /*!
-  \brief Assign a pen
-
-  The pen is used to draw the outline of the shape
-
-  \param pen Pen
-  \sa pen(), brush()
-*/
-void QwtPlotShapeItem::setPen( const QPen &pen )
-{
-    if ( pen != d_data->pen )
-    {
-        d_data->pen = pen;
+   \brief Assign a pen
+
+   The pen is used to draw the outline of the shape
+
+   \param pen Pen
+   \sa pen(), brush()
+ */
+void QwtPlotShapeItem::setPen( const QPen& pen )
+{
+    if ( pen != m_data->pen )
+    {
+        m_data->pen = pen;
         itemChanged();
     }
@@ -301,23 +307,23 @@
     \return Pen used to draw the outline of the shape
     \sa setPen(), brush()
-*/
+ */
 QPen QwtPlotShapeItem::pen() const
 {
-    return d_data->pen;
-}
-
-/*!
-  Assign a brush.
-
-  The brush is used to fill the path
-
-  \param brush Brush
-  \sa brush(), pen()
-*/
-void QwtPlotShapeItem::setBrush( const QBrush &brush )
-{
-    if ( brush != d_data->brush )
-    {
-        d_data->brush = brush;
+    return m_data->pen;
+}
+
+/*!
+   Assign a brush.
+
+   The brush is used to fill the path
+
+   \param brush Brush
+   \sa brush(), pen()
+ */
+void QwtPlotShapeItem::setBrush( const QBrush& brush )
+{
+    if ( brush != m_data->brush )
+    {
+        m_data->brush = brush;
         itemChanged();
     }
@@ -325,35 +331,35 @@
 
 /*!
-  \return Brush used to fill the shape
-  \sa setBrush(), pen()
-*/
+   \return Brush used to fill the shape
+   \sa setBrush(), pen()
+ */
 QBrush QwtPlotShapeItem::brush() const
 {
-    return d_data->brush;
-}
-
-/*!
-  \brief Set the tolerance for the weeding optimization
-
-  After translating the shape into target device coordinate
-  ( usually widget geometries ) the painter path can be simplified
-  by a point weeding algorithm ( Douglas-Peucker ).
-
-  For shapes built from curves and ellipses weeding might
-  have the opposite effect because they have to be expanded
-  to polygons.
-
-  \param tolerance Accepted error when reducing the number of points
+    return m_data->brush;
+}
+
+/*!
+   \brief Set the tolerance for the weeding optimization
+
+   After translating the shape into target device coordinate
+   ( usually widget geometries ) the painter path can be simplified
+   by a point weeding algorithm ( Douglas-Peucker ).
+
+   For shapes built from curves and ellipses weeding might
+   have the opposite effect because they have to be expanded
+   to polygons.
+
+   \param tolerance Accepted error when reducing the number of points
                    A value <= 0.0 disables weeding.
 
-  \sa renderTolerance(), QwtWeedingCurveFitter
+   \sa renderTolerance(), QwtWeedingCurveFitter
  */
 void QwtPlotShapeItem::setRenderTolerance( double tolerance )
 {
-    tolerance = qMax( tolerance, 0.0 );
-
-    if ( tolerance != d_data->renderTolerance )
-    {
-        d_data->renderTolerance = tolerance;
+    tolerance = qwtMaxF( tolerance, 0.0 );
+
+    if ( tolerance != m_data->renderTolerance )
+    {
+        m_data->renderTolerance = tolerance;
         itemChanged();
     }
@@ -361,29 +367,29 @@
 
 /*!
-  \return Tolerance for the weeding optimization
-  \sa setRenderTolerance()
+   \return Tolerance for the weeding optimization
+   \sa setRenderTolerance()
  */
 double QwtPlotShapeItem::renderTolerance() const
 {
-    return d_data->renderTolerance;
-}
-
-/*!
-  Draw the shape item
-
-  \param painter Painter
-  \param xMap X-Scale Map
-  \param yMap Y-Scale Map
-  \param canvasRect Contents rect of the plot canvas
-*/
-void QwtPlotShapeItem::draw( QPainter *painter,
-    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
-    const QRectF &canvasRect ) const
-{
-    if ( d_data->shape.isEmpty() )
+    return m_data->renderTolerance;
+}
+
+/*!
+   Draw the shape item
+
+   \param painter Painter
+   \param xMap X-Scale Map
+   \param yMap Y-Scale Map
+   \param canvasRect Contents rect of the plot canvas
+ */
+void QwtPlotShapeItem::draw( QPainter* painter,
+    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
+    const QRectF& canvasRect ) const
+{
+    if ( m_data->shape.isEmpty() )
         return;
 
-    if ( d_data->pen.style() == Qt::NoPen
-        && d_data->brush.style() == Qt::NoBrush )
+    if ( m_data->pen.style() == Qt::NoPen
+        && m_data->brush.style() == Qt::NoBrush )
     {
         return;
@@ -393,10 +399,10 @@
         xMap, yMap, canvasRect.toRect() );
 
-    const QRectF &br = d_data->boundingRect;
+    const QRectF& br = m_data->boundingRect;
 
     if ( ( br.left() > cr.right() ) || ( br.right() < cr.left() )
         || ( br.top() > cr.bottom() ) || ( br.bottom() < cr.top() ) )
     {
-        // outside the visisble area
+        // outside the visible area
         return;
     }
@@ -405,21 +411,19 @@
 
     QPainterPath path = qwtTransformPath( xMap, yMap,
-        d_data->shape, doAlign );
+        m_data->shape, doAlign );
 
     if ( testPaintAttribute( QwtPlotShapeItem::ClipPolygons ) )
     {
-        qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
-        QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
+        const qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
+        const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );
 
         QPainterPath clippedPath;
         clippedPath.setFillRule( path.fillRule() );
 
-        const QList<QPolygonF> polygons = path.toSubpathPolygons();
+        QList< QPolygonF > polygons = path.toSubpathPolygons();
         for ( int i = 0; i < polygons.size(); i++ )
         {
-            const QPolygonF p = QwtClipper::clipPolygonF(
-                clipRect, polygons[i], true );
-
-            clippedPath.addPolygon( p );
+            QwtClipper::clipPolygonF( clipRect, polygons[i], true );
+            clippedPath.addPolygon( polygons[i] );
 
         }
@@ -428,12 +432,12 @@
     }
 
-    if ( d_data->renderTolerance > 0.0 )
-    {
-        QwtWeedingCurveFitter fitter( d_data->renderTolerance );
+    if ( m_data->renderTolerance > 0.0 )
+    {
+        QwtWeedingCurveFitter fitter( m_data->renderTolerance );
 
         QPainterPath fittedPath;
         fittedPath.setFillRule( path.fillRule() );
 
-        const QList<QPolygonF> polygons = path.toSubpathPolygons();
+        const QList< QPolygonF > polygons = path.toSubpathPolygons();
         for ( int i = 0; i < polygons.size(); i++ )
             fittedPath.addPolygon( fitter.fitCurve( polygons[ i ] ) );
@@ -442,6 +446,6 @@
     }
 
-    painter->setPen( d_data->pen );
-    painter->setBrush( d_data->brush );
+    painter->setPen( m_data->pen );
+    painter->setBrush( m_data->brush );
 
     painter->drawPath( path );
@@ -449,14 +453,14 @@
 
 /*!
-  \return A rectangle filled with the color of the brush ( or the pen )
-
-  \param index Index of the legend entry
+   \return A rectangle filled with the color of the brush ( or the pen )
+
+   \param index Index of the legend entry
                 ( usually there is only one )
-  \param size Icon size
-
-  \sa setLegendIconSize(), legendData()
-*/
+   \param size Icon size
+
+   \sa setLegendIconSize(), legendData()
+ */
 QwtGraphic QwtPlotShapeItem::legendIcon( int index,
-    const QSizeF &size ) const
+    const QSizeF& size ) const
 {
     Q_UNUSED( index );
@@ -468,7 +472,7 @@
         return icon;
 
-    if ( d_data->legendMode == QwtPlotShapeItem::LegendShape )
-    {
-        const QRectF &br = d_data->boundingRect;
+    if ( m_data->legendMode == QwtPlotShapeItem::LegendShape )
+    {
+        const QRectF& br = m_data->boundingRect;
 
         QPainter painter( &icon );
@@ -478,15 +482,15 @@
         painter.translate( -br.topLeft() );
 
-        painter.setPen( d_data->pen );
-        painter.setBrush( d_data->brush );
-        painter.drawPath( d_data->shape );
+        painter.setPen( m_data->pen );
+        painter.setBrush( m_data->brush );
+        painter.drawPath( m_data->shape );
     }
     else
     {
         QColor iconColor;
-        if ( d_data->brush.style() != Qt::NoBrush )
-            iconColor = d_data->brush.color();
+        if ( m_data->brush.style() != Qt::NoBrush )
+            iconColor = m_data->brush.color();
         else
-            iconColor = d_data->pen.color();
+            iconColor = m_data->pen.color();
 
         icon = defaultIcon( iconColor, size );
