Skip to content

Commit 26aafb7

Browse files
author
telwertowski
committedMar 25, 2008
Patch #878 for PrintComposer SVG Export from Steven Bell with conditional compilation directives added to use QSvgGenerator for Qt4.3 or greater while continuing to use Q3Picture for Qt 4.2 or lower.
git-svn-id: http://svn.osgeo.org/qgis/trunk@8264 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 98444a4 commit 26aafb7

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
#include <QSettings>
3838
#include <QIcon>
3939
#include <QPixmap>
40+
#if QT_VERSION < 0x040300
4041
#include <Q3Picture>
42+
#else
43+
#include <QSvgGenerator>
44+
#endif
4145
#include <QToolBar>
4246
#include <QImageWriter>
4347
#include <QCheckBox>
@@ -773,9 +777,6 @@ QRectF renderArea(0,0,(mComposition->paperWidth() * mComposition->scale()),(mCom
773777
void QgsComposer::on_mActionExportAsSVG_activated(void)
774778
{
775779

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-
779780
QString myQSettingsLabel = "/UI/displaySVGWarning";
780781
QSettings myQSettings;
781782

@@ -791,10 +792,16 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
791792
m->setCheckBoxQSettingsLabel(myQSettingsLabel);
792793
m->setMessageAsHtml(tr("<p>The SVG export function in Qgis has several "
793794
"problems due to bugs and deficiencies in the "
795+
#if QT_VERSION < 0x040300
794796
"Qt4 svg code. Of note, text does not "
795797
"appear in the SVG file and there are problems "
796798
"with the map bounding box clipping other items "
797799
"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
798805
"If you require a vector-based output file from "
799806
"Qgis it is suggested that you try printing "
800807
"to PostScript if the SVG output is not "
@@ -822,20 +829,30 @@ void QgsComposer::on_mActionExportAsSVG_activated(void)
822829
mView->setScene(0);//don't redraw the scene on the display while we render
823830
mComposition->setPlotStyle ( QgsComposition::Print );
824831

832+
#if QT_VERSION < 0x040300
825833
Q3Picture pic;
826834
QPainter p(&pic);
827835
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
829845
mComposition->canvas()->render(&p, renderArea);
830846
p.end();
831847

832848
mComposition->setPlotStyle ( QgsComposition::Preview );
833849
mView->setScene(mComposition->canvas()); //now that we're done, set the view to show the scene again
834850

851+
#if QT_VERSION < 0x040300
835852
QRect br = pic.boundingRect();
836853

837854
pic.save ( myOutputFileNameQString, "svg" );
838-
855+
#endif
839856
}
840857

841858

0 commit comments

Comments
 (0)
Please sign in to comment.