Skip to content

Commit 160b58f

Browse files
committed
Merge pull request #288 from Oslandia/atlas
Clean up atlas pdf generation code and fix a bug on windows
2 parents f230f51 + 12ddac6 commit 160b58f

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -643,31 +643,28 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
643643
myQSettings.setValue( "/UI/lastSaveAtlasAsPdfDir", outputDir );
644644
}
645645

646-
size_t featureI = 0;
647-
QPrinter printer;
646+
mView->setPaintingEnabled( false );
647+
648648
if ( hasAnAtlas )
649649
{
650+
QPrinter printer;
651+
652+
QPainter painter;
653+
650654
atlasMap->beginRender();
651655
if ( atlasOnASingleFile )
652656
{
653657
mComposition->beginPrintAsPDF( printer, outputFileName );
658+
painter.begin( &printer );
654659
}
655-
}
656-
QPainter painter( &printer );
657660

658-
QProgressDialog progress( tr("Rendering maps..."), tr("Abort"), 0, atlasMap->numFeatures(), this );
659-
QApplication::setOverrideCursor( Qt::BusyCursor );
660-
mView->setPaintingEnabled( false );
661+
QProgressDialog progress( tr("Rendering maps..."), tr("Abort"), 0, atlasMap->numFeatures(), this );
662+
QApplication::setOverrideCursor( Qt::BusyCursor );
661663

662-
do
663-
{
664-
if ( hasAnAtlas )
664+
for ( size_t featureI = 0; featureI < atlasMap->numFeatures(); ++featureI )
665665
{
666-
if ( 0 == atlasMap->numFeatures() )
667-
break;
668-
669666
progress.setValue( featureI );
670-
// process input events in order to allow aborting
667+
// process input events in order to allow aborting
671668
QCoreApplication::processEvents();
672669
if ( progress.wasCanceled() )
673670
{
@@ -689,30 +686,30 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
689686
if ( !atlasOnASingleFile )
690687
{
691688
outputFileName = QDir(outputDir).filePath( atlasMap->currentFilename() ) + ".pdf";
689+
mComposition->beginPrintAsPDF( printer, outputFileName );
690+
painter.begin( &printer );
691+
mComposition->doPrint( printer, painter );
692+
painter.end();
692693
}
693-
}
694-
695-
if ( !atlasOnASingleFile )
696-
{
697-
mComposition->exportAsPDF( outputFileName );
698-
}
699-
else
700-
{
701-
if ( featureI > 0 )
694+
else
702695
{
703-
printer.newPage();
696+
if ( featureI > 0 )
697+
{
698+
printer.newPage();
699+
}
700+
mComposition->doPrint( printer, painter );
704701
}
705-
mComposition->doPrint( printer, painter );
706702
}
707-
708-
featureI++;
709-
} while ( hasAnAtlas && featureI < atlasMap->numFeatures() );
710-
711-
if ( hasAnAtlas )
712-
{
713703
atlasMap->endRender();
704+
if ( atlasOnASingleFile )
705+
{
706+
painter.end();
707+
}
708+
}
709+
else
710+
{
711+
mComposition->exportAsPDF( outputFileName );
714712
}
715-
painter.end();
716713

717714
mView->setPaintingEnabled( true );
718715
QApplication::restoreOverrideCursor();

0 commit comments

Comments
 (0)