Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (3 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

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

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_scale_map.h"
    1212#include "qwt_painter.h"
    13 #include <qapplication.h>
    14 #include <qdesktopwidget.h>
     13#include "qwt_text.h"
     14#include "qwt_interval.h"
     15#include "qwt_math.h"
     16
    1517#include <qpainter.h>
    1618#include <qpaintengine.h>
    17 #include <qmath.h>
    18 #if QT_VERSION >= 0x040400
    1919#include <qthread.h>
    2020#include <qfuture.h>
    2121#include <qtconcurrentrun.h>
    22 #endif
    23 #include <float.h>
     22
     23#include <limits>
    2424
    2525class QwtPlotRasterItem::PrivateData
    2626{
    27 public:
    28     PrivateData():
    29         alpha( -1 ),
    30         paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution )
     27  public:
     28    PrivateData()
     29        : alpha( -1 )
     30        , paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution )
    3131    {
    3232        cache.policy = QwtPlotRasterItem::NoCache;
    … …  
    4747
    4848
    49 static QRectF qwtAlignRect(const QRectF &rect)
     49static QRectF qwtAlignRect(const QRectF& rect)
    5050{
    5151    QRectF r;
    … …  
    5858}
    5959
    60 static QRectF qwtStripRect(const QRectF &rect, const QRectF &area,
    61     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    62     const QwtInterval &xInterval, const QwtInterval &yInterval)
     60static QRectF qwtStripRect(const QRectF& rect, const QRectF& area,
     61    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     62    const QwtInterval& xInterval, const QwtInterval& yInterval)
    6363{
    6464    QRectF r = rect;
    … …  
    110110}
    111111
    112 static QImage qwtExpandImage(const QImage &image,
    113     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    114     const QRectF &area, const QRectF &area2, const QRectF &paintRect,
    115     const QwtInterval &xInterval, const QwtInterval &yInterval )
     112static QImage qwtExpandImage(const QImage& image,
     113    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     114    const QRectF& area, const QRectF& area2, const QRectF& paintRect,
     115    const QwtInterval& xInterval, const QwtInterval& yInterval )
    116116{
    117117    const QRectF strippedRect = qwtStripRect(paintRect, area2,
    … …  
    123123
    124124    const QRectF r = QwtScaleMap::transform(xMap, yMap, area).normalized();
    125     const double pw = ( r.width() - 1) / w;
    126     const double ph = ( r.height() - 1) / h;
     125    const double pw = ( r.width() - 1 ) / w;
     126    const double ph = ( r.height() - 1 ) / h;
    127127
    128128    double px0, py0;
    … …  
    193193                }
    194194
    195                 const quint32 *line1 =
    196                     reinterpret_cast<const quint32 *>( image.scanLine( y1 ) );
     195                const quint32* line1 =
     196                    reinterpret_cast< const quint32* >( image.scanLine( y1 ) );
    197197
    198198                for ( int x1 = 0; x1 < w; x1++ )
    … …  
    225225                    for ( int y2 = yy1; y2 < yy2; y2++ )
    226226                    {
    227                         quint32 *line2 = reinterpret_cast<quint32 *>(
     227                        quint32* line2 = reinterpret_cast< quint32* >(
    228228                            expanded.scanLine( y2 ) );
    229229
    … …  
    263263                }
    264264
    265                 const uchar *line1 = image.scanLine( y1 );
     265                const uchar* line1 = image.scanLine( y1 );
    266266
    267267                for ( int x1 = 0; x1 < w; x1++ )
    … …  
    293293                    for ( int y2 = yy1; y2 < yy2; y2++ )
    294294                    {
    295                         uchar *line2 = expanded.scanLine( y2 );
     295                        uchar* line2 = expanded.scanLine( y2 );
    296296                        memset( line2 + xx1, line1[x1], xx2 - xx1 );
    297297                    }
    … …  
    307307}
    308308
    309 static QRectF qwtExpandToPixels(const QRectF &rect, const QRectF &pixelRect)
     309static QRectF qwtExpandToPixels(const QRectF& rect, const QRectF& pixelRect)
    310310{
    311311    const double pw = pixelRect.width();
    … …  
    318318
    319319    QRectF r;
    320     r.setLeft( pixelRect.left() - qCeil( dx1 / pw ) * pw );
    321     r.setTop( pixelRect.top() - qCeil( dy1 / ph ) * ph );
    322     r.setRight( pixelRect.right() - qFloor( dx2 / pw ) * pw );
    323     r.setBottom( pixelRect.bottom() - qFloor( dy2 / ph ) * ph );
     320    r.setLeft( pixelRect.left() - qwtCeil( dx1 / pw ) * pw );
     321    r.setTop( pixelRect.top() - qwtCeil( dy1 / ph ) * ph );
     322    r.setRight( pixelRect.right() - qwtFloor( dx2 / pw ) * pw );
     323    r.setBottom( pixelRect.bottom() - qwtFloor( dy2 / ph ) * ph );
    324324
    325325    return r;
    326326}
    327327
    328 static void qwtTransformMaps( const QTransform &tr,
    329     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    330     QwtScaleMap &xxMap, QwtScaleMap &yyMap )
     328static void qwtTransformMaps( const QTransform& tr,
     329    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     330    QwtScaleMap& xxMap, QwtScaleMap& yyMap )
    331331{
    332332    const QPointF p1 = tr.map( QPointF( xMap.p1(), yMap.p1() ) );
    … …  
    340340}
    341341
    342 static void qwtAdjustMaps( QwtScaleMap &xMap, QwtScaleMap &yMap,
    343     const QRectF &area, const QRectF &paintRect)
     342static void qwtAdjustMaps( QwtScaleMap& xMap, QwtScaleMap& yMap,
     343    const QRectF& area, const QRectF& paintRect)
    344344{
    345345    double sx1 = area.left();
    … …  
    354354        qSwap(sy1, sy2);
    355355
    356     xMap.setPaintInterval(paintRect.left(), paintRect.right());
     356    xMap.setPaintInterval(paintRect.left(), paintRect.right() );
    357357    xMap.setScaleInterval(sx1, sx2);
    358358
    359     yMap.setPaintInterval(paintRect.top(), paintRect.bottom());
     359    yMap.setPaintInterval(paintRect.top(), paintRect.bottom() );
    360360    yMap.setScaleInterval(sy1, sy2);
    361361}
    362362
    363363static bool qwtUseCache( QwtPlotRasterItem::CachePolicy policy,
    364     const QPainter *painter )
     364    const QPainter* painter )
    365365{
    366366    bool doCache = false;
    … …  
    375375            case QPaintEngine::SVG:
    376376            case QPaintEngine::Pdf:
     377#if QT_VERSION < 0x060000
    377378            case QPaintEngine::PostScript:
     379#endif
    378380            case QPaintEngine::MacPrinter:
    379381            case QPaintEngine::Picture:
    … …  
    403405        for ( int y = y0; y <= y1; y++ )
    404406        {
    405             QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) );
    406             const unsigned char *line = from->scanLine( y );
     407            QRgb* alphaLine = reinterpret_cast< QRgb* >( to->scanLine( y ) );
     408            const unsigned char* line = from->scanLine( y );
    407409
    408410            for ( int x = x0; x <= x1; x++ )
    … …  
    414416        for ( int y = y0; y <= y1; y++ )
    415417        {
    416             QRgb *alphaLine = reinterpret_cast<QRgb *>( to->scanLine( y ) );
    417             const QRgb *line = reinterpret_cast<const QRgb *>( from->scanLine( y ) );
     418            QRgb* alphaLine = reinterpret_cast< QRgb* >( to->scanLine( y ) );
     419            const QRgb* line = reinterpret_cast< const QRgb* >( from->scanLine( y ) );
    418420
    419421            for ( int x = x0; x <= x1; x++ )
    … …  
    430432
    431433//! Constructor
    432 QwtPlotRasterItem::QwtPlotRasterItem( const QString& title ):
    433     QwtPlotItem( QwtText( title ) )
     434QwtPlotRasterItem::QwtPlotRasterItem( const QString& title )
     435    : QwtPlotItem( QwtText( title ) )
    434436{
    435437    init();
    … …  
    437439
    438440//! Constructor
    439 QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title ):
    440     QwtPlotItem( title )
     441QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title )
     442    : QwtPlotItem( title )
    441443{
    442444    init();
    … …  
    446448QwtPlotRasterItem::~QwtPlotRasterItem()
    447449{
    448     delete d_data;
     450    delete m_data;
    449451}
    450452
    451453void QwtPlotRasterItem::init()
    452454{
    453     d_data = new PrivateData();
     455    m_data = new PrivateData();
    454456
    455457    setItemAttribute( QwtPlotItem::AutoScale, true );
    … …  
    460462
    461463/*!
    462   Specify an attribute how to draw the raster item
    463 
    464   \param attribute Paint attribute
    465   \param on On/Off
    466   /sa PaintAttribute, testPaintAttribute()
    467 */
     464   Specify an attribute how to draw the raster item
     465
     466   \param attribute Paint attribute
     467   \param on On/Off
     468   /sa PaintAttribute, testPaintAttribute()
     469 */
    468470void QwtPlotRasterItem::setPaintAttribute( PaintAttribute attribute, bool on )
    469471{
    470472    if ( on )
    471         d_data->paintAttributes |= attribute;
     473        m_data->paintAttributes |= attribute;
    472474    else
    473         d_data->paintAttributes &= ~attribute;
     475        m_data->paintAttributes &= ~attribute;
    474476}
    475477
    … …  
    477479    \return True, when attribute is enabled
    478480    \sa PaintAttribute, setPaintAttribute()
    479 */
     481 */
    480482bool QwtPlotRasterItem::testPaintAttribute( PaintAttribute attribute ) const
    481483{
    482     return ( d_data->paintAttributes & attribute );
     484    return ( m_data->paintAttributes & attribute );
    483485}
    484486
    … …  
    505507
    506508   \sa alpha()
    507 */
     509 */
    508510void QwtPlotRasterItem::setAlpha( int alpha )
    509511{
    … …  
    514516        alpha = 255;
    515517
    516     if ( alpha != d_data->alpha )
    517     {
    518         d_data->alpha = alpha;
     518    if ( alpha != m_data->alpha )
     519    {
     520        m_data->alpha = alpha;
    519521
    520522        itemChanged();
    … …  
    523525
    524526/*!
    525   \return Alpha value of the raster item
    526   \sa setAlpha()
    527 */
     527   \return Alpha value of the raster item
     528   \sa setAlpha()
     529 */
    528530int QwtPlotRasterItem::alpha() const
    529531{
    530     return d_data->alpha;
    531 }
    532 
    533 /*!
    534   Change the cache policy
    535 
    536   The default policy is NoCache
    537 
    538   \param policy Cache policy
    539   \sa CachePolicy, cachePolicy()
    540 */
     532    return m_data->alpha;
     533}
     534
     535/*!
     536   Change the cache policy
     537
     538   The default policy is NoCache
     539
     540   \param policy Cache policy
     541   \sa CachePolicy, cachePolicy()
     542 */
    541543void QwtPlotRasterItem::setCachePolicy(
    542544    QwtPlotRasterItem::CachePolicy policy )
    543545{
    544     if ( d_data->cache.policy != policy )
    545     {
    546         d_data->cache.policy = policy;
     546    if ( m_data->cache.policy != policy )
     547    {
     548        m_data->cache.policy = policy;
    547549
    548550        invalidateCache();
    … …  
    552554
    553555/*!
    554   \return Cache policy
    555   \sa CachePolicy, setCachePolicy()
    556 */
     556   \return Cache policy
     557   \sa CachePolicy, setCachePolicy()
     558 */
    557559QwtPlotRasterItem::CachePolicy QwtPlotRasterItem::cachePolicy() const
    558560{
    559     return d_data->cache.policy;
     561    return m_data->cache.policy;
    560562}
    561563
    … …  
    563565   Invalidate the paint cache
    564566   \sa setCachePolicy()
    565 */
     567 */
    566568void QwtPlotRasterItem::invalidateCache()
    567569{
    568     d_data->cache.image = QImage();
    569     d_data->cache.area = QRect();
    570     d_data->cache.size = QSize();
     570    m_data->cache.image = QImage();
     571    m_data->cache.area = QRect();
     572    m_data->cache.size = QSize();
    571573}
    572574
    … …  
    596598
    597599   \sa render(), renderImage()
    598 */
    599 QRectF QwtPlotRasterItem::pixelHint( const QRectF &area ) const
     600 */
     601QRectF QwtPlotRasterItem::pixelHint( const QRectF& area ) const
    600602{
    601603    Q_UNUSED( area );
    … …  
    604606
    605607/*!
    606   \brief Draw the raster data
    607   \param painter Painter
    608   \param xMap X-Scale Map
    609   \param yMap Y-Scale Map
    610   \param canvasRect Contents rectangle of the plot canvas
    611 */
    612 void QwtPlotRasterItem::draw( QPainter *painter,
    613     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    614     const QRectF &canvasRect ) const
    615 {
    616     if ( canvasRect.isEmpty() || d_data->alpha == 0 )
     608   \brief Draw the raster data
     609   \param painter Painter
     610   \param xMap X-Scale Map
     611   \param yMap Y-Scale Map
     612   \param canvasRect Contents rectangle of the plot canvas
     613 */
     614void QwtPlotRasterItem::draw( QPainter* painter,
     615    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     616    const QRectF& canvasRect ) const
     617{
     618    if ( canvasRect.isEmpty() || m_data->alpha == 0 )
    617619        return;
    618620
    619     const bool doCache = qwtUseCache( d_data->cache.policy, painter );
     621    const bool doCache = qwtUseCache( m_data->cache.policy, painter );
    620622
    621623    const QwtInterval xInterval = interval( Qt::XAxis );
    … …  
    626628        precision/quality. So we always render the image in
    627629        paint device resolution.
    628     */
     630     */
    629631
    630632    QwtScaleMap xxMap, yyMap;
    … …  
    657659        {
    658660            /*
    659               When the resolution of the data pixels is higher than
    660               the resolution of the target device we render in
    661               target device resolution.
     661               When the resolution of the data pixels is higher than
     662               the resolution of the target device we render in
     663               target device resolution.
    662664             */
    663665            pixelRect = QRectF();
    … …  
    666668        {
    667669            /*
    668               If only one dimension is of the data pixel is higher
    669               we expand the pixel rect to the resolution of the target device.
     670               If only one dimension is of the data pixel is higher
     671               we expand the pixel rect to the resolution of the target device.
    670672             */
    671673
    … …  
    692694        // data pixels we render in resolution of the paint device.
    693695
     696        auto imageSize = paintRect.size();
     697
     698#if QT_VERSION >= 0x050000
     699        const auto pixelRatio = QwtPainter::devicePixelRatio( painter->device() );
     700        imageSize *= pixelRatio;
     701#endif
     702
    694703        image = compose(xxMap, yyMap,
    695             area, paintRect, paintRect.size().toSize(), doCache);
     704            area, paintRect, imageSize.toSize(), doCache);
     705
    696706        if ( image.isNull() )
    697707            return;
    698708
     709#if QT_VERSION >= 0x050000
     710        image.setDevicePixelRatio( pixelRatio );
     711#endif
     712
    699713        // Remove pixels at the boundaries, when explicitly
    700714        // excluded in the intervals
    … …  
    706720        {
    707721            const QRect r(
    708                 qRound( imageRect.x() - paintRect.x()),
     722                qRound( imageRect.x() - paintRect.x() ),
    709723                qRound( imageRect.y() - paintRect.y() ),
    710724                qRound( imageRect.width() ),
    … …  
    773787
    774788   \param axis X, Y, or Z axis
    775 */
     789 */
    776790QwtInterval QwtPlotRasterItem::interval(Qt::Axis axis) const
    777791{
    … …  
    783797   \return Bounding rectangle of the data
    784798   \sa QwtPlotRasterItem::interval()
    785 */
     799 */
    786800QRectF QwtPlotRasterItem::boundingRect() const
    787801{
    … …  
    801815    else
    802816    {
    803         r.setLeft(-0.5 * FLT_MAX);
    804         r.setWidth(FLT_MAX);
     817        const qreal max = std::numeric_limits< float >::max();
     818
     819        r.setLeft( -0.5 * max );
     820        r.setWidth( max );
    805821    }
    806822
    … …  
    812828    else
    813829    {
    814         r.setTop(-0.5 * FLT_MAX);
    815         r.setHeight(FLT_MAX);
     830        const qreal max = std::numeric_limits< float >::max();
     831
     832        r.setTop( -0.5 * max );
     833        r.setHeight( max );
    816834    }
    817835
    … …  
    820838
    821839QImage QwtPlotRasterItem::compose(
    822     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    823     const QRectF &imageArea, const QRectF &paintRect,
    824     const QSize &imageSize, bool doCache) const
     840    const QwtScaleMap& xMap, const QwtScaleMap& yMap,
     841    const QRectF& imageArea, const QRectF& paintRect,
     842    const QSize& imageSize, bool doCache) const
    825843{
    826844    QImage image;
    … …  
    830848    if ( doCache )
    831849    {
    832         if ( !d_data->cache.image.isNull()
    833             && d_data->cache.area == imageArea
    834             && d_data->cache.size == paintRect.size() )
    835         {
    836             image = d_data->cache.image;
     850        if ( !m_data->cache.image.isNull()
     851            && m_data->cache.area == imageArea
     852            && m_data->cache.size == paintRect.size() )
     853        {
     854            image = m_data->cache.image;
    837855        }
    838856    }
    … …  
    858876        if ( doCache )
    859877        {
    860             d_data->cache.area = imageArea;
    861             d_data->cache.size = paintRect.size();
    862             d_data->cache.image = image;
    863         }
    864     }
    865 
    866     if ( d_data->alpha >= 0 && d_data->alpha < 255 )
     878            m_data->cache.area = imageArea;
     879            m_data->cache.size = paintRect.size();
     880            m_data->cache.image = image;
     881        }
     882    }
     883
     884    if ( m_data->alpha >= 0 && m_data->alpha < 255 )
    867885    {
    868886        QImage alphaImage( image.size(), QImage::Format_ARGB32 );
    869887
    870 #if QT_VERSION >= 0x040400 && !defined(QT_NO_QFUTURE)
     888#if !defined( QT_NO_QFUTURE )
    871889        uint numThreads = renderThreadCount();
    872890
    … …  
    879897        const int numRows = image.height() / numThreads;
    880898
    881         QList< QFuture<void> > futures;
     899        QVector< QFuture< void > > futures;
     900        futures.reserve( numThreads - 1 );
     901
    882902        for ( uint i = 0; i < numThreads; i++ )
    883903        {
    … …  
    886906            {
    887907                tile.setHeight( image.height() - i * numRows );
    888                 qwtToRgba( &image, &alphaImage, tile, d_data->alpha );
     908                qwtToRgba( &image, &alphaImage, tile, m_data->alpha );
    889909            }
    890910            else
    891911            {
    892912                futures += QtConcurrent::run(
    893                     &qwtToRgba, &image, &alphaImage, tile, d_data->alpha );
     913                    &qwtToRgba, &image, &alphaImage, tile, m_data->alpha );
    894914            }
    895915        }
    … …  
    898918#else
    899919        const QRect tile( 0, 0, image.width(), image.height() );
    900         qwtToRgba( &image, &alphaImage, tile, d_data->alpha );
     920        qwtToRgba( &image, &alphaImage, tile, m_data->alpha );
    901921#endif
    902922        image = alphaImage;
    … …  
    916936
    917937   \return Calculated scale map
    918 */
     938 */
    919939QwtScaleMap QwtPlotRasterItem::imageMap(
    920940    Qt::Orientation orientation,
    921     const QwtScaleMap &map, const QRectF &area,
    922     const QSize &imageSize, double pixelSize) const
     941    const QwtScaleMap& map, const QRectF& area,
     942    const QSize& imageSize, double pixelSize) const
    923943{
    924944    double p1, p2, s1, s2;
Note: See TracChangeset for help on using the changeset viewer.