Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply layout page size to all pages #59182

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 26 additions & 0 deletions src/core/layout/qgslayoutpagecollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,32 @@ const QgsLayoutGuideCollection &QgsLayoutPageCollection::guides() const
return *mGuideCollection;
}

void QgsLayoutPageCollection::applyPropertiesToAllOtherPages( int sourcePage )
{
QgsLayoutItemPage *referencePage = page( sourcePage );
if ( !referencePage )
{
return;
}

mLayout->undoStack()->beginCommand( this, tr( "Apply page properties" ) );
mBlockUndoCommands = true;

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
Loading