Skip to content
Permalink
Browse files

[FEATURE] Add seperate controls for printing/exporting whole of atlas…

… composition. Allows single features from an atlas to be printed/exported.
  • Loading branch information
nyalldawson committed Jan 1, 2014
1 parent 5cc408c commit 5a91aa77d3e3004a7b5f0aa60d5087bb38c7c157
Showing with 197 additions and 13 deletions.
  1. +129 −13 src/app/composer/qgscomposer.cpp
  2. +31 −0 src/app/composer/qgscomposer.h
  3. +37 −0 src/ui/qgscomposerbase.ui
@@ -315,6 +315,21 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
atlasMenu->addAction( mActionAtlasPrev );
atlasMenu->addAction( mActionAtlasNext );
atlasMenu->addAction( mActionAtlasLast );
atlasMenu->addSeparator();
atlasMenu->addAction( mActionPrintAtlas );
atlasMenu->addAction( mActionExportAtlasAsImage );
atlasMenu->addAction( mActionExportAtlasAsSVG );
atlasMenu->addAction( mActionExportAtlasAsPDF );

QToolButton* atlasExportToolButton = new QToolButton( mAtlasToolbar );
atlasExportToolButton->setPopupMode( QToolButton::InstantPopup );
atlasExportToolButton->setAutoRaise( true );
atlasExportToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
atlasExportToolButton->addAction( mActionExportAtlasAsImage );
atlasExportToolButton->addAction( mActionExportAtlasAsSVG );
atlasExportToolButton->addAction( mActionExportAtlasAsPDF );
atlasExportToolButton->setDefaultAction( mActionExportAtlasAsImage );
mAtlasToolbar->addWidget( atlasExportToolButton );

QMenu *settingsMenu = menuBar()->addMenu( tr( "Settings" ) );
settingsMenu->addAction( mActionOptions );
@@ -486,6 +501,10 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mActionAtlasLast->setEnabled( false );
mActionAtlasNext->setEnabled( false );
mActionAtlasPrev->setEnabled( false );
mActionPrintAtlas->setEnabled( false );
mActionExportAtlasAsImage->setEnabled( false );
mActionExportAtlasAsSVG->setEnabled( false );
mActionExportAtlasAsPDF->setEnabled( false );

// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
//should not be needed now that composer has a status bar?
@@ -787,6 +806,10 @@ void QgsComposer::toggleAtlasControls( bool atlasEnabled )
//preview defaults to unchecked
mActionAtlasPreview->setChecked( false );
mActionAtlasPreview->setEnabled( atlasEnabled );
mActionPrintAtlas->setEnabled( atlasEnabled );
mActionExportAtlasAsImage->setEnabled( atlasEnabled );
mActionExportAtlasAsSVG->setEnabled( atlasEnabled );
mActionExportAtlasAsPDF->setEnabled( atlasEnabled );
}

void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
@@ -1036,7 +1059,24 @@ void QgsComposer::toggleRulers( bool checked )
myQSettings.setValue( "/Composer/showRulers", checked );
}

void QgsComposer::on_mActionExportAtlasAsPDF_triggered()
{
exportCompositionAsPDF( QgsComposer::Atlas );

if ( mComposition->atlasPreviewEnabled() )
{
//after atlas output, jump back to preview first feature
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
atlasMap->firstFeature();
}
}

void QgsComposer::on_mActionExportAsPDF_triggered()
{
exportCompositionAsPDF( QgsComposer::Single );
}

