Skip to content
Permalink
Browse files

Apply patch #1716 (improvements to ZoomLast, ZoomNext tools) from Smi…

…zuno

git-svn-id: http://svn.osgeo.org/qgis/trunk@12279 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 28, 2009
1 parent c9eb241 commit f81780d271b9f7177ab1f96449d34334dadc5912
Showing with 62 additions and 4 deletions.
  1. +11 −0 python/gui/qgsmapcanvas.sip
  2. +3 −0 src/app/legend/qgslegend.cpp
  3. +6 −0 src/app/qgisapp.cpp
  4. +31 −4 src/gui/qgsmapcanvas.cpp
  5. +11 −0 src/gui/qgsmapcanvas.h
@@ -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);
@@ -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
@@ -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();
@@ -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

@@ -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 & ) ) );
@@ -3193,6 +3198,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )

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

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

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

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

0 comments on commit f81780d

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