Skip to content

Commit

Permalink
Fix QgsMapCanvas::xyCoordinates reports incorrect coordinates if a pan
Browse files Browse the repository at this point in the history
operation is in progress

This causes the status bar coordinates widget to show nonsense coordinates
during the pan operation. The cursor world position ISN'T changing during
a pan operation, it stuck to a fixed location!

(cherry picked from commit 527eca9)
  • Loading branch information
nyalldawson authored and nirvn committed Jan 15, 2020
1 parent ed48c55 commit 6a355b8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsmaptoolpan.sip.in
Expand Up @@ -44,6 +44,13 @@ constructor
virtual bool gestureEvent( QGestureEvent *e );


bool isDragging() const;
%Docstring
Returns ``True`` if a drag operation is in progress.

.. versionadded:: 3.12
%End

};

/************************************************************************
Expand Down
23 changes: 20 additions & 3 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -1728,9 +1728,12 @@ void QgsMapCanvas::mouseMoveEvent( QMouseEvent *e )
}
}

// show x y on status bar
mCursorPoint = getCoordinateTransform()->toMapCoordinates( mCanvasProperties->mouseLastXY );
emit xyCoordinates( mCursorPoint );
// show x y on status bar (if we are mid pan operation, then the cursor point hasn't changed!)
if ( !panOperationInProgress() )
{
mCursorPoint = getCoordinateTransform()->toMapCoordinates( mCanvasProperties->mouseLastXY );
emit xyCoordinates( mCursorPoint );
}
}

void QgsMapCanvas::setMapTool( QgsMapTool *tool, bool clean )
Expand Down Expand Up @@ -2486,3 +2489,17 @@ void QgsMapCanvas::schedulePreviewJob( int number )
} );
mPreviewTimer.start();
}

bool QgsMapCanvas::panOperationInProgress()
{
if ( mCanvasProperties->panSelectorDown )
return true;

if ( QgsMapToolPan *panTool = qobject_cast< QgsMapToolPan *>( mMapTool ) )
{
if ( panTool->isDragging() )
return true;
}

return false;
}
5 changes: 5 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -1073,6 +1073,11 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
void stopPreviewJobs();
void schedulePreviewJob( int number );

/**
* Returns TRUE if a pan operation is in progress
*/
bool panOperationInProgress();

friend class TestQgsMapCanvas;

}; // class QgsMapCanvas
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsmaptoolpan.h
Expand Up @@ -45,6 +45,13 @@ class GUI_EXPORT QgsMapToolPan : public QgsMapTool
void canvasDoubleClickEvent( QgsMapMouseEvent *e ) override;
bool gestureEvent( QGestureEvent *e ) override;

/**
* Returns TRUE if a drag operation is in progress.
*
* \since QGIS 3.12
*/
bool isDragging() const { return mDragging; }

private:

//! Flag to indicate a map canvas drag operation is taking place
Expand Down

0 comments on commit 6a355b8

Please sign in to comment.