Skip to content
Permalink
Browse files

Add undo/redo for item move with cursor. Prevent item command merge f…

…or different items
  • Loading branch information
mhugent committed Jun 29, 2012
1 parent 0a9204c commit 663f5ad0a17ee68c2d42fd685348f6f8a22c4808
@@ -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;
}
@@ -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;
@@ -108,7 +110,8 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
ArrowOutlineWidth,
ArrowHeadWidth,
//item
ItemOutlineWidth
ItemOutlineWidth,
ItemMove
};

QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text );
@@ -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();
}
}
}

0 comments on commit 663f5ad

Please sign in to comment.
You can’t perform that action at this time.