Skip to content

Commit

Permalink
show warning if width or height of exported image is larger than
Browse files Browse the repository at this point in the history
QPainter limit (refs qgis#41045)
  • Loading branch information
alexbruy committed Jan 29, 2024
1 parent 1fd3def commit 1f894bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/app/qgsmapsavedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void QgsMapSaveDialog::updateDpi( int dpi )
mDpi = dpi;

updateOutputSize();
checkOutputSize();
}

void QgsMapSaveDialog::updateOutputWidth( int width )
Expand All @@ -187,6 +188,8 @@ void QgsMapSaveDialog::updateOutputWidth( int width )
}

whileBlocking( mExtentGroupBox )->setOutputExtentFromUser( mExtent, mExtentGroupBox->currentCrs() );

checkOutputSize();
}

void QgsMapSaveDialog::updateOutputHeight( int height )
Expand All @@ -213,6 +216,8 @@ void QgsMapSaveDialog::updateOutputHeight( int height )
}

whileBlocking( mExtentGroupBox )->setOutputExtentFromUser( mExtent, mExtentGroupBox->currentCrs() );

checkOutputSize();
}

void QgsMapSaveDialog::updateExtent( const QgsRectangle &extent )
Expand Down Expand Up @@ -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() )
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmapsavedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
16 changes: 16 additions & 0 deletions src/ui/qgsmapsavedialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
<string>Save Map as Image</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QgsMessageBar" name="mMessageBar">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0,0,0,0,0">
<item row="2" column="0">
Expand Down Expand Up @@ -401,6 +411,12 @@ Rasterizing the map is recommended when such effects are used.</string>
<header location="global">qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsMessageBar</class>
<extends>QFrame</extends>
<header>qgsmessagebar.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mExtentGroupBox</tabstop>
Expand Down

0 comments on commit 1f894bd

Please sign in to comment.