Skip to content

Commit 978dbb5

Browse files
author
mhugent
committed
Apply patch #1716 (improvements to ZoomLast, ZoomNext tools) from Smizuno
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12279 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 76abb78 commit 978dbb5

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

python/gui/qgsmapcanvas.sip

+11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class QgsMapCanvas : QGraphicsView
9393
//! Zoom to the next extent (view)
9494
void zoomToNextExtent();
9595

96+
// ! Clears the list of extents and sets current extent as first item
97+
void clearExtentHistory();
98+
9699
/** Zoom to the extent of the selected features of current (vector) layer.
97100
Added in version 1.2: optionally specify different than current layer */
98101
void zoomToSelected(QgsVectorLayer* layer = NULL);
@@ -257,6 +260,14 @@ class QgsMapCanvas : QGraphicsView
257260
//! Emit map tool changed event
258261
void mapToolSet(QgsMapTool *tool);
259262

263+
//! Emitted when zoom last status changed
264+
//! @note: this signal was added in version 1.4
265+
void zoomLastStatusChanged( bool );
266+
267+
//! Emitted when zoom next status changed
268+
//! @note: this signal was added in version 1.4
269+
void zoomNextStatusChanged( bool );
270+
260271
protected:
261272

262273
//! Overridden key press event

src/app/legend/qgslegend.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,10 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
516516

517517
// first layer?
518518
if ( mMapCanvas->layerCount() == 1 )
519+
{
519520
mMapCanvas->zoomToFullExtent();
521+
mMapCanvas->clearExtentHistory();
522+
}
520523
setCurrentItem( llayer );
521524
//make the QTreeWidget item up-to-date
522525
doItemsLayout();

src/app/qgisapp.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl )
466466
QgsDebugMsg( QgsApplication::showSettings() );
467467
QgsDebugMsg( "\n--------------------------\n\n\n" );
468468
mMapCanvas->freeze( false );
469+
mMapCanvas->clearExtentHistory(); // reset zoomnext/zoomlast
469470
mLastComposerId = 0;
470471
} // QgisApp ctor
471472

@@ -1802,6 +1803,10 @@ void QgisApp::setupConnections()
18021803
connect( mActionRedo, SIGNAL( triggered() ), mUndoWidget, SLOT( redo() ) );
18031804
connect( mUndoWidget, SIGNAL( undoStackChanged() ), this, SLOT( updateUndoActions() ) );
18041805

1806+
// Connect status from ZoomLast/ZoomNext to corresponding action
1807+
connect( mMapCanvas, SIGNAL( zoomLastStatusChanged( bool ) ), mActionZoomLast, SLOT( setEnabled( bool ) ) );
1808+
connect( mMapCanvas, SIGNAL( zoomNextStatusChanged( bool ) ), mActionZoomNext, SLOT( setEnabled( bool ) ) );
1809+
18051810
// Monitor change of project path
18061811
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
18071812
this, SLOT( projectChanged( const QDomDocument & ) ) );
@@ -3193,6 +3198,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
31933198

31943199
mMapCanvas->freeze( false );
31953200
mMapCanvas->refresh();
3201+
mMapCanvas->clearExtentHistory();
31963202

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

src/gui/qgsmapcanvas.cpp

+31-4
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,20 @@ void QgsMapCanvas::setExtent( QgsRectangle const & r )
504504
mLastExtent.removeAt( i );
505505
}
506506

507-
508507
mLastExtent.append( extent() ) ;
508+
509+
// adjust history to no more than 20
510+
if ( mLastExtent.size() > 20 )
511+
{
512+
mLastExtent.removeAt( 0 );
513+
}
514+
515+
// the last item is the current extent
509516
mLastExtentIndex = mLastExtent.size() - 1;
517+
518+
// update controls' enabled state
519+
emit zoomLastStatusChanged( mLastExtentIndex > 0 );
520+
emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
510521
// notify canvas items of change
511522
updateCanvasItemPositions();
512523

@@ -558,17 +569,20 @@ void QgsMapCanvas::zoomToPreviousExtent()
558569
return;
559570
}
560571

561-
if ( mLastExtentIndex > 1 )
572+
if ( mLastExtentIndex > 0 )
562573
{
563574
mLastExtentIndex--;
564575
mMapRenderer->setExtent( mLastExtent[mLastExtentIndex] );
565576
emit extentsChanged();
566577
updateScale();
567578
if ( mMapOverview )
568579
mMapOverview->drawExtentRect();
580+
refresh();
581+
// update controls' enabled state
582+
emit zoomLastStatusChanged( mLastExtentIndex > 0 );
583+
emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
569584
}
570585

571-
refresh();
572586
} // zoomToPreviousExtent
573587

574588
void QgsMapCanvas::zoomToNextExtent()
@@ -585,10 +599,22 @@ void QgsMapCanvas::zoomToNextExtent()
585599
updateScale();
586600
if ( mMapOverview )
587601
mMapOverview->drawExtentRect();
602+
refresh();
603+
// update controls' enabled state
604+
emit zoomLastStatusChanged( mLastExtentIndex > 0 );
605+
emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
588606
}
589-
refresh();
590607
}// zoomToNextExtent
591608

609+
void QgsMapCanvas::clearExtentHistory()
610+
{
611+
mLastExtent.clear(); // clear the zoom history list
612+
mLastExtent.append( extent() ) ; // set the current extent in the list
613+
mLastExtentIndex = mLastExtent.size() - 1;
614+
// update controls' enabled state
615+
emit zoomLastStatusChanged( mLastExtentIndex > 0 );
616+
emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
617+
}// clearExtentHistory
592618

593619

594620
bool QgsMapCanvas::hasCrsTransformEnabled()
@@ -1340,6 +1366,7 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )
13401366
{
13411367
QDomNode node = nodes.item( 0 );
13421368
mMapRenderer->readXML( node );
1369+
clearExtentHistory(); // clear the extent history on project load
13431370
}
13441371
else
13451372
{

src/gui/qgsmapcanvas.h

+11
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
147147
//! Zoom to the Next extent (view)
148148
void zoomToNextExtent();
149149

150+
// ! Clears the list of extents and sets current extent as first item
151+
void clearExtentHistory();
152+
150153
/** Zoom to the extent of the selected features of current (vector) layer.
151154
Added in version 1.2: optionally specify different than current layer */
152155
void zoomToSelected( QgsVectorLayer* layer = NULL );
@@ -321,6 +324,14 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
321324
//! Emitted when selection in any layer gets changed
322325
void selectionChanged( QgsMapLayer * layer );
323326

327+
//! Emitted when zoom last status changed
328+
//! @note: this signal was added in version 1.4
329+
void zoomLastStatusChanged( bool );
330+
331+
//! Emitted when zoom next status changed
332+
//! @note: this signal was added in version 1.4
333+
void zoomNextStatusChanged( bool );
334+
324335
protected:
325336
//! Overridden key press event
326337
void keyPressEvent( QKeyEvent * e );

0 commit comments

Comments
 (0)