Navigation Menu

Skip to content

Commit

Permalink
[processing] Improve atlas exporting feedback, don't throw is no feat…
Browse files Browse the repository at this point in the history
…ures found
  • Loading branch information
nirvn authored and nyalldawson committed Feb 19, 2021
1 parent 654e76b commit af4fb3f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 37 deletions.
44 changes: 26 additions & 18 deletions src/analysis/processing/qgsalgorithmlayoutatlastoimage.cpp
Expand Up @@ -217,30 +217,38 @@ QVariantMap QgsLayoutAtlasToImageAlgorithm::processAlgorithm( const QVariantMap
}
}

switch ( exporter.exportToImage( atlas, fileName, extension, settings, error, feedback ) )
if ( atlas->updateFeatures() )
{
case QgsLayoutExporter::Success:
feedback->pushInfo( QObject::tr( "Exporting %n atlas feature(s)", "", atlas->count() ) );
switch ( exporter.exportToImage( atlas, fileName, extension, settings, error, feedback ) )
{
feedback->pushInfo( QObject::tr( "Successfully exported layout to %1" ).arg( QDir::toNativeSeparators( directory ) ) );
break;
}
case QgsLayoutExporter::Success:
{
feedback->pushInfo( QObject::tr( "Successfully exported layout to %1" ).arg( QDir::toNativeSeparators( directory ) ) );
break;
}

case QgsLayoutExporter::FileError:
throw QgsProcessingException( QObject::tr( "Cannot write to %1.\n\nThis file may be open in another application." ).arg( QDir::toNativeSeparators( directory ) ) );
case QgsLayoutExporter::FileError:
throw QgsProcessingException( QObject::tr( "Cannot write to %1.\n\nThis file may be open in another application." ).arg( QDir::toNativeSeparators( directory ) ) );

case QgsLayoutExporter::MemoryError:
throw QgsProcessingException( QObject::tr( "Trying to create the image "
"resulted in a memory overflow.\n\n"
"Please try a lower resolution or a smaller paper size." ) );
case QgsLayoutExporter::MemoryError:
throw QgsProcessingException( QObject::tr( "Trying to create the image "
"resulted in a memory overflow.\n\n"
"Please try a lower resolution or a smaller paper size." ) );

case QgsLayoutExporter::IteratorError:
throw QgsProcessingException( QObject::tr( "Error encountered while exporting atlas." ) );
case QgsLayoutExporter::IteratorError:
throw QgsProcessingException( QObject::tr( "Error encountered while exporting atlas." ) );

case QgsLayoutExporter::SvgLayerError:
case QgsLayoutExporter::PrintError:
case QgsLayoutExporter::Canceled:
// no meaning for imageexports, will not be encountered
break;
case QgsLayoutExporter::SvgLayerError:
case QgsLayoutExporter::PrintError:
case QgsLayoutExporter::Canceled:
// no meaning for imageexports, will not be encountered
break;
}
}
else
{
feedback->reportError( QObject::tr( "No atlas features found" ) );
}

feedback->setProgress( 100 );
Expand Down
46 changes: 27 additions & 19 deletions src/analysis/processing/qgsalgorithmlayoutatlastopdf.cpp
Expand Up @@ -201,32 +201,40 @@ QVariantMap QgsLayoutAtlasToPdfAlgorithm::processAlgorithm( const QVariantMap &p
}

const QString dest = parameterAsFileOutput( parameters, QStringLiteral( "OUTPUT" ), context );
switch ( exporter.exportToPdf( atlas, dest, settings, error, feedback ) )
if ( atlas->updateFeatures() )
{
case QgsLayoutExporter::Success:
feedback->pushInfo( QObject::tr( "Exporting %n atlas feature(s)", "", atlas->count() ) );
switch ( exporter.exportToPdf( atlas, dest, settings, error, feedback ) )
{
feedback->pushInfo( QObject::tr( "Successfully exported layout to %1" ).arg( QDir::toNativeSeparators( dest ) ) );
break;
}
case QgsLayoutExporter::Success:
{
feedback->pushInfo( QObject::tr( "Successfully exported layout to %1" ).arg( QDir::toNativeSeparators( dest ) ) );
break;
}

case QgsLayoutExporter::FileError:
throw QgsProcessingException( QObject::tr( "Cannot write to %1.\n\nThis file may be open in another application." ).arg( QDir::toNativeSeparators( dest ) ) );
case QgsLayoutExporter::FileError:
throw QgsProcessingException( QObject::tr( "Cannot write to %1.\n\nThis file may be open in another application." ).arg( QDir::toNativeSeparators( dest ) ) );

case QgsLayoutExporter::PrintError:
throw QgsProcessingException( QObject::tr( "Could not create print device." ) );
case QgsLayoutExporter::PrintError:
throw QgsProcessingException( QObject::tr( "Could not create print device." ) );

case QgsLayoutExporter::MemoryError:
throw QgsProcessingException( QObject::tr( "Trying to create the image "
"resulted in a memory overflow.\n\n"
"Please try a lower resolution or a smaller paper size." ) );
case QgsLayoutExporter::MemoryError:
throw QgsProcessingException( QObject::tr( "Trying to create the image "
"resulted in a memory overflow.\n\n"
"Please try a lower resolution or a smaller paper size." ) );

case QgsLayoutExporter::IteratorError:
throw QgsProcessingException( QObject::tr( "Error encountered while exporting atlas." ) );
case QgsLayoutExporter::IteratorError:
throw QgsProcessingException( QObject::tr( "Error encountered while exporting atlas." ) );

case QgsLayoutExporter::SvgLayerError:
case QgsLayoutExporter::Canceled:
// no meaning for imageexports, will not be encountered
break;
case QgsLayoutExporter::SvgLayerError:
case QgsLayoutExporter::Canceled:
// no meaning for imageexports, will not be encountered
break;
}
}
else
{
feedback->reportError( QObject::tr( "No atlas features found" ) );
}

feedback->setProgress( 100 );
Expand Down

0 comments on commit af4fb3f

Please sign in to comment.