Skip to content

Commit

Permalink
Add undo/redo for item move with cursor. Prevent item command merge f…
Browse files Browse the repository at this point in the history
…or different items
  • Loading branch information
mhugent committed Jun 29, 2012
1 parent 0a9204c commit 663f5ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposeritemcommand.cpp
Expand Up @@ -88,7 +88,7 @@ QgsComposerMergeCommand::~QgsComposerMergeCommand()
bool QgsComposerMergeCommand::mergeWith( const QUndoCommand * command )
{
const QgsComposerItemCommand* c = dynamic_cast<const QgsComposerItemCommand*>( command );
if ( !c )
if ( !c || mItem != c->item() )
{
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/composer/qgscomposeritemcommand.h
Expand Up @@ -46,6 +46,8 @@ class CORE_EXPORT QgsComposerItemCommand: public QUndoCommand
/**Returns true if previous state and after state are valid and different*/
bool containsChange() const;

const QgsComposerItem* item() const { return mItem; }

protected:
/**Target item of the command*/
QgsComposerItem* mItem;
Expand Down Expand Up @@ -108,7 +110,8 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
ArrowOutlineWidth,
ArrowHeadWidth,
//item
ItemOutlineWidth
ItemOutlineWidth,
ItemMove
};

QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text );
Expand Down
8 changes: 8 additions & 0 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -502,28 +502,36 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
{
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
( *itemIt )->move( -1.0, 0.0 );
( *itemIt )->endCommand();
}
}
else if ( e->key() == Qt::Key_Right )
{
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
( *itemIt )->move( 1.0, 0.0 );
( *itemIt )->endCommand();
}
}
else if ( e->key() == Qt::Key_Down )
{
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
( *itemIt )->move( 0.0, 1.0 );
( *itemIt )->endCommand();
}
}
else if ( e->key() == Qt::Key_Up )
{
for ( ; itemIt != composerItemList.end(); ++itemIt )
{
( *itemIt )->beginCommand( tr( "Item moved" ), QgsComposerMergeCommand::ItemMove );
( *itemIt )->move( 0.0, -1.0 );
( *itemIt )->endCommand();
}
}
}
Expand Down

0 comments on commit 663f5ad

Please sign in to comment.