Skip to content
Permalink
Browse files

Added undo/redo buttons in composer, fix undo problems when deleting …

…grouped items

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14831 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Dec 3, 2010
1 parent bd06cda commit 75c686bdc62b1b05df5fb65325e7bc090420bdd2
@@ -151,6 +151,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
viewMenu->addAction( mActionZoomIn );
viewMenu->addAction( mActionZoomOut );
viewMenu->addAction( mActionZoomAll );
viewMenu->addAction( mActionUndo );
viewMenu->addAction( mActionRedo );
viewMenu->addSeparator();
viewMenu->addAction( mActionRefreshView );

@@ -198,7 +200,17 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
mView = new QgsComposerView( mViewFrame );
connectSlots();

//init undo/redo buttons
mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );
mActionUndo->setEnabled( false );
mActionRedo->setEnabled( false );
if ( mComposition->undoStack() )
{
connect( mComposition->undoStack(), SIGNAL( canUndoChanged( bool ) ), mActionUndo, SLOT( setEnabled( bool ) ) );
connect( mComposition->undoStack(), SIGNAL( canRedoChanged( bool ) ), mActionRedo, SLOT( setEnabled( bool ) ) );
}


mComposition->setParent( mView );
mView->setComposition( mComposition );

@@ -257,6 +269,8 @@ void QgsComposer::setupTheme()
mActionZoomIn->setIcon( QgisApp::getThemeIcon( "/mActionZoomIn.png" ) );
mActionZoomOut->setIcon( QgisApp::getThemeIcon( "/mActionZoomOut.png" ) );
mActionRefreshView->setIcon( QgisApp::getThemeIcon( "/mActionDraw.png" ) );
mActionUndo->setIcon( QgisApp::getThemeIcon( "/mActionUndo.png" ) );
mActionRedo->setIcon( QgisApp::getThemeIcon( "/mActionRedo.png" ) );
mActionAddImage->setIcon( QgisApp::getThemeIcon( "/mActionAddImage.png" ) );
mActionAddNewMap->setIcon( QgisApp::getThemeIcon( "/mActionAddMap.png" ) );
mActionAddNewLabel->setIcon( QgisApp::getThemeIcon( "/mActionLabel.png" ) );
@@ -1059,6 +1073,22 @@ void QgsComposer::on_mActionAlignBottom_triggered()
}
}

void QgsComposer::on_mActionUndo_triggered()
{
if ( mComposition && mComposition->undoStack() )
{
mComposition->undoStack()->undo();
}
}

void QgsComposer::on_mActionRedo_triggered()
{
if ( mComposition && mComposition->undoStack() )
{
mComposition->undoStack()->redo();
}
}

void QgsComposer::moveEvent( QMoveEvent *e ) { saveWindowState(); }

void QgsComposer::resizeEvent( QResizeEvent *e )
@@ -1332,9 +1362,19 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&

if ( mUndoView )
{
mUndoView->setStack( mComposition->undoStack() );
//init undo/redo buttons
mActionUndo->setEnabled( false );
mActionRedo->setEnabled( false );
if ( mComposition->undoStack() )
{
mUndoView->setStack( mComposition->undoStack() );
connect( mComposition->undoStack(), SIGNAL( canUndoChanged( bool ) ), mActionUndo, SLOT( setEnabled( bool ) ) );
connect( mComposition->undoStack(), SIGNAL( canRedoChanged( bool ) ), mActionRedo, SLOT( setEnabled( bool ) ) );
}
}



setSelectionTool();
}

@@ -203,6 +203,12 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Align selected composer items to bottom
void on_mActionAlignBottom_triggered();

//!Undo last composer change
void on_mActionUndo_triggered();

//!Redo last composer change
void on_mActionRedo_triggered();

//! Save window state
void saveWindowState();

@@ -39,7 +39,7 @@ QgsComposerShapeWidget::QgsComposerShapeWidget( QgsComposerShape* composerShape

blockAllSignals( false );

connect( mShapeComboBox, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
connect( mShapeComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGuiElementValues() ) );
}

QgsComposerShapeWidget::~QgsComposerShapeWidget()
@@ -146,10 +146,16 @@ void QgsComposerTableWidget::on_mComposerMapComboBox_activated( int index )
const QgsComposition* tableComposition = mComposerTable->composition();
if ( tableComposition )
{
mComposerTable->beginCommand( tr( "Table map changed" ) );
if ( sender() ) //only create command if called from GUI
{
mComposerTable->beginCommand( tr( "Table map changed" ) );
}
mComposerTable->setComposerMap( tableComposition->getComposerMapById( mapId ) );
mComposerTable->update();
mComposerTable->endCommand();
if ( sender() )
{
mComposerTable->endCommand();
}
}
}

