32#include "moc_qgslayoutpropertieswidget.cpp"
34using namespace Qt::StringLiterals;
46 mVariableEditor->setMinimumHeight( mVariableEditor->fontMetrics().height() * 15 );
48 updateSnappingElements();
50 mGridSpacingUnitsCombo->linkToWidget( mGridResolutionSpinBox );
51 mGridOffsetUnitsComboBox->linkToWidget( mOffsetXSpinBox );
52 mGridOffsetUnitsComboBox->linkToWidget( mOffsetYSpinBox );
54 blockSignals(
false );
56 connect( mSnapToleranceSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::snapToleranceChanged );
60 connect( mGridResolutionSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::gridResolutionChanged );
61 connect( mOffsetXSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::gridOffsetXChanged );
62 connect( mOffsetYSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::gridOffsetYChanged );
64 const double leftMargin = mLayout->customProperty( u
"resizeToContentsLeftMargin"_s ).toDouble();
65 const double topMargin = mLayout->customProperty( u
"resizeToContentsTopMargin"_s ).toDouble();
66 const double bottomMargin = mLayout->customProperty( u
"resizeToContentsBottomMargin"_s ).toDouble();
67 const double rightMargin = mLayout->customProperty( u
"resizeToContentsRightMargin"_s ).toDouble();
70 const bool exportWorldFile = mLayout->customProperty( u
"exportWorldFile"_s,
false ).toBool();
71 mGenerateWorldFileCheckBox->setChecked( exportWorldFile );
72 connect( mGenerateWorldFileCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::worldFileToggled );
74 connect( mRasterizeCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::rasterizeToggled );
75 connect( mForceVectorCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::forceVectorToggled );
77 mTopMarginSpinBox->setValue( topMargin );
78 mMarginUnitsComboBox->linkToWidget( mTopMarginSpinBox );
79 mRightMarginSpinBox->setValue( rightMargin );
80 mMarginUnitsComboBox->linkToWidget( mRightMarginSpinBox );
81 mBottomMarginSpinBox->setValue( bottomMargin );
82 mMarginUnitsComboBox->linkToWidget( mBottomMarginSpinBox );
83 mLeftMarginSpinBox->setValue( leftMargin );
84 mMarginUnitsComboBox->linkToWidget( mLeftMarginSpinBox );
85 mMarginUnitsComboBox->setUnit( marginUnit );
86 mMarginUnitsComboBox->setConverter( &mLayout->renderContext().measurementConverter() );
88 connect( mTopMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
89 connect( mRightMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
90 connect( mBottomMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
91 connect( mLeftMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
92 connect( mResizePageButton, &QPushButton::clicked,
this, &QgsLayoutPropertiesWidget::resizeToContents );
94 connect( mResolutionSpinBox, &QSpinBox::editingFinished,
this, [
this] { dpiChanged( mResolutionSpinBox->value() ); } );
96 mReferenceMapComboBox->setCurrentLayout( mLayout );
126 whileBlocking( mReferenceMapComboBox )->setItem( mLayout->referenceMap() );
127 whileBlocking( mResolutionSpinBox )->setValue( mLayout->renderContext().dpi() );
129 const bool rasterize = mLayout->customProperty( u
"rasterize"_s,
false ).toBool();
130 whileBlocking( mRasterizeCheckBox )->setChecked( rasterize );
132 const bool forceVectors = mLayout->customProperty( u
"forceVector"_s,
false ).toBool();
133 whileBlocking( mForceVectorCheckBox )->setChecked( forceVectors );
137 mForceVectorCheckBox->setChecked(
false );
138 mForceVectorCheckBox->setEnabled(
false );
142 mForceVectorCheckBox->setEnabled(
true );
146void QgsLayoutPropertiesWidget::updateSnappingElements()
158void QgsLayoutPropertiesWidget::gridResolutionChanged(
double d )
160 QgsLayoutMeasurement m = mLayout->gridSettings().resolution();
162 mLayout->gridSettings().setResolution( m );
163 mLayout->pageCollection()->redraw();
166void QgsLayoutPropertiesWidget::gridResolutionUnitsChanged(
Qgis::LayoutUnit unit )
168 QgsLayoutMeasurement m = mLayout->gridSettings().resolution();
170 mLayout->gridSettings().setResolution( m );
171 mLayout->pageCollection()->redraw();
174void QgsLayoutPropertiesWidget::gridOffsetXChanged(
double d )
176 QgsLayoutPoint o = mLayout->gridSettings().offset();
178 mLayout->gridSettings().setOffset( o );
179 mLayout->pageCollection()->redraw();
182void QgsLayoutPropertiesWidget::gridOffsetYChanged(
double d )
184 QgsLayoutPoint o = mLayout->gridSettings().offset();
186 mLayout->gridSettings().setOffset( o );
187 mLayout->pageCollection()->redraw();
190void QgsLayoutPropertiesWidget::gridOffsetUnitsChanged(
Qgis::LayoutUnit unit )
192 QgsLayoutPoint o = mLayout->gridSettings().offset();
194 mLayout->gridSettings().setOffset( o );
195 mLayout->pageCollection()->redraw();
198void QgsLayoutPropertiesWidget::snapToleranceChanged(
int tolerance )
200 mLayout->snapper().setSnapTolerance( tolerance );
203void QgsLayoutPropertiesWidget::resizeMarginsChanged()
205 mLayout->setCustomProperty( u
"resizeToContentsLeftMargin"_s, mLeftMarginSpinBox->value() );
206 mLayout->setCustomProperty( u
"resizeToContentsTopMargin"_s, mTopMarginSpinBox->value() );
207 mLayout->setCustomProperty( u
"resizeToContentsBottomMargin"_s, mBottomMarginSpinBox->value() );
208 mLayout->setCustomProperty( u
"resizeToContentsRightMargin"_s, mRightMarginSpinBox->value() );
209 mLayout->setCustomProperty( u
"imageCropMarginUnit"_s,
static_cast<int>( mMarginUnitsComboBox->unit() ) );
212void QgsLayoutPropertiesWidget::resizeToContents()
214 mLayout->undoStack()->beginMacro( tr(
"Resize to Contents" ) );
216 mLayout->pageCollection()->resizeToContents( QgsMargins( mLeftMarginSpinBox->value(), mTopMarginSpinBox->value(), mRightMarginSpinBox->value(), mBottomMarginSpinBox->value() ), mMarginUnitsComboBox->unit() );
218 mLayout->undoStack()->endMacro();
221void QgsLayoutPropertiesWidget::referenceMapChanged(
QgsLayoutItem *item )
223 mLayout->undoStack()->beginCommand( mLayout, tr(
"Set Reference Map" ) );
224 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( item );
225 mLayout->setReferenceMap( map );
226 mLayout->undoStack()->endCommand();
229void QgsLayoutPropertiesWidget::dpiChanged(
int value )
232 mLayout->renderContext().setDpi( value );
233 mLayout->undoStack()->endCommand();
238void QgsLayoutPropertiesWidget::worldFileToggled()
240 mLayout->setCustomProperty( u
"exportWorldFile"_s, mGenerateWorldFileCheckBox->isChecked() );
243void QgsLayoutPropertiesWidget::rasterizeToggled()
245 mLayout->setCustomProperty( u
"rasterize"_s, mRasterizeCheckBox->isChecked() );
247 if ( mRasterizeCheckBox->isChecked() )
249 mForceVectorCheckBox->setChecked(
false );
250 mForceVectorCheckBox->setEnabled(
false );
254 mForceVectorCheckBox->setEnabled(
true );
258void QgsLayoutPropertiesWidget::forceVectorToggled()
260 mLayout->setCustomProperty( u
"forceVector"_s, mForceVectorCheckBox->isChecked() );
263void QgsLayoutPropertiesWidget::variablesChanged()
265 mBlockVariableUpdates =
true;
267 mBlockVariableUpdates =
false;
270void QgsLayoutPropertiesWidget::updateVariables()
272 if ( mBlockVariableUpdates )
275 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.