Skip to content

Commit d69a5c2

Browse files
author
jef
committedJul 17, 2010
apply #2858
git-svn-id: http://svn.osgeo.org/qgis/trunk@13920 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 2d6defd commit d69a5c2

File tree

1 file changed

+55
-19
lines changed

1 file changed

+55
-19
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -541,29 +541,54 @@ void QgsComposer::print( QPrinter &printer )
541541

542542
QApplication::setOverrideCursor( Qt::BusyCursor );
543543

544-
if ( mComposition->printAsRaster() )
544+
bool printAsRaster = mComposition->printAsRaster();
545+
546+
if ( printAsRaster )
545547
{
546548
//print out via QImage, code copied from on_mActionExportAsImage_activated
547549
int width = ( int )( mComposition->printResolution() * mComposition->paperWidth() / 25.4 );
548550
int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
549551
QImage image( QSize( width, height ), QImage::Format_ARGB32 );
550-
image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
551-
image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
552-
image.fill( 0 );
553-
QPainter imagePainter( &image );
554-
QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
555-
QRectF targetArea( 0, 0, width, height );
556-
mComposition->render( &imagePainter, targetArea, sourceArea );
557-
imagePainter.end();
558-
p.drawImage( targetArea, image, targetArea );
552+
if ( !image.isNull() )
553+
{
554+
image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
555+
image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
556+
image.fill( 0 );
557+
QPainter imagePainter( &image );
558+
QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
559+
QRectF targetArea( 0, 0, width, height );
560+
mComposition->render( &imagePainter, targetArea, sourceArea );
561+
imagePainter.end();
562+
p.drawImage( targetArea, image, targetArea );
563+
}
564+
else
565+
{
566+
QApplication::restoreOverrideCursor();
567+
int answer = QMessageBox::warning( 0,
568+
tr( "Image too large" ),
569+
tr( "Creation of image with %1x%2 pixels failed. Retry without 'Print As Raster'?" )
570+
.arg( width ).arg( height ),
571+
QMessageBox::Ok | QMessageBox::Cancel,
572+
QMessageBox::Ok );
573+
if ( answer == QMessageBox::Cancel )
574+
{
575+
mComposition->setPlotStyle( savedPlotStyle );
576+
return;
577+
}
578+
579+
QApplication::setOverrideCursor( Qt::BusyCursor );
580+
printAsRaster = false;
581+
}
559582
}
560-
else
583+
584+
if ( !printAsRaster )
561585
{
562586
//better in case of custom page size, but only possible with Qt>=4.4.0
563587
QRectF paperRectMM = printer.pageRect( QPrinter::Millimeter );
564588
QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );
565589
mComposition->render( &p, paperRectPixel, paperRectMM );
566590
}
591+
567592
mComposition->setPlotStyle( savedPlotStyle );
568593
QApplication::restoreOverrideCursor();
569594
}
@@ -580,18 +605,19 @@ void QgsComposer::on_mActionExportAsImage_triggered()
580605
int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
581606

582607
int memuse = width * height * 3 / 1000000; // pixmap + image
583-
QgsDebugMsg( QString( "Image %1 x %2" ).arg( width ).arg( height ) );
608+
QgsDebugMsg( QString( "Image %1x%2" ).arg( width ).arg( height ) );
584609
QgsDebugMsg( QString( "memuse = %1" ).arg( memuse ) );
585610

586-
if ( memuse > 200 ) // cca 4500 x 4500
611+
if ( memuse > 200 ) // about 4500x4500
587612
{
588613
int answer = QMessageBox::warning( 0, tr( "Big image" ),
589-
tr( "To create image %1 x %2 requires circa %3 MB of memory" )
614+
tr( "To create image %1x%2 requires about %3 MB of memory. Proceed?" )
590615
.arg( width ).arg( height ).arg( memuse ),
591-
QMessageBox::Ok, QMessageBox::Abort );
616+
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok );
592617

593618
raise();
594-
if ( answer == QMessageBox::Abort ) return;
619+
if ( answer == QMessageBox::Cancel )
620+
return;
595621
}
596622

597623
// Get file and format (stolen from qgisapp.cpp but modified significantely)
@@ -678,12 +704,22 @@ void QgsComposer::on_mActionExportAsImage_triggered()
678704
myQSettings.setValue( "/UI/lastSaveAsImageFormat", myFilterMap[myFilterString] );
679705
myQSettings.setValue( "/UI/lastSaveAsImageFile", myOutputFileNameQString );
680706

681-
if ( myOutputFileNameQString == "" ) return;
707+
if ( myOutputFileNameQString == "" )
708+
return;
709+
710+
QImage image( QSize( width, height ), QImage::Format_ARGB32 );
711+
if ( image.isNull() )
712+
{
713+
QMessageBox::warning( 0,
714+
tr( "Image too big" ),
715+
tr( "Creation of image with %1x%2 pixels failed. Export aborted." )
716+
.arg( width ).arg( height ),
717+
QMessageBox::Ok );
718+
return;
719+
}
682720

683721
mComposition->setPlotStyle( QgsComposition::Print );
684722
mView->setScene( 0 );
685-
686-
QImage image( QSize( width, height ), QImage::Format_ARGB32 );
687723
image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
688724
image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
689725
image.fill( 0 );

0 commit comments

Comments
 (0)
Please sign in to comment.