Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_rasteritem.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_rasteritem.cpp (modified) (45 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_rasteritem.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_scale_map.h" 12 12 #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 15 17 #include <qpainter.h> 16 18 #include <qpaintengine.h> 17 #include <qmath.h>18 #if QT_VERSION >= 0x04040019 19 #include <qthread.h> 20 20 #include <qfuture.h> 21 21 #include <qtconcurrentrun.h> 22 #endif 23 #include < float.h>22 23 #include <limits> 24 24 25 25 class QwtPlotRasterItem::PrivateData 26 26 { 27 public: 28 PrivateData() :29 alpha( -1 ) ,30 paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution ) 27 public: 28 PrivateData() 29 : alpha( -1 ) 30 , paintAttributes( QwtPlotRasterItem::PaintInDeviceResolution ) 31 31 { 32 32 cache.policy = QwtPlotRasterItem::NoCache; … … 47 47 48 48 49 static QRectF qwtAlignRect(const QRectF &rect)49 static QRectF qwtAlignRect(const QRectF& rect) 50 50 { 51 51 QRectF r; … … 58 58 } 59 59 60 static QRectF qwtStripRect(const QRectF &rect, const QRectF&area,61 const QwtScaleMap &xMap, const QwtScaleMap&yMap,62 const QwtInterval &xInterval, const QwtInterval&yInterval)60 static QRectF qwtStripRect(const QRectF& rect, const QRectF& area, 61 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 62 const QwtInterval& xInterval, const QwtInterval& yInterval) 63 63 { 64 64 QRectF r = rect; … … 110 110 } 111 111 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 )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 ) 116 116 { 117 117 const QRectF strippedRect = qwtStripRect(paintRect, area2, … … 123 123 124 124 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; 127 127 128 128 double px0, py0; … … 193 193 } 194 194 195 const quint32 *line1 =196 reinterpret_cast<const quint32 *>( image.scanLine( y1 ) );195 const quint32* line1 = 196 reinterpret_cast< const quint32* >( image.scanLine( y1 ) ); 197 197 198 198 for ( int x1 = 0; x1 < w; x1++ ) … … 225 225 for ( int y2 = yy1; y2 < yy2; y2++ ) 226 226 { 227 quint32 *line2 = reinterpret_cast<quint32*>(227 quint32* line2 = reinterpret_cast< quint32* >( 228 228 expanded.scanLine( y2 ) ); 229 229 … … 263 263 } 264 264 265 const uchar *line1 = image.scanLine( y1 );265 const uchar* line1 = image.scanLine( y1 ); 266 266 267 267 for ( int x1 = 0; x1 < w; x1++ ) … … 293 293 for ( int y2 = yy1; y2 < yy2; y2++ ) 294 294 { 295 uchar *line2 = expanded.scanLine( y2 );295 uchar* line2 = expanded.scanLine( y2 ); 296 296 memset( line2 + xx1, line1[x1], xx2 - xx1 ); 297 297 } … … 307 307 } 308 308 309 static QRectF qwtExpandToPixels(const QRectF &rect, const QRectF&pixelRect)309 static QRectF qwtExpandToPixels(const QRectF& rect, const QRectF& pixelRect) 310 310 { 311 311 const double pw = pixelRect.width(); … … 318 318 319 319 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 ); 324 324 325 325 return r; 326 326 } 327 327 328 static void qwtTransformMaps( const QTransform &tr,329 const QwtScaleMap &xMap, const QwtScaleMap&yMap,330 QwtScaleMap &xxMap, QwtScaleMap&yyMap )328 static void qwtTransformMaps( const QTransform& tr, 329 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 330 QwtScaleMap& xxMap, QwtScaleMap& yyMap ) 331 331 { 332 332 const QPointF p1 = tr.map( QPointF( xMap.p1(), yMap.p1() ) ); … … 340 340 } 341 341 342 static void qwtAdjustMaps( QwtScaleMap &xMap, QwtScaleMap&yMap,343 const QRectF &area, const QRectF&paintRect)342 static void qwtAdjustMaps( QwtScaleMap& xMap, QwtScaleMap& yMap, 343 const QRectF& area, const QRectF& paintRect) 344 344 { 345 345 double sx1 = area.left(); … … 354 354 qSwap(sy1, sy2); 355 355 356 xMap.setPaintInterval(paintRect.left(), paintRect.right()); 356 xMap.setPaintInterval(paintRect.left(), paintRect.right() ); 357 357 xMap.setScaleInterval(sx1, sx2); 358 358 359 yMap.setPaintInterval(paintRect.top(), paintRect.bottom()); 359 yMap.setPaintInterval(paintRect.top(), paintRect.bottom() ); 360 360 yMap.setScaleInterval(sy1, sy2); 361 361 } 362 362 363 363 static bool qwtUseCache( QwtPlotRasterItem::CachePolicy policy, 364 const QPainter *painter )364 const QPainter* painter ) 365 365 { 366 366 bool doCache = false; … … 375 375 case QPaintEngine::SVG: 376 376 case QPaintEngine::Pdf: 377 #if QT_VERSION < 0x060000 377 378 case QPaintEngine::PostScript: 379 #endif 378 380 case QPaintEngine::MacPrinter: 379 381 case QPaintEngine::Picture: … … 403 405 for ( int y = y0; y <= y1; y++ ) 404 406 { 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 ); 407 409 408 410 for ( int x = x0; x <= x1; x++ ) … … 414 416 for ( int y = y0; y <= y1; y++ ) 415 417 { 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 ) ); 418 420 419 421 for ( int x = x0; x <= x1; x++ ) … … 430 432 431 433 //! Constructor 432 QwtPlotRasterItem::QwtPlotRasterItem( const QString& title ) :433 QwtPlotItem( QwtText( title ) ) 434 QwtPlotRasterItem::QwtPlotRasterItem( const QString& title ) 435 : QwtPlotItem( QwtText( title ) ) 434 436 { 435 437 init(); … … 437 439 438 440 //! Constructor 439 QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title ) :440 QwtPlotItem( title ) 441 QwtPlotRasterItem::QwtPlotRasterItem( const QwtText& title ) 442 : QwtPlotItem( title ) 441 443 { 442 444 init(); … … 446 448 QwtPlotRasterItem::~QwtPlotRasterItem() 447 449 { 448 delete d_data;450 delete m_data; 449 451 } 450 452 451 453 void QwtPlotRasterItem::init() 452 454 { 453 d_data = new PrivateData();455 m_data = new PrivateData(); 454 456 455 457 setItemAttribute( QwtPlotItem::AutoScale, true ); … … 460 462 461 463 /*! 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 */ 468 470 void QwtPlotRasterItem::setPaintAttribute( PaintAttribute attribute, bool on ) 469 471 { 470 472 if ( on ) 471 d_data->paintAttributes |= attribute;473 m_data->paintAttributes |= attribute; 472 474 else 473 d_data->paintAttributes &= ~attribute;475 m_data->paintAttributes &= ~attribute; 474 476 } 475 477 … … 477 479 \return True, when attribute is enabled 478 480 \sa PaintAttribute, setPaintAttribute() 479 */ 481 */ 480 482 bool QwtPlotRasterItem::testPaintAttribute( PaintAttribute attribute ) const 481 483 { 482 return ( d_data->paintAttributes & attribute );484 return ( m_data->paintAttributes & attribute ); 483 485 } 484 486 … … 505 507 506 508 \sa alpha() 507 */ 509 */ 508 510 void QwtPlotRasterItem::setAlpha( int alpha ) 509 511 { … … 514 516 alpha = 255; 515 517 516 if ( alpha != d_data->alpha )517 { 518 d_data->alpha = alpha;518 if ( alpha != m_data->alpha ) 519 { 520 m_data->alpha = alpha; 519 521 520 522 itemChanged(); … … 523 525 524 526 /*! 525 \return Alpha value of the raster item 526 \sa setAlpha() 527 */ 527 \return Alpha value of the raster item 528 \sa setAlpha() 529 */ 528 530 int QwtPlotRasterItem::alpha() const 529 531 { 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 */ 541 543 void QwtPlotRasterItem::setCachePolicy( 542 544 QwtPlotRasterItem::CachePolicy policy ) 543 545 { 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; 547 549 548 550 invalidateCache(); … … 552 554 553 555 /*! 554 \return Cache policy 555 \sa CachePolicy, setCachePolicy() 556 */ 556 \return Cache policy 557 \sa CachePolicy, setCachePolicy() 558 */ 557 559 QwtPlotRasterItem::CachePolicy QwtPlotRasterItem::cachePolicy() const 558 560 { 559 return d_data->cache.policy;561 return m_data->cache.policy; 560 562 } 561 563 … … 563 565 Invalidate the paint cache 564 566 \sa setCachePolicy() 565 */ 567 */ 566 568 void QwtPlotRasterItem::invalidateCache() 567 569 { 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(); 571 573 } 572 574 … … 596 598 597 599 \sa render(), renderImage() 598 */ 599 QRectF QwtPlotRasterItem::pixelHint( const QRectF &area ) const600 */ 601 QRectF QwtPlotRasterItem::pixelHint( const QRectF& area ) const 600 602 { 601 603 Q_UNUSED( area ); … … 604 606 605 607 /*! 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 ) const615 { 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 */ 614 void 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 ) 617 619 return; 618 620 619 const bool doCache = qwtUseCache( d_data->cache.policy, painter );621 const bool doCache = qwtUseCache( m_data->cache.policy, painter ); 620 622 621 623 const QwtInterval xInterval = interval( Qt::XAxis ); … … 626 628 precision/quality. So we always render the image in 627 629 paint device resolution. 628 */ 630 */ 629 631 630 632 QwtScaleMap xxMap, yyMap; … … 657 659 { 658 660 /* 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. 662 664 */ 663 665 pixelRect = QRectF(); … … 666 668 { 667 669 /* 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. 670 672 */ 671 673 … … 692 694 // data pixels we render in resolution of the paint device. 693 695 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 694 703 image = compose(xxMap, yyMap, 695 area, paintRect, paintRect.size().toSize(), doCache); 704 area, paintRect, imageSize.toSize(), doCache); 705 696 706 if ( image.isNull() ) 697 707 return; 698 708 709 #if QT_VERSION >= 0x050000 710 image.setDevicePixelRatio( pixelRatio ); 711 #endif 712 699 713 // Remove pixels at the boundaries, when explicitly 700 714 // excluded in the intervals … … 706 720 { 707 721 const QRect r( 708 qRound( imageRect.x() - paintRect.x()), 722 qRound( imageRect.x() - paintRect.x() ), 709 723 qRound( imageRect.y() - paintRect.y() ), 710 724 qRound( imageRect.width() ), … … 773 787 774 788 \param axis X, Y, or Z axis 775 */ 789 */ 776 790 QwtInterval QwtPlotRasterItem::interval(Qt::Axis axis) const 777 791 { … … 783 797 \return Bounding rectangle of the data 784 798 \sa QwtPlotRasterItem::interval() 785 */ 799 */ 786 800 QRectF QwtPlotRasterItem::boundingRect() const 787 801 { … … 801 815 else 802 816 { 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 ); 805 821 } 806 822 … … 812 828 else 813 829 { 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 ); 816 834 } 817 835 … … 820 838 821 839 QImage QwtPlotRasterItem::compose( 822 const QwtScaleMap &xMap, const QwtScaleMap&yMap,823 const QRectF &imageArea, const QRectF&paintRect,824 const QSize &imageSize, bool doCache) const840 const QwtScaleMap& xMap, const QwtScaleMap& yMap, 841 const QRectF& imageArea, const QRectF& paintRect, 842 const QSize& imageSize, bool doCache) const 825 843 { 826 844 QImage image; … … 830 848 if ( doCache ) 831 849 { 832 if ( ! d_data->cache.image.isNull()833 && d_data->cache.area == imageArea834 && 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; 837 855 } 838 856 } … … 858 876 if ( doCache ) 859 877 { 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 ) 867 885 { 868 886 QImage alphaImage( image.size(), QImage::Format_ARGB32 ); 869 887 870 #if QT_VERSION >= 0x040400 &&!defined(QT_NO_QFUTURE)888 #if !defined( QT_NO_QFUTURE ) 871 889 uint numThreads = renderThreadCount(); 872 890 … … 879 897 const int numRows = image.height() / numThreads; 880 898 881 QList< QFuture<void> > futures; 899 QVector< QFuture< void > > futures; 900 futures.reserve( numThreads - 1 ); 901 882 902 for ( uint i = 0; i < numThreads; i++ ) 883 903 { … … 886 906 { 887 907 tile.setHeight( image.height() - i * numRows ); 888 qwtToRgba( &image, &alphaImage, tile, d_data->alpha );908 qwtToRgba( &image, &alphaImage, tile, m_data->alpha ); 889 909 } 890 910 else 891 911 { 892 912 futures += QtConcurrent::run( 893 &qwtToRgba, &image, &alphaImage, tile, d_data->alpha );913 &qwtToRgba, &image, &alphaImage, tile, m_data->alpha ); 894 914 } 895 915 } … … 898 918 #else 899 919 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 ); 901 921 #endif 902 922 image = alphaImage; … … 916 936 917 937 \return Calculated scale map 918 */ 938 */ 919 939 QwtScaleMap QwtPlotRasterItem::imageMap( 920 940 Qt::Orientation orientation, 921 const QwtScaleMap &map, const QRectF&area,922 const QSize &imageSize, double pixelSize) const941 const QwtScaleMap& map, const QRectF& area, 942 const QSize& imageSize, double pixelSize) const 923 943 { 924 944 double p1, p2, s1, s2;
Note:
See TracChangeset
for help on using the changeset viewer.
