Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti authored and nyalldawson committed Nov 20, 2019
1 parent 47bc117 commit b848b0a
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion tests/src/app/testqgsmaptooladdfeaturepoint.cpp
Expand Up @@ -46,12 +46,14 @@ class TestQgsMapToolAddFeaturePoint : public QObject
void cleanupTestCase();// will be called after the last testfunction was executed.

void testPointZ();
void testTopologicalEditingZ();

private:
QgisApp *mQgisApp = nullptr;
QgsMapCanvas *mCanvas = nullptr;
QgsMapToolAddFeature *mCaptureTool = nullptr;
QgsVectorLayer *mLayerPointZSnap = nullptr;
QgsVectorLayer *mLayerLineZSnap = nullptr;
QgsVectorLayer *mLayerPointZ = nullptr;
};

Expand Down Expand Up @@ -109,18 +111,31 @@ void TestQgsMapToolAddFeaturePoint::initTestCase()
mLayerPointZSnap->addFeature( pointF );
QCOMPARE( mLayerPointZSnap->featureCount(), ( long )1 );

// make line layer for snapping
mLayerLineZSnap = new QgsVectorLayer( QStringLiteral( "LineStringZ?crs=EPSG:27700" ), QStringLiteral( "Snap line" ), QStringLiteral( "memory" ) );
QVERIFY( mLayerLineZSnap->isValid() );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerLineZSnap );

mLayerLineZSnap->startEditing();
QgsFeature lineF;
lineF.setGeometry( QgsGeometry::fromWkt( "LineStringZ( 1 1 1, 5 5 5)" ) );

mLayerLineZSnap->addFeature( lineF );
QCOMPARE( mLayerLineZSnap->featureCount(), ( long )1 );

QgsSnappingConfig cfg = mCanvas->snappingUtils()->config();
cfg.setMode( QgsSnappingConfig::AllLayers );
cfg.setTolerance( 100 );
cfg.setType( QgsSnappingConfig::VertexAndSegment );
cfg.setEnabled( true );
mCanvas->snappingUtils()->setConfig( cfg );

mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerPointZ << mLayerPointZSnap );
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerPointZ << mLayerPointZSnap << mLayerLineZSnap );
mCanvas->setCurrentLayer( mLayerPointZ );

mCanvas->snappingUtils()->locatorForLayer( mLayerPointZ )->init();
mCanvas->snappingUtils()->locatorForLayer( mLayerPointZSnap )->init();
mCanvas->snappingUtils()->locatorForLayer( mLayerLineZSnap )->init();

// create the tool
mCaptureTool = new QgsMapToolAddFeature( mCanvas, /*mAdvancedDigitizingDockWidget, */ QgsMapToolCapture::CapturePoint );
Expand Down Expand Up @@ -167,5 +182,38 @@ void TestQgsMapToolAddFeaturePoint::testPointZ()
mLayerPointZ->undoStack()->undo();
}

void TestQgsMapToolAddFeaturePoint::testTopologicalEditingZ()
{
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
QgsProject::instance()->setTopologicalEditing( true );

TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );

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

QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();

utils.mouseClick( 3, 3, Qt::LeftButton, Qt::KeyboardModifiers(), true );
QgsFeatureId newFid = utils.newFeatureId( oldFids );

QCOMPARE( mLayerPointZ->featureCount(), ( long )2 );

QString wkt = "PointZ (3 3 3)";
QCOMPARE( mLayerPointZ->getFeature( newFid ).geometry().asWkt(), wkt );


QCOMPARE( mLayerLineZSnap->featureCount(), ( long )1 );

wkt = "LineStringZ (1 1 1, 3 3 3, 5 5 5)";
QgsFeature f;
QgsFeatureIterator it = mLayerLineZSnap->getFeatures();
it.nextFeature( f );
QCOMPARE( f.geometry().asWkt(), wkt );
QgsProject::instance()->setTopologicalEditing( topologicalEditing );
mLayerPointZ->undoStack()->undo();
mLayerLineZSnap->undoStack()->undo();

}
QGSTEST_MAIN( TestQgsMapToolAddFeaturePoint )
#include "testqgsmaptooladdfeaturepoint.moc"

0 comments on commit b848b0a

Please sign in to comment.