30#include "moc_qgslayoutpropertieswidget.cpp"
42 mVariableEditor->setMinimumHeight( mVariableEditor->fontMetrics().height() * 15 );
44 updateSnappingElements();
46 mGridSpacingUnitsCombo->linkToWidget( mGridResolutionSpinBox );
47 mGridOffsetUnitsComboBox->linkToWidget( mOffsetXSpinBox );
48 mGridOffsetUnitsComboBox->linkToWidget( mOffsetYSpinBox );
50 blockSignals(
false );
52 connect( mSnapToleranceSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::snapToleranceChanged );
56 connect( mGridResolutionSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::gridResolutionChanged );
57 connect( mOffsetXSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::gridOffsetXChanged );
58 connect( mOffsetYSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::gridOffsetYChanged );
60 const double leftMargin = mLayout->customProperty( QStringLiteral(
"resizeToContentsLeftMargin" ) ).toDouble();
61 const double topMargin = mLayout->customProperty( QStringLiteral(
"resizeToContentsTopMargin" ) ).toDouble();
62 const double bottomMargin = mLayout->customProperty( QStringLiteral(
"resizeToContentsBottomMargin" ) ).toDouble();
63 const double rightMargin = mLayout->customProperty( QStringLiteral(
"resizeToContentsRightMargin" ) ).toDouble();
68 const bool exportWorldFile = mLayout->customProperty( QStringLiteral(
"exportWorldFile" ),
false ).toBool();
69 mGenerateWorldFileCheckBox->setChecked( exportWorldFile );
70 connect( mGenerateWorldFileCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::worldFileToggled );
72 connect( mRasterizeCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::rasterizeToggled );
73 connect( mForceVectorCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::forceVectorToggled );
75 mTopMarginSpinBox->setValue( topMargin );
76 mMarginUnitsComboBox->linkToWidget( mTopMarginSpinBox );
77 mRightMarginSpinBox->setValue( rightMargin );
78 mMarginUnitsComboBox->linkToWidget( mRightMarginSpinBox );
79 mBottomMarginSpinBox->setValue( bottomMargin );
80 mMarginUnitsComboBox->linkToWidget( mBottomMarginSpinBox );
81 mLeftMarginSpinBox->setValue( leftMargin );
82 mMarginUnitsComboBox->linkToWidget( mLeftMarginSpinBox );
83 mMarginUnitsComboBox->setUnit( marginUnit );
84 mMarginUnitsComboBox->setConverter( &mLayout->renderContext().measurementConverter() );
86 connect( mTopMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
87 connect( mRightMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
88 connect( mBottomMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
89 connect( mLeftMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
90 connect( mResizePageButton, &QPushButton::clicked,
this, &QgsLayoutPropertiesWidget::resizeToContents );
92 connect( mResolutionSpinBox, &QSpinBox::editingFinished,
this, [
this] { dpiChanged( mResolutionSpinBox->value() ); } );
94 mReferenceMapComboBox->setCurrentLayout( mLayout );
124 whileBlocking( mReferenceMapComboBox )->setItem( mLayout->referenceMap() );
125 whileBlocking( mResolutionSpinBox )->setValue( mLayout->renderContext().dpi() );
127 const bool rasterize = mLayout->customProperty( QStringLiteral(
"rasterize" ),
false ).toBool();
128 whileBlocking( mRasterizeCheckBox )->setChecked( rasterize );
130 const bool forceVectors = mLayout->customProperty( QStringLiteral(
"forceVector" ),
false ).toBool();
131 whileBlocking( mForceVectorCheckBox )->setChecked( forceVectors );
135 mForceVectorCheckBox->setChecked(
false );
136 mForceVectorCheckBox->setEnabled(
false );
140 mForceVectorCheckBox->setEnabled(
true );
144void QgsLayoutPropertiesWidget::updateSnappingElements()
156void QgsLayoutPropertiesWidget::gridResolutionChanged(
double d )
158 QgsLayoutMeasurement m = mLayout->gridSettings().resolution();
160 mLayout->gridSettings().setResolution( m );
161 mLayout->pageCollection()->redraw();
164void QgsLayoutPropertiesWidget::gridResolutionUnitsChanged(
Qgis::LayoutUnit unit )
166 QgsLayoutMeasurement m = mLayout->gridSettings().resolution();
168 mLayout->gridSettings().setResolution( m );
169 mLayout->pageCollection()->redraw();
172void QgsLayoutPropertiesWidget::gridOffsetXChanged(
double d )
174 QgsLayoutPoint o = mLayout->gridSettings().offset();
176 mLayout->gridSettings().setOffset( o );
177 mLayout->pageCollection()->redraw();
180void QgsLayoutPropertiesWidget::gridOffsetYChanged(
double d )
182 QgsLayoutPoint o = mLayout->gridSettings().offset();
184 mLayout->gridSettings().setOffset( o );
185 mLayout->pageCollection()->redraw();
188void QgsLayoutPropertiesWidget::gridOffsetUnitsChanged(
Qgis::LayoutUnit unit )
190 QgsLayoutPoint o = mLayout->gridSettings().offset();
192 mLayout->gridSettings().setOffset( o );
193 mLayout->pageCollection()->redraw();
196void QgsLayoutPropertiesWidget::snapToleranceChanged(
int tolerance )
198 mLayout->snapper().setSnapTolerance( tolerance );
201void QgsLayoutPropertiesWidget::resizeMarginsChanged()
203 mLayout->setCustomProperty( QStringLiteral(
"resizeToContentsLeftMargin" ), mLeftMarginSpinBox->value() );
204 mLayout->setCustomProperty( QStringLiteral(
"resizeToContentsTopMargin" ), mTopMarginSpinBox->value() );
205 mLayout->setCustomProperty( QStringLiteral(
"resizeToContentsBottomMargin" ), mBottomMarginSpinBox->value() );
206 mLayout->setCustomProperty( QStringLiteral(
"resizeToContentsRightMargin" ), mRightMarginSpinBox->value() );
207 mLayout->setCustomProperty( QStringLiteral(
"imageCropMarginUnit" ),
static_cast<int>( mMarginUnitsComboBox->unit() ) );
210void QgsLayoutPropertiesWidget::resizeToContents()
212 mLayout->undoStack()->beginMacro( tr(
"Resize to Contents" ) );
214 mLayout->pageCollection()->resizeToContents( QgsMargins( mLeftMarginSpinBox->value(), mTopMarginSpinBox->value(), mRightMarginSpinBox->value(), mBottomMarginSpinBox->value() ), mMarginUnitsComboBox->unit() );
216 mLayout->undoStack()->endMacro();
219void QgsLayoutPropertiesWidget::referenceMapChanged(
QgsLayoutItem *item )
221 mLayout->undoStack()->beginCommand( mLayout, tr(
"Set Reference Map" ) );
222 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( item );
223 mLayout->setReferenceMap( map );
224 mLayout->undoStack()->endCommand();
227void QgsLayoutPropertiesWidget::dpiChanged(
int value )
230 mLayout->renderContext().setDpi( value );
231 mLayout->undoStack()->endCommand();
236void QgsLayoutPropertiesWidget::worldFileToggled()
238 mLayout->setCustomProperty( QStringLiteral(
"exportWorldFile" ), mGenerateWorldFileCheckBox->isChecked() );
241void QgsLayoutPropertiesWidget::rasterizeToggled()
243 mLayout->setCustomProperty( QStringLiteral(
"rasterize" ), mRasterizeCheckBox->isChecked() );
245 if ( mRasterizeCheckBox->isChecked() )
247 mForceVectorCheckBox->setChecked(
false );
248 mForceVectorCheckBox->setEnabled(
false );
252 mForceVectorCheckBox->setEnabled(
true );
256void QgsLayoutPropertiesWidget::forceVectorToggled()
258 mLayout->setCustomProperty( QStringLiteral(
"forceVector" ), mForceVectorCheckBox->isChecked() );
261void QgsLayoutPropertiesWidget::variablesChanged()
263 mBlockVariableUpdates =
true;
265 mBlockVariableUpdates =
false;
268void QgsLayoutPropertiesWidget::updateVariables()
270 if ( mBlockVariableUpdates )
273 QgsExpressionContext context;
277 mVariableEditor->setContext( &context );
278 mVariableEditor->setEditableScopeIndex( 2 );
281void QgsLayoutPropertiesWidget::blockSignals(
bool block )
283 mGridResolutionSpinBox->blockSignals( block );
284 mOffsetXSpinBox->blockSignals( block );
285 mOffsetYSpinBox->blockSignals( block );
286 mSnapToleranceSpinBox->blockSignals( block );
LayoutUnit
Layout measurement units.
@ Millimeters
Millimeters.
void customVariablesChanged()
Emitted whenever a custom global variable changes.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
static QgsExpressionContextScope * layoutScope(const QgsLayout *layout)
Creates a new scope which contains variables and functions relating to a QgsLayout layout.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static void setLayoutVariables(QgsLayout *layout, const QVariantMap &variables)
Sets all layout context variables.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
void coverageLayerChanged(QgsVectorLayer *layer)
Emitted when the coverage layer for the atlas changes.
QgsLayoutMeasurement resolution() const
Returns the page/snap grid resolution.
QgsLayoutPoint offset() const
Returns the offset of the page/snap grid.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Base class for graphical items within a QgsLayout.
void setLength(const double length)
Sets the length of the measurement.
Qgis::LayoutUnit units() const
Returns the units for the measurement.
void setUnits(const Qgis::LayoutUnit units)
Sets the units for the measurement.
double length() const
Returns the length of the measurement.
void changed()
Emitted when pages are added or removed from the collection.
double x() const
Returns x coordinate of point.
void setX(const double x)
Sets the x coordinate of point.
void setUnits(const Qgis::LayoutUnit units)
Sets the units for the point.
double y() const
Returns y coordinate of point.
Qgis::LayoutUnit units() const
Returns the units for the point.
void setY(const double y)
Sets y coordinate of point.
void dpiChanged()
Emitted when the context's DPI is changed.
int snapTolerance() const
Returns the snap tolerance (in pixels) to use when snapping.
void unitChanged(Qgis::LayoutUnit unit)
Emitted when the unit is changed.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutSnapper & snapper()
Returns a reference to the layout's snapper, which stores handles layout snap grids and lines and sna...
void variablesChanged()
Emitted whenever the expression variables stored in the layout have been changed.
void changed()
Emitted when properties of the layout change.
QgsLayoutGridSettings & gridSettings()
Returns a reference to the layout's grid settings, which stores settings relating to grid appearance,...
@ UndoLayoutDpi
Change layout default DPI.
Interface for master layout type objects, such as print layouts and reports.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
void nameChanged(const QString &name)
Emitted when the layout's name is changed.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void metadataChanged()
Emitted when the project's metadata is changed.
void customVariablesChanged()
Emitted whenever the expression variables stored in the project have been changed.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.