Skip to content

Commit 0cba29c

Browse files
committedJul 21, 2017
improve extent and scale/dpi relation in save as image/PDF
1 parent 78ee9f7 commit 0cba29c

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed
 

‎src/app/qgsmapsavedialog.cpp‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ QgsMapSaveDialog::QgsMapSaveDialog( QWidget *parent, QgsMapCanvas *mapCanvas, QL
5454
mDpi = ms.outputDpi();
5555
mSize = ms.outputSize();
5656

57-
mResolutionSpinBox->setValue( qt_defaultDpiX() );
57+
mResolutionSpinBox->setValue( mDpi );
5858

5959
mExtentGroupBox->setOutputCrs( ms.destinationCrs() );
6060
mExtentGroupBox->setCurrentExtent( mExtent, ms.destinationCrs() );
@@ -176,16 +176,39 @@ void QgsMapSaveDialog::updateOutputHeight( int height )
176176

177177
void QgsMapSaveDialog::updateExtent( const QgsRectangle &extent )
178178
{
179-
mSize.setWidth( mSize.width() * extent.width() / mExtent.width() );
180-
mSize.setHeight( mSize.height() * extent.height() / mExtent.height() );
181-
mExtent = extent;
179+
int currentDpi = 0;
180+
181+
// reset scale to properly sync output width and height when extent set using
182+
// current map view, layer extent, or drawn on canvas buttons
183+
if ( mExtentGroupBox->extentState() != QgsExtentGroupBox::UserExtent )
184+
{
185+
currentDpi = mDpi;
186+
187+
QgsMapSettings ms = mMapCanvas->mapSettings();
188+
ms.setRotation( 0 );
189+
mDpi = ms.outputDpi();
190+
mSize.setWidth( ms.outputSize().width() * extent.width() / ms.visibleExtent().width() );
191+
mSize.setHeight( ms.outputSize().height() * extent.height() / ms.visibleExtent().height() );
192+
193+
whileBlocking( mScaleWidget )->setScale( ms.scale() );
194+
195+
if ( currentDpi != mDpi )
196+
{
197+
updateDpi( currentDpi );
198+
}
199+
}
200+
else
201+
{
202+
mSize.setWidth( mSize.width() * extent.width() / mExtent.width() );
203+
mSize.setHeight( mSize.height() * extent.height() / mExtent.height() );
204+
}
205+
updateOutputSize();
182206

207+
mExtent = extent;
183208
if ( mLockAspectRatio->locked() )
184209
{
185210
mExtentGroupBox->setRatio( QSize( mSize.width(), mSize.height() ) );
186211
}
187-
188-
updateOutputSize();
189212
}
190213

191214
void QgsMapSaveDialog::updateScale( double scale )

0 commit comments

Comments
 (0)
Please sign in to comment.