Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_renderer.cpp


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

update qwt and qwtpolar, many QT5 fixes (unfinished)

File:
1 edited

Legend:

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

    r4271 r8127  
    1111#include "qwt_plot.h"
    1212#include "qwt_painter.h"
    13 #include "qwt_plot_canvas.h"
    1413#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"
    1815#include "qwt_scale_widget.h"
    1916#include "qwt_scale_engine.h"
     
    2522#include <qtransform.h>
    2623#include <qprinter.h>
     24#include <qprintdialog.h>
     25#include <qfiledialog.h>
     26#include <qfileinfo.h>
    2727#include <qstyle.h>
    2828#include <qstyleoption.h>
    2929#include <qimagewriter.h>
    30 #include <qfileinfo.h>
    3130#ifndef QWT_NO_SVG
    3231#ifdef QT_SVG_LIB
     
    3534#endif
    3635
     36static 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
    3760class QwtPlotRenderer::PrivateData
    3861{
    3962public:
    4063    PrivateData():
    41         discardFlags( QwtPlotRenderer::DiscardBackground ),
     64        discardFlags( QwtPlotRenderer::DiscardNone ),
    4265        layoutFlags( QwtPlotRenderer::DefaultLayout )
    4366    {
     
    4770    QwtPlotRenderer::LayoutFlags layoutFlags;
    4871};
    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     else
    63     {
    64         const QBrush brush =
    65             widget->palette().brush( widget->backgroundRole() );
    66 
    67         painter->fillRect( rect, brush );
    68     }
    69 }
    7072
    7173/*!
     
    102104
    103105/*!
    104   Check if a flag is set.
    105 
     106  \return True, if flag is enabled.
    106107  \param flag Flag to be tested
    107108  \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags()
     
    149150
    150151/*!
    151   Check if a flag is set.
    152 
     152  \return True, if flag is enabled.
    153153  \param flag Flag to be tested
    154154  \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags()
     
    182182  Render a plot to a file
    183183
    184   The format of the document will be autodetected from the
    185   suffix of the filename.
     184  The format of the document will be auto-detected from the
     185  suffix of the file name.
    186186
    187187  \param plot Plot widget
     
    239239
    240240    const QString fmt = format.toLower();
    241     if ( fmt == "pdf" || fmt == "ps" )
     241    if ( fmt == "pdf" )
    242242    {
    243243#ifndef QT_NO_PRINTER
    244244        QPrinter printer;
     245        printer.setOutputFormat( QPrinter::PdfFormat );
     246        printer.setColorMode( QPrinter::Color );
    245247        printer.setFullPage( true );
    246248        printer.setPaperSize( sizeMM, QPrinter::Millimeter );
    247249        printer.setDocName( title );
    248250        printer.setOutputFileName( fileName );
    249         printer.setOutputFormat( ( format == "pdf" )
    250             ? QPrinter::PdfFormat : QPrinter::PostScriptFormat );
    251251        printer.setResolution( resolution );
    252252
    253253        QPainter painter( &printer );
    254254        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
    255273#endif
    256274    }
     
    393411    QPainter *painter, const QRectF &plotRect ) const
    394412{
    395     int axisId;
    396 
    397413    if ( painter == 0 || !painter->isActive() ||
    398414            !plotRect.isValid() || plot->size().isNull() )
     415    {
    399416        return;
     417    }
    400418
    401419    if ( !( d_data->discardFlags & DiscardBackground ) )
    402         qwtRenderBackground( painter, plotRect, plot );
     420        QwtPainter::drawBackgound( painter, plotRect, plot );
    403421
    404422    /*
     
    412430        double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() );
    413431
    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();
    415444
    416445    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 )
    420453        {
    421454            QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
     
    425458                scaleWidget->setMargin( 0 );
    426459            }
    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
    433505    if ( d_data->discardFlags & DiscardLegend )
    434506        layoutOptions |= QwtPlotLayout::IgnoreLegend;
    435507
    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();
    439532    painter->setWorldTransform( transform, true );
    440533
    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 );
    446535
    447536    if ( !( d_data->discardFlags & DiscardTitle )
    448537        && ( !plot->titleLabel()->text().isEmpty() ) )
    449538    {
    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() );
    451546    }
    452547
     
    454549        && plot->legend() && !plot->legend()->isEmpty() )
    455550    {
    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++ )
    460555    {
    461556        QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
     
    468563
    469564            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 )
    483575        {
    484576            QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
     
    486578                scaleWidget->setMargin( baseLineDists[axisId] );
    487579        }
    488     }
    489 
    490     painter->restore();
     580
     581        layout->setCanvasMargin( canvasMargins[axisId] );
     582    }
     583
     584    layout->invalidate();
     585
    491586}
    492587
     
    511606
    512607/*!
    513   Render the legend into a given rectangle.
     608  Render the footer into a given rectangle.
    514609
    515610  \param plot Plot widget
     
    517612  \param rect Bounding rectangle
    518613*/
     614void 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*/
    519634void QwtPlotRenderer::renderLegend( const QwtPlot *plot,
    520635    QPainter *painter, const QRectF &rect ) const
    521636{
    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 );
    609641    }
    610642}
     
    635667    {
    636668        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();
    643670    }
    644671
     
    720747    const QwtScaleMap *map ) const
    721748{
    722     painter->save();
    723 
    724     QPainterPath clipPath;
     749    const QWidget *canvas = plot->canvas();
    725750
    726751    QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 );
     
    728753    if ( d_data->layoutFlags & FrameWithScales )
    729754    {
     755        painter->save();
     756
    730757        r.adjust( -1.0, -1.0, 1.0, 1.0 );
    731758        painter->setPen( QPen( Qt::black ) );
     
    734761        {
    735762            const QBrush bgBrush =
    736                 plot->canvas()->palette().brush( plot->backgroundRole() );
     763                canvas->palette().brush( plot->backgroundRole() );
    737764            painter->setBrush( bgBrush );
    738765        }
    739766
    740767        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();
    741800    }
    742801    else
    743802    {
     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
    744830        if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
    745831        {
    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 )
    749853            {
    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 );
    762858            }
    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    }
    778870}
    779871
     
    793885            plot->axisScaleEngine( axisId )->transformation() );
    794886
    795         const QwtScaleDiv &scaleDiv = *plot->axisScaleDiv( axisId );
     887        const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId );
    796888        maps[axisId].setScaleInterval(
    797889            scaleDiv.lowerBound(), scaleDiv.upperBound() );
     
    802894            const int sDist = plot->axisWidget( axisId )->startBorderDist();
    803895            const int eDist = plot->axisWidget( axisId )->endBorderDist();
    804             const QRectF &scaleRect = plot->plotLayout()->scaleRect( axisId );
     896            const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );
    805897
    806898            if ( axisId == QwtPlot::xTop || axisId == QwtPlot::xBottom )
     
    817909        else
    818910        {
    819             int margin = plot->plotLayout()->canvasMargin( axisId );
     911            int margin = 0;
     912            if ( !plot->plotLayout()->alignCanvasToScale( axisId ) )
     913                margin = plot->plotLayout()->canvasMargin( axisId );
     914
    820915            if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight )
    821916            {
     
    832927    }
    833928}
     929
     930bool 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*/
     963bool 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.