Skip to content

Commit

Permalink
Fix digitizing features using CAD dock when layer CRS != canvas CRS
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 17, 2021
1 parent 9098591 commit 73ced5d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
Expand Up @@ -309,6 +309,15 @@ automatically populated when user clicks with left mouse button on map canvas.
The last point.
Helper for the CAD point list. The CAD point list is the list of points
currently digitized. It contains both "normal" points and intermediate points (construction mode).

.. versionadded:: 3.22
%End

QgsPoint currentPointLayerCoordinates( QgsMapLayer *layer ) const;
%Docstring
Returns the last CAD point, in a map ``layer``'s coordinates.

.. versionadded:: 3.22
%End

QgsPointXY currentPoint( bool *exists = 0 ) const /Deprecated/;
Expand Down
13 changes: 13 additions & 0 deletions src/gui/qgsadvanceddigitizingdockwidget.cpp
Expand Up @@ -1537,6 +1537,19 @@ QgsPoint QgsAdvancedDigitizingDockWidget::currentPointV2( bool *exist ) const
return QgsPoint();
}

QgsPoint QgsAdvancedDigitizingDockWidget::currentPointLayerCoordinates( QgsMapLayer *layer ) const
{
if ( pointsCount() > 0 && layer )
{
QgsPoint res = mCadPointList.value( 0 );
const QgsPointXY layerCoordinates = mMapCanvas->mapSettings().mapToLayerCoordinates( layer, res );
res.setX( layerCoordinates.x() );
res.setY( layerCoordinates.y() );
return res;
}
return QgsPoint();
}

QgsPoint QgsAdvancedDigitizingDockWidget::previousPointV2( bool *exist ) const
{
if ( exist )
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgsadvanceddigitizingdockwidget.h
Expand Up @@ -324,9 +324,18 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
* The last point.
* Helper for the CAD point list. The CAD point list is the list of points
* currently digitized. It contains both "normal" points and intermediate points (construction mode).
*
* \since QGIS 3.22
*/
QgsPoint currentPointV2( bool *exists = nullptr ) const;

/**
* Returns the last CAD point, in a map \a layer's coordinates.
*
* \since QGIS 3.22
*/
QgsPoint currentPointLayerCoordinates( QgsMapLayer *layer ) const;

/**
* The last point.
* Helper for the CAD point list. The CAD point list is the list of points
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -488,7 +488,7 @@ int QgsMapToolCapture::fetchLayerPoint( const QgsPointLocator::Match &match, Qgs
QgsVectorLayer *sourceLayer = match.layer();
if ( mCadDockWidget && mCadDockWidget->cadEnabled() )
{
layerPoint = mCadDockWidget->currentPointV2();
layerPoint = mCadDockWidget->currentPointLayerCoordinates( vlayer );

This comment has been minimized.

Copy link
@3nids

3nids Jan 3, 2022

Member

@nyalldawson this doesn't seem right to me. QgsMapToolCapture is supposed to be layer agnostic, it's QgsMapToolDigitizeFeature which is aware of the layer. Do you confirm?

return 0;
}
else
Expand Down

0 comments on commit 73ced5d

Please sign in to comment.