Changeset 9383 in ntrip for trunk/BNC/qwt/qwt_plot_renderer.cpp
- Timestamp:
- Mar 19, 2021, 9:15:03 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_renderer.cpp
r8127 r9383 15 15 #include "qwt_scale_widget.h" 16 16 #include "qwt_scale_engine.h" 17 #include "qwt_scale_map.h" 17 18 #include "qwt_text.h" 18 19 #include "qwt_text_label.h" 19 20 #include "qwt_math.h" 21 20 22 #include <qpainter.h> 21 #include <qpainte ngine.h>23 #include <qpainterpath.h> 22 24 #include <qtransform.h> 23 25 #include <qprinter.h> 24 #include <qprintdialog.h>25 26 #include <qfiledialog.h> 26 27 #include <qfileinfo.h> 27 #include <qstyle.h>28 #include <qstyleoption.h>29 28 #include <qimagewriter.h> 29 #include <qvariant.h> 30 30 31 #ifndef QWT_NO_SVG 31 32 #ifdef QT_SVG_LIB 33 #if QT_VERSION >= 0x040500 34 #define QWT_FORMAT_SVG 1 35 #endif 36 #endif 37 #endif 38 39 #ifndef QT_NO_PRINTER 40 #define QWT_FORMAT_PDF 1 41 #endif 42 43 #ifndef QT_NO_PDF 44 45 // QPdfWriter::setResolution() has been introduced with 46 // Qt 5.3. Guess it is o.k. to stay with QPrinter for older 47 // versions. 48 49 #if QT_VERSION >= 0x050300 50 51 #ifndef QWT_FORMAT_PDF 52 #define QWT_FORMAT_PDF 1 53 #endif 54 55 #define QWT_PDF_WRITER 1 56 57 #endif 58 #endif 59 60 #ifndef QT_NO_PRINTER 61 // postscript support has been dropped in Qt5 62 #if QT_VERSION < 0x050000 63 #define QWT_FORMAT_POSTSCRIPT 1 64 #endif 65 #endif 66 67 #if QWT_FORMAT_SVG 32 68 #include <qsvggenerator.h> 33 69 #endif 34 #endif 35 36 static QPainterPath qwtCanvasClip( 70 71 #if QWT_PDF_WRITER 72 #include <qpdfwriter.h> 73 #endif 74 75 static QPainterPath qwtCanvasClip( 37 76 const QWidget* canvas, const QRectF &canvasRect ) 38 77 { … … 58 97 } 59 98 99 static inline QFont qwtResolvedFont( const QWidget *widget ) 100 { 101 QFont font = widget->font(); 102 font.resolve( QFont::AllPropertiesResolved ); 103 104 return font; 105 } 106 60 107 class QwtPlotRenderer::PrivateData 61 108 { … … 71 118 }; 72 119 73 /*! 120 /*! 74 121 Constructor 75 122 \param parent Parent object … … 239 286 240 287 const QString fmt = format.toLower(); 241 if ( fmt == "pdf" ) 242 { 243 #ifndef QT_NO_PRINTER 288 if ( fmt == QLatin1String( "pdf" ) ) 289 { 290 #if QWT_FORMAT_PDF 291 292 #if QWT_PDF_WRITER 293 QPdfWriter pdfWriter( fileName ); 294 pdfWriter.setPageSizeMM( sizeMM ); 295 pdfWriter.setTitle( title ); 296 pdfWriter.setPageMargins( QMarginsF() ); 297 pdfWriter.setResolution( resolution ); 298 299 QPainter painter( &pdfWriter ); 300 render( plot, &painter, documentRect ); 301 #else 244 302 QPrinter printer; 245 303 printer.setOutputFormat( QPrinter::PdfFormat ); … … 254 312 render( plot, &painter, documentRect ); 255 313 #endif 256 } 257 else if ( fmt == "ps" )258 {259 #if QT_VERSION < 0x050000 260 #if ndef QT_NO_PRINTER314 #endif 315 } 316 else if ( fmt == QLatin1String( "ps" ) ) 317 { 318 #if QWT_FORMAT_POSTSCRIPT 261 319 QPrinter printer; 262 320 printer.setOutputFormat( QPrinter::PostScriptFormat ); … … 271 329 render( plot, &painter, documentRect ); 272 330 #endif 273 #endif 274 } 275 else if ( fmt == "svg" ) 276 { 277 #ifndef QWT_NO_SVG 278 #ifdef QT_SVG_LIB 279 #if QT_VERSION >= 0x040500 331 } 332 else if ( fmt == QLatin1String( "svg" ) ) 333 { 334 #if QWT_FORMAT_SVG 280 335 QSvgGenerator generator; 281 336 generator.setTitle( title ); … … 287 342 render( plot, &painter, documentRect ); 288 343 #endif 289 #endif290 #endif291 344 } 292 345 else … … 367 420 #endif 368 421 369 #ifndef QWT_NO_SVG 370 #ifdef QT_SVG_LIB 371 #if QT_VERSION >= 0x040500 422 #if QWT_FORMAT_SVG 372 423 373 424 /*! … … 395 446 render( plot, &p, rect ); 396 447 } 397 #endif 398 #endif 448 399 449 #endif 400 450 … … 461 511 if ( !plot->axisEnabled( axisId ) ) 462 512 { 463 int left = 0;464 int right = 0;465 int top = 0;466 int bottom = 0;467 468 513 // When we have a scale the frame is painted on 469 514 // the position of the backbone - otherwise we … … 487 532 break; 488 533 } 489 layoutRect.adjust( left, top, right, bottom );490 534 } 491 535 } … … 500 544 { 501 545 layoutOptions |= QwtPlotLayout::IgnoreFrames; 502 } 503 546 } 504 547 505 548 if ( d_data->discardFlags & DiscardLegend ) … … 591 634 \param plot Plot widget 592 635 \param painter Painter 593 \param rect Bounding rectangle636 \param titleRect Bounding rectangle for the title 594 637 */ 595 638 void QwtPlotRenderer::renderTitle( const QwtPlot *plot, 596 QPainter *painter, const QRectF & rect ) const597 { 598 painter->setFont( plot->titleLabel()->font() );639 QPainter *painter, const QRectF &titleRect ) const 640 { 641 painter->setFont( qwtResolvedFont( plot->titleLabel() ) ); 599 642 600 643 const QColor color = plot->titleLabel()->palette().color( … … 602 645 603 646 painter->setPen( color ); 604 plot->titleLabel()->text().draw( painter, rect );647 plot->titleLabel()->text().draw( painter, titleRect ); 605 648 } 606 649 … … 610 653 \param plot Plot widget 611 654 \param painter Painter 612 \param rect Bounding rectangle655 \param footerRect Bounding rectangle for the footer 613 656 */ 614 657 void QwtPlotRenderer::renderFooter( const QwtPlot *plot, 615 QPainter *painter, const QRectF & rect ) const616 { 617 painter->setFont( plot->footerLabel()->font() );658 QPainter *painter, const QRectF &footerRect ) const 659 { 660 painter->setFont( qwtResolvedFont( plot->footerLabel() ) ); 618 661 619 662 const QColor color = plot->footerLabel()->palette().color( … … 621 664 622 665 painter->setPen( color ); 623 plot->footerLabel()->text().draw( painter, rect ); 624 } 625 666 plot->footerLabel()->text().draw( painter, footerRect ); 667 } 626 668 627 669 /*! … … 630 672 \param plot Plot widget 631 673 \param painter Painter 632 \param rect Bounding rectangle674 \param legendRect Bounding rectangle for the legend 633 675 */ 634 676 void QwtPlotRenderer::renderLegend( const QwtPlot *plot, 635 QPainter *painter, const QRectF & rect ) const677 QPainter *painter, const QRectF &legendRect ) const 636 678 { 637 679 if ( plot->legend() ) 638 680 { 639 681 bool fillBackground = !( d_data->discardFlags & DiscardBackground ); 640 plot->legend()->renderLegend( painter, rect, fillBackground );682 plot->legend()->renderLegend( painter, legendRect, fillBackground ); 641 683 } 642 684 } … … 652 694 \param endDist End border distance 653 695 \param baseDist Base distance 654 \param rect Bounding rectangle696 \param scaleRect Bounding rectangle for the scale 655 697 */ 656 698 void QwtPlotRenderer::renderScale( const QwtPlot *plot, 657 699 QPainter *painter, 658 700 int axisId, int startDist, int endDist, int baseDist, 659 const QRectF & rect ) const701 const QRectF &scaleRect ) const 660 702 { 661 703 if ( !plot->axisEnabled( axisId ) ) … … 666 708 && scaleWidget->colorBarWidth() > 0 ) 667 709 { 668 scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( rect ) );710 scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( scaleRect ) ); 669 711 baseDist += scaleWidget->colorBarWidth() + scaleWidget->spacing(); 670 712 } … … 679 721 case QwtPlot::yLeft: 680 722 { 681 x = rect.right() - 1.0 - baseDist;682 y = rect.y() + startDist;683 w = rect.height() - startDist - endDist;723 x = scaleRect.right() - 1.0 - baseDist; 724 y = scaleRect.y() + startDist; 725 w = scaleRect.height() - startDist - endDist; 684 726 align = QwtScaleDraw::LeftScale; 685 727 break; … … 687 729 case QwtPlot::yRight: 688 730 { 689 x = rect.left() + baseDist;690 y = rect.y() + startDist;691 w = rect.height() - startDist - endDist;731 x = scaleRect.left() + baseDist; 732 y = scaleRect.y() + startDist; 733 w = scaleRect.height() - startDist - endDist; 692 734 align = QwtScaleDraw::RightScale; 693 735 break; … … 695 737 case QwtPlot::xTop: 696 738 { 697 x = rect.left() + startDist;698 y = rect.bottom() - 1.0 - baseDist;699 w = rect.width() - startDist - endDist;739 x = scaleRect.left() + startDist; 740 y = scaleRect.bottom() - 1.0 - baseDist; 741 w = scaleRect.width() - startDist - endDist; 700 742 align = QwtScaleDraw::TopScale; 701 743 break; … … 703 745 case QwtPlot::xBottom: 704 746 { 705 x = rect.left() + startDist;706 y = rect.top() + baseDist;707 w = rect.width() - startDist - endDist;747 x = scaleRect.left() + startDist; 748 y = scaleRect.top() + baseDist; 749 w = scaleRect.width() - startDist - endDist; 708 750 align = QwtScaleDraw::BottomScale; 709 751 break; … … 713 755 } 714 756 715 scaleWidget->drawTitle( painter, align, rect );716 717 painter->setFont( scaleWidget->font() );757 scaleWidget->drawTitle( painter, align, scaleRect ); 758 759 painter->setFont( qwtResolvedFont( scaleWidget ) ); 718 760 719 761 QwtScaleDraw *sd = const_cast<QwtScaleDraw *>( scaleWidget->scaleDraw() ); … … 740 782 \param plot Plot widget 741 783 \param painter Painter 742 \param map Maps mapping between plot and paint device coordinates784 \param maps Maps mapping between plot and paint device coordinates 743 785 \param canvasRect Canvas rectangle 744 786 */ 745 787 void QwtPlotRenderer::renderCanvas( const QwtPlot *plot, 746 QPainter *painter, const QRectF &canvasRect, 747 const QwtScaleMap *map ) const788 QPainter *painter, const QRectF &canvasRect, 789 const QwtScaleMap *maps ) const 748 790 { 749 791 const QWidget *canvas = plot->canvas(); … … 771 813 772 814 painter->setClipRect( canvasRect ); 773 plot->drawItems( painter, canvasRect, map );815 plot->drawItems( painter, canvasRect, maps ); 774 816 775 817 painter->restore(); … … 795 837 painter->setClipPath( clipPath ); 796 838 797 plot->drawItems( painter, canvasRect, map );839 plot->drawItems( painter, canvasRect, maps ); 798 840 799 841 painter->restore(); … … 814 856 } 815 857 816 QRectF innerRect = canvasRect.adjusted( 858 QRectF innerRect = canvasRect.adjusted( 817 859 frameWidth, frameWidth, -frameWidth, -frameWidth ); 818 860 … … 833 875 } 834 876 835 plot->drawItems( painter, innerRect, map );877 plot->drawItems( painter, innerRect, maps ); 836 878 837 879 painter->restore(); … … 845 887 canvas->property( "frameShape" ).toInt(); 846 888 847 const int frameWidth = canvas->property( "frameWidth" ).toInt();848 849 850 889 const QVariant borderRadius = canvas->property( "borderRadius" ); 851 if ( borderRadius.type() == QVariant::Double 890 if ( borderRadius.type() == QVariant::Double 852 891 && borderRadius.toDouble() > 0.0 ) 853 892 { 854 const double r = borderRadius.toDouble();893 const double radius = borderRadius.toDouble(); 855 894 856 895 QwtPainter::drawRoundedFrame( painter, canvasRect, 857 r , r, canvas->palette(), frameWidth, frameStyle );896 radius, radius, canvas->palette(), frameWidth, frameStyle ); 858 897 } 859 898 else … … 933 972 double margins[QwtPlot::axisCnt]; 934 973 plot->getCanvasMarginsHint( maps, canvasRect, 935 margins[QwtPlot::yLeft], margins[QwtPlot::xTop], 974 margins[QwtPlot::yLeft], margins[QwtPlot::xTop], 936 975 margins[QwtPlot::yRight], margins[QwtPlot::xBottom] ); 937 976 … … 963 1002 bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString &documentName, 964 1003 const QSizeF &sizeMM, int resolution ) 965 { 1004 { 966 1005 if ( plot == NULL ) 967 1006 return false; 968 1007 969 1008 QString fileName = documentName; 970 1009 971 // What about translation 1010 // What about translation 972 1011 973 1012 #ifndef QT_NO_FILEDIALOG 974 1013 const QList<QByteArray> imageFormats = 975 1014 QImageWriter::supportedImageFormats(); 976 1015 977 1016 QStringList filter; 978 #if ndef QT_NO_PRINTER1017 #if QWT_FORMAT_PDF 979 1018 filter += QString( "PDF " ) + tr( "Documents" ) + " (*.pdf)"; 980 1019 #endif 981 #if ndef QWT_NO_SVG1020 #if QWT_FORMAT_SVG 982 1021 filter += QString( "SVG " ) + tr( "Documents" ) + " (*.svg)"; 983 1022 #endif 984 #if ndef QT_NO_PRINTER1023 #if QWT_FORMAT_POSTSCRIPT 985 1024 filter += QString( "Postscript " ) + tr( "Documents" ) + " (*.ps)"; 986 1025 #endif 987 1026 988 1027 if ( imageFormats.size() > 0 ) 989 1028 { … … 994 1033 if ( i > 0 ) 995 1034 imageFilter += " "; 996 imageFilter += "*."; 1035 imageFilter += "*."; 997 1036 imageFilter += imageFormats[i]; 998 } 1037 } 999 1038 imageFilter += ")"; 1000 1039 1001 1040 filter += imageFilter; 1002 } 1003 1041 } 1042 1004 1043 fileName = QFileDialog::getSaveFileName( 1005 1044 NULL, tr( "Export File Name" ), fileName, 1006 1045 filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite ); 1007 #endif 1046 #endif 1008 1047 if ( fileName.isEmpty() ) 1009 1048 return false; … … 1012 1051 1013 1052 return true; 1014 } 1053 }
Note:
See TracChangeset
for help on using the changeset viewer.