Skip to content

Commit

Permalink
Apply patch #1716 (improvements to ZoomLast, ZoomNext tools) from Smi…
Browse files Browse the repository at this point in the history
…zuno

git-svn-id: http://svn.osgeo.org/qgis/trunk@12279 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 28, 2009
1 parent c9eb241 commit f81780d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
11 changes: 11 additions & 0 deletions python/gui/qgsmapcanvas.sip
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class QgsMapCanvas : QGraphicsView
//! 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);
Expand Down Expand Up @@ -257,6 +260,14 @@ class QgsMapCanvas : QGraphicsView
//! Emit map tool changed event
void mapToolSet(QgsMapTool *tool);

//! Emitted when zoom last status changed
//! @note: this signal was added in version 1.4
void zoomLastStatusChanged( bool );

//! Emitted when zoom next status changed
//! @note: this signal was added in version 1.4
void zoomNextStatusChanged( bool );

protected:

//! Overridden key press event
Expand Down
3 changes: 3 additions & 0 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,10 @@ void QgsLegend::addLayer( QgsMapLayer * layer )

// first layer?
if ( mMapCanvas->layerCount() == 1 )
{
mMapCanvas->zoomToFullExtent();
mMapCanvas->clearExtentHistory();
}
setCurrentItem( llayer );
//make the QTreeWidget item up-to-date
doItemsLayout();
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl )
QgsDebugMsg( QgsApplication::showSettings() );
QgsDebugMsg( "\n--------------------------\n\n\n" );
mMapCanvas->freeze( false );
mMapCanvas->clearExtentHistory(); // reset zoomnext/zoomlast
mLastComposerId = 0;
} // QgisApp ctor

Expand Down Expand Up @@ -1802,6 +1803,10 @@ void QgisApp::setupConnections()
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 & ) ) );
Expand Down Expand Up @@ -3193,6 +3198,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )

mMapCanvas->freeze( false );
mMapCanvas->refresh();
mMapCanvas->clearExtentHistory();

mMapCanvas->mapRenderer()->setProjectionsEnabled( FALSE );

Expand Down
35 changes: 31 additions & 4 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,20 @@ void QgsMapCanvas::setExtent( QgsRectangle const & r )
mLastExtent.removeAt( i );
}


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

Expand Down Expand Up @@ -558,17 +569,20 @@ void QgsMapCanvas::zoomToPreviousExtent()
return;
}

if ( mLastExtentIndex > 1 )
if ( mLastExtentIndex > 0 )
{
mLastExtentIndex--;
mMapRenderer->setExtent( mLastExtent[mLastExtentIndex] );
emit extentsChanged();
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()
Expand All @@ -585,10 +599,22 @@ void QgsMapCanvas::zoomToNextExtent()
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()
Expand Down Expand Up @@ -1340,6 +1366,7 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )
{
QDomNode node = nodes.item( 0 );
mMapRenderer->readXML( node );
clearExtentHistory(); // clear the extent history on project load
}
else
{
Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsmapcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! 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 );
Expand Down Expand Up @@ -321,6 +324,14 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Emitted when selection in any layer gets changed
void selectionChanged( QgsMapLayer * layer );

//! Emitted when zoom last status changed
//! @note: this signal was added in version 1.4
void zoomLastStatusChanged( bool );

//! Emitted when zoom next status changed
//! @note: this signal was added in version 1.4
void zoomNextStatusChanged( bool );

protected:
//! Overridden key press event
void keyPressEvent( QKeyEvent * e );
Expand Down

0 comments on commit f81780d

Please sign in to comment.