[QGIS Commit] r14831 - in trunk/qgis/src: app/composer core/composer gui ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Dec 3 07:53:22 EST 2010


Author: mhugent
Date: 2010-12-03 04:53:22 -0800 (Fri, 03 Dec 2010)
New Revision: 14831

Modified:
   trunk/qgis/src/app/composer/qgscomposer.cpp
   trunk/qgis/src/app/composer/qgscomposer.h
   trunk/qgis/src/app/composer/qgscomposershapewidget.cpp
   trunk/qgis/src/app/composer/qgscomposertablewidget.cpp
   trunk/qgis/src/core/composer/qgscomposeritemgroup.cpp
   trunk/qgis/src/core/composer/qgscomposeritemgroup.h
   trunk/qgis/src/gui/qgscomposerview.cpp
   trunk/qgis/src/ui/qgscomposerbase.ui
Log:
Added undo/redo buttons in composer, fix undo problems when deleting grouped items

Modified: trunk/qgis/src/app/composer/qgscomposer.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposer.cpp	2010-12-02 22:22:06 UTC (rev 14830)
+++ trunk/qgis/src/app/composer/qgscomposer.cpp	2010-12-03 12:53:22 UTC (rev 14831)
@@ -151,6 +151,8 @@
   viewMenu->addAction( mActionZoomIn );
   viewMenu->addAction( mActionZoomOut );
   viewMenu->addAction( mActionZoomAll );
+  viewMenu->addAction( mActionUndo );
+  viewMenu->addAction( mActionRedo );
   viewMenu->addSeparator();
   viewMenu->addAction( mActionRefreshView );
 
@@ -198,7 +200,17 @@
   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 @@
   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_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 @@
 
   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();
 }
 

Modified: trunk/qgis/src/app/composer/qgscomposer.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposer.h	2010-12-02 22:22:06 UTC (rev 14830)
+++ trunk/qgis/src/app/composer/qgscomposer.h	2010-12-03 12:53:22 UTC (rev 14831)
@@ -203,6 +203,12 @@
     //!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();
 

Modified: trunk/qgis/src/app/composer/qgscomposershapewidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposershapewidget.cpp	2010-12-02 22:22:06 UTC (rev 14830)
+++ trunk/qgis/src/app/composer/qgscomposershapewidget.cpp	2010-12-03 12:53:22 UTC (rev 14831)
@@ -39,7 +39,7 @@
 
   blockAllSignals( false );
 
-  connect( mShapeComboBox, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
+  connect( mShapeComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGuiElementValues() ) );
 }
 
 QgsComposerShapeWidget::~QgsComposerShapeWidget()

Modified: trunk/qgis/src/app/composer/qgscomposertablewidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposertablewidget.cpp	2010-12-02 22:22:06 UTC (rev 14830)
+++ trunk/qgis/src/app/composer/qgscomposertablewidget.cpp	2010-12-03 12:53:22 UTC (rev 14831)
@@ -146,10 +146,16 @@
   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();
+    }
   }
 }
 

Modified: trunk/qgis/src/core/composer/qgscomposeritemgroup.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritemgroup.cpp	2010-12-02 22:22:06 UTC (rev 14830)
+++ trunk/qgis/src/core/composer/qgscomposeritemgroup.cpp	2010-12-03 12:53:22 UTC (rev 14831)
@@ -31,7 +31,11 @@
   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 @@
     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...
-}

Modified: trunk/qgis/src/core/composer/qgscomposeritemgroup.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritemgroup.h	2010-12-02 22:22:06 UTC (rev 14830)
+++ trunk/qgis/src/core/composer/qgscomposeritemgroup.h	2010-12-03 12:53:22 UTC (rev 14831)
@@ -48,14 +48,16 @@
        * @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 );
 

Modified: trunk/qgis/src/gui/qgscomposerview.cpp
===================================================================
--- trunk/qgis/src/gui/qgscomposerview.cpp	2010-12-02 22:22:06 UTC (rev 14830)
+++ trunk/qgis/src/gui/qgscomposerview.cpp	2010-12-03 12:53:22 UTC (rev 14831)
@@ -394,9 +394,30 @@
       if ( !map || !map->isDrawing() ) //don't delete a composer map while it draws
       {
         composition()->removeItem( *itemIt );
-        emit itemRemoved( *itemIt );
+        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" ) );
 
-        pushAddRemoveCommand( *itemIt, tr( "Item deleted" ), QgsAddRemoveItemCommand::Removed );
+          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 @@
     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 )

Modified: trunk/qgis/src/ui/qgscomposerbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposerbase.ui	2010-12-02 22:22:06 UTC (rev 14830)
+++ trunk/qgis/src/ui/qgscomposerbase.ui	2010-12-03 12:53:22 UTC (rev 14831)
@@ -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>



More information about the QGIS-commit mailing list