Skip to content

Commit

Permalink
Fix some multiple updates from gui, squash some undo commands
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 17, 2017
1 parent db17c2c commit 8f0144b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app/layout/qgslayoutpagepropertieswidget.cpp
Expand Up @@ -81,6 +81,7 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q

void QgsLayoutPagePropertiesWidget::pageSizeChanged( int )
{
mBlockPageUpdate = true;
if ( mPageSizeComboBox->currentData().toString().isEmpty() )
{
//custom size
Expand Down Expand Up @@ -111,6 +112,7 @@ void QgsLayoutPagePropertiesWidget::pageSizeChanged( int )
}
mSettingPresetSize = false;
}
mBlockPageUpdate = false;
updatePageSize();
}

Expand Down Expand Up @@ -145,12 +147,17 @@ void QgsLayoutPagePropertiesWidget::orientationChanged( int )

void QgsLayoutPagePropertiesWidget::updatePageSize()
{
if ( mBlockPageUpdate )
return;

mPage->layout()->undoStack()->beginMacro( tr( "Change Page Size" ) );
mPage->layout()->pageCollection()->beginPageSizeChange();
mPage->layout()->undoStack()->beginCommand( mPage, tr( "Change Page Size" ), 1 + mPage->layout()->pageCollection()->pageNumber( mPage ) );
mPage->setPageSize( QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() ) );
mPage->layout()->undoStack()->endCommand();
mPage->layout()->pageCollection()->reflow();
mPage->layout()->pageCollection()->endPageSizeChange();
mPage->layout()->undoStack()->endMacro();
}

void QgsLayoutPagePropertiesWidget::setToCustomSize()
Expand Down Expand Up @@ -186,7 +193,7 @@ void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
QString pageSize = QgsApplication::pageSizeRegistry()->find( paperSize );
if ( !pageSize.isEmpty() )
{
mPageSizeComboBox->setCurrentIndex( mPageSizeComboBox->findData( pageSize ) );
whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->findData( pageSize ) );
mLockAspectRatio->setEnabled( false );
mLockAspectRatio->setLocked( false );
mSizeUnitsComboBox->setEnabled( false );
Expand All @@ -195,7 +202,7 @@ void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
else
{
// custom
mPageSizeComboBox->setCurrentIndex( mPageSizeComboBox->count() - 1 );
whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
mLockAspectRatio->setEnabled( true );
mSizeUnitsComboBox->setEnabled( true );
mPageOrientationComboBox->setEnabled( false );
Expand Down
1 change: 1 addition & 0 deletions src/app/layout/qgslayoutpagepropertieswidget.h
Expand Up @@ -58,6 +58,7 @@ class QgsLayoutPagePropertiesWidget : public QgsLayoutItemBaseWidget, private Ui
QgsLayoutMeasurementConverter mConverter;

bool mSettingPresetSize = false;
bool mBlockPageUpdate = false;

void showCurrentPageSize();

Expand Down
2 changes: 2 additions & 0 deletions src/core/layout/qgslayout.cpp
Expand Up @@ -700,10 +700,12 @@ QList<QgsLayoutItem *> QgsLayout::ungroupItems( QgsLayoutItemGroup *group )

void QgsLayout::refresh()
{
mUndoStack->blockCommands( true );
mPageCollection->beginPageSizeChange();
emit refreshed();
mPageCollection->reflow();
mPageCollection->endPageSizeChange();
mUndoStack->blockCommands( false );
update();
}

Expand Down

0 comments on commit 8f0144b

Please sign in to comment.