Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_renderer.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_renderer.cpp
r4271 r8127 11 11 #include "qwt_plot.h" 12 12 #include "qwt_painter.h" 13 #include "qwt_plot_canvas.h"14 13 #include "qwt_plot_layout.h" 15 #include "qwt_legend.h" 16 #include "qwt_legend_item.h" 17 #include "qwt_dyngrid_layout.h" 14 #include "qwt_abstract_legend.h" 18 15 #include "qwt_scale_widget.h" 19 16 #include "qwt_scale_engine.h" … … 25 22 #include <qtransform.h> 26 23 #include <qprinter.h> 24 #include <qprintdialog.h> 25 #include <qfiledialog.h> 26 #include <qfileinfo.h> 27 27 #include <qstyle.h> 28 28 #include <qstyleoption.h> 29 29 #include <qimagewriter.h> 30 #include <qfileinfo.h>31 30 #ifndef QWT_NO_SVG 32 31 #ifdef QT_SVG_LIB … … 35 34 #endif 36 35 36 static QPainterPath qwtCanvasClip( 37 const QWidget* canvas, const QRectF &canvasRect ) 38 { 39 // The clip region is calculated in integers 40 // To avoid too much rounding errors better 41 // calculate it in target device resolution 42 43 int x1 = qCeil( canvasRect.left() ); 44 int x2 = qFloor( canvasRect.right() ); 45 int y1 = qCeil( canvasRect.top() ); 46 int y2 = qFloor( canvasRect.bottom() ); 47 48 const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 ); 49 50 QPainterPath clipPath; 51 52 ( void ) QMetaObject::invokeMethod( 53 const_cast< QWidget *>( canvas ), "borderPath", 54 Qt::DirectConnection, 55 Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) ); 56 57 return clipPath; 58 } 59 37 60 class QwtPlotRenderer::PrivateData 38 61 { 39 62 public: 40 63 PrivateData(): 41 discardFlags( QwtPlotRenderer::Discard Background),64 discardFlags( QwtPlotRenderer::DiscardNone ), 42 65 layoutFlags( QwtPlotRenderer::DefaultLayout ) 43 66 { … … 47 70 QwtPlotRenderer::LayoutFlags layoutFlags; 48 71 }; 49 50 static void qwtRenderBackground( QPainter *painter,51 const QRectF &rect, const QWidget *widget )52 {53 if ( widget->testAttribute( Qt::WA_StyledBackground ) )54 {55 QStyleOption opt;56 opt.initFrom( widget );57 opt.rect = rect.toAlignedRect();58 59 widget->style()->drawPrimitive(60 QStyle::PE_Widget, &opt, painter, widget);61 }62 else63 {64 const QBrush brush =65 widget->palette().brush( widget->backgroundRole() );66 67 painter->fillRect( rect, brush );68 }69 }70 72 71 73 /*! … … 102 104 103 105 /*! 104 Check if a flag is set. 105 106 \return True, if flag is enabled. 106 107 \param flag Flag to be tested 107 108 \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags() … … 149 150 150 151 /*! 151 Check if a flag is set. 152 152 \return True, if flag is enabled. 153 153 \param flag Flag to be tested 154 154 \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags() … … 182 182 Render a plot to a file 183 183 184 The format of the document will be auto detected from the185 suffix of the file name.184 The format of the document will be auto-detected from the 185 suffix of the file name. 186 186 187 187 \param plot Plot widget … … 239 239 240 240 const QString fmt = format.toLower(); 241 if ( fmt == "pdf" || fmt == "ps")241 if ( fmt == "pdf" ) 242 242 { 243 243 #ifndef QT_NO_PRINTER 244 244 QPrinter printer; 245 printer.setOutputFormat( QPrinter::PdfFormat ); 246 printer.setColorMode( QPrinter::Color ); 245 247 printer.setFullPage( true ); 246 248 printer.setPaperSize( sizeMM, QPrinter::Millimeter ); 247 249 printer.setDocName( title ); 248 250 printer.setOutputFileName( fileName ); 249 printer.setOutputFormat( ( format == "pdf" )250 ? QPrinter::PdfFormat : QPrinter::PostScriptFormat );251 251 printer.setResolution( resolution ); 252 252 253 253 QPainter painter( &printer ); 254 254 render( plot, &painter, documentRect ); 255 #endif 256 } 257 else if ( fmt == "ps" ) 258 { 259 #if QT_VERSION < 0x050000 260 #ifndef QT_NO_PRINTER 261 QPrinter printer; 262 printer.setOutputFormat( QPrinter::PostScriptFormat ); 263 printer.setColorMode( QPrinter::Color ); 264 printer.setFullPage( true ); 265 printer.setPaperSize( sizeMM, QPrinter::Millimeter ); 266 printer.setDocName( title ); 267 printer.setOutputFileName( fileName ); 268 printer.setResolution( resolution ); 269 270 QPainter painter( &printer ); 271 render( plot, &painter, documentRect ); 272 #endif 255 273 #endif 256 274 } … … 393 411 QPainter *painter, const QRectF &plotRect ) const 394 412 { 395 int axisId;396 397 413 if ( painter == 0 || !painter->isActive() || 398 414 !plotRect.isValid() || plot->size().isNull() ) 415 { 399 416 return; 417 } 400 418 401 419 if ( !( d_data->discardFlags & DiscardBackground ) ) 402 qwtRenderBackground( painter, plotRect, plot );420 QwtPainter::drawBackgound( painter, plotRect, plot ); 403 421 404 422 /* … … 412 430 double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() ); 413 431 414 painter->save(); 432 QRectF layoutRect = transform.inverted().mapRect( plotRect ); 433 434 if ( !( d_data->discardFlags & DiscardBackground ) ) 435 { 436 // subtract the contents margins 437 438 int left, top, right, bottom; 439 plot->getContentsMargins( &left, &top, &right, &bottom ); 440 layoutRect.adjust( left, top, -right, -bottom ); 441 } 442 443 QwtPlotLayout *layout = plot->plotLayout(); 415 444 416 445 int baseLineDists[QwtPlot::axisCnt]; 417 if ( d_data->layoutFlags & FrameWithScales ) 418 { 419 for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 446 int canvasMargins[QwtPlot::axisCnt]; 447 448 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 449 { 450 canvasMargins[ axisId ] = layout->canvasMargin( axisId ); 451 452 if ( d_data->layoutFlags & FrameWithScales ) 420 453 { 421 454 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); … … 425 458 scaleWidget->setMargin( 0 ); 426 459 } 427 } 428 } 429 // Calculate the layout for the print. 430 431 QwtPlotLayout::Options layoutOptions = 432 QwtPlotLayout::IgnoreScrollbars | QwtPlotLayout::IgnoreFrames; 460 461 if ( !plot->axisEnabled( axisId ) ) 462 { 463 int left = 0; 464 int right = 0; 465 int top = 0; 466 int bottom = 0; 467 468 // When we have a scale the frame is painted on 469 // the position of the backbone - otherwise we 470 // need to introduce a margin around the canvas 471 472 switch( axisId ) 473 { 474 case QwtPlot::yLeft: 475 layoutRect.adjust( 1, 0, 0, 0 ); 476 break; 477 case QwtPlot::yRight: 478 layoutRect.adjust( 0, 0, -1, 0 ); 479 break; 480 case QwtPlot::xTop: 481 layoutRect.adjust( 0, 1, 0, 0 ); 482 break; 483 case QwtPlot::xBottom: 484 layoutRect.adjust( 0, 0, 0, -1 ); 485 break; 486 default: 487 break; 488 } 489 layoutRect.adjust( left, top, right, bottom ); 490 } 491 } 492 } 493 494 // Calculate the layout for the document. 495 496 QwtPlotLayout::Options layoutOptions = QwtPlotLayout::IgnoreScrollbars; 497 498 if ( ( d_data->layoutFlags & FrameWithScales ) || 499 ( d_data->discardFlags & DiscardCanvasFrame ) ) 500 { 501 layoutOptions |= QwtPlotLayout::IgnoreFrames; 502 } 503 504 433 505 if ( d_data->discardFlags & DiscardLegend ) 434 506 layoutOptions |= QwtPlotLayout::IgnoreLegend; 435 507 436 const QRectF layoutRect = transform.inverted().mapRect( plotRect ); 437 plot->plotLayout()->activate( plot, layoutRect, layoutOptions ); 438 508 if ( d_data->discardFlags & DiscardTitle ) 509 layoutOptions |= QwtPlotLayout::IgnoreTitle; 510 511 if ( d_data->discardFlags & DiscardFooter ) 512 layoutOptions |= QwtPlotLayout::IgnoreFooter; 513 514 layout->activate( plot, layoutRect, layoutOptions ); 515 516 // canvas 517 518 QwtScaleMap maps[QwtPlot::axisCnt]; 519 buildCanvasMaps( plot, layout->canvasRect(), maps ); 520 if ( updateCanvasMargins( plot, layout->canvasRect(), maps ) ) 521 { 522 // recalculate maps and layout, when the margins 523 // have been changed 524 525 layout->activate( plot, layoutRect, layoutOptions ); 526 buildCanvasMaps( plot, layout->canvasRect(), maps ); 527 } 528 529 // now start painting 530 531 painter->save(); 439 532 painter->setWorldTransform( transform, true ); 440 533 441 // canvas 442 443 QwtScaleMap maps[QwtPlot::axisCnt]; 444 buildCanvasMaps( plot, plot->plotLayout()->canvasRect(), maps ); 445 renderCanvas( plot, painter, plot->plotLayout()->canvasRect(), maps ); 534 renderCanvas( plot, painter, layout->canvasRect(), maps ); 446 535 447 536 if ( !( d_data->discardFlags & DiscardTitle ) 448 537 && ( !plot->titleLabel()->text().isEmpty() ) ) 449 538 { 450 renderTitle( plot, painter, plot->plotLayout()->titleRect() ); 539 renderTitle( plot, painter, layout->titleRect() ); 540 } 541 542 if ( !( d_data->discardFlags & DiscardFooter ) 543 && ( !plot->footerLabel()->text().isEmpty() ) ) 544 { 545 renderFooter( plot, painter, layout->footerRect() ); 451 546 } 452 547 … … 454 549 && plot->legend() && !plot->legend()->isEmpty() ) 455 550 { 456 renderLegend( plot, painter, plot->plotLayout()->legendRect() );457 } 458 459 for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )551 renderLegend( plot, painter, layout->legendRect() ); 552 } 553 554 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 460 555 { 461 556 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); … … 468 563 469 564 renderScale( plot, painter, axisId, startDist, endDist, 470 baseDist, plot->plotLayout()->scaleRect( axisId ) ); 471 } 472 } 473 474 475 plot->plotLayout()->invalidate(); 476 477 // reset all widgets with their original attributes. 478 if ( d_data->layoutFlags & FrameWithScales ) 479 { 480 // restore the previous base line dists 481 482 for ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 565 baseDist, layout->scaleRect( axisId ) ); 566 } 567 } 568 569 painter->restore(); 570 571 // restore all setting to their original attributes. 572 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 573 { 574 if ( d_data->layoutFlags & FrameWithScales ) 483 575 { 484 576 QwtScaleWidget *scaleWidget = plot->axisWidget( axisId ); … … 486 578 scaleWidget->setMargin( baseLineDists[axisId] ); 487 579 } 488 } 489 490 painter->restore(); 580 581 layout->setCanvasMargin( canvasMargins[axisId] ); 582 } 583 584 layout->invalidate(); 585 491 586 } 492 587 … … 511 606 512 607 /*! 513 Render the legendinto a given rectangle.608 Render the footer into a given rectangle. 514 609 515 610 \param plot Plot widget … … 517 612 \param rect Bounding rectangle 518 613 */ 614 void QwtPlotRenderer::renderFooter( const QwtPlot *plot, 615 QPainter *painter, const QRectF &rect ) const 616 { 617 painter->setFont( plot->footerLabel()->font() ); 618 619 const QColor color = plot->footerLabel()->palette().color( 620 QPalette::Active, QPalette::Text ); 621 622 painter->setPen( color ); 623 plot->footerLabel()->text().draw( painter, rect ); 624 } 625 626 627 /*! 628 Render the legend into a given rectangle. 629 630 \param plot Plot widget 631 \param painter Painter 632 \param rect Bounding rectangle 633 */ 519 634 void QwtPlotRenderer::renderLegend( const QwtPlot *plot, 520 635 QPainter *painter, const QRectF &rect ) const 521 636 { 522 if ( !plot->legend() || plot->legend()->isEmpty() ) 523 return; 524 525 if ( !( d_data->discardFlags & DiscardBackground ) ) 526 { 527 if ( plot->legend()->autoFillBackground() || 528 plot->legend()->testAttribute( Qt::WA_StyledBackground ) ) 529 { 530 qwtRenderBackground( painter, rect, plot->legend() ); 531 } 532 } 533 534 const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>( 535 plot->legend()->contentsWidget()->layout() ); 536 if ( legendLayout == NULL ) 537 return; 538 539 uint numCols = legendLayout->columnsForWidth( rect.width() ); 540 QList<QRect> itemRects = 541 legendLayout->layoutItems( rect.toRect(), numCols ); 542 543 int index = 0; 544 545 for ( int i = 0; i < legendLayout->count(); i++ ) 546 { 547 QLayoutItem *item = legendLayout->itemAt( i ); 548 QWidget *w = item->widget(); 549 if ( w ) 550 { 551 painter->save(); 552 553 painter->setClipRect( itemRects[index] ); 554 renderLegendItem( plot, painter, w, itemRects[index] ); 555 556 index++; 557 painter->restore(); 558 } 559 } 560 } 561 562 /*! 563 Render the legend item into a given rectangle. 564 565 \param plot Plot widget 566 \param painter Painter 567 \param widget Widget representing a legend item 568 \param rect Bounding rectangle 569 570 \note When widget is not derived from QwtLegendItem renderLegendItem 571 does nothing and needs to be overloaded 572 */ 573 void QwtPlotRenderer::renderLegendItem( const QwtPlot *plot, 574 QPainter *painter, const QWidget *widget, const QRectF &rect ) const 575 { 576 if ( !( d_data->discardFlags & DiscardBackground ) ) 577 { 578 if ( widget->autoFillBackground() || 579 widget->testAttribute( Qt::WA_StyledBackground ) ) 580 { 581 qwtRenderBackground( painter, rect, widget ); 582 } 583 } 584 585 const QwtLegendItem *item = qobject_cast<const QwtLegendItem *>( widget ); 586 if ( item ) 587 { 588 const QSize sz = item->identifierSize(); 589 590 const QRectF identifierRect( rect.x() + item->margin(), 591 rect.center().y() - 0.5 * sz.height(), sz.width(), sz.height() ); 592 593 QwtLegendItemManager *itemManger = plot->legend()->find( item ); 594 if ( itemManger ) 595 { 596 painter->save(); 597 painter->setClipRect( identifierRect, Qt::IntersectClip ); 598 itemManger->drawLegendIdentifier( painter, identifierRect ); 599 painter->restore(); 600 } 601 602 // Label 603 604 QRectF titleRect = rect; 605 titleRect.setX( identifierRect.right() + 2 * item->spacing() ); 606 607 painter->setFont( item->font() ); 608 item->text().draw( painter, titleRect ); 637 if ( plot->legend() ) 638 { 639 bool fillBackground = !( d_data->discardFlags & DiscardBackground ); 640 plot->legend()->renderLegend( painter, rect, fillBackground ); 609 641 } 610 642 } … … 635 667 { 636 668 scaleWidget->drawColorBar( painter, scaleWidget->colorBarRect( rect ) ); 637 638 const int off = scaleWidget->colorBarWidth() + scaleWidget->spacing(); 639 if ( scaleWidget->scaleDraw()->orientation() == Qt::Horizontal ) 640 baseDist += off; 641 else 642 baseDist += off; 669 baseDist += scaleWidget->colorBarWidth() + scaleWidget->spacing(); 643 670 } 644 671 … … 720 747 const QwtScaleMap *map ) const 721 748 { 722 painter->save(); 723 724 QPainterPath clipPath; 749 const QWidget *canvas = plot->canvas(); 725 750 726 751 QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 ); … … 728 753 if ( d_data->layoutFlags & FrameWithScales ) 729 754 { 755 painter->save(); 756 730 757 r.adjust( -1.0, -1.0, 1.0, 1.0 ); 731 758 painter->setPen( QPen( Qt::black ) ); … … 734 761 { 735 762 const QBrush bgBrush = 736 plot->canvas()->palette().brush( plot->backgroundRole() );763 canvas->palette().brush( plot->backgroundRole() ); 737 764 painter->setBrush( bgBrush ); 738 765 } 739 766 740 767 QwtPainter::drawRect( painter, r ); 768 769 painter->restore(); 770 painter->save(); 771 772 painter->setClipRect( canvasRect ); 773 plot->drawItems( painter, canvasRect, map ); 774 775 painter->restore(); 776 } 777 else if ( canvas->testAttribute( Qt::WA_StyledBackground ) ) 778 { 779 QPainterPath clipPath; 780 781 painter->save(); 782 783 if ( !( d_data->discardFlags & DiscardCanvasBackground ) ) 784 { 785 QwtPainter::drawBackgound( painter, r, canvas ); 786 clipPath = qwtCanvasClip( canvas, canvasRect ); 787 } 788 789 painter->restore(); 790 painter->save(); 791 792 if ( clipPath.isEmpty() ) 793 painter->setClipRect( canvasRect ); 794 else 795 painter->setClipPath( clipPath ); 796 797 plot->drawItems( painter, canvasRect, map ); 798 799 painter->restore(); 741 800 } 742 801 else 743 802 { 803 QPainterPath clipPath; 804 805 int frameWidth = 0; 806 807 if ( !( d_data->discardFlags & DiscardCanvasFrame ) ) 808 { 809 const QVariant fw = canvas->property( "frameWidth" ); 810 if ( fw.type() == QVariant::Int ) 811 frameWidth = fw.toInt(); 812 813 clipPath = qwtCanvasClip( canvas, canvasRect ); 814 } 815 816 QRectF innerRect = canvasRect.adjusted( 817 frameWidth, frameWidth, -frameWidth, -frameWidth ); 818 819 painter->save(); 820 821 if ( clipPath.isEmpty() ) 822 { 823 painter->setClipRect( innerRect ); 824 } 825 else 826 { 827 painter->setClipPath( clipPath ); 828 } 829 744 830 if ( !( d_data->discardFlags & DiscardCanvasBackground ) ) 745 831 { 746 qwtRenderBackground( painter, r, plot->canvas() ); 747 748 if ( plot->canvas()->testAttribute( Qt::WA_StyledBackground ) ) 832 QwtPainter::drawBackgound( painter, innerRect, canvas ); 833 } 834 835 plot->drawItems( painter, innerRect, map ); 836 837 painter->restore(); 838 839 if ( frameWidth > 0 ) 840 { 841 painter->save(); 842 843 const int frameStyle = 844 canvas->property( "frameShadow" ).toInt() | 845 canvas->property( "frameShape" ).toInt(); 846 847 const int frameWidth = canvas->property( "frameWidth" ).toInt(); 848 849 850 const QVariant borderRadius = canvas->property( "borderRadius" ); 851 if ( borderRadius.type() == QVariant::Double 852 && borderRadius.toDouble() > 0.0 ) 749 853 { 750 // The clip region is calculated in integers 751 // To avoid too much rounding errors better 752 // calculate it in target device resolution 753 // TODO ... 754 755 int x1 = qCeil( canvasRect.left() ); 756 int x2 = qFloor( canvasRect.right() ); 757 int y1 = qCeil( canvasRect.top() ); 758 int y2 = qFloor( canvasRect.bottom() ); 759 760 clipPath = plot->canvas()->borderPath( 761 QRect( x1, y1, x2 - x1 - 1, y2 - y1 - 1 ) ); 854 const double r = borderRadius.toDouble(); 855 856 QwtPainter::drawRoundedFrame( painter, canvasRect, 857 r, r, canvas->palette(), frameWidth, frameStyle ); 762 858 } 763 } 764 } 765 766 painter->restore(); 767 768 painter->save(); 769 770 if ( clipPath.isEmpty() ) 771 painter->setClipRect( canvasRect ); 772 else 773 painter->setClipPath( clipPath ); 774 775 plot->drawItems( painter, canvasRect, map ); 776 777 painter->restore(); 859 else 860 { 861 const int midLineWidth = canvas->property( "midLineWidth" ).toInt(); 862 863 QwtPainter::drawFrame( painter, canvasRect, 864 canvas->palette(), canvas->foregroundRole(), 865 frameWidth, midLineWidth, frameStyle ); 866 } 867 painter->restore(); 868 } 869 } 778 870 } 779 871 … … 793 885 plot->axisScaleEngine( axisId )->transformation() ); 794 886 795 const QwtScaleDiv &scaleDiv = *plot->axisScaleDiv( axisId );887 const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId ); 796 888 maps[axisId].setScaleInterval( 797 889 scaleDiv.lowerBound(), scaleDiv.upperBound() ); … … 802 894 const int sDist = plot->axisWidget( axisId )->startBorderDist(); 803 895 const int eDist = plot->axisWidget( axisId )->endBorderDist(); 804 const QRectF &scaleRect = plot->plotLayout()->scaleRect( axisId );896 const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId ); 805 897 806 898 if ( axisId == QwtPlot::xTop || axisId == QwtPlot::xBottom ) … … 817 909 else 818 910 { 819 int margin = plot->plotLayout()->canvasMargin( axisId ); 911 int margin = 0; 912 if ( !plot->plotLayout()->alignCanvasToScale( axisId ) ) 913 margin = plot->plotLayout()->canvasMargin( axisId ); 914 820 915 if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight ) 821 916 { … … 832 927 } 833 928 } 929 930 bool QwtPlotRenderer::updateCanvasMargins( QwtPlot *plot, 931 const QRectF &canvasRect, const QwtScaleMap maps[] ) const 932 { 933 double margins[QwtPlot::axisCnt]; 934 plot->getCanvasMarginsHint( maps, canvasRect, 935 margins[QwtPlot::yLeft], margins[QwtPlot::xTop], 936 margins[QwtPlot::yRight], margins[QwtPlot::xBottom] ); 937 938 bool marginsChanged = false; 939 for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ ) 940 { 941 if ( margins[axisId] >= 0.0 ) 942 { 943 const int m = qCeil( margins[axisId] ); 944 plot->plotLayout()->setCanvasMargin( m, axisId); 945 marginsChanged = true; 946 } 947 } 948 949 return marginsChanged; 950 } 951 952 /*! 953 \brief Execute a file dialog and render the plot to the selected file 954 955 \param plot Plot widget 956 \param documentName Default document name 957 \param sizeMM Size for the document in millimeters. 958 \param resolution Resolution in dots per Inch (dpi) 959 960 \return True, when exporting was successful 961 \sa renderDocument() 962 */ 963 bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString &documentName, 964 const QSizeF &sizeMM, int resolution ) 965 { 966 if ( plot == NULL ) 967 return false; 968 969 QString fileName = documentName; 970 971 // What about translation 972 973 #ifndef QT_NO_FILEDIALOG 974 const QList<QByteArray> imageFormats = 975 QImageWriter::supportedImageFormats(); 976 977 QStringList filter; 978 #ifndef QT_NO_PRINTER 979 filter += QString( "PDF " ) + tr( "Documents" ) + " (*.pdf)"; 980 #endif 981 #ifndef QWT_NO_SVG 982 filter += QString( "SVG " ) + tr( "Documents" ) + " (*.svg)"; 983 #endif 984 #ifndef QT_NO_PRINTER 985 filter += QString( "Postscript " ) + tr( "Documents" ) + " (*.ps)"; 986 #endif 987 988 if ( imageFormats.size() > 0 ) 989 { 990 QString imageFilter( tr( "Images" ) ); 991 imageFilter += " ("; 992 for ( int i = 0; i < imageFormats.size(); i++ ) 993 { 994 if ( i > 0 ) 995 imageFilter += " "; 996 imageFilter += "*."; 997 imageFilter += imageFormats[i]; 998 } 999 imageFilter += ")"; 1000 1001 filter += imageFilter; 1002 } 1003 1004 fileName = QFileDialog::getSaveFileName( 1005 NULL, tr( "Export File Name" ), fileName, 1006 filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite ); 1007 #endif 1008 if ( fileName.isEmpty() ) 1009 return false; 1010 1011 renderDocument( plot, fileName, sizeMM, resolution ); 1012 1013 return true; 1014 }
Note:
See TracChangeset
for help on using the changeset viewer.