QGIS/python/core/layout/qgslayoutexporter.sip

303 lines
9.1 KiB
Plaintext
Raw Normal View History

2017-10-16 14:03:57 +10:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutexporter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsLayoutExporter
{
%Docstring
Handles rendering and exports of layouts to various formats.
2017-12-15 10:36:55 -04:00
2017-10-16 14:03:57 +10:00
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgslayoutexporter.h"
%End
public:
struct PageExportDetails
{
QString directory;
%Docstring
Target folder
%End
QString baseName;
%Docstring
Base part of filename (i.e. file name without extension or '.')
%End
QString extension;
%Docstring
File suffix/extension (without the leading '.')
%End
int page;
%Docstring
Page number, where 0 = first page.
%End
};
2017-10-16 14:03:57 +10:00
QgsLayoutExporter( QgsLayout *layout );
%Docstring
2017-12-15 10:36:55 -04:00
Constructor for QgsLayoutExporter, for the specified ``layout``.
2017-10-16 14:03:57 +10:00
%End
virtual ~QgsLayoutExporter();
QgsLayout *layout() const;
%Docstring
2017-12-16 08:16:52 +10:00
Returns the layout linked to this exporter.
%End
void renderPage( QPainter *painter, int page ) const;
2017-10-16 14:03:57 +10:00
%Docstring
2017-12-15 10:36:55 -04:00
Renders a full page to a destination ``painter``.
2017-10-16 14:03:57 +10:00
2017-12-15 10:36:55 -04:00
The ``page`` argument specifies the page number to render. Page numbers
are 0 based, such that the first page in a layout is page 0.
2017-10-16 14:03:57 +10:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`renderRect()`
2017-10-16 14:03:57 +10:00
%End
QImage renderPageToImage( int page, QSize imageSize = QSize(), double dpi = 0 ) const;
%Docstring
2017-12-16 08:16:52 +10:00
Renders a full page to an image.
2017-12-16 08:16:52 +10:00
The ``page`` argument specifies the page number to render. Page numbers
are 0 based, such that the first page in a layout is page 0.
2017-12-16 08:16:52 +10:00
The optional ``imageSize`` parameter can specify the target image size, in pixels.
It is the caller's responsibility to ensure that the ratio of the target image size
matches the ratio of the corresponding layout page size.
2017-12-16 08:16:52 +10:00
The ``dpi`` parameter is an optional dpi override. Set to 0 to use the default layout print
resolution. This parameter has no effect if ``imageSize`` is specified.
2017-12-16 08:16:52 +10:00
Returns the rendered image, or a null QImage if the image does not fit into available memory.
.. seealso:: :py:func:`renderPage()`
2017-12-16 08:16:52 +10:00
.. seealso:: :py:func:`renderRegionToImage()`
%End
void renderRegion( QPainter *painter, const QRectF &region ) const;
2017-10-16 14:03:57 +10:00
%Docstring
2017-12-15 10:36:55 -04:00
Renders a ``region`` from the layout to a ``painter``. This method can be used
to render sections of pages rather than full pages.
2017-10-16 14:03:57 +10:00
2017-12-05 20:04:14 -04:00
.. seealso:: :py:func:`renderPage()`
2017-12-16 08:16:52 +10:00
.. seealso:: :py:func:`renderRegionToImage()`
%End
QImage renderRegionToImage( const QRectF &region, QSize imageSize = QSize(), double dpi = 0 ) const;
%Docstring
2017-12-16 08:16:52 +10:00
Renders a ``region`` of the layout to an image. This method can be used to render
sections of pages rather than full pages.
2017-12-16 08:16:52 +10:00
The optional ``imageSize`` parameter can specify the target image size, in pixels.
It is the caller's responsibility to ensure that the ratio of the target image size
matches the ratio of the specified region of the layout.
2017-12-16 08:16:52 +10:00
The ``dpi`` parameter is an optional dpi override. Set to 0 to use the default layout print
resolution. This parameter has no effect if ``imageSize`` is specified.
2017-12-16 08:16:52 +10:00
Returns the rendered image, or a null QImage if the image does not fit into available memory.
.. seealso:: :py:func:`renderRegion()`
2017-12-16 08:16:52 +10:00
.. seealso:: :py:func:`renderPageToImage()`
%End
enum ExportResult
{
Success,
MemoryError,
FileError,
2017-12-12 13:59:05 +10:00
PrintError,
};
struct ImageExportSettings
{
ImageExportSettings();
%Docstring
Constructor for ImageExportSettings
%End
double dpi;
%Docstring
2017-12-12 13:59:05 +10:00
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
%End
QSize imageSize;
%Docstring
2017-12-16 08:16:52 +10:00
Manual size in pixels for output image. If imageSize is not
set then it will be automatically calculated based on the
output dpi and layout size.
2017-12-16 08:16:52 +10:00
If cropToContents is true then imageSize has no effect.
2017-12-16 08:16:52 +10:00
Be careful when specifying manual sizes if pages in the layout
have differing sizes! It's likely not going to give a reasonable
output in this case, and the automatic dpi-based image size should be
used instead.
%End
bool cropToContents;
%Docstring
2017-12-16 08:16:52 +10:00
Set to true if image should be cropped so only parts of the layout
containing items are exported.
%End
QgsMargins cropMargins;
%Docstring
2017-12-16 08:16:52 +10:00
Crop to content margins, in pixels. These margins will be added
to the bounds of the exported layout if cropToContents is true.
%End
QList< int > pages;
%Docstring
2017-12-16 08:16:52 +10:00
List of specific pages to export, or an empty list to
export all pages.
2017-12-16 08:16:52 +10:00
Page numbers are 0 index based, so the first page in the
layout corresponds to page 0.
%End
bool generateWorldFile;
%Docstring
2017-12-16 08:16:52 +10:00
Set to true to generate an external world file alongside
exported images.
%End
QgsLayoutContext::Flags flags;
%Docstring
2017-12-16 08:16:52 +10:00
Layout context flags, which control how the export will be created.
%End
};
2017-12-12 13:59:05 +10:00
ExportResult exportToImage( const QString &filePath, const QgsLayoutExporter::ImageExportSettings &settings );
%Docstring
2017-12-16 08:16:52 +10:00
Exports the layout to the a ``filePath``, using the specified export ``settings``.
2017-12-16 08:16:52 +10:00
If the layout is a multi-page layout, then filenames for each page will automatically
be generated by appending "_1", "_2", etc to the image file's base name.
2017-12-16 08:16:52 +10:00
Returns a result code indicating whether the export was successful or an
error was encountered. If an error code is returned, errorFile() can be called
to determine the filename for the export which encountered the error.
2017-10-16 14:03:57 +10:00
%End
2017-12-12 13:59:05 +10:00
struct PdfExportSettings
{
PdfExportSettings();
%Docstring
Constructor for PdfExportSettings
%End
double dpi;
%Docstring
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
%End
bool rasterizeWholeImage;
%Docstring
2017-12-16 08:16:52 +10:00
Set to true to force whole layout to be rasterized while exporting.
2017-12-16 08:16:52 +10:00
This option is mutually exclusive with forceVectorOutput.
%End
bool forceVectorOutput;
%Docstring
2017-12-16 08:16:52 +10:00
Set to true to force vector object exports, even when the resultant appearance will differ
from the layout. If false, some items may be rasterized in order to maintain their
correct appearance in the output.
2017-12-16 08:16:52 +10:00
This option is mutually exclusive with rasterizeWholeImage.
2017-12-12 13:59:05 +10:00
%End
QgsLayoutContext::Flags flags;
%Docstring
2017-12-16 08:16:52 +10:00
Layout context flags, which control how the export will be created.
2017-12-12 13:59:05 +10:00
%End
};
ExportResult exportToPdf( const QString &filePath, const QgsLayoutExporter::PdfExportSettings &settings );
%Docstring
2017-12-16 08:16:52 +10:00
Exports the layout as a PDF to the a ``filePath``, using the specified export ``settings``.
2017-12-12 13:59:05 +10:00
2017-12-16 08:16:52 +10:00
Returns a result code indicating whether the export was successful or an
error was encountered.
2017-12-12 13:59:05 +10:00
%End
QString errorFile() const;
%Docstring
2017-12-16 08:16:52 +10:00
Returns the file name corresponding to the last error encountered during
an export.
%End
2017-12-11 13:39:01 +10:00
bool georeferenceOutput( const QString &file, QgsLayoutItemMap *referenceMap = 0,
const QRectF &exportRegion = QRectF(), double dpi = -1 ) const;
%Docstring
2017-12-16 08:16:52 +10:00
Georeferences a ``file`` (image of PDF) exported from the layout.
2017-12-11 13:39:01 +10:00
2017-12-16 08:16:52 +10:00
The ``referenceMap`` argument specifies a map item to use for georeferencing. If left as None, the
default layout QgsLayout.referenceMap() will be used.
2017-12-11 13:39:01 +10:00
2017-12-16 08:16:52 +10:00
The ``exportRegion`` argument can be set to a valid rectangle to indicate that only part of the layout was
exported.
2017-12-11 13:39:01 +10:00
2017-12-16 08:16:52 +10:00
Similarly, the ``dpi`` can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI.
2017-12-11 13:39:01 +10:00
2017-12-16 08:16:52 +10:00
The function will return true if the output was successfully georeferenced.
2017-12-11 13:39:01 +10:00
.. seealso:: :py:func:`computeGeoTransform()`
%End
void computeWorldFileParameters( double &a, double &b, double &c, double &d, double &e, double &f, double dpi = -1 ) const;
%Docstring
2017-12-16 08:16:52 +10:00
Compute world file parameters. Assumes the whole page containing the reference map item
will be exported.
2017-12-16 08:16:52 +10:00
The ``dpi`` argument can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI.
%End
void computeWorldFileParameters( const QRectF &region, double &a, double &b, double &c, double &d, double &e, double &f, double dpi = -1 ) const;
%Docstring
2017-12-16 08:16:52 +10:00
Computes the world file parameters for a specified ``region`` of the layout.
2017-12-16 08:16:52 +10:00
The ``dpi`` argument can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI.
%End
protected:
virtual QString generateFileName( const PageExportDetails &details ) const;
%Docstring
2017-12-16 08:16:52 +10:00
Generates the file name for a page during export.
2017-12-16 08:16:52 +10:00
Subclasses can override this method to customise page file naming.
%End
2017-10-16 14:03:57 +10:00
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutexporter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/