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();
72 const bool exportWorldFile = mLayout->customProperty( u
"exportWorldFile"_s,
false ).toBool();
73 mGenerateWorldFileCheckBox->setChecked( exportWorldFile );
74 connect( mGenerateWorldFileCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::worldFileToggled );
76 connect( mRasterizeCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::rasterizeToggled );
77 connect( mForceVectorCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::forceVectorToggled );
79 mTopMarginSpinBox->setValue( topMargin );
80 mMarginUnitsComboBox->linkToWidget( mTopMarginSpinBox );
81 mRightMarginSpinBox->setValue( rightMargin );
82 mMarginUnitsComboBox->linkToWidget( mRightMarginSpinBox );
83 mBottomMarginSpinBox->setValue( bottomMargin );
84 mMarginUnitsComboBox->linkToWidget( mBottomMarginSpinBox );
85 mLeftMarginSpinBox->setValue( leftMargin );
86 mMarginUnitsComboBox->linkToWidget( mLeftMarginSpinBox );
87 mMarginUnitsComboBox->setUnit( marginUnit );
88 mMarginUnitsComboBox->setConverter( &mLayout->renderContext().measurementConverter() );
90 connect( mTopMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
91 connect( mRightMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
92 connect( mBottomMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
93 connect( mLeftMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
94 connect( mResizePageButton, &QPushButton::clicked,
this, &QgsLayoutPropertiesWidget::resizeToContents );
96 connect( mResolutionSpinBox, &QSpinBox::editingFinished,
this, [
this] { dpiChanged( mResolutionSpinBox->value() ); } );
98 mReferenceMapComboBox->setCurrentLayout( mLayout );
128 whileBlocking( mReferenceMapComboBox )->setItem( mLayout->referenceMap() );
129 whileBlocking( mResolutionSpinBox )->setValue( mLayout->renderContext().dpi() );
131 const bool rasterize = mLayout->customProperty( u
"rasterize"_s,
false ).toBool();
132 whileBlocking( mRasterizeCheckBox )->setChecked( rasterize );
134 const bool forceVectors = mLayout->customProperty( u
"forceVector"_s,
false ).toBool();
135 whileBlocking( mForceVectorCheckBox )->setChecked( forceVectors );
139 mForceVectorCheckBox->setChecked(
false );
140 mForceVectorCheckBox->setEnabled(
false );
144 mForceVectorCheckBox->setEnabled(
true );
148void QgsLayoutPropertiesWidget::updateSnappingElements()
160void QgsLayoutPropertiesWidget::gridResolutionChanged(
double d )
162 QgsLayoutMeasurement m = mLayout->gridSettings().resolution();
164 mLayout->gridSettings().setResolution( m );
165 mLayout->pageCollection()->redraw();
168void QgsLayoutPropertiesWidget::gridResolutionUnitsChanged(
Qgis::LayoutUnit unit )
170 QgsLayoutMeasurement m = mLayout->gridSettings().resolution();
172 mLayout->gridSettings().setResolution( m );
173 mLayout->pageCollection()->redraw();
176void QgsLayoutPropertiesWidget::gridOffsetXChanged(
double d )
178 QgsLayoutPoint o = mLayout->gridSettings().offset();
180 mLayout->gridSettings().setOffset( o );
181 mLayout->pageCollection()->redraw();
184void QgsLayoutPropertiesWidget::gridOffsetYChanged(
double d )
186 QgsLayoutPoint o = mLayout->gridSettings().offset();
188 mLayout->gridSettings().setOffset( o );
189 mLayout->pageCollection()->redraw();
192void QgsLayoutPropertiesWidget::gridOffsetUnitsChanged(
Qgis::LayoutUnit unit )
194 QgsLayoutPoint o = mLayout->gridSettings().offset();
196 mLayout->gridSettings().setOffset( o );
197 mLayout->pageCollection()->redraw();
200void QgsLayoutPropertiesWidget::snapToleranceChanged(
int tolerance )
202 mLayout->snapper().setSnapTolerance( tolerance );
205void QgsLayoutPropertiesWidget::resizeMarginsChanged()
207 mLayout->setCustomProperty( u
"resizeToContentsLeftMargin"_s, mLeftMarginSpinBox->value() );
208 mLayout->setCustomProperty( u
"resizeToContentsTopMargin"_s, mTopMarginSpinBox->value() );
209 mLayout->setCustomProperty( u
"resizeToContentsBottomMargin"_s, mBottomMarginSpinBox->value() );
210 mLayout->setCustomProperty( u
"resizeToContentsRightMargin"_s, mRightMarginSpinBox->value() );
211 mLayout->setCustomProperty( u
"imageCropMarginUnit"_s,
static_cast<int>( mMarginUnitsComboBox->unit() ) );
214void QgsLayoutPropertiesWidget::resizeToContents()
216 mLayout->undoStack()->beginMacro( tr(
"Resize to Contents" ) );
218 mLayout->pageCollection()->resizeToContents( QgsMargins( mLeftMarginSpinBox->value(), mTopMarginSpinBox->value(), mRightMarginSpinBox->value(), mBottomMarginSpinBox->value() ), mMarginUnitsComboBox->unit() );
220 mLayout->undoStack()->endMacro();
223void QgsLayoutPropertiesWidget::referenceMapChanged(
QgsLayoutItem *item )
225 mLayout->undoStack()->beginCommand( mLayout, tr(
"Set Reference Map" ) );
226 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( item );
227 mLayout->setReferenceMap( map );
228 mLayout->undoStack()->endCommand();
231void QgsLayoutPropertiesWidget::dpiChanged(
int value )
234 mLayout->renderContext().setDpi( value );
235 mLayout->undoStack()->endCommand();
240void QgsLayoutPropertiesWidget::worldFileToggled()
242 mLayout->setCustomProperty( u
"exportWorldFile"_s, mGenerateWorldFileCheckBox->isChecked() );
245void QgsLayoutPropertiesWidget::rasterizeToggled()
247 mLayout->setCustomProperty( u
"rasterize"_s, mRasterizeCheckBox->isChecked() );
249 if ( mRasterizeCheckBox->isChecked() )
251 mForceVectorCheckBox->setChecked(
false );
252 mForceVectorCheckBox->setEnabled(
false );
256 mForceVectorCheckBox->setEnabled(
true );
260void QgsLayoutPropertiesWidget::forceVectorToggled()
262 mLayout->setCustomProperty( u
"forceVector"_s, mForceVectorCheckBox->isChecked() );
265void QgsLayoutPropertiesWidget::variablesChanged()
267 mBlockVariableUpdates =
true;
269 mBlockVariableUpdates =
false;
272void QgsLayoutPropertiesWidget::updateVariables()
274 if ( mBlockVariableUpdates )
277 QgsExpressionContext context;
281 mVariableEditor->setContext( &context );
282 mVariableEditor->setEditableScopeIndex( 2 );
285void QgsLayoutPropertiesWidget::blockSignals(
bool block )
287 mGridResolutionSpinBox->blockSignals( block );
288 mOffsetXSpinBox->blockSignals( block );
289 mOffsetYSpinBox->blockSignals( block );
290 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.