Skip to content
Permalink
Browse files

[processing] Improve atlas exporting feedback, don't throw is no feat…

…ures found
  • Loading branch information
nirvn authored and nyalldawson committed Feb 19, 2021
1 parent 654e76b commit af4fb3f9f7a6dc617ee6f820c09d86a56e7ef99b
@@ -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 );
@@ -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 );

0 comments on commit af4fb3f

Please sign in to comment.