Index: trunk/BNC/qwt/qwt_plot_rasteritem.cpp
===================================================================
--- trunk/BNC/qwt/qwt_plot_rasteritem.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_plot_rasteritem.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -11,22 +11,22 @@
 #include "qwt_scale_map.h"
 #include "qwt_painter.h"
-#include <qapplication.h>
-#include <qdesktopwidget.h>
+#include "qwt_text.h"
+#include "qwt_interval.h"
+#include "qwt_math.h"
+
 #include <qpainter.h>
 #include <qpaintengine.h>
-#include <qmath.h>
-#if QT_VERSION >= 0x040400
 #include <qthread.h>
 #include <qfuture.h>
 #include <qtconcurrentrun.h>
-#endif
-#include <float.h>
+
+#include <limits>
 
 class QwtPlotRasterItem::PrivateData
 {
-public:
-    PrivateData():
-        alpha( -1 ),
-        paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution )
+  public:
+    PrivateData()
+        : alpha( -1 )
+        , paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution )
     {
         cache.policy = QwtPlotRasterItem::NoCache;
@@ -47,5 +47,5 @@
 
 
-static QRectF qwtAlignRect(const QRectF &rect)
+static QRectF qwtAlignRect(const QRectF& rect)
 {
     QRectF r;
@@ -58,7 +58,7 @@
 }
 
-static QRectF qwtStripRect(const QRectF &rect, const QRectF &area,
-    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
-    const QwtInterval &xInterval, const QwtInterval &yInterval)
+static QRectF qwtStripRect(const QRectF& rect, const QRectF& area,
+    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
+    const QwtInterval& xInterval, const QwtInterval& yInterval)
 {
     QRectF r = rect;
@@ -110,8 +110,8 @@
 }
 
-static QImage qwtExpandImage(const QImage &image,
-    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
-    const QRectF &area, const QRectF &area2, const QRectF &paintRect,
-    const QwtInterval &xInterval, const QwtInterval &yInterval )
+static QImage qwtExpandImage(const QImage& image,
+    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
+    const QRectF& area, const QRectF& area2, const QRectF& paintRect,
+    const QwtInterval& xInterval, const QwtInterval& yInterval )
 {
     const QRectF strippedRect = qwtStripRect(paintRect, area2,
@@ -123,6 +123,6 @@
 
     const QRectF r = QwtScaleMap::transform(xMap, yMap, area).normalized();
-    const double pw = ( r.width() - 1) / w;
-    const double ph = ( r.height() - 1) / h;
+    const double pw = ( r.width() - 1 ) / w;
+    const double ph = ( r.height() - 1 ) / h;
 
     double px0, py0;
@@ -193,6 +193,6 @@
                 }
 
-                const quint32 *line1 =
-                    reinterpret_cast<const quint32 *>( image.scanLine( y1 ) );
+                const quint32* line1 =
+                    reinterpret_cast< const quint32* >( image.scanLine( y1 ) );
 
                 for ( int x1 = 0; x1 < w; x1++ )
@@ -225,5 +225,5 @@
                     for ( int y2 = yy1; y2 < yy2; y2++ )
                     {
-                        quint32 *line2 = reinterpret_cast<quint32 *>(
+                        quint32* line2 = reinterpret_cast< quint32* >(
                             expanded.scanLine( y2 ) );
 
@@ -263,5 +263,5 @@
                 }
 
-                const uchar *line1 = image.scanLine( y1 );
+                const uchar* line1 = image.scanLine( y1 );
 
                 for ( int x1 = 0; x1 < w; x1++ )
@@ -293,5 +293,5 @@
                     for ( int y2 = yy1; y2 < yy2; y2++ )
                     {
-                        uchar *line2 = expanded.scanLine( y2 );
+                        uchar* line2 = expanded.scanLine( y2 );
                         memset( line2 + xx1, line1[x1], xx2 - xx1 );
                     }
@@ -307,5 +307,5 @@
 }
 
-static QRectF qwtExpandToPixels(const QRectF &rect, const QRectF &pixelRect)
+static QRectF qwtExpandToPixels(const QRectF& rect, const QRectF& pixelRect)
 {
     const double pw = pixelRect.width();
@@ -318,15 +318,15 @@
 
     QRectF r;
-    r.setLeft( pixelRect.left() - qCeil( dx1 / pw ) * pw );
-    r.setTop( pixelRect.top() - qCeil( dy1 / ph ) * ph );
-    r.setRight( pixelRect.right() - qFloor( dx2 / pw ) * pw );
-    r.setBottom( pixelRect.bottom() - qFloor( dy2 / ph ) * ph );
+    r.setLeft( pixelRect.left() - qwtCeil( dx1 / pw ) * pw );
+    r.setTop( pixelRect.top() - qwtCeil( dy1 / ph ) * ph );
+    r.setRight( pixelRect.right() - qwtFloor( dx2 / pw ) * pw );
+    r.setBottom( pixelRect.bottom() - qwtFloor( dy2 / ph ) * ph );
 
     return r;
 }
 
-static void qwtTransformMaps( const QTransform &tr,
-    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
-    QwtScaleMap &xxMap, QwtScaleMap &yyMap )
+static void qwtTransformMaps( const QTransform& tr,
+    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
+    QwtScaleMap& xxMap, QwtScaleMap& yyMap )
 {
     const QPointF p1 = tr.map( QPointF( xMap.p1(), yMap.p1() ) );
@@ -340,6 +340,6 @@
 }
 
-static void qwtAdjustMaps( QwtScaleMap &xMap, QwtScaleMap &yMap,
-    const QRectF &area, const QRectF &paintRect)
+static void qwtAdjustMaps( QwtScaleMap& xMap, QwtScaleMap& yMap,
+    const QRectF& area, const QRectF& paintRect)
 {
     double sx1 = area.left();
@@ -354,13 +354,13 @@
         qSwap(sy1, sy2);
 
-    xMap.setPaintInterval(paintRect.left(), paintRect.right());
+    xMap.setPaintInterval(paintRect.left(), paintRect.right() );
     xMap.setScaleInterval(sx1, sx2);
 
-    yMap.setPaintInterval(paintRect.top(), paintRect.bottom());
+    yMap.setPaintInterval(paintRect.top(), paintRect.bottom() );
     yMap.setScaleInterval(sy1, sy2);
 }
 
 static bool qwtUseCache( QwtPlotRasterItem::CachePolicy policy,
-    const QPainter *painter )
+    const QPainter* painter )
 {
     bool doCache = false;
@@ -375,5 +375,7 @@
             case QPaintEngine::SVG:
             case QPaintEngine::Pdf:
+#if QT_VERSION < 0x060000
             case QPaintEngine::PostScript:
+#endif
             case QPaintEngine::MacPrinter:
             case QPaintEngine::Picture:
@@ -403,6 +405,6 @@
         for ( int y = y0; y <= y1; y++ )
         {
-            QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) );
-            const unsigned char *line = from->scanLine( y );
+            QRgb* alphaLine = reinterpret_cast< QRgb* >( to->scanLine( y ) );
+            const unsigned char* line = from->scanLine( y );
 
             for ( int x = x0; x <= x1; x++ )
@@ -414,6 +416,6 @@
         for ( int y = y0; y <= y1; y++ )
         {
-            QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) );
-            const QRgb *line = reinterpret_cast<const QRgb *>( from->scanLine( y ) );
+            QRgb* alphaLine = reinterpret_cast< QRgb* >( to->scanLine( y ) );
+            const QRgb* line = reinterpret_cast< const QRgb* >( from->scanLine( y ) );
 
             for ( int x = x0; x <= x1; x++ )
