Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QSvgGenerator Class Reference

\inmodule QtSvg More...

#include <qsvggenerator.h>

+ Inheritance diagram for QSvgGenerator:
+ Collaboration diagram for QSvgGenerator:

Public Types

enum class  SvgVersion { SvgTiny12 , Svg11 }
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM ,
  PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY ,
  PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled
}
 

Public Member Functions

 QSvgGenerator ()
 Constructs a new generator using the SVG Tiny 1.2 profile.
 
 QSvgGenerator (SvgVersion version)
 
 ~QSvgGenerator ()
 Destroys the generator.
 
QString title () const
 
void setTitle (const QString &title)
 
QString description () const
 
void setDescription (const QString &description)
 
QSize size () const
 
void setSize (const QSize &size)
 
QRect viewBox () const
 
QRectF viewBoxF () const
 
void setViewBox (const QRect &viewBox)
 
void setViewBox (const QRectF &viewBox)
 
QString fileName () const
 
void setFileName (const QString &fileName)
 
QIODeviceoutputDevice () const
 
void setOutputDevice (QIODevice *outputDevice)
 
void setResolution (int dpi)
 
int resolution () const
 
SvgVersion svgVersion () const
 
- Public Member Functions inherited from QPaintDevice
virtual ~QPaintDevice ()
 
virtual int devType () const
 
bool paintingActive () const
 
int width () const
 
int height () const
 
int widthMM () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
qreal devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int colorCount () const
 
int depth () const
 

Protected Member Functions

QPaintEnginepaintEngine () const override
 Returns the paint engine used to render graphics to be converted to SVG format information.
 
int metric (QPaintDevice::PaintDeviceMetric metric) const override
 \reimp
 
- Protected Member Functions inherited from QPaintDevice
 QPaintDevice () noexcept
 
virtual void initPainter (QPainter *painter) const
 
virtual QPaintDeviceredirected (QPoint *offset) const
 
virtual QPaintersharedPainter () const
 

Properties

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

Additional Inherited Members

- Static Public Member Functions inherited from QPaintDevice
static qreal devicePixelRatioFScale ()
 
- Protected Attributes inherited from QPaintDevice
ushort painters
 

Detailed Description

\inmodule QtSvg

Since
4.3

The QSvgGenerator class provides a paint device that is used to create SVG drawings. \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 \l fileName or \l outputDevice properties. It is usually necessary to specify the size of the drawing by setting the \l size property, and in some cases where the drawing will be included in another, the \l viewBox property also needs to be set.

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:

\dots

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

See also
QSvgRenderer, QSvgWidget, {Qt SVG C++ Classes}

Definition at line 22 of file qsvggenerator.h.

Member Enumeration Documentation

◆ SvgVersion

enum class QSvgGenerator::SvgVersion
strong
Since
6.5

This enumeration describes the version of the SVG output of the generator.

\value SvgTiny12 The generated document follows the SVG Tiny 1.2 specification. \value Svg11 The generated document follows the SVG 1.1 specification.

Enumerator
SvgTiny12 
Svg11 

Definition at line 35 of file qsvggenerator.h.

Constructor & Destructor Documentation

◆ QSvgGenerator() [1/2]

QSvgGenerator::QSvgGenerator ( )

Constructs a new generator using the SVG Tiny 1.2 profile.

Definition at line 580 of file qsvggenerator.cpp.

◆ QSvgGenerator() [2/2]

QSvgGenerator::QSvgGenerator ( SvgVersion version)
explicit
Since
6.5

Constructs a new generator that uses the SVG version version.

Definition at line 590 of file qsvggenerator.cpp.

References d.

◆ ~QSvgGenerator()

QSvgGenerator::~QSvgGenerator ( )

Destroys the generator.

Definition at line 602 of file qsvggenerator.cpp.

References d.

Member Function Documentation

◆ description()

QString QSvgGenerator::description ( ) const

Definition at line 636 of file qsvggenerator.cpp.

References d.

◆ fileName()

QString QSvgGenerator::fileName ( ) const

Definition at line 735 of file qsvggenerator.cpp.

References d.

◆ metric()

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

\reimp

Reimplemented from QPaintDevice.

Definition at line 834 of file qsvggenerator.cpp.

