Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
backport #42713
  • Loading branch information
vcloarec authored and nyalldawson committed Apr 18, 2021
1 parent 4ff8708 commit fb8c8b2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsmaptooladdcircularstring.cpp
Expand Up @@ -144,8 +144,8 @@ void QgsMapToolAddCircularString::activate()
{
//mParentTool->captureCurve() is in layer coordinates, but we need map coordinates
QgsPoint endPointLayerCoord = curve->endPoint();
QgsPointXY mapPoint = toMapCoordinates( mCanvas->currentLayer(), QgsPointXY( endPointLayerCoord.x(), endPointLayerCoord.y() ) );
mPoints.append( QgsPoint( mapPoint ) );
QgsPoint mapPoint = toMapCoordinates( mCanvas->currentLayer(), endPointLayerCoord );
mPoints.append( mapPoint );
if ( !mTempRubberBand )
{
mTempRubberBand = createGeometryRubberBand( mLayerType, true );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -600,7 +600,7 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
mCaptureLastPoint = mapPoint;
mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, mDigitizingType, firstCapturedMapPoint() );
}
else if ( mCaptureCurve.numPoints() == 0 )
else if ( mTempRubberBand->pointsCount() == 0 )
{
mCaptureLastPoint = mapPoint;
mCaptureCurve.addVertex( layerPoint );
Expand Down
37 changes: 37 additions & 0 deletions tests/src/app/testqgsmaptoolcircularstring.cpp
Expand Up @@ -42,6 +42,7 @@ class TestQgsMapToolCircularString : public QObject
void testAddCircularStringRadius();
void testAddCircularStringCurvePointWithDeletedVertex();
void testAddCircularStringRadiusWithDeletedVertex();
void testAddCircularStringAfterClassicDigitizing();

private:
QgisApp *mQgisApp = nullptr;
Expand Down Expand Up @@ -187,5 +188,41 @@ void TestQgsMapToolCircularString::testAddCircularStringRadiusWithDeletedVertex(
mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}

void TestQgsMapToolCircularString::testAddCircularStringAfterClassicDigitizing()
{
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 333 );
mLayer->startEditing();

TestQgsMapToolAdvancedDigitizingUtils utilsClassic( mParentTool );

mCanvas->setMapTool( mParentTool );
utilsClassic.mouseClick( 2, 1, Qt::LeftButton );
utilsClassic.mouseClick( 2, 0, Qt::LeftButton );
utilsClassic.mouseClick( 0, 0, Qt::LeftButton );

QgsMapToolCircularStringCurvePoint mapTool( mParentTool, mCanvas );
mCanvas->setMapTool( &mapTool );

TestQgsMapToolAdvancedDigitizingUtils utilsCircular( &mapTool );
utilsCircular.mouseClick( 1, 1, Qt::LeftButton );
utilsCircular.mouseClick( 0, 2, Qt::LeftButton );

mCanvas->setMapTool( mParentTool );
utilsClassic.mouseClick( 2, 2, Qt::LeftButton );
utilsClassic.mouseClick( 4, 2, Qt::LeftButton );

utilsCircular.mouseClick( 4, 2, Qt::RightButton );
QgsFeatureId newFid = utilsCircular.newFeatureId();

QCOMPARE( mLayer->featureCount(), ( long )1 );
QgsFeature f = mLayer->getFeature( newFid );

QString wkt = "CompoundCurveZ ((2 1 333, 2 0 333),(2 0 333, 0 0 333),CircularStringZ (0 0 333, 1 1 333, 0 2 333),(0 2 333, 2 2 333),(2 2 333, 4 2 333))";
QCOMPARE( f.geometry().asWkt(), wkt );

mLayer->rollBack();
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 );
}
QGSTEST_MAIN( TestQgsMapToolCircularString )
#include "testqgsmaptoolcircularstring.moc"

0 comments on commit fb8c8b2

Please sign in to comment.