Skip to content

Commit

Permalink
Fix updating gui after undoing layout settings change
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 17, 2017
1 parent 2e68dd7 commit 94b63d1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions python/core/layout/qgslayout.sip
Expand Up @@ -541,6 +541,13 @@ Updates the scene bounds of the layout.

signals:

void changed();
%Docstring
Is emitted when properties of the layout change. This signal is only
emitted for settings directly managed by the layout, and is not emitted
when child items change.
%End

void variablesChanged();
%Docstring
Emitted whenever the expression variables stored in the layout have been changed.
Expand Down
9 changes: 8 additions & 1 deletion src/app/layout/qgslayoutpropertieswidget.cpp
Expand Up @@ -74,7 +74,14 @@ QgsLayoutPropertiesWidget::QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout
connect( mReferenceMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutPropertiesWidget::referenceMapChanged );

mReferenceMapComboBox->setCurrentLayout( mLayout );
mReferenceMapComboBox->setItem( mLayout->referenceMap() );

connect( mLayout, &QgsLayout::changed, this, &QgsLayoutPropertiesWidget::updateGui );
updateGui();
}

void QgsLayoutPropertiesWidget::updateGui()
{
whileBlocking( mReferenceMapComboBox )->setItem( mLayout->referenceMap() );
}

void QgsLayoutPropertiesWidget::updateSnappingElements()
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout/qgslayoutpropertieswidget.h
Expand Up @@ -30,6 +30,8 @@ class QgsLayoutPropertiesWidget: public QgsPanelWidget, private Ui::QgsLayoutWid

private slots:

void updateGui();

void gridResolutionChanged( double d );
void gridResolutionUnitsChanged( QgsUnitTypes::LayoutUnit unit );
void gridOffsetXChanged( double d );
Expand Down
7 changes: 6 additions & 1 deletion src/core/layout/qgslayout.cpp
Expand Up @@ -624,7 +624,7 @@ class QgsLayoutUndoCommand: public QgsAbstractLayoutUndoCommand
return;
}

mLayout->readXmlLayoutSettings( stateDoc.documentElement().firstChild().toElement(), stateDoc, QgsReadWriteContext() );
mLayout->readXmlLayoutSettings( stateDoc.documentElement(), stateDoc, QgsReadWriteContext() );
mLayout->project()->setDirty( true );
}

Expand Down Expand Up @@ -753,6 +753,7 @@ bool QgsLayout::readXmlLayoutSettings( const QDomElement &layoutElement, const Q
setName( layoutElement.attribute( QStringLiteral( "name" ) ) );
setUnits( QgsUnitTypes::decodeLayoutUnit( layoutElement.attribute( QStringLiteral( "units" ) ) ) );
mWorldFileMapId = layoutElement.attribute( QStringLiteral( "worldFileMap" ) );
emit changed();

return true;
}
Expand Down Expand Up @@ -848,13 +849,17 @@ bool QgsLayout::readXml( const QDomElement &layoutElement, const QDomDocument &d
return object->readXml( layoutElement, document, context );
};

blockSignals( true ); // defer changed signal to end
readXmlLayoutSettings( layoutElement, document, context );
blockSignals( false );

restore( mPageCollection.get() );
restore( &mSnapper );
restore( &mGridSettings );
addItemsFromXml( layoutElement, document, context );

emit changed();

return true;
}

Expand Down
7 changes: 7 additions & 0 deletions src/core/layout/qgslayout.h
Expand Up @@ -582,6 +582,13 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext

signals:

/**
* Is emitted when properties of the layout change. This signal is only
* emitted for settings directly managed by the layout, and is not emitted
* when child items change.
*/
void changed();

/**
* Emitted whenever the expression variables stored in the layout have been changed.
*/
Expand Down

0 comments on commit 94b63d1

Please sign in to comment.