Skip to content

Commit

Permalink
[layouts] Don't refresh the map canvas multiple times during atlas ex…
Browse files Browse the repository at this point in the history
…ports

Fixes #30144
  • Loading branch information
nyalldawson committed May 26, 2020
1 parent 38673f5 commit 57519e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -259,6 +259,30 @@ static bool cmpByText_( QAction *a, QAction *b )
}


class QgsAtlasExportGuard
{
public:

QgsAtlasExportGuard( QgsLayoutDesignerDialog *dialog )
: mDialog( dialog )
{
mDialog->mIsExportingAtlas = true;
}

~QgsAtlasExportGuard()
{
mDialog->mIsExportingAtlas = false;

// need to update the GUI to reflect the final atlas feature
mDialog->atlasFeatureChanged( mDialog->currentLayout()->reportContext().feature() );
}

private:
QgsLayoutDesignerDialog *mDialog = nullptr;

};


QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
, mInterface( new QgsAppLayoutDesignerInterface( this ) )
Expand Down Expand Up @@ -2764,6 +2788,7 @@ void QgsLayoutDesignerDialog::exportAtlasToRaster()

mView->setPaintingEnabled( false );
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
QgsAtlasExportGuard exportingAtlas( this );

QString error;
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
Expand Down Expand Up @@ -2928,6 +2953,7 @@ void QgsLayoutDesignerDialog::exportAtlasToSvg()

mView->setPaintingEnabled( false );
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
QgsAtlasExportGuard exportingAtlas( this );

QString error;
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
Expand Down Expand Up @@ -3148,6 +3174,8 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()

mView->setPaintingEnabled( false );
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
QgsAtlasExportGuard exportingAtlas( this );

pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();

QString error;
Expand Down Expand Up @@ -3284,6 +3312,7 @@ void QgsLayoutDesignerDialog::exportReportToRaster()

mView->setPaintingEnabled( false );
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
QgsAtlasExportGuard exportingAtlas( this );

QString error;
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
Expand Down Expand Up @@ -3400,6 +3429,7 @@ void QgsLayoutDesignerDialog::exportReportToSvg()

mView->setPaintingEnabled( false );
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
QgsAtlasExportGuard exportingAtlas( this );

QString error;
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
Expand Down Expand Up @@ -3533,6 +3563,7 @@ void QgsLayoutDesignerDialog::exportReportToPdf()

mView->setPaintingEnabled( false );
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );
QgsAtlasExportGuard exportingAtlas( this );

pdfSettings.rasterizeWholeImage = rasterize;

Expand Down Expand Up @@ -4427,7 +4458,8 @@ void QgsLayoutDesignerDialog::updateAtlasPageComboBox( int pageCount )

void QgsLayoutDesignerDialog::atlasFeatureChanged( const QgsFeature &feature )
{
//TODO - this should be disabled during an export
if ( mIsExportingAtlas )
return;

QgsPrintLayout *printLayout = qobject_cast< QgsPrintLayout *>( mLayout );
if ( !printLayout )
Expand Down
4 changes: 4 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -488,6 +488,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB

QgsLayoutGuideWidget *mGuideWidget = nullptr;

bool mIsExportingAtlas = false;

//! Save window state
void saveWindowState();

Expand Down Expand Up @@ -559,6 +561,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB

//! update default action of toolbutton
void toolButtonActionTriggered( QAction * );

friend class QgsAtlasExportGuard;
};

#endif // QGSLAYOUTDESIGNERDIALOG_H
Expand Down

0 comments on commit 57519e9

Please sign in to comment.