Skip to content

Commit

Permalink
improve extent and scale/dpi relation in save as image/PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 21, 2017
1 parent 78ee9f7 commit 0cba29c
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/app/qgsmapsavedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ QgsMapSaveDialog::QgsMapSaveDialog( QWidget *parent, QgsMapCanvas *mapCanvas, QL
mDpi = ms.outputDpi();
mSize = ms.outputSize();

mResolutionSpinBox->setValue( qt_defaultDpiX() );
mResolutionSpinBox->setValue( mDpi );

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

void QgsMapSaveDialog::updateExtent( const QgsRectangle &extent )
{
mSize.setWidth( mSize.width() * extent.width() / mExtent.width() );
mSize.setHeight( mSize.height() * extent.height() / mExtent.height() );
mExtent = extent;
int currentDpi = 0;

// reset scale to properly sync output width and height when extent set using
// current map view, layer extent, or drawn on canvas buttons
if ( mExtentGroupBox->extentState() != QgsExtentGroupBox::UserExtent )
{
currentDpi = mDpi;

QgsMapSettings ms = mMapCanvas->mapSettings();
ms.setRotation( 0 );
mDpi = ms.outputDpi();
mSize.setWidth( ms.outputSize().width() * extent.width() / ms.visibleExtent().width() );
mSize.setHeight( ms.outputSize().height() * extent.height() / ms.visibleExtent().height() );

whileBlocking( mScaleWidget )->setScale( ms.scale() );

if ( currentDpi != mDpi )
{
updateDpi( currentDpi );
}
}
else
{
mSize.setWidth( mSize.width() * extent.width() / mExtent.width() );
mSize.setHeight( mSize.height() * extent.height() / mExtent.height() );
}
updateOutputSize();

mExtent = extent;
if ( mLockAspectRatio->locked() )
{
mExtentGroupBox->setRatio( QSize( mSize.width(), mSize.height() ) );
}

updateOutputSize();
}

void QgsMapSaveDialog::updateScale( double scale )
Expand Down

0 comments on commit 0cba29c

Please sign in to comment.