37
37
#include < QSettings>
38
38
#include < QIcon>
39
39
#include < QPixmap>
40
+ #if QT_VERSION < 0x040300
40
41
#include < Q3Picture>
42
+ #else
43
+ #include < QSvgGenerator>
44
+ #endif
41
45
#include < QToolBar>
42
46
#include < QImageWriter>
43
47
#include < QCheckBox>
@@ -773,9 +777,6 @@ QRectF renderArea(0,0,(mComposition->paperWidth() * mComposition->scale()),(mCom
773
777
void QgsComposer::on_mActionExportAsSVG_activated (void )
774
778
{
775
779
776
- // QT 4 QPicture does not support export to SVG, so we're still using Q3Picture.
777
- // When QGIS moves to Qt 4.3, we can use QSvgGenerator instead.
778
-
779
780
QString myQSettingsLabel = " /UI/displaySVGWarning" ;
780
781
QSettings myQSettings;
781
782
@@ -791,10 +792,16 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
791
792
m->setCheckBoxQSettingsLabel (myQSettingsLabel);
792
793
m->setMessageAsHtml (tr (" <p>The SVG export function in Qgis has several "
793
794
" problems due to bugs and deficiencies in the "
795
+ #if QT_VERSION < 0x040300
794
796
" Qt4 svg code. Of note, text does not "
795
797
" appear in the SVG file and there are problems "
796
798
" with the map bounding box clipping other items "
797
799
" such as the legend or scale bar.</p>"
800
+ #else
801
+ " Qt4 svg code. In particular, there are problems "
802
+ " with layers not being clipped to the map"
803
+ " bounding box.</p>"
804
+ #endif
798
805
" If you require a vector-based output file from "
799
806
" Qgis it is suggested that you try printing "
800
807
" to PostScript if the SVG output is not "
@@ -822,20 +829,30 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
822
829
mView ->setScene (0 );// don't redraw the scene on the display while we render
823
830
mComposition ->setPlotStyle ( QgsComposition::Print );
824
831
832
+ #if QT_VERSION < 0x040300
825
833
Q3Picture pic;
826
834
QPainter p (&pic);
827
835
QRectF renderArea (0 ,0 , (mComposition ->paperWidth () * mComposition ->scale ()), (mComposition ->paperHeight () * mComposition ->scale ()) );
828
-
836
+ #else
837
+ QSvgGenerator generator;
838
+ generator.setFileName (myOutputFileNameQString);
839
+ generator.setSize (QSize ( (int )mComposition ->paperWidth (), (int )mComposition ->paperHeight () ));
840
+ generator.setResolution ((int )(mComposition ->resolution () / 25.4 )); // because the rendering is done in mm, convert the dpi
841
+
842
+ QPainter p (&generator);
843
+ QRectF renderArea (0 ,0 , mComposition ->paperWidth (), mComposition ->paperHeight ());
844
+ #endif
829
845
mComposition ->canvas ()->render (&p, renderArea);
830
846
p.end ();
831
847
832
848
mComposition ->setPlotStyle ( QgsComposition::Preview );
833
849
mView ->setScene (mComposition ->canvas ()); // now that we're done, set the view to show the scene again
834
850
851
+ #if QT_VERSION < 0x040300
835
852
QRect br = pic.boundingRect ();
836
853
837
854
pic.save ( myOutputFileNameQString, " svg" );
838
-
855
+ # endif
839
856
}
840
857
841
858
0 commit comments