From 1f894bd5ba4bedd8a5afb83a2d93a0ecc81afa5a Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 25 Jan 2024 19:40:33 +0200 Subject: [PATCH] show warning if width or height of exported image is larger than QPainter limit (refs #41045) --- src/app/qgsmapsavedialog.cpp | 15 +++++++++++++++ src/app/qgsmapsavedialog.h | 1 + src/ui/qgsmapsavedialog.ui | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/app/qgsmapsavedialog.cpp b/src/app/qgsmapsavedialog.cpp index e1994e8f2b4e..19b2761b5834 100644 --- a/src/app/qgsmapsavedialog.cpp +++ b/src/app/qgsmapsavedialog.cpp @@ -161,6 +161,7 @@ void QgsMapSaveDialog::updateDpi( int dpi ) mDpi = dpi; updateOutputSize(); + checkOutputSize(); } void QgsMapSaveDialog::updateOutputWidth( int width ) @@ -187,6 +188,8 @@ void QgsMapSaveDialog::updateOutputWidth( int width ) } whileBlocking( mExtentGroupBox )->setOutputExtentFromUser( mExtent, mExtentGroupBox->currentCrs() ); + + checkOutputSize(); } void QgsMapSaveDialog::updateOutputHeight( int height ) @@ -213,6 +216,8 @@ void QgsMapSaveDialog::updateOutputHeight( int height ) } whileBlocking( mExtentGroupBox )->setOutputExtentFromUser( mExtent, mExtentGroupBox->currentCrs() ); + + checkOutputSize(); } void QgsMapSaveDialog::updateExtent( const QgsRectangle &extent ) @@ -244,6 +249,7 @@ void QgsMapSaveDialog::updateExtent( const QgsRectangle &extent ) mSize.setHeight( mSize.height() * extent.height() / mExtent.height() ); } updateOutputSize(); + checkOutputSize(); mExtent = extent; if ( mLockAspectRatio->locked() ) @@ -270,6 +276,15 @@ void QgsMapSaveDialog::updateOutputSize() whileBlocking( mOutputHeightSpinBox )->setValue( mSize.height() ); } +void QgsMapSaveDialog::checkOutputSize() +{ + // check if image size does not exceed QPainter limitation https://doc.qt.io/qt-5/qpainter.html#limitations + if ( mSize.width() > 32768 || mSize.height() > 32768 ) + { + mMessageBar->pushWarning( tr( "Save as image" ), tr( "Image width or height is larger than 32768 pixels. Output raster will be truncated." ) ); + } +} + QgsRectangle QgsMapSaveDialog::extent() const { return mExtentGroupBox->outputExtent(); diff --git a/src/app/qgsmapsavedialog.h b/src/app/qgsmapsavedialog.h index 8e59ff7d726d..b61ab20dc98f 100644 --- a/src/app/qgsmapsavedialog.h +++ b/src/app/qgsmapsavedialog.h @@ -92,6 +92,7 @@ class APP_EXPORT QgsMapSaveDialog: public QDialog, private Ui::QgsMapSaveDialog void lockChanged( bool locked ); void copyToClipboard(); + void checkOutputSize(); void updateDpi( int dpi ); void updateOutputWidth( int width ); diff --git a/src/ui/qgsmapsavedialog.ui b/src/ui/qgsmapsavedialog.ui index 4f5fb1e41205..26e9446e2ccc 100644 --- a/src/ui/qgsmapsavedialog.ui +++ b/src/ui/qgsmapsavedialog.ui @@ -14,6 +14,16 @@ Save Map as Image + + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -401,6 +411,12 @@ Rasterizing the map is recommended when such effects are used.
qgscollapsiblegroupbox.h
1 + + QgsMessageBar + QFrame +
qgsmessagebar.h
+ 1 +
mExtentGroupBox