Skip to content

Commit

Permalink
Add method to determine file path for exports which encountered errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 17, 2017
1 parent 5cf36cd commit 1b8f4a0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion python/core/layout/qgslayoutexporter.sip
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/core/layout/qgslayoutexporter.cpp
Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 10 additions & 1 deletion src/core/layout/qgslayoutexporter.h
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1b8f4a0

Please sign in to comment.