Skip to content

Commit 172d484

Browse files
committedOct 6, 2017
Fix undo/redo for mouse actions
1 parent 8517cfe commit 172d484

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed
 

‎src/gui/layout/qgslayoutmousehandles.cpp

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
577577
if ( mCurrentMouseMoveAction == QgsLayoutMouseHandles::MoveItem )
578578
{
579579
//move selected items
580-
QUndoCommand *parentCommand = new QUndoCommand( tr( "Change item position" ) );
580+
mLayout->undoStack()->beginMacro( tr( "Change item position" ) );
581581

582582
QPointF mEndHandleMovePos = scenePos();
583583

@@ -593,30 +593,24 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
593593
//don't move locked items
594594
continue;
595595
}
596-
#if 0 //TODO
597-
QgsComposerItemCommand *subcommand = new QgsComposerItemCommand( item, QLatin1String( "" ), parentCommand );
598-
subcommand->savePreviousState();
599-
#endif
596+
597+
mLayout->undoStack()->beginCommand( item, QString() );
600598

601599
// need to convert delta from layout units -> item units
602600
QgsLayoutPoint itemPos = item->positionWithUnits();
603601
QgsLayoutPoint deltaPos = mLayout->convertFromLayoutUnits( QPointF( deltaX, deltaY ), itemPos.units() );
604602
itemPos.setX( itemPos.x() + deltaPos.x() );
605603
itemPos.setY( itemPos.y() + deltaPos.y() );
606604
item->attemptMove( itemPos );
607-
#if 0
608-
subcommand->saveAfterState();
609-
#endif
605+
606+
mLayout->undoStack()->endCommand();
610607
}
611-
#if 0
612-
mLayout->undoStack()->push( parentCommand );
613-
mLayout->project()->setDirty( true );
614-
#endif
608+
mLayout->undoStack()->endMacro();
615609
}
616610
else if ( mCurrentMouseMoveAction != QgsLayoutMouseHandles::NoAction )
617611
{
618612
//resize selected items
619-
QUndoCommand *parentCommand = new QUndoCommand( tr( "Change item size" ) );
613+
mLayout->undoStack()->beginMacro( tr( "Change item size" ) );
620614

621615
//resize all selected items
622616
const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems( false );
@@ -627,10 +621,9 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
627621
//don't resize locked items or deselectable items (e.g., items which make up an item group)
628622
continue;
629623
}
630-
#if 0
631-
QgsComposerItemCommand *subcommand = new QgsComposerItemCommand( item, QLatin1String( "" ), parentCommand );
632-
subcommand->savePreviousState();
633-
#endif
624+
625+
mLayout->undoStack()->beginCommand( item, QString() );
626+
634627
QRectF itemRect;
635628
if ( selectedItems.size() == 1 )
636629
{
@@ -653,14 +646,10 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
653646

654647
QgsLayoutSize itemSize = mLayout->convertFromLayoutUnits( itemRect.size(), item->sizeWithUnits().units() );
655648
item->attemptResize( itemSize );
656-
#if 0
657-
subcommand->saveAfterState();
658-
#endif
649+
650+
mLayout->undoStack()->endCommand();
659651
}
660-
#if 0
661-
mLayout->undoStack()->push( parentCommand );
662-
mLayout->project()->setDirty( true );
663-
#endif
652+
mLayout->undoStack()->endMacro();
664653
}
665654

666655
#if 0

0 commit comments

Comments
 (0)
Please sign in to comment.