26#include "moc_qgslayoutaddpagesdialog.cpp"
29 : QDialog( parent, flags )
35 mPageOrientationComboBox->setCurrentIndex( 1 );
40 mPageSizeComboBox->addItem( size.displayName, size.name );
42 mPageSizeComboBox->addItem( tr(
"Custom" ) );
43 mPageSizeComboBox->setCurrentIndex( mPageSizeComboBox->findData( QStringLiteral(
"A4" ) ) );
44 pageSizeChanged( mPageSizeComboBox->currentIndex() );
45 orientationChanged( 1 );
47 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
48 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
50 mLockAspectRatio->setWidthSpinBox( mWidthSpin );
51 mLockAspectRatio->setHeightSpinBox( mHeightSpin );
53 connect( mPositionComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutAddPagesDialog::positionChanged );
54 mExistingPageSpinBox->setEnabled(
false );
56 connect( mPageSizeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutAddPagesDialog::pageSizeChanged );
57 connect( mPageOrientationComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutAddPagesDialog::orientationChanged );
59 connect( mWidthSpin,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutAddPagesDialog::setToCustomSize );
60 connect( mHeightSpin,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutAddPagesDialog::setToCustomSize );
62 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsLayoutAddPagesDialog::showHelp );
68 mSizeUnitsComboBox->setConverter( &mConverter );
70 mSizeUnitsComboBox->setUnit( layout->
units() );
75 return mPagesSpinBox->value();
80 return static_cast<PagePosition>( mPositionComboBox->currentIndex() );
85 return mExistingPageSpinBox->value();
90 return QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
93void QgsLayoutAddPagesDialog::positionChanged(
int index )
95 mExistingPageSpinBox->setEnabled( index != 2 );
98void QgsLayoutAddPagesDialog::pageSizeChanged(
int )
100 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
103 mLockAspectRatio->setEnabled(
true );
104 mSizeUnitsComboBox->setEnabled(
true );
105 mPageOrientationComboBox->setEnabled(
false );
109 mLockAspectRatio->setEnabled(
false );
110 mLockAspectRatio->setLocked(
false );
111 mSizeUnitsComboBox->setEnabled(
false );
112 mPageOrientationComboBox->setEnabled(
true );
114 const QgsLayoutSize convertedSize = mConverter.convert( size.
size, mSizeUnitsComboBox->unit() );
115 mSettingPresetSize =
true;
116 switch ( mPageOrientationComboBox->currentData().toInt() )
119 mWidthSpin->setValue( convertedSize.
height() );
120 mHeightSpin->setValue( convertedSize.
width() );
124 mWidthSpin->setValue( convertedSize.
width() );
125 mHeightSpin->setValue( convertedSize.
height() );
128 mSettingPresetSize =
false;
132void QgsLayoutAddPagesDialog::orientationChanged(
int )
134 if ( mPageSizeComboBox->currentData().toString().isEmpty() )
137 const double width = mWidthSpin->value();
138 const double height = mHeightSpin->value();
139 switch ( mPageOrientationComboBox->currentData().toInt() )
142 if ( width < height )
150 if ( width > height )
159void QgsLayoutAddPagesDialog::setToCustomSize()
161 if ( mSettingPresetSize )
163 whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
164 mPageOrientationComboBox->setEnabled(
false );
165 mLockAspectRatio->setEnabled(
true );
166 mSizeUnitsComboBox->setEnabled(
true );
169void QgsLayoutAddPagesDialog::showHelp()
171 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.
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.
Provides a method of storing sizes, consisting of a width and height, for use in QGIS layouts.
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.
Qgis::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.