Skip to content

Commit

Permalink
Merge pull request #34884 from lbartoletti/backport-34797-to-release-…
Browse files Browse the repository at this point in the history
…3_10

[Backport 3.10] Backport 34797 to release 3 10
  • Loading branch information
m-kuhn committed Mar 10, 2020
2 parents 12f5283 + 6dcf392 commit 190390d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/gui/qgsmaptooldigitizefeature.cpp
Expand Up @@ -274,7 +274,7 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
return;
}

if ( mode() == CapturePolygon )
if ( mode() == CapturePolygon || e->modifiers() == Qt::ShiftModifier )
{
closePolygon();
}
Expand Down
27 changes: 26 additions & 1 deletion tests/src/app/testqgsmaptooladdfeatureline.cpp
Expand Up @@ -42,7 +42,7 @@ namespace QTest
// pretty printing of geometries in comparison tests
template<> char *toString( const QgsGeometry &geom )
{
QByteArray ba = geom.asWkt().toAscii();
QByteArray ba = geom.asWkt().toLatin1();
return qstrdup( ba.data() );
}
}
Expand All @@ -68,6 +68,7 @@ class TestQgsMapToolAddFeatureLine : public QObject
void testZ();
void testZMSnapping();
void testTopologicalEditingZ();
void testCloseLine();

private:
QgisApp *mQgisApp = nullptr;
Expand All @@ -80,6 +81,7 @@ class TestQgsMapToolAddFeatureLine : public QObject
QgsVectorLayer *mLayerPointZM = nullptr;
QgsVectorLayer *mLayerTopoZ = nullptr;
QgsVectorLayer *mLayerLine2D = nullptr;
QgsVectorLayer *mLayerCloseLine = nullptr;
QgsFeatureId mFidLineF1 = 0;
};

Expand Down Expand Up @@ -137,6 +139,11 @@ void TestQgsMapToolAddFeatureLine::initTestCase()
mLayerLineZ->addFeature( lineF2 );
QCOMPARE( mLayerLineZ->featureCount(), ( long )1 );

mLayerCloseLine = new QgsVectorLayer( QStringLiteral( "LineString?crs=EPSG:27700" ), QStringLiteral( "layer line Closed" ), QStringLiteral( "memory" ) );
QVERIFY( mLayerCloseLine->isValid() );
mLayerCloseLine->startEditing();
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerCloseLine );

mCanvas->setFrameStyle( QFrame::NoFrame );
mCanvas->resize( 512, 512 );
mCanvas->setExtent( QgsRectangle( 0, 0, 8, 8 ) );
Expand Down Expand Up @@ -482,5 +489,23 @@ void TestQgsMapToolAddFeatureLine::testTopologicalEditingZ()
mCanvas->snappingUtils()->setConfig( cfg );
cfg.project()->setTopologicalEditing( topologicalEditing );
}

void TestQgsMapToolAddFeatureLine::testCloseLine()
{
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"
12 changes: 6 additions & 6 deletions tests/src/app/testqgsmaptoolutils.h
Expand Up @@ -97,12 +97,12 @@ class TestQgsMapToolAdvancedDigitizingUtils
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 );
}

Expand Down Expand Up @@ -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 );
}

Expand Down

0 comments on commit 190390d

Please sign in to comment.