Skip to content
Permalink
Browse files

Fix QgsMapCanvas::xyCoordinates reports incorrect coordinates if a pan

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 527eca9684caf3269958a6ce98f914a274175931
Showing with 39 additions and 3 deletions.
  1. +7 −0 python/gui/auto_generated/qgsmaptoolpan.sip.in
  2. +20 −3 src/gui/qgsmapcanvas.cpp
  3. +5 −0 src/gui/qgsmapcanvas.h
  4. +7 −0 src/gui/qgsmaptoolpan.h
@@ -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 );
@@ -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 )
@@ -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;
}
@@ -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
@@ -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:

/**

0 comments on commit 527eca9

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