18#include "moc_qgslayoutpropertieswidget.cpp"
40 mVariableEditor->setMinimumHeight( mVariableEditor->fontMetrics().height() * 15 );
42 updateSnappingElements();
44 mGridSpacingUnitsCombo->linkToWidget( mGridResolutionSpinBox );
45 mGridOffsetUnitsComboBox->linkToWidget( mOffsetXSpinBox );
46 mGridOffsetUnitsComboBox->linkToWidget( mOffsetYSpinBox );
48 blockSignals(
false );
50 connect( mSnapToleranceSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::snapToleranceChanged );
54 connect( mGridResolutionSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::gridResolutionChanged );
55 connect( mOffsetXSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::gridOffsetXChanged );
56 connect( mOffsetYSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::gridOffsetYChanged );
58 const double leftMargin = mLayout->
customProperty( QStringLiteral(
"resizeToContentsLeftMargin" ) ).toDouble();
59 const double topMargin = mLayout->
customProperty( QStringLiteral(
"resizeToContentsTopMargin" ) ).toDouble();
60 const double bottomMargin = mLayout->
customProperty( QStringLiteral(
"resizeToContentsBottomMargin" ) ).toDouble();
61 const double rightMargin = mLayout->
customProperty( QStringLiteral(
"resizeToContentsRightMargin" ) ).toDouble();
65 const bool exportWorldFile = mLayout->
customProperty( QStringLiteral(
"exportWorldFile" ), false ).toBool();
66 mGenerateWorldFileCheckBox->setChecked( exportWorldFile );
67 connect( mGenerateWorldFileCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::worldFileToggled );
69 connect( mRasterizeCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::rasterizeToggled );
70 connect( mForceVectorCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPropertiesWidget::forceVectorToggled );
72 mTopMarginSpinBox->setValue( topMargin );
73 mMarginUnitsComboBox->linkToWidget( mTopMarginSpinBox );
74 mRightMarginSpinBox->setValue( rightMargin );
75 mMarginUnitsComboBox->linkToWidget( mRightMarginSpinBox );
76 mBottomMarginSpinBox->setValue( bottomMargin );
77 mMarginUnitsComboBox->linkToWidget( mBottomMarginSpinBox );
78 mLeftMarginSpinBox->setValue( leftMargin );
79 mMarginUnitsComboBox->linkToWidget( mLeftMarginSpinBox );
80 mMarginUnitsComboBox->setUnit( marginUnit );
83 connect( mTopMarginSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
84 connect( mRightMarginSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
85 connect( mBottomMarginSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
86 connect( mLeftMarginSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::resizeMarginsChanged );
87 connect( mResizePageButton, &QPushButton::clicked,
this, &QgsLayoutPropertiesWidget::resizeToContents );
89 connect( mResolutionSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutPropertiesWidget::dpiChanged );
91 mReferenceMapComboBox->setCurrentLayout( mLayout );
124 const bool rasterize = mLayout->
customProperty( QStringLiteral(
"rasterize" ),
false ).toBool();
125 whileBlocking( mRasterizeCheckBox )->setChecked( rasterize );
127 const bool forceVectors = mLayout->
customProperty( QStringLiteral(
"forceVector" ),
false ).toBool();
128 whileBlocking( mForceVectorCheckBox )->setChecked( forceVectors );
132 mForceVectorCheckBox->setChecked(
false );
133 mForceVectorCheckBox->setEnabled(
false );
137 mForceVectorCheckBox->setEnabled(
true );
141void QgsLayoutPropertiesWidget::updateSnappingElements()
153void QgsLayoutPropertiesWidget::gridResolutionChanged(
double d )
161void QgsLayoutPropertiesWidget::gridResolutionUnitsChanged(
Qgis::LayoutUnit unit )
169void QgsLayoutPropertiesWidget::gridOffsetXChanged(
double d )
177void QgsLayoutPropertiesWidget::gridOffsetYChanged(
double d )
185void QgsLayoutPropertiesWidget::gridOffsetUnitsChanged(
Qgis::LayoutUnit unit )
193void QgsLayoutPropertiesWidget::snapToleranceChanged(
int tolerance )
198void QgsLayoutPropertiesWidget::resizeMarginsChanged()
200 mLayout->
setCustomProperty( QStringLiteral(
"resizeToContentsLeftMargin" ), mLeftMarginSpinBox->value() );
201 mLayout->
setCustomProperty( QStringLiteral(
"resizeToContentsTopMargin" ), mTopMarginSpinBox->value() );
202 mLayout->
setCustomProperty( QStringLiteral(
"resizeToContentsBottomMargin" ), mBottomMarginSpinBox->value() );
203 mLayout->
setCustomProperty( QStringLiteral(
"resizeToContentsRightMargin" ), mRightMarginSpinBox->value() );
204 mLayout->
setCustomProperty( QStringLiteral(
"imageCropMarginUnit" ),
static_cast< int >( mMarginUnitsComboBox->unit() ) );
207void QgsLayoutPropertiesWidget::resizeToContents()
212 mTopMarginSpinBox->value(),
213 mRightMarginSpinBox->value(),
214 mBottomMarginSpinBox->value() ),
215 mMarginUnitsComboBox->unit() );
220void QgsLayoutPropertiesWidget::referenceMapChanged(
QgsLayoutItem *item )
228void QgsLayoutPropertiesWidget::dpiChanged(
int value )
237void QgsLayoutPropertiesWidget::worldFileToggled()
239 mLayout->
setCustomProperty( QStringLiteral(
"exportWorldFile" ), mGenerateWorldFileCheckBox->isChecked() );
242void QgsLayoutPropertiesWidget::rasterizeToggled()
244 mLayout->
setCustomProperty( QStringLiteral(
"rasterize" ), mRasterizeCheckBox->isChecked() );
246 if ( mRasterizeCheckBox->isChecked() )
248 mForceVectorCheckBox->setChecked(
false );
249 mForceVectorCheckBox->setEnabled(
false );
253 mForceVectorCheckBox->setEnabled(
true );
257void QgsLayoutPropertiesWidget::forceVectorToggled()
259 mLayout->
setCustomProperty( QStringLiteral(
"forceVector" ), mForceVectorCheckBox->isChecked() );
262void QgsLayoutPropertiesWidget::variablesChanged()
264 mBlockVariableUpdates =
true;
266 mBlockVariableUpdates =
false;
269void QgsLayoutPropertiesWidget::updateVariables()
271 if ( mBlockVariableUpdates )
278 mVariableEditor->setContext( &context );
279 mVariableEditor->setEditableScopeIndex( 2 );
282void QgsLayoutPropertiesWidget::blockSignals(
bool block )
284 mGridResolutionSpinBox->blockSignals( block );
285 mOffsetXSpinBox->blockSignals( block );
286 mOffsetYSpinBox->blockSignals( block );
287 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.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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 setOffset(const QgsLayoutPoint &offset)
Sets the offset of the page/snap grid.
void setResolution(QgsLayoutMeasurement resolution)
Sets the page/snap grid resolution.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Layout graphical items for displaying a map.
Base class for graphical items within a QgsLayout.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
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.
void resizeToContents(const QgsMargins &margins, Qgis::LayoutUnit marginUnits)
Resizes the layout to a single page which fits the current contents of the layout.
void redraw()
Triggers a redraw for all pages.
This class provides a method of storing points, consisting of an x and y coordinate,...
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 setDpi(double dpi)
Sets the dpi for outputting the layout.
void dpiChanged()
Emitted when the context's DPI is changed.
double dpi() const
Returns the dpi for outputting the layout.
const QgsLayoutMeasurementConverter & measurementConverter() const
Returns the layout measurement converter to be used in the layout.
int snapTolerance() const
Returns the snap tolerance (in pixels) to use when snapping.
void setSnapTolerance(int snapTolerance)
Sets the snap tolerance (in pixels) to use when snapping.
void endCommand()
Saves final state of an object and pushes the active command to the undo history.
void beginMacro(const QString &commandText)
Starts a macro command, with the given descriptive commandText.
void beginCommand(QgsLayoutUndoObjectInterface *object, const QString &commandText, int id=0)
Begins a new undo command for the specified object.
void endMacro()
Ends a macro command.
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.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the layout.
QgsLayoutSnapper & snapper()
Returns a reference to the layout's snapper, which stores handles layout snap grids and lines and sna...
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
void variablesChanged()
Emitted whenever the expression variables stored in the layout have been changed.
QgsLayoutItemMap * referenceMap() const
Returns the map item which will be used to generate corresponding world files when the layout is expo...
void changed()
Emitted when properties of the layout change.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the layout.
QgsLayoutGridSettings & gridSettings()
Returns a reference to the layout's grid settings, which stores settings relating to grid appearance,...
void refresh()
Forces the layout, and all items contained within it, to refresh.
void setReferenceMap(QgsLayoutItemMap *map)
Sets the map item which will be used to generate corresponding world files when the layout is exporte...
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...
@ UndoLayoutDpi
Change layout default DPI.
The QgsMargins class defines the four margins of a rectangle.
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.