Skip to content

Commit

Permalink
Fix layout crash when resizing frames
Browse files Browse the repository at this point in the history
Fix #46575

QgsLayoutPageCollection::endPageSizeChange() calls attemptMove()
which emits sizePositionChanged() which may delete frames inside
QgsLayoutMultiFrame::recalculateFrameSizes(), so we check if the
frame still exists before issuing endCommand() because endCommand()
calls QgsLayoutItemUndoCommand::saveState() that ASSERT to have
a valid item in the layout (but the item was deleted!).

The change in src/core/layout/qgslayoutmultiframe.cpp
suppresses a Qt warning when an invalid list index was used.
  • Loading branch information
elpaso authored and github-actions[bot] committed Jan 28, 2022
1 parent 572cb3a commit d27bf67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/core/layout/qgslayoutmultiframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ void QgsLayoutMultiFrame::removeFrame( int i, const bool removeEmptyPages )
mLayout->undoStack()->blockCommands( false );
mIsRecalculatingSize = false;
}

if ( i >= mFrameItems.count() )
{
return;
}

mFrameItems.removeAt( i );
}

Expand Down
17 changes: 14 additions & 3 deletions src/core/layout/qgslayoutpagecollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ void QgsLayoutPageCollection::endPageSizeChange()
{
for ( auto it = mPreviousItemPositions.constBegin(); it != mPreviousItemPositions.constEnd(); ++it )
{
if ( QgsLayoutItem *item = mLayout->itemByUuid( it.key() ) )
const QString key { it.key() };
if ( QgsLayoutItem *item = mLayout->itemByUuid( key ) )
{
if ( !mBlockUndoCommands )
item->beginCommand( QString() );

item->attemptMove( it.value().second, true, false, it.value().first );
if ( !mBlockUndoCommands )
item->endCommand();

// Item might have been deleted
if ( mLayout->itemByUuid( key ) )
{
if ( !mBlockUndoCommands )
item->endCommand();
}
else
{
item->cancelCommand();
}
}
}
mPreviousItemPositions.clear();
Expand Down

0 comments on commit d27bf67

Please sign in to comment.