Skip to content
Permalink
Browse files
Remove another restriction on QgsMapToolCapture preventing non-vector
use of this class
  • Loading branch information
nyalldawson committed Sep 8, 2021
1 parent c8ac971 commit e7faf956b6f2358bb5229547ca1992284a2a2d6b
@@ -157,7 +157,7 @@ Converts a map point to layer coordinates

:return:
0 in case of success
1 if the current layer is ``None`` or not a vector layer
1 if the current layer is ``None``
2 if the transformation failed
%End

@@ -450,26 +450,26 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )

int QgsMapToolCapture::nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
QgsDebugMsg( QStringLiteral( "no vector layer" ) );
return 1;
}
try
if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ) )
{
const QgsPointXY mapP( mapPoint.x(), mapPoint.y() ); //#spellok
layerPoint = QgsPoint( toLayerCoordinates( vlayer, mapP ) ); //transform snapped point back to layer crs //#spellok
if ( QgsWkbTypes::hasZ( vlayer->wkbType() ) )
layerPoint.addZValue( defaultZValue() );
if ( QgsWkbTypes::hasM( vlayer->wkbType() ) )
layerPoint.addMValue( defaultMValue() );
try
{
const QgsPointXY mapP( mapPoint.x(), mapPoint.y() ); //#spellok
layerPoint = QgsPoint( toLayerCoordinates( vlayer, mapP ) ); //transform snapped point back to layer crs //#spellok
if ( QgsWkbTypes::hasZ( vlayer->wkbType() ) )
layerPoint.addZValue( defaultZValue() );
if ( QgsWkbTypes::hasM( vlayer->wkbType() ) )
layerPoint.addMValue( defaultMValue() );
}
catch ( QgsCsException & )
{
QgsDebugMsg( QStringLiteral( "transformation to layer coordinate failed" ) );
return 2;
}
}
catch ( QgsCsException &cse )
else
{
Q_UNUSED( cse )
QgsDebugMsg( QStringLiteral( "transformation to layer coordinate failed" ) );
return 2;
layerPoint = QgsPoint( toLayerCoordinates( mCanvas->currentLayer(), mapPoint ) );
}

return 0;
@@ -256,7 +256,7 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
* \param[in,out] layerPoint the point in layer coordinates
* \returns
* 0 in case of success
* 1 if the current layer is NULLPTR or not a vector layer
* 1 if the current layer is NULLPTR
* 2 if the transformation failed
*/
int nextPoint( const QgsPoint &mapPoint, QgsPoint &layerPoint );
@@ -83,7 +83,11 @@ void TestQgsMapToolCapture::addVertexNonVectorLayer()
// even though we don't have a vector layer selected, adding vertices should still be allowed
QCOMPARE( tool.addVertex( QgsPoint( 5, 5 ), QgsPointLocator::Match() ), 0 );


// the nextPoint method must also accept non vector layers
QgsPoint layerPoint;
QCOMPARE( tool.nextPoint( QgsPoint( 5, 6 ), layerPoint ), 0 );
QCOMPARE( layerPoint.x(), 5.0 );
QCOMPARE( layerPoint.y(), 6.0 );
}

QGSTEST_MAIN( TestQgsMapToolCapture )

0 comments on commit e7faf95

Please sign in to comment.