Index: python/gui/qgsmapcanvas.sip =================================================================== --- python/gui/qgsmapcanvas.sip (revision 11258) +++ 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); @@ -255,6 +258,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 11258) +++ src/app/legend/qgslegend.cpp (working copy) @@ -603,7 +603,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 11258) +++ src/app/qgisapp.cpp (working copy) @@ -454,6 +454,7 @@ //finally show all the application settings as initialised above QgsApplication::showSettings(); mMapCanvas->freeze( false ); + mMapCanvas->clearExtentHistory(); // reset zoomnext/zoomlast } // QgisApp ctor @@ -1694,6 +1695,10 @@ connect( mActionUndo, SIGNAL( triggered() ), mUndoWidget, SLOT( undo() ) ); 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 ) ) ); } void QgisApp::createCanvas() @@ -3104,6 +3109,7 @@ mMapCanvas->freeze( false ); mMapCanvas->refresh(); + mMapCanvas->clearExtentHistory(); mMapCanvas->mapRenderer()->setProjectionsEnabled( FALSE ); Index: src/gui/qgsmapcanvas.cpp =================================================================== --- src/gui/qgsmapcanvas.cpp (revision 11258) +++ src/gui/qgsmapcanvas.cpp (working copy) @@ -507,6 +507,9 @@ mLastExtent.append( 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 +561,7 @@ return; } - if ( mLastExtentIndex > 1 ) + if ( mLastExtentIndex > 0 ) { mLastExtentIndex--; mMapRenderer->setExtent( mLastExtent[mLastExtentIndex] ); @@ -566,9 +569,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 +591,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() @@ -1344,6 +1362,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 11258) +++ 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); @@ -319,6 +322,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 );