Index: python/gui/qgsmapcanvas.sip =================================================================== --- python/gui/qgsmapcanvas.sip (revision 12262) +++ python/gui/qgsmapcanvas.sip (working copy) @@ -93,6 +93,9 @@ //! Zoom to the next extent (view) void zoomToNextExtent(); + // ! Clears the list of extents and sets current extent as first item + void clearExtentHistory(); + /** Zoom to the extent of the selected features of current (vector) layer. Added in version 1.2: optionally specify different than current layer */ void zoomToSelected(QgsVectorLayer* layer = NULL); @@ -257,6 +260,12 @@ //! Emit map tool changed event void mapToolSet(QgsMapTool *tool); + //! Emitted when zoom last status changed + void zoomLastStatusChanged( bool ); + + //! Emitted when zoom next status changed + void zoomNextStatusChanged( bool ); + protected: //! Overridden key press event Index: src/app/legend/qgslegend.cpp =================================================================== --- src/app/legend/qgslegend.cpp (revision 12262) +++ src/app/legend/qgslegend.cpp (working copy) @@ -516,7 +516,10 @@ // first layer? if ( mMapCanvas->layerCount() == 1 ) + { mMapCanvas->zoomToFullExtent(); + mMapCanvas->clearExtentHistory(); + } setCurrentItem( llayer ); //make the QTreeWidget item up-to-date doItemsLayout(); Index: src/app/qgisapp.cpp =================================================================== --- src/app/qgisapp.cpp (revision 12262) +++ src/app/qgisapp.cpp (working copy) @@ -466,6 +466,7 @@ QgsDebugMsg( QgsApplication::showSettings() ); QgsDebugMsg( "\n--------------------------\n\n\n" ); mMapCanvas->freeze( false ); + mMapCanvas->clearExtentHistory(); // reset zoomnext/zoomlast mLastComposerId = 0; } // QgisApp ctor @@ -1802,6 +1803,10 @@ connect( mActionRedo, SIGNAL( triggered() ), mUndoWidget, SLOT( redo() ) ); connect( mUndoWidget, SIGNAL( undoStackChanged() ), this, SLOT( updateUndoActions() ) ); + // Connect status from ZoomLast/ZoomNext to corresponding action + connect( mMapCanvas, SIGNAL( zoomLastStatusChanged( bool ) ), mActionZoomLast, SLOT( setEnabled( bool ) ) ); + connect( mMapCanvas, SIGNAL( zoomNextStatusChanged( bool ) ), mActionZoomNext, SLOT( setEnabled( bool ) ) ); + // Monitor change of project path connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), this, SLOT( projectChanged( const QDomDocument & ) ) ); @@ -3193,6 +3198,7 @@ mMapCanvas->freeze( false ); mMapCanvas->refresh(); + mMapCanvas->clearExtentHistory(); mMapCanvas->mapRenderer()->setProjectionsEnabled( FALSE ); Index: src/gui/qgsmapcanvas.cpp =================================================================== --- src/gui/qgsmapcanvas.cpp (revision 12262) +++ src/gui/qgsmapcanvas.cpp (working copy) @@ -504,9 +504,20 @@ mLastExtent.removeAt( i ); } + mLastExtent.append( extent() ) ; - mLastExtent.append( extent() ) ; + // adjust history to no more than 20 + if ( mLastExtent.size() > 20 ) + { + mLastExtent.removeAt( 0 ); + } + + // the last item is the current extent mLastExtentIndex = mLastExtent.size() - 1; + + // update controls' enabled state + emit zoomLastStatusChanged( mLastExtentIndex > 0 ); + emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 ); // notify canvas items of change updateCanvasItemPositions(); @@ -558,7 +569,7 @@ return; } - if ( mLastExtentIndex > 1 ) + if ( mLastExtentIndex > 0 ) { mLastExtentIndex--; mMapRenderer->setExtent( mLastExtent[ mLastExtentIndex ] ); @@ -566,9 +577,12 @@ updateScale(); if ( mMapOverview ) mMapOverview->drawExtentRect(); + refresh(); + // update controls' enabled state + emit zoomLastStatusChanged( mLastExtentIndex > 0 ); + emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 ); } - refresh(); } // zoomToPreviousExtent void QgsMapCanvas::zoomToNextExtent() @@ -585,10 +599,22 @@ updateScale(); if ( mMapOverview ) mMapOverview->drawExtentRect(); + refresh(); + // update controls' enabled state + emit zoomLastStatusChanged( mLastExtentIndex > 0 ); + emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 ); } - refresh(); }// zoomToNextExtent +void QgsMapCanvas::clearExtentHistory() +{ + mLastExtent.clear(); // clear the zoom history list + mLastExtent.append( extent() ) ; // set the current extent in the list + mLastExtentIndex = mLastExtent.size() - 1; + // update controls' enabled state + emit zoomLastStatusChanged( mLastExtentIndex > 0 ); + emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 ); +}// clearExtentHistory bool QgsMapCanvas::hasCrsTransformEnabled() @@ -1340,6 +1366,7 @@ { QDomNode node = nodes.item( 0 ); mMapRenderer->readXML( node ); + clearExtentHistory(); // clear the extent history on project load } else { Index: src/gui/qgsmapcanvas.h =================================================================== --- src/gui/qgsmapcanvas.h (revision 12262) +++ src/gui/qgsmapcanvas.h (working copy) @@ -147,6 +147,9 @@ //! Zoom to the Next extent (view) void zoomToNextExtent(); + // ! Clears the list of extents and sets current extent as first item + void clearExtentHistory(); + /** Zoom to the extent of the selected features of current (vector) layer. Added in version 1.2: optionally specify different than current layer */ void zoomToSelected(QgsVectorLayer* layer = NULL); @@ -321,6 +324,12 @@ //! Emitted when selection in any layer gets changed void selectionChanged( QgsMapLayer * layer ); + //! Emitted when zoom last status changed + void zoomLastStatusChanged( bool ); + + //! Emitted when zoom next status changed + void zoomNextStatusChanged( bool ); + protected: //! Overridden key press event void keyPressEvent( QKeyEvent * e );