qwt_plot_svgitem.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #include "qwt_plot_svgitem.h"
11 #include "qwt_scale_map.h"
12 #include "qwt_painter.h"
13 #include <qpainter.h>
14 #include <qsvgrenderer.h>
15 
17 {
18 public:
20  {
21  }
22 
23  QRectF boundingRect;
24  QSvgRenderer renderer;
25 };
26 
37  QwtPlotItem( QwtText( title ) )
38 {
39  init();
40 }
41 
52  QwtPlotItem( title )
53 {
54  init();
55 }
56 
59 {
60  delete d_data;
61 }
62 
64 {
65  d_data = new PrivateData();
67 
70 
71  setZ( 8.0 );
72 }
73 
76 {
78 }
79 
88 bool QwtPlotSvgItem::loadFile( const QRectF &rect,
89  const QString &fileName )
90 {
91  d_data->boundingRect = rect;
92  const bool ok = d_data->renderer.load( fileName );
93 
94  legendChanged();
95  itemChanged();
96 
97  return ok;
98 }
99 
108 bool QwtPlotSvgItem::loadData( const QRectF &rect,
109  const QByteArray &data )
110 {
111  d_data->boundingRect = rect;
112  const bool ok = d_data->renderer.load( data );
113 
114  legendChanged();
115  itemChanged();
116 
117  return ok;
118 }
119 
122 {
123  return d_data->boundingRect;
124 }
125 
127 const QSvgRenderer &QwtPlotSvgItem::renderer() const
128 {
129  return d_data->renderer;
130 }
131 
134 {
135  return d_data->renderer;
136 }
137 
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 
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 
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 }
virtual void legendChanged()
virtual void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &rect) const
QwtPlotSvgItem(const QString &title=QString())
Constructor.
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
void render(QPainter *painter, const QRectF &viewBox, const QRectF &rect) const
For QwtPlotSvgItem.
The item is represented on the legend.
PrivateData * d_data
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
A class representing a text.
Definition: qwt_text.h:51
void setZ(double z)
Set the z value.
virtual ~QwtPlotSvgItem()
Destructor.
A scale map.
Definition: qwt_scale_map.h:30
double invTransform(double p) const
virtual void itemChanged()
bool loadFile(const QRectF &, const QString &fileName)
virtual int rtti() const
Base class for items on the plot canvas.
Definition: qwt_plot_item.h:64
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
virtual QRectF boundingRect() const
Bounding rectangle of the item.
bool loadData(const QRectF &, const QByteArray &)
const QSvgRenderer & renderer() const
QRectF viewBox(const QRectF &area) const
static bool roundingAlignment()
Definition: qwt_painter.h:176
const QwtText & title() const
virtual QRectF boundingRect() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17