Skip to content
Permalink
Browse files

Expose some more export related settings to GUI

  • Loading branch information
nyalldawson committed Dec 11, 2017
1 parent f08ff15 commit 069a0baa40f5036aeb62b440b0eebddb16f0e2be
@@ -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``.
@@ -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 );
@@ -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 );
@@ -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()
@@ -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 );
@@ -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;
@@ -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
@@ -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;
@@ -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.
*
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>311</width>
<height>515</height>
<height>494</height>
</rect>
</property>
<property name="windowTitle">
@@ -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">
@@ -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">
@@ -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>
@@ -24,7 +24,9 @@
QgsProject,
QgsMargins,
QgsLayoutItemShape,
QgsRectangle,
QgsLayoutItemPage,
QgsLayoutItemMap,
QgsLayoutPoint,
QgsSimpleFillSymbolLayer,
QgsFillSymbol)

0 comments on commit 069a0ba

Please sign in to comment.
You can’t perform that action at this time.