Skip to content

Commit d2ed783

Browse files
committedFeb 16, 2018
Add test for z values on QgsMapToolAddFeature with LineStringZ
1 parent 4bfc7b7 commit d2ed783

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed
 

‎tests/src/app/testqgsmaptooladdfeature.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgsmaptooladdfeature.h"
2424
#include "qgsmapcanvastracer.h"
2525
#include "qgsproject.h"
26+
#include "qgssettings.h"
2627
#include "qgsvectorlayer.h"
2728

2829

@@ -81,6 +82,7 @@ class TestQgsMapToolAddFeature : public QObject
8182
void testNoTracing();
8283
void testTracing();
8384
void testTracingWithOffset();
85+
void testZ();
8486

8587
private:
8688
QPoint mapToScreen( double mapX, double mapY )
@@ -129,6 +131,7 @@ class TestQgsMapToolAddFeature : public QObject
129131
QAction *mEnableTracingAction = nullptr;
130132
QgsMapToolAddFeature *mCaptureTool = nullptr;
131133
QgsVectorLayer *mLayerLine = nullptr;
134+
QgsVectorLayer *mLayerLineZ = nullptr;
132135
QgsFeatureId mFidLineF1 = 0;
133136
};
134137

@@ -172,6 +175,20 @@ void TestQgsMapToolAddFeature::initTestCase()
172175
// just one added feature
173176
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
174177

178+
// make testing layers
179+
mLayerLineZ = new QgsVectorLayer( QStringLiteral( "LineStringZ?crs=EPSG:27700" ), QStringLiteral( "layer line Z" ), QStringLiteral( "memory" ) );
180+
QVERIFY( mLayerLineZ->isValid() );
181+
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerLineZ );
182+
183+
QgsPolyline line2;
184+
line2 << QgsPoint( 1, 1, 0 ) << QgsPoint( 2, 1, 1 ) << QgsPoint( 3, 2, 2 ) << QgsPoint( 1, 2, 3 ) << QgsPoint( 1, 1, 0 );
185+
QgsFeature lineF2;
186+
lineF2.setGeometry( QgsGeometry::fromPolyline( line2 ) );
187+
188+
mLayerLineZ->startEditing();
189+
mLayerLineZ->addFeature( lineF2 );
190+
QCOMPARE( mLayerLineZ->featureCount(), ( long )1 );
191+
175192
mCanvas->setFrameStyle( QFrame::NoFrame );
176193
mCanvas->resize( 512, 512 );
177194
mCanvas->setExtent( QgsRectangle( 0, 0, 8, 8 ) );
@@ -180,7 +197,7 @@ void TestQgsMapToolAddFeature::initTestCase()
180197
QCOMPARE( mCanvas->mapSettings().outputSize(), QSize( 512, 512 ) );
181198
QCOMPARE( mCanvas->mapSettings().visibleExtent(), QgsRectangle( 0, 0, 8, 8 ) );
182199

183-
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerLine ); //<< mLayerPolygon << mLayerPoint );
200+
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerLine << mLayerLineZ ); //<< mLayerPolygon << mLayerPoint );
184201

185202
mCanvas->setSnappingUtils( new QgsMapCanvasSnappingUtils( mCanvas, this ) );
186203

@@ -346,6 +363,45 @@ void TestQgsMapToolAddFeature::testTracingWithOffset()
346363
mEnableTracingAction->setChecked( false );
347364
}
348365

366+
void TestQgsMapToolAddFeature::testZ()
367+
{
368+
mCanvas->setCurrentLayer( mLayerLineZ );
369+
370+
// test with default Z value = 333
371+
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 333 );
372+
373+
QSet<QgsFeatureId> oldFids = _existingFeatureIds( mLayerLineZ );
374+
mouseClick( 4, 0, Qt::LeftButton );
375+
mouseClick( 5, 0, Qt::LeftButton );
376+
mouseClick( 5, 1, Qt::LeftButton );
377+
mouseClick( 4, 1, Qt::LeftButton );
378+
mouseClick( 4, 1, Qt::RightButton );
379+
QgsFeatureId newFid = _newFeatureId( mLayerLineZ, oldFids );
380+
381+
QString wkt = "LineStringZ (4 0 333, 5 0 333, 5 1 333, 4 1 333)";
382+
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );
383+
384+
mLayerLine->undoStack()->undo();
385+
386+
// test with default Z value = 222
387+
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 );
388+
389+
oldFids = _existingFeatureIds( mLayerLineZ );
390+
mouseClick( 4, 0, Qt::LeftButton );
391+
mouseClick( 5, 0, Qt::LeftButton );
392+
mouseClick( 5, 1, Qt::LeftButton );
393+
mouseClick( 4, 1, Qt::LeftButton );
394+
mouseClick( 4, 1, Qt::RightButton );
395+
newFid = _newFeatureId( mLayerLineZ, oldFids );
396+
397+
wkt = "LineStringZ (4 0 222, 5 0 222, 5 1 222, 4 1 222)";
398+
QCOMPARE( mLayerLineZ->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );
399+
400+
mLayerLine->undoStack()->undo();
401+
402+
mCanvas->setCurrentLayer( mLayerLine );
403+
}
404+
349405

350406
QGSTEST_MAIN( TestQgsMapToolAddFeature )
351407
#include "testqgsmaptooladdfeature.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.