Skip to content

Commit 663f5ad

Browse files
committed
Add undo/redo for item move with cursor. Prevent item command merge for different items
1 parent 0a9204c commit 663f5ad

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/core/composer/qgscomposeritemcommand.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ QgsComposerMergeCommand::~QgsComposerMergeCommand()
8888
bool QgsComposerMergeCommand::mergeWith( const QUndoCommand * command )
8989
{
9090
const QgsComposerItemCommand* c = dynamic_cast<const QgsComposerItemCommand*>( command );
91-
if ( !c )
91+
if ( !c || mItem != c->item() )
9292
{
9393
return false;
9494
}

src/core/composer/qgscomposeritemcommand.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class CORE_EXPORT QgsComposerItemCommand: public QUndoCommand
4646
/**Returns true if previous state and after state are valid and different*/
4747
bool containsChange() const;
4848

49+
const QgsComposerItem* item() const { return mItem; }
50+
4951
protected:
5052
/**Target item of the command*/
5153
QgsComposerItem* mItem;
@@ -108,7 +110,8 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
108110
ArrowOutlineWidth,
109111
ArrowHeadWidth,
110112
//item
111-
ItemOutlineWidth
113+
ItemOutlineWidth,
114+
ItemMove
112115
};
113116

114117
QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text );

src/gui/qgscomposerview.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -502,28 +502,36 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
502502
{
503503
for ( ; itemIt != composerItemList.end(); ++itemIt )
504504
{
505+
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
505506
( *itemIt )->move( -1.0, 0.0 );
507+
( *itemIt )->endCommand();
506508
}
507509
}
508510
else if ( e->key() == Qt::Key_Right )
509511
{
510512
for ( ; itemIt != composerItemList.end(); ++itemIt )
511513
{
514+
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
512515
( *itemIt )->move( 1.0, 0.0 );
516+
( *itemIt )->endCommand();
513517
}
514518
}
515519
else if ( e->key() == Qt::Key_Down )
516520
{
517521
for ( ; itemIt != composerItemList.end(); ++itemIt )
518522
{
523+
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
519524
( *itemIt )->move( 0.0, 1.0 );
525+
( *itemIt )->endCommand();
520526
}
521527
}
522528
else if ( e->key() == Qt::Key_Up )
523529
{
524530
for ( ; itemIt != composerItemList.end(); ++itemIt )
525531
{
532+
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
526533
( *itemIt )->move( 0.0, -1.0 );
534+
( *itemIt )->endCommand();
527535
}
528536
}
529537
}

0 commit comments

Comments
 (0)