16#ifndef QGSLAYOUTEXPORTER_H
17#define QGSLAYOUTEXPORTER_H
35#if defined( HAVE_QTPRINTER )
104 void renderPage( QPainter *painter,
int page )
const;
124 QImage
renderPageToImage(
int page, QSize imageSize = QSize(),
double dpi = -1 )
const;
133 void renderRegion( QPainter *painter,
const QRectF ®ion )
const;
151 QImage
renderRegionToImage(
const QRectF ®ion, QSize imageSize = QSize(),
double dpi = -1 )
const;
170 :
flags(
Qgis::LayoutRenderFlag::Antialiasing |
Qgis::LayoutRenderFlag::UseAdvancedEffects )
277 :
flags(
Qgis::LayoutRenderFlag::Antialiasing |
Qgis::LayoutRenderFlag::UseAdvancedEffects )
455 :
flags(
Qgis::LayoutRenderFlag::Antialiasing |
Qgis::LayoutRenderFlag::UseAdvancedEffects )
481#if defined( HAVE_QTPRINTER )
508 :
flags(
Qgis::LayoutRenderFlag::Antialiasing |
Qgis::LayoutRenderFlag::UseAdvancedEffects )
632 QMap< QString, QgsLabelingResults * > labelingResults();
645 QMap< QString, QgsLabelingResults * > takeLabelingResults();
663 bool georeferenceOutput(
const QString &file,
QgsLayoutItemMap *referenceMap =
nullptr,
const QRectF &exportRegion = QRectF(),
double dpi = -1 )
const;
671 void computeWorldFileParameters(
double &a,
double &b,
double &
c,
double &d,
double &e,
double &f,
double dpi = -1 )
const;
678 void computeWorldFileParameters(
const QRectF ®ion,
double &a,
double &b,
double &
c,
double &d,
double &e,
double &f,
double dpi = -1 )
const;
688 static bool requiresRasterization(
const QgsLayout *layout );
697 static bool containsAdvancedEffects(
const QgsLayout *layout );
705 virtual QString generateFileName(
const PageExportDetails &details )
const;
708 QPointer< QgsLayout > mLayout;
710 void captureLabelingResults();
711 QMap< QString, QgsLabelingResults * > mLabelingResults;
713 mutable QString mErrorFileName;
714 mutable QString mErrorMessage;
716 QImage createImage(
const ImageExportSettings &settings,
int page, QRectF &bounds,
bool &skipPage )
const;
722 static int firstPageToBeExported(
QgsLayout *layout );
727 static bool saveImage(
const QImage &image,
const QString &imageFilename,
const QString &imageFormat,
QgsProject *projectForMetadata,
int quality = -1 );
742 std::unique_ptr<double[]> computeGeoTransform(
const QgsLayoutItemMap *referenceMap =
nullptr,
const QRectF &exportRegion = QRectF(),
double dpi = -1 )
const;
745 void writeWorldFile(
const QString &fileName,
double a,
double b,
double c,
double d,
double e,
double f )
const;
750 static void preparePrintAsPdf(
QgsLayout *layout, QPdfWriter *device,
const QString &filePath );
752 static void preparePrint(
QgsLayout *layout, QPagedPaintDevice *device,
bool setFirstPageSize =
false );
757 ExportResult print( QPagedPaintDevice *device );
767 ExportResult printPrivate( QPagedPaintDevice *device, QPainter &painter,
bool startNewPage =
false,
double dpi = -1,
bool rasterize =
false );
769 static void updatePrinterPageSize(
QgsLayout *layout, QPagedPaintDevice *device,
int page );
771 ExportResult renderToLayeredSvg(
772 const SvgExportSettings &settings,
776 const QRectF &bounds,
777 const QString &filename,
778 unsigned int svgLayerId,
779 const QString &layerName,
781 QDomNode &svgDocRoot,
785 void appendMetadataToSvg( QDomDocument &svg )
const;
787 bool georeferenceOutputPrivate(
788 const QString &file,
QgsLayoutItemMap *referenceMap =
nullptr,
const QRectF &exportRegion = QRectF(),
double dpi = -1,
bool includeGeoreference =
true,
bool includeMetadata =
false
791 ExportResult handleLayeredExport(
792 const QList<QGraphicsItem *> &items,
794 const std::function<QString(
QgsLayoutItem *item )> &getItemExportGroupFunc
798 static QString getCreator();
801 static void setXmpMetadata( QPdfWriter *pdfWriter,
QgsLayout *layout );
Provides global constants and enumerations for use throughout the application.
QFlags< LayoutRenderFlag > LayoutRenderFlags
Flags for controlling how a layout is rendered.
TextRenderFormat
Options for rendering text.
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
An abstract base class for QgsLayout based classes which can be exported by QgsLayoutExporter.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Stores computed placement from labeling engine.
ExportResult exportToSvg(const QString &filePath, const QgsLayoutExporter::SvgExportSettings &settings)
Exports the layout as an SVG to the filePath, using the specified export settings.
ExportResult exportToImage(const QString &filePath, const QgsLayoutExporter::ImageExportSettings &settings)
Exports the layout to the filePath, using the specified export settings.
QString errorMessage() const
Returns a string describing the last error encountered during an export.
ExportResult exportToPdf(const QString &filePath, const QgsLayoutExporter::PdfExportSettings &settings)
Exports the layout as a PDF to the filePath, using the specified export settings.
QImage renderRegionToImage(const QRectF ®ion, QSize imageSize=QSize(), double dpi=-1) const
Renders a region of the layout to an image.
QgsLayout * layout() const
Returns the layout linked to this exporter.
static const QgsSettingsEntryBool * settingOpenAfterExportingPdf
Settings entry - Whether to automatically open pdfs after exporting them.
ExportResult
Result codes for exporting layouts.
@ Canceled
Export was canceled.
@ MemoryError
Unable to allocate memory required to export.
@ PrintError
Could not start printing to destination device.
@ IteratorError
Error iterating over layout.
@ FileError
Could not write to destination file, likely due to a lock held by another application.
@ Success
Export was successful.
@ SvgLayerError
Could not create layered SVG file.
static const QgsSettingsEntryInteger * settingImageQuality
Settings entry - Image quality for lossy formats.
QImage renderPageToImage(int page, QSize imageSize=QSize(), double dpi=-1) const
Renders a full page to an image.
QgsLayoutExporter(QgsLayout *layout)
Constructor for QgsLayoutExporter, for the specified layout.
friend class TestQgsLayoutExporter
static ExportResult exportToPdfs(QgsAbstractLayoutIterator *iterator, const QString &baseFilePath, const QgsLayoutExporter::PdfExportSettings &settings, QString &error, QgsFeedback *feedback=nullptr)
Exports a layout iterator to multiple PDF files, with the specified export settings.
QString errorFile() const
Returns the file name corresponding to the last error encountered during an export.
void renderPage(QPainter *painter, int page) const
Renders a full page to a destination painter.
static const QgsSettingsEntryBool * settingOpenAfterExportingImage
Settings entry - Whether to automatically open images after exporting them.
static const QgsSettingsEntryBool * settingOpenAfterExportingSvg
Settings entry - Whether to automatically open svgs after exporting them.
void renderRegion(QPainter *painter, const QRectF ®ion) const
Renders a region from the layout to a painter.
friend class TestQgsLayout
Layout graphical items for displaying a map.
Base class for graphical items within a QgsLayout.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Defines the four margins of a rectangle.
Contains settings regarding how masks are calculated and handled during a map render.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
A boolean settings entry.
An integer settings entry.
Contains settings for simplifying geometries fetched from a vector layer.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define SIP_IF_FEATURE(feature)
Contains settings relating to exporting layouts to raster images.
QgsMargins cropMargins
Crop to content margins, in pixels.
QList< int > pages
List of specific pages to export, or an empty list to export all pages.
bool generateWorldFile
Set to true to generate an external world file alongside exported images.
QSize imageSize
Manual size in pixels for output image.
bool exportMetadata
Indicates whether image export should include metadata generated from the layout's project's metadata...
int quality
Image quality, typically used for JPEG compression (whose quality ranges from 1 to 100) if quality is...
Qgis::LayoutRenderFlags flags
Layout context flags, which control how the export will be created.
bool cropToContents
Set to true if image should be cropped so only parts of the layout containing items are exported.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QVector< qreal > predefinedMapScales
A list of predefined scales to use with the layout.
Contains details of a page being exported by the class.
QString baseName
Base part of filename (i.e. file name without extension or '.').
QString extension
File suffix/extension (without the leading '.').
QString directory
Target folder.
int page
Page number, where 0 = first page.
Contains settings relating to exporting layouts to PDF.
bool useIso32000ExtensionFormatGeoreferencing
true if ISO3200 extension format georeferencing should be used.
bool forceVectorOutput
Set to true to force vector object exports, even when the resultant appearance will differ from the l...
bool rasterizeWholeImage
Set to true to force whole layout to be rasterized while exporting.
QStringList exportThemes
Optional list of map themes to export as Geospatial PDF layer groups.
bool includeGeoPdfFeatures
true if feature vector information (such as attributes) should be exported during Geospatial PDF expo...
bool exportMetadata
Indicates whether PDF export should include metadata generated from the layout's project's metadata.
bool appendGeoreference
Indicates whether PDF export should append georeference data.
Qgis::LayoutRenderFlags flags
Layout context flags, which control how the export will be created.
bool writeGeoPdf
true if geospatial PDF files should be created, instead of normal PDF files.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QVector< qreal > predefinedMapScales
A list of predefined scales to use with the layout.
bool exportLayersAsSeperateFiles
true if individual layers from the layout should be rendered to separate PDF files.
bool simplifyGeometries
Indicates whether vector geometries should be simplified to avoid redundant extraneous detail,...
bool useOgcBestPracticeFormatGeoreferencing
true if OGC "best practice" format georeferencing should be used.
Qgis::TextRenderFormat textRenderFormat
Text rendering format, which controls how text should be rendered in the export (e....
Contains settings relating to printing layouts.
QVector< qreal > predefinedMapScales
A list of predefined scales to use with the layout.
Qgis::LayoutRenderFlags flags
Layout context flags, which control how the export will be created.
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
bool rasterizeWholeImage
Set to true to force whole layout to be rasterized while exporting.
Contains settings relating to exporting layouts to SVG.
bool forceVectorOutput
Set to true to force vector object exports, even when the resultant appearance will differ from the l...
Qgis::LayoutRenderFlags flags
Layout context flags, which control how the export will be created.
Qgis::TextRenderFormat textRenderFormat
Text rendering format, which controls how text should be rendered in the export (e....
bool exportAsLayers
Set to true to export as a layered SVG file.
bool simplifyGeometries
Indicates whether vector geometries should be simplified to avoid redundant extraneous detail,...
bool exportMetadata
Indicates whether SVG export should include RDF metadata generated from the layout's project's metada...
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
QVector< qreal > predefinedMapScales
A list of predefined scales to use with the layout.
bool exportLabelsToSeparateLayers
Set to true to export labels to separate layers (grouped by map layer) in layered SVG exports.
bool cropToContents
Set to true if image should be cropped so only parts of the layout containing items are exported.
QgsMargins cropMargins
Crop to content margins, in layout units.
Contains details of a particular export layer relating to a layout item.