Qt 4.8
Public Functions | Protected Functions | Properties | List of all members
QSvgGenerator Class Reference

The QSvgGenerator class provides a paint device that is used to create SVG drawings. More...

#include <qsvggenerator.h>

Inheritance diagram for QSvgGenerator:
QPaintDevice

Public Functions

QString description () const
 
QString fileName () const
 
QIODeviceoutputDevice () const
 
 QSvgGenerator ()
 Constructs a new generator. More...
 
int resolution () const
 
void setDescription (const QString &description)
 
void setFileName (const QString &fileName)
 
void setOutputDevice (QIODevice *outputDevice)
 
void setResolution (int dpi)
 
void setSize (const QSize &size)
 
void setTitle (const QString &title)
 
void setViewBox (const QRect &viewBox)
 
void setViewBox (const QRectF &viewBox)
 
QSize size () const
 
QString title () const
 
QRect viewBox () const
 
QRectF viewBoxF () const
 
 ~QSvgGenerator ()
 Destroys the generator. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
virtual int devType () const
 
virtual HDC getDC () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
virtual void releaseDC (HDC hdc) const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Protected Functions

int metric (QPaintDevice::PaintDeviceMetric metric) const
 Reimplemented Function More...
 
QPaintEnginepaintEngine () const
 Returns the paint engine used to render graphics to be converted to SVG format information. More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

QScopedPointer< QSvgGeneratorPrivated_ptr
 
QString description
 the description of the generated SVG drawing More...
 
QString fileName
 the target filename for the generated SVG drawing More...
 
QIODeviceoutputDevice
 the output device for the generated SVG drawing More...
 
int resolution
 the resolution of the generated output More...
 
QSize size
 the size of the generated SVG drawing More...
 
QString title
 the title of the generated SVG drawing More...
 
QRectF viewBox
 the viewBox of the generated SVG drawing More...
 

Additional Inherited Members

- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 
- Protected Variables inherited from QPaintDevice
ushort painters
 

Detailed Description

The QSvgGenerator class provides a paint device that is used to create SVG drawings.

Since
4.3
Note
This class or function is reentrant.

This paint device represents a Scalable Vector Graphics (SVG) drawing. Like QPrinter, it is designed as a write-only device that generates output in a specific format.

To write an SVG file, you first need to configure the output by setting the fileName or outputDevice properties. It is usually necessary to specify the size of the drawing by setting the size property, and in some cases where the drawing will be included in another, the viewBox property also needs to be set.

QSvgGenerator generator;
generator.setFileName(path);
generator.setSize(QSize(200, 200));
generator.setViewBox(QRect(0, 0, 200, 200));
generator.setTitle(tr("SVG Generator Example Drawing"));
generator.setDescription(tr("An SVG drawing created by the SVG Generator "
"Example provided with Qt."));

Other meta-data can be specified by setting the title, description and resolution properties.

As with other QPaintDevice subclasses, a QPainter object is used to paint onto an instance of this class:

QPainter painter;
painter.begin(&generator);

...

painter.end();

Painting is performed in the same way as for any other paint device. However, it is necessary to use the QPainter::begin() and QPainter::end() to explicitly begin and end painting on the device.

The SVG Generator Example shows how the same painting commands can be used for painting a widget and writing an SVG file.

See also
QSvgRenderer, QSvgWidget, {About SVG}

Definition at line 62 of file qsvggenerator.h.

Constructors and Destructors

◆ QSvgGenerator()

QSvgGenerator::QSvgGenerator ( )

Constructs a new generator.

Definition at line 551 of file qsvggenerator.cpp.

