Use WkbType instead of GeometryType enum for addPart

Deprecating QgsGeometry::addPart in favor of QgsGeometry::addPartV2
to use Qgis::WkbType instead of Qgis::GeometryType because the latter
can't handle curved geometries (not specific enough).

Fixes #57255
This commit is contained in:
Jacky Volpes 2024-05-31 16:39:03 +02:00 committed by Loïc Bartoletti
parent 2c38dc8cbd
commit ab663b485b
10 changed files with 266 additions and 31 deletions

View File

@ -841,7 +841,7 @@ Adds a new ring to this geometry. This makes only sense for polygon and multipol
:return: OperationResult a result code: success or reason of failure
%End
Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /PyName=addPointsXY/;
Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /PyName=addPointsXY,Deprecated/;
%Docstring
Adds a new part to a the geometry.
@ -849,9 +849,24 @@ Adds a new part to a the geometry.
:param geomType: default geometry type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. deprecated:: QGIS 3.38
- will be removed in QGIS 4.0. Use addPartV2 which accepts :py:class:`Qgis`.WkbType geometry type instead of :py:class:`Qgis`.GeometryType.
%End
Qgis::GeometryOperationResult addPart( const QgsPointSequence &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /PyName=addPoints/;
Qgis::GeometryOperationResult addPartV2( const QVector<QgsPointXY> &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) /PyName=addPointsXYV2/;
%Docstring
Adds a new part to a the geometry.
:param points: points describing part to add
:param wkbType: default WKB type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. versionadded:: 3.38
%End
Qgis::GeometryOperationResult addPart( const QgsPointSequence &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /PyName=addPoints,Deprecated/;
%Docstring
Adds a new part to a the geometry.
@ -859,9 +874,24 @@ Adds a new part to a the geometry.
:param geomType: default geometry type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. deprecated:: QGIS 3.38
- will be removed in QGIS 4.0. Use addPartV2 which accepts :py:class:`Qgis`.WkbType geometry type instead of :py:class:`Qgis`.GeometryType.
%End
Qgis::GeometryOperationResult addPart( QgsAbstractGeometry *part /Transfer/, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown );
Qgis::GeometryOperationResult addPartV2( const QgsPointSequence &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) /PyName=addPointsV2/;
%Docstring
Adds a new part to a the geometry.
:param points: points describing part to add
:param wkbType: default WKB type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. versionadded:: 3.38
%End
Qgis::GeometryOperationResult addPart( QgsAbstractGeometry *part /Transfer/, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /Deprecated/;
%Docstring
Adds a new part to this geometry.
@ -869,6 +899,21 @@ Adds a new part to this geometry.
:param geomType: default geometry type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. deprecated:: QGIS 3.38
- will be removed in QGIS 4.0. Use addPartV2 which accepts :py:class:`Qgis`.WkbType geometry type instead of :py:class:`Qgis`.GeometryType.
%End
Qgis::GeometryOperationResult addPartV2( QgsAbstractGeometry *part /Transfer/, Qgis::WkbType wkbType = Qgis::WkbType::Unknown );
%Docstring
Adds a new part to this geometry.
:param part: part to add (ownership is transferred)
:param wkbType: default WKB type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. versionadded:: 3.38
%End
Qgis::GeometryOperationResult addPart( const QgsGeometry &newPart ) /PyName=addPartGeometry/;

View File

@ -841,7 +841,7 @@ Adds a new ring to this geometry. This makes only sense for polygon and multipol
:return: OperationResult a result code: success or reason of failure
%End
Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /PyName=addPointsXY/;
Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /PyName=addPointsXY,Deprecated/;
%Docstring
Adds a new part to a the geometry.
@ -849,9 +849,24 @@ Adds a new part to a the geometry.
:param geomType: default geometry type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. deprecated:: QGIS 3.38
- will be removed in QGIS 4.0. Use addPartV2 which accepts :py:class:`Qgis`.WkbType geometry type instead of :py:class:`Qgis`.GeometryType.
%End
Qgis::GeometryOperationResult addPart( const QgsPointSequence &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /PyName=addPoints/;
Qgis::GeometryOperationResult addPartV2( const QVector<QgsPointXY> &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) /PyName=addPointsXYV2/;
%Docstring
Adds a new part to a the geometry.
:param points: points describing part to add
:param wkbType: default WKB type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. versionadded:: 3.38
%End
Qgis::GeometryOperationResult addPart( const QgsPointSequence &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /PyName=addPoints,Deprecated/;
%Docstring
Adds a new part to a the geometry.
@ -859,9 +874,24 @@ Adds a new part to a the geometry.
:param geomType: default geometry type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. deprecated:: QGIS 3.38
- will be removed in QGIS 4.0. Use addPartV2 which accepts :py:class:`Qgis`.WkbType geometry type instead of :py:class:`Qgis`.GeometryType.
%End
Qgis::GeometryOperationResult addPart( QgsAbstractGeometry *part /Transfer/, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown );
Qgis::GeometryOperationResult addPartV2( const QgsPointSequence &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) /PyName=addPointsV2/;
%Docstring
Adds a new part to a the geometry.
:param points: points describing part to add
:param wkbType: default WKB type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. versionadded:: 3.38
%End
Qgis::GeometryOperationResult addPart( QgsAbstractGeometry *part /Transfer/, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) /Deprecated/;
%Docstring
Adds a new part to this geometry.
@ -869,6 +899,21 @@ Adds a new part to this geometry.
:param geomType: default geometry type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. deprecated:: QGIS 3.38
- will be removed in QGIS 4.0. Use addPartV2 which accepts :py:class:`Qgis`.WkbType geometry type instead of :py:class:`Qgis`.GeometryType.
%End
Qgis::GeometryOperationResult addPartV2( QgsAbstractGeometry *part /Transfer/, Qgis::WkbType wkbType = Qgis::WkbType::Unknown );
%Docstring
Adds a new part to this geometry.
:param part: part to add (ownership is transferred)
:param wkbType: default WKB type to create if no existing geometry
:return: OperationResult a result code: success or reason of failure
.. versionadded:: 3.38
%End
Qgis::GeometryOperationResult addPart( const QgsGeometry &newPart ) /PyName=addPartGeometry/;

View File

@ -127,12 +127,12 @@ void QgsConcaveHullAlgorithm::concaveHullGeos( std::unique_ptr< QgsFeatureSink >
const QgsMultiPoint mp( *qgsgeometry_cast< const QgsMultiPoint * >( geom ) );
for ( auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
{
allPoints.addPart( qgsgeometry_cast< QgsPoint * >( *pit )->clone(), Qgis::GeometryType::Point );
allPoints.addPartV2( qgsgeometry_cast< QgsPoint * >( *pit )->clone(), Qgis::WkbType::Point );
}
}
else
{
allPoints.addPart( qgsgeometry_cast< QgsPoint * >( geom )->clone(), Qgis::GeometryType::Point );
allPoints.addPartV2( qgsgeometry_cast< QgsPoint * >( geom )->clone(), Qgis::WkbType::Point );
}
}
const QgsGeometry concaveHull = allPoints.concaveHull( mPercentage, mAllowHoles );

View File

@ -120,12 +120,12 @@ QVariantMap QgsDelaunayTriangulationAlgorithm::processAlgorithm( const QVariantM
const QgsMultiPoint mp( *qgsgeometry_cast< const QgsMultiPoint * >( geom ) );
for ( auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
{
allPoints.addPart( qgsgeometry_cast< QgsPoint * >( *pit )->clone(), Qgis::GeometryType::Point );
allPoints.addPartV2( qgsgeometry_cast< QgsPoint * >( *pit )->clone(), Qgis::WkbType::Point );
}
}
else
{
allPoints.addPart( qgsgeometry_cast< QgsPoint * >( geom )->clone(), Qgis::GeometryType::Point );
allPoints.addPartV2( qgsgeometry_cast< QgsPoint * >( geom )->clone(), Qgis::WkbType::Point );
}
return true;

View File

@ -136,12 +136,12 @@ QString QgsVoronoiPolygonsAlgorithm::voronoiWithAttributes( const QVariantMap &p
const QgsMultiPoint mp( *qgsgeometry_cast< const QgsMultiPoint * >( geom ) );
for ( auto pit = mp.const_parts_begin(); pit != mp.const_parts_end(); ++pit )
{
allPoints.addPart( qgsgeometry_cast< QgsPoint * >( *pit )->clone(), Qgis::GeometryType::Point );
allPoints.addPartV2( qgsgeometry_cast< QgsPoint * >( *pit )->clone(), Qgis::WkbType::Point );
}
}
else
{
allPoints.addPart( qgsgeometry_cast< QgsPoint * >( geom )->clone(), Qgis::GeometryType::Point );
allPoints.addPartV2( qgsgeometry_cast< QgsPoint * >( geom )->clone(), Qgis::WkbType::Point );
}
attributeCache.insert( f.id(), f.attributes() );

View File

@ -395,7 +395,7 @@ QgsGeometry QgsGeometry::collectGeometry( const QVector< QgsGeometry > &geometri
{
for ( auto p = g.const_parts_begin(); p != g.const_parts_end(); ++p )
{
collected.addPart( ( *p )->clone() );
collected.addPartV2( ( *p )->clone() );
}
}
else
@ -950,6 +950,13 @@ Qgis::GeometryOperationResult QgsGeometry::addPart( const QVector<QgsPointXY> &p
return addPart( l, geomType );
}
Qgis::GeometryOperationResult QgsGeometry::addPartV2( const QVector<QgsPointXY> &points, Qgis::WkbType wkbType )
{
QgsPointSequence l;
convertPointList( points, l );
return addPartV2( l, wkbType );
}
Qgis::GeometryOperationResult QgsGeometry::addPart( const QgsPointSequence &points, Qgis::GeometryType geomType )
{
std::unique_ptr< QgsAbstractGeometry > partGeom;
@ -966,6 +973,22 @@ Qgis::GeometryOperationResult QgsGeometry::addPart( const QgsPointSequence &poin
return addPart( partGeom.release(), geomType );
}
Qgis::GeometryOperationResult QgsGeometry::addPartV2( const QgsPointSequence &points, Qgis::WkbType wkbType )
{
std::unique_ptr< QgsAbstractGeometry > partGeom;
if ( points.size() == 1 )
{
partGeom = std::make_unique< QgsPoint >( points[0] );
}
else if ( points.size() > 1 )
{
std::unique_ptr< QgsLineString > ringLine = std::make_unique< QgsLineString >();
ringLine->setPoints( points );
partGeom = std::move( ringLine );
}
return addPartV2( partGeom.release(), wkbType );
}
Qgis::GeometryOperationResult QgsGeometry::addPart( QgsAbstractGeometry *part, Qgis::GeometryType geomType )
{
std::unique_ptr< QgsAbstractGeometry > p( part );
@ -996,6 +1019,44 @@ Qgis::GeometryOperationResult QgsGeometry::addPart( QgsAbstractGeometry *part, Q
return QgsGeometryEditUtils::addPart( d->geometry.get(), std::move( p ) );
}
Qgis::GeometryOperationResult QgsGeometry::addPartV2( QgsAbstractGeometry *part, Qgis::WkbType wkbType )
{
std::unique_ptr< QgsAbstractGeometry > p( part );
if ( !d->geometry )
{
switch ( QgsWkbTypes::singleType( QgsWkbTypes::flatType( wkbType ) ) )
{
case Qgis::WkbType::Point:
reset( std::make_unique< QgsMultiPoint >() );
break;
case Qgis::WkbType::LineString:
reset( std::make_unique< QgsMultiLineString >() );
break;
case Qgis::WkbType::Polygon:
case Qgis::WkbType::Triangle:
reset( std::make_unique< QgsMultiPolygon >() );
break;
case Qgis::WkbType::CurvePolygon:
reset( std::make_unique< QgsMultiSurface >() );
break;
case Qgis::WkbType::CompoundCurve:
case Qgis::WkbType::CircularString:
reset( std::make_unique< QgsMultiCurve >() );
break;
default:
reset( nullptr );
return Qgis::GeometryOperationResult::AddPartNotMultiGeometry;
}
}
else
{
detach();
}
convertToMultiType();
return QgsGeometryEditUtils::addPart( d->geometry.get(), std::move( p ) );
}
Qgis::GeometryOperationResult QgsGeometry::addPart( const QgsGeometry &newPart )
{
if ( !d->geometry )
@ -1007,7 +1068,7 @@ Qgis::GeometryOperationResult QgsGeometry::addPart( const QgsGeometry &newPart )
return Qgis::GeometryOperationResult::AddPartNotMultiGeometry;
}
return addPart( newPart.d->geometry->clone() );
return addPartV2( newPart.d->geometry->clone() );
}
QgsGeometry QgsGeometry::removeInteriorRings( double minimumRingArea ) const

View File

@ -908,24 +908,54 @@ class CORE_EXPORT QgsGeometry
* \param points points describing part to add
* \param geomType default geometry type to create if no existing geometry
* \returns OperationResult a result code: success or reason of failure
* \deprecated since QGIS 3.38 - will be removed in QGIS 4.0. Use addPartV2 which accepts Qgis::WkbType geometry type instead of Qgis::GeometryType.
*/
Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) SIP_PYNAME( addPointsXY );
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart( const QVector<QgsPointXY> &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) SIP_PYNAME( addPointsXY ) SIP_DEPRECATED;
/**
* Adds a new part to a the geometry.
* \param points points describing part to add
* \param wkbType default WKB type to create if no existing geometry
* \returns OperationResult a result code: success or reason of failure
* \since QGIS 3.38
*/
Qgis::GeometryOperationResult addPartV2( const QVector<QgsPointXY> &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) SIP_PYNAME( addPointsXYV2 );
/**
* Adds a new part to a the geometry.
* \param points points describing part to add
* \param geomType default geometry type to create if no existing geometry
* \returns OperationResult a result code: success or reason of failure
* \deprecated since QGIS 3.38 - will be removed in QGIS 4.0. Use addPartV2 which accepts Qgis::WkbType geometry type instead of Qgis::GeometryType.
*/
Qgis::GeometryOperationResult addPart( const QgsPointSequence &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) SIP_PYNAME( addPoints );
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart( const QgsPointSequence &points, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) SIP_PYNAME( addPoints ) SIP_DEPRECATED;
/**
* Adds a new part to a the geometry.
* \param points points describing part to add
* \param wkbType default WKB type to create if no existing geometry
* \returns OperationResult a result code: success or reason of failure
* \since QGIS 3.38
*/
Qgis::GeometryOperationResult addPartV2( const QgsPointSequence &points, Qgis::WkbType wkbType = Qgis::WkbType::Unknown ) SIP_PYNAME( addPointsV2 );
/**
* Adds a new part to this geometry.
* \param part part to add (ownership is transferred)
* \param geomType default geometry type to create if no existing geometry
* \returns OperationResult a result code: success or reason of failure
* \deprecated since QGIS 3.38 - will be removed in QGIS 4.0. Use addPartV2 which accepts Qgis::WkbType geometry type instead of Qgis::GeometryType.
*/
Qgis::GeometryOperationResult addPart( QgsAbstractGeometry *part SIP_TRANSFER, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown );
Q_DECL_DEPRECATED Qgis::GeometryOperationResult addPart( QgsAbstractGeometry *part SIP_TRANSFER, Qgis::GeometryType geomType = Qgis::GeometryType::Unknown ) SIP_DEPRECATED;
/**
* Adds a new part to this geometry.
* \param part part to add (ownership is transferred)
* \param wkbType default WKB type to create if no existing geometry
* \returns OperationResult a result code: success or reason of failure
* \since QGIS 3.38
*/
Qgis::GeometryOperationResult addPartV2( QgsAbstractGeometry *part SIP_TRANSFER, Qgis::WkbType wkbType = Qgis::WkbType::Unknown );
/**
* Adds a new island polygon to a multipolygon feature

View File

@ -664,7 +664,7 @@ QgsGeometry QgsInternalGeometryEngine::orthogonalize( double tolerance, int maxI
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -823,7 +823,7 @@ QgsGeometry QgsInternalGeometryEngine::densifyByCount( int extraNodesPerSegment
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -859,7 +859,7 @@ QgsGeometry QgsInternalGeometryEngine::densifyByDistance( double distance ) cons
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -1786,7 +1786,7 @@ QgsGeometry QgsInternalGeometryEngine::convertToCurves( double distanceTolerance
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -2090,7 +2090,7 @@ QgsGeometry QgsInternalGeometryEngine::triangularWaves( double wavelength, doubl
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -2133,7 +2133,7 @@ QgsGeometry QgsInternalGeometryEngine::triangularWavesRandomized( double minimum
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -2386,7 +2386,7 @@ QgsGeometry QgsInternalGeometryEngine::squareWaves( double wavelength, double am
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -2429,7 +2429,7 @@ QgsGeometry QgsInternalGeometryEngine::squareWavesRandomized( double minimumWave
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -2802,7 +2802,7 @@ QgsGeometry QgsInternalGeometryEngine::roundWaves( double wavelength, double amp
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -2845,7 +2845,7 @@ QgsGeometry QgsInternalGeometryEngine::roundWavesRandomized( double minimumWavel
QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
for ( QgsAbstractGeometry *g : std::as_const( geometryList ) )
{
first.addPart( g );
first.addPartV2( g );
}
return first;
}
@ -3161,13 +3161,13 @@ QgsGeometry QgsInternalGeometryEngine::applyDashPattern( const QVector<double> &
{
for ( int j = 0; j < collection->numGeometries(); ++j )
{
first.addPart( collection->geometryN( j )->clone() );
first.addPartV2( collection->geometryN( j )->clone() );
}
delete collection;
}
else
{
first.addPart( g );
first.addPartV2( g );
}
}
return first;

View File

@ -278,7 +278,7 @@ Qgis::GeometryOperationResult QgsVectorLayerEditUtils::addPart( const QgsPointSe
geometry = f.geometry();
}
Qgis::GeometryOperationResult errorCode = geometry.addPart( points, mLayer->geometryType() );
Qgis::GeometryOperationResult errorCode = geometry.addPartV2( points, mLayer->wkbType() );
if ( errorCode == Qgis::GeometryOperationResult::Success )
{
if ( firstPart && QgsWkbTypes::isSingleType( mLayer->wkbType() )
@ -317,7 +317,7 @@ Qgis::GeometryOperationResult QgsVectorLayerEditUtils::addPart( QgsCurve *ring,
ring = ring->reversed();
}
}
Qgis::GeometryOperationResult errorCode = geometry.addPart( ring, mLayer->geometryType() );
Qgis::GeometryOperationResult errorCode = geometry.addPartV2( ring, mLayer->wkbType() );
if ( errorCode == Qgis::GeometryOperationResult::Success )
{

View File

@ -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"