Skip to content

Commit 069a0ba

Browse files
committedDec 17, 2017
Expose some more export related settings to GUI
1 parent f08ff15 commit 069a0ba

File tree

7 files changed

+90
-3
lines changed

7 files changed

+90
-3
lines changed
 

‎python/core/layout/qgslayout.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
3333
ZSnapIndicator,
3434
};
3535

36+
enum UndoCommand
37+
{
38+
UndoLayoutDpi,
39+
UndoNone,
40+
};
41+
3642
QgsLayout( QgsProject *project );
3743
%Docstring
3844
Construct a new layout linked to the specified ``project``.

‎src/app/layout/qgslayoutpropertieswidget.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ QgsLayoutPropertiesWidget::QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout
5454
QgsUnitTypes::LayoutUnit marginUnit = static_cast< QgsUnitTypes::LayoutUnit >(
5555
mLayout->customProperty( QStringLiteral( "imageCropMarginUnit" ), QgsUnitTypes::LayoutMillimeters ).toInt() );
5656

57+
bool exportWorldFile = mLayout->customProperty( QStringLiteral( "exportWorldFile" ), false ).toBool();
58+
mGenerateWorldFileCheckBox->setChecked( exportWorldFile );
59+
5760
mTopMarginSpinBox->setValue( topMargin );
5861
mMarginUnitsComboBox->linkToWidget( mTopMarginSpinBox );
5962
mRightMarginSpinBox->setValue( rightMargin );
@@ -71,6 +74,7 @@ QgsLayoutPropertiesWidget::QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout
7174
connect( mLeftMarginSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
7275
connect( mResizePageButton, &QPushButton::clicked, this, &QgsLayoutPropertiesWidget::resizeToContents );
7376

77+
connect( mResolutionSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutPropertiesWidget::dpiChanged );
7478
connect( mReferenceMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutPropertiesWidget::referenceMapChanged );
7579

7680
mReferenceMapComboBox->setCurrentLayout( mLayout );
@@ -82,6 +86,7 @@ QgsLayoutPropertiesWidget::QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout
8286
void QgsLayoutPropertiesWidget::updateGui()
8387
{
8488
whileBlocking( mReferenceMapComboBox )->setItem( mLayout->referenceMap() );
89+
whileBlocking( mResolutionSpinBox )->setValue( mLayout->context().dpi() );
8590
}
8691

8792
void QgsLayoutPropertiesWidget::updateSnappingElements()
@@ -171,6 +176,18 @@ void QgsLayoutPropertiesWidget::referenceMapChanged( QgsLayoutItem *item )
171176
mLayout->undoStack()->endCommand();
172177
}
173178

