mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
More unit tests
This commit is contained in:
parent
55d0ad7533
commit
ae5651e41f
@ -54,6 +54,7 @@ class TestQgsNodeTool : public QObject
|
||||
void testMoveVertex();
|
||||
void testMoveEdge();
|
||||
void testAddVertex();
|
||||
void testAddVertexAtEndpoint();
|
||||
void testDeleteVertex();
|
||||
|
||||
private:
|
||||
@ -63,6 +64,12 @@ class TestQgsNodeTool : public QObject
|
||||
return QPoint( qRound( pt.x() ), qRound( pt.y() ) );
|
||||
}
|
||||
|
||||
void mouseMove( double mapX, double mapY )
|
||||
{
|
||||
QgsMapMouseEvent e( mCanvas, QEvent::MouseMove, mapToScreen( mapX, mapY ) );
|
||||
mNodeTool->cadCanvasMoveEvent( &e );
|
||||
}
|
||||
|
||||
void mouseClick( double mapX, double mapY, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers() )
|
||||
{
|
||||
QgsMapMouseEvent e1( mCanvas, QEvent::MouseButtonPress, mapToScreen( mapX, mapY ), button, button, stateKey );
|
||||
@ -170,6 +177,8 @@ void TestQgsNodeTool::initTestCase()
|
||||
|
||||
mCanvas->setLayers( QList<QgsMapLayer*>() << mLayerLine << mLayerPolygon << mLayerPoint );
|
||||
|
||||
qApp->processEvents(); // will this fix travis?
|
||||
|
||||
// TODO: set up snapping
|
||||
|
||||
// create node tool
|
||||
@ -195,6 +204,8 @@ void TestQgsNodeTool::testMoveVertex()
|
||||
mouseClick( 2, 1, Qt::LeftButton );
|
||||
mouseClick( 2, 2, Qt::LeftButton );
|
||||
|
||||
qApp->processEvents(); // will this fix travis?
|
||||
|
||||
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 2, 1 1, 1 3)" ) );
|
||||
|
||||
@ -330,6 +341,41 @@ void TestQgsNodeTool::testAddVertex()
|
||||
}
|
||||
|
||||
|
||||
void TestQgsNodeTool::testAddVertexAtEndpoint()
|
||||
{
|
||||
// offset of the endpoint marker - currently set as 15px away from the last node in direction of the line
|
||||
double offsetInMapUnits = 15 * mCanvas->mapSettings().mapUnitsPerPixel();
|
||||
|
||||
// add vertex at the end
|
||||
|
||||
mouseMove( 1, 3 ); // first we need to move to the vertex
|
||||
mouseClick( 1, 3 + offsetInMapUnits, Qt::LeftButton );
|
||||
mouseClick( 2, 3, Qt::LeftButton );
|
||||
|
||||
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3, 2 3)" ) );
|
||||
|
||||
mLayerLine->undoStack()->undo();
|
||||
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
|
||||
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
|
||||
|
||||
// add vertex at the start
|
||||
|
||||
mouseMove( 2, 1 ); // first we need to move to the vertex
|
||||
mouseClick( 2 + offsetInMapUnits, 1, Qt::LeftButton );
|
||||
mouseClick( 2, 2, Qt::LeftButton );
|
||||
|
||||
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 2, 2 1, 1 1, 1 3)" ) );
|
||||
|
||||
mLayerLine->undoStack()->undo();
|
||||
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
|
||||
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestQgsNodeTool::testDeleteVertex()
|
||||
{
|
||||
// delete vertex in linestring
|
||||
|
Loading…
x
Reference in New Issue
Block a user