MuseScore  3.4
Music composition and notation
Protected Member Functions | Private Member Functions | Private Attributes | List of all members
SvgGenerator Class Reference

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

#include <svggenerator.h>

Inheritance diagram for SvgGenerator:
Inheritance graph
[legend]
Collaboration diagram for SvgGenerator:
Collaboration graph
[legend]

Protected Member Functions

QPaintEngine * paintEngine () const
 
int metric (QPaintDevice::PaintDeviceMetric metric) const
 

Private Member Functions

QString title () const
 the title of the generated SVG drawing More...
 
void setTitle (const QString &title)
 
QString description () const
 the description of the generated SVG drawing More...
 
void setDescription (const QString &description)
 
QSize size () const
 the size of the generated SVG drawing More...
 
void setSize (const QSize &size)
 
QRect viewBox () const
 the viewBox of the generated SVG drawing More...
 
QRectF viewBoxF () const
 
void setViewBox (const QRect &viewBox)
 
void setViewBox (const QRectF &viewBox)
 
QString fileName () const
 the target filename for the generated SVG drawing More...
 
void setFileName (const QString &fileName)
 
QIODevice * outputDevice () const
 the output device for the generated SVG drawing More...
 
void setOutputDevice (QIODevice *outputDevice)
 
void setResolution (int dpi)
 
int resolution () const
 the resolution of the generated output More...
 
void setElement (const Ms::Element *e)
 

Private Attributes

Q_DECLARE_PRIVATE(SvgGenerator) Q_PROPERTY(QSize size READ size WRITE setSize) Q_PROPERTY(QRectF viewBox READ viewBoxF WRITE setViewBox) Q_PROPERTY(QString title READ title WRITE setTitle) Q_PROPERTY(QString description READ description WRITE setDescription) Q_PROPERTY(QString fileName READ fileName WRITE setFileName) Q_PROPERTY(QIODevice *outputDevice READ outputDevice WRITE setOutputDevice) Q_PROPERTY(int resolution READ resolution WRITE setResolution) publi ~SvgGenerator )()
 
QScopedPointer< SvgGeneratorPrivated_ptr
 

Detailed Description

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

Since
4.3 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.

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:

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
SvgRenderer, SvgWidget, {About SVG}

Member Function Documentation

◆ description()

QString SvgGenerator::description ( ) const
private

the description of the generated SVG drawing

Since
4.5
See also
title

◆ fileName()

QString SvgGenerator::fileName ( ) const
private

the target filename for the generated SVG drawing

Since
4.5
See also
outputDevice

◆ metric()

int SvgGenerator::metric ( QPaintDevice::PaintDeviceMetric  metric) const
protected

◆ outputDevice()

QIODevice * SvgGenerator::outputDevice ( ) const
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

◆ paintEngine()

QPaintEngine * SvgGenerator::paintEngine ( ) const
protected

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

◆ resolution()

int SvgGenerator::resolution ( ) const
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

◆ setDescription()

void SvgGenerator::setDescription ( const QString &  description)
private

◆ setElement()

void SvgGenerator::setElement ( const Ms::Element e)
private

setElement() function Sets the _element variable in SvgPaintEngine. Called by saveSVG() in mscore/file.cpp.

◆ setFileName()

void SvgGenerator::setFileName ( const QString &  fileName)
private

◆ setOutputDevice()

void SvgGenerator::setOutputDevice ( QIODevice *  outputDevice)
private

◆ setResolution()

void SvgGenerator::setResolution ( int  dpi)
private

◆ setSize()

void SvgGenerator::setSize ( const QSize &  size)
private

◆ setTitle()

void SvgGenerator::setTitle ( const QString &  title)
private

◆ setViewBox() [1/2]

void SvgGenerator::setViewBox ( const QRect &  viewBox)
private

◆ setViewBox() [2/2]

void SvgGenerator::setViewBox ( const QRectF &  viewBox)
private

◆ size()

QSize SvgGenerator::size ( ) const
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

◆ title()

QString SvgGenerator::title ( ) const
private

the title of the generated SVG drawing

Since
4.5
See also
description

◆ viewBox()

QRect SvgGenerator::viewBox ( ) const
private

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
Since
4.5

Returns viewBoxF().toRect().

See also
viewBoxF()

◆ viewBoxF()

QRectF SvgGenerator::viewBoxF ( ) const
private

Member Data Documentation

◆ d_ptr

QScopedPointer<SvgGeneratorPrivate> SvgGenerator::d_ptr
private

◆ ~SvgGenerator

SvgGenerator::~SvgGenerator
private

Destroys the generator.


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