179+
void QgsLayoutPropertiesWidget::dpiChanged( int value )
180+
{
181+
mLayout->undoStack()->beginCommand( mLayout, tr( "Set Default DPI" ), QgsLayout::UndoLayoutDpi );
182+
mLayout->context().setDpi( value );
183+
mLayout->undoStack()->endCommand();
184+
}
185+
186+
void QgsLayoutPropertiesWidget::worldFileToggled()
187+
{
188+
mLayout->setCustomProperty( QStringLiteral( "exportWorldFile" ), mGenerateWorldFileCheckBox->isChecked() );
189+
}
190+
174191
void QgsLayoutPropertiesWidget::blockSignals( bool block )
175192
{
176193
mGridResolutionSpinBox->blockSignals( block );

‎src/app/layout/qgslayoutpropertieswidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class QgsLayoutPropertiesWidget: public QgsPanelWidget, private Ui::QgsLayoutWid
4141
void resizeMarginsChanged();
4242
void resizeToContents();
4343
void referenceMapChanged( QgsLayoutItem *item );
44+
void dpiChanged( int value );
45+
void worldFileToggled();
46+
4447
private:
4548

4649
QgsLayout *mLayout = nullptr;

‎src/core/layout/qgslayout.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ void QgsLayout::writeXmlLayoutSettings( QDomElement &element, QDomDocument &docu
710710
element.setAttribute( QStringLiteral( "name" ), mName );
711711
element.setAttribute( QStringLiteral( "units" ), QgsUnitTypes::encodeUnit( mUnits ) );
712712
element.setAttribute( QStringLiteral( "worldFileMap" ), mWorldFileMapId );
713+
element.setAttribute( QStringLiteral( "printResolution" ), mContext.dpi() );
713714
}
714715

715716
QDomElement QgsLayout::writeXml( QDomDocument &document, const QgsReadWriteContext &context ) const
@@ -753,6 +754,7 @@ bool QgsLayout::readXmlLayoutSettings( const QDomElement &layoutElement, const Q
753754
setName( layoutElement.attribute( QStringLiteral( "name" ) ) );
754755
setUnits( QgsUnitTypes::decodeLayoutUnit( layoutElement.attribute( QStringLiteral( "units" ) ) ) );
755756
mWorldFileMapId = layoutElement.attribute( QStringLiteral( "worldFileMap" ) );
757+
mContext.setDpi( layoutElement.attribute( QStringLiteral( "printResolution" ), "300" ).toDouble() );
756758
emit changed();
757759

758760
return true;

‎src/core/layout/qgslayout.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
6464
ZSnapIndicator = 10002, //!< Z-value for snapping indicator
6565
};
6666

67+
//! Layout undo commands, used for collapsing undo commands
68+
enum UndoCommand
69+
{
70+
UndoLayoutDpi, //!< Change layout default DPI
71+
UndoNone = -1, //!< No command suppression
72+
};
73+
6774
/**
6875
* Construct a new layout linked to the specified \a project.
6976
*

‎src/ui/layout/qgslayoutwidgetbase.ui

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>311</width>
10-
<height>515</height>
10+
<height>494</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -55,14 +55,14 @@
5555
<x>0</x>
5656
<y>0</y>
5757
<width>297</width>
58-
<height>632</height>
58+
<height>746</height>
5959
</rect>
6060
</property>
6161
<layout class="QVBoxLayout" name="verticalLayout_2">
6262
<item>
6363
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox">
6464
<property name="title">
65-
<string>GroupBox</string>
65+
<string>General settings</string>
6666
</property>
6767
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
6868
<item row="0" column="0">
@@ -204,6 +204,54 @@
204204
</layout>
205205
</widget>
206206
</item>
207+
<item>
208+
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox_3">
209+
<property name="title">
210+
<string>Export settings</string>
211+
</property>
212+
<layout class="QGridLayout" name="gridLayout_3">
213+
<item row="1" column="1">
214+
<widget class="QgsSpinBox" name="mResolutionSpinBox">
215+
<property name="suffix">
216+
<string> dpi</string>
217+
</property>
218+
<property name="prefix">
219+
<string/>
220+
</property>
221+
<property name="maximum">
222+
<number>3000</number>
223+
</property>
224+
<property name="showClearButton" stdset="0">
225+
<bool>false</bool>
226+
</property>
227+
</widget>
228+
</item>
229+
<item row="1" column="0">
230+
<widget class="QLabel" name="label_9">
231+
<property name="text">
232+
<string>Export resolution</string>
233+
</property>
234+
</widget>
235+
</item>
236+
<item row="2" column="0" colspan="2">
237+
<widget class="QCheckBox" name="mGenerateWorldFileCheckBox">
238+
<property name="sizePolicy">
239+
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
240+
<horstretch>0</horstretch>
241+
<verstretch>0</verstretch>
242+
</sizepolicy>
243+
</property>
244+
<property name="toolTip">
245+
<string>If checked, a separate world file which georeferences exported images will be created</string>
246+
</property>
247+
<property name="text">
248+
<string>Save world file</string>
249+
</property>
250+
</widget>
251+
</item>
252+
</layout>
253+
</widget>
254+
</item>
207255
<item>
208256
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox_5">
209257
<property name="title">
@@ -388,6 +436,8 @@
388436
<tabstop>mOffsetYSpinBox</tabstop>
389437
<tabstop>mGridOffsetUnitsComboBox</tabstop>
390438
<tabstop>mSnapToleranceSpinBox</tabstop>
439+
<tabstop>mResolutionSpinBox</tabstop>
440+
<tabstop>mGenerateWorldFileCheckBox</tabstop>
391441
<tabstop>mMarginUnitsComboBox</tabstop>
392442
<tabstop>mTopMarginSpinBox</tabstop>
393443
<tabstop>mLeftMarginSpinBox</tabstop>

‎tests/src/python/test_qgslayoutexporter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
QgsProject,
2525
QgsMargins,
2626
QgsLayoutItemShape,
27+
QgsRectangle,
2728
QgsLayoutItemPage,
29+
QgsLayoutItemMap,
2830
QgsLayoutPoint,
2931
QgsSimpleFillSymbolLayer,
3032
QgsFillSymbol)

0 commit comments

Comments
 (0)
Please sign in to comment.