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_renderer.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    2828#include <qimagewriter.h>
    2929#include <qvariant.h>
     30#include <qmargins.h>
    3031
    3132#ifndef QWT_NO_SVG
    3233#ifdef QT_SVG_LIB
    33 #if QT_VERSION >= 0x040500
    3434#define QWT_FORMAT_SVG 1
    35 #endif
    3635#endif
    3736#endif
    … …  
    7372#endif
    7473
     74static qreal qwtScalePenWidth( const QwtPlot* plot )
     75{
     76    qreal pw = 0.0;
     77
     78    for ( int axisId = 0; axisId < QwtAxis::AxisPositions; axisId++ )
     79    {
     80        if ( plot->isAxisVisible( axisId ) )
     81            pw = qMax( pw, plot->axisScaleDraw( axisId )->penWidthF() );
     82    }
     83
     84    return pw;
     85}
     86
     87static QColor qwtScalePenColor( const QwtPlot* plot )
     88{
     89    const QPalette pal = plot->axisWidget( QwtAxis::YLeft )->palette();
     90    return pal.color( QPalette::WindowText );
     91}
     92
    7593static QPainterPath qwtCanvasClip(
    76     const QWidget* canvas, const QRectF &canvasRect )
     94    const QWidget* canvas, const QRectF& canvasRect )
    7795{
    7896    // The clip region is calculated in integers
    … …  
    8098    // calculate it in target device resolution
    8199
    82     int x1 = qCeil( canvasRect.left() );
    83     int x2 = qFloor( canvasRect.right() );
    84     int y1 = qCeil( canvasRect.top() );
    85     int y2 = qFloor( canvasRect.bottom() );
     100    int x1 = qwtCeil( canvasRect.left() );
     101    int x2 = qwtFloor( canvasRect.right() );
     102    int y1 = qwtCeil( canvasRect.top() );
     103    int y2 = qwtFloor( canvasRect.bottom() );
    86104
    87105    const QRect r( x1, y1, x2 - x1 - 1, y2 - y1 - 1 );
    … …  
    90108
    91109    ( void ) QMetaObject::invokeMethod(
    92         const_cast< QWidget *>( canvas ), "borderPath",
     110        const_cast< QWidget* >( canvas ), "borderPath",
    93111        Qt::DirectConnection,
    94112        Q_RETURN_ARG( QPainterPath, clipPath ), Q_ARG( QRect, r ) );
    … …  
    97115}
    98116
    99 static inline QFont qwtResolvedFont( const QWidget *widget )
     117static inline QFont qwtResolvedFont( const QWidget* widget )
    100118{
    101119    QFont font = widget->font();
     120#if QT_VERSION >= 0x060000
     121    font.setResolveMask( QFont::AllPropertiesResolved );
     122#else
    102123    font.resolve( QFont::AllPropertiesResolved );
     124#endif
    103125
    104126    return font;
    … …  
    107129class QwtPlotRenderer::PrivateData
    108130{
    109 public:
    110     PrivateData():
    111         discardFlags( QwtPlotRenderer::DiscardNone ),
    112         layoutFlags( QwtPlotRenderer::DefaultLayout )
     131  public:
     132    PrivateData()
     133        : discardFlags( QwtPlotRenderer::DiscardNone )
     134        , layoutFlags( QwtPlotRenderer::DefaultLayout )
    113135    {
    114136    }
    … …  
    121143   Constructor
    122144   \param parent Parent object
    123 */
    124 QwtPlotRenderer::QwtPlotRenderer( QObject *parent ):
    125     QObject( parent )
    126 {
    127     d_data = new PrivateData;
     145 */
     146QwtPlotRenderer::QwtPlotRenderer( QObject* parent )
     147    : QObject( parent )
     148{
     149    m_data = new PrivateData;
    128150}
    129151
    … …  
    131153QwtPlotRenderer::~QwtPlotRenderer()
    132154{
    133     delete d_data;
    134 }
    135 
    136 /*!
    137   Change a flag, indicating what to discard from rendering
    138 
    139   \param flag Flag to change
    140   \param on On/Off
    141 
    142   \sa DiscardFlag, testDiscardFlag(), setDiscardFlags(), discardFlags()
    143 */
     155    delete m_data;
     156}
     157
     158/*!
     159   Change a flag, indicating what to discard from rendering
     160
     161   \param flag Flag to change
     162   \param on On/Off
     163
     164   \sa DiscardFlag, testDiscardFlag(), setDiscardFlags(), discardFlags()
     165 */
    144166void QwtPlotRenderer::setDiscardFlag( DiscardFlag flag, bool on )
    145167{
    146168    if ( on )
    147         d_data->discardFlags |= flag;
     169        m_data->discardFlags |= flag;
    148170    else
    149         d_data->discardFlags &= ~flag;
    150 }
    151 
    152 /*!
    153   \return True, if flag is enabled.
    154   \param flag Flag to be tested
    155   \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags()
    156 */
     171        m_data->discardFlags &= ~flag;
     172}
     173
     174/*!
     175   \return True, if flag is enabled.
     176   \param flag Flag to be tested
     177   \sa DiscardFlag, setDiscardFlag(), setDiscardFlags(), discardFlags()
     178 */
    157179bool QwtPlotRenderer::testDiscardFlag( DiscardFlag flag ) const
    158180{
    159     return d_data->discardFlags & flag;
    160 }
    161 
    162 /*!
    163   Set the flags, indicating what to discard from rendering
    164 
    165   \param flags Flags
    166   \sa DiscardFlag, setDiscardFlag(), testDiscardFlag(), discardFlags()
    167 */
     181    return m_data->discardFlags & flag;
     182}
     183
     184/*!
     185   Set the flags, indicating what to discard from rendering
     186
     187   \param flags Flags
     188   \sa DiscardFlag, setDiscardFlag(), testDiscardFlag(), discardFlags()
     189 */
    168190void QwtPlotRenderer::setDiscardFlags( DiscardFlags flags )
    169191{
    170     d_data->discardFlags = flags;
    171 }
    172 
    173 /*!
    174   \return Flags, indicating what to discard from rendering
    175   \sa DiscardFlag, setDiscardFlags(), setDiscardFlag(), testDiscardFlag()
    176 */
     192    m_data->discardFlags = flags;
     193}
     194
     195/*!
     196   \return Flags, indicating what to discard from rendering
     197   \sa DiscardFlag, setDiscardFlags(), setDiscardFlag(), testDiscardFlag()
     198 */
    177199QwtPlotRenderer::DiscardFlags QwtPlotRenderer::discardFlags() const
    178200{
    179     return d_data->discardFlags;
    180 }
    181 
    182 /*!
    183   Change a layout flag
    184 
    185   \param flag Flag to change
    186   \param on On/Off
    187 
    188   \sa LayoutFlag, testLayoutFlag(), setLayoutFlags(), layoutFlags()
    189 */
     201    return m_data->discardFlags;
     202}
     203
     204/*!
     205   Change a layout flag
     206
     207   \param flag Flag to change
     208   \param on On/Off
     209
     210   \sa LayoutFlag, testLayoutFlag(), setLayoutFlags(), layoutFlags()
     211 */
    190212void QwtPlotRenderer::setLayoutFlag( LayoutFlag flag, bool on )
    191213{
    192214    if ( on )
    193         d_data->layoutFlags |= flag;
     215        m_data->layoutFlags |= flag;
    194216    else
    195         d_data->layoutFlags &= ~flag;
    196 }
    197 
    198 /*!
    199   \return True, if flag is enabled.
    200   \param flag Flag to be tested
    201   \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags()
    202 */
     217        m_data->layoutFlags &= ~flag;
     218}
     219
     220/*!
     221   \return True, if flag is enabled.
     222   \param flag Flag to be tested
     223   \sa LayoutFlag, setLayoutFlag(), setLayoutFlags(), layoutFlags()
     224 */
    203225bool QwtPlotRenderer::testLayoutFlag( LayoutFlag flag ) const
    204226{
    205     return d_data->layoutFlags & flag;
    206 }
    207 
    208 /*!
    209   Set the layout flags
    210 
    211   \param flags Flags
    212   \sa LayoutFlag, setLayoutFlag(), testLayoutFlag(), layoutFlags()
    213 */
     227    return m_data->layoutFlags & flag;
     228}
     229
     230/*!
     231   Set the layout flags
     232
     233   \param flags Flags
     234   \sa LayoutFlag, setLayoutFlag(), testLayoutFlag(), layoutFlags()
     235 */
    214236void QwtPlotRenderer::setLayoutFlags( LayoutFlags flags )
    215237{
    216     d_data->layoutFlags = flags;
    217 }
    218 
    219 /*!
    220   \return Layout flags
    221   \sa LayoutFlag, setLayoutFlags(), setLayoutFlag(), testLayoutFlag()
    222 */
     238    m_data->layoutFlags = flags;
     239}
     240
     241/*!
     242   \return Layout flags
     243   \sa LayoutFlag, setLayoutFlags(), setLayoutFlag(), testLayoutFlag()
     244 */
    223245QwtPlotRenderer::LayoutFlags QwtPlotRenderer::layoutFlags() const
    224246{
    225     return d_data->layoutFlags;
    226 }
    227 
    228 /*!
    229   Render a plot to a file
    230 
    231   The format of the document will be auto-detected from the
    232   suffix of the file name.
    233 
    234   \param plot Plot widget
    235   \param fileName Path of the file, where the document will be stored
    236   \param sizeMM Size for the document in millimeters.
    237   \param resolution Resolution in dots per Inch (dpi)
    238 */
    239 void QwtPlotRenderer::renderDocument( QwtPlot *plot,
    240     const QString &fileName, const QSizeF &sizeMM, int resolution )
     247    return m_data->layoutFlags;
     248}
     249
     250/*!
     251   Render a plot to a file
     252
     253   The format of the document will be auto-detected from the
     254   suffix of the file name.
     255
     256   \param plot Plot widget
     257   \param fileName Path of the file, where the document will be stored
     258   \param sizeMM Size for the document in millimeters.
     259   \param resolution Resolution in dots per Inch (dpi)
     260 */
     261void QwtPlotRenderer::renderDocument( QwtPlot* plot,
     262    const QString& fileName, const QSizeF& sizeMM, int resolution )
    241263{
    242264    renderDocument( plot, fileName,
    … …  
    245267
    246268/*!
    247   Render a plot to a file
    248 
    249   Supported formats are:
    250 
    251   - pdf\n
     269   Render a plot to a file
     270
     271   Supported formats are:
     272
     273   - pdf\n
    252274    Portable Document Format PDF
    253   - ps\n
     275   - ps\n
    254276    Postcript
    255   - svg\n
     277   - svg\n
    256278    Scalable Vector Graphics SVG
    257   - all image formats supported by Qt\n
     279   - all image formats supported by Qt\n
    258280    see QImageWriter::supportedImageFormats()
    259281
    260   Scalable vector graphic formats like PDF or SVG are superior to
    261   raster graphics formats.
    262 
    263   \param plot Plot widget
    264   \param fileName Path of the file, where the document will be stored
    265   \param format Format for the document
    266   \param sizeMM Size for the document in millimeters.
    267   \param resolution Resolution in dots per Inch (dpi)
    268 
    269   \sa renderTo(), render(), QwtPainter::setRoundingAlignment()
    270 */
    271 void QwtPlotRenderer::renderDocument( QwtPlot *plot,
    272     const QString &fileName, const QString &format,
    273     const QSizeF &sizeMM, int resolution )
     282   Scalable vector graphic formats like PDF or SVG are superior to
     283   raster graphics formats.
     284
     285   \param plot Plot widget
     286   \param fileName Path of the file, where the document will be stored
     287   \param format Format for the document
     288   \param sizeMM Size for the document in millimeters.
     289   \param resolution Resolution in dots per Inch (dpi)
     290
     291   \sa renderTo(), render(), QwtPainter::setRoundingAlignment()
     292 */
     293void QwtPlotRenderer::renderDocument( QwtPlot* plot,
     294    const QString& fileName, const QString& format,
     295    const QSizeF& sizeMM, int resolution )
    274296{
    275297    if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 )
    … …  
    292314#if QWT_PDF_WRITER
    293315        QPdfWriter pdfWriter( fileName );
    294         pdfWriter.setPageSizeMM( sizeMM );
     316        pdfWriter.setPageSize( QPageSize( sizeMM, QPageSize::Millimeter ) );
    295317        pdfWriter.setTitle( title );
    296318        pdfWriter.setPageMargins( QMarginsF() );
    … …  
    366388
    367389/*!
    368   \brief Render the plot to a \c QPaintDevice
    369 
    370   This function renders the contents of a QwtPlot instance to
    371   \c QPaintDevice object. The target rectangle is derived from
    372   its device metrics.
    373 
    374   \param plot Plot to be rendered
    375   \param paintDevice device to paint on, f.e a QImage
    376 
    377   \sa renderDocument(), render(), QwtPainter::setRoundingAlignment()
    378 */
     390   \brief Render the plot to a \c QPaintDevice
     391
     392   This function renders the contents of a QwtPlot instance to
     393   \c QPaintDevice object. The target rectangle is derived from
     394   its device metrics.
     395
     396   \param plot Plot to be rendered
     397   \param paintDevice device to paint on, f.e a QImage
     398
     399   \sa renderDocument(), render(), QwtPainter::setRoundingAlignment()
     400 */
    379401
    380402void QwtPlotRenderer::renderTo(
    381     QwtPlot *plot, QPaintDevice &paintDevice ) const
     403    QwtPlot* plot, QPaintDevice& paintDevice ) const
    382404{
    383405    int w = paintDevice.width();
    … …  
    389411
    390412/*!
    391   \brief Render the plot to a QPrinter
    392 
    393   This function renders the contents of a QwtPlot instance to
    394   \c QPaintDevice object. The size is derived from the printer
    395   metrics.
    396 
    397   \param plot Plot to be rendered
    398   \param printer Printer to paint on
    399 
    400   \sa renderDocument(), render(), QwtPainter::setRoundingAlignment()
    401 */
     413   \brief Render the plot to a QPrinter
     414
     415   This function renders the contents of a QwtPlot instance to
     416   \c QPaintDevice object. The size is derived from the printer
     417   metrics.
     418
     419   \param plot Plot to be rendered
     420   \param printer Printer to paint on
     421
     422   \sa renderDocument(), render(), QwtPainter::setRoundingAlignment()
     423 */
    402424
    403425#ifndef QT_NO_PRINTER
    404426
    405427void QwtPlotRenderer::renderTo(
    406     QwtPlot *plot, QPrinter &printer ) const
     428    QwtPlot* plot, QPrinter& printer ) const
    407429{
    408430    int w = printer.width();
    … …  
    423445
    424446/*!
    425   \brief Render the plot to a QSvgGenerator
    426 
    427   If the generator has a view box, the plot will be rendered into it.
    428   If it has no viewBox but a valid size the target coordinates
    429   will be (0, 0, generator.width(), generator.height()). Otherwise
    430   the target rectangle will be QRectF(0, 0, 800, 600);
    431 
    432   \param plot Plot to be rendered
    433   \param generator SVG generator
    434 */
     447   \brief Render the plot to a QSvgGenerator
     448
     449   If the generator has a view box, the plot will be rendered into it.
     450   If it has no viewBox but a valid size the target coordinates
     451   will be (0, 0, generator.width(), generator.height()). Otherwise
     452   the target rectangle will be QRectF(0, 0, 800, 600);
     453
     454   \param plot Plot to be rendered
     455   \param generator SVG generator
     456 */
    435457void QwtPlotRenderer::renderTo(
    436     QwtPlot *plot, QSvgGenerator &generator ) const
     458    QwtPlot* plot, QSvgGenerator& generator ) const
    437459{
    438460    QRectF rect = generator.viewBoxF();
    … …  
    450472
    451473/*!
    452   Paint the contents of a QwtPlot instance into a given rectangle.
    453 
    454   \param plot Plot to be rendered
    455   \param painter Painter
    456   \param plotRect Bounding rectangle
    457 
    458   \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment()
    459 */
    460 void QwtPlotRenderer::render( QwtPlot *plot,
    461     QPainter *painter, const QRectF &plotRect ) const
     474   Paint the contents of a QwtPlot instance into a given rectangle.
     475
     476   \param plot Plot to be rendered
     477   \param painter Painter
     478   \param plotRect Bounding rectangle
     479
     480   \sa renderDocument(), renderTo(), QwtPainter::setRoundingAlignment()
     481 */
     482void QwtPlotRenderer::render( QwtPlot* plot,
     483    QPainter* painter, const QRectF& plotRect ) const
    462484{
    463485    if ( painter == 0 || !painter->isActive() ||
    464             !plotRect.isValid() || plot->size().isNull() )
     486        !plotRect.isValid() || plot->size().isNull() )
    465487    {
    466488        return;
    467489    }
    468490
    469     if ( !( d_data->discardFlags & DiscardBackground ) )
     491    if ( !( m_data->discardFlags & DiscardBackground ) )
    470492        QwtPainter::drawBackgound( painter, plotRect, plot );
    471493
    472494    /*
    473       The layout engine uses the same methods as they are used
    474       by the Qt layout system. Therefore we need to calculate the
    475       layout in screen coordinates and paint with a scaled painter.
     495       The layout engine uses the same methods as they are used
     496       by the Qt layout system. Therefore we need to calculate the
     497       layout in screen coordinates and paint with a scaled painter.
    476498     */
    477499    QTransform transform;
    … …  
    482504    QRectF layoutRect = transform.inverted().mapRect( plotRect );
    483505
    484     if ( !( d_data->discardFlags & DiscardBackground ) )
     506    if ( !( m_data->discardFlags & DiscardBackground ) )
    485507    {
    486508        // subtract the contents margins
    487509
    488         int left, top, right, bottom;
    489         plot->getContentsMargins( &left, &top, &right, &bottom );
    490         layoutRect.adjust( left, top, -right, -bottom );
    491     }
    492 
    493     QwtPlotLayout *layout = plot->plotLayout();
    494 
    495     int baseLineDists[QwtPlot::axisCnt];
    496     int canvasMargins[QwtPlot::axisCnt];
    497 
    498     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    499     {
    500         canvasMargins[ axisId ] = layout->canvasMargin( axisId );
    501 
    502         if ( d_data->layoutFlags & FrameWithScales )
    503         {
    504             QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
     510        const QMargins m = plot->contentsMargins();
     511        layoutRect.adjust( m.left(), m.top(), -m.right(), -m.bottom() );
     512    }
     513
     514    QwtPlotLayout* layout = plot->plotLayout();
     515
     516    int baseLineDists[QwtAxis::AxisPositions];
     517    int canvasMargins[QwtAxis::AxisPositions];
     518
     519    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     520    {
     521        canvasMargins[axisPos] = layout->canvasMargin( axisPos );
     522
     523        if ( m_data->layoutFlags & FrameWithScales )
     524        {
     525            const QwtAxisId axisId( axisPos );
     526
     527            QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
    505528            if ( scaleWidget )
    506529            {
    507                 baseLineDists[axisId] = scaleWidget->margin();
     530                baseLineDists[axisPos] = scaleWidget->margin();
    508531                scaleWidget->setMargin( 0 );
    509532            }
    510533
    511             if ( !plot->axisEnabled( axisId ) )
     534            if ( !plot->isAxisVisible( axisId ) )
    512535            {
    513536                // When we have a scale the frame is painted on
    … …  
    515538                // need to introduce a margin around the canvas
    516539
    517                 switch( axisId )
     540                const qreal fw = qwtScalePenWidth( plot );
     541
     542                switch( axisPos )
    518543                {
    519                     case QwtPlot::yLeft:
    520                         layoutRect.adjust( 1, 0, 0, 0 );
     544                    case QwtAxis::YLeft:
     545                        layoutRect.adjust( fw, 0, 0, 0 );
    521546                        break;
    522                     case QwtPlot::yRight:
    523                         layoutRect.adjust( 0, 0, -1, 0 );
     547
     548                    case QwtAxis::YRight:
     549                        layoutRect.adjust( 0, 0, -fw, 0 );
    524550                        break;
    525                     case QwtPlot::xTop:
    526                         layoutRect.adjust( 0, 1, 0, 0 );
     551
     552                    case QwtAxis::XTop:
     553                        layoutRect.adjust( 0, fw, 0, 0 );
    527554                        break;
    528                     case QwtPlot::xBottom:
    529                         layoutRect.adjust( 0, 0, 0, -1 );
     555
     556                    case QwtAxis::XBottom:
     557                        layoutRect.adjust( 0, 0, 0, -fw );
    530558                        break;
     559
    531560                    default:
    532                         break;
     561                        ;
    533562                }
    534563            }
    … …  
    540569    QwtPlotLayout::Options layoutOptions = QwtPlotLayout::IgnoreScrollbars;
    541570
    542     if ( ( d_data->layoutFlags & FrameWithScales ) ||
    543         ( d_data->discardFlags & DiscardCanvasFrame ) )
     571    if ( ( m_data->layoutFlags & FrameWithScales ) ||
     572        ( m_data->discardFlags & DiscardCanvasFrame ) )
    544573    {
    545574        layoutOptions |= QwtPlotLayout::IgnoreFrames;
    546575    }
    547576
    548     if ( d_data->discardFlags & DiscardLegend )
     577    if ( m_data->discardFlags & DiscardLegend )
    549578        layoutOptions |= QwtPlotLayout::IgnoreLegend;
    550579
    551     if ( d_data->discardFlags & DiscardTitle )
     580    if ( m_data->discardFlags & DiscardTitle )
    552581        layoutOptions |= QwtPlotLayout::IgnoreTitle;
    553582
    554     if ( d_data->discardFlags & DiscardFooter )
     583    if ( m_data->discardFlags & DiscardFooter )
    555584        layoutOptions |= QwtPlotLayout::IgnoreFooter;
    556585
    … …  
    559588    // canvas
    560589
    561     QwtScaleMap maps[QwtPlot::axisCnt];
     590    QwtScaleMap maps[QwtAxis::AxisPositions];
    562591    buildCanvasMaps( plot, layout->canvasRect(), maps );
    563592    if ( updateCanvasMargins( plot, layout->canvasRect(), maps ) )
    … …  
    577606    renderCanvas( plot, painter, layout->canvasRect(), maps );
    578607
    579     if ( !( d_data->discardFlags & DiscardTitle )
     608    if ( !( m_data->discardFlags & DiscardTitle )
    580609        && ( !plot->titleLabel()->text().isEmpty() ) )
    581610    {
    … …  
    583612    }
    584613
    585     if ( !( d_data->discardFlags & DiscardFooter )
     614    if ( !( m_data->discardFlags & DiscardFooter )
    586615        && ( !plot->footerLabel()->text().isEmpty() ) )
    587616    {
    … …  
    589618    }
    590619
    591     if ( !( d_data->discardFlags & DiscardLegend )
     620    if ( !( m_data->discardFlags & DiscardLegend )
    592621        && plot->legend() && !plot->legend()->isEmpty() )
    593622    {
    … …  
    595624    }
    596625
    597     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    598     {
    599         QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
    600         if ( scaleWidget )
    601         {
    602             int baseDist = scaleWidget->margin();
    603 
    604             int startDist, endDist;
    605             scaleWidget->getBorderDistHint( startDist, endDist );
    606 
    607             renderScale( plot, painter, axisId, startDist, endDist,
    608                 baseDist, layout->scaleRect( axisId ) );
     626    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     627    {
     628        {
     629            const QwtAxisId axisId( axisPos );
     630
     631            QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
     632            if ( scaleWidget )
     633            {
     634                int baseDist = scaleWidget->margin();
     635
     636                int startDist, endDist;
     637                scaleWidget->getBorderDistHint( startDist, endDist );
     638
     639                renderScale( plot, painter, axisId, startDist, endDist,
     640                    baseDist, layout->scaleRect( axisId ) );
     641            }
    609642        }
    610643    }
    … …  
    613646
    614647    // restore all setting to their original attributes.
    615     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    616     {
    617         if ( d_data->layoutFlags & FrameWithScales )
    618         {
    619             QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
     648    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     649    {
     650        if ( m_data->layoutFlags & FrameWithScales )
     651        {
     652            const QwtAxisId axisId( axisPos );
     653
     654            QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
    620655            if ( scaleWidget  )
    621                 scaleWidget->setMargin( baseLineDists[axisId] );
    622         }
    623 
    624         layout->setCanvasMargin( canvasMargins[axisId] );
     656                scaleWidget->setMargin( baseLineDists[axisPos] );
     657        }
     658
     659        layout->setCanvasMargin( canvasMargins[axisPos] );
    625660    }
    626661
    … …  
    630665
    631666/*!
    632   Render the title into a given rectangle.
    633 
    634   \param plot Plot widget
    635   \param painter Painter
    636   \param titleRect Bounding rectangle for the title
    637 */
    638 void QwtPlotRenderer::renderTitle( const QwtPlot *plot,
    639     QPainter *painter, const QRectF &titleRect ) const
     667   Render the title into a given rectangle.
     668
     669   \param plot Plot widget
     670   \param painter Painter
     671   \param titleRect Bounding rectangle for the title
     672 */
     673void QwtPlotRenderer::renderTitle( const QwtPlot* plot,
     674    QPainter* painter, const QRectF& titleRect ) const
    640675{
    641676    painter->setFont( qwtResolvedFont( plot->titleLabel() ) );
    642677
    643678    const QColor color = plot->titleLabel()->palette().color(
    644             QPalette::Active, QPalette::Text );
     679        QPalette::Active, QPalette::Text );
    645680
    646681    painter->setPen( color );
    … …  
    649684
    650685/*!
    651   Render the footer into a given rectangle.
    652 
    653   \param plot Plot widget
    654   \param painter Painter
    655   \param footerRect Bounding rectangle for the footer
    656 */
    657 void QwtPlotRenderer::renderFooter( const QwtPlot *plot,
    658     QPainter *painter, const QRectF &footerRect ) const
     686   Render the footer into a given rectangle.
     687
     688   \param plot Plot widget
     689   \param painter Painter
     690   \param footerRect Bounding rectangle for the footer
     691 */
     692void QwtPlotRenderer::renderFooter( const QwtPlot* plot,
     693    QPainter* painter, const QRectF& footerRect ) const
    659694{
    660695    painter->setFont( qwtResolvedFont( plot->footerLabel() ) );
    661696
    662697    const QColor color = plot->footerLabel()->palette().color(
    663             QPalette::Active, QPalette::Text );
     698        QPalette::Active, QPalette::Text );
    664699
    665700    painter->setPen( color );
    … …  
    668703
    669704/*!
    670   Render the legend into a given rectangle.
    671 
    672   \param plot Plot widget
    673   \param painter Painter
    674   \param legendRect Bounding rectangle for the legend
    675 */
    676 void QwtPlotRenderer::renderLegend( const QwtPlot *plot,
    677     QPainter *painter, const QRectF &legendRect ) const
     705   Render the legend into a given rectangle.
     706
     707   \param plot Plot widget
     708   \param painter Painter
     709   \param legendRect Bounding rectangle for the legend
     710 */
     711void QwtPlotRenderer::renderLegend( const QwtPlot* plot,
     712    QPainter* painter, const QRectF& legendRect ) const
    678713{
    679714    if ( plot->legend() )
    680715    {
    681         bool fillBackground = !( d_data->discardFlags & DiscardBackground );
     716        bool fillBackground = !( m_data->discardFlags & DiscardBackground );
    682717        plot->legend()->renderLegend( painter, legendRect, fillBackground );
    683718    }
    … …  
    685720
    686721/*!
    687   \brief Paint a scale into a given rectangle.
    688   Paint the scale into a given rectangle.
    689 
    690   \param plot Plot widget
    691   \param painter Painter
    692   \param axisId Axis
    693   \param startDist Start border distance
    694   \param endDist End border distance
    695   \param baseDist Base distance
    696   \param scaleRect Bounding rectangle for the scale
    697 */
    698 void QwtPlotRenderer::renderScale( const QwtPlot *plot,
    699     QPainter *painter,
    700     int axisId, int startDist, int endDist, int baseDist,
    701     const QRectF &scaleRect ) const
    702 {
    703     if ( !plot->axisEnabled( axisId ) )
     722   \brief Paint a scale into a given rectangle.
     723   Paint the scale into a given rectangle.
     724
     725   \param plot Plot widget
     726   \param painter Painter
     727   \param axisId Axis
     728   \param startDist Start border distance
     729   \param endDist End border distance
     730   \param baseDist Base distance
     731   \param scaleRect Bounding rectangle for the scale
     732 */
     733void QwtPlotRenderer::renderScale( const QwtPlot* plot, QPainter* painter,
     734    QwtAxisId axisId, int startDist, int endDist, int baseDist,
     735    const QRectF& scaleRect ) const
     736{
     737    if ( !plot->isAxisVisible( axisId ) )
    704738        return;
    705739
    706     const QwtScaleWidget *scaleWidget = plot->axisWidget( axisId );
     740    const QwtScaleWidget* scaleWidget = plot->axisWidget( axisId );
    707741    if ( scaleWidget->isColorBarEnabled()
    708742        && scaleWidget->colorBarWidth() > 0 )
    … …  
    717751    double x, y, w;
    718752
     753    qreal off = 0.0;
     754    if ( m_data->layoutFlags & FrameWithScales )
     755        off = qwtScalePenWidth( plot );
     756
    719757    switch ( axisId )
    720758    {
    721         case QwtPlot::yLeft:
    722         {
    723             x = scaleRect.right() - 1.0 - baseDist;
     759        case QwtAxis::YLeft:
     760        {
     761            x = scaleRect.right() - 1.0 - baseDist - off;
    724762            y = scaleRect.y() + startDist;
    725763            w = scaleRect.height() - startDist - endDist;
    … …  
    727765            break;
    728766        }
    729         case QwtPlot::yRight:
    730         {
    731             x = scaleRect.left() + baseDist;
     767        case QwtAxis::YRight:
     768        {
     769            x = scaleRect.left() + baseDist + off;
    732770            y = scaleRect.y() + startDist;
    733771            w = scaleRect.height() - startDist - endDist;
    … …  
    735773            break;
    736774        }
    737         case QwtPlot::xTop:
     775        case QwtAxis::XTop:
    738776        {
    739777            x = scaleRect.left() + startDist;
    740             y = scaleRect.bottom() - 1.0 - baseDist;
     778            y = scaleRect.bottom() - 1.0 - baseDist - off;
    741779            w = scaleRect.width() - startDist - endDist;
    742780            align = QwtScaleDraw::TopScale;
    743781            break;
    744782        }
    745         case QwtPlot::xBottom:
     783        case QwtAxis::XBottom:
    746784        {
    747785            x = scaleRect.left() + startDist;
    748             y = scaleRect.top() + baseDist;
     786            y = scaleRect.top() + baseDist + off;
    749787            w = scaleRect.width() - startDist - endDist;
    750788            align = QwtScaleDraw::BottomScale;
    … …  
    759797    painter->setFont( qwtResolvedFont( scaleWidget ) );
    760798
    761     QwtScaleDraw *sd = const_cast<QwtScaleDraw *>( scaleWidget->scaleDraw() );
     799    QwtScaleDraw* sd = const_cast< QwtScaleDraw* >( scaleWidget->scaleDraw() );
    762800    const QPointF sdPos = sd->pos();
    763801    const double sdLength = sd->length();
     802
     803    const bool hasBackbone = sd->hasComponent( QwtAbstractScaleDraw::Backbone );
     804
     805    if ( m_data->layoutFlags & FrameWithScales )
     806        sd->enableComponent( QwtAbstractScaleDraw::Backbone, false );
    764807
    765808    sd->move( x, y );
    … …  
    773816    sd->move( sdPos );
    774817    sd->setLength( sdLength );
     818    sd->enableComponent( QwtAbstractScaleDraw::Backbone, hasBackbone );
    775819
    776820    painter->restore();
    … …  
    778822
    779823/*!
    780   Render the canvas into a given rectangle.
    781 
    782   \param plot Plot widget
    783   \param painter Painter
    784   \param maps Maps mapping between plot and paint device coordinates
    785   \param canvasRect Canvas rectangle
    786 */
    787 void QwtPlotRenderer::renderCanvas( const QwtPlot *plot,
    788     QPainter *painter, const QRectF &canvasRect,
    789     const QwtScaleMap *maps ) const
    790 {
    791     const QWidget *canvas = plot->canvas();
     824   Render the canvas into a given rectangle.
     825
     826   \param plot Plot widget
     827   \param painter Painter
     828   \param maps Maps mapping between plot and paint device coordinates
     829   \param canvasRect Canvas rectangle
     830 */
     831void QwtPlotRenderer::renderCanvas( const QwtPlot* plot,
     832    QPainter* painter, const QRectF& canvasRect,
     833    const QwtScaleMap* maps ) const
     834{
     835    const QWidget* canvas = plot->canvas();
    792836
    793837    QRectF r = canvasRect.adjusted( 0.0, 0.0, -1.0, -1.0 );
    794838
    795     if ( d_data->layoutFlags & FrameWithScales )
     839    if ( m_data->layoutFlags & FrameWithScales )
    796840    {
    797841        painter->save();
    798842
    799         r.adjust( -1.0, -1.0, 1.0, 1.0 );
    800         painter->setPen( QPen( Qt::black ) );
    801 
    802         if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
     843        QPen pen;
     844        pen.setColor( qwtScalePenColor( plot ) );
     845        pen.setWidth( qwtScalePenWidth( plot ) );
     846        pen.setJoinStyle( Qt::MiterJoin );
     847
     848        painter->setPen( pen );
     849
     850        const qreal pw2 = 0.5 * pen.widthF();
     851        r.adjust( -pw2, -pw2, pw2, pw2 );
     852
     853        if ( !( m_data->discardFlags & DiscardCanvasBackground ) )
    803854        {
    804855            const QBrush bgBrush =
    … …  
    823874        painter->save();
    824875
    825         if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
     876        if ( !( m_data->discardFlags & DiscardCanvasBackground ) )
    826877        {
    827878            QwtPainter::drawBackgound( painter, r, canvas );
    … …  
    845896        QPainterPath clipPath;
    846897
    847         int frameWidth = 0;
    848 
    849         if ( !( d_data->discardFlags & DiscardCanvasFrame ) )
     898        double frameWidth = 0.0;
     899
     900        if ( !( m_data->discardFlags & DiscardCanvasFrame ) )
    850901        {
    851902            const QVariant fw = canvas->property( "frameWidth" );
    852             if ( fw.type() == QVariant::Int )
    853                 frameWidth = fw.toInt();
     903            if ( fw.canConvert< double >() )
     904                frameWidth = fw.value< double >();
    854905
    855906            clipPath = qwtCanvasClip( canvas, canvasRect );
    … …  
    870921        }
    871922
    872         if ( !( d_data->discardFlags & DiscardCanvasBackground ) )
     923        if ( !( m_data->discardFlags & DiscardCanvasBackground ) )
    873924        {
    874925            QwtPainter::drawBackgound( painter, innerRect, canvas );
    … …  
    888939
    889940            const QVariant borderRadius = canvas->property( "borderRadius" );
    890             if ( borderRadius.type() == QVariant::Double
    891                 && borderRadius.toDouble() > 0.0 )
     941            if ( borderRadius.canConvert< double >()
     942                && borderRadius.value< double >() > 0.0 )
    892943            {
    893                 const double radius = borderRadius.toDouble();
     944                const double radius = borderRadius.value< double >();
    894945
    895946                QwtPainter::drawRoundedFrame( painter, canvasRect,
    … …  
    915966   \param canvasRect Target rectangle
    916967   \param maps Scale maps to be calculated
    917 */
    918 void QwtPlotRenderer::buildCanvasMaps( const QwtPlot *plot,
    919     const QRectF &canvasRect, QwtScaleMap maps[] ) const
    920 {
    921     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
    922     {
    923         maps[axisId].setTransformation(
    924             plot->axisScaleEngine( axisId )->transformation() );
    925 
    926         const QwtScaleDiv &scaleDiv = plot->axisScaleDiv( axisId );
    927         maps[axisId].setScaleInterval(
    928             scaleDiv.lowerBound(), scaleDiv.upperBound() );
    929 
    930         double from, to;
    931         if ( plot->axisEnabled( axisId ) )
    932         {
    933             const int sDist = plot->axisWidget( axisId )->startBorderDist();
    934             const int eDist = plot->axisWidget( axisId )->endBorderDist();
    935             const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );
    936 
    937             if ( axisId == QwtPlot::xTop || axisId == QwtPlot::xBottom )
     968 */
     969void QwtPlotRenderer::buildCanvasMaps( const QwtPlot* plot,
     970    const QRectF& canvasRect, QwtScaleMap maps[] ) const
     971{
     972    for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
     973    {
     974        {
     975            const QwtAxisId axisId( axisPos );
     976
     977            QwtScaleMap& scaleMap = maps[axisId];
     978
     979            scaleMap.setTransformation(
     980                plot->axisScaleEngine( axisId )->transformation() );
     981
     982            const QwtScaleDiv& scaleDiv = plot->axisScaleDiv( axisId );
     983            scaleMap.setScaleInterval(
     984                scaleDiv.lowerBound(), scaleDiv.upperBound() );
     985
     986            double from, to;
     987            if ( plot->isAxisVisible( axisId ) )
    938988            {
    939                 from = scaleRect.left() + sDist;
    940                 to = scaleRect.right() - eDist;
     989                const int sDist = plot->axisWidget( axisId )->startBorderDist();
     990                const int eDist = plot->axisWidget( axisId )->endBorderDist();
     991                const QRectF scaleRect = plot->plotLayout()->scaleRect( axisId );
     992
     993                if ( QwtAxis::isXAxis( axisPos ) )
     994                {
     995                    from = scaleRect.left() + sDist;
     996                    to = scaleRect.right() - eDist;
     997                }
     998                else
     999                {
     1000                    from = scaleRect.bottom() - eDist;
     1001                    to = scaleRect.top() + sDist;
     1002                }
    9411003            }
    9421004            else
    9431005            {
    944                 from = scaleRect.bottom() - eDist;
    945                 to = scaleRect.top() + sDist;
     1006                int margin = 0;
     1007                if ( !plot->plotLayout()->alignCanvasToScale( axisPos ) )
     1008                    margin = plot->plotLayout()->canvasMargin( axisPos );
     1009
     1010                if ( QwtAxis::isYAxis( axisPos ) )
     1011                {
     1012                    from = canvasRect.bottom() - margin;
     1013                    to = canvasRect.top() + margin;
     1014                }
     1015                else
     1016                {
     1017                    from = canvasRect.left() + margin;
     1018                    to = canvasRect.right() - margin;
     1019                }
    9461020            }
    947         }
    948         else
    949         {
    950             int margin = 0;
    951             if ( !plot->plotLayout()->alignCanvasToScale( axisId ) )
    952                 margin = plot->plotLayout()->canvasMargin( axisId );
    953 
    954             if ( axisId == QwtPlot::yLeft || axisId == QwtPlot::yRight )
    955             {
    956                 from = canvasRect.bottom() - margin;
    957                 to = canvasRect.top() + margin;
    958             }
    959             else
    960             {
    961                 from = canvasRect.left() + margin;
    962                 to = canvasRect.right() - margin;
    963             }
    964         }
    965         maps[axisId].setPaintInterval( from, to );
    966     }
    967 }
    968 
    969 bool QwtPlotRenderer::updateCanvasMargins( QwtPlot *plot,
    970     const QRectF &canvasRect, const QwtScaleMap maps[] ) const
    971 {
    972     double margins[QwtPlot::axisCnt];
     1021            scaleMap.setPaintInterval( from, to );
     1022        }
     1023    }
     1024}
     1025
     1026bool QwtPlotRenderer::updateCanvasMargins( QwtPlot* plot,
     1027    const QRectF& canvasRect, const QwtScaleMap maps[] ) const
     1028{
     1029    using namespace QwtAxis;
     1030
     1031    double margins[AxisPositions];
    9731032    plot->getCanvasMarginsHint( maps, canvasRect,
    974         margins[QwtPlot::yLeft], margins[QwtPlot::xTop],
    975         margins[QwtPlot::yRight], margins[QwtPlot::xBottom] );
     1033        margins[YLeft], margins[XTop], margins[YRight], margins[XBottom] );
    9761034
    9771035    bool marginsChanged = false;
    978     for ( int axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
     1036    for ( int axisId = 0; axisId < AxisPositions; axisId++ )
    9791037    {
    9801038        if ( margins[axisId] >= 0.0 )
    9811039        {
    982             const int m = qCeil( margins[axisId] );
     1040            const int m = qwtCeil( margins[axisId] );
    9831041            plot->plotLayout()->setCanvasMargin( m, axisId);
    9841042            marginsChanged = true;
    … …  
    9991057   \return True, when exporting was successful
    10001058   \sa renderDocument()
    1001 */
    1002 bool QwtPlotRenderer::exportTo( QwtPlot *plot, const QString &documentName,
    1003      const QSizeF &sizeMM, int resolution )
     1059 */
     1060bool QwtPlotRenderer::exportTo( QwtPlot* plot, const QString& documentName,
     1061    const QSizeF& sizeMM, int resolution )
    10041062{
    10051063    if ( plot == NULL )
    … …  
    10111069
    10121070#ifndef QT_NO_FILEDIALOG
    1013     const QList<QByteArray> imageFormats =
     1071    const QList< QByteArray > imageFormats =
    10141072        QImageWriter::supportedImageFormats();
    10151073
    … …  
    10521110    return true;
    10531111}
     1112
     1113#include "moc_qwt_plot_renderer.cpp"
Note: See TracChangeset for help on using the changeset viewer.