@@ -31,7 +31,11 @@ QgsComposerItemGroup::~QgsComposerItemGroup()
QSet<QgsComposerItem*>::iterator itemIt = mItems.begin();
for ( ; itemIt != mItems.end(); ++itemIt )
{
emit childItemDeleted( *itemIt );
if ( *itemIt )
{
mComposition->removeItem( *itemIt );
( *itemIt )->setFlag( QGraphicsItem::ItemIsSelectable, true );
}
}
}

@@ -162,13 +166,3 @@ void QgsComposerItemGroup::drawFrame( QPainter* p )
p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
}
}

bool QgsComposerItemGroup::writeXML( QDomElement& elem, QDomDocument & doc ) const
{
return true; //soon...
}

bool QgsComposerItemGroup::readXML( const QDomElement& itemElem, const QDomDocument& doc )
{
return false; //soon...
}
@@ -48,13 +48,15 @@ class CORE_EXPORT QgsComposerItemGroup: public QgsComposerItem
* @param elem is Dom element corresponding to 'Composer' tag
* @param doc is the Dom document
*/
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
bool writeXML( QDomElement& elem, QDomDocument & doc ) const {}

/** sets state from Dom document
* @param itemElem is Dom node corresponding to item tag
* @param doc is the Dom document
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) {}

QSet<QgsComposerItem*> items() { return mItems; }

signals:
void childItemDeleted( QgsComposerItem* item );
@@ -394,9 +394,30 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
if ( !map || !map->isDrawing() ) //don't delete a composer map while it draws
{
composition()->removeItem( *itemIt );
emit itemRemoved( *itemIt );

pushAddRemoveCommand( *itemIt, tr( "Item deleted" ), QgsAddRemoveItemCommand::Removed );
QgsComposerItemGroup* itemGroup = dynamic_cast<QgsComposerItemGroup*>( *itemIt );
if ( itemGroup && composition() )
{
//add add/remove item command for every item in the group
QUndoCommand* parentCommand = new QUndoCommand( tr( "Remove item group" ) );

QSet<QgsComposerItem*> groupedItems = itemGroup->items();
QSet<QgsComposerItem*>::iterator it = groupedItems.begin();
for ( ; it != groupedItems.end(); ++it )
{
QgsAddRemoveItemCommand* subcommand = new QgsAddRemoveItemCommand( QgsAddRemoveItemCommand::Removed, *it, composition(), "", parentCommand );
connectAddRemoveCommandSignals( subcommand );
emit itemRemoved( *it );
}

composition()->undoStack()->push( parentCommand );
delete itemGroup;
emit itemRemoved( itemGroup );
}
else
{
emit itemRemoved( *itemIt );
pushAddRemoveCommand( *itemIt, tr( "Item deleted" ), QgsAddRemoveItemCommand::Removed );
}
}
}
}
@@ -591,8 +612,6 @@ void QgsComposerView::groupItems()
return; //not enough items for a group
}
QgsComposerItemGroup* itemGroup = new QgsComposerItemGroup( composition() );
//connect signal/slot to let item group tell if child items get removed
connect( itemGroup, SIGNAL( childItemDeleted( QgsComposerItem* ) ), this, SIGNAL( itemRemoved( QgsComposerItem* ) ) );

QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
for ( ; itemIter != selectionList.end(); ++itemIter )
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1145</width>
<width>1333</width>
<height>609</height>
</rect>
</property>
@@ -163,6 +163,8 @@
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="mActionRefreshView"/>
<addaction name="mActionUndo"/>
<addaction name="mActionRedo"/>
<addaction name="separator"/>
<addaction name="mActionAddNewMap"/>
<addaction name="mActionAddImage"/>
@@ -479,11 +481,38 @@
<string>Page Setup</string>
</property>
</action>
<action name="mActionUndo">
<property name="icon">
<iconset>
<normalon>:/images/themes/default/mActionUndo.png</normalon>
</iconset>
</property>
<property name="text">
<string>Undo</string>
</property>
<property name="toolTip">
<string>Revert last change</string>
</property>
</action>
<action name="mActionRedo">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionRedo.png</normaloff>:/images/themes/default/mActionRedo.png</iconset>
</property>
<property name="text">
<string>Redo</string>
</property>
<property name="toolTip">
<string>Restore last change</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>mCompositionNameComboBox</tabstop>
<tabstop>mOptionsTabWidget</tabstop>
</tabstops>
<resources/>
<resources>
<include location="../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit 75c686b

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