Skip to content
Permalink
Browse files

Add method to determine file path for exports which encountered errors

  • Loading branch information
nyalldawson committed Dec 11, 2017
1 parent 5cf36cd commit 1b8f4a09ba2025e3619533c5a001fac4716e2036
@@ -151,10 +151,18 @@ Resolution to export layout at
be generated by appending "_1", "_2", etc to the image file's base name.

Returns a result code indicating whether the export was successful or an
error was encountered.
error was encountered. If an error code is returned, errorFile() can be called
to determine the filename for the export which encountered the error.
:rtype: ExportResult
%End

QString errorFile() const;
%Docstring
Returns the file name corresponding to the last error encountered during
an export.
:rtype: str
%End

bool georeferenceOutput( const QString &file, QgsLayoutItemMap *referenceMap = 0,
const QRectF &exportRegion = QRectF(), double dpi = -1 ) const;
%Docstring
@@ -155,6 +155,8 @@ class LayoutDpiRestorer

QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToImage( const QString &filePath, const QgsLayoutExporter::ImageExportSettings &settings )
{
mErrorFileName.clear();

int worldFilePageNo = -1;
if ( QgsLayoutItemMap *referenceMap = mLayout->referenceMap() )
{
@@ -199,14 +201,17 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToImage( const QString
if ( skip )
continue; // should skip this page, e.g. null size

QString outputFilePath = generateFileName( path, baseName, extension, page );

if ( image.isNull() )
{
mErrorFileName = outputFilePath;
return MemoryError;
}

QString outputFilePath = generateFileName( path, baseName, extension, page );
if ( !saveImage( image, outputFilePath, extension ) )
{
mErrorFileName = outputFilePath;
return FileError;
}

@@ -164,10 +164,17 @@ class CORE_EXPORT QgsLayoutExporter
* be generated by appending "_1", "_2", etc to the image file's base name.
*
* Returns a result code indicating whether the export was successful or an
* error was encountered.
* error was encountered. If an error code is returned, errorFile() can be called
* to determine the filename for the export which encountered the error.
*/
ExportResult exportToImage( const QString &filePath, const ImageExportSettings &settings );

/**
* Returns the file name corresponding to the last error encountered during
* an export.
*/
QString errorFile() const { return mErrorFileName; }

/**
* Georeferences a \a file (image of PDF) exported from the layout.
*
@@ -206,6 +213,8 @@ class CORE_EXPORT QgsLayoutExporter

QPointer< QgsLayout > mLayout;

QString mErrorFileName;

QImage createImage( const ImageExportSettings &settings, int page, QRectF &bounds, bool &skipPage ) const;

QString generateFileName( const QString &path, const QString &baseName, const QString &suffix, int page ) const;

0 comments on commit 1b8f4a0

Please sign in to comment.
You can’t perform that action at this time.