Skip to content

Commit

Permalink
Apply layout page size to all pages
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ committed Oct 23, 2024
1 parent e62b17d commit 0e41c9f
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ Returns a reference to the collection's guide collection, which manages page sna
%End


void applyPropertiesToAllOtherPages( int sourcePage );
%Docstring
Apply the source page properties (size & background color) to all other pages

.. versionadded:: 3.42
%End

public slots:

void redraw();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ Returns a reference to the collection's guide collection, which manages page sna
%End


void applyPropertiesToAllOtherPages( int sourcePage );
%Docstring
Apply the source page properties (size & background color) to all other pages

.. versionadded:: 3.42
%End

public slots:

void redraw();
Expand Down
21 changes: 21 additions & 0 deletions src/core/layout/qgslayoutpagecollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,27 @@ const QgsLayoutGuideCollection &QgsLayoutPageCollection::guides() const
return *mGuideCollection;
}

void QgsLayoutPageCollection::applyPropertiesToAllOtherPages( int sourcePage )
{
mLayout->undoStack()->beginCommand( this, tr( "Apply page properties" ) );
mBlockUndoCommands = true;
QgsLayoutItemPage *referencePage = page( sourcePage );

for ( QgsLayoutItemPage *page : mPages )
{
if ( page == referencePage )
{
continue;
}
page->setPageSize( referencePage->pageSize() );
page->setPageStyleSymbol( referencePage->pageStyleSymbol()->clone() );
}

mLayout->undoStack()->endCommand();
mBlockUndoCommands = false;
mLayout->refresh();
}

void QgsLayoutPageCollection::redraw()
{
const auto constMPages = mPages;
Expand Down
7 changes: 7 additions & 0 deletions src/core/layout/qgslayoutpagecollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,13 @@ class CORE_EXPORT QgsLayoutPageCollection : public QObject, public QgsLayoutSeri
*/
SIP_SKIP const QgsLayoutGuideCollection &guides() const;

/**
* Apply the source page properties (size & background color) to all other pages
*
* \since QGIS 3.42
*/
void applyPropertiesToAllOtherPages( int sourcePage );

public slots:

/**
Expand Down
13 changes: 12 additions & 1 deletion src/gui/layout/qgslayoutpagepropertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q

mSymbolButton->registerExpressionContextGenerator( mPage );
mSymbolButton->setLayer( coverageLayer() );

connect( mApplyToAllButton, &QPushButton::clicked, this, &QgsLayoutPagePropertiesWidget::applyToAll );

if ( mPage->layout() )
{
connect( &mPage->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mSymbolButton, &QgsSymbolButton::setLayer );

QgsLayoutPageCollection *pages = mPage->layout()->pageCollection();
if ( pages->pageCount() > 1 )
const bool multiPage = pages->pageCount() > 1;
if ( multiPage )
{
const int pageNumber = mPage->layout()->pageCollection()->pageNumber( mPage );
mTitleLabel->setText( tr( "Page (%1/%2)" ).arg( pageNumber + 1 ).arg( pages->pageCount() ) );
Expand All @@ -97,6 +101,7 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q
{
mTitleLabel->setText( tr( "Page" ) );
}
mApplyToAllButton->setVisible( multiPage );

}

Expand Down Expand Up @@ -236,3 +241,9 @@ void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
mPageOrientationComboBox->setEnabled( false );
}
}

void QgsLayoutPagePropertiesWidget::applyToAll()
{
QgsLayoutPageCollection *pages = mPage->layout()->pageCollection();
pages->applyPropertiesToAllOtherPages( pages->pageNumber( mPage ) );
}
1 change: 1 addition & 0 deletions src/gui/layout/qgslayoutpagepropertieswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class GUI_EXPORT QgsLayoutPagePropertiesWidget : public QgsLayoutItemBaseWidget,
void symbolChanged();
void excludeExportsToggled( bool checked );
void refreshLayout();
void applyToAll();

private:

Expand Down
57 changes: 33 additions & 24 deletions src/ui/layout/qgslayoutpagepropertieswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>385</width>
<width>407</width>
<height>405</height>
</rect>
</property>
Expand Down Expand Up @@ -86,7 +86,7 @@
<property name="value">
<double>100.000000000000000</double>
</property>
<property name="showClearButton">
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
Expand All @@ -105,7 +105,7 @@
<property name="value">
<double>100.000000000000000</double>
</property>
<property name="showClearButton">
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
Expand Down Expand Up @@ -213,20 +213,14 @@
</layout>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Background</string>
</property>
</spacer>
</widget>
</item>
<item row="1" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="mExcludePageCheckBox">
Expand Down Expand Up @@ -263,14 +257,7 @@
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Background</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<widget class="QgsSymbolButton" name="mSymbolButton">
<property name="enabled">
<bool>true</bool>
Expand All @@ -292,6 +279,29 @@
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="mApplyToAllButton">
<property name="toolTip">
<string>Resets all other pages' size and background color to match this page</string>
</property>
<property name="text">
<string>Apply to all Pages</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -338,7 +348,6 @@
<tabstop>mSizeUnitsComboBox</tabstop>
<tabstop>mExcludePageCheckBox</tabstop>
<tabstop>mExcludePageDDBtn</tabstop>
<tabstop>mSymbolButton</tabstop>
</tabstops>
<resources/>
<connections/>
Expand Down

0 comments on commit 0e41c9f

Please sign in to comment.