A plot item, which displays data in Scalable Vector Graphics (SVG) format. More...
#include <qwt_plot_svgitem.h>
Classes | |
class | PrivateData |
Public Member Functions | |
QwtPlotSvgItem (const QString &title=QString::null) | |
Constructor. | |
QwtPlotSvgItem (const QwtText &title) | |
Constructor. | |
virtual | ~QwtPlotSvgItem () |
Destructor. | |
bool | loadFile (const QwtDoubleRect &, const QString &fileName) |
bool | loadData (const QwtDoubleRect &, const QByteArray &) |
virtual QwtDoubleRect | boundingRect () const |
Bounding rect of the item. | |
virtual void | draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &rect) const |
virtual int | rtti () const |
Protected Member Functions | |
void | render (QPainter *painter, const QwtDoubleRect &viewBox, const QRect &rect) const |
QwtDoubleRect | viewBox (const QwtDoubleRect &area) const |
A plot item, which displays data in Scalable Vector Graphics (SVG) format.
SVG images are often used to display maps
Definition at line 31 of file qwt_plot_svgitem.h.
QwtPlotSvgItem::QwtPlotSvgItem | ( | const QString & | title = QString::null ) |
[explicit] |
Constructor.
Sets the following item attributes:
title | Title |
Definition at line 51 of file qwt_plot_svgitem.cpp.
: QwtPlotItem(QwtText(title)) { init(); }
QwtPlotSvgItem::QwtPlotSvgItem | ( | const QwtText & | title ) | [explicit] |
Constructor.
Sets the following item attributes:
title | Title |
Definition at line 66 of file qwt_plot_svgitem.cpp.
: QwtPlotItem(title) { init(); }
QwtPlotSvgItem::~QwtPlotSvgItem | ( | ) | [virtual] |
QwtDoubleRect QwtPlotSvgItem::boundingRect | ( | ) | const [virtual] |
Bounding rect of the item.
Reimplemented from QwtPlotItem.
Definition at line 142 of file qwt_plot_svgitem.cpp.
References QwtPlotSvgItem::PrivateData::boundingRect.
Referenced by draw(), and viewBox().
{ return d_data->boundingRect; }
void QwtPlotSvgItem::draw | ( | QPainter * | painter, |
const QwtScaleMap & | xMap, | ||
const QwtScaleMap & | yMap, | ||
const QRect & | canvasRect | ||
) | const [virtual] |
Draw the SVG item
painter | Painter |
xMap | X-Scale Map |
yMap | Y-Scale Map |
canvasRect | Contents rect of the plot canvas |
Implements QwtPlotItem.
Definition at line 170 of file qwt_plot_svgitem.cpp.
References boundingRect(), QwtDoubleRect::contains(), QwtPlotItem::invTransform(), QwtDoubleRect::isValid(), render(), QwtPlotItem::transform(), and viewBox().
{ const QwtDoubleRect cRect = invTransform(xMap, yMap, canvasRect); const QwtDoubleRect bRect = boundingRect(); if ( bRect.isValid() && cRect.isValid() ) { QwtDoubleRect rect = bRect; if ( bRect.contains(cRect) ) rect = cRect; const QRect r = transform(xMap, yMap, rect); render(painter, viewBox(rect), r); } }
bool QwtPlotSvgItem::loadData | ( | const QwtDoubleRect & | rect, |
const QByteArray & | data | ||
) |
Load SVG data
rect | Bounding rectangle |
data | in SVG format |
Definition at line 123 of file qwt_plot_svgitem.cpp.
References QwtPlotSvgItem::PrivateData::boundingRect, QwtPlotItem::itemChanged(), and QwtPlotSvgItem::PrivateData::picture.
{ d_data->boundingRect = rect; #if QT_VERSION >= 0x040100 const bool ok = d_data->renderer.load(data); #else #if QT_VERSION >= 0x040000 QBuffer buffer(&(QByteArray&)data); #else QBuffer buffer(data); #endif const bool ok = d_data->picture.load(&buffer, "svg"); #endif itemChanged(); return ok; }
bool QwtPlotSvgItem::loadFile | ( | const QwtDoubleRect & | rect, |
const QString & | fileName | ||
) |
Load a SVG file
rect | Bounding rectangle |
fileName | SVG file name |
Definition at line 102 of file qwt_plot_svgitem.cpp.
References QwtPlotSvgItem::PrivateData::boundingRect, QwtPlotItem::itemChanged(), and QwtPlotSvgItem::PrivateData::picture.
{ d_data->boundingRect = rect; #if QT_VERSION >= 0x040100 const bool ok = d_data->renderer.load(fileName); #else const bool ok = d_data->picture.load(fileName, "svg"); #endif itemChanged(); return ok; }
void QwtPlotSvgItem::render | ( | QPainter * | painter, |
const QwtDoubleRect & | viewBox, | ||
const QRect & | rect | ||
) | const [protected] |
Render the SVG data
painter | Painter |
viewBox | View Box, see QSvgRenderer::viewBox |
rect | Traget rectangle on the paint device |
Definition at line 194 of file qwt_plot_svgitem.cpp.
References QwtDoubleRect::height(), QwtDoubleRect::isValid(), QwtPlotSvgItem::PrivateData::picture, QwtDoubleRect::toRect(), QwtDoubleRect::width(), QwtDoubleRect::x(), and QwtDoubleRect::y().
Referenced by draw().
{ if ( !viewBox.isValid() ) return; #if QT_VERSION >= 0x040200 d_data->renderer.setViewBox(viewBox); d_data->renderer.render(painter, rect); return; #else #if QT_VERSION >= 0x040100 const QSize paintSize(painter->window().width(), painter->window().height()); if ( !paintSize.isValid() ) return; const double xRatio = paintSize.width() / viewBox.width(); const double yRatio = paintSize.height() / viewBox.height(); const double dx = rect.left() / xRatio + 1.0; const double dy = rect.top() / yRatio + 1.0; const double mx = double(rect.width()) / paintSize.width(); const double my = double(rect.height()) / paintSize.height(); painter->save(); painter->translate(dx, dy); painter->scale(mx, my); d_data->renderer.setViewBox(viewBox.toRect()); d_data->renderer.render(painter); painter->restore(); #else const double mx = rect.width() / viewBox.width(); const double my = rect.height() / viewBox.height(); const double dx = rect.x() - mx * viewBox.x(); const double dy = rect.y() - my * viewBox.y(); painter->save(); painter->translate(dx, dy); painter->scale(mx, my); d_data->picture.play(painter); painter->restore(); #endif // < 0x040100 #endif // < 0x040200 }
int QwtPlotSvgItem::rtti | ( | ) | const [virtual] |
Reimplemented from QwtPlotItem.
Definition at line 89 of file qwt_plot_svgitem.cpp.
References QwtPlotItem::Rtti_PlotSVG.
{ return QwtPlotItem::Rtti_PlotSVG; }
QwtDoubleRect QwtPlotSvgItem::viewBox | ( | const QwtDoubleRect & | rect ) | const [protected] |
Calculate the viewBox from an rect and boundingRect().
rect | Rectangle in scale coordinates |
Definition at line 254 of file qwt_plot_svgitem.cpp.
References QwtDoubleRect::bottom(), boundingRect(), QwtDoubleRect::isValid(), QwtDoubleRect::left(), QwtPlotSvgItem::PrivateData::picture, QwtDoubleRect::right(), QwtScaleMap::setPaintInterval(), QwtScaleMap::setScaleInterval(), QwtDoubleRect::top(), and QwtScaleMap::xTransform().
Referenced by draw().
{ #if QT_VERSION >= 0x040100 const QSize sz = d_data->renderer.defaultSize(); #else #if QT_VERSION > 0x040000 const QSize sz(d_data->picture.width(), d_data->picture.height()); #else QPaintDeviceMetrics metrics(&d_data->picture); const QSize sz(metrics.width(), metrics.height()); #endif #endif const QwtDoubleRect br = boundingRect(); if ( !rect.isValid() || !br.isValid() || sz.isNull() ) return QwtDoubleRect(); QwtScaleMap xMap; xMap.setScaleInterval(br.left(), br.right()); xMap.setPaintInterval(0, sz.width()); QwtScaleMap yMap; yMap.setScaleInterval(br.top(), br.bottom()); yMap.setPaintInterval(sz.height(), 0); const double x1 = xMap.xTransform(rect.left()); const double x2 = xMap.xTransform(rect.right()); const double y1 = yMap.xTransform(rect.bottom()); const double y2 = yMap.xTransform(rect.top()); return QwtDoubleRect(x1, y1, x2 - x1, y2 - y1); }