add export to PDF to composer

git-svn-id: http://svn.osgeo.org/qgis/trunk@11165 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
jef 2009-07-23 22:15:46 +00:00
parent a4c7bb7e3b
commit fe1e324360
5 changed files with 95 additions and 52 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 B

View File

@ -239,6 +239,7 @@ void QgsComposer::setupTheme()
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_mActionRefreshView_triggered()
}
}
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,19 +490,12 @@ void QgsComposer::on_mActionPrint_triggered()
}
//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 );
QgsComposition::PlotStyle savedPlotStyle = mComposition->plotStyle();
@ -505,7 +534,6 @@ void QgsComposer::on_mActionPrint_triggered()
}
mComposition->setPlotStyle( savedPlotStyle );
QApplication::restoreOverrideCursor();
}
}
void QgsComposer::on_mActionExportAsImage_triggered()

View File

@ -119,6 +119,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Print as SVG
void on_mActionExportAsSVG_triggered();
//! Print as PDF
void on_mActionExportAsPDF_triggered();
//! Select item
void on_mActionSelectMoveItem_triggered();
@ -243,6 +246,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! 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

View File

@ -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>