553 {
555 
556  d->engine = new QSvgPaintEngine;
557  d->owns_iodevice = false;
558 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QSvgGeneratorPrivate > d_ptr
#define Q_D(Class)
Definition: qglobal.h:2482
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

◆ ~QSvgGenerator()

QSvgGenerator::~QSvgGenerator ( )

Destroys the generator.

Definition at line 563 of file qsvggenerator.cpp.

564 {
566  if (d->owns_iodevice)
567  delete d->engine->outputDevice();
568  delete d->engine;
569 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

Functions

◆ description()

QString QSvgGenerator::description ( ) const

Referenced by setTitle().

◆ fileName()

QString QSvgGenerator::fileName ( ) const

Referenced by setFileName(), and setViewBox().

◆ metric()

int QSvgGenerator::metric ( QPaintDevice::PaintDeviceMetric  metric) const
protectedvirtual

Reimplemented Function

Reimplemented from QPaintDevice.

Definition at line 807 of file qsvggenerator.cpp.

808 {
809  Q_D(const QSvgGenerator);
810  switch (metric) {
812  return 32;
814  return d->engine->size().width();
816  return d->engine->size().height();
818  return d->engine->resolution();
820  return d->engine->resolution();
822  return qRound(d->engine->size().height() * 25.4 / d->engine->resolution());
824  return qRound(d->engine->size().width() * 25.4 / d->engine->resolution());
826  return 0xffffffff;
828  return d->engine->resolution();
830  return d->engine->resolution();
831  default:
832  qWarning("QSvgGenerator::metric(), unhandled metric %d\n", metric);
833  break;
834  }
835  return 0;
836 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
int metric(QPaintDevice::PaintDeviceMetric metric) const
Reimplemented Function
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ outputDevice()

QIODevice* QSvgGenerator::outputDevice ( ) const

Referenced by setFileName().

◆ paintEngine()

QPaintEngine * QSvgGenerator::paintEngine ( ) const
protectedvirtual

Returns the paint engine used to render graphics to be converted to SVG format information.

Implements QPaintDevice.

Definition at line 798 of file qsvggenerator.cpp.

799 {
800  Q_D(const QSvgGenerator);
801  return d->engine;
802 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

◆ resolution()

int QSvgGenerator::resolution ( ) const

Referenced by setOutputDevice().

◆ setDescription()

void QSvgGenerator::setDescription ( const QString description)

Definition at line 610 of file qsvggenerator.cpp.

611 {
613 
614  d->engine->setDocumentDescription(description);
615 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

◆ setFileName()

void QSvgGenerator::setFileName ( const QString fileName)

Definition at line 720 of file qsvggenerator.cpp.

721 {
723  if (d->engine->isActive()) {
724  qWarning("QSvgGenerator::setFileName(), cannot set file name while SVG is being generated");
725  return;
726  }
727 
728  if (d->owns_iodevice)
729  delete d->engine->outputDevice();
730 
731  d->owns_iodevice = true;
732 
733  d->fileName = fileName;
734  QFile *file = new QFile(fileName);
735  d->engine->setOutputDevice(file);
736 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
QString fileName() const
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

◆ setOutputDevice()

void QSvgGenerator::setOutputDevice ( QIODevice outputDevice)

Definition at line 757 of file qsvggenerator.cpp.

758 {
760  if (d->engine->isActive()) {
761  qWarning("QSvgGenerator::setOutputDevice(), cannot set output device while SVG is being generated");
762  return;
763  }
764  d->owns_iodevice = false;
765  d->engine->setOutputDevice(outputDevice);
766  d->fileName = QString();
767 }
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

◆ setResolution()

void QSvgGenerator::setResolution ( int  dpi)

Definition at line 788 of file qsvggenerator.cpp.

789 {
791  d->engine->setResolution(dpi);
792 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

◆ setSize()

void QSvgGenerator::setSize ( const QSize size)

Definition at line 640 of file qsvggenerator.cpp.

641 {
643  if (d->engine->isActive()) {
644  qWarning("QSvgGenerator::setSize(), cannot set size while SVG is being generated");
645  return;
646  }
647  d->engine->setSize(size);
648 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

◆ setTitle()

void QSvgGenerator::setTitle ( const QString title)

Definition at line 587 of file qsvggenerator.cpp.

588 {
590 
591  d->engine->setDocumentTitle(title);
592 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

◆ setViewBox() [1/2]

void QSvgGenerator::setViewBox ( const QRect viewBox)

Definition at line 699 of file qsvggenerator.cpp.

700 {
701  setViewBox(QRectF(viewBox));
702 }
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void setViewBox(const QRect &viewBox)

◆ setViewBox() [2/2]

void QSvgGenerator::setViewBox ( const QRectF viewBox)

Definition at line 689 of file qsvggenerator.cpp.

690 {
692  if (d->engine->isActive()) {
693  qWarning("QSvgGenerator::setViewBox(), cannot set viewBox while SVG is being generated");
694  return;
695  }
696  d->engine->setViewBox(viewBox);
697 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

◆ size()

QSize QSvgGenerator::size ( ) const

Referenced by setDescription().

◆ title()

QString QSvgGenerator::title ( ) const

Referenced by ~QSvgGenerator().

◆ viewBox()

QRect QSvgGenerator::viewBox ( ) const

Referenced by viewBoxF().

◆ viewBoxF()

QRectF QSvgGenerator::viewBoxF ( ) const

Definition at line 667 of file qsvggenerator.cpp.

668 {
669  Q_D(const QSvgGenerator);
670  return d->engine->viewBox();
671 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QSvgGenerator class provides a paint device that is used to create SVG drawings.
Definition: qsvggenerator.h:62

Properties

◆ d_ptr

QScopedPointer<QSvgGeneratorPrivate> QSvgGenerator::d_ptr
private

Definition at line 104 of file qsvggenerator.h.

◆ description

QString QSvgGenerator::description
private

the description of the generated SVG drawing

Since
4.5
See also
title

Definition at line 69 of file qsvggenerator.h.

◆ fileName

QString QSvgGenerator::fileName
private

the target filename for the generated SVG drawing

Since
4.5
See also
outputDevice

Definition at line 70 of file qsvggenerator.h.

◆ outputDevice

QIODevice * QSvgGenerator::outputDevice
private

the output device for the generated SVG drawing

Since
4.5

If both output device and file name are specified, the output device will have precedence.

See also
fileName

Definition at line 71 of file qsvggenerator.h.

◆ resolution

int QSvgGenerator::resolution
private

the resolution of the generated output

Since
4.5

The resolution is specified in dots per inch, and is used to calculate the physical size of an SVG drawing.

See also
size, viewBox

Definition at line 72 of file qsvggenerator.h.

◆ size

QSize QSvgGenerator::size
private

the size of the generated SVG drawing

Since
4.5

By default this property is set to QSize(-1, -1), which indicates that the generator should not output the width and height attributes of the <svg> element.

Note
It is not possible to change this property while a QPainter is active on the generator.
See also
viewBox, resolution

Definition at line 66 of file qsvggenerator.h.

◆ title

QString QSvgGenerator::title
private

the title of the generated SVG drawing

Since
4.5
See also
description

Definition at line 68 of file qsvggenerator.h.

◆ viewBox

QRect QSvgGenerator::viewBox
private

the viewBox of the generated SVG drawing

Returns viewBoxF().

Since
4.5

By default this property is set to QRect(0, 0, -1, -1), which indicates that the generator should not output the viewBox attribute of the <svg> element.

Note
It is not possible to change this property while a QPainter is active on the generator.
See also
viewBox(), size, resolution
Since
4.5

toRect().

\sa viewBoxF()

Definition at line 67 of file qsvggenerator.h.


The documentation for this class was generated from the following files: