29#include "moc_qgslayoutpagepropertieswidget.cpp"
43 mPageSizeComboBox->addItem( size.displayName, size.name );
45 mPageSizeComboBox->addItem( tr(
"Custom" ) );
47 mWidthSpin->setValue( mPage->pageSize().width() );
48 mHeightSpin->setValue( mPage->pageSize().height() );
49 mSizeUnitsComboBox->setUnit( mPage->pageSize().units() );
50 mExcludePageCheckBox->setChecked( mPage->excludeFromExports() );
52 mPageOrientationComboBox->setCurrentIndex( mPageOrientationComboBox->findData( mPage->orientation() ) );
54 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
55 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
56 mSizeUnitsComboBox->setConverter( &mPage->layout()->renderContext().measurementConverter() );
58 mLockAspectRatio->setWidthSpinBox( mWidthSpin );
59 mLockAspectRatio->setHeightSpinBox( mHeightSpin );
62 mSymbolButton->setSymbol( mPage->pageStyleSymbol()->clone() );
64 connect( mPageSizeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPagePropertiesWidget::pageSizeChanged );
65 connect( mPageOrientationComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutPagePropertiesWidget::orientationChanged );
67 connect( mWidthSpin,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::updatePageSize );
68 connect( mHeightSpin,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::updatePageSize );
69 connect( mWidthSpin,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
70 connect( mHeightSpin,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
71 connect( mExcludePageCheckBox, &QCheckBox::toggled,
this, &QgsLayoutPagePropertiesWidget::excludeExportsToggled );
85 mExcludePageDDBtn->registerEnabledWidget( mExcludePageCheckBox,
false );
87 mSymbolButton->registerExpressionContextGenerator( mPage );
90 connect( mApplyToAllButton, &QPushButton::clicked,
this, &QgsLayoutPagePropertiesWidget::applyToAll );
92 if ( mPage->layout() )
97 const bool multiPage = pages->
pageCount() > 1;
100 const int pageNumber = mPage->layout()->pageCollection()->pageNumber( mPage );
101 mTitleLabel->setText( tr(
"Page (%1/%2)" ).arg( pageNumber + 1 ).arg( pages->
pageCount() ) );
105 mTitleLabel->setText( tr(
"Page" ) );
107 mApplyToAllButton->setVisible( multiPage );
110 showCurrentPageSize();
113void QgsLayoutPagePropertiesWidget::pageSizeChanged(
int )
115 mBlockPageUpdate =
true;
116 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
119 mLockAspectRatio->setEnabled(
true );
120 mSizeUnitsComboBox->setEnabled(
true );
121 mPageOrientationComboBox->setEnabled(
false );
125 mLockAspectRatio->setEnabled(
false );
126 mLockAspectRatio->setLocked(
false );
127 mSizeUnitsComboBox->setEnabled(
false );
128 mPageOrientationComboBox->setEnabled(
true );
130 const QgsLayoutSize convertedSize = mConverter.convert( size.
size, mSizeUnitsComboBox->unit() );
131 mSettingPresetSize =
true;
132 switch ( mPageOrientationComboBox->currentData().toInt() )
135 mWidthSpin->setValue( convertedSize.
height() );
136 mHeightSpin->setValue( convertedSize.
width() );
140 mWidthSpin->setValue( convertedSize.
width() );
141 mHeightSpin->setValue( convertedSize.
height() );
144 mSettingPresetSize =
false;
146 mBlockPageUpdate =
false;
150void QgsLayoutPagePropertiesWidget::orientationChanged(
int )
152 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
155 const double width = mWidthSpin->value();
156 const double height = mHeightSpin->value();
157 switch ( mPageOrientationComboBox->currentData().toInt() )
160 if ( width < height )
168 if ( width > height )
179void QgsLayoutPagePropertiesWidget::updatePageSize()
181 if ( mBlockPageUpdate )
184 mPage->layout()->undoStack()->beginMacro( tr(
"Change Page Size" ) );
185 mPage->layout()->pageCollection()->beginPageSizeChange();
186 mPage->layout()->undoStack()->beginCommand( mPage, tr(
"Change Page Size" ), 1 + mPage->layout()->pageCollection()->pageNumber( mPage ) );
187 mPage->setPageSize( QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() ) );
188 mPage->layout()->undoStack()->endCommand();
189 mPage->layout()->pageCollection()->reflow();
190 mPage->layout()->pageCollection()->endPageSizeChange();
191 mPage->layout()->undoStack()->endMacro();
197void QgsLayoutPagePropertiesWidget::setToCustomSize()
199 if ( mSettingPresetSize )
201 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
202 mPageOrientationComboBox->setEnabled(
false );
203 pageSizeChanged( mPageSizeComboBox->currentIndex() );
206void QgsLayoutPagePropertiesWidget::symbolChanged()
209 mPage->setPageStyleSymbol(
static_cast<QgsFillSymbol *
>( mSymbolButton->symbol() )->clone() );
210 mPage->layout()->undoStack()->endCommand();
213void QgsLayoutPagePropertiesWidget::excludeExportsToggled(
bool checked )
215 mPage->beginCommand( !checked ? tr(
"Include Page in Exports" ) : tr(
"Exclude Page from Exports" ) );
216 mPage->setExcludeFromExports( checked );
220void QgsLayoutPagePropertiesWidget::refreshLayout()
222 mPage->layout()->refresh();
225void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
227 const QgsLayoutSize paperSize = mPage->pageSize();
229 if ( !pageSize.isEmpty() )
231 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->findData( pageSize ) );
232 mLockAspectRatio->setEnabled(
false );
233 mLockAspectRatio->setLocked(
false );
234 mSizeUnitsComboBox->setEnabled(
false );
235 mPageOrientationComboBox->setEnabled(
true );
240 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
241 mLockAspectRatio->setEnabled(
true );
242 mSizeUnitsComboBox->setEnabled(
true );
243 mPageOrientationComboBox->setEnabled(
false );
247void QgsLayoutPagePropertiesWidget::applyToAll()
249 QgsLayoutPageCollection *pages = mPage->layout()->pageCollection();
static QgsPageSizeRegistry * pageSizeRegistry()
Returns the application's page size registry, used for managing layout page sizes.
Item representing the paper in a layout.
@ Landscape
Landscape orientation.
@ Portrait
Portrait orientation.
@ UndoPageSymbol
Layout page symbol change.
Base class for graphical items within a QgsLayout.
@ 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.
QgsLayout * layout() override
Returns the layout the object belongs to.
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.
QgsLayoutPagePropertiesWidget(QWidget *parent, QgsLayoutItem *page)
Constructor for QgsLayoutPagePropertiesWidget.
void pageOrientationChanged()
Emitted when page orientation changes.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
double height() const
Returns the height of the size.
double width() const
Returns the width of the size.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
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.