[QGIS Commit] r11165 - in trunk/qgis: images/themes/classic
images/themes/gis src/app/composer src/ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Jul 23 18:15:46 EDT 2009
Author: jef
Date: 2009-07-23 18:15:46 -0400 (Thu, 23 Jul 2009)
New Revision: 11165
Added:
trunk/qgis/images/themes/classic/mActionSaveAsPDF.png
trunk/qgis/images/themes/gis/mActionSaveAsPDF.png
Modified:
trunk/qgis/src/app/composer/qgscomposer.cpp
trunk/qgis/src/app/composer/qgscomposer.h
trunk/qgis/src/ui/qgscomposerbase.ui
Log:
add export to PDF to composer
Copied: trunk/qgis/images/themes/classic/mActionSaveAsPDF.png (from rev 11164, trunk/qgis/src/plugins/quick_print/quick_print.png)
===================================================================
(Binary files differ)
Copied: trunk/qgis/images/themes/gis/mActionSaveAsPDF.png (from rev 11164, trunk/qgis/images/themes/gis/plugins/quick_print.png)
===================================================================
(Binary files differ)
Modified: trunk/qgis/src/app/composer/qgscomposer.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposer.cpp 2009-07-23 20:15:50 UTC (rev 11164)
+++ trunk/qgis/src/app/composer/qgscomposer.cpp 2009-07-23 22:15:46 UTC (rev 11165)
@@ -239,6 +239,7 @@
mActionSaveAsTemplate->setIcon( QgisApp::getThemeIcon( "/mActionFileSaveAs.png" ) );
mActionExportAsImage->setIcon( QgisApp::getThemeIcon( "/mActionExportMapServer.png" ) );
mActionExportAsSVG->setIcon( QgisApp::getThemeIcon( "/mActionSaveAsSVG.png" ) );
+ mActionExportAsPDF->setIcon( QgisApp::getThemeIcon( "/mActionSaveAsPDF.png" ) );
mActionPrint->setIcon( QgisApp::getThemeIcon( "/mActionFilePrint.png" ) );
mActionZoomAll->setIcon( QgisApp::getThemeIcon( "/mActionZoomFullExtent.png" ) );
mActionZoomIn->setIcon( QgisApp::getThemeIcon( "/mActionZoomIn.png" ) );
@@ -429,20 +430,55 @@
}
}
+void QgsComposer::on_mActionExportAsPDF_triggered()
+{
+ QSettings myQSettings; // where we keep last used filter in persistant state
+ QString myLastUsedFile = myQSettings.value( "/UI/lastSaveAsPdfFile", "qgis.pdf" ).toString();
+ QFileInfo file( myLastUsedFile );
+ QFileDialog *myQFileDialog = new QFileDialog( this, tr( "Choose a file name to save the map as" ),
+ file.path(), tr( "PDF Format" ) + " (*.pdf *PDF)" );
+ myQFileDialog->selectFile( file.fileName() );
+ myQFileDialog->setFileMode( QFileDialog::AnyFile );
+ myQFileDialog->setAcceptMode( QFileDialog::AcceptSave );
+
+ int result = myQFileDialog->exec();
+ raise();
+ if ( result != QDialog::Accepted ) return;
+
+ QString myOutputFileNameQString = myQFileDialog->selectedFiles().first();
+ if ( myOutputFileNameQString == "" ) return;
+
+ myQSettings.setValue( "/UI/lastSaveAsPdfFile", myOutputFileNameQString );
+
+ QPrinter printer;
+
+ printer.setOutputFormat( QPrinter::PdfFormat );
+ printer.setOutputFileName( myOutputFileNameQString );
+
+ print( printer );
+}
+
void QgsComposer::on_mActionPrint_triggered()
{
- if ( !mComposition )
- {
+ QPrinter printer;
+
+ QPrintDialog printDialog( &printer );
+ if ( printDialog.exec() != QDialog::Accepted )
return;
- }
+ print( printer );
+}
+
+void QgsComposer::print( QPrinter &printer )
+{
+ if( !mComposition )
+ return;
+
if ( containsWMSLayer() )
{
showWMSPrintingWarning();
}
- QPrinter printer;
-
//try to set most of the print dialog settings based on composer properties
if ( mComposition->paperHeight() > mComposition->paperWidth() )
{
@@ -454,58 +490,50 @@
}
//set resolution based on composer setting
-
-
printer.setFullPage( true );
printer.setColorMode( QPrinter::Color );
- QPrintDialog printDialog( &printer );
- if ( printDialog.exec() == QDialog::Accepted )
- {
- //set user-defined resolution
- if ( mComposition )
- {
- printer.setResolution( mComposition->printResolution() );
- }
- QPainter p( &printer );
+ //set user-defined resolution
+ printer.setResolution( mComposition->printResolution() );
- QgsComposition::PlotStyle savedPlotStyle = mComposition->plotStyle();
- mComposition->setPlotStyle( QgsComposition::Print );
+ QPainter p( &printer );
- QApplication::setOverrideCursor( Qt::BusyCursor );
+ QgsComposition::PlotStyle savedPlotStyle = mComposition->plotStyle();
+ mComposition->setPlotStyle( QgsComposition::Print );
- if ( mComposition->printAsRaster() )
- {
- //print out via QImage, code copied from on_mActionExportAsImage_activated
- int width = ( int )( mComposition->printResolution() * mComposition->paperWidth() / 25.4 );
- int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
- QImage image( QSize( width, height ), QImage::Format_ARGB32 );
- image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
- image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
- image.fill( 0 );
- QPainter imagePainter( &image );
- QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
- QRectF targetArea( 0, 0, width, height );
- mComposition->render( &imagePainter, targetArea, sourceArea );
- imagePainter.end();
- p.drawImage( targetArea, image, targetArea );
- }
- else
- {
+ QApplication::setOverrideCursor( Qt::BusyCursor );
+
+ if ( mComposition->printAsRaster() )
+ {
+ //print out via QImage, code copied from on_mActionExportAsImage_activated
+ int width = ( int )( mComposition->printResolution() * mComposition->paperWidth() / 25.4 );
+ int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
+ QImage image( QSize( width, height ), QImage::Format_ARGB32 );
+ image.setDotsPerMeterX( mComposition->printResolution() / 25.4 * 1000 );
+ image.setDotsPerMeterY( mComposition->printResolution() / 25.4 * 1000 );
+ image.fill( 0 );
+ QPainter imagePainter( &image );
+ QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
+ QRectF targetArea( 0, 0, width, height );
+ mComposition->render( &imagePainter, targetArea, sourceArea );
+ imagePainter.end();
+ p.drawImage( targetArea, image, targetArea );
+ }
+ else
+ {
#if QT_VERSION < 0x040400
- QRectF paperRect( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
- QRect pageRect = printer.pageRect();
- mComposition->render( &p, pageRect, paperRect );
+ QRectF paperRect( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
+ QRect pageRect = printer.pageRect();
+ mComposition->render( &p, pageRect, paperRect );
#else
- //better in case of custom page size, but only possible with Qt>=4.4.0
- QRectF paperRectMM = printer.pageRect( QPrinter::Millimeter );
- QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );
- mComposition->render( &p, paperRectPixel, paperRectMM );
+ //better in case of custom page size, but only possible with Qt>=4.4.0
+ QRectF paperRectMM = printer.pageRect( QPrinter::Millimeter );
+ QRectF paperRectPixel = printer.pageRect( QPrinter::DevicePixel );
+ mComposition->render( &p, paperRectPixel, paperRectMM );
#endif
- }
- mComposition->setPlotStyle( savedPlotStyle );
- QApplication::restoreOverrideCursor();
}
+ mComposition->setPlotStyle( savedPlotStyle );
+ QApplication::restoreOverrideCursor();
}
void QgsComposer::on_mActionExportAsImage_triggered()
Modified: trunk/qgis/src/app/composer/qgscomposer.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposer.h 2009-07-23 20:15:50 UTC (rev 11164)
+++ trunk/qgis/src/app/composer/qgscomposer.h 2009-07-23 22:15:46 UTC (rev 11165)
@@ -119,6 +119,9 @@
//! Print as SVG
void on_mActionExportAsSVG_triggered();
+ //! Print as PDF
+ void on_mActionExportAsPDF_triggered();
+
//! Select item
void on_mActionSelectMoveItem_triggered();
@@ -243,6 +246,9 @@
//! Changes elements that are not suitable for this project
void cleanupAfterTemplateRead();
+ //! Print to a printer object
+ void print( QPrinter &printer );
+
//! Writes state under DOM element
void writeXML( QDomNode& parentNode, QDomDocument& doc );
//! Pointer to composer view
Modified: trunk/qgis/src/ui/qgscomposerbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposerbase.ui 2009-07-23 20:15:50 UTC (rev 11164)
+++ trunk/qgis/src/ui/qgscomposerbase.ui 2009-07-23 22:15:46 UTC (rev 11165)
@@ -232,6 +232,7 @@
<addaction name="mActionLoadFromTemplate" />
<addaction name="mActionSaveAsTemplate" />
<addaction name="mActionExportAsImage" />
+ <addaction name="mActionExportAsPDF" />
<addaction name="mActionExportAsSVG" />
<addaction name="mActionPrint" />
<addaction name="separator" />
@@ -334,6 +335,14 @@
<string>Export as Image...</string>
</property>
</action>
+ <action name="mActionExportAsPDF" >
+ <property name="icon" >
+ <iconset>../themes/default/mActionSaveAsPDF.png</iconset>
+ </property>
+ <property name="text" >
+ <string>Export as PDF...</string>
+ </property>
+ </action>
<action name="mActionExportAsSVG" >
<property name="icon" >
<iconset>../themes/default/mActionSaveAsSVG.png</iconset>
More information about the QGIS-commit
mailing list