Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_svgitem.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_svgitem.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_svgitem.cpp
r8127 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #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 14 14 #include <qsvgrenderer.h> 15 16 class QwtPlotSvgItem::PrivateData17 {18 public:19 PrivateData()20 {21 }22 23 QRectF boundingRect;24 QSvgRenderer renderer;25 };26 15 27 16 /*! 28 17 \brief Constructor 29 30 Sets the following item attributes:31 - QwtPlotItem::AutoScale: true32 - QwtPlotItem::Legend: false33 34 18 \param title Title 35 */ 36 QwtPlotSvgItem::QwtPlotSvgItem( const QString& title ) :37 QwtPlotItem( QwtText( title ) )19 */ 20 QwtPlotSvgItem::QwtPlotSvgItem( const QString& title ) 21 : QwtPlotGraphicItem( QwtText( title ) ) 38 22 { 39 init();40 23 } 41 24 42 25 /*! 43 26 \brief Constructor 44 45 Sets the following item attributes:46 - QwtPlotItem::AutoScale: true47 - QwtPlotItem::Legend: false48 49 27 \param title Title 50 */ 51 QwtPlotSvgItem::QwtPlotSvgItem( const QwtText& title ) :52 QwtPlotItem( title )28 */ 29 QwtPlotSvgItem::QwtPlotSvgItem( const QwtText& title ) 30 : QwtPlotGraphicItem( title ) 53 31 { 54 init();55 32 } 56 33 … … 58 35 QwtPlotSvgItem::~QwtPlotSvgItem() 59 36 { 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_PlotSVG75 int QwtPlotSvgItem::rtti() const76 {77 return QwtPlotItem::Rtti_PlotSVG;78 37 } 79 38 … … 85 44 86 45 \return true, if the SVG file could be loaded 87 */ 88 bool QwtPlotSvgItem::loadFile( const QRectF &rect,89 const QString &fileName )46 */ 47 bool QwtPlotSvgItem::loadFile( const QRectF& rect, 48 const QString& fileName ) 90 49 { 91 d_data->boundingRect = rect; 92 const bool ok = d_data->renderer.load( fileName ); 50 QwtGraphic graphic; 93 51 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 ); 96 62 97 63 return ok; … … 105 71 106 72 \return true, if the SVG data could be loaded 107 */ 108 bool QwtPlotSvgItem::loadData( const QRectF &rect,109 const QByteArray &data )73 */ 74 bool QwtPlotSvgItem::loadData( const QRectF& rect, 75 const QByteArray& data ) 110 76 { 111 d_data->boundingRect = rect; 112 const bool ok = d_data->renderer.load( data ); 77 QwtGraphic graphic; 113 78 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 ); 116 89 117 90 return ok; 118 91 } 119 120 //! Bounding rectangle of the item121 QRectF QwtPlotSvgItem::boundingRect() const122 {123 return d_data->boundingRect;124 }125 126 //! \return Renderer used to render the SVG data127 const QSvgRenderer &QwtPlotSvgItem::renderer() const128 {129 return d_data->renderer;130 }131 132 //! \return Renderer used to render the SVG data133 QSvgRenderer &QwtPlotSvgItem::renderer()134 {135 return d_data->renderer;136 }137 138 /*!139 Draw the SVG item140 141 \param painter Painter142 \param xMap X-Scale Map143 \param yMap Y-Scale Map144 \param canvasRect Contents rect of the plot canvas145 */146 void QwtPlotSvgItem::draw( QPainter *painter,147 const QwtScaleMap &xMap, const QwtScaleMap &yMap,148 const QRectF &canvasRect ) const149 {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 data166 167 \param painter Painter168 \param viewBox View Box, see QSvgRenderer::viewBox()169 \param rect Target rectangle on the paint device170 */171 void QwtPlotSvgItem::render( QPainter *painter,172 const QRectF &viewBox, const QRectF &rect ) const173 {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 coordinates195 \return View box, see QSvgRenderer::viewBox()196 */197 QRectF QwtPlotSvgItem::viewBox( const QRectF &rect ) const198 {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.
