Index: trunk/BNC/qwt/qwt_graphic.cpp
===================================================================
--- trunk/BNC/qwt/qwt_graphic.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_graphic.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -10,4 +10,6 @@
 #include "qwt_graphic.h"
 #include "qwt_painter_command.h"
+#include "qwt_math.h"
+
 #include <qvector.h>
 #include <qpainter.h>
@@ -16,7 +18,17 @@
 #include <qpixmap.h>
 #include <qpainterpath.h>
-#include <qmath.h>
-
-static bool qwtHasScalablePen( const QPainter *painter )
+
+#if QT_VERSION >= 0x050000
+
+#include <qguiapplication.h>
+
+static inline qreal qwtDevicePixelRatio()
+{
+    return qGuiApp ? qGuiApp->devicePixelRatio() : 1.0;
+}
+
+#endif
+
+static bool qwtHasScalablePen( const QPainter* painter )
 {
     const QPen pen = painter->pen();
@@ -27,4 +39,5 @@
     {
         scalablePen = !pen.isCosmetic();
+#if QT_VERSION < 0x050000
         if ( !scalablePen && pen.widthF() == 0.0 )
         {
@@ -33,4 +46,5 @@
                 scalablePen = true;
         }
+#endif
     }
 
@@ -39,5 +53,5 @@
 
 static QRectF qwtStrokedPathRect(
-    const QPainter *painter, const QPainterPath &path )
+    const QPainter* painter, const QPainterPath& path )
 {
     QPainterPathStroker stroker;
@@ -50,10 +64,10 @@
     if ( qwtHasScalablePen( painter ) )
     {
-        QPainterPath stroke = stroker.createStroke(path);
-        rect = painter->transform().map(stroke).boundingRect();
+        QPainterPath stroke = stroker.createStroke( path );
+        rect = painter->transform().map( stroke ).boundingRect();
     }
     else
     {
-        QPainterPath mappedPath = painter->transform().map(path);
+        QPainterPath mappedPath = painter->transform().map( path );
         mappedPath = stroker.createStroke( mappedPath );
 
@@ -65,8 +79,8 @@
 
 static inline void qwtExecCommand(
-    QPainter *painter, const QwtPainterCommand &cmd,
+    QPainter* painter, const QwtPainterCommand& cmd,
     QwtGraphic::RenderHints renderHints,
-    const QTransform &transform,
-    const QTransform *initialTransform )
+    const QTransform& transform,
+    const QTransform* initialTransform )
 {
     switch( cmd.type() )
@@ -76,8 +90,8 @@
             bool doMap = false;
 
-            if ( renderHints.testFlag( QwtGraphic::RenderPensUnscaled )
-                && painter->transform().isScaling() )
+            if ( painter->transform().isScaling() )
             {
                 bool isCosmetic = painter->pen().isCosmetic();
+#if QT_VERSION < 0x050000
                 if ( isCosmetic && painter->pen().widthF() == 0.0 )
                 {
@@ -86,6 +100,17 @@
                         isCosmetic = false;
                 }
-
-                doMap = !isCosmetic;
+#endif
+
+                if ( isCosmetic )
+                {
+                    // OpenGL2 seems to be buggy for cosmetic pens.
+                    // It interpolates curves in too rough steps then
+
+                    doMap = painter->paintEngine()->type() == QPaintEngine::OpenGL2;
+                }
+                else
+                {
+                    doMap = renderHints.testFlag( QwtGraphic::RenderPensUnscaled );
+                }
             }
 
@@ -115,5 +140,5 @@
         case QwtPainterCommand::Pixmap:
         {
-            const QwtPainterCommand::PixmapData *data = cmd.pixmapData();
+            const QwtPainterCommand::PixmapData* data = cmd.pixmapData();
             painter->drawPixmap( data->rect, data->pixmap, data->subRect );
             break;
@@ -121,5 +146,5 @@
         case QwtPainterCommand::Image:
         {
-            const QwtPainterCommand::ImageData *data = cmd.imageData();
+            const QwtPainterCommand::ImageData* data = cmd.imageData();
             painter->drawImage( data->rect, data->image,
                 data->subRect, data->flags );
@@ -128,5 +153,5 @@
         case QwtPainterCommand::State:
         {
-            const QwtPainterCommand::StateData *data = cmd.stateData();
+            const QwtPainterCommand::StateData* data = cmd.stateData();
 
             if ( data->flags & QPaintEngine::DirtyPen )
@@ -156,5 +181,5 @@
                 painter->setClipping( data->isClipEnabled );
 
-            if ( data->flags & QPaintEngine::DirtyClipRegion)
+            if ( data->flags & QPaintEngine::DirtyClipRegion )
             {
                 painter->setClipRegion( data->clipRegion,
@@ -167,28 +192,17 @@
             }
 
-            if ( data->flags & QPaintEngine::DirtyHints)
+            if ( data->flags & QPaintEngine::DirtyHints )
             {
-                const QPainter::RenderHints hints = data->renderHints;
-
-                painter->setRenderHint( QPainter::Antialiasing,
-                    hints.testFlag( QPainter::Antialiasing ) );
-
-                painter->setRenderHint( QPainter::TextAntialiasing,
-                    hints.testFlag( QPainter::TextAntialiasing ) );
-
-                painter->setRenderHint( QPainter::SmoothPixmapTransform,
-                    hints.testFlag( QPainter::SmoothPixmapTransform ) );
-
-                painter->setRenderHint( QPainter::HighQualityAntialiasing,
-                    hints.testFlag( QPainter::HighQualityAntialiasing ) );
-
-                painter->setRenderHint( QPainter::NonCosmeticDefaultPen,
-                    hints.testFlag( QPainter::NonCosmeticDefaultPen ) );
+                for ( int i = 0; i < 8; i++ )
+                {
+                    const QPainter::RenderHint hint = static_cast< QPainter::RenderHint >( 1 << i );
+                    painter->setRenderHint( hint, data->renderHints.testFlag( hint ) );
+                }
             }
 
-            if ( data->flags & QPaintEngine::DirtyCompositionMode)
+            if ( data->flags & QPaintEngine::DirtyCompositionMode )
                 painter->setCompositionMode( data->compositionMode );
 
-            if ( data->flags & QPaintEngine::DirtyOpacity)
+            if ( data->flags & QPaintEngine::DirtyOpacity )
                 painter->setOpacity( data->opacity );
 
@@ -198,29 +212,27 @@
             break;
     }
-
 }
 
 class QwtGraphic::PathInfo
 {
-public:
-    PathInfo():
-        d_scalablePen( false )
+  public:
+    PathInfo()
+        : m_scalablePen( false )
     {
         // QVector needs a default constructor
     }
 
-    PathInfo( const QRectF &pointRect,
-            const QRectF &boundingRect, bool scalablePen ):
-        d_pointRect( pointRect ),
-        d_boundingRect( boundingRect ),
-        d_scalablePen( scalablePen )
-    {
-    }
-
-    inline QRectF scaledBoundingRect( double sx, double sy,
-        bool scalePens ) const
+    PathInfo( const QRectF& pointRect,
+            const QRectF& boundingRect, bool scalablePen )
+        : m_pointRect( pointRect )
+        , m_boundingRect( boundingRect )
+        , m_scalablePen( scalablePen )
+    {
+    }
+
+    inline QRectF scaledBoundingRect( qreal sx, qreal sy, bool scalePens ) const
     {
         if ( sx == 1.0 && sy == 1.0 )
-            return d_boundingRect;
+            return m_boundingRect;
 
         QTransform transform;
@@ -228,16 +240,16 @@
 
         QRectF rect;
-        if ( scalePens && d_scalablePen )
-        {
-            rect = transform.mapRect( d_boundingRect );
+        if ( scalePens && m_scalablePen )
+        {
+            rect = transform.mapRect( m_boundingRect );
         }
         else
         {
-            rect = transform.mapRect( d_pointRect );
-
-            const double l = qAbs( d_pointRect.left() - d_boundingRect.left() );
-            const double r = qAbs( d_pointRect.right() - d_boundingRect.right() );
-            const double t = qAbs( d_pointRect.top() - d_boundingRect.top() );
-            const double b = qAbs( d_pointRect.bottom() - d_boundingRect.bottom() );
+            rect = transform.mapRect( m_pointRect );
+
+            const qreal l = qAbs( m_pointRect.left() - m_boundingRect.left() );
+            const qreal r = qAbs( m_pointRect.right() - m_boundingRect.right() );
+            const qreal t = qAbs( m_pointRect.top() - m_boundingRect.top() );
+            const qreal b = qAbs( m_pointRect.bottom() - m_boundingRect.bottom() );
 
             rect.adjust( -l, -t, r, b );
@@ -248,29 +260,29 @@
 
     inline double scaleFactorX( const QRectF& pathRect,
-        const QRectF &targetRect, bool scalePens ) const
+        const QRectF& targetRect, bool scalePens ) const
     {
         if ( pathRect.width() <= 0.0 )
             return 0.0;
 
-        const QPointF p0 = d_pointRect.center();
-
-        const double l = qAbs( pathRect.left() - p0.x() );
-        const double r = qAbs( pathRect.right() - p0.x() );
-
-        const double w = 2.0 * qMin( l, r )
+        const QPointF p0 = m_pointRect.center();
+
+        const qreal l = qAbs( pathRect.left() - p0.x() );
+        const qreal r = qAbs( pathRect.right() - p0.x() );
+
+        const double w = 2.0 * qwtMinF( l, r )
             * targetRect.width() / pathRect.width();
 
         double sx;
-        if ( scalePens && d_scalablePen )
-        {
-            sx = w / d_boundingRect.width();
+        if ( scalePens && m_scalablePen )
+        {
+            sx = w / m_boundingRect.width();
         }
         else
         {
-            const double pw = qMax(
-                qAbs( d_boundingRect.left() - d_pointRect.left() ),
-                qAbs( d_boundingRect.right() - d_pointRect.right() ) );
-
-            sx = ( w - 2 * pw ) / d_pointRect.width();
+            const qreal pw = qwtMaxF(
+                qAbs( m_boundingRect.left() - m_pointRect.left() ),
+                qAbs( m_boundingRect.right() - m_pointRect.right() ) );
+
+            sx = ( w - 2 * pw ) / m_pointRect.width();
         }
 
@@ -279,29 +291,29 @@
 
     inline double scaleFactorY( const QRectF& pathRect,
-        const QRectF &targetRect, bool scalePens ) const
+        const QRectF& targetRect, bool scalePens ) const
     {
         if ( pathRect.height() <= 0.0 )
             return 0.0;
 
-        const QPointF p0 = d_pointRect.center();
-
-        const double t = qAbs( pathRect.top() - p0.y() );
-        const double b = qAbs( pathRect.bottom() - p0.y() );
-
-        const double h = 2.0 * qMin( t, b )
+        const QPointF p0 = m_pointRect.center();
+
+        const qreal t = qAbs( pathRect.top() - p0.y() );
+        const qreal b = qAbs( pathRect.bottom() - p0.y() );
+
+        const qreal h = 2.0 * qwtMinF( t, b )
             * targetRect.height() / pathRect.height();
 
         double sy;
-        if ( scalePens && d_scalablePen )
-        {
-            sy = h / d_boundingRect.height();
+        if ( scalePens && m_scalablePen )
+        {
+            sy = h / m_boundingRect.height();
         }
         else
         {
-            const double pw =
-                qMax( qAbs( d_boundingRect.top() - d_pointRect.top() ),
-                qAbs( d_boundingRect.bottom() - d_pointRect.bottom() ) );
-
-            sy = ( h - 2 * pw ) / d_pointRect.height();
+            const qreal pw = qwtMaxF(
+                qAbs( m_boundingRect.top() - m_pointRect.top() ),
+                qAbs( m_boundingRect.bottom() - m_pointRect.bottom() ) );
+
+            sy = ( h - 2 * pw ) / m_pointRect.height();
         }
 
@@ -309,55 +321,52 @@
     }
 
-private:
-    QRectF d_pointRect;
-    QRectF d_boundingRect;
-    bool d_scalablePen;
+  private:
+    QRectF m_pointRect;
+    QRectF m_boundingRect;
+    bool m_scalablePen;
 };
 
 class QwtGraphic::PrivateData
 {
-public:
-    PrivateData():
-        boundingRect( 0.0, 0.0, -1.0, -1.0 ),
-        pointRect( 0.0, 0.0, -1.0, -1.0 ),
-        initialTransform( NULL )
+  public:
+    PrivateData()
+        : boundingRect( 0.0, 0.0, -1.0, -1.0 )
+        , pointRect( 0.0, 0.0, -1.0, -1.0 )
     {
     }
 
     QSizeF defaultSize;
-    QVector<QwtPainterCommand> commands;
-    QVector<QwtGraphic::PathInfo> pathInfos;
+    QVector< QwtPainterCommand > commands;
+    QVector< QwtGraphic::PathInfo > pathInfos;
 
     QRectF boundingRect;
     QRectF pointRect;
 
+    QwtGraphic::CommandTypes commandTypes;
     QwtGraphic::RenderHints renderHints;
-    QTransform *initialTransform;
 };
 
 /*!
-  \brief Constructor
-
-  Initializes a null graphic
-  \sa isNull()
- */
-QwtGraphic::QwtGraphic():
-    QwtNullPaintDevice()
+   \brief Constructor
+
+   Initializes a null graphic
+   \sa isNull()
+ */
+QwtGraphic::QwtGraphic()
 {
     setMode( QwtNullPaintDevice::PathMode );
-    d_data = new PrivateData;
-}
-
-/*!
-  \brief Copy constructor
-
-  \param other Source
-  \sa operator=()
- */
-QwtGraphic::QwtGraphic( const QwtGraphic &other ):
-    QwtNullPaintDevice()
+    m_data = new PrivateData;
+}
+
+/*!
+   \brief Copy constructor
+
+   \param other Source
+   \sa operator=()
+ */
+QwtGraphic::QwtGraphic( const QwtGraphic& other )
 {
     setMode( other.mode() );
-    d_data = new PrivateData( *other.d_data );
+    m_data = new PrivateData( *other.m_data );
 }
 
@@ -365,17 +374,17 @@
 QwtGraphic::~QwtGraphic()
 {
-    delete d_data;
-}
-
-/*!
-  \brief Assignment operator
-
-  \param other Source
-  \return A reference of this object
- */
-QwtGraphic& QwtGraphic::operator=(const QwtGraphic &other)
+    delete m_data;
+}
+
+/*!
+   \brief Assignment operator
+
+   \param other Source
+   \return A reference of this object
+ */
+QwtGraphic& QwtGraphic::operator=( const QwtGraphic& other )
 {
     setMode( other.mode() );
-    *d_data = *other.d_data;
+    *m_data = *other.m_data;
 
     return *this;
@@ -383,124 +392,138 @@
 
 /*!
-  \brief Clear all stored commands
-  \sa isNull()
+   \brief Clear all stored commands
+   \sa isNull()
  */
 void QwtGraphic::reset()
 {
-    d_data->commands.clear();
-    d_data->pathInfos.clear();
-
-    d_data->boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
-    d_data->pointRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
-    d_data->defaultSize = QSizeF();
-
-}
-
-/*!
-  \return True, when no painter commands have been stored
-  \sa isEmpty(), commands()
-*/
+    m_data->commands.clear();
+    m_data->pathInfos.clear();
+
+    m_data->commandTypes = CommandTypes();
+
+    m_data->boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
+    m_data->pointRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
+    m_data->defaultSize = QSizeF();
+}
+
+/*!
+   \return True, when no painter commands have been stored
+   \sa isEmpty(), commands()
+ */
 bool QwtGraphic::isNull() const
 {
-    return d_data->commands.isEmpty();
-}
-
-/*!
-  \return True, when the bounding rectangle is empty
-  \sa boundingRect(), isNull()
-*/
+    return m_data->commands.isEmpty();
+}
+
+/*!
+   \return True, when the bounding rectangle is empty
+   \sa boundingRect(), isNull()
+ */
 bool QwtGraphic::isEmpty() const
 {
-    return d_data->boundingRect.isEmpty();
-}
-
-/*!
-  Toggle an render hint
-
-  \param hint Render hint
-  \param on true/false
-
-  \sa testRenderHint(), RenderHint
-*/
+    return m_data->boundingRect.isEmpty();
+}
+
+/*!
+   \return Types of painter commands being used
+ */
+QwtGraphic::CommandTypes QwtGraphic::commandTypes() const
+{
+    return m_data->commandTypes;
+}
+
+/*!
+   Toggle an render hint
+
+   \param hint Render hint
+   \param on true/false
+
+   \sa testRenderHint(), RenderHint
+ */
 void QwtGraphic::setRenderHint( RenderHint hint, bool on )
 {
     if ( on )
-        d_data->renderHints |= hint;
+        m_data->renderHints |= hint;
     else
-        d_data->renderHints &= ~hint;
-}
-
-/*!
-  Test a render hint
-
-  \param hint Render hint
-  \return true/false
-  \sa setRenderHint(), RenderHint
-*/
+        m_data->renderHints &= ~hint;
+}
+
+/*!
+   Test a render hint
+
+   \param hint Render hint
+   \return true/false
+   \sa setRenderHint(), RenderHint
+ */
 bool QwtGraphic::testRenderHint( RenderHint hint ) const
 {
-    return d_data->renderHints.testFlag( hint );
-}
-
-/*!
-  The bounding rectangle is the controlPointRect()
-  extended by the areas needed for rendering the outlines
-  with unscaled pens.
-
-  \return Bounding rectangle of the graphic
-  \sa controlPointRect(), scaledBoundingRect()
+    return m_data->renderHints.testFlag( hint );
+}
+
+//! \return Render hints
+QwtGraphic::RenderHints QwtGraphic::renderHints() const
+{
+    return m_data->renderHints;
+}
+
+/*!
+   The bounding rectangle is the controlPointRect()
+   extended by the areas needed for rendering the outlines
+   with unscaled pens.
+
+   \return Bounding rectangle of the graphic
+   \sa controlPointRect(), scaledBoundingRect()
  */
 QRectF QwtGraphic::boundingRect() const
 {
-    if ( d_data->boundingRect.width() < 0 )
+    if ( m_data->boundingRect.width() < 0 )
         return QRectF();
 
-    return d_data->boundingRect;
-}
-
-/*!
-  The control point rectangle is the bounding rectangle
-  of all control points of the paths and the target
-  rectangles of the images/pixmaps.
-
-  \return Control point rectangle
-  \sa boundingRect(), scaledBoundingRect()
+    return m_data->boundingRect;
+}
+
+/*!
+   The control point rectangle is the bounding rectangle
+   of all control points of the paths and the target
+   rectangles of the images/pixmaps.
+
+   \return Control point rectangle
+   \sa boundingRect(), scaledBoundingRect()
  */
 QRectF QwtGraphic::controlPointRect() const
 {
-    if ( d_data->pointRect.width() < 0 )
+    if ( m_data->pointRect.width() < 0 )
         return QRectF();
 
-    return d_data->pointRect;
-}
-
-/*!
-  \brief Calculate the target rectangle for scaling the graphic
-
-  \param sx Horizontal scaling factor
-  \param sy Vertical scaling factor
-
-  \note In case of paths that are painted with a cosmetic pen
+    return m_data->pointRect;
+}
+
+/*!
+   \brief Calculate the target rectangle for scaling the graphic
+
+   \param sx Horizontal scaling factor
+   \param sy Vertical scaling factor
+
+   \note In case of paths that are painted with a cosmetic pen
         ( see QPen::isCosmetic() ) the target rectangle is different to
         multiplying the bounding rectangle.
 
-  \return Scaled bounding rectangle
-  \sa boundingRect(), controlPointRect()
- */
-QRectF QwtGraphic::scaledBoundingRect( double sx, double sy ) const
+   \return Scaled bounding rectangle
+   \sa boundingRect(), controlPointRect()
+ */
+QRectF QwtGraphic::scaledBoundingRect( qreal sx, qreal sy ) const
 {
     if ( sx == 1.0 && sy == 1.0 )
-        return d_data->boundingRect;
+        return m_data->boundingRect;
+
+    const bool scalePens = !( m_data->renderHints & RenderPensUnscaled );
 
     QTransform transform;
     transform.scale( sx, sy );
 
-    QRectF rect = transform.mapRect( d_data->pointRect );
-
-    for ( int i = 0; i < d_data->pathInfos.size(); i++ )
-    {
-        rect |= d_data->pathInfos[i].scaledBoundingRect( sx, sy,
-            !d_data->renderHints.testFlag( RenderPensUnscaled ) );
-    }
+    QRectF rect = transform.mapRect( m_data->pointRect );
+
+    for ( int i = 0; i < m_data->pathInfos.size(); i++ )
+        rect |= m_data->pathInfos[i].scaledBoundingRect( sx, sy, scalePens );
 
     return rect;
@@ -511,46 +534,46 @@
 {
     const QSizeF sz = defaultSize();
-    return QSize( qCeil( sz.width() ), qCeil( sz.height() ) );
-}
-
-/*!
-  \brief Set a default size
-
-  The default size is used in all methods rendering the graphic,
-  where no size is explicitly specified. Assigning an empty size
-  means, that the default size will be calculated from the bounding
-  rectangle.
-
-  The default setting is an empty size.
-
-  \param size Default size
-
-  \sa defaultSize(), boundingRect()
- */
-void QwtGraphic::setDefaultSize( const QSizeF &size )
-{
-    const double w = qMax( qreal( 0.0 ), size.width() );
-    const double h = qMax( qreal( 0.0 ), size.height() );
-
-    d_data->defaultSize = QSizeF( w, h );
-}
-
-/*!
-  \brief Default size
-
-  When a non empty size has been assigned by setDefaultSize() this
-  size will be returned. Otherwise the default size is the size
-  of the bounding rectangle.
-
-  The default size is used in all methods rendering the graphic,
-  where no size is explicitly specified.
-
-  \return Default size
-  \sa setDefaultSize(), boundingRect()
+    return QSize( qwtCeil( sz.width() ), qwtCeil( sz.height() ) );
+}
+
+/*!
+   \brief Set a default size
+
+   The default size is used in all methods rendering the graphic,
+   where no size is explicitly specified. Assigning an empty size
+   means, that the default size will be calculated from the bounding
+   rectangle.
+
+   The default setting is an empty size.
+
+   \param size Default size
+
+   \sa defaultSize(), boundingRect()
+ */
+void QwtGraphic::setDefaultSize( const QSizeF& size )
+{
+    const double w = qwtMaxF( 0.0, size.width() );
+    const double h = qwtMaxF( 0.0, size.height() );
+
+    m_data->defaultSize = QSizeF( w, h );
+}
+
+/*!
+   \brief Default size
+
+   When a non empty size has been assigned by setDefaultSize() this
+   size will be returned. Otherwise the default size is the size
+   of the bounding rectangle.
+
+   The default size is used in all methods rendering the graphic,
+   where no size is explicitly specified.
+
+   \return Default size
+   \sa setDefaultSize(), boundingRect()
  */
 QSizeF QwtGraphic::defaultSize() const
 {
-    if ( !d_data->defaultSize.isEmpty() )
-        return d_data->defaultSize;
+    if ( !m_data->defaultSize.isEmpty() )
+        return m_data->defaultSize;
 
     return boundingRect().size();
@@ -558,14 +581,57 @@
 
 /*!
-  \brief Replay all recorded painter commands
-  \param painter Qt painter
- */
-void QwtGraphic::render( QPainter *painter ) const
+   Find the height for a given width
+
+   The height is calculated using the aspect ratio of defaultSize().
+
+   \param width Width
+
+   \return Calculated height
+   \sa defaultSize()
+ */
+qreal QwtGraphic::heightForWidth( qreal width ) const
+{
+    const QSizeF sz = defaultSize();
+    if ( sz.isEmpty() )
+        return 0.0;
+
+    return sz.height() * width / sz.width();
+}
+
+/*!
+   Find the width for a given height
+
+   The width is calculated using the aspect ratio of defaultSize().
+
+   \param height Height
+
+   \return Calculated width
+   \sa defaultSize()
+ */
+qreal QwtGraphic::widthForHeight( qreal height ) const
+{
+    const QSizeF sz = defaultSize();
+    if ( sz.isEmpty() )
+        return 0.0;
+
+    return sz.width() * height / sz.height();
+}
+
+/*!
+   \brief Replay all recorded painter commands
+   \param painter Qt painter
+ */
+void QwtGraphic::render( QPainter* painter ) const
+{
+    renderGraphic( painter, NULL );
+}
+
+void QwtGraphic::renderGraphic( QPainter* painter, QTransform* initialTransform ) const
 {
     if ( isNull() )
         return;
 
-    const int numCommands = d_data->commands.size();
-    const QwtPainterCommand *commands = d_data->commands.constData();
+    const int numCommands = m_data->commands.size();
+    const QwtPainterCommand* commands = m_data->commands.constData();
 
     const QTransform transform = painter->transform();
@@ -576,5 +642,5 @@
     {
         qwtExecCommand( painter, commands[i],
-            d_data->renderHints, transform, d_data->initialTransform );
+            m_data->renderHints, transform, initialTransform );
     }
 
@@ -583,14 +649,14 @@
 
 /*!
-  \brief Replay all recorded painter commands
-
-  The graphic is scaled to fit into the rectangle
-  of the given size starting at ( 0, 0 ).
-
-  \param painter Qt painter
-  \param size Size for the scaled graphic
-  \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode
- */
-void QwtGraphic::render( QPainter *painter, const QSizeF &size,
+   \brief Replay all recorded painter commands
+
+   The graphic is scaled to fit into the rectangle
+   of the given size starting at ( 0, 0 ).
+
+   \param painter Qt painter
+   \param size Size for the scaled graphic
+   \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode
+ */
+void QwtGraphic::render( QPainter* painter, const QSizeF& size,
     Qt::AspectRatioMode aspectRatioMode ) const
 {
@@ -600,13 +666,13 @@
 
 /*!
-  \brief Replay all recorded painter commands
-
-  The graphic is scaled to fit into the given rectangle
-
-  \param painter Qt painter
-  \param rect Rectangle for the scaled graphic
-  \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode
- */
-void QwtGraphic::render( QPainter *painter, const QRectF &rect,
+   \brief Replay all recorded painter commands
+
+   The graphic is scaled to fit into the given rectangle
+
+   \param painter Qt painter
+   \param rect Rectangle for the scaled graphic
+   \param aspectRatioMode Mode how to scale - See Qt::AspectRatioMode
+ */
+void QwtGraphic::render( QPainter* painter, const QRectF& rect,
     Qt::AspectRatioMode aspectRatioMode ) const
 {
@@ -617,33 +683,32 @@
     double sy = 1.0;
 
-    if ( d_data->pointRect.width() > 0.0 )
-        sx = rect.width() / d_data->pointRect.width();
-
-    if ( d_data->pointRect.height() > 0.0 )
-        sy = rect.height() / d_data->pointRect.height();
-
-    const bool scalePens =
-        !d_data->renderHints.testFlag( RenderPensUnscaled );
-
-    for ( int i = 0; i < d_data->pathInfos.size(); i++ )
-    {
-        const PathInfo info = d_data->pathInfos[i];
+    if ( m_data->pointRect.width() > 0.0 )
+        sx = rect.width() / m_data->pointRect.width();
+
+    if ( m_data->pointRect.height() > 0.0 )
+        sy = rect.height() / m_data->pointRect.height();
+
+    const bool scalePens = !m_data->renderHints.testFlag( RenderPensUnscaled );
+
+    for ( int i = 0; i < m_data->pathInfos.size(); i++ )
+    {
+        const PathInfo& info = m_data->pathInfos[i];
 
         const double ssx = info.scaleFactorX(
-            d_data->pointRect, rect, scalePens );
+            m_data->pointRect, rect, scalePens );
 
         if ( ssx > 0.0 )
-            sx = qMin( sx, ssx );
+            sx = qwtMinF( sx, ssx );
 
         const double ssy = info.scaleFactorY(
-            d_data->pointRect, rect, scalePens );
+            m_data->pointRect, rect, scalePens );
 
         if ( ssy > 0.0 )
-            sy = qMin( sy, ssy );
+            sy = qwtMinF( sy, ssy );
     }
 
     if ( aspectRatioMode == Qt::KeepAspectRatio )
     {
-        const double s = qMin( sx, sy );
+        const qreal s = qwtMinF( sx, sy );
         sx = s;
         sy = s;
@@ -651,5 +716,5 @@
     else if ( aspectRatioMode == Qt::KeepAspectRatioByExpanding )
     {
-        const double s = qMax( sx, sy );
+        const qreal s = qwtMaxF( sx, sy );
         sx = s;
         sy = s;
@@ -657,10 +722,13 @@
 
     QTransform tr;
-    tr.translate( rect.center().x() - 0.5 * sx * d_data->pointRect.width(),
-        rect.center().y() - 0.5 * sy * d_data->pointRect.height() );
+    tr.translate( rect.center().x() - 0.5 * sx * m_data->pointRect.width(),
+        rect.center().y() - 0.5 * sy * m_data->pointRect.height() );
     tr.scale( sx, sy );
-    tr.translate( -d_data->pointRect.x(), -d_data->pointRect.y() );
+    tr.translate( -m_data->pointRect.x(), -m_data->pointRect.y() );
 
     const QTransform transform = painter->transform();
+
+    painter->setTransform( tr, true );
+
     if ( !scalePens && transform.isScaling() )
     {
@@ -669,30 +737,29 @@
         // painter transformation later
 
-        d_data->initialTransform = new QTransform();
-        d_data->initialTransform->scale( transform.m11(), transform.m22() );
-    }
-
-    painter->setTransform( tr, true );
-    render( painter );
+        QTransform initialTransform;
+        initialTransform.scale( transform.m11(), transform.m22() );
+
+        renderGraphic( painter, &initialTransform );
+    }
+    else
+    {
+        renderGraphic( painter, NULL );
+    }
 
     painter->setTransform( transform );
-
-    delete d_data->initialTransform;
-    d_data->initialTransform = NULL;
-}
-
-/*!
-  \brief Replay all recorded painter commands
-
-  The graphic is scaled to the defaultSize() and aligned
-  to a position.
-
-  \param painter Qt painter
-  \param pos Reference point, where to render
-  \param alignment Flags how to align the target rectangle
-                   to pos.
- */
-void QwtGraphic::render( QPainter *painter,
-    const QPointF &pos, Qt::Alignment alignment ) const
+}
+
+/*!
+   \brief Replay all recorded painter commands
+
+   The graphic is scaled to the defaultSize() and aligned
+   to a position.
+
+   \param painter Qt painter
+   \param pos Reference point, where to render
+   \param alignment Flags how to align the target rectangle to pos.
+ */
+void QwtGraphic::render( QPainter* painter,
+    const QPointF& pos, Qt::Alignment alignment ) const
 {
     QRectF r( pos, defaultSize() );
@@ -728,16 +795,20 @@
 
 /*!
-  \brief Convert the graphic to a QPixmap
-
-  All pixels of the pixmap get initialized by Qt::transparent
-  before the graphic is scaled and rendered on it.
-
-  The size of the pixmap is the default size ( ceiled to integers )
-  of the graphic.
-
-  \return The graphic as pixmap in default size
-  \sa defaultSize(), toImage(), render()
- */
-QPixmap QwtGraphic::toPixmap() const
+   \brief Convert the graphic to a QPixmap
+
+   All pixels of the pixmap get initialized by Qt::transparent
+   before the graphic is scaled and rendered on it.
+
+   The size of the pixmap is the default size ( ceiled to integers )
+   of the graphic.
+
+   \param devicePixelRatio Device pixel ratio for the pixmap.
+                          If devicePixelRatio <= 0.0 the pixmap
+                          is initialized with the system default.
+
+   \return The graphic as pixmap in default size
+   \sa defaultSize(), toImage(), render()
+ */
+QPixmap QwtGraphic::toPixmap( qreal devicePixelRatio ) const
 {
     if ( isNull() )
@@ -746,8 +817,22 @@
     const QSizeF sz = defaultSize();
 
-    const int w = qCeil( sz.width() );
-    const int h = qCeil( sz.height() );
+#if QT_VERSION >= 0x050000
+    if ( devicePixelRatio <= 0.0 )
+        devicePixelRatio = qwtDevicePixelRatio();
+
+    const int w = qwtCeil( sz.width() * devicePixelRatio );
+    const int h = qwtCeil( sz.height() * devicePixelRatio );
 
     QPixmap pixmap( w, h );
+    pixmap.setDevicePixelRatio( devicePixelRatio );
+#else
+    Q_UNUSED( devicePixelRatio )
+
+    const int w = qwtCeil( sz.width() );
+    const int h = qwtCeil( sz.height() );
+
+    QPixmap pixmap( w, h );
+#endif
+
     pixmap.fill( Qt::transparent );
 
@@ -762,19 +847,34 @@
 
 /*!
-  \brief Convert the graphic to a QPixmap
-
-  All pixels of the pixmap get initialized by Qt::transparent
-  before the graphic is scaled and rendered on it.
-
-  \param size Size of the image
-  \param aspectRatioMode Aspect ratio how to scale the graphic
-
-  \return The graphic as pixmap
-  \sa toImage(), render()
- */
-QPixmap QwtGraphic::toPixmap( const QSize &size,
-    Qt::AspectRatioMode aspectRatioMode ) const
-{
+   \brief Convert the graphic to a QPixmap
+
+   All pixels of the pixmap get initialized by Qt::transparent
+   before the graphic is scaled and rendered on it.
+
+   \param size Size of the image
+   \param aspectRatioMode Aspect ratio how to scale the graphic
+   \param devicePixelRatio Device pixel ratio for the pixmap.
+                          If devicePixelRatio <= 0.0 the pixmap
+                          is initialized with the system default.
+
+   \return The graphic as pixmap
+   \sa toImage(), render()
+ */
+QPixmap QwtGraphic::toPixmap( const QSize& size,
+    Qt::AspectRatioMode aspectRatioMode, qreal devicePixelRatio ) const
+{
+#if QT_VERSION >= 0x050000
+    if ( devicePixelRatio <= 0.0 )
+        devicePixelRatio = qwtDevicePixelRatio();
+
+    const int w = qwtCeil( size.width() * devicePixelRatio );
+    const int h = qwtCeil( size.height() * devicePixelRatio );
+
+    QPixmap pixmap( w, h );
+    pixmap.setDevicePixelRatio( devicePixelRatio );
+#else
+    Q_UNUSED( devicePixelRatio )
     QPixmap pixmap( size );
+#endif
     pixmap.fill( Qt::transparent );
 
@@ -789,21 +889,37 @@
 
 /*!
-  \brief Convert the graphic to a QImage
-
-  All pixels of the image get initialized by 0 ( transparent )
-  before the graphic is scaled and rendered on it.
-
-  The format of the image is QImage::Format_ARGB32_Premultiplied.
-
-  \param size Size of the image
-  \param aspectRatioMode Aspect ratio how to scale the graphic
-
-  \return The graphic as image
-  \sa toPixmap(), render()
- */
-QImage QwtGraphic::toImage( const QSize &size,
-    Qt::AspectRatioMode aspectRatioMode  ) const
-{
+   \brief Convert the graphic to a QImage
+
+   All pixels of the image get initialized by 0 ( transparent )
+   before the graphic is scaled and rendered on it.
+
+   The format of the image is QImage::Format_ARGB32_Premultiplied.
+
+   \param size Size of the image ( will be multiplied by the devicePixelRatio )
+   \param aspectRatioMode Aspect ratio how to scale the graphic
+   \param devicePixelRatio Device pixel ratio for the image.
+                          If devicePixelRatio <= 0.0 the pixmap
+                          is initialized with the system default.
+
+   \return The graphic as image
+   \sa toPixmap(), render()
+ */
+QImage QwtGraphic::toImage( const QSize& size,
+    Qt::AspectRatioMode aspectRatioMode, qreal devicePixelRatio  ) const
+{
+#if QT_VERSION >= 0x050000
+    if ( devicePixelRatio <= 0.0 )
+        devicePixelRatio = qwtDevicePixelRatio();
+
+    const int w = qwtCeil( size.width() * devicePixelRatio );
+    const int h = qwtCeil( size.height() * devicePixelRatio );
+
+    QImage image( w, h, QImage::Format_ARGB32_Premultiplied );
+    image.setDevicePixelRatio( devicePixelRatio );
+#else
+    Q_UNUSED( devicePixelRatio )
     QImage image( size, QImage::Format_ARGB32_Premultiplied );
+#endif
+
     image.fill( 0 );
 
@@ -818,18 +934,22 @@
 
 /*!
-  \brief Convert the graphic to a QImage
-
-  All pixels of the image get initialized by 0 ( transparent )
-  before the graphic is scaled and rendered on it.
-
-  The format of the image is QImage::Format_ARGB32_Premultiplied.
-
-  The size of the image is the default size ( ceiled to integers )
-  of the graphic.
-
-  \return The graphic as image in default size
-  \sa defaultSize(), toPixmap(), render()
- */
-QImage QwtGraphic::toImage() const
+   \brief Convert the graphic to a QImage
+
+   All pixels of the image get initialized by 0 ( transparent )
+   before the graphic is scaled and rendered on it.
+
+   The format of the image is QImage::Format_ARGB32_Premultiplied.
+
+   The size of the image is the default size ( ceiled to integers )
+   of the graphic multiplied by the devicePixelRatio.
+
+   \param devicePixelRatio Device pixel ratio for the image.
+                          If devicePixelRatio <= 0.0 the pixmap
+                          is initialized with the system default.
+
+   \return The graphic as image in default size
+   \sa defaultSize(), toPixmap(), render()
+ */
+QImage QwtGraphic::toImage( qreal devicePixelRatio ) const
 {
     if ( isNull() )
@@ -838,8 +958,22 @@
     const QSizeF sz = defaultSize();
 
-    const int w = qCeil( sz.width() );
-    const int h = qCeil( sz.height() );
+#if QT_VERSION >= 0x050000
+    if ( devicePixelRatio <= 0.0 )
+        devicePixelRatio = qwtDevicePixelRatio();
+
+    const int w = qwtCeil( sz.width() * devicePixelRatio );
+    const int h = qwtCeil( sz.height() * devicePixelRatio );
 
     QImage image( w, h, QImage::Format_ARGB32 );
+    image.setDevicePixelRatio( devicePixelRatio );
+#else
+    Q_UNUSED( devicePixelRatio )
+
+    const int w = qwtCeil( sz.width() );
+    const int h = qwtCeil( sz.height() );
+
+    QImage image( w, h, QImage::Format_ARGB32 );
+#endif
+
     image.fill( 0 );
 
@@ -854,16 +988,17 @@
 
 /*!
-  Store a path command in the command list
-
-  \param path Painter path
-  \sa QPaintEngine::drawPath()
-*/
-void QwtGraphic::drawPath( const QPainterPath &path )
-{
-    const QPainter *painter = paintEngine()->painter();
+   Store a path command in the command list
+
+   \param path Painter path
+   \sa QPaintEngine::drawPath()
+ */
+void QwtGraphic::drawPath( const QPainterPath& path )
+{
+    const QPainter* painter = paintEngine()->painter();
     if ( painter == NULL )
         return;
 
-    d_data->commands += QwtPainterCommand( path );
+    m_data->commands += QwtPainterCommand( path );
+    m_data->commandTypes |= QwtGraphic::VectorData;
 
     if ( !path.isEmpty() )
@@ -883,5 +1018,5 @@
         updateBoundingRect( boundingRect );
 
-        d_data->pathInfos += PathInfo( pointRect,
+        m_data->pathInfos += PathInfo( pointRect,
             boundingRect, qwtHasScalablePen( painter ) );
     }
@@ -889,20 +1024,21 @@
 
 /*!
-  \brief Store a pixmap command in the command list
-
-  \param rect target rectangle
-  \param pixmap Pixmap to be painted
-  \param subRect Reactangle of the pixmap to be painted
-
-  \sa QPaintEngine::drawPixmap()
-*/
-void QwtGraphic::drawPixmap( const QRectF &rect,
-    const QPixmap &pixmap, const QRectF &subRect )
-{
-    const QPainter *painter = paintEngine()->painter();
+   \brief Store a pixmap command in the command list
+
+   \param rect target rectangle
+   \param pixmap Pixmap to be painted
+   \param subRect Reactangle of the pixmap to be painted
+
+   \sa QPaintEngine::drawPixmap()
+ */
+void QwtGraphic::drawPixmap( const QRectF& rect,
+    const QPixmap& pixmap, const QRectF& subRect )
+{
+    const QPainter* painter = paintEngine()->painter();
     if ( painter == NULL )
         return;
 
-    d_data->commands += QwtPainterCommand( rect, pixmap, subRect );
+    m_data->commands += QwtPainterCommand( rect, pixmap, subRect );
+    m_data->commandTypes |= QwtGraphic::RasterData;
 
     const QRectF r = painter->transform().mapRect( rect );
@@ -912,21 +1048,22 @@
 
 /*!
-  \brief Store a image command in the command list
-
-  \param rect traget rectangle
-  \param image Image to be painted
-  \param subRect Reactangle of the pixmap to be painted
-  \param flags Image conversion flags
-
-  \sa QPaintEngine::drawImage()
- */
-void QwtGraphic::drawImage( const QRectF &rect, const QImage &image,
-    const QRectF &subRect, Qt::ImageConversionFlags flags)
-{
-    const QPainter *painter = paintEngine()->painter();
+   \brief Store a image command in the command list
+
+   \param rect target rectangle
+   \param image Image to be painted
+   \param subRect Reactangle of the pixmap to be painted
+   \param flags Image conversion flags
+
+   \sa QPaintEngine::drawImage()
+ */
+void QwtGraphic::drawImage( const QRectF& rect, const QImage& image,
+    const QRectF& subRect, Qt::ImageConversionFlags flags )
+{
+    const QPainter* painter = paintEngine()->painter();
     if ( painter == NULL )
         return;
 
-    d_data->commands += QwtPainterCommand( rect, image, subRect, flags );
+    m_data->commands += QwtPainterCommand( rect, image, subRect, flags );
+    m_data->commandTypes |= QwtGraphic::RasterData;
 
     const QRectF r = painter->transform().mapRect( rect );
@@ -937,19 +1074,33 @@
 
 /*!
-  \brief Store a state command in the command list
-
-  \param state State to be stored
-  \sa QPaintEngine::updateState()
- */
-void QwtGraphic::updateState( const QPaintEngineState &state)
-{
-    d_data->commands += QwtPainterCommand( state );
-}
-
-void QwtGraphic::updateBoundingRect( const QRectF &rect )
+   \brief Store a state command in the command list
+
+   \param state State to be stored
+   \sa QPaintEngine::updateState()
+ */
+void QwtGraphic::updateState( const QPaintEngineState& state )
+{
+    m_data->commands += QwtPainterCommand( state );
+
+    if ( state.state() & QPaintEngine::DirtyTransform )
+    {
+        if ( !( m_data->commandTypes & QwtGraphic::Transformation ) )
+        {
+            /*
+                QTransform::isScaling() returns true for all type
+                of transformations beside simple translations
+                even if it is f.e a rotation
+             */
+            if ( state.transform().isScaling() )
+                m_data->commandTypes |= QwtGraphic::Transformation;
+        }
+    }
+}
+
+void QwtGraphic::updateBoundingRect( const QRectF& rect )
 {
     QRectF br = rect;
 
-    const QPainter *painter = paintEngine()->painter();
+    const QPainter* painter = paintEngine()->painter();
     if ( painter && painter->hasClipping() )
     {
@@ -960,34 +1111,34 @@
     }
 
-    if ( d_data->boundingRect.width() < 0 )
-        d_data->boundingRect = br;
+    if ( m_data->boundingRect.width() < 0 )
+        m_data->boundingRect = br;
     else
-        d_data->boundingRect |= br;
-}
-
-void QwtGraphic::updateControlPointRect( const QRectF &rect )
-{
-    if ( d_data->pointRect.width() < 0.0 )
-        d_data->pointRect = rect;
+        m_data->boundingRect |= br;
+}
+
+void QwtGraphic::updateControlPointRect( const QRectF& rect )
+{
+    if ( m_data->pointRect.width() < 0.0 )
+        m_data->pointRect = rect;
     else
-        d_data->pointRect |= rect;
-}
-
-/*!
-  \return List of recorded paint commands
-  \sa setCommands()
- */
-const QVector< QwtPainterCommand > &QwtGraphic::commands() const
-{
-    return d_data->commands;
-}
-
-/*!
-  \brief Append paint commands
-
-  \param commands Paint commands
-  \sa commands()
- */
-void QwtGraphic::setCommands( QVector< QwtPainterCommand > &commands )
+        m_data->pointRect |= rect;
+}
+
+/*!
+   \return List of recorded paint commands
+   \sa setCommands()
+ */
+const QVector< QwtPainterCommand >& QwtGraphic::commands() const
+{
+    return m_data->commands;
+}
+
+/*!
+   \brief Append paint commands
+
+   \param commands Paint commands
+   \sa commands()
+ */
+void QwtGraphic::setCommands( const QVector< QwtPainterCommand >& commands )
 {
     reset();
@@ -1000,9 +1151,12 @@
     // the commands.
 
-    const QwtPainterCommand *cmds = commands.constData();
+    const QwtPainterCommand* cmds = commands.constData();
+
+    const QTransform noTransform;
+    const RenderHints noRenderHints;
 
     QPainter painter( this );
     for ( int i = 0; i < numCommands; i++ )
-        qwtExecCommand( &painter, cmds[i], RenderHints(), QTransform(), NULL );
+        qwtExecCommand( &painter, cmds[i], noRenderHints, noTransform, NULL );
 
     painter.end();
