Skip to content

Commit 8f0144b

Browse files
committed
Fix some multiple updates from gui, squash some undo commands
1 parent db17c2c commit 8f0144b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/app/layout/qgslayoutpagepropertieswidget.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q
8181

8282
void QgsLayoutPagePropertiesWidget::pageSizeChanged( int )
8383
{
84+
mBlockPageUpdate = true;
8485
if ( mPageSizeComboBox->currentData().toString().isEmpty() )
8586
{
8687
//custom size
@@ -111,6 +112,7 @@ void QgsLayoutPagePropertiesWidget::pageSizeChanged( int )
111112
}
112113
mSettingPresetSize = false;
113114
}
115+
mBlockPageUpdate = false;
114116
updatePageSize();
115117
}
116118

@@ -145,12 +147,17 @@ void QgsLayoutPagePropertiesWidget::orientationChanged( int )
145147

146148
void QgsLayoutPagePropertiesWidget::updatePageSize()
147149
{
150+
if ( mBlockPageUpdate )
151+
return;
152+
153+
mPage->layout()->undoStack()->beginMacro( tr( "Change Page Size" ) );
148154
mPage->layout()->pageCollection()->beginPageSizeChange();
149155
mPage->layout()->undoStack()->beginCommand( mPage, tr( "Change Page Size" ), 1 + mPage->layout()->pageCollection()->pageNumber( mPage ) );
150156
mPage->setPageSize( QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() ) );
151157
mPage->layout()->undoStack()->endCommand();
152158
mPage->layout()->pageCollection()->reflow();
153159
mPage->layout()->pageCollection()->endPageSizeChange();
160+
mPage->layout()->undoStack()->endMacro();
154161
}
155162

156163
void QgsLayoutPagePropertiesWidget::setToCustomSize()
@@ -186,7 +193,7 @@ void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
186193
QString pageSize = QgsApplication::pageSizeRegistry()->find( paperSize );
187194
if ( !pageSize.isEmpty() )
188195
{
189-
mPageSizeComboBox->setCurrentIndex( mPageSizeComboBox->findData( pageSize ) );
196+
whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->findData( pageSize ) );
190197
mLockAspectRatio->setEnabled( false );
191198
mLockAspectRatio->setLocked( false );
192199
mSizeUnitsComboBox->setEnabled( false );
@@ -195,7 +202,7 @@ void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
195202
else
196203
{
197204
// custom
198-
mPageSizeComboBox->setCurrentIndex( mPageSizeComboBox->count() - 1 );
205+
whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
199206
mLockAspectRatio->setEnabled( true );
200207
mSizeUnitsComboBox->setEnabled( true );
201208
mPageOrientationComboBox->setEnabled( false );

src/app/layout/qgslayoutpagepropertieswidget.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class QgsLayoutPagePropertiesWidget : public QgsLayoutItemBaseWidget, private Ui
5858
QgsLayoutMeasurementConverter mConverter;
5959

6060
bool mSettingPresetSize = false;
61+
bool mBlockPageUpdate = false;
6162

6263
void showCurrentPageSize();
6364

src/core/layout/qgslayout.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,12 @@ QList<QgsLayoutItem *> QgsLayout::ungroupItems( QgsLayoutItemGroup *group )
700700

701701
void QgsLayout::refresh()
702702
{
703+
mUndoStack->blockCommands( true );
703704
mPageCollection->beginPageSizeChange();
704705
emit refreshed();
705706
mPageCollection->reflow();
706707
mPageCollection->endPageSizeChange();
708+
mUndoStack->blockCommands( false );
707709
update();
708710
}
709711

0 commit comments

Comments
 (0)