mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
add test for add part to geometry less features on single geometry type layers (#57260)
This commit is contained in:
parent
1b21d8d5fc
commit
b6f929e5d5
@ -42,6 +42,7 @@ class TestQgsMapToolAddPart: public QObject
|
||||
|
||||
void testAddPart();
|
||||
void testAddPartClockWise();
|
||||
void testAddPartToSingleGeometryLess();
|
||||
|
||||
private:
|
||||
QPoint mapToPoint( double x, double y );
|
||||
@ -221,5 +222,58 @@ void TestQgsMapToolAddPart::testAddPartClockWise()
|
||||
const QString wkt = "MultiPolygon (((2 2, 4 2, 4 4, 2 4)),((5 5, 5 5, 6 5, 6 6, 5 6, 5 5)),((15 15, 16 15, 16 16, 15 16, 15 15)))";
|
||||
QCOMPARE( mLayerMultiPolygon->getFeature( 1 ).geometry().asWkt(), wkt );
|
||||
}
|
||||
|
||||
void TestQgsMapToolAddPart::testAddPartToSingleGeometryLess()
|
||||
{
|
||||
QMap<QStringList, QList<QgsPoint>> geomTypes;
|
||||
geomTypes.insert( {"Point"}, {QgsPoint( 0, 0 )} );
|
||||
geomTypes.insert( {"LineString", "CompoundCurve"}, {QgsPoint( 0, 0 ), QgsPoint( 1, 1 )} );
|
||||
geomTypes.insert( {"Polygon", "CurvePolygon"}, {QgsPoint( 0, 0 ), QgsPoint( 1, 0 ), QgsPoint( 1, 1 ), QgsPoint( 0, 1 )} );
|
||||
|
||||
|
||||
for ( auto it = geomTypes.constBegin(); it != geomTypes.constEnd(); it++ )
|
||||
{
|
||||
for ( const QString &geomType : it.key() )
|
||||
{
|
||||
QgsVectorLayer *vl = new QgsVectorLayer( QStringLiteral( "%1?crs=EPSG:3946" ).arg( geomType ), QStringLiteral( "layer" ), QStringLiteral( "memory" ) );
|
||||
QVERIFY( vl->isValid() );
|
||||
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << vl );
|
||||
|
||||
vl->startEditing();
|
||||
QgsFeature f;
|
||||
vl->dataProvider()->addFeatures( QgsFeatureList() << f );
|
||||
QCOMPARE( vl->featureCount(), ( long )1 );
|
||||
QVERIFY( vl->getFeature( 1 ).geometry().isNull() );
|
||||
|
||||
mCanvas->setCurrentLayer( vl );
|
||||
vl->select( 1 );
|
||||
|
||||
QCOMPARE( mCanvas->mapSettings().outputSize(), QSize( 512, 512 ) );
|
||||
QCOMPARE( mCanvas->mapSettings().visibleExtent(), QgsRectangle( 0, 0, 8, 8 ) );
|
||||
|
||||
std::unique_ptr< QgsMapMouseEvent > event;
|
||||
for ( const QgsPoint &point : it.value() )
|
||||
{
|
||||
event.reset( new QgsMapMouseEvent(
|
||||
mCanvas,
|
||||
QEvent::MouseButtonRelease,
|
||||
mapToPoint( point.x(), point.y() ),
|
||||
Qt::LeftButton
|
||||
) );
|
||||
mCaptureTool->cadCanvasReleaseEvent( event.get() );
|
||||
}
|
||||
event.reset( new QgsMapMouseEvent(
|
||||
mCanvas,
|
||||
QEvent::MouseButtonRelease,
|
||||
mapToPoint( 0, 0 ),
|
||||
Qt::RightButton
|
||||
) );
|
||||
mCaptureTool->cadCanvasReleaseEvent( event.get() );
|
||||
|
||||
QVERIFY2( ! vl->getFeature( 1 ).geometry().isNull(), QString( "failed for %1" ).arg( geomType ).toLocal8Bit().data() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsMapToolAddPart )
|
||||
#include "testqgsmaptooladdpart.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user