Skip to content
Permalink
Browse files

Merge pull request #34884 from lbartoletti/backport-34797-to-release-…

…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 190390da33666b85e392add974e64d0e0e099e66
@@ -274,7 +274,7 @@ void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
return;
}

if ( mode() == CapturePolygon )
if ( mode() == CapturePolygon || e->modifiers() == Qt::ShiftModifier )
{
closePolygon();
}
@@ -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() );
}
}
@@ -68,6 +68,7 @@ class TestQgsMapToolAddFeatureLine : public QObject
void testZ();
void testZMSnapping();
void testTopologicalEditingZ();
void testCloseLine();

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

@@ -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 ) );
@@ -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"
@@ -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 );
}

@@ -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 190390d

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