References d, QPaintDevice::devicePixelRatioFScale(), metric(), QPaintDevice::PdmDepth, QPaintDevice::PdmDevicePixelRatio, QPaintDevice::PdmDevicePixelRatioScaled, QPaintDevice::PdmDpiX, QPaintDevice::PdmDpiY, QPaintDevice::PdmHeight, QPaintDevice::PdmHeightMM, QPaintDevice::PdmNumColors, QPaintDevice::PdmPhysicalDpiX, QPaintDevice::PdmPhysicalDpiY, QPaintDevice::PdmWidth, QPaintDevice::PdmWidthMM, qRound(), and qWarning.

Referenced by metric().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ outputDevice()

QIODevice * QSvgGenerator::outputDevice ( ) const

Definition at line 769 of file qsvggenerator.cpp.

References d.

◆ paintEngine()

QPaintEngine * QSvgGenerator::paintEngine ( ) const
overrideprotectedvirtual

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

Implements QPaintDevice.

Definition at line 825 of file qsvggenerator.cpp.

References d.

◆ resolution()

int QSvgGenerator::resolution ( ) const

Definition at line 797 of file qsvggenerator.cpp.

References d.

◆ setDescription()

void QSvgGenerator::setDescription ( const QString & description)

Definition at line 643 of file qsvggenerator.cpp.

References d, and description.

◆ setFileName()

void QSvgGenerator::setFileName ( const QString & fileName)

Definition at line 741 of file qsvggenerator.cpp.

References d, file, fileName, and qWarning.

◆ setOutputDevice()

void QSvgGenerator::setOutputDevice ( QIODevice * outputDevice)

Definition at line 775 of file qsvggenerator.cpp.

References d, outputDevice, and qWarning.

◆ setResolution()

void QSvgGenerator::setResolution ( int dpi)

Definition at line 803 of file qsvggenerator.cpp.

References d.

◆ setSize()

void QSvgGenerator::setSize ( const QSize & size)

Definition at line 670 of file qsvggenerator.cpp.

References d, and qWarning.

◆ setTitle()

void QSvgGenerator::setTitle ( const QString & title)

Definition at line 623 of file qsvggenerator.cpp.

References d, and title.

◆ setViewBox() [1/2]

void QSvgGenerator::setViewBox ( const QRect & viewBox)

Definition at line 723 of file qsvggenerator.cpp.

References setViewBox(), and viewBox.

Referenced by setViewBox().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setViewBox() [2/2]

void QSvgGenerator::setViewBox ( const QRectF & viewBox)

Definition at line 713 of file qsvggenerator.cpp.

References d, qWarning, and viewBox.

◆ size()

QSize QSvgGenerator::size ( ) const

Definition at line 664 of file qsvggenerator.cpp.

References d.

◆ svgVersion()

QSvgGenerator::SvgVersion QSvgGenerator::svgVersion ( ) const
Since
6.5

Returns the version of the SVG document that this generator is producing.

Definition at line 815 of file qsvggenerator.cpp.

References d.

◆ title()

QString QSvgGenerator::title ( ) const

Definition at line 616 of file qsvggenerator.cpp.

References d.

◆ viewBox()

QRect QSvgGenerator::viewBox ( ) const
Since
4.5

Returns viewBoxF().toRect().

See also
viewBoxF()

Definition at line 707 of file qsvggenerator.cpp.

References d.

◆ viewBoxF()

QRectF QSvgGenerator::viewBoxF ( ) const

Definition at line 694 of file qsvggenerator.cpp.

References d.

Property Documentation

◆ description

QSvgGenerator::description
readwrite

the description of the generated SVG drawing

Since
4.5
See also
title

Definition at line 30 of file qsvggenerator.h.

Referenced by setDescription().

◆ fileName

QSvgGenerator::fileName
readwrite

the target filename for the generated SVG drawing

Since
4.5
See also
outputDevice

Definition at line 31 of file qsvggenerator.h.

Referenced by setFileName().

◆ outputDevice

QSvgGenerator::outputDevice
readwrite

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 32 of file qsvggenerator.h.

Referenced by setOutputDevice().

◆ resolution

QSvgGenerator::resolution
readwrite

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 33 of file qsvggenerator.h.

◆ size

QSvgGenerator::size
readwrite

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 27 of file qsvggenerator.h.

◆ title

QSvgGenerator::title
readwrite

the title of the generated SVG drawing

Since
4.5
See also
description

Definition at line 29 of file qsvggenerator.h.

Referenced by setTitle().

◆ viewBox

QSvgGenerator::viewBox
readwrite

the viewBox of the generated SVG drawing

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

Definition at line 28 of file qsvggenerator.h.

Referenced by setViewBox(), and setViewBox().


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