@@ -641,6 +641,12 @@ void QgsComposer::on_mActionExportAsImage_triggered()
641
641
QgsDebugMsg ( QString ( " Selected filter: %1" ).arg ( myFilterString ) );
642
642
QgsDebugMsg ( QString ( " Image type: %1" ).arg ( myFilterMap[myFilterString] ) );
643
643
644
+ // Add the file type suffix to the fileName if required
645
+ if ( !myOutputFileNameQString.endsWith ( myFilterMap[myFilterString] ) )
646
+ {
647
+ myOutputFileNameQString += " ." + myFilterMap[myFilterString];
648
+ }
649
+
644
650
myQSettings.setValue ( " /UI/lastSaveAsImageFormat" , myFilterMap[myFilterString] );
645
651
myQSettings.setValue ( " /UI/lastSaveAsImageFile" , myOutputFileNameQString );
646
652
@@ -687,16 +693,9 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
687
693
m->setCheckBoxQSettingsLabel ( myQSettingsLabel );
688
694
m->setMessageAsHtml ( tr ( " <p>The SVG export function in Qgis has several "
689
695
" problems due to bugs and deficiencies in the " )
690
- #if QT_VERSION < 0x040300
691
- + tr ( " Qt4 svg code. Of note, text does not "
692
- " appear in the SVG file and there are problems "
693
- " with the map bounding box clipping other items "
694
- " such as the legend or scale bar.</p>" )
695
- #else
696
696
+ tr ( " Qt4 svg code. In particular, there are problems "
697
697
" with layers not being clipped to the map "
698
698
" bounding box.</p>" )
699
- #endif
700
699
+ tr ( " If you require a vector-based output file from "
701
700
" Qgis it is suggested that you try printing "
702
701
" to PostScript if the SVG output is not "
@@ -724,30 +723,26 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
724
723
// mView->setScene(0);//don't redraw the scene on the display while we render
725
724
mComposition ->setPlotStyle ( QgsComposition::Print );
726
725
727
- #if QT_VERSION < 0x040300
728
- Q3Picture pic;
729
- QPainter p ( &pic );
730
- QRectF renderArea ( 0 , 0 , ( mComposition ->paperWidth () * mComposition ->scale () ), ( mComposition ->paperHeight () * mComposition ->scale () ) );
731
- #else
732
726
QSvgGenerator generator;
727
+ generator.setTitle ( QgsProject::instance ()->title () );
733
728
generator.setFileName ( myOutputFileNameQString );
734
- generator.setSize ( QSize (( int )mComposition ->paperWidth (), ( int )mComposition ->paperHeight () ) );
735
- generator.setResolution ( 25.4 ); // because the rendering is done in mm, convert the dpi
729
+ // width in pixel
730
+ int width = ( int )( mComposition ->paperWidth () * mComposition ->printResolution () / 25.4 );
731
+ // height in pixel
732
+ int height = ( int )( mComposition ->paperHeight () * mComposition ->printResolution () / 25.4 );
733
+ generator.setSize ( QSize ( width, height ) );
734
+ generator.setResolution ( mComposition ->printResolution () ); // because the rendering is done in mm, convert the dpi
736
735
737
736
QPainter p ( &generator );
738
- QRectF renderArea ( 0 , 0 , mComposition ->paperWidth (), mComposition ->paperHeight () );
739
- #endif
740
- mComposition ->render ( &p, renderArea, renderArea );
737
+
738
+ QRectF sourceArea ( 0 , 0 , mComposition ->paperWidth (), mComposition ->paperHeight () );
739
+ QRectF targetArea ( 0 , 0 , width, height );
740
+ mComposition ->render ( &p, targetArea, sourceArea );
741
+
741
742
p.end ();
742
743
743
744
mComposition ->setPlotStyle ( QgsComposition::Preview );
744
745
// mView->setScene(mComposition->canvas()); //now that we're done, set the view to show the scene again
745
-
746
- #if QT_VERSION < 0x040300
747
- QRect br = pic.boundingRect ();
748
-
749
- pic.save ( myOutputFileNameQString, " svg" );
750
- #endif
751
746
}
752
747
753
748
void QgsComposer::on_mActionSelectMoveItem_triggered ()
0 commit comments