Skip to content

Commit 5a91aa7

Browse files
committedJan 1, 2014
[FEATURE] Add seperate controls for printing/exporting whole of atlas composition. Allows single features from an atlas to be printed/exported.
1 parent 5cc408c commit 5a91aa7

File tree

3 files changed

+197
-13
lines changed

3 files changed

+197
-13
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 129 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
315315
atlasMenu->addAction( mActionAtlasPrev );
316316
atlasMenu->addAction( mActionAtlasNext );
317317
atlasMenu->addAction( mActionAtlasLast );
318+
atlasMenu->addSeparator();
319+
atlasMenu->addAction( mActionPrintAtlas );
320+
atlasMenu->addAction( mActionExportAtlasAsImage );
321+
atlasMenu->addAction( mActionExportAtlasAsSVG );
322+
atlasMenu->addAction( mActionExportAtlasAsPDF );
323+
324+
QToolButton* atlasExportToolButton = new QToolButton( mAtlasToolbar );
325+
atlasExportToolButton->setPopupMode( QToolButton::InstantPopup );
326+
atlasExportToolButton->setAutoRaise( true );
327+
atlasExportToolButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
328+
atlasExportToolButton->addAction( mActionExportAtlasAsImage );
329+
atlasExportToolButton->addAction( mActionExportAtlasAsSVG );
330+
atlasExportToolButton->addAction( mActionExportAtlasAsPDF );
331+
atlasExportToolButton->setDefaultAction( mActionExportAtlasAsImage );
332+
mAtlasToolbar->addWidget( atlasExportToolButton );
318333

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

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

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

