Skip to content
Permalink
Browse files
[FEATURE] customizable output width and height in save as image dialog
  • Loading branch information
nirvn committed May 2, 2017
1 parent 1711a41 commit fa7a3e7aff07b03d2ac2a0e48af974c7661cabf5
Showing with 85 additions and 9 deletions.
  1. +1 −1 src/app/qgisapp.cpp
  2. +30 −1 src/app/qgsmapsavedialog.cpp
  3. +2 −0 src/app/qgsmapsavedialog.h
  4. +52 −7 src/ui/qgsmapsavedialog.ui
@@ -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 )
{
@@ -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 );

@@ -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() );
@@ -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
@@ -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();
@@ -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>
@@ -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>
@@ -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>
@@ -61,6 +103,9 @@
<property name="prefix">
<string/>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>3000</number>
</property>

0 comments on commit fa7a3e7

Please sign in to comment.