Skip to content
Permalink
Browse files

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.
  • Loading branch information
tqhien committed Jun 21, 2013
1 parent f8d6e32 commit bed65cb1f4dbc582d0b3be0d3b1d9e9083e8086e
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/app/composer/qgscomposer.cpp
@@ -940,6 +940,7 @@ void QgsComposer::on_mActionExportAsImage_triggered()
// Image size
int width = ( int )( mComposition->printResolution() * mComposition->paperWidth() / 25.4 );
int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
int dpi = ( int )( mComposition->printResolution() );

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

0 comments on commit bed65cb

Please sign in to comment.
You can’t perform that action at this time.