Skip to content

Commit

Permalink
Don't create undo commands on destroying a layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 9, 2017
1 parent 6b418de commit 955742a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/layout/qgslayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ QgsLayout::QgsLayout( QgsProject *project )

QgsLayout::~QgsLayout()
{
// no need for undo commands when we're destroying the layout
mBlockUndoCommands = true;

// make sure that all layout items are removed before
// this class is deconstructed - to avoid segfaults
// when layout items access in destructor layout that isn't valid anymore
Expand Down Expand Up @@ -376,9 +379,12 @@ void QgsLayout::addLayoutItem( QgsLayoutItem *item )

void QgsLayout::removeLayoutItem( QgsLayoutItem *item )
{
QgsLayoutItemDeleteUndoCommand *deleteCommand = new QgsLayoutItemDeleteUndoCommand( item, tr( "Deleted item" ) );
std::unique_ptr< QgsLayoutItemDeleteUndoCommand > deleteCommand;
if ( !mBlockUndoCommands )
deleteCommand.reset( new QgsLayoutItemDeleteUndoCommand( item, tr( "Deleted item" ) ) );
removeLayoutItemPrivate( item );
mUndoStack->stack()->push( deleteCommand );
if ( deleteCommand )
mUndoStack->stack()->push( deleteCommand.release() );
}

QgsLayoutUndoStack *QgsLayout::undoStack()
Expand Down
2 changes: 2 additions & 0 deletions src/core/layout/qgslayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
std::unique_ptr< QgsLayoutPageCollection > mPageCollection;
std::unique_ptr< QgsLayoutUndoStack > mUndoStack;

bool mBlockUndoCommands = false;

//! Writes only the layout settings (not member settings like grid settings, etc) to XML
void writeXmlLayoutSettings( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
//! Reads only the layout settings (not member settings like grid settings, etc) from XML
Expand Down

0 comments on commit 955742a

Please sign in to comment.