Add undo/redo for item move with cursor. Prevent item command merge for different items

This commit is contained in:
Marco Hugentobler 2012-06-29 11:20:04 +02:00
parent 0a9204c40d
commit 663f5ad0a1
3 changed files with 13 additions and 2 deletions

View File

@ -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;
}

View File

@ -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 );

View File

@ -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();
}
}
}