Skip to content

Commit

Permalink
[FEATURE] customizable output width and height in save as image dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 2, 2017
1 parent 1711a41 commit fa7a3e7
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -5835,7 +5835,7 @@ void QgisApp::saveMapAsImage()

connect( mapRendererTask, &QgsMapRendererTask::renderingComplete, this, [ = ]
{
messageBar()->pushSuccess( tr( "Save as image" ), tr( "Successfully saved canvas to image" ) );
messageBar()->pushSuccess( tr( "Save as image" ), tr( "Successfully saved map to image" ) );
} );
connect( mapRendererTask, &QgsMapRendererTask::errorOccurred, this, [ = ]( int error )
{
Expand Down
31 changes: 30 additions & 1 deletion src/app/qgsmapsavedialog.cpp
Expand Up @@ -50,6 +50,8 @@ QgsMapSaveDialog::QgsMapSaveDialog( QWidget *parent, QgsMapCanvas *mapCanvas, co
mDrawDecorations->setText( tr( "Draw active decorations: %1" ).arg( !activeDecorations.isEmpty() ? activeDecorations : tr( "none" ) ) );

connect( mResolutionSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsMapSaveDialog::updateDpi );
connect( mOutputWidthSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsMapSaveDialog::updateOutputWidth );
connect( mOutputHeightSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsMapSaveDialog::updateOutputHeight );
connect( mExtentGroupBox, &QgsExtentGroupBox::extentChanged, this, &QgsMapSaveDialog::updateExtent );
connect( mScaleWidget, &QgsScaleWidget::scaleChanged, this, &QgsMapSaveDialog::updateScale );

Expand All @@ -64,6 +66,32 @@ void QgsMapSaveDialog::updateDpi( int dpi )
updateOutputSize();
}

void QgsMapSaveDialog::updateOutputWidth( int width )
{
double scale = ( double )width / mSize.width();
double adjustment = ( ( mExtent.width() * scale ) - mExtent.width() ) / 2;

mExtent.setXMinimum( mExtent.xMinimum() - adjustment );
mExtent.setXMaximum( mExtent.xMaximum() + adjustment );

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

mSize.setWidth( width );
}

void QgsMapSaveDialog::updateOutputHeight( int height )
{
double scale = ( double )height / mSize.height();
double adjustment = ( ( mExtent.height() * scale ) - mExtent.height() ) / 2;

mExtent.setYMinimum( mExtent.yMinimum() - adjustment );
mExtent.setYMaximum( mExtent.yMaximum() + adjustment );

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

mSize.setHeight( height );
}

void QgsMapSaveDialog::updateExtent( const QgsRectangle &extent )
{
mSize.setWidth( mSize.width() * extent.width() / mExtent.width() );
Expand All @@ -87,7 +115,8 @@ void QgsMapSaveDialog::updateScale( double scale )

void QgsMapSaveDialog::updateOutputSize()
{
mOutputSize->setText( tr( "Output size: %1 x %2 pixels" ).arg( mSize.width() ).arg( mSize.height() ) );
whileBlocking( mOutputWidthSpinBox )->setValue( mSize.width() );
whileBlocking( mOutputHeightSpinBox )->setValue( mSize.height() );
}

QgsRectangle QgsMapSaveDialog::extent() const
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsmapsavedialog.h
Expand Up @@ -59,6 +59,8 @@ class APP_EXPORT QgsMapSaveDialog: public QDialog, private Ui::QgsMapSaveDialog
private:

void updateDpi( int dpi );
void updateOutputWidth( int width );
void updateOutputHeight( int height );
void updateExtent( const QgsRectangle &extent );
void updateScale( double scale );
void updateOutputSize();
Expand Down
59 changes: 52 additions & 7 deletions src/ui/qgsmapsavedialog.ui
Expand Up @@ -16,7 +16,7 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="0" colspan="2">>
<item row="6" column="0" colspan="2">>
<widget class="QCheckBox" name="mDrawAnnotations">
<property name="text">
<string>Draw annotations</string>
Expand All @@ -26,7 +26,7 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="mDrawDecorations">
<property name="text">
<string>Draw active decorations</string>
Expand All @@ -36,13 +36,55 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="mOutputSize">
<property name="enabled">
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Output height</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QgsSpinBox" name="mOutputHeightSpinBox">
<property name="suffix">
<string> px</string>
</property>
<property name="prefix">
<string/>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>99999</number>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Output width</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsSpinBox" name="mOutputWidthSpinBox">
<property name="suffix">
<string> px</string>
</property>
<property name="prefix">
<string/>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>99999</number>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
Expand All @@ -61,6 +103,9 @@
<property name="prefix">
<string/>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>3000</number>
</property>
Expand Down

0 comments on commit fa7a3e7

Please sign in to comment.