Skip to content

Commit

Permalink
Merge pull request #288 from Oslandia/atlas
Browse files Browse the repository at this point in the history
Clean up atlas pdf generation code and fix a bug on windows
  • Loading branch information
mhugent committed Oct 12, 2012
2 parents f230f51 + 12ddac6 commit 160b58f
Showing 1 changed file with 29 additions and 32 deletions.
61 changes: 29 additions & 32 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -643,31 +643,28 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
myQSettings.setValue( "/UI/lastSaveAtlasAsPdfDir", outputDir );
}

size_t featureI = 0;
QPrinter printer;
mView->setPaintingEnabled( false );

if ( hasAnAtlas )
{
QPrinter printer;

QPainter painter;

atlasMap->beginRender();
if ( atlasOnASingleFile )
{
mComposition->beginPrintAsPDF( printer, outputFileName );
painter.begin( &printer );
}
}
QPainter painter( &printer );

QProgressDialog progress( tr("Rendering maps..."), tr("Abort"), 0, atlasMap->numFeatures(), this );
QApplication::setOverrideCursor( Qt::BusyCursor );
mView->setPaintingEnabled( false );
QProgressDialog progress( tr("Rendering maps..."), tr("Abort"), 0, atlasMap->numFeatures(), this );
QApplication::setOverrideCursor( Qt::BusyCursor );

do
{
if ( hasAnAtlas )
for ( size_t featureI = 0; featureI < atlasMap->numFeatures(); ++featureI )
{
if ( 0 == atlasMap->numFeatures() )
break;

progress.setValue( featureI );
// process input events in order to allow aborting
// process input events in order to allow aborting
QCoreApplication::processEvents();
if ( progress.wasCanceled() )
{
Expand All @@ -689,30 +686,30 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
if ( !atlasOnASingleFile )
{
outputFileName = QDir(outputDir).filePath( atlasMap->currentFilename() ) + ".pdf";
mComposition->beginPrintAsPDF( printer, outputFileName );
painter.begin( &printer );
mComposition->doPrint( printer, painter );
painter.end();
}
}

if ( !atlasOnASingleFile )
{
mComposition->exportAsPDF( outputFileName );
}
else
{
if ( featureI > 0 )
else
{
printer.newPage();
if ( featureI > 0 )
{
printer.newPage();
}
mComposition->doPrint( printer, painter );
}
mComposition->doPrint( printer, painter );
}

featureI++;
} while ( hasAnAtlas && featureI < atlasMap->numFeatures() );

if ( hasAnAtlas )
{
atlasMap->endRender();
if ( atlasOnASingleFile )
{
painter.end();
}
}
else
{
mComposition->exportAsPDF( outputFileName );
}
painter.end();

mView->setPaintingEnabled( true );
QApplication::restoreOverrideCursor();
Expand Down

0 comments on commit 160b58f

Please sign in to comment.