Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_svgitem.cpp


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

    r8127 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_plot_svgitem.h"
    11 #include "qwt_scale_map.h"
    12 #include "qwt_painter.h"
    13 #include <qpainter.h>
     11#include "qwt_text.h"
     12#include "qwt_graphic.h"
     13
    1414#include <qsvgrenderer.h>
    15 
    16 class QwtPlotSvgItem::PrivateData
    17 {
    18 public:
    19     PrivateData()
    20     {
    21     }
    22 
    23     QRectF boundingRect;
    24     QSvgRenderer renderer;
    25 };
    2615
    2716/*!
    2817   \brief Constructor
    29 
    30    Sets the following item attributes:
    31    - QwtPlotItem::AutoScale: true
    32    - QwtPlotItem::Legend:    false
    33 
    3418   \param title Title
    35 */
    36 QwtPlotSvgItem::QwtPlotSvgItem( const QString& title ):
    37     QwtPlotItem( QwtText( title ) )
     19 */
     20QwtPlotSvgItem::QwtPlotSvgItem( const QString& title )
     21    : QwtPlotGraphicItem( QwtText( title ) )
    3822{
    39     init();
    4023}
    4124
    4225/*!
    4326   \brief Constructor
    44 
    45    Sets the following item attributes:
    46    - QwtPlotItem::AutoScale: true
    47    - QwtPlotItem::Legend:    false
    48 
    4927   \param title Title
    50 */
    51 QwtPlotSvgItem::QwtPlotSvgItem( const QwtText& title ):
    52     QwtPlotItem( title )
     28 */
     29QwtPlotSvgItem::QwtPlotSvgItem( const QwtText& title )
     30    : QwtPlotGraphicItem( title )
    5331{
    54     init();
    5532}
    5633
    … …  
    5835QwtPlotSvgItem::~QwtPlotSvgItem()
    5936{
    60     delete d_data;
    61 }
    62 
    63 void QwtPlotSvgItem::init()
    64 {
    65     d_data = new PrivateData();
    66     d_data->boundingRect = QwtPlotItem::boundingRect();
    67 
    68     setItemAttribute( QwtPlotItem::AutoScale, true );
    69     setItemAttribute( QwtPlotItem::Legend, false );
    70 
    71     setZ( 8.0 );
    72 }
    73 
    74 //! \return QwtPlotItem::Rtti_PlotSVG
    75 int QwtPlotSvgItem::rtti() const
    76 {
    77     return QwtPlotItem::Rtti_PlotSVG;
    7837}
    7938
    … …  
    8544
    8645   \return true, if the SVG file could be loaded
    87 */
    88 bool QwtPlotSvgItem::loadFile( const QRectF &rect,
    89     const QString &fileName )
     46 */
     47bool QwtPlotSvgItem::loadFile( const QRectF& rect,
     48    const QString& fileName )
    9049{
    91     d_data->boundingRect = rect;
    92     const bool ok = d_data->renderer.load( fileName );
     50    QwtGraphic graphic;
    9351
    94     legendChanged();
    95     itemChanged();
     52    QSvgRenderer renderer;
     53
     54    const bool ok = renderer.load( fileName );
     55    if ( ok )
     56    {
     57        QPainter p( &graphic );
     58        renderer.render( &p );
     59    }
     60
     61    setGraphic( rect, graphic );
    9662
    9763    return ok;
    … …  
    10571
    10672   \return true, if the SVG data could be loaded
    107 */
    108 bool QwtPlotSvgItem::loadData( const QRectF &rect,
    109     const QByteArray &data )
     73 */
     74bool QwtPlotSvgItem::loadData( const QRectF& rect,
     75    const QByteArray& data )
    11076{
    111     d_data->boundingRect = rect;
    112     const bool ok = d_data->renderer.load( data );
     77    QwtGraphic graphic;
    11378
    114     legendChanged();
    115     itemChanged();
     79    QSvgRenderer renderer;
     80
     81    const bool ok = renderer.load( data );
     82    if ( ok )
     83    {
     84        QPainter p( &graphic );
     85        renderer.render( &p );
     86    }
     87
     88    setGraphic( rect, graphic );
    11689
    11790    return ok;
    11891}
    119 
    120 //! Bounding rectangle of the item
    121 QRectF QwtPlotSvgItem::boundingRect() const
    122 {
    123     return d_data->boundingRect;
    124 }
    125 
    126 //! \return Renderer used to render the SVG data
    127 const QSvgRenderer &QwtPlotSvgItem::renderer() const
    128 {
    129     return d_data->renderer;
    130 }
    131 
    132 //! \return Renderer used to render the SVG data
    133 QSvgRenderer &QwtPlotSvgItem::renderer()
    134 {
    135     return d_data->renderer;
    136 }
    137 
    138 /*!
    139   Draw the SVG item
    140 
    141   \param painter Painter
    142   \param xMap X-Scale Map
    143   \param yMap Y-Scale Map
    144   \param canvasRect Contents rect of the plot canvas
    145 */
    146 void QwtPlotSvgItem::draw( QPainter *painter,
    147     const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    148     const QRectF &canvasRect ) const
    149 {
    150     const QRectF cRect = QwtScaleMap::invTransform(
    151         xMap, yMap, canvasRect.toRect() );
    152     const QRectF bRect = boundingRect();
    153     if ( bRect.isValid() && cRect.isValid() )
    154     {
    155         QRectF rect = bRect;
    156         if ( bRect.contains( cRect ) )
    157             rect = cRect;
    158 
    159         const QRectF r = QwtScaleMap::transform( xMap, yMap, rect );
    160         render( painter, viewBox( rect ), r );
    161     }
    162 }
    163 
    164 /*!
    165   Render the SVG data
    166 
    167   \param painter Painter
    168   \param viewBox View Box, see QSvgRenderer::viewBox()
    169   \param rect Target rectangle on the paint device
    170 */
    171 void QwtPlotSvgItem::render( QPainter *painter,
    172     const QRectF &viewBox, const QRectF &rect ) const
    173 {
    174     if ( !viewBox.isValid() )
    175         return;
    176 
    177     QRectF r = rect;
    178 
    179     if ( QwtPainter::roundingAlignment( painter ) )
    180     {
    181         r.setLeft ( qRound( r.left() ) );
    182         r.setRight ( qRound( r.right() ) );
    183         r.setTop ( qRound( r.top() ) );
    184         r.setBottom ( qRound( r.bottom() ) );
    185     }
    186 
    187     d_data->renderer.setViewBox( viewBox );
    188     d_data->renderer.render( painter, r );
    189 }
    190 
    191 /*!
    192   Calculate the view box from rect and boundingRect().
    193 
    194   \param rect Rectangle in scale coordinates
    195   \return View box, see QSvgRenderer::viewBox()
    196 */
    197 QRectF QwtPlotSvgItem::viewBox( const QRectF &rect ) const
    198 {
    199     const QSize sz = d_data->renderer.defaultSize();
    200     const QRectF br = boundingRect();
    201 
    202     if ( !rect.isValid() || !br.isValid() || sz.isNull() )
    203         return QRectF();
    204 
    205     QwtScaleMap xMap;
    206     xMap.setScaleInterval( br.left(), br.right() );
    207     xMap.setPaintInterval( 0, sz.width() );
    208 
    209     QwtScaleMap yMap;
    210     yMap.setScaleInterval( br.top(), br.bottom() );
    211     yMap.setPaintInterval( sz.height(), 0 );
    212 
    213     const double x1 = xMap.transform( rect.left() );
    214     const double x2 = xMap.transform( rect.right() );
    215     const double y1 = yMap.transform( rect.bottom() );
    216     const double y2 = yMap.transform( rect.top() );
    217 
    218     return QRectF( x1, y1, x2 - x1, y2 - y1 );
    219 }
Note: See TracChangeset for help on using the changeset viewer.