void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
{
if ( !mComposition || !mView )
{
@@ -1072,16 +1112,25 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
QString outputFileName;
QString outputDir;

if ( !hasAnAtlas || atlasOnASingleFile )
if ( mode == QgsComposer::Single || ( mode == QgsComposer::Atlas && atlasOnASingleFile ) )
{
QSettings myQSettings; // where we keep last used filter in persistent state
QString lastUsedFile = myQSettings.value( "/UI/lastSaveAsPdfFile", "qgis.pdf" ).toString();
QFileInfo file( lastUsedFile );

if ( hasAnAtlas && !atlasOnASingleFile && ( mode == QgsComposer::Atlas || mComposition->atlasPreviewEnabled() ) )
{
outputFileName = QDir( file.path() ).filePath( atlasMap->currentFilename() ) + ".pdf";
}
else
{
outputFileName = file.path();
}

outputFileName = QFileDialog::getSaveFileName(
this,
tr( "Choose a file name to save the map as" ),
file.path(),
outputFileName,
tr( "PDF Format" ) + " (*.pdf *.PDF)" );
if ( outputFileName.isEmpty() )
{
@@ -1136,7 +1185,7 @@ void QgsComposer::on_mActionExportAsPDF_triggered()

mView->setPaintingEnabled( false );

if ( hasAnAtlas )
if ( mode == QgsComposer::Atlas )
{
QPrinter printer;

@@ -1233,6 +1282,18 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
}

void QgsComposer::on_mActionPrint_triggered()
{
//print only current feature
printComposition( QgsComposer::Single );
}

void QgsComposer::on_mActionPrintAtlas_triggered()
{
//print whole atlas
printComposition( QgsComposer::Atlas );
}

void QgsComposer::printComposition( QgsComposer::OutputMode mode )
{
if ( !mComposition || !mView )
{
@@ -1272,7 +1333,7 @@ void QgsComposer::on_mActionPrint_triggered()
mView->setPaintingEnabled( false );

QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap->enabled() )
if ( mode == QgsComposer::Single )
{
mComposition->print( mPrinter );
}
@@ -1341,7 +1402,24 @@ void QgsComposer::on_mActionPrint_triggered()
QApplication::restoreOverrideCursor();
}

void QgsComposer::on_mActionExportAtlasAsImage_triggered()
{
exportCompositionAsImage( QgsComposer::Atlas );

if ( mComposition->atlasPreviewEnabled() )
{
//after atlas output, jump back to preview first feature
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
atlasMap->firstFeature();
}
}

void QgsComposer::on_mActionExportAsImage_triggered()
{
exportCompositionAsImage( QgsComposer::Single );
}

void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
{
if ( !mComposition || !mView )
{
@@ -1353,6 +1431,8 @@ void QgsComposer::on_mActionExportAsImage_triggered()
showWMSPrintingWarning();
}

QSettings settings;

// Image size
int width = ( int )( mComposition->printResolution() * mComposition->paperWidth() / 25.4 );
int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
@@ -1375,9 +1455,17 @@ void QgsComposer::on_mActionExportAsImage_triggered()
}

QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap->enabled() )
if ( mode == QgsComposer::Single )
{
QPair<QString, QString> fileNExt = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) );
QString outputFileName = QString::null;

if ( atlasMap->enabled() && mComposition->atlasPreviewEnabled() )
{
QString lastUsedDir = settings.value( "/UI/lastSaveAsImageDir", "." ).toString();
outputFileName = QDir( lastUsedDir ).filePath( atlasMap->currentFilename() );
}

QPair<QString, QString> fileNExt = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ), outputFileName );

if ( fileNExt.first.isEmpty() )
{
@@ -1591,8 +1679,24 @@ void QgsComposer::on_mActionExportAsImage_triggered()
}
}

void QgsComposer::on_mActionExportAtlasAsSVG_triggered()
{
exportCompositionAsSVG( QgsComposer::Atlas );

if ( mComposition->atlasPreviewEnabled() )
{
//after atlas output, jump back to preview first feature
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
atlasMap->firstFeature();
}
}

void QgsComposer::on_mActionExportAsSVG_triggered()
{
exportCompositionAsSVG( QgsComposer::Single );
}

