17#include "moc_qgslayoutpagepropertieswidget.cpp"
41 mPageSizeComboBox->addItem( size.displayName, size.name );
43 mPageSizeComboBox->addItem( tr(
"Custom" ) );
50 mPageOrientationComboBox->setCurrentIndex( mPageOrientationComboBox->findData( mPage->
orientation() ) );
52 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
53 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
56 mLockAspectRatio->setWidthSpinBox( mWidthSpin );
57 mLockAspectRatio->setHeightSpinBox( mHeightSpin );
62 connect( mPageSizeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPagePropertiesWidget::pageSizeChanged );
63 connect( mPageOrientationComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPagePropertiesWidget::orientationChanged );
65 connect( mWidthSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::updatePageSize );
66 connect( mHeightSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::updatePageSize );
67 connect( mWidthSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
68 connect( mHeightSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
69 connect( mExcludePageCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPagePropertiesWidget::excludeExportsToggled );
83 mExcludePageDDBtn->registerEnabledWidget( mExcludePageCheckBox,
false );
85 mSymbolButton->registerExpressionContextGenerator( mPage );
88 connect( mApplyToAllButton, &QPushButton::clicked,
this, &QgsLayoutPagePropertiesWidget::applyToAll );
95 const bool multiPage = pages->
pageCount() > 1;
99 mTitleLabel->setText( tr(
"Page (%1/%2)" ).arg( pageNumber + 1 ).arg( pages->
pageCount() ) );
103 mTitleLabel->setText( tr(
"Page" ) );
105 mApplyToAllButton->setVisible( multiPage );
109 showCurrentPageSize();
112void QgsLayoutPagePropertiesWidget::pageSizeChanged(
int )
114 mBlockPageUpdate =
true;
115 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
118 mLockAspectRatio->setEnabled(
true );
119 mSizeUnitsComboBox->setEnabled(
true );
120 mPageOrientationComboBox->setEnabled(
false );
124 mLockAspectRatio->setEnabled(
false );
125 mLockAspectRatio->setLocked(
false );
126 mSizeUnitsComboBox->setEnabled(
false );
127 mPageOrientationComboBox->setEnabled(
true );
130 mSettingPresetSize =
true;
131 switch ( mPageOrientationComboBox->currentData().toInt() )
134 mWidthSpin->setValue( convertedSize.
height() );
135 mHeightSpin->setValue( convertedSize.
width() );
139 mWidthSpin->setValue( convertedSize.
width() );
140 mHeightSpin->setValue( convertedSize.
height() );
143 mSettingPresetSize =
false;
145 mBlockPageUpdate =
false;
149void QgsLayoutPagePropertiesWidget::orientationChanged(
int )
151 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
154 const double width = mWidthSpin->value();
155 const double height = mHeightSpin->value();
156 switch ( mPageOrientationComboBox->currentData().toInt() )
159 if ( width < height )
167 if ( width > height )
178void QgsLayoutPagePropertiesWidget::updatePageSize()
180 if ( mBlockPageUpdate )
196void QgsLayoutPagePropertiesWidget::setToCustomSize()
198 if ( mSettingPresetSize )
200 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
201 mPageOrientationComboBox->setEnabled(
false );
202 pageSizeChanged( mPageSizeComboBox->currentIndex() );
205void QgsLayoutPagePropertiesWidget::symbolChanged()
212void QgsLayoutPagePropertiesWidget::excludeExportsToggled(
bool checked )
214 mPage->
beginCommand( !checked ? tr(
"Include Page in Exports" ) : tr(
"Exclude Page from Exports" ) );
219void QgsLayoutPagePropertiesWidget::refreshLayout()
224void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
228 if ( !pageSize.isEmpty() )
230 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->findData( pageSize ) );
231 mLockAspectRatio->setEnabled(
false );
232 mLockAspectRatio->setLocked(
false );
233 mSizeUnitsComboBox->setEnabled(
false );
234 mPageOrientationComboBox->setEnabled(
true );
239 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
240 mLockAspectRatio->setEnabled(
true );
241 mSizeUnitsComboBox->setEnabled(
true );
242 mPageOrientationComboBox->setEnabled(
false );
246void QgsLayoutPagePropertiesWidget::applyToAll()
static QgsPageSizeRegistry * pageSizeRegistry()
Returns the application's page size registry, used for managing layout page sizes.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
Item representing the paper in a layout.
void setPageSize(const QgsLayoutSize &size)
Sets the size of the page.
QgsLayoutSize pageSize() const
Returns the size of the page.
const QgsFillSymbol * pageStyleSymbol() const
Returns the symbol to use for drawing the page background.
Orientation orientation() const
Returns the page orientation.
void setPageStyleSymbol(QgsFillSymbol *symbol)
Sets the symbol to use for drawing the page background.
@ Landscape
Landscape orientation.
@ Portrait
Portrait orientation.
@ UndoPageSymbol
Layout page symbol change.
Base class for graphical items within a QgsLayout.
bool excludeFromExports() const
Returns whether the item should be excluded from layout exports and prints.
void beginCommand(const QString &commandText, UndoCommand command=UndoNone)
Starts new undo command for this item.
void endCommand()
Completes the current item command and push it onto the layout's undo stack.
void setExcludeFromExports(bool exclude)
Sets whether the item should be excluded from layout exports and prints.
QgsLayoutMeasurement convert(QgsLayoutMeasurement measurement, Qgis::LayoutUnit targetUnits) const
Converts a measurement from one unit to another.
const QgsLayout * layout() const
Returns the layout the object is attached to.
@ ItemWidth
Width of item.
@ ExcludeFromExports
Exclude item from exports.
@ PaperOrientation
Paper orientation.
@ ItemHeight
Height of item.
@ PresetPaperSize
Preset paper size for composition.
A manager for a collection of pages in a layout.
void reflow()
Forces the page collection to reflow the arrangement of pages, e.g.
void endPageSizeChange()
Should be called after changing any page item sizes, and preceded by a call to beginPageSizeChange().
int pageCount() const
Returns the number of pages in the collection.
void applyPropertiesToAllOtherPages(int sourcePage)
Apply the source page properties (size & background color) to all other pages.
int pageNumber(QgsLayoutItemPage *page) const
Returns the page number for the specified page, or -1 if the page is not contained in the collection.
void beginPageSizeChange()
Should be called before changing any page item sizes, and followed by a call to endPageSizeChange().
QgsLayoutPagePropertiesWidget(QWidget *parent, QgsLayoutItem *page)
Constructor for QgsLayoutPagePropertiesWidget.
void pageOrientationChanged()
Emitted when page orientation changes.
const QgsLayoutMeasurementConverter & measurementConverter() const
Returns the layout measurement converter to be used in the layout.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
double height() const
Returns the height of the size.
Qgis::LayoutUnit units() const
Returns the units for the size.
double width() const
Returns the width of the size.
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.
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 refresh()
Forces the layout, and all items contained within it, to refresh.
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...
QList< QgsPageSize > entries() const
Returns a list of page sizes in the registry.
QList< QgsPageSize > find(const QString &name) const
Finds matching page sizes from the registry, using a case insensitive match on the page size name.
A named page size for layouts.
QgsLayoutSize size
Page size.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.