Skip to content

Commit 1b8f4a0

Browse files
committed
Add method to determine file path for exports which encountered errors
1 parent 5cf36cd commit 1b8f4a0

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

python/core/layout/qgslayoutexporter.sip

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,18 @@ Resolution to export layout at
151151
be generated by appending "_1", "_2", etc to the image file's base name.
152152

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

159+
QString errorFile() const;
160+
%Docstring
161+
Returns the file name corresponding to the last error encountered during
162+
an export.
163+
:rtype: str
164+
%End
165+
158166
bool georeferenceOutput( const QString &file, QgsLayoutItemMap *referenceMap = 0,
159167
const QRectF &exportRegion = QRectF(), double dpi = -1 ) const;
160168
%Docstring

src/core/layout/qgslayoutexporter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class LayoutDpiRestorer
155155

156156
QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToImage( const QString &filePath, const QgsLayoutExporter::ImageExportSettings &settings )
157157
{
158+
mErrorFileName.clear();
159+
158160
int worldFilePageNo = -1;
159161
if ( QgsLayoutItemMap *referenceMap = mLayout->referenceMap() )
160162
{
@@ -199,14 +201,17 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToImage( const QString
199201
if ( skip )
200202
continue; // should skip this page, e.g. null size
201203

204+
QString outputFilePath = generateFileName( path, baseName, extension, page );
205+
202206
if ( image.isNull() )
203207
{
208+
mErrorFileName = outputFilePath;
204209
return MemoryError;
205210
}
206211

207-
QString outputFilePath = generateFileName( path, baseName, extension, page );
208212
if ( !saveImage( image, outputFilePath, extension ) )
209213
{
214+
mErrorFileName = outputFilePath;
210215
return FileError;
211216
}
212217

src/core/layout/qgslayoutexporter.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,17 @@ class CORE_EXPORT QgsLayoutExporter
164164
* be generated by appending "_1", "_2", etc to the image file's base name.
165165
*
166166
* Returns a result code indicating whether the export was successful or an
167-
* error was encountered.
167+
* error was encountered. If an error code is returned, errorFile() can be called
168+
* to determine the filename for the export which encountered the error.
168169
*/
169170
ExportResult exportToImage( const QString &filePath, const ImageExportSettings &settings );
170171

172+
/**
173+
* Returns the file name corresponding to the last error encountered during
174+
* an export.
175+
*/
176+
QString errorFile() const { return mErrorFileName; }
177+
171178
/**
172179
* Georeferences a \a file (image of PDF) exported from the layout.
173180
*
@@ -206,6 +213,8 @@ class CORE_EXPORT QgsLayoutExporter
206213

207214
QPointer< QgsLayout > mLayout;
208215

216+
QString mErrorFileName;
217+
209218
QImage createImage( const ImageExportSettings &settings, int page, QRectF &bounds, bool &skipPage ) const;
210219

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

0 commit comments

Comments
 (0)