Skip to content

Commit bed65cb

Browse files
committed
Fix #7927 : Add a warning message if trying to print a composition
as an image fails (Qt's QImage sanity check for memory overflow) Moved previous commit from core/qgscomposition to apps/qgscomposer as QGIS server uses qgscomposition.
1 parent f8d6e32 commit bed65cb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ void QgsComposer::on_mActionExportAsImage_triggered()
940940
// Image size
941941
int width = ( int )( mComposition->printResolution() * mComposition->paperWidth() / 25.4 );
942942
int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
943+
int dpi = ( int )( mComposition->printResolution() );
943944

944945
int memuse = width * height * 3 / 1000000; // pixmap + image
945946
QgsDebugMsg( QString( "Image %1x%2" ).arg( width ).arg( height ) );
@@ -972,6 +973,17 @@ void QgsComposer::on_mActionExportAsImage_triggered()
972973
for ( int i = 0; i < mComposition->numPages(); ++i )
973974
{
974975
QImage image = mComposition->printPageAsRaster( i );
976+
if (image.isNull())
977+
{
978+
QMessageBox::warning( 0, tr( "Memory Allocation Error" ),
979+
tr( "Trying to create image #%1 ( %2x%3 @ %4dpi )"
980+
"may result in a memory overflow.\n"
981+
"Please try a lower resolution or a smaller papersize" )
982+
.arg( i+1 ).arg( width ).arg( height ).arg ( dpi ),
983+
QMessageBox::Ok , QMessageBox::Ok );
984+
mView->setPaintingEnabled( true );
985+
return;
986+
}
975987
if ( i == 0 )
976988
{
977989
image.save( fileNExt.first, fileNExt.second.toLocal8Bit().constData() );

0 commit comments

Comments
 (0)