Skip to content
Permalink
Browse files

Use Shift+Right click to close a line and add a test

  • Loading branch information
lbartoletti committed Mar 2, 2020
1 parent 099db4b commit 14760f5a20c5f2cc44cd95ddab0b05cfb946bd43
@@ -131,6 +131,7 @@ void QgsMapToolDigitizeFeature::keyPressEvent( QKeyEvent *e )
else
QgsMapToolCapture::keyPressEvent( e );
}

void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayer );
@@ -313,7 +314,7 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
return;
}

if ( mode() == CapturePolygon )
if ( mode() == CapturePolygon || e->modifiers() == Qt::ShiftModifier )
{
closePolygon();
}
@@ -69,6 +69,7 @@ class TestQgsMapToolAddFeatureLine : public QObject
void testZMSnapping();
void testTopologicalEditingZ();
void testCloseLine();
void testCloseLineShiftRigthClick();

private:
QgisApp *mQgisApp = nullptr;
@@ -507,5 +508,22 @@ void TestQgsMapToolAddFeatureLine::testCloseLine()

mLayerCloseLine->undoStack()->undo();
}
void TestQgsMapToolAddFeatureLine::testCloseLineShiftRigthClick()
{
TestQgsMapToolAdvancedDigitizingUtils utils( mCaptureTool );

mCanvas->setCurrentLayer( mLayerCloseLine );
QSet<QgsFeatureId> oldFids = utils.existingFeatureIds();
utils.mouseClick( 1, 1, Qt::LeftButton );
utils.mouseClick( 5, 1, Qt::LeftButton );
utils.mouseClick( 5, 5, Qt::LeftButton );
utils.mouseClick( 5, 5, Qt::RightButton, Qt::ShiftModifier );
QgsFeatureId newFid = utils.newFeatureId( oldFids );

QString wkt = "LineString (1 1, 5 1, 5 5, 1 1)";
QCOMPARE( mLayerCloseLine->getFeature( newFid ).geometry(), QgsGeometry::fromWkt( wkt ) );

mLayerCloseLine->undoStack()->undo();
}
QGSTEST_MAIN( TestQgsMapToolAddFeatureLine )
#include "testqgsmaptooladdfeatureline.moc"
@@ -97,12 +97,12 @@ class TestQgsMapToolAdvancedDigitizingUtils
mouseRelease( mapX, mapY, button, stateKey, snap );
}

void keyClick( int key, modifier = Qt::KeyboardModifiers() )
void keyClick( int key, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers() )
{
QKeyEvent e1( QEvent::KeyPress, key, modifier );
QKeyEvent e1( QEvent::KeyPress, key, stateKey );
mMapTool->keyPressEvent( &e1 );

QKeyEvent e2( QEvent::KeyRelease, key, modifier );
QKeyEvent e2( QEvent::KeyRelease, key, stateKey );
mMapTool->keyReleaseEvent( &e2 );
}

@@ -183,12 +183,12 @@ class TestQgsMapToolUtils
mouseRelease( mapX, mapY, button, stateKey, snap );
}

void keyClick( int key )
void keyClick( int key, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers() )
{
QKeyEvent e1( QEvent::KeyPress, key, Qt::KeyboardModifiers() );
QKeyEvent e1( QEvent::KeyPress, key, stateKey );
mMapTool->keyPressEvent( &e1 );

QKeyEvent e2( QEvent::KeyRelease, key, Qt::KeyboardModifiers() );
QKeyEvent e2( QEvent::KeyRelease, key, stateKey );
mMapTool->keyReleaseEvent( &e2 );
}

0 comments on commit 14760f5

Please sign in to comment.
You can’t perform that action at this time.