Ignore:
Timestamp:
May 10, 2017, 3:20:54 PM (7 years ago)
Author:
stoecker
Message:

update qwt and qwtpolar, many QT5 fixes (unfinished)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_plot_directpainter.cpp

    r4271 r8127  
    1818#include <qpixmap.h>
    1919
    20 static inline void renderItem(
     20static inline void qwtRenderItem(
    2121    QPainter *painter, const QRect &canvasRect,
    22     QwtPlotAbstractSeriesItem *seriesItem, int from, int to )
     22    QwtPlotSeriesItem *seriesItem, int from, int to )
    2323{
    2424    // A minor performance improvement is possible
     
    3232        seriesItem->testRenderHint( QwtPlotItem::RenderAntialiased ) );
    3333    seriesItem->drawSeries( painter, xMap, yMap, canvasRect, from, to );
     34}
     35
     36static inline bool qwtHasBackingStore( const QwtPlotCanvas *canvas )
     37{
     38    return canvas->testPaintAttribute( QwtPlotCanvas::BackingStore )
     39        && canvas->backingStore() && !canvas->backingStore()->isNull();
    3440}
    3541
     
    4046        attributes( 0 ),
    4147        hasClipping(false),
    42         seriesItem( NULL )
     48        seriesItem( NULL ),
     49        from( 0 ),
     50        to( 0 )
    4351    {
    4452    }
     
    5159    QPainter painter;
    5260
    53     QwtPlotAbstractSeriesItem *seriesItem;
     61    QwtPlotSeriesItem *seriesItem;
    5462    int from;
    5563    int to;
     
    92100
    93101/*!
    94   Check if a attribute is set.
    95 
     102  \return True, when attribute is enabled
    96103  \param attribute Attribute to be tested
    97104  \sa Attribute, setAttribute()
     
    152159
    153160  When observing an measurement while it is running, new points have to be
    154   added to an existing seriesItem. drawSeries can be used to display them avoiding
     161  added to an existing seriesItem. drawSeries() can be used to display them avoiding
    155162  a complete redraw of the canvas.
    156163
     
    165172*/
    166173void QwtPlotDirectPainter::drawSeries(
    167     QwtPlotAbstractSeriesItem *seriesItem, int from, int to )
     174    QwtPlotSeriesItem *seriesItem, int from, int to )
    168175{
    169176    if ( seriesItem == NULL || seriesItem->plot() == NULL )
    170177        return;
    171178
    172     QwtPlotCanvas *canvas = seriesItem->plot()->canvas();
     179    QWidget *canvas = seriesItem->plot()->canvas();
    173180    const QRect canvasRect = canvas->contentsRect();
    174181
    175     const bool hasBackingStore =
    176         canvas->testPaintAttribute( QwtPlotCanvas::BackingStore )
    177         && canvas->backingStore() && !canvas->backingStore()->isNull();
    178 
    179     if ( hasBackingStore )
    180     {
    181         QPainter painter( const_cast<QPixmap *>( canvas->backingStore() ) );
    182         painter.translate( -canvasRect.x(), -canvasRect.y() );
     182    QwtPlotCanvas *plotCanvas = qobject_cast<QwtPlotCanvas *>( canvas );
     183
     184    if ( plotCanvas && qwtHasBackingStore( plotCanvas ) )
     185    {
     186        QPainter painter( const_cast<QPixmap *>( plotCanvas->backingStore() ) );
    183187
    184188        if ( d_data->hasClipping )
    185189            painter.setClipRegion( d_data->clipRegion );
    186190
    187         renderItem( &painter, canvasRect, seriesItem, from, to );
     191        qwtRenderItem( &painter, canvasRect, seriesItem, from, to );
     192
     193        painter.end();
    188194
    189195        if ( testAttribute( QwtPlotDirectPainter::FullRepaint ) )
    190196        {
    191             canvas->repaint();
     197            plotCanvas->repaint();
    192198            return;
    193199        }
     
    195201
    196202    bool immediatePaint = true;
    197     if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) &&
    198         !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) )
    199     {
    200         immediatePaint = false;
     203    if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) )
     204    {
     205#if QT_VERSION < 0x050000
     206        if ( !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) )
     207#endif
     208            immediatePaint = false;
    201209    }
    202210
    203211    if ( immediatePaint )
    204212    {
    205         QwtPlotCanvas *canvas = seriesItem->plot()->canvas();
    206213        if ( !d_data->painter.isActive() )
    207214        {
     
    223230        }
    224231
    225         renderItem( &d_data->painter, canvasRect, seriesItem, from, to );
     232        qwtRenderItem( &d_data->painter, canvasRect, seriesItem, from, to );
    226233
    227234        if ( d_data->attributes & QwtPlotDirectPainter::AtomicPainter )
     
    260267    if ( d_data->painter.isActive() )
    261268    {
    262         QWidget *w = ( QWidget * )d_data->painter.device();
     269        QWidget *w = static_cast<QWidget *>( d_data->painter.device() );
    263270        if ( w )
    264271            w->removeEventFilter( this );
     
    279286            const QPaintEvent *pe = static_cast< QPaintEvent *>( event );
    280287
    281             QwtPlotCanvas *canvas = d_data->seriesItem->plot()->canvas();
     288            QWidget *canvas = d_data->seriesItem->plot()->canvas();
    282289
    283290            QPainter painter( canvas );
    284291            painter.setClipRegion( pe->region() );
    285292
    286             bool copyCache = testAttribute( CopyBackingStore )
    287                 && canvas->testPaintAttribute( QwtPlotCanvas::BackingStore );
    288 
    289             if ( copyCache )
     293            bool doCopyCache = testAttribute( CopyBackingStore );
     294
     295            if ( doCopyCache )
    290296            {
    291                 // is something valid in the cache ?
    292                 copyCache = ( canvas->backingStore() != NULL )
    293                     && !canvas->backingStore()->isNull();
     297                QwtPlotCanvas *plotCanvas =
     298                    qobject_cast<QwtPlotCanvas *>( canvas );
     299                if ( plotCanvas )
     300                {
     301                    doCopyCache = qwtHasBackingStore( plotCanvas );
     302                    if ( doCopyCache )
     303                    {
     304                        painter.drawPixmap( plotCanvas->rect().topLeft(),
     305                            *plotCanvas->backingStore() );
     306                    }
     307                }
    294308            }
    295309
    296             if ( copyCache )
     310            if ( !doCopyCache )
    297311            {
    298                 painter.drawPixmap(
    299                     canvas->contentsRect().topLeft(),
    300                     *canvas->backingStore() );
    301             }
    302             else
    303             {
    304                 renderItem( &painter, canvas->contentsRect(),
     312                qwtRenderItem( &painter, canvas->contentsRect(),
    305313                    d_data->seriesItem, d_data->from, d_data->to );
    306314            }
Note: See TracChangeset for help on using the changeset viewer.