Skip to content

Commit

Permalink
add test for QgsMapToolAddFeatureLine
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Apr 30, 2021
1 parent f66d4b0 commit 1902351
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion tests/src/app/testqgsmaptooladdfeatureline.cpp
Expand Up @@ -69,6 +69,7 @@ class TestQgsMapToolAddFeatureLine : public QObject
void testTracingWithConvertToCurves();
void testTracingWithConvertToCurvesCustomTolerance();
void testZ();
void testM();
void testZMSnapping();
void testTopologicalEditingZ();
void testCloseLine();
Expand All @@ -89,6 +90,7 @@ class TestQgsMapToolAddFeatureLine : public QObject
QgsVectorLayer *mLayerLineCurved = nullptr;
QgsVectorLayer *mLayerLineCurvedOffset = nullptr;
QgsVectorLayer *mLayerLineZ = nullptr;
QgsVectorLayer *mLayerLineM = nullptr;
QgsVectorLayer *mLayerPointZM = nullptr;
QgsVectorLayer *mLayerTopoZ = nullptr;
QgsVectorLayer *mLayerLine2D = nullptr;
Expand Down Expand Up @@ -177,6 +179,11 @@ void TestQgsMapToolAddFeatureLine::initTestCase()
QVERIFY( mLayerLineZ->isValid() );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerLineZ );

mLayerLineM = new QgsVectorLayer( QStringLiteral( "LineStringM?crs=EPSG:27700" ), QStringLiteral( "layer line M" ), QStringLiteral( "memory" ) );
QVERIFY( mLayerLineM->isValid() );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerLineM );
mLayerLineM->startEditing();

QgsPolyline line2;
line2 << QgsPoint( 1, 1, 0 ) << QgsPoint( 2, 1, 1 ) << QgsPoint( 3, 2, 2 ) << QgsPoint( 1, 2, 3 ) << QgsPoint( 1, 1, 0 );
QgsFeature lineF2;
Expand Down Expand Up @@ -243,7 +250,7 @@ void TestQgsMapToolAddFeatureLine::initTestCase()
mLayerSelfSnapLine->startEditing();

// add layers to canvas
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerLine << mLayerLineCurved << mLayerLineCurvedOffset << mLayerLineZ << mLayerPointZM << mLayerTopoZ << mLayerLine2D << mLayerSelfSnapLine );
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerLine << mLayerLineCurved << mLayerLineCurvedOffset << mLayerLineZ << mLayerLineM << mLayerPointZM << mLayerTopoZ << mLayerLine2D << mLayerSelfSnapLine );
mCanvas->setSnappingUtils( new QgsMapCanvasSnappingUtils( mCanvas, this ) );

// create the tool
Expand Down Expand Up @@ -606,6 +613,47 @@ void TestQgsMapToolAddFeatureLine::testZ()
mCanvas->setCurrentLayer( mLayerLine );
}

void TestQgsMapToolAddFeatureLine::testM()
{
TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );

mCanvas->setCurrentLayer( mLayerLineM );

// test with default M value = 333
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_m_value" ), 333 );

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
utils.mouseClick( 5, 0, Qt::LeftButton );
utils.mouseClick( 5, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::RightButton );
QgsFeatureId newFid = utils.newFeatureId( oldFids );

QString wkt = "LineStringM (4 0 333, 5 0 333, 5 1 333, 4 1 333)";
QCOMPARE( mLayerLineM->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();

// test with default M value = 222
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_m_value" ), 222 );

oldFids = utils.existingFeatureIds();
utils.mouseClick( 4, 0, Qt::LeftButton );
utils.mouseClick( 5, 0, Qt::LeftButton );
utils.mouseClick( 5, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::LeftButton );
utils.mouseClick( 4, 1, Qt::RightButton );
newFid = utils.newFeatureId( oldFids );

wkt = "LineStringM (4 0 222, 5 0 222, 5 1 222, 4 1 222)";
QCOMPARE( mLayerLineM->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerLine->undoStack()->undo();

mCanvas->setCurrentLayer( mLayerLine );
}

void TestQgsMapToolAddFeatureLine::testZMSnapping()
{
TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );
Expand Down

0 comments on commit 1902351

Please sign in to comment.