Index: trunk/BNC/qwt/qwt_plot_directpainter.cpp
===================================================================
--- trunk/BNC/qwt/qwt_plot_directpainter.cpp	(revision 4271)
+++ trunk/BNC/qwt/qwt_plot_directpainter.cpp	(revision 8127)
@@ -18,7 +18,7 @@
 #include <qpixmap.h>
 
-static inline void renderItem( 
+static inline void qwtRenderItem( 
     QPainter *painter, const QRect &canvasRect,
-    QwtPlotAbstractSeriesItem *seriesItem, int from, int to )
+    QwtPlotSeriesItem *seriesItem, int from, int to )
 {
     // A minor performance improvement is possible
@@ -32,4 +32,10 @@
         seriesItem->testRenderHint( QwtPlotItem::RenderAntialiased ) );
     seriesItem->drawSeries( painter, xMap, yMap, canvasRect, from, to );
+}
+
+static inline bool qwtHasBackingStore( const QwtPlotCanvas *canvas )
+{
+    return canvas->testPaintAttribute( QwtPlotCanvas::BackingStore )
+        && canvas->backingStore() && !canvas->backingStore()->isNull();
 }
 
@@ -40,5 +46,7 @@
         attributes( 0 ),
         hasClipping(false),
-        seriesItem( NULL )
+        seriesItem( NULL ),
+        from( 0 ),
+        to( 0 )
     {
     }
@@ -51,5 +59,5 @@
     QPainter painter;
 
-    QwtPlotAbstractSeriesItem *seriesItem;
+    QwtPlotSeriesItem *seriesItem;
     int from;
     int to;
@@ -92,6 +100,5 @@
 
 /*!
-  Check if a attribute is set.
-
+  \return True, when attribute is enabled
   \param attribute Attribute to be tested
   \sa Attribute, setAttribute()
@@ -152,5 +159,5 @@
 
   When observing an measurement while it is running, new points have to be
-  added to an existing seriesItem. drawSeries can be used to display them avoiding
+  added to an existing seriesItem. drawSeries() can be used to display them avoiding
   a complete redraw of the canvas.
 
@@ -165,29 +172,28 @@
 */
 void QwtPlotDirectPainter::drawSeries(
-    QwtPlotAbstractSeriesItem *seriesItem, int from, int to )
+    QwtPlotSeriesItem *seriesItem, int from, int to )
 {
     if ( seriesItem == NULL || seriesItem->plot() == NULL )
         return;
 
-    QwtPlotCanvas *canvas = seriesItem->plot()->canvas();
+    QWidget *canvas = seriesItem->plot()->canvas();
     const QRect canvasRect = canvas->contentsRect();
 
-    const bool hasBackingStore = 
-        canvas->testPaintAttribute( QwtPlotCanvas::BackingStore ) 
-        && canvas->backingStore() && !canvas->backingStore()->isNull();
-
-    if ( hasBackingStore )
-    {
-        QPainter painter( const_cast<QPixmap *>( canvas->backingStore() ) );
-        painter.translate( -canvasRect.x(), -canvasRect.y() );
+    QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>( canvas );
+
+    if ( plotCanvas && qwtHasBackingStore( plotCanvas ) )
+    {
+        QPainter painter( const_cast<QPixmap *>( plotCanvas->backingStore() ) );
 
         if ( d_data->hasClipping )
             painter.setClipRegion( d_data->clipRegion );
 
-        renderItem( &painter, canvasRect, seriesItem, from, to );
+        qwtRenderItem( &painter, canvasRect, seriesItem, from, to );
+
+        painter.end();
 
         if ( testAttribute( QwtPlotDirectPainter::FullRepaint ) )
         {
-            canvas->repaint();
+            plotCanvas->repaint();
             return;
         }
@@ -195,13 +201,14 @@
 
     bool immediatePaint = true;
-    if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) &&
-        !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) )
-    {
-        immediatePaint = false;
+    if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) ) 
+    {
+#if QT_VERSION < 0x050000
+        if ( !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) )
+#endif
+            immediatePaint = false;
     }
 
     if ( immediatePaint )
     {
-        QwtPlotCanvas *canvas = seriesItem->plot()->canvas();
         if ( !d_data->painter.isActive() )
         {
@@ -223,5 +230,5 @@
         }
 
-        renderItem( &d_data->painter, canvasRect, seriesItem, from, to );
+        qwtRenderItem( &d_data->painter, canvasRect, seriesItem, from, to );
 
         if ( d_data->attributes & QwtPlotDirectPainter::AtomicPainter )
@@ -260,5 +267,5 @@
     if ( d_data->painter.isActive() )
     {
-        QWidget *w = ( QWidget * )d_data->painter.device();
+        QWidget *w = static_cast<QWidget *>( d_data->painter.device() );
         if ( w )
             w->removeEventFilter( this );
@@ -279,28 +286,29 @@
             const QPaintEvent *pe = static_cast< QPaintEvent *>( event );
 
-            QwtPlotCanvas *canvas = d_data->seriesItem->plot()->canvas();
+            QWidget *canvas = d_data->seriesItem->plot()->canvas();
 
             QPainter painter( canvas );
             painter.setClipRegion( pe->region() );
 
-            bool copyCache = testAttribute( CopyBackingStore )
-                && canvas->testPaintAttribute( QwtPlotCanvas::BackingStore );
-
-            if ( copyCache )
+            bool doCopyCache = testAttribute( CopyBackingStore );
+
+            if ( doCopyCache )
             {
-                // is something valid in the cache ?
-                copyCache = ( canvas->backingStore() != NULL )
-                    && !canvas->backingStore()->isNull();
+                QwtPlotCanvas *plotCanvas = 
+                    qobject_cast<QwtPlotCanvas *>( canvas );
+                if ( plotCanvas )
+                {
+                    doCopyCache = qwtHasBackingStore( plotCanvas );
+                    if ( doCopyCache )
+                    {
+                        painter.drawPixmap( plotCanvas->rect().topLeft(), 
+                            *plotCanvas->backingStore() );
+                    }
+                }
             }
 
-            if ( copyCache )
+            if ( !doCopyCache )
             {
-                painter.drawPixmap( 
-                    canvas->contentsRect().topLeft(), 
-                    *canvas->backingStore() );
-            }
-            else
-            {
-                renderItem( &painter, canvas->contentsRect(),
+                qwtRenderItem( &painter, canvas->contentsRect(),
                     d_data->seriesItem, d_data->from, d_data->to );
             }
