Skip to content

Commit

Permalink
Expose some more export related settings to GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 17, 2017
1 parent f08ff15 commit 069a0ba
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 3 deletions.
6 changes: 6 additions & 0 deletions python/core/layout/qgslayout.sip
Expand Up @@ -33,6 +33,12 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
ZSnapIndicator,
};

enum UndoCommand
{
UndoLayoutDpi,
UndoNone,
};

QgsLayout( QgsProject *project );
%Docstring
Construct a new layout linked to the specified ``project``.
Expand Down
17 changes: 17 additions & 0 deletions src/app/layout/qgslayoutpropertieswidget.cpp
Expand Up @@ -54,6 +54,9 @@ QgsLayoutPropertiesWidget::QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout
QgsUnitTypes::LayoutUnit marginUnit = static_cast< QgsUnitTypes::LayoutUnit >(
mLayout->customProperty( QStringLiteral( "imageCropMarginUnit" ), QgsUnitTypes::LayoutMillimeters ).toInt() );

bool exportWorldFile = mLayout->customProperty( QStringLiteral( "exportWorldFile" ), false ).toBool();
mGenerateWorldFileCheckBox->setChecked( exportWorldFile );

mTopMarginSpinBox->setValue( topMargin );
mMarginUnitsComboBox->linkToWidget( mTopMarginSpinBox );
mRightMarginSpinBox->setValue( rightMargin );
Expand All @@ -71,6 +74,7 @@ QgsLayoutPropertiesWidget::QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout
connect( mLeftMarginSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
connect( mResizePageButton, &QPushButton::clicked, this, &QgsLayoutPropertiesWidget::resizeToContents );

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

mReferenceMapComboBox->setCurrentLayout( mLayout );
Expand All @@ -82,6 +86,7 @@ QgsLayoutPropertiesWidget::QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout
void QgsLayoutPropertiesWidget::updateGui()
{
whileBlocking( mReferenceMapComboBox )->setItem( mLayout->referenceMap() );
whileBlocking( mResolutionSpinBox )->setValue( mLayout->context().dpi() );
}

void QgsLayoutPropertiesWidget::updateSnappingElements()
Expand Down Expand Up @@ -171,6 +176,18 @@ void QgsLayoutPropertiesWidget::referenceMapChanged( QgsLayoutItem *item )
mLayout->undoStack()->endCommand();
}

void QgsLayoutPropertiesWidget::dpiChanged( int value )
{
mLayout->undoStack()->beginCommand( mLayout, tr( "Set Default DPI" ), QgsLayout::UndoLayoutDpi );
mLayout->context().setDpi( value );
mLayout->undoStack()->endCommand();
}

void QgsLayoutPropertiesWidget::worldFileToggled()
{
mLayout->setCustomProperty( QStringLiteral( "exportWorldFile" ), mGenerateWorldFileCheckBox->isChecked() );
}

void QgsLayoutPropertiesWidget::blockSignals( bool block )
{
mGridResolutionSpinBox->blockSignals( block );
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout/qgslayoutpropertieswidget.h
Expand Up @@ -41,6 +41,9 @@ class QgsLayoutPropertiesWidget: public QgsPanelWidget, private Ui::QgsLayoutWid
void resizeMarginsChanged();
void resizeToContents();
void referenceMapChanged( QgsLayoutItem *item );
void dpiChanged( int value );
void worldFileToggled();

private:

QgsLayout *mLayout = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions src/core/layout/qgslayout.cpp
Expand Up @@ -710,6 +710,7 @@ void QgsLayout::writeXmlLayoutSettings( QDomElement &element, QDomDocument &docu
element.setAttribute( QStringLiteral( "name" ), mName );
element.setAttribute( QStringLiteral( "units" ), QgsUnitTypes::encodeUnit( mUnits ) );
element.setAttribute( QStringLiteral( "worldFileMap" ), mWorldFileMapId );
element.setAttribute( QStringLiteral( "printResolution" ), mContext.dpi() );
}

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

return true;
Expand Down
7 changes: 7 additions & 0 deletions src/core/layout/qgslayout.h
Expand Up @@ -64,6 +64,13 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
ZSnapIndicator = 10002, //!< Z-value for snapping indicator
};

//! Layout undo commands, used for collapsing undo commands
enum UndoCommand
{
UndoLayoutDpi, //!< Change layout default DPI
UndoNone = -1, //!< No command suppression
};

/**
* Construct a new layout linked to the specified \a project.
*
Expand Down
56 changes: 53 additions & 3 deletions src/ui/layout/qgslayoutwidgetbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>311</width>
<height>515</height>
<height>494</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -55,14 +55,14 @@
<x>0</x>
<y>0</y>
<width>297</width>
<height>632</height>
<height>746</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox">
<property name="title">
<string>GroupBox</string>
<string>General settings</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
<item row="0" column="0">
Expand Down Expand Up @@ -204,6 +204,54 @@
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox_3">
<property name="title">
<string>Export settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<widget class="QgsSpinBox" name="mResolutionSpinBox">
<property name="suffix">
<string> dpi</string>
</property>
<property name="prefix">
<string/>
</property>
<property name="maximum">
<number>3000</number>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Export resolution</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mGenerateWorldFileCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>If checked, a separate world file which georeferences exported images will be created</string>
</property>
<property name="text">
<string>Save world file</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="groupBox_5">
<property name="title">
Expand Down Expand Up @@ -388,6 +436,8 @@
<tabstop>mOffsetYSpinBox</tabstop>
<tabstop>mGridOffsetUnitsComboBox</tabstop>
<tabstop>mSnapToleranceSpinBox</tabstop>
<tabstop>mResolutionSpinBox</tabstop>
<tabstop>mGenerateWorldFileCheckBox</tabstop>
<tabstop>mMarginUnitsComboBox</tabstop>
<tabstop>mTopMarginSpinBox</tabstop>
<tabstop>mLeftMarginSpinBox</tabstop>
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_qgslayoutexporter.py
Expand Up @@ -24,7 +24,9 @@
QgsProject,
QgsMargins,
QgsLayoutItemShape,
QgsRectangle,
QgsLayoutItemPage,
QgsLayoutItemMap,
QgsLayoutPoint,
QgsSimpleFillSymbolLayer,
QgsFillSymbol)
Expand Down

0 comments on commit 069a0ba

Please sign in to comment.