Skip to content

Commit 3dc80f2

Browse files
author
mhugent
committedSep 2, 2008

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -857,11 +857,9 @@ bool QgsComposer::shiftFileContent( QFile *file, Q_LONG start, int shift )
857857

858858
void QgsComposer::on_mActionExportAsImage_activated( void )
859859
{
860-
861-
#if 0
862860
// Image size
863-
int width = ( int )( mComposition->resolution() * mComposition->paperWidth() / 25.4 );
864-
int height = ( int )( mComposition->resolution() * mComposition->paperHeight() / 25.4 );
861+
int width = ( int )( mComposition->printoutResolution() * mComposition->paperWidth() / 25.4 );
862+
int height = ( int )( mComposition-> printoutResolution() * mComposition->paperHeight() / 25.4 );
865863

866864
int memuse = width * height * 3 / 1000000; // pixmap + image
867865
QgsDebugMsg( QString( "Image %1 x %2" ).arg( width ).arg( height ) );
@@ -889,8 +887,8 @@ void QgsComposer::on_mActionExportAsImage_activated( void )
889887

890888
//find out the last used filter
891889
QSettings myQSettings; // where we keep last used filter in persistant state
892-
QString myLastUsedFormat = myQSettings.readEntry( "/UI/lastSaveAsImageFormat", "png" );
893-
QString myLastUsedFile = myQSettings.readEntry( "/UI/lastSaveAsImageFile", "qgis.png" );
890+
QString myLastUsedFormat = myQSettings.value( "/UI/lastSaveAsImageFormat", "png" ).toString();
891+
QString myLastUsedFile = myQSettings.value( "/UI/lastSaveAsImageFile", "qgis.png").toString();
894892
QFileInfo file( myLastUsedFile );
895893

896894
// get a list of supported output image types
@@ -900,7 +898,7 @@ void QgsComposer::on_mActionExportAsImage_activated( void )
900898
for ( ; myCounterInt < QImageWriter::supportedImageFormats().count(); myCounterInt++ )
901899
{
902900
QString myFormat = QString( QImageWriter::supportedImageFormats().at( myCounterInt ) );
903-
QString myFilter = myFormat + " " + tr( "format" ) + " (*." + myFormat.lower() + " *." + myFormat.upper() + ")";
901+
QString myFilter = myFormat + " " + tr( "format" ) + " (*." + myFormat.toLower() + " *." + myFormat.toUpper() + ")";
904902

905903
if ( myCounterInt > 0 ) myFilters += ";;";
906904
myFilters += myFilter;
@@ -931,7 +929,7 @@ void QgsComposer::on_mActionExportAsImage_activated( void )
931929
myQFileDialog->selectFile( file.fileName() );
932930

933931
// allow for selection of more than one file
934-
myQFileDialog->setMode( QFileDialog::AnyFile );
932+
myQFileDialog->setFileMode( QFileDialog::AnyFile );
935933

936934
// set the filter to the last one used
937935
myQFileDialog->selectFilter( myLastUsedFilter );
@@ -940,43 +938,42 @@ void QgsComposer::on_mActionExportAsImage_activated( void )
940938
myQFileDialog->setAcceptMode( QFileDialog::AcceptSave );
941939

942940
//prompt the user for a file name
943-
QString myOutputFileNameQString; // = myQFileDialog->getSaveFileName(); //delete this
941+
QString myOutputFileNameQString;
944942

945943
int result = myQFileDialog->exec();
946-
raise();
944+
//raise();
947945

948-
if ( result != QDialog::Accepted ) return;
946+
if ( result != QDialog::Accepted )
947+
{
948+
return;
949+
}
949950

950951
myOutputFileNameQString = myQFileDialog->selectedFiles().first();
951952
QString myFilterString = myQFileDialog->selectedFilter();
952953
QgsDebugMsg( QString( "Selected filter: %1" ).arg( myFilterString ) );
953954
QgsDebugMsg( QString( "Image type: %1" ).arg( myFilterMap[myFilterString] ) );
954955

955-
myQSettings.writeEntry( "/UI/lastSaveAsImageFormat", myFilterMap[myFilterString] );
956-
myQSettings.writeEntry( "/UI/lastSaveAsImageFile", myOutputFileNameQString );
956+
myQSettings.setValue( "/UI/lastSaveAsImageFormat", myFilterMap[myFilterString] );
957+
myQSettings.setValue( "/UI/lastSaveAsImageFile", myOutputFileNameQString );
957958

958959
if ( myOutputFileNameQString == "" ) return;
959960

960-
double scale = ( double )( mComposition->resolution() / 25.4 / mComposition->scale() );
961-
962-
mView->setScene( 0 );
963961
mComposition->setPlotStyle( QgsComposition::Print );
964-
965-
QPixmap pixmap( width, height );
966-
pixmap.fill( QColor( 255, 255, 255 ) ) ;
967-
QPainter p( &pixmap );
968-
p.scale( scale, scale );
969-
970-
QRectF renderArea( 0, 0, ( mComposition->paperWidth() * mComposition->scale() ), ( mComposition->paperHeight() * mComposition->scale() ) );
971-
972-
mComposition->canvas()->render( &p, renderArea );
962+
mView->setScene(0);
963+
964+
QImage image( QSize(width, height), QImage::Format_ARGB32 );
965+
image.setDotsPerMeterX(mComposition->printoutResolution() / 25.4 * 1000);
966+
image.setDotsPerMeterY(mComposition->printoutResolution() / 25.4 * 1000);
967+
image.fill(0);
968+
QPainter p( &image );
969+
QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight());
970+
QRectF targetArea(0, 0, width, height);
971+
mComposition->render( &p, targetArea, sourceArea);
973972
p.end();
974973

975974
mComposition->setPlotStyle( QgsComposition::Preview );
976-
mView->setScene( mComposition->canvas() );
977-
978-
pixmap.save( myOutputFileNameQString, myFilterMap[myFilterString].toLocal8Bit().data() );
979-
#endif //0
975+
image.save( myOutputFileNameQString, myFilterMap[myFilterString].toLocal8Bit().data() );
976+
mView->setScene(mComposition);
980977
}
981978

982979

0 commit comments

Comments
 (0)
Please sign in to comment.