void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
{
if ( containsWMSLayer() )
{
@@ -1626,20 +1730,28 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
}

QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
bool hasAnAtlas = atlasMap->enabled();

QString outputFileName;
QString outputDir;

if ( !hasAnAtlas )
if ( mode == QgsComposer::Single )
{
QString lastUsedFile = settings.value( "/UI/lastSaveAsSvgFile", "qgis.svg" ).toString();
QFileInfo file( lastUsedFile );

if ( atlasMap->enabled() )
{
outputFileName = QDir( file.path() ).filePath( atlasMap->currentFilename() ) + ".svg";
}
else
{
outputFileName = file.path();
}

outputFileName = QFileDialog::getSaveFileName(
this,
tr( "Choose a file name to save the map as" ),
file.path(),
outputFileName,
tr( "SVG Format" ) + " (*.svg *.SVG)" );
if ( outputFileName.isEmpty() )
return;
@@ -1694,7 +1806,7 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
mView->setPaintingEnabled( false );

int featureI = 0;
if ( hasAnAtlas )
if ( mode == QgsComposer::Atlas )
{
try
{
@@ -1714,7 +1826,7 @@ void QgsComposer::on_mActionExportAsSVG_triggered()

do
{
if ( hasAnAtlas )
if ( mode == QgsComposer::Atlas )
{
if ( atlasMap->numFeatures() == 0 )
break;
@@ -1772,9 +1884,9 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
}
featureI++;
}
while ( hasAnAtlas && featureI < atlasMap->numFeatures() );
while ( mode == QgsComposer::Atlas && featureI < atlasMap->numFeatures() );

if ( hasAnAtlas )
if ( mode == QgsComposer::Atlas )
atlasMap->endRender();

mView->setPaintingEnabled( true );
@@ -2497,6 +2609,10 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
mActionAtlasLast->setEnabled( false );
mActionAtlasNext->setEnabled( false );
mActionAtlasPrev->setEnabled( false );
mActionPrintAtlas->setEnabled( atlasMap->enabled() );
mActionExportAtlasAsImage->setEnabled( atlasMap->enabled() );
mActionExportAtlasAsSVG->setEnabled( atlasMap->enabled() );
mActionExportAtlasAsPDF->setEnabled( atlasMap->enabled() );
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );

setSelectionTool();
@@ -56,6 +56,13 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
Q_OBJECT

public:

enum OutputMode
{
Single = 0,
Atlas
};

QgsComposer( QgisApp *qgis, const QString& title );
~QgsComposer();

@@ -330,6 +337,18 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Last atlas feature
void on_mActionAtlasLast_triggered();

//! Print the atlas
void on_mActionPrintAtlas_triggered();

//! Print atlas as image
void on_mActionExportAtlasAsImage_triggered();

//! Print atlas as SVG
void on_mActionExportAtlasAsSVG_triggered();

//! Print atlas as PDF
void on_mActionExportAtlasAsPDF_triggered();

//! Save window state
void saveWindowState();

@@ -438,6 +457,18 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Updates the grid/guide action status based on compositions grid/guide settings
void restoreGridSettings();

//! Prints either the whole atlas or just the current feature, depending on mode
void printComposition( QgsComposer::OutputMode mode );

//! Exports either either the whole atlas or just the current feature as an image, depending on mode
void exportCompositionAsImage( QgsComposer::OutputMode mode );

//! Exports either either the whole atlas or just the current feature as an SVG, depending on mode
void exportCompositionAsSVG( QgsComposer::OutputMode mode );

//! Exports either either the whole atlas or just the current feature as a PDF, depending on mode
void exportCompositionAsPDF( QgsComposer::OutputMode mode );

/**Composer title*/
QString mTitle;

@@ -144,6 +144,7 @@
<addaction name="mActionAtlasPrev"/>
<addaction name="mActionAtlasNext"/>
<addaction name="mActionAtlasLast"/>
<addaction name="mActionPrintAtlas"/>
</widget>
<action name="mActionPrint">
<property name="checkable">
@@ -890,6 +891,42 @@
<string>Preview Atlas</string>
</property>
</action>
<action name="mActionPrintAtlas">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFilePrint.png</normaloff>:/images/themes/default/mActionFilePrint.png</iconset>
</property>
<property name="text">
<string>Print Atlas...</string>
</property>
</action>
<action name="mActionExportAtlasAsImage">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSaveMapAsImage.png</normaloff>:/images/themes/default/mActionSaveMapAsImage.png</iconset>
</property>
<property name="text">
<string>Export Atlas as Images...</string>
</property>
</action>
<action name="mActionExportAtlasAsSVG">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSaveAsSVG.png</normaloff>:/images/themes/default/mActionSaveAsSVG.png</iconset>
</property>
<property name="text">
<string>Export Atlas as SVG...</string>
</property>
</action>
<action name="mActionExportAtlasAsPDF">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSaveAsPDF.png</normaloff>:/images/themes/default/mActionSaveAsPDF.png</iconset>
</property>
<property name="text">
<string>Export Atlas As PDF...</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit 5a91aa7

Please sign in to comment.
You can’t perform that action at this time.