25 : QDialog( parent, flags )
31 mPageOrientationComboBox->setCurrentIndex( 1 );
36 mPageSizeComboBox->addItem( size.displayName, size.name );
38 mPageSizeComboBox->addItem( tr(
"Custom" ) );
39 mPageSizeComboBox->setCurrentIndex( mPageSizeComboBox->findData( QStringLiteral(
"A4" ) ) );
40 pageSizeChanged( mPageSizeComboBox->currentIndex() );
41 orientationChanged( 1 );
43 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
44 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
46 mLockAspectRatio->setWidthSpinBox( mWidthSpin );
47 mLockAspectRatio->setHeightSpinBox( mHeightSpin );
49 connect( mPositionComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutAddPagesDialog::positionChanged );
50 mExistingPageSpinBox->setEnabled(
false );
52 connect( mPageSizeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutAddPagesDialog::pageSizeChanged );
53 connect( mPageOrientationComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutAddPagesDialog::orientationChanged );
55 connect( mWidthSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutAddPagesDialog::setToCustomSize );
56 connect( mHeightSpin,
static_cast< void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutAddPagesDialog::setToCustomSize );
58 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsLayoutAddPagesDialog::showHelp );
64 mSizeUnitsComboBox->setConverter( &mConverter );
66 mSizeUnitsComboBox->setUnit( layout->
units() );
71 return mPagesSpinBox->value();
76 return static_cast< PagePosition >( mPositionComboBox->currentIndex() );
81 return mExistingPageSpinBox->value();
86 return QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
89void QgsLayoutAddPagesDialog::positionChanged(
int index )
91 mExistingPageSpinBox->setEnabled( index != 2 );
94void QgsLayoutAddPagesDialog::pageSizeChanged(
int )
96 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
99 mLockAspectRatio->setEnabled(
true );
100 mSizeUnitsComboBox->setEnabled(
true );
101 mPageOrientationComboBox->setEnabled(
false );
105 mLockAspectRatio->setEnabled(
false );
106 mLockAspectRatio->setLocked(
false );
107 mSizeUnitsComboBox->setEnabled(
false );
108 mPageOrientationComboBox->setEnabled(
true );
111 mSettingPresetSize =
true;
112 switch ( mPageOrientationComboBox->currentData().toInt() )
115 mWidthSpin->setValue( convertedSize.
height() );
116 mHeightSpin->setValue( convertedSize.
width() );
120 mWidthSpin->setValue( convertedSize.
width() );
121 mHeightSpin->setValue( convertedSize.
height() );
124 mSettingPresetSize =
false;
128void QgsLayoutAddPagesDialog::orientationChanged(
int )
130 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
133 const double width = mWidthSpin->value();
134 const double height = mHeightSpin->value();
135 switch ( mPageOrientationComboBox->currentData().toInt() )
138 if ( width < height )
146 if ( width > height )
155void QgsLayoutAddPagesDialog::setToCustomSize()
157 if ( mSettingPresetSize )
159 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
160 mPageOrientationComboBox->setEnabled(
false );
161 mLockAspectRatio->setEnabled(
true );
162 mSizeUnitsComboBox->setEnabled(
true );
165void QgsLayoutAddPagesDialog::showHelp()
167 QgsHelp::openHelp( QStringLiteral(
"print_composer/overview_composer.html#working-with-the-page-properties" ) );
static QgsPageSizeRegistry * pageSizeRegistry()
Returns the application's page size registry, used for managing layout page sizes.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
int numberPages() const
Returns the number of pages to insert.
QgsLayoutAddPagesDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsLayoutAddPagesDialog.
void setLayout(QgsLayout *layout)
Sets the layout associated with the dialog.
PagePosition
Page insertion positions.
PagePosition pagePosition() const
Returns the position at which to insert the new pages.
QgsLayoutSize pageSize() const
Returns the desired page size.
int beforePage() const
Returns the page number for which new pages should be inserted before/after.
@ Landscape
Landscape orientation.
@ Portrait
Portrait orientation.
QgsLayoutMeasurement convert(QgsLayoutMeasurement measurement, QgsUnitTypes::LayoutUnit targetUnits) const
Converts a measurement from one unit to another.
int pageCount() const
Returns the number of pages in the collection.
const QgsLayoutMeasurementConverter & measurementConverter() const
Returns the layout measurement converter to be used in the layout.
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.
double width() const
Returns the width of the size.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
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.
QgsUnitTypes::LayoutUnit units() const
Returns the native units for 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.