Skip to content

Commit

Permalink
More roboust zoom tool - prevent zooming to empty extent
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@6970 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed May 31, 2007
1 parent 825e248 commit d76cab5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/gui/qgsmaptoolzoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ QgsMapToolZoom::QgsMapToolZoom(QgsMapCanvas* canvas, bool zoomOut)

void QgsMapToolZoom::canvasMoveEvent(QMouseEvent * e)
{
if (e->state() != Qt::LeftButton)
if ( ! (e->buttons() & Qt::LeftButton) )
return;

if (!mDragging)
Expand All @@ -54,12 +54,18 @@ void QgsMapToolZoom::canvasMoveEvent(QMouseEvent * e)

void QgsMapToolZoom::canvasPressEvent(QMouseEvent * e)
{
if (e->button() != Qt::LeftButton)
return;

mZoomRect.setRect(0, 0, 0, 0);
}


void QgsMapToolZoom::canvasReleaseEvent(QMouseEvent * e)
{
if (e->button() != Qt::LeftButton)
return;

if (mDragging)
{
mDragging = false;
Expand All @@ -83,6 +89,12 @@ void QgsMapToolZoom::canvasReleaseEvent(QMouseEvent * e)
r.setYmax(ur.y());
r.normalize();

// prevent zooming to an empty extent
if (r.width() == 0 || r.height() == 0)
{
return;
}

if (mZoomOut)
{
QgsPoint cer = r.center();
Expand All @@ -91,18 +103,10 @@ void QgsMapToolZoom::canvasReleaseEvent(QMouseEvent * e)
double sf;
if (mZoomRect.width() > mZoomRect.height())
{
if(r.width() == 0)//prevent nan map extent
{
return;
}
sf = extent.width() / r.width();
}
else
{
if(r.height() == 0)//prevent nan map extent
{
return;
}
sf = extent.height() / r.height();
}
r.expand(sf);
Expand Down

0 comments on commit d76cab5

Please sign in to comment.