@@ -430,6 +432,6 @@
 
 //! Constructor
-QwtPlotRasterItem::QwtPlotRasterItem( const QString& title ):
-    QwtPlotItem( QwtText( title ) )
+QwtPlotRasterItem::QwtPlotRasterItem( const QString& title )
+    : QwtPlotItem( QwtText( title ) )
 {
     init();
@@ -437,6 +439,6 @@
 
 //! Constructor
-QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title ):
-    QwtPlotItem( title )
+QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title )
+    : QwtPlotItem( title )
 {
     init();
@@ -446,10 +448,10 @@
 QwtPlotRasterItem::~QwtPlotRasterItem()
 {
-    delete d_data;
+    delete m_data;
 }
 
 void QwtPlotRasterItem::init()
 {
-    d_data = new PrivateData();
+    m_data = new PrivateData();
 
     setItemAttribute( QwtPlotItem::AutoScale, true );
@@ -460,16 +462,16 @@
 
 /*!
-  Specify an attribute how to draw the raster item
-
-  \param attribute Paint attribute
-  \param on On/Off
-  /sa PaintAttribute, testPaintAttribute()
-*/
+   Specify an attribute how to draw the raster item
+
+   \param attribute Paint attribute
+   \param on On/Off
+   /sa PaintAttribute, testPaintAttribute()
+ */
 void QwtPlotRasterItem::setPaintAttribute( PaintAttribute attribute, bool on )
 {
     if ( on )
-        d_data->paintAttributes |= attribute;
+        m_data->paintAttributes |= attribute;
     else
-        d_data->paintAttributes &= ~attribute;
+        m_data->paintAttributes &= ~attribute;
 }
 
@@ -477,8 +479,8 @@
     \return True, when attribute is enabled
     \sa PaintAttribute, setPaintAttribute()
-*/
+ */
 bool QwtPlotRasterItem::testPaintAttribute( PaintAttribute attribute ) const
 {
-    return ( d_data->paintAttributes & attribute );
+    return ( m_data->paintAttributes & attribute );
 }
 
@@ -505,5 +507,5 @@
 
    \sa alpha()
-*/
+ */
 void QwtPlotRasterItem::setAlpha( int alpha )
 {
@@ -514,7 +516,7 @@
         alpha = 255;
 
-    if ( alpha != d_data->alpha )
-    {
-        d_data->alpha = alpha;
+    if ( alpha != m_data->alpha )
+    {
+        m_data->alpha = alpha;
 
         itemChanged();
@@ -523,26 +525,26 @@
 
 /*!
-  \return Alpha value of the raster item
-  \sa setAlpha()
-*/
+   \return Alpha value of the raster item
+   \sa setAlpha()
+ */
 int QwtPlotRasterItem::alpha() const
 {
-    return d_data->alpha;
-}
-
-/*!
-  Change the cache policy
-
-  The default policy is NoCache
-
-  \param policy Cache policy
-  \sa CachePolicy, cachePolicy()
-*/
+    return m_data->alpha;
+}
+
+/*!
+   Change the cache policy
+
+   The default policy is NoCache
+
+   \param policy Cache policy
+   \sa CachePolicy, cachePolicy()
+ */
 void QwtPlotRasterItem::setCachePolicy(
     QwtPlotRasterItem::CachePolicy policy )
 {
-    if ( d_data->cache.policy != policy )
-    {
-        d_data->cache.policy = policy;
+    if ( m_data->cache.policy != policy )
+    {
+        m_data->cache.policy = policy;
 
         invalidateCache();
@@ -552,10 +554,10 @@
 
 /*!
-  \return Cache policy
-  \sa CachePolicy, setCachePolicy()
-*/
+   \return Cache policy
+   \sa CachePolicy, setCachePolicy()
+ */
 QwtPlotRasterItem::CachePolicy QwtPlotRasterItem::cachePolicy() const
 {
-    return d_data->cache.policy;
+    return m_data->cache.policy;
 }
 
@@ -563,10 +565,10 @@
    Invalidate the paint cache
    \sa setCachePolicy()
-*/
+ */
 void QwtPlotRasterItem::invalidateCache()
 {
-    d_data->cache.image = QImage();
-    d_data->cache.area = QRect();
-    d_data->cache.size = QSize();
+    m_data->cache.image = QImage();
+    m_data->cache.area = QRect();
+    m_data->cache.size = QSize();
 }
 
@@ -596,6 +598,6 @@
 
    \sa render(), renderImage()
-*/
-QRectF QwtPlotRasterItem::pixelHint( const QRectF &area ) const
+ */
+QRectF QwtPlotRasterItem::pixelHint( const QRectF& area ) const
 {
     Q_UNUSED( area );
@@ -604,18 +606,18 @@
 
 /*!
-  \brief Draw the raster data
-  \param painter Painter
-  \param xMap X-Scale Map
-  \param yMap Y-Scale Map
-  \param canvasRect Contents rectangle of the plot canvas
-*/
-void QwtPlotRasterItem::draw( QPainter *painter,
-    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
-    const QRectF &canvasRect ) const
-{
-    if ( canvasRect.isEmpty() || d_data->alpha == 0 )
+   \brief Draw the raster data
+   \param painter Painter
+   \param xMap X-Scale Map
+   \param yMap Y-Scale Map
+   \param canvasRect Contents rectangle of the plot canvas
+ */
+void QwtPlotRasterItem::draw( QPainter* painter,
+    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
+    const QRectF& canvasRect ) const
+{
+    if ( canvasRect.isEmpty() || m_data->alpha == 0 )
         return;
 
-    const bool doCache = qwtUseCache( d_data->cache.policy, painter );
+    const bool doCache = qwtUseCache( m_data->cache.policy, painter );
 
     const QwtInterval xInterval = interval( Qt::XAxis );
@@ -626,5 +628,5 @@
         precision/quality. So we always render the image in
         paint device resolution.
-    */
+     */
 
     QwtScaleMap xxMap, yyMap;
@@ -657,7 +659,7 @@
         {
             /*
-              When the resolution of the data pixels is higher than
-              the resolution of the target device we render in
-              target device resolution.
+               When the resolution of the data pixels is higher than
+               the resolution of the target device we render in
+               target device resolution.
              */
             pixelRect = QRectF();
@@ -666,6 +668,6 @@
         {
             /*
-              If only one dimension is of the data pixel is higher
-              we expand the pixel rect to the resolution of the target device.
+               If only one dimension is of the data pixel is higher
+               we expand the pixel rect to the resolution of the target device.
              */
 
@@ -692,9 +694,21 @@
         // data pixels we render in resolution of the paint device.
 
+        auto imageSize = paintRect.size();
+
+#if QT_VERSION >= 0x050000
+        const auto pixelRatio = QwtPainter::devicePixelRatio( painter->device() );
+        imageSize *= pixelRatio;
+#endif
+
         image = compose(xxMap, yyMap,
-            area, paintRect, paintRect.size().toSize(), doCache);
+            area, paintRect, imageSize.toSize(), doCache);
+
         if ( image.isNull() )
             return;
 
+#if QT_VERSION >= 0x050000
+        image.setDevicePixelRatio( pixelRatio );
+#endif
+
         // Remove pixels at the boundaries, when explicitly
         // excluded in the intervals
@@ -706,5 +720,5 @@
         {
             const QRect r(
-                qRound( imageRect.x() - paintRect.x()),
+                qRound( imageRect.x() - paintRect.x() ),
                 qRound( imageRect.y() - paintRect.y() ),
                 qRound( imageRect.width() ),
@@ -773,5 +787,5 @@
 
    \param axis X, Y, or Z axis
-*/
+ */
 QwtInterval QwtPlotRasterItem::interval(Qt::Axis axis) const
 {
@@ -783,5 +797,5 @@
    \return Bounding rectangle of the data
    \sa QwtPlotRasterItem::interval()
-*/
+ */
 QRectF QwtPlotRasterItem::boundingRect() const
 {
@@ -801,6 +815,8 @@
     else
     {
-        r.setLeft(-0.5 * FLT_MAX);
-        r.setWidth(FLT_MAX);
+        const qreal max = std::numeric_limits< float >::max();
+
+        r.setLeft( -0.5 * max );
+        r.setWidth( max );
     }
 
@@ -812,6 +828,8 @@
     else
     {
-        r.setTop(-0.5 * FLT_MAX);
-        r.setHeight(FLT_MAX);
+        const qreal max = std::numeric_limits< float >::max();
+
+        r.setTop( -0.5 * max );
+        r.setHeight( max );
     }
 
@@ -820,7 +838,7 @@
 
 QImage QwtPlotRasterItem::compose(
-    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
-    const QRectF &imageArea, const QRectF &paintRect,
-    const QSize &imageSize, bool doCache) const
+    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
+    const QRectF& imageArea, const QRectF& paintRect,
+    const QSize& imageSize, bool doCache) const
 {
     QImage image;
@@ -830,9 +848,9 @@
     if ( doCache )
     {
-        if ( !d_data->cache.image.isNull()
-            && d_data->cache.area == imageArea
-            && d_data->cache.size == paintRect.size() )
-        {
-            image = d_data->cache.image;
+        if ( !m_data->cache.image.isNull()
+            && m_data->cache.area == imageArea
+            && m_data->cache.size == paintRect.size() )
+        {
+            image = m_data->cache.image;
         }
     }
@@ -858,15 +876,15 @@
         if ( doCache )
         {
-            d_data->cache.area = imageArea;
-            d_data->cache.size = paintRect.size();
-            d_data->cache.image = image;
-        }
-    }
-
-    if ( d_data->alpha >= 0 && d_data->alpha < 255 )
+            m_data->cache.area = imageArea;
+            m_data->cache.size = paintRect.size();
+            m_data->cache.image = image;
+        }
+    }
+
+    if ( m_data->alpha >= 0 && m_data->alpha < 255 )
     {
         QImage alphaImage( image.size(), QImage::Format_ARGB32 );
 
-#if QT_VERSION >= 0x040400 && !defined(QT_NO_QFUTURE)
+#if !defined( QT_NO_QFUTURE )
         uint numThreads = renderThreadCount();
 
@@ -879,5 +897,7 @@
         const int numRows = image.height() / numThreads;
 
-        QList< QFuture<void> > futures;
+        QVector< QFuture< void > > futures;
+        futures.reserve( numThreads - 1 );
+
         for ( uint i = 0; i < numThreads; i++ )
         {
@@ -886,10 +906,10 @@
             {
                 tile.setHeight( image.height() - i * numRows );
-                qwtToRgba( &image, &alphaImage, tile, d_data->alpha );
+                qwtToRgba( &image, &alphaImage, tile, m_data->alpha );
             }
             else
             {
                 futures += QtConcurrent::run(
-                    &qwtToRgba, &image, &alphaImage, tile, d_data->alpha );
+                    &qwtToRgba, &image, &alphaImage, tile, m_data->alpha );
             }
         }
@@ -898,5 +918,5 @@
 #else
         const QRect tile( 0, 0, image.width(), image.height() );
-        qwtToRgba( &image, &alphaImage, tile, d_data->alpha );
+        qwtToRgba( &image, &alphaImage, tile, m_data->alpha );
 #endif
         image = alphaImage;
@@ -916,9 +936,9 @@
 
    \return Calculated scale map
-*/
+ */
 QwtScaleMap QwtPlotRasterItem::imageMap(
     Qt::Orientation orientation,
-    const QwtScaleMap &map, const QRectF &area,
-    const QSize &imageSize, double pixelSize) const
+    const QwtScaleMap& map, const QRectF& area,
+    const QSize& imageSize, double pixelSize) const
 {
     double p1, p2, s1, s2;
