@@ -54,6 +54,7 @@ class TestQgsNodeTool : public QObject
54
54
void testMoveVertex ();
55
55
void testMoveEdge ();
56
56
void testAddVertex ();
57
+ void testAddVertexAtEndpoint ();
57
58
void testDeleteVertex ();
58
59
59
60
private:
@@ -63,6 +64,12 @@ class TestQgsNodeTool : public QObject
63
64
return QPoint ( qRound ( pt.x () ), qRound ( pt.y () ) );
64
65
}
65
66
67
+ void mouseMove ( double mapX, double mapY )
68
+ {
69
+ QgsMapMouseEvent e ( mCanvas , QEvent::MouseMove, mapToScreen ( mapX, mapY ) );
70
+ mNodeTool ->cadCanvasMoveEvent ( &e );
71
+ }
72
+
66
73
void mouseClick ( double mapX, double mapY, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers() )
67
74
{
68
75
QgsMapMouseEvent e1 ( mCanvas , QEvent::MouseButtonPress, mapToScreen ( mapX, mapY ), button, button, stateKey );
@@ -170,6 +177,8 @@ void TestQgsNodeTool::initTestCase()
170
177
171
178
mCanvas ->setLayers ( QList<QgsMapLayer*>() << mLayerLine << mLayerPolygon << mLayerPoint );
172
179
180
+ qApp->processEvents (); // will this fix travis?
181
+
173
182
// TODO: set up snapping
174
183
175
184
// create node tool
@@ -195,6 +204,8 @@ void TestQgsNodeTool::testMoveVertex()
195
204
mouseClick ( 2 , 1 , Qt::LeftButton );
196
205
mouseClick ( 2 , 2 , Qt::LeftButton );
197
206
207
+ qApp->processEvents (); // will this fix travis?
208
+
198
209
QCOMPARE ( mLayerLine ->undoStack ()->index (), 2 );
199
210
QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 2, 1 1, 1 3)" ) );
200
211
@@ -330,6 +341,41 @@ void TestQgsNodeTool::testAddVertex()
330
341
}
331
342
332
343
344
+ void TestQgsNodeTool::testAddVertexAtEndpoint ()
345
+ {
346
+ // offset of the endpoint marker - currently set as 15px away from the last node in direction of the line
347
+ double offsetInMapUnits = 15 * mCanvas ->mapSettings ().mapUnitsPerPixel ();
348
+
349
+ // add vertex at the end
350
+
351
+ mouseMove ( 1 , 3 ); // first we need to move to the vertex
352
+ mouseClick ( 1 , 3 + offsetInMapUnits, Qt::LeftButton );
353
+ mouseClick ( 2 , 3 , Qt::LeftButton );
354
+
355
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 2 );
356
+ QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 1, 1 1, 1 3, 2 3)" ) );
357
+
358
+ mLayerLine ->undoStack ()->undo ();
359
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 1 );
360
+
361
+ QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 1, 1 1, 1 3)" ) );
362
+
363
+ // add vertex at the start
364
+
365
+ mouseMove ( 2 , 1 ); // first we need to move to the vertex
366
+ mouseClick ( 2 + offsetInMapUnits, 1 , Qt::LeftButton );
367
+ mouseClick ( 2 , 2 , Qt::LeftButton );
368
+
369
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 2 );
370
+ QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 2, 2 1, 1 1, 1 3)" ) );
371
+
372
+ mLayerLine ->undoStack ()->undo ();
373
+ QCOMPARE ( mLayerLine ->undoStack ()->index (), 1 );
374
+
375
+ QCOMPARE ( mLayerLine ->getFeature ( mFidLineF1 ).geometry (), QgsGeometry::fromWkt ( " LINESTRING(2 1, 1 1, 1 3)" ) );
376
+ }
377
+
378
+
333
379
void TestQgsNodeTool::testDeleteVertex ()
334
380
{
335
381
// delete vertex in linestring
0 commit comments