1062+
void QgsComposer::on_mActionExportAtlasAsPDF_triggered()
1063+
{
1064+
exportCompositionAsPDF( QgsComposer::Atlas );
1065+
1066+
if ( mComposition->atlasPreviewEnabled() )
1067+
{
1068+
//after atlas output, jump back to preview first feature
1069+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
1070+
atlasMap->firstFeature();
1071+
}
1072+
}
1073+
10391074
void QgsComposer::on_mActionExportAsPDF_triggered()
1075+
{
1076+
exportCompositionAsPDF( QgsComposer::Single );
1077+
}
1078+
1079+
void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
10401080
{
10411081
if ( !mComposition || !mView )
10421082
{
@@ -1072,16 +1112,25 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
10721112
QString outputFileName;
10731113
QString outputDir;
10741114

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

1121+
if ( hasAnAtlas && !atlasOnASingleFile && ( mode == QgsComposer::Atlas || mComposition->atlasPreviewEnabled() ) )
1122+
{
1123+
outputFileName = QDir( file.path() ).filePath( atlasMap->currentFilename() ) + ".pdf";
1124+
}
1125+
else
1126+
{
1127+
outputFileName = file.path();
1128+
}
1129+
10811130
outputFileName = QFileDialog::getSaveFileName(
10821131
this,
10831132
tr( "Choose a file name to save the map as" ),
1084-
file.path(),
1133+
outputFileName,
10851134
tr( "PDF Format" ) + " (*.pdf *.PDF)" );
10861135
if ( outputFileName.isEmpty() )
10871136
{
@@ -1136,7 +1185,7 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
11361185

11371186
mView->setPaintingEnabled( false );
11381187

1139-
if ( hasAnAtlas )
1188+
if ( mode == QgsComposer::Atlas )
11401189
{
11411190
QPrinter printer;
11421191

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

12351284
void QgsComposer::on_mActionPrint_triggered()
1285+
{
1286+
//print only current feature
1287+
printComposition( QgsComposer::Single );
1288+
}
1289+
1290+
void QgsComposer::on_mActionPrintAtlas_triggered()
1291+
{
1292+
//print whole atlas
1293+
printComposition( QgsComposer::Atlas );
1294+
}
1295+
1296+
void QgsComposer::printComposition( QgsComposer::OutputMode mode )
12361297
{
12371298
if ( !mComposition || !mView )
12381299
{
@@ -1272,7 +1333,7 @@ void QgsComposer::on_mActionPrint_triggered()
12721333
mView->setPaintingEnabled( false );
12731334

12741335
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
1275-
if ( !atlasMap->enabled() )
1336+
if ( mode == QgsComposer::Single )
12761337
{
12771338
mComposition->print( mPrinter );
12781339
}
@@ -1341,7 +1402,24 @@ void QgsComposer::on_mActionPrint_triggered()
13411402
QApplication::restoreOverrideCursor();
13421403
}
13431404

1405+
void QgsComposer::on_mActionExportAtlasAsImage_triggered()
1406+
{
1407+
exportCompositionAsImage( QgsComposer::Atlas );
1408+
1409+
if ( mComposition->atlasPreviewEnabled() )
1410+
{
1411+
//after atlas output, jump back to preview first feature
1412+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
1413+
atlasMap->firstFeature();
1414+
}
1415+
}
1416+
13441417
void QgsComposer::on_mActionExportAsImage_triggered()
1418+
{
1419+
exportCompositionAsImage( QgsComposer::Single );
1420+
}
1421+
1422+
void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
13451423
{
13461424
if ( !mComposition || !mView )
13471425
{
@@ -1353,6 +1431,8 @@ void QgsComposer::on_mActionExportAsImage_triggered()
13531431
showWMSPrintingWarning();
13541432
}
13551433

1434+
QSettings settings;
1435+
13561436
// Image size
13571437
int width = ( int )( mComposition->printResolution() * mComposition->paperWidth() / 25.4 );
13581438
int height = ( int )( mComposition-> printResolution() * mComposition->paperHeight() / 25.4 );
@@ -1375,9 +1455,17 @@ void QgsComposer::on_mActionExportAsImage_triggered()
13751455
}
13761456

13771457
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
1378-
if ( !atlasMap->enabled() )
1458+
if ( mode == QgsComposer::Single )
13791459
{
1380-
QPair<QString, QString> fileNExt = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) );
1460+
QString outputFileName = QString::null;
1461+
1462+
if ( atlasMap->enabled() && mComposition->atlasPreviewEnabled() )
1463+
{
1464+
QString lastUsedDir = settings.value( "/UI/lastSaveAsImageDir", "." ).toString();
1465+
outputFileName = QDir( lastUsedDir ).filePath( atlasMap->currentFilename() );
1466+
}
1467+
1468+
QPair<QString, QString> fileNExt = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ), outputFileName );
13811469

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

1682+
void QgsComposer::on_mActionExportAtlasAsSVG_triggered()
1683+
{
1684+
exportCompositionAsSVG( QgsComposer::Atlas );
1685+
1686+
if ( mComposition->atlasPreviewEnabled() )
1687+
{
1688+
//after atlas output, jump back to preview first feature
1689+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
1690+
atlasMap->firstFeature();
1691+
}
1692+
}
15941693

15951694
void QgsComposer::on_mActionExportAsSVG_triggered()
1695+
{
1696+
exportCompositionAsSVG( QgsComposer::Single );
1697+
}
1698+
1699+
void QgsComposer::exportCompositionAsSVG( QgsComposer::OutputMode mode )
15961700
{
15971701
if ( containsWMSLayer() )
15981702
{
@@ -1626,20 +1730,28 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
16261730
}
16271731

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

16311734
QString outputFileName;
16321735
QString outputDir;
16331736

1634-
if ( !hasAnAtlas )
1737+
if ( mode == QgsComposer::Single )
16351738
{
16361739
QString lastUsedFile = settings.value( "/UI/lastSaveAsSvgFile", "qgis.svg" ).toString();
16371740
QFileInfo file( lastUsedFile );
16381741

1742+
if ( atlasMap->enabled() )
1743+
{
1744+
outputFileName = QDir( file.path() ).filePath( atlasMap->currentFilename() ) + ".svg";
1745+
}
1746+
else
1747+
{
1748+
outputFileName = file.path();
1749+
}
1750+
16391751
outputFileName = QFileDialog::getSaveFileName(
16401752
this,
16411753
tr( "Choose a file name to save the map as" ),
1642-
file.path(),
1754+
outputFileName,
16431755
tr( "SVG Format" ) + " (*.svg *.SVG)" );
16441756
if ( outputFileName.isEmpty() )
16451757
return;
@@ -1694,7 +1806,7 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
16941806
mView->setPaintingEnabled( false );
16951807

16961808
int featureI = 0;
1697-
if ( hasAnAtlas )
1809+
if ( mode == QgsComposer::Atlas )
16981810
{
16991811
try
17001812
{
@@ -1714,7 +1826,7 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
17141826

17151827
do
17161828
{
1717-
if ( hasAnAtlas )
1829+
if ( mode == QgsComposer::Atlas )
17181830
{
17191831
if ( atlasMap->numFeatures() == 0 )
17201832
break;
@@ -1772,9 +1884,9 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
17721884
}
17731885
featureI++;
17741886
}
1775-
while ( hasAnAtlas && featureI < atlasMap->numFeatures() );
1887+
while ( mode == QgsComposer::Atlas && featureI < atlasMap->numFeatures() );
17761888

1777-
if ( hasAnAtlas )
1889+
if ( mode == QgsComposer::Atlas )
17781890
atlasMap->endRender();
17791891

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

25022618
setSelectionTool();

‎src/app/composer/qgscomposer.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
5656
Q_OBJECT
5757

5858
public:
59+
60+
enum OutputMode
61+
{
62+
Single = 0,
63+
Atlas
64+
};
65+
5966
QgsComposer( QgisApp *qgis, const QString& title );
6067
~QgsComposer();
6168

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

340+
//! Print the atlas
341+
void on_mActionPrintAtlas_triggered();
342+
343+
//! Print atlas as image
344+
void on_mActionExportAtlasAsImage_triggered();
345+
346+
//! Print atlas as SVG
347+
void on_mActionExportAtlasAsSVG_triggered();
348+
349+
//! Print atlas as PDF
350+
void on_mActionExportAtlasAsPDF_triggered();
351+
333352
//! Save window state
334353
void saveWindowState();
335354

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

460+
//! Prints either the whole atlas or just the current feature, depending on mode
461+
void printComposition( QgsComposer::OutputMode mode );
462+
463+
//! Exports either either the whole atlas or just the current feature as an image, depending on mode
464+
void exportCompositionAsImage( QgsComposer::OutputMode mode );
465+
466+
//! Exports either either the whole atlas or just the current feature as an SVG, depending on mode
467+
void exportCompositionAsSVG( QgsComposer::OutputMode mode );
468+
469+
//! Exports either either the whole atlas or just the current feature as a PDF, depending on mode
470+
void exportCompositionAsPDF( QgsComposer::OutputMode mode );
471+
441472
/**Composer title*/
442473
QString mTitle;
443474

‎src/ui/qgscomposerbase.ui

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<addaction name="mActionAtlasPrev"/>
145145
<addaction name="mActionAtlasNext"/>
146146
<addaction name="mActionAtlasLast"/>
147+
<addaction name="mActionPrintAtlas"/>
147148
</widget>
148149
<action name="mActionPrint">
149150
<property name="checkable">
@@ -890,6 +891,42 @@
890891
<string>Preview Atlas</string>
891892
</property>
892893
</action>
894+
<action name="mActionPrintAtlas">
895+
<property name="icon">
896+
<iconset resource="../../images/images.qrc">
897+
<normaloff>:/images/themes/default/mActionFilePrint.png</normaloff>:/images/themes/default/mActionFilePrint.png</iconset>
898+
</property>
899+
<property name="text">
900+
<string>Print Atlas...</string>
901+
</property>
902+
</action>
903+
<action name="mActionExportAtlasAsImage">
904+
<property name="icon">
905+
<iconset resource="../../images/images.qrc">
906+
<normaloff>:/images/themes/default/mActionSaveMapAsImage.png</normaloff>:/images/themes/default/mActionSaveMapAsImage.png</iconset>
907+
</property>
908+
<property name="text">
909+
<string>Export Atlas as Images...</string>
910+
</property>
911+
</action>
912+
<action name="mActionExportAtlasAsSVG">
913+
<property name="icon">
914+
<iconset resource="../../images/images.qrc">
915+
<normaloff>:/images/themes/default/mActionSaveAsSVG.png</normaloff>:/images/themes/default/mActionSaveAsSVG.png</iconset>
916+
</property>
917+
<property name="text">
918+
<string>Export Atlas as SVG...</string>
919+
</property>
920+
</action>
921+
<action name="mActionExportAtlasAsPDF">
922+
<property name="icon">
923+
<iconset resource="../../images/images.qrc">
924+
<normaloff>:/images/themes/default/mActionSaveAsPDF.png</normaloff>:/images/themes/default/mActionSaveAsPDF.png</iconset>
925+
</property>
926+
<property name="text">
927+
<string>Export Atlas As PDF...</string>
928+
</property>
929+
</action>
893930
</widget>
894931
<resources>
895932
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)
Please sign in to comment.