Skip to content

Commit

Permalink
Fix undo/redo for mouse actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent 8517cfe commit 172d484
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/gui/layout/qgslayoutmousehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
if ( mCurrentMouseMoveAction == QgsLayoutMouseHandles::MoveItem )
{
//move selected items
QUndoCommand *parentCommand = new QUndoCommand( tr( "Change item position" ) );
mLayout->undoStack()->beginMacro( tr( "Change item position" ) );

QPointF mEndHandleMovePos = scenePos();

Expand All @@ -593,30 +593,24 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
//don't move locked items
continue;
}
#if 0 //TODO
QgsComposerItemCommand *subcommand = new QgsComposerItemCommand( item, QLatin1String( "" ), parentCommand );
subcommand->savePreviousState();
#endif

mLayout->undoStack()->beginCommand( item, QString() );

// need to convert delta from layout units -> item units
QgsLayoutPoint itemPos = item->positionWithUnits();
QgsLayoutPoint deltaPos = mLayout->convertFromLayoutUnits( QPointF( deltaX, deltaY ), itemPos.units() );
itemPos.setX( itemPos.x() + deltaPos.x() );
itemPos.setY( itemPos.y() + deltaPos.y() );
item->attemptMove( itemPos );
#if 0
subcommand->saveAfterState();
#endif

mLayout->undoStack()->endCommand();
}
#if 0
mLayout->undoStack()->push( parentCommand );
mLayout->project()->setDirty( true );
#endif
mLayout->undoStack()->endMacro();
}
else if ( mCurrentMouseMoveAction != QgsLayoutMouseHandles::NoAction )
{
//resize selected items
QUndoCommand *parentCommand = new QUndoCommand( tr( "Change item size" ) );
mLayout->undoStack()->beginMacro( tr( "Change item size" ) );

//resize all selected items
const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems( false );
Expand All @@ -627,10 +621,9 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
//don't resize locked items or deselectable items (e.g., items which make up an item group)
continue;
}
#if 0
QgsComposerItemCommand *subcommand = new QgsComposerItemCommand( item, QLatin1String( "" ), parentCommand );
subcommand->savePreviousState();
#endif

mLayout->undoStack()->beginCommand( item, QString() );

QRectF itemRect;
if ( selectedItems.size() == 1 )
{
Expand All @@ -653,14 +646,10 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )

QgsLayoutSize itemSize = mLayout->convertFromLayoutUnits( itemRect.size(), item->sizeWithUnits().units() );
item->attemptResize( itemSize );
#if 0
subcommand->saveAfterState();
#endif

mLayout->undoStack()->endCommand();
}
#if 0
mLayout->undoStack()->push( parentCommand );
mLayout->project()->setDirty( true );
#endif
mLayout->undoStack()->endMacro();
}

#if 0
Expand Down

0 comments on commit 172d484

Please sign in to comment.