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!
  • Loading branch information
nyalldawson committed Jan 14, 2020
1 parent 8a74a3d commit 527eca9
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 @@ -45,6 +45,13 @@ constructor
virtual bool gestureEvent( QGestureEvent *e );


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

.. versionadded:: 3.12
%End

signals:

void panDistanceBearingChanged( double distance, QgsUnitTypes::DistanceUnit unit, double bearing );
Expand Down
23 changes: 20 additions & 3 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -1732,9 +1732,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 @@ -2503,3 +2506,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 @@ -1097,6 +1097,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 @@ -48,6 +48,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; }

signals:

/**
Expand Down

0 comments on commit 527eca9

Please sign in to comment.