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

update qwt and qwtpolar, many QT5 fixes (unfinished)

File:
1 edited

Legend:

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

    r4271 r8127  
    1616public:
    1717    PrivateData():
    18         size( 0, 0 )
    19     {
    20     }
    21 
    22     QSize size;
     18        mode( QwtNullPaintDevice::NormalMode )
     19    {
     20    }
     21
     22    QwtNullPaintDevice::Mode mode;
    2323};
    2424
     
    2626{
    2727public:
    28     PaintEngine( QPaintEngine::PaintEngineFeatures );
     28    PaintEngine();
    2929
    3030    virtual bool begin( QPaintDevice * );
     
    5555
    5656    virtual void drawTextItem(const QPointF &, const QTextItem &);
     57
    5758    virtual void drawTiledPixmap(const QRectF &,
    5859        const QPixmap &, const QPointF &s);
     60
    5961    virtual void drawImage(const QRectF &,
    6062        const QImage &, const QRectF &, Qt::ImageConversionFlags );
    6163
    6264private:
    63     QwtNullPaintDevice *d_device;
     65    QwtNullPaintDevice *nullDevice();
    6466};
    6567   
    66 QwtNullPaintDevice::PaintEngine::PaintEngine(
    67         QPaintEngine::PaintEngineFeatures features ):
    68     QPaintEngine( features ),
    69     d_device(NULL)
    70 {
    71 }
    72 
    73 bool QwtNullPaintDevice::PaintEngine::begin(
    74     QPaintDevice *device )
    75 {
    76     d_device = static_cast<QwtNullPaintDevice *>( device );
     68QwtNullPaintDevice::PaintEngine::PaintEngine():
     69    QPaintEngine( QPaintEngine::AllFeatures )
     70{
     71}
     72
     73bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice * )
     74{
     75    setActive( true );
    7776    return true;
    7877}
     
    8079bool QwtNullPaintDevice::PaintEngine::end()
    8180{
    82     d_device = NULL;
     81    setActive( false );
    8382    return true;
    8483}
    8584
    86 QPaintEngine::Type
    87 QwtNullPaintDevice::PaintEngine::type () const
     85QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const
    8886{
    8987    return QPaintEngine::User;
     
    9391    const QRect *rects, int rectCount)
    9492{
    95     if ( d_device )
    96         d_device->drawRects( rects, rectCount );
     93    QwtNullPaintDevice *device = nullDevice();
     94    if ( device == NULL )
     95        return;
     96
     97    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     98    {
     99        QPaintEngine::drawRects( rects, rectCount );
     100        return;
     101    }
     102
     103    device->drawRects( rects, rectCount );
    97104}
    98105
     
    100107    const QRectF *rects, int rectCount)
    101108{
    102     if ( d_device )
    103         d_device->drawRects( rects, rectCount );
     109    QwtNullPaintDevice *device = nullDevice();
     110    if ( device == NULL )
     111        return;
     112
     113    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     114    {
     115        QPaintEngine::drawRects( rects, rectCount );
     116        return;
     117    }
     118
     119    device->drawRects( rects, rectCount );
    104120}
    105121
     
    107123    const QLine *lines, int lineCount)
    108124{
    109     if ( d_device )
    110         d_device->drawLines( lines, lineCount );
     125    QwtNullPaintDevice *device = nullDevice();
     126    if ( device == NULL )
     127        return;
     128
     129    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     130    {
     131        QPaintEngine::drawLines( lines, lineCount );
     132        return;
     133    }
     134
     135    device->drawLines( lines, lineCount );
    111136}
    112137
     
    114139    const QLineF *lines, int lineCount)
    115140{
    116     if ( d_device )
    117         d_device->drawLines( lines, lineCount );
     141    QwtNullPaintDevice *device = nullDevice();
     142    if ( device == NULL )
     143        return;
     144
     145    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     146    {
     147        QPaintEngine::drawLines( lines, lineCount );
     148        return;
     149    }
     150
     151    device->drawLines( lines, lineCount );
    118152}
    119153
     
    121155    const QRectF &rect)
    122156{
    123     if ( d_device )
    124         d_device->drawEllipse( rect );
     157    QwtNullPaintDevice *device = nullDevice();
     158    if ( device == NULL )
     159        return;
     160
     161    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     162    {
     163        QPaintEngine::drawEllipse( rect );
     164        return;
     165    }
     166
     167    device->drawEllipse( rect );
    125168}
    126169
     
    128171    const QRect &rect)
    129172{
    130     if ( d_device )
    131         d_device->drawEllipse( rect );
     173    QwtNullPaintDevice *device = nullDevice();
     174    if ( device == NULL )
     175        return;
     176
     177    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     178    {
     179        QPaintEngine::drawEllipse( rect );
     180        return;
     181    }
     182
     183    device->drawEllipse( rect );
    132184}
    133185
     
    136188    const QPainterPath &path)
    137189{
    138     if ( d_device )
    139         d_device->drawPath( path );
     190    QwtNullPaintDevice *device = nullDevice();
     191    if ( device == NULL )
     192        return;
     193
     194    device->drawPath( path );
    140195}
    141196
     
    143198    const QPointF *points, int pointCount)
    144199{
    145     if ( d_device )
    146         d_device->drawPoints( points, pointCount );
     200    QwtNullPaintDevice *device = nullDevice();
     201    if ( device == NULL )
     202        return;
     203
     204    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     205    {
     206        QPaintEngine::drawPoints( points, pointCount );
     207        return;
     208    }
     209
     210    device->drawPoints( points, pointCount );
    147211}
    148212
     
    150214    const QPoint *points, int pointCount)
    151215{
    152     if ( d_device )
    153         d_device->drawPoints( points, pointCount );
     216    QwtNullPaintDevice *device = nullDevice();
     217    if ( device == NULL )
     218        return;
     219
     220    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     221    {
     222        QPaintEngine::drawPoints( points, pointCount );
     223        return;
     224    }
     225
     226    device->drawPoints( points, pointCount );
    154227}
    155228
     
    157230    const QPointF *points, int pointCount, PolygonDrawMode mode)
    158231{
    159     if ( d_device )
    160         d_device->drawPolygon( points, pointCount, mode );
     232    QwtNullPaintDevice *device = nullDevice();
     233    if ( device == NULL )
     234        return;
     235
     236    if ( device->mode() == QwtNullPaintDevice::PathMode )
     237    {
     238        QPainterPath path;
     239
     240        if ( pointCount > 0 )
     241        {
     242            path.moveTo( points[0] );
     243            for ( int i = 1; i < pointCount; i++ )
     244                path.lineTo( points[i] );
     245
     246            if ( mode != PolylineMode )
     247                path.closeSubpath();
     248        }
     249
     250        device->drawPath( path );
     251        return;
     252    }
     253
     254    device->drawPolygon( points, pointCount, mode );
    161255}
    162256
     
    164258    const QPoint *points, int pointCount, PolygonDrawMode mode)
    165259{
    166     if ( d_device )
    167         d_device->drawPolygon( points, pointCount, mode );
     260    QwtNullPaintDevice *device = nullDevice();
     261    if ( device == NULL )
     262        return;
     263
     264    if ( device->mode() == QwtNullPaintDevice::PathMode )
     265    {
     266        QPainterPath path;
     267
     268        if ( pointCount > 0 )
     269        {
     270            path.moveTo( points[0] );
     271            for ( int i = 1; i < pointCount; i++ )
     272                path.lineTo( points[i] );
     273
     274            if ( mode != PolylineMode )
     275                path.closeSubpath();
     276        }
     277
     278        device->drawPath( path );
     279        return;
     280    }
     281
     282    device->drawPolygon( points, pointCount, mode );
    168283}
    169284
     
    171286    const QRectF &rect, const QPixmap &pm, const QRectF &subRect )
    172287{
    173     if ( d_device )
    174         d_device->drawPixmap( rect, pm, subRect );
     288    QwtNullPaintDevice *device = nullDevice();
     289    if ( device == NULL )
     290        return;
     291
     292    device->drawPixmap( rect, pm, subRect );
    175293}
    176294
     
    178296    const QPointF &pos, const QTextItem &textItem)
    179297{
    180     if ( d_device )
    181         d_device->drawTextItem( pos, textItem );
     298    QwtNullPaintDevice *device = nullDevice();
     299    if ( device == NULL )
     300        return;
     301
     302    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     303    {
     304        QPaintEngine::drawTextItem( pos, textItem );
     305        return;
     306    }
     307
     308    device->drawTextItem( pos, textItem );
    182309}
    183310
     
    186313    const QPointF &subRect)
    187314{
    188     if ( d_device )
    189         d_device->drawTiledPixmap( rect, pixmap, subRect );
     315    QwtNullPaintDevice *device = nullDevice();
     316    if ( device == NULL )
     317        return;
     318
     319    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     320    {
     321        QPaintEngine::drawTiledPixmap( rect, pixmap, subRect );
     322        return;
     323    }   
     324
     325    device->drawTiledPixmap( rect, pixmap, subRect );
    190326}
    191327
     
    194330    const QRectF &subRect, Qt::ImageConversionFlags flags)
    195331{
    196     if ( d_device )
    197         d_device->drawImage( rect, image, subRect, flags );
     332    QwtNullPaintDevice *device = nullDevice();
     333    if ( device == NULL )
     334        return;
     335
     336    device->drawImage( rect, image, subRect, flags );
    198337}
    199338
     
    201340    const QPaintEngineState &state)
    202341{
    203     if ( d_device )
    204         d_device->updateState( state );
     342    QwtNullPaintDevice *device = nullDevice();
     343    if ( device == NULL )
     344        return;
     345
     346    device->updateState( state );
     347}
     348
     349inline QwtNullPaintDevice *QwtNullPaintDevice::PaintEngine::nullDevice()
     350{
     351    if ( !isActive() )
     352        return NULL;
     353
     354    return static_cast<QwtNullPaintDevice *>( paintDevice() );
    205355}
    206356
    207357//! Constructor
    208 QwtNullPaintDevice::QwtNullPaintDevice(
    209     QPaintEngine::PaintEngineFeatures features )
    210 {
    211     init( features );
    212 }
    213 
    214 //! Constructor
    215 QwtNullPaintDevice::QwtNullPaintDevice( const QSize &size,
    216     QPaintEngine::PaintEngineFeatures features )
    217 {
    218     init( features );
    219     d_data->size = size;
    220 }
    221 
    222 void QwtNullPaintDevice::init(
    223     QPaintEngine::PaintEngineFeatures features )
    224 {
    225     d_engine = new PaintEngine( features );
     358QwtNullPaintDevice::QwtNullPaintDevice():
     359    d_engine( NULL )
     360{
    226361    d_data = new PrivateData;
    227362}
     
    235370
    236371/*!
    237    Set the size of the paint device
    238 
    239    \param size Size
    240    \sa size()
     372    Set the render mode
     373
     374    \param mode New mode
     375    \sa mode()
     376 */
     377void QwtNullPaintDevice::setMode( Mode mode )
     378{
     379    d_data->mode = mode;
     380}
     381
     382/*!
     383    \return Render mode
     384    \sa setMode()
    241385*/
    242 void QwtNullPaintDevice::setSize( const QSize & size )
    243 {
    244     d_data->size = size;
    245 }
    246 
    247 /*!
    248     \return Size of the paint device
    249     \sa setSize()
    250 */
    251 QSize QwtNullPaintDevice::size() const
    252 {
    253     return d_data->size;
     386QwtNullPaintDevice::Mode QwtNullPaintDevice::mode() const
     387{
     388    return d_data->mode;
    254389}
    255390
     
    257392QPaintEngine *QwtNullPaintDevice::paintEngine() const
    258393{
     394    if ( d_engine == NULL )
     395    {
     396        QwtNullPaintDevice *that =
     397            const_cast< QwtNullPaintDevice * >( this );
     398
     399        that->d_engine = new PaintEngine();
     400    }
     401
    259402    return d_engine;
    260403}
     
    262405/*!
    263406    See QPaintDevice::metric()
    264     \sa setSize()
     407
     408    \param deviceMetric Type of metric
     409    \return Metric information for the given paint device metric.
     410
     411    \sa sizeMetrics()
    265412*/
    266 int QwtNullPaintDevice::metric( PaintDeviceMetric metric ) const
    267 {
    268     static QPixmap pm;
    269 
     413int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const
     414{
    270415    int value;
    271416
    272     switch ( metric )
     417    switch ( deviceMetric )
    273418    {
    274419        case PdmWidth:
    275             value = qMax( d_data->size.width(), 0 );
    276             break;
     420        {
     421            value = sizeMetrics().width();
     422            break;
     423        }
    277424        case PdmHeight:
    278             value = qMax( d_data->size.height(), 0 );
    279             break;
     425        {
     426            value = sizeMetrics().height();
     427            break;
     428        }
    280429        case PdmNumColors:
    281             value = 16777216;
    282             break;
     430        {
     431            value = 0xffffffff;
     432            break;
     433        }
    283434        case PdmDepth:
    284             value = 24;
    285             break;
     435        {
     436            value = 32;
     437            break;
     438        }
    286439        case PdmPhysicalDpiX:
     440        case PdmPhysicalDpiY:
    287441        case PdmDpiY:
    288         case PdmPhysicalDpiY:
     442        case PdmDpiX:
     443        {
     444            value = 72;
     445            break;
     446        }
    289447        case PdmWidthMM:
     448        {
     449            value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) );
     450            break;
     451        }
    290452        case PdmHeightMM:
    291         case PdmDpiX:
     453        {
     454            value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) );
     455            break;
     456        }
    292457        default:
    293458            value = 0;
Note: See TracChangeset for help on using the changeset viewer.