Skip to content

Commit fa7a3e7

Browse files
committedMay 2, 2017
[FEATURE] customizable output width and height in save as image dialog
1 parent 1711a41 commit fa7a3e7

File tree

4 files changed

+85
-9
lines changed

4 files changed

+85
-9
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5835,7 +5835,7 @@ void QgisApp::saveMapAsImage()
58355835

58365836
connect( mapRendererTask, &QgsMapRendererTask::renderingComplete, this, [ = ]
58375837
{
5838-
messageBar()->pushSuccess( tr( "Save as image" ), tr( "Successfully saved canvas to image" ) );
5838+
messageBar()->pushSuccess( tr( "Save as image" ), tr( "Successfully saved map to image" ) );
58395839
} );
58405840
connect( mapRendererTask, &QgsMapRendererTask::errorOccurred, this, [ = ]( int error )
58415841
{

‎src/app/qgsmapsavedialog.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ QgsMapSaveDialog::QgsMapSaveDialog( QWidget *parent, QgsMapCanvas *mapCanvas, co
5050
mDrawDecorations->setText( tr( "Draw active decorations: %1" ).arg( !activeDecorations.isEmpty() ? activeDecorations : tr( "none" ) ) );
5151

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

@@ -64,6 +66,32 @@ void QgsMapSaveDialog::updateDpi( int dpi )
6466
updateOutputSize();
6567
}
6668

69+
void QgsMapSaveDialog::updateOutputWidth( int width )
70+
{
71+
double scale = ( double )width / mSize.width();
72+
double adjustment = ( ( mExtent.width() * scale ) - mExtent.width() ) / 2;
73+
74+
mExtent.setXMinimum( mExtent.xMinimum() - adjustment );
75+
mExtent.setXMaximum( mExtent.xMaximum() + adjustment );
76+
77+
whileBlocking( mExtentGroupBox )->setOutputExtentFromUser( mExtent, mExtentGroupBox->currentCrs() );
78+
79+
mSize.setWidth( width );
80+
}
81+
82+
void QgsMapSaveDialog::updateOutputHeight( int height )
83+
{
84+
double scale = ( double )height / mSize.height();
85+
double adjustment = ( ( mExtent.height() * scale ) - mExtent.height() ) / 2;
86+
87+
mExtent.setYMinimum( mExtent.yMinimum() - adjustment );
88+
mExtent.setYMaximum( mExtent.yMaximum() + adjustment );
89+
90+
whileBlocking( mExtentGroupBox )->setOutputExtentFromUser( mExtent, mExtentGroupBox->currentCrs() );
91+
92+
mSize.setHeight( height );
93+
}
94+
6795
void QgsMapSaveDialog::updateExtent( const QgsRectangle &extent )
6896
{
6997
mSize.setWidth( mSize.width() * extent.width() / mExtent.width() );
@@ -87,7 +115,8 @@ void QgsMapSaveDialog::updateScale( double scale )
87115

88116
void QgsMapSaveDialog::updateOutputSize()
89117
{
90-
mOutputSize->setText( tr( "Output size: %1 x %2 pixels" ).arg( mSize.width() ).arg( mSize.height() ) );
118+
whileBlocking( mOutputWidthSpinBox )->setValue( mSize.width() );
119+
whileBlocking( mOutputHeightSpinBox )->setValue( mSize.height() );
91120
}
92121

93122
QgsRectangle QgsMapSaveDialog::extent() const

‎src/app/qgsmapsavedialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class APP_EXPORT QgsMapSaveDialog: public QDialog, private Ui::QgsMapSaveDialog
5959
private:
6060

6161
void updateDpi( int dpi );
62+
void updateOutputWidth( int width );
63+
void updateOutputHeight( int height );
6264
void updateExtent( const QgsRectangle &extent );
6365
void updateScale( double scale );
6466
void updateOutputSize();

‎src/ui/qgsmapsavedialog.ui

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<layout class="QVBoxLayout" name="verticalLayout">
1717
<item>
1818
<layout class="QGridLayout" name="gridLayout">
19-
<item row="5" column="0" colspan="2">>
19+
<item row="6" column="0" colspan="2">>
2020
<widget class="QCheckBox" name="mDrawAnnotations">
2121
<property name="text">
2222
<string>Draw annotations</string>
@@ -26,7 +26,7 @@
2626
</property>
2727
</widget>
2828
</item>
29-
<item row="4" column="0" colspan="2">
29+
<item row="5" column="0" colspan="2">
3030
<widget class="QCheckBox" name="mDrawDecorations">
3131
<property name="text">
3232
<string>Draw active decorations</string>
@@ -36,13 +36,55 @@
3636
</property>
3737
</widget>
3838
</item>
39-
<item row="3" column="0" colspan="2">
40-
<widget class="QLabel" name="mOutputSize">
41-
<property name="enabled">
39+
<item row="4" column="0">
40+
<widget class="QLabel" name="label_4">
41+
<property name="text">
42+
<string>Output height</string>
43+
</property>
44+
</widget>
45+
</item>
46+
<item row="4" column="1">
47+
<widget class="QgsSpinBox" name="mOutputHeightSpinBox">
48+
<property name="suffix">
49+
<string> px</string>
50+
</property>
51+
<property name="prefix">
52+
<string/>
53+
</property>
54+
<property name="minimum">
55+
<number>1</number>
56+
</property>
57+
<property name="maximum">
58+
<number>99999</number>
59+
</property>
60+
<property name="showClearButton" stdset="0">
4261
<bool>false</bool>
4362
</property>
44-
<property name="alignment">
45-
<set>Qt::AlignCenter</set>
63+
</widget>
64+
</item>
65+
<item row="3" column="0">
66+
<widget class="QLabel" name="label_3">
67+
<property name="text">
68+
<string>Output width</string>
69+
</property>
70+
</widget>
71+
</item>
72+
<item row="3" column="1">
73+
<widget class="QgsSpinBox" name="mOutputWidthSpinBox">
74+
<property name="suffix">
75+
<string> px</string>
76+
</property>
77+
<property name="prefix">
78+
<string/>
79+
</property>
80+
<property name="minimum">
81+
<number>1</number>
82+
</property>
83+
<property name="maximum">
84+
<number>99999</number>
85+
</property>
86+
<property name="showClearButton" stdset="0">
87+
<bool>false</bool>
4688
</property>
4789
</widget>
4890
</item>
@@ -61,6 +103,9 @@
61103
<property name="prefix">
62104
<string/>
63105
</property>
106+
<property name="minimum">
107+
<number>1</number>
108+
</property>
64109
<property name="maximum">
65110
<number>3000</number>
66111
</property>

0 commit comments

Comments
 (0)